Commit Graph

5375 Commits

Author SHA1 Message Date
Frando 5a8f972014 fix: spread connections over sockets with the same address and routes
Sockets with the same local address and routes, such as SO_REUSEPORT
sockets bound for parallel receive, now share one entry of the route
table. Each connection creates its sender on the next of them in turn
and keeps it. Before, all sends went through the first such socket.
Receiving was already parallel, with one task per socket.

Routes are compared regardless of their order.
2026-11-20 14:12:11 +01:00
Frando 06272882f2 perf: send connection events after releasing the endpoint lock
The receive tasks of an endpoint with multiple sockets sent each
datagram's connection event while holding the endpoint lock. Sending
wakes the connection's task, which may wake a runtime worker thread, so
every other receive task waited for those wakeups too.

Collect the events of a batch into a buffer reused across batches, and
send them after the lock is released. The single-socket driver holds
the lock throughout, and sends them right after each batch as before.
2026-11-20 13:30:59 +01:00
Frando eafb8fee5e perf: match routes with one mask and compare
The route table runs for every path on each transmit. Each lookup made
up to two passes over the routes, and each check canonicalized the
addresses and built the network of an IpNet. On a table like iroh's,
with five routes, a lookup took 25 to 110 ns.

Routes now keep their destinations as the bits of an IPv6 address, with
IPv4 as IPv4-mapped. A check is a mask and a compare, and one pass also
finds the default route. A lookup now takes 9 to 19 ns. Socket ids are
indices into the table, so a connection finds its sender without a
search.

An IPv4 prefix now counts as its IPv4-mapped prefix when routes are
sorted. Before, ::ffff:0:0/96 sorted ahead of 10.0.0.0/8, although
10.0.0.0/8 is the longer prefix.

Both receive paths now share RecvState::handle_received, which also
maps sources to IPv6 when the endpoint keeps addresses as IPv6.
2026-11-20 10:00:51 +01:00
Frando db4cfcc791 test: endpoints with multiple sockets
Covers serving on an IPv4 and an IPv6 socket, the default
Runtime::wrap_udp_socket_next, adding sockets to a running endpoint and
its connections, a failing receiver, and a blocked socket that resumes.
2026-11-20 10:00:51 +01:00
Frando b98fbd5a07 feat: endpoints with multiple sockets
An endpoint has a single socket, so it cannot receive on several sockets
in parallel, and one busy socket stalls all sends. iroh has to put all
its transports behind one socket, polls them in turn, and drops
datagrams when a transport is not ready.

Endpoint::new_with_multiple_sockets takes sockets that implement the new
AsyncUdpSocketNext trait, each with its SocketRoutes. The endpoint picks
the socket for each transmit from an internal route table, by
destination and source address. Each receiver of a socket runs in its
own task. A socket that returns Pending holds back only the paths routed
to it. Endpoint::add_socket adds sockets later, also for existing
connections.

AsyncUdpSocket, the single-socket path and rebind are unchanged.
2026-11-20 10:00:51 +01:00
Robert Queenin b36dc4de8e refactor(proto): call the std-only float math through crate-root helpers (#848)
<!-- Attention agents and contributors using AI, please see our AI
policy before opening a PR:
https://github.com/n0-computer/noq/blob/main/AI_POLICY.md -->
<!-- Any PRs violating this policy will be closed. -->

<!-- As per our contributor guidelines, all PRs that do not link to an
issue with the label `ready-for-pr` will be closed:
https://github.com/n0-computer/noq/blob/main/CONTRIBUTING.md -->

## Description

Closes #847

`round`, `cbrt`, and `powi` on `f64` exist only in `std`. With the calls
going through a `math` module at the crate root, a build without `std`
can switch them to `libm` in one place.

`clippy.toml` prevents new code from calling the `std` methods directly.


## API Changes

None

## Notes & open questions

<details>
<summary>Design notes</summary>

- Functions, not an extension trait: with `std`, the inherent `f64`
methods win over trait methods, so the trait import would be unused and
warn, and `disallowed_methods` would flag every call.
- The BBRv3 tests call `math::round` too, because the lint also checks
test code.

</details>


## Change checklist

- [x] Self-review.
- [x] Documentation updates following the [style
guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text),
if relevant.
- [x] Tests if relevant.
- [x] All API changes documented.
- [x] `cargo make` passes locally.

---------

Co-authored-by: Floris Bruynooghe <flub@n0.computer>
2026-11-20 01:25:25 +00:00
Floris Bruynooghe 9c5052e86e refactor(proto): Avoid PathId allocation when building PATH_ACKS (#901)
## Description

When writing PATH_ACK frames into a packet we need to iterate all the
paths which have such frames to write. Because of borrowing issues
this was allocating a Vec<PathId> each time this happened which is
fairly silly.

By passing the &mut PacketNumberSpace directly from the iteration this
allocation can be avoided, and the iteration is much more sane.

## API Changes

n/a

## Notes & open questions

This came out of me trying to understand #879 where this is singled
out as an expensive allocation. It was much simpler to directly make
the PR once I understood what was being described.

## Change checklist

- [x] Self-review.
- [x] Documentation updates following the [style
guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text),
if relevant.
- [x] Tests if relevant.
- [x] All API changes documented.
- [x] `cargo make` passes locally.
2026-11-19 20:08:21 +00:00
ramfox c7b87d5843 chore: Release noq-proto-v1.5.0 noq-udp-v1.5.0 noq-v1.5.0 2026-11-18 22:01:16 -05:00
Floris Bruynooghe 5d4856945b chore(deps): fix unused crates warnings of rust 1.100 (#899)
## Description

rust 1.100 finally warns us about unused crates, which is nice. But now
the crates we have as an indirect dependency to make our unused crates
work correctly trigger the warning.

Apparently what we were supposed to do was add a cfg(false) section for
those dependencies. That does not trigger the warnings and still affects
the resolution. It also made us notice tokio-streams is now accidentally
used.

So I moved tokio-streams to the normal dependencies. The rest of the
normal dependencies is only re-ordered to be alphabetical (it is always
supposed to be but we don't lint on it).

## API Changes

n/a

## Notes & open questions

n/a

## Change checklist

- [x] Self-review.
- [x] Documentation updates following the [style
guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text),
if relevant.
- [x] Tests if relevant.
- [x] All API changes documented.
- [x] `cargo make` passes locally.
2026-11-18 09:03:06 +00:00
Floris Bruynooghe bb1c63ee62 chore: Update issue template checkboxes (#897)
## Description

This explicitly refers to the AI policy and aims to make the text more
welcoming.

## API Changes

n/a

## Notes & open questions

n/a

## Change checklist

- [x] Self-review.
- [x] Documentation updates following the [style
guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text),
if relevant.
- [x] Tests if relevant.
- [x] All API changes documented.
- [x] `cargo make` passes locally.
2026-11-18 03:26:18 +00:00
Floris Bruynooghe d2367f41c7 chore: humantime is unmaintained (#900)
## Description

That's fine for now.

## API Changes

n/a

## Notes & open questions

`cargo make` needs #899 to be merged. But that needs this to be
unblocked because the world is just mad.

## Change checklist

- [x] Self-review.
- [x] Documentation updates following the [style
guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text),
if relevant.
- [x] Tests if relevant.
- [x] All API changes documented.
- [ ] `cargo make` passes locally.
2026-11-18 01:45:53 +00:00
Floris Bruynooghe 4f5b094f98 chore(ci): fix workflows for test binaries locations (#896)
## Description

Rust 1.100 moved around where test binaries are. Update the workflows
so that we're not dependent on this.

## API Changes

n/a

## Notes & open questions

none

## Change checklist

- [x] Self-review.
- [x] Documentation updates following the [style
guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text),
if relevant.
- [x] Tests if relevant.
- [x] All API changes documented.
- [x] `cargo make` passes locally.
2026-11-17 07:44:45 +00:00
Franz Heinzmann a80c82e497 fix(perf): don't enable qlog feature in perf binary (#850)
## Description

We shouldn't enable the `qlog` feature for our `perf` binary by default.
qlog slows things down considerably, and it shouldn't be on by default
for a perf-measuring tool.

## Change checklist

- [x] Self-review.

---------

Co-authored-by: Floris Bruynooghe <flub@n0.computer>
2026-11-16 22:24:22 +00:00
Zheng She bb9a5edca1 fix(proto): track the key update boundary per path (#869)
Fixes #864

## Description

`PrevCrypto` now records, for each path, the first packet received under
the new keys. A packet decrypts with the previous keys until its own
path has seen one. `end_packet` is split into `end_time` (still used by
the discard timer) and `end_packets`. Adds
`key_update_keeps_late_old_key_packets_on_another_path`, which fails on
main.

## Notes

A path with no new-key packet yet keeps using the previous keys, so a
further key update the peer started on such a path before we drop the
old keys would fail to decrypt. RFC 9001 §6.5 has the peer wait three
PTOs after its previous update is acknowledged, and accepts that packets
may be discarded if it doesn't.

## Change checklist

- [x] Self-review.
- [x] Tests if relevant.
- [x] `cargo make` passes locally.
2026-11-12 14:15:36 +00:00
ramfox 577359636c tests: additional stream affinity tests (#890)
<!-- Attention agents and contributors using AI, please see our AI
policy before opening a PR:
https://github.com/n0-computer/noq/blob/main/AI_POLICY.md -->
<!-- Any PRs violating this policy will be closed. -->

<!-- As per our contributor guidelines, all PRs that do not link to an
issue with the label `ready-for-pr` will be closed:
https://github.com/n0-computer/noq/blob/main/CONTRIBUTING.md -->

## Description

Add additional tests for stream affinity.

noq-proto test is a vanity test so I can have a hook into starting to
understand stream affinity and packet building.

<!-- A summary of what this pull request achieves and a rough list of
changes. -->

## API Changes

<!-- Optional, any API additions, deprecations or breaking changes,
including how to migrate older code. -->

## Notes & open questions

<!-- Any notes, remarks or open questions you have to make about the PR.
-->
Not finished, going to add additional tests for these cases:
- general noq test showing affinities are respected
- test showing stream affinity changes happen if you change from block
-> any


## Change checklist

- [x] Self-review.
- [x] Documentation updates following the [style
guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text),
if relevant.
- [x] Tests if relevant.
- [x] `cargo make` passes locally.
2026-11-11 10:14:03 +00:00
Floris Bruynooghe 2f3ba68ab1 feat: allow streams to set an affinity for a path, simple version (#881)
## Description

This allows streams to declare an affinity to a particular path. The
path ID must be known, which can be retrieved from path events etc.

## API Changes

New API:
- `SendStream::set_affinity`

## Notes & open questions

Replaces #871.

The way to to discover which paths are available and how to get updates
to them could be improved. But the existing APIs are already able to do
this. E.g. iroh does expose this in an easier way already. Improving
those APIs can be a reasonable thing to do, but does not need to be part
of this API.

This does not yet allow setting a connection-wide affinity. It is too
easy to accidentally block all data on a connection. There are already
other APIs that affect global path use: closing paths or using the path
status. This is specifically for stream-specific exceptions, so leaving
the API like this makes this more clear.

## Change checklist

- [x] Self-review.
- [x] Documentation updates following the [style
guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text),
if relevant.
- [ ] Tests if relevant.
- [x] All API changes documented.
- [x] `cargo make` passes locally.
2026-11-09 21:43:48 +00:00
Rüdiger Klaehn 04807b674c fix(udp): handle receive errors before truncation flags in recv_single (#884)
## Description

Fixes #883.

## Notes & open questions

These are just two cherry-picks. Still needs review from somebody
familiar with the context.

Verified that
`recv_single_after_truncation_returns_would_block_instead_of_spin` fails
without the fix (macOS).

## Change checklist

- [x] Self-review.
- [ ] ~~Documentation updates following the [style
guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text),
if relevant.~~
- [x] Tests if relevant.
- [ ] ~~All API changes documented.~~
- [x] This PR was created by a human that thought critically about the
      proposed change and wrote an as clear and concise description as
      they could.
- [x] This PR isn't slop, and is carefully crafted to do have the
      intented effect.
- [x] `cargo make` passes locally.

---------

Co-authored-by: zerox80 <rujbin@protonmail.com>
Co-authored-by: Dirkjan Ochtman <dirkjan@ochtman.nl>
2026-11-04 16:58:09 +00:00
Floris Bruynooghe 99ad1cc0c7 chore: Upgrade async-executor and allow warnings in patchbay build (#888)
## Description

- There was a use-after-fee regression in 1.14 that means it was yanked
which made cargo-deny unhappy.

- patchbay failed to build because noq main has deprecated an API that
iroh uses. But we don't actually care about build warnings of iroh in
noq. Allow them.

## API Changes

n/a

## Notes & open questions

n/a

## Change checklist

- [x] Self-review.
- [x] Documentation updates following the [style
guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text),
if relevant.
- [x] Tests if relevant.
- [x] All API changes documented.
- [x] `cargo make` passes locally.
2026-11-04 15:48:46 +00:00
Floris Bruynooghe 70fdbfa24e chore: Use shared minimal-crates worksflow (#862)
## Description

This moves the minimal-crates tests to the shared workflow. This will
allow us to make this test required again as it should no longer fail
when we release our own crates.

Also triggers the wine and zizmor workflows for the merge queue, so that
we can make those required checks as well.

## API Changes

n/a

## Notes & open questions

Needs a new tag on the workflows repo once
https://github.com/n0-computer/workflows/pull/10 is merged. Then pinact
and zizmor will be happy here.

This will allow us making the min-crates a required check again.

## Change checklist

- [x] Self-review.
- [x] Documentation updates following the [style
guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text),
if relevant.
- [x] Tests if relevant.
- [x] All API changes documented.
- [x] `cargo make` passes locally.
2026-10-28 11:42:34 +00:00
Floris Bruynooghe 9672cac792 tests: Increase local slow-tests timeout (#860)
## Description

The new BBR3 tests do so much work that they're slow. I guess we have
to accept this slowness for now :(

## API Changes

n/a

## Notes & open questions

This is kinda sad, but I didn't see an easy win as to why they're slow.

## Change checklist

- [x] Self-review.
- [x] Documentation updates following the [style
guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text),
if relevant.
- [x] Tests if relevant.
- [x] All API changes documented.
- [x] `cargo make` passes locally.
2026-10-28 10:03:39 +00:00
Thtbee_ b70f1f2e44 fix(proto): keep unread data when compacting an unordered stream (#867)
## Description

Fixes #865.

`defragment` dropped everything below `bytes_read`, which in unordered
mode is a count of delivered bytes, not an offset, so compaction could
throw away data that was never read. `defragment` now takes the offset
to discard below: `insert` passes 0, and only the switch to unordered
mode passes `bytes_read`, where it's still an offset. That matches
quinn.

Adds `unordered_compaction_keeps_unread_data`, the repro from the issue.

## API Changes

None.

## Notes & open questions

This touches `defragment` like #866, so whichever lands second needs a
small rebase.

## Change checklist

- [x] Self-review.
- [x] Documentation updates following the [style
guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text),
if relevant.
- [x] Tests if relevant.
- [x] All API changes documented.
- [x] `cargo make` passes locally.
2026-10-27 17:04:53 +00:00
Thtbee_ 3ff2822f9e fix(proto): coalesce contiguous chunks during defragment (#866)
## Description

Replaces #828, as discussed there. The first two commits of that PR
landed in #823, so this is the remaining one: the port of
quinn-rs/quinn#2814, adapted to the sorted `VecDeque` from #823.

Without it, 1.4.0 can close a connection with "too many gaps in stream
buffer" when a reader falls about 2,048 packets behind, even with no
gaps. Packet-sized chunks get marked defragmented and are never merged
again, so compaction can't get back under `MAX_CHUNKS`. `defragment` now
also merges contiguous chunks smaller than `buffered / MAX_CHUNKS` (at
least 128 bytes), like quinn.

Brings over quinn's two tests. `ordered_lossless_stream_is_not_rejected`
fails on `main` and passes here.

## API Changes

None.

## Notes & open questions

quinn-rs/quinn#2955 (contiguous data behind a single gap under sustained
loss) is still open upstream and isn't covered here. This touches
`defragment` like #867 (the fix for #865), so whichever lands second
needs a small rebase.

## Change checklist

- [x] Self-review.
- [x] Documentation updates following the [style
guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text),
if relevant.
- [x] Tests if relevant.
- [x] All API changes documented.
- [x] `cargo make` passes locally.

Co-authored-by: Eanna Lyons <eanna@magic.dev>
Co-authored-by: Luke Curley <kixelated@gmail.com>
Co-authored-by: Floris Bruynooghe <flub@n0.computer>
2026-10-27 11:59:46 +00:00
Floris Bruynooghe 2f667bd06a deps: Bump tokio for RUSTSEC-2026-0386 (#868)
## Description

Makes cargo-deny happy.

## API Changes

n/a

## Notes & open questions

Not bumping Cargo.toml as we didn't need any code changes. So we're
not using any of the dangerous APIs.

## Change checklist

- [x] Self-review.
- [x] Documentation updates following the [style
guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text),
if relevant.
- [x] Tests if relevant.
- [x] All API changes documented.
- [x] `cargo make` passes locally.
2026-10-27 11:26:48 +00:00
Philipp Pohl-Krüger 07047ffa93 feat(proto): Implement noq_proto::SendStream::set_affinity (#836)
## Description

Implements setting a stream's affinity to being sent on paths. See the
doc comment on `SendStream::set_affinity` for more information.

This is implemented via keeping multiple `PendingStreamsQueue`s instead
of just one: One queue for each possible affinity, except
`StreamAffinity::Block`, which doesn't need a queue.

On sending in each path, we first check the `any` queue, and then
compare it with pending streams that are pinned to our path.
Between these we compare which one is supposed to go first and use that.

When a stream changes affinity, we need to potentially move it between
queues.

If a stream goes from blocked to another affinity, we don't restore its
recency, instead, we give it a new one. This is as if the data the
stream had queued were submitted just when switching. This is to avoid a
situation in which someone suddenly unblocks a lot of small streams
after a long time of being blocked and these streams suddenly jumping
the queue and starving out other streams.

## API Changes

- Adds `noq_proto::StreamAffinity`
- Adds `noq_proto::SendStream::set_affinity`

## Notes & open questions

- Plan is to also add APIs for noq, but not in this PR
- This is stacked on top of #835 because that simplifies this
implementation.
- This somewhat conflicts with #859 but the conflicts are reconcilable.
- I'm using `PendingQueueMut` as an abstraction to ensure we don't
accidentally leave empty `PendingStreamsQueue`s around for sticky paths
that don't exist anymore.

## Change checklist

- [x] Self-review.
- [x] Documentation updates following the [style
guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text),
if relevant.
- [x] Tests if relevant.
- [x] All API changes documented.
- [x] `cargo make` passes locally.

---------

Co-authored-by: Floris Bruynooghe <flub@n0.computer>
2026-10-23 11:05:37 +00:00
Asmir Avdicevic c1c4950674 fix(ci): bump deps for illumos (#856)
<!-- Attention agents and contributors using AI, please see our AI
policy before opening a PR:
https://github.com/n0-computer/noq/blob/main/AI_POLICY.md -->
<!-- Any PRs violating this policy will be closed. -->

<!-- As per our contributor guidelines, all PRs that do not link to an
issue with the label `ready-for-pr` will be closed:
https://github.com/n0-computer/noq/blob/main/CONTRIBUTING.md -->

## Description

Recent runner images got bumped from Ubuntu 24.04 to 26.04 and some of
the package layout changed. Bumping the dep makes sure things work
again.

## API Changes

<!-- Optional, any API additions, deprecations or breaking changes,
including how to migrate older code. -->

## Notes & open questions

<!-- Any notes, remarks or open questions you have to make about the PR.
-->

## Change checklist

- [x] Self-review.
- [x] Documentation updates following the [style
guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text),
if relevant.
- [x] Tests if relevant.
- [x] All API changes documented.
- [x] `cargo make` passes locally.

Co-authored-by: Floris Bruynooghe <flub@n0.computer>
2026-10-23 08:52:29 +00:00
Asmir Avdicevic 2d7214a98e chore(ci): migrate CI runners mostly to blacksmith (#861)
<!-- Attention agents and contributors using AI, please see our AI
policy before opening a PR:
https://github.com/n0-computer/noq/blob/main/AI_POLICY.md -->
<!-- Any PRs violating this policy will be closed. -->

<!-- As per our contributor guidelines, all PRs that do not link to an
issue with the label `ready-for-pr` will be closed:
https://github.com/n0-computer/noq/blob/main/CONTRIBUTING.md -->

## Description

Similarly to iroh were moving noq onto blacksmith runners. 
https://github.com/n0-computer/iroh/pull/4635

## API Changes

<!-- Optional, any API additions, deprecations or breaking changes,
including how to migrate older code. -->

## Notes & open questions

<!-- Any notes, remarks or open questions you have to make about the PR.
-->

## Change checklist

- [x] Self-review.
- [x] Documentation updates following the [style
guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text),
if relevant.
- [x] Tests if relevant.
- [x] All API changes documented.
- [x] `cargo make` passes locally.
2026-10-22 17:09:02 +00:00
Floris Bruynooghe eece61a9d0 feat: Bump minor version number to fix semver CI (#857)
## Description

feat rather than chore because of the minor version bump, even though
this isn't directly a feat itself.

## API Changes

n/a

## Notes & open questions

none

## Change checklist

- [x] Self-review.
- [x] Documentation updates following the [style
guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text),
if relevant.
- [x] Tests if relevant.
- [x] All API changes documented.
- [x] `cargo make` passes locally.
2026-10-22 15:55:46 +00:00
Philipp Pohl-Krüger a78daf8714 feat(noq-proto): deprecate send_fairness and remove unfair scheduling (#835)
## Description

Always schedule equal-priority streams round-robin, removing
continuation handling before introducing stream affinity. Keep the
setter as a deprecated no-op for source compatibility.

## API Changes

- `noq::TransportConfig::send_fairness` is now deprecated.

## Notes & open questions

We might want to wait for #833 before we release with this PR, so we can
have an alternative to link to in deprecation documentation (the
`incremental=false` setting).

## Change checklist

- [x] Self-review.
- [x] Documentation updates following the [style
guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text),
if relevant.
- [x] Tests if relevant.
- [x] All API changes documented.
- [x] `cargo make` passes locally.
2026-10-22 08:55:05 +00:00
Philipp Pohl-Krüger f40e402484 chore(deps): Update rustls-webpki and webpki-root-certs in lockfile (#855)
## Description

Updates webpki dependency versions in lockfile due to
`RUSTSEC-2026-0383` and `RUSTSEC-2026-0382`.

## API Changes

None.

## Notes & open questions

No changes to `Cargo.toml`, because they're only indirect dependencies.

## Change checklist

- [x] Self-review.
- [x] Documentation updates following the [style
guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text),
if relevant.
- [x] Tests if relevant.
- [x] All API changes documented.
- [x] `cargo make` passes locally.
2026-10-21 13:44:57 +00:00
ramfox 34f75c49f9 chore: Release noq-proto-v1.4.0 noq-udp-v1.4.0 noq-v1.4.0 2026-10-20 13:16:07 -04:00
Robert Queenin 117e54cb84 refactor(proto): name the hash map types through crate-root aliases (#845)
<!-- Attention agents and contributors using AI, please see our AI
policy before opening a PR:
https://github.com/n0-computer/noq/blob/main/AI_POLICY.md -->
<!-- Any PRs violating this policy will be closed. -->

<!-- As per our contributor guidelines, all PRs that do not link to an
issue with the label `ready-for-pr` will be closed:
https://github.com/n0-computer/noq/blob/main/CONTRIBUTING.md -->

## Description

Closes #840

A build without `std` needs `hashbrown` maps in place of the `std` ones,
including the `rustc-hash` and `identity-hash` maps, (`std` maps with a
different hasher). With the map types and `hash_map::Entry` named in one
place, as time already is, that becomes a change to `lib.rs` alone. The
`clippy.toml` keeps new code from going around it.


## API Changes

None

## Notes & open questions

<details>
<summary>Design notes</summary>

- Type aliases instead of the `use` re-exports from the issue: clippy
resolves a re-export to the original type, so it would flag every use.
- `hash_map::Entry` goes through an alias in a crate-root `hash_map`
module, so the existing `hash_map::Entry::Occupied` matches stay as they
are. Clippy catches a direct `use std::collections::hash_map::Entry`,
but not `use std::collections::hash_map;`, because it can't ban a module
import (rust-lang/rust-clippy#9489). A CI build without `std` will catch
that case.


</details>


## Change checklist

- [x] Self-review.
- [x] Documentation updates following the [style
guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text),
if relevant.
- [x] Tests if relevant.
- [x] All API changes documented.
- [x] `cargo make` passes locally.
2026-10-20 09:01:13 +00:00
Zac Shenker 13b93f70ae fix(proto): issue flow control credit once for streams both stopped and reset (#842)
## Description

A receive stream that is both stopped and reset gets its
connection-level flow control credit issued twice for unread data.

Both paths credit unread data without knowing whether the other already
did:

- `RecvStream::stop` credits `end - bytes_read`
- `StreamsState::received_reset` credits `final_size - bytes_read`

Example: 32 bytes received and unread, final size 64. Stopping credits
32, then the reset credits 64, so `local_max_data` grows by 96 instead
of 64. The same happens in the other order (reset, then stop). The peer
can then send more than the receive window allows before we'd consider
it a flow control violation.

The fix tracks, per stream, how much credit has already been issued for
data the application will never read (`Recv::unread_credit`).
`Recv::take_unread_credit` returns only what's still owed, so each byte
of the stream is credited once regardless of the order of stop, reset
and incoming frames. Reads still credit through `Chunks::finalize` as
before.

Two regression tests cover both orders: `stopped_reset_flow_control` and
`reset_stopped_flow_control`. Both fail on `main` (crediting 96 instead
of 64).

Found while working on RESET_STREAM_AT (#809), which builds on this.

## Breaking Changes

None.

## Change checklist
- [x] Self-review.
- [x] Tests if relevant.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Floris Bruynooghe <flub@n0.computer>
2026-10-19 10:52:01 +00:00
Diva Martínez 58869bfbb0 Merge commit 'ba18f6c12ad96a66c92d38471eb3370b7bd68337' into sync-upstream 2026-10-16 10:13:14 -05:00
Otto Hermann 4523eaa63c perf(proto): replace the assembler BinaryHeap with a sorted VecDeque (#823)
Closes #2739 via option 1.

Chunks now live in a `VecDeque` ordered by offset instead of a
`BinaryHeap`:
- `read` takes from the front
- an in-order frame appends to the back
- a frame below everything buffered pushes to the front; anything else
is placed by binary search

Two orderings are now explicit:
- a partial read can advance the front chunk past a neighbour it
overlaps
- `defragment` has to emit the accumulated chunk before a later
defragmented one

Tie order stays unspecified, as it was under the heap.

Measurements
- nanoseconds per frame
- 1200 byte frames
- best-of-N with N sized to at least 300ms per case
- median of five processes, or three for the bounded-read and 32 chunk
rows
- binaries interleaved

Note: the figures I posted in the issue were best-of-40 and too noisy to
use, so please ignore them.

| case | BinaryHeap | VecDeque |
| --- | --- | --- |
| in-order, 1 chunk buffered | 52.6 | 31.5 |
| in-order, 25 chunks buffered | 64.1 | 31.5 |
| in-order, 127 chunks buffered | 84.7 | 31.8 |
| in-order, 1000 chunks buffered | 108.4 | 31.9 |
| in-order, 127 buffered, 1024 byte reads | 106.6 | 55.8 |
| descending offsets | 36.1 | 18.8 |
| gapped inserts mid-range, 32 buffered | 37.1 | 68.9 |
| gapped inserts mid-range, 500 buffered | 38.5 | 187.2 |
| gapped inserts mid-range, 1500 buffered | 37.1 | 423.9 |
| one `defragment` call at 1900 chunks | 179 us | 39 us |

Summary
- about 19ns of each in-order row (in both columns) is `Bytes::clone`
plus the `Chunk` drop
- the heap slows down as the buffer deepens and the deque does not
- the bounded-read row exercises the partial-read path, where the new
code restores ordering by hand; it costs nothing measurable, since the
guard returns immediately on in-order data

The gapped rows are what it costs: the deque is already the slower of
the two by about 32 buffered chunks; `COMPACT_THRESHOLD` holds the
buffer to 2048 chunks of 56 bytes, so the shift should stay under ~57KB;
in unordered mode the dedup loop can do several of these inserts for one
frame, which I measured at parity with the heap.

`defragment` gets cheaper because its input is already ordered, so it no
longer sorts.

(cherry picked from commit ba18f6c12a)
2026-10-16 10:03:50 -05:00
Jaideep Pyne 5fecec88f4 fix(proto): apply RFC 9000 §12.4 packet-type rules to CONNECTION_CLOSE (#823)
RFC 9000 §12.4 Table 3 marks CONNECTION_CLOSE `ih01`, where `ih` means
"Only a CONNECTION_CLOSE frame of type 0x1c can appear in Initial or
Handshake packets", and §12.4 requires PROTOCOL_VIOLATION on receipt of
a frame in a packet type that is not permitted.

quinn applies this on the send path: `poll_transmit` rewrites an
application close into a 0x1c close with APPLICATION_ERROR for non-Data
spaces, per §10.2.3. The receive path does not.

Two changes, one per direction:

1. `process_early_payload` accepted both close types. Initial packets
are protected with keys derived from the cleartext original DCID, so
anyone observing the handshake can forge one and hand the application an
arbitrary application error code and reason phrase. Now only 0x1c is
accepted; 0x1d falls through to the existing "illegal frame type in
handshake" arm.

2. The 0-RTT filter rejected a 0x1d close. §12.5 lists the frames that
cannot appear in 0-RTT as ACK, CRYPTO, HANDSHAKE_DONE, NEW_TOKEN,
PATH_RESPONSE and RETIRE_CONNECTION_ID. CONNECTION_CLOSE is not in that
list, and §19.19 says 0x1d "can only be sent using 0-RTT or 1-RTT
packets". This turned a peer's clean application close into a transport
error.

Test: `application_close_in_initial_is_rejected` builds an
Initial-key-protected packet containing a 0x1d close and checks the
connection fails with PROTOCOL_VIOLATION rather than surfacing
`ApplicationClosed`. It fails before this change. There is no test for
the 0-RTT half because quinn never emits such a packet itself:
`poll_transmit` skips the Data space for a close unless 1-RTT keys
exist, so it cannot be reproduced quinn to quinn.

`cargo test -p quinn-proto` passes (294), `cargo test -p quinn` passes
(23), fmt and clippy are clean.

(cherry picked from commit d5d5b978c2)
2026-10-16 10:03:50 -05:00
Diva Martínez f268351284 tests(proto): port connection_close_while_congestion_blocked to noq's api 2026-10-16 10:03:50 -05:00
christofferbing a17c35e55a tests(proto): Test that CONNECTION_CLOSE is sent even when congestion blocked (#823)
The commit cherry-picked by the current one fixes a bug in quinn that we
had already solved in noq. The cherry-pick limits the brought changes to
adding the test.

Fixes #2785.

Calling `close()` while the congestion window is full never gets
CONNECTION_CLOSE onto
the wire. The gate in `poll_transmit` classifies the packet by the
stream frames still
pending in the space, but a closing connection will never send those —
the packet it
actually builds is just ACKs + CONNECTION_CLOSE. And once closed nothing
can reopen the
gate: incoming ACKs aren't processed anymore so in-flight bytes never
drain, and
`close_common()` stopped the loss timers so the `loss_probes` bypass
never fires. The
peer just sits there until its idle timeout.

We hit this cancelling a bulk sender mid-transfer — captures showed zero
close datagrams
leaving, every time the cancel landed on a saturated window.

Fix is to exempt close packets from the gate, same idea as the existing
tail-loss-probe
exemption on the line above: the close packet isn't congestion
controlled, and blocking
it can deadlock.

The new test saturates the window with unacked data, closes, and checks
the peer sees
the right close code/reason within a few PTOs instead of idle-timing
out. Fails on main,
passes with the change.

(cherry picked from commit e556fde4b5)
2026-10-16 10:03:50 -05:00
Luke Curley dcb8949c3b feat(proto): Expose BBR bandwidth estimate in path stats (#823)
Expose the bandwidth estimate from the congestion controller.

With Reno/CUBIC we can compute this from window / RTT, but for BBR we
need the actual estimate from the CC algorithm.

(cherry picked from commit 766cca4822)
2026-10-16 10:03:50 -05:00
vcarus dd77a46be4 fix(proto): Treat an equal-size delivery as evidence against a preceding loss burst (#823)
Fixes #2791.

`BlackHoleDetector::on_non_probe_acked` returned early for any packet no
larger than `acked_mtu`, so once a full-size packet had been
acknowledged, `largest_post_loss_packet` never advanced again as long as
every packet was full-size — the steady state of a bulk transfer.
Because `on_ack_received` registers acknowledgments before running loss
detection, one ACK that confirms newer full-size packets and reveals ≥
`BLACK_HOLE_THRESHOLD + 1` older non-adjacent holes then judged all of
those holes suspicious, even though the same ACK had just shown that
full-size packets still get through. On a lossy path this turns ordinary
congestion loss during a download into a black hole verdict and a drop
to `min_mtu` (details and production numbers in #2791).

The change: when `len == acked_mtu`, keep `acked_mtu` but advance
`largest_post_loss_packet` to the newer packet number, so loss bursts
that precede that delivery are non-suspicious under the existing rule
while losses transmitted after the last delivery remain suspicious. This
matches the design in #1855 ("larger than any more recently acknowledged
packet").

The new unit test fails on `main` before the change and passes after;
the existing black hole tests, including
`blackhole_after_mtu_change_repairs_itself`, still pass.

On 0.11.x this fix alone is not sufficient because `finish_loss_burst`
there still uses strict `<` (fixed on `main` by #2400 but not
backported); I have a branch with #2400's two commits cherry-picked plus
this one, all tests green
(https://github.com/vcarus/quinn/tree/bhd-0.11.x), if you'd like a
backport PR.

Co-authored-by: vcarus <8207711+vcarus@users.noreply.github.com>
(cherry picked from commit b0afb6e6fb)
2026-10-16 10:03:50 -05:00
Benjamin Saunders 09dd4ee6c7 fix(proto): Limit total memory used to buffer outgoing datagrams (#823)
(cherry picked from commit 35fe337920)
2026-10-16 10:03:50 -05:00
Benjamin Saunders 2ea64e1378 fix(proto): Limit total memory used to buffer incoming datagrams (#823)
(cherry picked from commit a3109c3413)
2026-10-16 10:03:50 -05:00
Benjamin Saunders 1c51be56cb refactor(proto): Factor out DatagramBuffer for queues in either direction (#823)
(cherry picked from commit de0f03ba6f)
2026-10-16 10:03:50 -05:00
Diva Martínez 78a4b2eed5 fix(proto): Check limits when processing already retired CIDs (#823)
Extract Retransmits::retire_cids, bounding pending_retired regardless of
which branch queues a retirement. The Ok(Some(..)) branch already enforced
MAX_PENDING_RETIRED_CIDS; the Err(InsertError::Retired) branch pushed
directly onto retire_cids, bypassing the cap entirely. Route both call sites
through the shared, bounded method instead of duplicating the check.
2026-10-16 10:03:46 -05:00
Otto Hermann b08b5e1ad4 fix(proto): bound assembler chunk count regardless of over-allocation (#823)
The `TooManyChunks` cap was only checked inside the over-allocation
branch of `Assembler::insert`, and only for the tail push. A peer
sending many small gapped STREAM frames can keep over-allocation below
the defragmentation threshold while the chunk count grows to the stream
flow-control limit, and frames handled entirely by the unordered dedup
loop return before the check runs. Either way the buffered chunk count
is unbounded, which is the memory-exhaustion class the original advisory
addressed.

Check the chunk count after every push, including the unordered dedup
loop, and compact once it passes a watermark above the cap so that a
flood of mergeable (duplicate or contiguous) frames cannot force a
defragmentation on every frame. A stream is rejected once compaction
cannot bring the distinct span count back to the cap. Buffered chunks
are bounded at O(twice the cap); the count is re-checked after every
insert, though a single unordered frame may transiently push a few
chunks past the watermark before that check.

(cherry picked from commit 4b88c9403a)
2026-10-15 15:48:37 -05:00
Dmitry Adamushka fdd408710f refator(proto): route locally-created CIDs via RouteDatagramTo (#823)
The locally-created-CID index (`connection_ids`) mapped directly to
`ConnectionHandle`, while the initial-DCID index already used
`RouteDatagramTo`. Store `RouteDatagramTo` in `connection_ids` too:
`new_cid` takes the route to register, and `ConnectionIndex::get`
returns it without re-wrapping.

No behavior change (every route is still `RouteDatagramTo::Connection`);
this is what later lets a locally-created CID point at an in-flight
`Incoming`.

(cherry picked from commit 97a5386e06)
2026-10-15 15:48:37 -05:00
Dmitry Adamushka 9fc7f7086d fix(proto): pass CID length/lifetime to Connection::new directly (#823)
`Connection::new` only queried `cid_len()` and `cid_lifetime()` on the
generator; it never minted a CID. Take the two values directly.

(cherry picked from commit c9008d05a9)
2026-10-15 15:48:37 -05:00
Thomas Eizinger 31032ff12d feat(udp): deprecate UdpSocketState::send (#823)
The `send` API handles IO errors by logging them. This is an error
handling policy that can just as easily be implemented by consumers as
well.

More importantly, upcoming features like the support for partial sends
conflicts with this API because we cannot return a truthful `Ok(())`
value when silencing an error.

To preserve the original behaviour of logging non-fatal IO errors, quinn
itself is transitioned to rate-limit the logging of errors inside each
`UdpSenderHelper`. This is a slight change in behaviour. Previously, the
errors were rate-limited per socket whereas now the errors are
rate-limited per `UdpSenderHelper`. Several of those share a single
socket.

(cherry picked from commit 148d760d88)
2026-10-15 15:48:29 -05:00
Bastien Veuthey 9612584d78 fix(proto): Allow the cwnd to be filled exactly (#823)
(cherry picked from commit acfec5f04c)
2026-10-15 15:46:54 -05:00
cnsky1103 56522d838f docs(noq): Document cancellation safety for accept_uni, accept_bi and read_datagram (#823)
(cherry picked from commit 8663c76177)
2026-10-15 15:46:54 -05:00
0x676e67 56a85081c3 chore(proto): fix typo (#823)
(cherry picked from commit ba294586bd)
2026-10-15 15:46:54 -05:00