Example #1
0
 public void AddSourcesToFile()
 {
     if ((Sources==null)||(Sources.Count==0)) return;
     CElement element=CKernel.FilesList[CKernel.StringToHash(this.Hash)];
     int i;
     if ((element!=null)&&(element.File.FileStatus==Protocol.FileState.Ready))
     {
         stDatosFuente[] sourcesList=new stDatosFuente[Sources.Count];
         i=0;
         foreach (uint ip in Sources.Keys)
         {
             sourcesList[i].IP=ip;
             sourcesList[i].Port=(ushort)Sources[ip];
             i++;
         }
         CKernel.ClientsList.AddClientsToFile(sourcesList,CKernel.StringToHash(this.Hash));
     }
 }
Example #2
0
 public void AddClientsToFile(stDatosFuente[] sources,byte[] FileHash)
 {
     foreach (stDatosFuente source in sources)
     {
         AddClientToFile(source.IP,source.Port,source.ServerIP,source.ServerPort,FileHash);
     }
 }
Example #3
0
        private string m_ExtractSourcesInfo(string elink)
        {
            Regex regex =
                new Regex(@"\/\|sources(?<sources>.*)\|(?<rest>.*)",
                    RegexOptions.IgnoreCase
                    | RegexOptions.Multiline
                    | RegexOptions.IgnorePatternWhitespace
                    | RegexOptions.Compiled
                );
            Match m=regex.Match(elink);
            if (m.Success)
            {
                string sources=m.Result("${sources}");
                ArrayList sourcesList=new ArrayList();
                while (sources.Length>0)
                {
                    regex=new Regex(@",(?<ip>[0-9.]+\.[0-9.]+\.[0-9.]+\.[0-9.]+):(?<port>[0-9]+)(?<sources>.*)",
                    RegexOptions.IgnoreCase
                    | RegexOptions.Multiline
                    | RegexOptions.IgnorePatternWhitespace
                    | RegexOptions.Compiled
                        );
                    m=regex.Match(sources);
                    if (m.Success)
                    {
                        stDatosFuente sourcefound=new stDatosFuente();
                        IPAddress ip = System.Net.IPAddress.Parse(m.Result("${ip}"));
                        sourcefound.IP=BitConverter.ToUInt32(ip.GetAddressBytes(),0);
                        sourcefound.Port=Convert.ToUInt16(m.Result("${port}"));
                        sourcesList.Add(sourcefound);
                        sources=m.Result("${sources}");
                    }else break;
                }
                if (sourcesList.Count>0)
                {
                    m_clients=new stDatosFuente[sourcesList.Count];
                    int i=0;
                    foreach (stDatosFuente src in sourcesList)
                    {
                        m_clients[i]=src;
                        i++;
                    }

                }
                return sources;
            }
            else return "";
        }
Example #4
0
 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);
 }