Skip to content

Commit

Permalink
removed self.banned from client class and replaced it with a node.pee…
Browse files Browse the repository at this point in the history
…rs.is_banned(host) check

the other option is to trigger self.banned on every ban (overly complex)
  • Loading branch information
hclivess committed Sep 19, 2019
1 parent d5fd5a2 commit 087dd15
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 8 deletions.
1 change: 0 additions & 1 deletion libs/client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
class Client:
def __init__(self):
self.banned = False
self.connected = False
3 changes: 1 addition & 2 deletions node.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,6 @@ def handle(self):
node.plugin_manager.execute_filter_hook('peer_ip', dict_ip)

if node.peers.is_banned(peer_ip) or dict_ip['ip'] == 'banned':
client_instance.banned = True
self.request.close()
node.logger.app_log.info(f"IP {peer_ip} banned, disconnected")

Expand All @@ -606,7 +605,7 @@ def handle(self):
timeout_operation = 120 # timeout
timer_operation = time.time() # start counting

while not client_instance.banned and node.peers.version_allowed(peer_ip, node.version_allow) and client_instance.connected:
while not node.peers.is_banned(host) and node.peers.version_allowed(peer_ip, node.version_allow) and client_instance.connected:
try:
# Failsafe
if self.request == -1:
Expand Down
7 changes: 2 additions & 5 deletions worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def worker(host, port, node):
client_instance_worker = client.Client()

if node.peers.is_banned(host) or dict_ip['ip'] == 'banned':
client_instance_worker.banned = True
node.logger.app_log.warning(f"IP {host} is banned, won't connect")
return

Expand Down Expand Up @@ -106,10 +105,10 @@ def worker(host, port, node):
node.logger.app_log.info(f"Connected to {this_client}")
node.logger.app_log.info(f"Current active pool: {node.peers.connection_pool}")

if not client_instance_worker.banned and node.peers.version_allowed(host, node.version_allow) and not node.IS_STOPPING:
if not node.peers.is_banned(host) and node.peers.version_allowed(host, node.version_allow) and not node.IS_STOPPING:
db_handler_instance = dbhandler.DbHandler(node.index_db, node.ledger_path, node.hyper_path, node.ram, node.ledger_ram_file, logger)

while not client_instance_worker.banned and node.peers.version_allowed(host, node.version_allow) and not node.IS_STOPPING:
while not node.peers.is_banned(host) and node.peers.version_allowed(host, node.version_allow) and not node.IS_STOPPING:
try:
#ensure_good_peer_version(host)

Expand Down Expand Up @@ -169,7 +168,6 @@ def worker(host, port, node):
send(s, data)

else:

node.logger.app_log.warning(
f"Outbound: Node is at block {client_block}") # now check if we have any newer

Expand Down Expand Up @@ -276,7 +274,6 @@ def worker(host, port, node):
except:
if node.peers.warning(s, peer_ip, "Failed to deliver the longest chain", 2):
raise ValueError(f"{peer_ip} is banned")

else:
digest_block(node, segments, s, peer_ip, db_handler_instance)

Expand Down

0 comments on commit 087dd15

Please sign in to comment.