Beispiel #1
0
 private void m_ProcessCompressedBlock(CReceivedCompressedBlock receivedBlock)
 {
     #if VERBOSE
     CKernel.LogClient.AddLog("ProcessCompressedBlock",m_ID);
     #endif
     int blockIndex=0;
     CFileBlock block;
     CKernel.GlobalStatistics.IncSessionDown(receivedBlock.Data.Length);
     //CElement Element=(CElement)CKernel.FilesList[CKernel.HashToString(DownFileHash)];
     lock (m_DownloadBlocks)
     {
     while (blockIndex<m_DownloadBlocks.Count)
     {
         block=(CFileBlock)m_DownloadBlocks[blockIndex];
         if (block.start==receivedBlock.Start) //&&(block.end+1>=RecepcionBloque.fin))
         {
             if (block.buffer==null)
             {
                 block.buffer=new Byte[block.end+1-block.start];
             }
             block.compressed=true;
             Buffer.BlockCopy(receivedBlock.Data,0,block.buffer,(int)(block.position-block.start),receivedBlock.Data.Length);
             m_DownloadedBytes+=(uint)receivedBlock.Data.Length;
             //ActualizarVelocidadDescarga();
             block.position+=(uint)receivedBlock.Data.Length;
             if (block.position==receivedBlock.End)
             {
                 receivedBlock.Data=null;
                 receivedBlock=null;
                 int uncompressedSize=CReceivedCompressedBlock.Uncompress(ref block.buffer);
                 if (uncompressedSize==block.end-block.start+1)
                 {
                     if (!m_DownloadElement.File.WriteBlock(block.start,block.start+(uint)block.buffer.Length-1,block.buffer))
                     {
                         m_DownloadElement.File.RemoveRequestedBlock(block.start,block.end);
                         CKernel.FilesList.StopFile(m_DownloadElement.File.FileHash);
                     }
                     m_DownloadElement.Statistics.IncSessionDownload(block.end-block.start+1);
                 }
                 else
                 {
                     m_DownloadElement.File.RemoveRequestedBlock(block.start,block.end);
                     Debug.Write("Error uncompressing block,size: "+Convert.ToString(uncompressedSize));
                 }
                 block.buffer=null;
                 block=null;
                 if (m_DownloadBlocks.Count>0)
                 {
                     m_DownloadBlocks.RemoveAt(blockIndex);
                 }
                 //Debug.WriteLine(GC.GetTotalMemory(true).ToString());
                 //GC.Collect();
                 if ((m_DownloadBlocks.Count<4)
                         && (m_DownloadState==Protocol.DownloadState.Downloading))
                 {
                     RequestBlocks();
                 }
             }
             break;
         }
         blockIndex++;
     }
     //              if (blockIndex==m_DownloadBlocks.Count)
     //              {
     //                  CLog.Log(Constants.Log.Verbose,"Requested part not found");
     //              }
     }
 }
Beispiel #2
0
 public void ReceiveCompressedBlock(byte[] packet)
 {
     #if VERBOSE
     CKernel.LogClient.AddLog("RecibirBloqueComprimido",m_ID);
     #endif
     MemoryStream streamPacket=new MemoryStream(packet);
     CReceivedCompressedBlock compressedBlock=new CReceivedCompressedBlock(ref streamPacket);
     if (!CKernel.SameHash(ref DownFileHash,ref compressedBlock.FileHash))
     {
     return;
     }
     m_ProcessCompressedBlock(compressedBlock);
 }