Example #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);
            }
        }
Example #2
0
        public void ProcessSourceRequest(byte[] packet)
        {
            #if VERBOSE
            CKernel.LogClient.AddLog("ProcessSourceRequest",m_ID);
            #endif
            MemoryStream requestBuffer=new MemoryStream(packet);
            CRequestSourceExchange requestSourceExchange=new CRequestSourceExchange(requestBuffer);

            requestBuffer.Close();
            requestBuffer=null;

            MemoryStream responsePacket=new MemoryStream();
            CSourceExchangeResponse sourceExchangeResponse=new CSourceExchangeResponse(responsePacket,requestSourceExchange.FileHash,m_ID,m_Port,m_SourceExchangeVersion);

            if (sourceExchangeResponse.nSources>0)
            {
            #if VERBOSE
                CKernel.LogClient.AddLog("Sent "+Convert.ToString(sourceExchangeResponse.nSources)+" sources\n",m_ID);
            #endif
                if (connection!=null)
                {
                    connection.SendPacket(responsePacket);
                }
            }
        }