Skip to content

p2p: Identify protocol rejects unknown protocol strings #2189

@iostat

Description

@iostat

File: network/identify/p2p_network_identify_protocol.rs:168-181

parse_protocol() returns Err(UnsupportedProtocol) for any protocol string not in Token::ALL. The TryFrom<pb::Identify> impl propagates this with ?, rejecting the entire Identify` message.

pub fn parse_protocol(name: &str) -> Result<StreamKind, ...> {
    for tok in token::Token::ALL.iter() {
        if let token::Token::Protocol(token::Protocol::Stream(a)) = tok {
            if a.name_str() == name {
                return Ok(*a);
            }
        }
    }
    Err(P2pNetworkIdentifyFromMessageError::UnsupportedProtocol(
        name.to_string(),
    ))
}

Impact:

  • Adding new capability strings (e.g., /mina/webrtc-relay/1.0.0) would cause
    older Rust nodes to reject the sender's Identify message entirely
  • If either the Rust or OCaml nodes ever add a new protocol string, Rust nodes break
  • This is inconsistent with the multistream-select parser (token.rs:parse_token) which gracefully returns Token::UnknownProtocol for unknowns
  • go-libp2p handles this correctly: unknown protocol strings are stored and simply never matched

This is a prerequisite for any capability advertisement work (#2034).

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

Status

In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions