network

package
v0.2.0-rc Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2022 License: GPL-3.0 Imports: 10 Imported by: 1

README

SSV - Networking

This document contains the networking layer design.

Overview

Design

Network package holds components that are responsible for the networking aspects in the project, such as subscribing to topics or reading, syncing and broadcasting messages.

Codebase Structure

network package contains the following:

  • interfaces and structs
  • implementation packages:
    • p2p contains implementation of a p2p network based on libp2p
    • local contains implementation of a mocked network, for tests
  • forks interface and implementation
  • common utilities
  • TBD websocket package
Interfaces

Network interface is composed of several dedicated interfaces. It is mostly based on protcolp2p.Network which is located in ./protocol/v1/p2p/network.go:

package protocolp2p

type Network interface {
    // Subscriber manages topics subscription
	Subscriber
	// Broadcaster enables to broadcast messages
	Broadcaster
	// Syncer holds the interface for syncing data from other peerz
	Syncer
	// ValidationReporting is the interface for reporting on message validation results
	ValidationReporting
}

The interface exported by ./network extend the protocol interface with MessageRouting and ops functions to manage the network layer:

package network
// P2PNetwork is a facade interface that provides the entire functionality of the different network interfaces
type P2PNetwork interface {
	protocolp2p.Network
    // MessageRouting allows to register a MessageRouter that handles incoming connections
    MessageRouting
	// Setup initialize the network layer and starts the libp2p host
	Setup() error
	// Start starts the network
	Start() error
    io.Closer
}

The separation of interfaces allows to use a minimal api by other components, as expressed in the following diagram:

TODO: add diagram

Connections

TODO: complete

Streams

TODO: complete

Pubsub Topics

TODO: complete

Discovery

TODO: complete


Testing

TODO: complete

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NetworkMsg_name = map[int32]string{
	0: "IBFTType",
	1: "DecidedType",
	2: "SignatureType",
	3: "SyncType",
}
View Source
var NetworkMsg_value = map[string]int32{
	"IBFTType":      0,
	"DecidedType":   1,
	"SignatureType": 2,
	"SyncType":      3,
}
View Source
var Sync_name = map[int32]string{
	0: "GetHighestType",
	1: "GetInstanceRange",
	2: "GetLatestChangeRound",
}
View Source
var Sync_value = map[string]int32{
	"GetHighestType":       0,
	"GetInstanceRange":     1,
	"GetLatestChangeRound": 2,
}

Functions

This section is empty.

Types

type Broadcaster added in v0.1.5

type Broadcaster interface {
	// Broadcast propagates a signed message to all peers
	Broadcast(topicName []byte, msg *proto.SignedMessage) error
	// BroadcastSignature broadcasts the given signature for the given lambda
	BroadcastSignature(topicName []byte, msg *proto.SignedMessage) error
	// BroadcastDecided broadcasts a decided instance with collected signatures
	BroadcastDecided(topicName []byte, msg *proto.SignedMessage) error
	// MaxBatch returns the maximum batch size for network responses
	MaxBatch() uint64
}

Broadcaster is the interface for broadcasting messages in the network

type Message

type Message struct {
	SignedMessage *proto.SignedMessage
	SyncMessage   *SyncMessage
	Type          NetworkMsg
	StreamID      string
}

Message is a container for network messages.

func (*Message) Decode added in v0.2.0

func (m *Message) Decode(data []byte) error

Decode implements MessageEncoder

func (*Message) Encode added in v0.2.0

func (m *Message) Encode() ([]byte, error)

Encode implements MessageEncoder

type MessageRouter added in v0.2.0

type MessageRouter interface {
	// Route routes the given message, this function MUST NOT block
	Route(message message.SSVMessage)
}

MessageRouter is accepting network messages and route them to the corresponding (internal) components

type MessageRouting added in v0.2.0

type MessageRouting interface {
	// UseMessageRouter registers a message router to handle incoming messages
	UseMessageRouter(router MessageRouter)
}

MessageRouting allows to register a MessageRouter

type Network

type Network interface {
	Reader
	Broadcaster
	Syncer

	// NotifyOperatorID updates the network regarding new operators joining the network
	// TODO: find a better way to do this
	NotifyOperatorID(oid string)
}

Network represents the behavior of the network

type NetworkMsg

type NetworkMsg int32
const (
	// IBFTType are all iBFT related messages
	NetworkMsg_IBFTType NetworkMsg = 0
	// DecidedType is an iBFT specific message for broadcasting post consensus decided message with signatures
	NetworkMsg_DecidedType NetworkMsg = 1
	// SignatureType is an SSV node specific message for broadcasting post consensus signatures on eth2 duties
	NetworkMsg_SignatureType NetworkMsg = 2
	// SyncType is an SSV iBFT specific message that a node uses to sync up with other nodes
	NetworkMsg_SyncType NetworkMsg = 3
)

func (NetworkMsg) EnumDescriptor

func (NetworkMsg) EnumDescriptor() ([]byte, []int)

func (NetworkMsg) String

func (x NetworkMsg) String() string

type P2PNetwork added in v0.2.0

type P2PNetwork interface {
	io.Closer
	protocolp2p.Network
	MessageRouting
	// Setup initialize the network layer and starts the libp2p host
	Setup() error
	// Start starts the network
	Start() error
}

P2PNetwork is a facade interface that provides the entire functionality of the different network interfaces

type Reader added in v0.1.5

type Reader interface {
	// ReceivedMsgChan is a channel that forwards new propagated messages to a subscriber
	ReceivedMsgChan() (<-chan *proto.SignedMessage, func())
	// ReceivedSignatureChan returns the channel with signatures
	ReceivedSignatureChan() (<-chan *proto.SignedMessage, func())
	// ReceivedDecidedChan returns the channel for decided messages
	ReceivedDecidedChan() (<-chan *proto.SignedMessage, func())
	// ReceivedSyncMsgChan returns the channel for sync messages
	ReceivedSyncMsgChan() (<-chan *SyncChanObj, func())
	// SubscribeToValidatorNetwork subscribes and listens to validator's network
	SubscribeToValidatorNetwork(validatorPk *bls.PublicKey) error
	// AllPeers returns all connected peers for a validator PK
	AllPeers(validatorPk []byte) ([]string, error)
	// SubscribeToMainTopic subscribes to main topic
	SubscribeToMainTopic() error
	// MaxBatch returns the maximum batch size for network responses
	MaxBatch() uint64
}

Reader is the interface for reading messages from the network

type Sync

type Sync int32
const (
	// GetHighestType is a request from peers to return the highest decided/ prepared instance they know of
	Sync_GetHighestType Sync = 0
	// GetInstanceRange is a request from peers to return instances and their decided/ prepared justifications
	Sync_GetInstanceRange Sync = 1
	// GetCurrentInstance is a request from peers to return their current running instance details
	Sync_GetLatestChangeRound Sync = 2
)

func (Sync) EnumDescriptor

func (Sync) EnumDescriptor() ([]byte, []int)

func (Sync) String

func (x Sync) String() string

type SyncChanObj

type SyncChanObj struct {
	Msg      *SyncMessage
	StreamID string
}

SyncChanObj is a wrapper object for streaming of sync messages

type SyncMessage

type SyncMessage struct {
	SignedMessages       []*proto1.SignedMessage `protobuf:"bytes,1,rep,name=SignedMessages,proto3" json:"SignedMessages,omitempty"`
	FromPeerID           string                  `protobuf:"bytes,2,opt,name=FromPeerID,proto3" json:"FromPeerID,omitempty"`
	Params               []uint64                `protobuf:"varint,3,rep,packed,name=params,proto3" json:"params,omitempty"`
	Lambda               []byte                  `protobuf:"bytes,4,opt,name=Lambda,proto3" json:"Lambda,omitempty"`
	Type                 Sync                    `protobuf:"varint,5,opt,name=Type,proto3,enum=network.Sync" json:"Type,omitempty"`
	Error                string                  `protobuf:"bytes,6,opt,name=error,proto3" json:"error,omitempty"`
	XXX_NoUnkeyedLiteral struct{}                `json:"-"`
	XXX_unrecognized     []byte                  `json:"-"`
	XXX_sizecache        int32                   `json:"-"`
}

func (*SyncMessage) Descriptor

func (*SyncMessage) Descriptor() ([]byte, []int)

func (*SyncMessage) GetError added in v0.0.13

func (m *SyncMessage) GetError() string

func (*SyncMessage) GetFromPeerID

func (m *SyncMessage) GetFromPeerID() string

func (*SyncMessage) GetLambda added in v0.0.4

func (m *SyncMessage) GetLambda() []byte

func (*SyncMessage) GetParams

func (m *SyncMessage) GetParams() []uint64

func (*SyncMessage) GetSignedMessages

func (m *SyncMessage) GetSignedMessages() []*proto1.SignedMessage

func (*SyncMessage) GetType

func (m *SyncMessage) GetType() Sync

func (*SyncMessage) ProtoMessage

func (*SyncMessage) ProtoMessage()

func (*SyncMessage) Reset

func (m *SyncMessage) Reset()

func (*SyncMessage) String

func (m *SyncMessage) String() string

func (*SyncMessage) XXX_DiscardUnknown

func (m *SyncMessage) XXX_DiscardUnknown()

func (*SyncMessage) XXX_Marshal

func (m *SyncMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*SyncMessage) XXX_Merge

func (m *SyncMessage) XXX_Merge(src proto.Message)

func (*SyncMessage) XXX_Size

func (m *SyncMessage) XXX_Size() int

func (*SyncMessage) XXX_Unmarshal

func (m *SyncMessage) XXX_Unmarshal(b []byte) error

type SyncStream

type SyncStream interface {
	io.Closer

	// CloseWrite closes the stream for writing but leaves it open for
	// reading.
	//
	// CloseWrite does not free the stream, users must still call Close or
	// Reset.
	CloseWrite() error

	// RemotePeer returns a string identifier of the remote peer connected to this stream
	RemotePeer() string

	// ReadWithTimeout will read bytes from stream and return the result, will return error if timeout or error.
	// does not close stream when returns
	ReadWithTimeout(timeout time.Duration) ([]byte, error)

	// WriteWithTimeout will write bytes to stream, will return error if timeout or error.
	// does not close stream when returns
	WriteWithTimeout(data []byte, timeout time.Duration) error

	// ID returns the id of the stream
	ID() string
}

SyncStream is a interface for all stream related functions for the sync process.

type Syncer added in v0.1.5

type Syncer interface {
	// GetHighestDecidedInstance sends a highest decided request to peers and returns answers.
	// If peer list is nil, broadcasts to all.
	GetHighestDecidedInstance(peerStr string, msg *SyncMessage) (*SyncMessage, error)
	// GetDecidedByRange returns a list of decided signed messages up to 25 in a batch.
	GetDecidedByRange(peerStr string, msg *SyncMessage) (*SyncMessage, error)
	// GetLastChangeRoundMsg returns the latest change round msg for a running instance, could return nil
	GetLastChangeRoundMsg(peerStr string, msg *SyncMessage) (*SyncMessage, error)
	// RespondSyncMsg responds to the stream with the given message
	RespondSyncMsg(streamID string, msg *SyncMessage) error
}

Syncer represents the needed functionality for performing sync

Directories

Path Synopsis
v0
v1

Jump to

Keyboard shortcuts

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