From 5a30ee77a1fa591133e85e6eb20df5e5e57648f8 Mon Sep 17 00:00:00 2001 From: Jason Ish Date: Wed, 7 Sep 2022 16:46:20 -0600 Subject: [PATCH] bittorrent-dht: only attempt to parse dht messages The bittorrent flow is shared with transport messages as well as dht messages. Only attempt to parse dht message as dht, ignore the rest. --- rust/src/bittorrent_dht/bittorrent_dht.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/rust/src/bittorrent_dht/bittorrent_dht.rs b/rust/src/bittorrent_dht/bittorrent_dht.rs index 346635714f..0e0d77fd87 100644 --- a/rust/src/bittorrent_dht/bittorrent_dht.rs +++ b/rust/src/bittorrent_dht/bittorrent_dht.rs @@ -92,7 +92,21 @@ impl BitTorrentDHTState { return tx; } + fn is_dht(input: &[u8]) -> bool { + if input.len() > 5 { + match &input[0..5] { + b"d1:ad" | b"d1:rd" | b"d2:ip" | b"d1:el" => true, + _ => false, + } + } else { + false + } + } + pub fn parse(&mut self, input: &[u8]) -> bool { + if !Self::is_dht(input) { + return true; + } let mut tx = self.new_tx(); let mut status = true; -- 2.47.2