Exemplo n.º 1
0
 def test_find_circuit(self):
     host = Host((MockupUDPServer(), 80))
     host2 = Host((MockupUDPServer(), 80))
     udp_connection = UDPDispatcher()
     assert len(udp_connection.circuit_manager.circuit_map) == 0, \
            "Circuit map has incorrect circuits"
     circuit1 = udp_connection.find_circuit(host)
     assert len(udp_connection.circuit_manager.circuit_map) == 1, \
            "Circuit map has incorrect circuits 2"
     circuit2 = udp_connection.find_circuit(host2)
     assert len(udp_connection.circuit_manager.circuit_map) == 2, \
            "Circuit map has incorrect circuits 3"
     circuit3 = udp_connection.find_circuit(host2)
     assert circuit2 == circuit3, "Didn't save circuit"
     assert len(udp_connection.circuit_manager.circuit_map) == 2, \
            "Circuit map has incorrect circuits 4"
Exemplo n.º 2
0
    def __init__(self,
                 sim_ip,
                 sim_port,
                 viewer_facing_port,
                 target_facing_port,
                 udp_client=None,
                 settings=None,
                 message_handler=None,
                 message_template=None,
                 message_xml=None):
        """ initialize a UDP proxy, extending the UDPDispatcher """

        # we are extending the standard UDPDispatcher
        super(UDPProxy, self).__init__(udp_client, settings, message_handler,
                                       message_template, message_xml)

        # tell the backend to keep quiet
        self.settings.PROXY_LOGGING = True
        # ToDo: remove this, use the message_handler to get at data instead
        self.settings.ENABLE_DEFERRED_PACKET_PARSING = False

        self.target_host = Host((sim_ip, sim_port))
        self.local_host = None
        self.viewer_address = None

        self.target_udp_client = self.udp_client  # region facing
        self.target_socket = self.socket  # already spun up as part of the parent UDPDispatcher class instance
        self.target_socket.bind(
            (socket.gethostname(), target_facing_port))  # bind it to a port
        self.target_socket.setblocking(0)  # set the socket to nonblocking

        self.proxy_udp_client = NetUDPClient()  # the viewer's socket
        self.proxy_socket = self.proxy_udp_client.start_udp_connection(
        )  # grab a socket!
        self.proxy_socket.bind(
            (socket.gethostname(), viewer_facing_port))  # bind it to a port
        self.proxy_socket.setblocking(0)  # set the socket to nonblocking

        # the viewer needs a local hostname to connect to, as well as a port
        self.hostname = self.proxy_socket.getsockname()[0]

        self.local_host = Host(
            (self.hostname,
             viewer_facing_port))  # populate this convenience reference

        logger.info("Initialized the UDPProxy for %s at %s" %
                    (self.target_host, self.local_host))
Exemplo n.º 3
0
    def setUp(self):

        self.settings = Settings()
        self.settings.ENABLE_DEFERRED_PACKET_PARSING = False

        self.udp_connection = UDPDispatcher(MockupUDPClient(),
                                            settings=self.settings)
        self.host = Host((MockupUDPServer(), 80))
Exemplo n.º 4
0
 def test_send_reliable(self):
     msg = Message('PacketAck', Block('Packets', ID=0x00000003))
     host = Host((MockupUDPServer(), 80))
     ret_msg = self.udp_connection.send_reliable(msg, host, 10)
     test_str = '\x40' + '\x00\x00\x00\x01' + '\x00' + '\xff\xff\xff\xfb' + \
            '\x01' + '\x03\x00\x00\x00'
     assert ret_msg == \
            test_str ,\
            'Received: ' + repr(msg) + '  ' + \
            'Expected: ' + repr(test_str)
Exemplo n.º 5
0
    def test_(self):
        manager = CircuitManager()
        assert len(manager.circuit_map) == 0, "Circuit list incorrect"
        manager.add_circuit(self.host, 1)
        assert len(manager.circuit_map) == 1, "Circuit list incorrect 2"
        host = Host((0x00000011, 80))
        manager.add_circuit(host, 10)
        assert len(manager.circuit_map) == 2, "Circuit list incorrect 4"
        circuit = manager.get_circuit(self.host)
        assert circuit.last_packet_in_id == 1, "Got wrong circuit"
        circuit = manager.get_circuit(host)
        assert circuit.last_packet_in_id == 10, "Got wrong circuit 1"

        assert manager.is_circuit_alive(self.host) == True, \
               "Incorrect circuit alive state"
        assert manager.is_circuit_alive(host) == True, \
               "Incorrect circuit alive state 2"
Exemplo n.º 6
0
 def send_message(self, client, send_message):
     #print 'SERVER send'
     client.rec = send_message
     client.sender = Host((self, self.port))
Exemplo n.º 7
0
 def setUp(self):
     self.host = Host((0x00000001, 80))
Exemplo n.º 8
0
 def test_fail(self):
     host = Host((None, None))
     assert host.is_ok() == False, "Bad host thinks it is good"
Exemplo n.º 9
0
 def test(self):
     host = Host((0x00000001, 80))
     assert host.is_ok() == True, "Good host thinks it is bad"
Exemplo n.º 10
0
    def __init__(self):

        self.sender = Host((None, None))
        self.socket = None
 def setUp(self):
     self.host = Host((MockupUDPServer(), 80))
     self.message_manager = MessageManager(self.host,
                                           capabilities={'EventQueueGet' : Capability('EventQueueGet', 'http://127.0.0.1')})
Exemplo n.º 12
0
    def setUp(self):

        self.eq = EventQueueClient(host = Host(('127.0.0.1', '9000')))