diff --git a/src/gxs/rsgenexchange.cc b/src/gxs/rsgenexchange.cc index c59da85de..b946b5931 100644 --- a/src/gxs/rsgenexchange.cc +++ b/src/gxs/rsgenexchange.cc @@ -1273,6 +1273,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 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::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(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(nxs_grp, nxs_grp->grpId,time(NULL)) ); + + return true ; +} bool RsGenExchange::getGroupData(const uint32_t &token, std::vector& grpItem) { diff --git a/src/gxs/rsgenexchange.h b/src/gxs/rsgenexchange.h index 8ebd40bd7..43891a80d 100644 --- a/src/gxs/rsgenexchange.h +++ b/src/gxs/rsgenexchange.h @@ -288,6 +288,20 @@ protected: */ bool getGroupData(const uint32_t &token, std::vector& 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 bool getGroupDataT(const uint32_t &token, std::vector& grpItem) { diff --git a/src/gxs/rsgxsdata.h b/src/gxs/rsgxsdata.h index 6e85193dc..76924167c 100644 --- a/src/gxs/rsgxsdata.h +++ b/src/gxs/rsgxsdata.h @@ -33,8 +33,8 @@ #include "rsitems/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 diff --git a/src/gxs/rsgxsdataaccess.cc b/src/gxs/rsgxsdataaccess.cc index 8fcbbde5d..56899d4ce 100644 --- a/src/gxs/rsgxsdataaccess.cc +++ b/src/gxs/rsgxsdataaccess.cc @@ -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& else if(req->status == GXS_REQUEST_V2_STATUS_COMPLETE) { GroupDataReq* gmreq = dynamic_cast(req); - if(gmreq) + GroupSerializedDataReq* gsreq = dynamic_cast(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(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 grpData; + std::list grpIdsOut; + getGroupList(req->mGroupIds, req->Options, grpIdsOut); + + if(grpIdsOut.empty()) + return true; + + + for(std::list::iterator lit = grpIdsOut.begin();lit != grpIdsOut.end();++lit) + grpData[*lit] = NULL; + + bool ok = mDataStore->retrieveNxsGrps(grpData, true, true); + req->mGroupData.clear(); + + std::map::iterator mit = grpData.begin(); + + for(; mit != grpData.end(); ++mit) + req->mGroupData.push_back(mit->second) ; + + return ok; +} bool RsGxsDataAccess::getGroupData(GroupDataReq* req) { std::map grpData; diff --git a/src/gxs/rsgxsdataaccess.h b/src/gxs/rsgxsdataaccess.h index ac21f4c41..d39823f81 100644 --- a/src/gxs/rsgxsdataaccess.h +++ b/src/gxs/rsgxsdataaccess.h @@ -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 diff --git a/src/gxs/rsgxsnetservice.cc b/src/gxs/rsgxsnetservice.cc index 1811f2658..789a77441 100644 --- a/src/gxs/rsgxsnetservice.cc +++ b/src/gxs/rsgxsnetservice.cc @@ -328,6 +328,23 @@ RsGxsNetService::RsGxsNetService(uint16_t servType, RsGeneralDataService *gds, mUpdateCounter = 0; } +void RsGxsNetService::getItemNames(std::map& names) const +{ + names.clear(); + + names[RS_PKT_SUBTYPE_NXS_SYNC_GRP_REQ_ITEM ] = "Group Sync Request" ; + names[RS_PKT_SUBTYPE_NXS_SYNC_GRP_ITEM ] = "Group Sync" ; + names[RS_PKT_SUBTYPE_NXS_SYNC_GRP_STATS_ITEM ] = "Group Stats" ; + names[RS_PKT_SUBTYPE_NXS_GRP_ITEM ] = "Group Data" ; + names[RS_PKT_SUBTYPE_NXS_ENCRYPTED_DATA_ITEM ] = "Encrypted data" ; + names[RS_PKT_SUBTYPE_NXS_SESSION_KEY_ITEM ] = "Session Key" ; + names[RS_PKT_SUBTYPE_NXS_SYNC_MSG_ITEM ] = "Message Sync" ; + names[RS_PKT_SUBTYPE_NXS_SYNC_MSG_REQ_ITEM ] = "Message Sync Request" ; + names[RS_PKT_SUBTYPE_NXS_MSG_ITEM ] = "Message Data" ; + names[RS_PKT_SUBTYPE_NXS_TRANSAC_ITEM ] = "Transaction" ; + names[RS_PKT_SUBTYPE_NXS_GRP_PUBLISH_KEY_ITEM ] = "Publish key" ; +} + RsGxsNetService::~RsGxsNetService() { RS_STACK_MUTEX(mNxsMutex) ; @@ -1972,7 +1989,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 +3017,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 diff --git a/src/gxs/rsgxsnetservice.h b/src/gxs/rsgxsnetservice.h index b74e53998..fe1dbef0d 100644 --- a/src/gxs/rsgxsnetservice.h +++ b/src/gxs/rsgxsnetservice.h @@ -99,6 +99,7 @@ public: virtual RsServiceInfo getServiceInfo() { return mServiceInfo; } + virtual void getItemNames(std::map& names) const ; public: diff --git a/src/gxs/rsgxsnetutils.cc b/src/gxs/rsgxsnetutils.cc index 4d54ce117..7454ba58a 100644 --- a/src/gxs/rsgxsnetutils.cc +++ b/src/gxs/rsgxsnetutils.cc @@ -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 { diff --git a/src/gxs/rsgxsrequesttypes.h b/src/gxs/rsgxsrequesttypes.h index a344a55e7..8009f294b 100644 --- a/src/gxs/rsgxsrequesttypes.h +++ b/src/gxs/rsgxsrequesttypes.h @@ -61,6 +61,12 @@ public: std::list mGroupIds; std::list mGroupIdResult; }; +class GroupSerializedDataReq : public GxsRequest +{ +public: + std::list mGroupIds; + std::list mGroupData; +}; class GroupDataReq : public GxsRequest { diff --git a/src/gxstunnel/p3gxstunnel.cc b/src/gxstunnel/p3gxstunnel.cc index 75f50c7d9..69bc091f4 100644 --- a/src/gxstunnel/p3gxstunnel.cc +++ b/src/gxstunnel/p3gxstunnel.cc @@ -1195,7 +1195,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) ; diff --git a/src/libretroshare.pro b/src/libretroshare.pro index dce14eafd..46daa85e8 100644 --- a/src/libretroshare.pro +++ b/src/libretroshare.pro @@ -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 diff --git a/src/plugins/pluginmanager.cc b/src/plugins/pluginmanager.cc index bbc1761fb..fa38394a5 100644 --- a/src/plugins/pluginmanager.cc +++ b/src/plugins/pluginmanager.cc @@ -50,9 +50,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); } diff --git a/src/plugins/pluginmanager.h b/src/plugins/pluginmanager.h index 5f2a8c3b7..27a74f870 100644 --- a/src/plugins/pluginmanager.h +++ b/src/plugins/pluginmanager.h @@ -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() ; /*! diff --git a/src/pqi/p3dhtmgr.cc b/src/pqi/p3dhtmgr.cc index a93577581..c1d929c94 100644 --- a/src/pqi/p3dhtmgr.cc +++ b/src/pqi/p3dhtmgr.cc @@ -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::iterator it; + std::map::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::iterator it; + std::map::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::iterator it; + std::map::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::iterator it; + std::map::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::iterator it,pit; + std::map::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::iterator it; + std::map::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::iterator it; + std::map::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::iterator it; + std::map::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::iterator it; + std::map::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::iterator it; + std::map::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; diff --git a/src/pqi/p3dhtmgr.h b/src/pqi/p3dhtmgr.h index f08c2bc96..86d6b5424 100644 --- a/src/pqi/p3dhtmgr.h +++ b/src/pqi/p3dhtmgr.h @@ -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 peers; + std::map peers; std::list stunIds; bool mStunRequired; diff --git a/src/pqi/p3peermgr.h b/src/pqi/p3peermgr.h index ee581b275..f0a9a44cb 100644 --- a/src/pqi/p3peermgr.h +++ b/src/pqi/p3peermgr.h @@ -397,7 +397,7 @@ private: std::map mReportedOwnAddresses ; std::map groupList; - uint32_t lastGroupId; + //uint32_t lastGroupId; std::list saveCleanupList; /* TEMPORARY LIST WHEN SAVING */ diff --git a/src/pqi/p3servicecontrol.cc b/src/pqi/p3servicecontrol.cc index 0b3b1514e..d0d9acbdc 100644 --- a/src/pqi/p3servicecontrol.cc +++ b/src/pqi/p3servicecontrol.cc @@ -30,7 +30,9 @@ #include "rsitems/rsitem.h" #include "serialiser/rsserial.h" #include "serialiser/rsbaseserial.h" +#include "serialiser/rsnxsitems.h" #include "pqi/p3cfgmgr.h" +#include "pqi/pqiservice.h" /*******************************/ // #define SERVICECONTROL_DEBUG 1 @@ -139,7 +141,7 @@ public: std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl; return NULL ; } - + /* add mandatory parts first */ ok &= getRawUInt32(data, rssize, &offset, &item->mServiceId); ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_NAME, item->mServiceName); @@ -249,6 +251,13 @@ const RsPeerId& p3ServiceControl::getOwnId() return mOwnPeerId; } +bool p3ServiceControl::getServiceItemNames(uint32_t serviceId,std::map& names) +{ + if(mServiceServer != NULL) + return mServiceServer->getServiceItemNames(serviceId,names) ; + + return false ; +} /* Interface for Services */ bool p3ServiceControl::registerService(const RsServiceInfo &info, bool defaultOn) @@ -538,7 +547,7 @@ bool p3ServiceControl::updateServicePermissions(uint32_t serviceId, const RsServ { for(pit = onlinePeers.begin(); pit != onlinePeers.end(); ++pit) { - if (it->second.peerHasPermission(*pit) != + if (it->second.peerHasPermission(*pit) != permissions.peerHasPermission(*pit)) { mUpdatedSet.insert(*pit); @@ -598,7 +607,7 @@ bool p3ServiceControl::checkFilter(uint32_t serviceId, const RsPeerId &peerId) #endif // 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)) //if (serviceId == RS_SERVICE_TYPE_SERVICEINFO) if (serviceId == FULLID_SERVICEINFO) @@ -692,21 +701,21 @@ bool ServiceInfoCompatible(const RsServiceInfo &info1, const RsServiceInfo &info } // ensure that info1 meets minimum requirements for info2 - if (!versionOkay(info1.mVersionMajor, info1.mVersionMinor, + if (!versionOkay(info1.mVersionMajor, info1.mVersionMinor, info2.mMinVersionMajor, info2.mMinVersionMinor)) { return false; } // ensure that info2 meets minimum requirements for info1 - if (!versionOkay(info2.mVersionMajor, info2.mVersionMinor, + if (!versionOkay(info2.mVersionMajor, info2.mVersionMinor, info1.mMinVersionMajor, info1.mMinVersionMinor)) { return false; } return true; } - + bool p3ServiceControl::updateFilterByPeer(const RsPeerId &peerId) { @@ -791,8 +800,8 @@ bool p3ServiceControl::updateFilterByPeer_locked(const RsPeerId &peerId) std::cerr << "p3ServiceControl::updateFilterByPeer_locked() Empty ... Clearing"; std::cerr << std::endl; #endif - - // empty, remove... + + // empty, remove... recordFilterChanges_locked(peerId, originalFilter, peerFilter); if (fit != mPeerFilterMap.end()) { @@ -883,7 +892,7 @@ bool p3ServiceControl::updateFilterByPeer_locked(const RsPeerId &peerId) std::cerr << "p3ServiceControl::updateFilterByPeer_locked() Empty(2) ... Clearing"; std::cerr << std::endl; #endif - + if (fit != mPeerFilterMap.end()) { mPeerFilterMap.erase(fit); @@ -901,7 +910,7 @@ bool p3ServiceControl::updateFilterByPeer_locked(const RsPeerId &peerId) return true; } -void p3ServiceControl::recordFilterChanges_locked(const RsPeerId &peerId, +void p3ServiceControl::recordFilterChanges_locked(const RsPeerId &peerId, ServicePeerFilter &originalFilter, ServicePeerFilter &updatedFilter) { #ifdef SERVICECONTROL_DEBUG @@ -1203,7 +1212,7 @@ bool p3ServiceControl::loadList(std::list& loadList) if(item != NULL) mServicePermissionMap[item->mServiceId] = *item ; - + delete *it ; } @@ -1397,49 +1406,49 @@ void p3ServiceControl::notifyServices() std::cerr << "p3ServiceControl::notifyServices(): Noone Monitoring ... skipping"; std::cerr << std::endl; #endif - + continue; } - + std::list peers; std::set::const_iterator pit; - for(pit = it->second.mAdded.begin(); + for(pit = it->second.mAdded.begin(); pit != it->second.mAdded.end(); ++pit) { pqiServicePeer peer; peer.id = *pit; peer.actions = RS_SERVICE_PEER_CONNECTED; - + peers.push_back(peer); - + #ifdef SERVICECONTROL_DEBUG std::cerr << "p3ServiceControl::notifyServices(): Peer: " << *pit << " CONNECTED"; std::cerr << std::endl; #endif } - - for(pit = it->second.mRemoved.begin(); + + for(pit = it->second.mRemoved.begin(); pit != it->second.mRemoved.end(); ++pit) { pqiServicePeer peer; peer.id = *pit; peer.actions = RS_SERVICE_PEER_DISCONNECTED; - + peers.push_back(peer); - + #ifdef SERVICECONTROL_DEBUG std::cerr << "p3ServiceControl::notifyServices(): Peer: " << *pit << " DISCONNECTED"; std::cerr << std::endl; #endif } - + for(; sit != eit; ++sit) { #ifdef SERVICECONTROL_DEBUG std::cerr << "p3ServiceControl::notifyServices(): Sending to Monitoring Service"; std::cerr << std::endl; #endif - + sit->second->statusChange(peers); } } @@ -1501,17 +1510,17 @@ void RsServicePermissions::resetPermission(const RsPeerId& peerId) } RsServiceInfo::RsServiceInfo( - const uint16_t service_type, - const std::string service_name, + const uint16_t service_type, + const std::string service_name, const uint16_t version_major, const uint16_t version_minor, const uint16_t min_version_major, const uint16_t min_version_minor) - :mServiceName(service_name), - mServiceType((((uint32_t) RS_PKT_VERSION_SERVICE) << 24) + (((uint32_t) service_type) << 8)), - mVersionMajor(version_major), + :mServiceName(service_name), + mServiceType((((uint32_t) RS_PKT_VERSION_SERVICE) << 24) + (((uint32_t) service_type) << 8)), + mVersionMajor(version_major), mVersionMinor(version_minor), - mMinVersionMajor(min_version_major), + mMinVersionMajor(min_version_major), mMinVersionMinor(min_version_minor) { return; @@ -1519,7 +1528,7 @@ RsServiceInfo::RsServiceInfo( RsServiceInfo::RsServiceInfo() - :mServiceName("unknown"), + :mServiceName("unknown"), mServiceType(0), mVersionMajor(0), mVersionMinor(0), diff --git a/src/pqi/p3servicecontrol.h b/src/pqi/p3servicecontrol.h index 948481a2b..9c9724347 100644 --- a/src/pqi/p3servicecontrol.h +++ b/src/pqi/p3servicecontrol.h @@ -36,6 +36,8 @@ #include "pqi/pqiservicemonitor.h" #include "pqi/p3linkmgr.h" +class p3ServiceServer ; + class ServiceNotifications { public: @@ -101,6 +103,9 @@ virtual bool updateServicePermissions(uint32_t serviceId, const RsServicePermiss virtual void getPeersConnected(const uint32_t serviceId, std::set &peerSet); virtual bool isPeerConnected(const uint32_t serviceId, const RsPeerId &peerId); + // Gets the list of items used by that service +virtual bool getServiceItemNames(uint32_t serviceId,std::map& names) ; + /** * Registration for all Services. */ @@ -132,6 +137,8 @@ virtual bool updateServicesProvided(const RsPeerId &peerId, const RsPeerServiceI // pqiMonitor. virtual void statusChange(const std::list &plist); + virtual void setServiceServer(p3ServiceServer *p) { mServiceServer = p ; } + protected: // configuration. virtual bool saveList(bool &cleanup, std::list&); @@ -196,6 +203,7 @@ bool peerHasPermissionForService_locked(const RsPeerId &peerId, uint32_t service // Below here is saved in Configuration. std::map mServicePermissionMap; + p3ServiceServer *mServiceServer ; }; diff --git a/src/pqi/pqimonitor.cc b/src/pqi/pqimonitor.cc index 03894a66d..fac7a50f9 100644 --- a/src/pqi/pqimonitor.cc +++ b/src/pqi/pqimonitor.cc @@ -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*/) diff --git a/src/pqi/pqimonitor.h b/src/pqi/pqimonitor.h index 34d998e75..94e9bdf05 100644 --- a/src/pqi/pqimonitor.h +++ b/src/pqi/pqimonitor.h @@ -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); }; diff --git a/src/pqi/pqiperson.cc b/src/pqi/pqiperson.cc index cade0c39e..e7d1cf18b 100644 --- a/src/pqi/pqiperson.cc +++ b/src/pqi/pqiperson.cc @@ -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() diff --git a/src/pqi/pqiperson.h b/src/pqi/pqiperson.h index f3ff940e1..69faec48c 100644 --- a/src/pqi/pqiperson.h +++ b/src/pqi/pqiperson.h @@ -29,6 +29,7 @@ #define MRK_PQI_PERSON_HEADER +#include #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 */ }; diff --git a/src/pqi/pqiservice.cc b/src/pqi/pqiservice.cc index 4ba249c69..d9c93cc18 100644 --- a/src/pqi/pqiservice.cc +++ b/src/pqi/pqiservice.cc @@ -79,11 +79,26 @@ int p3ServiceServer::addService(pqiService *ts, bool defaultOn) services[info.mServiceType] = ts; // This doesn't need to be in Mutex. - mServiceControl->registerService(info, defaultOn); + mServiceControl->registerService(info,defaultOn); return 1; } +bool p3ServiceServer::getServiceItemNames(uint32_t service_type,std::map& names) +{ + RsStackMutex stack(srvMtx); /********* LOCKED *********/ + + std::map::iterator it=services.find(service_type) ; + + if(it != services.end()) + { + it->second->getItemNames(names) ; + return true ; + } + else + return false ; +} + int p3ServiceServer::removeService(pqiService *ts) { RsStackMutex stack(srvMtx); /********* LOCKED *********/ diff --git a/src/pqi/pqiservice.h b/src/pqi/pqiservice.h index c293cc005..41c540d4c 100644 --- a/src/pqi/pqiservice.h +++ b/src/pqi/pqiservice.h @@ -60,24 +60,26 @@ class p3ServiceServerIface; class pqiService { - protected: +protected: pqiService() // our type of packets. - :mServiceServer(NULL) { return; } + :mServiceServer(NULL) { return; } -virtual ~pqiService() { return; } + virtual ~pqiService() { return; } - public: -void setServiceServer(p3ServiceServerIface *server); - // -virtual bool recv(RsRawItem *) = 0; -virtual bool send(RsRawItem *item); +public: + void setServiceServer(p3ServiceServerIface *server); + // + virtual bool recv(RsRawItem *) = 0; + virtual bool send(RsRawItem *item); -virtual RsServiceInfo getServiceInfo() = 0; + virtual RsServiceInfo getServiceInfo() = 0; -virtual int tick() { return 0; } + virtual int tick() { return 0; } - private: + virtual void getItemNames(std::map& /*names*/) const {} // This does nothing by default. Service should derive it in order to give info for the UI + +private: p3ServiceServerIface *mServiceServer; // const, no need for mutex. }; @@ -97,10 +99,10 @@ public: virtual ~p3ServiceServerIface() {} -virtual bool recvItem(RsRawItem *) = 0; -virtual bool sendItem(RsRawItem *) = 0; - + virtual bool recvItem(RsRawItem *) = 0; + virtual bool sendItem(RsRawItem *) = 0; + virtual bool getServiceItemNames(uint32_t service_type,std::map& names) =0; }; class p3ServiceServer : public p3ServiceServerIface @@ -108,13 +110,15 @@ class p3ServiceServer : public p3ServiceServerIface public: p3ServiceServer(pqiPublisher *pub, p3ServiceControl *ctrl); -int addService(pqiService *, bool defaultOn); -int removeService(pqiService *); + int addService(pqiService *, bool defaultOn); + int removeService(pqiService *); -bool recvItem(RsRawItem *); -bool sendItem(RsRawItem *); + bool recvItem(RsRawItem *); + bool sendItem(RsRawItem *); -int tick(); + bool getServiceItemNames(uint32_t service_type, std::map& names) ; + + int tick(); public: private: @@ -122,7 +126,7 @@ private: pqiPublisher *mPublisher; // constant no need for mutex. p3ServiceControl *mServiceControl; - RsMutex srvMtx; + RsMutex srvMtx; std::map services; }; diff --git a/src/pqi/pqissl.cc b/src/pqi/pqissl.cc index b7709bb82..bcc49cbbc 100644 --- a/src/pqi/pqissl.cc +++ b/src/pqi/pqissl.cc @@ -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()); diff --git a/src/pqi/pqissludp.cc b/src/pqi/pqissludp.cc index 9519e2af3..29bd228c9 100644 --- a/src/pqi/pqissludp.cc +++ b/src/pqi/pqissludp.cc @@ -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) { diff --git a/src/pqi/pqissludp.h b/src/pqi/pqissludp.h index 848717bbd..195e9e604 100644 --- a/src/pqi/pqissludp.h +++ b/src/pqi/pqissludp.h @@ -95,7 +95,7 @@ private: BIO *tou_bio; // specific to ssludp. - long listen_checktime; + //long listen_checktime; uint32_t mConnectPeriod; uint32_t mConnectFlags; diff --git a/src/pqi/sslfns.cc b/src/pqi/sslfns.cc index 7cf742956..ba5a9e6a3 100644 --- a/src/pqi/sslfns.cc +++ b/src/pqi/sslfns.cc @@ -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]) ; diff --git a/src/retroshare/rsgxsifacetypes.h b/src/retroshare/rsgxsifacetypes.h index 0b1682327..fd477fc9f 100644 --- a/src/retroshare/rsgxsifacetypes.h +++ b/src/retroshare/rsgxsifacetypes.h @@ -26,7 +26,7 @@ typedef std::pair RsGxsGrpMsgIdPair; typedef std::map > MsgRelatedIdResult; typedef std::map > GxsMsgReq; -class RsMsgMetaData; +struct RsMsgMetaData; typedef std::map > MsgMetaResult; diff --git a/src/retroshare/rsgxsservice.h b/src/retroshare/rsgxsservice.h index 8f26e5262..6afed31c6 100644 --- a/src/retroshare/rsgxsservice.h +++ b/src/retroshare/rsgxsservice.h @@ -5,7 +5,7 @@ #include "retroshare/rsgxsifacetypes.h" #include "retroshare/rstokenservice.h" -class RsMsgMetaData ; +struct RsMsgMetaData ; typedef std::map > GxsMsgMetaMap; typedef std::map > GxsMsgRelatedMetaMap; diff --git a/src/retroshare/rsidentity.h b/src/retroshare/rsidentity.h index 82f4932a3..6be124e93 100644 --- a/src/retroshare/rsidentity.h +++ b/src/retroshare/rsidentity.h @@ -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 &groups) = 0; + virtual bool getGroupSerializedData(const uint32_t &token, std::map& serialized_groups)=0; //virtual bool getMsgData(const uint32_t &token, std::vector &opinions) = 0; }; diff --git a/src/retroshare/rsservicecontrol.h b/src/retroshare/rsservicecontrol.h index a6d8fde7c..7558764e7 100644 --- a/src/retroshare/rsservicecontrol.h +++ b/src/retroshare/rsservicecontrol.h @@ -109,6 +109,7 @@ virtual ~RsServiceControl() { return; } virtual bool getOwnServices(RsPeerServiceInfo &info) = 0; virtual std::string getServiceName(uint32_t service_id) = 0; +virtual bool getServiceItemNames(uint32_t service_id,std::map& names) = 0; virtual bool getServicesAllowed(const RsPeerId &peerId, RsPeerServiceInfo &info) = 0; virtual bool getServicesProvided(const RsPeerId &peerId, RsPeerServiceInfo &info) = 0; diff --git a/src/retroshare/rstokenservice.h b/src/retroshare/rstokenservice.h index c55213965..5e74a527f 100644 --- a/src/retroshare/rstokenservice.h +++ b/src/retroshare/rstokenservice.h @@ -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 diff --git a/src/rsserver/p3peers.cc b/src/rsserver/p3peers.cc index 73a5801fd..f43dfb485 100644 --- a/src/rsserver/p3peers.cc +++ b/src/rsserver/p3peers.cc @@ -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; diff --git a/src/rsserver/rsinit.cc b/src/rsserver/rsinit.cc index 47036b691..fd378b286 100644 --- a/src/rsserver/rsinit.cc +++ b/src/rsserver/rsinit.cc @@ -1243,6 +1243,8 @@ int RsServer::StartupRetroShare() pqih = new pqisslpersongrp(serviceCtrl, flags, mPeerMgr); //pqih = new pqipersongrpDummy(none, flags); + serviceCtrl->setServiceServer(pqih) ; + /****** New Ft Server **** !!! */ ftServer *ftserver = new ftServer(mPeerMgr, serviceCtrl); ftserver->setConfigDirectory(rsAccounts->PathAccountDirectory()); diff --git a/src/services/p3banlist.cc b/src/services/p3banlist.cc index 800fe697c..6fd733de5 100644 --- a/src/services/p3banlist.cc +++ b/src/services/p3banlist.cc @@ -67,8 +67,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()); diff --git a/src/services/p3banlist.h b/src/services/p3banlist.h index 7cdc983a5..5a31bd1b1 100644 --- a/src/services/p3banlist.h +++ b/src/services/p3banlist.h @@ -148,7 +148,7 @@ private: std::map mWhiteListedRanges; p3ServiceControl *mServiceCtrl; - p3NetMgr *mNetMgr; + //p3NetMgr *mNetMgr; time_t mLastDhtInfoRequest ; bool mIPFilteringEnabled ; diff --git a/src/services/p3gxsreputation.cc b/src/services/p3gxsreputation.cc index d2ad1b9da..ae4189cfe 100644 --- a/src/services/p3gxsreputation.cc +++ b/src/services/p3gxsreputation.cc @@ -1036,7 +1036,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); } diff --git a/src/services/p3gxsreputation.h b/src/services/p3gxsreputation.h index 06ff7415b..ad45e2298 100644 --- a/src/services/p3gxsreputation.h +++ b/src/services/p3gxsreputation.h @@ -176,7 +176,7 @@ private: time_t mLastIdentityFlagsUpdate ; bool mReputationsUpdated; - float mAutoBanIdentitiesLimit ; + //float mAutoBanIdentitiesLimit ; bool mAutoSetPositiveOptionToContacts; p3LinkMgr *mLinkMgr; diff --git a/src/services/p3idservice.cc b/src/services/p3idservice.cc index 37c609373..f267accd0 100644 --- a/src/services/p3idservice.cc +++ b/src/services/p3idservice.cc @@ -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 &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::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 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::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 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 ¶ms) { @@ -709,7 +788,7 @@ bool p3IdService::createIdentity(uint32_t& token, RsIdentityParameters ¶ms) 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 @@ -1395,6 +1474,28 @@ bool p3IdService::getGroupData(const uint32_t &token, std::vector return ok; } +bool p3IdService::getGroupSerializedData(const uint32_t &token, std::map& 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; +} /********************************************************************************/ /********************************************************************************/ @@ -4117,6 +4218,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; diff --git a/src/services/p3idservice.h b/src/services/p3idservice.h index f745aca83..a88f0ad7e 100644 --- a/src/services/p3idservice.h +++ b/src/services/p3idservice.h @@ -212,6 +212,13 @@ private: void init(const RsGxsIdGroupItem *item, const RsTlvPublicRSAKey& in_pub_key, const RsTlvPrivateRSAKey& in_priv_key,const std::list &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 &groups); + virtual bool getGroupSerializedData(const uint32_t &token, std::map& serialized_groups); + //virtual bool getMsgData(const uint32_t &token, std::vector &opinions); // These are local - and not exposed via RsIdentity. @@ -302,6 +311,8 @@ public: virtual bool requestKey(const RsGxsId &id, const std::list &peers, 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 ****************/ @@ -394,6 +405,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. * @@ -524,6 +541,8 @@ private: std::map > mIdsNotPresent; std::map mKeysTS ; + std::map mSerialisedIdentities ; + // keep a list of regular contacts. This is useful to sort IDs, and allow some services to priviledged ids only. std::set mContacts; RsNetworkExchangeService* mNes; diff --git a/src/util/radix64.h b/src/util/radix64.h index dc7f8528c..7776995f9 100644 --- a/src/util/radix64.h +++ b/src/util/radix64.h @@ -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. diff --git a/src/util/rsnet.cc b/src/util/rsnet.cc index 63501511b..8b8c9ef82 100644 --- a/src/util/rsnet.cc +++ b/src/util/rsnet.cc @@ -81,15 +81,18 @@ bool rsGetHostByName(const std::string& hostname, in_addr& returned_addr) addrinfo *info = NULL; int res = getaddrinfo(hostname.c_str(),NULL,NULL,&info) ; + bool ok = true; if(res > 0 || info == NULL || info->ai_addr == NULL) { std::cerr << "(EE) getaddrinfo returned error " << res << " on string \"" << hostname << "\"" << std::endl; returned_addr.s_addr = 0 ; + ok = false; } else returned_addr.s_addr = ((sockaddr_in*)info->ai_addr)->sin_addr.s_addr ; - freeaddrinfo(info) ; + if(info) + freeaddrinfo(info) ; #ifdef DEPRECATED_TO_REMOVE #if defined(WINDOWS_SYS) || defined(__APPLE__) || defined(__HAIKU__) @@ -123,7 +126,7 @@ bool rsGetHostByName(const std::string& hostname, in_addr& returned_addr) returned_addr.s_addr = *(unsigned long*) (result->h_addr); #endif - return true ; + return ok; } bool isValidNet(const struct in_addr *addr) diff --git a/tests/unittests/libretroshare/gxs/nxs_test/nxstesthub.cc b/tests/unittests/libretroshare/gxs/nxs_test/nxstesthub.cc index 216f971c1..36b288341 100644 --- a/tests/unittests/libretroshare/gxs/nxs_test/nxstesthub.cc +++ b/tests/unittests/libretroshare/gxs/nxs_test/nxstesthub.cc @@ -53,6 +53,7 @@ public: { return recvItem(i); } + bool getServiceItemNames(uint32_t /*service_type*/, std::map& /*names*/) { return false; } private: RsPeerId mPeerId; RecvPeerItemIface* mRecvIface;