Skip to content

Commit

Permalink
refactor: wait for semaphore permit only if accepting content
Browse files Browse the repository at this point in the history
  • Loading branch information
njgheorghita committed Feb 29, 2024
1 parent 661777a commit 3094fbb
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions portalnet/src/overlay_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1281,22 +1281,6 @@ where
)
})?;

// Attempt to get semaphore permit if fails we return an empty accept
let permit = match self
.utp_controller
.inbound_utp_transfer_semaphore
.clone()
.try_acquire_owned()
{
Ok(permit) => permit,
Err(_) => {
return Ok(Accept {
connection_id: 0,
content_keys: requested_keys,
});
}
};

let content_keys: Vec<TContentKey> = request
.content_keys
.into_iter()
Expand Down Expand Up @@ -1341,6 +1325,22 @@ where
});
}

// Attempt to get semaphore permit, if this fails we return an empty accept
let permit = match self
.utp_controller
.inbound_utp_transfer_semaphore
.clone()
.try_acquire_owned()
{
Ok(permit) => permit,
Err(_) => {
return Ok(Accept {
connection_id: 0,
content_keys: requested_keys,
});
}
};

// Generate a connection ID for the uTP connection if there is data we would like to
// accept.
let node_addr = self.discovery.cached_node_addr(source).ok_or_else(|| {
Expand Down Expand Up @@ -1417,7 +1417,7 @@ where
{
debug!(%err, cid.send, cid.recv, peer = ?cid.peer.client(), content_keys = ?content_keys_string, "unable to process uTP payload");
}
// explictically drop semaphore permit in thread so the permit is moved into the thread
// explicitly drop semaphore permit in thread so the permit is moved into the thread
drop(permit);
});

Expand Down

0 comments on commit 3094fbb

Please sign in to comment.