simulator

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2022 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const FAILURE_PREAMBLE = "Failed unmarshalling event: "
View Source
const MaxBandwidthReports = 10

Variables

This section is empty.

Functions

This section is empty.

Types

type APICommandID added in v0.7.0

type APICommandID int
const (
	UnknownCommand APICommandID = iota
	SimDebug
	SimPlay
	SimPause
	SimDelay
	SimAddNode
	SimRemoveNode
	SimAddPeer
	SimRemovePeer
	SimConfigureAdversaryDefaults
	SimConfigureAdversaryPeer
	SimStartPings
	SimStopPings
)

type APICommandMessageID added in v0.7.0

type APICommandMessageID int
const (
	UnknownCommandMsg APICommandMessageID = iota
	SimPlaySequence
)

type APIEventMessageID added in v0.7.0

type APIEventMessageID int
const (
	UnknownEventMsg APIEventMessageID = iota
	SimInitialState
	SimStateUpdate
)

type APINodeType added in v0.7.0

type APINodeType int
const (
	UnknownType APINodeType = iota
	DefaultNode
	GeneralAdversaryNode
)

type APIUpdateID added in v0.6.0

type APIUpdateID int
const (
	UnknownUpdate APIUpdateID = iota
	SimNodeAdded
	SimNodeRemoved
	SimPeerAdded
	SimPeerRemoved
	SimTreeParentUpdated
	SimSnakeAscUpdated
	SimSnakeDescUpdated
	SimTreeRootAnnUpdated
	SimSnakeEntryAdded
	SimSnakeEntryRemoved
	SimPingStateUpdated
	SimNetworkStatsUpdated
	SimBroadcastReceived
	SimBandwidthReport
)

type AddNode added in v0.7.0

type AddNode struct {
	Node     string
	NodeType APINodeType
}

func (AddNode) Run added in v0.7.0

func (c AddNode) Run(log *log.Logger, sim *Simulator)

Tag AddNode as a Command

func (AddNode) String added in v0.7.0

func (c AddNode) String() string

type AddPeer added in v0.7.0

type AddPeer struct {
	Node string
	Peer string
}

func (AddPeer) Run added in v0.7.0

func (c AddPeer) Run(log *log.Logger, sim *Simulator)

Tag AddPeer as a Command

func (AddPeer) String added in v0.7.0

func (c AddPeer) String() string

type BandwidthReport added in v0.10.0

type BandwidthReport struct {
	Node      string
	Bandwidth BandwidthSnapshot
}

type BandwidthReports added in v0.10.0

type BandwidthReports []BandwidthSnapshot

type BandwidthSnapshot added in v0.10.0

type BandwidthSnapshot struct {
	ReceiveTime uint64
	Peers       map[string]PeerBandwidthUsage
}

type BroadcastEntry added in v0.11.0

type BroadcastEntry struct {
	PeerID string
	Time   uint64
}

type BroadcastReceived added in v0.11.0

type BroadcastReceived struct {
	Node   string
	PeerID string
	Time   uint64
}

type ConfigureAdversaryDefaults added in v0.7.0

type ConfigureAdversaryDefaults struct {
	Node      string
	DropRates adversary.DropRates
}

func (ConfigureAdversaryDefaults) Run added in v0.7.0

func (c ConfigureAdversaryDefaults) Run(log *log.Logger, sim *Simulator)

Tag ConfigureAdversaryDefaults as an Command

func (ConfigureAdversaryDefaults) String added in v0.7.0

type ConfigureAdversaryPeer added in v0.7.0

type ConfigureAdversaryPeer struct {
	Node      string
	Peer      string
	DropRates adversary.DropRates
}

func (ConfigureAdversaryPeer) Run added in v0.7.0

func (c ConfigureAdversaryPeer) Run(log *log.Logger, sim *Simulator)

Tag ConfigureAdversaryPeer as an Command

func (ConfigureAdversaryPeer) String added in v0.7.0

func (c ConfigureAdversaryPeer) String() string

type DefaultRouter added in v0.7.0

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

func (*DefaultRouter) ConfigureFilterDefaults added in v0.7.0

func (r *DefaultRouter) ConfigureFilterDefaults(rates adversary.DropRates)

func (*DefaultRouter) ConfigureFilterPeer added in v0.7.0

func (r *DefaultRouter) ConfigureFilterPeer(peer types.PublicKey, rates adversary.DropRates)

func (*DefaultRouter) Connect added in v0.7.0

func (r *DefaultRouter) Connect(conn net.Conn, options ...router.ConnectionOption) (types.SwitchPortID, error)

func (*DefaultRouter) Coords added in v0.7.0

func (r *DefaultRouter) Coords() types.Coordinates

func (*DefaultRouter) DisableWakeupBroadcasts added in v0.11.0

func (r *DefaultRouter) DisableWakeupBroadcasts()

func (*DefaultRouter) EnableHopLimiting added in v0.11.0

func (r *DefaultRouter) EnableHopLimiting()

func (*DefaultRouter) EnableWakeupBroadcasts added in v0.11.0

func (r *DefaultRouter) EnableWakeupBroadcasts()

func (*DefaultRouter) ManholeHandler added in v0.8.0

func (r *DefaultRouter) ManholeHandler(w http.ResponseWriter, req *http.Request)

func (*DefaultRouter) OverlayReadHandler added in v0.9.0

func (r *DefaultRouter) OverlayReadHandler(quit <-chan bool)

func (*DefaultRouter) Ping added in v0.7.0

func (r *DefaultRouter) Ping(ctx context.Context, destination types.PublicKey) (uint16, time.Duration, error)

func (*DefaultRouter) PingFilter added in v0.10.0

func (r *DefaultRouter) PingFilter(from types.PublicKey, f *types.Frame) bool

func (*DefaultRouter) PublicKey added in v0.7.0

func (r *DefaultRouter) PublicKey() types.PublicKey

func (*DefaultRouter) Subscribe added in v0.7.0

func (r *DefaultRouter) Subscribe(ch chan events.Event)

type Delay added in v0.7.0

type Delay struct {
	Length uint64 // delay time in ms
}

func (Delay) Run added in v0.7.0

func (c Delay) Run(log *log.Logger, sim *Simulator)

Tag Delay as a Command

func (Delay) String added in v0.7.0

func (c Delay) String() string

type Distance

type Distance struct {
	Real     int64
	Observed int64
}

type EventSequencePlayer added in v0.7.0

type EventSequencePlayer interface {
	Play()
	Pause()
	AddToPlaylist(commands []SimCommand)
}

type EventSequenceRunner added in v0.7.0

type EventSequenceRunner struct {
	phony.Inbox
	// contains filtered or unexported fields
}

func (*EventSequenceRunner) Pause added in v0.7.0

func (r *EventSequenceRunner) Pause()

func (*EventSequenceRunner) Play added in v0.7.0

func (r *EventSequenceRunner) Play()

func (*EventSequenceRunner) Run added in v0.7.0

func (r *EventSequenceRunner) Run(sim *Simulator)

type ExpectedBroadcasts added in v0.11.0

type ExpectedBroadcasts map[string]bool

type InitialNodeState added in v0.6.0

type InitialNodeState struct {
	PublicKey          string
	NodeType           APINodeType
	RootState          RootState
	Peers              []PeerInfo
	TreeParent         string
	SnakeAsc           string
	SnakeAscPath       string
	SnakeDesc          string
	SnakeDescPath      string
	SnakeEntries       []SnakeRouteEntry
	BroadcastsReceived []BroadcastEntry
	BandwidthReports   []BandwidthSnapshot
}

type InitialStateMsg added in v0.6.0

type InitialStateMsg struct {
	MsgID               APIEventMessageID
	Nodes               map[string]InitialNodeState
	End                 bool
	BWReportingInterval int
}

type NetworkStatsUpdate added in v0.9.0

type NetworkStatsUpdate struct {
	PathConvergence uint64
	AverageStretch  float64
}

type Node

type Node struct {
	SimRouter

	ListenAddr *net.TCPAddr
	Type       APINodeType
	// contains filtered or unexported fields
}

type NodeAdded added in v0.6.0

type NodeAdded struct {
	Node       string
	PublicKey  string
	NodeType   int
	RouteCount int
}

type NodeRemoved added in v0.6.0

type NodeRemoved struct {
	Node string
}

type NodeState added in v0.6.0

type NodeState struct {
	PeerID             string
	NodeType           APINodeType
	Connections        map[int]string
	Parent             string
	Coords             []uint64
	Announcement       RootAnnouncement
	AscendingPeer      string
	AscendingPathID    string
	DescendingPeer     string
	DescendingPathID   string
	SnakeEntries       map[string]string
	BroadcastsReceived map[string]uint64
	BandwidthReports   BandwidthReports
	NextReportIndex    uint
	ExpectedBroadcasts ExpectedBroadcasts
}

func NewNodeState added in v0.6.0

func NewNodeState(peerID string, nodeType APINodeType) *NodeState

func (NodeState) String added in v0.7.0

func (n NodeState) String() string

type Pause added in v0.7.0

type Pause struct{}

func (Pause) Run added in v0.7.0

func (c Pause) Run(log *log.Logger, sim *Simulator)

Tag Pause as a Command

func (Pause) String added in v0.7.0

func (c Pause) String() string

type PeerAdded added in v0.6.0

type PeerAdded struct {
	Node string
	Peer string
	Port uint64
}

type PeerBandwidthUsage added in v0.10.0

type PeerBandwidthUsage struct {
	Protocol struct {
		Rx uint64
		Tx uint64
	}
	Overlay struct {
		Rx uint64
		Tx uint64
	}
}

type PeerInfo added in v0.6.0

type PeerInfo struct {
	ID   string
	Port int
}

type PeerRemoved added in v0.6.0

type PeerRemoved struct {
	Node string
	Peer string
}

type PingPayload added in v0.9.0

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

func (*PingPayload) MarshalBinary added in v0.9.0

func (p *PingPayload) MarshalBinary(buffer []byte) (int, error)

func (*PingPayload) UnmarshalBinary added in v0.9.0

func (p *PingPayload) UnmarshalBinary(buffer []byte) (int, error)

type PingStateUpdate added in v0.9.0

type PingStateUpdate struct {
	Enabled bool
	Active  bool
}

type PingType added in v0.9.0

type PingType uint8
const (
	Ping PingType = iota
	Pong
)

type Play added in v0.7.0

type Play struct{}

func (Play) Run added in v0.7.0

func (c Play) Run(log *log.Logger, sim *Simulator)

Tag Play as a Command

func (Play) String added in v0.7.0

func (c Play) String() string

type RemoveNode added in v0.7.0

type RemoveNode struct {
	Node string
}

func (RemoveNode) Run added in v0.7.0

func (c RemoveNode) Run(log *log.Logger, sim *Simulator)

Tag RemoveNode as an Command

func (RemoveNode) String added in v0.7.0

func (c RemoveNode) String() string

type RemovePeer added in v0.7.0

type RemovePeer struct {
	Node string
	Peer string
}

func (RemovePeer) Run added in v0.7.0

func (c RemovePeer) Run(log *log.Logger, sim *Simulator)

Tag RemovePeer as an Command

func (RemovePeer) String added in v0.7.0

func (c RemovePeer) String() string

type RootAnnouncement added in v0.6.0

type RootAnnouncement struct {
	Root     string
	Sequence uint64
	Time     uint64
}

type RootState added in v0.6.0

type RootState struct {
	Root        string
	AnnSequence uint64
	AnnTime     uint64
	Coords      []uint64
}

type RouterCreatorFn added in v0.7.0

type RouterCreatorFn func(log *log.Logger, sk ed25519.PrivateKey, quit <-chan bool) SimRouter

type SimCommand added in v0.7.0

type SimCommand interface {
	Run(log *log.Logger, sim *Simulator)
}

func UnmarshalCommandJSON added in v0.7.0

func UnmarshalCommandJSON(command *SimCommandMsg) (SimCommand, error)

type SimCommandMsg added in v0.7.0

type SimCommandMsg struct {
	MsgID APICommandID
	Event interface{}
}

type SimCommandSequenceMsg added in v0.7.0

type SimCommandSequenceMsg struct {
	MsgID  APICommandMessageID
	Events []SimCommandMsg
}

type SimEvent added in v0.6.0

type SimEvent interface {
	// contains filtered or unexported methods
}

type SimEventMsg added in v0.6.0

type SimEventMsg struct {
	UpdateID APIUpdateID
	Event    SimEvent
}

type SimRouter added in v0.7.0

type SimRouter interface {
	PublicKey() types.PublicKey
	Connect(conn net.Conn, options ...router.ConnectionOption) (types.SwitchPortID, error)
	Subscribe(ch chan events.Event)
	Ping(ctx context.Context, a types.PublicKey) (uint16, time.Duration, error)
	Coords() types.Coordinates
	ConfigureFilterDefaults(rates adversary.DropRates)
	ConfigureFilterPeer(peer types.PublicKey, rates adversary.DropRates)
	ManholeHandler(w http.ResponseWriter, req *http.Request)
}

type Simulator

type Simulator struct {
	AcceptCommands bool

	State *StateAccessor
	// contains filtered or unexported fields
}

func NewSimulator

func NewSimulator(log *log.Logger, sockets, acceptCommands bool) *Simulator

func (*Simulator) AddToPlaylist added in v0.7.0

func (sim *Simulator) AddToPlaylist(commands []SimCommand)

func (*Simulator) CalculatePathConvergence added in v0.10.0

func (sim *Simulator) CalculatePathConvergence() float64

func (*Simulator) CalculateStretch added in v0.9.0

func (sim *Simulator) CalculateStretch() float64

func (*Simulator) ConfigureFilterDefaults added in v0.7.0

func (sim *Simulator) ConfigureFilterDefaults(node string, rates adversary.DropRates)

func (*Simulator) ConfigureFilterPeer added in v0.7.0

func (sim *Simulator) ConfigureFilterPeer(node string, peer string, rates adversary.DropRates)

func (*Simulator) ConnectNodes

func (sim *Simulator) ConnectNodes(a, b string) error

func (*Simulator) CreateNode

func (sim *Simulator) CreateNode(t string, nodeType APINodeType) error

func (*Simulator) DisconnectAllPeers added in v0.7.0

func (sim *Simulator) DisconnectAllPeers(disconnectNode string)

func (*Simulator) DisconnectNodes

func (sim *Simulator) DisconnectNodes(a, b string) error

func (*Simulator) Distances

func (sim *Simulator) Distances() map[string]map[string]*Distance

func (*Simulator) GenerateNetworkGraph added in v0.11.0

func (sim *Simulator) GenerateNetworkGraph()

func (*Simulator) Node

func (sim *Simulator) Node(t string) *Node

func (*Simulator) Nodes

func (sim *Simulator) Nodes() map[string]*Node

func (*Simulator) PathConvergence

func (sim *Simulator) PathConvergence() map[string]map[string]bool

func (*Simulator) Pause added in v0.7.0

func (sim *Simulator) Pause()

func (*Simulator) Ping added in v0.10.0

func (sim *Simulator) Ping(from, to string) (uint16, time.Duration, error)

func (*Simulator) PingingActive added in v0.9.0

func (sim *Simulator) PingingActive() bool

func (*Simulator) PingingEnabled added in v0.4.0

func (sim *Simulator) PingingEnabled() bool

func (*Simulator) Play added in v0.7.0

func (sim *Simulator) Play()

func (*Simulator) RemoveNode added in v0.7.0

func (sim *Simulator) RemoveNode(node string)

func (*Simulator) ReportDistance

func (sim *Simulator) ReportDistance(a, b string, l int64)

func (*Simulator) StartNodeEventHandler added in v0.6.0

func (sim *Simulator) StartNodeEventHandler(t string, nodeType APINodeType)

func (*Simulator) StartPinging added in v0.9.0

func (sim *Simulator) StartPinging(ping_period time.Duration)

func (*Simulator) StartPings added in v0.9.0

func (sim *Simulator) StartPings()

func (*Simulator) StopPings added in v0.9.0

func (sim *Simulator) StopPings()

func (*Simulator) UpdateRealDistances added in v0.11.0

func (sim *Simulator) UpdateRealDistances()

func (*Simulator) Uptime added in v0.4.0

func (sim *Simulator) Uptime() time.Duration

type SnakeAscUpdate added in v0.6.0

type SnakeAscUpdate struct {
	Node   string
	Peer   string
	Prev   string
	PathID string
}

type SnakeDescUpdate added in v0.6.0

type SnakeDescUpdate struct {
	Node   string
	Peer   string
	Prev   string
	PathID string
}

type SnakeEntryAdded added in v0.9.0

type SnakeEntryAdded struct {
	Node    string
	EntryID string
	PeerID  string
}

type SnakeEntryRemoved added in v0.9.0

type SnakeEntryRemoved struct {
	Node    string
	EntryID string
}

type SnakeRouteEntry added in v0.9.0

type SnakeRouteEntry struct {
	EntryID string
	PeerID  string
}

type StartPings added in v0.9.0

type StartPings struct{}

func (StartPings) Run added in v0.9.0

func (c StartPings) Run(log *log.Logger, sim *Simulator)

Tag StartPings as a Command

func (StartPings) String added in v0.9.0

func (c StartPings) String() string

type State added in v0.6.0

type State struct {
	Nodes map[string]*NodeState
}

func NewState added in v0.6.0

func NewState() *State

func (State) String added in v0.7.0

func (s State) String() string

type StateAccessor added in v0.6.0

type StateAccessor struct {
	phony.Inbox
	// contains filtered or unexported fields
}

func NewStateAccessor added in v0.6.0

func NewStateAccessor() *StateAccessor

func (*StateAccessor) DebugLog added in v0.7.0

func (s *StateAccessor) DebugLog() string

func (*StateAccessor) GetLinkCount added in v0.6.0

func (s *StateAccessor) GetLinkCount() float64

func (*StateAccessor) GetNodeCoords added in v0.6.0

func (s *StateAccessor) GetNodeCoords(name string) []uint64

func (*StateAccessor) GetNodeName added in v0.6.0

func (s *StateAccessor) GetNodeName(peerID string) (string, error)

func (*StateAccessor) Subscribe added in v0.6.0

func (s *StateAccessor) Subscribe(ch chan<- SimEvent) State

type StateDebug added in v0.7.0

type StateDebug struct{}

func (StateDebug) Run added in v0.7.0

func (c StateDebug) Run(log *log.Logger, sim *Simulator)

Tag StateDebug as a Command

func (StateDebug) String added in v0.7.0

func (c StateDebug) String() string

type StateUpdateMsg added in v0.6.0

type StateUpdateMsg struct {
	MsgID APIEventMessageID
	Event SimEventMsg
}

type StopPings added in v0.9.0

type StopPings struct{}

func (StopPings) Run added in v0.9.0

func (c StopPings) Run(log *log.Logger, sim *Simulator)

Tag StopPings as a Command

func (StopPings) String added in v0.9.0

func (c StopPings) String() string

type TreeParentUpdate added in v0.6.0

type TreeParentUpdate struct {
	Node string
	Peer string
	Prev string
}

type TreeRootAnnUpdate added in v0.6.0

type TreeRootAnnUpdate struct {
	Node     string
	Root     string // Root Public Key
	Sequence uint64
	Time     uint64 // Unix Time
	Coords   []uint64
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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