How to extend a BitSwap strategy?


Can anyone point me out, what should I do if I want some other libp2p protocol to use a BitSwap ledger of two nodes (the score and the “debt”) as the basis for decision of communication? And also to use that the other way around, i.e.: to make my additional protocol routines able to alter the BitSwap ledger score and “debt” (on both nodes) upon the results of communication?

I guess, I have the following three options:

  • to extend the current BitSwap decision strategy engine with appropriate methods to access and alter the Ledger;
  • to go a level higher and try to use a custom decision strategy engine (probably, the one based on the current implementation);
  • to go even higher and implement a custom block exchange protocol that will be backward compatible with BitSwap.

In all cases I speak about the go-bitswap implementation.

I’d go with the first or second option. Ideally, you’d eventually find a clean way to expose these methods and submit a patch but I’d start by forking and experimenting a bit.

I was beginning to figure out an interface for the second option — the ability to use a custom engine with the current BitSwap protocol, but then saw it’s probably a wrong idea. As far as I understand the very idea of peer-to-peer ledgers, the peers must keep their ledgers mutually synchronized which assumes the use of the same decision logic, isn’t it? (Currently, I can’t see any ledger match functions at runtime, however that is a part of the testing suite.) If so, then there is actually only the third option really available: to map each decision logic to a separate protocol (that could be backward compatible to BitSwap though).

ledgers mutually synchronized which assumes the use of the same decision logic

This isn’t required. Different peers can decide how they want to prioritize their peers.

Hi! I’ve started with . If that’s OK I’ll be looking for a way to allow ScoreLedgers be provided in a form of go-ipfs plugin (yet another class of plugins).

Made a pull request for that: .

Hey, I’m recently start to learning the credit system, is there any documentation that described your new decision engine?

Hi. Only the comment I’d made to the PR: . There aren’t much changes and no new decision engine at all: only the possibility to plug-in some custom one.

Hi! Let me say why I’ve raised this topic about adjusting a Bitswap strategy a year ago: A preliminary discussion of the “Workswap” protocol .