Ver Fonte

Renamed DownloadResult::bitfieldStr to bitfield and changed its
content from hex string to raw byte string.

Tatsuhiro Tsujikawa há 14 anos atrás
pai
commit
2f59ce0048
4 ficheiros alterados com 12 adições e 12 exclusões
  1. 1 1
      src/DownloadResult.h
  2. 3 2
      src/RequestGroup.cc
  3. 3 3
      src/RequestGroupMan.cc
  4. 5 6
      src/RpcMethodImpl.cc

+ 1 - 1
src/DownloadResult.h

@@ -85,7 +85,7 @@ struct DownloadResult
 
   uint64_t uploadLength;
 
-  std::string bitfieldStr;
+  std::string bitfield;
 
   std::string infoHash;
 

+ 3 - 2
src/RequestGroup.cc

@@ -1182,8 +1182,9 @@ DownloadResultHandle RequestGroup::createDownloadResult() const
   res->uploadLength = st.getAllTimeUploadLength();
   if(pieceStorage_) {
     if(pieceStorage_->getBitfieldLength() > 0) {
-      res->bitfieldStr = util::toHex(pieceStorage_->getBitfield(),
-                                     pieceStorage_->getBitfieldLength());
+      res->bitfield = std::string(pieceStorage_->getBitfield(),
+                                  pieceStorage_->getBitfield()+
+                                  pieceStorage_->getBitfieldLength());
     }
   }
 #ifdef ENABLE_BITTORRENT

+ 3 - 3
src/RequestGroupMan.cc

@@ -692,8 +692,8 @@ void RequestGroupMan::formatDownloadResultFull
 {
   BitfieldMan bt(downloadResult->pieceLength, downloadResult->totalLength);
   bt.setBitfield(reinterpret_cast<const unsigned char*>
-                 (util::fromHex(downloadResult->bitfieldStr).data()),
-                 downloadResult->bitfieldStr.size()/2);
+                 (downloadResult->bitfield.data()),
+                 downloadResult->bitfield.size());
   bool head = true;
   const std::vector<SharedHandle<FileEntry> >& fileEntries =
     downloadResult->fileEntries;
@@ -709,7 +709,7 @@ void RequestGroupMan::formatDownloadResultFull
     } else {
       o << "   |    |           |";
     }
-    if((*i)->getLength() == 0 || downloadResult->bitfieldStr.empty()) {
+    if((*i)->getLength() == 0 || downloadResult->bitfield.empty()) {
       o << "  -|";
     } else {
       uint64_t completedLength =

+ 5 - 6
src/RpcMethodImpl.cc

@@ -607,9 +607,8 @@ void createFileEntry
  InputIterator first, InputIterator last,
  uint64_t totalLength,
  size_t pieceLength,
- const std::string& bitfieldStr)
+ const std::string& bitfield)
 {
-  std::string bitfield = util::fromHex(bitfieldStr);
   BitfieldMan bf(pieceLength, totalLength);
   bf.setBitfield(reinterpret_cast<const unsigned char*>(bitfield.data()),
                  bitfield.size());
@@ -868,7 +867,7 @@ void gatherStoppedDownload
   if(requested_key(keys, KEY_FILES)) {
     SharedHandle<List> files = List::g();
     createFileEntry(files, ds->fileEntries.begin(), ds->fileEntries.end(),
-                    ds->totalLength, ds->pieceLength, ds->bitfieldStr);
+                    ds->totalLength, ds->pieceLength, ds->bitfield);
     entryDict->put(KEY_FILES, files);
   }
   if(requested_key(keys, KEY_TOTAL_LENGTH)) {
@@ -881,8 +880,8 @@ void gatherStoppedDownload
     entryDict->put(KEY_UPLOAD_LENGTH, util::uitos(ds->uploadLength));
   }
   if(requested_key(keys, KEY_BITFIELD)) {
-    if(!ds->bitfieldStr.empty()) {
-      entryDict->put(KEY_BITFIELD, ds->bitfieldStr);
+    if(!ds->bitfield.empty()) {
+      entryDict->put(KEY_BITFIELD, util::toHex(ds->bitfield));
     }
   }
   if(requested_key(keys, KEY_DOWNLOAD_SPEED)) {
@@ -931,7 +930,7 @@ SharedHandle<ValueBase> GetFilesRpcMethod::process
              util::itos(gid).c_str()));
     } else {
       createFileEntry(files, dr->fileEntries.begin(), dr->fileEntries.end(),
-                      dr->totalLength, dr->pieceLength, dr->bitfieldStr);
+                      dr->totalLength, dr->pieceLength, dr->bitfield);
     }
   } else {
     const SharedHandle<PieceStorage>& ps = group->getPieceStorage();