1 ## Copyright 2002-2003 Andrew Loewenstern, All Rights Reserved
2 # see LICENSE.txt for license information
9 """encapsulate contact info"""
13 self.id = self.host = self.port = ''
15 def init(self, id, host, port):
17 self.num = khash.intify(id)
20 self._senderDict = {'id': self.id, 'port' : self.port, 'host' : self.host}
23 def initWithDict(self, dict):
24 self._senderDict = dict
26 self.num = khash.intify(self.id)
27 self.port = dict['port']
28 self.host = dict['host']
31 def updateLastSeen(self):
32 self.lastSeen = time.time()
36 self.fails = self.fails + 1
40 return self._senderDict
43 return `(self.id, self.host, self.port)`
45 ## these comparators let us bisect/index a list full of nodes with either a node or an int/long
47 if type(a) == InstanceType:
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:
74 class TestNode(unittest.TestCase):
76 self.node = Node().init(khash.newID(), 'localhost', 2002)
77 def testUpdateLastSeen(self):
78 t = self.node.lastSeen
79 self.node.updateLastSeen()
80 assert t < self.node.lastSeen