api

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2022 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnectionID

func ConnectionID(conn Connection) string

ConnectionID calculates the id of the given Connection

Types

type Broadcaster added in v0.1.5

type Broadcaster interface {
	FromFeed(feed *event.Feed) error
	Broadcast(msg Message) error
	Register(conn broadcasted) bool
	Deregister(conn broadcasted) bool
}

Broadcaster is an interface broadcasting stream message across all available connections

type Conn added in v0.1.5

type Conn interface {
	ID() string
	ReadNext() []byte
	Send(msg []byte)
	WriteLoop()
	ReadLoop()
	Close() error
	RemoteAddr() net.Addr
}

Conn is a wrapper interface for websocket connections

type Connection

type Connection interface {
	Close() error
	RemoteAddr() net.Addr
}

Connection is an interface to abstract the actual websocket connection implementation

type DutyRole

type DutyRole string

DutyRole is the role of the duty

const (
	// RoleAttester is an enum for attester role
	RoleAttester DutyRole = "ATTESTER"
	// RoleAggregator is an enum for aggregator role
	RoleAggregator DutyRole = "AGGREGATOR"
	// RoleProposer is an enum for proposer role
	RoleProposer DutyRole = "PROPOSER"
)

type Message

type Message struct {
	// Type is the type of message
	Type MessageType `json:"type"`
	// Filter
	Filter MessageFilter `json:"filter"`
	// Values holds the results, optional as it's relevant for response
	Data interface{} `json:"data,omitempty"`
}

Message represents an exporter message

type MessageFilter

type MessageFilter struct {
	// From is the starting index of the desired data
	From int64 `json:"from"`
	// To is the ending index of the desired data
	To int64 `json:"to"`
	// Role is the duty type enum, optional as it's relevant for IBFT data
	Role DutyRole `json:"role,omitempty"`
	// PublicKey is optional, used for fetching decided messages or information about specific validator/operator
	PublicKey string `json:"publicKey,omitempty"`
}

MessageFilter is a criteria for query in request messages and projection in responses

type MessageType

type MessageType string

MessageType is the type of message being sent

const (
	// TypeValidator is an enum for validator type messages
	TypeValidator MessageType = "validator"
	// TypeOperator is an enum for operator type messages
	TypeOperator MessageType = "operator"
	// TypeDecided is an enum for ibft type messages
	TypeDecided MessageType = "decided"
	// TypeError is an enum for error type messages
	TypeError MessageType = "error"
)

type NetworkMessage

type NetworkMessage struct {
	Msg  Message
	Err  error
	Conn Connection
}

NetworkMessage wraps an actual message with more information

type OperatorsMessage

type OperatorsMessage struct {
	Data []storage.OperatorInformation `json:"data,omitempty"`
}

OperatorsMessage represents message for operators response

type QueryMessageHandler added in v0.1.2

type QueryMessageHandler func(nm *NetworkMessage)

QueryMessageHandler handles the given message

type ValidatorsMessage

type ValidatorsMessage struct {
	Data []storage.ValidatorInformation `json:"data,omitempty"`
}

ValidatorsMessage represents message for validators response

type WSClient added in v0.1.5

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

WSClient represents a client connection to be used in tests

func NewWSClient added in v0.1.5

func NewWSClient(ctx context.Context, logger *zap.Logger) *WSClient

NewWSClient creates a new instance of ws client

func (*WSClient) MessageCount added in v0.1.5

func (client *WSClient) MessageCount() int

MessageCount returns the count of incoming messages

func (*WSClient) StartQuery added in v0.1.5

func (client *WSClient) StartQuery(addr, path string) error

StartQuery initiates query requests

func (*WSClient) StartStream added in v0.1.5

func (client *WSClient) StartStream(addr, path string) error

StartStream initiates stream

type WebSocketServer

type WebSocketServer interface {
	Start(addr string) error
	BroadcastFeed() *event.Feed
	UseQueryHandler(handler QueryMessageHandler)
}

WebSocketServer is responsible for managing all

func NewWsServer

func NewWsServer(ctx context.Context, logger *zap.Logger, handler QueryMessageHandler, mux *http.ServeMux) WebSocketServer

NewWsServer creates a new instance

Jump to

Keyboard shortcuts

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