simulation

package
v0.0.0-...-4d9f4f2 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2021 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Envelope

type Envelope struct {
	From    string
	To      string
	Content interface{}
}

Envelope wraps a message with network information for delivery.

type Simnet

type Simnet struct {
	Endpoints []*SimnetEndpoint

	MsgLogs []Envelope
	// contains filtered or unexported fields
}

Simnet represents an instance of simulated network.

func NewSimnet

func NewSimnet() *Simnet

NewSimnet creates a new instance of Simnet.

func NewSimnetWithHandler

func NewSimnetWithHandler(msgHandler p2p.MessageHandler) *Simnet

NewSimnetWithHandler creates a new instance of Simnet with given MessageHandler as the default handler.

func (*Simnet) AddEndpoint

func (sn *Simnet) AddEndpoint(id string) *SimnetEndpoint

AddEndpoint adds an endpoint with given ID to the Simnet instance.

func (*Simnet) AddMessage

func (sn *Simnet) AddMessage(msg Envelope)

AddMessage send a message through the network.

func (*Simnet) Start

func (sn *Simnet) Start(ctx context.Context)

Start is the main entry point for Simnet. It starts all endpoints and start a goroutine to handle message dlivery.

func (*Simnet) Stop

func (sn *Simnet) Stop()

Stop notifies all goroutines to stop without blocking.

func (*Simnet) Wait

func (sn *Simnet) Wait()

Wait blocks until all goroutines have stopped.

type SimnetEndpoint

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

SimnetEndpoint is the implementation of Network interface for Simnet.

func (*SimnetEndpoint) Broadcast

func (se *SimnetEndpoint) Broadcast(message p2ptypes.Message) (successes chan bool)

Broadcast implements the Network interface.

func (*SimnetEndpoint) BroadcastToNeighbors

func (se *SimnetEndpoint) BroadcastToNeighbors(message p2ptypes.Message, maxNumPeersToBroadcast int) (successes chan bool)

BroadcastToNeighbors implements the Network interface.

func (*SimnetEndpoint) HandleMessage

func (se *SimnetEndpoint) HandleMessage(message p2ptypes.Message) error

HandleMessage implements the MessageHandler interface.

func (*SimnetEndpoint) ID

func (se *SimnetEndpoint) ID() string

ID implements the Network interface.

func (*SimnetEndpoint) PeerExists

func (se *SimnetEndpoint) PeerExists(peerID string) bool

PeerExists indicates if the given peerID is a neighboring peer

func (*SimnetEndpoint) Peers

func (se *SimnetEndpoint) Peers() []string

Peers returns the IDs of all peers

func (*SimnetEndpoint) RegisterMessageHandler

func (se *SimnetEndpoint) RegisterMessageHandler(handler p2p.MessageHandler)

RegisterMessageHandler implements the Network interface.

func (*SimnetEndpoint) Send

func (se *SimnetEndpoint) Send(id string, message p2ptypes.Message) bool

Send implements the Network interface.

func (*SimnetEndpoint) Start

func (se *SimnetEndpoint) Start(ctx context.Context) error

Start implements the Network interface. It starts goroutines to receive/send message from network.

func (*SimnetEndpoint) Stop

func (se *SimnetEndpoint) Stop()

Stop implements the Network interface.

func (*SimnetEndpoint) Wait

func (se *SimnetEndpoint) Wait()

Wait blocks until all goroutines have stopped.

Jump to

Keyboard shortcuts

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