Пример #1
0
    def send_message(self, parsed_message):
        destination_ip = self.server_data["gateway_ip"]
        packet = utils.rewrite_packet(parsed_message)

        msg = " ".join(["Sending message to:", destination_ip])
        utils.show_status(self.server_id, msg)

        self.notify_incoming_connection()  # alert main router

        check.socket_send(self.server_connection, packet,
                          "Could not send the message")
Пример #2
0
    def send_message(self, parsed_message, destination_socket, destination_ip):
        packet = utils.rewrite_packet(
            parsed_message    
        )

        utils.report(
            self.router_id,
            parsed_message,
            "preparing to forward the following packet:"
        )
        
        check.socket_send(
            destination_socket,
            packet,
            self.router_id,
            "packet to the client could not be sent"
        )

        msg = " ".join(["message sent to", destination_ip])
        utils.show_status(self.router_id, msg)
Пример #3
0
    def go_offline(self):

        utils.show_status(self.client_id, "going offline")
        gateway_ip = self.client_data["gateway_ip"]
        server_ip = self.client_data["server_ip"]

        leave_packet = utils.write_packet(self.client_data.get("ip_address"),
                                          server_ip,
                                          self.client_data.get("mac_address"),
                                          self.arp_table_mac[gateway_ip],
                                          "{going offline}")

        self.notify_incoming_message()
        self.sync_event_message.wait()  # wait for router approval
        self.sync_event_message.clear()

        check.socket_send(self.client_connection, leave_packet, self.client_id,
                          "Leave packet could not be sent")

        self.join()
Пример #4
0
    def go_online(self):

        utils.show_status(self.client_id, "connecting to the network")
        server_ip = self.client_data["server_ip"]
        router_port = self.client_data["gateway_port"]
        router_address = ("localhost", router_port)
        gateway_ip = self.client_data["gateway_ip"]

        self.notify_incoming_connection()
        # waiting for router approving connection
        self.sync_event_connection.wait()
        self.sync_event_connection.clear()  # ready for reuse

        connected = check.socket_connect(self.client_connection,
                                         router_address, self.client_id)

        if (connected is True):
            utils.show_status(self.client_id, "going online")
            # waiting for router completing connection procedure
            self.sync_event_connection.wait()
            self.sync_event_connection.clear()  # ready for reuse

            greeting_packet = utils.write_packet(
                self.client_data.get("ip_address"), server_ip,
                self.client_data.get("mac_address"),
                self.arp_table_mac[gateway_ip], "{going online}")

            utils.show_status(self.client_id,
                              "waiting for router accepting message")
            self.notify_incoming_message()
            # waiting for router approving message sending
            self.sync_event_message.wait()
            self.sync_event_message.clear()

            check.socket_send(self.client_connection, greeting_packet,
                              self.client_id,
                              "Greeting packet could not be sent")

        return connected
Пример #5
0
    def send_message(self, recipient_ip, message):

        gateway_ip = self.client_data["gateway_ip"]

        packet = utils.write_packet(self.client_data["ip_address"],
                                    recipient_ip,
                                    self.client_data.get("mac_address"),
                                    self.arp_table_mac[gateway_ip], message)

        utils.show_status(self.client_id,
                          "waiting for router listening messages")
        self.notify_incoming_message()
        # waiting for router approving message sending
        self.sync_event_message.wait()

        sent = check.socket_send(self.client_connection, packet,
                                 self.router_id)
        if (sent is True):
            msg = " ".join(["message sent to", gateway_ip])
            utils.show_status(self.client_id, msg)

        self.sync_event_message.clear()