network

package
v0.0.0-...-40917eb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 9, 2014 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package network provides threaded P2P functionality for sending Messages wrapped in the bitmsg header.

Index

Constants

View Source
const (
	ENTFND = iota
	EPRDUP = iota
)

Error constants for PeerError

View Source
const (
	ESMALL = iota
	EMAGIC = iota
	EPALEN = iota
	ECHECK = iota
	ETIMEO = iota
)

Error constants for MessageError

Variables

This section is empty.

Functions

func ConnectToPeer

func ConnectToPeer(p *Peer) error

ConnectToPeer adds the provided peer to the peerlist, or just connects to it if it already exists. Duplicate connected peers are not allowed.

func Listen

func Listen(port string) error

Listen sets up a local TCP BitMSG server on the provided port. The port must be in the format ":###", with the colon.

func Send

func Send(msg *Message) error

Send adds a validated messge to the send channel.

Types

type Message

type Message struct {
	// contains filtered or unexported fields
}

Message holds a standard, serializeable BitMsg message header and generic payload. See more info at https://bitmessage.org/wiki/Protocol_specification#Message_structure

func GetNext

func GetNext(timeout time.Duration) (*Message, error)

GetNext returns the next message in the queue or nil if the timeout is reached

func MakeMessage

func MakeMessage(cmd string, pload types.Serializer, recipient *Peer) *Message

MakeMessage generates a new message given a command, payload, and recipient. No defensive copy is made of the byte slice

func (*Message) Command

func (m *Message) Command() string

Command returns the command associated with the message

func (*Message) Payload

func (m *Message) Payload() []byte

Payload returns the generic payload byte slice of the Message

func (*Message) Sender

func (m *Message) Sender() *Peer

Sender returns the recipient and/or sender of the message

func (*Message) Serialize

func (m *Message) Serialize() []byte

Serialize converts a message to a byte stream that can be sent over the network.

type MessageError

type MessageError int

MessageError handles all errors associated with the Message struct.

func (MessageError) Error

func (errno MessageError) Error() string

Error converts the MessageError constant to a human-readable string

type Peer

type Peer struct {
	// contains filtered or unexported fields
}

Peer represents and holds connection information for an external connection specified by a hostname/port combination.

func GetPeer

func GetPeer(host string) *Peer

GetPeer checks the peer list to see if a peer exists under a hostname. It then returns that peer.

func MakePeer

func MakePeer(host string) *Peer

MakePeer creates an unconnected peer from a host/port combination

func (*Peer) Hostname

func (p *Peer) Hostname() string

Hostname returns the host/port combination for a given peer

func (*Peer) IsConnected

func (p *Peer) IsConnected() bool

IsConnected returns the connection status of the peer

type PeerError

type PeerError int

PeerError handles all errors associated with the Peer struct.

func (PeerError) Error

func (errno PeerError) Error() string

Error converts the PeerError constant to a human-readable string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL