ajnavarro
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee
  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # New multi-router configuration system <!-- IPIP number will be assigned by an editor. When opening a pull request to submit your IPIP, please use number 0000 and an abbreviated title in the filename, `0000-draft-title-abbrev.md`. --> - Start Date: 2022-08-15 - Related Issues: - https://github.com/ipfs/kubo/issues/9188 - https://github.com/ipfs/kubo/issues/9079 ## Summary Previously we only used DHT for content routing and content providing. After kubo-0.14.0 release we added support for [delegated routing using Reframe protocol](https://github.com/ipfs/kubo/pull/8997). Now we need a better way to add different routers using different protocols like Reframe or DHT, and be able to configure them to cover different use cases. ## Motivation The actual routing implementation is not enough. Some users needs to have more options when configuring the routing system. The new implementations should be able to: - [x] Be user-friendly and easy enough to configure, but also versatile - [x] Configurable Router execution order - [x] Delay some of the Router methods execution when they will be executed on parallel - [x] Configure which method of a giving router will be used - [x] Mark some router methods as mandatory to make the execution fails if that method fails ## Detailed design ### Configuration file description The `Routing` configuration section will contain the following keys: #### Type `Type` will be still in use to avoid complexity for the user that only wants to use Kubo with the default behavior. We are going to add a new type, `custom`, that will use the new router systems. `none` type will deactivate **all** routers, default dht and delegated ones. #### Routers `Routers` will be a key-value list of routers that will be available to use. The key is the router name and the value is all the needed configurations for that router. the `Type` will define the routing kind. The main router types will be `reframe` and `dht`, but we will implement two special routers used to execute a set of routers in parallel or sequentially: `parallel` router and `sequential` router. Depending on the routing type, it will use different parameters: ##### Reframe Params: - `"Endpoint"`: URL endpoint implementing Reframe protocol. ##### DHT Params: - `"Mode"`: Mode used by the DHT. Possible values: "server", "client", "auto" - `"AcceleratedDHTClient"`: Set to `true` if you want to use the experimentalDHT. - `"PublicIPNetwork"`: Set to `true` to create a `WAN` DHT. Set to `false` to create a `LAN` DHT. ##### Parallel Params: - `Routers`: A list of routers that will be executed in parallel: - `Name:string`: Name of the router. It should be one of the previously added to `Routers` list. - `Timeout:duration`: Local timeout. It accepts strings compatible with Go `time.ParseDuration(string)`. Time will start counting when this specific router is called, and it will stop when the router returns, or we reach the specified timeout. - `ExecuteAfter:duration`: Providing this param will delay the execution of that router at the specified time. It accepts strings compatible with Go `time.ParseDuration(string)`. - `IgnoreErrors:bool`: It will specify if that router should be ignored if an error occurred. - `Timeout:duration`: Global timeout. It accepts strings compatible with Go `time.ParseDuration(string)`. ##### Sequential Params: - `Routers`: A list of routers that will be executed in order: - `Name:string`: Name of the router. It should be one of the previously added to `Routers` list. - `Timeout:duration`: Local timeout. It accepts strings compatible with Go `time.ParseDuration(string)`. Time will start counting when this specific router is called, and it will stop when the router returns, or we reach the specified timeout. - `IgnoreErrors:bool`: It will specify if that router should be ignored if an error occurred. - `Timeout:duration`: Global timeout. It accepts strings compatible with Go `time.ParseDuration(string)`. #### Methods `Methods:map` will define which routers will be executed per method. The key will be the name of the method: `"provide"`, `"find-providers"`, `"find-peers"`, `"put-ipns"`, `"get-ipns"`. All methods must be added to the list. This will make configuration discoverable giving good errors to the user if a method is missing. The value will contain: - `RouterName:string`: Name of the router. It should be one of the previously added to `Routers` list. #### Configuration file example: ```json "Routing": { "Type": "custom", "Routers": { "storetheindex": { "Type": "reframe", "Parameters": { "Endpoint": "https://cid.contact/reframe" } }, "dht-lan": { "Type": "dht", "Parameters": { "Mode": "server", "PublicIPNetwork": false, "AcceleratedDHTClient": false } }, "dht-wan": { "Type": "dht", "Parameters": { "Mode": "auto", "PublicIPNetwork": true, "AcceleratedDHTClient": false } }, "find-providers-router": { "Type": "parallel", "Parameters": { "Routers": [ { "RouterName": "dht-lan", "IgnoreErrors": true }, { "RouterName": "dht-wan" }, { "RouterName": "storetheindex" } ] } }, "provide-router": { "Type": "parallel", "Parameters": { "Routers": [ { "RouterName": "dht-lan", "IgnoreErrors": true }, { "RouterName": "dht-wan", "ExecuteAfter": "100ms", "Timeout": "100ms" }, { "RouterName": "storetheindex", "ExecuteAfter": "100ms" } ] } }, "get-ipns-router": { "Type": "sequential", "Parameters": { "Routers": [ { "RouterName": "dht-lan", "IgnoreErrors": true }, { "RouterName": "dht-wan", "Timeout": "300ms" }, { "RouterName": "storetheindex", "Timeout": "300ms" } ] } }, "put-ipns-router": { "Type": "parallel", "Parameters": { "Routers": [ { "RouterName": "dht-lan" }, { "RouterName": "dht-wan" }, { "RouterName": "storetheindex" } ] } } }, "Methods": { "find-providers": { "RouterName": "find-providers-router" }, "provide": { "RouterName": "provide-router" }, "get-ipns": { "RouterName": "get-ipns-router" }, "put-ipns": { "RouterName": "put-ipns-router" } } } ``` Added YAML for clarity: ```yaml --- Type: custom Routers: storetheindex: Type: reframe Parameters: Endpoint: https://cid.contact/reframe dht-lan: Type: dht Parameters: Mode: server PublicIPNetwork: false AcceleratedDHTClient: false dht-wan: Type: dht Parameters: Mode: auto PublicIPNetwork: true AcceleratedDHTClient: false find-providers-router: Type: parallel Parameters: Routers: - RouterName: dht-lan IgnoreErrors: true - RouterName: dht-wan - RouterName: storetheindex provide-router: Type: parallel Parameters: Routers: - RouterName: dht-lan IgnoreErrors: true - RouterName: dht-wan ExecuteAfter: 100ms Timeout: 100ms - RouterName: storetheindex ExecuteAfter: 100ms get-ipns-router: Type: sequential Parameters: Routers: - RouterName: dht-lan IgnoreErrors: true - RouterName: dht-wan Timeout: 300ms - RouterName: storetheindex Timeout: 300ms put-ipns-router: Type: parallel Parameters: Routers: - RouterName: dht-lan - RouterName: dht-wan - RouterName: storetheindex Methods: find-providers: RouterName: find-providers-router provide: RouterName: provide-router get-ipns: RouterName: get-ipns-router put-ipns: RouterName: put-ipns-router ``` ### Error cases - If any of the routers fails, the output will be an error by default. - You can use `IgnoreErrors:true` to ignore errors for a specific router output - To avoid any error at the output, you must ignore all router errors. ### Implementation Details #### Methods All routers must implement the `routing.Routing` interface: ```go= type Routing interface { ContentRouting PeerRouting ValueStore Bootstrap(context.Context) error } ``` All methods involved: ```go= type Routing interface { Provide(context.Context, cid.Cid, bool) error FindProvidersAsync(context.Context, cid.Cid, int) <-chan peer.AddrInfo FindPeer(context.Context, peer.ID) (peer.AddrInfo, error) PutValue(context.Context, string, []byte, ...Option) error GetValue(context.Context, string, ...Option) ([]byte, error) SearchValue(context.Context, string, ...Option) (<-chan []byte, error) Bootstrap(context.Context) error } ``` We can configure which methods will be used per routing implementation. Methods names used in the configuration file will be: - `Provide`: `"provide"` - `FindProvidersAsync`: `"find-providers"` - `FindPeer`: `"find-peers"` - `PutValue`: `"put-ipns"` - `GetValue`, `SearchValue`: `"get-ipns"` - `Bootstrap`: It will be always executed when needed. #### Routers We need to implement the `parallel` and `sequential` routers and stop using `routinghelpers.Tiered` router implementation. Add cycle detection to avoid to user some headaches. Also we need to implement an internal router, that will define the router used per method. #### Other considerations - We need to refactor how DHT routers are created to be able to use and add any amount of custom DHT routers. - We need to add a new `custom` router type to be able to use the new routing system. - Bitswap WANT broadcasting is not included on this document, but it can be added in next iterations. - This document will live in docs/design-notes for historical reasons and future reference. ## Test fixtures As test fixtures we can add different use cases here and see how the configuration will look like. ### Mimic previous dual DHT config ```json "Routing": { "Type": "custom", "Routers": { "dht-lan": { "Type": "dht", "Parameters": { "Mode": "server", "PublicIPNetwork": false } }, "dht-wan": { "Type": "dht", "Parameters": { "Mode": "auto", "PublicIPNetwork": true } }, "parallel-dht-strict": { "Type": "parallel", "Parameters": { "Routers": [ { "RouterName": "dht-lan" }, { "RouterName": "dht-wan" } ] } }, "parallel-dht": { "Type": "parallel", "Parameters": { "Routers": [ { "RouterName": "dht-lan", "IgnoreError": true }, { "RouterName": "dht-wan" } ] } } }, "Methods": { "provide": { "RouterName": "dht-wan" }, "find-providers": { "RouterName": "parallel-dht-strict" }, "find-peers": { "RouterName": "parallel-dht-strict" }, "get-ipns": { "RouterName": "parallel-dht" }, "put-ipns": { "RouterName": "parallel-dht" } } } ``` Yaml representation for clarity: ```yaml --- Type: custom Routers: dht-lan: Type: dht Parameters: Mode: server PublicIPNetwork: false dht-wan: Type: dht Parameters: Mode: auto PublicIPNetwork: true parallel-dht-strict: Type: parallel Parameters: Routers: - RouterName: dht-lan - RouterName: dht-wan parallel-dht: Type: parallel Parameters: Routers: - RouterName: dht-lan IgnoreError: true - RouterName: dht-wan Methods: provide: RouterName: dht-wan find-providers: RouterName: parallel-dht-strict find-peers: RouterName: parallel-dht-strict get-ipns: RouterName: parallel-dht put-ipns: RouterName: parallel-dht ``` ### Compatibility ~~We need to create a config migration using [fs-repo-migrations](https://github.com/ipfs/fs-repo-migrations). We should remove the `Routing.Type` param and add the configuration specified [previously](#Mimic-previous-dual-DHT-config).~~ We don't need to create any config migration! To avoid to the users the hassle of understanding how the new routing system works, we are gonna keep the old behavior. We will add the Type `custom` to make available the new Routing system. ### Security No new security implications or considerations were found. ### Alternatives I got ideas from all of the following links to create this design document: - https://github.com/ipfs/kubo/issues/9079#issuecomment-1211288268 - https://github.com/ipfs/kubo/issues/9157 - https://github.com/ipfs/kubo/issues/9079#issuecomment-1205000253 - https://www.notion.so/pl-strflt/Delegated-Routing-Thoughts-very-very-WIP-0543bc51b1bd4d63a061b0f28e195d38 - https://gist.github.com/guseggert/effa027ff4cbadd7f67598efb6704d12 ### Copyright Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/).

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully