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

Commit aa6cea3

Browse files
committed
Hit up seeds if bootstrap from cache fails
1 parent 890c513 commit aa6cea3

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

dht/network.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def bootstrappableNeighbors(self):
151151
neighbors = self.protocol.router.findNeighbors(self.node)
152152
return [tuple(n)[-2:] for n in neighbors]
153153

154-
def bootstrap(self, addrs):
154+
def bootstrap(self, addrs, deferred=None):
155155
"""
156156
Bootstrap the server by connecting to other known nodes in the network.
157157
@@ -165,9 +165,18 @@ def bootstrap(self, addrs):
165165
return task.deferLater(reactor, 1, self.bootstrap, addrs)
166166
self.log.info("bootstrapping with %s addresses, finding neighbors..." % len(addrs))
167167

168-
d = defer.Deferred()
168+
if deferred is None:
169+
d = defer.Deferred()
170+
else:
171+
d = deferred
169172

170173
def initTable(results):
174+
if len(results) == 0:
175+
if self.protocol.multiplexer.testnet:
176+
self.bootstrap(self.querySeed(SEEDS_TESTNET), d)
177+
else:
178+
self.bootstrap(self.querySeed(SEEDS), d)
179+
return
171180
potential_relay_nodes = []
172181
for addr, result in results.items():
173182
if result[0]:

net/wireprotocol.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def __init__(self, processors, nat_type, relay_node, ban_score, *args, **kwargs)
6868
self.is_new_node = True
6969
self.on_connection_made()
7070
self.time_last_message = 0
71+
self.ping_interval = 30 if nat_type != FULL_CONE else 300
7172

7273
def on_connection_made(self):
7374
if self.connection is None or self.connection.state == State.CONNECTING:
@@ -144,7 +145,8 @@ def keep_alive(self):
144145
):
145146
self.connection.shutdown()
146147
return
147-
if t - self.time_last_message >= 30:
148+
149+
if t - self.time_last_message >= self.ping_interval:
148150
for processor in self.processors:
149151
if PING in processor and self.node is not None:
150152
processor.callPing(self.node)

0 commit comments

Comments
 (0)