Skip to content
This repository was archived by the owner on May 16, 2019. It is now read-only.

Commit a22568f

Browse files
committed
Move keep alive loop from handlers to multiplexer
1 parent c8e6a6e commit a22568f

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

net/wireprotocol.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ def __init__(self, db, ip_address, nat_type, testnet=False, relaying=False):
4545
self.vendors = db.vendors.get_vendors()
4646
self.factory = self.ConnHandlerFactory(self.processors, nat_type, self.relay_node)
4747
self.log = Logger(system=self)
48+
self.keep_alive_loop = LoopingCall(self.keep_alive)
49+
self.keep_alive_loop.start(30 if nat_type == RESTRICTED else 1200, now=False)
4850
ConnectionMultiplexer.__init__(self, CryptoConnectionFactory(self.factory), self.ip_address[0], relaying)
4951

5052
class ConnHandler(Handler):
@@ -56,8 +58,6 @@ def __init__(self, processors, nat_type, relay_node, *args, **kwargs):
5658
self.connection = None
5759
self.node = None
5860
self.relay_node = relay_node
59-
self.keep_alive_loop = LoopingCall(self.keep_alive)
60-
self.keep_alive_loop.start(30 if nat_type == RESTRICTED else 1200, now=False)
6161
self.addr = None
6262
self.ban_score = None
6363
self.is_new_node = True
@@ -202,6 +202,11 @@ def set_servers(self, ws, blockchain):
202202
self.ws = ws
203203
self.blockchain = blockchain
204204

205+
def keep_alive(self):
206+
for connection in self:
207+
if connection.state != State.CONNECTING:
208+
connection.handler.keep_alive()
209+
205210
def send_message(self, datagram, address, relay_addr):
206211
"""
207212
Sends a datagram over the wire to the given address. It will create a new rudp connection if one
@@ -221,4 +226,3 @@ def send_message(self, datagram, address, relay_addr):
221226
con.set_relay_address(relay_addr)
222227

223228
con.send_message(datagram)
224-

0 commit comments

Comments
 (0)