Skip to content

Add Gossipsub direct peer support - #211

Open
flcl42 wants to merge 5 commits into
gossipsub-v13-partial-messagesfrom
gossipsub-direct-peers
Open

Add Gossipsub direct peer support#211
flcl42 wants to merge 5 commits into
gossipsub-v13-partial-messagesfrom
gossipsub-direct-peers

Conversation

@flcl42

@flcl42 flcl42 commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add reciprocal direct-peer configuration and periodic reconnection
  • forward valid subscribed-topic messages directly while excluding direct peers from mesh, fanout, and gossip selection
  • reject direct-peer GRAFTs with PRUNE and cover delivery, mesh isolation, startup dialing, and configuration validation

Validation

  • Pubsub protocol unit tests

@flcl42
flcl42 requested a review from rubo as a code owner August 24, 2026 09:08
@flcl42
flcl42 requested a lite review from Copilot August 24, 2026 09:08

Copilot AI 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.

Pull request overview

Adds Gossipsub “direct peer” support to the pubsub router, enabling explicit peering (reciprocal direct connections) with special routing rules (direct forwarding + isolation from mesh/fanout/gossip).

Changes:

  • Introduces direct-peer configuration (addresses + reconnect period) and validates configuration at router startup.
  • Updates publish/forwarding logic to send subscribed-topic messages directly to configured direct peers while excluding them from mesh/fanout/gossip selection and graylisting behavior.
  • Rejects direct-peer GRAFTs with PRUNE and adds unit tests covering delivery, mesh isolation, startup dialing, and configuration validation.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/libp2p/Libp2p.Protocols.Pubsub/PubSubSettings.cs Adds DirectPeers + DirectConnectPeriod settings for explicit peering and reconnect cadence.
src/libp2p/Libp2p.Protocols.Pubsub/PubsubRouter.Topics.cs Publishes directly to subscribed direct peers and excludes direct peers from fanout selection/publish paths.
src/libp2p/Libp2p.Protocols.Pubsub/PubsubRouter.Rpc.cs Forwards valid messages to direct peers, skips graylist for direct peers, and rejects direct-peer GRAFT with PRUNE.
src/libp2p/Libp2p.Protocols.Pubsub/PubsubRouter.cs Builds direct-peer map, discovers configured direct peers at startup, and periodically reconnects disconnected direct peers.
src/libp2p/Libp2p.Protocols.Pubsub.Tests/DirectPeersTests.cs Adds tests for direct peer forwarding, mesh isolation, GRAFT rejection, startup dialing, and config validation.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/libp2p/Libp2p.Protocols.Pubsub/PubsubRouter.cs Outdated
Comment thread src/libp2p/Libp2p.Protocols.Pubsub/PubsubRouter.Rpc.cs Outdated
@flcl42
flcl42 force-pushed the gossipsub-direct-peers branch from 859154c to 105400f Compare August 24, 2026 09:21
@flcl42
flcl42 changed the base branch from main to sipsorcery-security-update August 24, 2026 09:21
@flcl42
flcl42 requested a lite review from Copilot August 24, 2026 09:29

Copilot AI 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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Suppressed comments (1)

src/libp2p/Libp2p.Protocols.Pubsub/PubsubRouter.cs:177

  • The ArgumentOutOfRangeException for DirectConnectPeriod uses nameof(settings) as the parameter name, which makes the exception less actionable for callers (it points at the whole settings object rather than the specific property).
        if (_settings.DirectConnectPeriod <= 0)
        {
            throw new ArgumentOutOfRangeException(nameof(settings), "DirectConnectPeriod must be positive.");
        }

Comment thread src/libp2p/Libp2p.Protocols.Pubsub/PubsubRouter.Topics.cs Outdated

Copilot AI 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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

Suppressed comments (2)

Previously missed (2) — in code that hasn't changed since the last review.

src/libp2p/Libp2p.Protocols.Pubsub/PubSubSettings.cs:34

  • The XML doc for DirectConnectPeriod doesn't state the units. Since the value is an int and used with AddMilliseconds(), it should explicitly document that this is milliseconds to avoid misconfiguration.
    /// <summary>
    /// Interval for reconnecting disconnected direct peers. Gossipsub recommends
    /// five minutes.
    /// </summary>
    public int DirectConnectPeriod { get; set; } = 5 * 60 * 1000;

src/libp2p/Libp2p.Protocols.Pubsub/PubsubRouter.cs:212

  • Direct peer reconnect timing is currently driven by the LoopReconnect cadence (ReconnectionPeriod), which means DirectConnectPeriod won't be respected if ReconnectionPeriod is larger. Since ReconnectDirectPeers() already self-throttles via nextDirectConnectionAttempt, consider calling it from the heartbeat loop as well so the configured DirectConnectPeriod is honored independently.
        nextDirectConnectionAttempt = DateTime.UtcNow.AddMilliseconds(_settings.DirectConnectPeriod);

        _ = Task.Run(LoopHeartbeat, token);
        _ = Task.Run(LoopReconnect, token);

@flcl42
flcl42 force-pushed the gossipsub-direct-peers branch from 6f1c889 to ead5428 Compare August 24, 2026 10:34
@flcl42
flcl42 changed the base branch from sipsorcery-security-update to gossipsub-v13-partial-messages August 24, 2026 10:34
@flcl42
flcl42 requested a lite review from Copilot August 24, 2026 10:35

Copilot AI 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.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comment thread src/libp2p/Libp2p.Protocols.Pubsub/PubsubRouter.cs
@flcl42
flcl42 force-pushed the gossipsub-direct-peers branch from ead5428 to 72d6b84 Compare August 24, 2026 10:44
@flcl42
flcl42 force-pushed the gossipsub-direct-peers branch from cbbc9d0 to 4ccdad0 Compare August 24, 2026 11:13
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