simulator

package
v0.0.0-...-26ee366 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2022 License: Apache-2.0 Imports: 23 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

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

type APICommandMessageID

type APICommandMessageID int
const (
	UnknownCommandMsg APICommandMessageID = iota
	SimPlaySequence
)

type APIEventMessageID

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

type APINodeType

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

type APIUpdateID

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

type AddNode

type AddNode struct {
	Node     string
	NodeType APINodeType
}

func (AddNode) Run

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

Tag AddNode as a Command

func (AddNode) String

func (c AddNode) String() string

type AddPeer

type AddPeer struct {
	Node string
	Peer string
}

func (AddPeer) Run

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

Tag AddPeer as a Command

func (AddPeer) String

func (c AddPeer) String() string

type BandwidthReport

type BandwidthReport struct {
	Node      string
	Bandwidth BandwidthSnapshot
}

type BandwidthReports

type BandwidthReports []BandwidthSnapshot

type BandwidthSnapshot

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

type ConfigureAdversaryDefaults

type ConfigureAdversaryDefaults struct {
	Node      string
	DropRates adversary.DropRates
}

func (ConfigureAdversaryDefaults) Run

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

Tag ConfigureAdversaryDefaults as an Command

func (ConfigureAdversaryDefaults) String

type ConfigureAdversaryPeer

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

func (ConfigureAdversaryPeer) Run

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

Tag ConfigureAdversaryPeer as an Command

func (ConfigureAdversaryPeer) String

func (c ConfigureAdversaryPeer) String() string

type DefaultRouter

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

func (*DefaultRouter) ConfigureFilterDefaults

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

func (*DefaultRouter) ConfigureFilterPeer

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

func (*DefaultRouter) Connect

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

func (*DefaultRouter) Coords

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

func (*DefaultRouter) ManholeHandler

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

func (*DefaultRouter) OverlayReadHandler

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

func (*DefaultRouter) Ping

func (*DefaultRouter) PublicKey

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

func (*DefaultRouter) Subscribe

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

type Delay

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

func (Delay) Run

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

Tag Delay as a Command

func (Delay) String

func (c Delay) String() string

type Distance

type Distance struct {
	Real         int64
	ObservedTree int64
	ObservedSNEK int64
}

type EventSequencePlayer

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

type EventSequenceRunner

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

func (*EventSequenceRunner) Pause

func (r *EventSequenceRunner) Pause()

func (*EventSequenceRunner) Play

func (r *EventSequenceRunner) Play()

func (*EventSequenceRunner) Run

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

type InitialNodeState

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

type InitialStateMsg

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

type NetworkStatsUpdate

type NetworkStatsUpdate struct {
	TreePathConvergence  uint64
	TreeAverageStretch   float64
	SnakePathConvergence uint64
	SnakeAverageStretch  float64
}

type Node

type Node struct {
	SimRouter

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

type NodeAdded

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

type NodeRemoved

type NodeRemoved struct {
	Node string
}

type NodeState

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
	BandwidthReports BandwidthReports
	NextReportIndex  uint
}

func NewNodeState

func NewNodeState(peerID string, nodeType APINodeType) *NodeState

func (NodeState) String

func (n NodeState) String() string

type Pause

type Pause struct{}

func (Pause) Run

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

Tag Pause as a Command

func (Pause) String

func (c Pause) String() string

type PeerAdded

type PeerAdded struct {
	Node string
	Peer string
	Port uint64
}

type PeerBandwidthUsage

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

type PeerInfo

type PeerInfo struct {
	ID   string
	Port int
}

type PeerRemoved

type PeerRemoved struct {
	Node string
	Peer string
}

type PingPayload

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

func (*PingPayload) MarshalBinary

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

func (*PingPayload) UnmarshalBinary

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

type PingStateUpdate

type PingStateUpdate struct {
	Enabled bool
	Active  bool
}

type PingType

type PingType uint8
const (
	TreePing PingType = iota
	TreePong
	SNEKPing
	SNEKPong
)

type Play

type Play struct{}

func (Play) Run

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

Tag Play as a Command

func (Play) String

func (c Play) String() string

type RemoveNode

type RemoveNode struct {
	Node string
}

func (RemoveNode) Run

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

Tag RemoveNode as an Command

func (RemoveNode) String

func (c RemoveNode) String() string

type RemovePeer

type RemovePeer struct {
	Node string
	Peer string
}

func (RemovePeer) Run

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

Tag RemovePeer as an Command

func (RemovePeer) String

func (c RemovePeer) String() string

type RootAnnouncement

type RootAnnouncement struct {
	Root     string
	Sequence uint64
	Time     uint64
}

type RootState

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

type RouterCreatorFn

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

type SimCommand

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

func UnmarshalCommandJSON

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

type SimCommandMsg

type SimCommandMsg struct {
	MsgID APICommandID
	Event interface{}
}

type SimCommandSequenceMsg

type SimCommandSequenceMsg struct {
	MsgID  APICommandMessageID
	Events []SimCommandMsg
}

type SimEvent

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

type SimEventMsg

type SimEventMsg struct {
	UpdateID APIUpdateID
	Event    SimEvent
}

type SimRouter

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 net.Addr) (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

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

func (*Simulator) CalculateSNEKPathConvergence

func (sim *Simulator) CalculateSNEKPathConvergence() float64

func (*Simulator) CalculateShortestPaths

func (sim *Simulator) CalculateShortestPaths()

func (*Simulator) CalculateStretch

func (sim *Simulator) CalculateStretch() (tree float64, snek float64)

func (*Simulator) CalculateTreePathConvergence

func (sim *Simulator) CalculateTreePathConvergence() float64

func (*Simulator) ConfigureFilterDefaults

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

func (*Simulator) ConfigureFilterPeer

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

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) Node

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

func (*Simulator) Nodes

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

func (*Simulator) Pause

func (sim *Simulator) Pause()

func (*Simulator) PingSNEK

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

func (*Simulator) PingTree

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

func (*Simulator) PingingActive

func (sim *Simulator) PingingActive() bool

func (*Simulator) PingingEnabled

func (sim *Simulator) PingingEnabled() bool

func (*Simulator) Play

func (sim *Simulator) Play()

func (*Simulator) RemoveNode

func (sim *Simulator) RemoveNode(node string)

func (*Simulator) ReportDistance

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

func (*Simulator) SNEKPathConvergence

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

func (*Simulator) StartNodeEventHandler

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

func (*Simulator) StartPinging

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

func (*Simulator) StartPings

func (sim *Simulator) StartPings()

func (*Simulator) StopPings

func (sim *Simulator) StopPings()

func (*Simulator) TreePathConvergence

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

func (*Simulator) Uptime

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

type SnakeAscUpdate

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

type SnakeDescUpdate

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

type SnakeEntryAdded

type SnakeEntryAdded struct {
	Node    string
	EntryID string
	PeerID  string
}

type SnakeEntryRemoved

type SnakeEntryRemoved struct {
	Node    string
	EntryID string
}

type SnakeRouteEntry

type SnakeRouteEntry struct {
	EntryID string
	PeerID  string
}

type StartPings

type StartPings struct{}

func (StartPings) Run

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

Tag StartPings as a Command

func (StartPings) String

func (c StartPings) String() string

type State

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

func NewState

func NewState() *State

func (State) String

func (s State) String() string

type StateAccessor

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

func NewStateAccessor

func NewStateAccessor() *StateAccessor

func (*StateAccessor) DebugLog

func (s *StateAccessor) DebugLog() string

func (*StateAccessor) GetLinkCount

func (s *StateAccessor) GetLinkCount() float64

func (*StateAccessor) GetNodeCoords

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

func (*StateAccessor) GetNodeName

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

func (*StateAccessor) Subscribe

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

type StateDebug

type StateDebug struct{}

func (StateDebug) Run

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

Tag StateDebug as a Command

func (StateDebug) String

func (c StateDebug) String() string

type StateUpdateMsg

type StateUpdateMsg struct {
	MsgID APIEventMessageID
	Event SimEventMsg
}

type StopPings

type StopPings struct{}

func (StopPings) Run

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

Tag StopPings as a Command

func (StopPings) String

func (c StopPings) String() string

type TreeParentUpdate

type TreeParentUpdate struct {
	Node string
	Peer string
	Prev string
}

type TreeRootAnnUpdate

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