swarm

package
v0.0.0-...-2ec1701 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2014 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const ChanBuffer = 10

ChanBuffer is the size of the buffer in the Conn Chan

Variables

This section is empty.

Functions

This section is empty.

Types

type Chan

type Chan struct {
	Outgoing chan Message
	Incoming chan Message
	Errors   chan error
	Close    chan bool
}

Chan is a swam channel, which provides duplex communication and errors.

func NewChan

func NewChan(bufsize int) *Chan

NewChan constructs a Chan instance, with given buffer size bufsize.

type Conn

type Conn struct {
	Peer *peer.Peer
	Addr *ma.Multiaddr
	Conn net.Conn

	Closed   chan bool
	Outgoing *msgio.Chan
	Incoming *msgio.Chan
}

Conn represents a connection to another Peer (IPFS Node).

func Dial

func Dial(network string, peer *peer.Peer) (*Conn, error)

Dial connects to a particular peer, over a given network Example: Dial("udp", peer)

func (*Conn) Close

func (s *Conn) Close() error

Close closes the connection, and associated channels.

type ConnMap

type ConnMap map[u.Key]*Conn

ConnMap maps Keys (Peer.IDs) to Connections.

type Message

type Message struct {
	// To or from, depending on direction.
	Peer *peer.Peer

	// Opaque data
	Data []byte
}

Message represents a packet of information sent to or received from a particular Peer.

type Swarm

type Swarm struct {
	Chan *Chan
	// contains filtered or unexported fields
}

Swarm is a connection muxer, allowing connections to other peers to be opened and closed, while still using the same Chan for all communication. The Chan sends/receives Messages, which note the destination or source Peer.

func NewSwarm

func NewSwarm() *Swarm

NewSwarm constructs a Swarm, with a Chan.

func (*Swarm) Close

func (s *Swarm) Close()

Close closes a swam.

func (*Swarm) Dial

func (s *Swarm) Dial(peer *peer.Peer) (*Conn, error)

Dial connects to a peer.

The idea is that the client of Swarm does not need to know what network the connection will happen over. Swarm can use whichever it choses. This allows us to use various transport protocols, do NAT traversal/relay, etc. to achive connection.

For now, Dial uses only TCP. This will be extended.

Jump to

Keyboard shortcuts

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