mirror of
https://github.com/threefoldtech/mycelium.git
synced 2026-03-29 07:39:51 +00:00
Use .div_ceil instead of reimplementing manually
Signed-off-by: Lee Smet <lee.smet@hotmail.com>
This commit is contained in:
@@ -48,7 +48,7 @@ impl RouteRequest {
|
||||
pub fn wire_size(&self) -> u8 {
|
||||
ROUTE_REQUEST_BASE_WIRE_SIZE
|
||||
+ (if let Some(prefix) = self.prefix {
|
||||
(prefix.prefix_len() + 7) / 8
|
||||
prefix.prefix_len().div_ceil(8)
|
||||
} else {
|
||||
0
|
||||
})
|
||||
@@ -65,7 +65,7 @@ impl RouteRequest {
|
||||
let ae = src.get_u8();
|
||||
let plen = src.get_u8();
|
||||
|
||||
let prefix_size = ((plen + 7) / 8) as usize;
|
||||
let prefix_size = plen.div_ceil(8) as usize;
|
||||
|
||||
let prefix_ip = match ae {
|
||||
AE_WILDCARD => None,
|
||||
@@ -122,7 +122,7 @@ impl RouteRequest {
|
||||
IpAddr::V6(_) => AE_IPV6,
|
||||
});
|
||||
dst.put_u8(prefix.prefix_len());
|
||||
let prefix_len = ((prefix.prefix_len() + 7) / 8) as usize;
|
||||
let prefix_len = prefix.prefix_len().div_ceil(8) as usize;
|
||||
match prefix.address() {
|
||||
IpAddr::V4(ip) => dst.put_slice(&ip.octets()[..prefix_len]),
|
||||
IpAddr::V6(ip) => dst.put_slice(&ip.octets()[..prefix_len]),
|
||||
|
||||
@@ -12,7 +12,7 @@ use super::{AE_IPV4, AE_IPV6, AE_IPV6_LL, AE_WILDCARD};
|
||||
|
||||
/// The default HOP COUNT value used in new SeqNo requests, as per https://datatracker.ietf.org/doc/html/rfc8966#section-3.8.2.1
|
||||
// SAFETY: value is not zero.
|
||||
const DEFAULT_HOP_COUNT: NonZeroU8 = unsafe { NonZeroU8::new_unchecked(64) };
|
||||
const DEFAULT_HOP_COUNT: NonZeroU8 = NonZeroU8::new(64).unwrap();
|
||||
|
||||
/// Base wire size of a [`SeqNoRequest`] without variable length address encoding.
|
||||
const SEQNO_REQUEST_BASE_WIRE_SIZE: u8 = 6 + RouterId::BYTE_SIZE as u8;
|
||||
@@ -101,7 +101,7 @@ impl SeqNoRequest {
|
||||
|
||||
let router_id = RouterId::from(router_id_bytes);
|
||||
|
||||
let prefix_size = ((plen + 7) / 8) as usize;
|
||||
let prefix_size = plen.div_ceil(8) as usize;
|
||||
|
||||
let prefix = match ae {
|
||||
AE_WILDCARD => {
|
||||
@@ -180,7 +180,7 @@ impl SeqNoRequest {
|
||||
// Write "reserved" value.
|
||||
dst.put_u8(0);
|
||||
dst.put_slice(&self.router_id.as_bytes()[..]);
|
||||
let prefix_len = ((self.prefix.prefix_len() + 7) / 8) as usize;
|
||||
let prefix_len = self.prefix.prefix_len().div_ceil(8) as usize;
|
||||
match self.prefix.address() {
|
||||
IpAddr::V4(ip) => dst.put_slice(&ip.octets()[..prefix_len]),
|
||||
IpAddr::V6(ip) => dst.put_slice(&ip.octets()[..prefix_len]),
|
||||
|
||||
@@ -86,7 +86,7 @@ impl Update {
|
||||
|
||||
/// Calculates the size on the wire of this `Update`.
|
||||
pub fn wire_size(&self) -> u8 {
|
||||
let address_bytes = (self.subnet.prefix_len() + 7) / 8;
|
||||
let address_bytes = self.subnet.prefix_len().div_ceil(8);
|
||||
UPDATE_BASE_WIRE_SIZE + address_bytes
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ impl Update {
|
||||
let interval = src.get_u16();
|
||||
let seqno = src.get_u16().into();
|
||||
let metric = src.get_u16().into();
|
||||
let prefix_size = ((plen + 7) / 8) as usize;
|
||||
let prefix_size = plen.div_ceil(8) as usize;
|
||||
let prefix = match ae {
|
||||
AE_WILDCARD => {
|
||||
if prefix_size != 0 {
|
||||
@@ -190,7 +190,7 @@ impl Update {
|
||||
dst.put_u16(self.interval);
|
||||
dst.put_u16(self.seqno.into());
|
||||
dst.put_u16(self.metric.into());
|
||||
let prefix_len = ((self.subnet.prefix_len() + 7) / 8) as usize;
|
||||
let prefix_len = self.subnet.prefix_len().div_ceil(8) as usize;
|
||||
match self.subnet.address() {
|
||||
IpAddr::V4(ip) => dst.put_slice(&ip.octets()[..prefix_len]),
|
||||
IpAddr::V6(ip) => dst.put_slice(&ip.octets()[..prefix_len]),
|
||||
|
||||
Reference in New Issue
Block a user