ipfs / boxo

A set of reference libraries for building IPFS applications and implementations in Go.
https://github.com/ipfs/boxo#readme
Other
189 stars 86 forks source link

[ipfs/go-bitswap] Bitswap architecture thoughts #90

Open Stebalien opened 4 years ago

Stebalien commented 4 years ago

Bitswap Architecture

This is a loose sketch of a potential bitswap architecture. It's mostly based on the current architecture (plus https://github.com/ipfs/go-bitswap/pull/398), but I've tried to simplify some things.

Really, this is mostly to help me understand how everything is (and could be) structured. Unfortunately, reality is complected so I'm missing a lot of edge cases including:

GetBlocks

A single "request" from the user, attached to a session.

Session

The session managers related wants/peers and makes all decisions concerning where/when to send wants.

BlockRouter

Routes blocks (and information about blocks) to the appropriate services. All incoming blocks pass through this service.

change: This was the WantRequestManager (mostly).

PeerRouter

Routes incoming peer information to interested sessions.

WantManager

Manages our outbound, per-peer wantlists (refcounting per session).

Engine

Tracks inbound wantlists and sends back blocks.

Network

Service to interact with the network. This one is kind of funky as there's no central event loop.

Ledger

Tracks our debt ratio with our peers. Updated synchronously by both the Engine (when sending blocks) and the BlockRouter (when receiving blocks).

change: Currently, this is embedded in the Engine. It should be it's own thing. change: Currently, the ledger also tracks who wants what. Wantlists should be tracked in the engine.

dirkmc commented 4 years ago

Thanks for doing this work - in retrospect I should have written something like this at the beginning of the refactor :)

Stebalien commented 4 years ago

If you have some time, want to take a stab at filling this out? Or modifying it to match bitswap as-is? It should make it easier to reason about the changes.