Skip to content

feat: add rust-p2p skill#356

Merged
iamquang95 merged 1 commit into
mainfrom
iamquang95/add-rustp2p-skill
Apr 29, 2026
Merged

feat: add rust-p2p skill#356
iamquang95 merged 1 commit into
mainfrom
iamquang95/add-rustp2p-skill

Conversation

@iamquang95
Copy link
Copy Markdown
Collaborator

This add skill to help agents implement and review rust libp2p related package

Copy link
Copy Markdown
Collaborator

@varex83 varex83 left a comment

Choose a reason for hiding this comment

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

LGTM!

Comment on lines +100 to +102
**Critical failure mode:** if `conn_logger` writes context A while an inner
behaviour reads context B, the inner behaviour will treat connected peers as
disconnected.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This paragraph is not very clear (why conn_logger? Write what specifically? Is this a matter of ordering?)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The conn_logger is a core behaviour in PlutoBehaviour. The peer_store in p2p_context is updated by conn_logger, and other behaviours use that peer_store.

/// Pluto network behaviour.
///
/// Combines multiple libp2p protocols:
/// - **Connection logging**: Tracks connections and updates peer store (first
///   to ensure other behaviours see updated peer state)
/// - **Connection gating**: Controls which connections are allowed
/// - **Identify**: Exchanges peer information and supported protocols
/// - **Ping**: Measures latency and keeps connections alive
/// - **AutoNAT**: Detects NAT status and public reachability
/// - **QUIC upgrade**: Periodically upgrades TCP connections to QUIC
#[derive(NetworkBehaviour)]
pub struct PlutoBehaviour<B: NetworkBehaviour> {
    /// Connection logger behaviour - MUST be first so peer store is updated
    /// before other behaviours process connection events.
    pub conn_logger: ConnectionLoggerBehaviour<DefaultConnectionLoggerMetrics>,
    /// Connection gater behaviour.
    pub gater: ConnGater,
    /// Identify behaviour.
    pub identify: identify::Behaviour,
    /// Ping behaviour.
    pub ping: ping::Behaviour,
    /// AutoNAT behaviour for NAT detection.
    pub autonat: autonat::Behaviour,
    /// QUIC upgrade behaviour for upgrading TCP to QUIC connections.
    pub quic_upgrade: QuicUpgradeBehaviour,
    /// Inner behaviour.
    pub inner: OptionalBehaviour<B>,
}

Ordering matters because #[derive(NetworkBehaviour)] delegates each trait method to fields in struct order. For poll(), it polls first field until Pending, then next field. That's why the conn_logger has to be placed on the top in PlutoBehaviour.

- poll retry/routing timers,
- translate handler events into feature events.

`poll` rules:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Does libp2p have any skills on the topic? Maybe we could incorporate them if so.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I couldn't find any skill related to rust-libp2p. Later if we can find some, we can improve our skill.

@iamquang95 iamquang95 merged commit 47ed0f3 into main Apr 29, 2026
12 checks passed
@iamquang95 iamquang95 deleted the iamquang95/add-rustp2p-skill branch April 29, 2026 03:48
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.

3 participants