Skip to content

Commit

Permalink
fix(relay): Add resource limits to CircuitReq to be set
Browse files Browse the repository at this point in the history
Fixes #5466
Adds resource limits to `CircuitReq` to be set .

Pull-Request: #5493.
  • Loading branch information
Prabhat1308 authored Jul 19, 2024
1 parent 1617abb commit a749a41
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions protocols/relay/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## 0.17.3
- Use `web-time` instead of `instant`.
See [PR 5347](https://github.com/libp2p/rust-libp2p/pull/5347).
- Add resource limits to `CircuitReq` to be set
See [PR 5493](https://github.com/libp2p/rust-libp2p/pull/5493)

## 0.17.2

Expand Down
19 changes: 17 additions & 2 deletions protocols/relay/src/protocol/inbound_hop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ impl ReservationReq {
pub struct CircuitReq {
dst: PeerId,
substream: Framed<Stream, quick_protobuf_codec::Codec<proto::HopMessage>>,
max_circuit_duration: Duration,
max_circuit_bytes: u64,
}

impl CircuitReq {
Expand All @@ -127,7 +129,15 @@ impl CircuitReq {
type_pb: proto::HopMessageType::STATUS,
peer: None,
reservation: None,
limit: None,
limit: Some(proto::Limit {
duration: Some(
self.max_circuit_duration
.as_secs()
.try_into()
.expect("`max_circuit_duration` not to exceed `u32::MAX`."),
),
data: Some(self.max_circuit_bytes),
}),
status: Some(proto::Status::OK),
};

Expand Down Expand Up @@ -204,7 +214,12 @@ pub(crate) async fn handle_inbound_request(

let dst = peer_id_res.map_err(|_| Error::ParsePeerId)?;

Either::Right(CircuitReq { dst, substream })
Either::Right(CircuitReq {
dst,
substream,
max_circuit_duration,
max_circuit_bytes,
})
}
Type::STATUS => return Err(Error::UnexpectedTypeStatus),
};
Expand Down

0 comments on commit a749a41

Please sign in to comment.