2012-02-13 13:22:35 -05:00
|
|
|
/*
|
|
|
|
* libretroshare/src/services: p3idservice.h
|
|
|
|
*
|
|
|
|
* Identity interface for RetroShare.
|
|
|
|
*
|
|
|
|
* Copyright 2012-2012 by Robert Fernie.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
2012-10-14 14:32:33 -04:00
|
|
|
* License Version 2.1 as published by the Free Software Foundation.
|
2012-02-13 13:22:35 -05:00
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA.
|
|
|
|
*
|
|
|
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef P3_IDENTITY_SERVICE_HEADER
|
|
|
|
#define P3_IDENTITY_SERVICE_HEADER
|
|
|
|
|
|
|
|
|
2012-10-21 11:48:18 -04:00
|
|
|
#include "retroshare/rsidentity.h" // External Interfaces.
|
|
|
|
#include "gxs/rsgenexchange.h" // GXS service.
|
|
|
|
#include "gxs/rsgixs.h" // Internal Interfaces.
|
2012-02-13 13:22:35 -05:00
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
/*
|
2012-06-07 13:10:47 -04:00
|
|
|
* Identity Service
|
2012-02-13 13:22:35 -05:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-10-14 14:32:33 -04:00
|
|
|
// INTERNAL DATA TYPES.
|
2012-07-29 09:09:36 -04:00
|
|
|
// Describes data stored in GroupServiceString.
|
|
|
|
class IdRepCumulScore
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
uint32_t count;
|
|
|
|
uint32_t nullcount;
|
|
|
|
double sum;
|
|
|
|
double sumsq;
|
|
|
|
|
|
|
|
// derived parameters:
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class IdGroupServiceStrData
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
IdGroupServiceStrData() { pgpIdKnown = false; }
|
|
|
|
bool pgpIdKnown;
|
|
|
|
std::string pgpId;
|
|
|
|
|
|
|
|
uint32_t ownScore;
|
|
|
|
IdRepCumulScore opinion;
|
|
|
|
IdRepCumulScore reputation;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#define ID_LOCAL_STATUS_FULL_CALC_FLAG 0x00010000
|
|
|
|
#define ID_LOCAL_STATUS_INC_CALC_FLAG 0x00020000
|
|
|
|
|
2012-02-13 13:22:35 -05:00
|
|
|
|
|
|
|
|
2012-10-14 14:32:33 -04:00
|
|
|
// Not sure exactly what should be inherited here?
|
|
|
|
// Chris - please correct as necessary.
|
2012-02-13 13:22:35 -05:00
|
|
|
|
2012-10-21 11:48:18 -04:00
|
|
|
class p3IdService: public RsGxsIdExchange, public RsIdentity
|
2012-10-14 14:32:33 -04:00
|
|
|
{
|
2012-02-13 13:22:35 -05:00
|
|
|
public:
|
2012-10-14 14:32:33 -04:00
|
|
|
p3IdService(RsGeneralDataService* gds, RsNetworkExchangeService* nes);
|
2012-02-13 13:22:35 -05:00
|
|
|
|
2012-10-14 14:32:33 -04:00
|
|
|
virtual int internal_tick(); // needed for background processing.
|
2012-06-07 13:10:47 -04:00
|
|
|
|
2012-06-13 20:27:28 -04:00
|
|
|
|
2012-10-14 14:32:33 -04:00
|
|
|
/* General Interface is provided by RsIdentity / RsGxsIfaceImpl. */
|
2012-06-13 20:27:28 -04:00
|
|
|
|
2012-10-14 14:32:33 -04:00
|
|
|
/* Data Specific Interface */
|
2012-06-13 20:27:28 -04:00
|
|
|
|
2012-10-21 11:48:18 -04:00
|
|
|
// These are exposed via RsIdentity.
|
|
|
|
virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsIdGroup> &groups);
|
2012-06-13 20:27:28 -04:00
|
|
|
|
2012-10-21 11:48:18 -04:00
|
|
|
// These are local - and not exposed via RsIdentity.
|
|
|
|
virtual bool getMsgData(const uint32_t &token, std::vector<RsGxsIdOpinion> &opinions);
|
|
|
|
virtual bool createGroup(uint32_t& token, RsGxsIdGroup &group);
|
|
|
|
virtual bool createMsg(uint32_t& token, RsGxsIdOpinion &opinion);
|
2012-06-13 20:27:28 -04:00
|
|
|
|
2012-10-17 20:28:54 -04:00
|
|
|
/**************** RsIdentity External Interface.
|
|
|
|
* Notes:
|
|
|
|
*/
|
|
|
|
|
2012-10-21 11:48:18 -04:00
|
|
|
virtual bool getNickname(const RsGxsId &id, std::string &nickname);
|
|
|
|
virtual bool getIdDetails(const RsGxsId &id, RsIdentityDetails &details);
|
|
|
|
virtual bool getOwnIds(std::list<RsGxsId> &ownIds);
|
2012-10-17 20:28:54 -04:00
|
|
|
|
|
|
|
//
|
|
|
|
virtual bool submitOpinion(uint32_t& token, RsIdOpinion &opinion);
|
|
|
|
virtual bool createIdentity(uint32_t& token, RsIdentityParameters ¶ms);
|
|
|
|
|
|
|
|
|
2012-10-14 14:32:33 -04:00
|
|
|
/**************** RsGixs Implementation
|
|
|
|
* Notes:
|
|
|
|
* Interface is only suggestion at the moment, will be changed as necessary.
|
|
|
|
* Results should be cached / preloaded for maximum speed.
|
|
|
|
*
|
|
|
|
*/
|
2012-10-21 11:48:18 -04:00
|
|
|
virtual bool haveKey(const RsGxsId &id);
|
|
|
|
virtual bool havePrivateKey(const RsGxsId &id);
|
|
|
|
virtual bool requestKey(const RsGxsId &id, const std::list<PeerId> &peers);
|
|
|
|
virtual int getKey(const RsGxsId &id, RsTlvSecurityKey &key);
|
|
|
|
virtual int getPrivateKey(const RsGxsId &id, RsTlvSecurityKey &key);
|
2012-06-13 20:27:28 -04:00
|
|
|
|
2012-10-14 14:32:33 -04:00
|
|
|
/**************** RsGixsReputation Implementation
|
|
|
|
* Notes:
|
|
|
|
* Again should be cached if possible.
|
|
|
|
*/
|
2012-06-13 20:27:28 -04:00
|
|
|
|
2012-10-14 14:32:33 -04:00
|
|
|
// get Reputation.
|
2012-10-21 11:48:18 -04:00
|
|
|
virtual bool getReputation(const RsGxsId &id, const GixsReputation &rep);
|
2012-06-13 20:27:28 -04:00
|
|
|
|
2012-07-06 19:14:18 -04:00
|
|
|
private:
|
2012-06-07 13:10:47 -04:00
|
|
|
|
2012-10-14 14:32:33 -04:00
|
|
|
/************************************************************************
|
|
|
|
* Below is the background task for processing opinions => reputations
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-02-13 13:22:35 -05:00
|
|
|
virtual void generateDummyData();
|
|
|
|
|
|
|
|
std::string genRandomId();
|
|
|
|
|
2012-07-29 09:09:36 -04:00
|
|
|
int background_tick();
|
|
|
|
bool background_checkTokenRequest();
|
|
|
|
bool background_requestGroups();
|
|
|
|
bool background_requestNewMessages();
|
|
|
|
bool background_processNewMessages();
|
|
|
|
bool background_FullCalcRequest();
|
|
|
|
bool background_processFullCalc();
|
|
|
|
|
|
|
|
bool background_cleanup();
|
|
|
|
|
|
|
|
bool encodeIdGroupCache(std::string &str, const IdGroupServiceStrData &data);
|
|
|
|
bool extractIdGroupCache(std::string &str, IdGroupServiceStrData &data);
|
|
|
|
|
2012-02-13 13:22:35 -05:00
|
|
|
RsMutex mIdMtx;
|
|
|
|
|
|
|
|
/***** below here is locked *****/
|
2012-07-29 09:09:36 -04:00
|
|
|
bool mLastBgCheck;
|
|
|
|
bool mBgProcessing;
|
|
|
|
|
|
|
|
uint32_t mBgToken;
|
|
|
|
uint32_t mBgPhase;
|
|
|
|
|
|
|
|
std::map<std::string, RsGroupMetaData> mBgGroupMap;
|
|
|
|
std::list<std::string> mBgFullCalcGroups;
|
2012-02-13 13:22:35 -05:00
|
|
|
|
2012-10-14 14:32:33 -04:00
|
|
|
/************************************************************************
|
|
|
|
* Other Data that is protected by the Mutex.
|
|
|
|
*/
|
2012-02-13 13:22:35 -05:00
|
|
|
|
2012-10-14 14:32:33 -04:00
|
|
|
std::vector<RsGxsGroupChange*> mGroupChange;
|
|
|
|
std::vector<RsGxsMsgChange*> mMsgChange;
|
2012-02-13 13:22:35 -05:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2012-10-14 14:32:33 -04:00
|
|
|
#endif // P3_IDENTITY_SERVICE_HEADER
|
|
|
|
|
|
|
|
|
|
|
|
|