package identify
import "github.com/libp2p/go-libp2p/p2p/protocol/identify"
Index ¶
- Constants
- Variables
- func HasConsistentTransport(a ma.Multiaddr, green []ma.Multiaddr) bool
- func NewIDService(h host.Host, opts ...Option) (*idService, error)
- type IDService
- type MetricsTracer
- type MetricsTracerOption
- type ObservedAddrManager
- func NewObservedAddrManager(listenAddrs, hostAddrs func() []ma.Multiaddr, interfaceListenAddrs func() ([]ma.Multiaddr, error), normalize func(ma.Multiaddr) ma.Multiaddr) (*ObservedAddrManager, error)
- func (o *ObservedAddrManager) Addrs() []ma.Multiaddr
- func (o *ObservedAddrManager) AddrsFor(addr ma.Multiaddr) (addrs []ma.Multiaddr)
- func (o *ObservedAddrManager) Close() error
- func (o *ObservedAddrManager) Record(conn connMultiaddrs, observed ma.Multiaddr)
- type Option
Constants ¶
const ( // ID is the protocol.ID of version 1.0.0 of the identify service. ID = "/ipfs/id/1.0.0" // IDPush is the protocol.ID of the Identify push protocol. // It sends full identify messages containing the current state of the peer. IDPush = "/ipfs/id/push/1.0.0" // DefaultTimeout for all id interactions, incoming / outgoing, id / id-push. DefaultTimeout = 5 * time.Second // ServiceName is the default identify service name ServiceName = "libp2p.identify" )
Variables ¶
var ActivationThresh = 4
ActivationThresh sets how many times an address must be seen as "activated" and therefore advertised to other peers as an address that the local peer can be contacted on. The "seen" events expire by default after 40 minutes (OwnObservedAddressTTL * ActivationThreshold). The are cleaned up during the GC rounds set by GCInterval.
Functions ¶
func HasConsistentTransport ¶
HasConsistentTransport returns true if the address 'a' shares a protocol set with any address in the green set. This is used to check if a given address might be one of the addresses a peer is listening on.
func NewIDService ¶
NewIDService constructs a new *idService and activates it by attaching its stream handler to the given host.Host.
Types ¶
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{} // OwnObservedAddrs returns the addresses peers have reported we've dialed from OwnObservedAddrs() []ma.Multiaddr // ObservedAddrsFor returns the addresses peers have reported we've dialed from, // for a specific local address. ObservedAddrsFor(local ma.Multiaddr) []ma.Multiaddr Start() io.Closer }
type MetricsTracer ¶
type MetricsTracer interface { // TriggeredPushes counts IdentifyPushes triggered by event TriggeredPushes(event any) // ConnPushSupport counts peers by Push Support ConnPushSupport(identifyPushSupport) // IdentifyReceived tracks metrics on receiving an identify response IdentifyReceived(isPush bool, numProtocols int, numAddrs int) // IdentifySent tracks metrics on sending an identify response IdentifySent(isPush bool, numProtocols int, numAddrs int) }
func NewMetricsTracer ¶
func NewMetricsTracer(opts ...MetricsTracerOption) MetricsTracer
type MetricsTracerOption ¶
type MetricsTracerOption func(*metricsTracerSetting)
func WithRegisterer ¶
func WithRegisterer(reg prometheus.Registerer) MetricsTracerOption
type ObservedAddrManager ¶
type ObservedAddrManager struct {
// contains filtered or unexported fields
}
ObservedAddrManager maps connection's local multiaddrs to their externally observable multiaddress
func NewObservedAddrManager ¶
func NewObservedAddrManager(listenAddrs, hostAddrs func() []ma.Multiaddr, interfaceListenAddrs func() ([]ma.Multiaddr, error), normalize func(ma.Multiaddr) ma.Multiaddr) (*ObservedAddrManager, error)
NewObservedAddrManager returns a new address manager using peerstore.OwnObservedAddressTTL as the TTL.
func (*ObservedAddrManager) Addrs ¶
func (o *ObservedAddrManager) Addrs() []ma.Multiaddr
Addrs return all activated observed addresses
func (*ObservedAddrManager) AddrsFor ¶
func (o *ObservedAddrManager) AddrsFor(addr ma.Multiaddr) (addrs []ma.Multiaddr)
AddrsFor return all activated observed addresses associated with the given (resolved) listen address.
func (*ObservedAddrManager) Close ¶
func (o *ObservedAddrManager) Close() error
func (*ObservedAddrManager) Record ¶
func (o *ObservedAddrManager) Record(conn connMultiaddrs, observed ma.Multiaddr)
Record enqueues an observation for recording
type Option ¶
type Option func(*config)
Option is an option function for identify.
func DisableObservedAddrManager ¶
func DisableObservedAddrManager() Option
DisableObservedAddrManager disables the observed address manager. It also effectively disables the nat emitter and EvtNATDeviceTypeChanged
func DisableSignedPeerRecord ¶
func DisableSignedPeerRecord() Option
DisableSignedPeerRecord disables populating signed peer records on the outgoing Identify response and ONLY sends the unsigned addresses.
func ProtocolVersion ¶
ProtocolVersion sets the protocol version string that will be used to identify the family of protocols used by the peer.
func UserAgent ¶
UserAgent sets the user agent this node will identify itself with to peers.
func WithMetricsTracer ¶
func WithMetricsTracer(tr MetricsTracer) Option
func WithTimeout ¶
WithTimeout sets the timeout for identify interactions.
Source Files ¶
id.go metrics.go nat_emitter.go obsaddr.go opts.go
Directories ¶
Path | Synopsis |
---|---|
p2p/protocol/identify/internal | |
p2p/protocol/identify/pb |
- Version
- v0.42.0 (latest)
- Published
- Jun 18, 2025
- Platform
- linux/amd64
- Imports
- 31 packages
- Last checked
- 4 weeks ago –
Tools for package owners.