From bea6769a4e23b9e20af738e6e302b8c0324e1472 Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 14 Sep 2019 16:26:24 +0200 Subject: [PATCH] removed unused code from p3gossipdiscovery --- .../gossipdiscovery/gossipdiscoveryitems.cc | 39 +- .../gossipdiscovery/gossipdiscoveryitems.h | 44 +-- .../src/gossipdiscovery/p3gossipdiscovery.cc | 366 +++++++----------- .../src/gossipdiscovery/p3gossipdiscovery.h | 75 ++-- .../src/retroshare/rsgossipdiscovery.h | 32 +- libretroshare/src/rsserver/rsinit.cc | 2 +- 6 files changed, 172 insertions(+), 386 deletions(-) diff --git a/libretroshare/src/gossipdiscovery/gossipdiscoveryitems.cc b/libretroshare/src/gossipdiscovery/gossipdiscoveryitems.cc index c1e00616d..3d56e3bc9 100644 --- a/libretroshare/src/gossipdiscovery/gossipdiscoveryitems.cc +++ b/libretroshare/src/gossipdiscovery/gossipdiscoveryitems.cc @@ -36,15 +36,11 @@ RsItem *RsDiscSerialiser::create_item( switch(static_cast(item_subtype)) { case RsGossipDiscoveryItemType::PGP_LIST: return new RsDiscPgpListItem(); -// case RsGossipDiscoveryItemType::PGP_CERT: return new RsDiscPgpCertItem(); case RsGossipDiscoveryItemType::PGP_CERT_BINARY: return new RsDiscPgpKeyItem(); case RsGossipDiscoveryItemType::CONTACT: return new RsDiscContactItem(); - case RsGossipDiscoveryItemType::IDENTITY_LIST: - return new RsDiscIdentityListItem(); - case RsGossipDiscoveryItemType::INVITE: - return new RsGossipDiscoveryInviteItem(); - case RsGossipDiscoveryItemType::INVITE_REQUEST: - return new RsGossipDiscoveryInviteRequestItem(); + case RsGossipDiscoveryItemType::IDENTITY_LIST: return new RsDiscIdentityListItem(); + default: + return NULL; } return nullptr; @@ -66,19 +62,6 @@ void RsDiscPgpListItem::serial_process( RS_SERIAL_PROCESS(pgpIdSet); } -void RsDiscPgpCertItem::clear() -{ - pgpId.clear(); - pgpCert.clear(); -} - - -void RsDiscPgpCertItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) -{ - RsTypeSerializer::serial_process(j,ctx,pgpId,"pgpId") ; - RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_PGPCERT,pgpCert,"pgpCert") ; -} - void RsDiscPgpKeyItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,pgpKeyId,"pgpKeyId") ; @@ -159,17 +142,9 @@ void RsDiscIdentityListItem::serial_process(RsGenericSerializer::SerializeJob j, RS_SERIAL_PROCESS(ownIdentityList); } - -RsGossipDiscoveryInviteItem::RsGossipDiscoveryInviteItem() : - RsDiscItem(RsGossipDiscoveryItemType::INVITE) -{ setPriorityLevel(QOS_PRIORITY_RS_DISC_ASK_INFO); } - -RsGossipDiscoveryInviteRequestItem::RsGossipDiscoveryInviteRequestItem() : - RsDiscItem(RsGossipDiscoveryItemType::INVITE_REQUEST) -{ setPriorityLevel(QOS_PRIORITY_RS_DISC_REPLY); } - -RsDiscItem::RsDiscItem(RsGossipDiscoveryItemType subtype) : - RsItem( RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_DISC, - static_cast(subtype) ) {} +RsDiscItem::RsDiscItem(RsGossipDiscoveryItemType subtype) + : RsItem( RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_DISC, static_cast(subtype) ) +{ +} RsDiscItem::~RsDiscItem() {} diff --git a/libretroshare/src/gossipdiscovery/gossipdiscoveryitems.h b/libretroshare/src/gossipdiscovery/gossipdiscoveryitems.h index c65b9c3a4..5e147d2ba 100644 --- a/libretroshare/src/gossipdiscovery/gossipdiscoveryitems.h +++ b/libretroshare/src/gossipdiscovery/gossipdiscoveryitems.h @@ -38,8 +38,8 @@ enum class RsGossipDiscoveryItemType : uint8_t PGP_CERT = 0x2, // deprecated CONTACT = 0x5, IDENTITY_LIST = 0x6, - INVITE = 0x7, - INVITE_REQUEST = 0x8, + INVITE = 0x7, // deprecated + INVITE_REQUEST = 0x8, // deprecated PGP_CERT_BINARY = 0x9, }; @@ -82,22 +82,6 @@ public: RsTlvPgpIdSet pgpIdSet; }; -class RsDiscPgpCertItem: public RsDiscItem -{ -public: - - RsDiscPgpCertItem() : RsDiscItem(RsGossipDiscoveryItemType::PGP_CERT) - { setPriorityLevel(QOS_PRIORITY_RS_DISC_PGP_CERT); } - - void clear() override; - void serial_process( - RsGenericSerializer::SerializeJob j, - RsGenericSerializer::SerializeContext& ctx) override; - - RsPgpId pgpId; - std::string pgpCert; -}; - class RsDiscPgpKeyItem: public RsDiscItem { public: @@ -174,30 +158,6 @@ public: std::list ownIdentityList; }; -struct RsGossipDiscoveryInviteItem : RsDiscItem -{ - RsGossipDiscoveryInviteItem(); - - void serial_process( RsGenericSerializer::SerializeJob j, - RsGenericSerializer::SerializeContext& ctx ) override - { RS_SERIAL_PROCESS(mInvite); } - void clear() override { mInvite.clear(); } - - std::string mInvite; -}; - -struct RsGossipDiscoveryInviteRequestItem : RsDiscItem -{ - RsGossipDiscoveryInviteRequestItem(); - - void serial_process( RsGenericSerializer::SerializeJob j, - RsGenericSerializer::SerializeContext& ctx ) override - { RS_SERIAL_PROCESS(mInviteId); } - void clear() override { mInviteId.clear(); } - - RsPeerId mInviteId; -}; - class RsDiscSerialiser: public RsServiceSerializer { public: diff --git a/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc b/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc index e1b435df3..d0b3e54be 100644 --- a/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc +++ b/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc @@ -36,9 +36,6 @@ /*extern*/ std::shared_ptr rsGossipDiscovery(nullptr); -RsGossipDiscovery::~RsGossipDiscovery() {}; - - static bool populateContactInfo( const peerState &detail, RsDiscContactItem *pkt, bool include_ip_information ) @@ -88,9 +85,9 @@ static bool populateContactInfo( const peerState &detail, return true; } -void DiscPgpInfo::mergeFriendList(const std::set &friends) +void DiscPgpInfo::mergeFriendList(const std::set &friends) { - std::set::const_iterator it; + std::set::const_iterator it; for(it = friends.begin(); it != friends.end(); ++it) { mFriendSet.insert(*it); @@ -141,13 +138,13 @@ RsServiceInfo p3discovery2::getServiceInfo() p3discovery2::~p3discovery2() { rsEvents->unregisterEventsHandler(mRsEventsHandle); } -void p3discovery2::addFriend(const SSLID &sslId) +void p3discovery2::addFriend(const RsPeerId &sslId) { - PGPID pgpId = getPGPId(sslId); + RsPgpId pgpId = getPGPId(sslId); RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/ - std::map::iterator it; + std::map::iterator it; it = mFriendList.find(pgpId); if (it == mFriendList.end()) { @@ -162,9 +159,9 @@ void p3discovery2::addFriend(const SSLID &sslId) } - /* now add SSLID */ + /* now add RsPeerId */ - std::map::iterator sit; + std::map::iterator sit; sit = it->second.mSslIds.find(sslId); if (sit == it->second.mSslIds.end()) { @@ -189,13 +186,13 @@ void p3discovery2::addFriend(const SSLID &sslId) } } -void p3discovery2::removeFriend(const SSLID &sslId) +void p3discovery2::removeFriend(const RsPeerId &sslId) { - PGPID pgpId = getPGPId(sslId); + RsPgpId pgpId = getPGPId(sslId); RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/ - std::map::iterator it; + std::map::iterator it; it = mFriendList.find(pgpId); if (it == mFriendList.end()) { @@ -206,7 +203,7 @@ void p3discovery2::removeFriend(const SSLID &sslId) return; } - std::map::iterator sit; + std::map::iterator sit; sit = it->second.mSslIds.find(sslId); if (sit == it->second.mSslIds.end()) { @@ -241,9 +238,9 @@ void p3discovery2::removeFriend(const SSLID &sslId) } } -PGPID p3discovery2::getPGPId(const SSLID &id) +RsPgpId p3discovery2::getPGPId(const RsPeerId &id) { - PGPID pgpId; + RsPgpId pgpId; mPeerMgr->getGpgId(id, pgpId); return pgpId; } @@ -261,13 +258,10 @@ int p3discovery2::handleIncoming() // While messages read while(nullptr != (item = recvItem())) { - RsDiscPgpListItem* pgplist = nullptr; - RsDiscPgpCertItem* pgpcert = nullptr; // deprecated - RsDiscPgpKeyItem* pgpkey = nullptr; - RsDiscContactItem* contact = nullptr; + RsDiscPgpListItem* pgplist = nullptr; + RsDiscPgpKeyItem* pgpkey = nullptr; + RsDiscContactItem* contact = nullptr; RsDiscIdentityListItem* gxsidlst = nullptr; -// RsGossipDiscoveryInviteItem* invite = nullptr; -// RsGossipDiscoveryInviteRequestItem* inviteReq = nullptr; ++nhandled; @@ -286,8 +280,6 @@ int p3discovery2::handleIncoming() recvIdentityList(item->PeerId(),gxsidlst->ownIdentityList); delete item; } -// else if((pgpcert = dynamic_cast(item)) != nullptr) -// recvPGPCertificate(item->PeerId(), pgpcert); else if((pgpkey = dynamic_cast(item)) != nullptr) recvPGPCertificate(item->PeerId(), pgpkey); else if((pgplist = dynamic_cast(item)) != nullptr) @@ -298,19 +290,10 @@ int p3discovery2::handleIncoming() recvPGPCertificateRequest(pgplist->PeerId(), pgplist); else delete item; } -// else if( (invite = dynamic_cast(item)) != nullptr ) -// recvInvite(std::unique_ptr(invite)); -// else if( (inviteReq = -// dynamic_cast(item)) -// != nullptr ) -// { -// sendInvite(inviteReq->mInviteId, item->PeerId()); -// delete item; -// } else { - RsWarn() << __PRETTY_FUNCTION__ << " Received unknown item type! " - << std::endl << item << std::endl; + RsWarn() << __PRETTY_FUNCTION__ << " Received unknown item type " << (int)item->PacketSubType() << "! " << std::endl ; + RsWarn() << item << std::endl; delete item; } } @@ -318,7 +301,7 @@ int p3discovery2::handleIncoming() return nhandled; } -void p3discovery2::sendOwnContactInfo(const SSLID &sslid) +void p3discovery2::sendOwnContactInfo(const RsPeerId &sslid) { #ifdef P3DISC_DEBUG @@ -366,7 +349,7 @@ void p3discovery2::sendOwnContactInfo(const SSLID &sslid) } } -void p3discovery2::recvOwnContactInfo(const SSLID &fromId, const RsDiscContactItem *item) +void p3discovery2::recvOwnContactInfo(const RsPeerId &fromId, const RsDiscContactItem *item) { std::unique_ptr pitem(item); // ensures that item will be destroyed whichever door we leave through @@ -429,11 +412,11 @@ void p3discovery2::recvOwnContactInfo(const SSLID &fromId, const RsDiscContactIt // Update mDiscStatus. RS_STACK_MUTEX(mDiscMtx); - PGPID pgpId = getPGPId(fromId); - std::map::iterator it = mFriendList.find(pgpId); + RsPgpId pgpId = getPGPId(fromId); + std::map::iterator it = mFriendList.find(pgpId); if (it != mFriendList.end()) { - std::map::iterator sit = it->second.mSslIds.find(fromId); + std::map::iterator sit = it->second.mSslIds.find(fromId); if (sit != it->second.mSslIds.end()) { sit->second.mDiscStatus = item->vs_disc; @@ -522,7 +505,7 @@ void p3discovery2::updatePeerAddressList(const RsDiscContactItem *item) // Starts the Discovery process. // should only be called it DISC2_STATUS_NOT_HIDDEN(OwnInfo.status). -void p3discovery2::sendPGPList(const SSLID &toId) +void p3discovery2::sendPGPList(const RsPeerId &toId) { updatePgpFriendList(); @@ -537,7 +520,7 @@ void p3discovery2::sendPGPList(const SSLID &toId) pkt->mode = RsGossipDiscoveryPgpListMode::FRIENDS; - std::map::const_iterator it; + std::map::const_iterator it; for(it = mFriendList.begin(); it != mFriendList.end(); ++it) { pkt->pgpIdSet.ids.insert(it->first); @@ -576,14 +559,14 @@ void p3discovery2::updatePgpFriendList() mLastPgpUpdate = time(NULL); - std::list pgpList; - std::set pgpSet; + std::list pgpList; + std::set pgpSet; - std::set::iterator sit; - std::list::iterator lit; - std::map::iterator it; + std::set::iterator sit; + std::list::iterator lit; + std::map::iterator it; - PGPID ownPgpId = AuthGPG::getAuthGPG()->getGPGOwnId(); + RsPgpId ownPgpId = AuthGPG::getAuthGPG()->getGPGOwnId(); AuthGPG::getAuthGPG()->getGPGAcceptedList(pgpList); pgpList.push_back(ownPgpId); @@ -593,8 +576,8 @@ void p3discovery2::updatePgpFriendList() pgpSet.insert(*lit); } - std::list pgpToAdd; - std::list pgpToRemove; + std::list pgpToAdd; + std::list pgpToRemove; sit = pgpSet.begin(); @@ -660,7 +643,7 @@ void p3discovery2::updatePgpFriendList() } -void p3discovery2::processPGPList(const SSLID &fromId, const RsDiscPgpListItem *item) +void p3discovery2::processPGPList(const RsPeerId &fromId, const RsDiscPgpListItem *item) { RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/ @@ -669,8 +652,8 @@ void p3discovery2::processPGPList(const SSLID &fromId, const RsDiscPgpListItem * std::cerr << std::endl; #endif - std::map::iterator it; - PGPID fromPgpId = getPGPId(fromId); + std::map::iterator it; + RsPgpId fromPgpId = getPGPId(fromId); it = mFriendList.find(fromPgpId); if (it == mFriendList.end()) { @@ -703,7 +686,7 @@ void p3discovery2::processPGPList(const SSLID &fromId, const RsDiscPgpListItem * if (requestUnknownPgpCerts) { - std::set::const_iterator fit; + std::set::const_iterator fit; for(fit = item->pgpIdSet.ids.begin(); fit != item->pgpIdSet.ids.end(); ++fit) { if (!AuthGPG::getAuthGPG()->isGPGId(*fit)) @@ -730,7 +713,7 @@ void p3discovery2::processPGPList(const SSLID &fromId, const RsDiscPgpListItem * * -> Update Other Peers about B. * -> Update B about Other Peers. */ -void p3discovery2::updatePeers_locked(const SSLID &aboutId) +void p3discovery2::updatePeers_locked(const RsPeerId &aboutId) { #ifdef P3DISC_DEBUG @@ -738,9 +721,9 @@ void p3discovery2::updatePeers_locked(const SSLID &aboutId) std::cerr << std::endl; #endif - PGPID aboutPgpId = getPGPId(aboutId); + RsPgpId aboutPgpId = getPGPId(aboutId); - std::map::const_iterator ait; + std::map::const_iterator ait; ait = mFriendList.find(aboutPgpId); if (ait == mFriendList.end()) { @@ -752,12 +735,12 @@ void p3discovery2::updatePeers_locked(const SSLID &aboutId) return; } - std::set mutualFriends; - std::set onlineFriends; - std::set::const_iterator sit; + std::set mutualFriends; + std::set onlineFriends; + std::set::const_iterator sit; - const std::set &friendSet = ait->second.mFriendSet; - std::set::const_iterator fit; + const std::set &friendSet = ait->second.mFriendSet; + std::set::const_iterator fit; for(fit = friendSet.begin(); fit != friendSet.end(); ++fit) { @@ -766,7 +749,7 @@ void p3discovery2::updatePeers_locked(const SSLID &aboutId) std::cerr << std::endl; #endif - std::map::const_iterator ffit; + std::map::const_iterator ffit; ffit = mFriendList.find(*fit); if (ffit == mFriendList.end()) { @@ -775,7 +758,7 @@ void p3discovery2::updatePeers_locked(const SSLID &aboutId) std::cerr << "p3discovery2::updatePeer_locked() Ignoring not our friend"; std::cerr << std::endl; #endif - // Not our friend, or we have no Locations (SSL) for this PGPID (same difference) + // Not our friend, or we have no Locations (SSL) for this RsPgpId (same difference) continue; } @@ -788,16 +771,16 @@ void p3discovery2::updatePeers_locked(const SSLID &aboutId) #endif mutualFriends.insert(*fit); - std::map::const_iterator mit; + std::map::const_iterator mit; for(mit = ffit->second.mSslIds.begin(); mit != ffit->second.mSslIds.end(); ++mit) { - SSLID sslid = mit->first; + RsPeerId sslid = mit->first; if (mServiceCtrl->isPeerConnected(getServiceInfo().mServiceType, sslid)) { // TODO IGNORE if sslid == aboutId, or sslid == ownId. #ifdef P3DISC_DEBUG - std::cerr << "p3discovery2::updatePeer_locked() Adding Online SSLID: " << sslid; + std::cerr << "p3discovery2::updatePeer_locked() Adding Online RsPeerId: " << sslid; std::cerr << std::endl; #endif onlineFriends.insert(sslid); @@ -829,13 +812,13 @@ void p3discovery2::updatePeers_locked(const SSLID &aboutId) } } -void p3discovery2::sendContactInfo_locked(const PGPID &aboutId, const SSLID &toId) +void p3discovery2::sendContactInfo_locked(const RsPgpId &aboutId, const RsPeerId &toId) { #ifdef P3DISC_DEBUG std::cerr << "p3discovery2::sendContactInfo_locked() aboutPGPId: " << aboutId << " toId: " << toId; std::cerr << std::endl; #endif - std::map::const_iterator it; + std::map::const_iterator it; it = mFriendList.find(aboutId); if (it == mFriendList.end()) { @@ -846,7 +829,7 @@ void p3discovery2::sendContactInfo_locked(const PGPID &aboutId, const SSLID &toI return; } - std::map::const_iterator sit; + std::map::const_iterator sit; for(sit = it->second.mSslIds.begin(); sit != it->second.mSslIds.end(); ++sit) { #ifdef P3DISC_DEBUG @@ -902,14 +885,14 @@ void p3discovery2::sendContactInfo_locked(const PGPID &aboutId, const SSLID &toI else { #ifdef P3DISC_DEBUG - std::cerr << "p3discovery2::sendContactInfo_locked() SSLID Hidden"; + std::cerr << "p3discovery2::sendContactInfo_locked() RsPeerId Hidden"; std::cerr << std::endl; #endif } } } -void p3discovery2::processContactInfo(const SSLID &fromId, const RsDiscContactItem *item) +void p3discovery2::processContactInfo(const RsPeerId &fromId, const RsDiscContactItem *item) { (void) fromId; // remove unused parameter warnings, debug only @@ -925,12 +908,12 @@ void p3discovery2::processContactInfo(const SSLID &fromId, const RsDiscContactIt return; } - std::map::iterator it; + std::map::iterator it; it = mFriendList.find(item->pgpId); if (it == mFriendList.end()) { #ifdef P3DISC_DEBUG - std::cerr << "p3discovery2::processContactInfo(" << fromId << ") PGPID: "; + std::cerr << "p3discovery2::processContactInfo(" << fromId << ") RsPgpId: "; std::cerr << item->pgpId << " Not Friend."; std::cerr << std::endl; std::cerr << "p3discovery2::processContactInfo(" << fromId << ") THIS SHOULD NEVER HAPPEN!"; @@ -956,7 +939,7 @@ void p3discovery2::processContactInfo(const SSLID &fromId, const RsDiscContactIt } bool should_notify_discovery = false; - std::map::iterator sit; + std::map::iterator sit; sit = it->second.mSslIds.find(item->sslId); if (sit == it->second.mSslIds.end()) { @@ -1005,7 +988,7 @@ void p3discovery2::processContactInfo(const SSLID &fromId, const RsDiscContactIt /* we explictly request certificates, instead of getting them all the time */ -void p3discovery2::requestPGPCertificate(const PGPID &aboutId, const SSLID &toId) +void p3discovery2::requestPGPCertificate(const RsPgpId &aboutId, const RsPeerId &toId) { #ifdef P3DISC_DEBUG std::cerr << "p3discovery2::requestPGPCertificate() aboutId: " << aboutId << " to: " << toId; @@ -1044,11 +1027,6 @@ void p3discovery2::recvPGPCertificateRequest( void p3discovery2::sendPGPCertificate(const RsPgpId &aboutId, const RsPeerId &toId) { - //RsDiscPgpCertItem* item = new RsDiscPgpCertItem(); - //item->pgpId = aboutId; - - //Dbg4() << __PRETTY_FUNCTION__ << " queuing for Cert generation: " << std::endl << *item << std::endl; - RsDiscPgpKeyItem *pgp_key_item = new RsDiscPgpKeyItem; pgp_key_item->PeerId(toId); @@ -1066,12 +1044,6 @@ void p3discovery2::sendPGPCertificate(const RsPgpId &aboutId, const RsPeerId &to pgp_key_item->pgpKeyData.bin_len = bin_len; sendItem(pgp_key_item); - - // (cyril) we shouldn't need to use a queue for that! There's no cost in getting a PGP cert from AuthGPG. - // { - // RS_STACK_MUTEX(mDiscMtx); - // mPendingDiscPgpCertOutList.push_back(item); - // } } void p3discovery2::recvPGPCertificate(const RsPeerId& fromId, RsDiscPgpKeyItem* item ) @@ -1190,8 +1162,8 @@ bool p3discovery2::getDiscFriends(const RsPeerId& id, std::list &proxy RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/ - std::map::const_iterator it; - PGPID pgp_id = getPGPId(id); + std::map::const_iterator it; + RsPgpId pgp_id = getPGPId(id); it = mFriendList.find(pgp_id); if (it == mFriendList.end()) @@ -1200,9 +1172,9 @@ bool p3discovery2::getDiscFriends(const RsPeerId& id, std::list &proxy return false; } - // For each of their friends that we know, grab that set of SSLIDs. - const std::set &friendSet = it->second.mFriendSet; - std::set::const_iterator fit; + // For each of their friends that we know, grab that set of RsPeerId. + const std::set &friendSet = it->second.mFriendSet; + std::set::const_iterator fit; for(fit = friendSet.begin(); fit != friendSet.end(); ++fit) { it = mFriendList.find(*fit); @@ -1211,7 +1183,7 @@ bool p3discovery2::getDiscFriends(const RsPeerId& id, std::list &proxy continue; } - std::map::const_iterator sit; + std::map::const_iterator sit; for(sit = it->second.mSslIds.begin(); sit != it->second.mSslIds.end(); ++sit) { @@ -1225,51 +1197,13 @@ bool p3discovery2::getDiscFriends(const RsPeerId& id, std::list &proxy bool p3discovery2::getWaitingDiscCount(size_t &sendCount, size_t &recvCount) { RS_STACK_MUTEX(mDiscMtx); - //sendCount = mPendingDiscPgpCertOutList.size(); - recvCount = mPendingDiscPgpCertInList.size(); + sendCount = 0;//mPendingDiscPgpCertOutList.size(); + recvCount = 0;//mPendingDiscPgpCertInList.size(); return true; } -bool p3discovery2::sendInvite( - const RsPeerId& inviteId, const RsPeerId& toSslId, - std::string& errorMsg ) -{ - RsPeers& mPeers = *rsPeers; - - std::string&& invite = mPeers.GetRetroshareInvite(inviteId); - - if(invite.empty()) - { - errorMsg = "Failure generating invite for peer: " + - inviteId.toStdString() + " are you sure is a friend?"; - RsErr() << __PRETTY_FUNCTION__ << " " << errorMsg << std::endl; - return false; - } - - RsGossipDiscoveryInviteItem* item = new RsGossipDiscoveryInviteItem; - item->PeerId(toSslId); - item->mInvite = mPeers.GetRetroshareInvite(inviteId, true, true); - - return sendItem(item); -} - -bool p3discovery2::requestInvite( - const RsPeerId& inviteId, const RsPeerId& toSslId, - std::string& /*errorMsg*/ ) -{ - Dbg2() << __PRETTY_FUNCTION__ << " inviteId: " << inviteId - << " toSslId: " << toSslId << std::endl; - - RsGossipDiscoveryInviteRequestItem* item = - new RsGossipDiscoveryInviteRequestItem; - item->PeerId(toSslId); - item->mInviteId = inviteId; - - return sendItem(item); -} - -bool p3discovery2::getDiscPgpFriends(const PGPID &pgp_id, std::list &proxyPgpIds) +bool p3discovery2::getDiscPgpFriends(const RsPgpId &pgp_id, std::list &proxyPgpIds) { /* find id -> and extract the neighbour_of ids */ @@ -1278,7 +1212,7 @@ bool p3discovery2::getDiscPgpFriends(const PGPID &pgp_id, std::list &prox RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/ - std::map::const_iterator it; + std::map::const_iterator it; it = mFriendList.find(pgp_id); if (it == mFriendList.end()) { @@ -1286,7 +1220,7 @@ bool p3discovery2::getDiscPgpFriends(const PGPID &pgp_id, std::list &prox return false; } - std::set::const_iterator fit; + std::set::const_iterator fit; for(fit = it->second.mFriendSet.begin(); fit != it->second.mFriendSet.end(); ++fit) { proxyPgpIds.push_back(*fit); @@ -1294,11 +1228,11 @@ bool p3discovery2::getDiscPgpFriends(const PGPID &pgp_id, std::list &prox return true; } -bool p3discovery2::getPeerVersion(const SSLID &peerId, std::string &version) +bool p3discovery2::getPeerVersion(const RsPeerId &peerId, std::string &version) { RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/ - std::map::const_iterator it; + std::map::const_iterator it; it = mLocationMap.find(peerId); if (it == mLocationMap.end()) { @@ -1310,11 +1244,11 @@ bool p3discovery2::getPeerVersion(const SSLID &peerId, std::string &version) return true; } -bool p3discovery2::setPeerVersion(const SSLID &peerId, const std::string &version) +bool p3discovery2::setPeerVersion(const RsPeerId &peerId, const std::string &version) { RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/ - std::map::iterator it; + std::map::iterator it; it = mLocationMap.find(peerId); if (it == mLocationMap.end()) { @@ -1326,112 +1260,74 @@ bool p3discovery2::setPeerVersion(const SSLID &peerId, const std::string &versio return true; } -void p3discovery2::recvInvite( - std::unique_ptr inviteItem ) -{ - typedef RsGossipDiscoveryFriendInviteReceivedEvent Evt_t; - if(rsEvents) - rsEvents->postEvent( - std::shared_ptr(new Evt_t(inviteItem->mInvite)) ); -} - void p3discovery2::rsEventsHandler(const RsEvent& event) { - Dbg3() << __PRETTY_FUNCTION__ << " " << static_cast(event.mType) - << std::endl; - - switch(event.mType) - { -// case RsEventType::PEER_STATE_CHANGED: -// { -// const RsPeerId& sslId = static_cast(event).mSslId; -// -// if( rsPeers && rsPeers->isSslOnlyFriend(sslId) && mServiceCtrl->isPeerConnected( getServiceInfo().mServiceType, sslId ) ) -// { -// if(!requestPGPCertificate(sslId, sslId)) -// RsErr() << __PRETTY_FUNCTION__ << " requestInvite to peer " -// << sslId << " failed" << std::endl; -// } -// break; -// } - default: break; - } + Dbg3() << __PRETTY_FUNCTION__ << " " << static_cast(event.mType) << std::endl; } /*************************************************************************************/ /* AuthGPGService */ /*************************************************************************************/ -AuthGPGOperation *p3discovery2::getGPGOperation() -{ - { - RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/ - - /* process disc reply in list */ - if (!mPendingDiscPgpCertInList.empty()) { - RsDiscPgpCertItem *item = mPendingDiscPgpCertInList.front(); - mPendingDiscPgpCertInList.pop_front(); - - return new AuthGPGOperationLoadOrSave(true, item->pgpId, item->pgpCert, item); - } - } - -// { -// RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/ +// AuthGPGOperation *p3discovery2::getGPGOperation() +// { +// { +// RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/ // -// /* process disc reply in list */ -// if (!mPendingDiscPgpCertOutList.empty()) { -// RsDiscPgpCertItem *item = mPendingDiscPgpCertOutList.front(); -// mPendingDiscPgpCertOutList.pop_front(); +// /* process disc reply in list */ +// if (!mPendingDiscPgpCertInList.empty()) { +// RsDiscPgpCertItem *item = mPendingDiscPgpCertInList.front(); +// mPendingDiscPgpCertInList.pop_front(); // -// return new AuthGPGOperationLoadOrSave(false, item->pgpId, "", item); -// } -// } - return NULL; -} +// return new AuthGPGOperationLoadOrSave(true, item->pgpId, item->pgpCert, item); +// } +// } +// +// return NULL; +// } -void p3discovery2::setGPGOperation(AuthGPGOperation *operation) -{ - AuthGPGOperationLoadOrSave *loadOrSave = dynamic_cast(operation); - if (loadOrSave) - { - RsDiscPgpCertItem *item = (RsDiscPgpCertItem *) loadOrSave->m_userdata; - if (!item) - { - return; - } +// void p3discovery2::setGPGOperation(AuthGPGOperation *operation) +// { +// AuthGPGOperationLoadOrSave *loadOrSave = dynamic_cast(operation); +// if (loadOrSave) +// { +// RsDiscPgpCertItem *item = (RsDiscPgpCertItem *) loadOrSave->m_userdata; +// if (!item) +// { +// return; +// } +// +// if (loadOrSave->m_load) +// { +// +// #ifdef P3DISC_DEBUG +// std::cerr << "p3discovery2::setGPGOperation() Loaded Cert" << std::endl; +// item->print(std::cerr, 5); +// std::cerr << std::endl; +// #endif +// // It has already been processed by PGP. +// delete item; +// } +// else +// { +// // Attaching Certificate. +// item->pgpCert = loadOrSave->m_certGpg; +// +// #ifdef P3DISC_DEBUG +// std::cerr << "p3discovery2::setGPGOperation() Sending Message:" << std::endl; +// item->print(std::cerr, 5); +// #endif +// +// // Send off message +// sendItem(item); +// } +// return; +// } +// +// /* ignore other operations */ +// } - if (loadOrSave->m_load) - { - -#ifdef P3DISC_DEBUG - std::cerr << "p3discovery2::setGPGOperation() Loaded Cert" << std::endl; - item->print(std::cerr, 5); - std::cerr << std::endl; -#endif - // It has already been processed by PGP. - delete item; - } - else - { - // Attaching Certificate. - item->pgpCert = loadOrSave->m_certGpg; - -#ifdef P3DISC_DEBUG - std::cerr << "p3discovery2::setGPGOperation() Sending Message:" << std::endl; - item->print(std::cerr, 5); -#endif - - // Send off message - sendItem(item); - } - return; - } - - /* ignore other operations */ -} - -RsGossipDiscoveryFriendInviteReceivedEvent:: -RsGossipDiscoveryFriendInviteReceivedEvent(const std::string& invite) : +// (cyril) do we still need this?? +RsGossipDiscoveryFriendInviteReceivedEvent::RsGossipDiscoveryFriendInviteReceivedEvent(const std::string& invite) : RsEvent(RsEventType::GOSSIP_DISCOVERY_INVITE_RECEIVED), mInvite(invite) {} diff --git a/libretroshare/src/gossipdiscovery/p3gossipdiscovery.h b/libretroshare/src/gossipdiscovery/p3gossipdiscovery.h index eaf148bb5..d7e0270f6 100644 --- a/libretroshare/src/gossipdiscovery/p3gossipdiscovery.h +++ b/libretroshare/src/gossipdiscovery/p3gossipdiscovery.h @@ -36,9 +36,6 @@ class p3ServiceControl; -using PGPID RS_DEPRECATED_FOR(RsPgpId) = RsPgpId; -using SSLID RS_DEPRECATED_FOR(RsPeerId) = RsPeerId; - struct DiscSslInfo { DiscSslInfo() : mDiscStatus(0) {} @@ -56,16 +53,16 @@ struct DiscPgpInfo { DiscPgpInfo() {} - void mergeFriendList(const std::set &friends); + void mergeFriendList(const std::set &friends); - std::set mFriendSet; - std::map mSslIds; + std::set mFriendSet; + std::map mSslIds; }; class p3discovery2 : - public RsGossipDiscovery, public p3Service, public pqiServiceMonitor, - public AuthGPGService + public RsGossipDiscovery, public p3Service, public pqiServiceMonitor + //public AuthGPGService { public: @@ -87,57 +84,41 @@ virtual RsServiceInfo getServiceInfo(); bool getPeerVersion(const RsPeerId &id, std::string &version); bool getWaitingDiscCount(size_t &sendCount, size_t &recvCount); - /// @see RsGossipDiscovery - bool sendInvite( - const RsPeerId& inviteId, const RsPeerId& toSslId, - std::string& errorMsg = RS_DEFAULT_STORAGE_PARAM(std::string) - ) override; - - /// @see RsGossipDiscovery - bool requestInvite( - const RsPeerId& inviteId, const RsPeerId& toSslId, - std::string& errorMsg = RS_DEFAULT_STORAGE_PARAM(std::string) - ) override; - - /************* from AuthGPService ****************/ -virtual AuthGPGOperation *getGPGOperation(); -virtual void setGPGOperation(AuthGPGOperation *operation); + /************* from AuthGPService ****************/ + // virtual AuthGPGOperation *getGPGOperation(); + // virtual void setGPGOperation(AuthGPGOperation *operation); private: - PGPID getPGPId(const SSLID &id); + RsPgpId getPGPId(const RsPeerId &id); int handleIncoming(); void updatePgpFriendList(); - void addFriend(const SSLID &sslId); - void removeFriend(const SSLID &sslId); + void addFriend(const RsPeerId &sslId); + void removeFriend(const RsPeerId &sslId); void updatePeerAddresses(const RsDiscContactItem *item); void updatePeerAddressList(const RsDiscContactItem *item); - void sendOwnContactInfo(const SSLID &sslid); - void recvOwnContactInfo(const SSLID &fromId, const RsDiscContactItem *item); + void sendOwnContactInfo(const RsPeerId &sslid); + void recvOwnContactInfo(const RsPeerId &fromId, const RsDiscContactItem *item); - void sendPGPList(const SSLID &toId); - void processPGPList(const SSLID &fromId, const RsDiscPgpListItem *item); + void sendPGPList(const RsPeerId &toId); + void processPGPList(const RsPeerId &fromId, const RsDiscPgpListItem *item); - void processContactInfo(const SSLID &fromId, const RsDiscContactItem *info); + void processContactInfo(const RsPeerId &fromId, const RsDiscContactItem *info); - void requestPGPCertificate(const PGPID &aboutId, const SSLID &toId); - - void recvPGPCertificateRequest( - const RsPeerId& fromId, const RsDiscPgpListItem* item ); + // send/recv information + void requestPGPCertificate(const RsPgpId &aboutId, const RsPeerId &toId); + void recvPGPCertificateRequest(const RsPeerId& fromId, const RsDiscPgpListItem* item ); void sendPGPCertificate(const RsPgpId &aboutId, const RsPeerId &toId); - void recvPGPCertificate(const SSLID &fromId, RsDiscPgpCertItem *item); // deprecated - void recvPGPCertificate(const SSLID &fromId, RsDiscPgpKeyItem *item); + void recvPGPCertificate(const RsPeerId &fromId, RsDiscPgpKeyItem *item); void recvIdentityList(const RsPeerId& pid,const std::list& ids); - bool setPeerVersion(const SSLID &peerId, const std::string &version); - - void recvInvite(std::unique_ptr inviteItem); + bool setPeerVersion(const RsPeerId &peerId, const std::string &version); void rsEventsHandler(const RsEvent& event); RsEventsHandlerId_t mRsEventsHandle; @@ -152,16 +133,18 @@ private: /* data */ RsMutex mDiscMtx; - void updatePeers_locked(const SSLID &aboutId); - void sendContactInfo_locked(const PGPID &aboutId, const SSLID &toId); + void updatePeers_locked(const RsPeerId &aboutId); + void sendContactInfo_locked(const RsPgpId &aboutId, const RsPeerId &toId); rstime_t mLastPgpUpdate; - std::map mFriendList; - std::map mLocationMap; + std::map mFriendList; + std::map mLocationMap; - std::list mPendingDiscPgpCertInList; - //std::list mPendingDiscPgpCertOutList; +// This was used to async the receiving of PGP keys, mainly because PGPHandler cross-checks all signatures, so receiving these keys in large loads can be costly +// Because discovery is not running in the main thread, there's no reason to re-async this into another process (e.g. AuthGPG) +// +// std::list mPendingDiscPgpCertInList; protected: RS_SET_CONTEXT_DEBUG_LEVEL(1) diff --git a/libretroshare/src/retroshare/rsgossipdiscovery.h b/libretroshare/src/retroshare/rsgossipdiscovery.h index cf748549c..89839995a 100644 --- a/libretroshare/src/retroshare/rsgossipdiscovery.h +++ b/libretroshare/src/retroshare/rsgossipdiscovery.h @@ -64,6 +64,8 @@ struct RsGossipDiscoveryFriendInviteReceivedEvent : RsEvent class RsGossipDiscovery { public: + virtual ~RsGossipDiscovery() {} + /** * @brief getDiscFriends get a list of all friends of a given friend * @jsonapi{development} @@ -101,34 +103,4 @@ public: * @return true on success false otherwise */ virtual bool getWaitingDiscCount(size_t& sendCount, size_t& recvCount) = 0; - - /** - * @brief Send RetroShare invite to given peer - * @jsonapi{development} - * @param[in] inviteId id of peer of which send the invite - * @param[in] toSslId ssl id of the destination peer - * @param[out] errorMessage Optional storage for the error message, - * meaningful only on failure. - * @return true on success false otherwise - */ - virtual bool sendInvite( - const RsPeerId& inviteId, const RsPeerId& toSslId, - std::string& errorMessage = RS_DEFAULT_STORAGE_PARAM(std::string) - ) = 0; - - /** - * @brief Request RetroShare certificate to given peer - * @jsonapi{development} - * @param[in] inviteId id of the peer of which request the invite - * @param[in] toSslId id of the destination of the request - * @param[out] errorMessage Optional storage for the error message, - * meaningful only on failure. - * @return true on success false otherwise - */ - virtual bool requestInvite( - const RsPeerId& inviteId, const RsPeerId& toSslId, - std::string& errorMessage = RS_DEFAULT_STORAGE_PARAM(std::string) - ) = 0; - - virtual ~RsGossipDiscovery(); }; diff --git a/libretroshare/src/rsserver/rsinit.cc b/libretroshare/src/rsserver/rsinit.cc index d2b60b992..7b571e48c 100644 --- a/libretroshare/src/rsserver/rsinit.cc +++ b/libretroshare/src/rsserver/rsinit.cc @@ -1792,7 +1792,7 @@ int RsServer::StartupRetroShare() /* Add AuthGPG services */ /**************************************************************************/ - AuthGPG::getAuthGPG()->addService(mDisc); + //AuthGPG::getAuthGPG()->addService(mDisc); /**************************************************************************/ /* Force Any Last Configuration Options */