2014-04-13 17:52:53 -04:00
|
|
|
/*
|
|
|
|
* nxsdummyservices.h
|
|
|
|
*
|
|
|
|
* Created on: 13 Apr 2014
|
|
|
|
* Author: crispy
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef NXSDUMMYSERVICES_H_
|
|
|
|
#define NXSDUMMYSERVICES_H_
|
|
|
|
|
2014-04-18 17:58:14 -04:00
|
|
|
#include <list>
|
|
|
|
#include <map>
|
|
|
|
#include <retroshare/rstypes.h>
|
|
|
|
#include <gxs/rsgixs.h>
|
|
|
|
#include <gxs/rsgxsnetutils.h>
|
|
|
|
#include <algorithm>
|
2014-05-27 17:14:05 -04:00
|
|
|
#include <pgp/pgpauxutils.h>
|
2014-04-18 17:58:14 -04:00
|
|
|
|
2014-04-13 17:52:53 -04:00
|
|
|
|
|
|
|
namespace rs_nxs_test
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
2014-05-27 17:14:05 -04:00
|
|
|
* This is a dummy circles implementation
|
2014-04-13 17:52:53 -04:00
|
|
|
*/
|
|
|
|
class RsNxsSimpleDummyCircles : public RsGcxs
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
/*!
|
|
|
|
*
|
|
|
|
* @param membership
|
|
|
|
* @param cached
|
|
|
|
*/
|
2014-05-27 17:14:05 -04:00
|
|
|
RsNxsSimpleDummyCircles();
|
2014-04-13 17:52:53 -04:00
|
|
|
|
|
|
|
/* GXS Interface - for working out who can receive */
|
|
|
|
bool isLoaded(const RsGxsCircleId &circleId);
|
|
|
|
bool loadCircle(const RsGxsCircleId &circleId);
|
|
|
|
|
2016-03-26 17:25:15 -04:00
|
|
|
int canSend(const RsGxsCircleId &circleId, const RsPgpId &id,bool& should_encrypt);
|
2014-04-13 17:52:53 -04:00
|
|
|
int canReceive(const RsGxsCircleId &circleId, const RsPgpId &id);
|
2016-06-02 13:34:58 -04:00
|
|
|
virtual bool recipients(const RsGxsCircleId &circleId, std::list<RsPgpId> &friendlist);
|
|
|
|
virtual bool recipients(const RsGxsCircleId &circleId, const RsGxsGroupId& destination_group, std::list<RsGxsId>& idlist) ;
|
|
|
|
virtual bool isRecipient(const RsGxsCircleId &circleId, const RsGxsGroupId& destination_group, const RsGxsId& id) ;
|
2017-01-21 10:31:22 -05:00
|
|
|
virtual bool getLocalCircleServerUpdateTS(const RsGxsCircleId& /*gid*/,time_t& /*grp_server_update_TS*/,time_t& /*msg_server_update_TS*/) { return true ; }
|
2014-04-13 17:52:53 -04:00
|
|
|
};
|
|
|
|
|
2014-05-18 13:24:21 -04:00
|
|
|
/*!
|
|
|
|
* This dummy circles implementation
|
|
|
|
* allow instantiation with simple membership
|
|
|
|
* list for a given circle
|
|
|
|
*/
|
|
|
|
class RsNxsDelayedDummyCircles : public RsGcxs
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
/*!
|
|
|
|
*
|
|
|
|
* @param membership
|
|
|
|
* @param countBeforePresent how many times a pgpid is checked before it becomes present
|
|
|
|
*/
|
|
|
|
RsNxsDelayedDummyCircles(int countBeforePresent);
|
|
|
|
virtual ~RsNxsDelayedDummyCircles();
|
|
|
|
|
|
|
|
/* GXS Interface - for working out who can receive */
|
|
|
|
bool isLoaded(const RsGxsCircleId &circleId);
|
|
|
|
bool loadCircle(const RsGxsCircleId &circleId);
|
|
|
|
|
2016-03-26 17:25:15 -04:00
|
|
|
int canSend(const RsGxsCircleId &circleId, const RsPgpId &id,bool& should_encrypt);
|
2014-05-18 13:24:21 -04:00
|
|
|
int canReceive(const RsGxsCircleId &circleId, const RsPgpId &id);
|
2016-06-02 13:34:58 -04:00
|
|
|
virtual bool recipients(const RsGxsCircleId &circleId, std::list<RsPgpId> &friendlist);
|
2017-01-21 10:31:22 -05:00
|
|
|
virtual bool recipients(const RsGxsCircleId &/*circleId*/, const RsGxsGroupId& /*destination_group*/, std::list<RsGxsId>& /*idlist*/) { return true ;}
|
|
|
|
virtual bool isRecipient(const RsGxsCircleId &circleId, const RsGxsGroupId& /*destination_group*/, const RsGxsId& /*id*/) { return allowed(circleId) ; }
|
|
|
|
virtual bool getLocalCircleServerUpdateTS(const RsGxsCircleId& /*gid*/,time_t& /*grp_server_update_TS*/,time_t& /*msg_server_update_TS*/) { return true ; }
|
2014-05-18 13:24:21 -04:00
|
|
|
private:
|
|
|
|
|
|
|
|
bool allowed(const RsGxsCircleId& circleId);
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
typedef int CallCount;
|
|
|
|
std::map<RsGxsCircleId, CallCount> mMembershipCallCount;
|
|
|
|
int mCountBeforePresent;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-04-13 17:52:53 -04:00
|
|
|
/*!
|
|
|
|
* This dummy reputation allows you to set the
|
|
|
|
* reputations of peers
|
|
|
|
*/
|
|
|
|
class RsNxsSimpleDummyReputation : public RsGixsReputation
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
typedef std::map<RsGxsId, GixsReputation> RepMap;
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Instantiate the dummy rep service with
|
|
|
|
* a reputation map
|
|
|
|
* @param repMap should contain the reputations of a set of ids
|
|
|
|
* @param cached this means initial call for an ids \n
|
|
|
|
* rep will return false, until a request has been made to load it
|
|
|
|
*/
|
|
|
|
RsNxsSimpleDummyReputation(RepMap& repMap, bool cached );
|
|
|
|
|
|
|
|
bool haveReputation(const RsGxsId &id);
|
|
|
|
bool loadReputation(const RsGxsId &id, const std::list<RsPeerId>& peers);
|
|
|
|
bool getReputation(const RsGxsId &id, GixsReputation &rep);
|
|
|
|
|
2017-02-20 10:15:31 -05:00
|
|
|
virtual RsReputations::ReputationLevel overallReputationLevel(const RsGxsId&,uint32_t */*identity_flags*/=NULL) { return RsReputations::REPUTATION_NEUTRAL ; }
|
2017-01-13 16:41:54 -05:00
|
|
|
|
2014-04-13 17:52:53 -04:00
|
|
|
private:
|
|
|
|
|
|
|
|
RepMap mRepMap;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Very simple net manager
|
|
|
|
*/
|
|
|
|
class RsNxsNetDummyMgr : public RsNxsNetMgr
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2014-04-18 17:58:14 -04:00
|
|
|
RsNxsNetDummyMgr(const RsPeerId& ownId, const std::list<RsPeerId>& peers) : mOwnId(ownId), mPeers(peers) {
|
2014-04-13 17:52:53 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
const RsPeerId& getOwnId() { return mOwnId; }
|
2017-01-21 10:31:22 -05:00
|
|
|
void getOnlineList(const uint32_t /*serviceId*/, std::set<RsPeerId>& ssl_peers)
|
2014-04-18 17:58:14 -04:00
|
|
|
{
|
|
|
|
RsPeerId::std_list::iterator lit = mPeers.begin();
|
|
|
|
|
|
|
|
for(; lit != mPeers.end(); lit++)
|
|
|
|
ssl_peers.insert(*lit);
|
|
|
|
}
|
2014-04-13 17:52:53 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
RsPeerId mOwnId;
|
2014-04-18 17:58:14 -04:00
|
|
|
std::list<RsPeerId> mPeers;
|
2014-04-13 17:52:53 -04:00
|
|
|
|
|
|
|
};
|
2014-04-18 17:58:14 -04:00
|
|
|
|
2014-05-27 17:14:05 -04:00
|
|
|
class RsDummyPgpUtils : public PgpAuxUtils
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
virtual ~RsDummyPgpUtils(){}
|
|
|
|
const RsPgpId &getPGPOwnId() ;
|
|
|
|
RsPgpId getPGPId(const RsPeerId& sslid) ;
|
|
|
|
bool getGPGAllList(std::list<RsPgpId> &ids) ;
|
|
|
|
bool getKeyFingerprint(const RsPgpId& id,PGPFingerprintType& fp) const;
|
|
|
|
|
2016-04-04 11:18:42 -04:00
|
|
|
bool parseSignature(unsigned char *sign, unsigned int signlen, RsPgpId& issuer) const;
|
2014-05-27 17:14:05 -04:00
|
|
|
bool VerifySignBin(const void *data, uint32_t len, unsigned char *sign, unsigned int signlen, const PGPFingerprintType& withfingerprint);
|
2016-08-08 19:22:14 -04:00
|
|
|
bool askForDeferredSelfSignature(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen, int& signature_result , std::string reason = "");
|
2014-05-27 17:14:05 -04:00
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
RsPgpId mOwnId;
|
|
|
|
};
|
2014-04-18 17:58:14 -04:00
|
|
|
|
2014-04-13 17:52:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* NXSDUMMYSERVICES_H_ */
|