Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore non-verack and non-version messages in handshake #3522

Merged
merged 4 commits into from
Feb 16, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions zebra-network/src/peer/handshake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,13 +588,25 @@ where
debug!(?our_version, "sending initial version message");
peer_conn.send(our_version).await?;

let remote_msg = peer_conn
let mut remote_msg = peer_conn
.next()
.await
.ok_or(HandshakeError::ConnectionClosed)??;

// Check that we got a Version and destructure its fields into the local scope.
debug!(?remote_msg, "got message from remote peer");

// Wait for next message if the one we have is not Version
match remote_msg {
Message::Version { .. } => (),
_ => {
remote_msg = peer_conn
.next()
.await
.ok_or(HandshakeError::ConnectionClosed)??;
debug!(?remote_msg, "got message from remote peer");
}
}
teor2345 marked this conversation as resolved.
Show resolved Hide resolved

// If we got a Version message, destructure its fields into the local scope.
let (remote_nonce, remote_services, remote_version, remote_canonical_addr, user_agent) =
if let Message::Version {
version,
Expand Down Expand Up @@ -705,9 +717,9 @@ where
.await
.ok_or(HandshakeError::ConnectionClosed)??;
if let Message::Verack = remote_msg {
debug!("got verack from remote peer");
debug!("got verack message from remote peer");
} else {
Err(HandshakeError::UnexpectedMessage(Box::new(remote_msg)))?;
debug!("ignoring non-verack message from remote peer");
teor2345 marked this conversation as resolved.
Show resolved Hide resolved
}

Ok((remote_version, remote_services, remote_canonical_addr))
Expand Down