Documentation ¶
Index ¶
- Constants
- Variables
- type Conn
- func (c *Conn) Close() error
- func (c *Conn) GetStreams() []network.Stream
- func (c *Conn) ID() string
- func (c *Conn) LocalMultiaddr() ma.Multiaddr
- func (c *Conn) LocalPeer() peer.ID
- func (c *Conn) LocalPrivateKey() ic.PrivKey
- func (c *Conn) NewStream() (network.Stream, error)
- func (c *Conn) RemoteMultiaddr() ma.Multiaddr
- func (c *Conn) RemotePeer() peer.ID
- func (c *Conn) RemotePublicKey() ic.PubKey
- func (c *Conn) Stat() network.Stat
- func (c *Conn) String() string
- type DialBackoff
- type DialError
- type DialFunc
- type DialSync
- type Stream
- func (s *Stream) Close() error
- func (s *Stream) Conn() network.Conn
- func (s *Stream) ID() string
- func (s *Stream) Protocol() protocol.ID
- func (s *Stream) Read(p []byte) (int, error)
- func (s *Stream) Reset() error
- func (s *Stream) SetDeadline(t time.Time) error
- func (s *Stream) SetProtocol(p protocol.ID)
- func (s *Stream) SetReadDeadline(t time.Time) error
- func (s *Stream) SetWriteDeadline(t time.Time) error
- func (s *Stream) Stat() network.Stat
- func (s *Stream) String() string
- func (s *Stream) Write(p []byte) (int, error)
- type Swarm
- func (s *Swarm) AddListenAddr(a ma.Multiaddr) error
- func (s *Swarm) AddTransport(t transport.Transport) error
- func (s *Swarm) Backoff() *DialBackoff
- func (s *Swarm) Close() error
- func (s *Swarm) ClosePeer(p peer.ID) error
- func (s *Swarm) ConnHandler() network.ConnHandler
- func (s *Swarm) Connectedness(p peer.ID) network.Connectedness
- func (s *Swarm) Conns() []network.Conn
- func (s *Swarm) ConnsToPeer(p peer.ID) []network.Conn
- func (s *Swarm) Context() context.Context
- func (s *Swarm) DialPeer(ctx context.Context, p peer.ID) (network.Conn, error)
- func (s *Swarm) InterfaceListenAddresses() ([]ma.Multiaddr, error)
- func (s *Swarm) IsFdConsumingAddr(addr ma.Multiaddr) bool
- func (s *Swarm) Listen(addrs ...ma.Multiaddr) error
- func (s *Swarm) ListenAddresses() []ma.Multiaddr
- func (s *Swarm) LocalPeer() peer.ID
- func (s *Swarm) NewStream(ctx context.Context, p peer.ID) (network.Stream, error)
- func (s *Swarm) Notify(f network.Notifiee)
- func (s *Swarm) Peers() []peer.ID
- func (s *Swarm) Peerstore() peerstore.Peerstore
- func (s *Swarm) Process() goprocess.Process
- func (s *Swarm) SetConnHandler(handler network.ConnHandler)
- func (s *Swarm) SetStreamHandler(handler network.StreamHandler)
- func (s *Swarm) StopNotify(f network.Notifiee)
- func (s *Swarm) StreamHandler() network.StreamHandler
- func (s *Swarm) String() string
- func (s *Swarm) TransportForDialing(a ma.Multiaddr) transport.Transport
- func (s *Swarm) TransportForListening(a ma.Multiaddr) transport.Transport
- type TransportError
Constants ¶
const ConcurrentFdDials = 160
ConcurrentFdDials is the number of concurrent outbound dials over transports that consume file descriptors
const DefaultPerPeerRateLimit = 8
DefaultPerPeerRateLimit is the number of concurrent outbound dials to make per peer
const DialAttempts = 1
DialAttempts governs how many times a goroutine will try to dial a given peer. Note: this is down to one, as we have _too many dials_ atm. To add back in, add loop back in Dial(.)
Variables ¶
var ( // ErrDialBackoff is returned by the backoff code when a given peer has // been dialed too frequently ErrDialBackoff = errors.New("dial backoff") // ErrDialToSelf is returned if we attempt to dial our own peer ErrDialToSelf = errors.New("dial to self attempted") // ErrNoTransport is returned when we don't know a transport for the // given multiaddr. ErrNoTransport = errors.New("no transport for protocol") // ErrAllDialsFailed is returned when connecting to a peer has ultimately failed ErrAllDialsFailed = errors.New("all dials failed") // ErrNoAddresses is returned when we fail to find any addresses for a // peer we're trying to dial. ErrNoAddresses = errors.New("no addresses") // ErrNoGoodAddresses is returned when we find addresses for a peer but // can't use any of them. ErrNoGoodAddresses = errors.New("no good addresses") // ErrGaterDisallowedConnection is returned when the gater prevents us from // forming a connection with a peer. ErrGaterDisallowedConnection = errors.New("gater disallows connection to peer") )
var BackoffBase = time.Second * 5
BackoffBase is the base amount of time to backoff (default: 5s).
var BackoffCoef = time.Second
BackoffCoef is the backoff coefficient (default: 1s).
var BackoffMax = time.Minute * 5
BackoffMax is the maximum backoff time (default: 5m).
var DialTimeoutLocal = 5 * time.Second
DialTimeoutLocal is the maximum duration a Dial to local network address is allowed to take. This includes the time between dialing the raw network connection, protocol selection as well the handshake, if applicable.
var ErrAddrFiltered = errors.New("address filtered")
ErrAddrFiltered is returned when trying to register a connection to a filtered address. You shouldn't see this error unless some underlying transport is misbehaving.
var ErrConnClosed = errors.New("connection closed")
ErrConnClosed is returned when operating on a closed connection.
var ErrDialTimeout = errors.New("dial timed out")
ErrDialTimeout is returned when one a dial times out due to the global timeout
var ErrSwarmClosed = errors.New("swarm closed")
ErrSwarmClosed is returned when one attempts to operate on a closed swarm.
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn is the connection type used by swarm. In general, you won't use this type directly.
func (*Conn) Close ¶
Close closes this connection.
Note: This method won't wait for the close notifications to finish as that would create a deadlock when called from an open notification (because all open notifications must finish before we can fire off the close notifications).
func (*Conn) GetStreams ¶
GetStreams returns the streams associated with this connection.
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) 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
type DialBackoff ¶
type DialBackoff struct {
// contains filtered or unexported fields
}
DialBackoff is a type for tracking peer dial backoffs.
* It's safe to use its zero value. * It's thread-safe. * It's *not* safe to move this type after using.
func (*DialBackoff) AddBackoff ¶
func (db *DialBackoff) AddBackoff(p peer.ID, addr ma.Multiaddr)
AddBackoff lets other nodes know that we've entered backoff with peer p, so dialers should not wait unnecessarily. We still will attempt to dial with one goroutine, in case we get through.
Backoff is not exponential, it's quadratic and computed according to the following formula:
BackoffBase + BakoffCoef * PriorBackoffs^2
Where PriorBackoffs is the number of previous backoffs.
func (*DialBackoff) Backoff ¶
Backoff returns whether the client should backoff from dialing peer p at address addr
func (*DialBackoff) Clear ¶
func (db *DialBackoff) Clear(p peer.ID)
Clear removes a backoff record. Clients should call this after a successful Dial.
type DialError ¶
type DialError struct { Peer peer.ID DialErrors []TransportError Cause error Skipped int }
DialError is the error type returned when dialing.
func (*DialError) Unwrap ¶
Unwrap implements https://godoc.org/golang.org/x/xerrors#Wrapper.
type DialSync ¶
type DialSync struct {
// contains filtered or unexported fields
}
DialSync is a dial synchronization helper that ensures that at most one dial to any given peer is active at any given time.
func (*DialSync) CancelDial ¶
CancelDial cancels all in-progress dials to the given peer.
type Stream ¶
type Stream struct {
// contains filtered or unexported fields
}
Stream is the stream type used by swarm. In general, you won't use this type directly.
func (*Stream) SetDeadline ¶
SetDeadline sets the read and write deadlines for this stream.
func (*Stream) SetProtocol ¶
SetProtocol sets the protocol for this stream.
This doesn't actually *do* anything other than record the fact that we're speaking the given protocol over this stream. It's still up to the user to negotiate the protocol. This is usually done by the Host.
func (*Stream) SetReadDeadline ¶
SetReadDeadline sets the read deadline for this stream.
func (*Stream) SetWriteDeadline ¶
SetWriteDeadline sets the write deadline for this stream.
type Swarm ¶
type Swarm struct {
// 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, local peer.ID, peers peerstore.Peerstore, bwc metrics.Reporter, extra ...interface{}) *Swarm
NewSwarm constructs a Swarm.
NOTE: go-libp2p will be moving to dependency injection soon. The variadic `extra` interface{} parameter facilitates the future migration. Supported elements are:
- connmgr.ConnectionGater
func (*Swarm) AddListenAddr ¶
AddListenAddr tells the swarm to listen on a single address. Unlike Listen, this method does not attempt to filter out bad addresses.
func (*Swarm) AddTransport ¶
AddTransport adds a transport to this swarm.
Satisfies the Network interface from go-libp2p-transport.
func (*Swarm) Backoff ¶
func (s *Swarm) Backoff() *DialBackoff
Backoff returns the DialBackoff object for this swarm.
func (*Swarm) ConnHandler ¶
func (s *Swarm) ConnHandler() network.ConnHandler
ConnHandler gets the handler for new connections.
func (*Swarm) Connectedness ¶
func (s *Swarm) Connectedness(p peer.ID) network.Connectedness
Connectedness returns our "connectedness" state with the given peer.
To check if we have an open connection, use `s.Connectedness(p) == network.Connected`.
func (*Swarm) ConnsToPeer ¶
ConnsToPeer returns all the live connections to peer.
func (*Swarm) DialPeer ¶
DialPeer 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 achieve 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) IsFdConsumingAddr ¶
TODO We should have a `IsFdConsuming() bool` method on the `Transport` interface in go-libp2p-core/transport. This function checks if any of the transport protocols in the address requires a file descriptor. For now: A Non-circuit address which has the TCP/UNIX protocol is deemed FD consuming. For a circuit-relay address, we look at the address of the relay server/proxy and use the same logic as above to decide.
func (*Swarm) Listen ¶
Listen sets up listeners for all of the given addresses. It returns as long as we successfully listen on at least *one* address.
func (*Swarm) ListenAddresses ¶
ListenAddresses returns a list of addresses at which this swarm listens.
func (*Swarm) NewStream ¶
NewStream creates a new stream on any available connection to peer, dialing if necessary.
func (*Swarm) SetConnHandler ¶
func (s *Swarm) SetConnHandler(handler network.ConnHandler)
SetConnHandler assigns the handler for new connections. You will rarely use this. See SetStreamHandler
func (*Swarm) SetStreamHandler ¶
func (s *Swarm) SetStreamHandler(handler network.StreamHandler)
SetStreamHandler assigns the handler for new streams.
func (*Swarm) StopNotify ¶
StopNotify unregisters Notifiee fromr receiving signals
func (*Swarm) StreamHandler ¶
func (s *Swarm) StreamHandler() network.StreamHandler
StreamHandler gets the handler for new streams.
func (*Swarm) TransportForDialing ¶
TransportForDialing retrieves the appropriate transport for dialing the given multiaddr.
type TransportError ¶
TransportError is the error returned when dialing a specific address.
func (*TransportError) Error ¶
func (e *TransportError) Error() string