server

package
v0.24.3 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2024 License: Apache-2.0, MIT Imports: 20 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Server)

func EngineBlockstoreWorkerCount

func EngineBlockstoreWorkerCount(count int) Option

EngineBlockstoreWorkerCount sets the number of worker threads used for blockstore operations in the decision engine

func EngineTaskWorkerCount

func EngineTaskWorkerCount(count int) Option

EngineTaskWorkerCount sets the number of worker threads used inside the engine

func MaxCidSize

func MaxCidSize(n uint) Option

MaxCidSize limits how big CIDs we are willing to serve. We will ignore CIDs over this limit. It defaults to defaults.MaxCidSize. If it is 0 no limit is applied.

func MaxOutstandingBytesPerPeer

func MaxOutstandingBytesPerPeer(count int) Option

MaxOutstandingBytesPerPeer describes approximately how much work we are will to have outstanding to a peer at any given time. Setting it to 0 will disable any limiting.

func MaxQueuedWantlistEntriesPerPeer

func MaxQueuedWantlistEntriesPerPeer(count uint) Option

MaxQueuedWantlistEntriesPerPeer limits how much individual entries each peer is allowed to send. If a peer send us more than this we will truncate newest entries. It defaults to defaults.MaxQueuedWantlistEntiresPerPeer.

func SetSendDontHaves

func SetSendDontHaves(send bool) Option

SetSendDontHaves indicates what to do when the engine receives a want-block for a block that is not in the blockstore. Either - Send a DONT_HAVE message - Simply don't respond This option is only used for testing.

func TaskWorkerCount

func TaskWorkerCount(count int) Option

func WithPeerBlockRequestFilter

func WithPeerBlockRequestFilter(pbrf decision.PeerBlockRequestFilter) Option

func WithPeerLedger added in v0.24.3

func WithPeerLedger(peerLedger decision.PeerLedger) Option

WithPeerLedger configures the engine with a custom decision.PeerLedger.

func WithScoreLedger

func WithScoreLedger(scoreLedger decision.ScoreLedger) Option

Configures the engine to use the given score decision logic.

func WithTargetMessageSize

func WithTargetMessageSize(tms int) Option

func WithTaskComparator

func WithTaskComparator(comparator decision.TaskComparator) Option

WithTaskComparator configures custom task prioritization logic.

func WithTracer

func WithTracer(tap tracer.Tracer) Option

func WithWantHaveReplaceSize added in v0.24.3

func WithWantHaveReplaceSize(size int) Option

WithWantHaveReplaceSize sets the maximum size of a block in bytes up to which the bitswap server will replace a WantHave with a WantBlock response.

Behavior:

  • If size > 0: The server may send full blocks instead of just confirming possession for blocks up to the specified size.
  • If size = 0: WantHave replacement is disabled entirely. This allows the server to skip reading block sizes during WantHave request processing, which can be more efficient if the data storage bills "possession" checks and "reads" differently.

Performance considerations:

  • Enabling replacement (size > 0) may reduce network round-trips but requires checking block sizes for each WantHave request to decide if replacement should occur.
  • Disabling replacement (size = 0) optimizes server performance by avoiding block size checks, potentially reducing infrastructure costs if possession checks are less expensive than full reads.

It defaults to defaults.DefaultWantHaveReplaceSize and the value may change in future releases.

Use this option to set explicit behavior to balance between network efficiency, server performance, and potential storage cost optimizations based on your specific use case and storage backend.

type PeerBlockRequestFilter

type PeerBlockRequestFilter = decision.PeerBlockRequestFilter

type PeerEntry added in v0.24.3

type PeerEntry = decision.PeerEntry

type PeerLedger added in v0.24.3

type PeerLedger = decision.PeerLedger

type Receipt

type Receipt = decision.Receipt

type ScoreLedger

type ScoreLedger = decision.ScoreLedger

type ScorePeerFunc

type ScorePeerFunc = decision.ScorePeerFunc

type Server

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

func New

func New(ctx context.Context, network bsnet.BitSwapNetwork, bstore blockstore.Blockstore, options ...Option) *Server

func (*Server) Close

func (bs *Server) Close()

Close is called to shutdown the Server. Returns when all workers and decision engine have finished. Safe to calling multiple times/concurrently.

func (*Server) LedgerForPeer

func (bs *Server) LedgerForPeer(p peer.ID) *decision.Receipt

LedgerForPeer returns aggregated data about blocks swapped and communication with a given peer.

func (*Server) NotifyNewBlocks

func (bs *Server) NotifyNewBlocks(ctx context.Context, blks ...blocks.Block) error

NotifyNewBlocks announces the existence of blocks to this bitswap service. The service will potentially notify its peers. Bitswap itself doesn't store new blocks. It's the caller responsibility to ensure that those blocks are available in the blockstore before calling this function.

func (*Server) PeerConnected

func (bs *Server) PeerConnected(p peer.ID)

func (*Server) PeerDisconnected

func (bs *Server) PeerDisconnected(p peer.ID)

func (*Server) ReceiveError

func (*Server) ReceiveError(err error)

func (*Server) ReceiveMessage

func (bs *Server) ReceiveMessage(ctx context.Context, p peer.ID, incoming message.BitSwapMessage)

func (*Server) ReceivedBlocks

func (bs *Server) ReceivedBlocks(from peer.ID, blks []blocks.Block)

ReceivedBlocks notify the decision engine that a peer is well behaving and gave us usefull data, potentially increasing it's score and making us send them more data in exchange.

func (*Server) Stat

func (bs *Server) Stat() (Stat, error)

Stat returns aggregated statistics about bitswap operations

func (*Server) WantlistForPeer

func (bs *Server) WantlistForPeer(p peer.ID) []cid.Cid

WantlistForPeer returns the currently understood list of blocks requested by a given peer.

type Stat

type Stat struct {
	Peers      []string
	BlocksSent uint64
	DataSent   uint64
}

type TaskComparator

type TaskComparator = decision.TaskComparator

type TaskInfo

type TaskInfo = decision.TaskInfo

Directories

Path Synopsis
internal
decision
Package decision implements the decision engine for the bitswap service.
Package decision implements the decision engine for the bitswap service.

Jump to

Keyboard shortcuts

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