Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(routing): Delegated Routing #8997

Merged
merged 27 commits into from
Jul 7, 2022

Conversation

ajnavarro
Copy link
Member

@ajnavarro ajnavarro commented May 27, 2022

Add a way to add any kind of router, starting with Reframe routers.
Reframe routers are implementing Reframe specs (https://github.com/ipfs/specs/blob/master/REFRAME.md) using the go-delegated-routing library.

Added on this PR:

  • Routing.Type is optional now (still work in progress until we add dht routes on delegated routing).
  • New Routing.Routes config param with documentation.
  • Deprecate dht commands (all but query)
  • New /routing HTTP commands endpoints:
    • /routing
    • /routing/put
    • /routing/get
    • /routing/findpeer
    • /routing/findprovs
    • /routing/provide
  • New routing command.
  • Routing system is split into two parts: TieredRouter with all routers, and routing.ContentRoutings, needed to generate a Tiered ContentRouting, used for Topic Discovery. All Delegated routers will be added to ContentRouters too.
  • Added a wrapper to be able to use github.com/ipfs/go-delegated-routing as routing.Routing implementations. Maybe we should do it in the library itself.

Things to do in next iterations:

@ajnavarro ajnavarro changed the title Delegated Routing feat(routing): Delegated Routing May 27, 2022
config/addresses.go Outdated Show resolved Hide resolved
Copy link
Contributor

@aschmahmann aschmahmann left a comment

Choose a reason for hiding this comment

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

Added some comments about where things go in the config file and the remaining fx issues. lmk what you think and others may chime in as well.

We're also missing tests here. I think using Go tests will likely make your life easier here than writing sharness tests.

@ajnavarro

This comment was marked as outdated.

@ajnavarro ajnavarro force-pushed the feature/delegated-routing branch 3 times, most recently from a4f38b4 to 276ccf0 Compare June 22, 2022 14:49
@ajnavarro

This comment was marked as outdated.

config/routing.go Outdated Show resolved Hide resolved
docs/config.md Outdated Show resolved Hide resolved
@ajnavarro

This comment was marked as outdated.

config/routing.go Outdated Show resolved Hide resolved
core/commands/routing.go Outdated Show resolved Hide resolved
docs/config.md Outdated Show resolved Hide resolved
core/commands/routing.go Outdated Show resolved Hide resolved
@ajnavarro

This comment was marked as outdated.

@BigLep
Copy link
Contributor

BigLep commented Jun 28, 2022

2022-06-28 conversation:

  • Scope reduction: DHT configuration will have a migration in 0.15
  • Scope reduction: fewer options for what you can do with reframe (e.g., limiting the number of methods)

Missing items:

  1. Add tests
  2. Docs
  3. Get all the tests pass (FX issues which @guseggert will help with)

@ajnavarro ajnavarro force-pushed the feature/delegated-routing branch 2 times, most recently from 0eb5007 to 0fbeac3 Compare June 29, 2022 16:36
@ajnavarro

This comment was marked as outdated.

@ajnavarro

This comment was marked as outdated.

@ajnavarro ajnavarro marked this pull request as ready for review June 30, 2022 15:03
Copy link
Contributor

@aschmahmann aschmahmann left a comment

Choose a reason for hiding this comment

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

Looking good, most of my questions are not super substantial.

Two other things are:

  1. We may should start writing up some info on this change in CHANGELOG.md so we don't have to get it all done right before the release. It also serves to summarize the end state of things to the reviewer since their expectations should match what the you're telling the user in the docs/changelog
  2. Maybe it's ok to rely on go-delegated-routing having tests for the a single reframe router and go-libp2p-routing-helpers having tests for multiple routers in use. However, there's a bunch of complexity here coming from fx and plugging all the pieces together. I think it'd be useful to have some closer to end-to-end tests (whether in sharness or Go) to exercise this a bit. Sharness might be easier given that we don't have any demo writeable-reframe servers at the moment.
    • @lidel WDYT, overkill or necessary?


It can contain several Router implementations, such as DHT and delegated routing based on the [reframe protocol](https://github.com/ipfs/specs/blob/master/REFRAME.md).

Type: `object[string->object]`
Copy link
Contributor

Choose a reason for hiding this comment

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

What does this mean?

Copy link
Member Author

Choose a reason for hiding this comment

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

I copy it from similar config param, Swarm.ResourceMgr.Limits I guess it means a map of objects.

docs/config.md Outdated Show resolved Hide resolved
go.mod Outdated
@@ -127,6 +127,7 @@ require (

require (
github.com/benbjohnson/clock v1.3.0
github.com/ipfs/go-delegated-routing v0.2.2
Copy link
Contributor

Choose a reason for hiding this comment

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

has commits missing from master, and master is failing CI.

Copy link
Member Author

@ajnavarro ajnavarro Jul 4, 2022

Choose a reason for hiding this comment

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

fix by @guseggert here: ipfs/go-delegated-routing#28. I'll update the dependency when merged.

routing/delegated.go Outdated Show resolved Hide resolved
routing/wrapper.go Outdated Show resolved Hide resolved
Comment on lines 167 to 172
fx.Provide(libp2p.Routing),
fx.Provide(libp2p.ContentRouting),

fx.Provide(libp2p.BaseRouting(cfg.Experimental.AcceleratedDHTClient)),
fx.Provide(libp2p.DelegatedRouting(cfg.Routing.Routers)),
maybeProvide(libp2p.PubsubRouter, bcfg.getOpt("ipnsps")),
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a bit of a confusing mess of functions here related to routing. Might help to have some docs explaining what's going on.

We seem to have multiple sets of tiered routers, how are you thinking they should be used? Is it one set of tiered routers for everything other than the pubsub router and then another set that is everything including the pubsub router?

Copy link
Member Author

@ajnavarro ajnavarro Jul 4, 2022

Choose a reason for hiding this comment

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

Is it one set of tiered routers for everything other than the pubsub router and then another set that is everything including the pubsub router?

Yes. First, we created a list of content-routers that will be used on pubsub router. Second, we created a list of routers using all previous routers + pubsub router.

Where/How should I add that documentation? Can you point me to some example of that on the fx code? Thx.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added some godoc on the new methods. Ping me if I should add something more. Thx!

// Usually used for reframe Routers.
RouterParamAddress RouterParam = "address"

RouterParamPriority RouterParam = "priority"
Copy link
Contributor

Choose a reason for hiding this comment

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

@lidel idk if you have thoughts here, but I'm not sure how much we want to expose here.

Might be useful info to have to understand some notion of user preference, but also we may want to just do more in parallel depending on our concerns about resource usage.

AFAICT the only areas where priority kicks in are for the GetValue, GetPublicKey and FindPeer functions (https://github.com/libp2p/go-libp2p-routing-helpers/blob/506670d53a31503f257980dbf354b3ea1b990fb7/tiered.go#L30). GetPublicKey is basically unused, FindPeer could probably be in parallel without issue, and GetValue sort of makes sense to have prioritization (there's some weird edge-cases around IPNS records since they're mutable and you're trying to find the latest ones but don't want to hang around forever checking every system) but IIRC SearchValue is generally used anyway which has parallelism.

Copy link
Member

@lidel lidel Jul 3, 2022

Choose a reason for hiding this comment

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

@aschmahmann If we talk about future where we have DHT routers here as well, I think we need two optional settings:

  1. priority – allows setting the order (when it matters)
  2. mandatory – allows for marking some routers as mandatory and others as best-effort

With these, we will be able to model custom rules around parallelism and best-effort/mandatory routers in the future, but for now we can skip them in config (thus optional with implicit default).

Copy link
Member Author

Choose a reason for hiding this comment

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

If we add the mandatory flag we must stop using routinghelpers.TieredRouter and use some new implementation that supports that.

Copy link
Member

Choose a reason for hiding this comment

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

ack, this needs a design first.
We can "mandatory" decision/discussion to kubo 0.15 or later.

Copy link
Member Author

Choose a reason for hiding this comment

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

add an issue to track it: #9083

docs/config.md Outdated Show resolved Hide resolved
routing/delegated_test.go Outdated Show resolved Hide resolved
config/routing.go Outdated Show resolved Hide resolved
@aschmahmann
Copy link
Contributor

I found a new error on go-libp2p-routing-helpers. When we put a new value, TieredRouter should succeed if at least one Router added the value, but the logic is wrong here

I think this is debatable and probably more a matter of opinion than a bug. Depending on the configuration of the multiple systems you might want it to fail if only one of the systems succeeds. This relates to some of the more complex configuration options we may want to add to the config in the future.

Example 1:

  • I want to do a put to the IPFS Public DHT and to a centralized database used by my application
  • If I only send the put to the centralized database and call that a success that's not great since it means users who don't have my centralized database configured won't see my put

Example 2:

  • I want to use a service that I delegate my routing requests to but fallback to the DHT if that fails
  • If I only send the put to the delegated routing service I'm ok calling that a success since it's supposed to do the put to the DHT on my behalf

@aschmahmann
Copy link
Contributor

I suspect to roll this out the main thing we need is to deal with expected vs unexpected errors. In particular, if I add a reframe router that doesn't support something like "put" it should be fine as long as it returns the correct error given https://github.com/libp2p/go-libp2p-routing-helpers/blob/506670d53a31503f257980dbf354b3ea1b990fb7/parallel.go#L142

@ajnavarro
Copy link
Member Author

I think this is debatable and probably more a matter of opinion than a bug.

@aschmahmann I only consider that to be a bug because the documentation (GoDoc) describes a behavior that is not the one happening. Any behavior is fine for me :)

CHANGELOG.md Outdated Show resolved Hide resolved
@BigLep
Copy link
Contributor

BigLep commented Jul 6, 2022

@ajnavarro : with the correspondence that has happened today synchronously and in chat, where are we at? What's remaining to get this landed?

@lidel
Copy link
Member

lidel commented Jul 6, 2022

@ajnavarro before you start work, please fetch my changes, should save you some time:

The failing gotest was already failing before my changes, so I assume it is still work-in-progress on your end. Up to you to decide if you want to fix them or add any additional sharness tests to test/sharness/t0701-delegated-routing-reframe.sh (fwwiw we already have basic end-to-end finprovs test there).

@ajnavarro
Copy link
Member Author

@ajnavarro : with the correspondence that has happened today synchronously and in chat, where are we at? What's remaining to get this landed?

Status:

Copy link
Member

@lidel lidel left a comment

Choose a reason for hiding this comment

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

nit: REFRAME spec link changed :^)

CHANGELOG.md Outdated Show resolved Hide resolved
config/routing.go Outdated Show resolved Hide resolved
docs/config.md Outdated Show resolved Hide resolved
docs/config.md Outdated Show resolved Hide resolved
core/node/provider.go Outdated Show resolved Hide resolved
Co-authored-by: Adin Schmahmann <adin.schmahmann@gmail.com>
@guseggert guseggert merged commit 92c4dc6 into ipfs:master Jul 7, 2022
@BigLep BigLep mentioned this pull request Jul 26, 2022
68 tasks
hannahhoward pushed a commit to filecoin-project/kubo-api-client that referenced this pull request Jun 19, 2023
* Delegated Routing.

Implementation of Reframe specs (https://github.com/ipfs/specs/blob/master/REFRAME.md) using go-delegated-routing library.

* Requested changes.

* Init using op string

* Separate possible ContentRouters for TopicDiscovery.

If we don't do this, we have a ciclic dependency creating TieredRouter.
Now we can create first all possible content routers, and after that,
create Routers.

* Set dht default routing type

* Add tests and remove uneeded code

* Add documentation.

* docs: Routing.Routers

* Requested changes.

Signed-off-by: Antonio Navarro Perez <antnavper@gmail.com>

* Add some documentation on new fx functions.

* Add changelog entry and integration tests

* test: sharness for 'dht' in 'routing' commands

Since 'routing' is currently the same as 'dht' (minus query command)
we need to test both, that way we won't have unnoticed divergence
in the default behavior.

* test(sharness): delegated routing via reframe URL

* Add more tests for delegated routing.

* If any put operation fails, the tiered router will fail.

* refactor: Routing.Routers: Parameters.Endpoint

As agreed  in ipfs/kubo#8997 (comment)

* Try to improve CHANGELOG entry.

* chore: update reframe spec link

* Update go-delegated-routing dependency

* Fix config error test

* use new changelog format

* Remove port conflict

* go mod tidy

* ProviderManyWrapper to ProviderMany

* Update docs/changelogs/v0.14.md

Co-authored-by: Adin Schmahmann <adin.schmahmann@gmail.com>

Co-authored-by: Marcin Rataj <lidel@lidel.org>
Co-authored-by: Adin Schmahmann <adin.schmahmann@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

delegated-routing support v1: use configurable delegated-routing endpoints for content-routing
5 participants