def __ge__(self, other):
return (self.getseq() - other.getseq()) % 2**16 < 256
-class OrderedConnection(AirhookConnection):
+class StreamConnection(AirhookConnection):
"""
- this implements a simple protocol for ordered messages over airhook
+ this implements a simple protocol for a stream over airhook
the first two octets of each message are interpreted as a 16-bit sequence number
253 bytes are used for payload
+
+ delegate should implement method:
+ def dataCameIn(self, host, port, data):
+ [...]
"""
def __init__(self, transport, addr, delegate):
AirhookConnection.__init__(self, transport, addr, delegate)
self.assertEqual(a.next, 255)
self.assertEqual(a.outMsgNums[(a.outSeq-1) % 256], 254)
-class OrderedTests(unittest.TestCase):
+class StreamTests(unittest.TestCase):
def setUp(self):
self.noisy = 0
class queuer:
self.msg+= data
self.A = queuer()
self.B = queuer()
- self.a = OrderedConnection(StringIO(), (None, 'localhost', 4040), self.A)
- self.b = OrderedConnection(StringIO(), (None, 'localhost', 4040), self.B)
+ self.a = StreamConnection(StringIO(), (None, 'localhost', 4040), self.A)
+ self.b = StreamConnection(StringIO(), (None, 'localhost', 4040), self.B)
- def testOrderedSimple(self, num = 2**18, prob=1.0):
+ def testStreamSimple(self, num = 2**18, prob=1.0):
f = open('/dev/urandom', 'r')
a = self.a
b = self.b
self.assertEqual(self.A.msg, MSGB)
self.assertEqual(self.B.msg, MSGA)
- def testOrderedLossy(self, num = 2**18, prob=0.5):
- self.testOrderedSimple(num, prob)
+ def testStreamLossy(self, num = 2**18, prob=0.5):
+ self.testStreamSimple(num, prob)