Documentation ¶
Overview ¶
package swarm implements a connection muxer with a pair of channels to synchronize all network communication.
Index ¶
- Variables
- type Conn
- func (c *Conn) Close() error
- func (c *Conn) LocalMultiaddr() ma.Multiaddr
- func (c *Conn) LocalPeer() peer.ID
- func (c *Conn) LocalPrivateKey() ic.PrivKey
- func (c *Conn) NewStream() (inet.Stream, error)
- func (c *Conn) NewSwarmStream() (*Stream, error)
- func (c *Conn) RawConn() conn.Conn
- func (c *Conn) RemoteMultiaddr() ma.Multiaddr
- func (c *Conn) RemotePeer() peer.ID
- func (c *Conn) RemotePublicKey() ic.PubKey
- func (c *Conn) StreamConn() *ps.Conn
- func (c *Conn) String() string
- type ConnHandler
- type Network
- func (n *Network) Close() error
- func (n *Network) ClosePeer(p peer.ID) error
- func (n *Network) Connectedness(p peer.ID) inet.Connectedness
- func (n *Network) Conns() []inet.Conn
- func (n *Network) ConnsToPeer(p peer.ID) []inet.Conn
- func (n *Network) DialPeer(ctx context.Context, p peer.ID) (inet.Conn, error)
- func (n *Network) InterfaceListenAddresses() ([]ma.Multiaddr, error)
- func (n *Network) Listen(addrs ...ma.Multiaddr) error
- func (n *Network) ListenAddresses() []ma.Multiaddr
- func (n *Network) LocalPeer() peer.ID
- func (n *Network) NewStream(p peer.ID) (inet.Stream, error)
- func (n *Network) Notify(f inet.Notifiee)
- func (n *Network) Peers() []peer.ID
- func (n *Network) Peerstore() peer.Peerstore
- func (n *Network) Process() goprocess.Process
- func (n *Network) SetConnHandler(h inet.ConnHandler)
- func (n *Network) SetStreamHandler(h inet.StreamHandler)
- func (n *Network) StopNotify(f inet.Notifiee)
- func (n *Network) String() string
- func (n *Network) Swarm() *Swarm
- type Stream
- type Swarm
- func (s *Swarm) AddAddrFilter(f string) error
- func (s *Swarm) Close() error
- func (s *Swarm) CloseConnection(p peer.ID) error
- func (s *Swarm) Connections() []*Conn
- func (s *Swarm) ConnectionsToPeer(p peer.ID) []*Conn
- func (s *Swarm) Context() context.Context
- func (s *Swarm) Dial(ctx context.Context, p peer.ID) (*Conn, error)
- func (s *Swarm) InterfaceListenAddresses() ([]ma.Multiaddr, error)
- func (s *Swarm) Listen(addrs ...ma.Multiaddr) error
- func (s *Swarm) ListenAddresses() []ma.Multiaddr
- func (s *Swarm) LocalPeer() peer.ID
- func (s *Swarm) NewStreamWithPeer(p peer.ID) (*Stream, error)
- func (s *Swarm) Notify(f inet.Notifiee)
- func (s *Swarm) Peers() []peer.ID
- func (s *Swarm) Process() goprocess.Process
- func (s *Swarm) SetConnHandler(handler ConnHandler)
- func (s *Swarm) SetStreamHandler(handler inet.StreamHandler)
- func (s *Swarm) StopNotify(f inet.Notifiee)
- func (s *Swarm) StreamSwarm() *ps.Swarm
- func (s *Swarm) StreamsWithPeer(p peer.ID) []*Stream
Constants ¶
This section is empty.
Variables ¶
var ( ErrDialBackoff = errors.New("dial backoff") ErrDialFailed = errors.New("dial attempt failed") ErrDialToSelf = errors.New("dial to self attempted") )
var DialTimeout time.Duration = time.Second * 10
DialTimeout is the amount of time each dial attempt has. We can think about making this larger down the road, or putting more granular timeouts (i.e. within each subcomponent of Dial)
var PSTransport pst.Transport
Functions ¶
This section is empty.
Types ¶
type Conn ¶
a Conn is a simple wrapper around a ps.Conn that also exposes some of the methods from the underlying conn.Conn. There's **five** "layers" to each connection:
- 0. the net.Conn - underlying net.Conn (TCP/UDP/UTP/etc)
- 1. the manet.Conn - provides multiaddr friendly Conn
- 2. the conn.Conn - provides Peer friendly Conn (inc Secure channel)
- 3. the peerstream.Conn - provides peerstream / spdysptream happiness
- 4. the Conn - abstracts everyting out, exposing only key parts of underlying layers
(I know, this is kinda crazy. it's more historical than a good design. though the layers do build up pieces of functionality. and they're all just io.RW :) )
func (*Conn) LocalMultiaddr ¶
LocalMultiaddr is the Multiaddr on this side
func (*Conn) LocalPrivateKey ¶
LocalPrivateKey is the public key of the peer on this side
func (*Conn) NewSwarmStream ¶
NewSwarmStream returns a new Stream from this connection
func (*Conn) RemoteMultiaddr ¶
RemoteMultiaddr is the Multiaddr on the remote side
func (*Conn) RemotePeer ¶
RemotePeer is the Peer on the remote side
func (*Conn) RemotePublicKey ¶
RemotePublicKey is the public key of the peer on the remote side
func (*Conn) StreamConn ¶
type ConnHandler ¶
type ConnHandler func(*Conn)
ConnHandler is called when new conns are opened from remote peers. See peerstream.ConnHandler
type Network ¶
type Network Swarm
Network implements the inet.Network interface. It is simply a swarm, with a few different functions to implement inet.Network.
func NewNetwork ¶
func NewNetwork(ctx context.Context, listen []ma.Multiaddr, local peer.ID, peers peer.Peerstore, bwc metrics.Reporter) (*Network, error)
NewNetwork constructs a new network and starts listening on given addresses.
func (*Network) Connectedness ¶
func (n *Network) Connectedness(p peer.ID) inet.Connectedness
Connectedness returns a state signaling connection capabilities For now only returns Connected || NotConnected. Expand into more later.
func (*Network) ConnsToPeer ¶
ConnsToPeer returns the connections in this Netowrk for given peer.
func (*Network) DialPeer ¶
DialPeer attempts to establish a connection to a given peer. Respects the context.
func (*Network) InterfaceListenAddresses ¶
InterfaceListenAddresses returns a list of addresses at which this network listens. It expands "any interface" addresses (/ip4/0.0.0.0, /ip6/::) to use the known local interfaces.
func (*Network) ListenAddresses ¶
ListenAddresses returns a list of addresses at which this network listens.
func (*Network) NewStream ¶
NewStream returns a new stream to given peer p. If there is no connection to p, attempts to create one.
func (*Network) SetConnHandler ¶
func (n *Network) SetConnHandler(h inet.ConnHandler)
SetConnHandler sets the conn handler on the Network. This operation is threadsafe.
func (*Network) SetStreamHandler ¶
func (n *Network) SetStreamHandler(h inet.StreamHandler)
SetHandler sets the protocol handler on the Network's Muxer. This operation is threadsafe.
func (*Network) StopNotify ¶
StopNotify unregisters Notifiee fromr receiving signals
type Stream ¶
a Stream is a wrapper around a ps.Stream that exposes a way to get our Conn and Swarm (instead of just the ps.Conn and ps.Swarm)
type Swarm ¶
type Swarm struct { // filters for addresses that shouldnt be dialed Filters *filter.Filters // 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.
Uses peerstream.Swarm
func NewSwarm ¶
func NewSwarm(ctx context.Context, listenAddrs []ma.Multiaddr, local peer.ID, peers peer.Peerstore, bwc metrics.Reporter) (*Swarm, error)
NewSwarm constructs a Swarm, with a Chan.
func (*Swarm) AddAddrFilter ¶ added in v0.3.6
func (*Swarm) CloseConnection ¶
CloseConnection removes a given peer from swarm + closes the connection
func (*Swarm) Connections ¶
Connections returns a slice of all connections.
func (*Swarm) ConnectionsToPeer ¶
ConnectionsToPeer returns all the live connections to p
func (*Swarm) Dial ¶
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.
func (*Swarm) InterfaceListenAddresses ¶
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 ¶
ListenAddresses returns a list of addresses at which this swarm listens.
func (*Swarm) NewStreamWithPeer ¶
NewStreamWithPeer creates a new stream on any available connection to p
func (*Swarm) SetConnHandler ¶
func (s *Swarm) SetConnHandler(handler ConnHandler)
SetConnHandler assigns the handler for new connections. See peerstream. You will rarely use this. See SetStreamHandler
func (*Swarm) SetStreamHandler ¶
func (s *Swarm) SetStreamHandler(handler inet.StreamHandler)
SetStreamHandler assigns the handler for new streams. See peerstream.
func (*Swarm) StopNotify ¶
StopNotify unregisters Notifiee fromr receiving signals
func (*Swarm) StreamSwarm ¶
StreamSwarm returns the underlying peerstream.Swarm