Skip to content

Commit

Permalink
Fix bug broken invariant active-requests and hole punch attempts
Browse files Browse the repository at this point in the history
  • Loading branch information
emhane committed Jan 17, 2024
1 parent 5c89f12 commit e3478c2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::{handler::Challenge, node_info::NonContactable};
use crate::{
handler::Challenge,
node_info::{NodeAddress, NonContactable},
};
use derive_more::From;
use rlp::DecoderError;
use std::fmt;
Expand Down Expand Up @@ -33,6 +36,8 @@ pub enum Discv5Error {
ServiceAlreadyStarted,
/// A session could not be established with the remote.
SessionNotEstablished,
/// A session to the given peer is already established.
SessionAlreadyEstablished(NodeAddress),
/// An RLP decoding error occurred.
RLPError(DecoderError),
/// Failed to encrypt a message.
Expand Down
9 changes: 8 additions & 1 deletion src/handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,11 @@ impl Handler {
.on_request_time_out::<P>(relay, local_enr, nonce, target)
.await
{
Err(NatError::Initiator(Discv5Error::SessionAlreadyEstablished(
node_address,
))) => {
debug!("Session to peer already established, aborting hole punch attempt. Peer: {node_address}");
}
Err(e) => {
warn!("Failed to start hole punching. Error: {:?}", e);
}
Expand Down Expand Up @@ -1591,7 +1596,9 @@ impl HolePunchNat for Handler {
) -> Result<(), NatError> {
// Another hole punch process with this target may have just completed.
if self.sessions.get(&target_node_address).is_some() {
return Ok(());
return Err(NatError::Initiator(Discv5Error::SessionAlreadyEstablished(
target_node_address,
)));
}
if let Some(session) = self.sessions.get_mut(&relay) {
let relay_init_notif =
Expand Down

0 comments on commit e3478c2

Please sign in to comment.