Skip to content

Commit 5ca27a9

Browse files
committed
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.
1 parent 9ee7b33 commit 5ca27a9

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/network/address.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,9 @@ impl Encodable for AddrV2Message {
259259
len += VarInt(self.services.to_u64()).consensus_encode(w)?;
260260
len += self.addr.consensus_encode(w)?;
261261

262-
// consensus_encode always encodes in LE, and we want to encode in BE.
263-
//TODO `len += io::Write::write(w, &self.port.to_be_bytes())?;` when MSRV >= 1.32
264-
len += self.port.swap_bytes().consensus_encode(w)?;
262+
w.write_all(&self.port.to_be_bytes())?;
263+
len += 2; // port u16 is two bytes.
264+
265265
Ok(len)
266266
}
267267
}

0 commit comments

Comments
 (0)