Exemple #1
0
 private void CheckMetadata(BencodedString announce, BencodedDictionary info)
 {
     if (announce == null || info == null)
     {
         throw new TorrentException("Invalid metadata, \'announce\'/\'info\' not of expected type.");
     }
 }
Exemple #2
0
 private void CheckMetadata(BencodedString announce, BencodedDictionary info)
 {
     if (announce == null || info == null)
     {
         throw new TorrentException(string.Format("Invalid metadata, 'announce'/'info' not of expected type."));
     }
 }
Exemple #3
0
        private void LoadMetadata()
        {
            BencodedDictionary metadata = GetMetadata();

            var announce = metadata["announce"] as BencodedString;

            var info = metadata["info"] as BencodedDictionary;

            CheckMetadata(announce, info);

            var pieceLength = info["piece length"] as BencodedInteger;

            List <byte[]>    checksumList = GetRawChecksums(info, pieceLength);
            BencodedString   name         = GetNameFromInfo(info);
            List <FileEntry> decodedFiles = DecodeFiles(info, name);

            if (metadata.ContainsKey("announce-list"))
            {
                var announceList = (BencodedList)metadata["announce-list"];
                AnnounceList = DecodeAnnounceList(announceList).AsReadOnly();
            }
            AnnounceURL = announce;
            Checksums   = checksumList.AsReadOnly();
            Files       = decodedFiles.AsReadOnly();
            PieceLength = pieceLength;
            PieceCount  = Checksums.Count;
            Name        = name;
            InfoHash    = ComputeInfoHash(info);
            Announces   = CreateAnnouces(AnnounceURL, AnnounceList);
            TotalLength = Files.Sum(f => f.Length);
        }
Exemple #4
0
 public override bool Equals(object obj)
 {
     try {
         BString other = (BString)obj;
         return(BencodedString.Equals(other.BencodedString));
     }
     catch (InvalidCastException e) {
         throw new InvalidCastException(e.Message);
     }
 }
Exemple #5
0
        private List <FileEntry> DecodeFiles(BencodedDictionary info, BencodedString name)
        {
            var decodedFiles = new List <FileEntry>();

            if (info.ContainsKey("files"))
            {
                var files = info["files"] as BencodedList;
                CheckInfoFiles(files);
                foreach (BencodedDictionary file in files)
                {
                    var torrentFile = CreateTorrentFile(file);
                    decodedFiles.Add(torrentFile);
                }
            }
            else
            {
                var fileLength = info["length"] as BencodedInteger;
                CheckFileLength(fileLength);
                decodedFiles.Add(new FileEntry(name, fileLength));
            }
            return(decodedFiles);
        }
Exemple #6
0
 private List<FileEntry> DecodeFiles(BencodedDictionary info, BencodedString name)
 {
     var decodedFiles = new List<FileEntry>();
     if (info.ContainsKey("files"))
     {
         var files = info["files"] as BencodedList;
         CheckInfoFiles(files);
         foreach (BencodedDictionary file in files)
         {
             FileEntry torrentFile = CreateTorrentFile(file);
             decodedFiles.Add(torrentFile);
         }
     }
     else
     {
         var fileLength = info["length"] as BencodedInteger;
         CheckFileLength(fileLength);
         decodedFiles.Add(new FileEntry(name, fileLength));
     }
     return decodedFiles;
 }
Exemple #7
0
 private void CheckMetadata(BencodedString announce, BencodedDictionary info)
 {
     if (announce == null || info == null)
         throw new TorrentException(string.Format("Invalid metadata, 'announce'/'info' not of expected type."));
 }