peer

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2022 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

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 CreatePeer

func CreatePeer(addrInfo pr.AddrInfo, isOutbound bool) *Peer

func (*Peer) AcceptStream

func (peer *Peer) AcceptStream(channel cmn.ChannelIDEnum, stream *transport.BufferedStream)

func (*Peer) AddrInfo

func (peer *Peer) AddrInfo() pr.AddrInfo

AddrInfo returns the addrInfo of the peer in the P2P network

func (*Peer) Addrs

func (peer *Peer) Addrs() []ma.Multiaddr

Addrs returns the Multiaddresses of the peer in the P2P network

func (*Peer) ID

func (peer *Peer) ID() pr.ID

ID returns the unique idenitifier of the peer in the P2P network

func (*Peer) OpenStreams

func (peer *Peer) OpenStreams() error

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) Start

func (peer *Peer) Start(ctx context.Context) bool

Start is called when the peer starts

func (*Peer) Stop

func (peer *Peer) Stop()

Stop is called when the peer stops

func (*Peer) StopStream

func (peer *Peer) StopStream(channel cmn.ChannelIDEnum)

func (*Peer) Wait

func (peer *Peer) Wait()

Wait suspends the caller goroutine

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) AddPeer

func (pt *PeerTable) AddPeer(peer *Peer) bool

AddPeer adds the given peer to the PeerTable

func (*PeerTable) DeletePeer

func (pt *PeerTable) DeletePeer(peerID pr.ID)

DeletePeer deletes the given peer from the PeerTable

func (*PeerTable) GetAllPeerIDs

func (pt *PeerTable) GetAllPeerIDs() *[]pr.ID

GetAllPeers returns all the peers

func (*PeerTable) GetAllPeers

func (pt *PeerTable) GetAllPeers() *([]*Peer)

GetAllPeers returns all the peers

func (*PeerTable) GetPeer

func (pt *PeerTable) GetPeer(peerID pr.ID) *Peer

GetPeer returns the peer for the given peerID (if exists)

func (*PeerTable) GetSelection

func (pt *PeerTable) GetSelection() (peerIDAddrs []pr.ID)

GetSelection randomly selects some peers. Suitable for peer-exchange protocols.

func (*PeerTable) GetTotalNumPeers

func (pt *PeerTable) GetTotalNumPeers() uint

GetTotalNumPeers returns the total number of peers in the PeerTable

func (*PeerTable) PeerExists

func (pt *PeerTable) PeerExists(peerID pr.ID) bool

PeerExists indicates whether the PeerTable has a peer for the given peerID

func (*PeerTable) RetrievePreviousPeers

func (pt *PeerTable) RetrievePreviousPeers() (res []*pr.AddrInfo, err error)

type RawStreamCreator

type RawStreamCreator func(channelID cmn.ChannelIDEnum) (network.Stream, error)

RawStreamCreator creates a raw libp2p stream with this peer

type ReceiveHandler

type ReceiveHandler func(message p2ptypes.Message) error

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

Jump to

Keyboard shortcuts

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