libp2p

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 46 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromBootstrapPeerAddrInfos

func FromBootstrapPeerAddrInfos(bootstrapPeerAddrInfos []BootstrapPeerAddrInfo) ([]peer.AddrInfo, error)

Types

type BootstrapPeerAddrInfo

type BootstrapPeerAddrInfo struct {
	ID    string   `json:"ID"`
	Addrs []string `json:"Addrs"`
}

BootstrapPeerAddrInfo mirrors libp2p's peer.AddrInfo JSON shape but allows the ID to be omitted or empty. libp2p's peer.AddrInfo.UnmarshalJSON rejects an empty ID, so we unmarshal into this struct and convert via fromBootstrapPeerAddrInfos.

type Bootstrapper

type Bootstrapper interface {
	// Get returns a list of peers that should be used as bootstrap nodes.
	// If the peer ID is empty it will be resolved.
	// If the address is missing a port the P2P router port will be used.
	Get(ctx context.Context) ([]peer.AddrInfo, error)
}

Bootstrapper resolves peers to bootstrap with for the P2P router.

type DNSBootstrapper

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

func NewDNSBootstrapper

func NewDNSBootstrapper(host string) *DNSBootstrapper

func (*DNSBootstrapper) Get

func (b *DNSBootstrapper) Get(ctx context.Context) ([]peer.AddrInfo, error)

type HTTPBootstrapper

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

HTTPBootstrapper resolves bootstrap peers over HTTP.

func NewHTTPBootstrapper

func NewHTTPBootstrapper(bootstrapURL url.URL, pool *x509.CertPool, cert *tls.Certificate) (*HTTPBootstrapper, error)

NewHTTPBootstrapper creates an HTTP bootstrapper.

func (*HTTPBootstrapper) Get

func (bs *HTTPBootstrapper) Get(ctx context.Context) ([]peer.AddrInfo, error)

type LookupResult

type LookupResult struct {
	Peer     routing.Peer
	Duration time.Duration
}

type Router

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

func NewRouter

func NewRouter(ctx context.Context, addr string, bs Bootstrapper, peerMetadata routing.PeerMetadata, opts ...RouterOption) (*Router, error)

func (*Router) Advertise

func (r *Router) Advertise(ctx context.Context, keys []string) error

func (*Router) Host

func (r *Router) Host() host.Host

func (*Router) ListPeers

func (r *Router) ListPeers() ([]routing.Peer, error)

func (*Router) LocalAddresses

func (r *Router) LocalAddresses() ([]netip.Addr, error)

func (*Router) Lookup

func (r *Router) Lookup(ctx context.Context, key string, count int) (*routing.Iterator, error)

func (*Router) Measure

func (r *Router) Measure(ctx context.Context, key string) ([]LookupResult, error)

Measure returns a list of time results containing the time it took to find each peer.

func (*Router) Ready

func (r *Router) Ready(ctx context.Context) (bool, error)

func (*Router) Run

func (r *Router) Run(ctx context.Context) error

func (*Router) Withdraw

func (r *Router) Withdraw(ctx context.Context, keys []string) error

type RouterConfig

type RouterConfig struct {
	DataDir           string
	Libp2pOpts        []libp2p.Option
	AdvertiseTTL      time.Duration
	MaxReprovideDelay time.Duration
}

type RouterOption

type RouterOption = option.Option[RouterConfig]

func WithAdvertiseTTL

func WithAdvertiseTTL(ttl time.Duration) RouterOption

func WithDataDir

func WithDataDir(dataDir string) RouterOption

func WithLibP2POptions

func WithLibP2POptions(opts ...libp2p.Option) RouterOption

func WithMaxReprovideDelay

func WithMaxReprovideDelay(delay time.Duration) RouterOption

type StaticBootstrapper

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

func NewStaticBootstrapper

func NewStaticBootstrapper(peers []peer.AddrInfo) *StaticBootstrapper

func NewStaticBootstrapperFromStrings

func NewStaticBootstrapperFromStrings(peerStrs []string) (*StaticBootstrapper, error)

func (*StaticBootstrapper) Add

func (b *StaticBootstrapper) Add(peer peer.AddrInfo)

func (*StaticBootstrapper) Get

Jump to

Keyboard shortcuts

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