diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2012-12-16 16:00:18 +0900 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2012-12-16 17:29:01 +0900 |
| commit | b9da9d4ed3ef9fe7b1488506555e3605aeb500ed (patch) | |
| tree | f2b61ce65623ec222428360fe827b2a62ab9bbae /src/RequestGroup.cc | |
| parent | 04586f50b17317ef257f6d3f81190021c93ad5ea (diff) | |
Use 64 bits random bytes as GID
This change replaces the current 64 bit sequential GID with 64 bits
random bytes GID in an attempt to support persistent GID. Internally,
the GID is stored as uint64_t. For human representation and RPC
interface, GID is represented as 16 bytes hex string. For console
readout, 16 bytes are too long, so it is abbreviated to first 6 bytes.
When querying GID in RPC calls, user can speicfy the prefix of GID as
long as the prefix is shared by more than 1 GID entries.
Diffstat (limited to 'src/RequestGroup.cc')
| -rw-r--r-- | src/RequestGroup.cc | 29 |
1 files changed, 11 insertions, 18 deletions
diff --git a/src/RequestGroup.cc b/src/RequestGroup.cc index c296c321..1776e548 100644 --- a/src/RequestGroup.cc +++ b/src/RequestGroup.cc @@ -120,10 +120,9 @@ namespace aria2 { -a2_gid_t RequestGroup::gidCounter_ = 0; - -RequestGroup::RequestGroup(const SharedHandle<Option>& option) - : gid_(newGID()), +RequestGroup::RequestGroup(const SharedHandle<GroupId>& gid, + const SharedHandle<Option>& option) + : gid_(gid), state_(STATE_WAITING), option_(option), numConcurrentCommand_(option->getAsInt(PREF_SPLIT)), @@ -244,7 +243,8 @@ SharedHandle<CheckIntegrityEntry> RequestGroup::createCheckIntegrityEntry() { downloadContext_->setChecksumVerified(true); A2_LOG_NOTICE(fmt(MSG_DOWNLOAD_ALREADY_COMPLETED, - gid_, downloadContext_->getBasePath().c_str())); + gid_->toHex().c_str(), + downloadContext_->getBasePath().c_str())); } } else { checkEntry.reset(new StreamCheckIntegrityEntry(this)); @@ -346,9 +346,9 @@ void RequestGroup::createInitialCommand btAnnouncePtr->shuffleAnnounce(); SharedHandle<BtAnnounce> btAnnounce(btAnnouncePtr); - assert(!btRegistry->get(gid_)); + assert(!btRegistry->get(gid_->getNumericId())); btRegistry->put - (gid_, SharedHandle<BtObject> + (gid_->getNumericId(), SharedHandle<BtObject> (new BtObject (downloadContext_, pieceStorage_, @@ -962,7 +962,7 @@ void RequestGroup::decreaseNumCommand() { --numCommand_; if(!numCommand_ && requestGroupMan_) { - A2_LOG_DEBUG(fmt("GID#%" PRId64 " - Request queue check", gid_)); + A2_LOG_DEBUG(fmt("GID#%s - Request queue check", gid_->toHex().c_str())); requestGroupMan_->requestQueueCheck(); } } @@ -1007,7 +1007,7 @@ void RequestGroup::setPauseRequested(bool f) void RequestGroup::releaseRuntimeResource(DownloadEngine* e) { #ifdef ENABLE_BITTORRENT - e->getBtRegistry()->remove(gid_); + e->getBtRegistry()->remove(gid_->getNumericId()); btRuntime_ = 0; peerStorage_ = 0; #endif // ENABLE_BITTORRENT @@ -1152,7 +1152,8 @@ bool RequestGroup::needsFileAllocation() const SharedHandle<DownloadResult> RequestGroup::createDownloadResult() const { - A2_LOG_DEBUG(fmt("GID#%" PRId64 " - Creating DownloadResult.", gid_)); + A2_LOG_DEBUG(fmt("GID#%s - Creating DownloadResult.", + gid_->toHex().c_str())); TransferStat st = calculateStat(); SharedHandle<DownloadResult> res(new DownloadResult()); res->gid = gid_; @@ -1298,12 +1299,4 @@ bool RequestGroup::p2pInvolved() const #endif // !ENABLE_BITTORRENT } -a2_gid_t RequestGroup::newGID() -{ - if(gidCounter_ == INT64_MAX) { - gidCounter_ = 0; - } - return ++gidCounter_; -} - } // namespace aria2 |
