p2p

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: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BroadcastDiscovery

func BroadcastDiscovery() error

BroadcastDiscovery sends a UDP broadcast message to announce this node's presence.

func DetectOfflineNodes

func DetectOfflineNodes(activeNodes map[string]bool, shardMap map[string][]Shard)

Check if a node storing shards is offline

func DiscoverPeers

func DiscoverPeers(timeout time.Duration) ([]string, error)

DiscoverPeers performs UDP-based peer discovery by broadcasting a message and then listening for responses.

func DistributeShards

func DistributeShards(fileID string, fileData []byte, nodes []string) map[string][]Shard

Function to distribute shards across nodes

func ListenForPeers

func ListenForPeers(timeout time.Duration) ([]string, error)

ListenForPeers listens on UDP for incoming discovery messages for the specified timeout.

func RedistributeShards

func RedistributeShards(shards []Shard, activeNodes map[string]bool)

Redistribute lost shards to active nodes

func SetupDHT

func SetupDHT(ctx context.Context) (host.Host, *dht.IpfsDHT, error)

SetupDHT creates a new libp2p host and initializes a Kademlia DHT instance. It returns the host, the DHT, and an error (if any).

func StartLibp2pDiscovery

func StartLibp2pDiscovery() (host.Host, *dht.IpfsDHT, error)

StartLibp2pDiscovery initializes a libp2p host, sets up DHT and mDNS discovery, and waits up to 30 seconds for peers. If no peers are found, the node becomes the seed.

Types

type SecureChannel

type SecureChannel struct {
	SendCipher *noise.CipherState
	RecvCipher *noise.CipherState
}

SecureChannel holds the cipher states for sending and receiving encrypted messages.

func PerformHandshakeInitiator

func PerformHandshakeInitiator(conn io.ReadWriter, payload []byte) (*SecureChannel, error)

PerformHandshakeInitiator performs a complete Noise XX handshake as the initiator over the provided connection. It exchanges three handshake messages and returns a SecureChannel containing the cipher states for secure communication.

func PerformHandshakeResponder

func PerformHandshakeResponder(conn io.ReadWriter, payload []byte) (*SecureChannel, error)

PerformHandshakeResponder performs a complete Noise XX handshake as the responder over the provided connection. It processes the initiator's messages, responds accordingly, and returns a SecureChannel with the cipher states.

type Shard

type Shard struct {
	ID      string
	Data    []byte
	Replica int
}

Structure to hold shard info

func SplitFileIntoShards

func SplitFileIntoShards(data []byte, numShards int) []Shard

Function to split file into 5 shards

Jump to

Keyboard shortcuts

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