Merge branch 'master' into merge_alpha_master

This commit is contained in:
Gioacchino Mazzurco 2017-04-18 21:30:25 +02:00
commit 4455bfa92d
110 changed files with 2395 additions and 629 deletions

View file

@ -459,8 +459,12 @@ bool GxsSecurity::validateNxsMsg(const RsNxsMsg& msg, const RsTlvKeySignature& s
msgMeta.signSet.TlvClear();
RsGxsMessageId msgId = msgMeta.mMsgId, origMsgId = msgMeta.mOrigMsgId;
msgMeta.mOrigMsgId.clear();
if(msgMeta.mOrigMsgId == msgMeta.mMsgId) // message is not versionned, then the signature was made with mOrigMsgId==NULL
msgMeta.mOrigMsgId.clear();
msgMeta.mMsgId.clear();
int signOk = 0 ;
{

View file

@ -1270,6 +1270,58 @@ bool RsGenExchange::getMsgRelatedMeta(const uint32_t &token, GxsMsgRelatedMetaMa
return ok;
}
bool RsGenExchange::getSerializedGroupData(const uint32_t &token, RsGxsGroupId& id,unsigned char *& data,uint32_t& size)
{
RS_STACK_MUTEX(mGenMtx) ;
std::list<RsNxsGrp*> nxsGrps;
if(!mDataAccess->getGroupData(token, nxsGrps))
return false ;
if(nxsGrps.size() != 1)
{
std::cerr << "(EE) getSerializedGroupData() got multiple groups in single request. This is unexpected." << std::endl;
for(std::list<RsNxsGrp*>::const_iterator it(nxsGrps.begin());it!=nxsGrps.end();++it)
delete *it ;
return false ;
}
RsNxsGrp *nxs_grp = *(nxsGrps.begin());
size = nxs_grp->serial_size() ;
id = nxs_grp->metaData->mGroupId ;
if(size > 1024*1024 || NULL==(data = (unsigned char *)rs_malloc(size)))
{
std::cerr << "(EE) getSerializedGroupData() cannot allocate mem chunk of size " << size << ". Too big, or no room." << std::endl;
delete nxs_grp ;
return false ;
}
return nxs_grp->serialise(data,size) ;
}
bool RsGenExchange::deserializeGroupData(unsigned char *data,uint32_t size)
{
RS_STACK_MUTEX(mGenMtx) ;
RsItem *item = RsNxsSerialiser(mServType).deserialise(data, &size);
RsNxsGrp *nxs_grp = dynamic_cast<RsNxsGrp*>(item) ;
if(item == NULL)
{
std::cerr << "(EE) RsGenExchange::deserializeGroupData(): cannot deserialise this data. Something's wrong." << std::endl;
delete item ;
return false ;
}
mReceivedGrps.push_back( GxsPendingItem<RsNxsGrp*, RsGxsGroupId>(nxs_grp, nxs_grp->grpId,time(NULL)) );
return true ;
}
bool RsGenExchange::getGroupData(const uint32_t &token, std::vector<RsGxsGrpItem *>& grpItem)
{
@ -2135,7 +2187,9 @@ void RsGenExchange::publishMsgs()
if(createOk && validSize)
{
// empty orig msg id means this is the original
// msg
// msg.
// (csoler) Why are we doing this???
if(msg->metaData->mOrigMsgId.isNull())
{
msg->metaData->mOrigMsgId = msg->metaData->mMsgId;

View file

@ -288,6 +288,20 @@ protected:
*/
bool getGroupData(const uint32_t &token, std::vector<RsGxsGrpItem*>& grpItem);
/*!
* \brief getSerializedGroupData
* Retrieves the complete group data serialized into a chunk of memory. This can be useful to
* transfer a full group from one machine to another.
*
* \param token token previously obtained from cache request
* \param data memory chunk allocated (using malloc)
* \param size size of the memory chunk.
* \return
*/
bool getSerializedGroupData(const uint32_t &token, RsGxsGroupId &id, unsigned char *& data, uint32_t& size);
bool deserializeGroupData(unsigned char *data, uint32_t size);
template<class GrpType>
bool getGroupDataT(const uint32_t &token, std::vector<GrpType*>& grpItem)
{

View file

@ -34,8 +34,8 @@
#include "serialiser/rstlvkeys.h"
#include "serialiser/rsgxsitems.h"
class RsGroupMetaData;
class RsMsgMetaData;
struct RsGroupMetaData;
struct RsMsgMetaData;
static const uint32_t RS_GXS_GRP_META_DATA_VERSION_ID_0001 = 0x0000 ; // change this, and keep old values if the content changes
static const uint32_t RS_GXS_GRP_META_DATA_VERSION_ID_0002 = 0xaf01 ; // current API
@ -56,22 +56,22 @@ public:
void clear();
void operator =(const RsGroupMetaData& rMeta);
//Sort data in same order than serialiser and deserializer
//Sort data in same order than serialiser and deserializer
RsGxsGroupId mGroupId;
RsGxsGroupId mOrigGrpId;
RsGxsGroupId mParentGrpId;
RsGxsGroupId mParentGrpId;
std::string mGroupName;
uint32_t mGroupFlags; // GXS_SERV::FLAG_PRIVACY_RESTRICTED | GXS_SERV::FLAG_PRIVACY_PRIVATE | GXS_SERV::FLAG_PRIVACY_PUBLIC
uint32_t mPublishTs;
uint32_t mCircleType;
uint32_t mAuthenFlags;
uint32_t mCircleType;
uint32_t mAuthenFlags;
RsGxsId mAuthorId;
std::string mServiceString;
std::string mServiceString;
RsGxsCircleId mCircleId;
RsTlvKeySignatureSet signSet;
RsTlvSecurityKeySet keys;
uint32_t mSignFlags;
uint32_t mSignFlags;
// BELOW HERE IS LOCAL DATA, THAT IS NOT FROM MSG.
@ -103,9 +103,9 @@ public:
void clear();
void operator =(const RsMsgMetaData& rMeta);
static int refcount;
//Sort data in same order than serialiser and deserializer
static int refcount;
//Sort data in same order than serialiser and deserializer
RsGxsGroupId mGroupId;
RsGxsMessageId mMsgId;
RsGxsMessageId mThreadId;
@ -121,7 +121,7 @@ public:
// BELOW HERE IS LOCAL DATA, THAT IS NOT FROM MSG.
// normally READ / UNREAD flags. LOCAL Data.
std::string mServiceString;
std::string mServiceString;
uint32_t mMsgStatus;
uint32_t mMsgSize;
time_t mChildTs;

View file

@ -75,6 +75,12 @@ bool RsGxsDataAccess::requestGroupInfo(uint32_t &token, uint32_t ansType, const
gir->mGroupIds = groupIds;
req = gir;
}
else if(reqType & GXS_REQUEST_TYPE_GROUP_SERIALIZED_DATA)
{
GroupSerializedDataReq* gir = new GroupSerializedDataReq();
gir->mGroupIds = groupIds;
req = gir;
}
if(req == NULL)
{
@ -103,34 +109,25 @@ bool RsGxsDataAccess::requestGroupInfo(uint32_t &token, uint32_t ansType, const
uint32_t reqType = opts.mReqType;
if(reqType & GXS_REQUEST_TYPE_GROUP_META)
{
GroupMetaReq* gmr = new GroupMetaReq();
req = gmr;
}
req = new GroupMetaReq();
else if(reqType & GXS_REQUEST_TYPE_GROUP_DATA)
{
GroupDataReq* gdr = new GroupDataReq();
req = gdr;
}
req = new GroupDataReq();
else if(reqType & GXS_REQUEST_TYPE_GROUP_IDS)
{
GroupIdReq* gir = new GroupIdReq();
req = gir;
}
if(req == NULL)
req = new GroupIdReq();
else if(reqType & GXS_REQUEST_TYPE_GROUP_SERIALIZED_DATA)
req = new GroupSerializedDataReq();
else
{
std::cerr << "RsGxsDataAccess::requestGroupInfo() request type not recognised, type "
<< reqType << std::endl;
return false;
}else
{
generateToken(token);
#ifdef DATA_DEBUG
std::cerr << "RsGxsDataAccess::requestGroupInfo() gets Token: " << token << std::endl;
#endif
}
generateToken(token);
#ifdef DATA_DEBUG
std::cerr << "RsGxsDataAccess::requestGroupInfo() gets Token: " << token << std::endl;
#endif
setReq(req, token, ansType, opts);
storeRequest(req);
@ -430,7 +427,16 @@ bool RsGxsDataAccess::getGroupData(const uint32_t& token, std::list<RsNxsGrp*>&
else if(req->status == GXS_REQUEST_V2_STATUS_COMPLETE)
{
GroupDataReq* gmreq = dynamic_cast<GroupDataReq*>(req);
if(gmreq)
GroupSerializedDataReq* gsreq = dynamic_cast<GroupSerializedDataReq*>(req);
if(gsreq)
{
grpData.swap(gsreq->mGroupData);
gsreq->mGroupData.clear();
locked_updateRequestStatus(token, GXS_REQUEST_V2_STATUS_DONE);
}
else if(gmreq)
{
grpData.swap(gmreq->mGroupData);
gmreq->mGroupData.clear();
@ -804,6 +810,7 @@ void RsGxsDataAccess::processRequests()
MsgIdReq* mir;
MsgRelatedInfoReq* mri;
GroupStatisticRequest* gsr;
GroupSerializedDataReq* grr;
ServiceStatisticRequest* ssr;
#ifdef DATA_DEBUG
@ -851,6 +858,11 @@ void RsGxsDataAccess::processRequests()
{
ok = getServiceStatistic(ssr);
}
else if((grr = dynamic_cast<GroupSerializedDataReq*>(req)) != NULL)
{
ok = getGroupSerializedData(grr);
}
else
{
std::cerr << "RsGxsDataAccess::processRequests() Failed to process request, token: "
@ -929,7 +941,30 @@ bool RsGxsDataAccess::getServiceStatistic(const uint32_t &token, GxsServiceStati
return true;
}
bool RsGxsDataAccess::getGroupSerializedData(GroupSerializedDataReq* req)
{
std::map<RsGxsGroupId, RsNxsGrp*> grpData;
std::list<RsGxsGroupId> grpIdsOut;
getGroupList(req->mGroupIds, req->Options, grpIdsOut);
if(grpIdsOut.empty())
return true;
for(std::list<RsGxsGroupId>::iterator lit = grpIdsOut.begin();lit != grpIdsOut.end();++lit)
grpData[*lit] = NULL;
bool ok = mDataStore->retrieveNxsGrps(grpData, true, true);
req->mGroupData.clear();
std::map<RsGxsGroupId, RsNxsGrp*>::iterator mit = grpData.begin();
for(; mit != grpData.end(); ++mit)
req->mGroupData.push_back(mit->second) ;
return ok;
}
bool RsGxsDataAccess::getGroupData(GroupDataReq* req)
{
std::map<RsGxsGroupId, RsNxsGrp*> grpData;

View file

@ -418,6 +418,13 @@ private:
*/
bool getGroupStatistic(GroupStatisticRequest* req);
/*!
*
* Attempts to retrieve group data in serialized format
* @param req Request object to satisfy
*/
bool getGroupSerializedData(GroupSerializedDataReq* req);
/*!
*
* Attempts to service statistic

View file

@ -1972,7 +1972,7 @@ void RsGxsNetService::updateServerSyncTS()
#endif
// I keep the creation, but the data is not used yet.
#warning disabled this, but do we need it?
#warning csoler 2016-12-12: Disabled this, but do we need it?
// RsGxsServerMsgUpdate& msui(mServerMsgUpdateMap[grpId]) ;
// (cyril) I'm removing this, because the msgUpdateTS is updated when new messages are received by calling locked_stampMsgServerUpdateTS().
@ -3000,7 +3000,7 @@ void RsGxsNetService::locked_genReqGrpTransaction(NxsTransaction* tr)
}
// FIXTESTS global variable rsReputations not available in unittests!
#warning Update the code below to correctly send/recv dependign on reputation
#warning csoler 2016-12-23: Update the code below to correctly send/recv dependign on reputation
if(!grpSyncItem->authorId.isNull() && mReputations->overallReputationLevel(grpSyncItem->authorId) == RsReputations::REPUTATION_LOCALLY_NEGATIVE)
{
#ifdef NXS_NET_DEBUG_0

View file

@ -45,7 +45,7 @@ bool AuthorPending::getAuthorRep(GixsReputation& rep, const RsGxsId& authorId, c
rep.id = authorId ;
rep.reputation_level = mRep->overallReputationLevel(authorId);
#warning can it happen that reputations do not have the info yet?
#warning csoler 2017-01-10: Can it happen that reputations do not have the info yet?
return true ;
#ifdef TO_BE_REMOVED
{

View file

@ -61,6 +61,12 @@ public:
std::list<RsGxsGroupId> mGroupIds;
std::list<RsGxsGroupId> mGroupIdResult;
};
class GroupSerializedDataReq : public GxsRequest
{
public:
std::list<RsGxsGroupId> mGroupIds;
std::list<RsNxsGrp*> mGroupData;
};
class GroupDataReq : public GxsRequest
{

View file

@ -1194,7 +1194,7 @@ bool p3GxsTunnelService::locked_sendClearTunnelData(RsGxsTunnelDHPublicKeyItem *
if(gitem->data_bytes == NULL)
{
delete gitem ;
return NULL ;
return false ;
}
// by convention, we use a IV of 0 for unencrypted data.
memset(gitem->data_bytes,0,8) ;

View file

@ -279,7 +279,12 @@ win32 {
CONFIG += upnp_miniupnpc
LIBS += -lsqlcipher
no_sqlcipher {
PKGCONFIG *= sqlite3
LIBS += -lsqlite3
} else {
LIBS += -lsqlcipher
}
DEPENDPATH += . $$INC_DIR
INCLUDEPATH += . $$INC_DIR

View file

@ -51,9 +51,14 @@ RsPluginManager::RsPluginManager(const RsFileHash &hash)
_allow_all_plugins = false ;
}
bool RsPluginManager::loadConfiguration(RsFileHash &loadHash)
{
return p3Config::loadConfiguration(loadHash);
}
void RsPluginManager::loadConfiguration()
{
RsFileHash dummyHash ;
RsFileHash dummyHash;
p3Config::loadConfiguration(dummyHash);
}

View file

@ -74,6 +74,7 @@ class RsPluginManager: public RsPluginHandler, public p3Config
// -------------------- Own members -------------------------//
//
virtual void addConfigurations(p3ConfigMgr *cfgMgr) ;
virtual bool loadConfiguration(RsFileHash &loadHash) ;
virtual void loadConfiguration() ;
/*!

View file

@ -92,7 +92,7 @@ dhtPeerEntry::dhtPeerEntry()
return;
}
p3DhtMgr::p3DhtMgr(std::string id, pqiConnectCb *cb)
p3DhtMgr::p3DhtMgr(RsPeerId id, pqiConnectCb *cb)
:pqiNetAssistConnect(id, cb), dhtMtx("p3DhtMgr"), mStunRequired(true)
{
/* setup own entry */
@ -237,13 +237,13 @@ bool p3DhtMgr::setExternalInterface(
/* add / remove peers */
bool p3DhtMgr::findPeer(std::string id)
bool p3DhtMgr::findPeer(const RsPeerId& id)
{
RsStackMutex stack(dhtMtx); /***** LOCK MUTEX *****/
mDhtModifications = true;
std::map<std::string, dhtPeerEntry>::iterator it;
std::map<RsPeerId, dhtPeerEntry>::iterator it;
it = peers.find(id);
if (it != peers.end())
{
@ -281,14 +281,14 @@ bool p3DhtMgr::findPeer(std::string id)
return true;
}
bool p3DhtMgr::dropPeer(std::string id)
bool p3DhtMgr::dropPeer(const RsPeerId& id)
{
RsStackMutex stack(dhtMtx); /***** LOCK MUTEX *****/
mDhtModifications = true;
/* once we are connected ... don't worry about them anymore */
std::map<std::string, dhtPeerEntry>::iterator it;
std::map<RsPeerId, dhtPeerEntry>::iterator it;
it = peers.find(id);
if (it == peers.end())
{
@ -302,14 +302,14 @@ bool p3DhtMgr::dropPeer(std::string id)
}
/* post DHT key saying we should connect */
bool p3DhtMgr::notifyPeer(std::string id)
bool p3DhtMgr::notifyPeer(const RsPeerId& id)
{
RsStackMutex stack(dhtMtx); /***** LOCK MUTEX *****/
#ifdef DHT_DEBUG
std::cerr << "p3DhtMgr::notifyPeer() " << id << std::endl;
std::cerr << "p3DhtMgr::notifyPeer() " << id.toStdString() << std::endl;
#endif
std::map<std::string, dhtPeerEntry>::iterator it;
std::map<RsPeerId, dhtPeerEntry>::iterator it;
it = peers.find(id);
if (it == peers.end())
{
@ -333,7 +333,7 @@ bool p3DhtMgr::notifyPeer(std::string id)
#ifdef DHT_LOGS
{
/* Log */
rslog(RSL_WARNING, p3dhtzone, "p3DhtMgr::notifyPeer() Id: " + id + " TO SOON - DROPPING");
rslog(RSL_WARNING, p3dhtzone, "p3DhtMgr::notifyPeer() Id: " + id.toStdString() + " TO SOON - DROPPING");
}
#endif
@ -352,7 +352,7 @@ bool p3DhtMgr::notifyPeer(std::string id)
#ifdef DHT_LOGS
{
/* Log */
rslog(RSL_WARNING, p3dhtzone, "p3DhtMgr::notifyPeer() Id: " + id + " PEER NOT FOUND - Trigger Search");
rslog(RSL_WARNING, p3dhtzone, "p3DhtMgr::notifyPeer() Id: " + id.toStdString() + " PEER NOT FOUND - Trigger Search");
}
#endif
it->second.lastTS = 0;
@ -364,14 +364,14 @@ bool p3DhtMgr::notifyPeer(std::string id)
}
/* extract current peer status */
bool p3DhtMgr::getPeerStatus(std::string id,
struct sockaddr_in &laddr,
struct sockaddr_in &raddr,
bool p3DhtMgr::getPeerStatus(const RsPeerId &id,
struct sockaddr_in &laddr,
struct sockaddr_in &raddr,
uint32_t &type, uint32_t &state)
{
RsStackMutex stack(dhtMtx); /* LOCK MUTEX */
std::map<std::string, dhtPeerEntry>::iterator it;
std::map<RsPeerId, dhtPeerEntry>::iterator it;
it = peers.find(id);
/* ignore OFF peers */
@ -776,7 +776,7 @@ int p3DhtMgr::checkPeerDHTKeys()
dhtMtx.lock(); /* LOCK MUTEX */
/* iterate through and find min time and suitable candidate */
std::map<std::string, dhtPeerEntry>::iterator it,pit;
std::map<RsPeerId, dhtPeerEntry>::iterator it,pit;
time_t now = time(NULL);
uint32_t period = 0;
uint32_t repeatPeriod = 6000;
@ -802,7 +802,7 @@ int p3DhtMgr::checkPeerDHTKeys()
period = DHT_CHECK_PERIOD;
}
#ifdef DHT_DEBUG
std::cerr << "p3DhtMgr::checkPeerDHTKeys() Peer: " << it->second.id;
std::cerr << "p3DhtMgr::checkPeerDHTKeys() Peer: " << it->second.id.toStdString();
std::cerr << " Period: " << period;
std::cerr << " Delta: " << delta;
std::cerr << std::endl;
@ -865,7 +865,7 @@ int p3DhtMgr::checkNotifyDHT()
RsStackMutex stack(dhtMtx); /***** LOCK MUTEX *****/
/* iterate through and find min time and suitable candidate */
std::map<std::string, dhtPeerEntry>::iterator it;
std::map<RsPeerId, dhtPeerEntry>::iterator it;
time_t now = time(NULL);
int repeatPeriod = DHT_DEFAULT_PERIOD;
@ -1015,7 +1015,7 @@ int p3DhtMgr::checkStunState()
if (mDhtState == DHT_STATE_CHECK_PEERS)
{
/* check that they have all be searched for */
std::map<std::string, dhtPeerEntry>::iterator it;
std::map<RsPeerId, dhtPeerEntry>::iterator it;
for(it = peers.begin(); it != peers.end(); it++)
{
if (it->second.state == DHT_PEER_INIT)
@ -1287,7 +1287,7 @@ int p3DhtMgr::status(std::ostream &out)
out << "OWN DETAILS END----------------------------------------" << std::endl;
/* now peers states */
std::map<std::string, dhtPeerEntry>::iterator it;
std::map<RsPeerId, dhtPeerEntry>::iterator it;
out << "PEER DETAILS ------------------------------------------" << std::endl;
for(it = peers.begin(); it != peers.end(); it++)
{
@ -1622,15 +1622,13 @@ bool p3DhtMgr::dhtResultNotify(std::string idhash)
std::cerr << "p3DhtMgr::dhtResultNotify() from idhash: ";
std::cerr << RsUtil::BinToHex(idhash) << std::endl;
#endif
std::map<std::string, dhtPeerEntry>::iterator it;
std::map<RsPeerId, dhtPeerEntry>::iterator it;
time_t now = time(NULL);
/* if notify - we must match on the second hash */
for(it = peers.begin(); (it != peers.end()) && ((it->second).hash2 != idhash); it++) ;
/* update data */
std::string peerid;
/* ignore OFF peers */
if ((it != peers.end()) && (it->second.state != DHT_PEER_OFF))
{
@ -1677,7 +1675,7 @@ bool p3DhtMgr::dhtResultSearch(std::string idhash,
std::cerr << "p3DhtMgr::dhtResultSearch() for idhash: ";
std::cerr << RsUtil::BinToHex(idhash) << std::endl;
#endif
std::map<std::string, dhtPeerEntry>::iterator it;
std::map<RsPeerId, dhtPeerEntry>::iterator it;
bool doCb = false;
bool doStun = false;
uint32_t stunFlags = 0;
@ -1780,7 +1778,7 @@ bool p3DhtMgr::dhtResultSearch(std::string idhash,
void printDhtPeerEntry(dhtPeerEntry *ent, std::ostream &out)
{
out << "DhtEntry: ID: " << ent->id;
out << "DhtEntry: ID: " << ent->id.toStdString();
out << " State: " << ent->state;
out << " lastTS: " << ent->lastTS;
out << " notifyPending: " << ent->notifyPending;

View file

@ -78,7 +78,7 @@ class dhtPeerEntry
public:
dhtPeerEntry();
std::string id;
RsPeerId id;
uint32_t state;
time_t lastTS;
@ -97,7 +97,7 @@ class p3DhtMgr: public pqiNetAssistConnect, public RsThread
/*
*/
public:
p3DhtMgr(std::string id, pqiConnectCb *cb);
p3DhtMgr(RsPeerId id, pqiConnectCb *cb);
/********** External DHT Interface ************************
* These Functions are the external interface
@ -121,15 +121,15 @@ virtual bool setExternalInterface(struct sockaddr_in laddr,
struct sockaddr_in raddr, uint32_t type);
/* add / remove peers */
virtual bool findPeer(std::string id);
virtual bool dropPeer(std::string id);
virtual bool findPeer(const RsPeerId& id);
virtual bool dropPeer(const RsPeerId& id);
/* post DHT key saying we should connect (callback when done) */
virtual bool notifyPeer(std::string id);
virtual bool notifyPeer(const RsPeerId& id);
/* extract current peer status */
virtual bool getPeerStatus(std::string id,
struct sockaddr_in &laddr, struct sockaddr_in &raddr,
virtual bool getPeerStatus(const RsPeerId& id,
struct sockaddr_in &laddr, struct sockaddr_in &raddr,
uint32_t &type, uint32_t &mode);
/* stun */
@ -154,17 +154,17 @@ virtual bool dhtResultBootstrap(std::string idhash);
protected:
/* can block briefly (called only from thread) */
virtual bool dhtPublish(std::string id,
virtual bool dhtPublish(std::string idhash,
struct sockaddr_in &laddr,
struct sockaddr_in &raddr,
uint32_t type, std::string sign);
virtual bool dhtNotify(std::string peerid, std::string ownId,
virtual bool dhtNotify(std::string idhash, std::string ownIdHash,
std::string sign);
virtual bool dhtSearch(std::string id, uint32_t mode);
virtual bool dhtSearch(std::string idhash, uint32_t mode);
virtual bool dhtBootstrap(std::string storehash, std::string ownIdHash,
virtual bool dhtBootstrap(std::string idhash, std::string ownIdHash,
std::string sign); /* to publish bootstrap */
@ -232,7 +232,7 @@ std::string randomBootstrapId();
dhtPeerEntry ownEntry;
time_t ownNotifyTS;
std::map<std::string, dhtPeerEntry> peers;
std::map<RsPeerId, dhtPeerEntry> peers;
std::list<std::string> stunIds;
bool mStunRequired;

View file

@ -397,7 +397,7 @@ private:
std::map<RsPeerId,sockaddr_storage> mReportedOwnAddresses ;
std::map<RsNodeGroupId,RsGroupInfo> groupList;
uint32_t lastGroupId;
//uint32_t lastGroupId;
std::list<RsItem *> saveCleanupList; /* TEMPORARY LIST WHEN SAVING */

View file

@ -61,14 +61,20 @@ void pqiConnectCbDummy::peerStatus(const RsPeerId& id, const pqiIpAddrSet &ad
std::cerr << out << std::endl;
}
void pqiConnectCbDummy::peerConnectRequest(const RsPeerId& id,
const struct sockaddr_storage &raddr, uint32_t source)
void pqiConnectCbDummy::peerConnectRequest(const RsPeerId &id, const sockaddr_storage &raddr
, const sockaddr_storage &proxyaddr, const sockaddr_storage &srcaddr
, uint32_t source, uint32_t flags, uint32_t delay, uint32_t bandwidth)
{
std::cerr << "pqiConnectCbDummy::peerConnectRequest()";
std::cerr << " id: " << id;
std::cerr << " raddr: " << sockaddr_storage_tostring(raddr);
std::cerr << " proxyaddr: " << sockaddr_storage_tostring(proxyaddr);
std::cerr << " srcaddr: " << sockaddr_storage_tostring(srcaddr);
std::cerr << " source: " << source;
std::cerr << std::endl;
std::cerr << " flags: " << flags;
std::cerr << " delay: " << delay;
std::cerr << " bandwidth: " << bandwidth;
std::cerr << std::endl;
}
void pqiMonitor::disconnectPeer(const RsPeerId &/*peer*/)

View file

@ -179,8 +179,9 @@ virtual ~pqiConnectCbDummy();
virtual void peerStatus(const RsPeerId& id, const pqiIpAddrSet &addrs,
uint32_t type, uint32_t mode, uint32_t source);
virtual void peerConnectRequest(const RsPeerId& id,
const struct sockaddr_storage &raddr, uint32_t source);
virtual void peerConnectRequest(const RsPeerId& id, const struct sockaddr_storage &raddr,
const struct sockaddr_storage &proxyaddr, const struct sockaddr_storage &srcaddr,
uint32_t source, uint32_t flags, uint32_t delay, uint32_t bandwidth);
//virtual void stunStatus(std::string id, const struct sockaddr_storage &raddr, uint32_t type, uint32_t flags);
};

View file

@ -40,7 +40,7 @@ static struct RsLog::logInfo pqipersonzoneInfo = {RsLog::Default, "pqiperson"};
pqiperson::pqiperson(const RsPeerId& id, pqipersongrp *pg) :
PQInterface(id), mNotifyMtx("pqiperson-notify"), mPersonMtx("pqiperson"),
active(false), activepqi(NULL), inConnectAttempt(false), waittimes(0),
active(false), activepqi(NULL), inConnectAttempt(false),// waittimes(0),
pqipg(pg) {} // TODO: must check id!
pqiperson::~pqiperson()

View file

@ -29,6 +29,7 @@
#define MRK_PQI_PERSON_HEADER
#include <string>
#include "pqi/pqi.h"
#include "util/rsnet.h"
@ -66,7 +67,7 @@ public:
virtual int reset() { pqistreamer::reset(); return ni->reset(); }
virtual int disconnect() { return reset() ; }
virtual bool connect_parameter(uint32_t type, uint32_t value) { return ni->connect_parameter(type, value);}
virtual bool connect_parameter(uint32_t type, std::string value) { return ni->connect_parameter(type, value);}
virtual bool connect_parameter(uint32_t type, const std::string &value) { return ni->connect_parameter(type, value);}
virtual bool connect_additional_address(uint32_t type, const struct sockaddr_storage &addr) { return ni->connect_additional_address(type, addr); }
virtual int getConnectAddress(struct sockaddr_storage &raddr){ return ni->getConnectAddress(raddr); }
@ -171,7 +172,7 @@ private:
bool active;
pqiconnect *activepqi;
bool inConnectAttempt;
int waittimes;
//int waittimes;
time_t lastHeartbeatReceived; // use to track connection failure
pqipersongrp *pqipg; /* parent for callback */
};

View file

@ -1009,7 +1009,7 @@ int pqissl::Basic_Connection_Complete()
return -1;
}
else if ((err == ECONNREFUSED))
else if (err == ECONNREFUSED)
{
rslog(RSL_WARNING, pqisslzone, "pqissl::Basic_Connection_Complete() ECONNREFUSED: cert: " + PeerId().toStdString());

View file

@ -53,7 +53,7 @@ static const uint32_t PQI_SSLUDP_DEF_CONN_PERIOD = 300; /* 5 minutes? */
/********** PQI SSL UDP STUFF **************************************/
pqissludp::pqissludp(PQInterface *parent, p3LinkMgr *lm) :
pqissl(NULL, parent, lm), tou_bio(NULL), listen_checktime(0),
pqissl(NULL, parent, lm), tou_bio(NULL),// listen_checktime(0),
mConnectPeriod(PQI_SSLUDP_DEF_CONN_PERIOD), mConnectFlags(0),
mConnectBandwidth(0)
{

View file

@ -95,7 +95,7 @@ private:
BIO *tou_bio; // specific to ssludp.
long listen_checktime;
//long listen_checktime;
uint32_t mConnectPeriod;
uint32_t mConnectFlags;

View file

@ -627,7 +627,7 @@ bool getX509id(X509 *x509, RsPeerId& xid)
* more randomness
*/
#warning this is cryptographically horrible. We should do a hash of the public key here!!!
#warning csoler 2017-02-19: This is cryptographically horrible. We should do a hash of the public key here!!!
xid = RsPeerId(&signdata[signlen - CERTSIGNLEN]) ;

View file

@ -25,7 +25,7 @@ typedef std::pair<RsGxsGroupId, RsGxsMessageId> RsGxsGrpMsgIdPair;
typedef std::map<RsGxsGrpMsgIdPair, std::vector<RsGxsMessageId> > MsgRelatedIdResult;
typedef std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > GxsMsgReq;
class RsMsgMetaData;
struct RsMsgMetaData;
typedef std::map<RsGxsGroupId, std::vector<RsMsgMetaData> > MsgMetaResult;

View file

@ -5,7 +5,7 @@
#include "retroshare/rsgxsifacetypes.h"
#include "retroshare/rstokenservice.h"
class RsMsgMetaData ;
struct RsMsgMetaData ;
typedef std::map<RsGxsGroupId, std::vector<RsMsgMetaData> > GxsMsgMetaMap;
typedef std::map<RsGxsGrpMsgIdPair, std::vector<RsMsgMetaData> > GxsMsgRelatedMetaMap;

View file

@ -305,6 +305,9 @@ public:
virtual bool setAsRegularContact(const RsGxsId& id,bool is_a_contact) = 0 ;
virtual bool isARegularContact(const RsGxsId& id) = 0 ;
virtual bool serialiseIdentityToMemory(const RsGxsId& id,std::string& radix_string)=0;
virtual bool deserialiseIdentityFromMemory(const std::string& radix_string)=0;
/*!
* \brief overallReputationLevel
* Returns the overall reputation level of the supplied identity. See rsreputations.h
@ -319,6 +322,7 @@ public:
*/
virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsIdGroup> &groups) = 0;
virtual bool getGroupSerializedData(const uint32_t &token, std::map<RsGxsId,std::string>& serialized_groups)=0;
//virtual bool getMsgData(const uint32_t &token, std::vector<RsGxsIdOpinion> &opinions) = 0;
};

View file

@ -47,6 +47,7 @@
#define GXS_REQUEST_TYPE_GROUP_STATS 0x01600000
#define GXS_REQUEST_TYPE_SERVICE_STATS 0x03200000
#define GXS_REQUEST_TYPE_GROUP_SERIALIZED_DATA 0x04000000
// TODO CLEANUP: RS_TOKREQOPT_MSG_* should be an inner enum of RsTokReqOptions

View file

@ -1037,6 +1037,9 @@ bool p3Peers::setProxyServer(const uint32_t type, const std::string &addr_str, c
std::cerr << "(EE) attempt to set proxy server address to something not allowed: " << addr_str << ":" << port << std::endl;
return false ;
}
std::cerr << "Settign proxy server address to " << addr_str << ":" << port << std::endl;
struct sockaddr_storage addr;
struct sockaddr_in *addrv4p = (struct sockaddr_in *) &addr;
addrv4p->sin_family = AF_INET;

View file

@ -66,8 +66,8 @@
*/
RsBanList *rsBanList = NULL ;
p3BanList::p3BanList(p3ServiceControl *sc, p3NetMgr *nm)
:p3Service(), mBanMtx("p3BanList"), mServiceCtrl(sc), mNetMgr(nm)
p3BanList::p3BanList(p3ServiceControl *sc, p3NetMgr */*nm*/)
:p3Service(), mBanMtx("p3BanList"), mServiceCtrl(sc)//, mNetMgr(nm)
{
addSerialType(new RsBanListSerialiser());

View file

@ -148,7 +148,7 @@ private:
std::map<struct sockaddr_storage, BanListPeer> mWhiteListedRanges;
p3ServiceControl *mServiceCtrl;
p3NetMgr *mNetMgr;
//p3NetMgr *mNetMgr;
time_t mLastDhtInfoRequest ;
bool mIPFilteringEnabled ;

View file

@ -1035,7 +1035,7 @@ bool p3GxsReputation::setOwnOpinion(const RsGxsId& gxsid, const RsReputations::O
if (rit == mReputations.end())
{
#warning we should set the owner node id here.
#warning csoler 2017-01-05: We should set the owner node id here.
mReputations[gxsid] = Reputation(gxsid);
rit = mReputations.find(gxsid);
}

View file

@ -174,7 +174,7 @@ private:
time_t mLastIdentityFlagsUpdate ;
bool mReputationsUpdated;
float mAutoBanIdentitiesLimit ;
//float mAutoBanIdentitiesLimit ;
bool mAutoSetPositiveOptionToContacts;
p3LinkMgr *mLinkMgr;

View file

@ -70,6 +70,8 @@ static const time_t MAX_KEEP_KEYS_SIGNED_KNOWN = 30 * 86400 ; // signed ident
static const uint32_t MAX_DELAY_BEFORE_CLEANING= 1800 ; // clean old keys every 30 mins
static const uint32_t MAX_SERIALISED_IDENTITY_AGE = 600 ; // after 10 mins, a serialised identity record must be renewed.
RsIdentity *rsIdentity = NULL;
/******
@ -97,13 +99,12 @@ RsIdentity *rsIdentity = NULL;
#define BG_REPUTATION 3
#define GXSIDREQ_CACHELOAD 0x0001
#define GXSIDREQ_CACHEOWNIDS 0x0002
#define GXSIDREQ_PGPHASH 0x0010
#define GXSIDREQ_RECOGN 0x0020
#define GXSIDREQ_OPINION 0x0030
#define GXSIDREQ_CACHELOAD 0x0001
#define GXSIDREQ_CACHEOWNIDS 0x0002
#define GXSIDREQ_PGPHASH 0x0010
#define GXSIDREQ_RECOGN 0x0020
#define GXSIDREQ_OPINION 0x0030
#define GXSIDREQ_SERIALIZE_TO_MEMORY 0x0040
#define GXSIDREQ_CACHETEST 0x1000
@ -697,6 +698,84 @@ bool p3IdService::getOwnIds(std::list<RsGxsId> &ownIds)
return true ;
}
bool p3IdService::serialiseIdentityToMemory(const RsGxsId& id,std::string& radix_string)
{
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
// look into cache. If available, return the data. If not, request it.
std::map<RsGxsId,SerialisedIdentityStruct>::const_iterator it = mSerialisedIdentities.find(id);
if(it != mSerialisedIdentities.end())
{
Radix64::encode(it->second.mMem,it->second.mSize,radix_string) ;
if(it->second.mLastUsageTS + MAX_SERIALISED_IDENTITY_AGE > time(NULL))
return true ;
std::cerr << "Identity " << id << " will be re-serialised, because the last record is too old." << std::endl;
}
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
uint32_t token = 0;
std::list<RsGxsGroupId> groupIds;
groupIds.push_back(RsGxsGroupId(id)) ;
RsGenExchange::getTokenService()->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, groupIds);
GxsTokenQueue::queueRequest(token, GXSIDREQ_SERIALIZE_TO_MEMORY);
return false;
}
void p3IdService::handle_get_serialized_grp(uint32_t token)
{
// store the serialized data in cache.
unsigned char *mem = NULL;
uint32_t size;
RsGxsGroupId id ;
if(!RsGenExchange::getSerializedGroupData(token,id, mem,size))
{
std::cerr << "(EE) call to RsGenExchage::getSerializedGroupData() failed." << std::endl;
return ;
}
std::cerr << "Received serialised group from RsGenExchange." << std::endl;
std::map<RsGxsId,SerialisedIdentityStruct>::const_iterator it = mSerialisedIdentities.find(RsGxsId(id));
if(it != mSerialisedIdentities.end())
free(it->second.mMem) ;
SerialisedIdentityStruct s ;
s.mMem = mem ;
s.mSize = size ;
s.mLastUsageTS = time(NULL) ;
mSerialisedIdentities[RsGxsId(id)] = s ;
}
bool p3IdService::deserialiseIdentityFromMemory(const std::string& radix_string)
{
std::vector<uint8_t> mem = Radix64::decode(radix_string) ;
if(mem.empty())
{
std::cerr << "Cannot decode radix string \"" << radix_string << "\"" << std::endl;
return false ;
}
if(!RsGenExchange::deserializeGroupData(mem.data(),mem.size()))
{
std::cerr << "Cannot load identity from radix string \"" << radix_string << "\"" << std::endl;
return false ;
}
return true ;
}
bool p3IdService::createIdentity(uint32_t& token, RsIdentityParameters &params)
{
@ -709,7 +788,7 @@ bool p3IdService::createIdentity(uint32_t& token, RsIdentityParameters &params)
if (params.isPgpLinked)
{
#warning Backward compatibility issue to fix here in v0.7.0
#warning csoler 2017-02-07: Backward compatibility issue to fix here in v0.7.0
// This is a hack, because a bad decision led to having RSGXSID_GROUPFLAG_REALID be equal to GXS_SERV::FLAG_PRIVACY_PRIVATE.
// In order to keep backward compatibility, we'll also add the new value
@ -1587,6 +1666,28 @@ bool p3IdService::getGroupData(const uint32_t &token, std::vector<RsGxsIdGroup>
return ok;
}
bool p3IdService::getGroupSerializedData(const uint32_t &token, std::map<RsGxsId,std::string>& serialized_groups)
{
unsigned char *mem = NULL;
uint32_t size;
RsGxsGroupId id ;
serialized_groups.clear() ;
if(!RsGenExchange::getSerializedGroupData(token,id, mem,size))
{
std::cerr << "(EE) call to RsGenExchage::getSerializedGroupData() failed." << std::endl;
return false;
}
std::string radix ;
Radix64::encode(mem,size,radix) ;
serialized_groups[RsGxsId(id)] = radix ;
return true;
}
/********************************************************************************/
/********************************************************************************/
@ -4309,6 +4410,9 @@ void p3IdService::handleResponse(uint32_t token, uint32_t req_type)
case GXSIDREQ_OPINION:
opinion_handlerequest(token);
break;
case GXSIDREQ_SERIALIZE_TO_MEMORY:
handle_get_serialized_grp(token) ;
default:
/* error */
std::cerr << "p3IdService::handleResponse() Unknown Request Type: " << req_type;

View file

@ -212,6 +212,13 @@ private:
void init(const RsGxsIdGroupItem *item, const RsTlvPublicRSAKey& in_pub_key, const RsTlvPrivateRSAKey& in_priv_key,const std::list<RsRecognTag> &tagList);
};
struct SerialisedIdentityStruct
{
unsigned char *mMem ;
uint32_t mSize ;
time_t mLastUsageTS;
};
// Not sure exactly what should be inherited here?
// Chris - please correct as necessary.
@ -238,6 +245,8 @@ public:
// These are exposed via RsIdentity.
virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsIdGroup> &groups);
virtual bool getGroupSerializedData(const uint32_t &token, std::map<RsGxsId,std::string>& serialized_groups);
//virtual bool getMsgData(const uint32_t &token, std::vector<RsGxsIdOpinion> &opinions);
// These are local - and not exposed via RsIdentity.
@ -341,6 +350,8 @@ public:
const RsIdentityUsage &use_info );
virtual bool requestPrivateKey(const RsGxsId &id);
virtual bool serialiseIdentityToMemory(const RsGxsId& id,std::string& radix_string);
virtual bool deserialiseIdentityFromMemory(const std::string& radix_string);
/**************** RsGixsReputation Implementation ****************/
@ -433,6 +444,12 @@ private:
bool mBgSchedule_Active;
uint32_t mBgSchedule_Mode;
/***********************************8
* Fonction to receive and handle group serialisation to memory
*/
virtual void handle_get_serialized_grp(uint32_t token);
/************************************************************************
* pgphash processing.
*
@ -563,6 +580,8 @@ private:
std::map<RsGxsId, std::list<RsPeerId> > mIdsNotPresent;
std::map<RsGxsId,keyTSInfo> mKeysTS ;
std::map<RsGxsId,SerialisedIdentityStruct> mSerialisedIdentities ;
// keep a list of regular contacts. This is useful to sort IDs, and allow some services to priviledged ids only.
std::set<RsGxsId> mContacts;
RsNetworkExchangeService* mNes;

View file

@ -93,9 +93,9 @@ again:
idx = (idx + 1) % 4;
}
idx = idx;
//idx = idx;
return buf;
return buf ;
}
/****************
@ -147,7 +147,7 @@ again:
private:
static inline char *bintoasc() { static char bta[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; return bta ; }
static inline char *asctobin() { static char s[256]; return s ; } /* runtime radix64_initd */
static inline uint8_t *asctobin() { static uint8_t s[256]; return s ; } /* runtime radix64_initd */
static int& is_radix64_initd() { static int is_inited = false ; return is_inited ; }
/* hey, guess what: this is a read-only table.