moved more peer connection notifications to rsEvents

This commit is contained in:
csoler 2019-12-07 21:43:28 +01:00
parent 9790b98605
commit f118b4656e
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
5 changed files with 57 additions and 35 deletions

View File

@ -473,30 +473,20 @@ void p3LinkMgrIMPL::tickMonitors()
#endif
/* notify GUI */
if (peer.actions & RS_PEER_CONNECTED)
{
p3Notify *notify = RsServer::notify();
if (notify)
{
auto e = std::make_shared<RsConnectionEvent>() ;
e->mConnectionType = RsConnectionEvent::PEER_CONNECTED;
e->mSslId = peer.id;
rsEvents->postEvent(e);
// normally these this below should disappear: there's no notion of popup in libretroshare.
// all GUI-type display features should be chosen in NotifyQt.
notify->AddPopupMessage(RS_POPUP_CONNECT, peer.id.toStdString(),"", "Online: ");
}
}
if (peer.actions & RS_PEER_DISCONNECTED)
if (rsEvents && (peer.actions & RS_PEER_CONNECTED))
{
auto e = std::make_shared<RsConnectionEvent>() ;
e->mConnectionType = RsConnectionEvent::PEER_DISCONNECTED;
e->mConnectionInfoCode = RsConnectionEvent::PEER_CONNECTED;
e->mSslId = peer.id;
rsEvents->postEvent(e);
}
if (rsEvents && (peer.actions & RS_PEER_DISCONNECTED))
{
auto e = std::make_shared<RsConnectionEvent>() ;
e->mConnectionInfoCode = RsConnectionEvent::PEER_DISCONNECTED;
e->mSslId = peer.id;
rsEvents->postEvent(e);

View File

@ -1808,7 +1808,16 @@ bool p3PeerMgrIMPL::addCandidateForOwnExternalAddress(const RsPeerId &from, cons
{
std::cerr << " Peer " << from << " reports a connection address (" << sockaddr_storage_iptostring(addr_filtered) <<") that is not your current external address (" << sockaddr_storage_iptostring(own_addr) << "). This is weird." << std::endl;
RsServer::notify()->AddFeedItem(RS_FEED_ITEM_SEC_IP_WRONG_EXTERNAL_IP_REPORTED, from.toStdString(), sockaddr_storage_iptostring(own_addr), sockaddr_storage_iptostring(addr));
if(rsEvents)
{
auto ev = std::make_shared<RsConnectionEvent>();
ev->mSslId = from;
ev->mStrInfo1 = sockaddr_storage_iptostring(addr);
ev->mStrInfo2 = sockaddr_storage_iptostring(own_addr);
ev->mConnectionInfoCode = RsConnectionEvent::PEER_REPORTS_WRONG_IP;
rsEvents->postEvent(ev);
}
}
// we could also sweep over all connected friends and see if some report a different address.

View File

@ -222,22 +222,26 @@ struct RsConnectionEvent : RsEvent
{
RsConnectionEvent()
: RsEvent(RsEventType::PEER_CONNECTION),
mConnectionType(UNKNOWN) {}
mConnectionInfoCode(UNKNOWN) {}
enum ConnectionType: uint8_t {
UNKNOWN = 0x00,
PEER_CONNECTED = 0x01,
PEER_DISCONNECTED = 0x02,
PEER_TIME_SHIFT = 0x03, // mStrInfo1 = time shift in seconds
PEER_REPORTS_WRONG_IP = 0x04, // mStrInfo1 = address reported, mStrInfo2 = own address
};
ConnectionType mConnectionType;
ConnectionType mConnectionInfoCode;
RsPeerId mSslId;
std::string mStrInfo1;
std::string mStrInfo2;
///* @see RsEvent @see RsSerializable
void serial_process( RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) override
{
RsEvent::serial_process(j, ctx);
RS_SERIAL_PROCESS(mConnectionType);
RS_SERIAL_PROCESS(mConnectionInfoCode);
RS_SERIAL_PROCESS(mSslId);
}
};

View File

@ -367,12 +367,16 @@ int p3rtt::storePongResult(const RsPeerId& id, uint32_t counter, double recv_ts,
peerInfo->mCurrentMeanOffset = mean / peerInfo->mPongResults.size();
if(fabs(peerInfo->mCurrentMeanOffset) > 120)
{
p3Notify *notify = RsServer::notify();
if (notify)
{
//notify->AddPopupMessage(RS_POPUP_OFFSET, eerInfo->mId.toStdString(),"", "Time Offset: ");
notify->AddFeedItem(RS_FEED_ITEM_PEER_OFFSET, peerInfo->mId.toStdString());
}
if(rsEvents)
{
auto ev = std::make_shared<RsConnectionEvent>();
ev->mSslId = peerInfo->mId;
ev->mStrInfo1 = RsUtil::NumberToString(peerInfo->mCurrentMeanOffset,false);
ev->mConnectionInfoCode = RsConnectionEvent::PEER_TIME_SHIFT;
rsEvents->postEvent(ev);
}
std::cerr << "(WW) Peer:" << peerInfo->mId << " get time offset more than two minutes with you!!!" << std::endl;
}
}

View File

@ -211,12 +211,17 @@ void NewsFeed::handleConnectionEvent(std::shared_ptr<const RsEvent> event)
std::cerr << "NotifyQt: handling connection event from peer " << e.mSslId << std::endl;
switch(e.mConnectionType)
switch(e.mConnectionInfoCode)
{
case RsConnectionEvent::PEER_CONNECTED: addFeedItemIfUnique(new PeerItem(this, NEWSFEED_PEERLIST, e.mSslId, PEER_TYPE_CONNECT, false), true);
break;
break;
case RsConnectionEvent::PEER_DISCONNECTED: // not handled yet
break;
case RsConnectionEvent::PEER_TIME_SHIFT:addFeedItemIfUnique(new PeerItem(this, NEWSFEED_PEERLIST, e.mSslId, PEER_TYPE_OFFSET, false),false);
break;
case RsConnectionEvent::PEER_REPORTS_WRONG_IP: addFeedItemIfUnique(new SecurityIpItem(this, e.mSslId, e.mStrInfo2, e.mStrInfo1, RS_FEED_ITEM_SEC_IP_WRONG_EXTERNAL_IP_REPORTED, false), false);
break;
case RsConnectionEvent::PEER_DISCONNECTED: break;// not handled yet
default: break;
}
}
@ -277,6 +282,7 @@ void NewsFeed::updateDisplay()
{
switch(fi.mType)
{
#ifdef TO_REMOVE
case RS_FEED_ITEM_PEER_HELLO:
if (flags & RS_FEED_TYPE_PEER)
addFeedItemPeerHello(fi);
@ -306,6 +312,7 @@ void NewsFeed::updateDisplay()
if (flags & RS_FEED_TYPE_SECURITY_IP)
addFeedItemSecurityWrongExternalIpReported(fi, false);
break;
#endif
case RS_FEED_ITEM_CHANNEL_NEW:
if (flags & RS_FEED_TYPE_CHANNEL)
@ -484,6 +491,7 @@ void NewsFeed::updateDisplay()
void NewsFeed::testFeeds(uint notifyFlags)
{
#ifdef TODO
if (!instance) {
return;
}
@ -507,7 +515,6 @@ void NewsFeed::testFeeds(uint notifyFlags)
instance->addFeedItemPeerDisconnect(fi);
instance->addFeedItemPeerHello(fi);
instance->addFeedItemPeerNew(fi);
instance->addFeedItemPeerOffset(fi);
break;
case RS_FEED_TYPE_SECURITY:
@ -647,6 +654,7 @@ void NewsFeed::testFeeds(uint notifyFlags)
instance->ui->feedWidget->enableCountChangedSignal(true);
instance->sendNewsFeedChanged();
#endif
}
void NewsFeed::loadCircleGroup(const uint32_t &token)
@ -1142,6 +1150,7 @@ void NewsFeed::remUniqueFeedItem(FeedItem *item)
}
}
#ifdef TO_REMOVE
void NewsFeed::addFeedItemPeerConnect(const RsFeedItem &fi)
{
/* make new widget */
@ -1183,6 +1192,7 @@ void NewsFeed::addFeedItemPeerHello(const RsFeedItem &fi)
std::cerr << std::endl;
#endif
}
#endif
void NewsFeed::addFeedItemPeerNew(const RsFeedItem &fi)
{
@ -1198,6 +1208,7 @@ void NewsFeed::addFeedItemPeerNew(const RsFeedItem &fi)
#endif
}
#ifdef TO_REMOVE
void NewsFeed::addFeedItemPeerOffset(const RsFeedItem &fi)
{
/* make new widget */
@ -1212,6 +1223,7 @@ void NewsFeed::addFeedItemPeerOffset(const RsFeedItem &fi)
#endif
}
void NewsFeed::addFeedItemSecurityConnectAttempt(const RsFeedItem &fi)
{
/* make new widget */
@ -1267,6 +1279,7 @@ void NewsFeed::addFeedItemSecurityUnknownOut(const RsFeedItem &fi)
std::cerr << std::endl;
#endif
}
#endif
void NewsFeed::addFeedItemSecurityIpBlacklisted(const RsFeedItem &fi, bool isTest)
{
@ -1282,6 +1295,7 @@ void NewsFeed::addFeedItemSecurityIpBlacklisted(const RsFeedItem &fi, bool isTes
#endif
}
#ifdef TO_REMOVE
void NewsFeed::addFeedItemSecurityWrongExternalIpReported(const RsFeedItem &fi, bool isTest)
{
/* make new widget */
@ -1295,6 +1309,7 @@ void NewsFeed::addFeedItemSecurityWrongExternalIpReported(const RsFeedItem &fi,
std::cerr << std::endl;
#endif
}
#endif
void NewsFeed::addFeedItemChannelNew(const RsFeedItem &fi)
{