Documentation
¶
Overview ¶
Package p2p provides types and interfaces for a peer-to-peer networking simulation.
Index ¶
- func BinomialRandom(n int, p float64) int
- func ExponentialRandom(lambda float64) float64
- func LogNormalRand(mu, sigma float64) float64
- func NormalRandom(mu, sigma float64) float64
- func ParetoRandom(xm, alpha float64) float64
- func PoissonRandom(lambda float64) int
- func UniformRandom(a, b float64) float64
- type BroadcastProtocol
- type Config
- type CustomProtocolFunc
- type Message
- type P2P
- func (p *P2P) FirstMessageReceptionTimes(msg string) []time.Time
- func (p *P2P) MessageInfo(nodeID PeerID, content string) (map[string]any, error)
- func (p *P2P) NumberOfDuplicateMessages(msg string) int
- func (p *P2P) PeerIDs() []PeerID
- func (p *P2P) Publish(nodeID PeerID, msg string, protocol BroadcastProtocol, ...) error
- func (p *P2P) Reachability(msg string) float64
- func (p *P2P) SimulateP2P(ctx context.Context)
- type PeerID
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BinomialRandom ¶ added in v0.8.3
Binomial(n, p): discrete distribution.
func ExponentialRandom ¶ added in v0.8.3
Exponential(λ): continuous distribution.
func LogNormalRand ¶
LogNormal(μ, σ): continuous distribution.
func NormalRandom ¶ added in v0.8.3
Normal(μ, σ): Box-Muller transform.
func ParetoRandom ¶ added in v0.8.3
Pareto(xm, α): continuous heavy-tailed distribution.
func PoissonRandom ¶ added in v0.8.3
Poisson(λ): discrete distribution.
func UniformRandom ¶ added in v0.8.3
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 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
FirstMessageReceptionTimes returns the first reception times of the specified message across all nodes.
func (*P2P) MessageInfo ¶ added in v0.9.0
MessageInfo returns a snapshot of the node's message-related information.
func (*P2P) NumberOfDuplicateMessages ¶ added in v0.9.0
NumberOfDuplicateMessages counts how many duplicate messages were received across all nodes.
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
Reachability calculates the fraction of nodes that have received the specified message.
func (*P2P) SimulateP2P ¶ added in v0.9.0
SimulateP2P starts the message handling routines for all nodes in the network.