From 3f89a3300d23f216d0d09a7f219b3ec7b29f2efa Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 6 Feb 2021 14:57:22 +0100 Subject: [PATCH] added event handling when peer discovery is received --- .../src/gossipdiscovery/p3gossipdiscovery.cc | 22 ++++++++++++++++++- .../src/retroshare/rsgossipdiscovery.h | 12 +++++----- .../src/gui/common/NewFriendList.cpp | 13 ++++++----- retroshare-gui/src/gui/common/NewFriendList.h | 3 ++- 4 files changed, 38 insertions(+), 12 deletions(-) diff --git a/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc b/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc index cba29915a..0060316ef 100644 --- a/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc +++ b/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc @@ -388,6 +388,15 @@ void p3discovery2::recvOwnContactInfo(const RsPeerId &fromId, const RsDiscContac if(!mPeerMgr->isHiddenNode(rsPeers->getOwnId())) updatePeerAddresses(item); + if(rsEvents) + { + auto ev = std::make_shared(); + ev->mGossipDiscoveryEventType = RsGossipDiscoveryEventType::FRIEND_PEER_INFO_RECEIVED; + ev->mFromId = fromId; + ev->mAboutId = item->sslId; + rsEvents->postEvent(ev); + } + // if the peer is not validated, we stop the exchange here if(det.skip_pgp_signature_validation) @@ -977,7 +986,18 @@ void p3discovery2::processContactInfo(const RsPeerId &fromId, const RsDiscContac RsServer::notify()->notifyListChange(NOTIFY_LIST_NEIGHBOURS, NOTIFY_TYPE_MOD); if(should_notify_discovery) - RsServer::notify()->notifyDiscInfoChanged(); + { + RsServer::notify()->notifyDiscInfoChanged(); + + if(rsEvents) + { + auto ev = std::make_shared(); + ev->mGossipDiscoveryEventType = RsGossipDiscoveryEventType::FRIEND_PEER_INFO_RECEIVED; + ev->mFromId = fromId; + ev->mAboutId = item->sslId; + rsEvents->postEvent(ev); + } + } } /* we explictly request certificates, instead of getting them all the time diff --git a/libretroshare/src/retroshare/rsgossipdiscovery.h b/libretroshare/src/retroshare/rsgossipdiscovery.h index ca1ab0d7c..9a6e2a792 100644 --- a/libretroshare/src/retroshare/rsgossipdiscovery.h +++ b/libretroshare/src/retroshare/rsgossipdiscovery.h @@ -47,8 +47,8 @@ extern std::shared_ptr rsGossipDiscovery; */ enum class RsGossipDiscoveryEventType: uint32_t { - UNKNOWN = 0x00, - PEER_INVITE_RECEIVED = 0x01 + UNKNOWN = 0x00, + FRIEND_PEER_INFO_RECEIVED = 0x01, }; struct RsGossipDiscoveryEvent : RsEvent @@ -57,7 +57,8 @@ struct RsGossipDiscoveryEvent : RsEvent virtual ~RsGossipDiscoveryEvent() override {} RsGossipDiscoveryEventType mGossipDiscoveryEventType; - std::string mInvite; + RsPeerId mFromId; + RsPeerId mAboutId; /// @see RsSerializable virtual void serial_process( RsGenericSerializer::SerializeJob j, @@ -65,8 +66,9 @@ struct RsGossipDiscoveryEvent : RsEvent { RsEvent::serial_process(j,ctx); RS_SERIAL_PROCESS(mGossipDiscoveryEventType); - RS_SERIAL_PROCESS(mInvite); - } + RS_SERIAL_PROCESS(mFromId); + RS_SERIAL_PROCESS(mAboutId); + } }; class RsGossipDiscovery diff --git a/retroshare-gui/src/gui/common/NewFriendList.cpp b/retroshare-gui/src/gui/common/NewFriendList.cpp index 4d794e6c4..561f7b524 100644 --- a/retroshare-gui/src/gui/common/NewFriendList.cpp +++ b/retroshare-gui/src/gui/common/NewFriendList.cpp @@ -177,10 +177,11 @@ NewFriendList::NewFriendList(QWidget */*parent*/) : /* RsAutoUpdatePage(5000,par ui->filterLineEdit->setPlaceholderText(tr("Search")) ; ui->filterLineEdit->showFilterIcon(); - mEventHandlerId=0; // forces initialization - rsEvents->registerEventsHandler( - [this](std::shared_ptr e) { handleEvent(e); }, - mEventHandlerId, RsEventType::PEER_CONNECTION ); + mEventHandlerId_peer=0; // forces initialization + mEventHandlerId_gssp=0; // forces initialization + + rsEvents->registerEventsHandler( [this](std::shared_ptr e) { handleEvent(e); }, mEventHandlerId_peer, RsEventType::PEER_CONNECTION ); + rsEvents->registerEventsHandler( [this](std::shared_ptr e) { handleEvent(e); }, mEventHandlerId_gssp, RsEventType::GOSSIP_DISCOVERY ); mModel = new RsFriendListModel(); mProxyModel = new FriendListSortFilterProxyModel(ui->peerTreeWidget->header(),this); @@ -269,7 +270,9 @@ void NewFriendList::handleEvent(std::shared_ptr /*e*/) NewFriendList::~NewFriendList() { - rsEvents->unregisterEventsHandler(mEventHandlerId); + rsEvents->unregisterEventsHandler(mEventHandlerId_peer); + rsEvents->unregisterEventsHandler(mEventHandlerId_gssp); + delete mModel; delete mProxyModel; delete ui; diff --git a/retroshare-gui/src/gui/common/NewFriendList.h b/retroshare-gui/src/gui/common/NewFriendList.h index 6d4b8d0a4..79b2d0a5a 100644 --- a/retroshare-gui/src/gui/common/NewFriendList.h +++ b/retroshare-gui/src/gui/common/NewFriendList.h @@ -121,7 +121,8 @@ private: // Settings for peer list display bool mShowState; - RsEventsHandlerId_t mEventHandlerId; + RsEventsHandlerId_t mEventHandlerId_peer; + RsEventsHandlerId_t mEventHandlerId_gssp; std::set openGroups; std::set openPeers;