Beispiel #1
0
        // Loop while program is running and ping trusted nodes to determine whether they are online or offline
        // When a node comes online, distribute indexes to that node
        public void BeginIndexDistribution()
        {
            DistributionDatabase ddb      = new DistributionDatabase();
            List <string>        guidList = new List <string>();
            NodeDatabase         ndb      = new NodeDatabase();
            string online  = "online";
            string offline = "offline";

            ddb.ResetStatus();

            while (distribute)
            {
                guidList = ndb.SelectGUID();

                foreach (string currentGUID in guidList)
                {
                    if (Node.GetGuid() != Guid.Parse(currentGUID))
                    {
                        Thread.Sleep(1000);
                        ddb.InsertNode(currentGUID, offline);
                        if (ndb.SelectNodeTrusted(Guid.Parse(currentGUID)) == "yes")
                        {
                            Ping pingSender = new Ping();
                            int  timeout    = 100;
                            try
                            {
                                IPAddress ip    = ndb.SelectNodeIp(Guid.Parse(currentGUID));
                                PingReply reply = pingSender.Send(ip, timeout);

                                if (reply.Status == IPStatus.Success)
                                {
                                    if (ddb.GetStatus(currentGUID) == offline)
                                    {
                                        sendIndexes(currentGUID);
                                        ddb.UpdateStatus(currentGUID, online);
                                    }
                                }
                                else
                                {
                                    ddb.UpdateStatus(currentGUID, offline);
                                }
                            }
                            catch (Exception ex)
                            {
                                Debug.Print(ex.Message);
                            }
                        }
                        else
                        {
                            ddb.UpdateStatus(currentGUID, offline);
                        }
                    }
                }
            }
        }
Beispiel #2
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);
                        }
                    }
                }
            }
        }
Beispiel #3
0
        public MainForm()
        {
            InitializeComponent();
            numUpDownMaxBackupCapacity.Value = Settings.Default.maxBackupCapacity;
            db      = new NodeDatabase();
            indexDB = new IndexDatabase();
            DataTable dt = db.GetNodes();

            dataGridViewNodeSets.DataSource = dt;

            ebic = new EBInterfaceClient();

            /*
             * dataGridViewNodeSets.Rows.Add("936DA01F-9ABD-4d9d-80C7-02AF85C822A8", "PC1", "192.168.1.1", "00-21-70-FE-23-EF", "1", "51", "89", "0", "100","yes");
             * dataGridViewNodeSets.Rows.Add("936DA01F-9ABD-4d9d-80C7-02AF85C822A8", "PC2", "192.168.1.2", "00-21-69-FE-23-AB", "32", "50", "88", "25", "75", "yes");
             * dataGridViewNodeSets.Rows.Add("936DA01F-9ABD-4d9d-80C7-02AF85C822AC", "PC3", "192.168.1.3", "00-21-69-FE-23-AC", "62", "49", "87", "50", "50", "no");
             */
        }
Beispiel #4
0
        /// <summary>
        /// Returns a list of GuidAndIP structs of the online nodes.
        /// </summary>
        /// <returns></returns>
        public static List <GuidAndIP> GetOnlineNodesIPAddresses()
        {
            Logger.Debug("NetworkFunctions:GetOnlineNodeIPAddresses");
            List <GuidAndIP> list     = new List <GuidAndIP>();
            NodeDatabase     ndb      = new NodeDatabase();
            List <string>    guidList = ndb.SelectGUID();

            foreach (string guid in guidList)
            {
                Guid parsed = Guid.Parse(guid);
                if (Node.GetGuid() != parsed && ndb.SelectNodeTrusted(parsed) == "yes")
                {
                    IPAddress ipa = ndb.SelectNodeIp(Guid.Parse(guid));
                    if (NodeOnline(ipa))
                    {
                        list.Add(new GuidAndIP(ipa, Guid.Parse(guid)));
                    }
                }
            }
            return(list);
        }
Beispiel #5
0
 // Use this for initialization
 void Start()
 {
     //GameStateMachine.currentGameMode = GameStateMachine.GameMode.multiPlayer;
     //GameStateMachine.currentGameMode = GameStateMachine.GameMode.singlePlayer;
     if (GameStateMachine.currentGameMode == GameStateMachine.GameMode.singlePlayer)
     {
         if (PlayerDatabase.players.Count == 0)
         {
             PlayerDatabase.initSingle();
         }
         GameStateMachine.initSingle();
         EnemyDatabase.init();
         NodeDatabase.init();
         loaded = true;
     }
     else if (GameStateMachine.currentGameMode == GameStateMachine.GameMode.multiPlayer)
     {
         GameStateMachine.initMulti();
         PlayerDatabase.initMulti();
         loaded = true;
     }
 }
Beispiel #6
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);
                }
            }
        }
 void OnEnable()
 {
     db = (NodeDatabase)target;
 }