network

package
v0.0.0-...-724b7ff Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package discovery provides functionalities to discover peers in a libp2p network using a Distributed Hash Table (DHT) and mDNS.

Package discovery provides functionality for peer discovery in a libp2p network.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanUpPeers

func CleanUpPeers(ctx context.Context, host host.Host, cfg *config.Config)

FIXME: This function does not work as intended. It should remove peers from the peerstore if they are unreachable.

func FilterOutPrivateAddrs

func FilterOutPrivateAddrs(addrs []ma.Multiaddr) []ma.Multiaddr

FilterOutPrivateAddrs filters out private IP addresses from a list of multiaddresses.

func GeneratePacket

func GeneratePacket(hostID peer.ID) []byte

func NATDiscovery

func NATDiscovery(log *ipfsLog.ZapEventLogger) bool

func NewPeerSource

func NewPeerSource(log *ipfsLog.ZapEventLogger, hostGetter func() host.Host) autorelay.PeerSource

func Ping

func Ping(ctx context.Context, host host.Host, randomInterval int64)

Types

type DHT

type DHT struct {
	BootstrapNode             bool                  // Indicates if the node is a bootstrap node.
	RendezvousString          string                // Used for identifying peers in the network.
	BootstrapPeers            []multiaddr.Multiaddr // List of initial peers to connect to.
	DiscorveryRefreshInterval time.Duration         // Interval to refresh discovery.
	IgnoredPeers              map[peer.ID]bool      // Set of peers to ignore during discovery.
	*dht.IpfsDHT                                    // Embedded IPFS DHT instance.
}

DHT encapsulates the functionalities of a Distributed Hash Table for peer discovery in a libp2p network.

func NewDHTDiscovery

func NewDHTDiscovery(bootstrapNode bool, rendezvousString string, bootstrapPeers []multiaddr.Multiaddr, discoveryRefreshInterval time.Duration) *DHT

func (*DHT) Run

func (d *DHT) Run(ctx context.Context, host host.Host) error

Run starts the DHT functionality of the node. It initializes the DHT, connects to bootstrap peers if necessary, and sets up continuous discovery of new peers.

type MDNS

type MDNS struct {
	Rendezvous string // Rendezvous string used to identify peers in the mDNS service.
}

MDNS struct encapsulates the parameters for mDNS-based peer discovery.

func NewMDNSDiscovery

func NewMDNSDiscovery(rendezvous string) *MDNS

NewMDNSDiscovery creates a new MDNS discovery instance with the specified rendezvous string.

func (*MDNS) Run

func (m *MDNS) Run(host host.Host) error

Run starts the mDNS discovery service with the configured parameters. It initializes and starts an mDNS service for peer discovery within the local network.

type Packet

type Packet struct {
	ID        uuid.UUID `json:"id"`
	EmittedBy peer.ID   `json:"emittedBy"`
	Timestamp int64     `json:"timestamp"`
}

Jump to

Keyboard shortcuts

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