Documentation ¶
Index ¶
- Variables
- type ErrorHandler
- type MessageEncoder
- type MessageParser
- type Peer
- func (peer *Peer) AcceptStream(channel cmn.ChannelIDEnum, stream *transport.BufferedStream)
- func (peer *Peer) AddrInfo() pr.AddrInfo
- func (peer *Peer) Addrs() []ma.Multiaddr
- func (peer *Peer) ID() pr.ID
- func (peer *Peer) OpenStreams() error
- func (peer *Peer) Send(channelID cmn.ChannelIDEnum, message interface{}) bool
- func (peer *Peer) SetErrorHandler(errorHandler ErrorHandler)
- func (peer *Peer) SetMessageEncoder(messageEncoder MessageEncoder)
- func (peer *Peer) SetMessageParser(messageParser MessageParser)
- func (peer *Peer) SetRawStreamCreator(rawStreamCreator RawStreamCreator)
- func (peer *Peer) SetReceiveHandler(receiveHandler ReceiveHandler)
- func (peer *Peer) SetStreamCreator(streamCreator StreamCreator)
- func (peer *Peer) Start(ctx context.Context) bool
- func (peer *Peer) Stop()
- func (peer *Peer) StopStream(channel cmn.ChannelIDEnum)
- func (peer *Peer) Wait()
- type PeerTable
- func (pt *PeerTable) AddPeer(peer *Peer) bool
- func (pt *PeerTable) DeletePeer(peerID pr.ID)
- func (pt *PeerTable) GetAllPeerIDs() *[]pr.ID
- func (pt *PeerTable) GetAllPeers() *([]*Peer)
- func (pt *PeerTable) GetPeer(peerID pr.ID) *Peer
- func (pt *PeerTable) GetSelection() (peerIDAddrs []pr.ID)
- func (pt *PeerTable) GetTotalNumPeers() uint
- func (pt *PeerTable) PeerExists(peerID pr.ID) bool
- func (pt *PeerTable) RetrievePreviousPeers() (res []*pr.AddrInfo, err error)
- type RawStreamCreator
- type ReceiveHandler
- type StreamCreator
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type ErrorHandler ¶
type ErrorHandler func(interface{})
ErrorHandler is the callback function to handle channel read errors
type MessageEncoder ¶
type MessageEncoder func(channelID cmn.ChannelIDEnum, message interface{}) (cmn.Bytes, error)
MessageEncoder encodes type p2ptypes.Message to raw message bytes
type MessageParser ¶
type MessageParser func(channelID cmn.ChannelIDEnum, rawMessageBytes cmn.Bytes) (p2ptypes.Message, error)
MessageParser parses the raw message bytes to type p2ptypes.Message
type Peer ¶
type Peer struct {
// contains filtered or unexported fields
}
Peer models a peer node in a network
func (*Peer) AcceptStream ¶
func (peer *Peer) AcceptStream(channel cmn.ChannelIDEnum, stream *transport.BufferedStream)
func (*Peer) OpenStreams ¶
func (*Peer) Send ¶
func (peer *Peer) Send(channelID cmn.ChannelIDEnum, message interface{}) bool
Send sends the given message through the specified channel to the target peer
func (*Peer) SetErrorHandler ¶
func (peer *Peer) SetErrorHandler(errorHandler ErrorHandler)
SetErrorHandler sets the error handler for the connection
func (*Peer) SetMessageEncoder ¶
func (peer *Peer) SetMessageEncoder(messageEncoder MessageEncoder)
SetMessageEncoder sets the message encoder for the connection
func (*Peer) SetMessageParser ¶
func (peer *Peer) SetMessageParser(messageParser MessageParser)
SetMessageParser sets the message parser for the connection
func (*Peer) SetRawStreamCreator ¶
func (peer *Peer) SetRawStreamCreator(rawStreamCreator RawStreamCreator)
func (*Peer) SetReceiveHandler ¶
func (peer *Peer) SetReceiveHandler(receiveHandler ReceiveHandler)
SetReceiveHandler sets the receive handler for the connection
func (*Peer) SetStreamCreator ¶
func (peer *Peer) SetStreamCreator(streamCreator StreamCreator)
func (*Peer) StopStream ¶
func (peer *Peer) StopStream(channel cmn.ChannelIDEnum)
type PeerTable ¶
type PeerTable struct {
// contains filtered or unexported fields
}
PeerTable is a lookup table for peers
func CreatePeerTable ¶
func CreatePeerTable() PeerTable
CreatePeerTable creates an instance of the PeerTable
func (*PeerTable) DeletePeer ¶
DeletePeer deletes the given peer from the PeerTable
func (*PeerTable) GetAllPeerIDs ¶
GetAllPeers returns all the peers
func (*PeerTable) GetAllPeers ¶
GetAllPeers returns all the peers
func (*PeerTable) GetSelection ¶
GetSelection randomly selects some peers. Suitable for peer-exchange protocols.
func (*PeerTable) GetTotalNumPeers ¶
GetTotalNumPeers returns the total number of peers in the PeerTable
func (*PeerTable) PeerExists ¶
PeerExists indicates whether the PeerTable has a peer for the given peerID
type RawStreamCreator ¶
type RawStreamCreator func(channelID cmn.ChannelIDEnum) (network.Stream, error)
RawStreamCreator creates a raw libp2p stream with this peer
type ReceiveHandler ¶
ReceiveHandler is the callback function to handle received bytes from the given channel
type StreamCreator ¶
type StreamCreator func(channelID cmn.ChannelIDEnum) (*transport.BufferedStream, error)
StreamCreator creates a buffered stream with this peer