p2p

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 20, 2026 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultBootstrapPeers = []string{
	"/dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN",
	"/dnsaddr/bootstrap.libp2p.io/p2p/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa",
	"/dnsaddr/bootstrap.libp2p.io/p2p/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb",
	"/dnsaddr/bootstrap.libp2p.io/p2p/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt",
	"/ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
	"/ip4/104.131.131.82/udp/4001/quic/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
}

DefaultBootstrapPeers are the default IPFS bootstrap nodes

Functions

This section is empty.

Types

type Host

type Host struct {
	// contains filtered or unexported fields
}

Host wraps libp2p host

func NewHost

func NewHost(ctx context.Context, config *HostConfig, logger types.Logger) (*Host, error)

NewHost creates a new P2P host

func (*Host) Addrs

func (h *Host) Addrs() []string

Addrs returns the host's listening addresses

func (*Host) Close

func (h *Host) Close() error

Close shuts down the host

func (*Host) Connect

func (h *Host) Connect(ctx context.Context, addr string) error

Connect establishes a connection to a peer

func (*Host) DHT added in v0.3.0

func (h *Host) DHT() *dht.IpfsDHT

DHT returns the DHT routing table (may be nil if DHT is disabled)

func (*Host) EnableMDNS

func (h *Host) EnableMDNS(ctx context.Context) error

EnableMDNS enables mDNS discovery

func (*Host) GetNetworkStats added in v0.3.0

func (h *Host) GetNetworkStats() NetworkStats

GetNetworkStats returns current network statistics

func (*Host) ID

func (h *Host) ID() string

ID returns the host's peer ID

func (*Host) LibP2PHost added in v0.3.0

func (h *Host) LibP2PHost() host.Host

LibP2PHost returns the underlying libp2p host for advanced usage

func (*Host) NewStream

func (h *Host) NewStream(ctx context.Context, peerID string, protocolID string) (types.Stream, error)

NewStream creates a new stream to a peer

func (*Host) Peers

func (h *Host) Peers() []PeerInfo

Peers returns a list of connected peers

func (*Host) SetStreamHandler

func (h *Host) SetStreamHandler(protocolID string, handler types.StreamHandler)

SetStreamHandler registers a handler for incoming streams

func (*Host) StartDiagnosticLogging added in v0.3.0

func (h *Host) StartDiagnosticLogging(ctx context.Context, interval time.Duration)

StartDiagnosticLogging starts periodic logging of network status

type HostConfig

type HostConfig struct {
	// ListenAddrs are the multiaddrs to listen on
	ListenAddrs []string

	// PSK is the pre-shared key for private network (hex-encoded)
	PSK string

	// EnableAuth enables PSK authentication
	EnableAuth bool

	// TrustedPeers are peer IDs allowed to connect (if non-empty)
	TrustedPeers []string

	// BootstrapPeers are initial peers to connect to
	BootstrapPeers []string

	// DisableDHT disables Distributed Hash Table for peer discovery
	DisableDHT bool

	// DHTMode is the DHT mode: "client" or "server" (default: "server")
	DHTMode string

	// DisableNATService disables NAT traversal service
	DisableNATService bool

	// DisableAutoRelay disables automatic relay for NAT traversal
	DisableAutoRelay bool

	// DisableHolePunching disables hole punching for direct connections
	DisableHolePunching bool

	// DisableRelayService disables this node from acting as a relay server
	DisableRelayService bool

	// StaticRelays are static relay addresses for NAT traversal
	// If provided, these will be used instead of DHT-based relay discovery
	StaticRelays []string
}

HostConfig contains configuration for creating a P2P host

type NetworkStats added in v0.3.0

type NetworkStats struct {
	ConnectedPeers  int
	DHTRoutingTable int
	DHTMode         string
}

NetworkStats contains network diagnostic information

type PeerInfo

type PeerInfo struct {
	ID    string
	Addrs []string
}

PeerInfo contains information about a peer

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址