Esempio n. 1
0
        public CCrumbSetResponse(MemoryStream buffer,ref CFile File)
        {
            BinaryReader reader=new BinaryReader(buffer);
            byte[] FileHash;
            FileHash=reader.ReadBytes(16);
            if (!CKernel.SameHash(ref FileHash,ref File.FileHash)) return;
            if (reader.ReadByte()!=1)
                return;
            ArrayList NewHashSet=new ArrayList();
            ArrayList NewCrumbsHashSet=new ArrayList();
            if (reader.PeekChar()<0)
            {
                NewHashSet.Add(FileHash);
                if (File.HashSetNeeded()) File.HashSet=NewHashSet;
                NewCrumbsHashSet.Add(FileHash);
                File.CrumbsHashSet=NewHashSet;
                return;
            }
            byte[] PartialHash;
            for (int i=0;i<CHash.GetChunksCount(File.FileSize);i++)
            {
                PartialHash=reader.ReadBytes(16);
                NewHashSet.Add(PartialHash);
            }
            if (File.HashSetNeeded())
            {
                byte[] HashSetChecked=CHash.DoHashSetHash(NewHashSet);
                if (CKernel.SameHash(ref HashSetChecked,ref File.FileHash)) File.HashSet=NewHashSet;
            }
            //crumbs hashes
            if (reader.ReadByte()!=1)
                return;
            for (int i=0;i<CHash.GetCrumbsCount(File.FileSize);i++)
            {
                PartialHash=reader.ReadBytes(8);
                NewCrumbsHashSet.Add(PartialHash);
            }
            //we can not check here hashes integrity we must trust edonkey, at least we check that the number matches
            if (CHash.GetCrumbsCount(File.FileSize)!=NewCrumbsHashSet.Count) return;
            CLog.Log(Types.Constants.Log.Verbose,"crumbset ok for "+File.FileName);
            File.CrumbsHashSet=NewCrumbsHashSet;

            reader.Close();
            buffer.Close();
            reader=null;
            buffer=null;
        }
Esempio n. 2
0
 public CHashSetResponse(MemoryStream buffer,ref CFile File)
 {
     BinaryReader reader=new BinaryReader(buffer);
     byte[] FileHash;//=new byte[16];
     FileHash=reader.ReadBytes(16);
     if (!CKernel.SameHash(ref FileHash,ref File.FileHash)) return;
     ArrayList NewHashSet=new ArrayList();
     ushort nChunks=reader.ReadUInt16();
     if (nChunks==0)
     {
         NewHashSet.Add(FileHash);
         //Fichero.GetHashSet().Clear();
         //Fichero.SetHashSet(null);
         File.HashSet=NewHashSet;
     }
     else
     {
         byte[] PartialHash;//=new byte[16];
         while (nChunks>0)
         {
             PartialHash=reader.ReadBytes(16);
             NewHashSet.Add(PartialHash);
             nChunks--;
         }
         byte[] HashSetChecked=CHash.DoHashSetHash(NewHashSet);
         if (CKernel.SameHash(ref HashSetChecked,ref File.FileHash))
         {
             //Fichero.GetHashSet().Clear();
             //Fichero.SetHashSet(null);
             File.HashSet=NewHashSet;
         }
     }
     reader.Close();
     buffer.Close();
     reader=null;
     buffer=null;
 }
Esempio n. 3
0
 public CCrumbSetResponse(MemoryStream buffer,CFile File)
 {
     BinaryWriter writer=new BinaryWriter(buffer);
     DonkeyHeader header=new DonkeyHeader((byte)Protocol.ClientCommand.HashSetAnswer,writer);
     writer.Write(File.FileHash);
     writer.Write((byte)1);
     foreach (byte[] PartialHash in File.HashSet)
     {
         writer.Write(PartialHash);
     }
     writer.Write((byte)1);
     foreach (byte[] CrumbHash in File.CrumbsHashSet)
     {
         writer.Write(CrumbHash);
     }
     header.Packetlength=(uint)writer.BaseStream.Length-header.Packetlength+1;
     writer.Seek(0,SeekOrigin.Begin);
     header.Serialize(writer);
 }
Esempio n. 4
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;
     }
 }
Esempio n. 5
0
 public void LoadIncompletedFiles()
 {
     foreach (string folder in CKernel.Preferences.GetStringArray("TempFolders"))
     {
         try
         {
             string [] files=Directory.GetFiles(folder);
             foreach (string strfile in files)
             {
                 if (Path.GetExtension(strfile).Equals(".part"))
                 {
                     CFile file=new CFile(Path.GetDirectoryName(strfile),Path.GetFileName(strfile));
                     if (file.FileHash!=null) AddFile(file); //file loaded properly
                 }
             }
         }
         catch (IOException e)
         {
             // any temp directory don't exist
             Debug.Write( e.ToString() );
         }
     }
 }
Esempio n. 6
0
 public void EmptyFileToSharedFile(CFile file)
 {
     CElement Element=this[file.FileHash];
     if (Element!=null) CKernel.NewSharedFile(Element);
     //TODO publish the file on the conected server
     if (CKernel.ServersList.ActiveServer!=null) CKernel.ServersList.ActiveServer.PublishSharedFile(Element);
 }
Esempio n. 7
0
 public void AddFile(string fichero, byte[] Hash, ArrayList HashSet)
 {
     FileInfo info= new FileInfo(fichero);
     CFile Fichero=new CFile(Hash,File.GetLastWriteTime(fichero).ToUniversalTime(),Path.GetDirectoryName(fichero),Path.GetFileName(fichero),(uint)info.Length,Constants.Priority.Normal,0, HashSet,"",0);
     AddFile(Fichero);
     SaveList("");
 }
Esempio n. 8
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);
 }