Fix tried to send handshake twice (#5413)

* Fix tried to send handshake twice

* Fix wrong boolean

* Change to debug
This commit is contained in:
Pierre Krieger
2020-03-30 13:33:46 +02:00
committed by GitHub
parent e17a23e907
commit dbba4f8929
3 changed files with 34 additions and 18 deletions
@@ -164,12 +164,9 @@ where TSubstream: AsyncRead + AsyncWrite,
{
/// Sends the handshake in order to inform the remote that we accept the substream.
pub fn send_handshake(&mut self, message: impl Into<Vec<u8>>) {
match self.handshake {
NotificationsInSubstreamHandshake::NotSent => {}
_ => {
error!(target: "sub-libp2p", "Tried to send handshake twice");
return;
}
if !matches!(self.handshake, NotificationsInSubstreamHandshake::NotSent) {
error!(target: "sub-libp2p", "Tried to send handshake twice");
return;
}
self.handshake = NotificationsInSubstreamHandshake::PendingSend(message.into());
@@ -189,8 +186,10 @@ where TSubstream: AsyncRead + AsyncWrite + Unpin,
match mem::replace(this.handshake, NotificationsInSubstreamHandshake::Sent) {
NotificationsInSubstreamHandshake::Sent =>
return Stream::poll_next(this.socket.as_mut(), cx),
NotificationsInSubstreamHandshake::NotSent =>
return Poll::Pending,
NotificationsInSubstreamHandshake::NotSent => {
*this.handshake = NotificationsInSubstreamHandshake::NotSent;
return Poll::Pending
},
NotificationsInSubstreamHandshake::PendingSend(msg) =>
match Sink::poll_ready(this.socket.as_mut(), cx) {
Poll::Ready(_) => {