Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,10 @@ pub enum TimedMessage {
CFilters,
/// Bitcoin blocks
Block,
/// Potential peers on the network
/// Potential peers on the network, either `addr` or `addrv2`.
Addr,
/// Transaction announcements by `Tx`, `WTx`, or `WitnessTransaction`.
TransactionAnnouncement,
}

#[derive(Debug, Clone)]
Expand All @@ -196,6 +198,7 @@ impl TimedMessages {
TimedMessage::CFilters,
TimedMessage::Block,
TimedMessage::Addr,
TimedMessage::TransactionAnnouncement,
] {
map.insert(key, MessageRate::new());
}
Expand Down
21 changes: 21 additions & 0 deletions src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use bitcoin::{
};
use p2p::{
message::{NetworkMessage, RawNetworkMessage, V1MessageHeader},
message_blockdata::Inventory,
Magic, NetworkExt,
};

Expand Down Expand Up @@ -336,6 +337,26 @@ impl ConnectionReader {
}
}
}
NetworkMessage::Inv(payload) => {
let payload = &payload.0;
let now = Instant::now();
if let Ok(mut lock) = self.timed_messages.lock() {
for inv in payload {
match inv {
Inventory::WTx(_) => {
lock.add_single(TimedMessage::TransactionAnnouncement, now);
}
Inventory::Transaction(_) => {
lock.add_single(TimedMessage::TransactionAnnouncement, now);
}
Inventory::WitnessTransaction(_) => {
lock.add_single(TimedMessage::TransactionAnnouncement, now);
}
_ => (),
}
}
}
}
_ => (),
}
}
Expand Down