network

package
v1.3.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2024 License: GPL-3.0 Imports: 5 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/v2/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

This section is empty.

Functions

This section is empty.

Types

type GetValidatorStats added in v0.3.2

type GetValidatorStats func() (uint64, uint64, uint64, error)

GetValidatorStats returns stats of validators, including the following:

  • the amount of validators in the network
  • the amount of active validators in the network (i.e. not slashed or existed)
  • the amount of validators assigned to this operator

type MessageRouter added in v0.2.0

type MessageRouter interface {
	// Route routes the given message, this function MUST NOT block
	Route(ctx context.Context, message *queue.DecodedSSVMessage)
}

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 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(logger *zap.Logger) error
	// Start starts the network
	Start(logger *zap.Logger) error
	// UpdateSubnets will update the registered subnets according to active validators
	UpdateSubnets(logger *zap.Logger)
	// SubscribeAll subscribes to all subnets
	SubscribeAll(logger *zap.Logger) error
	// SubscribeRandoms subscribes to random subnets
	SubscribeRandoms(logger *zap.Logger, numSubnets int) error
}

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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