p2p

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package p2p provides types and interfaces for a peer-to-peer networking simulation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BinomialRandom added in v0.8.3

func BinomialRandom(n int, p float64) int

Binomial(n, p): discrete distribution.

func ExponentialRandom added in v0.8.3

func ExponentialRandom(lambda float64) float64

Exponential(λ): continuous distribution.

func LogNormalRand

func LogNormalRand(mu, sigma float64) float64

LogNormal(μ, σ): continuous distribution.

func NormalRandom added in v0.8.3

func NormalRandom(mu, sigma float64) float64

Normal(μ, σ): Box-Muller transform.

func ParetoRandom added in v0.8.3

func ParetoRandom(xm, alpha float64) float64

Pareto(xm, α): continuous heavy-tailed distribution.

func PoissonRandom added in v0.8.3

func PoissonRandom(lambda float64) int

Poisson(λ): discrete distribution.

func UniformRandom added in v0.8.3

func UniformRandom(a, b float64) float64

Uniform(a, b): continuous distribution.

Types

type BroadcastProtocol added in v0.7.3

type BroadcastProtocol int

BroadcastProtocol defines the protocol used for broadcasting messages in the P2P network.

const (
	Flooding BroadcastProtocol = iota
	Gossiping
	Custom
)

type Config added in v0.7.3

type Config struct {
	GossipFactor float64        // fraction of neighbors to gossip to
	CustomParams map[string]any // parameters for custom protocols
}

Config holds configuration parameters for the P2P network.

type CustomProtocolFunc added in v0.9.0

type CustomProtocolFunc func(msg Message, neighbours []PeerID, sentPeers []PeerID, receivedPeers []PeerID, customParams map[string]any) *[]PeerID

type Message

type Message struct {
	From           PeerID
	Content        string
	Protocol       BroadcastProtocol
	HopCount       int
	CustomProtocol CustomProtocolFunc
}

Message represents a message sent between nodes in the P2P network.

type P2P added in v0.9.0

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

Config holds configuration parameters for the P2P network.

func GenerateP2P added in v0.9.0

func GenerateP2P(g *graph.Graph, nodeLatency, edgeLatency func() float64, cfg *Config) (*P2P, error)

GenerateP2P creates a P2P network from the given graph. nodeLatency and edgeLatency are functions that generate latencies for nodes and edges respectively.

func (*P2P) FirstMessageReceptionTimes added in v0.9.0

func (p *P2P) FirstMessageReceptionTimes(msg string) []time.Time

FirstMessageReceptionTimes returns the first reception times of the specified message across all nodes.

func (*P2P) MessageInfo added in v0.9.0

func (p *P2P) MessageInfo(nodeID PeerID, content string) (map[string]any, error)

MessageInfo returns a snapshot of the node's message-related information.

func (*P2P) NumberOfDuplicateMessages added in v0.9.0

func (p *P2P) NumberOfDuplicateMessages(msg string) int

NumberOfDuplicateMessages counts how many duplicate messages were received across all nodes.

func (*P2P) PeerIDs added in v0.9.0

func (p *P2P) PeerIDs() []PeerID

PeerIDs returns a slice of all node IDs in the network.

func (*P2P) Publish added in v0.9.0

func (p *P2P) Publish(nodeID PeerID, msg string, protocol BroadcastProtocol, customProtocol CustomProtocolFunc) error

Publish sends a message to the specified node's message queue.

func (*P2P) Reachability added in v0.9.0

func (p *P2P) Reachability(msg string) float64

Reachability calculates the fraction of nodes that have received the specified message.

func (*P2P) SimulateP2P added in v0.9.0

func (p *P2P) SimulateP2P(ctx context.Context)

SimulateP2P starts the message handling routines for all nodes in the network.

type PeerID added in v0.8.1

type PeerID uint64

PeerID represents a unique identifier for a node in the P2P network.

Jump to

Keyboard shortcuts

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