Skip to content

Commit a749a41

Browse files
authored
fix(relay): Add resource limits to CircuitReq to be set
Fixes #5466 Adds resource limits to `CircuitReq` to be set . Pull-Request: #5493.
1 parent 1617abb commit a749a41

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

protocols/relay/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
## 0.17.3
22
- Use `web-time` instead of `instant`.
33
See [PR 5347](https://github.com/libp2p/rust-libp2p/pull/5347).
4+
- Add resource limits to `CircuitReq` to be set
5+
See [PR 5493](https://github.com/libp2p/rust-libp2p/pull/5493)
46

57
## 0.17.2
68

protocols/relay/src/protocol/inbound_hop.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ impl ReservationReq {
115115
pub struct CircuitReq {
116116
dst: PeerId,
117117
substream: Framed<Stream, quick_protobuf_codec::Codec<proto::HopMessage>>,
118+
max_circuit_duration: Duration,
119+
max_circuit_bytes: u64,
118120
}
119121

120122
impl CircuitReq {
@@ -127,7 +129,15 @@ impl CircuitReq {
127129
type_pb: proto::HopMessageType::STATUS,
128130
peer: None,
129131
reservation: None,
130-
limit: None,
132+
limit: Some(proto::Limit {
133+
duration: Some(
134+
self.max_circuit_duration
135+
.as_secs()
136+
.try_into()
137+
.expect("`max_circuit_duration` not to exceed `u32::MAX`."),
138+
),
139+
data: Some(self.max_circuit_bytes),
140+
}),
131141
status: Some(proto::Status::OK),
132142
};
133143

@@ -204,7 +214,12 @@ pub(crate) async fn handle_inbound_request(
204214

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

207-
Either::Right(CircuitReq { dst, substream })
217+
Either::Right(CircuitReq {
218+
dst,
219+
substream,
220+
max_circuit_duration,
221+
max_circuit_bytes,
222+
})
208223
}
209224
Type::STATUS => return Err(Error::UnexpectedTypeStatus),
210225
};

0 commit comments

Comments
 (0)