Documentation
¶
Index ¶
- type BlockPresence
- type PeerManager
- type Session
- func (s *Session) Close()
- func (s *Session) GetBlock(ctx context.Context, k cid.Cid) (blocks.Block, error)
- func (s *Session) GetBlocks(ctx context.Context, keys []cid.Cid) (<-chan blocks.Block, error)
- func (s *Session) ID() uint64
- func (s *Session) ReceiveFrom(from peer.ID, ks []cid.Cid, haves []cid.Cid, dontHaves []cid.Cid)
- func (s *Session) SetBaseTickDelay(baseTickDelay time.Duration)
- type SessionManager
- type SessionPeerManager
- type SessionWantsCanceller
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BlockPresence ¶
type BlockPresence int
BlockPresence indicates whether a peer has a block. Note that the order is important, we decide which peer to send a want to based on knowing whether peer has the block. eg we're more likely to send a want to a peer that has the block than a peer that doesnt have the block so BPHave > BPDontHave
const ( BPDontHave BlockPresence = iota BPUnknown BPHave )
type PeerManager ¶
type PeerManager interface {
// RegisterSession tells the PeerManager that the session is interested in
// a peer's connection state.
RegisterSession(peer.ID, bspm.Session)
// UnregisterSession tells the PeerManager that the session is no longer
// interested in a peer's connection state.
UnregisterSession(uint64)
// SendWants tells the PeerManager to send wants to the given peer.
SendWants(peerId peer.ID, wantBlocks []cid.Cid, wantHaves []cid.Cid) bool
// BroadcastWantHaves sends want-haves to all connected peers (used for
// session discovery).
BroadcastWantHaves([]cid.Cid)
// SendCancels tells the PeerManager to send cancels to all peers.
SendCancels([]cid.Cid)
}
PeerManager keeps track of which sessions are interested in which peers and takes care of sending wants for the sessions.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session holds state for an individual bitswap transfer operation. This allows bitswap to make smarter decisions about who to send wantlist info to, and who to request blocks from.
Sessions manage their own lifecycle independently of any request contexts. Each session maintains an internal context for its operations and must be explicitly closed via the Close() method when no longer needed. The session's internal context is used for provider discovery and other long-running operations.
func New ¶
func New( ctx context.Context, sm SessionManager, id uint64, sprm SessionPeerManager, providerFinder routing.ContentDiscovery, sim *bssim.SessionInterestManager, pm PeerManager, bpm *bsbpm.BlockPresenceManager, notif notifications.PubSub, initialSearchDelay time.Duration, periodicSearchDelay time.Duration, self peer.ID, havesReceivedGauge bspm.Gauge, ) *Session
New creates a new bitswap session whose lifetime is bounded by the given context.
The caller MUST call Close() or cancel the context when the session is no longer needed to ensure proper cleanup.
The retrievalState parameter, if provided, enables diagnostic tracking of the retrieval process. It is attached to the session's internal context and used to track provider discovery, connection attempts, and data retrieval phases. This is particularly useful for debugging timeout errors and understanding retrieval performance.
func (*Session) Close ¶ added in v0.35.0
func (s *Session) Close()
Close terminates the session and cleans up its resources. This method must be called, or the context used to create the session must be canceled, when the session is no longer needed to avoid resource leaks. After calling Close, the session should not be used anymore.
func (*Session) GetBlocks ¶
GetBlocks fetches a set of blocks within the context of this session and returns a channel that found blocks will be returned on. No order is guaranteed on the returned blocks.
func (*Session) ReceiveFrom ¶
ReceiveFrom receives incoming blocks from the given peer.
func (*Session) SetBaseTickDelay ¶
SetBaseTickDelay changes the rate at which ticks happen.
type SessionManager ¶
type SessionManager interface {
// RemoveSession removes a session (called when the session shuts down).
RemoveSession(sesid uint64)
// CancelSessionWants cancels the specified session's wants (called when a
// call to GetBlocks() is cancelled).
CancelSessionWants(sid uint64, wants []cid.Cid)
}
SessionManager manages all the sessions,
type SessionPeerManager ¶
type SessionPeerManager interface {
// PeersDiscovered indicates if any peers have been discovered yet,
PeersDiscovered() bool
// Shutdown stops the SessionPeerManager.
Shutdown()
// AddPeer adds a peer to the session, returning true if the peer is new.
AddPeer(peer.ID) bool
// RemovePeer removes a peer from the session, returning true if the peer
// existed.
RemovePeer(peer.ID) bool
// Peers returns all peers in the session.
Peers() []peer.ID
// HasPeers returns true if there are any peers in the session.
HasPeers() bool
// ProtectConnection prevents a connection from being pruned by the
// connection manager.
ProtectConnection(peer.ID)
}
SessionPeerManager keeps track of peers in the session
type SessionWantsCanceller ¶
type SessionWantsCanceller interface {
// Cancel wants for this session
CancelSessionWants(sid uint64, wants []cid.Cid)
}
SessionWantsCanceller provides a method to cancel wants