diff --git a/libretroshare/src/gxs/rsgxsnetutils.cc b/libretroshare/src/gxs/rsgxsnetutils.cc index a3d46961e..9bb9edd58 100644 --- a/libretroshare/src/gxs/rsgxsnetutils.cc +++ b/libretroshare/src/gxs/rsgxsnetutils.cc @@ -233,11 +233,11 @@ bool GrpCircleVetting::expired() { return time(NULL) > (mTimeStamp + EXPIRY_PERIOD_OFFSET); } -bool GrpCircleVetting::canSend(const RsPgpId& peerId, const RsGxsCircleId& circleId) +bool GrpCircleVetting::canSend(const SSLIdType& peerId, const RsGxsCircleId& circleId) { if(mCircles->isLoaded(circleId)) { - const RsPgpId& pgpId = rsPeers->getGPGId(peerId); + const PGPIdType& pgpId = rsPeers->getGPGId(peerId); return mCircles->canSend(circleId, pgpId); } @@ -247,7 +247,7 @@ bool GrpCircleVetting::canSend(const RsPgpId& peerId, const RsGxsCircleId& circl } GrpCircleIdRequestVetting::GrpCircleIdRequestVetting( - RsGcxs* const circles, std::vector grpCircleV, const std::string& peerId) + RsGcxs* const circles, std::vector grpCircleV, const RsPeerId& peerId) : GrpCircleVetting(circles), mGrpCircleV(grpCircleV), mPeerId(peerId) {} bool GrpCircleIdRequestVetting::cleared() @@ -287,7 +287,7 @@ MsgIdCircleVet::MsgIdCircleVet(const RsGxsMessageId& msgId, MsgCircleIdsRequestVetting::MsgCircleIdsRequestVetting(RsGcxs* const circles, std::vector msgs, const RsGxsGroupId& grpId, - const std::string& peerId, const RsGxsCircleId& circleId) + const RsPeerId& peerId, const RsGxsCircleId& circleId) : GrpCircleVetting(circles), mMsgs(msgs), mGrpId(grpId), mPeerId(peerId), mCircleId(circleId) {} bool MsgCircleIdsRequestVetting::cleared() diff --git a/libretroshare/src/gxs/rsgxsnetutils.h b/libretroshare/src/gxs/rsgxsnetutils.h index 0708011e4..8e2478d3e 100644 --- a/libretroshare/src/gxs/rsgxsnetutils.h +++ b/libretroshare/src/gxs/rsgxsnetutils.h @@ -250,7 +250,7 @@ public: virtual bool cleared() = 0; protected: - bool canSend(const RsPgpId& peerId, const RsGxsCircleId& circleId); + bool canSend(const SSLIdType& peerId, const RsGxsCircleId& circleId); private: diff --git a/libretroshare/src/retroshare/rsidentity.h b/libretroshare/src/retroshare/rsidentity.h index a1891e6ac..e8c63257b 100644 --- a/libretroshare/src/retroshare/rsidentity.h +++ b/libretroshare/src/retroshare/rsidentity.h @@ -89,7 +89,7 @@ class RsGxsIdGroup // Not Serialised - for GUI's benefit. bool mPgpKnown; - std::string mPgpId; + RsPgpId mPgpId; }; @@ -214,7 +214,7 @@ class RsIdentityDetails // PGP Stuff. bool mPgpLinked; bool mPgpKnown; - std::string mPgpId; + RsPgpId mPgpId; // Recogn details. std::list mRecognTags; diff --git a/libretroshare/src/serialiser/rsgxscircleitems.cc b/libretroshare/src/serialiser/rsgxscircleitems.cc index a48a4fe24..7b85afc70 100644 --- a/libretroshare/src/serialiser/rsgxscircleitems.cc +++ b/libretroshare/src/serialiser/rsgxscircleitems.cc @@ -121,7 +121,10 @@ bool RsGxsCircleGroupItem::convertFrom(const RsGxsCircleGroup &group) // Enforce the local rules. if (meta.mCircleType == GXS_CIRCLE_TYPE_LOCAL) { - pgpIdSet.ids = group.mLocalFriends; + std::list::const_iterator it = group.mLocalFriends.begin(); + + for(; it != group.mLocalFriends.end(); it++) + pgpIdSet.ids.push_back(it->toStdString()); } else { @@ -138,7 +141,9 @@ bool RsGxsCircleGroupItem::convertTo(RsGxsCircleGroup &group) const // Enforce the local rules. if (meta.mCircleType == GXS_CIRCLE_TYPE_LOCAL) { - group.mLocalFriends = pgpIdSet.ids; + std::list::const_iterator it = pgpIdSet.ids.begin(); + for(; it != pgpIdSet.ids.end(); it++) + group.mLocalFriends.push_back(RsPgpId(*it)); group.mInvitedMembers.clear(); } else diff --git a/libretroshare/src/services/p3gxscircles.cc b/libretroshare/src/services/p3gxscircles.cc index d556f8016..6a559cbda 100644 --- a/libretroshare/src/services/p3gxscircles.cc +++ b/libretroshare/src/services/p3gxscircles.cc @@ -311,7 +311,7 @@ bool p3GxsCircles::loadCircle(const RsGxsCircleId &circleId) return cache_request_load(circleId); } -int p3GxsCircles::canSend(const RsGxsCircleId &circleId, const std::string &id) +int p3GxsCircles::canSend(const RsGxsCircleId &circleId, const RsPgpId &id) { RsStackMutex stack(mCircleMtx); /********** STACK LOCKED MTX ******/ if (mCircleCache.is_cached(circleId)) diff --git a/libretroshare/src/services/p3idservice.cc b/libretroshare/src/services/p3idservice.cc index cc490a3f0..123773e58 100644 --- a/libretroshare/src/services/p3idservice.cc +++ b/libretroshare/src/services/p3idservice.cc @@ -478,7 +478,7 @@ bool p3IdService::haveReputation(const RsGxsId &id) return haveKey(id); } -bool p3IdService::loadReputation(const RsGxsId &id, const std::list& peers) +bool p3IdService::loadReputation(const RsGxsId &id, const std::list& peers) { if (haveKey(id)) return true; @@ -556,7 +556,7 @@ bool p3IdService::getGroupData(const uint32_t &token, std::vector else { group.mPgpKnown = false; - group.mPgpId = ""; + group.mPgpId.clear(); std::cerr << "p3IdService::getGroupData() Failed to decode ServiceString"; std::cerr << std::endl; @@ -699,7 +699,8 @@ bool SSGxsIdPgp::load(const std::string &input) if (1 == sscanf(input.c_str(), "K:1 I:%[^)]", pgpline)) { idKnown = true; - pgpId = pgpline; + std::string str_line = pgpline; + pgpId = RsPgpId(str_line); } else if (1 == sscanf(input.c_str(), "K:0 T:%d", ×tamp)) { @@ -719,7 +720,7 @@ std::string SSGxsIdPgp::save() const if (idKnown) { output += "K:1 I:"; - output += pgpId; + output += pgpId.toStdString(); } else { @@ -1039,7 +1040,7 @@ void RsGxsIdCache::updateServiceString(std::string serviceString) } else { - details.mPgpId = ""; + details.mPgpId.clear(); } } @@ -1097,7 +1098,7 @@ void RsGxsIdCache::updateServiceString(std::string serviceString) else { details.mPgpKnown = false; - details.mPgpId = ""; + details.mPgpId.clear(); details.mOpinion = 0; details.mReputation = 0; @@ -1329,7 +1330,7 @@ bool p3IdService::cache_store(const RsGxsIdGroupItem *item) #define MIN_CYCLE_GAP 2 -bool p3IdService::cache_request_load(const RsGxsId &id, const std::list& peers) +bool p3IdService::cache_request_load(const RsGxsId &id, const std::list& peers) { #ifdef DEBUG_IDS std::cerr << "p3IdService::cache_request_load(" << id << ")"; @@ -1370,7 +1371,7 @@ bool p3IdService::cache_start_load() RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/ /* now we process the modGroupList -> a map so we can use it easily later, and create id list too */ - std::map >::iterator it; + std::map >::iterator it; for(it = mCacheLoad_ToCache.begin(); it != mCacheLoad_ToCache.end(); it++) { #ifdef DEBUG_IDS @@ -1471,8 +1472,8 @@ void p3IdService::requestIdsFromNet() { RsStackMutex stack(mIdMtx); - std::map >::const_iterator cit; - std::map > requests; + std::map >::const_iterator cit; + std::map > requests; // transform to appropriate structure ( > map) to make request to nes for(cit = mIdsNotPresent.begin(); cit != mIdsNotPresent.end(); cit++) @@ -1486,13 +1487,13 @@ void p3IdService::requestIdsFromNet() } - const std::list& peers = cit->second; - std::list::const_iterator cit2; + const std::list& peers = cit->second; + std::list::const_iterator cit2; for(cit2 = peers.begin(); cit2 != peers.end(); cit2++) requests[*cit2].push_back(cit->first); } - std::map >::const_iterator cit2; + std::map >::const_iterator cit2; for(cit2 = requests.begin(); cit2 != requests.end(); cit2++) { @@ -2234,7 +2235,7 @@ bool p3IdService::pgphash_process() /* update */ ssdata.pgp.idKnown = true; - ssdata.pgp.pgpId = pgpId.toStdString(); + ssdata.pgp.pgpId = pgpId; } else @@ -2312,7 +2313,7 @@ bool p3IdService::checkId(const RsGxsIdGroup &grp, PGPIdType &pgpId) /* check signature too */ if (AuthGPG::getAuthGPG()->VerifySignBin((void *) hash.toByteArray(), hash.SIZE_IN_BYTES, (unsigned char *) grp.mPgpIdSign.c_str(), grp.mPgpIdSign.length(), - mit->second.toStdString())) + mit->second)) { std::cerr << "p3IdService::checkId() Signature Okay too!"; std::cerr << std::endl; @@ -2372,14 +2373,14 @@ void p3IdService::getPgpIdList() std::cerr << std::endl; #endif // DEBUG_IDS - std::list list; + std::list list; AuthGPG::getAuthGPG()->getGPGFilteredList(list); RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/ mPgpFingerprintMap.clear(); - std::list::iterator it; + std::list::iterator it; for(it = list.begin(); it != list.end(); it++) { PGPIdType pgpId(*it); @@ -2840,7 +2841,7 @@ void p3IdService::generateDummy_OwnIds() /* grab all the gpg ids... and make some ids */ - std::string ownId = rsPeers->getGPGOwnId(); + PGPIdType ownId = rsPeers->getGPGOwnId(); // generate some ownIds. int genCount = 0; @@ -2854,15 +2855,15 @@ void p3IdService::generateDummy_OwnIds() id.mMeta.mGroupFlags = RSGXSID_GROUPFLAG_REALID; - // HACK FOR DUMMY GENERATION. - id.mMeta.mAuthorId = ownId; - if (rsPeers->getPeerDetails(ownId, details)) - { - std::ostringstream out; - out << details.name << "_" << i + 1; - - id.mMeta.mGroupName = out.str(); - } +// // HACK FOR DUMMY GENERATION. +// id.mMeta.mAuthorId = ownId.toStdString(); +// if (rsPeers->getPeerDetails(ownId, details)) +// { +// std::ostringstream out; +// out << details.name << "_" << i + 1; +// +// id.mMeta.mGroupName = out.str(); +// } uint32_t dummyToken = 0; createGroup(dummyToken, id); @@ -2875,8 +2876,8 @@ void p3IdService::generateDummy_FriendPGP() RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/ // Now Generate for friends. - std::list gpgids; - std::list::iterator it; + std::list gpgids; + std::list::const_iterator it; rsPeers->getGPGAllList(gpgids); RsGxsIdGroup id; @@ -2888,10 +2889,10 @@ void p3IdService::generateDummy_FriendPGP() for(int j = 0; j < idx; j++, it++) ; // HACK FOR DUMMY GENERATION. - id.mMeta.mAuthorId = *it; + id.mMeta.mAuthorId = it->toStdString(); RsPeerDetails details; - if (rsPeers->getPeerDetails(*it, details)) + if (/*rsPeers->getPeerDetails(*it, details)*/false) { std::ostringstream out; out << details.name << "_" << RSRandom::random_u32() % 1000; diff --git a/libretroshare/src/services/p3idservice.h b/libretroshare/src/services/p3idservice.h index 0269c7f97..30e4d50a1 100644 --- a/libretroshare/src/services/p3idservice.h +++ b/libretroshare/src/services/p3idservice.h @@ -73,7 +73,7 @@ virtual std::string save() const; bool idKnown; time_t lastCheckTs; uint32_t checkAttempts; - std::string pgpId; + RsPgpId pgpId; }; class SSGxsIdRecognTags: public SSBit @@ -290,7 +290,7 @@ virtual void handle_event(uint32_t event_type, const std::string &elabel); */ int cache_tick(); - bool cache_request_load(const RsGxsId &id, const std::list& peers = std::list()); + bool cache_request_load(const RsGxsId &id, const std::list& peers = std::list()); bool cache_start_load(); bool cache_load_for_token(uint32_t token); @@ -303,7 +303,7 @@ virtual void handle_event(uint32_t event_type, const std::string &elabel); // Mutex protected. //std::list mCacheLoad_ToCache; - std::map > mCacheLoad_ToCache, mPendingCache; + std::map > mCacheLoad_ToCache, mPendingCache; // Switching to RsMemCache for Key Caching. RsMemCache mPublicKeyCache; @@ -434,7 +434,7 @@ std::string genRandomId(int len = 20); std::map > mIdsPendingCache; std::map > mGroupNotPresent; - std::map > mIdsNotPresent; + std::map > mIdsNotPresent; RsNetworkExchangeService* mNes; }; diff --git a/libretroshare/src/util/rsid.h b/libretroshare/src/util/rsid.h index 7e9654ac5..1bb89ad7a 100644 --- a/libretroshare/src/util/rsid.h +++ b/libretroshare/src/util/rsid.h @@ -27,130 +27,130 @@ // #pragma once - -#include -#include -#include -#include -#include - -template class t_RsGenericIdType -{ - public: - t_RsGenericIdType() - { - memset(bytes,0,ID_SIZE_IN_BYTES) ; // by default, ids are set to null() - } - virtual ~t_RsGenericIdType() {} - - // Explicit constructor from a hexadecimal string - // - explicit t_RsGenericIdType(const std::string& hex_string) ; - - // Explicit constructor from a byte array. The array should have size at least ID_SIZE_IN_BYTES - // - explicit t_RsGenericIdType(const unsigned char bytes[]) ; - - // Random initialization. Can be useful for testing. - // - static t_RsGenericIdType random() - { - t_RsGenericIdType id ; - - for(uint32_t i=0;i& fp) const { return !memcmp(bytes,fp.bytes,ID_SIZE_IN_BYTES) ; } - inline bool operator!=(const t_RsGenericIdType& fp) const { return !!memcmp(bytes,fp.bytes,ID_SIZE_IN_BYTES); } - inline bool operator< (const t_RsGenericIdType& fp) const { return (memcmp(bytes,fp.bytes,ID_SIZE_IN_BYTES) < 0) ; } - - inline bool isNull() const - { - for(int i=0;i std::string t_RsGenericIdType::toStdString(bool upper_case) const -{ - static const char outh[16] = { '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' } ; - static const char outl[16] = { '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f' } ; - - std::string res(ID_SIZE_IN_BYTES*2,' ') ; - - for(uint32_t j = 0; j < ID_SIZE_IN_BYTES; j++) - if(upper_case) - { - res[2*j ] = outh[ (bytes[j]>>4) ] ; - res[2*j+1] = outh[ bytes[j] & 0xf ] ; - } - else - { - res[2*j ] = outl[ (bytes[j]>>4) ] ; - res[2*j+1] = outl[ bytes[j] & 0xf ] ; - } - - return res ; -} - -template t_RsGenericIdType::t_RsGenericIdType(const std::string& s) -{ - int n=0; - if(s.length() != ID_SIZE_IN_BYTES*2) - throw std::runtime_error("t_RsGenericIdType<>::t_RsGenericIdType(std::string&): supplied string in constructor has wrong size.") ; - - for(uint32_t i = 0; i < ID_SIZE_IN_BYTES; ++i) - { - bytes[i] = 0 ; - - for(int k=0;k<2;++k) - { - char b = s[n++] ; - - if(b >= 'A' && b <= 'F') - bytes[i] += (b-'A'+10) << 4*(1-k) ; - else if(b >= 'a' && b <= 'f') - bytes[i] += (b-'a'+10) << 4*(1-k) ; - else if(b >= '0' && b <= '9') - bytes[i] += (b-'0') << 4*(1-k) ; - else - throw std::runtime_error("t_RsGenericIdType<>::t_RsGenericIdType(std::string&): supplied string is not purely hexadecimal") ; - } - } -} - -template t_RsGenericIdType::t_RsGenericIdType(const unsigned char *mem) -{ - memcpy(bytes,mem,ID_SIZE_IN_BYTES) ; -} - -static const int SSL_ID_SIZE = 16 ; -static const int PGP_KEY_ID_SIZE = 8 ; -static const int PGP_KEY_FINGERPRINT_SIZE = 20 ; -static const int SHA1_SIZE = 20 ; - -// These constants are random, but should be different, in order to make the various IDs incompatible with each other. // -static const uint32_t RS_GENERIC_ID_SSL_ID_TYPE = 0x038439ff ; -static const uint32_t RS_GENERIC_ID_PGP_ID_TYPE = 0x80339f4f ; -static const uint32_t RS_GENERIC_ID_SHA1_ID_TYPE = 0x9540284e ; -static const uint32_t RS_GENERIC_ID_PGP_FINGERPRINT_TYPE = 0x102943e3 ; - -typedef t_RsGenericIdType< SSL_ID_SIZE , RS_GENERIC_ID_SSL_ID_TYPE> SSLIdType ; -typedef t_RsGenericIdType< PGP_KEY_ID_SIZE , RS_GENERIC_ID_PGP_ID_TYPE> PGPIdType; -typedef t_RsGenericIdType< SHA1_SIZE , RS_GENERIC_ID_SHA1_ID_TYPE> Sha1CheckSum ; -typedef t_RsGenericIdType< PGP_KEY_FINGERPRINT_SIZE, RS_GENERIC_ID_PGP_FINGERPRINT_TYPE> PGPFingerprintType ; +//#include +//#include +//#include +//#include +//#include +// +//template class t_RsGenericIdType +//{ +// public: +// t_RsGenericIdType() +// { +// memset(bytes,0,ID_SIZE_IN_BYTES) ; // by default, ids are set to null() +// } +// virtual ~t_RsGenericIdType() {} +// +// // Explicit constructor from a hexadecimal string +// // +// explicit t_RsGenericIdType(const std::string& hex_string) ; +// +// // Explicit constructor from a byte array. The array should have size at least ID_SIZE_IN_BYTES +// // +// explicit t_RsGenericIdType(const unsigned char bytes[]) ; +// +// // Random initialization. Can be useful for testing. +// // +// static t_RsGenericIdType random() +// { +// t_RsGenericIdType id ; +// +// for(uint32_t i=0;i& fp) const { return !memcmp(bytes,fp.bytes,ID_SIZE_IN_BYTES) ; } +// inline bool operator!=(const t_RsGenericIdType& fp) const { return !!memcmp(bytes,fp.bytes,ID_SIZE_IN_BYTES); } +// inline bool operator< (const t_RsGenericIdType& fp) const { return (memcmp(bytes,fp.bytes,ID_SIZE_IN_BYTES) < 0) ; } +// +// inline bool isNull() const +// { +// for(int i=0;i std::string t_RsGenericIdType::toStdString(bool upper_case) const +//{ +// static const char outh[16] = { '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' } ; +// static const char outl[16] = { '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f' } ; +// +// std::string res(ID_SIZE_IN_BYTES*2,' ') ; +// +// for(uint32_t j = 0; j < ID_SIZE_IN_BYTES; j++) +// if(upper_case) +// { +// res[2*j ] = outh[ (bytes[j]>>4) ] ; +// res[2*j+1] = outh[ bytes[j] & 0xf ] ; +// } +// else +// { +// res[2*j ] = outl[ (bytes[j]>>4) ] ; +// res[2*j+1] = outl[ bytes[j] & 0xf ] ; +// } +// +// return res ; +//} +// +//template t_RsGenericIdType::t_RsGenericIdType(const std::string& s) +//{ +// int n=0; +// if(s.length() != ID_SIZE_IN_BYTES*2) +// throw std::runtime_error("t_RsGenericIdType<>::t_RsGenericIdType(std::string&): supplied string in constructor has wrong size.") ; +// +// for(uint32_t i = 0; i < ID_SIZE_IN_BYTES; ++i) +// { +// bytes[i] = 0 ; +// +// for(int k=0;k<2;++k) +// { +// char b = s[n++] ; +// +// if(b >= 'A' && b <= 'F') +// bytes[i] += (b-'A'+10) << 4*(1-k) ; +// else if(b >= 'a' && b <= 'f') +// bytes[i] += (b-'a'+10) << 4*(1-k) ; +// else if(b >= '0' && b <= '9') +// bytes[i] += (b-'0') << 4*(1-k) ; +// else +// throw std::runtime_error("t_RsGenericIdType<>::t_RsGenericIdType(std::string&): supplied string is not purely hexadecimal") ; +// } +// } +//} +// +//template t_RsGenericIdType::t_RsGenericIdType(const unsigned char *mem) +//{ +// memcpy(bytes,mem,ID_SIZE_IN_BYTES) ; +//} +// +//static const int SSL_ID_SIZE = 16 ; +//static const int PGP_KEY_ID_SIZE = 8 ; +//static const int PGP_KEY_FINGERPRINT_SIZE = 20 ; +//static const int SHA1_SIZE = 20 ; +// +//// These constants are random, but should be different, in order to make the various IDs incompatible with each other. +//// +//static const uint32_t RS_GENERIC_ID_SSL_ID_TYPE = 0x038439ff ; +//static const uint32_t RS_GENERIC_ID_PGP_ID_TYPE = 0x80339f4f ; +//static const uint32_t RS_GENERIC_ID_SHA1_ID_TYPE = 0x9540284e ; +//static const uint32_t RS_GENERIC_ID_PGP_FINGERPRINT_TYPE = 0x102943e3 ; +// +//typedef t_RsGenericIdType< SSL_ID_SIZE , RS_GENERIC_ID_SSL_ID_TYPE> SSLIdType ; +//typedef t_RsGenericIdType< PGP_KEY_ID_SIZE , RS_GENERIC_ID_PGP_ID_TYPE> PGPIdType; +//typedef t_RsGenericIdType< SHA1_SIZE , RS_GENERIC_ID_SHA1_ID_TYPE> Sha1CheckSum ; +//typedef t_RsGenericIdType< PGP_KEY_FINGERPRINT_SIZE, RS_GENERIC_ID_PGP_FINGERPRINT_TYPE> PGPFingerprintType ;