Skip to content

Experimental P2P fix for Linux#1087

Merged
iverc merged 3 commits into
sourcenetwork:mainfrom
ChrisBQu:experimental-linux-p2p-fix
Jul 6, 2026
Merged

Experimental P2P fix for Linux#1087
iverc merged 3 commits into
sourcenetwork:mainfrom
ChrisBQu:experimental-linux-p2p-fix

Conversation

@ChrisBQu

@ChrisBQu ChrisBQu commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

This PR is to show something I have worked on, which seems to get the demo running on Linux.

@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@iverc, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 48 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9fefd431-ec10-422a-ab2a-bdffd31b97b7

📥 Commits

Reviewing files that changed from the base of the PR and between ce151e9 and 87a53e3.

📒 Files selected for processing (2)
  • crates/p2p-adapter/src/iroh.rs
  • crates/p2p/src/iroh/mod.rs
📝 Walkthrough

Walkthrough

The iroh peer ID helper now normalizes endpoint-style IDs, and the p2p adapter uses that normalization to detect existing connections before dialing. Existing peers now short-circuit connect and replicator setup, with regression tests covering the new behavior.

Changes

Peer ID canonicalization and adapter connection checks

Layer / File(s) Summary
Canonical peer IDs
crates/p2p/src/iroh/addr.rs, crates/p2p/src/iroh/mod.rs
Adds canonical peer ID normalization for endpoint-style IDs and keeps the module re-exports unchanged.
Connection checks before dialing
crates/p2p-adapter/Cargo.toml, crates/p2p-adapter/src/iroh.rs
Adds the helper imports and dev dependencies, then updates connect and replicator setup to skip dialing when the transport already reports the peer as connected.
Regression tests
crates/p2p-adapter/src/iroh.rs
Adds tests for already-connected reconnects, canonical ID matching, disconnected failure, and replicator registration without redial.

Estimated code review effort: 3 (Moderate) | ~25 minutes


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/p2p-adapter/src/iroh.rs`:
- Around line 276-281: The `connected_peers()` call in `IrohAdapter` is
swallowing transport failures by falling back to false, which makes real errors
look like “not connected.” Update the `already_connected` lookup to handle the
`Result` explicitly: propagate or map the error to `P2PError::transport` the
same way other `connected_peers()` call sites do, and only compute
`contains(&peer_id)` on the successful path. Use the `IrohAdapter` logic around
`connected_peers()` and the existing `P2PError::transport` patterns as the
reference points.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: aef9c443-ef64-4aba-b61f-06d0e6108dcb

📥 Commits

Reviewing files that changed from the base of the PR and between 08c14cb and 6f1a08b.

📒 Files selected for processing (1)
  • crates/p2p-adapter/src/iroh.rs
📜 Review details
⏰ Context from checks skipped due to timeout. (3)
  • GitHub Check: WASM Build Check
  • GitHub Check: Build & Test
  • GitHub Check: Lint
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.rs: Use self-documenting code with minimal comments - only comment non-obvious WHY, safety invariants, and public API docs with ///. Do not include what the code does, TODO/FIXME comments, commented-out code, or change history
Name files and modules using snake_case (e.g., lww.rs)
Name types using PascalCase (e.g., LwwDelta)
Name functions using snake_case (e.g., encode_priority())
Name constants using SCREAMING_SNAKE_CASE (e.g., MAX_PRIORITY)
Organize code into one concept per file, preferring small files over large files. Keep files under 200 lines; check consistency if 200-400 lines; consider splitting if over 400 lines
Do not include commented-out code in the codebase
Use issues instead of TODO or FIXME comments - do not include TODO/FIXME comments in code

Files:

  • crates/p2p-adapter/src/iroh.rs
🔇 Additional comments (2)
crates/p2p-adapter/src/iroh.rs (2)

282-287: 🩺 Stability & Availability

Early-return path skips topic re-subscription.

The full connect path calls resubscribe_tracked_document_topics() (Line 309) after connecting, but the idempotent early-return path does not. If the peer is technically still in connected_peers() but topic subscriptions had lapsed (e.g. after a partial network blip), this early return would leave them unrepaired. Worth confirming whether "already connected" truly implies "topics still subscribed" for this transport.


276-287: 🎯 Functional Correctness

No issue: keep the fast path

connected_peers() is the source of truth here, and peer_addresses only rewrites the display address for peers already reported as connected. A later disconnect is handled by the transport state, so this does not create a lasting false-positive.

			> Likely an incorrect or invalid review comment.

Comment thread crates/p2p-adapter/src/iroh.rs Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
crates/p2p-adapter/src/iroh.rs (1)

49-67: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Silently swallowed transport errors on the liveness check.

.unwrap_or(false) discards any error from connected_peers() without logging, unlike the other connected_peers() call sites in this file (e.g. Lines 288-292, 871-873) which propagate the error via P2PError::transport. The doc comment explains the fallback is intentional (preserve pre-existing dial-on-uncertainty behavior), but a transport failure here is still indistinguishable from "not connected" in the logs, which can hide a real underlying issue during debugging.

🩺 Suggested fix: log the error before degrading to `false`
     async fn is_transport_connected(&self, peer_id: &p2p::transport::PeerId) -> bool {
         let canonical_id = canonical_peer_id(peer_id);
         self.transport
             .connected_peers()
             .await
             .map(|peers| {
                 peers
                     .iter()
                     .any(|peer| canonical_peer_id(peer) == canonical_id)
             })
-            .unwrap_or(false)
+            .unwrap_or_else(|error| {
+                tracing::warn!(peer_id = %peer_id, error = %error, "failed to read connected peers; falling back to dial");
+                false
+            })
     }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/p2p-adapter/src/iroh.rs` around lines 49 - 67, The liveness check in
is_transport_connected currently hides transport failures by turning any
connected_peers() error into false. Update this path to log the error before
falling back to false, using the same transport logging style as the other
connected_peers() call sites in iroh.rs, so a real transport issue is visible
while preserving the existing dial-on-uncertainty behavior.
🧹 Nitpick comments (1)
crates/p2p-adapter/src/iroh.rs (1)

998-1191: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Test module addition pushes iroh.rs well past the file-size guideline.

The new #[cfg(test)] mod tests block is well-targeted (covers idempotent reconnect, canonical-ID matching, and a negative-control redial-failure case), but it adds ~190 lines to a file already exceeding the repository's file-size guideline. Consider moving tests into a separate test module/file to keep iroh.rs closer to the recommended size.

As per coding guidelines, "Organize code into one concept per file, preferring small files over large files. Keep files under 200 lines; check consistency if 200-400 lines; consider splitting if over 400 lines."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/p2p-adapter/src/iroh.rs` around lines 998 - 1191, The new #[cfg(test)]
mod tests block in iroh.rs pushes the file beyond the size guideline; move these
tests into a separate test module/file so iroh.rs stays focused on the transport
implementation. Keep the existing test coverage intact by relocating the helper
symbols and cases such as NoopBlockstore, test_endpoint_config, dialable_ticket,
base32_spelling, connect_peer_is_noop_when_already_connected,
connect_peer_still_dials_when_not_connected, and
add_replicator_skips_dial_when_already_connected.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@crates/p2p-adapter/src/iroh.rs`:
- Around line 49-67: The liveness check in is_transport_connected currently
hides transport failures by turning any connected_peers() error into false.
Update this path to log the error before falling back to false, using the same
transport logging style as the other connected_peers() call sites in iroh.rs, so
a real transport issue is visible while preserving the existing
dial-on-uncertainty behavior.

---

Nitpick comments:
In `@crates/p2p-adapter/src/iroh.rs`:
- Around line 998-1191: The new #[cfg(test)] mod tests block in iroh.rs pushes
the file beyond the size guideline; move these tests into a separate test
module/file so iroh.rs stays focused on the transport implementation. Keep the
existing test coverage intact by relocating the helper symbols and cases such as
NoopBlockstore, test_endpoint_config, dialable_ticket, base32_spelling,
connect_peer_is_noop_when_already_connected,
connect_peer_still_dials_when_not_connected, and
add_replicator_skips_dial_when_already_connected.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bfbc3584-5168-4861-b1f3-d4c73cfe37af

📥 Commits

Reviewing files that changed from the base of the PR and between 6f1a08b and ce151e9.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (4)
  • crates/p2p-adapter/Cargo.toml
  • crates/p2p-adapter/src/iroh.rs
  • crates/p2p/src/iroh/addr.rs
  • crates/p2p/src/iroh/mod.rs
✅ Files skipped from review due to trivial changes (1)
  • crates/p2p/src/iroh/mod.rs
📜 Review details
⏰ Context from checks skipped due to timeout. (2)
  • GitHub Check: Build & Test
  • GitHub Check: P2P Integration (Linux)
🧰 Additional context used
📓 Path-based instructions (2)
**/Cargo.toml

📄 CodeRabbit inference engine (CLAUDE.md)

Name crates using lowercase with hyphens (e.g., defra-core)

Files:

  • crates/p2p-adapter/Cargo.toml
**/*.rs

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.rs: Use self-documenting code with minimal comments - only comment non-obvious WHY, safety invariants, and public API docs with ///. Do not include what the code does, TODO/FIXME comments, commented-out code, or change history
Name files and modules using snake_case (e.g., lww.rs)
Name types using PascalCase (e.g., LwwDelta)
Name functions using snake_case (e.g., encode_priority())
Name constants using SCREAMING_SNAKE_CASE (e.g., MAX_PRIORITY)
Organize code into one concept per file, preferring small files over large files. Keep files under 200 lines; check consistency if 200-400 lines; consider splitting if over 400 lines
Do not include commented-out code in the codebase
Use issues instead of TODO or FIXME comments - do not include TODO/FIXME comments in code

Files:

  • crates/p2p/src/iroh/addr.rs
  • crates/p2p-adapter/src/iroh.rs
🔇 Additional comments (8)
crates/p2p/src/iroh/addr.rs (3)

6-6: LGTM!


73-88: LGTM!


223-251: LGTM!

crates/p2p-adapter/Cargo.toml (1)

43-45: LGTM!

crates/p2p-adapter/src/iroh.rs (4)

16-17: LGTM!


189-206: LGTM!


314-325: LGTM!


496-508: LGTM!

@iverc iverc force-pushed the experimental-linux-p2p-fix branch from 3d2d078 to 87a53e3 Compare July 6, 2026 10:30
@iverc iverc merged commit def0e7e into sourcenetwork:main Jul 6, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants