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: 24 Imported by: 0

Documentation

Index

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

func (peer *Peer) GetRemoteAddress() net.Addr

GetRemoteAddress returns the remote address of the peer

func (*Peer) Handshake

func (peer *Peer) Handshake(sourceNodeInfo *p2ptypes.NodeInfo) error

Handshake handles the initial signaling between two peers NOTE: need to call peer.Handshake() before peer.Start()

func (*Peer) ID

func (peer *Peer) ID() string

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

func (*Peer) IsOutbound

func (peer *Peer) IsOutbound() bool

IsOutbound returns whether the peer is an outbound peer

func (*Peer) IsPersistent

func (peer *Peer) IsPersistent() bool

IsPersistent returns whether the peer is persistent

func (*Peer) IsSeed

func (peer *Peer) IsSeed() bool

IsSeed returns whether the peer is a seed peer

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

func (peer *Peer) SetPersistency(persistent bool)

SetPersistency sets the persistency for the given peer

func (*Peer) SetPort

func (peer *Peer) SetPort(port uint16)

SetPort sets the network port of the peer

func (*Peer) SetSeed

func (peer *Peer) SetSeed(isSeed bool)

SetSeed sets the isSeed for the given peer

func (*Peer) Start

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

Start is called when the peer starts NOTE: need to call peer.Handshake() before peer.Start()

func (*Peer) Stop

func (peer *Peer) Stop()

Stop is called when the peer stops

func (*Peer) Wait

func (peer *Peer) Wait()

Wait suspends the caller goroutine

type PeerConfig

type PeerConfig struct {
	HandshakeTimeout time.Duration
	DialTimeout      time.Duration
}

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

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

AddPeer adds the given peer to the PeerTable

func (*PeerTable) DeletePeer

func (pt *PeerTable) DeletePeer(peerID string)

DeletePeer deletes the given peer from the PeerTable

func (*PeerTable) GetAllPeers

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

GetAllPeers returns all the peers

func (*PeerTable) GetPeer

func (pt *PeerTable) GetPeer(peerID string) *Peer

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

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() (peerIDAddrs []PeerIDAddress)

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

func (pt *PeerTable) PeerAddrExists(addr *nu.NetAddress) bool

PeerAddrExists indicates whether the PeerTable has a peer for the given address

func (*PeerTable) PeerExists

func (pt *PeerTable) PeerExists(peerID string) bool

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

func (*PeerTable) PurgeOldestPeer

func (pt *PeerTable) PurgeOldestPeer() *Peer

PurgeOldestPeer purges the oldest peer from the PeerTable

func (*PeerTable) RetrievePreviousPeers

func (pt *PeerTable) RetrievePreviousPeers() ([]*nu.NetAddress, error)

Jump to

Keyboard shortcuts

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