swarm

package
v0.0.0-...-e4696f9 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2014 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

package swarm implements a connection muxer with a pair of channels to synchronize all network communication.

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyOpen = errors.New("Error: Connection to this peer already open.")

ErrAlreadyOpen signals that a connection to a peer is already open.

Functions

This section is empty.

Types

type ListenErr

type ListenErr struct {
	Errors []error
}

ListenErr contains a set of errors mapping to each of the swarms addresses. Used to return multiple errors, as in listen.

func (*ListenErr) Error

func (e *ListenErr) Error() string

type Swarm

type Swarm struct {

	// Swarm includes a Pipe object.
	*msg.Pipe

	// ContextCloser
	ctxc.ContextCloser
	// 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(ctx context.Context, listenAddrs []ma.Multiaddr, local peer.Peer, ps peer.Peerstore) (*Swarm, error)

NewSwarm constructs a Swarm, with a Chan.

func (*Swarm) CloseConnection

func (s *Swarm) CloseConnection(p peer.Peer) error

CloseConnection removes a given peer from swarm + closes the connection

func (*Swarm) Connections

func (s *Swarm) Connections() []conn.Conn

Connections returns a slice of all connections.

func (*Swarm) Dial

func (s *Swarm) Dial(peer peer.Peer) (conn.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.

func (*Swarm) Error

func (s *Swarm) Error(e error)

func (*Swarm) GetConnection

func (s *Swarm) GetConnection(pid peer.ID) conn.Conn

GetConnection returns the connection in the swarm to given peer.ID

func (*Swarm) GetErrChan

func (s *Swarm) GetErrChan() chan error

GetErrChan returns the errors chan.

func (*Swarm) GetPeerList

func (s *Swarm) GetPeerList() []peer.Peer

GetPeerList returns a copy of the set of peers swarm is connected to.

func (*Swarm) InterfaceListenAddresses

func (s *Swarm) InterfaceListenAddresses() ([]ma.Multiaddr, error)

InterfaceListenAddresses returns a list of addresses at which this swarm listens. It expands "any interface" addresses (/ip4/0.0.0.0, /ip6/::) to use the known local interfaces.

func (*Swarm) ListenAddresses

func (s *Swarm) ListenAddresses() []ma.Multiaddr

ListenAddresses returns a list of addresses at which this swarm listens.

Jump to

Keyboard shortcuts

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