From 15917bfb32e2df9693bd511e05cc5b6535a01dca Mon Sep 17 00:00:00 2001 From: Eichhornchen Date: Wed, 6 Jan 2021 22:04:23 +0100 Subject: [PATCH] Added a fix to avoid becoming one's own neighbour. --- squinnondation/messages.py | 3 +++ squinnondation/peers.py | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/squinnondation/messages.py b/squinnondation/messages.py index 4cc6488..5b8c4f8 100644 --- a/squinnondation/messages.py +++ b/squinnondation/messages.py @@ -176,6 +176,9 @@ class HelloTLV(TLV): f"the id {self.source_id}.") sender.id = self.source_id + if self.source_id == user.id: + sender.marked_as_banned = True + if not sender.active: sender.id = self.source_id # The sender we are given misses an id time_hl = time.time() diff --git a/squinnondation/peers.py b/squinnondation/peers.py index 8d37222..584b86f 100644 --- a/squinnondation/peers.py +++ b/squinnondation/peers.py @@ -26,6 +26,7 @@ class Peer: self.symmetric = False self.active = False self.errors = 0 + self.marked_as_banned = False try: # Resolve DNS as an IPv6 @@ -60,7 +61,7 @@ class Peer: """ If a client send more than 5 invalid packets, we don't trust it anymore. """ - return self.errors >= 5 + return self.errors >= 5 or self.marked_as_banned def __repr__(self): return self.nickname or str(self.id) or str(self.main_address) @@ -79,6 +80,7 @@ class Peer: self.addresses.update(self.addresses) self.addresses.update(other.addresses) self.id = self.id if self.id > 0 else other.id + self.marked_as_banned = other.marked_as_banned return self