p2p

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateNetwork

func GenerateNetwork(g *graph.Graph, nodeLatency, edgeLatency func() float64) (map[ID]*Node, error)

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

func LogNormalRand

func LogNormalRand(mu, sigma float64, src rand.Source) float64

LogNormalRand generates a log-normally distributed random number with given mu and sigma parameters.

func Publish

func Publish(node *Node, msg string)

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

func RunNetworkSimulation

func RunNetworkSimulation(nodes map[ID]*Node)

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

Types

type Edge

type Edge struct {
	TargetID ID
	Latency  float64 // in milliseconds
}

Edge represents a connection from one node to another in the P2P network.

type ID

type ID uint64

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

type Message

type Message struct {
	From    ID
	Content string
}

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

type Node

type Node struct {
	ID      ID
	Latency float64
	Edges   map[ID]Edge

	RecvFrom map[string]map[ID]struct{} // content -> set of senders
	SentTo   map[string]map[ID]struct{} // content -> set of targets
	SeenAt   map[string]time.Time       // content -> first arrival time
	// contains filtered or unexported fields
}

Node represents a node in the P2P network.

func (*Node) Degree

func (n *Node) Degree() int

Degree returns the number of edges connected to the node.

Jump to

Keyboard shortcuts

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