Use MAX associated const (#9196)

* Use MAX associated const
This commit is contained in:
Squirrel
2021-06-24 11:53:49 +01:00
committed by GitHub
parent 09d9c2c9f6
commit ea1f21a904
56 changed files with 178 additions and 178 deletions
@@ -159,7 +159,7 @@ where TSubstream: AsyncRead + AsyncWrite + Unpin + Send + 'static,
}
let mut codec = UviBytes::default();
codec.set_max_len(usize::try_from(self.max_notification_size).unwrap_or(usize::max_value()));
codec.set_max_len(usize::try_from(self.max_notification_size).unwrap_or(usize::MAX));
let substream = NotificationsInSubstream {
socket: Framed::new(socket, codec),
@@ -390,7 +390,7 @@ where TSubstream: AsyncRead + AsyncWrite + Unpin + Send + 'static,
}
let mut codec = UviBytes::default();
codec.set_max_len(usize::try_from(self.max_notification_size).unwrap_or(usize::max_value()));
codec.set_max_len(usize::try_from(self.max_notification_size).unwrap_or(usize::MAX));
Ok(NotificationsOutOpen {
handshake,
@@ -809,7 +809,7 @@ impl RequestResponseCodec for GenericCodec {
// Read the length.
let length = unsigned_varint::aio::read_usize(&mut io).await
.map_err(|err| io::Error::new(io::ErrorKind::InvalidInput, err))?;
if length > usize::try_from(self.max_request_size).unwrap_or(usize::max_value()) {
if length > usize::try_from(self.max_request_size).unwrap_or(usize::MAX) {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
format!("Request size exceeds limit: {} > {}", length, self.max_request_size)
@@ -846,7 +846,7 @@ impl RequestResponseCodec for GenericCodec {
Err(err) => return Err(io::Error::new(io::ErrorKind::InvalidInput, err)),
};
if length > usize::try_from(self.max_response_size).unwrap_or(usize::max_value()) {
if length > usize::try_from(self.max_response_size).unwrap_or(usize::MAX) {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
format!("Response size exceeds limit: {} > {}", length, self.max_response_size)
+4 -4
View File
@@ -300,20 +300,20 @@ impl<B: BlockT + 'static, H: ExHashT> NetworkWorker<B, H> {
let yamux_maximum_buffer_size = {
let requests_max = params.network_config
.request_response_protocols.iter()
.map(|cfg| usize::try_from(cfg.max_request_size).unwrap_or(usize::max_value()));
.map(|cfg| usize::try_from(cfg.max_request_size).unwrap_or(usize::MAX));
let responses_max = params.network_config
.request_response_protocols.iter()
.map(|cfg| usize::try_from(cfg.max_response_size).unwrap_or(usize::max_value()));
.map(|cfg| usize::try_from(cfg.max_response_size).unwrap_or(usize::MAX));
let notifs_max = params.network_config
.extra_sets.iter()
.map(|cfg| usize::try_from(cfg.max_notification_size).unwrap_or(usize::max_value()));
.map(|cfg| usize::try_from(cfg.max_notification_size).unwrap_or(usize::MAX));
// A "default" max is added to cover all the other protocols: ping, identify,
// kademlia, block announces, and transactions.
let default_max = cmp::max(
1024 * 1024,
usize::try_from(protocol::BLOCK_ANNOUNCES_TRANSACTIONS_SUBSTREAM_SIZE)
.unwrap_or(usize::max_value())
.unwrap_or(usize::MAX)
);
iter::once(default_max)
@@ -254,7 +254,7 @@ impl Metrics {
.inc_by(num);
self.notifications_sizes
.with_label_values(&[protocol, "sent", name])
.inc_by(num.saturating_mul(u64::try_from(message.len()).unwrap_or(u64::max_value())));
.inc_by(num.saturating_mul(u64::try_from(message.len()).unwrap_or(u64::MAX)));
}
},
}
@@ -294,7 +294,7 @@ impl Metrics {
.inc();
self.notifications_sizes
.with_label_values(&[&protocol, "received", name])
.inc_by(u64::try_from(message.len()).unwrap_or(u64::max_value()));
.inc_by(u64::try_from(message.len()).unwrap_or(u64::MAX));
}
},
}
@@ -345,7 +345,7 @@ fn lots_of_incoming_peers_works() {
fallback_names: Vec::new(),
max_notification_size: 1024 * 1024,
set_config: config::SetConfig {
in_peers: u32::max_value(),
in_peers: u32::MAX,
.. Default::default()
},
}