~ubuntu-branches/ubuntu/quantal/aria2/quantal

« back to all changes in this revision

Viewing changes to src/bittorrent_helper.h

  • Committer: Package Import Robot
  • Author(s): Kartik Mistry
  • Date: 2011-11-08 20:25:08 UTC
  • mfrom: (2.5.7 sid)
  • Revision ID: package-import@ubuntu.com-20111108202508-scfph8rj6tz0cckk
Tags: 1.13.0-1
* New upstream version:
  + Depends on libgcrypt11 (>= 1.5.0-3) (Closes: #642989)

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
#include "a2netcompat.h"
48
48
#include "Peer.h"
49
49
#include "ValueBase.h"
 
50
#include "util.h"
 
51
#include "DownloadContext.h"
 
52
#include "TimeA2.h"
50
53
 
51
54
namespace aria2 {
52
55
 
142
145
(std::vector<size_t>& fastSet, const std::string& ipaddr,
143
146
 size_t numPieces, const unsigned char* infoHash, size_t fastSetSize);
144
147
 
145
 
// Writes the detailed information about torrent loaded in dctx.
146
 
void print(std::ostream& o, const SharedHandle<DownloadContext>& dctx);
147
 
 
148
148
SharedHandle<TorrentAttribute> getTorrentAttrs
149
149
(const SharedHandle<DownloadContext>& dctx);
150
150
 
290
290
    {
291
291
      for(List::ValueType::const_iterator itr = peerData.begin(),
292
292
            eoi = peerData.end(); itr != eoi; ++itr) {
293
 
        const Dict* peerDict = asDict(*itr);
 
293
        const Dict* peerDict = downcast<Dict>(*itr);
294
294
        if(!peerDict) {
295
295
          continue;
296
296
        }
297
297
        static const std::string IP = "ip";
298
298
        static const std::string PORT = "port";
299
 
        const String* ip = asString(peerDict->get(IP));
300
 
        const Integer* port = asInteger(peerDict->get(PORT));
 
299
        const String* ip = downcast<String>(peerDict->get(IP));
 
300
        const Integer* port = downcast<Integer>(peerDict->get(PORT));
301
301
        if(!ip || !port || !(0 < port->i() && port->i() < 65536)) {
302
302
          continue;
303
303
        }
323
323
 
324
324
int getCompactLength(int family);
325
325
 
 
326
// Writes the detailed information about torrent loaded in dctx.
 
327
template<typename Output>
 
328
void print(Output& o, const SharedHandle<DownloadContext>& dctx)
 
329
{
 
330
  SharedHandle<TorrentAttribute> torrentAttrs = getTorrentAttrs(dctx);
 
331
  o.write("*** BitTorrent File Information ***\n");
 
332
  if(!torrentAttrs->comment.empty()) {
 
333
    o.printf("Comment: %s\n", torrentAttrs->comment.c_str());
 
334
  }
 
335
  if(torrentAttrs->creationDate) {
 
336
    o.printf("Creation Date: %s\n",
 
337
             Time(torrentAttrs->creationDate).toHTTPDate().c_str());
 
338
  }
 
339
  if(!torrentAttrs->createdBy.empty()) {
 
340
    o.printf("Created By: %s\n", torrentAttrs->createdBy.c_str());
 
341
  }
 
342
  o.printf("Mode: %s\n", torrentAttrs->mode.c_str());
 
343
  o.write("Announce:\n");
 
344
  for(std::vector<std::vector<std::string> >::const_iterator tierIter =
 
345
        torrentAttrs->announceList.begin(),
 
346
        eoi = torrentAttrs->announceList.end(); tierIter != eoi; ++tierIter) {
 
347
    for(std::vector<std::string>::const_iterator i = (*tierIter).begin(),
 
348
          eoi2 = (*tierIter).end(); i != eoi2; ++i) {
 
349
      o.printf(" %s", (*i).c_str());
 
350
    }
 
351
    o.write("\n");
 
352
  }
 
353
  o.printf("Info Hash: %s\n", util::toHex(torrentAttrs->infoHash).c_str());
 
354
  o.printf("Piece Length: %sB\n",
 
355
           util::abbrevSize(dctx->getPieceLength()).c_str());
 
356
  o.printf("The Number of Pieces: %lu\n",
 
357
           static_cast<unsigned long>(dctx->getNumPieces()));
 
358
  o.printf("Total Length: %sB (%s)\n",
 
359
           util::abbrevSize(dctx->getTotalLength()).c_str(),
 
360
           util::uitos(dctx->getTotalLength(), true).c_str());
 
361
  if(!torrentAttrs->urlList.empty()) {
 
362
    o.write("URL List:\n");
 
363
    for(std::vector<std::string>::const_iterator i =
 
364
          torrentAttrs->urlList.begin(),
 
365
          eoi = torrentAttrs->urlList.end(); i != eoi; ++i) {
 
366
      o.printf(" %s\n", (*i).c_str());
 
367
    }
 
368
  }
 
369
  o.printf("Name: %s\n", torrentAttrs->name.c_str());
 
370
  o.printf("Magnet URI: %s\n", torrent2Magnet(torrentAttrs).c_str());
 
371
  util::toStream
 
372
    (dctx->getFileEntries().begin(), dctx->getFileEntries().end(), o);
 
373
}
 
374
 
326
375
} // namespace bittorrent
327
376
 
328
377
} // namespace aria2