Documentation ¶
Index ¶
- type Peer
- func (peer *Peer) AttemptToSend(channelID cmn.ChannelIDEnum, message interface{}) bool
- func (peer *Peer) CanSend(channelID cmn.ChannelIDEnum) bool
- func (peer *Peer) CancelConnection()
- func (peer *Peer) GetConnection() *cn.Connection
- func (peer *Peer) GetRemoteAddress() net.Addr
- func (peer *Peer) Handshake(sourceNodeInfo *p2ptypes.NodeInfo) error
- func (peer *Peer) ID() string
- func (peer *Peer) IsOutbound() bool
- func (peer *Peer) IsPersistent() bool
- func (peer *Peer) IsSeed() bool
- func (peer *Peer) NetAddress() *nu.NetAddress
- func (peer *Peer) NodeType() cmn.NodeType
- func (peer *Peer) Send(channelID cmn.ChannelIDEnum, message interface{}) bool
- func (peer *Peer) SetNetAddress(netAddr *nu.NetAddress)
- func (peer *Peer) SetPersistency(persistent bool)
- func (peer *Peer) SetPort(port uint16)
- func (peer *Peer) SetSeed(isSeed bool)
- func (peer *Peer) Start(ctx context.Context) bool
- func (peer *Peer) Stop()
- func (peer *Peer) Wait()
- type PeerConfig
- type PeerIDAddress
- type PeerTable
- func (pt *PeerTable) AddPeer(peer *Peer) bool
- func (pt *PeerTable) DeletePeer(peerID string)
- func (pt *PeerTable) GetAllPeers(skipEdgeNode bool) *([]*Peer)
- func (pt *PeerTable) GetPeer(peerID string) *Peer
- func (pt *PeerTable) GetPeerWithAddr(addr *nu.NetAddress) *Peer
- func (pt *PeerTable) GetSelection(skipEdgeNode bool) (peerIDAddrs []PeerIDAddress)
- func (pt *PeerTable) GetTotalNumPeers(skipEdgeNode bool) uint
- func (pt *PeerTable) PeerAddrExists(addr *nu.NetAddress) bool
- func (pt *PeerTable) PeerExists(peerID string) bool
- func (pt *PeerTable) PurgeOldestPeer() *Peer
- func (pt *PeerTable) RetrievePreviousPeers() ([]*nu.NetAddress, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Peer ¶
type Peer struct {
// contains filtered or unexported fields
}
Peer models a peer node in a network
func CreateInboundPeer ¶
func CreateInboundPeer(netconn net.Conn, peerConfig PeerConfig, connConfig cn.ConnectionConfig) (*Peer, error)
CreateInboundPeer creates an instance of an inbound peer
func CreateOutboundPeer ¶
func CreateOutboundPeer(peerAddr *nu.NetAddress, peerConfig PeerConfig, connConfig cn.ConnectionConfig) (*Peer, error)
CreateOutboundPeer creates an instance of an outbound peer
func (*Peer) AttemptToSend ¶
func (peer *Peer) AttemptToSend(channelID cmn.ChannelIDEnum, message interface{}) bool
AttemptToSend attempts to send the given message through the specified channel to the target peer (non-blocking)
func (*Peer) CanSend ¶
func (peer *Peer) CanSend(channelID cmn.ChannelIDEnum) bool
CanSend indicates whether more messages can be sent through the specified channel
func (*Peer) CancelConnection ¶
func (peer *Peer) CancelConnection()
CancelConnection for testing purpose only
func (*Peer) GetConnection ¶
func (peer *Peer) GetConnection() *cn.Connection
GetConnection returns the connection object attached to the peer
func (*Peer) GetRemoteAddress ¶
GetRemoteAddress returns the remote address of the peer
func (*Peer) Handshake ¶
Handshake handles the initial signaling between two peers NOTE: need to call peer.Handshake() before peer.Start()
func (*Peer) IsOutbound ¶
IsOutbound returns whether the peer is an outbound peer
func (*Peer) IsPersistent ¶
IsPersistent returns whether the peer is persistent
func (*Peer) NetAddress ¶
func (peer *Peer) NetAddress() *nu.NetAddress
NetAddress returns the network address of the peer
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) SetNetAddress ¶
func (peer *Peer) SetNetAddress(netAddr *nu.NetAddress)
SetNetAddress sets the network address of the peer
func (*Peer) SetPersistency ¶
SetPersistency sets the persistency for the given peer
type PeerConfig ¶
PeerConfig specifies the configuration of a peer
func GetDefaultPeerConfig ¶
func GetDefaultPeerConfig() PeerConfig
GetDefaultPeerConfig creates the default PeerConfig
type PeerIDAddress ¶
type PeerIDAddress struct { ID string Addr *nu.NetAddress }
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) GetAllPeers ¶
GetAllPeers returns all the peers
func (*PeerTable) GetPeerWithAddr ¶
func (pt *PeerTable) GetPeerWithAddr(addr *nu.NetAddress) *Peer
GetPeerWithAddr returns the peer for the given address (if exists)
func (*PeerTable) GetSelection ¶
func (pt *PeerTable) GetSelection(skipEdgeNode bool) (peerIDAddrs []PeerIDAddress)
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) PeerAddrExists ¶
func (pt *PeerTable) PeerAddrExists(addr *nu.NetAddress) bool
PeerAddrExists indicates whether the PeerTable has a peer for the given address
func (*PeerTable) PeerExists ¶
PeerExists indicates whether the PeerTable has a peer for the given peerID
func (*PeerTable) PurgeOldestPeer ¶
PurgeOldestPeer purges the oldest peer from the PeerTable
func (*PeerTable) RetrievePreviousPeers ¶
func (pt *PeerTable) RetrievePreviousPeers() ([]*nu.NetAddress, error)