Documentation
¶
Overview ¶
package swarm implements a connection muxer with a pair of channels to synchronize all network communication.
Index ¶
- Variables
- type ListenErr
- type Swarm
- func (s *Swarm) CloseConnection(p peer.Peer) error
- func (s *Swarm) Connections() []conn.Conn
- func (s *Swarm) Dial(peer peer.Peer) (conn.Conn, error)
- func (s *Swarm) Error(e error)
- func (s *Swarm) GetConnection(pid peer.ID) conn.Conn
- func (s *Swarm) GetErrChan() chan error
- func (s *Swarm) GetPeerList() []peer.Peer
- func (s *Swarm) InterfaceListenAddresses() ([]ma.Multiaddr, error)
- func (s *Swarm) ListenAddresses() []ma.Multiaddr
Constants ¶
This section is empty.
Variables ¶
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.
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) 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.