p2p

package
v0.0.0-...-fb4f826 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const DiscoveryServiceTag = "chatroom"
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(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(data []byte) ([]byte, error)

func (*BlockReqHandler) Type

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

type ChatMessage

type ChatMessage []byte

type ChatRoom

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

ChatRoom represents a subscription to a single PubSub topic. Messages can be published to the topic with ChatRoom.Publish, and received messages are pushed to the emitter.Emitter.

func JoinChatRoom

func JoinChatRoom(ctx context.Context, ps *pubsub.PubSub, selfID peer.ID) (*ChatRoom, error)

JoinChatRoom tries to subscribe to the PubSub topic, returning a ChatRoom on success.

func (*ChatRoom) Publish

func (cr *ChatRoom) Publish(message ChatMessage) error

Publish sends a message to the pubsub topic.

type Host

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

func NewHost

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

func (*Host) Close

func (host *Host) Close()

func (*Host) ConnectPeer

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

func (*Host) JoinChatRoom

func (host *Host) JoinChatRoom() error

func (*Host) RoleStore

func (host *Host) RoleStore() RoleStore

func (*Host) SetLeader

func (host *Host) SetLeader(idx int)

func (*Host) SetRoleStore

func (host *Host) SetRoleStore(roleStore RoleStore)

func (*Host) SubscribePointMsg

func (host *Host) SubscribePointMsg() *emitter.Subscription

func (*Host) SubscribeTopicMsg

func (host *Host) SubscribeTopicMsg() *emitter.Subscription

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
)

func (MsgType) String

func (t MsgType) String() string

type Peer

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

Peer type

func NewPeer

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

func (*Peer) PointAddr

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

PointAddr return point 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) TopicAddr

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

TopicAddr return topic address of peer

func (*Peer) WriteMsg

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

type PeerStatus

type PeerStatus int8

PeerStatus type

const (
	PeerStatusDisconnected PeerStatus = iota
	PeerStatusConnecting
	PeerStatusConnected
)

PeerStatus

type PeerStore

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

func NewPeerStore

func NewPeerStore(host *Host) *PeerStore

func (*PeerStore) Delete

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

func (*PeerStore) IsValidID

func (s *PeerStore) IsValidID(id peer.ID) bool

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

func (*PeerStore) StoredPeers

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

type PointMsg

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

type QCReqHandler

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

func (*QCReqHandler) HandleReq

func (hdlr *QCReqHandler) HandleReq(data []byte) ([]byte, error)

func (*QCReqHandler) Type

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

type ReqHandler

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

type RoleStore

type RoleStore interface {
	Load(pubKey *core.PublicKey) *Peer
	Store(p *Peer) *Peer
	StoredPeers() []*Peer
	AllPeers() []*Peer
	IsValidID(id peer.ID) bool
}

type TxListReqHandler

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

func (*TxListReqHandler) HandleReq

func (hdlr *TxListReqHandler) HandleReq(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