Exemplo n.º 1
0
        //constructor to publish a list of files
        public CServerPublishFiles(MemoryStream buffer, CFilesList FilesList, uint startIndex)
        {
            DonkeyHeader header;

            LastFilePublished = startIndex;
            BinaryWriter writer = new BinaryWriter(buffer);

            header = new DonkeyHeader((byte)Protocol.ServerCommand.OfferFiles, writer);
            writer.Write((uint)FilesList.Count);
            uint nfiles    = 0;
            int  fileIndex = 0;

            foreach (CElement element in FilesList.Values)
            {
                fileIndex++;
                if (fileIndex < startIndex)
                {
                    continue;
                }
                if (m_AddFileToPacket(writer, element))
                {
                    nfiles++;
                }
                LastFilePublished++;
                if (nfiles >= 200)
                {
                    break;                              //TODO: check server soft limits
                }
            }
            header.Packetlength = (uint)writer.BaseStream.Length - header.Packetlength + 1;
            writer.Seek(0, SeekOrigin.Begin);
            header.Serialize(writer);
            writer.Write(nfiles);
            CLog.Log(Types.Constants.Log.Info, "FIL_PUBLISHED", nfiles);
        }
Exemplo n.º 2
0
        public CServerHello(MemoryStream buffer)
        {
            DonkeyHeader header;
            BinaryWriter writer = new BinaryWriter(buffer);

            header = new DonkeyHeader((byte)Protocol.ServerCommand.LoginRequest, writer);
            writer.Write(CKernel.Preferences.GetByteArray("UserHash"));
            writer.Write(CKernel.Preferences.GetUInt("ID"));
            writer.Write(CKernel.Preferences.GetUShort("TCPPort"));
            uint nParameters = 5;

            writer.Write(nParameters);
            // user
            new ParameterWriter((byte)Protocol.ClientParameter.Name, CKernel.Preferences.GetString("UserName"), writer);
            // version
            new ParameterWriter((byte)Protocol.ClientParameter.Version, Protocol.EDONKEYVERSION, writer);
            // port
            new ParameterWriter((byte)Protocol.ClientParameter.Port, (uint)CKernel.Preferences.GetUShort("TCPPort"), writer);
            // compression
            new ParameterWriter((byte)Protocol.ClientParameter.Compression, 5, writer);           //1 (supports compression) + 5 (supports alternative server ports)
            // emule version
            new ParameterWriter((byte)Protocol.ClientParameter.EmuleVersion, Protocol.EMULE_VERSION_COMPLEX, writer);

            header.Packetlength = (uint)writer.BaseStream.Length - header.Packetlength + 1;
            writer.Seek(0, SeekOrigin.Begin);
            header.Serialize(writer);
        }
Exemplo n.º 3
0
 public CCCmdCachedMultiBlockFile(ArrayList cachedBlocks, uint IPProxy, byte[] fileHash, byte[] fileStatus, MemoryStream buffer)
 {
     if ((cachedBlocks != null) && (cachedBlocks.Count != 0))
     {
         BinaryWriter writer1 = new BinaryWriter(buffer);
         DonkeyHeader header1 = new DonkeyHeader(0x21, writer1, Protocol.ProtocolType.Ant);
         this.n = 0;
         writer1.Write(this.n);
         writer1.Write(IPProxy);
         writer1.Write(fileHash);
         foreach (CCachedBlock block1 in cachedBlocks)
         {
             if (((block1.Element == null) || (block1.Element.File == null)) || !CKernel.SameHash(ref fileHash, ref block1.Element.File.FileHash))
             {
                 continue;
             }
             uint num1 = CHash.GetChunkNumberAt(block1.StartOffset);
             if (fileStatus[(int)((IntPtr)num1)] == 0)
             {
                 writer1.Write(block1.IPClient);
                 writer1.Write(block1.PortClient);
                 writer1.Write(block1.StartOffset);
                 writer1.Write(block1.EndOffset);
                 writer1.Write(block1.Key);
                 writer1.Write(block1.ID);
                 this.n = (ushort)(this.n + 1);
             }
         }
         header1.Packetlength = (((uint)writer1.BaseStream.Length) - header1.Packetlength) + 1;
         writer1.Seek(0, SeekOrigin.Begin);
         header1.Serialize(writer1);
         writer1.Write(this.n);
     }
 }
Exemplo n.º 4
0
        public CServerServerList(MemoryStream buffer)
        {
            DonkeyHeader header;
            BinaryWriter writer = new BinaryWriter(buffer);

            header = new DonkeyHeader((byte)Protocol.ServerCommand.GetServerList, writer);
            header.Packetlength = (uint)writer.BaseStream.Length - header.Packetlength + 1;
            writer.Seek(0, SeekOrigin.Begin);
            header.Serialize(writer);
        }
Exemplo n.º 5
0
        public CServerRequestCallback(uint ID, MemoryStream buffer)
        {
            DonkeyHeader header;
            BinaryWriter writer = new BinaryWriter(buffer);

            header = new DonkeyHeader((byte)Protocol.ServerCommand.CallBackRequest, writer);
            writer.Write(ID);
            header.Packetlength = (uint)writer.BaseStream.Length - header.Packetlength + 1;
            writer.Seek(0, SeekOrigin.Begin);
            header.Serialize(writer);
        }
Exemplo n.º 6
0
        public CServerAskSources(byte[] FileHash, MemoryStream buffer)
        {
            DonkeyHeader header;
            BinaryWriter writer = new BinaryWriter(buffer);

            writer.Seek(0, SeekOrigin.End);
            header = new DonkeyHeader((byte)Protocol.ServerCommand.GetSources /*,writer*/);
            header.Packetlength = 17;
            header.Serialize(writer);
            writer.Write(FileHash);
//			header.Packetlength=(uint)writer.BaseStream.Length-header.Packetlength+1;
//			writer.Seek(0,SeekOrigin.Begin);
//			header.Serialize(writer);
        }
Exemplo n.º 7
0
        //constructor to publish one file
        public CServerPublishFiles(MemoryStream buffer, CElement element)
        {
            DonkeyHeader header;
            BinaryWriter writer = new BinaryWriter(buffer);

            header = new DonkeyHeader((byte)Protocol.ServerCommand.OfferFiles, writer);
            writer.Write(1);
            m_AddFileToPacket(writer, element);
            header.Packetlength = (uint)writer.BaseStream.Length - header.Packetlength + 1;
            writer.Seek(0, SeekOrigin.Begin);
            header.Serialize(writer);
            writer.Write(1);
            CLog.Log(Types.Constants.Log.Info, "FIL_PUBLISHED", 1);
        }
Exemplo n.º 8
0
        public CServerRequestSearch(MemoryStream buffer, string searchString, bool matchAnyWords, string type, uint maxSize, uint minSize, uint avaibility, string exclude, bool esUDP)
        {
            DonkeyHeader header = new DonkeyHeader((byte)Protocol.ServerCommand.SearchRequest);
            BinaryWriter writer = new BinaryWriter(buffer);

            if (esUDP)
            {
                writer.Write((byte)Protocol.Header.eDonkey);
                //writer.Write((byte)Protocol.ServerCommandsUDP.GlobalSearchRequest);
                writer.Write((byte)Protocol.ServerCommandUDP.GlobalSearchRequest2);
            }
            else
            {
                header.Serialize(writer);
            }

            if (type == "Any")
            {
                type = "";
            }
            //header
            int parametercount = 0;           //must be written parametercount-1 parmeter headers

            if (exclude.Length > 0)
            {
                writer.Write(notParameter);
            }

            if (searchString.Length > 0)
            {
                parametercount++;
                if (parametercount > 1)
                {
                    writer.Write(andParameter);
                }
            }

            if (type.Length > 0)
            {
                parametercount++;
                if (parametercount > 1)
                {
                    writer.Write(andParameter);
                }
            }

            if (minSize > 0)
            {
                parametercount++;
                if (parametercount > 1)
                {
                    writer.Write(andParameter);
                }
            }

            if (maxSize > 0)
            {
                parametercount++;
                if (parametercount > 1)
                {
                    writer.Write(andParameter);
                }
            }

            if (avaibility > 0)
            {
                parametercount++;
                if (parametercount > 1)
                {
                    writer.Write(andParameter);
                }
            }

            //				if (extension.GetLength()>0)
            //				{
            //				parametercount++;
            //				if (parametercount>1)
            //					writer.Write(andParameter);
            //				}
            //body
            if (searchString.Length > 0)           //search a string
            {
                //writer.Write(notParameter);

                string[] list = searchString.Split(" ".ToCharArray());
                byte[]   searchbyte;
                if ((matchAnyWords) && (list.Length > 1))
                {
                    for (int i = 0; i < list.Length; i++)
                    {
                        if (i != list.Length - 1)
                        {
                            writer.Write(orParameter);
                        }
                        writer.Write(stringParameter);                         //write the parameter type
                        searchbyte = Encoding.Default.GetBytes(list[i]);
                        writer.Write((ushort)searchbyte.Length);
                        writer.Write(searchbyte);
                    }
                }
                else
                {
                    writer.Write(stringParameter);                             //write the parameter type
                    searchbyte = Encoding.Default.GetBytes(searchString);
                    writer.Write((ushort)searchbyte.Length);
                    writer.Write(searchbyte);
                }
            }

            if (type.Length > 0)
            {
                writer.Write(typeParameter);                 //write the parameter type
                byte[] searchbyte = Encoding.Default.GetBytes(type);
                writer.Write((ushort)searchbyte.Length);
                writer.Write(searchbyte);
                writer.Write(typeNemonic2);
                writer.Write(typeNemonic1);
            }

            if (minSize > 0)
            {
                writer.Write(numericParameter);              //write the parameter type
                writer.Write(minSize);                       //write the parameter
                writer.Write(minNemonic);                    //nemonic for this kind of parameter
            }

            if (maxSize > 0)
            {
                writer.Write(numericParameter);              //write the parameter type
                writer.Write(maxSize);                       //write the parameter
                writer.Write(maxNemonic);                    //nemonic for this kind of parameter
            }

            if (avaibility > 0)
            {
                writer.Write(numericParameter);              //write the parameter type
                writer.Write(avaibility);                    //write the parameter
                writer.Write(avaibilityNemonic);             //nemonic for this kind of parameter
            }

            //				if (extension.GetLength()>0)
            //				{
            //					data.Write(&stringParameter,1); //write the parameter type
            //					nSize=extension.GetLength();
            //					data.Write(&nSize,2);   //write the length
            //					formatC=extension.GetBuffer();
            //					data.Write(formatC,nSize); //write parameter
            //					data.Write(&extensionNemonic,3); //nemonic for this kind of parameter (only 3 bytes!!)
            //				}
            if (exclude.Length > 0)
            {
                writer.Write(stringParameter);                 //write the parameter type
                byte[] searchbyte2 = Encoding.Default.GetBytes(exclude);
                writer.Write((ushort)searchbyte2.Length);
                writer.Write(searchbyte2);
            }

            if (!esUDP)
            {
                header.Packetlength = (uint)writer.BaseStream.Length - header.Packetlength + 1;
                writer.Seek(0, SeekOrigin.Begin);
                header.Serialize(writer);
            }
        }
Exemplo n.º 9
0
 private bool m_ProcessReceptionStream()
 {
     if (m_HeaderPending)
     {
         if (m_ReceptionStream.Length - m_StreamPosition >= 6)
         {
             m_ReceptionStream.Seek(m_StreamPosition, SeekOrigin.Begin);
             m_DonkeyHeader = new DonkeyHeader(m_ReceptionStream);
             if ((m_DonkeyHeader.Packetlength > 200000) || ((m_DonkeyHeader.eDonkeyID != Protocol.ProtocolType.eDonkey) &&
                                                            (m_DonkeyHeader.eDonkeyID != Protocol.ProtocolType.eMule) &&
                                                            (m_DonkeyHeader.eDonkeyID != Protocol.ProtocolType.Packet)))
             {
                 OnConnectionFail((byte)Protocol.ConnectionReason.InvalidHeader);
                 return(false);
             }
             m_HeaderPending = false;
             m_ReceptionStream.Seek(0, SeekOrigin.End);
         }
     }
     if ((!m_HeaderPending) &&
         ((m_ReceptionStream.Length - m_StreamPosition) >= m_DonkeyHeader.Packetlength + 5))
     {
         m_ReceptionStream.Seek(m_StreamPosition + 6, SeekOrigin.Begin);
         byte[] paquete = new byte[m_DonkeyHeader.Packetlength - 1];
         m_ReceptionStream.Read(paquete, 0, (int)m_DonkeyHeader.Packetlength - 1);
         m_HeaderPending = true;
         if (m_DonkeyHeader.eDonkeyID == Protocol.ProtocolType.eDonkey)
         {
             ProcessDonkeyPacket(ref paquete);
         }
         else if (m_DonkeyHeader.eDonkeyID == Protocol.ProtocolType.eMule)
         {
             ProcessMulePacket(ref paquete);
         }
         else if (m_DonkeyHeader.eDonkeyID == Protocol.ProtocolType.Packet)
         {
             CReceivedCompressedBlock.Uncompress(ref paquete);
             ProcessMulePacket(ref paquete);
         }
         m_DonkeyHeader = null;
         if (m_ReceptionStream.Position == m_ReceptionStream.Length)
         {
             //m_ReceptionStream=new MemoryStream(buffSize);
             m_ReceptionStream.SetLength(0);
             m_StreamPosition = 0;
         }
         else
         {
             if (m_ReceptionStream.Length > 10240)
             {
                 byte[] tmpbuffer = new byte[m_ReceptionStream.Length - m_ReceptionStream.Position];
                 m_ReceptionStream.Read(tmpbuffer, 0, tmpbuffer.Length);
                 //						m_ReceptionStream.Close();
                 //						MemoryStream nuevoStream=new MemoryStream();
                 //						nuevoStream.Write(tmpbuffer,0,tmpbuffer.Length);
                 //						m_ReceptionStream=nuevoStream;
                 m_ReceptionStream.SetLength(0);
                 m_ReceptionStream.Write(tmpbuffer, 0, tmpbuffer.Length);
                 m_StreamPosition = 0;
                 return(true);
             }
             else
             {
                 m_StreamPosition = m_ReceptionStream.Position;
                 //m_ReceptionStream.Seek(0,SeekOrigin.End);
                 return(true);
             }
         }
     }
     if (m_ReceptionStream.Position != m_ReceptionStream.Length)
     {
         m_ReceptionStream.Seek(0, SeekOrigin.End);
     }
     return(false);
 }