Documentation
¶
Index ¶
- type BroadcastControl
- type Gauge
- type PeerManager
- func (pm *PeerManager) AvailablePeers() []peer.ID
- func (pm *PeerManager) BroadcastWantHaves(ctx context.Context, wantHaves []cid.Cid)
- func (pm *PeerManager) Connected(p peer.ID)
- func (pm *PeerManager) ConnectedPeers() []peer.ID
- func (pm *PeerManager) CurrentWantBlocks() []cid.Cid
- func (pm *PeerManager) CurrentWantHaves() []cid.Cid
- func (pm *PeerManager) CurrentWants() []cid.Cid
- func (pm *PeerManager) Disconnected(p peer.ID)
- func (pm *PeerManager) MarkBroadcastTarget(from peer.ID)
- func (pm *PeerManager) RegisterSession(p peer.ID, s Session)
- func (pm *PeerManager) ResponseReceived(p peer.ID, ks []cid.Cid)
- func (pm *PeerManager) SendCancels(ctx context.Context, cancelKs []cid.Cid)
- func (pm *PeerManager) SendWants(ctx context.Context, p peer.ID, wantBlocks []cid.Cid, wantHaves []cid.Cid) bool
- func (pm *PeerManager) UnregisterSession(ses uint64)
- type PeerQueue
- type PeerQueueFactory
- type Session
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BroadcastControl ¶ added in v0.32.0
type BroadcastControl struct {
// Enable enables or disables broadcast control.
Enable bool
// Host is the libp2p host used to get peer information.
Host host.Host
// MaxPeers is the hard limit on the number of peers to send broadcasts
// to. A value of 0 means no broadcasts are sent. A value of -1 means there
// is no limit.
MaxPeers int
// LocalPeers enables or disables broadcast control for peers on the local
// network. If false, than always broadcast to peers on the local network.
// If true, apply broadcast reduction to local peers.
LocalPeers bool
// PeeredPeers enables or disables broadcast reduction for peers configured
// for peering. If false, than always broadcast to peers configured for
// peering. If true, apply broadcast reduction to peered peers.
// false (always broadcast to peered peers).
PeeredPeers bool
// MaxRandomPeers is the number of peers to broadcast to anyway, even
// though broadcast reduction logic has determined that they are not
// broadcast targets. Setting this to a non-zero value ensures at least
// this number of random peers receives a broadcast. This may be helpful in
// cases where peers that are not receiving broadcasts may have wanted
// blocks.
MaxRandomPeers int
// SendToPendingPeers, when true, sends broadcasts to any peers that already
// have a pending message to send.
SendToPendingPeers bool
// SkipGauge overrides the Gauge that tracks the number of broadcasts
// skipped by broadcast reduction logic.
SkipGauge Gauge
}
BroadcastControl configures broadcast control functionality.
func (BroadcastControl) NeedHost ¶ added in v0.32.0
func (bc BroadcastControl) NeedHost() bool
NeedHost returns true if the Host is required to support the configuration.
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, bcastControl BroadcastControl) *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) MarkBroadcastTarget ¶ added in v0.32.0
func (pm *PeerManager) MarkBroadcastTarget(from peer.ID)
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) bool
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)
HasMessage() bool
Startup()
Shutdown()
}
PeerQueue provides a queue of messages to be sent for a single peer.
type PeerQueueFactory ¶
PeerQueueFactory provides a function that will create a PeerQueue.