Documentation
¶
Index ¶
- Variables
- func GenPeerID() (peer.ID, error)
- func WaitForMinPeers(pctx context.Context, logger *zap.Logger, subscriber Subscriber, ...) error
- type Broadcaster
- type EventHandler
- type MockMessageEvent
- type MockNetwork
- type MsgValidationResult
- type Network
- type RequestHandler
- type Subscriber
- type SyncHandler
- type SyncProtocol
- type SyncResult
- type Syncer
- type ValidationReporting
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNetworkIsNotReady is returned when trying to access the network instance before it's ready ErrNetworkIsNotReady = errors.New("network services are not ready") )
Functions ¶
func WaitForMinPeers ¶
func WaitForMinPeers(pctx context.Context, logger *zap.Logger, subscriber Subscriber, vpk spectypes.ValidatorPK, minPeers int, interval time.Duration) error
WaitForMinPeers waits until there are minPeers conntected for the given validator
Types ¶
type Broadcaster ¶
type Broadcaster interface {
// Broadcast broadcasts the given message to the corresponding subnet
Broadcast(msg spectypes.SSVMessage) error
}
Broadcaster enables to broadcast messages
type EventHandler ¶
type EventHandler func(e MockMessageEvent) *spectypes.SSVMessage
EventHandler represents a function that handles a message event
type MockMessageEvent ¶
type MockMessageEvent struct {
From peer.ID
Topic string
Protocol string
Msg *spectypes.SSVMessage
}
MockMessageEvent is an abstraction used to push stream/pubsub messages
type MockNetwork ¶
type MockNetwork interface {
Network
SendStreamMessage(protocol string, pi peer.ID, msg *spectypes.SSVMessage) error
Self() peer.ID
PushMsg(e MockMessageEvent)
AddPeers(pk spectypes.ValidatorPK, toAdd ...MockNetwork)
Start(ctx context.Context)
SetLastDecidedHandler(lastDecidedHandler EventHandler)
SetGetHistoryHandler(getHistoryHandler EventHandler)
}
MockNetwork is a wrapping interface that enables tests to run with local network
func NewMockNetwork ¶
NewMockNetwork creates a new instance of MockNetwork
type MsgValidationResult ¶
type MsgValidationResult int32
MsgValidationResult helps other components to report message validation with a generic results scheme
const ( // ValidationAccept is the result of a valid message ValidationAccept MsgValidationResult = iota // ValidationIgnore is the result in case we want to ignore the validation ValidationIgnore // ValidationRejectLow is the result for invalid message, with low severity (e.g. late message) ValidationRejectLow // ValidationRejectMedium is the result for invalid message, with medium severity (e.g. wrong height) ValidationRejectMedium // ValidationRejectHigh is the result for invalid message, with high severity (e.g. invalid signature) ValidationRejectHigh )
type Network ¶
type Network interface {
Subscriber
Broadcaster
Syncer
ValidationReporting
}
Network holds the networking layer used to complement the underlying protocols
type RequestHandler ¶
type RequestHandler func(*spectypes.SSVMessage) (*spectypes.SSVMessage, error)
RequestHandler handles p2p requests
func CombineRequestHandlers ¶
func CombineRequestHandlers(handlers ...RequestHandler) RequestHandler
CombineRequestHandlers combines multiple handlers into a single handler
type Subscriber ¶
type Subscriber interface {
// Subscribe subscribes to validator subnet
Subscribe(pk spectypes.ValidatorPK) error
// Unsubscribe unsubscribes from the validator subnet
Unsubscribe(pk spectypes.ValidatorPK) error
// Peers returns the peers that are connected to the given validator
Peers(pk spectypes.ValidatorPK) ([]peer.ID, error)
}
Subscriber manages topics subscription
type SyncHandler ¶
type SyncHandler struct {
Protocol SyncProtocol
Handler RequestHandler
}
SyncHandler is a wrapper for RequestHandler, that enables to specify the protocol
func WithHandler ¶
func WithHandler(protocol SyncProtocol, handler RequestHandler) *SyncHandler
WithHandler enables to inject an SyncHandler
type SyncProtocol ¶
type SyncProtocol int32
SyncProtocol represent the type of sync protocols
const ( // LastDecidedProtocol is the last decided protocol type LastDecidedProtocol SyncProtocol = iota // LastChangeRoundProtocol is the last change round protocol type LastChangeRoundProtocol // DecidedHistoryProtocol is the decided history protocol type DecidedHistoryProtocol )
type SyncResult ¶
type SyncResult struct {
Msg *spectypes.SSVMessage
Sender string
}
SyncResult holds the result of a sync request, including the actual message and the sender
type Syncer ¶
type Syncer interface {
// RegisterHandlers registers handler for the given protocol
RegisterHandlers(handlers ...*SyncHandler)
// LastDecided fetches last decided from a random set of peers
LastDecided(mid spectypes.MessageID) ([]SyncResult, error)
// GetHistory sync the given range from a set of peers that supports history for the given identifier
// it accepts a list of targets for the request
GetHistory(mid spectypes.MessageID, from, to specqbft.Height, targets ...string) ([]SyncResult, specqbft.Height, error)
// LastChangeRound fetches last change round message from a random set of peers
LastChangeRound(mid spectypes.MessageID, height specqbft.Height) ([]SyncResult, error)
}
Syncer holds the interface for syncing data from other peerz
type ValidationReporting ¶
type ValidationReporting interface {
// ReportValidation reports the result for the given message
ReportValidation(message *spectypes.SSVMessage, res MsgValidationResult)
}
ValidationReporting is the interface for reporting on message validation results