peermanager

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Gauge

type Gauge interface {
	Inc()
	Dec()
}

Gauge can be used to keep track of a metric that increases and decreases incrementally. It is used by the peerWantManager to track the number of want-blocks that are active (ie sent but no response received)

type PeerManager

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

PeerManager manages a pool of peers and sends messages to peers in the pool.

func New

func New(ctx context.Context, createPeerQueue PeerQueueFactory, self peer.ID) *PeerManager

New creates a new PeerManager, given a context and a peerQueueFactory.

func (*PeerManager) AvailablePeers

func (pm *PeerManager) AvailablePeers() []peer.ID

func (*PeerManager) BroadcastWantHaves

func (pm *PeerManager) BroadcastWantHaves(ctx context.Context, wantHaves []cid.Cid)

BroadcastWantHaves broadcasts want-haves to all peers (used by the session to discover seeds). For each peer it filters out want-haves that have previously been sent to the peer.

func (*PeerManager) Connected

func (pm *PeerManager) Connected(p peer.ID)

Connected is called to add a new peer to the pool, and send it an initial set of wants.

func (*PeerManager) ConnectedPeers

func (pm *PeerManager) ConnectedPeers() []peer.ID

ConnectedPeers returns a list of peers this PeerManager is managing.

func (*PeerManager) CurrentWantBlocks

func (pm *PeerManager) CurrentWantBlocks() []cid.Cid

CurrentWantBlocks returns the list of pending want-blocks

func (*PeerManager) CurrentWantHaves

func (pm *PeerManager) CurrentWantHaves() []cid.Cid

CurrentWantHaves returns the list of pending want-haves

func (*PeerManager) CurrentWants

func (pm *PeerManager) CurrentWants() []cid.Cid

CurrentWants returns the list of pending wants (both want-haves and want-blocks).

func (*PeerManager) Disconnected

func (pm *PeerManager) Disconnected(p peer.ID)

Disconnected is called to remove a peer from the pool.

func (*PeerManager) RegisterSession

func (pm *PeerManager) RegisterSession(p peer.ID, s Session)

RegisterSession tells the PeerManager that the given session is interested in events about the given peer.

func (*PeerManager) ResponseReceived

func (pm *PeerManager) ResponseReceived(p peer.ID, ks []cid.Cid)

ResponseReceived is called when a message is received from the network. ks is the set of blocks, HAVEs and DONT_HAVEs in the message Note that this is just used to calculate latency.

func (*PeerManager) SendCancels

func (pm *PeerManager) SendCancels(ctx context.Context, cancelKs []cid.Cid)

SendCancels sends cancels for the given keys to all peers who had previously received a want for those keys.

func (*PeerManager) SendWants

func (pm *PeerManager) SendWants(ctx context.Context, p peer.ID, wantBlocks []cid.Cid, wantHaves []cid.Cid)

SendWants sends the given want-blocks and want-haves to the given peer. It filters out wants that have previously been sent to the peer.

func (*PeerManager) UnregisterSession

func (pm *PeerManager) UnregisterSession(ses uint64)

UnregisterSession tells the PeerManager that the given session is no longer interested in PeerManager events.

type PeerQueue

type PeerQueue interface {
	AddBroadcastWantHaves([]cid.Cid)
	AddWants([]cid.Cid, []cid.Cid)
	AddCancels([]cid.Cid)
	ResponseReceived(ks []cid.Cid)
	Startup()
	Shutdown()
}

PeerQueue provides a queue of messages to be sent for a single peer.

type PeerQueueFactory

type PeerQueueFactory func(ctx context.Context, p peer.ID) PeerQueue

PeerQueueFactory provides a function that will create a PeerQueue.

type Session

type Session interface {
	ID() uint64
	SignalAvailability(peer.ID, bool)
}

Jump to

Keyboard shortcuts

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