diff --git a/util/network-devp2p/src/handshake.rs b/util/network-devp2p/src/handshake.rs index e664f0402..aac43865c 100644 --- a/util/network-devp2p/src/handshake.rs +++ b/util/network-devp2p/src/handshake.rs @@ -69,8 +69,6 @@ pub struct Handshake { pub auth_cipher: Bytes, /// A copy of received encrypted ack packet pub ack_cipher: Bytes, - /// This Handshake is marked for deletion flag - pub expired: bool, } const V4_AUTH_PACKET_SIZE: usize = 307; @@ -95,15 +93,9 @@ impl Handshake { remote_version: PROTOCOL_VERSION, auth_cipher: Bytes::new(), ack_cipher: Bytes::new(), - expired: false, }) } - /// Check if this handshake is expired. - pub fn expired(&self) -> bool { - self.expired - } - /// Start a handshake pub fn start(&mut self, io: &IoContext, host: &HostInfo, originated: bool) -> Result<(), Error> where Message: Send + Clone+ Sync + 'static { self.originated = originated; @@ -125,28 +117,26 @@ impl Handshake { /// Readable IO handler. Drives the state change. pub fn readable(&mut self, io: &IoContext, host: &HostInfo) -> Result<(), Error> where Message: Send + Clone + Sync + 'static { - if !self.expired() { - while let Some(data) = self.connection.readable()? { - match self.state { - HandshakeState::New => {}, - HandshakeState::StartSession => {}, - HandshakeState::ReadingAuth => { - self.read_auth(io, host.secret(), &data)?; - }, - HandshakeState::ReadingAuthEip8 => { - self.read_auth_eip8(io, host.secret(), &data)?; - }, - HandshakeState::ReadingAck => { - self.read_ack(host.secret(), &data)?; - }, - HandshakeState::ReadingAckEip8 => { - self.read_ack_eip8(host.secret(), &data)?; - }, - } - if self.state == HandshakeState::StartSession { - io.clear_timer(self.connection.token).ok(); - break; - } + while let Some(data) = self.connection.readable()? { + match self.state { + HandshakeState::New => {}, + HandshakeState::StartSession => {}, + HandshakeState::ReadingAuth => { + self.read_auth(io, host.secret(), &data)?; + }, + HandshakeState::ReadingAuthEip8 => { + self.read_auth_eip8(io, host.secret(), &data)?; + }, + HandshakeState::ReadingAck => { + self.read_ack(host.secret(), &data)?; + }, + HandshakeState::ReadingAckEip8 => { + self.read_ack_eip8(host.secret(), &data)?; + }, + } + if self.state == HandshakeState::StartSession { + io.clear_timer(self.connection.token).ok(); + break; } } Ok(()) @@ -154,9 +144,7 @@ impl Handshake { /// Writable IO handler. pub fn writable(&mut self, io: &IoContext) -> Result<(), Error> where Message: Send + Clone + Sync + 'static { - if !self.expired() { - self.connection.writable(io)?; - } + self.connection.writable(io)?; Ok(()) } diff --git a/util/network-devp2p/src/session.rs b/util/network-devp2p/src/session.rs index 910e54a06..1b659bc8e 100644 --- a/util/network-devp2p/src/session.rs +++ b/util/network-devp2p/src/session.rs @@ -166,10 +166,7 @@ impl Session { /// Check if this session is expired. pub fn expired(&self) -> bool { - match self.state { - State::Handshake(ref h) => self.expired || h.expired(), - _ => self.expired, - } + self.expired } /// Check if this session is over and there is nothing to be sent.