From 2919058652d20b0fc6beaa6f7ecd3ee27a26bcee Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 3 Jan 2017 23:31:29 +0100 Subject: [PATCH] finished backend part for identity usage statistics --- libretroshare/src/retroshare/rsidentity.h | 17 ++++++++++++++--- libretroshare/src/services/p3gxscircles.cc | 2 +- libretroshare/src/services/p3idservice.cc | 19 ++++++++++++++----- retroshare-gui/src/gui/Identity/IdDialog.cpp | 18 ++++++++++++++---- retroshare-gui/src/gui/Identity/IdDialog.h | 1 + 5 files changed, 44 insertions(+), 13 deletions(-) diff --git a/libretroshare/src/retroshare/rsidentity.h b/libretroshare/src/retroshare/rsidentity.h index e0fdac678..ff1610d1a 100644 --- a/libretroshare/src/retroshare/rsidentity.h +++ b/libretroshare/src/retroshare/rsidentity.h @@ -195,11 +195,16 @@ public: GLOBAL_ROUTER_SIGNATURE_CHECK = 0x0a, // Global router message validation GLOBAL_ROUTER_SIGNATURE_CREATION = 0x0b, // Global router message signature GXS_TUNNEL_DH_SIGNATURE_CHECK = 0x0c, // - GXS_TUNNEL_DH_SIGNATURE_CREATION = 0x0d // + GXS_TUNNEL_DH_SIGNATURE_CREATION = 0x0d, // + IDENTITY_DATA_UPDATE = 0x0e, // Group update on that identity data. Can be avatar, name, etc. + IDENTITY_GENERIC_SIGNATURE_CHECK = 0x0f, // Any signature verified for that identity + IDENTITY_GENERIC_SIGNATURE_CREATION = 0x10, // Any signature made by that identity + IDENTITY_GENERIC_ENCRYPTION = 0x11, + IDENTITY_GENERIC_DECRYPTION = 0x12, + CIRCLE_MEMBERSHIP_CHECK = 0x13 } ; - RsIdentityUsage(uint16_t service,const RsIdentityUsage::UsageCode& code,const RsGxsGroupId& gid=RsGxsGroupId(),const RsGxsMessageId& mid=RsGxsMessageId(),uint64_t additional_id=0,const std::string& comment = std::string()) - : mServiceId(service), mUsageCode(code), mGrpId(gid), mMsgId(mid),mAdditionalId(additional_id),mComment(comment) {} + explicit RsIdentityUsage(uint16_t service,const RsIdentityUsage::UsageCode& code,const RsGxsGroupId& gid=RsGxsGroupId(),const RsGxsMessageId& mid=RsGxsMessageId(),uint64_t additional_id=0,const std::string& comment = std::string()); uint16_t mServiceId; // Id of the service using that identity UsageCode mUsageCode; // Specific code to use. Will allow forming the correct translated message in the GUI if necessary. @@ -208,6 +213,12 @@ public: RsGxsMessageId mMsgId; // Message ID using the identity uint64_t mAdditionalId; // Some additional ID. Can be used for e.g. chat lobbies. std::string mComment ; // additional comment to be used mainly for debugging, but not GUI display + + bool operator<(const RsIdentityUsage& u) const + { + return mHash < u.mHash ; + } + RsFileHash mHash ; }; class RsIdentityDetails diff --git a/libretroshare/src/services/p3gxscircles.cc b/libretroshare/src/services/p3gxscircles.cc index c9087cea1..f3e2dea58 100644 --- a/libretroshare/src/services/p3gxscircles.cc +++ b/libretroshare/src/services/p3gxscircles.cc @@ -1094,7 +1094,7 @@ bool p3GxsCircles::locked_processLoadingCacheEntry(RsGxsCircleCache& cache) rsPeers->getOnlineList(peers) ; } - mIdentities->requestKey(pit->first, peers,"Membership status check in Circle "+cache.mCircleName+" ("+cache.mCircleId.toStdString()+")"); + mIdentities->requestKey(pit->first, peers,RsIdentityUsage(serviceType(),RsIdentityUsage::CIRCLE_MEMBERSHIP_CHECK,RsGxsGroupId(cache.mCircleId))); //isUnprocessedPeers = true; } } diff --git a/libretroshare/src/services/p3idservice.cc b/libretroshare/src/services/p3idservice.cc index cbf310a55..fe2ec867d 100644 --- a/libretroshare/src/services/p3idservice.cc +++ b/libretroshare/src/services/p3idservice.cc @@ -33,6 +33,7 @@ #include "util/rsrandom.h" #include "util/rsstring.h" #include "util/radix64.h" +#include "util/rsdir.h" #include "gxs/gxssecurity.h" #include "retroshare/rspeers.h" @@ -525,7 +526,7 @@ void p3IdService::notifyChanges(std::vector &changes) // also time_stamp the key that this group represents - timeStampKey(RsGxsId(*git),"Group meta data changed") ; + timeStampKey(RsGxsId(*git),RsIdentityUsage(serviceType(),RsIdentityUsage::IDENTITY_DATA_UPDATE)) ; ++git; } @@ -932,7 +933,8 @@ bool p3IdService::signData(const uint8_t *data,uint32_t data_size,const RsGxsId& return false ; } error_status = RS_GIXS_ERROR_NO_ERROR ; - timeStampKey(own_gxs_id,"Own GXS id") ; + timeStampKey(own_gxs_id,RsIdentityUsage(serviceType(),RsIdentityUsage::IDENTITY_GENERIC_SIGNATURE_CREATION)) ; + return true ; } bool p3IdService::validateData(const uint8_t *data,uint32_t data_size,const RsTlvKeySignature& signature,bool force_load,const RsIdentityUsage& info,uint32_t& signing_error) @@ -997,7 +999,7 @@ bool p3IdService::encryptData(const uint8_t *decrypted_data,uint32_t decrypted_d return false ; } error_status = RS_GIXS_ERROR_NO_ERROR ; - timeStampKey(encryption_key_id,"Used to encrypt data") ; + timeStampKey(encryption_key_id,RsIdentityUsage(serviceType(),RsIdentityUsage::IDENTITY_GENERIC_ENCRYPTION)) ; return true ; } @@ -1029,7 +1031,7 @@ bool p3IdService::decryptData(const uint8_t *encrypted_data,uint32_t encrypted_d return false ; } error_status = RS_GIXS_ERROR_NO_ERROR ; - timeStampKey(key_id,"Used to decrypt data") ; + timeStampKey(key_id,RsIdentityUsage(serviceType(),RsIdentityUsage::IDENTITY_GENERIC_DECRYPTION)) ; return true ; } @@ -2537,7 +2539,7 @@ bool p3IdService::cachetest_handlerequest(uint32_t token) if (!haveKey(*vit)) { std::list nullpeers; - requestKey(*vit, nullpeers,"Cache test in p3IdService"); + requestKey(*vit, nullpeers,RsIdentityUsage(serviceType(),RsIdentityUsage::UNKNOWN_USAGE)); #ifdef DEBUG_IDS std::cerr << "p3IdService::cachetest_request() Requested Key Id: " << *vit; @@ -4117,5 +4119,12 @@ void p3IdService::handle_event(uint32_t event_type, const std::string &/*elabel* } } +RsIdentityUsage::RsIdentityUsage(uint16_t service,const RsIdentityUsage::UsageCode& code,const RsGxsGroupId& gid,const RsGxsMessageId& mid,uint64_t additional_id,const std::string& comment) + : mServiceId(service), mUsageCode(code), mGrpId(gid), mMsgId(mid),mAdditionalId(additional_id),mComment(comment) +{ + // This is a hack, since it will hash also mHash, but because it is initialized to 0, and only computed in the constructor here, it should be ok. + mHash = RsDirUtil::sha1sum(reinterpret_cast(this),sizeof(RsIdentityUsage)) ; +} + diff --git a/retroshare-gui/src/gui/Identity/IdDialog.cpp b/retroshare-gui/src/gui/Identity/IdDialog.cpp index dfba6030a..87709f411 100644 --- a/retroshare-gui/src/gui/Identity/IdDialog.cpp +++ b/retroshare-gui/src/gui/Identity/IdDialog.cpp @@ -1879,12 +1879,12 @@ void IdDialog::insertIdDetails(uint32_t token) rsIdentity->getIdDetails(RsGxsId(data.mMeta.mGroupId),det) ; QString usage_txt ; - std::map rmap ; - for(std::map::const_iterator it(det.mUseCases.begin());it!=det.mUseCases.end();++it) + std::map rmap ; + for(std::map::const_iterator it(det.mUseCases.begin());it!=det.mUseCases.end();++it) rmap.insert(std::make_pair(it->second,it->first)) ; - for(std::map::const_iterator it(rmap.begin());it!=rmap.end();++it) - usage_txt += QString("")+ getHumanReadableDuration(now - data.mLastUsageTS) + " \t: " + QString::fromStdString(it->second) + "
" ; + for(std::map::const_iterator it(rmap.begin());it!=rmap.end();++it) + usage_txt += QString("")+ getHumanReadableDuration(now - data.mLastUsageTS) + " \t: " + createUsageString(it->second) + "
" ; if(usage_txt.isNull()) usage_txt = tr("[No record in current session]") ; @@ -1892,6 +1892,16 @@ void IdDialog::insertIdDetails(uint32_t token) ui->usageStatistics_TB->setText(usage_txt) ; } +QString IdDialog::createUsageString(const RsIdentityUsage& u) const +{ + switch(u.mUsageCode) + { +#warning TODO! Add the different strings and translations here. + default: + return QString("Undone yet"); + } +} + void IdDialog::modifyReputation() { #ifdef ID_DEBUG diff --git a/retroshare-gui/src/gui/Identity/IdDialog.h b/retroshare-gui/src/gui/Identity/IdDialog.h index 0d8886279..d8f515f4e 100644 --- a/retroshare-gui/src/gui/Identity/IdDialog.h +++ b/retroshare-gui/src/gui/Identity/IdDialog.h @@ -119,6 +119,7 @@ private slots: private: void processSettings(bool load); + QString createUsageString(const RsIdentityUsage& u) const; void requestIdDetails(); void insertIdDetails(uint32_t token);