From abc0034a45eb2cef4e45a066106622ecf8a89b76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Frosteg=C3=A5rd?= Date: Mon, 25 May 2020 18:59:43 +0200 Subject: [PATCH] aquatic_ws: don't send peer its own offer --- TODO.md | 2 ++ aquatic_ws/src/lib/handler.rs | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/TODO.md b/TODO.md index 79f757e..0cb2fec 100644 --- a/TODO.md +++ b/TODO.md @@ -31,6 +31,8 @@ out and everything will start working * stack-allocated vectors for announce request offers and scrape request info hashes? +* write new version of extract_response_peers which checks for equality with + peer sending request? ## aquatic_udp diff --git a/aquatic_ws/src/lib/handler.rs b/aquatic_ws/src/lib/handler.rs index d0bf910..a7f4078 100644 --- a/aquatic_ws/src/lib/handler.rs +++ b/aquatic_ws/src/lib/handler.rs @@ -168,6 +168,17 @@ pub fn handle_announce_requests( ); for (offer, peer) in offers.into_iter().zip(peers){ + // Avoid sending offer back to requesting peer. This could be + // done in extract_announce_peers, but it would likely hurt + // performance to check all peers there for their socket addr, + // especially if there are thousands of peers. It might be + // possible to write a new version of that function which isn't + // shared with aquatic_udp and goes about it differently + // though. + if sender_meta.peer_addr == peer.connection_meta.peer_addr { + continue; + } + let middleman_offer = MiddlemanOfferToPeer { info_hash, peer_id,