示例#1
0
 public NetworkRequest()
 {
     mySourceIPAddress = Node.GetIPAddress();
     mySequenceNumber  = new Random().Next();
     mySourceGuid      = Node.GetGuid();
 }
示例#2
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);
         }
     }
 }