from datetime import datetime, timedelta
from random import randrange, shuffle
from sha import sha
+from copy import copy
import os
from twisted.internet.defer import Deferred
"""
# Get K nodes out of local table/cache
nodes = self.table.findNodes(id)
+ nodes = [copy(node) for node in nodes]
d = Deferred()
if errback:
d.addCallbacks(callback, errback)
"""
# Get K nodes out of local table/cache
nodes = self.table.findNodes(key)
+ nodes = [copy(node) for node in nodes]
d = Deferred()
if errback:
d.addCallbacks(callback, errback)
def __repr__(self):
return `(self.id, self.host, self.port)`
+ def __copy__(self):
+ """Create a shallow copy of the node, resetting some values."""
+ cp = self.__class__(self.id, self.host, self.port)
+ cp.fails = self.fails
+ cp.lastSeen = self.lastSeen
+ if getattr(self, 'table', None) is not None:
+ cp.table = self.table
+ if getattr(self, 'conn', None) is not None:
+ cp.conn = self.conn
+ return cp
+
#{ Comparators to bisect/index a list of nodes with either a node or a long
def __lt__(self, a):
if type(a) == InstanceType: