1 ## Copyright 2002-2003 Andrew Loewenstern, All Rights Reserved
2 # see LICENSE.txt for license information
5 from types import InstanceType
10 """encapsulate contact info"""
14 self.id = self.host = self.port = ''
16 def init(self, id, host, port):
18 self.num = khash.intify(id)
21 self._senderDict = {'id': self.id, 'port' : self.port, 'host' : self.host}
24 def initWithDict(self, dict):
25 self._senderDict = dict
27 self.num = khash.intify(self.id)
28 self.port = dict['port']
29 self.host = dict['host']
32 def updateLastSeen(self):
33 self.lastSeen = time()
37 self.fails = self.fails + 1
41 return self._senderDict
44 return `(self.id, self.host, self.port)`
46 ## these comparators let us bisect/index a list full of nodes with either a node or an int/long
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:
68 if type(a) == InstanceType:
75 class TestNode(unittest.TestCase):
77 self.node = Node().init(khash.newID(), 'localhost', 2002)
78 def testUpdateLastSeen(self):
79 t = self.node.lastSeen
80 self.node.updateLastSeen()
81 assert t < self.node.lastSeen