4 from xmlrpclib import Binary
7 """encapsulate contact info"""
8 def init(self, id, host, port):
10 self.int = hash.intify(id)
13 self.lastSeen = time.time()
14 self._senderDict = {'id': Binary(self.id), 'port' : self.port, 'host' : self.host}
17 def initWithDict(self, dict):
18 self._senderDict = dict
19 self.id = dict['id'].data
20 self.int = hash.intify(self.id)
21 self.port = dict['port']
22 self.host = dict['host']
23 self.lastSeen = time.time()
26 def updateLastSeen(self):
27 self.lastSeen = time.time()
30 return self._senderDict
33 return `(self.id, self.host, self.port)`
35 ## these comparators let us bisect/index a list full of nodes with either a node or an int/long
37 if type(a) == InstanceType:
41 if type(a) == InstanceType:
45 if type(a) == InstanceType:
49 if type(a) == InstanceType:
53 if type(a) == InstanceType:
57 if type(a) == InstanceType:
64 class TestNode(unittest.TestCase):
66 self.node = Node().init(hash.newID(), 'localhost', 2002)
67 def testUpdateLastSeen(self):
68 t = self.node.lastSeen
69 self.node.updateLastSeen()
70 assert t < self.node.lastSeen