Angelo Capossele
    • 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

      This note has no invitees

    • 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
    • Note Insights New
    • Engagement control
    • Make a copy
    • 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 Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy 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

    This note has no invitees

  • 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
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    + Feature name: `Peer Discovery` + Start date: 2020-04-13 + RFC PR: [iotaledger/protocol-rfcs#0000](https://github.com/iotaledger/protocol-rfcs/pull/0000) # Summary This RFC defines the *Peer Discovery* protocol, its logic and the different messages exchanged. # Motivation In order to establish connections, an IOTA node needs to discover and maintain a list of the reachable IP addresses of other peers. Moreover, some external modules, such as the *Neighbor Selection* and the *Fast Probabilistic Consensus (FPC)* may require an updated list of all the known peers. # Terminology Throughout this RFC the terms `Node` and `Peer` are used interchangeably. # Detailed design To bootstrap the peer discovery, a node *must* be able to reach one or more entry nodes. Thus, the implementation of the protocol *must* provide a hard-coded list of trusted **entry nodes** run by the IF or by trusted community members that answer to peer discovery messages coming from new nodes joining the IOTA network. This approach is a common practice of many distributed networks [[Neudecker 2018]](https://ieeexplore.ieee.org/iel7/9739/8649699/08456488.pdf). Public Key-based Cryptography (PKC) *must* be used for uniquely [identifying](#Node_identities) peers and for authenticating each message. In a nutshell, [*Ping*](#Ping) messages are sent to verify a given peer and, upon reception of a valid [*Pong*](#Pong) message as a response from that peer, the peer is verified. Once a peer has been verified, it can be queried to discover new peers by sending a [*DiscoveryRequest*](#DiscoveryRequest) message. As a response, a [*DiscoveryResponse*](#DiscoveryResponse) message should be expected, containing a list of new peers that *should* be verified. The main goal of the *Peer Discovery* protocol is to expose an interface providing the list of all the verified peers. This process is sketched in the following figure and detailed in the following subsections: ![](https://i.imgur.com/U51tPeK.png) ## Node identities Every node has a cryptographic identity, a key on the ed25519 elliptic curve. The `blake2b` hash of the public key of the peer serves as its identifier or `node ID`. ## Verification The verification process aims at both verifying peer identities and checking their online status. Each peer keeps a list of all the known peers called `known_peer_list`. Elements of such a list contain a [Peer](#Peer) and are ordered based on their verified status: the oldest verified peer (or unverified peer) as the head and the most recent verified peer as the tail. This way should allow to first verify newly discovered (and thus still unverified) peers and re-verify (to confirm their online status) older peers by iterating over the `known_peer_list`. The verification process always initiates from a [Ping](#Ping) message. Upon reception of a [Ping](#Ping) message, a peer *must* check its validity by: * verifying that the signature of the [Ping](#Ping) message is valid and discard the message otherwise; * checking that the `version` and `network_id` fields match its configuration and discard the message otherwise ; * checking that the `timestamp` field is fresh and discard the message otherwise; * checking that the `dest_addr` matches its IP address and discard the message otherwise. Upon successful validation of a received [Ping](#Ping) message, a peer *should* respond with a [Pong](#Pong) message. In case the peer sender of the *Ping* message is a new peer, the receiver peer *should* add it to its `known_peer_list` (so that the verification process can also occur the other way around). Upon reception of a [Pong](#Pong) message, a peer *must* check its validity by: * verifying that the signature of the [Pong](#Pong) message is valid and discard the message otherwise; * checking that the `req_hash` field matches a request (i.e., *Ping*) previously sent and not expired; * checking that the `dest_addr` matches its IP address and discard the message otherwise. Upon successful validation of a received [Pong](#Pong) message, a peer *should*: * add the peer sender of the *Pong* message to a list of verified peers called `verified_peer_list`; * move the peer entry of the `known_peer_list` to the tail. ## Removal While verifying a new peer, if no or an invalid *Pong* message is received after `max_verify_attempts` attempts, the peer *should* be removed from the `known_peer_list`. Each peer on the `verified_peer_list` *should* be re-verified after `verification_lifetime` hours; while re-verifying a peer, if no or invalid *Pong* message is received after `max_reverify_attempts` attempts, the peer *should* be removed from the `verified_peer_list`. ## Discovery Each peer entry of the `verified_peer_list` can be used to discover new peers. This process initiates by sending a [DiscoveryRequest](#DiscoveryRequest) message. Upon reception of a [DiscoveryRequest](#DiscoveryRequest) message, a peer *must* check its validity by: * checking that the peer sender of the [DiscoveryRequest](#DiscoveryRequest) message is a verified peer (i.e., is stored in the `verified_peer_list`) and discard the message otherwise; * verifying that the signature of the [DiscoveryRequest](#DiscoveryRequest) message is valid and discard the message otherwise; * checking that the `timestamp` field is fresh and discard the message otherwise; Upon successful validation of a received [DiscoveryRequest](#DiscoveryRequest) message, a peer *should* reply with a [DiscoveryResponse](#DiscoveryResponse) message. Upon reception of a [DiscoveryResponse](#DiscoveryResponse) message, a peer *must* check its validity by: * verifying that the signature of the [DiscoveryResponse](#DiscoveryResponse) message is valid and discard the message otherwise; * checking that the `req_hash` field matches a discovery request (i.e., *DiscoveryRequest*) previously sent and not expired. Upon successful validation of a received [DiscoveryResponse](#DiscoveryResponse) message, a peer *should* add the peers contained in the `peers` field to the top of the `known_peer_list`. ## Messages Each message is encapsulated into a `data` field of a `Packet` message. The `type` of the different messages *must* be specified in the `type` field. Each message *must* be signed with the ed25519 private key of the sender's [identity](#Node_identities) and contain the related public key to allow the message receiver to verify the signature. All the received messages *must* be verified and discard those with invalid signature. In the following, the **protocol buffer** language is used to define the structure of each message. ### Packet ``` message Packet { uint32 type = 1; bytes data = 2; bytes public_key = 3; bytes signature = 4; } ``` * `type` defines the type of the message: * `0x0A`: [`Ping`](#Ping) message; * `0x0B`: [`Pong`](#Pong) message; * `0x0C`: [`DiscoveryRequest`](#DiscoveryRequest) message; * `0x0D`: [`DiscoveryResponse`](#DiscoveryResponse) message; * `data` contains the payload of the message (e.g., a `ping` message). * `public_key` is the ed25519 public key of the peer's [identity](#Peer_identities) used to verify its signatures. * `signature` is the ed25519 signature of the `data` field, signed by using the private key of the peer's [identity](#Peer_identities). ### Ping ``` message Ping { uint32 version = 1; uint32 network_id = 2; int64 timestamp = 3; string src_addr = 4; uint32 src_port = 5; string dst_addr = 6; } ``` * `version` and `network_id` are used to classify the protocol. * `timestamp` is defined as the unix timestamp. * `src_addr` is the IP address, as a string form, of the sender (e.g., "192.0.2.1", "[2001:db8::1]"). * `src_port` is the listening port of the sender. * `dst_addr` is the string form of the receiver's IP address. This provides a way to discover the external address (after NAT). ### Pong ``` message Pong { bytes req_hash = 1; ServiceMap services = 2; string dst_addr = 3; } ``` * `req_hash` is the `blake2b` digest of the corresponding received [`ping`](#Ping) message. * `services` are the [services](#ServiceMap) supported by the `pong` message sender. * `dst_addr` is the string form of the receiver's IP address. This *MUST* mirror the `src_addr` of the [`ping`](#Ping)'s IP message. It provides a way to discover the external address (after NAT). ### DiscoveryRequest ``` message DiscoveryRequest { int64 timestamp = 1; } ``` * `timestamp` is defined as the unix timestamp. ### DiscoveryResponse ``` message DiscoveryResponse { bytes req_hash = 1; repeated Peer peers = 2; } ``` * `req_hash` is the `blake2b` digest of the corresponding received [`DiscoveryRequest`](#DiscoveryRequest) message. * `peers` is a list of *some* randomly chosen [peers](#Peer) known by the sender of the `DiscoveryRepsonse` message. ### Peer ``` message Peer { bytes public_key = 1; string ip = 2; ServiceMap services = 3; } ``` * `public_key` is the ed25519 public key of the peer's [identity](#Peer_identities) used to verify its signatures. * `ip` defines the string form of the peers IP address. * `services` are the [services](#ServiceMap) supported by the peer. ### ServiceMap `ServiceMap` is a data structure used to map a service ID to its tuple `NetworkAddress`. ``` message ServiceMap { map<string, NetworkAddress> map = 1; } ``` * `map` maps a service ID to the corresponding `NetworkAddress` (e.g., map["autopeering":NetworkAddress{"udp", 14636}]). `NetworkAddress` defines the tuple `<network, port>` of a service: ``` message NetworkAddress { string network = 1; uint32 port = 2; } ``` * `network` defines the network type (e.g., "tcp", "udp") of the service. * `port` defines the listening port of the service. # Drawbacks + The *Peer Discovery* aims at discovering as many peers as possible. This is a requirement of both *Neighbor Selection* and *FPC*. On the other hand, this exposes the public IP of all the IOTA nodes. + Scalability of this protocol might be problematic since any peer needs to discover the entire set of the peers. # Rationale and alternatives - Why is this design the best in the space of possible designs? - What other designs have been considered and what is the rationale for not choosing them? - What is the impact of not doing this? # Unresolved questions - What parts of the design do you expect to resolve through the RFC process before this gets merged? - What parts of the design do you expect to resolve through the implementation of this feature before stabilization? - What related issues do you consider out of scope for this RFC that could be addressed in the future independently of the solution that comes out of this RFC?

    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