Skip to content

refactor!: change wire protocol to use uni streams per topic #75

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

Open
wants to merge 9 commits into
base: Frando/irpc
Choose a base branch
from

Conversation

Frando
Copy link
Member

@Frando Frando commented Jun 7, 2025

Description

Wire-breaking change

Based on #67

Changes the wire protocol to use uni streams per topic instead of a single bidirectional stream for all topics. This saves 32 bytes per message because we don't have to include the topic id in each message anymore.

Peers open uni streams whenever they want to send a message for a topic for which no uni stream is open yet. First, a header is written. The header is length-prefixed and versioned, so that we can do non-breaking upgrades here. Right now, the header only contains the topic id.

Peers accept uni streams, read the header, and then forward messages to the proto state machine, as previously.

Right now the recv code path does not check if the topic is open (this will need further refactoring) but this is, in a way, no change to the status quo, were peers could also send you messages for unknown topics (they will simply be ignored). But with this change, we can later optimize to close accepted streams for unjoined topics.

Breaking Changes

  • Wire protocol is changed in a non-backwards-compatible way. The ALPN is updated to /iroh-gossip/1 . There's no downwards compatibility.
  • MSRV updtaed to 1.85
  • net::util module is now private. The utilities in here already were not intended to be used in other crates. If you were using something from there, copy-paste it into your crate.

Notes & open questions

For now, the structure of the net module is mostly unchanged. Sending is still fully sequential, even though we could send on multiple topics in parallel now. I have an unfinished branch that has a much bigger refactoring of the net module to use actor loops per topic instead of a global actor loop. However this is still unfinished, and I wanted to get a smaller version with only the wire-protocol changes out first. The refactoring to use task loops per topic is then purely internal without further wire breakage.

Change checklist

  • Self-review.
  • Documentation updates following the style guide, if relevant.
  • Tests if relevant.
  • All breaking changes documented.

Copy link

github-actions bot commented Jun 7, 2025

Documentation for this PR has been generated and is available at: https://n0-computer.github.io/iroh-gossip/pr/75/docs/iroh_gossip/

Last updated: 2025-06-09T11:08:56Z

Copy link

github-actions bot commented Jun 7, 2025

Simulation report
GossipAll-n100-r5 with 4 seeds
        RMR    LDH  missed  duration 
 mean  1.01  10.00    0.00     715ms 
  max  1.02  11.00    0.00     788ms 
  min  1.00   9.00    0.00     490ms 

GossipAll-n20-r30 with 4 seeds
        RMR   LDH  missed  duration 
 mean  1.38  5.03    0.00     394ms 
  max  1.46  7.00    0.00     443ms 
  min  1.12  3.00    0.00     232ms 

GossipMulti-n100-r30 with 4 seeds
        RMR    LDH  missed  duration 
 mean  0.34  10.17    0.00     298ms 
  max  1.50  14.00    0.00     409ms 
  min  0.07   5.00    0.00     147ms 

GossipMulti-n1000-r30 with 4 seeds
        RMR    LDH  missed  duration 
 mean  0.44  20.43    0.00     583ms 
  max  2.06  26.00    0.00     718ms 
  min  0.04  12.00    0.00     319ms 

GossipMulti-n20-r30 with 4 seeds
        RMR   LDH  missed  duration 
 mean  0.27  3.97    0.00     146ms 
  max  1.61  6.00    0.00     264ms 
  min  0.06  2.00    0.00      83ms 

GossipSingle-n100-r30 with 4 seeds
        RMR   LDH  missed  duration 
 mean  0.08  5.00    0.00     147ms 
  max  1.50  5.00    0.00     147ms 
  min  0.01  5.00    0.00     147ms 

GossipSingle-n1000-r30 with 4 seeds
        RMR    LDH  missed  duration 
 mean  0.07  12.00    0.00     319ms 
  max  2.06  12.00    0.00     319ms 
  min  0.00  12.00    0.00     319ms 

GossipSingle-n20-r30 with 4 seeds
        RMR   LDH  missed  duration 
 mean  0.14  3.00    0.00      83ms 
  max  1.44  3.00    0.00      83ms 
  min  0.06  3.00    0.00      83ms 

comparing GossipAll-n100-r5
               RMR          LDH       missed     duration 
 mean       +0.00%       +0.00%       +0.00%       +0.00% 
 max        +0.00%       +0.00%       +0.00%       +0.00% 
 min        +0.00%       +0.00%       +0.00%       +0.00% 
comparing GossipAll-n20-r30
               RMR          LDH       missed     duration 
 mean       +0.00%       +0.00%       +0.00%       +0.00% 
 max        +0.00%       +0.00%       +0.00%       +0.00% 
 min        +0.00%       +0.00%       +0.00%       +0.00% 
comparing GossipMulti-n100-r30
               RMR          LDH       missed     duration 
 mean       +0.00%       +0.00%       +0.00%       +0.00% 
 max        +0.00%       +0.00%       +0.00%       +0.00% 
 min        +0.00%       +0.00%       +0.00%       +0.00% 
comparing GossipMulti-n1000-r30
               RMR          LDH       missed     duration 
 mean       +0.00%       +0.00%       +0.00%       +0.00% 
 max        +0.00%       +0.00%       +0.00%       +0.00% 
 min        +0.00%       +0.00%       +0.00%       +0.00% 
comparing GossipMulti-n20-r30
               RMR          LDH       missed     duration 
 mean       +0.00%       +0.00%       +0.00%       +0.00% 
 max        +0.00%       +0.00%       +0.00%       +0.00% 
 min        +0.00%       +0.00%       +0.00%       +0.00% 
comparing GossipSingle-n100-r30
               RMR          LDH       missed     duration 
 mean       +0.00%       +0.00%       +0.00%       +0.00% 
 max        +0.00%       +0.00%       +0.00%       +0.00% 
 min        +0.00%       +0.00%       +0.00%       +0.00% 
comparing GossipSingle-n1000-r30
               RMR          LDH       missed     duration 
 mean       +0.00%       +0.00%       +0.00%       +0.00% 
 max        +0.00%       +0.00%       +0.00%       +0.00% 
 min        +0.00%       +0.00%       +0.00%       +0.00% 
comparing GossipSingle-n20-r30
               RMR          LDH       missed     duration 
 mean       +0.00%       +0.00%       +0.00%       +0.00% 
 max        +0.00%       +0.00%       +0.00%       +0.00% 
 min        +0.00%       +0.00%       +0.00%       +0.00% 

Last updated: 2025-06-09T11:09:57Z

@n0bot n0bot bot added this to iroh Jun 7, 2025
@github-project-automation github-project-automation bot moved this to 🏗 In progress in iroh Jun 7, 2025
@Frando Frando requested a review from divagant-martian June 7, 2025 12:11
@Frando Frando marked this pull request as ready for review June 7, 2025 12:11
@Frando Frando changed the title refactor(net)!: use uni streams per topic refactor!: change wire protocol to use uni streams per topic Jun 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🏗 In progress
Development

Successfully merging this pull request may close these issues.

1 participant