示例#1
0
        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);
            //			}

            if ((m_supportsHorde)&&(m_DownloadElement.File.CrumbsHashSetNeeded()))
            {
                //packet.Seek(0,SeekOrigin.End);
                //CHordeSlotRequest HordeSlotRequest=new CHordeSlotRequest(DownFileHash,packet);
                CLog.Log(Constants.Log.Verbose,"Requesting crumhashset to "+m_UserName+" for "+m_DownloadElement.File.FileName);
                packet.Seek(0,SeekOrigin.End);
                CCrumbSetRequest CrumbSetRequest=new CCrumbSetRequest(DownFileHash,packet);
            }

            // Request sources if allowed
            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);
            }
        }
示例#2
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));
                }
            }
        }