Skip to content

Commit e8d93ef

Browse files
authored
crypto/noise: Fix connection negotiation logic on partial writes (#519)
This PR replaces the `io.write` with `io.write_all` calls to ensure the negotiation messages are fully propagated. - There was a bug in the `fn handshake` implementation, which might propagate only a part of the provided negotiation message (ie on partial writes the `write` call would return immediately) - This would then be rejected by the other side, causing unnecessary negotiation errors while opening the connection - The downstream effect of this is that higher level protocols (like notification protocols) would backoff the peer for ~5s. Signed-off-by: Alexandru Vasile <[email protected]>
1 parent 9dc8b34 commit e8d93ef

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/crypto/noise/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ pub async fn handshake<S: AsyncRead + AsyncWrite + Unpin>(
797797
Role::Dialer => {
798798
// write initial message
799799
let first_message = noise.first_message(Role::Dialer)?;
800-
let _ = io.write(&first_message).await?;
800+
io.write_all(&first_message).await?;
801801
io.flush().await?;
802802

803803
// read back response which contains the remote peer id
@@ -812,7 +812,7 @@ pub async fn handshake<S: AsyncRead + AsyncWrite + Unpin>(
812812

813813
// send the final message which contains local peer id
814814
let second_message = noise.second_message()?;
815-
let _ = io.write(&second_message).await?;
815+
io.write_all(&second_message).await?;
816816
io.flush().await?;
817817

818818
payload
@@ -823,7 +823,7 @@ pub async fn handshake<S: AsyncRead + AsyncWrite + Unpin>(
823823

824824
// send local peer id.
825825
let second_message = noise.second_message()?;
826-
let _ = io.write(&second_message).await?;
826+
io.write_all(&second_message).await?;
827827
io.flush().await?;
828828

829829
// read remote's second message which contains their peer id

0 commit comments

Comments
 (0)