Documentation
¶
Index ¶
- Constants
- func DefaultListenAddrs() []multiaddr.Multiaddr
- func UnicastListenAddrs() []multiaddr.Multiaddr
- type BootstrapPeerDebugInfo
- type ConnectionInfo
- type Duration
- type HostConfig
- type IDService
- type KnownPeer
- type P2p
- func (p *P2p) AnnouncedAs() []multiaddr.Multiaddr
- func (p *P2p) Bootstrap()
- func (p *P2p) BootstrapPeersStats() (int, int)
- func (p *P2p) BootstrapPeersStatsDetailed() map[string]BootstrapPeerDebugInfo
- func (p *P2p) ClearBackoff(peerID peer.ID)
- func (p *P2p) Close() error
- func (p *P2p) ConfirmedAddrs() (reachable []multiaddr.Multiaddr, unreachable []multiaddr.Multiaddr, ...)
- func (p *P2p) ConnectPeer(ctx context.Context, peerID peer.ID) error
- func (p *P2p) ConnectedPeersCount() int
- func (p *P2p) ConnectionsLastTrimAgo() time.Duration
- func (p *P2p) FindPeer(ctx context.Context, id peer.ID) (peer.AddrInfo, error)
- func (p *P2p) GetPeerLatency(id peer.ID) time.Duration
- func (p *P2p) HasDirectConnection(peerID peer.ID) bool
- func (p *P2p) Host() host.Host
- func (p *P2p) IDService() IDService
- func (p *P2p) InitHost(hostConfig HostConfig) (host.Host, error)
- func (p *P2p) IsConnected(peerID peer.ID) bool
- func (p *P2p) MaintainBackgroundConnections(ctx context.Context, interval time.Duration, knownPeersFunc func() []KnownPeer)
- func (p *P2p) NetworkSize() (int32, error)
- func (p *P2p) NetworkStats() metrics.Stats
- func (p *P2p) NetworkStatsByPeer() map[peer.ID]metrics.Stats
- func (p *P2p) NetworkStatsByProtocol() map[protocol.ID]metrics.Stats
- func (p *P2p) NetworkStatsForPeer(peerID peer.ID) metrics.Stats
- func (p *P2p) NewStream(ctx context.Context, id peer.ID, proto protocol.ID) (network.Stream, error)
- func (p *P2p) NewStreamMulti(ctx context.Context, id peer.ID, protos ...protocol.ID) (network.Stream, error)
- func (p *P2p) NewStreamWithDedicatedConn(ctx context.Context, id peer.ID, proto protocol.ID) (network.Stream, error)
- func (p *P2p) NotifyNetworkChanged()
- func (p *P2p) OpenConnectionsCount() int
- func (p *P2p) OpenStreamStats() map[protocol.ID]map[string]int
- func (p *P2p) OpenStreamsCount() int64
- func (p *P2p) PeerConnectionsInfo(peerID peer.ID) []ConnectionInfo
- func (p *P2p) PeerID() peer.ID
- func (p *P2p) PeerPublicIP(peerID peer.ID) string
- func (p *P2p) PeerUserAgent(peerID peer.ID) string
- func (p *P2p) PeersWithAddrsCount() int
- func (p *P2p) PeerstoreAddrs(peerID peer.ID) []string
- func (p *P2p) ProtectPeer(id peer.ID)
- func (p *P2p) Reachability() network.Reachability
- func (p *P2p) ReconnectInfo(peerID peer.ID) *ReconnectDebugInfo
- func (p *P2p) RecordPeerLatency(id peer.ID, rtt time.Duration)
- func (p *P2p) RoutingTablePeers() []kbucket.PeerInfo
- func (p *P2p) RoutingTableSize() int
- func (p *P2p) SubscribeConnectionEvents(onConnected, onDisconnected func(network.Network, network.Conn))
- func (p *P2p) TCPDialStats() TCPDialStats
- func (p *P2p) UnprotectPeer(id peer.ID)
- func (p *P2p) Uptime() time.Duration
- type ReconnectDebugInfo
- type TCPDialStats
Constants ¶
const ( DesiredRelays = 2 RelayBootDelay = 20 * time.Second DHTProtocolPrefix protocol.ID = "/awl" )
Variables ¶
This section is empty.
Functions ¶
func DefaultListenAddrs ¶
func UnicastListenAddrs ¶
Types ¶
type BootstrapPeerDebugInfo ¶
type BootstrapPeerDebugInfo struct {
Error string `json:",omitempty"`
Connections []string `json:",omitempty"`
Ping Duration `json:",omitempty" swaggertype:"string"`
// PeerstoreAddrs are the addresses a dial to the peer goes through
PeerstoreAddrs []string `json:",omitempty"`
// Reconnect is set while the peer cannot be reached
Reconnect *ReconnectDebugInfo `json:",omitempty"`
}
type ConnectionInfo ¶
type Duration ¶ added in v0.13.0
func (Duration) MarshalJSON ¶ added in v0.13.0
func (*Duration) UnmarshalJSON ¶ added in v0.13.0
type HostConfig ¶
type HostConfig struct {
PrivKeyBytes []byte
ListenAddrs []multiaddr.Multiaddr
UserAgent string
BootstrapPeers []peer.AddrInfo
AllowEmptyBootstrapPeers bool
EnableAutoRelay bool
// SocketControlFunc is set when gateway mode is enabled to mark sockets
// (e.g., SO_MARK on Linux) so they bypass the VPN TUN interface.
SocketControlFunc func(network, address string, c syscall.RawConn) error
Libp2pOpts []libp2p.Option
ConnManager struct {
LowWater int
HighWater int
GracePeriod time.Duration
}
Peerstore peerstore.Peerstore
DHTDatastore ds.Batching
DHTOpts []dht.Option
}
type IDService ¶
type IDService interface {
// IdentifyConn synchronously triggers an identify request on the connection and
// waits for it to complete. If the connection is being identified by another
// caller, this call will wait. If the connection has already been identified,
// it will return immediately.
IdentifyConn(network.Conn)
// IdentifyWait triggers an identify (if the connection has not already been
// identified) and returns a channel that is closed when the identify protocol
// completes.
IdentifyWait(network.Conn) <-chan struct{}
}
type KnownPeer ¶ added in v0.20.0
type KnownPeer struct {
ID peer.ID
// Eager peers are tried every round with no backoff, however long they have
// been unreachable.
Eager bool
}
KnownPeer is a peer MaintainBackgroundConnections keeps a connection to.
type P2p ¶
type P2p struct {
// contains filtered or unexported fields
}
func (*P2p) AnnouncedAs ¶
func (*P2p) BootstrapPeersStats ¶
BootstrapPeersStats returns total peers count and connected count.
func (*P2p) BootstrapPeersStatsDetailed ¶
func (p *P2p) BootstrapPeersStatsDetailed() map[string]BootstrapPeerDebugInfo
func (*P2p) ClearBackoff ¶
func (*P2p) ConfirmedAddrs ¶ added in v0.14.0
func (*P2p) ConnectedPeersCount ¶
func (*P2p) ConnectionsLastTrimAgo ¶
func (*P2p) GetPeerLatency ¶ added in v0.14.0
func (*P2p) HasDirectConnection ¶ added in v0.18.0
HasDirectConnection reports whether at least one current connection to the given peer is direct (i.e. not via a libp2p circuit relay). Returns false if there are no connections at all.
func (*P2p) MaintainBackgroundConnections ¶
func (p *P2p) MaintainBackgroundConnections(ctx context.Context, interval time.Duration, knownPeersFunc func() []KnownPeer)
MaintainBackgroundConnections keeps the node connected to its known and bootstrap peers. A peer that cannot be reached is retried less and less often, see retrySchedule; interval is both the pace of the rounds and the first pause of that backoff.
func (*P2p) NetworkSize ¶ added in v0.8.0
func (*P2p) NetworkStats ¶
func (*P2p) NetworkStatsByProtocol ¶
func (*P2p) NewStreamMulti ¶ added in v0.17.0
func (*P2p) NewStreamWithDedicatedConn ¶ added in v0.11.0
func (*P2p) NotifyNetworkChanged ¶ added in v0.20.0
func (p *P2p) NotifyNetworkChanged()
NotifyNetworkChanged tells P2p that the network of the host has changed, for the case when the caller knows better than P2p can find out. Every known and bootstrap peer is then tried right away, with no regard to its backoff. It does not block, and calls that pile up are handled as one.
func (*P2p) OpenConnectionsCount ¶
func (*P2p) OpenStreamsCount ¶
func (*P2p) PeerConnectionsInfo ¶
func (p *P2p) PeerConnectionsInfo(peerID peer.ID) []ConnectionInfo
func (*P2p) PeerPublicIP ¶ added in v0.18.0
PeerPublicIP returns the verified public IP of the directly-connected peer. It inspects active connections (skipping /p2p-circuit relay connections) and returns the IP from the first non-relay Conn's RemoteMultiaddr — that address is the one libp2p actually completed a handshake against, so it's reliable (unlike Peerstore entries, which include unverified self-reported addrs from identify). Returns "" if the peer is reachable only via a relay or is not connected; in that case the real public IP is not observable to us.
func (*P2p) PeersWithAddrsCount ¶
func (*P2p) PeerstoreAddrs ¶ added in v0.20.0
PeerstoreAddrs returns the addresses we have for the peer, sorted: the ones a dial to it goes through, a /dnsaddr among them is yet to be resolved. They are kept in memory and expire, so there are none for a peer that has been away for a while.
func (*P2p) ProtectPeer ¶
func (*P2p) Reachability ¶
func (p *P2p) Reachability() network.Reachability
func (*P2p) ReconnectInfo ¶ added in v0.20.0
func (p *P2p) ReconnectInfo(peerID peer.ID) *ReconnectDebugInfo
ReconnectInfo reports what MaintainBackgroundConnections remembers about a known or a bootstrap peer it could not reach. It is nil for a peer with nothing against it: one that is connected, or was not tried yet.
func (*P2p) RecordPeerLatency ¶ added in v0.14.0
func (*P2p) RoutingTablePeers ¶
func (*P2p) RoutingTableSize ¶
func (*P2p) SubscribeConnectionEvents ¶
func (*P2p) TCPDialStats ¶ added in v0.20.0
func (p *P2p) TCPDialStats() TCPDialStats
TCPDialStats returns the dial counters of the main host. The AutoNAT dial-back hosts are left out: they never reuse a port by design.
func (*P2p) UnprotectPeer ¶
type ReconnectDebugInfo ¶ added in v0.20.0
type ReconnectDebugInfo struct {
// Failures in a row
Failures int
LastAttemptAgo Duration `swaggertype:"string"`
// NextAttemptIn is zero when the peer is to be tried on the next round
NextAttemptIn Duration `swaggertype:"string"`
LastError string
}
ReconnectDebugInfo is what MaintainBackgroundConnections remembers about a peer it could not reach.
type TCPDialStats ¶ added in v0.20.0
type TCPDialStats struct {
// FromListenPort is what hole punching needs. If it stays at zero while
// FromRandomPort grows, port reuse is silently broken.
FromListenPort int64
FromRandomPort int64
}
TCPDialStats counts successful outbound TCP dials of the main libp2p host by the source port they left from. Only maintained when socket marking is on (see reuseportDialer); zero otherwise.