Example #1
0
 public void ProcessOutOfParts()
 {
     #if VERBOSE
     CKernel.LogClient.AddLog("ProcessOutOfParts",m_ID);
     #endif
     //CLog.Log(Constants.Log.Verbose,"Transfer interrupted: out of parts");
     m_CleanDownloadBlocks();
     m_DownloadSpeeds.Clear();
     m_DownloadSpeed=0;
     m_DownloadState=Protocol.DownloadState.OnQueue;
     if (DownFileHash!=null)
     {
     MemoryStream responsePacket=new MemoryStream();
     CStartDownload StartDownload=new CStartDownload(responsePacket,DownFileHash);
     if (connection!=null)
     {
         connection.SendPacket(responsePacket);
     }
     }
 }
Example #2
0
 public void ProcessChunksStatus(MemoryStream packet, bool udpConnection)
 {
     #if VERBOSE
     CKernel.LogClient.AddLog("ProcessChunksStatus",m_ID);
     #endif
     if ((DownFileHash==null)||(m_DownloadElement==null)) return;
     CFileStatus fileStatus=new CFileStatus(packet,!udpConnection);
     if ((!udpConnection)&&(!CKernel.SameHash(ref DownFileHash,ref fileStatus.FileHash)))
     {
     Exception e=new Exception("Chunks status: invalid fileHash");
     throw(e);
     }
     if (!CKernel.SameHash(ref DownFileHash,ref m_DownloadElement.File.FileHash))
     {
     m_DownloadElement=CKernel.FilesList[DownFileHash];
     }
     if ((CHash.GetChunksCount(m_DownloadElement.File.FileSize)!=fileStatus.nChunks)
         && (fileStatus.nChunks!=0))
     {
     Debug.Write("Received chunks numer does not match with file chunks numer\n");
     m_DownFileChunks=null;
     }
     if (m_DownloadElement.SourcesList!=null) m_DownloadElement.SourcesList.RemoveChunksAvaibility(m_DownFileChunks);
     uint nChunks=CHash.GetChunksCount(m_DownloadElement.File.FileSize);
     if (fileStatus.Chunks==null)
     {
     if ((m_DownFileChunks==null)||(m_DownFileChunks.Length!=nChunks))
     {
         m_DownFileChunks=new byte[nChunks];
     }
     for (int i=0; i!=m_DownFileChunks.Length; i++)
     {
         m_DownFileChunks[i]=(byte)Protocol.ChunkState.Complete;
     }
     //TODO hay alguna función para hacer esto en .NET equivalente a memset?
     }
     else
     {
     if ((m_DownFileChunks==null)||(m_DownFileChunks.Length!=nChunks))
     {
         m_DownFileChunks=new byte[nChunks];
     }
     Buffer.BlockCopy(fileStatus.Chunks,0,m_DownFileChunks,0,fileStatus.Chunks.Length);
     }
     if (fileStatus.nChunks>0)
     {
     m_DownloadState=Protocol.DownloadState.NoNeededParts;
     for (int i=0; i!=m_DownFileChunks.Length; i++)
     {
         if (((Protocol.ChunkState)m_DownFileChunks[i]==Protocol.ChunkState.Complete)
                 &&((m_DownloadElement.File.ChunksStatus.Length==0)
                    ||((Protocol.ChunkState)m_DownloadElement.File.ChunksStatus[i]!=Protocol.ChunkState.Complete)))
         {
             m_DownloadState=Protocol.DownloadState.OnQueue;
             break;
         }
     }
     }
     else
     {
     m_DownloadState=Protocol.DownloadState.OnQueue;
     }
     //m_DownloadElement.SourcesList.UpdateChunksAvaibility();
     if (m_DownloadElement.SourcesList!=null) m_DownloadElement.SourcesList.AddChunksAvaibility(m_DownFileChunks);
     if (udpConnection) return;
     packet.Close();
     packet=null;
     // ver si necesitamos el hashset del fichero(si no lo tenemos aun lo pedimos)
     // CElement Element=(CElement)CKernel.FilesList[CKernel.HashToString(DownFileHash)];
     // TODO no es necesario pedir hashSets de ficheros de una única parte
     if ((m_DownloadElement.File.HashSetNeeded())&&(m_DownloadState!=Protocol.DownloadState.NoNeededParts))
     {
     #if VERBOSE
     CKernel.LogClient.AddLog("ProcesarInformacionPartesFichero-Pide HashSet",m_ID);
     #endif
     m_DownloadState=Protocol.DownloadState.ReqestHashSet;
     MemoryStream responsePacket=new MemoryStream();
     CHashSetRequest hashSet=new CHashSetRequest(DownFileHash,responsePacket);
     if (connection!=null)
     {
         connection.SendPacket(responsePacket);
     }
     }
     else
     {
     if (m_DownloadState!=Protocol.DownloadState.NoNeededParts)
     {
     #if VERBOSE
         CKernel.LogClient.AddLog("ProcesarInformacionPartesFichero-Envía IniciarDescarga",m_ID);
     #endif
         MemoryStream responsePacket=new MemoryStream();
         CStartDownload startDonwload=new CStartDownload(responsePacket,DownFileHash);
         if (connection!=null)
         {
             connection.SendPacket(responsePacket);
         }
     }
     }
 }
Example #3
0
 public void ProcessHashSet(byte[] packet)
 {
     #if VERBOSE
     CKernel.LogClient.AddLog("ProcessHashSet",m_ID);
     #endif
     if (DownFileHash==null) return;
     Debug.WriteLine("HashSet received,file "+m_DownloadElement.File.FileName+" client "+m_UserName);
     CHashSetResponse hashSetResponse;
     if (m_DownloadElement.File.HashSetNeeded())
     {
     hashSetResponse=new CHashSetResponse(new MemoryStream(packet),ref m_DownloadElement.File);
     }
     else
     {
     Debug.WriteLine("File already has hash");
     }
     m_DownloadState=Protocol.DownloadState.OnQueue;
     if (!m_DownloadElement.File.HashSetNeeded())
     {
     #if VERBOSE
     CKernel.LogClient.AddLog("ProcessHashSet-start download",m_ID);
     #endif
     MemoryStream responsePacket=new MemoryStream();
     CStartDownload startDownload=new CStartDownload(responsePacket,DownFileHash);
     if (connection!=null)
     {
         connection.SendPacket(responsePacket);
     }
     }
 }