From 2f59ce0048a85f45b25e65a41aa4e445fbc7e1b0 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 13 Oct 2011 21:57:33 +0900 Subject: [PATCH] Renamed DownloadResult::bitfieldStr to bitfield and changed its content from hex string to raw byte string. --- src/DownloadResult.h | 2 +- src/RequestGroup.cc | 5 +++-- src/RequestGroupMan.cc | 6 +++--- src/RpcMethodImpl.cc | 11 +++++------ 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/DownloadResult.h b/src/DownloadResult.h index 30136f53..6c80ad29 100644 --- a/src/DownloadResult.h +++ b/src/DownloadResult.h @@ -85,7 +85,7 @@ struct DownloadResult uint64_t uploadLength; - std::string bitfieldStr; + std::string bitfield; std::string infoHash; diff --git a/src/RequestGroup.cc b/src/RequestGroup.cc index cfeebb01..b0f52e1c 100644 --- a/src/RequestGroup.cc +++ b/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 diff --git a/src/RequestGroupMan.cc b/src/RequestGroupMan.cc index 72d40be4..227c4c8c 100644 --- a/src/RequestGroupMan.cc +++ b/src/RequestGroupMan.cc @@ -692,8 +692,8 @@ void RequestGroupMan::formatDownloadResultFull { BitfieldMan bt(downloadResult->pieceLength, downloadResult->totalLength); bt.setBitfield(reinterpret_cast - (util::fromHex(downloadResult->bitfieldStr).data()), - downloadResult->bitfieldStr.size()/2); + (downloadResult->bitfield.data()), + downloadResult->bitfield.size()); bool head = true; const std::vector >& 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 = diff --git a/src/RpcMethodImpl.cc b/src/RpcMethodImpl.cc index 34347538..2ddb7133 100644 --- a/src/RpcMethodImpl.cc +++ b/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(bitfield.data()), bitfield.size()); @@ -868,7 +867,7 @@ void gatherStoppedDownload if(requested_key(keys, KEY_FILES)) { SharedHandle 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 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& ps = group->getPieceStorage();