4 from xmlrpclib import Binary
7 """encapsulate contact info"""
12 self.id = self.host = self.port = ''
14 def init(self, id, host, port):
16 self.int = hash.intify(id)
19 self._senderDict = {'id': self.id.encode('base64'), 'port' : self.port, 'host' : self.host}
22 def initWithDict(self, dict):
23 self._senderDict = dict
24 self.id = dict['id'].decode('base64')
25 self.int = hash.intify(self.id)
26 self.port = dict['port']
27 self.host = dict['host']
30 def updateLastSeen(self):
31 self.lastSeen = time.time()
35 self.fails = self.fails + 1
39 return self._senderDict
42 return `(self.id, self.host, self.port)`
44 ## these comparators let us bisect/index a list full of nodes with either a node or an int/long
46 if type(a) == InstanceType:
50 if type(a) == InstanceType:
54 if type(a) == InstanceType:
58 if type(a) == InstanceType:
62 if type(a) == InstanceType:
66 if type(a) == InstanceType:
73 class TestNode(unittest.TestCase):
75 self.node = Node().init(hash.newID(), 'localhost', 2002)
76 def testUpdateLastSeen(self):
77 t = self.node.lastSeen
78 self.node.updateLastSeen()
79 assert t < self.node.lastSeen