]> git.mxchange.org Git - quix0rs-apt-p2p.git/blobdiff - apt_p2p_Khashmir/node.py
Fix some errors in the new twisted HTTP client's connectionLost() methods.
[quix0rs-apt-p2p.git] / apt_p2p_Khashmir / node.py
index 49b8fe75a06923379d5bfecad8d86f083262a5aa..a5f40eb0c4362e7f219a7c67e0de07915af6286d 100644 (file)
@@ -16,7 +16,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 +105,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: