network

package
v0.18.2 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2024 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PeerMessageTypePing               = 1
	PeerMessageTypeAuthentication     = 3
	PeerMessageTypeGraph              = 4
	PeerMessageTypeSnapshotConfirm    = 5
	PeerMessageTypeTransactionRequest = 6
	PeerMessageTypeTransaction        = 7

	PeerMessageTypeSnapshotAnnouncement = 10 // leader send snapshot to peer
	PeerMessageTypeSnapshotCommitment   = 11 // peer generate ri based, send Ri to leader
	PeerMessageTypeTransactionChallenge = 12 // leader send bitmask Z and aggregated R to peer
	PeerMessageTypeSnapshotResponse     = 13 // peer generate A from nodes and Z, send response si = ri + H(R || A || M)ai to leader
	PeerMessageTypeSnapshotFinalization = 14 // leader generate A, verify si B = ri B + H(R || A || M)ai B = Ri + H(R || A || M)Ai, then finalize based on threshold
	PeerMessageTypeCommitments          = 15
	PeerMessageTypeFullChallenge        = 16

	PeerMessageTypeBundle          = 100
	PeerMessageTypeGossipNeighbors = 101

	MaxMessageBundleSize = 16
)
View Source
const (
	MaxIncomingStreams = 128
	HandshakeTimeout   = 10 * time.Second
	IdleTimeout        = 60 * time.Second
	ReadDeadline       = 10 * time.Second
	WriteDeadline      = 10 * time.Second
)
View Source
const (
	TransportMessageVersion    = 2
	TransportMessageMaxSize    = 32 * 1024 * 1024
	TransportMessageHeaderSize = 6
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ChanMsg

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

type Client

type Client interface {
	RemoteAddr() net.Addr
	Receive() (*TransportMessage, error)
	Send([]byte) error
	Close() error
}

type MetricPool added in v0.14.9

type MetricPool struct {
	PeerMessageTypePing               uint32 `json:"ping"`
	PeerMessageTypeAuthentication     uint32 `json:"authentication"`
	PeerMessageTypeGraph              uint32 `json:"graph"`
	PeerMessageTypeSnapshotConfirm    uint32 `json:"snapshot-confirm"`
	PeerMessageTypeTransactionRequest uint32 `json:"transaction-request"`
	PeerMessageTypeTransaction        uint32 `json:"transaction"`

	PeerMessageTypeSnapshotAnnouncement uint32 `json:"snapshot-announcement"`
	PeerMessageTypeSnapshotCommitment   uint32 `json:"snapshot-commitment"`
	PeerMessageTypeTransactionChallenge uint32 `json:"transaciton-challenge"`
	PeerMessageTypeSnapshotResponse     uint32 `json:"snapshot-response"`
	PeerMessageTypeSnapshotFinalization uint32 `json:"snapshot-finalization"`
	PeerMessageTypeCommitments          uint32 `json:"commitments"`
	PeerMessageTypeFullChallenge        uint32 `json:"full-challenge"`

	PeerMessageTypeBundle          uint32 `json:"bundle"`
	PeerMessageTypeGossipNeighbors uint32 `json:"gossip-neighbors"`
	// contains filtered or unexported fields
}

func (*MetricPool) String added in v0.14.9

func (mp *MetricPool) String() string

type Peer

type Peer struct {
	IdForNetwork crypto.Hash
	Address      string
	// contains filtered or unexported fields
}

func NewPeer

func NewPeer(handle SyncHandle, idForNetwork crypto.Hash, addr string, gossipNeighbors, enableMetric bool) *Peer

func (*Peer) AddNeighbor

func (me *Peer) AddNeighbor(idForNetwork crypto.Hash, addr string) (*Peer, error)

func (*Peer) ConfirmSnapshotForPeer

func (me *Peer) ConfirmSnapshotForPeer(idForNetwork, snap crypto.Hash)

func (*Peer) ListenNeighbors

func (me *Peer) ListenNeighbors() error

func (*Peer) Metric added in v0.14.9

func (me *Peer) Metric() map[string]*MetricPool

func (*Peer) Neighbors added in v0.12.4

func (me *Peer) Neighbors() []*Peer

func (*Peer) PingNeighbor added in v0.7.25

func (me *Peer) PingNeighbor(addr string) error

func (*Peer) SendCommitmentsMessage added in v0.14.6

func (me *Peer) SendCommitmentsMessage(idForNetwork crypto.Hash, commitments []*crypto.Key) error

func (*Peer) SendFullChallengeMessage added in v0.14.6

func (me *Peer) SendFullChallengeMessage(idForNetwork crypto.Hash, s *common.Snapshot, commitment, challenge *crypto.Key, tx *common.VersionedTransaction) error

func (*Peer) SendSnapshotAnnouncementMessage added in v0.5.0

func (me *Peer) SendSnapshotAnnouncementMessage(idForNetwork crypto.Hash, s *common.Snapshot, R crypto.Key) error

func (*Peer) SendSnapshotCommitmentMessage added in v0.5.0

func (me *Peer) SendSnapshotCommitmentMessage(idForNetwork crypto.Hash, snap crypto.Hash, R crypto.Key, wantTx bool) error

func (*Peer) SendSnapshotConfirmMessage

func (me *Peer) SendSnapshotConfirmMessage(idForNetwork crypto.Hash, snap crypto.Hash) error

func (*Peer) SendSnapshotFinalizationMessage added in v0.5.0

func (me *Peer) SendSnapshotFinalizationMessage(idForNetwork crypto.Hash, s *common.Snapshot) error

func (*Peer) SendSnapshotResponseMessage added in v0.5.0

func (me *Peer) SendSnapshotResponseMessage(idForNetwork crypto.Hash, snap crypto.Hash, si *[32]byte) error

func (*Peer) SendTransactionChallengeMessage added in v0.5.0

func (me *Peer) SendTransactionChallengeMessage(idForNetwork crypto.Hash, snap crypto.Hash, cosi *crypto.CosiSignature, tx *common.VersionedTransaction) error

func (*Peer) SendTransactionMessage

func (me *Peer) SendTransactionMessage(idForNetwork crypto.Hash, ver *common.VersionedTransaction) error

func (*Peer) SendTransactionRequestMessage

func (me *Peer) SendTransactionRequestMessage(idForNetwork crypto.Hash, tx crypto.Hash) error

func (*Peer) Teardown added in v0.8.3

func (me *Peer) Teardown()

type PeerMessage

type PeerMessage struct {
	Type            uint8
	Snapshot        *common.Snapshot
	SnapshotHash    crypto.Hash
	Transaction     *common.VersionedTransaction
	TransactionHash crypto.Hash
	Cosi            crypto.CosiSignature
	Commitment      crypto.Key
	Challenge       crypto.Key
	Response        [32]byte
	WantTx          bool
	Commitments     []*crypto.Key
	Graph           []*SyncPoint
	Data            []byte
	Neighbors       []string
}

type QuicClient

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

func (*QuicClient) Close

func (c *QuicClient) Close() error

func (*QuicClient) Receive

func (c *QuicClient) Receive() (*TransportMessage, error)

func (*QuicClient) RemoteAddr added in v0.4.1

func (c *QuicClient) RemoteAddr() net.Addr

func (*QuicClient) Send

func (c *QuicClient) Send(data []byte) error

type QuicTransport

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

func NewQuicClient

func NewQuicClient(addr string) (*QuicTransport, error)

func NewQuicServer

func NewQuicServer(addr string) (*QuicTransport, error)

func (*QuicTransport) Accept

func (t *QuicTransport) Accept(ctx context.Context) (Client, error)

func (*QuicTransport) Close added in v0.8.3

func (t *QuicTransport) Close() error

func (*QuicTransport) Dial

func (t *QuicTransport) Dial(ctx context.Context) (Client, error)

func (*QuicTransport) Listen

func (t *QuicTransport) Listen() error

type SyncHandle

type SyncHandle interface {
	GetCacheStore() *ristretto.Cache
	BuildLegacyAuthenticationMessage() []byte
	Authenticate(msg []byte) (crypto.Hash, string, error)
	UpdateNeighbors(neighbors []string) error
	BuildLegacyGraph() []*SyncPoint
	UpdateLegacySyncPoint(peerId crypto.Hash, points []*SyncPoint)
	ReadAllNodesWithoutState() []crypto.Hash
	ReadSnapshotsSinceTopology(offset, count uint64) ([]*common.SnapshotWithTopologicalOrder, error)
	ReadSnapshotsForNodeRound(nodeIdWithNetwork crypto.Hash, round uint64) ([]*common.SnapshotWithTopologicalOrder, error)
	SendTransactionToPeer(peerId, tx crypto.Hash) error
	CachePutTransaction(peerId crypto.Hash, ver *common.VersionedTransaction) error
	CosiQueueExternalAnnouncementLegacy(peerId crypto.Hash, s *common.Snapshot, R *crypto.Key) error
	CosiAggregateSelfCommitmentsLegacy(peerId crypto.Hash, snap crypto.Hash, commitment *crypto.Key, wantTx bool) error
	CosiQueueExternalChallenge(peerId crypto.Hash, snap crypto.Hash, cosi *crypto.CosiSignature, ver *common.VersionedTransaction) error
	CosiQueueExternalFullChallenge(peerId crypto.Hash, s *common.Snapshot, commitment, challenge *crypto.Key, cosi *crypto.CosiSignature, ver *common.VersionedTransaction) error
	CosiAggregateSelfResponses(peerId crypto.Hash, snap crypto.Hash, response *[32]byte) error
	VerifyAndQueueAppendSnapshotFinalization(peerId crypto.Hash, s *common.Snapshot) error
	CosiQueueExternalCommitmentsLegacy(peerId crypto.Hash, commitments []*crypto.Key) error
}

type SyncPoint

type SyncPoint struct {
	NodeId crypto.Hash `json:"node"`
	Number uint64      `json:"round"`
	Hash   crypto.Hash `json:"hash"`
	Pool   any         `json:"pool"`
}

type Transport

type Transport interface {
	Listen() error
	Dial(ctx context.Context) (Client, error)
	Accept(ctx context.Context) (Client, error)
	Close() error
}

type TransportMessage

type TransportMessage struct {
	Version uint8
	Size    uint32
	Data    []byte
}

Jump to

Keyboard shortcuts

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