コード例 #1
0
        /*Fucnión que genera un paquete de agregación para que los demás vehículos firmen si están
         * de acuerto con la información*/
        public void EnviaNuevoPaqueteAgregacion()
        {
            string IP = IPAddress.Broadcast.ToString();
            Cripto criputiles = new Cripto(Formulario);
            //Se obtiene el pseudónim
            BD AccesoBD = new BD(Formulario);
            string pseudonym = AccesoBD.recuperamyPseu();

            Cliente Client = new Cliente(Formulario, "9050");
            string prueba = "I_Traffic Jam_" + NombreVia + "_" + SentidoMarcha + "_" + CoodX.ToString() + "_" + CoordY.ToString() + "_" + CoordZ.ToString() + "_" + HoraGeneracionPaquete.ToString("MM/dd/yyyy HH:mm:ss");
            // Client.respuesta("T1", pseudonym,prueba, IP);
            Formulario.Invoke(Formulario.myDelegate, new Object[] { "Se envía el paquete" });
            Client.respuesta("T1", pseudonym, criputiles.Encrypt(prueba, AccesoBD.recuperamySK()), IP);
        }
コード例 #2
0
ファイル: Cliente.cs プロジェクト: CandidoCaballero/WM-VAiPho
        public void beacon()
        {
            // txtPuertoCliente.Text; //COJO LA IP DEL OTRO (PUESTA A MANO)
            string hostName = Dns.GetHostName();
            IPHostEntry thisHost = Dns.GetHostEntry(hostName);
            string thisIpAddr = thisHost.AddressList[0].ToString();//RECUPERO MI IP
            Random randomNumber = new Random(DateTime.Now.Second);
            BD DButiles = new BD(Formulario);
            /*POR AQUI DEBO GENERAR EL BEACON A ENVIAR*/
            Thread hiloCliente;// = new Thread(new ThreadStart(IniciarCliente));
            // hiloCliente.Start();

            int cambioPseu = 50 + randomNumber.Next(10);//calculamos aleatoriamente cuantos beacons enviaremos antes de hacer el cambio de pseudonimo
            int vecesPseu = 0;
            string newPseu;
            while (!Formulario.cerrar)

            {// EL BEACON SE ENVIA PERIODICAMENTE(en un rango de tiempo)
                IP = IPAddress.Broadcast.ToString();//"192.168.1.255";//txtIpCliente.Text; //BROADCAST
                puerto = "9050";
                //msj = "01," + thisIpAddr + "," + "PSEU1,"+DateTime.Now.ToString()+", Ek1(ID1:KUid1:TimeStamp)";//";// +generaHash();//txtSmsCliente.Text;

                msj = "01," + Server.myPseudonimo + "," + DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss") +", Ek1(ID1:KUid1:TimeStamp)";//";// +generaHash();//txtSmsCliente.Text;

                hiloCliente = new Thread(new ThreadStart(IniciarCliente));
                hiloCliente.Start();
                Thread.Sleep(1000 * (8 + randomNumber.Next(10)));//beacon enviado en tiempo aleatorio entre 5 y 15
                vecesPseu++;
                if (vecesPseu == cambioPseu)//cuando se alcance esta cantidad se cambia el pseudonimo
                {
                    newPseu = "pseu" + randomNumber.Next(99999);
                    Server.viejoPseu = Server.myPseudonimo;
                    msj = "01," + Server.myPseudonimo + "," + DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss") +",00," + newPseu + ", Ek1(00:TimeStamp:newPseu)";
                    hiloCliente = new Thread(new ThreadStart(IniciarCliente));
                    hiloCliente.Start();
                    DButiles.cambiamyPseu(Server.myPseudonimo, newPseu);
                    Server.myPseudonimo = DButiles.recuperamyPseu();
                    Formulario.Invoke(Formulario.myDelegate5, new Object[] { newPseu });
                    vecesPseu = 0;
                    cambioPseu = 50 + randomNumber.Next(100);
                    Thread.Sleep(1000 * (5 + randomNumber.Next(10)));
                }
            }
        }
コード例 #3
0
        /*Función que devuelve el resultado de firmar un mensaje si estamos de acuerdo con la información*/
        public void InformacionAggreacion(string msje, string IP)
        {
            //OBTIENE HORA ACTUAL
            //DateTime myDateTime = DateTime.Now;
            //ACCESO A LA BD
            string hash, viaSentido;
            BD AccesoBD = new BD(Formulario);
            string evento, posibleevento;
            Cripto criputiles = new Cripto(Formulario);
            DetectaIncidente incidente = new DetectaIncidente(Formulario);
            //Se comprueba si ya existe el incidente en las coordenadas X,Y aprox.
            evento = AccesoBD.ExisteEvento("T1", NombreVia, SentidoMarcha, CoodX, CoordY);

            Formulario.Invoke(Formulario.myDelegate, new Object[] { "¿Tengo el evento en BD? " });
            if (evento.Equals(""))
            {

                Formulario.Invoke(Formulario.myDelegate, new Object[] { "El evento no lo tengo en BD" });

                //SE VA A COMPROBAR SI SE PUEDE SER TESTIGO DE ESTE EVENTO

                //1º Obtenemos el la vía y el sentido de circulación de nuestr vehículo
                viaSentido = incidente.ViaSentidoMarcha();
                string via = "";
                string sentido = "";
                if (!viaSentido.Equals(""))
                {
                    string[] viaSentidoAux = viaSentido.Split('|');
                    via = viaSentidoAux[0];
                    sentido = viaSentidoAux[1];
                }

                //2º Si la información está dentro de mi Rango, y circulo por esa vía yo puedo detectar el problema
                if (EnRango(CoodX, CoordY, via, sentido))
                {
                    Formulario.Invoke(Formulario.myDelegate, new Object[] { "La información está dentro de mi rango" });
                    //3º Si estoy dentro del rango compruebo si detecto el problema
                    if (incidente.CompruebaIncidente())
                    {
                        Formulario.Invoke(Formulario.myDelegate, new Object[] { "Yo también detecto el incidente" });

                        Formulario.Invoke(Formulario.myDelegate, new Object[] { "¿Tengo el posible evento en PosibleEvento? " });
                        posibleevento = AccesoBD.ExistePosibleEvento("T1", NombreVia, SentidoMarcha, CoodX, CoordY);
                        if (posibleevento.Equals(""))
                        {
                            Formulario.Invoke(Formulario.myDelegate, new Object[] { "NO" });
                            Formulario.Invoke(Formulario.myDelegate, new Object[] { "Inserto PosibleEvento en BD " });
                            //Se inserta el incidente en posible Evento BD
                            AccesoBD.insertarPosibleEvento("T1", NombreVia, SentidoMarcha, CoodX, CoordY, CoordZ, HoraGeneracionPaquete, "");
                        }
                        //Firmo el paquete
                        Formulario.Invoke(Formulario.myDelegate, new Object[] { "The packet is to be signed because I can detect the incident" });
                        //Firmo la información
                        hash = FirmarMsje(msje, Server.myPseudonimo);
                        //Busco my pseudónimo
                        string myPseudonimo = AccesoBD.recuperamyPseu();
                        //Mando el mensaje  con  la Firma
                        //Nota hay que agregar el hash
                        Cliente Client = new Cliente(Formulario, "9050");
                        Formulario.Invoke(Formulario.myDelegate, new Object[] { "Send a signed packet" });
                        //Client.respuesta("T1", myPseudonimo, "F_Traffic Jam_" + NombreVia + "_" + SentidoMarcha + "_" + Server.myPseudonimo + "_" + hash + "_" + CoodX + "_" + CoordY + "_" + CoordZ, IP);
                        Client.respuesta("T1", myPseudonimo, criputiles.Encrypt("F_Traffic Jam_" + NombreVia + "_" + SentidoMarcha + "_" + Server.myPseudonimo + "_" + hash + "_" + CoodX + "_" + CoordY + "_" + CoordZ, AccesoBD.recuperamySK()), IP);

                    }//EnIF CompruebaIncidente
                    //se trata de un ataque
                    else
                    {
                        Formulario.Invoke(Formulario.myDelegate, new Object[] { "Intento de Ataque" });
                    }
                }//EndIF EnRango
                //No estoy en rango por lo que no puedo comprobar la información
                else
                {
                    Formulario.Invoke(Formulario.myDelegate, new Object[] { "La información no está en  mi rango" });
                }
            }//EndIF ExisteEvento
            //Si tengo el evento en la BD o bien yo lo detecté y envié un msje para ser firmado o ya lo firmé y recibí el agregado
            else
            {
                Formulario.Invoke(Formulario.myDelegate, new Object[] { "El evento no es nuevo, ya existe en BD" });
                /*Si estoy esperando firmas que que ya mandé el paquete agregado, */
                if (AggregarFirmas.getEsperoFirmas())
                {
                    Formulario.Invoke(Formulario.myDelegate, new Object[] { "Tambien tengo este evento en mi BD y espero firmas" });
                    // si mi evento es más antiguo que el que me llega noo
                    string[] info = evento.Split('|');
                    //Si el mio es más antiguo me quedo con el mio
                    if (DateTime.Parse(info[2]).CompareTo(HoraGeneracionPaquete) < 0)
                    {
                        Formulario.Invoke(Formulario.myDelegate, new Object[] { "La fecha en que yo creé el evento" + info[2] });
                        Formulario.Invoke(Formulario.myDelegate, new Object[] { "La fecha del evento en el paquete" + HoraGeneracionPaquete });
                        Formulario.Invoke(Formulario.myDelegate, new Object[] { "Mi evento se creó antes" });

                    }
                    //Sino, tengo que modificar el mio y quedarme con este
                    else
                    {
                        Formulario.Invoke(Formulario.myDelegate, new Object[] { "Mi evento es más viejo, lo borro de BD" });
                        //Ya no se queda a la espera de ninguna firma
                        AggregarFirmas.resetEsperoFirmas();
                        //eliminamos el evento existente
                        AccesoBD.EliminaEvento("T1", HoraGeneracionPaquete);
                        //Agregamos el nuevo evento y lo mandamos firmado
                        InformacionAggreacion(msje, IP);

                    }

                }//EndIF esperoFirmas
                //Si no espero firmas es que ya firmé
                else
                {
                    Formulario.Invoke(Formulario.myDelegate, new Object[] { "Incident already dealt" });
                }

            }
        }
コード例 #4
0
ファイル: Form1.cs プロジェクト: CandidoCaballero/WM-VAiPho
        //Iniciamos aplicacion
        private void Play_Click(object sender, EventArgs e)
        {
            progressBar1.Maximum = 7;
            progressBar1.Value = 1;
            cerrar = false;
            Invoke(myDelegate, new Object[] { "Loading... Please Wait." });
            Play.Enabled = false;//DESABILITO PLAY
            Play.Visible = false;

            //Habilitamos hardware
            Hardware detect = new Hardware();
            if (detect.BluetoothOn())//habilita bluetooth
                Invoke(myDelegate, new Object[] { "Enabled Bluetooth successfully." });
            if (detect.WifiOn())// habilita wifi
                Invoke(myDelegate, new Object[] { "Enabled Wifi successfully." });
            if (detect.conectawifi("vaipho"))//conecta a la red vaipho
                Invoke(myDelegate, new Object[] { "VAiPho conected successfully." });
            progressBar1.Value = 2;
            //Si el manos libres del coche se apaga, VAiPho se apagará también (para evitar atascos inexistentes)
            int key = (int)Registry.GetValue(registryKey, "Bluetooth", -1);
            rg = new RegistryState(registryKey, registryValueName);
            rg.Changed += new ChangeEventHandler(bluetooth_Changed);
            progressBar1.Value = 3;

            //LA CREACION DE LA BD NO SE DEBE EJECUTAR EN LA VERSIÓN FINAL
            Invoke(myDelegate, new Object[] { "Generating DB." });
            BD basededatos = new BD(this);
            //if (basededatos.crearBD())
                if (basededatos.crearTablas())
                {
                    progressBar1.Value = 4;
                    Server Servidor = new Server(this);//, 9050);
                    Cliente Cliente1 = new Cliente(this, "9050");

                    progressBar1.Value = 5;
                    string hostName = Dns.GetHostName();
                    IPHostEntry thisHost = Dns.GetHostEntry(hostName);
                    labelIP.Text = thisHost.AddressList[0].ToString();
                    labelPseu.Text = basededatos.recuperamyPseu();
                    Thread hiloCliente = new Thread(new ThreadStart(Cliente1.beacon));
                    hiloCliente.Start();
                    progressBar1.Value = 6;
                    DetectaIncidente VigilaCarretera = new DetectaIncidente(this);//Aquí dentro se lleva a cabo todo lo de detectarIncidentes
                    VigilaCarretera.DetectaIncidenteStart();
                    //VigilaCarretera.posibleparking();//señala un posible aparcamiento(al encenderse el servicio, no en el play)
                    progressBar1.Value = 7;
                    /*Prueba VigilaCarretera = new Prueba(this);
                    VigilaCarretera.DetectaIncidenteStart();*/
                }
                progressBar1.Value = 0;
        }
コード例 #5
0
ファイル: Form1.cs プロジェクト: CandidoCaballero/WM-VAiPho
        private void Form1_Load(object sender, EventArgs e)
        {
            cerrar = false;
            Play.Visible = false;
            progressBar1.Maximum = 8;
            progressBar1.Value = 1;
            Invoke(myDelegate, new Object[] { "Loading... Please Wait." });
            Play.Enabled = false;//DESABILITO PLAY

            //byte[] m_soundBytes = new byte[Properties.Resources.iniciando1.Length];
            //Properties.Resources.iniciando1.Read(m_soundBytes, 0, (int)Properties.Resources.iniciando1.Length);
              //  new System.Media.SoundPlayer(
            //System.IO.Stream stream = (System.IO.Stream)Properties.Resources.ResourceManager.BaseName. "iniciando1",false,false);
               // System.Media.SoundPlayer player = new System.Media.SoundPlayer(stream);
               //     Properties.Resources.iniciando1.Play();
            //WSounds ws1 = ;

               // string patch = System.AppDomain.CurrentDomain.BaseDirectory.ToString() BaseDirectory;// BaseDirectory;
            string _appFolder = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
            string dirSonido = _appFolder + @"\Sounds\iniciando.wav";//\Sounds\\Sonidos"\\Tarjeta de almacenamiento\\FLEET_MOBILE_14d\\MisSonidos\\iniciando.wav";//Properties.Resources.ResourceManager.BaseName+"\\// "..\\Resources\\iniciando.wav";//\\Tarjeta de almacenamiento\\FLEET_MOBILE_14d\\MisSonidos\\iniciando.wav";
            dirSonido = "\\Tarjeta de almacenamiento\\FLEET_MOBILE_14d\\MisSonidos\\iniciando.wav";

            try
            {
                WSounds ws = new WSounds();
                ws.Play(dirSonido, ws.SND_FILENAME | ws.SND_ASYNC);
            }
            catch (Exception ex)
            {
                Invoke(myDelegate, new Object[] { "Error: " + ex.Message });
            }

            Hardware detect = new Hardware();
            if (detect.BluetoothOn())//habilita bluetooth
                Invoke(myDelegate, new Object[] { "Enabled Bluetooth successfully." });
            if (detect.WifiOn())// habilita wifi
                Invoke(myDelegate, new Object[] { "Enabled Wifi successfully." });
            if (detect.conectawifi("vaipho"))//conecta a la red vaipho
                Invoke(myDelegate, new Object[] { "VAiPho connected successfully." });
            progressBar1.Value = 2;

            //Si el manos libres del coche se apaga, VAiPho se apagará también (para evitar atascos inexistentes)
            int key = (int)Registry.GetValue(registryKey, "Bluetooth", -1);
            rg = new RegistryState(registryKey, registryValueName);
            rg.Changed += new ChangeEventHandler(bluetooth_Changed);

            progressBar1.Value = 3;
            //LA CREACION DE LA BD NO SE DEBE EJECUTAR EN LA VERSIÓN FINAL
            Invoke(myDelegate, new Object[] { "Generating DB." });
            BD basededatos = new BD(this);
            progressBar1.Value = 4;
               /* if (basededatos.crearTablas())//comentar inserts en crear tablas.
            {
                basededatos.creaActualizaBD();
            }*/

            //if (basededatos.crearBD())
                if (basededatos.crearTablas())
                {
                    progressBar1.Value = 5;
                    Server Servidor = new Server(this);//, 9050);
                    Cliente Cliente1 = new Cliente(this, "9050");
                    string hostName = Dns.GetHostName();
                    progressBar1.Value = 6;
                    IPHostEntry thisHost = Dns.GetHostEntry(hostName);
                    labelPseu.Text = basededatos.recuperamyPseu();
                    labelIP.Text = thisHost.AddressList[0].ToString();
                    labelPseu.Text = basededatos.recuperamyPseu();
                    Thread hiloCliente = new Thread(new ThreadStart(Cliente1.beacon));
                    hiloCliente.Start();
                    progressBar1.Value = 7;
                    DetectaIncidente VigilaCarretera = new DetectaIncidente(this);
                    VigilaCarretera.DetectaIncidenteStart();
                    VigilaCarretera.posibleparking();
                    progressBar1.Value = 8;
                    /*Prueba VigilaCarretera = new Prueba(this);
                    VigilaCarretera.DetectaIncidenteStart();*/
                }
                progressBar1.Value = 0;
        }