Example #1
0
    def test_timeout(self):
        alice = Connection([], 0.5)
        self.assertEquals(alice.has_timeouted(), False)        
        sleep(0.6)

        self.assertEquals(alice.has_timeouted(), True)     
        self.assertEquals(alice.has_new_data, False) 
Example #2
0
    def test_timeout(self):
        alice = Connection([], 0.5)
        self.assertEquals(alice.has_timeouted(), False)
        sleep(0.6)

        self.assertEquals(alice.has_timeouted(), True)
        self.assertEquals(alice.has_new_data, False)
Example #3
0
    def test_nothingtosend(self):
        alice_0 = Channel(0, RTM_NONE)
        alice_1 = Channel(1, RTM_NONE)

        alice = Connection([alice_0, alice_1])

        self.assertRaises(NothingToSend, alice.on_sendable)
Example #4
0
    def test_misrouting(self):
        alice_0 = Channel(0, RTM_NONE)
        alice_1 = Channel(1, RTM_NONE)
        bob_1 = Channel(1, RTM_NONE)

        alice = Connection([alice_0, alice_1])
        bob = Connection([bob_1])

        alice[0].write(bytearray('DUPA1'))

        pk = alice.on_sendable()

        bob.on_received(pk)

        self.assertRaises(NothingToRead, bob[1].read)
        self.assertEquals(bob.has_new_data, False)
Example #5
0
    def test_channels(self):
        alice_0 = Channel(0, RTM_NONE)
        bob_0 = Channel(0, RTM_NONE)

        alice_1 = Channel(1, RTM_NONE)
        bob_1 = Channel(1, RTM_NONE)

        alice = Connection([alice_0, alice_1])
        bob = Connection([bob_0, bob_1])

        alice[0].write(bytearray('DUPA1'))

        pk1 = alice.on_sendable()

        self.assertEquals(pk1.channel_id, 0)

        bob.on_received(pk1)

        self.assertEquals(bob[0].read(), bytearray('DUPA1'))
        self.assertEquals(bob.has_new_data, True)
Example #6
0
    def test_misrouting(self):
        alice_0 = Channel(0, RTM_NONE)
        alice_1 = Channel(1, RTM_NONE)
        bob_1 = Channel(1, RTM_NONE)

        alice = Connection([alice_0, alice_1])
        bob = Connection([bob_1])

        alice[0].write(bytearray('DUPA1'))

        pk = alice.on_sendable()

        bob.on_received(pk)

        self.assertRaises(NothingToRead, bob[1].read)
        self.assertEquals(bob.has_new_data, False)
Example #7
0
    def test_channels(self):
        alice_0 = Channel(0, RTM_NONE)
        bob_0 = Channel(0, RTM_NONE)

        alice_1 = Channel(1, RTM_NONE)
        bob_1 = Channel(1, RTM_NONE)

        alice = Connection([alice_0, alice_1])
        bob = Connection([bob_0, bob_1])

        alice[0].write(bytearray('DUPA1'))

        pk1 = alice.on_sendable()

        self.assertEquals(pk1.channel_id, 0)

        bob.on_received(pk1)

        self.assertEquals(bob[0].read(), bytearray('DUPA1'))
        self.assertEquals(bob.has_new_data, True)
Example #8
0
from lnx2 import Packet, Connection, Channel, RTM_AUTO_ORDERED, RTM_NONE, ClientSocket, NothingToRead, RTM_MANUAL, RTM_AUTO
import sys, select, socket, hashlib, time, struct

# Prepare channel and connection
c_0 = Channel(0, RTM_AUTO_ORDERED, 10, 60)
c_1 = Channel(1, RTM_MANUAL, 5, 1)
c_2 = Channel(2, RTM_MANUAL, 5, 1) 
c_3 = Channel(3, RTM_AUTO, 10, 60)
c_4 = Channel(4, RTM_NONE, 5, 1) 
c_5 = Channel(5, RTM_AUTO, 5, 60)


conn = Connection([c_0, c_1, c_2, c_3, c_4, c_5], 15)

def wait_until_clear(chanid):
    """Waits until there is no tx activity on channel chanid"""
    while conn[chanid].is_tx_in_progress():
        rs, ws, xs = select.select([sock.socket], [sock.socket], [], 5)
        if len(ws) == 1:
            sock.on_sendable()
        if len(rs) == 1:
            sock.on_readable()

def packon(chanid):
    """Waits until a packet is received on channel chanid. Returns it"""
    while True:
        rs, ws, xs = select.select([sock.socket], [sock.socket], [], 5)
        if len(ws) == 1:
            sock.on_sendable()
        if len(rs) == 1:
            sock.on_readable()