Added PgpAuxUtils to allow Mocking of Pgp functions for simulations.

Cleaned up some of the debug messages.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7306 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2014-04-27 13:14:07 +00:00
parent 4fe6161d58
commit 23480be883
16 changed files with 490 additions and 94 deletions

View File

@ -26,7 +26,7 @@
#include "gxssecurity.h" #include "gxssecurity.h"
#include "pqi/authgpg.h" #include "pqi/authgpg.h"
#include "retroshare/rspeers.h" //#include "retroshare/rspeers.h"
#define GXS_SECURITY_DEBUG #define GXS_SECURITY_DEBUG

View File

@ -140,7 +140,9 @@
#define COL_IDENTITY 4 #define COL_IDENTITY 4
#define COL_HASH 5 #define COL_HASH 5
#define RS_DATA_SERVICE_DEBUG /*****
* #define RS_DATA_SERVICE_DEBUG 1
****/
const std::string RsGeneralDataService::GRP_META_SERV_STRING = KEY_NXS_SERV_STRING; const std::string RsGeneralDataService::GRP_META_SERV_STRING = KEY_NXS_SERV_STRING;
const std::string RsGeneralDataService::GRP_META_STATUS = KEY_GRP_STATUS; const std::string RsGeneralDataService::GRP_META_STATUS = KEY_GRP_STATUS;
@ -196,6 +198,12 @@ RsDataService::RsDataService(const std::string &serviceDir, const std::string &d
} }
RsDataService::~RsDataService(){ RsDataService::~RsDataService(){
#ifdef RS_DATA_SERVICE_DEBUG
std::cerr << "RsDataService::~RsDataService()";
std::cerr << std::endl;
#endif
mDb->closeDb(); mDb->closeDb();
delete mDb; delete mDb;
} }
@ -270,6 +278,11 @@ void RsDataService::initialise(){
RsGxsGrpMetaData* RsDataService::locked_getGrpMeta(RetroCursor &c) RsGxsGrpMetaData* RsDataService::locked_getGrpMeta(RetroCursor &c)
{ {
#ifdef RS_DATA_SERVICE_DEBUG
std::cerr << "RsDataService::locked_getGrpMeta()";
std::cerr << std::endl;
#endif
RsGxsGrpMetaData* grpMeta = new RsGxsGrpMetaData(); RsGxsGrpMetaData* grpMeta = new RsGxsGrpMetaData();
bool ok = true; bool ok = true;
@ -283,11 +296,9 @@ RsGxsGrpMetaData* RsDataService::locked_getGrpMeta(RetroCursor &c)
std::string tempId; std::string tempId;
c.getString(COL_GRP_ID, tempId); c.getString(COL_GRP_ID, tempId);
grpMeta->mGroupId = RsGxsGroupId(tempId); grpMeta->mGroupId = RsGxsGroupId(tempId);
c.getString(COL_IDENTITY, tempId); c.getString(COL_IDENTITY, tempId);
grpMeta->mAuthorId = RsGxsId(tempId); grpMeta->mAuthorId = RsGxsId(tempId);
c.getString(COL_GRP_NAME, grpMeta->mGroupName); c.getString(COL_GRP_NAME, grpMeta->mGroupName);
c.getString(COL_ORIG_GRP_ID, tempId); c.getString(COL_ORIG_GRP_ID, tempId);
grpMeta->mOrigGrpId = RsGxsGroupId(tempId); grpMeta->mOrigGrpId = RsGxsGroupId(tempId);
@ -1081,11 +1092,20 @@ void RsDataService::locked_retrieveMsgMeta(RetroCursor *c, std::vector<RsGxsMsgM
int RsDataService::retrieveGxsGrpMetaData(std::map<RsGxsGroupId, RsGxsGrpMetaData *>& grp) int RsDataService::retrieveGxsGrpMetaData(std::map<RsGxsGroupId, RsGxsGrpMetaData *>& grp)
{ {
#ifdef RS_DATA_SERVICE_DEBUG
std::cerr << "RsDataService::retrieveGxsGrpMetaData()";
std::cerr << std::endl;
#endif
RsStackMutex stack(mDbMutex); RsStackMutex stack(mDbMutex);
if(grp.empty()){ if(grp.empty()){
#ifdef RS_DATA_SERVICE_DEBUG
std::cerr << "RsDataService::retrieveGxsGrpMetaData() retrieving all";
std::cerr << std::endl;
#endif
RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, grpMetaColumns, "", ""); RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, grpMetaColumns, "", "");
if(c) if(c)
@ -1095,7 +1115,6 @@ int RsDataService::retrieveGxsGrpMetaData(std::map<RsGxsGroupId, RsGxsGrpMetaDat
while(valid) while(valid)
{ {
RsGxsGrpMetaData* g = locked_getGrpMeta(*c); RsGxsGrpMetaData* g = locked_getGrpMeta(*c);
if(g) if(g)
{ {
grp[g->mGroupId] = g; grp[g->mGroupId] = g;

View File

@ -30,9 +30,12 @@
#include "rsgxsnetservice.h" #include "rsgxsnetservice.h"
#include "retroshare/rsgxsflags.h" #include "retroshare/rsgxsflags.h"
#include "retroshare/rsgxscircles.h" #include "retroshare/rsgxscircles.h"
#include "retroshare/rspeers.h" #include "pgp/pgpauxutils.h"
/***
* #define NXS_NET_DEBUG 1
***/
#define NXS_NET_DEBUG 1
#define GIXS_CUT_OFF 0 #define GIXS_CUT_OFF 0
#define SYNC_PERIOD 12 // in microseconds every 10 seconds (1 second for testing) #define SYNC_PERIOD 12 // in microseconds every 10 seconds (1 second for testing)
@ -43,11 +46,14 @@
RsGxsNetService::RsGxsNetService(uint16_t servType, RsGeneralDataService *gds, RsGxsNetService::RsGxsNetService(uint16_t servType, RsGeneralDataService *gds,
RsNxsNetMgr *netMgr, RsNxsObserver *nxsObs, RsNxsNetMgr *netMgr, RsNxsObserver *nxsObs,
const RsServiceInfo serviceInfo, const RsServiceInfo serviceInfo,
RsGixsReputation* reputations, RsGcxs* circles, bool grpAutoSync) RsGixsReputation* reputations, RsGcxs* circles,
PgpAuxUtils *pgpUtils, bool grpAutoSync)
: p3ThreadedService(), p3Config(), mTransactionN(0), : p3ThreadedService(), p3Config(), mTransactionN(0),
mObserver(nxsObs), mDataStore(gds), mServType(servType), mObserver(nxsObs), mDataStore(gds), mServType(servType),
mTransactionTimeOut(TRANSAC_TIMEOUT), mNetMgr(netMgr), mNxsMutex("RsGxsNetService"), mTransactionTimeOut(TRANSAC_TIMEOUT), mNetMgr(netMgr), mNxsMutex("RsGxsNetService"),
mSyncTs(0), mSYNC_PERIOD(SYNC_PERIOD), mCircles(circles), mReputations(reputations), mGrpAutoSync(grpAutoSync), mGrpServerUpdateItem(NULL), mSyncTs(0), mSYNC_PERIOD(SYNC_PERIOD), mCircles(circles), mReputations(reputations),
mPgpUtils(pgpUtils),
mGrpAutoSync(grpAutoSync), mGrpServerUpdateItem(NULL),
mServiceInfo(serviceInfo) mServiceInfo(serviceInfo)
{ {
@ -61,8 +67,8 @@ RsGxsNetService::~RsGxsNetService()
} }
int RsGxsNetService::tick(){ int RsGxsNetService::tick()
{
// always check for new items arriving // always check for new items arriving
// from peers // from peers
if(receivedItems()) if(receivedItems())
@ -82,6 +88,10 @@ int RsGxsNetService::tick(){
void RsGxsNetService::syncWithPeers() void RsGxsNetService::syncWithPeers()
{ {
#ifdef NXS_NET_DEBUG
std::cerr << "RsGxsNetService::syncWithPeers()";
std::cerr << std::endl;
#endif
std::set<RsPeerId> peers; std::set<RsPeerId> peers;
mNetMgr->getOnlineList(mServiceInfo.mServiceType, peers); mNetMgr->getOnlineList(mServiceInfo.mServiceType, peers);
@ -363,6 +373,10 @@ void RsGxsNetService::locked_createTransactionFromPending(
if(entry.mPassedVetting) if(entry.mPassedVetting)
{ {
#ifdef NXS_NET_DEBUG
std::cerr << "locked_createTransactionFromPending(AUTHOR VETTING) Group Id: " << entry.mGrpId << " PASSED";
std::cerr << std::endl;
#endif
RsNxsSyncGrpItem* msgItem = new RsNxsSyncGrpItem(mServType); RsNxsSyncGrpItem* msgItem = new RsNxsSyncGrpItem(mServType);
msgItem->grpId = entry.mGrpId; msgItem->grpId = entry.mGrpId;
msgItem->authorId = entry.mAuthorId; msgItem->authorId = entry.mAuthorId;
@ -371,6 +385,13 @@ void RsGxsNetService::locked_createTransactionFromPending(
msgItem->PeerId(grpPend->mPeerId); msgItem->PeerId(grpPend->mPeerId);
reqList.push_back(msgItem); reqList.push_back(msgItem);
} }
else
{
#ifdef NXS_NET_DEBUG
std::cerr << "locked_createTransactionFromPending(AUTHOR VETTING) Group Id: " << entry.mGrpId << " FAILED";
std::cerr << std::endl;
#endif
}
} }
if(!reqList.empty()) if(!reqList.empty())
@ -386,14 +407,12 @@ void RsGxsNetService::locked_createTransactionFromPending(GrpCircleIdRequestVett
for(; cit != grpPend->mGrpCircleV.end(); cit++) for(; cit != grpPend->mGrpCircleV.end(); cit++)
{ {
const GrpIdCircleVet& entry = *cit; const GrpIdCircleVet& entry = *cit;
// this shows what groups got cleared by the server
#ifdef NXS_NET_DEBUG
std::cerr << "locked_createTransactionFromPending() Group Id: " << entry.mGroupId << "cleared: "
<< entry.mCleared << std::endl;
#endif
if(entry.mCleared) if(entry.mCleared)
{ {
#ifdef NXS_NET_DEBUG
std::cerr << "locked_createTransactionFromPending(CIRCLE VETTING) Group Id: " << entry.mGroupId << " PASSED";
std::cerr << std::endl;
#endif
RsNxsSyncGrpItem* gItem = new RsNxsSyncGrpItem* gItem = new
RsNxsSyncGrpItem(mServType); RsNxsSyncGrpItem(mServType);
gItem->flag = RsNxsSyncGrpItem::FLAG_RESPONSE; gItem->flag = RsNxsSyncGrpItem::FLAG_RESPONSE;
@ -401,8 +420,16 @@ void RsGxsNetService::locked_createTransactionFromPending(GrpCircleIdRequestVett
gItem->publishTs = 0; gItem->publishTs = 0;
gItem->PeerId(grpPend->mPeerId); gItem->PeerId(grpPend->mPeerId);
gItem->transactionNumber = transN; gItem->transactionNumber = transN;
// why it authorId not set here???
itemL.push_back(gItem); itemL.push_back(gItem);
} }
else
{
#ifdef NXS_NET_DEBUG
std::cerr << "locked_createTransactionFromPending(CIRCLE VETTING) Group Id: " << entry.mGroupId << " FAILED";
std::cerr << std::endl;
#endif
}
} }
if(!itemL.empty()) if(!itemL.empty())
@ -457,7 +484,7 @@ bool RsGxsNetService::locked_canReceive(const RsGxsGrpMetaData * const grpMeta,
if(mCircles->isLoaded(grpMeta->mCircleId)) if(mCircles->isLoaded(grpMeta->mCircleId))
{ {
const RsPgpId& pgpId = mNetMgr->getGPGId(peerId); const RsPgpId& pgpId = mPgpUtils->getPGPId(peerId);
return mCircles->canSend(grpMeta->mCircleId, pgpId); return mCircles->canSend(grpMeta->mCircleId, pgpId);
} }
@ -465,7 +492,8 @@ bool RsGxsNetService::locked_canReceive(const RsGxsGrpMetaData * const grpMeta,
i++; i++;
} }
}else }
else
{ {
return true; return true;
} }
@ -680,6 +708,7 @@ void RsGxsNetService::recvNxsItemQueue(){
{ {
#ifdef NXS_NET_DEBUG #ifdef NXS_NET_DEBUG
std::cerr << "RsGxsNetService Item:" << (void*)item << std::endl ; std::cerr << "RsGxsNetService Item:" << (void*)item << std::endl ;
item->print(std::cerr);
#endif #endif
// RsNxsItem needs dynamic_cast, since they have derived siblings. // RsNxsItem needs dynamic_cast, since they have derived siblings.
// //
@ -1047,10 +1076,13 @@ void RsGxsNetService::processTransactions(){
mComplTransactions.push_back(tr); mComplTransactions.push_back(tr);
}else{ }else{
#ifdef NXS_NET_DEBUG
std::cerr << "processTransactions() " << std::endl; std::cerr << "processTransactions() " << std::endl;
std::cerr << "processTransactions(), Unknown flag for active transaction, transN: " << transN std::cerr << "processTransactions(), Unknown flag for active transaction, transN: " << transN
<< std::endl; << std::endl;
std::cerr << "processTransactions(), Unknown flag, Peer: " << mit->first; std::cerr << "processTransactions(), Unknown flag, Peer: " << mit->first;
#endif
toRemove.push_back(transN); toRemove.push_back(transN);
tr->mFlag = NxsTransaction::FLAG_STATE_FAILED; tr->mFlag = NxsTransaction::FLAG_STATE_FAILED;
mComplTransactions.push_back(tr); mComplTransactions.push_back(tr);
@ -1080,11 +1112,9 @@ void RsGxsNetService::processTransactions(){
if(locked_checkTransacTimedOut(tr)) if(locked_checkTransacTimedOut(tr))
{ {
#ifdef NXS_NET_DEBUG
std::cerr << "processTransactions() " << std::endl; std::cerr << "processTransactions() " << std::endl;
std::cerr << "Transaction has failed, tranN: " << transN << std::endl; std::cerr << "Transaction has failed, tranN: " << transN << std::endl;
std::cerr << "Transaction has failed, Peer: " << mit->first << std::endl; std::cerr << "Transaction has failed, Peer: " << mit->first << std::endl;
#endif
tr->mFlag = NxsTransaction::FLAG_STATE_FAILED; tr->mFlag = NxsTransaction::FLAG_STATE_FAILED;
toRemove.push_back(transN); toRemove.push_back(transN);
@ -1612,6 +1642,11 @@ void RsGxsNetService::addGroupItemToList(NxsTransaction*& tr,
const RsGxsGroupId& grpId, uint32_t& transN, const RsGxsGroupId& grpId, uint32_t& transN,
std::list<RsNxsItem*>& reqList) std::list<RsNxsItem*>& reqList)
{ {
#ifdef NXS_NET_DEBUG
std::cerr << "RsGxsNetService::addGroupItemToList() Added GroupID: << grpId";
std::cerr << std::endl;
#endif
RsNxsSyncGrpItem* grpItem = new RsNxsSyncGrpItem(mServType); RsNxsSyncGrpItem* grpItem = new RsNxsSyncGrpItem(mServType);
grpItem->PeerId(tr->mTransaction->PeerId()); grpItem->PeerId(tr->mTransaction->PeerId());
grpItem->grpId = grpId; grpItem->grpId = grpId;
@ -2074,6 +2109,10 @@ bool RsGxsNetService::locked_CanReceiveUpdate(const RsNxsSyncGrp *item)
{ {
if(item->updateTS >= mGrpServerUpdateItem->grpUpdateTS && item->updateTS != 0) if(item->updateTS >= mGrpServerUpdateItem->grpUpdateTS && item->updateTS != 0)
{ {
#ifdef NXS_NET_DEBUG
std::cerr << "RsGxsNetService::locked_CanReceiveUpdate() No Updates";
std::cerr << std::endl;
#endif
return false; return false;
} }
} }
@ -2087,7 +2126,13 @@ void RsGxsNetService::handleRecvSyncGroup(RsNxsSyncGrp* item)
RsStackMutex stack(mNxsMutex); RsStackMutex stack(mNxsMutex);
if(!locked_CanReceiveUpdate(item)) if(!locked_CanReceiveUpdate(item))
{
#ifdef NXS_NET_DEBUG
std::cerr << "RsGxsNetService::handleRecvSyncGroup() Cannot RecvUpdate";
std::cerr << std::endl;
#endif
return; return;
}
RsPeerId peer = item->PeerId(); RsPeerId peer = item->PeerId();
@ -2097,7 +2142,13 @@ void RsGxsNetService::handleRecvSyncGroup(RsNxsSyncGrp* item)
mDataStore->retrieveGxsGrpMetaData(grp); mDataStore->retrieveGxsGrpMetaData(grp);
if(grp.empty()) if(grp.empty())
{
#ifdef NXS_NET_DEBUG
std::cerr << "RsGxsNetService::handleRecvSyncGroup() Grp Empty";
std::cerr << std::endl;
#endif
return; return;
}
std::map<RsGxsGroupId, RsGxsGrpMetaData*>::iterator mit = std::map<RsGxsGroupId, RsGxsGrpMetaData*>::iterator mit =
grp.begin(); grp.begin();
@ -2134,8 +2185,12 @@ void RsGxsNetService::handleRecvSyncGroup(RsNxsSyncGrp* item)
gItem->transactionNumber = transN; gItem->transactionNumber = transN;
itemL.push_back(gItem); itemL.push_back(gItem);
#ifdef NXS_NET_DEBUG #ifdef NXS_NET_DEBUG
std::cerr << "RsGxsNetService::handleRecvSyncGroup" std::cerr << "RsGxsNetService::handleRecvSyncGroup";
<< "\nGroup : " << grpMeta->mGroupName << ", id: " << gItem->grpId << std::endl; std::cerr << std::endl;
std::cerr << "Group : " << grpMeta->mGroupName;
std::cerr << ", id: " << gItem->grpId;
std::cerr << ", authorId: " << gItem->authorId;
std::cerr << std::endl;
#endif #endif
} }
} }
@ -2145,7 +2200,7 @@ void RsGxsNetService::handleRecvSyncGroup(RsNxsSyncGrp* item)
if(!toVet.empty()) if(!toVet.empty())
{ {
mPendingCircleVets.push_back(new GrpCircleIdRequestVetting(mCircles, mNetMgr, toVet, peer)); mPendingCircleVets.push_back(new GrpCircleIdRequestVetting(mCircles, mPgpUtils, toVet, peer));
} }
locked_pushGrpRespFromList(itemL, peer, transN); locked_pushGrpRespFromList(itemL, peer, transN);
@ -2157,14 +2212,30 @@ void RsGxsNetService::handleRecvSyncGroup(RsNxsSyncGrp* item)
bool RsGxsNetService::canSendGrpId(const RsPeerId& sslId, RsGxsGrpMetaData& grpMeta, std::vector<GrpIdCircleVet>& toVet) bool RsGxsNetService::canSendGrpId(const RsPeerId& sslId, RsGxsGrpMetaData& grpMeta, std::vector<GrpIdCircleVet>& toVet)
{ {
#ifdef NXS_NET_DEBUG
std::cerr << "RsGxsNetService::canSendGrpId()";
std::cerr << std::endl;
#endif
// first do the simple checks // first do the simple checks
uint8_t circleType = grpMeta.mCircleType; uint8_t circleType = grpMeta.mCircleType;
if(circleType == GXS_CIRCLE_TYPE_LOCAL) if(circleType == GXS_CIRCLE_TYPE_LOCAL)
{
#ifdef NXS_NET_DEBUG
std::cerr << "RsGxsNetService::canSendGrpId() LOCAL_CIRCLE, cannot send";
std::cerr << std::endl;
#endif
return false; return false;
}
if(circleType == GXS_CIRCLE_TYPE_PUBLIC) if(circleType == GXS_CIRCLE_TYPE_PUBLIC)
{
#ifdef NXS_NET_DEBUG
std::cerr << "RsGxsNetService::canSendGrpId() PUBLIC_CIRCLE, can send";
std::cerr << std::endl;
#endif
return true; return true;
}
const RsGxsCircleId& circleId = grpMeta.mCircleId; const RsGxsCircleId& circleId = grpMeta.mCircleId;
@ -2172,7 +2243,11 @@ bool RsGxsNetService::canSendGrpId(const RsPeerId& sslId, RsGxsGrpMetaData& grpM
{ {
if(mCircles->isLoaded(circleId)) if(mCircles->isLoaded(circleId))
{ {
const RsPgpId& pgpId = mNetMgr->getGPGId(sslId); #ifdef NXS_NET_DEBUG
std::cerr << "RsGxsNetService::canSendGrpId() EXTERNAL_CIRCLE, checking mCircles->canSend";
std::cerr << std::endl;
#endif
const RsPgpId& pgpId = mPgpUtils->getPGPId(sslId);
return mCircles->canSend(circleId, pgpId); return mCircles->canSend(circleId, pgpId);
} }
@ -2182,17 +2257,38 @@ bool RsGxsNetService::canSendGrpId(const RsPeerId& sslId, RsGxsGrpMetaData& grpM
if(circleType == GXS_CIRCLE_TYPE_YOUREYESONLY) if(circleType == GXS_CIRCLE_TYPE_YOUREYESONLY)
{ {
#ifdef NXS_NET_DEBUG
std::cerr << "RsGxsNetService::canSendGrpId() YOUREYESONLY, checking further";
std::cerr << std::endl;
#endif
// a non empty internal circle id means this // a non empty internal circle id means this
// is the personal circle owner // is the personal circle owner
if(!grpMeta.mInternalCircle.isNull()) if(!grpMeta.mInternalCircle.isNull())
{ {
const RsGxsCircleId& internalCircleId = grpMeta.mInternalCircle; const RsGxsCircleId& internalCircleId = grpMeta.mInternalCircle;
#ifdef NXS_NET_DEBUG
std::cerr << "RsGxsNetService::canSendGrpId() have mInternalCircle - we are Group creator";
std::cerr << std::endl;
std::cerr << "RsGxsNetService::canSendGrpId() mCircleId: " << grpMeta.mCircleId;
std::cerr << std::endl;
std::cerr << "RsGxsNetService::canSendGrpId() mInternalCircle: " << grpMeta.mInternalCircle;
std::cerr << std::endl;
#endif
if(mCircles->isLoaded(internalCircleId)) if(mCircles->isLoaded(internalCircleId))
{ {
const RsPgpId& pgpId = mNetMgr->getGPGId(sslId); #ifdef NXS_NET_DEBUG
std::cerr << "RsGxsNetService::canSendGrpId() circle Loaded - checking mCircles->canSend";
std::cerr << std::endl;
#endif
const RsPgpId& pgpId = mPgpUtils->getPGPId(sslId);
return mCircles->canSend(internalCircleId, pgpId); return mCircles->canSend(internalCircleId, pgpId);
} }
#ifdef NXS_NET_DEBUG
std::cerr << "RsGxsNetService::canSendGrpId() Circle Not Loaded - add to vetting";
std::cerr << std::endl;
#endif
toVet.push_back(GrpIdCircleVet(grpMeta.mGroupId, internalCircleId)); toVet.push_back(GrpIdCircleVet(grpMeta.mGroupId, internalCircleId));
return false; return false;
} }
@ -2200,12 +2296,28 @@ bool RsGxsNetService::canSendGrpId(const RsPeerId& sslId, RsGxsGrpMetaData& grpM
{ {
// an empty internal circle id means this peer can only // an empty internal circle id means this peer can only
// send circle related info from peer he received it // send circle related info from peer he received it
#ifdef NXS_NET_DEBUG
std::cerr << "RsGxsNetService::canSendGrpId() mInternalCircle not set, someone else's personal circle";
std::cerr << std::endl;
#endif
if(grpMeta.mOriginator == sslId) if(grpMeta.mOriginator == sslId)
{
#ifdef NXS_NET_DEBUG
std::cerr << "RsGxsNetService::canSendGrpId() Originator matches -> can send";
std::cerr << std::endl;
#endif
return true; return true;
}
else else
{
#ifdef NXS_NET_DEBUG
std::cerr << "RsGxsNetService::canSendGrpId() Originator doesn't match -> cannot send";
std::cerr << std::endl;
#endif
return false; return false;
} }
} }
}
return true; return true;
} }
@ -2323,6 +2435,11 @@ void RsGxsNetService::locked_pushMsgRespFromList(std::list<RsNxsItem*>& itemL, c
bool RsGxsNetService::canSendMsgIds(const std::vector<RsGxsMsgMetaData*>& msgMetas, bool RsGxsNetService::canSendMsgIds(const std::vector<RsGxsMsgMetaData*>& msgMetas,
const RsGxsGrpMetaData& grpMeta, const RsPeerId& sslId) const RsGxsGrpMetaData& grpMeta, const RsPeerId& sslId)
{ {
#ifdef NXS_NET_DEBUG
std::cerr << "RsGxsNetService::canSendMsgIds() CIRCLE VETTING";
std::cerr << std::endl;
#endif
// first do the simple checks // first do the simple checks
uint8_t circleType = grpMeta.mCircleType; uint8_t circleType = grpMeta.mCircleType;
@ -2338,7 +2455,7 @@ bool RsGxsNetService::canSendMsgIds(const std::vector<RsGxsMsgMetaData*>& msgMet
{ {
if(mCircles->isLoaded(circleId)) if(mCircles->isLoaded(circleId))
{ {
const RsPgpId& pgpId = mNetMgr->getGPGId(sslId); const RsPgpId& pgpId = mPgpUtils->getPGPId(sslId);
return mCircles->canSend(circleId, pgpId); return mCircles->canSend(circleId, pgpId);
} }
@ -2354,7 +2471,7 @@ bool RsGxsNetService::canSendMsgIds(const std::vector<RsGxsMsgMetaData*>& msgMet
} }
if(!toVet.empty()) if(!toVet.empty())
mPendingCircleVets.push_back(new MsgCircleIdsRequestVetting(mCircles, mNetMgr, toVet, grpMeta.mGroupId, mPendingCircleVets.push_back(new MsgCircleIdsRequestVetting(mCircles, mPgpUtils, toVet, grpMeta.mGroupId,
sslId, grpMeta.mCircleId)); sslId, grpMeta.mCircleId));
return false; return false;
@ -2369,7 +2486,7 @@ bool RsGxsNetService::canSendMsgIds(const std::vector<RsGxsMsgMetaData*>& msgMet
const RsGxsCircleId& internalCircleId = grpMeta.mInternalCircle; const RsGxsCircleId& internalCircleId = grpMeta.mInternalCircle;
if(mCircles->isLoaded(internalCircleId)) if(mCircles->isLoaded(internalCircleId))
{ {
const RsPgpId& pgpId = mNetMgr->getGPGId(sslId); const RsPgpId& pgpId = mPgpUtils->getPGPId(sslId);
return mCircles->canSend(internalCircleId, pgpId); return mCircles->canSend(internalCircleId, pgpId);
} }
@ -2385,7 +2502,8 @@ bool RsGxsNetService::canSendMsgIds(const std::vector<RsGxsMsgMetaData*>& msgMet
} }
if(!toVet.empty()) if(!toVet.empty())
mPendingCircleVets.push_back(new MsgCircleIdsRequestVetting(mCircles, mNetMgr, toVet, grpMeta.mGroupId, mPendingCircleVets.push_back(new MsgCircleIdsRequestVetting(mCircles, mPgpUtils,
toVet, grpMeta.mGroupId,
sslId, grpMeta.mCircleId)); sslId, grpMeta.mCircleId));
return false; return false;

View File

@ -46,6 +46,7 @@ typedef std::map<uint32_t, NxsTransaction*> TransactionIdMap;
/// to keep track of peers active transactions /// to keep track of peers active transactions
typedef std::map<RsPeerId, TransactionIdMap > TransactionsPeerMap; typedef std::map<RsPeerId, TransactionIdMap > TransactionsPeerMap;
class PgpAuxUtils;
/*! /*!
* This class implements the RsNetWorkExchangeService * This class implements the RsNetWorkExchangeService
@ -80,7 +81,9 @@ public:
RsNxsNetMgr *netMgr, RsNxsNetMgr *netMgr,
RsNxsObserver *nxsObs, // used to be = NULL. RsNxsObserver *nxsObs, // used to be = NULL.
const RsServiceInfo serviceInfo, const RsServiceInfo serviceInfo,
RsGixsReputation* reputations = NULL, RsGcxs* circles = NULL, bool grpAutoSync = true); RsGixsReputation* reputations = NULL, RsGcxs* circles = NULL,
PgpAuxUtils *pgpUtils = NULL,
bool grpAutoSync = true);
virtual ~RsGxsNetService(); virtual ~RsGxsNetService();
@ -429,6 +432,7 @@ private:
RsGcxs* mCircles; RsGcxs* mCircles;
RsGixsReputation* mReputations; RsGixsReputation* mReputations;
PgpAuxUtils *mPgpUtils;
bool mGrpAutoSync; bool mGrpAutoSync;
// need to be verfied // need to be verfied

View File

@ -25,7 +25,7 @@
#include "rsgxsnetutils.h" #include "rsgxsnetutils.h"
#include "pqi/p3servicecontrol.h" #include "pqi/p3servicecontrol.h"
#include "retroshare/rspeers.h" #include "pgp/pgpauxutils.h"
const time_t AuthorPending::EXPIRY_PERIOD_OFFSET = 30; // 30 seconds const time_t AuthorPending::EXPIRY_PERIOD_OFFSET = 30; // 30 seconds
@ -213,8 +213,8 @@ const int GrpCircleVetting::MSG_ID_RECV_PEND = 3;
GrpIdCircleVet::GrpIdCircleVet(const RsGxsGroupId& grpId, const RsGxsCircleId& circleId) GrpIdCircleVet::GrpIdCircleVet(const RsGxsGroupId& grpId, const RsGxsCircleId& circleId)
: mGroupId(grpId), mCircleId(circleId), mCleared(false) {} : mGroupId(grpId), mCircleId(circleId), mCleared(false) {}
GrpCircleVetting::GrpCircleVetting(RsGcxs* const circles, RsNxsNetMgr* const netMgr) GrpCircleVetting::GrpCircleVetting(RsGcxs* const circles, PgpAuxUtils *pgpUtils)
: mCircles(circles), mNetMgr(netMgr) {} : mCircles(circles), mPgpUtils(pgpUtils) {}
GrpCircleVetting::~GrpCircleVetting() {} GrpCircleVetting::~GrpCircleVetting() {}
@ -226,7 +226,7 @@ bool GrpCircleVetting::canSend(const SSLIdType& peerId, const RsGxsCircleId& cir
{ {
if(mCircles->isLoaded(circleId)) if(mCircles->isLoaded(circleId))
{ {
const RsPgpId& pgpId = mNetMgr->getGPGId(peerId); const RsPgpId& pgpId = mPgpUtils->getPGPId(peerId);
return mCircles->canSend(circleId, pgpId); return mCircles->canSend(circleId, pgpId);
} }
@ -236,8 +236,10 @@ bool GrpCircleVetting::canSend(const SSLIdType& peerId, const RsGxsCircleId& cir
} }
GrpCircleIdRequestVetting::GrpCircleIdRequestVetting( GrpCircleIdRequestVetting::GrpCircleIdRequestVetting(
RsGcxs* const circles, RsNxsNetMgr* const netMgr, std::vector<GrpIdCircleVet> grpCircleV, const RsPeerId& peerId) RsGcxs* const circles,
: GrpCircleVetting(circles, netMgr), mGrpCircleV(grpCircleV), mPeerId(peerId) {} PgpAuxUtils *pgpUtils,
std::vector<GrpIdCircleVet> grpCircleV, const RsPeerId& peerId)
: GrpCircleVetting(circles, pgpUtils), mGrpCircleV(grpCircleV), mPeerId(peerId) {}
bool GrpCircleIdRequestVetting::cleared() bool GrpCircleIdRequestVetting::cleared()
{ {
@ -274,10 +276,11 @@ MsgIdCircleVet::MsgIdCircleVet(const RsGxsMessageId& msgId,
: mMsgId(msgId), mAuthorId(authorId) { : mMsgId(msgId), mAuthorId(authorId) {
} }
MsgCircleIdsRequestVetting::MsgCircleIdsRequestVetting(RsGcxs* const circles, RsNxsNetMgr* const netMgr, MsgCircleIdsRequestVetting::MsgCircleIdsRequestVetting(RsGcxs* const circles,
PgpAuxUtils *pgpUtils,
std::vector<MsgIdCircleVet> msgs, const RsGxsGroupId& grpId, std::vector<MsgIdCircleVet> msgs, const RsGxsGroupId& grpId,
const RsPeerId& peerId, const RsGxsCircleId& circleId) const RsPeerId& peerId, const RsGxsCircleId& circleId)
: GrpCircleVetting(circles, netMgr), mMsgs(msgs), mGrpId(grpId), mPeerId(peerId), mCircleId(circleId) {} : GrpCircleVetting(circles, pgpUtils), mMsgs(msgs), mGrpId(grpId), mPeerId(peerId), mCircleId(circleId) {}
bool MsgCircleIdsRequestVetting::cleared() bool MsgCircleIdsRequestVetting::cleared()
{ {
@ -291,8 +294,4 @@ int MsgCircleIdsRequestVetting::getType() const
return MSG_ID_SEND_PEND; return MSG_ID_SEND_PEND;
} }
RsPgpId RsNxsNetMgrImpl::getGPGId(const RsPeerId& peerId) {
rsPeers->getGPGId(peerId);
}

View File

@ -32,6 +32,7 @@
#include "rsgixs.h" #include "rsgixs.h"
class p3ServiceControl; class p3ServiceControl;
class PgpAuxUtils;
/*! /*!
* This represents a transaction made * This represents a transaction made
@ -83,7 +84,6 @@ public:
virtual ~RsNxsNetMgr(){}; virtual ~RsNxsNetMgr(){};
virtual const RsPeerId& getOwnId() = 0; virtual const RsPeerId& getOwnId() = 0;
virtual void getOnlineList(const uint32_t serviceId, std::set<RsPeerId>& ssl_peers) = 0; virtual void getOnlineList(const uint32_t serviceId, std::set<RsPeerId>& ssl_peers) = 0;
virtual RsPgpId getGPGId(const RsPeerId& peerId) = 0;
}; };
@ -95,9 +95,8 @@ public:
RsNxsNetMgrImpl(p3ServiceControl* sc); RsNxsNetMgrImpl(p3ServiceControl* sc);
virtual ~RsNxsNetMgrImpl(){}; virtual ~RsNxsNetMgrImpl(){};
const RsPeerId& getOwnId(); virtual const RsPeerId& getOwnId();
void getOnlineList(const uint32_t serviceId, std::set<RsPeerId>& ssl_peers); virtual void getOnlineList(const uint32_t serviceId, std::set<RsPeerId>& ssl_peers);
RsPgpId getGPGId(const RsPeerId& peerId);
private: private:
@ -245,7 +244,7 @@ public:
static const int MSG_ID_RECV_PEND; static const int MSG_ID_RECV_PEND;
GrpCircleVetting(RsGcxs* const circles, RsNxsNetMgr* const netMgr); GrpCircleVetting(RsGcxs* const circles, PgpAuxUtils *pgpUtils);
virtual ~GrpCircleVetting(); virtual ~GrpCircleVetting();
bool expired(); bool expired();
virtual int getType() const = 0; virtual int getType() const = 0;
@ -257,14 +256,16 @@ protected:
private: private:
RsGcxs* const mCircles; RsGcxs* const mCircles;
RsNxsNetMgr* const mNetMgr; PgpAuxUtils *mPgpUtils;
time_t mTimeStamp; time_t mTimeStamp;
}; };
class GrpCircleIdRequestVetting : public GrpCircleVetting class GrpCircleIdRequestVetting : public GrpCircleVetting
{ {
public: public:
GrpCircleIdRequestVetting(RsGcxs* const circles, RsNxsNetMgr* const netMgr, std::vector<GrpIdCircleVet> mGrpCircleV, const RsPeerId& peerId); GrpCircleIdRequestVetting(RsGcxs* const circles,
PgpAuxUtils *pgpUtils,
std::vector<GrpIdCircleVet> mGrpCircleV, const RsPeerId& peerId);
bool cleared(); bool cleared();
int getType() const; int getType() const;
std::vector<GrpIdCircleVet> mGrpCircleV; std::vector<GrpIdCircleVet> mGrpCircleV;
@ -274,7 +275,9 @@ public:
class MsgCircleIdsRequestVetting : public GrpCircleVetting class MsgCircleIdsRequestVetting : public GrpCircleVetting
{ {
public: public:
MsgCircleIdsRequestVetting(RsGcxs* const circles, RsNxsNetMgr* const netMgr, std::vector<MsgIdCircleVet> msgs, const RsGxsGroupId& grpId, MsgCircleIdsRequestVetting(RsGcxs* const circles,
PgpAuxUtils *auxUtils,
std::vector<MsgIdCircleVet> msgs, const RsGxsGroupId& grpId,
const RsPeerId& peerId, const RsGxsCircleId& circleId); const RsPeerId& peerId, const RsGxsCircleId& circleId);
bool cleared(); bool cleared();
int getType() const; int getType() const;

View File

@ -332,6 +332,7 @@ HEADERS += pqi/authssl.h \
pgp/pgpkeyutil.h \ pgp/pgpkeyutil.h \
pgp/rsaes.h \ pgp/rsaes.h \
pgp/rscertificate.h \ pgp/rscertificate.h \
pgp/pgpauxutils.h \
pqi/p3cfgmgr.h \ pqi/p3cfgmgr.h \
pqi/p3peermgr.h \ pqi/p3peermgr.h \
pqi/p3linkmgr.h \ pqi/p3linkmgr.h \
@ -482,6 +483,7 @@ SOURCES += pqi/authgpg.cc \
pgp/pgphandler.cc \ pgp/pgphandler.cc \
pgp/pgpkeyutil.cc \ pgp/pgpkeyutil.cc \
pgp/rscertificate.cc \ pgp/rscertificate.cc \
pgp/pgpauxutils.cc \
pqi/p3cfgmgr.cc \ pqi/p3cfgmgr.cc \
pqi/p3peermgr.cc \ pqi/p3peermgr.cc \
pqi/p3linkmgr.cc \ pqi/p3linkmgr.cc \

View File

@ -0,0 +1,79 @@
/*
* libretroshare/src/pgp: pgpauxutils.cc
*
* PGP interface for RetroShare.
*
* Copyright 2014-2014 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
* License Version 2.1 as published by the Free Software Foundation.
*
* 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".
*
*/
#include "pgp/pgpauxutils.h"
#include "pqi/authgpg.h"
#include "rsserver/p3face.h"
#include "retroshare/rsiface.h"
#include "retroshare/rspeers.h"
PgpAuxUtilsImpl::PgpAuxUtilsImpl()
{
return;
}
const RsPgpId& PgpAuxUtilsImpl::getPGPOwnId()
{
return AuthGPG::getAuthGPG()->getGPGOwnId();
}
RsPgpId PgpAuxUtilsImpl::getPGPId(const RsPeerId& sslid)
{
return rsPeers->getGPGId(sslid);
}
bool PgpAuxUtilsImpl::getKeyFingerprint(const RsPgpId& id,PGPFingerprintType& fp) const
{
return AuthGPG::getAuthGPG()->getKeyFingerprint(id, fp);
}
bool PgpAuxUtilsImpl::VerifySignBin(const void *data,
uint32_t len,
unsigned char *sign,
unsigned int signlen,
const PGPFingerprintType& withfingerprint)
{
return AuthGPG::getAuthGPG()->VerifySignBin(data, len, sign, signlen, withfingerprint);
}
bool PgpAuxUtilsImpl::getGPGAllList(std::list<RsPgpId> &ids)
{
return AuthGPG::getAuthGPG()->getGPGAllList(ids);
}
bool PgpAuxUtilsImpl::askForDeferredSelfSignature(const void *data,
const uint32_t len,
unsigned char *sign,
unsigned int *signlen,
int& signature_result )
{
return RsServer::notify()->askForDeferredSelfSignature(data, len, sign, signlen, signature_result);
}

View File

@ -0,0 +1,65 @@
/*
* libretroshare/src/pgp: pgpauxutils.h
*
* PGP interface for RetroShare.
*
* Copyright 2014-2014 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
* License Version 2.1 as published by the Free Software Foundation.
*
* 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".
*
*/
#pragma once
#include "retroshare/rsids.h"
#include "retroshare/rstypes.h"
/* This is a small collection of PGP functions that are widely used in libretroshare.
* This interface class allows these functions to be easily mocked for testing.
*/
class PgpAuxUtils
{
public:
virtual const RsPgpId &getPGPOwnId() = 0;
virtual RsPgpId getPGPId(const RsPeerId& sslid) = 0;
virtual bool getGPGAllList(std::list<RsPgpId> &ids) = 0;
virtual bool getKeyFingerprint(const RsPgpId& id,PGPFingerprintType& fp) const = 0;
virtual bool VerifySignBin(const void *data, uint32_t len, unsigned char *sign, unsigned int signlen, const PGPFingerprintType& withfingerprint) = 0;
virtual bool askForDeferredSelfSignature(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen,int& signature_result ) = 0;
};
class PgpAuxUtilsImpl: public PgpAuxUtils
{
public:
PgpAuxUtilsImpl();
virtual const RsPgpId &getPGPOwnId();
virtual RsPgpId getPGPId(const RsPeerId& sslid);
virtual bool getKeyFingerprint(const RsPgpId& id,PGPFingerprintType& fp) const;
virtual bool VerifySignBin(const void *data, uint32_t len, unsigned char *sign, unsigned int signlen, const PGPFingerprintType& withfingerprint);
virtual bool getGPGAllList(std::list<RsPgpId> &ids);
virtual bool askForDeferredSelfSignature(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen,int& signature_result );
};

View File

@ -29,8 +29,9 @@
#include "serialiser/rsserial.h" #include "serialiser/rsserial.h"
/*******************************/ /*******************************/
// #define SERVICECONTROL_DEBUG // #define SERVICECONTROL_DEBUG 1
/*******************************/ /*******************************/
#define SERVICECONTROL_DEBUG 1
RsServiceControl *rsServiceControl = NULL; RsServiceControl *rsServiceControl = NULL;
@ -64,10 +65,12 @@ bool p3ServiceControl::registerService(const RsServiceInfo &info, bool defaultOn
/* sanity check ServiceInfo */ /* sanity check ServiceInfo */
mOwnServices[info.mServiceType] = info; mOwnServices[info.mServiceType] = info;
#ifdef SERVICECONTROL_DEBUG
std::cerr << "p3ServiceControl::registerService() Registered ServiceID: " << info.mServiceType; std::cerr << "p3ServiceControl::registerService() Registered ServiceID: " << info.mServiceType;
std::cerr << std::endl; std::cerr << std::endl;
std::cerr << "p3ServiceControl::registerService() ServiceName: " << info.mServiceName; std::cerr << "p3ServiceControl::registerService() ServiceName: " << info.mServiceName;
std::cerr << std::endl; std::cerr << std::endl;
#endif
/* create default permissions for this service /* create default permissions for this service
@ -91,8 +94,10 @@ bool p3ServiceControl::deregisterService(uint32_t serviceId)
return false; return false;
} }
#ifdef SERVICECONTROL_DEBUG
std::cerr << "p3ServiceControl::deregisterService() Removed ServiceID: " << serviceId; std::cerr << "p3ServiceControl::deregisterService() Removed ServiceID: " << serviceId;
std::cerr << std::endl; std::cerr << std::endl;
#endif
mOwnServices.erase(it); mOwnServices.erase(it);
return true; return true;
} }
@ -103,9 +108,11 @@ bool p3ServiceControl::registerServiceMonitor(pqiServiceMonitor *monitor, uint32
{ {
RsStackMutex stack(mMonitorMtx); /***** LOCK STACK MUTEX ****/ RsStackMutex stack(mMonitorMtx); /***** LOCK STACK MUTEX ****/
#ifdef SERVICECONTROL_DEBUG
std::cerr << "p3ServiceControl::registerServiceMonitor() for ServiceId: "; std::cerr << "p3ServiceControl::registerServiceMonitor() for ServiceId: ";
std::cerr << serviceId; std::cerr << serviceId;
std::cerr << std::endl; std::cerr << std::endl;
#endif
mMonitors.insert(std::make_pair(serviceId, monitor)); mMonitors.insert(std::make_pair(serviceId, monitor));
return true; return true;
@ -116,8 +123,10 @@ bool p3ServiceControl::deregisterServiceMonitor(pqiServiceMonitor *monitor)
{ {
RsStackMutex stack(mMonitorMtx); /***** LOCK STACK MUTEX ****/ RsStackMutex stack(mMonitorMtx); /***** LOCK STACK MUTEX ****/
#ifdef SERVICECONTROL_DEBUG
std::cerr << "p3ServiceControl::deregisterServiceMonitor()"; std::cerr << "p3ServiceControl::deregisterServiceMonitor()";
std::cerr << std::endl; std::cerr << std::endl;
#endif
std::multimap<uint32_t, pqiServiceMonitor *>::iterator it; std::multimap<uint32_t, pqiServiceMonitor *>::iterator it;
for(it = mMonitors.begin(); it != mMonitors.end(); ) for(it = mMonitors.begin(); it != mMonitors.end(); )
@ -353,15 +362,21 @@ bool p3ServiceControl::checkFilter(uint32_t serviceId, const RsPeerId &peerId)
it = mOwnServices.find(serviceId); it = mOwnServices.find(serviceId);
if (it != mOwnServices.end()) if (it != mOwnServices.end())
{ {
#ifdef SERVICECONTROL_DEBUG
std::cerr << " ServiceName: " << it->second.mServiceName; std::cerr << " ServiceName: " << it->second.mServiceName;
#endif
} }
else else
{ {
#ifdef SERVICECONTROL_DEBUG
std::cerr << " ServiceName: Unknown! "; std::cerr << " ServiceName: Unknown! ";
#endif
} }
#ifdef SERVICECONTROL_DEBUG
std::cerr << " PeerId: " << peerId.toStdString(); std::cerr << " PeerId: " << peerId.toStdString();
std::cerr << std::endl; std::cerr << std::endl;
#endif
// must allow ServiceInfo through, or we have nothing! // must allow ServiceInfo through, or we have nothing!
#define FULLID_SERVICEINFO ((((uint32_t) RS_PKT_VERSION_SERVICE) << 24) + ((RS_SERVICE_TYPE_SERVICEINFO) << 8)) #define FULLID_SERVICEINFO ((((uint32_t) RS_PKT_VERSION_SERVICE) << 24) + ((RS_SERVICE_TYPE_SERVICEINFO) << 8))
@ -369,8 +384,10 @@ bool p3ServiceControl::checkFilter(uint32_t serviceId, const RsPeerId &peerId)
//if (serviceId == RS_SERVICE_TYPE_SERVICEINFO) //if (serviceId == RS_SERVICE_TYPE_SERVICEINFO)
if (serviceId == FULLID_SERVICEINFO) if (serviceId == FULLID_SERVICEINFO)
{ {
#ifdef SERVICECONTROL_DEBUG
std::cerr << "p3ServiceControl::checkFilter() Allowed SERVICEINFO"; std::cerr << "p3ServiceControl::checkFilter() Allowed SERVICEINFO";
std::cerr << std::endl; std::cerr << std::endl;
#endif
return true; return true;
} }
@ -379,22 +396,28 @@ bool p3ServiceControl::checkFilter(uint32_t serviceId, const RsPeerId &peerId)
pit = mPeerFilterMap.find(peerId); pit = mPeerFilterMap.find(peerId);
if (pit == mPeerFilterMap.end()) if (pit == mPeerFilterMap.end())
{ {
#ifdef SERVICECONTROL_DEBUG
std::cerr << "p3ServiceControl::checkFilter() Denied No PeerId"; std::cerr << "p3ServiceControl::checkFilter() Denied No PeerId";
std::cerr << std::endl; std::cerr << std::endl;
#endif
return false; return false;
} }
if (pit->second.mDenyAll) if (pit->second.mDenyAll)
{ {
#ifdef SERVICECONTROL_DEBUG
std::cerr << "p3ServiceControl::checkFilter() Denied Peer.DenyAll"; std::cerr << "p3ServiceControl::checkFilter() Denied Peer.DenyAll";
std::cerr << std::endl; std::cerr << std::endl;
#endif
return false; return false;
} }
if (pit->second.mAllowAll) if (pit->second.mAllowAll)
{ {
#ifdef SERVICECONTROL_DEBUG
std::cerr << "p3ServiceControl::checkFilter() Allowed Peer.AllowAll"; std::cerr << "p3ServiceControl::checkFilter() Allowed Peer.AllowAll";
std::cerr << std::endl; std::cerr << std::endl;
#endif
return true; return true;
} }
@ -402,8 +425,10 @@ bool p3ServiceControl::checkFilter(uint32_t serviceId, const RsPeerId &peerId)
sit = pit->second.mAllowedServices.find(serviceId); sit = pit->second.mAllowedServices.find(serviceId);
if (sit == pit->second.mAllowedServices.end()) if (sit == pit->second.mAllowedServices.end())
{ {
#ifdef SERVICECONTROL_DEBUG
std::cerr << "p3ServiceControl::checkFilter() Denied !Peer.find(serviceId)"; std::cerr << "p3ServiceControl::checkFilter() Denied !Peer.find(serviceId)";
std::cerr << std::endl; std::cerr << std::endl;
#endif
return false; return false;
} }
#ifdef SERVICECONTROL_DEBUG #ifdef SERVICECONTROL_DEBUG
@ -434,6 +459,7 @@ bool ServiceInfoCompatible(const RsServiceInfo &info1, const RsServiceInfo &info
if ((info1.mServiceType != info2.mServiceType) || if ((info1.mServiceType != info2.mServiceType) ||
(info1.mServiceName != info2.mServiceName)) (info1.mServiceName != info2.mServiceName))
{ {
#ifdef SERVICECONTROL_DEBUG
std::cerr << "servicesCompatible: Type/Name mismatch"; std::cerr << "servicesCompatible: Type/Name mismatch";
std::cerr << std::endl; std::cerr << std::endl;
std::cerr << "Info1 ID: " << info1.mServiceType; std::cerr << "Info1 ID: " << info1.mServiceType;
@ -442,6 +468,7 @@ bool ServiceInfoCompatible(const RsServiceInfo &info1, const RsServiceInfo &info
std::cerr << "Info2 ID: " << info2.mServiceType; std::cerr << "Info2 ID: " << info2.mServiceType;
std::cerr << " " << info2.mServiceName; std::cerr << " " << info2.mServiceName;
std::cerr << std::endl; std::cerr << std::endl;
#endif
return false; return false;
} }
@ -541,8 +568,10 @@ bool p3ServiceControl::updateFilterByPeer_locked(const RsPeerId &peerId)
it = mServicesProvided.find(peerId); it = mServicesProvided.find(peerId);
if (it == mServicesProvided.end()) if (it == mServicesProvided.end())
{ {
#ifdef SERVICECONTROL_DEBUG
std::cerr << "p3ServiceControl::updateFilterByPeer_locked() Empty ... Clearing"; std::cerr << "p3ServiceControl::updateFilterByPeer_locked() Empty ... Clearing";
std::cerr << std::endl; std::cerr << std::endl;
#endif
// empty, remove... // empty, remove...
recordFilterChanges_locked(peerId, originalFilter, peerFilter); recordFilterChanges_locked(peerId, originalFilter, peerFilter);
@ -573,16 +602,20 @@ bool p3ServiceControl::updateFilterByPeer_locked(const RsPeerId &peerId)
{ {
if (oit->first == tit->first) if (oit->first == tit->first)
{ {
#ifdef SERVICECONTROL_DEBUG
std::cerr << "\tChecking Matching Service ID: " << oit->first; std::cerr << "\tChecking Matching Service ID: " << oit->first;
std::cerr << std::endl; std::cerr << std::endl;
#endif
/* match of service IDs */ /* match of service IDs */
/* check if compatible */ /* check if compatible */
if (ServiceInfoCompatible(oit->second, tit->second)) if (ServiceInfoCompatible(oit->second, tit->second))
{ {
if (peerHasPermissionForService_locked(peerId, oit->first)) if (peerHasPermissionForService_locked(peerId, oit->first))
{ {
#ifdef SERVICECONTROL_DEBUG
std::cerr << "\t\tMatched Service ID: " << oit->first; std::cerr << "\t\tMatched Service ID: " << oit->first;
std::cerr << std::endl; std::cerr << std::endl;
#endif
peerFilter.mAllowedServices.insert(oit->first); peerFilter.mAllowedServices.insert(oit->first);
} }
} }
@ -593,14 +626,18 @@ bool p3ServiceControl::updateFilterByPeer_locked(const RsPeerId &peerId)
{ {
if (oit->first < tit->first) if (oit->first < tit->first)
{ {
#ifdef SERVICECONTROL_DEBUG
std::cerr << "\tSkipping Only Own Service ID: " << oit->first; std::cerr << "\tSkipping Only Own Service ID: " << oit->first;
std::cerr << std::endl; std::cerr << std::endl;
#endif
oit++; oit++;
} }
else else
{ {
#ifdef SERVICECONTROL_DEBUG
std::cerr << "\tSkipping Only Peer Service ID: " << tit->first; std::cerr << "\tSkipping Only Peer Service ID: " << tit->first;
std::cerr << std::endl; std::cerr << std::endl;
#endif
tit++; tit++;
} }
} }
@ -623,8 +660,10 @@ bool p3ServiceControl::updateFilterByPeer_locked(const RsPeerId &peerId)
// update or remove. // update or remove.
if (peerFilter.mDenyAll) if (peerFilter.mDenyAll)
{ {
#ifdef SERVICECONTROL_DEBUG
std::cerr << "p3ServiceControl::updateFilterByPeer_locked() Empty(2) ... Clearing"; std::cerr << "p3ServiceControl::updateFilterByPeer_locked() Empty(2) ... Clearing";
std::cerr << std::endl; std::cerr << std::endl;
#endif
if (fit != mPeerFilterMap.end()) if (fit != mPeerFilterMap.end())
{ {
@ -633,8 +672,10 @@ bool p3ServiceControl::updateFilterByPeer_locked(const RsPeerId &peerId)
} }
else else
{ {
#ifdef SERVICECONTROL_DEBUG
std::cerr << "p3ServiceControl::updateFilterByPeer_locked() Installing PeerFilter"; std::cerr << "p3ServiceControl::updateFilterByPeer_locked() Installing PeerFilter";
std::cerr << std::endl; std::cerr << std::endl;
#endif
mPeerFilterMap[peerId] = peerFilter; mPeerFilterMap[peerId] = peerFilter;
} }
recordFilterChanges_locked(peerId, originalFilter, peerFilter); recordFilterChanges_locked(peerId, originalFilter, peerFilter);
@ -644,6 +685,7 @@ bool p3ServiceControl::updateFilterByPeer_locked(const RsPeerId &peerId)
void p3ServiceControl::recordFilterChanges_locked(const RsPeerId &peerId, void p3ServiceControl::recordFilterChanges_locked(const RsPeerId &peerId,
ServicePeerFilter &originalFilter, ServicePeerFilter &updatedFilter) ServicePeerFilter &originalFilter, ServicePeerFilter &updatedFilter)
{ {
#ifdef SERVICECONTROL_DEBUG
std::cerr << "p3ServiceControl::recordFilterChanges_locked()"; std::cerr << "p3ServiceControl::recordFilterChanges_locked()";
std::cerr << std::endl; std::cerr << std::endl;
std::cerr << "PeerId: " << peerId.toStdString(); std::cerr << "PeerId: " << peerId.toStdString();
@ -652,6 +694,7 @@ void p3ServiceControl::recordFilterChanges_locked(const RsPeerId &peerId,
std::cerr << std::endl; std::cerr << std::endl;
std::cerr << "UpdatedFilter: " << updatedFilter; std::cerr << "UpdatedFilter: " << updatedFilter;
std::cerr << std::endl; std::cerr << std::endl;
#endif
/* find differences */ /* find differences */
std::map<uint32_t, bool> changes; std::map<uint32_t, bool> changes;
@ -665,8 +708,10 @@ void p3ServiceControl::recordFilterChanges_locked(const RsPeerId &peerId,
{ {
if (*it1 < *it2) if (*it1 < *it2)
{ {
#ifdef SERVICECONTROL_DEBUG
std::cerr << "Removed Service: " << *it1; std::cerr << "Removed Service: " << *it1;
std::cerr << std::endl; std::cerr << std::endl;
#endif
// removal // removal
changes[*it1] = false; changes[*it1] = false;
filterChangeRemoved_locked(peerId, *it1); filterChangeRemoved_locked(peerId, *it1);
@ -674,8 +719,10 @@ void p3ServiceControl::recordFilterChanges_locked(const RsPeerId &peerId,
} }
else if (*it2 < *it1) else if (*it2 < *it1)
{ {
#ifdef SERVICECONTROL_DEBUG
std::cerr << "Added Service: " << *it2; std::cerr << "Added Service: " << *it2;
std::cerr << std::endl; std::cerr << std::endl;
#endif
// addition. // addition.
filterChangeAdded_locked(peerId, *it2); filterChangeAdded_locked(peerId, *it2);
changes[*it2] = true; changes[*it2] = true;
@ -691,8 +738,10 @@ void p3ServiceControl::recordFilterChanges_locked(const RsPeerId &peerId,
// Handle the unfinished Set. // Handle the unfinished Set.
for(; it1 != eit1; it1++) for(; it1 != eit1; it1++)
{ {
#ifdef SERVICECONTROL_DEBUG
std::cerr << "Removed Service: " << *it1; std::cerr << "Removed Service: " << *it1;
std::cerr << std::endl; std::cerr << std::endl;
#endif
// removal // removal
changes[*it1] = false; changes[*it1] = false;
filterChangeRemoved_locked(peerId, *it1); filterChangeRemoved_locked(peerId, *it1);
@ -700,8 +749,10 @@ void p3ServiceControl::recordFilterChanges_locked(const RsPeerId &peerId,
for(; it2 != eit2; it2++) for(; it2 != eit2; it2++)
{ {
#ifdef SERVICECONTROL_DEBUG
std::cerr << "Added Service: " << *it2; std::cerr << "Added Service: " << *it2;
std::cerr << std::endl; std::cerr << std::endl;
#endif
// addition. // addition.
changes[*it2] = true; changes[*it2] = true;
filterChangeAdded_locked(peerId, *it2); filterChangeAdded_locked(peerId, *it2);
@ -745,8 +796,10 @@ void p3ServiceControl::removePeer(const RsPeerId &peerId)
fit = mPeerFilterMap.find(peerId); fit = mPeerFilterMap.find(peerId);
if (fit != mPeerFilterMap.end()) if (fit != mPeerFilterMap.end())
{ {
#ifdef SERVICECONTROL_DEBUG
std::cerr << "p3ServiceControl::removePeer() clearing mPeerFilterMap"; std::cerr << "p3ServiceControl::removePeer() clearing mPeerFilterMap";
std::cerr << std::endl; std::cerr << std::endl;
#endif
hadFilter = true; hadFilter = true;
originalFilter = fit->second; originalFilter = fit->second;
@ -754,8 +807,10 @@ void p3ServiceControl::removePeer(const RsPeerId &peerId)
} }
else else
{ {
#ifdef SERVICECONTROL_DEBUG
std::cerr << "p3ServiceControl::removePeer() Nothing in mPeerFilterMap"; std::cerr << "p3ServiceControl::removePeer() Nothing in mPeerFilterMap";
std::cerr << std::endl; std::cerr << std::endl;
#endif
} }
} }
@ -764,15 +819,19 @@ void p3ServiceControl::removePeer(const RsPeerId &peerId)
sit = mServicesProvided.find(peerId); sit = mServicesProvided.find(peerId);
if (sit != mServicesProvided.end()) if (sit != mServicesProvided.end())
{ {
#ifdef SERVICECONTROL_DEBUG
std::cerr << "p3ServiceControl::removePeer() clearing mServicesProvided"; std::cerr << "p3ServiceControl::removePeer() clearing mServicesProvided";
std::cerr << std::endl; std::cerr << std::endl;
#endif
mServicesProvided.erase(sit); mServicesProvided.erase(sit);
} }
else else
{ {
#ifdef SERVICECONTROL_DEBUG
std::cerr << "p3ServiceControl::removePeer() Nothing in mServicesProvided"; std::cerr << "p3ServiceControl::removePeer() Nothing in mServicesProvided";
std::cerr << std::endl; std::cerr << std::endl;
#endif
} }
} }
@ -790,9 +849,11 @@ void p3ServiceControl::removePeer(const RsPeerId &peerId)
void p3ServiceControl::filterChangeRemoved_locked(const RsPeerId &peerId, uint32_t serviceId) void p3ServiceControl::filterChangeRemoved_locked(const RsPeerId &peerId, uint32_t serviceId)
{ {
#ifdef SERVICECONTROL_DEBUG
std::cerr << "p3ServiceControl::filterChangeRemoved_locked(" << peerId.toStdString(); std::cerr << "p3ServiceControl::filterChangeRemoved_locked(" << peerId.toStdString();
std::cerr << ", " << serviceId << ")"; std::cerr << ", " << serviceId << ")";
std::cerr << std::endl; std::cerr << std::endl;
#endif
std::map<uint32_t, std::set<RsPeerId> >::iterator mit; std::map<uint32_t, std::set<RsPeerId> >::iterator mit;
@ -819,9 +880,11 @@ void p3ServiceControl::filterChangeRemoved_locked(const RsPeerId &peerId, uint32
void p3ServiceControl::filterChangeAdded_locked(const RsPeerId &peerId, uint32_t serviceId) void p3ServiceControl::filterChangeAdded_locked(const RsPeerId &peerId, uint32_t serviceId)
{ {
#ifdef SERVICECONTROL_DEBUG
std::cerr << "p3ServiceControl::filterChangeAdded_locked(" << peerId.toStdString(); std::cerr << "p3ServiceControl::filterChangeAdded_locked(" << peerId.toStdString();
std::cerr << ", " << serviceId << ")"; std::cerr << ", " << serviceId << ")";
std::cerr << std::endl; std::cerr << std::endl;
#endif
std::map<uint32_t, std::set<RsPeerId> >::iterator mit; std::map<uint32_t, std::set<RsPeerId> >::iterator mit;
@ -928,11 +991,13 @@ void p3ServiceControl::statusChange(const std::list<pqipeer> &plist)
std::list<pqipeer>::const_iterator pit; std::list<pqipeer>::const_iterator pit;
for(pit = plist.begin(); pit != plist.end(); pit++) for(pit = plist.begin(); pit != plist.end(); pit++)
{ {
#ifdef SERVICECONTROL_DEBUG
std::cerr << "p3ServiceControl::statusChange() for peer: "; std::cerr << "p3ServiceControl::statusChange() for peer: ";
std::cerr << " peer: " << (pit->id).toStdString(); std::cerr << " peer: " << (pit->id).toStdString();
std::cerr << " state: " << pit->state; std::cerr << " state: " << pit->state;
std::cerr << " actions: " << pit->actions; std::cerr << " actions: " << pit->actions;
std::cerr << std::endl; std::cerr << std::endl;
#endif
if (pit->state & RS_PEER_S_FRIEND) if (pit->state & RS_PEER_S_FRIEND)
{ {
// Connected / Disconnected. (interal actions). // Connected / Disconnected. (interal actions).
@ -1035,8 +1100,10 @@ void p3ServiceControl::notifyAboutFriends()
{ {
return; return;
} }
#ifdef SERVICECONTROL_DEBUG
std::cerr << "p3ServiceControl::notifyAboutFriends(): Something has changed!"; std::cerr << "p3ServiceControl::notifyAboutFriends(): Something has changed!";
std::cerr << std::endl; std::cerr << std::endl;
#endif
mFriendNotifications.swap(friendNotifications); mFriendNotifications.swap(friendNotifications);
} }
@ -1064,8 +1131,10 @@ void p3ServiceControl::notifyServices()
return; return;
} }
#ifdef SERVICECONTROL_DEBUG
std::cerr << "p3ServiceControl::notifyServices()"; std::cerr << "p3ServiceControl::notifyServices()";
std::cerr << std::endl; std::cerr << std::endl;
#endif
mNotifications.swap(notifications); mNotifications.swap(notifications);
} }
@ -1077,16 +1146,20 @@ void p3ServiceControl::notifyServices()
std::multimap<uint32_t, pqiServiceMonitor *>::const_iterator sit, eit; std::multimap<uint32_t, pqiServiceMonitor *>::const_iterator sit, eit;
for(it = notifications.begin(); it != notifications.end(); it++) for(it = notifications.begin(); it != notifications.end(); it++)
{ {
#ifdef SERVICECONTROL_DEBUG
std::cerr << "p3ServiceControl::notifyServices(): Notifications for Service: " << it->first; std::cerr << "p3ServiceControl::notifyServices(): Notifications for Service: " << it->first;
std::cerr << std::endl; std::cerr << std::endl;
#endif
sit = mMonitors.lower_bound(it->first); sit = mMonitors.lower_bound(it->first);
eit = mMonitors.upper_bound(it->first); eit = mMonitors.upper_bound(it->first);
if (sit == eit) if (sit == eit)
{ {
/* nothing to notify - skip */ /* nothing to notify - skip */
#ifdef SERVICECONTROL_DEBUG
std::cerr << "p3ServiceControl::notifyServices(): Noone Monitoring ... skipping"; std::cerr << "p3ServiceControl::notifyServices(): Noone Monitoring ... skipping";
std::cerr << std::endl; std::cerr << std::endl;
#endif
continue; continue;
} }
@ -1102,8 +1175,10 @@ void p3ServiceControl::notifyServices()
peers.push_back(peer); peers.push_back(peer);
#ifdef SERVICECONTROL_DEBUG
std::cerr << "p3ServiceControl::notifyServices(): Peer: " << *pit << " CONNECTED"; std::cerr << "p3ServiceControl::notifyServices(): Peer: " << *pit << " CONNECTED";
std::cerr << std::endl; std::cerr << std::endl;
#endif
} }
for(pit = it->second.mRemoved.begin(); for(pit = it->second.mRemoved.begin();
@ -1115,14 +1190,18 @@ void p3ServiceControl::notifyServices()
peers.push_back(peer); peers.push_back(peer);
#ifdef SERVICECONTROL_DEBUG
std::cerr << "p3ServiceControl::notifyServices(): Peer: " << *pit << " DISCONNECTED"; std::cerr << "p3ServiceControl::notifyServices(): Peer: " << *pit << " DISCONNECTED";
std::cerr << std::endl; std::cerr << std::endl;
#endif
} }
for(; sit != eit; sit++) for(; sit != eit; sit++)
{ {
#ifdef SERVICECONTROL_DEBUG
std::cerr << "p3ServiceControl::notifyServices(): Sending to Monitoring Service"; std::cerr << "p3ServiceControl::notifyServices(): Sending to Monitoring Service";
std::cerr << std::endl; std::cerr << std::endl;
#endif
sit->second->statusChange(peers); sit->second->statusChange(peers);
} }

View File

@ -89,14 +89,15 @@ bool p3ServiceServer::recvItem(RsRawItem *item)
RsStackMutex stack(srvMtx); /********* LOCKED *********/ RsStackMutex stack(srvMtx); /********* LOCKED *********/
#ifdef SERVICE_DEBUG #ifdef SERVICE_DEBUG
pqioutput(PQL_DEBUG_BASIC, pqiservicezone, std::cerr << "p3ServiceServer::incoming()";
"p3ServiceServer::incoming()"); std::cerr << std::endl;
{ {
std::string out; std::string out;
rs_sprintf(out, "p3ServiceServer::incoming() PacketId: %x\nLooking for Service: %x\nItem:\n", item -> PacketId(), (item -> PacketId() & 0xffffff00)); rs_sprintf(out, "p3ServiceServer::incoming() PacketId: %x\nLooking for Service: %x\nItem:\n", item -> PacketId(), (item -> PacketId() & 0xffffff00));
item -> print_string(out); item -> print_string(out);
pqioutput(PQL_DEBUG_BASIC, pqiservicezone, out); std::cerr << out;
std::cerr << std::endl;
} }
#endif #endif
@ -115,8 +116,8 @@ bool p3ServiceServer::recvItem(RsRawItem *item)
if (it == services.end()) if (it == services.end())
{ {
#ifdef SERVICE_DEBUG #ifdef SERVICE_DEBUG
pqioutput(PQL_DEBUG_BASIC, pqiservicezone, std::cerr << "p3ServiceServer::incoming() Service: No Service - deleting";
"p3ServiceServer::incoming() Service: No Service - deleting"); std::cerr << std::endl;
#endif #endif
delete item; delete item;
return false; return false;
@ -124,9 +125,8 @@ bool p3ServiceServer::recvItem(RsRawItem *item)
{ {
#ifdef SERVICE_DEBUG #ifdef SERVICE_DEBUG
std::string out; std::cerr << "p3ServiceServer::incoming() Sending to : " << (void *) it -> second;
rs_sprintf(out, "p3ServiceServer::incoming() Sending to %p", it -> second); std::cerr << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqiservicezone, out);
#endif #endif
return (it->second) -> recv(item); return (it->second) -> recv(item);
@ -143,7 +143,7 @@ bool p3ServiceServer::sendItem(RsRawItem *item)
#ifdef SERVICE_DEBUG #ifdef SERVICE_DEBUG
std::cerr << "p3ServiceServer::sendItem()"; std::cerr << "p3ServiceServer::sendItem()";
std::cerr << std::endl; std::cerr << std::endl;
item -> print_string(out); item -> print(std::cerr);
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
if (!item) if (!item)

View File

@ -883,6 +883,7 @@ RsGRouter *rsGRouter = NULL ;
#include "gxs/rsgxsnetservice.h" #include "gxs/rsgxsnetservice.h"
#include "retroshare/rsgxsflags.h" #include "retroshare/rsgxsflags.h"
#include "pgp/pgpauxutils.h"
#include "services/p3idservice.h" #include "services/p3idservice.h"
#include "services/p3gxscircles.h" #include "services/p3gxscircles.h"
#include "services/p3wiki.h" #include "services/p3wiki.h"
@ -1310,19 +1311,22 @@ int RsServer::StartupRetroShare()
RS_SERVICE_GXS_TYPE_GXSID, NULL, RsInitConfig::gxs_passwd); RS_SERVICE_GXS_TYPE_GXSID, NULL, RsInitConfig::gxs_passwd);
// init gxs services // init gxs services
mGxsIdService = new p3IdService(gxsid_ds, NULL); PgpAuxUtils *pgpAuxUtils = new PgpAuxUtilsImpl();
mGxsIdService = new p3IdService(gxsid_ds, NULL, pgpAuxUtils);
// circles created here, as needed by Ids.
RsGeneralDataService* gxscircles_ds = new RsDataService(currGxsDir + "/", "gxscircles_db", RsGeneralDataService* gxscircles_ds = new RsDataService(currGxsDir + "/", "gxscircles_db",
RS_SERVICE_GXS_TYPE_GXSCIRCLE, NULL, RsInitConfig::gxs_passwd); RS_SERVICE_GXS_TYPE_GXSCIRCLE, NULL, RsInitConfig::gxs_passwd);
// create GxsCircles - early, as IDs need it. // create GxsCircles - early, as IDs need it.
mGxsCircles = new p3GxsCircles(gxscircles_ds, NULL, mGxsIdService); mGxsCircles = new p3GxsCircles(gxscircles_ds, NULL, mGxsIdService, pgpAuxUtils);
// create GXS ID service // create GXS ID service
RsGxsNetService* gxsid_ns = new RsGxsNetService( RsGxsNetService* gxsid_ns = new RsGxsNetService(
RS_SERVICE_GXS_TYPE_GXSID, gxsid_ds, nxsMgr, RS_SERVICE_GXS_TYPE_GXSID, gxsid_ds, nxsMgr,
mGxsIdService, mGxsIdService->getServiceInfo(), mGxsIdService, mGxsIdService->getServiceInfo(),
mGxsIdService, mGxsCircles, mGxsIdService, mGxsCircles,
pgpAuxUtils,
false); // don't synchronise group automatic (need explicit group request) false); // don't synchronise group automatic (need explicit group request)
mGxsIdService->setNes(gxsid_ns); mGxsIdService->setNes(gxsid_ns);
@ -1332,8 +1336,8 @@ int RsServer::StartupRetroShare()
RsGxsNetService* gxscircles_ns = new RsGxsNetService( RsGxsNetService* gxscircles_ns = new RsGxsNetService(
RS_SERVICE_GXS_TYPE_GXSCIRCLE, gxscircles_ds, nxsMgr, RS_SERVICE_GXS_TYPE_GXSCIRCLE, gxscircles_ds, nxsMgr,
mGxsCircles, mGxsCircles->getServiceInfo(), mGxsCircles, mGxsCircles->getServiceInfo(),
mGxsIdService, mGxsCircles); mGxsIdService, mGxsCircles,
pgpAuxUtils);
/**** Posted GXS service ****/ /**** Posted GXS service ****/
@ -1349,7 +1353,8 @@ int RsServer::StartupRetroShare()
RsGxsNetService* posted_ns = new RsGxsNetService( RsGxsNetService* posted_ns = new RsGxsNetService(
RS_SERVICE_GXS_TYPE_POSTED, posted_ds, nxsMgr, RS_SERVICE_GXS_TYPE_POSTED, posted_ds, nxsMgr,
mPosted, mPosted->getServiceInfo(), mPosted, mPosted->getServiceInfo(),
mGxsIdService, mGxsCircles); mGxsIdService, mGxsCircles,
pgpAuxUtils);
/**** Wiki GXS service ****/ /**** Wiki GXS service ****/
@ -1364,7 +1369,8 @@ int RsServer::StartupRetroShare()
RsGxsNetService* wiki_ns = new RsGxsNetService( RsGxsNetService* wiki_ns = new RsGxsNetService(
RS_SERVICE_GXS_TYPE_WIKI, wiki_ds, nxsMgr, RS_SERVICE_GXS_TYPE_WIKI, wiki_ds, nxsMgr,
mWiki, mWiki->getServiceInfo(), mWiki, mWiki->getServiceInfo(),
mGxsIdService, mGxsCircles); mGxsIdService, mGxsCircles,
pgpAuxUtils);
/**** Forum GXS service ****/ /**** Forum GXS service ****/
@ -1379,7 +1385,8 @@ int RsServer::StartupRetroShare()
RsGxsNetService* gxsforums_ns = new RsGxsNetService( RsGxsNetService* gxsforums_ns = new RsGxsNetService(
RS_SERVICE_GXS_TYPE_FORUMS, gxsforums_ds, nxsMgr, RS_SERVICE_GXS_TYPE_FORUMS, gxsforums_ds, nxsMgr,
mGxsForums, mGxsForums->getServiceInfo(), mGxsForums, mGxsForums->getServiceInfo(),
mGxsIdService, mGxsCircles); mGxsIdService, mGxsCircles,
pgpAuxUtils);
/**** Channel GXS service ****/ /**** Channel GXS service ****/
@ -1393,7 +1400,8 @@ int RsServer::StartupRetroShare()
RsGxsNetService* gxschannels_ns = new RsGxsNetService( RsGxsNetService* gxschannels_ns = new RsGxsNetService(
RS_SERVICE_GXS_TYPE_CHANNELS, gxschannels_ds, nxsMgr, RS_SERVICE_GXS_TYPE_CHANNELS, gxschannels_ds, nxsMgr,
mGxsChannels, mGxsChannels->getServiceInfo(), mGxsChannels, mGxsChannels->getServiceInfo(),
mGxsIdService, mGxsCircles); mGxsIdService, mGxsCircles,
pgpAuxUtils);
@ -1409,7 +1417,8 @@ int RsServer::StartupRetroShare()
RsGxsNetService* photo_ns = new RsGxsNetService( RsGxsNetService* photo_ns = new RsGxsNetService(
RS_SERVICE_GXS_TYPE_PHOTO, photo_ds, nxsMgr, RS_SERVICE_GXS_TYPE_PHOTO, photo_ds, nxsMgr,
mPhoto, mPhoto->getServiceInfo(), mPhoto, mPhoto->getServiceInfo(),
mGxsIdService, mGxsCircles); mGxsIdService, mGxsCircles,
pgpAuxUtils);
#endif #endif
#if 0 // WIRE IS DISABLED FOR THE MOMENT #if 0 // WIRE IS DISABLED FOR THE MOMENT
@ -1424,7 +1433,8 @@ int RsServer::StartupRetroShare()
RsGxsNetService* wire_ns = new RsGxsNetService( RsGxsNetService* wire_ns = new RsGxsNetService(
RS_SERVICE_GXS_TYPE_WIRE, wire_ds, nxsMgr, RS_SERVICE_GXS_TYPE_WIRE, wire_ds, nxsMgr,
mWire, mWire->getServiceInfo(), mWire, mWire->getServiceInfo(),
mGxsIdService, mGxsCircles); mGxsIdService, mGxsCircles,
pgpAuxUtils);
#endif #endif
// now add to p3service // now add to p3service
pqih->addService(gxsid_ns, true); pqih->addService(gxsid_ns, true);

View File

@ -29,9 +29,7 @@
#include "util/rsrandom.h" #include "util/rsrandom.h"
#include "util/rsstring.h" #include "util/rsstring.h"
#include "pqi/authgpg.h" #include "pgp/pgpauxutils.h"
#include <retroshare/rspeers.h>
#include <sstream> #include <sstream>
#include <stdio.h> #include <stdio.h>
@ -106,10 +104,13 @@ RsGxsCircles *rsGxsCircles = NULL;
/******************* Startup / Tick ******************************************/ /******************* Startup / Tick ******************************************/
/********************************************************************************/ /********************************************************************************/
p3GxsCircles::p3GxsCircles(RsGeneralDataService *gds, RsNetworkExchangeService *nes, p3IdService *identities) p3GxsCircles::p3GxsCircles(RsGeneralDataService *gds, RsNetworkExchangeService *nes,
p3IdService *identities, PgpAuxUtils *pgpUtils)
: RsGxsCircleExchange(gds, nes, new RsGxsCircleSerialiser(), : RsGxsCircleExchange(gds, nes, new RsGxsCircleSerialiser(),
RS_SERVICE_GXS_TYPE_GXSCIRCLE, identities, circleAuthenPolicy()), RS_SERVICE_GXS_TYPE_GXSCIRCLE, identities, circleAuthenPolicy()),
RsGxsCircles(this), GxsTokenQueue(this), RsTickEvent(), mIdentities(identities), RsGxsCircles(this), GxsTokenQueue(this), RsTickEvent(),
mIdentities(identities),
mPgpUtils(pgpUtils),
mCircleMtx("p3GxsCircles"), mCircleMtx("p3GxsCircles"),
mCircleCache(DEFAULT_MEM_CACHE_SIZE, "GxsCircleCache") mCircleCache(DEFAULT_MEM_CACHE_SIZE, "GxsCircleCache")
@ -1186,7 +1187,7 @@ bool p3GxsCircles::checkCircleCacheForAutoSubscribe(RsGxsCircleCache &cache)
} }
/* if we appear in the group - then autosubscribe, and mark as processed */ /* if we appear in the group - then autosubscribe, and mark as processed */
const RsPgpId& ownId = AuthGPG::getAuthGPG()->getGPGOwnId(); const RsPgpId& ownId = mPgpUtils->getPGPOwnId();
std::map<RsPgpId, std::list<RsGxsId> >::iterator it = cache.mAllowedPeers.find(ownId); std::map<RsPgpId, std::list<RsGxsId> >::iterator it = cache.mAllowedPeers.find(ownId);
if (it != cache.mAllowedPeers.end()) if (it != cache.mAllowedPeers.end())
{ {

View File

@ -126,14 +126,14 @@ class RsGxsCircleCache
}; };
class PgpAuxUtils;
class p3GxsCircles: public RsGxsCircleExchange, public RsGxsCircles, class p3GxsCircles: public RsGxsCircleExchange, public RsGxsCircles,
public GxsTokenQueue, public RsTickEvent public GxsTokenQueue, public RsTickEvent
{ {
public: public:
p3GxsCircles(RsGeneralDataService* gds, RsNetworkExchangeService* nes, p3GxsCircles(RsGeneralDataService* gds, RsNetworkExchangeService* nes,
p3IdService *identities); p3IdService *identities, PgpAuxUtils *pgpUtils);
virtual RsServiceInfo getServiceInfo(); virtual RsServiceInfo getServiceInfo();
@ -196,6 +196,7 @@ virtual RsServiceInfo getServiceInfo();
p3IdService *mIdentities; // Needed for constructing Circle Info, p3IdService *mIdentities; // Needed for constructing Circle Info,
PgpAuxUtils *mPgpUtils;
RsMutex mCircleMtx; /* Locked Below Here */ RsMutex mCircleMtx; /* Locked Below Here */

View File

@ -24,16 +24,17 @@
*/ */
#include "services/p3idservice.h" #include "services/p3idservice.h"
#include "pgp/pgpauxutils.h"
#include "serialiser/rsgxsiditems.h" #include "serialiser/rsgxsiditems.h"
#include "retroshare/rsgxsflags.h" #include "retroshare/rsgxsflags.h"
#include "rsserver/p3face.h"
#include "util/rsrandom.h" #include "util/rsrandom.h"
#include "util/rsstring.h" #include "util/rsstring.h"
#include "util/radix64.h" #include "util/radix64.h"
#include "pqi/authgpg.h"
#include <retroshare/rspeers.h> //#include "pqi/authgpg.h"
//#include <retroshare/rspeers.h>
#include <sstream> #include <sstream>
#include <stdio.h> #include <stdio.h>
@ -136,12 +137,13 @@ RsIdentity *rsIdentity = NULL;
/******************* Startup / Tick ******************************************/ /******************* Startup / Tick ******************************************/
/********************************************************************************/ /********************************************************************************/
p3IdService::p3IdService(RsGeneralDataService *gds, RsNetworkExchangeService *nes) p3IdService::p3IdService(RsGeneralDataService *gds, RsNetworkExchangeService *nes, PgpAuxUtils *pgpUtils)
: RsGxsIdExchange(gds, nes, new RsGxsIdSerialiser(), RS_SERVICE_GXS_TYPE_GXSID, idAuthenPolicy()), : RsGxsIdExchange(gds, nes, new RsGxsIdSerialiser(), RS_SERVICE_GXS_TYPE_GXSID, idAuthenPolicy()),
RsIdentity(this), GxsTokenQueue(this), RsTickEvent(), RsIdentity(this), GxsTokenQueue(this), RsTickEvent(),
mPublicKeyCache(DEFAULT_MEM_CACHE_SIZE, "GxsIdPublicKeyCache"), mPublicKeyCache(DEFAULT_MEM_CACHE_SIZE, "GxsIdPublicKeyCache"),
mPrivateKeyCache(DEFAULT_MEM_CACHE_SIZE, "GxsIdPrivateKeyCache"), mPrivateKeyCache(DEFAULT_MEM_CACHE_SIZE, "GxsIdPrivateKeyCache"),
mIdMtx("p3IdService"), mNes(nes) mIdMtx("p3IdService"), mNes(nes),
mPgpUtils(pgpUtils)
{ {
mBgSchedule_Mode = 0; mBgSchedule_Mode = 0;
mBgSchedule_Active = false; mBgSchedule_Active = false;
@ -2078,7 +2080,7 @@ RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(RsGxsGrpIte
/* */ /* */
PGPFingerprintType ownFinger; PGPFingerprintType ownFinger;
RsPgpId ownId(AuthGPG::getAuthGPG()->getGPGOwnId()); RsPgpId ownId(mPgpUtils->getPGPOwnId());
std::cerr << "p3IdService::service_CreateGroup() OwnPgpID: " << ownId.toStdString(); std::cerr << "p3IdService::service_CreateGroup() OwnPgpID: " << ownId.toStdString();
std::cerr << std::endl; std::cerr << std::endl;
@ -2090,7 +2092,7 @@ RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(RsGxsGrpIte
// } // }
#endif #endif
if (!AuthGPG::getAuthGPG()->getKeyFingerprint(ownId,ownFinger)) if (!mPgpUtils->getKeyFingerprint(ownId,ownFinger))
{ {
std::cerr << "p3IdService::service_CreateGroup() ERROR Own Finger is stuck"; std::cerr << "p3IdService::service_CreateGroup() ERROR Own Finger is stuck";
std::cerr << std::endl; std::cerr << std::endl;
@ -2118,7 +2120,7 @@ RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(RsGxsGrpIte
unsigned int sign_size = MAX_SIGN_SIZE; unsigned int sign_size = MAX_SIGN_SIZE;
int result ; int result ;
if (!RsServer::notify()->askForDeferredSelfSignature((void *) hash.toByteArray(), hash.SIZE_IN_BYTES, signarray, &sign_size,result)) if (!mPgpUtils->askForDeferredSelfSignature((void *) hash.toByteArray(), hash.SIZE_IN_BYTES, signarray, &sign_size,result))
{ {
/* error */ /* error */
std::cerr << "p3IdService::service_CreateGroup() ERROR Signing stuff"; std::cerr << "p3IdService::service_CreateGroup() ERROR Signing stuff";
@ -2438,7 +2440,7 @@ bool p3IdService::checkId(const RsGxsIdGroup &grp, RsPgpId &pgpId)
/* miracle match! */ /* miracle match! */
/* check signature too */ /* check signature too */
if (AuthGPG::getAuthGPG()->VerifySignBin((void *) hash.toByteArray(), hash.SIZE_IN_BYTES, if (mPgpUtils->VerifySignBin((void *) hash.toByteArray(), hash.SIZE_IN_BYTES,
(unsigned char *) grp.mPgpIdSign.c_str(), grp.mPgpIdSign.length(), (unsigned char *) grp.mPgpIdSign.c_str(), grp.mPgpIdSign.length(),
mit->second)) mit->second))
{ {
@ -2488,7 +2490,7 @@ void p3IdService::getPgpIdList()
#endif // DEBUG_IDS #endif // DEBUG_IDS
std::list<RsPgpId> list; std::list<RsPgpId> list;
AuthGPG::getAuthGPG()->getGPGFilteredList(list); mPgpUtils->getGPGAllList(list);
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/ RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
@ -2499,7 +2501,7 @@ void p3IdService::getPgpIdList()
{ {
RsPgpId pgpId(*it); RsPgpId pgpId(*it);
PGPFingerprintType fp; PGPFingerprintType fp;
AuthGPG::getAuthGPG()->getKeyFingerprint(pgpId, fp); mPgpUtils->getKeyFingerprint(pgpId, fp);
#ifdef DEBUG_IDS #ifdef DEBUG_IDS
std::cerr << "p3IdService::getPgpIdList() Id: " << pgpId.toStdString() << " => " << fp.toStdString(); std::cerr << "p3IdService::getPgpIdList() Id: " << pgpId.toStdString() << " => " << fp.toStdString();
@ -2940,8 +2942,9 @@ void p3IdService::generateDummy_OwnIds()
/* grab all the gpg ids... and make some ids */ /* grab all the gpg ids... and make some ids */
RsPgpId ownId = rsPeers->getGPGOwnId(); RsPgpId ownId = mPgpUtils->getPGPOwnId();
#if 0
// generate some ownIds. // generate some ownIds.
//int genCount = 0; //int genCount = 0;
int i; int i;
@ -2967,6 +2970,7 @@ void p3IdService::generateDummy_OwnIds()
uint32_t dummyToken = 0; uint32_t dummyToken = 0;
createGroup(dummyToken, id); createGroup(dummyToken, id);
} }
#endif
} }
@ -2977,7 +2981,7 @@ void p3IdService::generateDummy_FriendPGP()
// Now Generate for friends. // Now Generate for friends.
std::list<RsPgpId> gpgids; std::list<RsPgpId> gpgids;
std::list<RsPgpId>::const_iterator it; std::list<RsPgpId>::const_iterator it;
rsPeers->getGPGAllList(gpgids); mPgpUtils->getGPGAllList(gpgids);
RsGxsIdGroup id; RsGxsIdGroup id;
@ -2987,6 +2991,7 @@ void p3IdService::generateDummy_FriendPGP()
it = gpgids.begin(); it = gpgids.begin();
for(int j = 0; j < idx; j++, it++) ; for(int j = 0; j < idx; j++, it++) ;
#if 0
// HACK FOR DUMMY GENERATION. // HACK FOR DUMMY GENERATION.
id.mMeta.mAuthorId = RsGxsId::random() ; id.mMeta.mAuthorId = RsGxsId::random() ;
@ -3006,6 +3011,7 @@ void p3IdService::generateDummy_FriendPGP()
uint32_t dummyToken = 0; uint32_t dummyToken = 0;
createGroup(dummyToken, id); createGroup(dummyToken, id);
#endif
} }

View File

@ -44,6 +44,8 @@
#include "serialiser/rsgxsrecognitems.h" #include "serialiser/rsgxsrecognitems.h"
class PgpAuxUtils;
/* /*
* Identity Service * Identity Service
* *
@ -215,7 +217,7 @@ class p3IdService: public RsGxsIdExchange, public RsIdentity,
public GxsTokenQueue, public RsTickEvent public GxsTokenQueue, public RsTickEvent
{ {
public: public:
p3IdService(RsGeneralDataService* gds, RsNetworkExchangeService* nes); p3IdService(RsGeneralDataService* gds, RsNetworkExchangeService* nes, PgpAuxUtils *pgpUtils);
virtual RsServiceInfo getServiceInfo(); virtual RsServiceInfo getServiceInfo();
static uint32_t idAuthenPolicy(); static uint32_t idAuthenPolicy();
@ -415,6 +417,7 @@ virtual void handle_event(uint32_t event_type, const std::string &elabel);
*/ */
void checkPeerForIdentities(); void checkPeerForIdentities();
/* MUTEX PROTECTED DATA (mIdMtx - maybe should use a 2nd?) */ /* MUTEX PROTECTED DATA (mIdMtx - maybe should use a 2nd?) */
bool checkRecognSignature_locked(std::string encoded, RSA &key, std::string signature); bool checkRecognSignature_locked(std::string encoded, RSA &key, std::string signature);
@ -480,6 +483,13 @@ std::string genRandomId(int len = 20);
std::map<uint32_t, std::list<RsGxsGroupId> > mGroupNotPresent; std::map<uint32_t, std::list<RsGxsGroupId> > mGroupNotPresent;
std::map<RsGxsId, std::list<RsPeerId> > mIdsNotPresent; std::map<RsGxsId, std::list<RsPeerId> > mIdsNotPresent;
RsNetworkExchangeService* mNes; RsNetworkExchangeService* mNes;
/**************************
* AuxUtils provides interface to Security Function (e.g. GPGAuth(), notify etc.)
* without depending directly on all these classes.
*/
PgpAuxUtils *mPgpUtils;
}; };
#endif // P3_IDENTITY_SERVICE_HEADER #endif // P3_IDENTITY_SERVICE_HEADER