Fix RsIdentity API to get own identities

This commit is contained in:
Gioacchino Mazzurco 2019-07-19 13:54:46 +02:00
parent c559a26224
commit d9979ca183
No known key found for this signature in database
GPG key ID: A1FBCA3872E87051
3 changed files with 17 additions and 39 deletions

View file

@ -380,6 +380,7 @@ struct RsIdentity : RsGxsIfaceHelper
/** /**
* @brief Get identity details, from the cache * @brief Get identity details, from the cache
* @jsonapi{development}
* @param[in] id Id of the identity * @param[in] id Id of the identity
* @param[out] details Storage for the identity details * @param[out] details Storage for the identity details
* @return false on error, true otherwise * @return false on error, true otherwise
@ -400,7 +401,7 @@ struct RsIdentity : RsGxsIfaceHelper
* @param[out] ids storage for the ids * @param[out] ids storage for the ids
* @return false on error, true otherwise * @return false on error, true otherwise
*/ */
virtual bool getOwnSignedIds(std::vector<RsGxsId> ids) = 0; virtual bool getOwnSignedIds(std::vector<RsGxsId>& ids) = 0;
/** /**
* @brief Get own pseudonimous (unsigned) ids * @brief Get own pseudonimous (unsigned) ids
@ -408,7 +409,7 @@ struct RsIdentity : RsGxsIfaceHelper
* @param[out] ids storage for the ids * @param[out] ids storage for the ids
* @return false on error, true otherwise * @return false on error, true otherwise
*/ */
virtual bool getOwnPseudonimousIds(std::vector<RsGxsId> ids) = 0; virtual bool getOwnPseudonimousIds(std::vector<RsGxsId>& ids) = 0;
/** /**
* @brief Check if an id is own * @brief Check if an id is own

View file

@ -757,7 +757,7 @@ bool p3IdService::isOwnId(const RsGxsId& id)
} }
bool p3IdService::getOwnSignedIds(std::vector<RsGxsId> ids) bool p3IdService::getOwnSignedIds(std::vector<RsGxsId>& ids)
{ {
ids.clear(); ids.clear();
@ -769,27 +769,29 @@ bool p3IdService::getOwnSignedIds(std::vector<RsGxsId> ids)
if(ownIdsAreLoaded()) if(ownIdsAreLoaded())
{ {
RS_STACK_MUTEX(mIdMtx); RS_STACK_MUTEX(mIdMtx);
ids.reserve(mOwnSignedIds.size()); ids.resize(mOwnSignedIds.size());
ids.insert(ids.end(), mOwnSignedIds.begin(), mOwnSignedIds.end()); std::copy(mOwnSignedIds.begin(), mOwnSignedIds.end(), ids.begin());
return true; return true;
} }
return false; return false;
} }
bool p3IdService::getOwnPseudonimousIds(std::vector<RsGxsId> ids) bool p3IdService::getOwnPseudonimousIds(std::vector<RsGxsId>& ids)
{ {
ids.clear(); ids.clear();
std::vector<RsGxsId> signedV; std::vector<RsGxsId> signedV;
// this implicitely ensure ids are already loaded ;) // this implicitely ensure ids are already loaded ;)
if(!getOwnSignedIds(signedV)) return false; if(!getOwnSignedIds(signedV)) return false;
std::set<RsGxsId> signedS(signedV.begin(), signedV.end()); std::set<RsGxsId> signedS(signedV.begin(), signedV.end());
{ {
RS_STACK_MUTEX(mIdMtx); RS_STACK_MUTEX(mIdMtx);
std::copy_if(mOwnIds.begin(), mOwnIds.end(), ids.end(), ids.resize(mOwnIds.size() - signedV.size());
[&](const RsGxsId& id) {return !signedS.count(id);}); std::copy_if( mOwnIds.begin(), mOwnIds.end(), ids.begin(),
[&](const RsGxsId& id) {return !signedS.count(id);} );
} }
return true; return true;

View file

@ -19,8 +19,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * * along with this program. If not, see <https://www.gnu.org/licenses/>. *
* * * *
*******************************************************************************/ *******************************************************************************/
#ifndef P3_IDENTITY_SERVICE_HEADER #pragma once
#define P3_IDENTITY_SERVICE_HEADER
#include "retroshare/rsidentity.h" // External Interfaces. #include "retroshare/rsidentity.h" // External Interfaces.
@ -36,34 +35,13 @@
#include "util/rsmemcache.h" #include "util/rsmemcache.h"
#include "util/rstickevent.h" #include "util/rstickevent.h"
#include "util/rsrecogn.h" #include "util/rsrecogn.h"
#include "util/rsdebug.h"
#include "pqi/authgpg.h" #include "pqi/authgpg.h"
#include "rsitems/rsgxsrecognitems.h" #include "rsitems/rsgxsrecognitems.h"
class PgpAuxUtils; class PgpAuxUtils;
/*
* Identity Service
*
*/
#if 0
class GxsReputation
{
public:
GxsReputation();
bool updateIdScore(bool pgpLinked, bool pgpKnown);
bool update(); // checks ranges and calculates overall score.
int mOverallScore;
int mIdScore; // PGP, Known, etc.
int mOwnOpinion;
int mPeerOpinion;
};
#endif
class OpinionRequest class OpinionRequest
{ {
public: public:
@ -312,10 +290,10 @@ public:
/**************** RsGixs Implementation ***************/ /**************** RsGixs Implementation ***************/
/// @see RsIdentity /// @see RsIdentity
bool getOwnSignedIds(std::vector<RsGxsId> ids) override; bool getOwnSignedIds(std::vector<RsGxsId>& ids) override;
/// @see RsIdentity /// @see RsIdentity
bool getOwnPseudonimousIds(std::vector<RsGxsId> ids) override; bool getOwnPseudonimousIds(std::vector<RsGxsId>& ids) override;
virtual bool getOwnIds(std::list<RsGxsId> &ownIds, bool signed_only = false); virtual bool getOwnIds(std::list<RsGxsId> &ownIds, bool signed_only = false);
@ -641,9 +619,6 @@ private:
bool mAutoAddFriendsIdentitiesAsContacts; bool mAutoAddFriendsIdentitiesAsContacts;
uint32_t mMaxKeepKeysBanned ; uint32_t mMaxKeepKeysBanned ;
RS_SET_CONTEXT_DEBUG_LEVEL(4);
}; };
#endif // P3_IDENTITY_SERVICE_HEADER