What changed, and why it matters
This commit is a straightforward internal code cleanup in the peer-to-peer networking module. It replaces an unnamed pair of values (a timestamp number and a network address) with a clearly named wrapper type called AddrV1Message. There is no change to security behavior, no bug fix, and no externally visible protocol change.
No security action needed. Treat as a normal refactoring review; verify downstream consumers of AddrPayload are updated if any exist outside this crate.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors AddrPayload from Vec<(u32, Address)> to Vec
Changed components
p2p/src/address.rsp2p/src/message.rsInspect captured patch +31 / −9
diff --git a/p2p/src/address.rs b/p2p/src/address.rs
index 5047c886..a7502e82 100644
--- a/p2p/src/address.rs
+++ b/p2p/src/address.rs
@@ -246,6 +246,17 @@ impl std::error::Error for AddressDecoderError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { Some(&self.0) }
}
+/// Data type received in an `addr` message.
+#[derive(Clone, PartialEq, Eq, Hash, Debug)]
+pub struct AddrV1Message {
+ /// Time the peer was last seen.
+ pub time: u32,
+ /// Network address to research the peer.
+ pub address: Address,
+}
+
+crate::consensus::impl_consensus_encoding!(AddrV1Message, time, address);
+
/// Supported networks for use in BIP-0155 addrv2 message
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
pub enum AddrV2 {
@@ -916,6 +927,17 @@ impl<'a> Arbitrary<'a> for Address {
Ok(Self::new(&socket_addr, u.arbitrary()?))
}
}
+
+#[cfg(feature = "arbitrary")]
+impl<'a> Arbitrary<'a> for AddrV1Message {
+ fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
+ Ok(Self {
+ time: u.arbitrary()?,
+ address: u.arbitrary()?,
+ })
+ }
+}
+
#[cfg(feature = "arbitrary")]
impl<'a> Arbitrary<'a> for AddrV2 {
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
diff --git a/p2p/src/message.rs b/p2p/src/message.rs
index 1bcd5a9b..c6f8c17f 100644
--- a/p2p/src/message.rs
+++ b/p2p/src/message.rs
@@ -27,7 +27,7 @@ use primitives::block::{self, HeaderDecoder, HeaderEncoder};
use primitives::transaction;
use units::FeeRate;
-use crate::address::{AddrV2Message, Address};
+use crate::address::{AddrV1Message, AddrV2Message};
use crate::consensus::{impl_consensus_encoding, impl_vec_wrapper};
use crate::merkle_tree::MerkleBlock;
use crate::{
@@ -399,14 +399,14 @@ impl std::error::Error for InventoryPayloadDecoderError {
/// A list of legacy p2p address messages.
#[derive(Clone, PartialEq, Eq, Debug)]
-pub struct AddrPayload(pub Vec<(u32, Address)>);
+pub struct AddrPayload(pub Vec<AddrV1Message>);
/// A list of v2 address messages.
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct AddrV2Payload(pub Vec<AddrV2Message>);
impl_vec_wrapper!(InventoryPayload, message_blockdata::Inventory);
-impl_vec_wrapper!(AddrPayload, (u32, Address));
+impl_vec_wrapper!(AddrPayload, AddrV1Message);
impl_vec_wrapper!(AddrV2Payload, AddrV2Message);
/// The `feefilter` message, wrapper around [`FeeRate`] for P2P wire format encoding.
@@ -1832,7 +1832,7 @@ fn sha2_checksum(data: &[u8]) -> [u8; 4] {
#[cfg(feature = "arbitrary")]
impl<'a> Arbitrary<'a> for AddrPayload {
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
- Ok(Self(Vec::<(u32, Address)>::arbitrary(u)?))
+ Ok(Self(Vec::<AddrV1Message>::arbitrary(u)?))
}
}
@@ -1934,7 +1934,7 @@ mod test {
use units::BlockHeight;
use super::*;
- use crate::address::AddrV2;
+ use crate::address::{Address, AddrV2};
use crate::bip152::BlockTransactionsRequest;
use crate::message_blockdata::{GetBlocksMessage, GetHeadersMessage, Inventory};
use crate::message_bloom::{BloomFlags, FilterAdd, FilterLoad};
@@ -1963,10 +1963,10 @@ mod test {
let msgs = [
NetworkMessage::Version(version_msg),
NetworkMessage::Verack,
- NetworkMessage::Addr(AddrPayload(vec![(
- 45,
- Address::new(&([123, 255, 000, 100], 833).into(), ServiceFlags::NETWORK),
- )])),
+ NetworkMessage::Addr(AddrPayload(vec![AddrV1Message {
+ time: 45,
+ address: Address::new(&([123, 255, 000, 100], 833).into(), ServiceFlags::NETWORK),
+ }])),
NetworkMessage::Inv(InventoryPayload(vec![Inventory::Block(
BlockHash::from_byte_array(hash([8u8; 32]).to_byte_array()),
)])),
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.