ipfs / go-bitswap

The golang implementation of the bitswap protocol
MIT License
216 stars 112 forks source link

Added `WithScoreLedger` Bitswap option #430

Closed wolneykien closed 4 years ago

wolneykien commented 4 years ago

First, I've separated the decision engine ledger on two parts: score and the wantlist. The wantlist still resides in the original ledger struct while sent/received byte accounting and scores are extracted to the new scoreledger struct managed by the original scoreWorker() logic. The accounting is integrated into the Engine via ScoreLedger interface making it possible to replace the original scoreWorker() with some other logic. The interface, however, doesn't allow a score logic to directly touch peer tags: the logic may decide about score values while tagging itself is still under control of Engine.

Then I've added new WithScoreLedger(decision.ScoreLedger) option in the bitswap package is the way to connect a custom ScoreLedger implementation to the decision engine. The Engine now has the corresponding UseScoreLedger(ScoreLedger) method.

The ScoreLedger and ScorePeerFunc types are exposed from the internal decision package to the public one.

New TestWithScoreLedger test is added. The test checks for start and stop of the testing score ledger implementation that is specified via WithScoreLedger option.

welcome[bot] commented 4 years ago

Thank you for submitting this PR! A maintainer will be here shortly to review it. We are super grateful, but we are also overloaded! Help us by making sure that:

Getting other community members to do a review would be great help too on complex PRs (you can ask in the chats/forums). If you are unsure about something, just leave us a comment. Next steps:

We currently aim to provide initial feedback/triaging within two business days. Please keep an eye on any labelling actions, as these will indicate priorities and status of your contribution. We are very grateful for your contribution!

wolneykien commented 4 years ago

The related discussion is here: https://discuss.ipfs.io/t/how-to-extend-a-bitswap-strategy/7960/3 . And a plugin type that injects ScoreLedgerss is here https://github.com/ipfs/go-ipfs/pull/7617 .

wolneykien commented 4 years ago

Ping?

wolneykien commented 4 years ago

Thanks! What about the related https://github.com/ipfs/go-ipfs/pull/7617 ?

dirkmc commented 4 years ago

I'll ping the go-ipfs folks