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;
}
}