From aa207e2c138b1bf44d47cc77b2b4c15cad3a8fb4 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Mon, 16 Dec 2019 16:25:49 +0000 Subject: [PATCH] mix_peer: using constant sized byte array for addressing --- src/mix_peer.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/mix_peer.rs b/src/mix_peer.rs index 8aab5dda73..053961718d 100644 --- a/src/mix_peer.rs +++ b/src/mix_peer.rs @@ -9,11 +9,12 @@ pub struct MixPeer { impl MixPeer { // note that very soon `next_hop_address` will be changed to `next_hop_metadata` pub fn new(next_hop_address: [u8; 32]) -> MixPeer { - let address = String::from_utf8_lossy(&next_hop_address) - .trim_end_matches(char::from(0)) - .to_string(); + let b = next_hop_address; + let host = Ipv4Addr::new(b[0], b[1], b[2], b[3]); + let port: u16 = u16::from_be_bytes([b[4], b[5]]); + let socket_address = SocketAddrV4::new(host, port); MixPeer { - connection: address, + connection: socket_address, } }