4 from xmlrpclib import Binary
7 """encapsulate contact info"""
11 self.id = self.host = self.port = ''
13 def init(self, id, host, port):
15 self.num = hash.intify(id)
18 self._senderDict = {'id': self.id.encode('base64'), 'port' : self.port, 'host' : self.host}
21 def initWithDict(self, dict):
22 self._senderDict = dict
23 self.id = dict['id'].decode('base64')
24 self.num = hash.intify(self.id)
25 self.port = dict['port']
26 self.host = dict['host']
29 def updateLastSeen(self):
30 self.lastSeen = time.time()
34 self.fails = self.fails + 1
38 return self._senderDict
41 return `(self.id, self.host, self.port)`
43 ## these comparators let us bisect/index a list full of nodes with either a node or an int/long
45 if type(a) == InstanceType:
49 if type(a) == InstanceType:
53 if type(a) == InstanceType:
57 if type(a) == InstanceType:
61 if type(a) == InstanceType:
65 if type(a) == InstanceType:
72 class TestNode(unittest.TestCase):
74 self.node = Node().init(hash.newID(), 'localhost', 2002)
75 def testUpdateLastSeen(self):
76 t = self.node.lastSeen
77 self.node.updateLastSeen()
78 assert t < self.node.lastSeen