Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

Added WithScoreLedger Bitswap option #430

Merged
merged 5 commits into from
Sep 3, 2020
Merged

Conversation

wolneykien
Copy link
Contributor

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.

This is the first step to make external decision logic (tagging
peers with score values) possible.

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.

Note: with this commit it's yet not possible to replace the original
score logic because there is no public methods for that.
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.

Because its options are processed by the `Bitswap` after construction
of its parts but before starting of the engine, the default
`scoreLedger` initialization is moved from `newEngine()` to
`StartWorkers()`.

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
Copy link

welcome bot commented Aug 22, 2020

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:

  • The context for this PR is clear, with relevant discussion, decisions
    and stakeholders linked/mentioned.

  • Your contribution itself is clear (code comments, self-review for the
    rest) and in its best form. Follow the code contribution
    guidelines

    if they apply.

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:

  • A maintainer will triage and assign priority to this PR, commenting on
    any missing things and potentially assigning a reviewer for high
    priority items.

  • The PR gets reviews, discussed and approvals as needed.

  • The PR is merged by maintainers when it has been approved and comments addressed.

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
Copy link
Contributor Author

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 ipfs/kubo#7617 .

Copy link
Contributor

@dirkmc dirkmc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of nits but this looks good overall

internal/decision/scoreledger.go Outdated Show resolved Hide resolved
internal/decision/scoreledger.go Outdated Show resolved Hide resolved
internal/decision/scoreledger.go Outdated Show resolved Hide resolved
Having a separate `Init(ScoreFunc)` method seems redundant (thx
@dirkmc for pointing about that). As a bonus, the two-step ledger
starting process is now enclosed in the `startScoreLedger()` function.
The `Close()` method was there to stop the ledger. Let call it
`Stop()` now.
Explicitly form it as the final resort.
@wolneykien
Copy link
Contributor Author

Ping?

Copy link
Contributor

@dirkmc dirkmc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I didn't see your commits until you pinged just now :)

@dirkmc dirkmc merged commit fd21393 into ipfs:master Sep 3, 2020
@wolneykien
Copy link
Contributor Author

Thanks! What about the related ipfs/kubo#7617 ?

@dirkmc
Copy link
Contributor

dirkmc commented Sep 3, 2020

I'll ping the go-ipfs folks

@aschmahmann aschmahmann mentioned this pull request Feb 18, 2021
73 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants