service

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Data

type Data interface {
	Bytes() []byte
	// contains filtered or unexported methods
}

type DataBytes

type DataBytes struct {
	Payload []byte
}

func (DataBytes) Bytes

func (m DataBytes) Bytes() []byte

type DataMsgWrapper

type DataMsgWrapper struct {
	Req     bool
	MsgType uint32
	ReqID   uint64
	Payload []byte
}

func (DataMsgWrapper) Bytes

func (m DataMsgWrapper) Bytes() []byte

type DirectMessage

type DirectMessage interface {
	Metadata() P2PMetadata
	Sender() p2pcrypto.PublicKey
	Bytes() []byte
}

DirectMessage is an interface that represents a simple direct message structure

type GossipMessage

type GossipMessage interface {
	Sender() p2pcrypto.PublicKey
	Bytes() []byte
	ValidationCompletedChan() chan MessageValidation
	ReportValidation(protocol string)
}

GossipMessage is an interface that represents a simple gossip message structure

type MessageValidation

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

func NewMessageValidation

func NewMessageValidation(sender p2pcrypto.PublicKey, msg []byte, prot string) MessageValidation

func (MessageValidation) Message

func (mv MessageValidation) Message() []byte

func (MessageValidation) Protocol

func (mv MessageValidation) Protocol() string

func (MessageValidation) Sender

type Node

type Node struct {
	*node.NodeInfo
	// contains filtered or unexported fields
}

Node is a simulated p2p node that can be used as a p2p service

func (*Node) Broadcast

func (sn *Node) Broadcast(protocol string, payload []byte) error

Broadcast

func (*Node) ProcessDirectProtocolMessage

func (sn *Node) ProcessDirectProtocolMessage(sender p2pcrypto.PublicKey, protocol string, payload Data, metadata P2PMetadata) error

ProcessDirectProtocolMessage

func (*Node) ProcessGossipProtocolMessage

func (sn *Node) ProcessGossipProtocolMessage(sender p2pcrypto.PublicKey, protocol string, data Data, validationCompletedChan chan MessageValidation) error

ProcessGossipProtocolMessage

func (*Node) RegisterDirectProtocol

func (sn *Node) RegisterDirectProtocol(protocol string) chan DirectMessage

RegisterDirectProtocol creates and returns a channel for a given direct based protocol.

func (*Node) RegisterDirectProtocolWithChannel

func (sn *Node) RegisterDirectProtocolWithChannel(protocol string, ingressChannel chan DirectMessage) chan DirectMessage

RegisterProtocolWithChannel configures and returns a channel for a given protocol.

func (*Node) RegisterGossipProtocol

func (sn *Node) RegisterGossipProtocol(protocol string, prio priorityq.Priority) chan GossipMessage

RegisterGossipProtocol creates and returns a channel for a given gossip based protocol.

func (*Node) SendMessage

func (sn *Node) SendMessage(peerPubkey p2pcrypto.PublicKey, protocol string, payload []byte) error

func (*Node) SendWrappedMessage

func (sn *Node) SendWrappedMessage(nodeID p2pcrypto.PublicKey, protocol string, payload *DataMsgWrapper) error

func (*Node) Shutdown

func (sn *Node) Shutdown()

Shutdown closes all node channels are remove it from the Simulator map

func (*Node) Start

func (sn *Node) Start() error

func (*Node) SubscribePeerEvents

func (sn *Node) SubscribePeerEvents() (conn chan p2pcrypto.PublicKey, disc chan p2pcrypto.PublicKey)

type P2PMetadata

type P2PMetadata struct {
	FromAddress net.Addr
}

Metadata is a generic metadata interface

type Service

type Service interface {
	Start() error
	RegisterGossipProtocol(protocol string, prio priorityq.Priority) chan GossipMessage
	RegisterDirectProtocol(protocol string) chan DirectMessage
	SubscribePeerEvents() (new chan p2pcrypto.PublicKey, del chan p2pcrypto.PublicKey)
	Broadcast(protocol string, payload []byte) error
	Shutdown()
}

Service is an interface that represents a networking service (ideally p2p) that we can use to send messages or listen to incoming messages

type Simulator

type Simulator struct {
	io.Closer
	// contains filtered or unexported fields
}

Simulator is a p2p node factory and message bridge

func NewSimulator

func NewSimulator() *Simulator

New Creates a p2p simulation by providing nodes as p2p services and bridge them.

func (*Simulator) NewFaulty

func (s *Simulator) NewFaulty(isRandBehaviour bool, maxBroadcastDelaySec uint32, maxReceiveDelaySec uint32) *Node

func (*Simulator) NewNode

func (s *Simulator) NewNode() *Node

NewNode creates a new p2p node in this Simulator

func (*Simulator) NewNodeFrom

func (s *Simulator) NewNodeFrom(n *node.NodeInfo) *Node

NewNodeFrom creates a new node from existing details

func (*Simulator) SubscribeToPeerEvents

func (s *Simulator) SubscribeToPeerEvents(myid p2pcrypto.Key) (chan p2pcrypto.PublicKey, chan p2pcrypto.PublicKey)

Jump to

Keyboard shortcuts

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