refactor: centralize BYTES_PER_MB and tidy peer IP parsing

- Add pub const BYTES_PER_MB to ui/utils.rs and replace 7 uses of the
  bare 1_048_576.0 literal across the UI modules. Also pick up
  uninlined-format-args cleanup in the same file while we're here.
- Replace Vec<i32> IP-byte accumulator in Peer::new_from_message with a
  [u8; 4]; the .abs() calls on u8.into() were no-ops on always-positive
  values. Network byte order ([3].[2].[1].[0]) preserved; tests cover
  the wire format.
This commit is contained in:
michel
2026-04-26 17:20:45 +02:00
parent e0218b2433
commit 9d6a33da34
5 changed files with 32 additions and 36 deletions
+7 -11
View File
@@ -119,17 +119,13 @@ impl Peer {
let username = message.read_string();
let connection_type = message.read_string().parse().unwrap();
let mut ip: Vec<i32> = vec![];
for _ in 0..4 {
ip.push(message.read_int8().into());
}
let host: String = format!(
"{}.{}.{}.{}",
ip[3].abs(),
ip[2].abs(),
ip[1].abs(),
ip[0].abs()
);
let ip = [
message.read_int8(),
message.read_int8(),
message.read_int8(),
message.read_int8(),
];
let host = format!("{}.{}.{}.{}", ip[3], ip[2], ip[1], ip[0]);
let (port, token, privileged, unknown, obfuscated_port) = (
message.read_int32(),