Esempio n. 1
0
 public void AddCachedBlock(CCmdCachedBlock cachedBlock, CClient client)
 {
     if (this.m_RuningOK)
     {
         if (client == null)
         {
             CLog.Log(Constants.Log.Verbose, "Cached block de un cliente desconocido");
         }
         if (!this.BlockFailedBefore(cachedBlock))
         {
             CCachedBlock block1 = new CCachedBlock(cachedBlock, client);
             bool         flag1  = false;
             if (block1.Element != null)
             {
                 for (int num1 = 0; num1 < this.m_PendingBlocks.Count; num1++)
                 {
                     if (((((CCachedBlock)this.m_PendingBlocks[num1]).StartOffset == block1.StartOffset) && (((CCachedBlock)this.m_PendingBlocks[num1]).EndOffset == block1.EndOffset)) && (((CCachedBlock)this.m_PendingBlocks[num1]).Key[0] == block1.Key[0]))
                     {
                         flag1 = true;
                         CLog.Log(Constants.Log.Verbose, "Cached block already added");
                         break;
                     }
                 }
                 if (!flag1)
                 {
                     this.m_PendingBlocks.Add(block1);
                 }
             }
         }
     }
 }
Esempio n. 2
0
 private bool BlockFailedBefore(CCmdCachedBlock cachedBlock)
 {
     if ((this.m_FailedWebcacheBlocks != null) && (this.m_FailedWebcacheBlocks.Count != 0))
     {
         for (int num1 = 0; num1 < this.m_FailedWebcacheBlocks.Count; num1++)
         {
             CCachedBlock block1 = (CCachedBlock)this.m_FailedWebcacheBlocks[num1];
             if (((cachedBlock.StartOffset == block1.StartOffset) && (cachedBlock.EndOffset == block1.EndOffset)) && ((cachedBlock.RemoteKey[0] == block1.Key[0]) && (cachedBlock.RemoteKey[1] == block1.Key[1])))
             {
                 CLog.Log(Constants.Log.Verbose, "Ignored previous failed block");
                 return(true);
             }
         }
     }
     return(false);
 }
Esempio n. 3
0
 // Methods
 public CWebCacheClient(CCachedBlock block) : base(CKernel.WebCache.Port, CKernel.WebCache.IP, (uint)0, (ushort)0, block.Element.File.FileHash)
 {
     if (block.Element.File == null)
     {
         this.m_Completado               = 1;
         this.m_DownloadState            = Protocol.DownloadState.None;
         this.m_WebCacheClientConnection = null;
     }
     else
     {
         this.m_CachedBlock     = block;
         this.m_Software        = 0x36;
         this.m_DownloadElement = block.Element;
         CKernel.FilesList[this.DownFileHash].SourcesList.AddSource(this, true);
         this.m_WebCacheClientConnection = new CWebCacheClientConnection(CKernel.WebCache.IP, CKernel.WebCache.Port, this);
         this.m_ARC4Encoder = new CMARC4Decoder(block.Key);
         byte[] buffer1  = this.m_ARC4Encoder.Decript(this.m_DownloadElement.File.FileHash);
         string text1    = Convert.ToBase64String(buffer1);
         char[] chArray1 = new char[1] {
             '='
         };
         text1 = text1.TrimEnd(chArray1);
         text1.Replace('/', '_');
         this.m_DownloadBlocks = new ArrayList();
         CFileBlock block1 = new CFileBlock();
         block1.start    = block.StartOffset;
         block1.end      = block.EndOffset;
         block1.FileHash = this.DownFileHash;
         block1.position = block.StartOffset;
         this.m_DownloadBlocks.Add(block1);
         this.m_Completado    = 0;
         this.m_UserName      = CKernel.WebCache.Name;
         this.m_DownloadState = Protocol.DownloadState.Downloading;
         this.m_WebCacheClientConnection.GetURL(block.HostPort, "", block.StartOffset, block.EndOffset, text1, 0);
     }
 }
Esempio n. 4
0
        private void m_Process()
        {
            CCachedBlock    block1  = null;
            CWebCacheClient client1 = null;

            while (this.m_WebCacheThread.IsAlive)
            {
                if ((this.m_PendingBlocks.Count > 0) && (block1 == null))
                {
                    block1 = (CCachedBlock)this.m_PendingBlocks[0];
                    this.m_PendingBlocks.RemoveAt(0);
                    if (block1.Element.File != null)
                    {
                        if (block1.Element.File.FileStatus == Protocol.FileState.Ready)
                        {
                            client1 = new CWebCacheClient(block1);
                        }
                        else
                        {
                            block1.Element.File.RemoveRequestedBlock(block1.RealStartOffset, block1.RealEndOffset);
                            block1 = null;
                        }
                    }
                    else
                    {
                        block1 = null;
                    }
                }
                if ((client1 != null) && client1.ConnectionEnded)
                {
                    if (client1.Success)
                    {
                        if (this.m_SuccessWebcacheBlocks == null)
                        {
                            this.m_SuccessWebcacheBlocks = new ArrayList();
                        }
                        if (this.m_SuccessWebcacheBlocks.Count > 400)
                        {
                            this.m_SuccessWebcacheBlocks.RemoveAt(0);
                        }
                        this.m_SuccessWebcacheBlocks.Add(block1);
                    }
                    else
                    {
                        if (this.m_FailedWebcacheBlocks == null)
                        {
                            this.m_FailedWebcacheBlocks = new ArrayList();
                        }
                        if (this.m_FailedWebcacheBlocks.Count > 400)
                        {
                            this.m_FailedWebcacheBlocks.RemoveAt(0);
                        }
                        block1.Element = null;
                        this.m_FailedWebcacheBlocks.Add(block1);
                    }
                    block1  = null;
                    client1 = null;
                    CLog.Log(Constants.Log.Verbose, "Cache blocks on queue: " + this.m_PendingBlocks.Count.ToString());
                }
                Thread.Sleep(100);
            }
        }