diff --git a/protocols/relay/CHANGELOG.md b/protocols/relay/CHANGELOG.md index 125f51e4961..f49e57af0f7 100644 --- a/protocols/relay/CHANGELOG.md +++ b/protocols/relay/CHANGELOG.md @@ -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 diff --git a/protocols/relay/src/protocol/inbound_hop.rs b/protocols/relay/src/protocol/inbound_hop.rs index 57b5d9ad039..401c6258176 100644 --- a/protocols/relay/src/protocol/inbound_hop.rs +++ b/protocols/relay/src/protocol/inbound_hop.rs @@ -115,6 +115,8 @@ impl ReservationReq { pub struct CircuitReq { dst: PeerId, substream: Framed>, + max_circuit_duration: Duration, + max_circuit_bytes: u64, } impl CircuitReq { @@ -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), }; @@ -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), };