Skip to content

[P2P] Support multiple simultaneous routers #762

@bryanchriswhite

Description

@bryanchriswhite

Objective

Enable the P2P module to handle incoming messages from multiple router implementations simultaneously.

Origin Document

Currently, the message handling interaction between the P2P and the router looks like this:

flowchart LR
    subgraph p2p[P2P Module]
        subgraph rt[RainTree Router]
            nd[Nonce Deduper]
            rth[[`RainTreeMessage` Handler]]
        end

        p2ph[[`PocketEnvelope` message Handler]]
    end

rth --> nd
rth --> p2ph
Loading
classDiagram
    class RainTreeMessage {
        <<protobuf>>
        +Level uint32
        +Data []byte
        +Nonce uint64
    }
    
    class PocketEnvelope {
        <<protobuf>>
        +Content *anypb.Any   
    }

    RainTreeMessage --* PocketEnvelope : serialized as `Data`
    
      
    class P2PModule {
        -handleNetworkData([]byte) error
        -handleStream(stream libp2pNetwork.Stream)
        -readStream(stream libp2pNetwork.Stream)
    }

    class RainTreeRouter {
        +HandleNetworkData func([]byte) ([]byte, error)
    }

    RainTreeRouter --> P2PModule
    P2PModule --> RainTreeRouter
    RainTreeRouter --o RainTreeMessage
    RainTreeRouter --* NonceDeduper
    P2PModule --o PocketEnvelope
Loading

Goals

  • Support handling message from multiple routers simultaneously
  • Support message deduplication across all messages (i.e. not just raintree)
  • Improve separation of concerns between P2P module and router(s)

Deliverable

flowchart LR
    subgraph p2p[P2P Module]
        subgraph rt[RainTree Router]
            rth[[`RainTreeMessage` Handler]]
        end

        nd[Nonce Deduper]
    
        p2ph[[`PocketEnvelope` message Handler]]
    end

p2ph --> nd
rth --> p2ph
Loading
classDiagram
    class RainTreeMessage {
        <<protobuf>>
        +Level uint32
        +Data []byte
    }
    
    class PocketEnvelope {
        <<protobuf>>
        +Content *anypb.Any
        +Nonce uint64
    }

    RainTreeMessage --* PocketEnvelope : serialized as `Data`
    
    class P2PModule {
        -handleAppData([]byte) error
    }

    class RainTreeRouter {
        -appDataHandler RouterHandler
        -handleRainTreeMsg([]byte) ([]byte, error)
        -handleStream(stream libp2pNetwork.Stream)
        -readStream(stream libp2pNetwork.Stream)
    }

    RainTreeRouter --> P2PModule : `appDataHandler` == `handleAppData`
    RainTreeRouter --o RainTreeMessage

    P2PModule --* NonceDeduper
    P2PModule --o PocketEnvelope
Loading
  • Move NonceDeduper to the P2P module
  • Refactor message handling logic to flow in one direction (from the router towards the application)
  • Move Nonce proto field from RainTreeMessage to PocketEnvelope

Non-goals / Non-deliverables

  • Integrating additional routers (e.g. BackgroundRouter)

General issue deliverables

  • Update the appropriate CHANGELOG(s)
  • Update any relevant local/global README(s)
  • Update relevant source code tree explanations
  • Add or update any relevant or supporting mermaid diagrams

Testing Methodology

  • All tests: make test_all
  • LocalNet: verify a LocalNet is still functioning correctly by following the instructions at docs/development/README.md
  • k8s LocalNet: verify a k8s LocalNet is still functioning correctly by following the instructions here

Creator: @bryanchriswhite

Metadata

Metadata

Labels

p2pP2P specific changes

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions