]> git.mxchange.org Git - quix0rs-apt-p2p.git/blobdiff - apt_p2p_Khashmir/node.py
Add $remote_fs dependency in init.d LSB header (Closes: #480645)
[quix0rs-apt-p2p.git] / apt_p2p_Khashmir / node.py
index 49b8fe75a06923379d5bfecad8d86f083262a5aa..eff754b318cc5690c41f10470ff678f1a7b28f14 100644 (file)
@@ -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):