예제 #1
0
        public void __handle_packet(IPAddress route_address, Packet now_packet)
        {
            byte[] command = now_packet.get_command_string();
            if (Encoding.UTF8.GetString(command) == "POST")
            {
                JsonObject decrypt_post = JsonConvert.DeserializeObject<JsonObject>(Encoding.UTF8.GetString(Utils.json_decrypt(SECRET_KEY.secret_key, now_packet.Payload)));
                this.__send_get_data_packet(route_address, decrypt_post.uuid);
            }
            else if (Encoding.UTF8.GetString(command) == "ACK")
            {
                JsonObject decrypt_ack = JsonConvert.DeserializeObject<JsonObject>(Encoding.UTF8.GetString(Utils.json_decrypt(SECRET_KEY.secret_key, now_packet.Payload)));
                if (DEBUG)
                {
                    Console.WriteLine("[LOG][{0}]: the data packet {1} has been received by {2}!", DateTime.Now.ToString(), decrypt_ack.uuid, route_address);
                }
                if (__caching_dict.ContainsKey(Encoding.UTF8.GetString(decrypt_ack.uuid)))
                {
                    this.__caching_dict.Remove(Encoding.UTF8.GetString(decrypt_ack.uuid));
                }
            }

            else if (Encoding.UTF8.GetString(command) == "GETDATA")
            {
                JsonObject decrypt_getdata = JsonConvert.DeserializeObject<JsonObject>(Encoding.UTF8.GetString(Utils.json_decrypt(SECRET_KEY.secret_key, now_packet.Payload)));
                this.__sending_queue.Enqueue(Tuple.Create<IPAddress, Packet>(route_address, this.__caching_dict[Encoding.UTF8.GetString(decrypt_getdata.uuid)]));
            }
            else if (Encoding.UTF8.GetString(command) == "DATA")
            {
                JsonDataObject decrypt_data = JsonConvert.DeserializeObject<JsonDataObject>(Encoding.UTF8.GetString(Utils.json_decrypt(SECRET_KEY.secret_key, now_packet.Payload)));
                Console.WriteLine("to do functions");

                Console.WriteLine(decrypt_data.command);
                if(decrypt_data.command == "get_plane_number")
                {
                    JsonDataObject js = new JsonDataObject();
                    js.command = "plane_number";
                    Dictionary<string, string> d = new Dictionary<string, string>();
                    d.Add("plane_state", "all");
                    d.Add("plane_number", "5");
                    js.options = d;
                    IPAddress ip = IPAddress.Parse(ROUTE_ADDRESS.route_address);
                    send_data_packet(ip, js);
                }
                if(decrypt_data.command == "get_plane_location")
                {
                    JsonDataObject js = new JsonDataObject();
                    js.command = "plane_location";
                    Dictionary<string, string> d = new Dictionary<string, string>();
                    d.Add("plane_id", "6077");
                    d.Add("plane_location_x", "126.632837");
                    d.Add("plane_location_y", "45.744368");
                    d.Add("plane_location_z", "3");
                    js.options = d;
                    IPAddress ip = IPAddress.Parse(ROUTE_ADDRESS.route_address);
                    send_data_packet(ip, js);
                }

            }
        }
예제 #2
0
 public void send_data_packet(IPAddress route_address, JsonDataObject data_dict)
 {
     byte[] encrypt_data = utils.Utils.json_encrypt(config.SECRET_KEY.secret_key, Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(data_dict)));
     Packet data_packet = Packet.gen_packet(Encoding.UTF8.GetBytes("DATA"), encrypt_data);
     if (DEBUG)
     {
         Console.WriteLine("[LOG][{0}]: create a DATA packet which uuid is {1}", DateTime.Now.ToString(), Encoding.UTF8.GetString(data_packet.Packet_uuid));
     }
     this.__caching_dict.Add(Encoding.UTF8.GetString(data_packet.Packet_uuid), data_packet);
     this.__send_post_packet(route_address, data_packet.Packet_uuid);
 }