refactor(client): propagate ProtoError from recv_buffer_size calculation
This commit is contained in:
1 file changed
+10
-6
@@ -328,8 +328,9 @@ impl Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
fn recv_buffer_size(&self) -> usize {
|
pub(crate) fn recv_buffer_size(&self) -> usize {
|
||||||
recv_buffer_size(self.config.hmac_key.is_some(), self.negotiated.as_ref())
|
recv_buffer_size(self.config.hmac_key.is_some(), self.negotiated.as_ref())
|
||||||
|
.expect("test params must have a non-negative packet length")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Polls for probes that have timed out as of the current monotonic time.
|
/// Polls for probes that have timed out as of the current monotonic time.
|
||||||
@@ -612,7 +613,7 @@ impl Client {
|
|||||||
let negotiated = NegotiatedParams {
|
let negotiated = NegotiatedParams {
|
||||||
params: reply.params.clone(),
|
params: reply.params.clone(),
|
||||||
};
|
};
|
||||||
let recv_buffer_size = recv_buffer_size(self.config.hmac_key.is_some(), Some(&negotiated));
|
let recv_buffer_size = recv_buffer_size(self.config.hmac_key.is_some(), Some(&negotiated))?;
|
||||||
let negotiated_dscp =
|
let negotiated_dscp =
|
||||||
u8::try_from(negotiated.params.dscp).map_err(|_| ClientError::InvalidConfig {
|
u8::try_from(negotiated.params.dscp).map_err(|_| ClientError::InvalidConfig {
|
||||||
reason: "negotiated dscp must be in range 0..=63".to_owned(),
|
reason: "negotiated dscp must be in range 0..=63".to_owned(),
|
||||||
@@ -735,13 +736,16 @@ fn instant_abs_diff(left: Instant, right: Instant) -> Duration {
|
|||||||
.unwrap_or(Duration::ZERO)
|
.unwrap_or(Duration::ZERO)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn recv_buffer_size(has_hmac: bool, negotiated: Option<&NegotiatedParams>) -> usize {
|
pub(crate) fn recv_buffer_size(
|
||||||
match negotiated {
|
has_hmac: bool,
|
||||||
Some(negotiated) => echo_packet_len(has_hmac, &negotiated.params)
|
negotiated: Option<&NegotiatedParams>,
|
||||||
|
) -> Result<usize, ClientError> {
|
||||||
|
Ok(match negotiated {
|
||||||
|
Some(negotiated) => echo_packet_len(has_hmac, &negotiated.params)?
|
||||||
.saturating_add(1)
|
.saturating_add(1)
|
||||||
.max(MIN_RECV_BUFFER_SIZE),
|
.max(MIN_RECV_BUFFER_SIZE),
|
||||||
None => MIN_RECV_BUFFER_SIZE,
|
None => MIN_RECV_BUFFER_SIZE,
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compute_rtt(
|
fn compute_rtt(
|
||||||
|
|||||||
Reference in new issue
Block a user