1 ## Copyright 2002-2003 Andrew Loewenstern, All Rights Reserved
2 # see LICENSE.txt for license information
5 from types import InstanceType
9 # magic id to use before we know a peer's id
13 """encapsulate contact info"""
17 self.id = self.host = self.port = ''
19 def init(self, id, host, port):
21 self.num = khash.intify(id)
24 self._senderDict = {'id': self.id, 'port' : self.port, 'host' : self.host}
27 def initWithDict(self, dict):
28 self._senderDict = dict
30 self.num = khash.intify(self.id)
31 self.port = dict['port']
32 self.host = dict['host']
35 def updateLastSeen(self):
36 self.lastSeen = time()
40 self.fails = self.fails + 1
44 return self._senderDict
47 return `(self.id, self.host, self.port)`
49 ## these comparators let us bisect/index a list full of nodes with either a node or an int/long
51 if type(a) == InstanceType:
55 if type(a) == InstanceType:
59 if type(a) == InstanceType:
63 if type(a) == InstanceType:
67 if type(a) == InstanceType:
71 if type(a) == InstanceType:
78 class TestNode(unittest.TestCase):
80 self.node = Node().init(khash.newID(), 'localhost', 2002)
81 def testUpdateLastSeen(self):
82 t = self.node.lastSeen
83 self.node.updateLastSeen()
84 assert t < self.node.lastSeen