From 06653c474e5cab899ad16f35abb147a7d2df0f4d Mon Sep 17 00:00:00 2001 From: RetroPooh Date: Tue, 4 Jul 2023 18:05:01 +0300 Subject: [PATCH] file upload stats (lib) --- src/ft/ftserver.cc | 30 ++++++++++++++++++++++++++++++ src/ft/ftserver.h | 6 ++++++ src/retroshare/rsfiles.h | 4 ++++ 3 files changed, 40 insertions(+) diff --git a/src/ft/ftserver.cc b/src/ft/ftserver.cc index 29615c982..3f23bd751 100644 --- a/src/ft/ftserver.cc +++ b/src/ft/ftserver.cc @@ -1335,6 +1335,15 @@ bool ftServer::sendData(const RsPeerId& peerId, const RsFileHash& hash, uint64_t offset += chunk; tosend -= chunk; } + std::map::iterator it = cumulative_uploaded.find(hash) ; + if(it != cumulative_uploaded.end()) + { + it->second += chunksize; + } + else + { + cumulative_uploaded.insert(std::make_pair(hash,(uint64_t)chunksize)) ; + } /* clean up data */ free(data); @@ -2385,3 +2394,24 @@ std::error_condition ftServer::parseFilesLink( if(tft) collection = *tft; return ec; } + +uint64_t ftServer::getCumulativeUpload(RsFileHash hash) +{ + std::map::iterator it = cumulative_uploaded.find(hash) ; + if(it != cumulative_uploaded.end()) + return it->second; + return 0; +} + +uint64_t ftServer::getCumulativeUploadAll() +{ + uint64_t all = 0; + for(std::map::iterator it(cumulative_uploaded.begin()); it!=cumulative_uploaded.end(); ++it) + all += it->second; + return all; +} + +uint64_t ftServer::getCumulativeUploadNum() +{ + return cumulative_uploaded.size(); +} diff --git a/src/ft/ftserver.h b/src/ft/ftserver.h index 16e1641cb..56c706784 100644 --- a/src/ft/ftserver.h +++ b/src/ft/ftserver.h @@ -364,6 +364,10 @@ class ftServer : bool encryptItem(RsTurtleGenericTunnelItem *clear_item,const RsFileHash& hash,RsTurtleGenericDataItem *& encrypted_item); bool decryptItem(const RsTurtleGenericDataItem *encrypted_item, const RsFileHash& hash, RsTurtleGenericTunnelItem *&decrypted_item); + virtual uint64_t getCumulativeUpload(RsFileHash hash); + virtual uint64_t getCumulativeUploadAll(); + virtual uint64_t getCumulativeUploadNum(); + /*************** Internal Transfer Fns *************************/ virtual int tick(); @@ -422,6 +426,8 @@ class ftServer : std::map mEncryptedPeerIds ; // This map holds the hash to be used with each peer id std::map > mUploadLimitMap ; + std::map cumulative_uploaded; + /** Store search callbacks with timeout*/ RS_DEPRECATED std::map< diff --git a/src/retroshare/rsfiles.h b/src/retroshare/rsfiles.h index 7e21d2f58..85b64ba61 100644 --- a/src/retroshare/rsfiles.h +++ b/src/retroshare/rsfiles.h @@ -1113,5 +1113,9 @@ class RsFiles virtual bool ignoreDuplicates() = 0; virtual void setIgnoreDuplicates(bool ignore) = 0; + virtual uint64_t getCumulativeUpload(RsFileHash hash) = 0; + virtual uint64_t getCumulativeUploadAll() = 0; + virtual uint64_t getCumulativeUploadNum() = 0; + virtual ~RsFiles() = default; };