Exemplo n.º 1
0
        public void AddFileFound(byte[] Hash, string name, uint size, uint avaibility, string codec, string length, uint bitrate, bool complete, uint ip, ushort port)
        {
            try
            {
                string strHash = CKernel.HashToString(Hash);

                m_sources += avaibility;
                if (ContainsKey(strHash))
                {
                    CFileFound fileFound = (CFileFound)this[strHash];
                    fileFound.UpdateFile(avaibility, name, codec, length, bitrate, complete, ip, port);
                    CKernel.SearchFileModified(fileFound, (int)CKernel.Searchs.GetKey(CKernel.Searchs.IndexOfValue(this)));
                }
                else
                {
                    CFileFound fileFound = new CFileFound(strHash, name, size, avaibility, codec, length, bitrate, complete, ip, port);
                    Add(strHash, fileFound);
                    CKernel.NewFileFound(fileFound, (int)CKernel.Searchs.GetKey(CKernel.Searchs.IndexOfValue(this)));
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("Search error");
                Debug.WriteLine(e.ToString());
                CKernel.SearchEnded((int)CKernel.Searchs.GetKey(CKernel.Searchs.IndexOfValue(this)));
            }
        }
Exemplo n.º 2
0
 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;
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Request file several sources in one TCP frame from server.
        /// </summary>
        /// <param name="FileHashes">Array with the file hashes.</param>
        public void RequestSources(ArrayList FileHashes)
        {
            MemoryStream      buffer = new MemoryStream();
            CServerAskSources RequestSources;

            foreach (byte[] FileHash in FileHashes)
            {
                RequestSources = new CServerAskSources(FileHash, buffer);
                Debug.WriteLine("Asking file " + CKernel.HashToString(FileHash));
            }
            if (m_ServerConnection != null)
            {
                m_ServerConnection.SendPacket(buffer);
            }
        }
Exemplo n.º 4
0
 public void AddClientToFile(CClient client, byte[] FileHash)
 {
     if (client.DownFileHash == null)
     {
         client.DownFileHash = FileHash;
         CKernel.FilesList.AddSource(FileHash, ref client);
     }
     else
     {
         if (CKernel.SameHash(ref FileHash, ref client.DownFileHash))
         {
             CKernel.FilesList.AddSource(FileHash, ref client);
         }
         else
         {
             client.AddOtherDownloadFile(CKernel.HashToString(FileHash));
         }
     }
 }
Exemplo n.º 5
0
        public CServerProcessSources(MemoryStream buffer, uint ServerIP, ushort ServerPort)
        {
            byte[]       FileHash;
            uint         IP;
            ushort       Port;
            byte         nSources;
            bool         moreFiles = true;
            BinaryReader reader    = new BinaryReader(buffer);

            do
            {
                FileHash = reader.ReadBytes(16);
                nSources = reader.ReadByte();
                Debug.WriteLine("Received " + nSources.ToString() + " for " + CKernel.HashToString(FileHash));
                while (nSources > 0)
                {
                    IP   = reader.ReadUInt32();
                    Port = reader.ReadUInt16();
                    nSources--;
                    CKernel.ClientsList.AddClientToFile(IP, Port, ServerIP, ServerPort, FileHash);
                }
                if ((reader.PeekChar() != 0) && (reader.PeekChar() != -1))
                {
                    if ((Protocol.ProtocolType)reader.ReadByte() != Protocol.ProtocolType.eDonkey)
                    {
                        moreFiles = false;
                    }
                    if ((reader.PeekChar() == -1) || (reader.ReadByte() != (byte)Protocol.ServerCommandUDP.GlobalFoundSources))
                    {
                        moreFiles = false;
                    }
                }
                else
                {
                    moreFiles = false;
                }
            }while (moreFiles);
            reader.Close();
            buffer.Close();
            reader = null;
            buffer = null;
        }
Exemplo n.º 6
0
        private void m_StartNextPausedFile(uint category)
        {
            CElement elementCandidate = null;

            lock (m_FileList.SyncRoot)
            {
                foreach (CElement element in m_FileList)
                {
                    if ((element.File.FileStatus == Protocol.FileState.Stopped) ||
                        (element.File.FileStatus == Protocol.FileState.Pause))
                    {
                        if (elementCandidate == null)                       //no one selected, select first
                        {
                            elementCandidate = element;
                        }
                        else if (element.File.CategoryID == category)                       //same category
                        {
                            if (elementCandidate.File.CategoryID != category)               //selected from other category
                            {
                                elementCandidate = element;
                            }
                            else if (elementCandidate.File.DownPriority < element.File.DownPriority)                           //selected from same category lower priority
                            {
                                elementCandidate = element;
                            }
                        }
                        else if ((elementCandidate.File.CategoryID != category) && (elementCandidate.File.DownPriority < element.File.DownPriority))
                        {
                            elementCandidate = element;
                        }
                    }
                }
            }
            if (elementCandidate != null)
            {
                this.ResumeFile(CKernel.HashToString(elementCandidate.File.FileHash));
            }
        }
Exemplo n.º 7
0
        public bool AddSource(CClient source)
        {
            bool notMaxSources;

            notMaxSources = (((m_Element.File != null) && (m_ArrayList.Count < m_Element.File.MaxSources)) ||
                             (RemoveNoNeededSource()));
            if ((notMaxSources) &&
                (!m_ArrayList.Contains(source)) &&
                ((source.UserID != CKernel.Preferences.GetUInt("ID")) ||
                 (source.Port != CKernel.Preferences.GetUShort("TCPPort"))))
            {
                //this is an additional check to avoid duplicated sources
                //is it really needed, does it solve the problem at 100% ?
                CClient existingSource = CKernel.GetClient(m_ArrayList, source.UserID, source.Port, source.ServerIP, source.UserHash);
                if (existingSource != null)
                {
#if DEBUG
                    //CLog.Log(Types.Constants.Log.Verbose,"Duplicated source detected: "+ source.UserName + "-" + source.UserID.ToString() + "-" + m_ArrayList.Contains(source).ToString());
#endif
                    //attach the client to the existing one
                    source = existingSource;
                    return(false);
                }
                //

                m_ArrayList.Add(source);

                CKernel.NewSource(source, CKernel.HashToString(source.DownFileHash));

                return(true);
            }
            else
            {
                CKernel.ClientsList.IsClientNeeded(source);
            }
            return(false);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Event handler for preferences class if any property was changed.
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">changed property arguments</param>
        internal void OnPropertyChanged(object sender, PropertyEventArgs e)
        {
            if (e.Key == "MaxDownloadRate")
            {
                float upRate   = Preferences.GetFloat("MaxUploadRate");
                float downRate = (float)e.NewValue;
                if (downRate < 1.0F)
                {
                    e.NewValue = 1.0F;
                }

                if ((upRate * 4.0F < downRate) && (upRate < 9))
                {
                    e.NewValue = upRate * 4.0F;
                }
                else
                {
                    // do nothing
                }
            }

            if (e.Key == "MaxUploadRate")
            {
                float upRate   = (float)e.NewValue;
                float downRate = Preferences.GetFloat("MaxDownloadRate");
                if (upRate < 1.0F)
                {
                    e.NewValue = 1.0F;
                }

                if ((upRate * 4.0F < downRate) && (upRate < 9))
                {
                    Preferences.SetProperty("MaxDownloadRate", upRate * 4.0F, false);
                }
                else
                {
                    // do nothing
                }
            }

            if (e.Key == "RemotePassword")
            {
                System.Security.Cryptography.MD5 crypto = System.Security.Cryptography.MD5.Create();
                byte [] c         = null;
                string  clearPass = (string)e.NewValue;
                c = new byte[clearPass.Length];
                for (int i = 0; i < clearPass.Length; i++)
                {
                    c[i] = System.Convert.ToByte(clearPass[i]);
                }
                byte[] res = crypto.ComputeHash(c);
                e.NewValue = CKernel.HashToString(res);
            }
            if (e.Key == "Language")
            {
                Globalization.Language = e.NewValue.ToString();
            }

            if (e.Key == "IPFilterEnabled")
            {
                bool enabled = (bool)e.NewValue;
                if (enabled)
                {
                    IPFilter = new CIPFilter();
                    IPFilter.LoadIPFilter(DllDirectory, "ipfilter.dat", 128);
                }
                else
                {
                    IPFilter = null;
                }
            }

            if (e.Key == "TCPPort")
            {
                m_PortChanged = true;
                if (e.NewValue != e.OldValue)
                {
                    CKernel.Listener.Stop();
                    CKernel.Listener = new CListener((ushort)e.NewValue);
                    CKernel.Listener.Start();
                    CKernel.ServersList.ConnectToAnyServer();                    //first call disconnects
                    CKernel.ServersList.ConnectToAnyServer();                    //secons call connects
                }
            }

            if (e.Key == "UDPPort")
            {
                if (e.NewValue != e.OldValue)
                {
                    CKernel.UDPListener.Close();
                    CKernel.UDPListener = new CUDPListener();
                    CKernel.UDPListener.Start();
                }
            }

            if (e.Key == "TempFolders")
            {
                ArrayList newFolders = new ArrayList((Array)e.NewValue);
                ArrayList oldFolders = new ArrayList((Array)e.OldValue);
                foreach (string oldfolder in (Array)e.OldValue)
                {
                    if (!newFolders.Contains(oldfolder))
                    {
                        //remove files from folder
                        CKernel.FilesList.RemoveIncompleteFolder(oldfolder);
                    }
                }
                foreach (string newfolder in (Array)e.NewValue)
                {
                    if (!oldFolders.Contains(newfolder))
                    {
                        //remove files from folderadd new temp folder
                        CKernel.FilesList.AddNewIncompleteFolder(newfolder);
                    }
                }
            }
            if (e.Key == "SharedFolders")
            {
                string sharedOld = "";
                string sharedNew = "";
                foreach (string oldfolder in (Array)e.OldValue)
                {
                    sharedOld += oldfolder;
                }
                foreach (string newfolder in (Array)e.NewValue)
                {
                    sharedNew += newfolder;
                }
                if (sharedOld != sharedNew)
                {
                    CKernel.FilesList.RefreshSharedList();
                }
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Event handler for preferences class to get the default values.
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">default property arguments</param>
        internal void OnGetDefaultProperty(object sender, PropertyDefaultArgs e)
        {
            switch (e.Key)
            {
            case "TCPPort":
                e.Value = (ushort)4662;
                break;

            case "UDPPort":
                e.Value = (ushort)4672;
                break;

            case "UseEmuleProtocol":
                e.Value = true;
                break;

            case "MaxServerFails":
                e.Value = (short)2;
                break;

            case "UserName":
                e.Value = "eAnt";
                break;

            case "AutoReconnect":
                e.Value = true;
                break;

            case "ICHEnabled":
                e.Value = true;
                break;

            case "MaxUploadRate":
                e.Value = (float)10;
                break;

            case "AutoExtendSearch":
                e.Value = true;
                break;

            case "ID":
                e.Value = (uint)0;
                break;

            case "MaxDownloadRate":
                e.Value = 55.0F;
                break;

            case "MaxConnections":
                e.Value = (int)140;
                break;

            case "QueueLength":
                e.Value = (int)200;
                break;

            case "MaxSourcesPerFile":
                e.Value = (int)900;
                break;

            case "RemoteControlEnabled":
                e.Value = false;
                break;

            case "DownloadServerMet":
                e.Value = true;
                break;

            case "ServerMetUri":
                e.Value = "http://www.salatti.net/eAnt/server/best/server.met";
                break;

            case "AllowViewShared":
                e.Value = Constants.AllowViewShared.Nobody;
                break;

            case "UserHash":
                byte[] myHash = new Byte[16];
                Random rnd    = new Random();
                rnd.NextBytes(myHash);
                // identify as eMule?
                if (Preferences.GetBool("UseEmuleProtocol", true))
                {
                    myHash[5]  = 14;
                    myHash[14] = 111;
                }
                e.Value = myHash;
                break;

            case "SharedFolders":
                string[] sharedFolders = new string[1];
                Directory.CreateDirectory(DllDirectory + "incoming");
                sharedFolders[0] = DllDirectory + "incoming";
                e.Value          = sharedFolders;
                break;

            case "TempFolders":
                string[] tempFolders = new string[1];
                Directory.CreateDirectory(DllDirectory + "temp");
                tempFolders[0] = DllDirectory + "temp";
                e.Value        = tempFolders;
                break;

            case "RemoteControlPort":
                Random rnd2 = new Random();
                e.Value = rnd2.Next(6000, 8000);
                break;

            case "RemotePassword":
                Random rnd3  = new Random();
                byte[] bPass = new byte[10];
                rnd3.NextBytes(bPass);
                e.Value = CKernel.HashToString(bPass);
                break;

            case "Language":
                e.Value = CultureInfo.CurrentCulture.Name;
                break;

            case "OSigEnabled":
                e.Value = false;
                break;

            case "UpdateServerListFromClient":
                e.Value = false;
                break;

            case "UpdateServerListFromServer":
                e.Value = true;
                break;

            case "IPFilterEnabled":
                e.Value = false;
                break;

            case "ReceiveMessageFromFriendOnly":
                e.Value = false;
                break;

            case "CompressionMethod":
                e.Value = "Zip";
                break;

            case "StartNextStoppedFile":
                e.Value = false;
                break;
            }
        }