network

package
v0.0.0-...-904bf0a Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2025 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToAddrInfos

func ToAddrInfos(addrs []string) ([]peer.AddrInfo, error)

func ToMultiaddrs

func ToMultiaddrs(addr []string) ([]multiaddr.Multiaddr, error)

Types

type Config

type Config struct {
	ProtocolID  string
	MaxPayload  uint64
	Timeout     time.Duration
	ListenAddrs []string
	UseTLS      bool
	UseNoise    bool

	// Ask router via UPnP/NAT-PMP/PCP to map inbound ports.
	// Use on home/office public IPv4; ineffective under CGNAT/double NAT.
	NATPortMap bool

	// Enable DCUtR to form direct connections through NATs.
	// Best with relay candidates; helpful when port mapping fails.
	HolePunching bool

	// Fixed relay candidates for AutoRelay v2 (/p2p-circuit).
	// Use behind CGNAT/strict NAT for predictable reachability.
	StaticRelays []string

	// Dynamic supplier of relay candidates when StaticRelays is empty.
	// AutoRelay requests up to numPeers; send then close the channel.
	PeerSource autorelay.PeerSource

	// Run THIS node as a public relay (HOP).
	// Use on well-connected/public hosts; clients usually keep OFF.
	RelayService bool
}

type HostWrapper

type HostWrapper struct {
	host.Host
	// contains filtered or unexported fields
}

func New

func New(cfg *Config) (*HostWrapper, error)

func (*HostWrapper) Close

func (n *HostWrapper) Close() error

func (*HostWrapper) ConnectToPeer

func (n *HostWrapper) ConnectToPeer(ctx context.Context, addrs ...multiaddr.Multiaddr) error

func (*HostWrapper) GetFullAddresses

func (n *HostWrapper) GetFullAddresses() []multiaddr.Multiaddr

func (*HostWrapper) GetMetrics

func (n *HostWrapper) GetMetrics() metrics.MetricsSnapshot

GetMetrics returns the current metrics for this network wrapper

func (*HostWrapper) Peers

func (n *HostWrapper) Peers() []peer.ID

func (*HostWrapper) Receive

func (n *HostWrapper) Receive(ctx context.Context, want cid.Cid) (peer.ID, []byte, error)

Receive blocks until a message whose CID == want arrives. Returns (fromPeer, payload, error).

func (*HostWrapper) Send

func (n *HostWrapper) Send(ctx context.Context, to peer.ID, payload []byte) (cid.Cid, error)

Jump to

Keyboard shortcuts

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