providerquerymanager

package
v0.40.0 Latest Latest
Warning

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

Go to latest
Published: May 26, 2026 License: Apache-2.0, MIT Imports: 15 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// DefaultMaxInProcessRequests is the default maximum number of requests
	// that are processed concurrently. A value of 0 means unlimited.
	DefaultMaxInProcessRequests = 8
	// DefaultMaxProviders is the default maximum number of providers that are
	// looked up per find request. 0 value means unlimited.
	DefaultMaxProviders = 0
	// DefaultTimeout is the limit on the amount of time to spend waiting for
	// the maximum number of providers from a find request.
	DefaultTimeout = 10 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*ProviderQueryManager) error

func WithFindPeerFallback added in v0.40.0

func WithFindPeerFallback(pr ProviderQueryPeerRouter) Option

WithFindPeerFallback enables a one-shot FindPeer fallback: when the first dial to a provider fails, the manager asks the supplied peer router for fresh addresses and retries the dial once, but only if FindPeer returned at least one address that wasn't already in the routing-record AddrInfo just attempted. This rescues providers whose routing-record snapshot is thin or stale but whose actual addresses can still be reached, without wasting a retry when the peer router would only hand back the same set.

Pass nil (or omit the option) to disable. Typically wired with a DHT client, e.g. WithFindPeerFallback(myDHT).

func WithIgnoreProviders added in v0.29.0

func WithIgnoreProviders(peers ...peer.ID) Option

WithIgnoreProviders will ignore provider records from the given peers.

func WithMaxInProcessRequests

func WithMaxInProcessRequests(count int) Option

WithMaxInProcessRequests sets maximum number of requests that are processed concurrently. A value of 0 means unlimited. Default is DefaultMaxInProcessRequests.

func WithMaxProviders

func WithMaxProviders(count int) Option

WithMaxProviders sets the maximum number of providers that are looked up per find request. Only providers that we can connect to are returned. Defaults to 0, which means unlimited.

func WithMaxTimeout

func WithMaxTimeout(timeout time.Duration) Option

WithMaxTimeout sets the limit on the amount of time to spend waiting for the maximum number of providers from a find request.

type ProviderQueryDialer

type ProviderQueryDialer interface {
	Connect(context.Context, peer.AddrInfo) error
}

ProviderQueryDialer is an interface for connecting to peers. Usually a libp2p.Host

type ProviderQueryManager

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

ProviderQueryManager manages requests to find more providers for blocks for bitswap sessions. It's main goals are to: - rate limit requests -- don't have too many find provider calls running simultaneously - connect to found peers and filter them if it can't connect - ensure two findprovider calls for the same block don't run concurrently - manage timeouts

func New

New initializes a new ProviderQueryManager for a given context and a given network provider.

func (*ProviderQueryManager) Close

func (pqm *ProviderQueryManager) Close()

func (*ProviderQueryManager) FindProvidersAsync

func (pqm *ProviderQueryManager) FindProvidersAsync(sessionCtx context.Context, k cid.Cid, max int) <-chan peer.AddrInfo

FindProvidersAsync finds providers for the given block. The max parameter controls how many will be returned at most. For a provider to be returned, we must have successfully connected to it. Setting max to 0 will use the configured MaxProviders which defaults to 0 (unbounded).

type ProviderQueryPeerRouter added in v0.40.0

type ProviderQueryPeerRouter interface {
	FindPeer(context.Context, peer.ID) (peer.AddrInfo, error)
}

ProviderQueryPeerRouter is the subset of routing.PeerRouting used by the FindPeer fallback configured with WithFindPeerFallback: when a dial to a provider fails, the manager asks for fresh addresses for that peer and retries the dial once, but only if FindPeer returned at least one address that wasn't already in the routing-record AddrInfo. Typically satisfied by a kademlia DHT client.

Jump to

Keyboard shortcuts

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