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

Commit 890c513

Browse files
committed
Don't transfer key values to node if we have recently
1 parent 9722851 commit 890c513

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

dht/protocol.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def __init__(self, sourceNode, storage, ksize, database, signing_key):
3131
self.signing_key = signing_key
3232
self.log = Logger(system=self)
3333
self.handled_commands = [PING, STUN, STORE, DELETE, FIND_NODE, FIND_VALUE, HOLE_PUNCH, INV, VALUES]
34+
self.recent_transfers = set()
3435
RPCProtocol.__init__(self, sourceNode, self.router)
3536

3637
def connect_multiplexer(self, multiplexer):
@@ -225,7 +226,10 @@ def handleCallResponse(self, result, node):
225226
we get no response, make sure it's removed from the routing table.
226227
"""
227228
if result[0]:
228-
if self.isNewConnection(node):
229+
if self.isNewConnection(node) and node.id not in self.recent_transfers:
230+
if len(self.recent_transfers) == 10:
231+
self.recent_transfers.pop()
232+
self.recent_transfers.add(node.id)
229233
self.log.debug("call response from new node, transferring key/values")
230234
reactor.callLater(1, self.transferKeyValues, node)
231235
self.router.addContact(node)
@@ -240,7 +244,10 @@ def addToRouter(self, node):
240244
We add the node to our router and transfer our stored values
241245
if they are new and within our neighborhood.
242246
"""
243-
if self.isNewConnection(node):
247+
if self.isNewConnection(node) and node.id not in self.recent_transfers:
248+
if len(self.recent_transfers) == 10:
249+
self.recent_transfers.pop()
250+
self.recent_transfers.add(node.id)
244251
self.log.debug("found a new node, transferring key/values")
245252
reactor.callLater(1, self.transferKeyValues, node)
246253
self.router.addContact(node)

seed/httpseed.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def __init__(self, kserver_r):
8989
self.nodes[(node.ip, node.port)] = node
9090
self.nodes[(this_node.ip, this_node.port)] = this_node
9191
loopingCall = task.LoopingCall(self.crawl)
92-
loopingCall.start(180, True)
92+
loopingCall.start(900, True)
9393

9494
def crawl(self):
9595
def gather_results(result):

0 commit comments

Comments
 (0)