コード例 #1
0
ファイル: MainForm.cs プロジェクト: 411blue/echo-backup
        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");
            */
        }
コード例 #2
0
        // After the local node receives the index file from a foreign node
        // Merge that foreign index file with the local index file, then delete the foreign index file
        public void processIndexes(string filePath)
        {
            IndexDatabase ind = new IndexDatabase();

            ind.MergeIndexFiles(filePath);

            if (System.IO.File.Exists(filePath))
            {
                try
                {
                    System.IO.File.Delete(filePath);
                }
                catch (System.IO.IOException e)
                {
                    Debug.Print(e.Message);
                }
            }
        }
コード例 #3
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);
                }
            }
        }
コード例 #4
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);
                        }
                    }
                }
            }
        }
コード例 #5
0
        protected void checkStorageThread()
        {
            if (storageThread.NumChunks() > 0)
            {
                Chunk chunk = storageThread.DequeueChunk();
                Logger.Debug("EchoBackupService:checkStorageThread Finished archiving chunk.");
                //identify host(s) to send to.
                List<GuidAndIP> gai = NetworkFunctions.GetOnlineNodesIPAddresses();
                if (gai.Count < 2)
                {
                    Logger.Warn("EchoBackupService:checkStorageThread not enough online hosts. hosts online: " + gai.Count);
                }
                //send chunk to hosts.
                List<Block> blocks = new List<Block>();
                long filesize = new FileInfo(chunk.Path()).Length;
                for (int i = 0; i < 2 && i < gai.Count; i++)
                {
                    TcpClient tc = new TcpClient(gai[i].ipAddress.ToString(), CommandServer.SERVER_PORT);
                    ClientThread ct = new ClientThread(tc, false, this.guid);
                    PushRequest pr = new PushRequest(Node.GetIPAddress(), this.guid, MiscFunctions.Next());
                    pr.Path = chunk.Path();
                    pr.FileSize = filesize;
                    pr.BackupNumber = chunk.BackupID();
                    pr.ChunkNumber = chunk.ChunkID();
                    ct.EnqueueWork(pr);
                    lock (clientThreads)
                    {
                        clientThreads.Add(ct);
                    }
                    blocks.Add(new Block(this.guid.ToString(), gai[i].guid.ToString(), "bad storage path", filesize, MiscFunctions.DBDateAndTime()));
                }
                //do something with the index so we know about this backup
                //store files in BackupIndex
                IndexDatabase idb = new IndexDatabase();
                foreach (FileInChunk fic in chunk.Files())
                {
                    BackupIndex bi = new BackupIndex();
                    string fullpath = Path.Combine(chunk.BasePath(), fic.path);
                    if (Directory.Exists(fullpath)) continue;
                    bi.backupLevel = 0;
                    bi.dateAndTime = MiscFunctions.DBDateAndTime();
                    bi.firstBlockOffset = 0;
                    bi.size = new FileInfo(fullpath).Length;
                    bi.sourceGUID = this.guid.ToString();
                    bi.sourcePath = fullpath;
                    //todo: we cannot insert multiple blocks for every file. that is what the index-to-block table is for
                    //idb.InsertIndex(bi, blocks);
                }
                //store indexes in DB

            }
            if (storageThread.NumRecoverStructs() > 0)
            {
                RecoverResult rs = storageThread.DequeueRecoverResult();
                lock (recoverResults)
                {
                    recoverResults.Enqueue(rs);
                }
            }
        }