1 ## Copyright 2002-2003 Andrew Loewenstern, All Rights Reserved
2 # see LICENSE.txt for license information
5 from types import InstanceType
7 from twisted.trial import unittest
11 # magic id to use before we know a peer's id
15 """encapsulate contact info"""
19 self.id = self.host = self.port = ''
21 def init(self, id, host, port):
23 self.num = khash.intify(id)
26 self._senderDict = {'id': self.id, 'port' : self.port, 'host' : self.host}
29 def initWithDict(self, dict):
30 self._senderDict = dict
32 self.num = khash.intify(self.id)
33 self.port = dict['port']
34 self.host = dict['host']
37 def updateLastSeen(self):
38 self.lastSeen = time()
42 self.fails = self.fails + 1
46 return self._senderDict
49 return `(self.id, self.host, self.port)`
51 ## these comparators let us bisect/index a list full of nodes with either a node or an int/long
53 if type(a) == InstanceType:
57 if type(a) == InstanceType:
61 if type(a) == InstanceType:
65 if type(a) == InstanceType:
69 if type(a) == InstanceType:
73 if type(a) == InstanceType:
78 class TestNode(unittest.TestCase):
80 self.node = Node().init(khash.newID(), 'localhost', 2002)
81 def testUpdateLastSeen(self):
82 t = self.node.lastSeen
83 self.node.updateLastSeen()
84 assert t < self.node.lastSeen