6 """encapsulate contact info"""
10 self.id = self.host = self.port = ''
12 def init(self, id, host, port):
14 self.num = hash.intify(id)
17 self._senderDict = {'id': self.id, 'port' : self.port, 'host' : self.host}
20 def initWithDict(self, dict):
21 self._senderDict = dict
23 self.num = hash.intify(self.id)
24 self.port = dict['port']
25 self.host = dict['host']
28 def updateLastSeen(self):
29 self.lastSeen = time.time()
33 self.fails = self.fails + 1
37 return self._senderDict
40 return `(self.id, self.host, self.port)`
42 ## these comparators let us bisect/index a list full of nodes with either a node or an int/long
44 if type(a) == InstanceType:
48 if type(a) == InstanceType:
52 if type(a) == InstanceType:
56 if type(a) == InstanceType:
60 if type(a) == InstanceType:
64 if type(a) == InstanceType:
71 class TestNode(unittest.TestCase):
73 self.node = Node().init(hash.newID(), 'localhost', 2002)
74 def testUpdateLastSeen(self):
75 t = self.node.lastSeen
76 self.node.updateLastSeen()
77 assert t < self.node.lastSeen