p2p

package
v0.0.0-...-3b47f62 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// message size limit in bytes (~100 MB)
	// to avoid out of memory allocation for reading next message
	MessageSizeLimit uint32 = 100000000
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockByHeightReqHandler

type BlockByHeightReqHandler struct {
	GetBlockByHeight func(height uint64) (*core.Block, error)
}

func (*BlockByHeightReqHandler) HandleReq

func (hdlr *BlockByHeightReqHandler) HandleReq(sender *core.PublicKey, data []byte) ([]byte, error)

func (*BlockByHeightReqHandler) Type

type BlockReqHandler

type BlockReqHandler struct {
	GetBlock func(hash []byte) (*core.Block, error)
}

func (*BlockReqHandler) HandleReq

func (hdlr *BlockReqHandler) HandleReq(sender *core.PublicKey, data []byte) ([]byte, error)

func (*BlockReqHandler) Type

func (hdlr *BlockReqHandler) Type() pb.Request_Type

type Host

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

func NewHost

func NewHost(privKey *core.PrivateKey, localAddr multiaddr.Multiaddr) (*Host, error)

func (*Host) AddPeer

func (host *Host) AddPeer(peer *Peer)

func (*Host) PeerStore

func (host *Host) PeerStore() *PeerStore

type MsgService

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

func NewMsgService

func NewMsgService(host *Host) *MsgService

func (*MsgService) BroadcastProposal

func (svc *MsgService) BroadcastProposal(blk *core.Block) error

func (*MsgService) BroadcastQC

func (svc *MsgService) BroadcastQC(qc *core.QuorumCert) error

func (*MsgService) BroadcastTxList

func (svc *MsgService) BroadcastTxList(txList *core.TxList) error

func (*MsgService) RequestBlock

func (svc *MsgService) RequestBlock(pubKey *core.PublicKey, hash []byte) (*core.Block, error)

func (*MsgService) RequestBlockByHeight

func (svc *MsgService) RequestBlockByHeight(pubKey *core.PublicKey, height uint64) (*core.Block, error)

func (*MsgService) RequestQC

func (svc *MsgService) RequestQC(pubKey *core.PublicKey, blkHash []byte) (*core.QuorumCert, error)

func (*MsgService) RequestTxList

func (svc *MsgService) RequestTxList(pubKey *core.PublicKey, hashes [][]byte) (*core.TxList, error)

func (*MsgService) SendQC

func (svc *MsgService) SendQC(pubKey *core.PublicKey, qc *core.QuorumCert) error

func (*MsgService) SendVote

func (svc *MsgService) SendVote(pubKey *core.PublicKey, vote *core.Vote) error

func (*MsgService) SetReqHandler

func (svc *MsgService) SetReqHandler(reqHandler ReqHandler) error

func (*MsgService) SubscribeProposal

func (svc *MsgService) SubscribeProposal(buffer int) *emitter.Subscription

func (*MsgService) SubscribeQC

func (svc *MsgService) SubscribeQC(buffer int) *emitter.Subscription

func (*MsgService) SubscribeTxList

func (svc *MsgService) SubscribeTxList(buffer int) *emitter.Subscription

func (*MsgService) SubscribeVote

func (svc *MsgService) SubscribeVote(buffer int) *emitter.Subscription

type MsgType

type MsgType byte
const (
	MsgTypeProposal MsgType
	MsgTypeVote
	MsgTypeQC
	MsgTypeTxList
	MsgTypeRequest
	MsgTypeResponse
)

type Peer

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

Peer type

func NewPeer

func NewPeer(pubKey *core.PublicKey, addr multiaddr.Multiaddr) *Peer

NewPeer godoc

func (*Peer) Addr

func (p *Peer) Addr() multiaddr.Multiaddr

Addr return network address of peer

func (*Peer) PublicKey

func (p *Peer) PublicKey() *core.PublicKey

PublicKey returns public key of peer

func (*Peer) Status

func (p *Peer) Status() PeerStatus

func (*Peer) SubscribeMsg

func (p *Peer) SubscribeMsg() *emitter.Subscription

func (*Peer) WriteMsg

func (p *Peer) WriteMsg(msg []byte) error

type PeerStatus

type PeerStatus int8

PeerStatus type

const (
	PeerStatusDisconnected PeerStatus = iota
	PeerStatusConnecting
	PeerStatusConnected
	PeerStatusBlocked
)

PeerStatus

type PeerStore

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

func NewPeerStore

func NewPeerStore() *PeerStore

func (*PeerStore) Delete

func (s *PeerStore) Delete(pubKey *core.PublicKey) *Peer

func (*PeerStore) List

func (s *PeerStore) List() []*Peer

func (*PeerStore) Load

func (s *PeerStore) Load(pubKey *core.PublicKey) *Peer

func (*PeerStore) LoadOrStore

func (s *PeerStore) LoadOrStore(p *Peer) (actual *Peer, loaded bool)

func (*PeerStore) Store

func (s *PeerStore) Store(p *Peer) *Peer

type QCReqHandler

type QCReqHandler struct {
	GetQC func(blkHash []byte) (*core.QuorumCert, error)
}

func (*QCReqHandler) HandleReq

func (hdlr *QCReqHandler) HandleReq(sender *core.PublicKey, data []byte) ([]byte, error)

func (*QCReqHandler) Type

func (hdlr *QCReqHandler) Type() pb.Request_Type

type ReqHandler

type ReqHandler interface {
	Type() pb.Request_Type
	HandleReq(sender *core.PublicKey, data []byte) ([]byte, error)
}

type TxListReqHandler

type TxListReqHandler struct {
	GetTxList func(hashes [][]byte) (*core.TxList, error)
}

func (*TxListReqHandler) HandleReq

func (hdlr *TxListReqHandler) HandleReq(sender *core.PublicKey, data []byte) ([]byte, error)

func (*TxListReqHandler) Type

func (hdlr *TxListReqHandler) Type() pb.Request_Type

Jump to

Keyboard shortcuts

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