Example #1
0
 public void ProcessFileRequest(byte[] packet)
 {
     #if VERBOSE
     CKernel.LogClient.AddLog("ProcessFileRequest",m_ID);
     #endif
     CFileRequest fileRequest=new CFileRequest(new MemoryStream(packet));
     if (fileRequest.FileHash==null)
     return;
     m_UpFileHash=fileRequest.FileHash;
     byte[] tmp_UploadFileHash=fileRequest.FileHash;
     m_UploadElement=(CElement)CKernel.FilesList[m_UpFileHash];
     CElement tmpUploadElement=m_UploadElement;
     if ((m_UploadElement==null)||(m_UploadElement.File.Empty))
     {
     /*  Dont need to send no file found,we have sent it already in ProcessRequestFileID
     *   MemoryStream buffer=new MemoryStream();
     *   CNoFile noFile=new CNoFile(buffer,m_UpFileHash);
     *   m_UpFileHash=null;
     *   m_UploadElement=null;
     *   if (connection!=null) connection.SendPacket(buffer);
     */
     }
     else
     {
     #if VERBOSE
     CKernel.LogClient.AddLog("ProcessFileRequest-send file info",m_ID);
     #endif
     m_UploadElement.Statistics.IncSessionRequests();
     if ((fileRequest.Partes!=null)
             &&(fileRequest.Partes.Length==m_UploadElement.File.NumChunks))
     {
         m_UpFileChunks=fileRequest.Partes;
     }
     MemoryStream fileInfoPacket=new MemoryStream();
     CFileInfo fileInfo=new CFileInfo(m_UpFileHash,m_UploadElement.File.FileName,fileInfoPacket);
     if (connection!=null)
     {
         connection.SendPacket(fileInfoPacket);
     }
     m_SendComment();
     }
     // it can be a new source for downloads
     if ((tmpUploadElement!=null)
         &&(tmpUploadElement.SourcesList!=null)
         &&(!tmpUploadElement.File.Completed)
         &&(tmpUploadElement.File.FileStatus==Protocol.FileState.Ready))
     {
     if (DownFileHash==null)
     {
     #if VERBOSE
         CKernel.LogClient.AddLog("ProcessFileRequest-add client to downloads",m_ID);
     #endif
         DownFileHash=new byte[16];
         Buffer.BlockCopy(tmpUploadElement.File.FileHash,0,DownFileHash,0,16);
         m_DownloadElement=tmpUploadElement;
         m_DownloadState=Protocol.DownloadState.Connected;
         if (tmpUploadElement.SourcesList.AddSource(this))
         {
             TryDownload();
         }
         else
         {
             m_DownloadState=Protocol.DownloadState.None;
         }
     }
     else
     {
         if (!CKernel.SameHash(ref DownFileHash,ref tmpUploadElement.File.FileHash))
             AddOtherDownloadFile(CKernel.HashToString(tmp_UploadFileHash));
     }
     }
 }
Example #2
0
 public void ProcessFileInfo(byte[] packet)
 {
     #if VERBOSE
     CKernel.LogClient.AddLog("ProcessFileInfo",m_ID);
     #endif
     if (DownFileHash==null) return;
     CFileInfo fileInformation=new CFileInfo(new MemoryStream(packet));
     if (!CKernel.SameHash(ref fileInformation.FileHash,ref DownFileHash))
     {
     #if VERBOSE
     CKernel.LogClient.AddLog("ProcessFileInfo-no match hashes",m_ID);
     #endif
     // raise exception
     // m_DownloadElement.SourcesList.RemoveSource(this);
     Exception e=new Exception("File info hash!=DownFileHash");
     throw(e);
     }
     m_ClientFileName=fileInformation.ClientFileName;
 }