Ejemplo n.º 1
0
 def send_encapsulated(self,
                       data,
                       address,
                       reliability,
                       reliable_frame_index=0,
                       sequenced_frame_index=0,
                       ordered_frame_index=0,
                       order_channel=0,
                       compound_size=0,
                       compound_id=0,
                       compound_index=0):
     connection = self.get_connection(address[0], address[1])
     packets.encapsulated["body"] = data
     packets.encapsulated["flags"] = reliability
     packets.encapsulated["sequence_order"] = connection["sequence_order"]
     packets.encapsulated["reliable_frame_index"] = reliable_frame_index
     packets.encapsulated["sequenced_frame_index"] = sequenced_frame_index
     packets.encapsulated["order"][
         "ordered_frame_index"] = ordered_frame_index
     packets.encapsulated["order"]["order_channel"] = order_channel
     packets.encapsulated["fragment"]["compound_size"] = compound_size
     packets.encapsulated["fragment"]["compound_id"] = compound_id
     packets.encapsulated["fragment"]["index"] = compound_index
     packet = packets.write_encapsulated()
     socket.send_buffer(self.socket, packet, address)
     self.send_ack_queue(address)
     self.add_to_queue(packet, address)
Ejemplo n.º 2
0
    def packet_handler(self, data, address):
        id = data[0]

        connection = self.get_connection(address[0], address[1])
        if self.OPTIONS["debug"]: print(f"[RECIEVED] DATA_PACKET -> {hex(id)}")
        if connection != None:
            if id == messages.ID_NACK:
                packets.read_encapsulated(self.get_last_packet(address))
                packets.encapsulated["flags"] = 0
                packets.encapsulated["sequence_order"] = connection[
                    "sequence_order"]
                socket.send_buffer(packets.write_encapsulated(), address, self)

            elif id == messages.ID_ACK:
                pass

            else:
                self.send_ack_queue(address)
                packets.read_encapsulated(data)
                data_packet = packets.encapsulated["body"]
                id = data_packet[0]

                self.EVENT_BEFORE(Context(self, data), connection)

                for eventID, func in self.EVENTS.items():
                    if self.OPTIONS["debug"]:
                        print(f"{hex(id)} -> {hex(eventID)}: {str(func)}")
                    if id == eventID:
                        func(Context(self, data), connection)
                        break

                self.EVENT_AFTER(Context(self, data), connection)

        elif id == messages.ID_UNCONNECTED_PING:
            socket.send_buffer(self.socket,
                               handler.handle_unconnected_ping(data, self),
                               address)

        elif id == messages.ID_UNCONNECTED_PING_OPEN_CONNECTIONS:
            socket.send_buffer(
                self.socket,
                handler.handle_unconnected_ping_open_connections(data, self),
                address)

        elif id == messages.ID_OPEN_CONNECTION_REQUEST_1:
            socket.send_buffer(
                self.socket,
                handler.handle_open_connection_request_1(data, self), address)

        elif id == messages.ID_OPEN_CONNECTION_REQUEST_2:
            socket.send_buffer(
                self.socket,
                handler.handle_open_connection_request_2(
                    data, (address[0], address[1]), self), address)
Ejemplo n.º 3
0
 def send_ack_queue(self, address):
     connection = self.get_connection(address[0], address[1])
     packets.ack["packets"] = []
     packets.ack["packets"].append(connection["sequence_order"])
     socket.send_buffer(self.socket, packets.write_ack(), address)