X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=apt_p2p_Khashmir%2Fnode.py;h=eff754b318cc5690c41f10470ff678f1a7b28f14;hb=0dc8101b31ff7509bd4ae0da8ecd4ce1e99e53c4;hp=49b8fe75a06923379d5bfecad8d86f083262a5aa;hpb=7b1167d8ce780312d3689c9309c7e9c64060c085;p=quix0rs-apt-p2p.git diff --git a/apt_p2p_Khashmir/node.py b/apt_p2p_Khashmir/node.py index 49b8fe7..eff754b 100644 --- a/apt_p2p_Khashmir/node.py +++ b/apt_p2p_Khashmir/node.py @@ -1,5 +1,3 @@ -## Copyright 2002-2003 Andrew Loewenstern, All Rights Reserved -# see LICENSE.txt for license information """Represents a node in the DHT. @@ -16,7 +14,7 @@ import khash from util import compact # magic id to use before we know a peer's id -NULL_ID = 20 * '\0' +NULL_ID = khash.HASH_LENGTH * '\0' class Node: """Encapsulate a node's contact info. @@ -105,6 +103,17 @@ class Node: 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: @@ -130,6 +139,8 @@ class Node: if type(a) == InstanceType: a = a.num return self.num != a + def __hash__(self): + return hash(self.num) class TestNode(unittest.TestCase):