session

package
v0.4.11 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2023 License: Apache-2.0, MIT Imports: 16 Imported by: 0

Documentation

Index

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(ctx context.Context, peerId peer.ID, wantBlocks []cid.Cid, wantHaves []cid.Cid)
	// BroadcastWantHaves sends want-haves to all connected peers (used for
	// session discovery)
	BroadcastWantHaves(context.Context, []cid.Cid)
	// SendCancels tells the PeerManager to send cancels to all peers
	SendCancels(context.Context, []cid.Cid)
}

PeerManager keeps track of which sessions are interested in which peers and takes care of sending wants for the sessions

type ProviderFinder

type ProviderFinder interface {
	// FindProvidersAsync searches for peers that provide the given CID
	FindProvidersAsync(ctx context.Context, k cid.Cid) <-chan peer.ID
}

ProviderFinder is used to find providers for a given key

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.

func New

func New(
	ctx context.Context,
	sm SessionManager,
	id uint64,
	sprm SessionPeerManager,
	providerFinder ProviderFinder,
	sim *bssim.SessionInterestManager,
	pm PeerManager,
	bpm *bsbpm.BlockPresenceManager,
	notif notifications.PubSub,
	initialSearchDelay time.Duration,
	periodicSearchDelay delay.D,
	self peer.ID) *Session

New creates a new bitswap session whose lifetime is bounded by the given context.

func (*Session) GetBlock

func (s *Session) GetBlock(ctx context.Context, k cid.Cid) (blocks.Block, error)

GetBlock fetches a single block.

func (*Session) GetBlocks

func (s *Session) GetBlocks(ctx context.Context, keys []cid.Cid) (<-chan blocks.Block, error)

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

func (s *Session) ID() uint64

func (*Session) ReceiveFrom

func (s *Session) ReceiveFrom(from peer.ID, ks []cid.Cid, haves []cid.Cid, dontHaves []cid.Cid)

ReceiveFrom receives incoming blocks from the given peer.

func (*Session) SetBaseTickDelay

func (s *Session) SetBaseTickDelay(baseTickDelay time.Duration)

SetBaseTickDelay changes the rate at which ticks happen.

func (*Session) Shutdown

func (s *Session) Shutdown()

type SessionManager

type SessionManager interface {
	// Remove a session (called when the session shuts down)
	RemoveSession(sesid uint64)
	// Cancel 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 the SessionPeerManager
	Shutdown()
	// Adds a peer to the session, returning true if the peer is new
	AddPeer(peer.ID) bool
	// Removes a peer from the session, returning true if the peer existed
	RemovePeer(peer.ID) bool
	// All peers in the session
	Peers() []peer.ID
	// Whether there are any peers in the session
	HasPeers() bool
	// Protect 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

Jump to

Keyboard shortcuts

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