Renamed DownloadResult::bitfieldStr to bitfield and changed its

content from hex string to raw byte string.
pull/2/head
Tatsuhiro Tsujikawa 2011-10-13 21:57:33 +09:00
parent 6404f119e1
commit 2f59ce0048
4 changed files with 12 additions and 12 deletions

View File

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

View File

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

View File

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

View File

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