From c19a02c5663e226b6dd9f685c0f27af61c422942 Mon Sep 17 00:00:00 2001 From: defnax Date: Sun, 11 Feb 2024 12:05:30 +0100 Subject: [PATCH] file upload stats (lib) --- src/ft/ftserver.cc | 32 ++++++++++++++++++++++++++++++++ src/ft/ftserver.h | 6 ++++++ src/retroshare/rsfiles.h | 20 ++++++++++++-------- 3 files changed, 50 insertions(+), 8 deletions(-) diff --git a/src/ft/ftserver.cc b/src/ft/ftserver.cc index 29615c982..32d19f823 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,26 @@ std::error_condition ftServer::parseFilesLink( if(tft) collection = *tft; return ec; } + +uint64_t ftServer::getCumulativeUpload(RsFileHash hash) +{ + RS_STACK_MUTEX(srvMutex); + std::map::iterator it = cumulative_uploaded.find(hash) ; + if(it != cumulative_uploaded.end()) + return it->second; + return 0; +} + +uint64_t ftServer::getCumulativeUploadAll() +{ + RS_STACK_MUTEX(srvMutex); + 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 f8aa9b401..680eb9eda 100644 --- a/src/retroshare/rsfiles.h +++ b/src/retroshare/rsfiles.h @@ -180,14 +180,14 @@ const TransferRequestFlags RS_FILE_REQ_NO_SEARCH ( 0x02000000 ); // di // | RS_FILE_HINTS_NETWORK_WIDE_GROUPS | RS_FILE_HINTS_BROWSABLE_GROUPS ; enum class RsSharedDirectoriesEventCode: uint8_t { - UNKNOWN = 0x00, - STARTING_DIRECTORY_SWEEP = 0x01, // (void) - HASHING_FILE = 0x02, // mMessage: full path and hashing speed of the file being hashed - DIRECTORY_SWEEP_ENDED = 0x03, // (void) - SAVING_FILE_INDEX = 0x04, // (void) - EXTRA_LIST_FILE_ADDED = 0x05, // (void) - EXTRA_LIST_FILE_REMOVED = 0x06, // (void) - SHARED_DIRS_LIST_CHANGED = 0x07, // (void) + UNKNOWN = 0x00, + STARTING_DIRECTORY_SWEEP = 0x01, // (void) + HASHING_FILE = 0x02, // mMessage: full path and hashing speed of the file being hashed + DIRECTORY_SWEEP_ENDED = 0x03, // (void) + SAVING_FILE_INDEX = 0x04, // (void) + EXTRA_LIST_FILE_ADDED = 0x05, // (void) + EXTRA_LIST_FILE_REMOVED = 0x06, // (void) + SHARED_DIRS_LIST_CHANGED = 0x07, // (void) }; enum class RsFileTransferEventCode: uint8_t { @@ -1114,5 +1114,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; };