コード例 #1
0
ファイル: SourcesList.cs プロジェクト: elnomade/hathi
 public CSourcesList(CElement in_Element)
 {
     m_ArrayList=ArrayList.Synchronized(new ArrayList());
     m_Element=in_Element;
     m_Avaibility=null;
     Random rnd=new Random();
     m_LastTCPSearch=DateTime.MinValue; //-TimeSpan.FromSeconds(rnd.Next(60));
     m_LastSourceExchangeRequest=DateTime.MinValue;
     m_DownloadSpeed=0;
 }
コード例 #2
0
ファイル: Client.cs プロジェクト: elnomade/hathi
 public void TryUDPDownload()
 {
     m_AskingUDP=true;
     if ((m_EmuleProtocol)&&
         (m_VersionUDP>=1)&&
         (m_ID>Protocol.LowIDLimit)&&
         (m_UDPPort>0)&&
         (DownFileHash!=null)&&
         ((m_QRDownload>50)||(m_QRDownload==0))&&
         ((!m_SupportsPartner)||(!CKernel.Queue.AllowNewParner()))&&
         !m_AllowSourceExchangeRequest())
     {
     #if VERBOSE
     CKernel.LogClient.AddLog("Intentar Descarga UDP");
     #endif
     MemoryStream buffer=new MemoryStream();
     if (m_DownloadElement==null) m_DownloadElement=CKernel.FilesList[DownFileHash];
     if (m_DownloadElement==null) return;
     CFileReaskUDP PeticionUDP=new CFileReaskUDP(buffer,DownFileHash,m_VersionUDP,m_DownloadElement.File.ChunksStatus);
     IPEndPoint hostRemote=new IPEndPoint(m_ID,m_UDPPort);
     CKernel.UDPListener.SendPacketUDP(buffer.GetBuffer(),hostRemote);
     }
 }
コード例 #3
0
ファイル: Client.cs プロジェクト: elnomade/hathi
 public void SwapToOtherFile()
 {
     if ((m_OtherDownFiles==null)||(m_OtherDownFiles.Count==0))
     {
     return;
     }
     byte highestPriority=0;
     CElement tmpElement=null;
     CElement Element=null;
     int i=0;
     do
     {
     tmpElement=(CElement)CKernel.FilesList[CKernel.StringToHash(m_OtherDownFiles[i])];
     if ((tmpElement!=null)
             &&(tmpElement.SourcesList!=null)
             &&(!tmpElement.File.Completed)
             &&(tmpElement.File.FileStatus==Protocol.FileState.Ready))
     {
         if ((byte)tmpElement.File.DownPriority>=highestPriority)
         {
             Element=tmpElement;
             highestPriority=(byte)tmpElement.File.DownPriority;
         }
         i++;
     }
     else
     {
         m_OtherDownFiles.RemoveAt(i);
     }
     }
     while ((i<m_OtherDownFiles.Count)&&(m_OtherDownFiles.Count>0));
     // element selected to download
     if (Element!=null)
     {
     m_OtherDownFiles.Remove(CKernel.HashToString(Element.File.FileHash));
     DownFileHash=new byte[16];
     Buffer.BlockCopy(Element.File.FileHash,0,DownFileHash,0,16);
     m_DownloadElement=Element;
     m_ClientFileName="";
     m_DownloadElement.SourcesList.AddSource(this);
     if ((connection!=null)&&connection.Connected)
     {
         m_DownloadState=Protocol.DownloadState.Connected;
         TryDownload();
     }
     else
     {
         m_DownloadState=Protocol.DownloadState.None;
     }
     }
 }
コード例 #4
0
ファイル: FilesList.cs プロジェクト: elnomade/hathi
 private void AddFile(CFile file)
 {
     if (!m_Contains(file.FileHash))
     {
     CElement Element=new CElement();
     Element.File=file;
     Element.Statistics=new CFileStatistics();
     m_FileList.Add(Element);
     if (((file.FileStatus==Protocol.FileState.Ready)||(Element.File.FileStatus==Protocol.FileState.Completing))&&(!file.Completed))
     {
         Element.SourcesList=new CSourcesList(Element);
         Element.Comments=new CedonkeyComments(Element);
     }
     if (!file.Completed)
         CKernel.NewFile(Element);
     else
         CKernel.NewSharedFile(Element);
     }
     else
     {
     CLog.Log(Constants.Log.Notify, "FIL_DUP",CKernel.HashToString(file.FileHash));
     file=null;
     }
 }
コード例 #5
0
ファイル: Client.cs プロジェクト: elnomade/hathi
 public void ProcessComment(byte[] packet)
 {
     CComment commentCMD=new CComment(new MemoryStream(packet));
     m_Comment=commentCMD.comment;
     m_Rating=commentCMD.rating;
     if ((m_DownloadElement==null)&&(DownFileHash!=null))
     {
     m_DownloadElement=CKernel.FilesList[DownFileHash];
     }
     if ((m_DownloadElement!=null)&&(m_DownloadElement.Comments!=null))
     {
     m_DownloadElement.Comments.NewComment(m_UserName,m_Rating,m_Comment);
     }
 }
コード例 #6
0
ファイル: Client.cs プロジェクト: elnomade/hathi
 public void OnDisconnect(byte reason)
 {
     connection=null;
     if (m_SharedFilesRequested) CLog.Log(Constants.Log.Notify,"CLI_DONT_SEND_SHARED",m_UserName);
     m_SharedFilesRequested=false;
     #if VERBOSE
     CKernel.LogClient.AddLog("OnDisconnect-Client",m_ID);
     #endif
     #if DEBUG
     string strReason=CKernel.Globalization["UNK_REASON"];
     switch ((Protocol.ConnectionReason)reason)
     {
     case Protocol.ConnectionReason.CannotConnect:
     strReason=CKernel.Globalization["CANT_CONNECT"];
     break;
     case Protocol.ConnectionReason.ClosedConnection:
     strReason=CKernel.Globalization["CONNECTION_CLOSED"];
     break;
     case Protocol.ConnectionReason.NullPacket:
     strReason=CKernel.Globalization["NULL_PACKET"];
     break;
     case Protocol.ConnectionReason.NullID:
     strReason=CKernel.Globalization["NULL_ID"];
     break;
     case Protocol.ConnectionReason.InvalidHeader:
     strReason=CKernel.Globalization["INVALID_HEADER"];
     break;
     case Protocol.ConnectionReason.TimeOut:
     strReason=CKernel.Globalization["TIMEOUT"];
     break;
     }
     #endif
     #if VERBOSE
     CKernel.LogClient.AddLog("OnDisconnect-"+strReason,m_ID);
     #endif
     if (m_ChatMessages!=null)
     {
     m_ChatMessages.Clear();
     m_ChatMessages=null;
     }
     if (m_UploadState==Protocol.UploadState.Uploading)
     {
     CancelUploadTransfer(true);
     }
     if ((m_UploadState==Protocol.UploadState.Connecting)
         || (m_UploadState==Protocol.UploadState.WaitCallBack))
     {
     CancelUploadTransfer(false);
     }
     if ((m_DownloadState==Protocol.DownloadState.Connecting)
         ||(m_DownloadState==Protocol.DownloadState.WaitCallBack))
     {
     if ((m_ConexionTries<Protocol.ConnectionRetries)
             &&(reason==(byte)Protocol.ConnectionReason.CannotConnect))
     {
     #if DEBUG
         m_UserName=strReason;
     #endif
         Connect();
     }
     else
     {
         //quitar la fuente
         m_ConexionTries=0;
         m_DownloadState=Protocol.DownloadState.None;
         if (DownFileHash!=null)
         {
             if (m_OtherDownFiles!=null)
             {
                 m_OtherDownFiles.Clear();
             }
             m_OtherDownFiles=null;
             if (m_DownloadElement==null)
             {
                 m_DownloadElement=(CElement)CKernel.FilesList[DownFileHash];
             }
             if ((m_DownloadElement!=null)&&(m_DownloadElement.SourcesList!=null)) m_DownloadElement.SourcesList.RemoveSource(this);
         }
         else
         {
             Debug.WriteLine(m_UserName+"Never should enter here-> null DownFileHash");
         }
     #if DEBUG
         m_UserName=strReason;
     #endif
     }
     }
     if (m_DownloadState==Protocol.DownloadState.Connected)
     {
     m_DownloadState=Protocol.DownloadState.None;
     if (m_DownloadElement==null)
     {
         m_DownloadElement=(CElement)CKernel.FilesList[DownFileHash];
     }
     m_DownloadElement.SourcesList.RemoveSource(this);
     }
     //free all pending blocks
     if (m_DownloadState==Protocol.DownloadState.Downloading)
     {
     //CLog.Log(Constants.Log.Verbose,"Transfer interrrupted,reason: {0}",strReason);
     m_CleanDownloadBlocks();
     m_LastDownloadRequest=DateTime.Now;
     m_DownloadSpeeds.Clear();
     m_DownloadSpeed=0;
     m_QRDownload=0;
     m_DownloadState=Protocol.DownloadState.OnQueue;
     }
     //for eny reason some clients (edonkeys mainly) have pending blocks but their downloadstate!=Downloading
     if (m_DownloadBlocks.Count>0)
     {
     m_CleanDownloadBlocks();
     //                  Debug.WriteLine(m_DownloadState.ToString());
     //                  Debug.WriteLine("Disconnected leaving pending blocks!!!");
     }
     CKernel.ClientsList.IsClientNeeded(this);
 }
コード例 #7
0
ファイル: Client.cs プロジェクト: elnomade/hathi
 public void AddOtherDownloadFile(string strDownloadFileHash)
 {
     if (m_OtherDownFiles==null)
     {
     m_OtherDownFiles=new StringCollection();
     }
     if (!m_OtherDownFiles.Contains(strDownloadFileHash))
     {
     m_OtherDownFiles.Add(strDownloadFileHash);
     }
     //if the alternative file has higher priority then swap
     CElement newElement=CKernel.FilesList[CKernel.StringToHash(strDownloadFileHash)];
     if (m_DownloadElement==null) m_DownloadElement=CKernel.FilesList[DownFileHash];
     if ((newElement!=null)&&
         (m_DownloadElement!=null)&&
         ((byte)m_DownloadElement.File.DownPriority<(byte)newElement.File.DownPriority)&&
         ((m_DownloadState==Protocol.DownloadState.OnQueue)||(m_DownloadState==Protocol.DownloadState.None)))
     {
     string previousDownloadHash=CKernel.HashToString(m_DownloadElement.File.FileHash);
     m_DownloadElement.SourcesList.RemoveSource(this); //this will swap the source to the highest priority alternative file
     //add the previous file to the alternative files
     m_OtherDownFiles.Add(previousDownloadHash);
     }
 }
コード例 #8
0
ファイル: Client.cs プロジェクト: elnomade/hathi
 private bool m_CreateDataPackets()
 {
     CFileBlock sendBlock;
     sendBlock=(CFileBlock)m_UploadBlocks[0];
     byte[] Datos=null;
     CElement element=(CElement)CKernel.FilesList[sendBlock.FileHash];
     m_UploadElement=element;
     if (CKernel.SameHash(ref m_UpFileHash,ref sendBlock.FileHash))
     {
     Buffer.BlockCopy(sendBlock.FileHash,0,m_UpFileHash,0,16);
     }
     if ((element!=null)&&(sendBlock.end-sendBlock.start<185000))
     {
     Datos=element.File.ReadBlock(sendBlock.start,sendBlock.end-1,false);
     }
     if ((Datos==null)||(element==null))
     {
     // cancel upload
     Debug.Write("Part not found in file\n");
     CancelUploadTransfer(false);
     return false;
     }
     MemoryStream DatosStream=new MemoryStream(Datos);
     //if you uncoment this upload compression will be enabled (not so tested)
     //if (bEsMula)
     //{
     //  CCompressedBlockSend EnvioBloque=new CCompressedBlockSend(Datos,sendBlock.inicio,sendBlock.fin,sendBlock.FileHash,ref m_UploadDataPackets);
     //}
     //else
     //{
     CSendBlock EnvioBloque=new CSendBlock(DatosStream,sendBlock.start,sendBlock.end,sendBlock.FileHash,ref m_UploadDataPackets);
     //}
     Datos=null;
     m_UploadBlocks.Remove(sendBlock);
     //GC.Collect();
     return true;
 }
コード例 #9
0
ファイル: Client.cs プロジェクト: elnomade/hathi
 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));
     }
     }
 }
コード例 #10
0
ファイル: Comments.cs プロジェクト: elnomade/hathi
 public CedonkeyComments(CElement in_Element)
 {
     Element=in_Element;
 }
コード例 #11
0
ファイル: SourcesList.cs プロジェクト: elnomade/hathi
 public void Clean()
 {
     m_Element=null;
     while (m_ArrayList.Count>0)
     {
     CClient Client=(CClient)m_ArrayList[0];
     RemoveSource(Client);
     }
 }
コード例 #12
0
ファイル: Kernel.cs プロジェクト: elnomade/hathi
 internal static void RemovedSharedFile(CElement element)
 {
     InterfaceFile file=InterfaceGateway[0].FileToInterfaceFile(element);
     for (int i=0; i<=InterfaceGateway.Length-1; i++)
     {
     if (CKernel.InterfaceGateway[i]!=null)
     {
         InterfaceGateway[i].RemovedSharedFile(file);
     }
     }
 }
コード例 #13
0
ファイル: FilesList.cs プロジェクト: elnomade/hathi
 private void m_StopFile(CElement Element)
 {
     if ((Element!=null)&& (Element.SourcesList!=null))
     {
     Element.SourcesList.Clean();
     Element.SourcesList=null;
     }
 }
コード例 #14
0
ファイル: FilesList.cs プロジェクト: elnomade/hathi
 private bool m_LoadFilesFromFolder(string folder/*,bool refreshing*/)
 {
     if (!Directory.Exists(folder)) return false;
     string [] ficheros=Directory.GetFiles(folder);
     DateTime date;
     string name;
     if (m_EdonkeyHash==null) m_EdonkeyHash=new CHash();
     foreach (string file in ficheros)
     {
     // 0 Kb file are ignored, avoid a crash
     FileInfo filInfo = new FileInfo(file);
     if ((filInfo.Length == 0)||
             ((filInfo.Attributes&(FileAttributes.Hidden|FileAttributes.System))!=0)) continue;
     date=File.GetLastWriteTime(file).ToUniversalTime();
     name=Path.GetFileName(file);
     CKnownFileAttributes Atributos;
     if ((Atributos=m_IsKnown(name,date))!=null)
     {
         //if (refreshing) continue;
         if (!m_Contains(Atributos.FileHash))
         {
             CElement Element=new CElement();
             Element.File=new CFile(Atributos.FileHash,Atributos.Date,folder,name,Atributos.Size, Atributos.Priority, Atributos.Permisions, Atributos.HashSet, Atributos.Comment, Atributos.Rating);
             Element.SourcesList=null;
             Element.Statistics=new CFileStatistics();
             this.m_FileList.Add(Element);
             CKernel.NewSharedFile(Element);
         }
         //if (!m_Contains(Atributos.FileHash))this.m_FileList.Add(Element);
     }
     else //new file
     {
         m_EdonkeyHash.AddFile(file);
     }
     }
     return true;
 }
コード例 #15
0
ファイル: Client.cs プロジェクト: elnomade/hathi
 private void InitializeClient(ushort in_Port,uint in_IP,uint in_ServerIP,ushort in_ServerPort,byte[] in_DownFileHash)
 {
     m_Port=in_Port;
     m_strIP=in_IP.ToString();
     m_ID=in_IP;
     m_ServerIP=in_ServerIP;
     m_ServerPort=in_ServerPort;
     m_ClientFileName="";
     m_LastDownloadRequest=DateTime.MinValue;
     m_LastSourcesRequest=DateTime.MinValue;
     m_SourceExchangeVersion=1;
     m_DownloadTries=0;
     m_Software=(byte)Protocol.Client.Unknown;
     if (in_DownFileHash!=null)
     {
     DownFileHash=in_DownFileHash;
     }
     else
     {
     DownFileHash=null;
     }
     m_DownloadState=Protocol.DownloadState.None;
     m_UploadState=Protocol.UploadState.None;
     m_UploadBlocks=new ArrayList();
     m_UploadDataPackets=new ArrayList();
     m_DownloadBlocks=new ArrayList();
     m_UploadElement=null;
     m_ConexionTries=0;
     #if DEBUG
     IPAddress DirectionIP=new IPAddress(in_IP);
     m_UserName=DirectionIP.ToString()+":"+Convert.ToString(m_Port);
     #else
     m_UserName="******";
     #endif
     m_DownloadSpeeds=new ArrayList();
     m_UploadSpeeds=new ArrayList();
     m_LastChunkRequested=-1;
     m_SentComment=false;
     m_AskingUDP=true;
     m_SharedFilesRequested=false;
     m_CallBackTime=DateTime.MinValue;
     m_FriendLevel=Types.Constants.FriendLevel.NoFriend;
     m_FirstMessage=true;
     m_IsSpammer=false;
     m_IsPartner=false;
     m_PartnerAllowed=false;
     m_SupportsPartner=false;
     m_BadPartnerTime=DateTime.MinValue;
     m_PartnerStartedTime=DateTime.MinValue;
 }
コード例 #16
0
ファイル: Client.cs プロジェクト: elnomade/hathi
 public void ProcessRequestFileID(byte[] packet)
 {
     #if VERBOSE
     CKernel.LogClient.AddLog("ProcessRequestFileID",m_ID);
     #endif
     CIDFileChange IDFileChange=new CIDFileChange(new MemoryStream(packet));
     if (!CKernel.SameHash(ref m_UpFileHash,ref IDFileChange.FileHash))
     {
     m_UpFileHash=IDFileChange.FileHash;
     m_UploadElement=(CElement)CKernel.FilesList[m_UpFileHash];
     }
     if ((m_UploadElement==null)||(m_UploadElement.File.Empty))
     {
     //Debug.Write("No se encontro fichero (Cambio ID) \n");
     MemoryStream buffer=new MemoryStream();
     CNoFile noFile=new CNoFile(buffer,m_UpFileHash);
     m_UpFileHash=null;
     if (connection!=null)
     {
         connection.SendPacket(buffer);
     }
     #if VERBOSE
     CKernel.LogClient.AddLog("ProcessRequestFileID-No found",m_ID);
     #endif
     }
     else
     {
     #if VERBOSE
     CKernel.LogClient.AddLog("ProcessRequestFileID-send file status",m_ID);
     #endif
     MemoryStream packetState=new MemoryStream();
     CFileStatus fileState;
     if (m_UploadElement.File.Completed)
     {
         fileState=new CFileStatus(m_UpFileHash,null,packetState);
     }
     else
     {
         fileState=new CFileStatus(m_UpFileHash,m_UploadElement.File.ChunksStatus,packetState);
     }
     if (connection!=null)
     {
         connection.SendPacket(packetState);
     }
     }
 }
コード例 #17
0
ファイル: Client.cs プロジェクト: elnomade/hathi
 private bool m_AllowSourceExchangeRequest()
 {
     long nextReask;
     if ((!m_EmuleProtocol)||(DownFileHash==null)) return false;
     if (m_DownloadElement==null) m_DownloadElement=CKernel.FilesList[DownFileHash];
     if ((m_DownloadElement==null)||(m_DownloadElement.SourcesList==null)) return false;
     if (DateTime.Now.Ticks-m_DownloadElement.Statistics.StartTime.Ticks<Protocol.StartUpPeriod)
     nextReask = Protocol.ReaskSourceAtStartUp;
     else
     nextReask = Protocol.ReaskSource;
     return ((DateTime.Now.Ticks-m_LastSourcesRequest.Ticks>Protocol.ReaskSameSource)
         && (DateTime.Now.Ticks-m_DownloadElement.SourcesList.GetLastSourceExchangeRequest().Ticks>nextReask)
         && (m_SourceExchangeVersion>=1)
         && (CKernel.Preferences.GetBool("UseEmuleProtocol"))
         && (CKernel.Preferences.GetInt("MaxSourcesPerFile")>m_DownloadElement.SourcesList.Count()-5));
 }
コード例 #18
0
ファイル: Client.cs プロジェクト: elnomade/hathi
 public CClient(CConnection in_connection)
 {
     connection=in_connection;
     m_UploadBlocks=new ArrayList();
     m_UploadDataPackets=new ArrayList();
     m_DownloadBlocks=new ArrayList();
     m_DownloadState=Protocol.DownloadState.None;
     m_UploadState=Protocol.UploadState.None;
     m_UploadElement=null;
     m_LastSourcesRequest=DateTime.MinValue;
     m_DownloadTries=0;
     m_ClientFileName="";
     m_Software=(byte)Protocol.Client.Unknown;
     m_DownloadSpeeds=new ArrayList();
     m_UploadSpeeds=new ArrayList();
     m_SentComment=false;
     m_LastChunkRequested=-1;
     m_AskingUDP=true;
     m_SharedFilesRequested=false;
     m_CallBackTime=DateTime.MinValue;
     m_FriendLevel=Types.Constants.FriendLevel.NoFriend;
     m_FirstMessage=true;
     m_IsSpammer=false;
     m_IsPartner=false;
     m_PartnerAllowed=false;
     m_SupportsPartner=false;
     m_BadPartnerTime=DateTime.MinValue;
     m_PartnerStartedTime=DateTime.MinValue;
 }
コード例 #19
0
ファイル: Client.cs プロジェクト: elnomade/hathi
 private void m_SendRequestFile()
 {
     #if VERBOSE
     CKernel.LogClient.AddLog("SendRequestFile",m_ID);
     #endif
     m_LastDownloadRequest=DateTime.Now;
     m_DownloadTries++;
     if (DownFileHash==null) return;
     m_DownloadElement=(CElement)CKernel.FilesList[DownFileHash];
     if (m_DownloadElement==null) return;
     MemoryStream packet=new MemoryStream();
     CFileRequest fileRequest;
     if ((m_EmuleProtocol)&&(m_VersionExtendedRequest>0))
     {
     fileRequest=new CFileRequest(DownFileHash,m_DownloadElement.File.ChunksStatus,packet);
     }
     else
     {
     fileRequest=new CFileRequest(DownFileHash,null,packet);
     }
     //          if (connection!=null)
     //          {
     //              connection.SendPacket(packet);
     //          }
     //packet=new MemoryStream();
     packet.Seek(0,SeekOrigin.End);
     CIDFileChange IDFileChange=new CIDFileChange(DownFileHash,packet);
     //          if (connection!=null)
     //          {
     //              connection.SendPacket(packet);
     //          }
     // ver si hay que pedir fuentes
     if (m_AllowSourceExchangeRequest())
     {
     #if VERBOSE
     CKernel.LogClient.AddLog("m_SendRequestFile-RequestSources",m_ID);
     #endif
     Debug.WriteLine(DateTime.Now.ToLongTimeString()+" : Requesting SourceExchange "+m_DownloadElement.File.FileName+" to "+ m_UserName+" | FileHash = "+ CKernel.HashToString(DownFileHash));
     //MemoryStream sourcesPacket=new MemoryStream();
     packet.Seek(0,SeekOrigin.End);
     CRequestSourceExchange requestSourceExchange=new CRequestSourceExchange(packet,DownFileHash);
     if (connection!=null)
     {
         m_LastSourcesRequest=DateTime.Now;
         m_DownloadElement.SourcesList.SetLastSourceExchangeRequest();
         //connection.SendPacket(sourcesPacket);
     }
     }
     if (connection!=null)
     {
     connection.SendPacket(packet);
     }
 }
コード例 #20
0
ファイル: Client.cs プロジェクト: elnomade/hathi
 public void RemoveDownload()
 {
     #if VERBOSE
     CKernel.LogClient.AddLog("RemoveDownload",m_ID);
     #endif
     if (m_DownloadState==Protocol.DownloadState.Downloading)
     {
     CancelDownloadTransfer(true);
     }
     CKernel.SourcesOld.AddClient(this);
     //          DownFileHash=null;
     //          m_DownFileChunks=null;
     m_DownloadElement=null;
     m_DownloadState=Protocol.DownloadState.None;
 }
コード例 #21
0
ファイル: Client.cs プロジェクト: elnomade/hathi
 public void FileNotFound(byte[] packet)
 {
     // delete source
     #if VERBOSE
     CKernel.LogClient.AddLog("FileNotFound",m_ID);
     #endif
     m_ClientFileName=CKernel.Globalization["FILE_NOT_FOUND"];
     Protocol.DownloadState prevState=m_DownloadState;
     m_DownloadState=Protocol.DownloadState.None;
     if (packet.Length!=16)
     {
     //raise exception
     Exception e=new Exception("Invalid packet size");
     throw(e);
     }
     if (!CKernel.SameHash(ref DownFileHash,ref packet))
     {
     DownFileHash=packet;
     }
     if ((DownFileHash!=null)&&(m_DownloadElement==null))
     {
     m_DownloadElement=(CElement)CKernel.FilesList[DownFileHash];
     }
     if ((m_DownloadElement!=null)&&(m_DownloadElement.SourcesList!=null))
     {
     if (prevState==Protocol.DownloadState.Downloading)
     {
         m_CleanDownloadBlocks();
         m_LastDownloadRequest=DateTime.Now;
         m_DownloadSpeeds.Clear();
         m_DownloadSpeed=0;
         m_QRDownload=0;
     }
     m_DownloadElement.SourcesList.RemoveSource(this);
     }
 }
コード例 #22
0
ファイル: Client.cs プロジェクト: elnomade/hathi
 public void RequestBlocks()
 {
     #if VERBOSE
     CKernel.LogClient.AddLog("RequestBlocks,download blocks.count:"+Convert.ToString(m_DownloadBlocks.Count),m_ID);
     #endif
     if (m_DownloadElement==null)
     {
     if (DownFileHash!=null)
     {
         m_DownloadElement=(CElement)CKernel.FilesList[DownFileHash];
         if ((m_DownloadElement!=null)&&(m_DownloadElement.SourcesList!=null))
         {
             m_DownloadElement.SourcesList.AddSource(this);
         }
         else
         {
             // probablemente el fichero ya se ha completado
             return;
         }
     }
     else
     {
         return;
     }
     }
     m_DownloadState=Protocol.DownloadState.Downloading;
     //CElement Element=(CElement)CKernel.FilesList[CKernel.HashToString(DownFileHash)];
     uint start=0;
     uint end=0;
     int chunk=0;
     CFileBlock[] blocks=new CFileBlock[3];
     for (uint i=0; i!=3; i++)
     {
     blocks[i]=new CFileBlock();
     //Debug.Write("LastChunk:"+m_LastChunkRequested.ToString());
     chunk=m_DownloadElement.SourcesList.SelectChunk(m_DownFileChunks,m_LastChunkRequested);
     m_LastChunkRequested=chunk;
     //Debug.WriteLine("NewChunk:"+m_LastChunkRequested.ToString());
     if (chunk>=0)
     {
         if (m_DownloadElement.File.GetNewBlockInChunk((uint)chunk,ref start,ref end))
         {
             blocks[i].start=start;
             blocks[i].end=end;
             blocks[i].FileHash=DownFileHash;
             blocks[i].position=start;
             //blocks[i].buffer=new Byte[fin+1-inicio];
             m_DownloadBlocks.Add(blocks[i]);
             if ((end==0)&&(start==0))
             {
                 Debug.WriteLine("no more blocks to request "+Convert.ToString(chunk));
             }
             else
             {
                 //Debug.WriteLine(m_UserName+", ChunksStatus = "+Convert.ToString(m_DownloadElement.File.ChunksStatus[0])/*+Convert.ToString(m_DownloadElement.File.GetChunksStatus()[1])*/);
     #if VERBOSE
                 CKernel.LogClient.AddLog("RequestBlocks-chunk requested "+Convert.ToString(chunk)+" block: "+Convert.ToString(start)+"-"+Convert.ToString(end)+"\n",m_ID);
     #endif
             }
         }
     }
     }
     if ((blocks[0].start==0)&&(blocks[0].end==0))
     {
     #if VERBOSE
     CKernel.LogClient.AddLog("RequestBlocks-first block is null,no request blocks",m_ID);
     #endif
     #if DEBUG
     Debug.WriteLine(m_UserName+" Parte: "+Convert.ToString(chunk)+" first block is null,no request blocks");
     for (int j=0; j<m_DownloadElement.File.ChunksStatus.Length; j++)
     {
         if (((m_DownloadElement.File.ChunksStatus[j]==(byte)Protocol.ChunkState.Empty)||
                 (m_DownloadElement.File.ChunksStatus[j]==(byte)Protocol.ChunkState.InProgress))&&
                 (m_DownFileChunks[j]==(byte)Protocol.ChunkState.Complete))
             Debug.WriteLine("Chunk not selected when available");
     }
     #endif
     if (m_DownloadBlocks.Count==0)
     {
         //no needed new blocks to download and nothing pending for receiving
         bool willBeChangedToOtherFile=((m_OtherDownFiles!=null)&&(m_OtherDownFiles.Count>0));
         CancelDownloadTransfer(false);
         if (!willBeChangedToOtherFile)
         {
             m_DownloadState=Protocol.DownloadState.NoNeededParts;
         }
     }
     }
     else
     {
     MemoryStream packet=new MemoryStream();
     CFileBlockRequest fileBlockRequest=new CFileBlockRequest(packet,DownFileHash,ref blocks[0],ref blocks[1],ref blocks[2]);
     if (connection!=null)
     {
         connection.SendPacket(packet);
     }
     }
 }
コード例 #23
0
ファイル: Client.cs プロジェクト: elnomade/hathi
 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);
         }
     }
     }
 }
コード例 #24
0
ファイル: Client.cs プロジェクト: elnomade/hathi
 public void SwapToHigherPriorityFile()
 {
     if ((m_OtherDownFiles==null)||
         (m_OtherDownFiles.Count==0)||
         (DownFileHash==null)||
         (m_DownloadState!=Protocol.DownloadState.OnQueue)&&(m_DownloadState!=Protocol.DownloadState.None))
     {
     return;
     }
     if (m_DownloadElement==null) m_DownloadElement=CKernel.FilesList[DownFileHash];
     if (m_DownloadElement==null) return;
     bool swapNeeded=false;
     foreach (string strFileHash in m_OtherDownFiles)
     {
     CElement newElement=CKernel.FilesList[CKernel.StringToHash(strFileHash)];
     if ((newElement!=null)&&
             ((byte)m_DownloadElement.File.DownPriority<(byte)newElement.File.DownPriority))
     {
         swapNeeded=true;
         break;
     }
     }
     if (!swapNeeded) return;
     //Debug.Write("Swapping "+this.UserName+m_DownloadElement.File.FileName);
     string previousDownloadHash=CKernel.HashToString(DownFileHash);
     m_DownloadElement.SourcesList.RemoveSource(this); //this will swap the source to the highest priority alternative file
     //add the previous file to the alternative files
     m_OtherDownFiles.Add(previousDownloadHash);
     //Debug.WriteLine(" to "+ m_DownloadElement.File.FileName);
 }
コード例 #25
0
ファイル: Server.cs プロジェクト: elnomade/hathi
 /// <summary>
 /// Publish one new shared file (only one)
 /// </summary>
 public void PublishSharedFile(CElement Element)
 {
     MemoryStream buffer=new MemoryStream();
     CServerPublishFiles ServerPublishFiles=new CServerPublishFiles(buffer, Element);
     //if server supports compression we send it compressed
     if (SupportCompression)
     {
     CCompressedPacket CompressedPacket=new CCompressedPacket(ref buffer);
     }
     if (m_ServerConnection!=null) m_ServerConnection.SendPacket(buffer);
 }
コード例 #26
0
ファイル: FilesList.cs プロジェクト: elnomade/hathi
 public void AddFile(string name, uint size, byte[] Hash, stDatosFuente[] sources)
 {
     CElement Element;
     if (this.m_Contains(Hash))
     {
     CLog.Log(Constants.Log.Notify,"FIL_DUP",name);
     Element=(CElement)this[Hash];
     }
     else
     {
     CFile file=new CFile(Hash,name,size);
     Element=new CElement();
     Element.File=file;
     Element.Statistics=new CFileStatistics();
     m_FileList.Add(Element);
     CKernel.NewFile(Element);
     CLog.Log(Constants.Log.Notify,"FIL_ADDED",name);
     }
     if ((Element.SourcesList==null)&&((Element.File.FileStatus==Protocol.FileState.Ready)||(Element.File.FileStatus==Protocol.FileState.Completing)))
     {
     CSourcesList sourcesList=new CSourcesList(Element);
     Element.SourcesList=sourcesList;
     if (CKernel.ServersList.ActiveServer!=null) CKernel.ServersList.ActiveServer.RequestSources(Element.File.FileHash);
     }
     if ((Element.SourcesList!=null)&&
         ((Element.File.FileStatus==Protocol.FileState.Ready)||(Element.File.FileStatus==Protocol.FileState.Completing))&&
         (sources!=null))
     CKernel.ClientsList.AddClientsToFile(sources,Hash);
 }