From 3c2869465bf1f39c3f6c4a7a9415b29737b03b1a Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Fri, 22 Jul 2022 13:35:54 +1000 Subject: [PATCH] Use to_be_bytes Now that MSRV is > 1.32 we can use `u16::to_be_bytes` to ensure network byte order when encoding the port number of a `AddrV2Message`. Remove the TODO and use `to_be_bytes` as suggested. --- src/network/address.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/network/address.rs b/src/network/address.rs index 3a7d6940..76234df7 100644 --- a/src/network/address.rs +++ b/src/network/address.rs @@ -259,9 +259,9 @@ impl Encodable for AddrV2Message { len += VarInt(self.services.to_u64()).consensus_encode(w)?; len += self.addr.consensus_encode(w)?; - // consensus_encode always encodes in LE, and we want to encode in BE. - //TODO `len += io::Write::write(w, &self.port.to_be_bytes())?;` when MSRV >= 1.32 - len += self.port.swap_bytes().consensus_encode(w)?; + w.write_all(&self.port.to_be_bytes())?; + len += 2; // port u16 is two bytes. + Ok(len) } }