Documentation
¶
Index ¶
- Constants
- Variables
- func EnableP2PLogging(log logging.Logger, l logging.Level) error
- func GetPeerTelemetryInfo(peerProtocols []protocol.ID) (telemetryID string, telemetryInstance string)
- func GetPrivKey(cfg config.Local, dataDir string) (crypto.PrivKey, error)
- func MakeHost(cfg config.Local, datadir string, pstore *pstore.PeerStore) (host.Host, string, error)
- func MakeService(ctx context.Context, log logging.Logger, cfg config.Local, h host.Host, ...) (*serviceImpl, error)
- func MakeTestHTTPClient(addrInfo *peer.AddrInfo, opts ...httpClientOption) (*http.Client, error)
- func SetP2PLogLevel(l logging.Level) error
- func WithHost(h host.Host) httpClientOption
- type CapabilitiesDiscovery
- func (c *CapabilitiesDiscovery) AdvertiseCapabilities(capabilities ...Capability)
- func (c *CapabilitiesDiscovery) Close() error
- func (c *CapabilitiesDiscovery) Host() host.Host
- func (c *CapabilitiesDiscovery) PeersForCapability(capability Capability, n int) ([]peer.AddrInfo, error)
- func (c *CapabilitiesDiscovery) RoutingTable() Sizer
- type Capability
- type HTTPServer
- type PeerID
- type PeerIDChallengeSigner
- type Service
- type Sizer
- type StreamHandler
- type SubNextCancellable
Constants ¶
const ( // Archival nodes Archival Capability = "archival" // Catchpoints storing nodes Catchpoints = "catchpointStoring" // Gossip nodes are non permissioned relays Gossip = "gossip" )
const AlgorandWsProtocol = "/algorand-ws/1.0.0"
AlgorandWsProtocol defines a libp2p protocol name for algorand's websockets messages
const DefaultPrivKeyPath = "peerIDPrivKey.key"
DefaultPrivKeyPath is the default path inside the node's root directory at which the private key for p2p identity is found and persisted to when a new one is generated.
const TXTopicName = "algotx01"
TXTopicName defines a pubsub topic for TX messages There is a micro optimization for const string comparison: 8 bytes const string require a single x86-64 CMPQ instruction. Naming convention: "algo" + 2 bytes protocol tag + 2 bytes version
Variables ¶
var ErrInvalidLogLevel = errors.New("invalid log level")
ErrInvalidLogLevel is returned when an invalid log level is provided.
Functions ¶
func EnableP2PLogging ¶
EnableP2PLogging enables libp2p logging into the provided logger with the provided level.
func GetPeerTelemetryInfo ¶
func GetPeerTelemetryInfo(peerProtocols []protocol.ID) (telemetryID string, telemetryInstance string)
GetPeerTelemetryInfo returns the telemetry ID of a peer by looking at its protocols
func GetPrivKey ¶
GetPrivKey manages loading and creation of private keys for network PeerIDs It prioritizes, in this order:
- user supplied path to privKey
- default path to privKey,
- generating a new privKey.
If a new privKey is generated it will be saved to default path if cfg.P2PPersistPeerID.
func MakeHost ¶
func MakeHost(cfg config.Local, datadir string, pstore *pstore.PeerStore) (host.Host, string, error)
MakeHost creates a libp2p host but does not start listening. Use host.Network().Listen() on the returned address to start listening.
func MakeService ¶
func MakeService(ctx context.Context, log logging.Logger, cfg config.Local, h host.Host, listenAddr string, wsStreamHandler StreamHandler, metricsTracer pubsub.RawTracer) (*serviceImpl, error)
MakeService creates a P2P service instance
func MakeTestHTTPClient ¶
MakeTestHTTPClient creates a http.Client that uses libp2p transport for a given protocol and peer address. This exported method is only used in tests.
func SetP2PLogLevel ¶
SetP2PLogLevel sets the log level for libp2p logging.
Types ¶
type CapabilitiesDiscovery ¶
type CapabilitiesDiscovery struct {
// contains filtered or unexported fields
}
CapabilitiesDiscovery exposes Discovery interfaces and wraps underlying DHT methods to provide capabilities advertisement for the node
func MakeCapabilitiesDiscovery ¶
func MakeCapabilitiesDiscovery(ctx context.Context, cfg config.Local, h host.Host, networkID protocol.NetworkID, log logging.Logger, bootstrapFunc func() []peer.AddrInfo) (*CapabilitiesDiscovery, error)
MakeCapabilitiesDiscovery creates a new CapabilitiesDiscovery object which exposes peer discovery and capabilities advertisement
func (*CapabilitiesDiscovery) AdvertiseCapabilities ¶
func (c *CapabilitiesDiscovery) AdvertiseCapabilities(capabilities ...Capability)
AdvertiseCapabilities periodically runs the Advertiser interface on the DHT If a capability fails to advertise we will retry every 10 seconds until full success This gets rerun every at the minimum ttl or the maxAdvertisementInterval.
func (*CapabilitiesDiscovery) Close ¶
func (c *CapabilitiesDiscovery) Close() error
Close should be called when fully shutting down the node
func (*CapabilitiesDiscovery) Host ¶
func (c *CapabilitiesDiscovery) Host() host.Host
Host exposes the underlying libp2p host.Host object
func (*CapabilitiesDiscovery) PeersForCapability ¶
func (c *CapabilitiesDiscovery) PeersForCapability(capability Capability, n int) ([]peer.AddrInfo, error)
PeersForCapability returns a slice of peer.AddrInfo for a Capability Since CapabilitiesDiscovery uses a backoffcache, it will attempt to hit cache, then disk, then network in order to fetch n peers which are advertising the required capability.
func (*CapabilitiesDiscovery) RoutingTable ¶
func (c *CapabilitiesDiscovery) RoutingTable() Sizer
RoutingTable exposes some knowledge about the DHT routing table
type Capability ¶
type Capability string
Capability represents functions that some nodes may provide and other nodes would want to know about
type HTTPServer ¶
type HTTPServer struct { libp2phttp.Host // contains filtered or unexported fields }
HTTPServer is a wrapper around libp2phttp.Host that allows registering http handlers with path parameters.
func MakeHTTPServer ¶
func MakeHTTPServer(streamHost host.Host) *HTTPServer
MakeHTTPServer creates a new HTTPServer
func (*HTTPServer) RegisterHTTPHandler ¶
func (s *HTTPServer) RegisterHTTPHandler(path string, handler http.Handler)
RegisterHTTPHandler registers a http handler with a given path.
func (*HTTPServer) RegisterHTTPHandlerFunc ¶
func (s *HTTPServer) RegisterHTTPHandlerFunc(path string, handler func(http.ResponseWriter, *http.Request))
RegisterHTTPHandlerFunc registers a http handler with a given path.
type PeerID ¶
type PeerID string
PeerID is a string representation of a peer's public key, primarily used to avoid importing libp2p into packages that shouldn't need it
func PeerIDFromPublicKey ¶
PeerIDFromPublicKey returns a PeerID from a public key, thin wrapper over libp2p function doing the same
type PeerIDChallengeSigner ¶
type PeerIDChallengeSigner struct {
// contains filtered or unexported fields
}
PeerIDChallengeSigner implements the identityChallengeSigner interface in the network package.
func (*PeerIDChallengeSigner) PublicKey ¶
func (p *PeerIDChallengeSigner) PublicKey() algocrypto.PublicKey
PublicKey implements the identityChallengeSigner interface.
func (*PeerIDChallengeSigner) Sign ¶
func (p *PeerIDChallengeSigner) Sign(message algocrypto.Hashable) algocrypto.Signature
Sign implements the identityChallengeSigner interface.
func (*PeerIDChallengeSigner) SignBytes ¶
func (p *PeerIDChallengeSigner) SignBytes(message []byte) algocrypto.Signature
SignBytes implements the identityChallengeSigner interface.
type Service ¶
type Service interface { Start() error Close() error ID() peer.ID // return peer.ID for self IDSigner() *PeerIDChallengeSigner AddrInfo() peer.AddrInfo // return addrInfo for self DialPeersUntilTargetCount(targetConnCount int) ClosePeer(peer.ID) error Conns() []network.Conn ListPeersForTopic(topic string) []peer.ID Subscribe(topic string, val pubsub.ValidatorEx) (SubNextCancellable, error) Publish(ctx context.Context, topic string, data []byte) error // GetHTTPClient returns a rate-limiting libp2p-streaming http client that can be used to make requests to the given peer GetHTTPClient(addrInfo *peer.AddrInfo, connTimeStore limitcaller.ConnectionTimeStore, queueingTimeout time.Duration) (*http.Client, error) }
Service defines the interface used by the network integrating with underlying p2p implementation
type StreamHandler ¶
StreamHandler is called when a new bidirectional stream for a given protocol and peer is opened.