Documentation ¶
Index ¶
- type Envelope
- type Simnet
- type SimnetEndpoint
- func (se *SimnetEndpoint) Broadcast(message p2ptypes.Message) (successes chan bool)
- func (se *SimnetEndpoint) BroadcastToNeighbors(message p2ptypes.Message, maxNumPeersToBroadcast int) (successes chan bool)
- func (se *SimnetEndpoint) HandleMessage(message p2ptypes.Message) error
- func (se *SimnetEndpoint) ID() string
- func (se *SimnetEndpoint) PeerExists(peerID string) bool
- func (se *SimnetEndpoint) Peers() []string
- func (se *SimnetEndpoint) RegisterMessageHandler(handler p2p.MessageHandler)
- func (se *SimnetEndpoint) Send(id string, message p2ptypes.Message) bool
- func (se *SimnetEndpoint) Start(ctx context.Context) error
- func (se *SimnetEndpoint) Stop()
- func (se *SimnetEndpoint) Wait()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Simnet ¶
type Simnet struct { Endpoints []*SimnetEndpoint MsgLogs []Envelope // contains filtered or unexported fields }
Simnet represents an instance of simulated network.
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 ¶
AddMessage send a message through the network.
func (*Simnet) Start ¶
Start is the main entry point for Simnet. It starts all endpoints and start a goroutine to handle message dlivery.
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.