Exemplo n.º 1
0
        // Send indexes to all trusted nodes that are online
        // For use after a backup and associated index insertion have occurred
        public void sendIndexes()
        {
            IndexDatabase idd = new IndexDatabase();

            if (!idd.TablesEmpty()) //if there are indexes to send
            {
                DistributionDatabase ddb      = new DistributionDatabase();
                List <string>        guidList = new List <string>();
                NodeDatabase         ndb      = new NodeDatabase();

                string online      = "online";
                string indexDBCopy = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + @"\indexes_" + (Properties.Settings.Default.guid).ToString() + ".s3db";

                if (System.IO.File.Exists(idd.GetPathFileName()))
                {
                    try
                    {
                        System.IO.File.Copy(idd.GetPathFileName(), indexDBCopy, true);
                    }
                    catch (System.IO.IOException e)
                    {
                        Debug.Print(e.Message);
                    }
                }

                guidList = ndb.SelectGUID();

                foreach (string currentGUID in guidList)
                {
                    if (Node.GetGuid() != Guid.Parse(currentGUID) && ddb.GetStatus(currentGUID) == online && ndb.SelectNodeTrusted(Guid.Parse(currentGUID)) == "yes")
                    {
                        Guid             myGuid    = Node.GetGuid();
                        TcpClient        tcpClient = new TcpClient((ndb.SelectNodeIp(Guid.Parse(currentGUID))).ToString(), 7890);
                        ClientThread     ct        = new ClientThread(tcpClient, false, myGuid);
                        PushIndexRequest pir       = new PushIndexRequest(indexDBCopy, new FileInfo(indexDBCopy).Length);
                        ct.EnqueueWork(pir);
                        NetworkResponse response = (NetworkResponse)ct.DequeueEvent();
                        while (ct.IsWorking())
                        {
                            Thread.Sleep(1000);
                        }
                        ct.RequestStop();
                        while (ct.IsAlive())
                        {
                            Thread.Sleep(1000);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        // Send indexes to a specific node
        // Use after a node comes online
        public void sendIndexes(string guid)
        {
            NodeDatabase  ndb = new NodeDatabase();
            IndexDatabase idd = new IndexDatabase();

            if (!idd.TablesEmpty()) //if there are indexes to send
            {
                string indexDBCopy = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + @"\indexes_" + (Properties.Settings.Default.guid).ToString() + ".s3db";

                if (System.IO.File.Exists(idd.GetPathFileName()))
                {
                    try
                    {
                        System.IO.File.Copy(idd.GetPathFileName(), indexDBCopy, true);
                    }
                    catch (System.IO.IOException e)
                    {
                        Debug.Print(e.Message);
                    }
                }

                Guid             myGuid    = Node.GetGuid();
                TcpClient        tcpClient = new TcpClient((ndb.SelectNodeIp(Guid.Parse(guid))).ToString(), 7890);
                ClientThread     ct        = new ClientThread(tcpClient, false, myGuid);
                PushIndexRequest pir       = new PushIndexRequest(indexDBCopy, new FileInfo(indexDBCopy).Length);
                ct.EnqueueWork(pir);
                NetworkResponse response = (NetworkResponse)ct.DequeueEvent();
                while (ct.IsWorking())
                {
                    Thread.Sleep(1000);
                }
                ct.RequestStop();
                while (ct.IsAlive())
                {
                    Thread.Sleep(1000);
                }
            }
        }
Exemplo n.º 3
0
 public static void testSendBackup()
 {
     string path = "C:\\Users\\James\\Desktop\\temp\\scratch 2\\How I Met Your Mother Season 06 Episode 24 - Challange Accepted.avi";
     Guid myGuid = Guid.NewGuid();
     TcpClient tcpClient = new TcpClient("172.18.9.11", 7890);
     ClientThread ct = new ClientThread(tcpClient, false, myGuid);
     PushRequest pr = new PushRequest(IPAddress.Parse(Node.GetInternetAddress()), myGuid, 777);
     pr.BackupNumber = 4;
     pr.ChunkNumber = 5;
     pr.Path = path;
     pr.FileSize = new FileInfo(path).Length;
     ct.EnqueueWork(pr);
     int x = 0;
     /*while (ct.EventCount() == 0)
     {
         x++;
         Thread.Sleep(1000);
         Print("waiting for response. " + x);
     }
     NetworkResponse response = (NetworkResponse)ct.DequeueEvent();
     Print("response: " + response.Type + " reason: " + response.Reason);*/
     while (ct.IsWorking())
     {
         x++;
         Thread.Sleep(1000);
         Print("waiting for thread to finish working. " + x);
     }
     Print("thread finished working. " + x);
     ct.RequestStop();
     Print("requested stop");
     while (ct.IsAlive())
     {
         x++;
         Thread.Sleep(1000);
         Print("waiting for thread to die. " + x);
     }
     Print("thread dead.");
     Console.WriteLine("press a key to continue");
     Console.ReadKey();
 }
Exemplo n.º 4
0
 //tests sending a QueryRequest and receiving a response
 static void testQueryRequestClient()
 {
     Guid myGuid = Guid.NewGuid();
     TcpClient tcpClient = new TcpClient("172.18.9.11", 7890);
     ClientThread ct = new ClientThread(tcpClient, false, myGuid);
     QueryRequest qr = new QueryRequest(IPAddress.Parse(Node.GetInternetAddress()), myGuid, 777);
     qr.QueryType = QueryType.Hostname;
     ct.EnqueueWork(qr);
     int x = 0;
     while (ct.EventCount() == 0)
     {
         x++;
         Thread.Sleep(1000);
         Print("waiting for response. " + x);
     }
     NetworkResponse response = (NetworkResponse) ct.DequeueEvent();
     Print("response: " + response.Type + " reason: " + response.Reason);
     ct.RequestStop();
     Print("requested stop");
     while (ct.IsAlive())
     {
         x++;
         Thread.Sleep(1000);
         Print("waiting for thread to die. " + x);
     }
     Print("thread dead.");
     Console.WriteLine("press a key to continue");
     Console.ReadKey();
 }
Exemplo n.º 5
0
        // Send indexes to a specific node
        // Use after a node comes online
        public void sendIndexes(string guid)
        {
            NodeDatabase ndb = new NodeDatabase();
            IndexDatabase idd = new IndexDatabase();
            if (!idd.TablesEmpty()) //if there are indexes to send
            {
                string indexDBCopy = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + @"\indexes_" + (Properties.Settings.Default.guid).ToString() + ".s3db";

                if (System.IO.File.Exists(idd.GetPathFileName()))
                {
                    try
                    {
                        System.IO.File.Copy(idd.GetPathFileName(), indexDBCopy, true);
                    }
                    catch (System.IO.IOException e)
                    {
                        Debug.Print(e.Message);
                    }
                }

                Guid myGuid = Node.GetGuid();
                TcpClient tcpClient = new TcpClient((ndb.SelectNodeIp(Guid.Parse(guid))).ToString(), 7890);
                ClientThread ct = new ClientThread(tcpClient, false, myGuid);
                PushIndexRequest pir = new PushIndexRequest(indexDBCopy, new FileInfo(indexDBCopy).Length);
                ct.EnqueueWork(pir);
                NetworkResponse response = (NetworkResponse)ct.DequeueEvent();
                while (ct.IsWorking())
                {
                    Thread.Sleep(1000);
                }
                ct.RequestStop();
                while (ct.IsAlive())
                {
                    Thread.Sleep(1000);
                }
            }
        }
Exemplo n.º 6
0
        // Send indexes to all trusted nodes that are online
        // For use after a backup and associated index insertion have occurred
        public void sendIndexes()
        {
            IndexDatabase idd = new IndexDatabase();
            if (!idd.TablesEmpty()) //if there are indexes to send
            {
                DistributionDatabase ddb = new DistributionDatabase();
                List<string> guidList = new List<string>();
                NodeDatabase ndb = new NodeDatabase();

                string online = "online";
                string indexDBCopy = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + @"\indexes_" + (Properties.Settings.Default.guid).ToString() + ".s3db";

                if (System.IO.File.Exists(idd.GetPathFileName()))
                {
                    try
                    {
                        System.IO.File.Copy(idd.GetPathFileName(), indexDBCopy, true);
                    }
                    catch (System.IO.IOException e)
                    {
                        Debug.Print(e.Message);
                    }
                }

                guidList = ndb.SelectGUID();

                foreach (string currentGUID in guidList)
                {
                    if (Node.GetGuid() != Guid.Parse(currentGUID) && ddb.GetStatus(currentGUID) == online && ndb.SelectNodeTrusted(Guid.Parse(currentGUID)) == "yes")
                    {
                        Guid myGuid = Node.GetGuid();
                        TcpClient tcpClient = new TcpClient((ndb.SelectNodeIp(Guid.Parse(currentGUID))).ToString(), 7890);
                        ClientThread ct = new ClientThread(tcpClient, false, myGuid);
                        PushIndexRequest pir = new PushIndexRequest(indexDBCopy, new FileInfo(indexDBCopy).Length);
                        ct.EnqueueWork(pir);
                        NetworkResponse response = (NetworkResponse)ct.DequeueEvent();
                        while (ct.IsWorking())
                        {
                            Thread.Sleep(1000);
                        }
                        ct.RequestStop();
                        while (ct.IsAlive())
                        {
                            Thread.Sleep(1000);
                        }
                    }
                }
            }
        }