added event handling when peer discovery is received

This commit is contained in:
csoler 2021-02-06 14:57:22 +01:00
parent 37dc37ce4a
commit 3f89a3300d
4 changed files with 38 additions and 12 deletions

View File

@ -388,6 +388,15 @@ void p3discovery2::recvOwnContactInfo(const RsPeerId &fromId, const RsDiscContac
if(!mPeerMgr->isHiddenNode(rsPeers->getOwnId())) if(!mPeerMgr->isHiddenNode(rsPeers->getOwnId()))
updatePeerAddresses(item); updatePeerAddresses(item);
if(rsEvents)
{
auto ev = std::make_shared<RsGossipDiscoveryEvent>();
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 the peer is not validated, we stop the exchange here
if(det.skip_pgp_signature_validation) 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); RsServer::notify()->notifyListChange(NOTIFY_LIST_NEIGHBOURS, NOTIFY_TYPE_MOD);
if(should_notify_discovery) if(should_notify_discovery)
RsServer::notify()->notifyDiscInfoChanged(); {
RsServer::notify()->notifyDiscInfoChanged();
if(rsEvents)
{
auto ev = std::make_shared<RsGossipDiscoveryEvent>();
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 /* we explictly request certificates, instead of getting them all the time

View File

@ -47,8 +47,8 @@ extern std::shared_ptr<RsGossipDiscovery> rsGossipDiscovery;
*/ */
enum class RsGossipDiscoveryEventType: uint32_t { enum class RsGossipDiscoveryEventType: uint32_t {
UNKNOWN = 0x00, UNKNOWN = 0x00,
PEER_INVITE_RECEIVED = 0x01 FRIEND_PEER_INFO_RECEIVED = 0x01,
}; };
struct RsGossipDiscoveryEvent : RsEvent struct RsGossipDiscoveryEvent : RsEvent
@ -57,7 +57,8 @@ struct RsGossipDiscoveryEvent : RsEvent
virtual ~RsGossipDiscoveryEvent() override {} virtual ~RsGossipDiscoveryEvent() override {}
RsGossipDiscoveryEventType mGossipDiscoveryEventType; RsGossipDiscoveryEventType mGossipDiscoveryEventType;
std::string mInvite; RsPeerId mFromId;
RsPeerId mAboutId;
/// @see RsSerializable /// @see RsSerializable
virtual void serial_process( RsGenericSerializer::SerializeJob j, virtual void serial_process( RsGenericSerializer::SerializeJob j,
@ -65,8 +66,9 @@ struct RsGossipDiscoveryEvent : RsEvent
{ {
RsEvent::serial_process(j,ctx); RsEvent::serial_process(j,ctx);
RS_SERIAL_PROCESS(mGossipDiscoveryEventType); RS_SERIAL_PROCESS(mGossipDiscoveryEventType);
RS_SERIAL_PROCESS(mInvite); RS_SERIAL_PROCESS(mFromId);
} RS_SERIAL_PROCESS(mAboutId);
}
}; };
class RsGossipDiscovery class RsGossipDiscovery

View File

@ -177,10 +177,11 @@ NewFriendList::NewFriendList(QWidget */*parent*/) : /* RsAutoUpdatePage(5000,par
ui->filterLineEdit->setPlaceholderText(tr("Search")) ; ui->filterLineEdit->setPlaceholderText(tr("Search")) ;
ui->filterLineEdit->showFilterIcon(); ui->filterLineEdit->showFilterIcon();
mEventHandlerId=0; // forces initialization mEventHandlerId_peer=0; // forces initialization
rsEvents->registerEventsHandler( mEventHandlerId_gssp=0; // forces initialization
[this](std::shared_ptr<const RsEvent> e) { handleEvent(e); },
mEventHandlerId, RsEventType::PEER_CONNECTION ); rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> e) { handleEvent(e); }, mEventHandlerId_peer, RsEventType::PEER_CONNECTION );
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> e) { handleEvent(e); }, mEventHandlerId_gssp, RsEventType::GOSSIP_DISCOVERY );
mModel = new RsFriendListModel(); mModel = new RsFriendListModel();
mProxyModel = new FriendListSortFilterProxyModel(ui->peerTreeWidget->header(),this); mProxyModel = new FriendListSortFilterProxyModel(ui->peerTreeWidget->header(),this);
@ -269,7 +270,9 @@ void NewFriendList::handleEvent(std::shared_ptr<const RsEvent> /*e*/)
NewFriendList::~NewFriendList() NewFriendList::~NewFriendList()
{ {
rsEvents->unregisterEventsHandler(mEventHandlerId); rsEvents->unregisterEventsHandler(mEventHandlerId_peer);
rsEvents->unregisterEventsHandler(mEventHandlerId_gssp);
delete mModel; delete mModel;
delete mProxyModel; delete mProxyModel;
delete ui; delete ui;

View File

@ -121,7 +121,8 @@ private:
// Settings for peer list display // Settings for peer list display
bool mShowState; bool mShowState;
RsEventsHandlerId_t mEventHandlerId; RsEventsHandlerId_t mEventHandlerId_peer;
RsEventsHandlerId_t mEventHandlerId_gssp;
std::set<RsNodeGroupId> openGroups; std::set<RsNodeGroupId> openGroups;
std::set<RsPgpId> openPeers; std::set<RsPgpId> openPeers;