network

package
v0.0.0-...-df8f024 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const ChatProtocolID = "/desvault/chat/1.0.0"

Variables

This section is empty.

Functions

func GetConnectedPeers

func GetConnectedPeers() []string

GetConnectedPeers returns a slice of connected peer IDs.

func GetNodePeerID

func GetNodePeerID() string

GetNodePeerID returns the node's peer ID.

func MonitorNetwork

func MonitorNetwork(h host.Host)

MonitorNetwork continuously monitors network connectivity and logs the current number of connected peers.

func RegisterNode

func RegisterNode(h host.Host, config *setup.Config) error

RegisterNode registers the node on the network using the provided production configuration. This implementation performs an HTTP POST to a registration service endpoint. The endpoint is defined here as a default constant, but you can modify this to read from configuration.

func SendMessage

func SendMessage(peerID string, msg string) error

SendMessage sends a chat message to the specified peer.

func SetGlobalAutoDiscoveryService

func SetGlobalAutoDiscoveryService(ads *AutoDiscoveryService)

SetGlobalAutoDiscoveryService stores the global AutoDiscoveryService instance.

Types

type AutoDiscoveryService

type AutoDiscoveryService struct {
	Host   host.Host
	DHT    *dht.IpfsDHT
	PubSub *pubsub.PubSub
}

AutoDiscoveryService encapsulates the libp2p host, DHT instance, and PubSub.

func InitializeNode

func InitializeNode(ctx context.Context) (*AutoDiscoveryService, error)

InitializeNode creates a libp2p host with a DHT and PubSub instance, sets up mDNS discovery, and a stream handler for chat messages. It returns an AutoDiscoveryService.

func (*AutoDiscoveryService) AnnounceStorage

func (s *AutoDiscoveryService) AnnounceStorage(storageGB int) error

AnnounceStorage publishes the node's storage contribution to the network using PubSub.

func (*AutoDiscoveryService) Start

func (s *AutoDiscoveryService) Start(ctx context.Context)

Start initializes mDNS discovery, bootstraps the DHT, and starts the mDNS service.

type Notifee

type Notifee struct {
	Host host.Host
}

Notifee implements the mdns.Notifee interface for mDNS discovery.

func (*Notifee) HandlePeerFound

func (n *Notifee) HandlePeerFound(pi peer.AddrInfo)

HandlePeerFound is invoked when a peer is discovered via mDNS.

Jump to

Keyboard shortcuts

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