p2p

package
v0.18.21 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2024 License: GPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PeerMessageTypePing               = 1 // not used because too more than enough graph sync messages
	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

	PeerMessageTypeRelay     = 200
	PeerMessageTypeConsumers = 201

	MsgPriorityNormal = 0
	MsgPriorityHigh   = 1
)
View Source
const (
	MaxIncomingStreams = 1024
	HandshakeTimeout   = 10 * time.Second
	IdleTimeout        = 60 * time.Second
	WriteDeadline      = 10 * time.Second
	ReadDeadline       = 2 * WriteDeadline
)
View Source
const (
	TransportMessageVersion    = 2
	TransportMessageMaxSize    = 32 * 1024 * 1024
	TransportMessageHeaderSize = 6
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthToken

type AuthToken struct {
	PeerId    crypto.Hash
	Timestamp uint64
	IsRelayer bool
	Data      []byte
}

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(string) error
}

type MetricPool

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"`

	PeerMessageTypeRelay uint32 `json:"relay"`
	// contains filtered or unexported fields
}

func (*MetricPool) String

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, isRelayer bool) *Peer

func (*Peer) ConfirmSnapshotForPeer

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

func (*Peer) ConnectRelayer

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

func (*Peer) GetNeighbors added in v0.18.11

func (me *Peer) GetNeighbors(key crypto.Hash) []*Peer

func (*Peer) GetRemoteRelayers added in v0.18.10

func (me *Peer) GetRemoteRelayers(key crypto.Hash) []*Peer

func (*Peer) IsRelayer added in v0.18.10

func (me *Peer) IsRelayer() bool

func (*Peer) ListenConsumers

func (me *Peer) ListenConsumers() error

func (*Peer) Metric

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

func (*Peer) Neighbors

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

func (*Peer) SendCommitmentsMessage

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

func (*Peer) SendFullChallengeMessage

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

func (*Peer) SendGraphMessage

func (me *Peer) SendGraphMessage(idForNetwork crypto.Hash) error

func (*Peer) SendSnapshotAnnouncementMessage

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

func (*Peer) SendSnapshotCommitmentMessage

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

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

func (*Peer) SendSnapshotResponseMessage

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

func (*Peer) SendTransactionChallengeMessage

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

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
	// contains filtered or unexported fields
}

type QuicClient

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

func NewQuicConsumer

func NewQuicConsumer(ctx context.Context, relayer string) (*QuicClient, error)

func (*QuicClient) Close

func (c *QuicClient) Close(code string) error

func (*QuicClient) Receive

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

func (*QuicClient) RemoteAddr

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

func (*QuicClient) Send

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

type QuicRelayer

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

func NewQuicRelayer

func NewQuicRelayer(listenAddr string) (*QuicRelayer, error)

func (*QuicRelayer) Accept

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

func (*QuicRelayer) Close

func (t *QuicRelayer) Close() error

type SyncHandle

type SyncHandle interface {
	GetCacheStore() *ristretto.Cache[[]byte, any]
	SignData(data []byte) crypto.Signature
	BuildAuthenticationMessage(relayerId crypto.Hash) []byte
	AuthenticateAs(recipientId crypto.Hash, msg []byte, timeoutSec int64) (*AuthToken, error)
	BuildGraph() []*SyncPoint
	UpdateSyncPoint(peerId crypto.Hash, points []*SyncPoint, data []byte, sig *crypto.Signature) error
	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
	CosiQueueExternalAnnouncement(peerId crypto.Hash, s *common.Snapshot, R *crypto.Key, sig *crypto.Signature) error
	CosiAggregateSelfCommitments(peerId crypto.Hash, snap crypto.Hash, commitment *crypto.Key, wantTx bool, data []byte, sig *crypto.Signature) 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
	CosiQueueExternalCommitments(peerId crypto.Hash, commitments []*crypto.Key, data []byte, sig *crypto.Signature) 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