{"record":{"id":"2fe5e99b1bbdbaae","repo":"diem/diem","slug":"noise-server-client-peer-id-is-malformed-0","errorCode":null,"errorMessage":"noise server: client peer id is malformed: {0}","messagePattern":"noise server: client peer id is malformed: (.+?)","errorType":"error_code","errorClass":"NoiseHandshakeError","httpStatus":null,"severity":"error","filePath":"network/src/noise/error.rs","lineNumber":37,"sourceCode":"    #[error(\"noise client: error sending client handshake init message: {0}\")]\n    ClientWriteFailed(io::Error),\n\n    #[error(\n        \"noise client: error reading server handshake response message, server \\\n         probably rejected our handshake message: {0}\"\n    )]\n    ClientReadFailed(io::Error),\n\n    #[error(\"noise client: error flushing socket after writing: {0}\")]\n    ClientFlushFailed(io::Error),\n\n    #[error(\"noise client: error finalizing secure connection: {0}\")]\n    ClientFinalizeFailed(NoiseError),\n\n    #[error(\"noise server: error reading client handshake init message: {0}\")]\n    ServerReadFailed(io::Error),\n\n    #[error(\"noise server: client peer id is malformed: {0}\")]\n    InvalidClientPeerId(String),\n\n    #[error(\"noise server: detected self-dial: we're trying to connect to ourselves\")]\n    SelfDialDetected,\n\n    #[error(\n        \"noise server: client {0}: client is expecting us to have a different \\\n         public key: {1}\"\n    )]\n    ClientExpectingDifferentPubkey(ShortHexStr, String),\n\n    #[error(\"noise server: client {0}: error parsing handshake init message: {1}\")]\n    ServerParseClient(ShortHexStr, NoiseError),\n\n    #[error(\n        \"noise server: client {0}: known client peer id connecting to us with \\\n         unauthenticated public key: {1}\"\n    )]","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/diem/diem/blob/fc4714a8ea273b6efe8b13dbce72ea60aad9a16c/network/src/noise/error.rs#L19-L55","documentation":"NoiseHandshakeError::InvalidClientPeerId is raised by the Noise server when the peer identity carried in the client's handshake payload cannot be parsed as a valid PeerId. The init message arrived but its self-reported identity is malformed, so the server refuses to authenticate the client.","triggerScenarios":"A client sends a handshake init whose protobuf/payload contains a peer id that fails PeerId parsing/validation on the server (wrong format, wrong length, invalid encoding).","commonSituations":"Client built with mismatched diem-types/protocol versions producing an incompatible handshake payload; buggy custom client or test harness sending a fabricated peer id; corrupted handshake bytes in transit.","solutions":["Update the client to the same protocol/types version as the server so the handshake payload encoding matches.","Fix the client's peer id construction — ensure it is derived correctly (typically from the public key) and serialized per the expected format.","Inspect the wrapped String ({0}) for the parse error detail to pinpoint the format problem.","Rule out corruption by confirming both endpoints negotiate the same Noise protocol and framing."],"exampleFix":"// before\nlet payload = HandshakeMsg { peer_id: PeerId::from_bytes(&raw[..16])? }; // truncated\n// after\nlet payload = HandshakeMsg { peer_id: PeerId::from_public_key(&my_identity_key) };","handlingStrategy":"validation","validationCode":"fn build_handshake_payload(key: &Ed25519PublicKey) -> Result<Vec<u8>, ParseError> {\n    let peer_id = PeerId::from_public_key(key); // derive, never fabricate\n    let mut buf = Vec::new();\n    proto::encode(&HandshakeMsg { peer_id }, &mut buf)?;\n    Ok(buf)\n}","typeGuard":null,"tryCatchPattern":"match accept_handshake(stream).await {\n    Err(NoiseHandshakeError::InvalidClientPeerId(details)) => {\n        error!(\"client sent malformed peer id: {} — likely protocol version mismatch\", details);\n        // reject connection, metric++ for version-mismatch\n    }\n    ok => ok.map(|_| ())?,\n}","preventionTips":["Always derive PeerId from the client's identity key rather than hand-constructing it.","Keep client and server diem-types/protocol versions identical.","Round-trip test handshake payload encoding in CI.","Reject at the client side early if the peer id fails local validation before dialing."],"tags":["rust","noise-protocol","peer-id","validation"],"backgroundTag":"invalid-peer-id","analyzedSha":"fc4714a8ea273b6efe8b13dbce72ea60aad9a16c","analyzedAt":"2026-09-04T21:07:05.890Z","contentChangedAt":"2026-09-04T21:07:05.890Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}