nettest

package
v0.0.0-...-e07b07e Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0, MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LinearTopology

func LinearTopology(n int, clk clock.Clock) (*Topology, []*Peer, error)

LinearTopology creates a network topology consisting of n nodes peered in a linear chain. The nodes are configured with routing tables that contain immediate neighbours. It returns the topology and the nodes ordered such that nodes[x] has nodes[x-1] and nodes[x+1] in its routing table The topology is not a ring: nodes[0] only has nodes[1] in its table and nodes[n-1] only has nodes[n-2] in its table. nodes[1] has nodes[0] and nodes[2] in its routing table. If n > 2 then the first and last nodes will not have one another in their routing tables.

func NewPeerID

func NewPeerID() (kadt.PeerID, error)

Types

type DefaultLink struct{}

DefaultLink is the default link used if none is specified. It has zero latency and always succeeds.

func (*DefaultLink) ConnLatency

func (l *DefaultLink) ConnLatency() time.Duration

func (*DefaultLink) DialErr

func (l *DefaultLink) DialErr() error

func (*DefaultLink) DialLatency

func (l *DefaultLink) DialLatency() time.Duration
type Link interface {
	ConnLatency() time.Duration // the simulated time taken to return an error or successful outcome
	DialLatency() time.Duration // the simulated time taken to connect to a node
	DialErr() error             // an error that should be returned on dial, nil if the dial is successful
}

Link represents the route between two nodes. It allows latency and transport failures to be simulated.

type Peer

type Peer struct {
	NodeID       kadt.PeerID
	Router       *Router
	RoutingTable routing.RoutingTableCpl[kadt.Key, kadt.PeerID]
}

type Router

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

func NewRouter

func NewRouter(self kadt.PeerID, top *Topology) *Router

func (*Router) AddToPeerStore

func (r *Router) AddToPeerStore(ctx context.Context, id kadt.PeerID) error

func (*Router) GetClosestNodes

func (r *Router) GetClosestNodes(ctx context.Context, to kadt.PeerID, target kadt.Key) ([]kadt.PeerID, error)

func (*Router) NodeID

func (r *Router) NodeID() kad.NodeID[kadt.Key]

func (*Router) SendMessage

func (r *Router) SendMessage(ctx context.Context, to kadt.PeerID, req *pb.Message) (*pb.Message, error)

type Topology

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

func NewTopology

func NewTopology(clk clock.Clock) *Topology

func (*Topology) ConnectPeers

func (t *Topology) ConnectPeers(a *Peer, b *Peer)

func (*Topology) ConnectPeersWithRoute

func (t *Topology) ConnectPeersWithRoute(a *Peer, b *Peer, l Link)

func (*Topology) Dial

func (t *Topology) Dial(ctx context.Context, from kadt.PeerID, to kadt.PeerID) error

func (*Topology) Peers

func (t *Topology) Peers() []*Peer

func (*Topology) RouteMessage

func (t *Topology) RouteMessage(ctx context.Context, from kadt.PeerID, to kadt.PeerID, req *pb.Message) (*pb.Message, error)

Jump to

Keyboard shortcuts

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