From d8569d813c833a82c5a22d5d45503d0aeeb506d6 Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 1 Dec 2019 22:35:16 +0100 Subject: [PATCH 01/39] switched security items to new notification system --- libretroshare/src/pqi/authssl.cc | 12 +++- libretroshare/src/pqi/authssl.h | 28 -------- libretroshare/src/pqi/p3notify.cc | 1 - libretroshare/src/pqi/pqissllistener.cc | 14 ++++ libretroshare/src/retroshare/rsevents.h | 49 ++++++++++++++ libretroshare/src/retroshare/rsnotify.h | 1 - retroshare-gui/src/gui/AboutWidget.cpp | 12 ++-- retroshare-gui/src/gui/NewsFeed.cpp | 87 +++++++++++++++++++++++++ retroshare-gui/src/gui/NewsFeed.h | 6 ++ retroshare-gui/src/gui/notifyqt.cpp | 18 ++--- retroshare-gui/src/gui/notifyqt.h | 3 +- 11 files changed, 179 insertions(+), 52 deletions(-) diff --git a/libretroshare/src/pqi/authssl.cc b/libretroshare/src/pqi/authssl.cc index 0b2fa91ec..1d500d74e 100644 --- a/libretroshare/src/pqi/authssl.cc +++ b/libretroshare/src/pqi/authssl.cc @@ -1189,6 +1189,8 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx) if(rsEvents) { ev->mErrorMsg = errMsg; + ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::NO_CERTIFICATE_SUPPLIED; + rsEvents->postEvent(std::move(ev)); } @@ -1218,7 +1220,8 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx) { ev->mSslCn = sslCn; ev->mPgpId = pgpId; - ev->mErrorMsg = errMsg; + ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::MISSING_AUTHENTICATION_INFO; + rsEvents->postEvent(std::move(ev)); } @@ -1237,6 +1240,8 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx) ev->mSslId = sslId; ev->mSslCn = sslCn; ev->mErrorMsg = errMsg; + ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::MISSING_AUTHENTICATION_INFO; + rsEvents->postEvent(std::move(ev)); } @@ -1266,6 +1271,7 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx) ev->mSslCn = sslCn; ev->mPgpId = pgpId; ev->mErrorMsg = errorMsg; + ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::MISMATCHED_PGP_ID; rsEvents->postEvent(std::move(ev)); } @@ -1290,6 +1296,7 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx) ev->mSslId = sslId; ev->mSslCn = sslCn; ev->mPgpId = pgpId; + ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::PGP_SIGNATURE_VALIDATION_FAILED; ev->mErrorMsg = errMsg; rsEvents->postEvent(std::move(ev)); } @@ -1311,6 +1318,7 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx) ev->mSslCn = sslCn; ev->mPgpId = pgpId; ev->mErrorMsg = errMsg; + ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::NOT_A_FRIEND; rsEvents->postEvent(std::move(ev)); } @@ -1330,6 +1338,8 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx) ev->mSslId = sslId; ev->mSslCn = sslCn; ev->mPgpId = pgpId; + ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::NO_ERROR; + rsEvents->postEvent(std::move(ev)); } diff --git a/libretroshare/src/pqi/authssl.h b/libretroshare/src/pqi/authssl.h index d7973e869..c38eab7ba 100644 --- a/libretroshare/src/pqi/authssl.h +++ b/libretroshare/src/pqi/authssl.h @@ -52,34 +52,6 @@ RsPeerId getCertSslId(const X509& x509); const EVP_PKEY* getPubKey(const X509& x509); }; -/** - * Event triggered by AuthSSL when authentication of a connection attempt either - * fail or success - */ -struct RsAuthSslConnectionAutenticationEvent : RsEvent -{ - RsAuthSslConnectionAutenticationEvent(); - - bool mSuccess; - RsPeerId mSslId; - std::string mSslCn; - RsPgpId mPgpId; - std::string mErrorMsg; - - ///* @see RsEvent @see RsSerializable - void serial_process( RsGenericSerializer::SerializeJob j, - RsGenericSerializer::SerializeContext& ctx) override - { - RsEvent::serial_process(j, ctx); - RS_SERIAL_PROCESS(mSuccess); - RS_SERIAL_PROCESS(mSslId); - RS_SERIAL_PROCESS(mSslCn); - RS_SERIAL_PROCESS(mPgpId); - RS_SERIAL_PROCESS(mErrorMsg); - } -}; - - /** * This is an implementation of SSL certificate authentication with PGP * signatures, instead of centralized certification authority. diff --git a/libretroshare/src/pqi/p3notify.cc b/libretroshare/src/pqi/p3notify.cc index 621c34119..c2ce4e059 100644 --- a/libretroshare/src/pqi/p3notify.cc +++ b/libretroshare/src/pqi/p3notify.cc @@ -236,7 +236,6 @@ void p3Notify::notifyOwnStatusMessageChanged() void p3Notify::notifyDiskFull (uint32_t location , uint32_t size_limit_in_MB ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyDiskFull (location,size_limit_in_MB) ; } void p3Notify::notifyPeerStatusChanged (const std::string& peer_id , uint32_t status ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyPeerStatusChanged (peer_id,status) ; } void p3Notify::notifyGxsChange (const RsGxsChanges& changes) {FOR_ALL_NOTIFY_CLIENTS (*it)->notifyGxsChange(changes) ;} -void p3Notify::notifyConnectionWithoutCert () { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyConnectionWithoutCert(); } void p3Notify::notifyPeerStatusChangedSummary () { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyPeerStatusChangedSummary() ; } void p3Notify::notifyDiscInfoChanged () { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyDiscInfoChanged () ; } diff --git a/libretroshare/src/pqi/pqissllistener.cc b/libretroshare/src/pqi/pqissllistener.cc index 3d62db9ea..879360fba 100644 --- a/libretroshare/src/pqi/pqissllistener.cc +++ b/libretroshare/src/pqi/pqissllistener.cc @@ -486,6 +486,20 @@ int pqissllistenbase::continueSSL(IncomingSSLInfo& incoming_connexion_info, bool break; } + if(rsEvents) + { + auto ev = std::unique_ptr(new RsAuthSslConnectionAutenticationEvent); + + ev->mSslId = incoming_connexion_info.sslid; + ev->mPgpId = incoming_connexion_info.gpgid; + ev->mSslCn = incoming_connexion_info.sslcn; + ev->mLocator = RsUrl(sockaddr_storage_iptostring(incoming_connexion_info.addr)); + ev->mSuccess = false; + ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::MISSING_AUTHENTICATION_INFO; + + rsEvents->postEvent(std::move(ev)); + } + closeConnection(fd, incoming_connexion_info.ssl) ; pqioutput(PQL_WARNING, pqissllistenzone, "Read Error on the SSL Socket\nShutting it down!"); diff --git a/libretroshare/src/retroshare/rsevents.h b/libretroshare/src/retroshare/rsevents.h index dbb4a4cee..a2fc7abbf 100644 --- a/libretroshare/src/retroshare/rsevents.h +++ b/libretroshare/src/retroshare/rsevents.h @@ -25,6 +25,7 @@ #include #include "util/rsmemory.h" +#include "util/rsurl.h" #include "serialiser/rsserializable.h" #include "serialiser/rstypeserializer.h" @@ -170,3 +171,51 @@ public: virtual ~RsEvents(); }; + +//===================================================================================================// +// Connexion events // +//===================================================================================================// + +/** + * Event triggered by AuthSSL when authentication of a connection attempt either + * fail or success + */ +struct RsAuthSslConnectionAutenticationEvent : RsEvent +{ + RsAuthSslConnectionAutenticationEvent(); + + enum ConnextionErrorCode: uint8_t { + UNKNOWN_ERROR = 0x00, + MISSING_AUTHENTICATION_INFO = 0x01, + PGP_SIGNATURE_VALIDATION_FAILED = 0x02, + MISMATCHED_PGP_ID = 0x03, + NO_CERTIFICATE_SUPPLIED = 0x04, + NOT_A_FRIEND = 0x05, + MISSING_CERTIFICATE = 0x06, + IP_IS_BLACKLISTED = 0x07, + NO_ERROR = 0x08, + }; + + bool mSuccess; + RsPeerId mSslId; + std::string mSslCn; + RsPgpId mPgpId; + RsUrl mLocator; + std::string mErrorMsg; + ConnextionErrorCode mErrorCode; + + ///* @see RsEvent @see RsSerializable + void serial_process( RsGenericSerializer::SerializeJob j, + RsGenericSerializer::SerializeContext& ctx) override + { + RsEvent::serial_process(j, ctx); + RS_SERIAL_PROCESS(mSuccess); + RS_SERIAL_PROCESS(mSslId); + RS_SERIAL_PROCESS(mSslCn); + RS_SERIAL_PROCESS(mPgpId); + RS_SERIAL_PROCESS(mLocator); + RS_SERIAL_PROCESS(mErrorMsg); + RS_SERIAL_PROCESS(mErrorCode); + } +}; + diff --git a/libretroshare/src/retroshare/rsnotify.h b/libretroshare/src/retroshare/rsnotify.h index 894d1f30d..b30c15170 100644 --- a/libretroshare/src/retroshare/rsnotify.h +++ b/libretroshare/src/retroshare/rsnotify.h @@ -231,7 +231,6 @@ public: virtual void notifyDiskFull (uint32_t /* location */, uint32_t /* size limit in MB */) {} virtual void notifyPeerStatusChanged (const std::string& /* peer_id */, uint32_t /* status */) {} virtual void notifyGxsChange (const RsGxsChanges& /* changes */) {} - virtual void notifyConnectionWithoutCert () {} /* one or more peers has changed the states */ virtual void notifyPeerStatusChangedSummary () {} diff --git a/retroshare-gui/src/gui/AboutWidget.cpp b/retroshare-gui/src/gui/AboutWidget.cpp index c2b07a6fe..e48b34804 100644 --- a/retroshare-gui/src/gui/AboutWidget.cpp +++ b/retroshare-gui/src/gui/AboutWidget.cpp @@ -973,11 +973,13 @@ void AboutWidget::on_copy_button_clicked() verInfo+=addLibraries("libretroshare", libraries); #ifdef RS_JSONAPI - /* Add version numbers of RetroShare */ - // Add versions here. Find a better place. - libraries.clear(); - libraries.push_back(RsLibraryInfo("RestBed", restbed::get_version())); - verInfo+=addLibraries("RetroShare", libraries); +// No version number available for restbed apparently. +// +// /* Add version numbers of RetroShare */ +// // Add versions here. Find a better place. +// libraries.clear(); +// libraries.push_back(RsLibraryInfo("RestBed", restbed::get_version())); +// verInfo+=addLibraries("RetroShare", libraries); #endif /* Add version numbers of plugins */ diff --git a/retroshare-gui/src/gui/NewsFeed.cpp b/retroshare-gui/src/gui/NewsFeed.cpp index 9a017270c..665817005 100644 --- a/retroshare-gui/src/gui/NewsFeed.cpp +++ b/retroshare-gui/src/gui/NewsFeed.cpp @@ -33,6 +33,7 @@ #include #include +#include "util/qtthreadsutils.h" #include "feeds/ChatMsgItem.h" #include "feeds/GxsCircleItem.h" #include "feeds/GxsChannelGroupItem.h" @@ -74,6 +75,8 @@ NewsFeed::NewsFeed(QWidget *parent) : RsAutoUpdatePage(1000,parent), ui(new Ui::NewsFeed) { + rsEvents->registerEventsHandler( [this](std::shared_ptr event) { handleEvent(event); }, mEventHandlerId ); + /* Invoke the Qt Designer generated object setup routine */ ui->setupUi(this); @@ -123,6 +126,8 @@ QString hlp_str = tr( NewsFeed::~NewsFeed() { + rsEvents->unregisterEventsHandler(mEventHandlerId); + // save settings processSettings(false); @@ -176,6 +181,88 @@ void NewsFeed::sortChanged(int index) ui->feedWidget->setSortRole(ROLE_RECEIVED, sortOrder); } +// handler for the new notification system in libretroshare. + +void NewsFeed::handleEvent(std::shared_ptr event) +{ + uint flags = Settings->getNewsFeedFlags(); + + const RsAuthSslConnectionAutenticationEvent *pssl_e = dynamic_cast(event.get()); + + if(pssl_e != nullptr && (flags & (RS_FEED_TYPE_SECURITY | RS_FEED_TYPE_PEER))) + { + RsAuthSslConnectionAutenticationEvent e = *pssl_e; // make a copy because we lose memory ownership here + + RsQThreadUtils::postToObject( [=]() + { + /* Here it goes any code you want to be executed on the Qt Gui + * thread, for example to update the data model with new information + * after a blocking call to RetroShare API complete, note that + * Qt::QueuedConnection is important! + */ + handleSecurityEvent(e); + + }, this ); + } +} + +void NewsFeed::handleSecurityEvent(const RsAuthSslConnectionAutenticationEvent& e) +{ + std::cerr << "NotifyQt: handling connection security event from (" << e.mSslId << "," << e.mPgpId << ") error code: " << e.mErrorCode << std::endl; + uint flags = Settings->getNewsFeedFlags(); + + if(e.mSuccess) + if(flags & RS_FEED_TYPE_PEER) + { + addFeedItem(new PeerItem(this, NEWSFEED_PEERLIST, e.mSslId, PEER_TYPE_CONNECT, false)); + return; + } + else + return; + + uint32_t FeedItemType=0; + + switch(e.mErrorCode) + { + case RsAuthSslConnectionAutenticationEvent::NO_CERTIFICATE_SUPPLIED: + case RsAuthSslConnectionAutenticationEvent::MISMATCHED_PGP_ID: // fallthrough + case RsAuthSslConnectionAutenticationEvent::MISSING_AUTHENTICATION_INFO: FeedItemType = RS_FEED_ITEM_SEC_BAD_CERTIFICATE; + break; + + case RsAuthSslConnectionAutenticationEvent::PGP_SIGNATURE_VALIDATION_FAILED: FeedItemType = RS_FEED_ITEM_SEC_WRONG_SIGNATURE; + break; + + case RsAuthSslConnectionAutenticationEvent::NOT_A_FRIEND: FeedItemType = RS_FEED_ITEM_SEC_AUTH_DENIED; + break; + + case RsAuthSslConnectionAutenticationEvent::IP_IS_BLACKLISTED: FeedItemType = RS_FEED_ITEM_SEC_IP_BLACKLISTED; + break; + + case RsAuthSslConnectionAutenticationEvent::MISSING_CERTIFICATE: FeedItemType = RS_FEED_ITEM_SEC_MISSING_CERTIFICATE; + break; + + default: + return; // display nothing + } + + RsPeerDetails det; + rsPeers->getPeerDetails(e.mSslId,det) || rsPeers->getGPGDetails(e.mPgpId,det); + + addFeedItemIfUnique(new SecurityItem(this, + NEWSFEED_SECLIST, + det.gpg_id, det.id, + det.location, + e.mLocator.toString(), + FeedItemType, + false), + RS_FEED_ITEM_SEC_BAD_CERTIFICATE, + det.gpg_id.toStdString(), + std::string(), + std::string(), + std::string(), + true ); +} + void NewsFeed::updateDisplay() { if (!rsNotify) diff --git a/retroshare-gui/src/gui/NewsFeed.h b/retroshare-gui/src/gui/NewsFeed.h index 3b91774ce..097260913 100644 --- a/retroshare-gui/src/gui/NewsFeed.h +++ b/retroshare-gui/src/gui/NewsFeed.h @@ -83,6 +83,8 @@ public: virtual void updateDisplay(); + void handleEvent(std::shared_ptr event); // get events from libretroshare + signals: void newsFeedChanged(int count); @@ -100,6 +102,8 @@ private slots: void sendNewsFeedChanged(); private: + void handleSecurityEvent(const RsAuthSslConnectionAutenticationEvent& e); + void addFeedItem(FeedItem *item); void addFeedItemIfUnique(FeedItem *item, int itemType, const std::string& id1, const std::string& id2, const std::string& id3, const std::string& id4, bool replace); void remUniqueFeedItem(FeedItem *item, int itemType, const std::string& id1, const std::string& id2, const std::string& id3, const std::string& id4); @@ -165,6 +169,8 @@ private: /* UI - from Designer */ Ui::NewsFeed *ui; + + RsEventsHandlerId_t mEventHandlerId; }; #endif diff --git a/retroshare-gui/src/gui/notifyqt.cpp b/retroshare-gui/src/gui/notifyqt.cpp index 5d1a2396f..d4ffa44b7 100644 --- a/retroshare-gui/src/gui/notifyqt.cpp +++ b/retroshare-gui/src/gui/notifyqt.cpp @@ -89,6 +89,10 @@ void NotifyQt::SetDisableAll(bool bValue) } } +NotifyQt::~NotifyQt() +{ +} + NotifyQt::NotifyQt() : cDialog(NULL) { runningToasterTimer = new QTimer(this); @@ -492,20 +496,6 @@ void NotifyQt::notifyChatLobbyTimeShift(int shift) emit chatLobbyTimeShift(shift) ; } -void NotifyQt::notifyConnectionWithoutCert() -{ - { - QMutexLocker m(&_mutex) ; - if(!_enabled) - return ; - } - -#ifdef NOTIFY_DEBUG - std::cerr << "notifyQt: Received notifyConnectionWithoutCert" << std::endl; -#endif - emit connectionWithoutCert(); -} - void NotifyQt::handleChatLobbyTimeShift(int /*shift*/) { return ; // we say nothing. The help dialog of lobbies explains this already. diff --git a/retroshare-gui/src/gui/notifyqt.h b/retroshare-gui/src/gui/notifyqt.h index de0fb7aca..82376304c 100644 --- a/retroshare-gui/src/gui/notifyqt.h +++ b/retroshare-gui/src/gui/notifyqt.h @@ -56,7 +56,7 @@ class NotifyQt: public QObject, public NotifyClient static bool isAllDisable(); void enable() ; - virtual ~NotifyQt() { return; } + virtual ~NotifyQt() ; void setNetworkDialog(NetworkDialog *c) { cDialog = c; } @@ -76,7 +76,6 @@ class NotifyQt: public QObject, public NotifyClient virtual void notifyOwnAvatarChanged() ; virtual void notifyChatLobbyEvent(uint64_t /* lobby id */, uint32_t /* event type */, const RsGxsId & /*nickname*/, const std::string& /* any string */) ; virtual void notifyChatLobbyTimeShift(int time_shift) ; - void notifyConnectionWithoutCert(); virtual void notifyOwnStatusMessageChanged() ; virtual void notifyDiskFull(uint32_t loc,uint32_t size_in_mb) ; From 65fa54c2064ded9cba0456139126c94144755201 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 2 Dec 2019 20:53:51 +0100 Subject: [PATCH 02/39] using new notification system for connection attempts --- libretroshare/src/pqi/authssl.cc | 15 +-- libretroshare/src/pqi/p3linkmgr.cc | 23 +++- libretroshare/src/pqi/p3notify.cc | 2 - libretroshare/src/pqi/p3notify.h | 2 - libretroshare/src/pqi/pqissllistener.cc | 3 +- libretroshare/src/retroshare/rsevents.h | 41 ++++-- libretroshare/src/retroshare/rsnotify.h | 2 - retroshare-gui/src/gui/NewsFeed.cpp | 126 +++++++++--------- retroshare-gui/src/gui/NewsFeed.h | 1 + .../src/gui/common/NewFriendList.cpp | 10 +- retroshare-gui/src/gui/common/NewFriendList.h | 2 + retroshare-gui/src/gui/notifyqt.cpp | 25 ---- retroshare-gui/src/gui/notifyqt.h | 6 +- 13 files changed, 127 insertions(+), 131 deletions(-) diff --git a/libretroshare/src/pqi/authssl.cc b/libretroshare/src/pqi/authssl.cc index 1d500d74e..397fdddea 100644 --- a/libretroshare/src/pqi/authssl.cc +++ b/libretroshare/src/pqi/authssl.cc @@ -1220,6 +1220,7 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx) { ev->mSslCn = sslCn; ev->mPgpId = pgpId; + ev->mErrorMsg = errMsg; ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::MISSING_AUTHENTICATION_INFO; rsEvents->postEvent(std::move(ev)); @@ -1332,17 +1333,6 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx) << "sslId: " << sslId << " isSslOnlyFriend: " << isSslOnlyFriend << std::endl; - if(rsEvents) - { - ev->mSuccess = true; - ev->mSslId = sslId; - ev->mSslCn = sslCn; - ev->mPgpId = pgpId; - ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::NO_ERROR; - - rsEvents->postEvent(std::move(ev)); - } - return verificationSuccess; } @@ -1795,9 +1785,6 @@ bool AuthSSLimpl::loadList(std::list& load) return true; } -RsAuthSslConnectionAutenticationEvent::RsAuthSslConnectionAutenticationEvent() : - RsEvent(RsEventType::AUTHSSL_CONNECTION_AUTENTICATION), mSuccess(false) {} - const EVP_PKEY*RsX509Cert::getPubKey(const X509& x509) { #if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER) diff --git a/libretroshare/src/pqi/p3linkmgr.cc b/libretroshare/src/pqi/p3linkmgr.cc index 100a16cad..a9554f43c 100644 --- a/libretroshare/src/pqi/p3linkmgr.cc +++ b/libretroshare/src/pqi/p3linkmgr.cc @@ -479,20 +479,29 @@ void p3LinkMgrIMPL::tickMonitors() if (notify) { - // normally these two 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: "); - notify->AddFeedItem(RS_FEED_ITEM_PEER_CONNECT, peer.id.toStdString()); + auto e = std::make_shared() ; - notify->notifyPeerConnected(peer.id.toStdString()); + e->mType = 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) { p3Notify *notify = RsServer::notify(); - if (notify) - notify->notifyPeerDisconnected(peer.id.toStdString()); + auto e = std::make_shared() ; + + e->mType = RsConnectionEvent::PEER_DISCONNECTED; + e->mSslId = peer.id; + + rsEvents->postEvent(e); } } } diff --git a/libretroshare/src/pqi/p3notify.cc b/libretroshare/src/pqi/p3notify.cc index c2ce4e059..95486f1a4 100644 --- a/libretroshare/src/pqi/p3notify.cc +++ b/libretroshare/src/pqi/p3notify.cc @@ -217,8 +217,6 @@ void p3Notify::notifyChatLobbyEvent(uint64_t lobby_id, uint32_t event_type,const void p3Notify::notifyListPreChange(int list, int type) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyListPreChange(list,type) ; } void p3Notify::notifyListChange (int list, int type) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyListChange (list,type) ; } -void p3Notify::notifyPeerConnected (const std::string& peer_id) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyPeerConnected(peer_id); } -void p3Notify::notifyPeerDisconnected (const std::string& peer_id) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyPeerDisconnected(peer_id); } void p3Notify::notifyErrorMsg (int list, int sev, std::string msg) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyErrorMsg(list,sev,msg) ; } void p3Notify::notifyChatMessage (const ChatMessage &msg) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyChatMessage(msg) ; } void p3Notify::notifyChatStatus (const ChatId& chat_id, const std::string& status_string) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyChatStatus(chat_id,status_string) ; } diff --git a/libretroshare/src/pqi/p3notify.h b/libretroshare/src/pqi/p3notify.h index 7cbbbef55..d288091c3 100644 --- a/libretroshare/src/pqi/p3notify.h +++ b/libretroshare/src/pqi/p3notify.h @@ -91,8 +91,6 @@ class p3Notify: public RsNotify // Notifications of clients. Can be called from anywhere inside libretroshare. // - void notifyPeerConnected (const std::string& /* peer_id */); - void notifyPeerDisconnected (const std::string& /* peer_id */); void notifyListPreChange (int /* list */, int /* type */) ; void notifyListChange (int /* list */, int /* type */) ; void notifyErrorMsg (int /* list */, int /* sev */, std::string /* msg */) ; diff --git a/libretroshare/src/pqi/pqissllistener.cc b/libretroshare/src/pqi/pqissllistener.cc index 879360fba..afd12ccbd 100644 --- a/libretroshare/src/pqi/pqissllistener.cc +++ b/libretroshare/src/pqi/pqissllistener.cc @@ -493,8 +493,7 @@ int pqissllistenbase::continueSSL(IncomingSSLInfo& incoming_connexion_info, bool ev->mSslId = incoming_connexion_info.sslid; ev->mPgpId = incoming_connexion_info.gpgid; ev->mSslCn = incoming_connexion_info.sslcn; - ev->mLocator = RsUrl(sockaddr_storage_iptostring(incoming_connexion_info.addr)); - ev->mSuccess = false; + ev->mLocator = RsUrl(incoming_connexion_info.addr); ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::MISSING_AUTHENTICATION_INFO; rsEvents->postEvent(std::move(ev)); diff --git a/libretroshare/src/retroshare/rsevents.h b/libretroshare/src/retroshare/rsevents.h index a2fc7abbf..aa366e7bf 100644 --- a/libretroshare/src/retroshare/rsevents.h +++ b/libretroshare/src/retroshare/rsevents.h @@ -59,7 +59,7 @@ enum class RsEventType : uint32_t AUTHSSL_CONNECTION_AUTENTICATION = 3, /// @see pqissl - REMOTE_PEER_REFUSED_CONNECTION = 4, + PEER_CONNECTION = 4, /// @see RsGxsChanges GXS_CHANGES = 5, @@ -173,7 +173,7 @@ public: }; //===================================================================================================// -// Connexion events // +// Connexion and security events // //===================================================================================================// /** @@ -182,10 +182,10 @@ public: */ struct RsAuthSslConnectionAutenticationEvent : RsEvent { - RsAuthSslConnectionAutenticationEvent(); + RsAuthSslConnectionAutenticationEvent() : RsEvent(RsEventType::AUTHSSL_CONNECTION_AUTENTICATION) {} - enum ConnextionErrorCode: uint8_t { - UNKNOWN_ERROR = 0x00, + enum ConnectionErrorCode: uint8_t { + NO_ERROR = 0x00, MISSING_AUTHENTICATION_INFO = 0x01, PGP_SIGNATURE_VALIDATION_FAILED = 0x02, MISMATCHED_PGP_ID = 0x03, @@ -193,23 +193,21 @@ struct RsAuthSslConnectionAutenticationEvent : RsEvent NOT_A_FRIEND = 0x05, MISSING_CERTIFICATE = 0x06, IP_IS_BLACKLISTED = 0x07, - NO_ERROR = 0x08, + UNKNOWN_ERROR = 0x08, }; - bool mSuccess; RsPeerId mSslId; std::string mSslCn; RsPgpId mPgpId; RsUrl mLocator; std::string mErrorMsg; - ConnextionErrorCode mErrorCode; + ConnectionErrorCode mErrorCode; ///* @see RsEvent @see RsSerializable void serial_process( RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext& ctx) override { RsEvent::serial_process(j, ctx); - RS_SERIAL_PROCESS(mSuccess); RS_SERIAL_PROCESS(mSslId); RS_SERIAL_PROCESS(mSslCn); RS_SERIAL_PROCESS(mPgpId); @@ -219,3 +217,28 @@ struct RsAuthSslConnectionAutenticationEvent : RsEvent } }; +struct RsConnectionEvent : RsEvent +{ + RsConnectionEvent() + : RsEvent(RsEventType::PEER_CONNECTION), + mType(UNKNOWN) {} + + enum ConnectionType: uint8_t { + UNKNOWN = 0x00, + PEER_CONNECTED = 0x01, + PEER_DISCONNECTED = 0x02, + PEER_REFUSED_CONNECTION = 0x03, + }; + + ConnectionType mType; + RsPeerId mSslId; + + ///* @see RsEvent @see RsSerializable + void serial_process( RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) override + { + RsEvent::serial_process(j, ctx); + RS_SERIAL_PROCESS(mType); + RS_SERIAL_PROCESS(mSslId); + } +}; + diff --git a/libretroshare/src/retroshare/rsnotify.h b/libretroshare/src/retroshare/rsnotify.h index b30c15170..001848439 100644 --- a/libretroshare/src/retroshare/rsnotify.h +++ b/libretroshare/src/retroshare/rsnotify.h @@ -212,8 +212,6 @@ public: NotifyClient() {} virtual ~NotifyClient() {} - virtual void notifyPeerConnected (const std::string& /* peer_id */) {} - virtual void notifyPeerDisconnected (const std::string& /* peer_id */) {} virtual void notifyListPreChange (int /* list */, int /* type */) {} virtual void notifyListChange (int /* list */, int /* type */) {} virtual void notifyErrorMsg (int /* list */, int /* sev */, std::string /* msg */) {} diff --git a/retroshare-gui/src/gui/NewsFeed.cpp b/retroshare-gui/src/gui/NewsFeed.cpp index 665817005..6df0232af 100644 --- a/retroshare-gui/src/gui/NewsFeed.cpp +++ b/retroshare-gui/src/gui/NewsFeed.cpp @@ -189,57 +189,83 @@ void NewsFeed::handleEvent(std::shared_ptr event) const RsAuthSslConnectionAutenticationEvent *pssl_e = dynamic_cast(event.get()); - if(pssl_e != nullptr && (flags & (RS_FEED_TYPE_SECURITY | RS_FEED_TYPE_PEER))) + if(pssl_e != nullptr && (flags & RS_FEED_TYPE_SECURITY)) { - RsAuthSslConnectionAutenticationEvent e = *pssl_e; // make a copy because we lose memory ownership here + auto e = *pssl_e; // make a copy because we lose memory ownership here - RsQThreadUtils::postToObject( [=]() - { - /* Here it goes any code you want to be executed on the Qt Gui - * thread, for example to update the data model with new information - * after a blocking call to RetroShare API complete, note that - * Qt::QueuedConnection is important! - */ - handleSecurityEvent(e); + RsQThreadUtils::postToObject( [=]() { handleSecurityEvent(e); }, this ); + return; + } - }, this ); + const RsConnectionEvent *conn_e = dynamic_cast(event.get()); + + if(conn_e != nullptr && (flags & RS_FEED_TYPE_PEER)) + { + auto e = *conn_e; + + RsQThreadUtils::postToObject( [=]() { handleConnectionEvent(e); }, this ); + return; + } +} + +void NewsFeed::handleConnectionEvent(const RsConnectionEvent& e) +{ + std::cerr << "NotifyQt: handling connection event from peer " << e.mSslId << std::endl; + + switch(e.mType) + { + case RsConnectionEvent::PEER_CONNECTED: + addFeedItemIfUnique(new PeerItem(this, NEWSFEED_PEERLIST, e.mSslId, PEER_TYPE_CONNECT, false), + PEER_TYPE_CONNECT, + e.mSslId.toStdString(), + std::string(), + std::string(), + std::string(), + true); + break; + + case RsConnectionEvent::PEER_DISCONNECTED: break;// not handled yet + case RsConnectionEvent::PEER_REFUSED_CONNECTION: + { + RsPeerDetails det; + if(!rsPeers->getPeerDetails(e.mSslId,det)) + return; + + addFeedItemIfUnique(new SecurityItem(this, + NEWSFEED_SECLIST, + det.gpg_id, det.id, + det.location, + std::string(), + RS_FEED_ITEM_SEC_AUTH_DENIED, + false), + RS_FEED_ITEM_SEC_AUTH_DENIED, + det.gpg_id.toStdString(), + std::string(), + std::string(), + std::string(), + true ); + } break; + + default: break; } } void NewsFeed::handleSecurityEvent(const RsAuthSslConnectionAutenticationEvent& e) { - std::cerr << "NotifyQt: handling connection security event from (" << e.mSslId << "," << e.mPgpId << ") error code: " << e.mErrorCode << std::endl; + std::cerr << "NotifyQt: handling security event from (" << e.mSslId << "," << e.mPgpId << ") error code: " << e.mErrorCode << std::endl; uint flags = Settings->getNewsFeedFlags(); - if(e.mSuccess) - if(flags & RS_FEED_TYPE_PEER) - { - addFeedItem(new PeerItem(this, NEWSFEED_PEERLIST, e.mSslId, PEER_TYPE_CONNECT, false)); - return; - } - else - return; - uint32_t FeedItemType=0; switch(e.mErrorCode) { case RsAuthSslConnectionAutenticationEvent::NO_CERTIFICATE_SUPPLIED: case RsAuthSslConnectionAutenticationEvent::MISMATCHED_PGP_ID: // fallthrough - case RsAuthSslConnectionAutenticationEvent::MISSING_AUTHENTICATION_INFO: FeedItemType = RS_FEED_ITEM_SEC_BAD_CERTIFICATE; - break; - - case RsAuthSslConnectionAutenticationEvent::PGP_SIGNATURE_VALIDATION_FAILED: FeedItemType = RS_FEED_ITEM_SEC_WRONG_SIGNATURE; - break; - - case RsAuthSslConnectionAutenticationEvent::NOT_A_FRIEND: FeedItemType = RS_FEED_ITEM_SEC_AUTH_DENIED; - break; - - case RsAuthSslConnectionAutenticationEvent::IP_IS_BLACKLISTED: FeedItemType = RS_FEED_ITEM_SEC_IP_BLACKLISTED; - break; - - case RsAuthSslConnectionAutenticationEvent::MISSING_CERTIFICATE: FeedItemType = RS_FEED_ITEM_SEC_MISSING_CERTIFICATE; - break; + case RsAuthSslConnectionAutenticationEvent::MISSING_AUTHENTICATION_INFO: FeedItemType = RS_FEED_ITEM_SEC_BAD_CERTIFICATE; break; + case RsAuthSslConnectionAutenticationEvent::PGP_SIGNATURE_VALIDATION_FAILED: FeedItemType = RS_FEED_ITEM_SEC_WRONG_SIGNATURE; break; + case RsAuthSslConnectionAutenticationEvent::NOT_A_FRIEND: FeedItemType = RS_FEED_ITEM_SEC_AUTH_DENIED; break; + case RsAuthSslConnectionAutenticationEvent::IP_IS_BLACKLISTED: FeedItemType = RS_FEED_ITEM_SEC_IP_BLACKLISTED; break; + case RsAuthSslConnectionAutenticationEvent::MISSING_CERTIFICATE: FeedItemType = RS_FEED_ITEM_SEC_MISSING_CERTIFICATE; break; default: return; // display nothing @@ -255,12 +281,15 @@ void NewsFeed::handleSecurityEvent(const RsAuthSslConnectionAutenticationEvent& e.mLocator.toString(), FeedItemType, false), - RS_FEED_ITEM_SEC_BAD_CERTIFICATE, + FeedItemType, det.gpg_id.toStdString(), std::string(), std::string(), std::string(), true ); + + if (Settings->getMessageFlags() & RS_MESSAGE_CONNECT_ATTEMPT) + MessageComposer::sendConnectAttemptMsg(e.mPgpId, e.mSslId, QString::fromStdString(det.name + "(" + det.location + ")")); } void NewsFeed::updateDisplay() @@ -276,14 +305,6 @@ void NewsFeed::updateDisplay() { switch(fi.mType) { - case RS_FEED_ITEM_PEER_CONNECT: - if (flags & RS_FEED_TYPE_PEER) - addFeedItemPeerConnect(fi); - break; - case RS_FEED_ITEM_PEER_DISCONNECT: - if (flags & RS_FEED_TYPE_PEER) - addFeedItemPeerDisconnect(fi); - break; case RS_FEED_ITEM_PEER_HELLO: if (flags & RS_FEED_TYPE_PEER) addFeedItemPeerHello(fi); @@ -297,21 +318,9 @@ void NewsFeed::updateDisplay() addFeedItemPeerOffset(fi); break; - case RS_FEED_ITEM_SEC_CONNECT_ATTEMPT: - case RS_FEED_ITEM_SEC_WRONG_SIGNATURE: - case RS_FEED_ITEM_SEC_BAD_CERTIFICATE: - case RS_FEED_ITEM_SEC_MISSING_CERTIFICATE: - case RS_FEED_ITEM_SEC_INTERNAL_ERROR: - if (Settings->getMessageFlags() & RS_MESSAGE_CONNECT_ATTEMPT) { - MessageComposer::sendConnectAttemptMsg(RsPgpId(fi.mId1), RsPeerId(fi.mId2), QString::fromUtf8(fi.mId3.c_str())); - } if (flags & RS_FEED_TYPE_SECURITY) addFeedItemSecurityConnectAttempt(fi); break; - case RS_FEED_ITEM_SEC_AUTH_DENIED: - if (flags & RS_FEED_TYPE_SECURITY) - addFeedItemSecurityAuthDenied(fi); - break; case RS_FEED_ITEM_SEC_UNKNOWN_IN: if (flags & RS_FEED_TYPE_SECURITY) addFeedItemSecurityUnknownIn(fi); @@ -321,11 +330,6 @@ void NewsFeed::updateDisplay() addFeedItemSecurityUnknownOut(fi); break; - case RS_FEED_ITEM_SEC_IP_BLACKLISTED: - if (flags & RS_FEED_TYPE_SECURITY_IP) - addFeedItemSecurityIpBlacklisted(fi, false); - break; - case RS_FEED_ITEM_SEC_IP_WRONG_EXTERNAL_IP_REPORTED: if (flags & RS_FEED_TYPE_SECURITY_IP) addFeedItemSecurityWrongExternalIpReported(fi, false); diff --git a/retroshare-gui/src/gui/NewsFeed.h b/retroshare-gui/src/gui/NewsFeed.h index 097260913..9bc8e0afe 100644 --- a/retroshare-gui/src/gui/NewsFeed.h +++ b/retroshare-gui/src/gui/NewsFeed.h @@ -103,6 +103,7 @@ private slots: private: void handleSecurityEvent(const RsAuthSslConnectionAutenticationEvent& e); + void handleConnectionEvent(const RsConnectionEvent& e); void addFeedItem(FeedItem *item); void addFeedItemIfUnique(FeedItem *item, int itemType, const std::string& id1, const std::string& id2, const std::string& id3, const std::string& id4, bool replace); diff --git a/retroshare-gui/src/gui/common/NewFriendList.cpp b/retroshare-gui/src/gui/common/NewFriendList.cpp index 38e6ba3fd..417e1a279 100644 --- a/retroshare-gui/src/gui/common/NewFriendList.cpp +++ b/retroshare-gui/src/gui/common/NewFriendList.cpp @@ -176,6 +176,8 @@ NewFriendList::NewFriendList(QWidget *parent) : /* RsAutoUpdatePage(5000,parent) ui->filterLineEdit->setPlaceholderText(tr("Search")) ; ui->filterLineEdit->showFilterIcon(); + rsEvents->registerEventsHandler( [this](std::shared_ptr e) { handleEvent(e); }, mEventHandlerId ); + mModel = new RsFriendListModel(); mProxyModel = new FriendListSortFilterProxyModel(ui->peerTreeWidget->header(),this); @@ -236,8 +238,6 @@ NewFriendList::NewFriendList(QWidget *parent) : /* RsAutoUpdatePage(5000,parent) connect(NotifyQt::getInstance(), SIGNAL(friendsChanged()) , this, SLOT(forceUpdateDisplay()),Qt::QueuedConnection); connect(NotifyQt::getInstance(), SIGNAL(groupsChanged(int)) , this, SLOT(forceUpdateDisplay()),Qt::QueuedConnection); - connect(NotifyQt::getInstance(), SIGNAL(peerConnected(const QString&)) , this, SLOT(forceUpdateDisplay()),Qt::QueuedConnection); - connect(NotifyQt::getInstance(), SIGNAL(peerDisconnected(const QString&)), this, SLOT(forceUpdateDisplay()),Qt::QueuedConnection); connect(ui->actionShowOfflineFriends, SIGNAL(triggered(bool)), this, SLOT(setShowUnconnected(bool))); connect(ui->actionShowState, SIGNAL(triggered(bool)), this, SLOT(setShowState(bool)) ); @@ -254,6 +254,12 @@ NewFriendList::NewFriendList(QWidget *parent) : /* RsAutoUpdatePage(5000,parent) } +void NewFriendList::handleEvent(std::shared_ptr e) +{ + if(dynamic_cast(e.get()) != nullptr) + forceUpdateDisplay(); +} + NewFriendList::~NewFriendList() { delete ui; diff --git a/retroshare-gui/src/gui/common/NewFriendList.h b/retroshare-gui/src/gui/common/NewFriendList.h index 17214093d..6e5f617f9 100644 --- a/retroshare-gui/src/gui/common/NewFriendList.h +++ b/retroshare-gui/src/gui/common/NewFriendList.h @@ -95,6 +95,7 @@ private slots: protected: void changeEvent(QEvent *e); + void handleEvent(std::shared_ptr e); private: Ui::NewFriendList *ui; @@ -117,6 +118,7 @@ private: // Settings for peer list display bool mShowState; + RsEventsHandlerId_t mEventHandlerId; std::set openGroups; std::set openPeers; diff --git a/retroshare-gui/src/gui/notifyqt.cpp b/retroshare-gui/src/gui/notifyqt.cpp index d4ffa44b7..e13ed610d 100644 --- a/retroshare-gui/src/gui/notifyqt.cpp +++ b/retroshare-gui/src/gui/notifyqt.cpp @@ -89,10 +89,6 @@ void NotifyQt::SetDisableAll(bool bValue) } } -NotifyQt::~NotifyQt() -{ -} - NotifyQt::NotifyQt() : cDialog(NULL) { runningToasterTimer = new QTimer(this); @@ -740,27 +736,6 @@ void NotifyQt::notifyListChange(int list, int type) return; } -void NotifyQt::notifyPeerConnected(const std::string& peer_id) -{ - { - QMutexLocker m(&_mutex) ; - if(!_enabled) - return ; - } - - emit peerConnected(QString::fromStdString(peer_id)); -} -void NotifyQt::notifyPeerDisconnected(const std::string& peer_id) -{ - { - QMutexLocker m(&_mutex) ; - if(!_enabled) - return ; - } - - emit peerDisconnected(QString::fromStdString(peer_id)); -} - void NotifyQt::notifyListPreChange(int list, int /*type*/) { { diff --git a/retroshare-gui/src/gui/notifyqt.h b/retroshare-gui/src/gui/notifyqt.h index 82376304c..91fb1edbf 100644 --- a/retroshare-gui/src/gui/notifyqt.h +++ b/retroshare-gui/src/gui/notifyqt.h @@ -56,12 +56,10 @@ class NotifyQt: public QObject, public NotifyClient static bool isAllDisable(); void enable() ; - virtual ~NotifyQt() ; + virtual ~NotifyQt() = default; void setNetworkDialog(NetworkDialog *c) { cDialog = c; } - virtual void notifyPeerConnected(const std::string& /* peer_id */); - virtual void notifyPeerDisconnected(const std::string& /* peer_id */); virtual void notifyListPreChange(int list, int type); virtual void notifyListChange(int list, int type); virtual void notifyErrorMsg(int list, int sev, std::string msg); @@ -122,8 +120,6 @@ class NotifyQt: public QObject, public NotifyClient // It's beneficial to send info to the GUI using signals, because signals are thread-safe // as they get queued by Qt. // - void peerConnected(const QString&) const ; - void peerDisconnected(const QString&) const ; void hashingInfoChanged(const QString&) const ; void filesPreModChanged(bool) const ; void filesPostModChanged(bool) const ; From 31968f82f25b0c613b3f600b7987a455cfd826a3 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 2 Dec 2019 22:34:14 +0100 Subject: [PATCH 03/39] fixed a few typos --- retroshare-gui/src/gui/NewsFeed.cpp | 8 ++++---- retroshare-gui/src/gui/RetroShareLink.cpp | 2 +- retroshare-gui/src/gui/RetroShareLink.h | 2 +- retroshare-gui/src/gui/feeds/PeerItem.cpp | 19 ++++++++++--------- .../src/gui/msgs/MessageComposer.cpp | 14 ++++++++------ retroshare-gui/src/gui/msgs/MessageComposer.h | 2 +- 6 files changed, 25 insertions(+), 22 deletions(-) diff --git a/retroshare-gui/src/gui/NewsFeed.cpp b/retroshare-gui/src/gui/NewsFeed.cpp index 6df0232af..ee0bc1eb8 100644 --- a/retroshare-gui/src/gui/NewsFeed.cpp +++ b/retroshare-gui/src/gui/NewsFeed.cpp @@ -233,13 +233,13 @@ void NewsFeed::handleConnectionEvent(const RsConnectionEvent& e) addFeedItemIfUnique(new SecurityItem(this, NEWSFEED_SECLIST, - det.gpg_id, det.id, + det.gpg_id, e.mSslId, det.location, std::string(), RS_FEED_ITEM_SEC_AUTH_DENIED, false), RS_FEED_ITEM_SEC_AUTH_DENIED, - det.gpg_id.toStdString(), + e.mSslId.toStdString(), std::string(), std::string(), std::string(), @@ -282,14 +282,14 @@ void NewsFeed::handleSecurityEvent(const RsAuthSslConnectionAutenticationEvent& FeedItemType, false), FeedItemType, - det.gpg_id.toStdString(), + e.mSslId.toStdString(), std::string(), std::string(), std::string(), true ); if (Settings->getMessageFlags() & RS_MESSAGE_CONNECT_ATTEMPT) - MessageComposer::sendConnectAttemptMsg(e.mPgpId, e.mSslId, QString::fromStdString(det.name + "(" + det.location + ")")); + MessageComposer::addConnectAttemptMsg(e.mPgpId, e.mSslId, QString::fromStdString(det.name + "(" + det.location + ")")); } void NewsFeed::updateDisplay() diff --git a/retroshare-gui/src/gui/RetroShareLink.cpp b/retroshare-gui/src/gui/RetroShareLink.cpp index 0631ddee4..fe7374c90 100644 --- a/retroshare-gui/src/gui/RetroShareLink.cpp +++ b/retroshare-gui/src/gui/RetroShareLink.cpp @@ -578,7 +578,7 @@ RetroShareLink RetroShareLink::createCertificate(const RsPeerId& ssl_id) return link; } -RetroShareLink RetroShareLink::createUnknwonSslCertificate(const RsPeerId& sslId, const RsPgpId& gpgId) +RetroShareLink RetroShareLink::createUnknownSslCertificate(const RsPeerId& sslId, const RsPgpId& gpgId) { RetroShareLink link; link.clear(); diff --git a/retroshare-gui/src/gui/RetroShareLink.h b/retroshare-gui/src/gui/RetroShareLink.h index 9858571d5..61c794b11 100644 --- a/retroshare-gui/src/gui/RetroShareLink.h +++ b/retroshare-gui/src/gui/RetroShareLink.h @@ -90,7 +90,7 @@ class RetroShareLink static RetroShareLink createMessage(const RsPeerId &peerId, const QString& subject); static RetroShareLink createMessage(const RsGxsId &peerId, const QString& subject); static RetroShareLink createCertificate(const RsPeerId &ssl_id) ; - static RetroShareLink createUnknwonSslCertificate(const RsPeerId &sslId, const RsPgpId &gpgId = RsPgpId()) ; + static RetroShareLink createUnknownSslCertificate(const RsPeerId &sslId, const RsPgpId &gpgId = RsPgpId()) ; static RetroShareLink createExtraFile(const QString& name, uint64_t size, const QString& hash, const QString& ssl_id); static RetroShareLink createPublicMsgInvite(time_t time_stamp,const QString& pgp_id,const QString& hash) ; static RetroShareLink createIdentity(const RsGxsId& gxs_id,const QString& name,const QString& radix_data) ; diff --git a/retroshare-gui/src/gui/feeds/PeerItem.cpp b/retroshare-gui/src/gui/feeds/PeerItem.cpp index c1ccd788e..9a6f2cd2e 100644 --- a/retroshare-gui/src/gui/feeds/PeerItem.cpp +++ b/retroshare-gui/src/gui/feeds/PeerItem.cpp @@ -135,15 +135,16 @@ void PeerItem::updateItemStatic() } else { - statusLabel->setText(tr("Unknown Peer")); - titleLabel->setText(tr("Unknown Peer")); - trustLabel->setText(tr("Unknown Peer")); - nameLabel->setText(tr("Unknown Peer")); - idLabel->setText(tr("Unknown Peer")); - locLabel->setText(tr("Unknown Peer")); - ipLabel->setText(tr("Unknown Peer")); - connLabel->setText(tr("Unknown Peer")); - lastLabel->setText(tr("Unknown Peer")); + peerNameLabel->setText(tr("Unknown peer")); + statusLabel->setText(tr("Unknown")); + titleLabel->setText(tr("Unknown peer")); + trustLabel->setText(tr("Unknown")); + nameLabel->setText(tr("Unknown")); + idLabel->setText(tr("Unknown")); + locLabel->setText(tr("Unknown")); + ipLabel->setText(tr("Unknown")); + connLabel->setText(tr("Unknown")); + lastLabel->setText(tr("Unknown")); chatButton->setEnabled(false); } diff --git a/retroshare-gui/src/gui/msgs/MessageComposer.cpp b/retroshare-gui/src/gui/msgs/MessageComposer.cpp index 8f485b410..52da5b10f 100644 --- a/retroshare-gui/src/gui/msgs/MessageComposer.cpp +++ b/retroshare-gui/src/gui/msgs/MessageComposer.cpp @@ -584,16 +584,18 @@ void MessageComposer::recommendFriend(const std::set &sslIds, const R /* window will destroy itself! */ } -void MessageComposer::sendConnectAttemptMsg(const RsPgpId &gpgId, const RsPeerId &sslId, const QString &/*sslName*/) +void MessageComposer::addConnectAttemptMsg(const RsPgpId &gpgId, const RsPeerId &sslId, const QString &/*sslName*/) { - if (gpgId.isNull()) { + if (gpgId.isNull()) return; - } - RetroShareLink link = RetroShareLink::createUnknwonSslCertificate(sslId, gpgId); - if (link.valid() == false) { + // PGPId+SslId are always here. But if the peer is not a friend the SSL id cannot be used. + // (todo) If the PGP id doesn't get us a PGP key from the keyring, we need to create a short invite + + RetroShareLink link = RetroShareLink::createUnknownSslCertificate(sslId); + + if (!link.valid()) return; - } QString title = QString("%1 %2").arg(link.name(), tr("wants to be friends with you on RetroShare")); diff --git a/retroshare-gui/src/gui/msgs/MessageComposer.h b/retroshare-gui/src/gui/msgs/MessageComposer.h index 1b0b2f2c5..7c2b4e13d 100644 --- a/retroshare-gui/src/gui/msgs/MessageComposer.h +++ b/retroshare-gui/src/gui/msgs/MessageComposer.h @@ -62,7 +62,7 @@ public: static QString recommendMessage(); static void recommendFriend(const std::set &sslIds, const RsPeerId &to = RsPeerId(), const QString &msg = "", bool autoSend = false); - static void sendConnectAttemptMsg(const RsPgpId &gpgId, const RsPeerId &sslId, const QString &sslName); + static void addConnectAttemptMsg(const RsPgpId &gpgId, const RsPeerId &sslId, const QString &sslName); static void sendInvite(const RsGxsId &to, bool autoSend); #ifdef UNUSED_CODE static void sendChannelPublishKey(RsGxsChannelGroup &group); From fcbecbaa16dfd0871e7071cad29f08aa98756b50 Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 3 Dec 2019 21:28:44 +0100 Subject: [PATCH 04/39] fixed errors reported by review of PR1735 --- libretroshare/src/pqi/p3linkmgr.cc | 6 ++-- libretroshare/src/retroshare/rsevents.h | 6 ++-- retroshare-gui/src/gui/NewsFeed.cpp | 38 ++++++++++++++----------- retroshare-gui/src/gui/NewsFeed.h | 4 +-- 4 files changed, 29 insertions(+), 25 deletions(-) diff --git a/libretroshare/src/pqi/p3linkmgr.cc b/libretroshare/src/pqi/p3linkmgr.cc index a9554f43c..a84090860 100644 --- a/libretroshare/src/pqi/p3linkmgr.cc +++ b/libretroshare/src/pqi/p3linkmgr.cc @@ -481,7 +481,7 @@ void p3LinkMgrIMPL::tickMonitors() { auto e = std::make_shared() ; - e->mType = RsConnectionEvent::PEER_CONNECTED; + e->mConnectionType = RsConnectionEvent::PEER_CONNECTED; e->mSslId = peer.id; rsEvents->postEvent(e); @@ -494,11 +494,9 @@ void p3LinkMgrIMPL::tickMonitors() } if (peer.actions & RS_PEER_DISCONNECTED) { - p3Notify *notify = RsServer::notify(); - auto e = std::make_shared() ; - e->mType = RsConnectionEvent::PEER_DISCONNECTED; + e->mConnectionType = RsConnectionEvent::PEER_DISCONNECTED; e->mSslId = peer.id; rsEvents->postEvent(e); diff --git a/libretroshare/src/retroshare/rsevents.h b/libretroshare/src/retroshare/rsevents.h index aa366e7bf..8bf2a6fe2 100644 --- a/libretroshare/src/retroshare/rsevents.h +++ b/libretroshare/src/retroshare/rsevents.h @@ -221,7 +221,7 @@ struct RsConnectionEvent : RsEvent { RsConnectionEvent() : RsEvent(RsEventType::PEER_CONNECTION), - mType(UNKNOWN) {} + mConnectionType(UNKNOWN) {} enum ConnectionType: uint8_t { UNKNOWN = 0x00, @@ -230,14 +230,14 @@ struct RsConnectionEvent : RsEvent PEER_REFUSED_CONNECTION = 0x03, }; - ConnectionType mType; + ConnectionType mConnectionType; RsPeerId mSslId; ///* @see RsEvent @see RsSerializable void serial_process( RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) override { RsEvent::serial_process(j, ctx); - RS_SERIAL_PROCESS(mType); + RS_SERIAL_PROCESS(mConnectionType); RS_SERIAL_PROCESS(mSslId); } }; diff --git a/retroshare-gui/src/gui/NewsFeed.cpp b/retroshare-gui/src/gui/NewsFeed.cpp index ee0bc1eb8..20482a8f1 100644 --- a/retroshare-gui/src/gui/NewsFeed.cpp +++ b/retroshare-gui/src/gui/NewsFeed.cpp @@ -75,6 +75,7 @@ NewsFeed::NewsFeed(QWidget *parent) : RsAutoUpdatePage(1000,parent), ui(new Ui::NewsFeed) { + mEventHandlerId =0; // needed to force intialization by registerEventsHandler() rsEvents->registerEventsHandler( [this](std::shared_ptr event) { handleEvent(event); }, mEventHandlerId ); /* Invoke the Qt Designer generated object setup routine */ @@ -187,32 +188,30 @@ void NewsFeed::handleEvent(std::shared_ptr event) { uint flags = Settings->getNewsFeedFlags(); - const RsAuthSslConnectionAutenticationEvent *pssl_e = dynamic_cast(event.get()); - - if(pssl_e != nullptr && (flags & RS_FEED_TYPE_SECURITY)) + if(event->mType == RsEventType::AUTHSSL_CONNECTION_AUTENTICATION && (flags & RS_FEED_TYPE_SECURITY)) { - auto e = *pssl_e; // make a copy because we lose memory ownership here - - RsQThreadUtils::postToObject( [=]() { handleSecurityEvent(e); }, this ); + RsQThreadUtils::postToObject( [=]() { handleSecurityEvent(event); }, this ); return; } - const RsConnectionEvent *conn_e = dynamic_cast(event.get()); - - if(conn_e != nullptr && (flags & RS_FEED_TYPE_PEER)) + if(event->mType == RsEventType::PEER_STATE_CHANGED && (flags & RS_FEED_TYPE_PEER)) { - auto e = *conn_e; - - RsQThreadUtils::postToObject( [=]() { handleConnectionEvent(e); }, this ); + RsQThreadUtils::postToObject( [=]() { handleConnectionEvent(event); }, this ); return; } } -void NewsFeed::handleConnectionEvent(const RsConnectionEvent& e) +void NewsFeed::handleConnectionEvent(std::shared_ptr event) { + const RsConnectionEvent *pe = dynamic_cast(event.get()); + if(!pe) + return; + + auto& e(*pe); + std::cerr << "NotifyQt: handling connection event from peer " << e.mSslId << std::endl; - switch(e.mType) + switch(e.mConnectionType) { case RsConnectionEvent::PEER_CONNECTED: addFeedItemIfUnique(new PeerItem(this, NEWSFEED_PEERLIST, e.mSslId, PEER_TYPE_CONNECT, false), @@ -250,8 +249,15 @@ void NewsFeed::handleConnectionEvent(const RsConnectionEvent& e) } } -void NewsFeed::handleSecurityEvent(const RsAuthSslConnectionAutenticationEvent& e) +void NewsFeed::handleSecurityEvent(std::shared_ptr event) { + const RsAuthSslConnectionAutenticationEvent *pe = dynamic_cast(event.get()); + + if(!pe) + return; + + auto& e(*pe); + std::cerr << "NotifyQt: handling security event from (" << e.mSslId << "," << e.mPgpId << ") error code: " << e.mErrorCode << std::endl; uint flags = Settings->getNewsFeedFlags(); @@ -280,7 +286,7 @@ void NewsFeed::handleSecurityEvent(const RsAuthSslConnectionAutenticationEvent& det.location, e.mLocator.toString(), FeedItemType, - false), + true), FeedItemType, e.mSslId.toStdString(), std::string(), diff --git a/retroshare-gui/src/gui/NewsFeed.h b/retroshare-gui/src/gui/NewsFeed.h index 9bc8e0afe..c7e50e47d 100644 --- a/retroshare-gui/src/gui/NewsFeed.h +++ b/retroshare-gui/src/gui/NewsFeed.h @@ -102,8 +102,8 @@ private slots: void sendNewsFeedChanged(); private: - void handleSecurityEvent(const RsAuthSslConnectionAutenticationEvent& e); - void handleConnectionEvent(const RsConnectionEvent& e); + void handleSecurityEvent(std::shared_ptr event); + void handleConnectionEvent(std::shared_ptr event); void addFeedItem(FeedItem *item); void addFeedItemIfUnique(FeedItem *item, int itemType, const std::string& id1, const std::string& id2, const std::string& id3, const std::string& id4, bool replace); From b85be7cc8e9b09c5a2e9b8d6a5db83189d3637f6 Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 3 Dec 2019 22:30:13 +0100 Subject: [PATCH 05/39] simplified the addIfUnique mechanism in NewsFeed by using a data-based identifier for items --- retroshare-gui/src/gui/NewsFeed.cpp | 146 +++--------------- retroshare-gui/src/gui/NewsFeed.h | 4 +- retroshare-gui/src/gui/Posted/PostedItem.h | 1 + .../src/gui/common/RSFeedWidget.cpp | 12 +- retroshare-gui/src/gui/common/RSFeedWidget.h | 2 +- retroshare-gui/src/gui/feeds/ChatMsgItem.h | 1 + retroshare-gui/src/gui/feeds/FeedItem.h | 6 + .../src/gui/feeds/GxsChannelGroupItem.h | 1 + .../src/gui/feeds/GxsChannelPostItem.h | 2 + .../src/gui/feeds/GxsCircleItem.cpp | 9 +- retroshare-gui/src/gui/feeds/GxsCircleItem.h | 3 +- .../src/gui/feeds/GxsForumGroupItem.h | 1 + .../src/gui/feeds/GxsForumMsgItem.h | 1 + retroshare-gui/src/gui/feeds/MsgItem.h | 1 + retroshare-gui/src/gui/feeds/PeerItem.cpp | 10 +- retroshare-gui/src/gui/feeds/PeerItem.h | 2 +- .../src/gui/feeds/PostedGroupItem.h | 2 + .../src/gui/feeds/SecurityIpItem.cpp | 9 +- retroshare-gui/src/gui/feeds/SecurityIpItem.h | 2 +- retroshare-gui/src/gui/feeds/SecurityItem.cpp | 10 +- retroshare-gui/src/gui/feeds/SecurityItem.h | 2 +- 21 files changed, 62 insertions(+), 165 deletions(-) diff --git a/retroshare-gui/src/gui/NewsFeed.cpp b/retroshare-gui/src/gui/NewsFeed.cpp index 20482a8f1..cb7f9737d 100644 --- a/retroshare-gui/src/gui/NewsFeed.cpp +++ b/retroshare-gui/src/gui/NewsFeed.cpp @@ -213,15 +213,8 @@ void NewsFeed::handleConnectionEvent(std::shared_ptr event) switch(e.mConnectionType) { - case RsConnectionEvent::PEER_CONNECTED: - addFeedItemIfUnique(new PeerItem(this, NEWSFEED_PEERLIST, e.mSslId, PEER_TYPE_CONNECT, false), - PEER_TYPE_CONNECT, - e.mSslId.toStdString(), - std::string(), - std::string(), - std::string(), - true); - break; + case RsConnectionEvent::PEER_CONNECTED: addFeedItemIfUnique(new PeerItem(this, NEWSFEED_PEERLIST, e.mSslId, PEER_TYPE_CONNECT, false), true); + break; case RsConnectionEvent::PEER_DISCONNECTED: break;// not handled yet case RsConnectionEvent::PEER_REFUSED_CONNECTION: @@ -230,20 +223,9 @@ void NewsFeed::handleConnectionEvent(std::shared_ptr event) if(!rsPeers->getPeerDetails(e.mSslId,det)) return; - addFeedItemIfUnique(new SecurityItem(this, - NEWSFEED_SECLIST, - det.gpg_id, e.mSslId, - det.location, - std::string(), - RS_FEED_ITEM_SEC_AUTH_DENIED, - false), - RS_FEED_ITEM_SEC_AUTH_DENIED, - e.mSslId.toStdString(), - std::string(), - std::string(), - std::string(), - true ); - } break; + addFeedItemIfUnique(new SecurityItem(this, NEWSFEED_SECLIST, det.gpg_id, e.mSslId, det.location, std::string(), RS_FEED_ITEM_SEC_AUTH_DENIED, false), true ); + } + break; default: break; } @@ -280,19 +262,7 @@ void NewsFeed::handleSecurityEvent(std::shared_ptr event) RsPeerDetails det; rsPeers->getPeerDetails(e.mSslId,det) || rsPeers->getGPGDetails(e.mPgpId,det); - addFeedItemIfUnique(new SecurityItem(this, - NEWSFEED_SECLIST, - det.gpg_id, det.id, - det.location, - e.mLocator.toString(), - FeedItemType, - true), - FeedItemType, - e.mSslId.toStdString(), - std::string(), - std::string(), - std::string(), - true ); + addFeedItemIfUnique(new SecurityItem(this, NEWSFEED_SECLIST, det.gpg_id, det.id, det.location, e.mLocator.toString(), FeedItemType, true), true ); if (Settings->getMessageFlags() & RS_MESSAGE_CONNECT_ATTEMPT) MessageComposer::addConnectAttemptMsg(e.mPgpId, e.mSslId, QString::fromStdString(det.name + "(" + det.location + ")")); @@ -1146,80 +1116,14 @@ void NewsFeed::addFeedItem(FeedItem *item) ui->feedWidget->addFeedItem(item, ROLE_RECEIVED, QDateTime::currentDateTime()); } -struct AddFeedItemIfUniqueData +void NewsFeed::addFeedItemIfUnique(FeedItem *item, bool replace) { - AddFeedItemIfUniqueData(FeedItem *feedItem, int type - , const std::string& id1, const std::string& id2 - , const std::string& id3, const std::string& id4) - : mType(type), mId1(id1), mId2(id2), mId3(id3), mId4(id4) - { - mGxsCircleItem = dynamic_cast(feedItem); - mPeerItem = dynamic_cast(feedItem); - mSecItem = dynamic_cast(feedItem); - mSecurityIpItem = dynamic_cast(feedItem); - } + FeedItem *feedItem = ui->feedWidget->findFeedItem(item->uniqueIdentifier()); - int mType; - const std::string& mId1; - const std::string& mId2; - const std::string& mId3; - const std::string& mId4; - - GxsCircleItem *mGxsCircleItem; - PeerItem *mPeerItem; - SecurityItem *mSecItem; - SecurityIpItem *mSecurityIpItem; -}; - -static bool addFeedItemIfUniqueCallback(FeedItem *feedItem, void *data) -{ - AddFeedItemIfUniqueData *findData = (AddFeedItemIfUniqueData*) data; - if (!findData || findData->mId1.empty()) { - return false; - } - - if (findData->mGxsCircleItem) { - GxsCircleItem *gxsCircleItem = dynamic_cast(feedItem); - if (gxsCircleItem && gxsCircleItem->isSame(RsGxsCircleId(findData->mId1), RsGxsId(findData->mId2), findData->mType)) { - return true; - } - return false; - } - - if (findData->mPeerItem) { - PeerItem *peerItem = dynamic_cast(feedItem); - if (peerItem && peerItem->isSame(RsPeerId(findData->mId1), findData->mType)) { - return true; - } - return false; - } - - if (findData->mSecItem) { - SecurityItem *secitem = dynamic_cast(feedItem); - if (secitem && secitem->isSame(RsPeerId(findData->mId1), findData->mType)) { - return true; - } - return false; - } - - if (findData->mSecurityIpItem) { - SecurityIpItem *securityIpItem = dynamic_cast(feedItem); - if (securityIpItem && securityIpItem->isSame(RsPeerId(findData->mId1), findData->mId2, findData->mId3, findData->mType)) { - return true; - } - return false; - } - - return false; -} - -void NewsFeed::addFeedItemIfUnique(FeedItem *item, int itemType, const std::string& id1, const std::string& id2, const std::string& id3, const std::string& id4, bool replace) -{ - AddFeedItemIfUniqueData data(item, itemType, id1, id2, id3, id4); - FeedItem *feedItem = ui->feedWidget->findFeedItem(addFeedItemIfUniqueCallback, &data); - - if (feedItem) { - if (!replace) { + if (feedItem) + { + if (!replace) + { delete item; return; } @@ -1230,12 +1134,12 @@ void NewsFeed::addFeedItemIfUnique(FeedItem *item, int itemType, const std::stri addFeedItem(item); } -void NewsFeed::remUniqueFeedItem(FeedItem *item, int itemType, const std::string &id1, const std::string &id2, const std::string &id3, const std::string &id4) +void NewsFeed::remUniqueFeedItem(FeedItem *item) { - AddFeedItemIfUniqueData data(item, itemType, id1, id2, id3, id4); - FeedItem *feedItem = ui->feedWidget->findFeedItem(addFeedItemIfUniqueCallback, &data); + FeedItem *feedItem = ui->feedWidget->findFeedItem(item->uniqueIdentifier()); - if (feedItem) { + if (feedItem) + { delete item; ui->feedWidget->removeFeedItem(feedItem); @@ -1304,7 +1208,7 @@ void NewsFeed::addFeedItemPeerOffset(const RsFeedItem &fi) PeerItem *pi = new PeerItem(this, NEWSFEED_PEERLIST, RsPeerId(fi.mId1), PEER_TYPE_OFFSET, false); /* add to layout */ - addFeedItemIfUnique(pi, PEER_TYPE_OFFSET, fi.mId1, fi.mId2, fi.mId3, fi.mId4, false); + addFeedItemIfUnique(pi, false); #ifdef NEWS_DEBUG std::cerr << "NewsFeed::addFeedItemPeerOffset()"; @@ -1318,7 +1222,7 @@ void NewsFeed::addFeedItemSecurityConnectAttempt(const RsFeedItem &fi) SecurityItem *pi = new SecurityItem(this, NEWSFEED_SECLIST, RsPgpId(fi.mId1), RsPeerId(fi.mId2), fi.mId3, fi.mId4, fi.mType, false); /* add to layout */ - addFeedItemIfUnique(pi, fi.mType, fi.mId2, "", "", "", false); + addFeedItemIfUnique(pi, false); #ifdef NEWS_DEBUG std::cerr << "NewsFeed::addFeedItemSecurityConnectAttempt()"; @@ -1332,7 +1236,7 @@ void NewsFeed::addFeedItemSecurityAuthDenied(const RsFeedItem &fi) SecurityItem *pi = new SecurityItem(this, NEWSFEED_SECLIST, RsPgpId(fi.mId1), RsPeerId(fi.mId2), fi.mId3, fi.mId4, fi.mType, false); /* add to layout */ - addFeedItemIfUnique(pi, RS_FEED_ITEM_SEC_AUTH_DENIED, fi.mId2, "", "", "", false); + addFeedItemIfUnique(pi, false); #ifdef NEWS_DEBUG std::cerr << "NewsFeed::addFeedItemSecurityAuthDenied()"; @@ -1346,7 +1250,7 @@ void NewsFeed::addFeedItemSecurityUnknownIn(const RsFeedItem &fi) SecurityItem *pi = new SecurityItem(this, NEWSFEED_SECLIST, RsPgpId(fi.mId1), RsPeerId(fi.mId2), fi.mId3, fi.mId4, RS_FEED_ITEM_SEC_UNKNOWN_IN, false); /* add to layout */ - addFeedItemIfUnique(pi, RS_FEED_ITEM_SEC_UNKNOWN_IN, fi.mId2, "", "", "", false); + addFeedItemIfUnique(pi, false); #ifdef NEWS_DEBUG std::cerr << "NewsFeed::addFeedItemSecurityUnknownIn()"; @@ -1360,7 +1264,7 @@ void NewsFeed::addFeedItemSecurityUnknownOut(const RsFeedItem &fi) SecurityItem *pi = new SecurityItem(this, NEWSFEED_SECLIST, RsPgpId(fi.mId1), RsPeerId(fi.mId2), fi.mId3, fi.mId4, RS_FEED_ITEM_SEC_UNKNOWN_OUT, false); /* add to layout */ - addFeedItemIfUnique(pi, RS_FEED_ITEM_SEC_UNKNOWN_OUT, fi.mId2, "", "", "", false); + addFeedItemIfUnique(pi, false); #ifdef NEWS_DEBUG std::cerr << "NewsFeed::addFeedItemSecurityUnknownOut()"; @@ -1374,7 +1278,7 @@ void NewsFeed::addFeedItemSecurityIpBlacklisted(const RsFeedItem &fi, bool isTes SecurityIpItem *pi = new SecurityIpItem(this, RsPeerId(fi.mId1), fi.mId2, fi.mResult1, RS_FEED_ITEM_SEC_IP_BLACKLISTED, isTest); /* add to layout */ - addFeedItemIfUnique(pi, RS_FEED_ITEM_SEC_IP_BLACKLISTED, fi.mId1, fi.mId2, fi.mId3, fi.mId4, false); + addFeedItemIfUnique(pi, false); #ifdef NEWS_DEBUG std::cerr << "NewsFeed::addFeedItemSecurityIpBlacklisted()"; @@ -1388,7 +1292,7 @@ void NewsFeed::addFeedItemSecurityWrongExternalIpReported(const RsFeedItem &fi, SecurityIpItem *pi = new SecurityIpItem(this, RsPeerId(fi.mId1), fi.mId2, fi.mId3, RS_FEED_ITEM_SEC_IP_WRONG_EXTERNAL_IP_REPORTED, isTest); /* add to layout */ - addFeedItemIfUnique(pi, RS_FEED_ITEM_SEC_IP_WRONG_EXTERNAL_IP_REPORTED, fi.mId1, fi.mId2, fi.mId3, fi.mId4, false); + addFeedItemIfUnique(pi, false); #ifdef NEWS_DEBUG std::cerr << "NewsFeed::addFeedItemSecurityWrongExternalIpReported()"; @@ -1656,7 +1560,7 @@ void NewsFeed::addFeedItemCircleMembReq(const RsFeedItem &fi) GxsCircleItem *item = new GxsCircleItem(this, NEWSFEED_CIRCLELIST, circleId, gxsId, RS_FEED_ITEM_CIRCLE_MEMB_REQ); /* add to layout */ - addFeedItemIfUnique(item, RS_FEED_ITEM_CIRCLE_MEMB_REQ, fi.mId1, fi.mId2, fi.mId3, fi.mId4, false); + addFeedItemIfUnique(item, false); #ifdef NEWS_DEBUG std::cerr << "NewsFeed::addFeedItemCircleMembReq()" << std::endl; @@ -1676,7 +1580,7 @@ void NewsFeed::remFeedItemCircleMembReq(const RsFeedItem &fi) GxsCircleItem *item = new GxsCircleItem(this, NEWSFEED_CIRCLELIST, circleId, gxsId, RS_FEED_ITEM_CIRCLE_MEMB_REQ); /* add to layout */ - remUniqueFeedItem(item, RS_FEED_ITEM_CIRCLE_MEMB_REQ, fi.mId1, fi.mId2, fi.mId3, fi.mId4); + remUniqueFeedItem(item); #ifdef NEWS_DEBUG std::cerr << "NewsFeed::remFeedItemCircleMembReq()" << std::endl; diff --git a/retroshare-gui/src/gui/NewsFeed.h b/retroshare-gui/src/gui/NewsFeed.h index c7e50e47d..747e86cea 100644 --- a/retroshare-gui/src/gui/NewsFeed.h +++ b/retroshare-gui/src/gui/NewsFeed.h @@ -106,8 +106,8 @@ private: void handleConnectionEvent(std::shared_ptr event); void addFeedItem(FeedItem *item); - void addFeedItemIfUnique(FeedItem *item, int itemType, const std::string& id1, const std::string& id2, const std::string& id3, const std::string& id4, bool replace); - void remUniqueFeedItem(FeedItem *item, int itemType, const std::string& id1, const std::string& id2, const std::string& id3, const std::string& id4); + void addFeedItemIfUnique(FeedItem *item, bool replace); + void remUniqueFeedItem(FeedItem *item); void addFeedItemPeerConnect(const RsFeedItem &fi); void addFeedItemPeerDisconnect(const RsFeedItem &fi); diff --git a/retroshare-gui/src/gui/Posted/PostedItem.h b/retroshare-gui/src/gui/Posted/PostedItem.h index 333018dee..ba8c04492 100644 --- a/retroshare-gui/src/gui/Posted/PostedItem.h +++ b/retroshare-gui/src/gui/Posted/PostedItem.h @@ -49,6 +49,7 @@ public: const RsPostedPost &getPost() const; RsPostedPost &post(); + QString uniqueIdentifier() const override { return "PostedItem " + QString::fromStdString(mMessageId.toStdString()); } protected: /* FeedItem */ virtual void doExpand(bool open); diff --git a/retroshare-gui/src/gui/common/RSFeedWidget.cpp b/retroshare-gui/src/gui/common/RSFeedWidget.cpp index 264eda7e8..8d853b55d 100644 --- a/retroshare-gui/src/gui/common/RSFeedWidget.cpp +++ b/retroshare-gui/src/gui/common/RSFeedWidget.cpp @@ -476,14 +476,13 @@ void RSFeedWidget::withAll(RSFeedWidgetCallbackFunction callback, void *data) } } -FeedItem *RSFeedWidget::findFeedItem(RSFeedWidgetFindCallbackFunction callback, void *data) +FeedItem *RSFeedWidget::findFeedItem(const QString& identifier) { - if (!callback) { - return NULL; - } - QTreeWidgetItemIterator it(ui->treeWidget); QTreeWidgetItem *treeItem; + + // this search could probably be automatised by giving the tree items the identifier as data for some specific role, then calling QTreeWidget::findItems() +#warning TODO while ((treeItem = *it) != NULL) { ++it; @@ -492,9 +491,8 @@ FeedItem *RSFeedWidget::findFeedItem(RSFeedWidgetFindCallbackFunction callback, continue; } - if (callback(feedItem, data)) { + if (feedItem->uniqueIdentifier() == identifier) return feedItem; - } } return NULL; diff --git a/retroshare-gui/src/gui/common/RSFeedWidget.h b/retroshare-gui/src/gui/common/RSFeedWidget.h index b440c0850..b83b9814a 100644 --- a/retroshare-gui/src/gui/common/RSFeedWidget.h +++ b/retroshare-gui/src/gui/common/RSFeedWidget.h @@ -71,7 +71,7 @@ public: bool scrollTo(FeedItem *feedItem, bool focus); void withAll(RSFeedWidgetCallbackFunction callback, void *data); - FeedItem *findFeedItem(RSFeedWidgetFindCallbackFunction callback, void *data); + FeedItem *findFeedItem(const QString &identifier); void selectedFeedItems(QList &feedItems); diff --git a/retroshare-gui/src/gui/feeds/ChatMsgItem.h b/retroshare-gui/src/gui/feeds/ChatMsgItem.h index bdfc343fe..4222fb23c 100644 --- a/retroshare-gui/src/gui/feeds/ChatMsgItem.h +++ b/retroshare-gui/src/gui/feeds/ChatMsgItem.h @@ -37,6 +37,7 @@ public: void updateItemStatic(); + virtual QString uniqueIdentifier() const override { return "ChatMsgItem " + QString::fromStdString(mPeerId.toStdString()) ;} protected: /* FeedItem */ virtual void doExpand(bool /*open*/) {} diff --git a/retroshare-gui/src/gui/feeds/FeedItem.h b/retroshare-gui/src/gui/feeds/FeedItem.h index 04adc9381..f7128e737 100644 --- a/retroshare-gui/src/gui/feeds/FeedItem.h +++ b/retroshare-gui/src/gui/feeds/FeedItem.h @@ -36,6 +36,12 @@ public: bool wasExpanded() { return mWasExpanded; } void expand(bool open); + /*! + * \brief uniqueIdentifier + * \return returns a string that is unique to this specific item. The string will be used to search for an existing item that + * would contain the same information. It should therefore sumarise the data represented by the item. + */ + virtual QString uniqueIdentifier() const =0; protected: virtual void doExpand(bool open) = 0; virtual void expandFill(bool /*first*/) {} diff --git a/retroshare-gui/src/gui/feeds/GxsChannelGroupItem.h b/retroshare-gui/src/gui/feeds/GxsChannelGroupItem.h index 5a307d522..273f50d39 100644 --- a/retroshare-gui/src/gui/feeds/GxsChannelGroupItem.h +++ b/retroshare-gui/src/gui/feeds/GxsChannelGroupItem.h @@ -42,6 +42,7 @@ public: bool setGroup(const RsGxsChannelGroup &group); + QString uniqueIdentifier() const override { return "GxsChannelGroupItem " + QString::fromStdString(mGroup.mMeta.mGroupId.toStdString()) ; } protected: /* FeedItem */ virtual void doExpand(bool open); diff --git a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.h b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.h index 8f045c2d9..366637c0b 100644 --- a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.h +++ b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.h @@ -53,6 +53,8 @@ public: //GxsChannelPostItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsChannelPost &post, bool isHome, bool autoUpdate); virtual ~GxsChannelPostItem(); + virtual QString uniqueIdentifier() const override { "GxsChannelPostItem " + QString::fromStdString(mPost.mMeta.mMsgId.toStdString()) ; } + bool setGroup(const RsGxsChannelGroup &group, bool doFill = true); bool setPost(const RsGxsChannelPost &post, bool doFill = true); diff --git a/retroshare-gui/src/gui/feeds/GxsCircleItem.cpp b/retroshare-gui/src/gui/feeds/GxsCircleItem.cpp index 8fe52b6b4..8cd67d28f 100644 --- a/retroshare-gui/src/gui/feeds/GxsCircleItem.cpp +++ b/retroshare-gui/src/gui/feeds/GxsCircleItem.cpp @@ -125,14 +125,9 @@ void GxsCircleItem::setup() } -bool GxsCircleItem::isSame(const RsGxsCircleId &circleId, const RsGxsId &gxsId, uint32_t type) +QString GxsCircleItem::uniqueIdentifier() const { - if ((mCircleId == circleId) && (mGxsId == gxsId) && (mType == type)) - { - return true; - } - return false; - + return "GxsCircle " + QString::fromStdString(mCircleId.toStdString()) + " " + QString::fromStdString(mGxsId.toStdString()) + " " + QString::number(mType); } void GxsCircleItem::removeItem() diff --git a/retroshare-gui/src/gui/feeds/GxsCircleItem.h b/retroshare-gui/src/gui/feeds/GxsCircleItem.h index a08adb8c1..7aeb457ca 100644 --- a/retroshare-gui/src/gui/feeds/GxsCircleItem.h +++ b/retroshare-gui/src/gui/feeds/GxsCircleItem.h @@ -52,8 +52,7 @@ public: GxsCircleItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsCircleId &circleId, const RsGxsId &gxsId, const uint32_t type); virtual ~GxsCircleItem(); - bool isSame(const RsGxsCircleId &circleId, const RsGxsId &gxsId, uint32_t type); - + QString uniqueIdentifier() const override; void loadRequest(const TokenQueue *queue, const TokenRequest &req); diff --git a/retroshare-gui/src/gui/feeds/GxsForumGroupItem.h b/retroshare-gui/src/gui/feeds/GxsForumGroupItem.h index 19e438b69..76587ad9c 100644 --- a/retroshare-gui/src/gui/feeds/GxsForumGroupItem.h +++ b/retroshare-gui/src/gui/feeds/GxsForumGroupItem.h @@ -42,6 +42,7 @@ public: bool setGroup(const RsGxsForumGroup &group); + virtual QString uniqueIdentifier() const override { return "GxsForumGroupItem " + QString::fromStdString(mGroup.mMeta.mGroupId.toStdString()) ; } protected: /* FeedItem */ virtual void doExpand(bool open); diff --git a/retroshare-gui/src/gui/feeds/GxsForumMsgItem.h b/retroshare-gui/src/gui/feeds/GxsForumMsgItem.h index ff152f92b..b241fa594 100644 --- a/retroshare-gui/src/gui/feeds/GxsForumMsgItem.h +++ b/retroshare-gui/src/gui/feeds/GxsForumMsgItem.h @@ -43,6 +43,7 @@ public: bool setGroup(const RsGxsForumGroup &group, bool doFill = true); bool setMessage(const RsGxsForumMsg &msg, bool doFill = true); + QString uniqueIdentifier() const override { return "GxsForumMsgItem " + QString::fromStdString(mMessage.mMeta.mMsgId.toStdString()) ; } protected: /* FeedItem */ virtual void doExpand(bool open); diff --git a/retroshare-gui/src/gui/feeds/MsgItem.h b/retroshare-gui/src/gui/feeds/MsgItem.h index 6aa595767..5fe0d0485 100644 --- a/retroshare-gui/src/gui/feeds/MsgItem.h +++ b/retroshare-gui/src/gui/feeds/MsgItem.h @@ -38,6 +38,7 @@ public: void updateItemStatic(); + virtual QString uniqueIdentifier() const override { return "MsgItem " + QString::fromStdString(mMsgId) ; } protected: /* FeedItem */ virtual void doExpand(bool open); diff --git a/retroshare-gui/src/gui/feeds/PeerItem.cpp b/retroshare-gui/src/gui/feeds/PeerItem.cpp index 9a6f2cd2e..f51b42f30 100644 --- a/retroshare-gui/src/gui/feeds/PeerItem.cpp +++ b/retroshare-gui/src/gui/feeds/PeerItem.cpp @@ -67,17 +67,11 @@ PeerItem::PeerItem(FeedHolder *parent, uint32_t feedId, const RsPeerId &peerId, updateItem(); } - -bool PeerItem::isSame(const RsPeerId &peerId, uint32_t type) +QString PeerItem::uniqueIdentifier() const { - if ((mPeerId == peerId) && (mType == type)) - { - return true; - } - return false; + return "PeerItem " + QString::fromStdString(mPeerId.toStdString()) + " " + QString::number(mType) ; } - void PeerItem::updateItemStatic() { if (!rsPeers) diff --git a/retroshare-gui/src/gui/feeds/PeerItem.h b/retroshare-gui/src/gui/feeds/PeerItem.h index d048ff8d5..40b7d384b 100644 --- a/retroshare-gui/src/gui/feeds/PeerItem.h +++ b/retroshare-gui/src/gui/feeds/PeerItem.h @@ -43,7 +43,7 @@ public: void updateItemStatic(); - bool isSame(const RsPeerId &peerId, uint32_t type); + virtual QString uniqueIdentifier() const; protected: /* FeedItem */ diff --git a/retroshare-gui/src/gui/feeds/PostedGroupItem.h b/retroshare-gui/src/gui/feeds/PostedGroupItem.h index 3b66afbcb..2994971fd 100644 --- a/retroshare-gui/src/gui/feeds/PostedGroupItem.h +++ b/retroshare-gui/src/gui/feeds/PostedGroupItem.h @@ -42,6 +42,8 @@ public: bool setGroup(const RsPostedGroup &group); + virtual QString uniqueIdentifier() const override { return "PostedGroupItem " + QString::fromStdString(mGroup.mMeta.mGroupId.toStdString()) ; } + protected: /* FeedItem */ virtual void doExpand(bool open); diff --git a/retroshare-gui/src/gui/feeds/SecurityIpItem.cpp b/retroshare-gui/src/gui/feeds/SecurityIpItem.cpp index a6a5d2d50..e7d7de5d9 100644 --- a/retroshare-gui/src/gui/feeds/SecurityIpItem.cpp +++ b/retroshare-gui/src/gui/feeds/SecurityIpItem.cpp @@ -78,13 +78,10 @@ void SecurityIpItem::setup() updateItem(); } -bool SecurityIpItem::isSame(const RsPeerId &sslId, const std::string& ipAddr, const std::string& ipAddrReported, uint32_t type) +QString SecurityIpItem::uniqueIdentifier() const { - if (mType == type && mSslId==sslId && mIpAddr == ipAddr && mIpAddrReported == ipAddrReported) { - return true; - } - - return false; + return "SecurityItem " + QString::number(mType) + " " + QString::fromStdString(mSslId.toStdString()) + + " " + QString::fromStdString(mIpAddr) + " " + QString::fromStdString(mIpAddrReported) ; } void SecurityIpItem::updateItemStatic() diff --git a/retroshare-gui/src/gui/feeds/SecurityIpItem.h b/retroshare-gui/src/gui/feeds/SecurityIpItem.h index 2dc9dc0ca..f7002ffb7 100644 --- a/retroshare-gui/src/gui/feeds/SecurityIpItem.h +++ b/retroshare-gui/src/gui/feeds/SecurityIpItem.h @@ -43,7 +43,7 @@ public: void updateItemStatic(); - bool isSame(const RsPeerId &sslId, const std::string& ipAddr, const std::string& ipAddrReported, uint32_t type); + QString uniqueIdentifier() const override; protected: /* FeedItem */ diff --git a/retroshare-gui/src/gui/feeds/SecurityItem.cpp b/retroshare-gui/src/gui/feeds/SecurityItem.cpp index 722296ae5..b14853ae2 100644 --- a/retroshare-gui/src/gui/feeds/SecurityItem.cpp +++ b/retroshare-gui/src/gui/feeds/SecurityItem.cpp @@ -81,17 +81,11 @@ SecurityItem::SecurityItem(FeedHolder *parent, uint32_t feedId, const RsPgpId &g updateItem(); } - -bool SecurityItem::isSame(const RsPeerId &sslId, uint32_t type) +QString SecurityItem::uniqueIdentifier() const { - if ((mSslId == sslId) && (mType == type)) - { - return true; - } - return false; + return "SecurityItem " + QString::number(mType) + " " + QString::fromStdString(mSslId.toStdString()); } - void SecurityItem::updateItemStatic() { if (!rsPeers) diff --git a/retroshare-gui/src/gui/feeds/SecurityItem.h b/retroshare-gui/src/gui/feeds/SecurityItem.h index 2af4af4a1..bc508edfc 100644 --- a/retroshare-gui/src/gui/feeds/SecurityItem.h +++ b/retroshare-gui/src/gui/feeds/SecurityItem.h @@ -42,7 +42,7 @@ public: void updateItemStatic(); - bool isSame(const RsPeerId &sslId, uint32_t type); + QString uniqueIdentifier() const override; protected: /* FeedItem */ From 00c74f0956d20e15e73b356f36f754813233dd17 Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 4 Dec 2019 22:24:11 +0100 Subject: [PATCH 06/39] moved rsevent for incomplete cert info to the right place so that it does not trigger when a connection from a non friend is denied --- libretroshare/src/pqi/authssl.cc | 14 +++++++------- libretroshare/src/pqi/pqissllistener.cc | 19 +++++++++---------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/libretroshare/src/pqi/authssl.cc b/libretroshare/src/pqi/authssl.cc index 397fdddea..f9815d76c 100644 --- a/libretroshare/src/pqi/authssl.cc +++ b/libretroshare/src/pqi/authssl.cc @@ -1186,13 +1186,13 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx) RsErr() << __PRETTY_FUNCTION__ << " " << errMsg << std::endl; - if(rsEvents) - { - ev->mErrorMsg = errMsg; - ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::NO_CERTIFICATE_SUPPLIED; - - rsEvents->postEvent(std::move(ev)); - } +// if(rsEvents) +// { +// ev->mErrorMsg = errMsg; +// ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::NO_CERTIFICATE_SUPPLIED; +// +// rsEvents->postEvent(std::move(ev)); +// } return verificationFailed; } diff --git a/libretroshare/src/pqi/pqissllistener.cc b/libretroshare/src/pqi/pqissllistener.cc index afd12ccbd..84fdd3dcb 100644 --- a/libretroshare/src/pqi/pqissllistener.cc +++ b/libretroshare/src/pqi/pqissllistener.cc @@ -486,23 +486,24 @@ int pqissllistenbase::continueSSL(IncomingSSLInfo& incoming_connexion_info, bool break; } - if(rsEvents) + pqioutput(PQL_WARNING, pqissllistenzone, "Read Error on the SSL Socket\nShutting it down!"); + + // We use SSL_get_verify_result() in order to differentiate two cases: + // case 1: the incoming connection is closed because the peer is not a friend. This is already handled in authssl. + // case 2: the incoming connection is closed because no authentication info is available, in which case it returns X509_V_OK + auto vres = SSL_get_verify_result(incoming_connexion_info.ssl); + + if(vres == X509_V_OK && nullptr != rsEvents) { auto ev = std::unique_ptr(new RsAuthSslConnectionAutenticationEvent); - ev->mSslId = incoming_connexion_info.sslid; - ev->mPgpId = incoming_connexion_info.gpgid; - ev->mSslCn = incoming_connexion_info.sslcn; ev->mLocator = RsUrl(incoming_connexion_info.addr); ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::MISSING_AUTHENTICATION_INFO; rsEvents->postEvent(std::move(ev)); } - closeConnection(fd, incoming_connexion_info.ssl) ; - pqioutput(PQL_WARNING, pqissllistenzone, "Read Error on the SSL Socket\nShutting it down!"); - // failure -1, pending 0, sucess 1. return -1; } @@ -524,17 +525,15 @@ int pqissllistenbase::continueSSL(IncomingSSLInfo& incoming_connexion_info, bool std::cerr << " Got SSL CN = " << incoming_connexion_info.sslcn << std::endl; #endif } + #ifdef DEBUG_LISTENNER else std::cerr << " no info." << std::endl; #endif - // if it succeeds if (0 < completeConnection(fd, incoming_connexion_info)) - { return 1; - } /* else we shut it down! */ pqioutput(PQL_WARNING, pqissllistenzone, From 324e7e802ed7752f360fb6aaa7427b2e8c8ad76b Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 4 Dec 2019 23:40:33 +0100 Subject: [PATCH 07/39] fixed not display of remove button --- retroshare-gui/src/gui/NewsFeed.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/retroshare-gui/src/gui/NewsFeed.cpp b/retroshare-gui/src/gui/NewsFeed.cpp index cb7f9737d..5ba4366e7 100644 --- a/retroshare-gui/src/gui/NewsFeed.cpp +++ b/retroshare-gui/src/gui/NewsFeed.cpp @@ -262,7 +262,7 @@ void NewsFeed::handleSecurityEvent(std::shared_ptr event) RsPeerDetails det; rsPeers->getPeerDetails(e.mSslId,det) || rsPeers->getGPGDetails(e.mPgpId,det); - addFeedItemIfUnique(new SecurityItem(this, NEWSFEED_SECLIST, det.gpg_id, det.id, det.location, e.mLocator.toString(), FeedItemType, true), true ); + addFeedItemIfUnique(new SecurityItem(this, NEWSFEED_SECLIST, det.gpg_id, det.id, det.location, e.mLocator.toString(), FeedItemType, false), true ); if (Settings->getMessageFlags() & RS_MESSAGE_CONNECT_ATTEMPT) MessageComposer::addConnectAttemptMsg(e.mPgpId, e.mSslId, QString::fromStdString(det.name + "(" + det.location + ")")); From c48aff44b2cc57ff38fc4613b31b6f59f6622e84 Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 5 Dec 2019 22:12:36 +0100 Subject: [PATCH 08/39] removed set/get CurrentConnectionAttemptInfo because it was both prone to error and useless --- libretroshare/src/pqi/authssl.cc | 41 +++++++++++++------------ libretroshare/src/pqi/authssl.h | 20 ++++++------ libretroshare/src/pqi/pqissllistener.cc | 18 ++--------- retroshare-gui/src/gui/NewsFeed.cpp | 2 +- 4 files changed, 35 insertions(+), 46 deletions(-) diff --git a/libretroshare/src/pqi/authssl.cc b/libretroshare/src/pqi/authssl.cc index f9815d76c..ffa26a75c 100644 --- a/libretroshare/src/pqi/authssl.cc +++ b/libretroshare/src/pqi/authssl.cc @@ -1219,6 +1219,7 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx) if(rsEvents) { ev->mSslCn = sslCn; + ev->mSslId = sslId; ev->mPgpId = pgpId; ev->mErrorMsg = errMsg; ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::MISSING_AUTHENTICATION_INFO; @@ -1305,6 +1306,8 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx) return verificationFailed; } + std::cerr << "******* VerifyX509Callback cert: " << std::hex << ctx->cert <getGPGOwnId() && !AuthGPG::getAuthGPG()->isGPGAccepted(pgpId) ) { std::string errMsg = "Connection attempt signed by PGP key id: " + @@ -1326,7 +1329,7 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx) return verificationFailed; } - setCurrentConnectionAttemptInfo(pgpId, sslId, sslCn); + //setCurrentConnectionAttemptInfo(pgpId, sslId, sslCn); LocalStoreCert(x509Cert); RsInfo() << __PRETTY_FUNCTION__ << " authentication successfull for " @@ -1590,24 +1593,24 @@ bool AuthSSLimpl::decrypt(void *&out, int &outlen, const void *in, int inlen) /********************************************************************************/ /********************************************************************************/ -void AuthSSLimpl::setCurrentConnectionAttemptInfo(const RsPgpId& gpg_id,const RsPeerId& ssl_id,const std::string& ssl_cn) -{ -#ifdef AUTHSSL_DEBUG - std::cerr << "AuthSSL: registering connection attempt from:" << std::endl; - std::cerr << " GPG id: " << gpg_id << std::endl; - std::cerr << " SSL id: " << ssl_id << std::endl; - std::cerr << " SSL cn: " << ssl_cn << std::endl; -#endif - _last_gpgid_to_connect = gpg_id ; - _last_sslid_to_connect = ssl_id ; - _last_sslcn_to_connect = ssl_cn ; -} -void AuthSSLimpl::getCurrentConnectionAttemptInfo(RsPgpId& gpg_id,RsPeerId& ssl_id,std::string& ssl_cn) -{ - gpg_id = _last_gpgid_to_connect ; - ssl_id = _last_sslid_to_connect ; - ssl_cn = _last_sslcn_to_connect ; -} +// void AuthSSLimpl::setCurrentConnectionAttemptInfo(const RsPgpId& gpg_id,const RsPeerId& ssl_id,const std::string& ssl_cn) +// { +// #ifdef AUTHSSL_DEBUG +// std::cerr << "AuthSSL: registering connection attempt from:" << std::endl; +// std::cerr << " GPG id: " << gpg_id << std::endl; +// std::cerr << " SSL id: " << ssl_id << std::endl; +// std::cerr << " SSL cn: " << ssl_cn << std::endl; +// #endif +// _last_gpgid_to_connect = gpg_id ; +// _last_sslid_to_connect = ssl_id ; +// _last_sslcn_to_connect = ssl_cn ; +// } +// void AuthSSLimpl::getCurrentConnectionAttemptInfo(RsPgpId& gpg_id,RsPeerId& ssl_id,std::string& ssl_cn) +// { +// gpg_id = _last_gpgid_to_connect ; +// ssl_id = _last_sslid_to_connect ; +// ssl_cn = _last_sslcn_to_connect ; +// } /* Locked search -> internal help function */ bool AuthSSLimpl::locked_FindCert(const RsPeerId& id, X509** cert) diff --git a/libretroshare/src/pqi/authssl.h b/libretroshare/src/pqi/authssl.h index c38eab7ba..f15a323b3 100644 --- a/libretroshare/src/pqi/authssl.h +++ b/libretroshare/src/pqi/authssl.h @@ -137,11 +137,11 @@ public: /// SSL specific functions used in pqissl/pqissllistener virtual SSL_CTX* getCTX() = 0; - virtual void setCurrentConnectionAttemptInfo( - const RsPgpId& gpg_id, const RsPeerId& ssl_id, - const std::string& ssl_cn ) = 0; - virtual void getCurrentConnectionAttemptInfo( - RsPgpId& gpg_id, RsPeerId& ssl_id, std::string& ssl_cn ) = 0; +// virtual void setCurrentConnectionAttemptInfo( +// const RsPgpId& gpg_id, const RsPeerId& ssl_id, +// const std::string& ssl_cn ) = 0; +// virtual void getCurrentConnectionAttemptInfo( +// RsPgpId& gpg_id, RsPeerId& ssl_id, std::string& ssl_cn ) = 0; /** @@ -231,11 +231,11 @@ public: SSL_CTX* getCTX() override; /* Restored these functions: */ - void setCurrentConnectionAttemptInfo( - const RsPgpId& gpg_id, const RsPeerId& ssl_id, - const std::string& ssl_cn ) override; - void getCurrentConnectionAttemptInfo( - RsPgpId& gpg_id, RsPeerId& ssl_id, std::string& ssl_cn ) override; +// void setCurrentConnectionAttemptInfo( +// const RsPgpId& gpg_id, const RsPeerId& ssl_id, +// const std::string& ssl_cn ) override; +// void getCurrentConnectionAttemptInfo( +// RsPgpId& gpg_id, RsPeerId& ssl_id, std::string& ssl_cn ) override; private: diff --git a/libretroshare/src/pqi/pqissllistener.cc b/libretroshare/src/pqi/pqissllistener.cc index 84fdd3dcb..98eabe951 100644 --- a/libretroshare/src/pqi/pqissllistener.cc +++ b/libretroshare/src/pqi/pqissllistener.cc @@ -424,23 +424,8 @@ int pqissllistenbase::continueSSL(IncomingSSLInfo& incoming_connexion_info, bool { // attempt the accept again. int fd = SSL_get_fd(incoming_connexion_info.ssl); - - AuthSSL::getAuthSSL()->setCurrentConnectionAttemptInfo(RsPgpId(),RsPeerId(),std::string()) ; int err = SSL_accept(incoming_connexion_info.ssl); - // Now grab the connection info that was filled in by the callback. - // In the case the callback did not succeed the SSL certificate will not be accessible - // from SSL_get_peer_certificate, so we need to get it from the callback system. - // - AuthSSL::getAuthSSL()->getCurrentConnectionAttemptInfo(incoming_connexion_info.gpgid,incoming_connexion_info.sslid,incoming_connexion_info.sslcn) ; - -#ifdef DEBUG_LISTENNER - std::cerr << "Info from callback: " << std::endl; - std::cerr << " Got PGP Id = " << incoming_connexion_info.gpgid << std::endl; - std::cerr << " Got SSL Id = " << incoming_connexion_info.sslid << std::endl; - std::cerr << " Got SSL CN = " << incoming_connexion_info.sslcn << std::endl; -#endif - if (err <= 0) { int ssl_err = SSL_get_error(incoming_connexion_info.ssl, err); @@ -519,7 +504,8 @@ int pqissllistenbase::continueSSL(IncomingSSLInfo& incoming_connexion_info, bool incoming_connexion_info.sslcn = RsX509Cert::getCertName(*x509); incoming_connexion_info.sslid = RsX509Cert::getCertSslId(*x509); -#ifdef DEBUG_LISTENNER +#ifndef DEBUG_LISTENNER + std::cerr << "ContinueSSL:" << std::endl; std::cerr << " Got PGP Id = " << incoming_connexion_info.gpgid << std::endl; std::cerr << " Got SSL Id = " << incoming_connexion_info.sslid << std::endl; std::cerr << " Got SSL CN = " << incoming_connexion_info.sslcn << std::endl; diff --git a/retroshare-gui/src/gui/NewsFeed.cpp b/retroshare-gui/src/gui/NewsFeed.cpp index 5ba4366e7..c6057c1f2 100644 --- a/retroshare-gui/src/gui/NewsFeed.cpp +++ b/retroshare-gui/src/gui/NewsFeed.cpp @@ -262,7 +262,7 @@ void NewsFeed::handleSecurityEvent(std::shared_ptr event) RsPeerDetails det; rsPeers->getPeerDetails(e.mSslId,det) || rsPeers->getGPGDetails(e.mPgpId,det); - addFeedItemIfUnique(new SecurityItem(this, NEWSFEED_SECLIST, det.gpg_id, det.id, det.location, e.mLocator.toString(), FeedItemType, false), true ); + addFeedItemIfUnique(new SecurityItem(this, NEWSFEED_SECLIST, e.mPgpId, e.mSslId, det.location, e.mLocator.toString(), FeedItemType, false), true ); if (Settings->getMessageFlags() & RS_MESSAGE_CONNECT_ATTEMPT) MessageComposer::addConnectAttemptMsg(e.mPgpId, e.mSslId, QString::fromStdString(det.name + "(" + det.location + ")")); From bb10b82c8e65c37beaa37e966af2c5a562cb181e Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 5 Dec 2019 23:43:38 +0100 Subject: [PATCH 09/39] moved refused connect attempt event to RsAuthSslConnectionAuthentication --- libretroshare/src/pqi/authssl.cc | 10 +++++++++- libretroshare/src/pqi/pqissl.cc | 10 ++++++++++ libretroshare/src/retroshare/rsevents.h | 4 ++-- libretroshare/src/retroshare/rsnotify.h | 3 ++- retroshare-gui/src/gui/NewsFeed.cpp | 20 ++++++++------------ 5 files changed, 31 insertions(+), 16 deletions(-) diff --git a/libretroshare/src/pqi/authssl.cc b/libretroshare/src/pqi/authssl.cc index ffa26a75c..62515970a 100644 --- a/libretroshare/src/pqi/authssl.cc +++ b/libretroshare/src/pqi/authssl.cc @@ -1298,7 +1298,15 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx) ev->mSslId = sslId; ev->mSslCn = sslCn; ev->mPgpId = pgpId; - ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::PGP_SIGNATURE_VALIDATION_FAILED; + + switch(auth_diagnostic) + { + case RS_SSL_HANDSHAKE_DIAGNOSTIC_ISSUER_UNKNOWN: ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::NOT_A_FRIEND; break; + case RS_SSL_HANDSHAKE_DIAGNOSTIC_WRONG_SIGNATURE: ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::PGP_SIGNATURE_VALIDATION_FAILED;break; + default: + ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::MISSING_AUTHENTICATION_INFO;break; + } + ev->mErrorMsg = errMsg; rsEvents->postEvent(std::move(ev)); } diff --git a/libretroshare/src/pqi/pqissl.cc b/libretroshare/src/pqi/pqissl.cc index 773c74e50..0506ed8d2 100644 --- a/libretroshare/src/pqi/pqissl.cc +++ b/libretroshare/src/pqi/pqissl.cc @@ -1108,6 +1108,16 @@ int pqissl::SSL_Connection_Complete() return 0; } + if(rsEvents) + { + auto ev = std::make_shared(); + + X509 *x509 = SSL_get_peer_certificate(ssl_connection) ; + + ev->mSslId = RsX509Cert::getCertSslId(*x509); + ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::PEER_REFUSED_CONNECTION; + rsEvents->postEvent(ev); + } std::string out; rs_sprintf(out, "pqissl::SSL_Connection_Complete()\nIssues with SSL Connect(%d)!\n", err); diff --git a/libretroshare/src/retroshare/rsevents.h b/libretroshare/src/retroshare/rsevents.h index 8bf2a6fe2..3c244ab95 100644 --- a/libretroshare/src/retroshare/rsevents.h +++ b/libretroshare/src/retroshare/rsevents.h @@ -193,7 +193,8 @@ struct RsAuthSslConnectionAutenticationEvent : RsEvent NOT_A_FRIEND = 0x05, MISSING_CERTIFICATE = 0x06, IP_IS_BLACKLISTED = 0x07, - UNKNOWN_ERROR = 0x08, + PEER_REFUSED_CONNECTION = 0x08, + UNKNOWN_ERROR = 0x09, }; RsPeerId mSslId; @@ -227,7 +228,6 @@ struct RsConnectionEvent : RsEvent UNKNOWN = 0x00, PEER_CONNECTED = 0x01, PEER_DISCONNECTED = 0x02, - PEER_REFUSED_CONNECTION = 0x03, }; ConnectionType mConnectionType; diff --git a/libretroshare/src/retroshare/rsnotify.h b/libretroshare/src/retroshare/rsnotify.h index 001848439..6f882215f 100644 --- a/libretroshare/src/retroshare/rsnotify.h +++ b/libretroshare/src/retroshare/rsnotify.h @@ -79,9 +79,10 @@ const uint32_t RS_FEED_ITEM_PEER_DISCONNECT = RS_FEED_TYPE_PEER | 0x000 const uint32_t RS_FEED_ITEM_PEER_HELLO = RS_FEED_TYPE_PEER | 0x0003; const uint32_t RS_FEED_ITEM_PEER_NEW = RS_FEED_TYPE_PEER | 0x0004; const uint32_t RS_FEED_ITEM_PEER_OFFSET = RS_FEED_TYPE_PEER | 0x0005; +const uint32_t RS_FEED_ITEM_PEER_DENIES_CONNEXION = RS_FEED_TYPE_PEER | 0x0006; const uint32_t RS_FEED_ITEM_SEC_CONNECT_ATTEMPT = RS_FEED_TYPE_SECURITY | 0x0001; -const uint32_t RS_FEED_ITEM_SEC_AUTH_DENIED = RS_FEED_TYPE_SECURITY | 0x0002; +const uint32_t RS_FEED_ITEM_SEC_AUTH_DENIED = RS_FEED_TYPE_SECURITY | 0x0002; // locally denied connection const uint32_t RS_FEED_ITEM_SEC_UNKNOWN_IN = RS_FEED_TYPE_SECURITY | 0x0003; const uint32_t RS_FEED_ITEM_SEC_UNKNOWN_OUT = RS_FEED_TYPE_SECURITY | 0x0004; const uint32_t RS_FEED_ITEM_SEC_WRONG_SIGNATURE = RS_FEED_TYPE_SECURITY | 0x0005; diff --git a/retroshare-gui/src/gui/NewsFeed.cpp b/retroshare-gui/src/gui/NewsFeed.cpp index c6057c1f2..673177dd3 100644 --- a/retroshare-gui/src/gui/NewsFeed.cpp +++ b/retroshare-gui/src/gui/NewsFeed.cpp @@ -194,7 +194,7 @@ void NewsFeed::handleEvent(std::shared_ptr event) return; } - if(event->mType == RsEventType::PEER_STATE_CHANGED && (flags & RS_FEED_TYPE_PEER)) + if(event->mType == RsEventType::PEER_CONNECTION && (flags & RS_FEED_TYPE_PEER)) { RsQThreadUtils::postToObject( [=]() { handleConnectionEvent(event); }, this ); return; @@ -217,16 +217,6 @@ void NewsFeed::handleConnectionEvent(std::shared_ptr event) break; case RsConnectionEvent::PEER_DISCONNECTED: break;// not handled yet - case RsConnectionEvent::PEER_REFUSED_CONNECTION: - { - RsPeerDetails det; - if(!rsPeers->getPeerDetails(e.mSslId,det)) - return; - - addFeedItemIfUnique(new SecurityItem(this, NEWSFEED_SECLIST, det.gpg_id, e.mSslId, det.location, std::string(), RS_FEED_ITEM_SEC_AUTH_DENIED, false), true ); - } - break; - default: break; } } @@ -243,6 +233,12 @@ void NewsFeed::handleSecurityEvent(std::shared_ptr event) std::cerr << "NotifyQt: handling security event from (" << e.mSslId << "," << e.mPgpId << ") error code: " << e.mErrorCode << std::endl; uint flags = Settings->getNewsFeedFlags(); + if(e.mErrorCode == RsAuthSslConnectionAutenticationEvent::PEER_REFUSED_CONNECTION) + { + addFeedItemIfUnique(new PeerItem(this, NEWSFEED_PEERLIST, e.mSslId, PEER_TYPE_HELLO, false), true ); + return; + } + uint32_t FeedItemType=0; switch(e.mErrorCode) @@ -251,7 +247,7 @@ void NewsFeed::handleSecurityEvent(std::shared_ptr event) case RsAuthSslConnectionAutenticationEvent::MISMATCHED_PGP_ID: // fallthrough case RsAuthSslConnectionAutenticationEvent::MISSING_AUTHENTICATION_INFO: FeedItemType = RS_FEED_ITEM_SEC_BAD_CERTIFICATE; break; case RsAuthSslConnectionAutenticationEvent::PGP_SIGNATURE_VALIDATION_FAILED: FeedItemType = RS_FEED_ITEM_SEC_WRONG_SIGNATURE; break; - case RsAuthSslConnectionAutenticationEvent::NOT_A_FRIEND: FeedItemType = RS_FEED_ITEM_SEC_AUTH_DENIED; break; + case RsAuthSslConnectionAutenticationEvent::NOT_A_FRIEND: FeedItemType = RS_FEED_ITEM_SEC_CONNECT_ATTEMPT; break; case RsAuthSslConnectionAutenticationEvent::IP_IS_BLACKLISTED: FeedItemType = RS_FEED_ITEM_SEC_IP_BLACKLISTED; break; case RsAuthSslConnectionAutenticationEvent::MISSING_CERTIFICATE: FeedItemType = RS_FEED_ITEM_SEC_MISSING_CERTIFICATE; break; From d152d9f50ca361fc441653c8f1cf9693e69918cd Mon Sep 17 00:00:00 2001 From: csoler Date: Fri, 6 Dec 2019 22:19:49 +0100 Subject: [PATCH 10/39] fixed proper async call of forceUpdateDisplay() --- retroshare-gui/src/gui/common/NewFriendList.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/retroshare-gui/src/gui/common/NewFriendList.cpp b/retroshare-gui/src/gui/common/NewFriendList.cpp index 417e1a279..e3dc2b015 100644 --- a/retroshare-gui/src/gui/common/NewFriendList.cpp +++ b/retroshare-gui/src/gui/common/NewFriendList.cpp @@ -47,6 +47,7 @@ #include "RSTreeWidgetItem.h" #include "StatusDefs.h" #include "util/misc.h" +#include "util/qtthreadsutils.h" #include "vmessagebox.h" #include "util/QtVersion.h" #include "gui/chat/ChatUserNotify.h" @@ -257,7 +258,12 @@ NewFriendList::NewFriendList(QWidget *parent) : /* RsAutoUpdatePage(5000,parent) void NewFriendList::handleEvent(std::shared_ptr e) { if(dynamic_cast(e.get()) != nullptr) - forceUpdateDisplay(); + { + // /!\ The function we're in is called from a different thread. It's very important + // to use this trick in order to avoid data races. + + RsQThreadUtils::postToObject( [=]() { forceUpdateDisplay() ; }, this ) ; + } } NewFriendList::~NewFriendList() From 9790b986054e8de7567e2288544822cd03bc7cf4 Mon Sep 17 00:00:00 2001 From: csoler Date: Fri, 6 Dec 2019 22:45:33 +0100 Subject: [PATCH 11/39] fixed "connexion refused by peer" message --- libretroshare/src/pqi/pqissl.cc | 3 +-- retroshare-gui/src/gui/feeds/PeerItem.cpp | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/libretroshare/src/pqi/pqissl.cc b/libretroshare/src/pqi/pqissl.cc index 0506ed8d2..017c3bbb2 100644 --- a/libretroshare/src/pqi/pqissl.cc +++ b/libretroshare/src/pqi/pqissl.cc @@ -1096,8 +1096,7 @@ int pqissl::SSL_Connection_Complete() if (err != 1) { int serr = SSL_get_error(ssl_connection, err); - if ((serr == SSL_ERROR_WANT_READ) - || (serr == SSL_ERROR_WANT_WRITE)) + if ((serr == SSL_ERROR_WANT_READ) || (serr == SSL_ERROR_WANT_WRITE)) { #ifdef PQISSL_LOG_DEBUG rslog(RSL_DEBUG_BASIC, pqisslzone, diff --git a/retroshare-gui/src/gui/feeds/PeerItem.cpp b/retroshare-gui/src/gui/feeds/PeerItem.cpp index f51b42f30..324a0b78b 100644 --- a/retroshare-gui/src/gui/feeds/PeerItem.cpp +++ b/retroshare-gui/src/gui/feeds/PeerItem.cpp @@ -94,7 +94,7 @@ void PeerItem::updateItemStatic() title = tr("Friend Connected"); break; case PEER_TYPE_HELLO: - title = tr("Connect Attempt"); + title = tr("Connection refused by peer"); break; case PEER_TYPE_NEW_FOF: title = tr("Friend of Friend"); From f118b4656e2e0abcbcddb0a774fe8d1471e229c3 Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 7 Dec 2019 21:43:28 +0100 Subject: [PATCH 12/39] moved more peer connection notifications to rsEvents --- libretroshare/src/pqi/p3linkmgr.cc | 32 +++++++++---------------- libretroshare/src/pqi/p3peermgr.cc | 11 ++++++++- libretroshare/src/retroshare/rsevents.h | 10 +++++--- libretroshare/src/services/p3rtt.cc | 16 ++++++++----- retroshare-gui/src/gui/NewsFeed.cpp | 23 ++++++++++++++---- 5 files changed, 57 insertions(+), 35 deletions(-) diff --git a/libretroshare/src/pqi/p3linkmgr.cc b/libretroshare/src/pqi/p3linkmgr.cc index a84090860..4440176c7 100644 --- a/libretroshare/src/pqi/p3linkmgr.cc +++ b/libretroshare/src/pqi/p3linkmgr.cc @@ -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() ; - - 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() ; - 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() ; + + e->mConnectionInfoCode = RsConnectionEvent::PEER_DISCONNECTED; e->mSslId = peer.id; rsEvents->postEvent(e); diff --git a/libretroshare/src/pqi/p3peermgr.cc b/libretroshare/src/pqi/p3peermgr.cc index 564eb44b8..3f6a5f6ee 100644 --- a/libretroshare/src/pqi/p3peermgr.cc +++ b/libretroshare/src/pqi/p3peermgr.cc @@ -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(); + 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. diff --git a/libretroshare/src/retroshare/rsevents.h b/libretroshare/src/retroshare/rsevents.h index 3c244ab95..84c41237e 100644 --- a/libretroshare/src/retroshare/rsevents.h +++ b/libretroshare/src/retroshare/rsevents.h @@ -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); } }; diff --git a/libretroshare/src/services/p3rtt.cc b/libretroshare/src/services/p3rtt.cc index 4c7effe36..dc3b37646 100644 --- a/libretroshare/src/services/p3rtt.cc +++ b/libretroshare/src/services/p3rtt.cc @@ -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(); + + 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; } } diff --git a/retroshare-gui/src/gui/NewsFeed.cpp b/retroshare-gui/src/gui/NewsFeed.cpp index 673177dd3..f4ebc596e 100644 --- a/retroshare-gui/src/gui/NewsFeed.cpp +++ b/retroshare-gui/src/gui/NewsFeed.cpp @@ -211,12 +211,17 @@ void NewsFeed::handleConnectionEvent(std::shared_ptr 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) { From b6ca07aaa3a3082ff5a226aefa343f621fc4952f Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 7 Dec 2019 22:26:26 +0100 Subject: [PATCH 13/39] fixed bug caused by accessing Settings from non Qt thread --- libretroshare/src/retroshare/rsevents.h | 2 ++ retroshare-gui/src/gui/NewsFeed.cpp | 17 +++++++++-------- retroshare-gui/src/gui/NewsFeed.h | 1 + retroshare-gui/src/gui/common/NewFriendList.cpp | 3 ++- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/libretroshare/src/retroshare/rsevents.h b/libretroshare/src/retroshare/rsevents.h index 84c41237e..123cfaf3e 100644 --- a/libretroshare/src/retroshare/rsevents.h +++ b/libretroshare/src/retroshare/rsevents.h @@ -243,6 +243,8 @@ struct RsConnectionEvent : RsEvent RsEvent::serial_process(j, ctx); RS_SERIAL_PROCESS(mConnectionInfoCode); RS_SERIAL_PROCESS(mSslId); + RS_SERIAL_PROCESS(mStrInfo1); + RS_SERIAL_PROCESS(mStrInfo2); } }; diff --git a/retroshare-gui/src/gui/NewsFeed.cpp b/retroshare-gui/src/gui/NewsFeed.cpp index f4ebc596e..8a87c2ea3 100644 --- a/retroshare-gui/src/gui/NewsFeed.cpp +++ b/retroshare-gui/src/gui/NewsFeed.cpp @@ -185,20 +185,21 @@ void NewsFeed::sortChanged(int index) // handler for the new notification system in libretroshare. void NewsFeed::handleEvent(std::shared_ptr event) +{ + // /!\ Absolutely no access to Qt structures (such as Settings) should happen here!!! + + RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); +} + +void NewsFeed::handleEvent_main_thread(std::shared_ptr event) { uint flags = Settings->getNewsFeedFlags(); if(event->mType == RsEventType::AUTHSSL_CONNECTION_AUTENTICATION && (flags & RS_FEED_TYPE_SECURITY)) - { - RsQThreadUtils::postToObject( [=]() { handleSecurityEvent(event); }, this ); - return; - } + handleSecurityEvent(event); if(event->mType == RsEventType::PEER_CONNECTION && (flags & RS_FEED_TYPE_PEER)) - { - RsQThreadUtils::postToObject( [=]() { handleConnectionEvent(event); }, this ); - return; - } + handleConnectionEvent(event); } void NewsFeed::handleConnectionEvent(std::shared_ptr event) diff --git a/retroshare-gui/src/gui/NewsFeed.h b/retroshare-gui/src/gui/NewsFeed.h index 747e86cea..52164330b 100644 --- a/retroshare-gui/src/gui/NewsFeed.h +++ b/retroshare-gui/src/gui/NewsFeed.h @@ -104,6 +104,7 @@ private slots: private: void handleSecurityEvent(std::shared_ptr event); void handleConnectionEvent(std::shared_ptr event); + void handleEvent_main_thread(std::shared_ptr event); void addFeedItem(FeedItem *item); void addFeedItemIfUnique(FeedItem *item, bool replace); diff --git a/retroshare-gui/src/gui/common/NewFriendList.cpp b/retroshare-gui/src/gui/common/NewFriendList.cpp index e3dc2b015..7b07f9086 100644 --- a/retroshare-gui/src/gui/common/NewFriendList.cpp +++ b/retroshare-gui/src/gui/common/NewFriendList.cpp @@ -177,6 +177,7 @@ NewFriendList::NewFriendList(QWidget *parent) : /* RsAutoUpdatePage(5000,parent) ui->filterLineEdit->setPlaceholderText(tr("Search")) ; ui->filterLineEdit->showFilterIcon(); + mEventHandlerId=0; // forces initialization rsEvents->registerEventsHandler( [this](std::shared_ptr e) { handleEvent(e); }, mEventHandlerId ); mModel = new RsFriendListModel(); @@ -257,7 +258,7 @@ NewFriendList::NewFriendList(QWidget *parent) : /* RsAutoUpdatePage(5000,parent) void NewFriendList::handleEvent(std::shared_ptr e) { - if(dynamic_cast(e.get()) != nullptr) + if(e->mType == RsEventType::PEER_CONNECTION) { // /!\ The function we're in is called from a different thread. It's very important // to use this trick in order to avoid data races. From e4026300955d257c521d3b1cb71d19e2ccc71e32 Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 8 Dec 2019 21:34:52 +0100 Subject: [PATCH 14/39] attempt to fix thread race between rsEvents and TokenQueue --- libretroshare/src/gxstunnel/p3gxstunnel.cc | 2 ++ libretroshare/src/services/p3msgservice.cc | 7 +++---- retroshare-gui/src/gui/NewsFeed.cpp | 3 +++ retroshare-gui/src/util/TokenQueue.cpp | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/libretroshare/src/gxstunnel/p3gxstunnel.cc b/libretroshare/src/gxstunnel/p3gxstunnel.cc index 0a1a45024..08ca943a6 100644 --- a/libretroshare/src/gxstunnel/p3gxstunnel.cc +++ b/libretroshare/src/gxstunnel/p3gxstunnel.cc @@ -1296,7 +1296,9 @@ bool p3GxsTunnelService::locked_sendEncryptedTunnelData(RsGxsTunnelItem *item) } if(it->second.status != RS_GXS_TUNNEL_STATUS_CAN_TALK) { +#ifdef DEBUG_GXS_TUNNEL std::cerr << "(EE) Cannot talk to tunnel id " << tunnel_id << ". Tunnel status is: " << it->second.status << std::endl; +#endif return false; } diff --git a/libretroshare/src/services/p3msgservice.cc b/libretroshare/src/services/p3msgservice.cc index ebf2ce496..20697f2d6 100644 --- a/libretroshare/src/services/p3msgservice.cc +++ b/libretroshare/src/services/p3msgservice.cc @@ -404,11 +404,10 @@ int p3MsgService::checkOutgoingMessages() mit->second->msgFlags |= RS_MSG_FLAGS_ROUTED; } } +#ifdef DEBUG_DISTANT_MSG else - { - Dbg3() << __PRETTY_FUNCTION__ << " Delaying until available..." - << std::endl; - } + Dbg3() << __PRETTY_FUNCTION__ << " Delaying until available..." << std::endl; +#endif } /* clean up */ diff --git a/retroshare-gui/src/gui/NewsFeed.cpp b/retroshare-gui/src/gui/NewsFeed.cpp index 8a87c2ea3..b4f582db5 100644 --- a/retroshare-gui/src/gui/NewsFeed.cpp +++ b/retroshare-gui/src/gui/NewsFeed.cpp @@ -1103,6 +1103,7 @@ void NewsFeed::addFeedItem(FeedItem *item) { static const int MAX_FEEDITEM_COUNT = 500 ; + std::cerr << "Adding feed item thread " << pthread_self() << std::endl; item->setAttribute(Qt::WA_DeleteOnClose, true); // costly, but not really a problem here @@ -1125,6 +1126,7 @@ void NewsFeed::addFeedItemIfUnique(FeedItem *item, bool replace) { FeedItem *feedItem = ui->feedWidget->findFeedItem(item->uniqueIdentifier()); + std::cerr << "Adding feed item thread " << pthread_self() << std::endl; if (feedItem) { if (!replace) @@ -1143,6 +1145,7 @@ void NewsFeed::remUniqueFeedItem(FeedItem *item) { FeedItem *feedItem = ui->feedWidget->findFeedItem(item->uniqueIdentifier()); + std::cerr << "Adding feed item thread " << pthread_self() << std::endl; if (feedItem) { delete item; diff --git a/retroshare-gui/src/util/TokenQueue.cpp b/retroshare-gui/src/util/TokenQueue.cpp index ac66d5c3c..4fad53fc5 100644 --- a/retroshare-gui/src/util/TokenQueue.cpp +++ b/retroshare-gui/src/util/TokenQueue.cpp @@ -34,7 +34,7 @@ TokenQueue::TokenQueue(RsTokenService *service, TokenResponse *resp) { mTrigger = new RsProtectedTimer(this); mTrigger->setSingleShot(true); - connect(mTrigger, SIGNAL(timeout()), this, SLOT(pollRequests())); + connect(mTrigger, SIGNAL(timeout()), this, SLOT(pollRequests()),Qt::QueuedConnection); } bool TokenQueue::requestGroupInfo(uint32_t &token, uint32_t anstype, const RsTokReqOptions &opts, std::list& ids, uint32_t usertype) From 27793627e3a8652f7a7ee15b2fb688c43e74352a Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 9 Dec 2019 22:19:03 +0100 Subject: [PATCH 15/39] moved GxsChanges to rsEvents --- libretroshare/src/gxs/rsgenexchange.cc | 17 ++--------------- libretroshare/src/pqi/p3notify.cc | 1 - libretroshare/src/pqi/p3notify.h | 1 - libretroshare/src/retroshare/rsnotify.h | 1 - retroshare-gui/src/gui/notifyqt.cpp | 2 ++ retroshare-gui/src/gui/notifyqt.h | 2 -- .../src/util/RsGxsUpdateBroadcast.cpp | 9 ++++++++- retroshare-gui/src/util/RsGxsUpdateBroadcast.h | 2 ++ 8 files changed, 14 insertions(+), 21 deletions(-) diff --git a/libretroshare/src/gxs/rsgenexchange.cc b/libretroshare/src/gxs/rsgenexchange.cc index 2ac0736e5..bdc83792c 100644 --- a/libretroshare/src/gxs/rsgenexchange.cc +++ b/libretroshare/src/gxs/rsgenexchange.cc @@ -1118,38 +1118,25 @@ void RsGenExchange::receiveChanges(std::vector& changes) if((mc = dynamic_cast(n)) != nullptr) { if (mc->metaChange()) - { addMessageChanged(out.mMsgsMeta, mc->msgChangeMap); - } else - { addMessageChanged(out.mMsgs, mc->msgChangeMap); - } } else if((gc = dynamic_cast(n)) != nullptr) { if(gc->metaChange()) - { out.mGrpsMeta.splice(out.mGrpsMeta.end(), gc->mGrpIdList); - } else - { out.mGrps.splice(out.mGrps.end(), gc->mGrpIdList); - } } - else if(( gt = - dynamic_cast(n) ) != nullptr) - { + else if(( gt = dynamic_cast(n) ) != nullptr) out.mDistantSearchReqs.push_back(gt->mRequestId); - } else - RsErr() << __PRETTY_FUNCTION__ << " Unknown changes type!" - << std::endl; + RsErr() << __PRETTY_FUNCTION__ << " Unknown changes type!" << std::endl; delete n; } changes.clear() ; - RsServer::notify()->notifyGxsChange(out); if(rsEvents) rsEvents->postEvent(std::move(evt)); } diff --git a/libretroshare/src/pqi/p3notify.cc b/libretroshare/src/pqi/p3notify.cc index 95486f1a4..7a5dc8c45 100644 --- a/libretroshare/src/pqi/p3notify.cc +++ b/libretroshare/src/pqi/p3notify.cc @@ -233,7 +233,6 @@ void p3Notify::notifyOwnAvatarChanged () void p3Notify::notifyOwnStatusMessageChanged() { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyOwnStatusMessageChanged() ; } void p3Notify::notifyDiskFull (uint32_t location , uint32_t size_limit_in_MB ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyDiskFull (location,size_limit_in_MB) ; } void p3Notify::notifyPeerStatusChanged (const std::string& peer_id , uint32_t status ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyPeerStatusChanged (peer_id,status) ; } -void p3Notify::notifyGxsChange (const RsGxsChanges& changes) {FOR_ALL_NOTIFY_CLIENTS (*it)->notifyGxsChange(changes) ;} void p3Notify::notifyPeerStatusChangedSummary () { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyPeerStatusChangedSummary() ; } void p3Notify::notifyDiscInfoChanged () { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyDiscInfoChanged () ; } diff --git a/libretroshare/src/pqi/p3notify.h b/libretroshare/src/pqi/p3notify.h index d288091c3..46fb69c8e 100644 --- a/libretroshare/src/pqi/p3notify.h +++ b/libretroshare/src/pqi/p3notify.h @@ -109,7 +109,6 @@ class p3Notify: public RsNotify void notifyOwnStatusMessageChanged () ; void notifyDiskFull (uint32_t /* location */, uint32_t /* size limit in MB */) ; void notifyPeerStatusChanged (const std::string& /* peer_id */, uint32_t /* status */) ; - void notifyGxsChange (const RsGxsChanges& /* changes */); void notifyConnectionWithoutCert (); void notifyPeerStatusChangedSummary () ; diff --git a/libretroshare/src/retroshare/rsnotify.h b/libretroshare/src/retroshare/rsnotify.h index 6f882215f..6cb55dd66 100644 --- a/libretroshare/src/retroshare/rsnotify.h +++ b/libretroshare/src/retroshare/rsnotify.h @@ -229,7 +229,6 @@ public: virtual void notifyOwnStatusMessageChanged () {} virtual void notifyDiskFull (uint32_t /* location */, uint32_t /* size limit in MB */) {} virtual void notifyPeerStatusChanged (const std::string& /* peer_id */, uint32_t /* status */) {} - virtual void notifyGxsChange (const RsGxsChanges& /* changes */) {} /* one or more peers has changed the states */ virtual void notifyPeerStatusChangedSummary () {} diff --git a/retroshare-gui/src/gui/notifyqt.cpp b/retroshare-gui/src/gui/notifyqt.cpp index e13ed610d..27a81546a 100644 --- a/retroshare-gui/src/gui/notifyqt.cpp +++ b/retroshare-gui/src/gui/notifyqt.cpp @@ -422,6 +422,7 @@ void NotifyQt::notifyPeerStatusChangedSummary() emit peerStatusChangedSummary(); } +#ifdef TO_REMOVE void NotifyQt::notifyGxsChange(const RsGxsChanges& changes) { { @@ -436,6 +437,7 @@ void NotifyQt::notifyGxsChange(const RsGxsChanges& changes) emit gxsChange(changes); } +#endif void NotifyQt::notifyOwnStatusMessageChanged() { diff --git a/retroshare-gui/src/gui/notifyqt.h b/retroshare-gui/src/gui/notifyqt.h index 91fb1edbf..dd09bf4ea 100644 --- a/retroshare-gui/src/gui/notifyqt.h +++ b/retroshare-gui/src/gui/notifyqt.h @@ -82,8 +82,6 @@ class NotifyQt: public QObject, public NotifyClient /* one or more peers has changed the states */ virtual void notifyPeerStatusChangedSummary(); - virtual void notifyGxsChange(const RsGxsChanges& change); - virtual void notifyHistoryChanged(uint32_t msgId, int type); virtual void notifyDiscInfoChanged() ; diff --git a/retroshare-gui/src/util/RsGxsUpdateBroadcast.cpp b/retroshare-gui/src/util/RsGxsUpdateBroadcast.cpp index 5dbbf1c5a..bd2d647f5 100644 --- a/retroshare-gui/src/util/RsGxsUpdateBroadcast.cpp +++ b/retroshare-gui/src/util/RsGxsUpdateBroadcast.cpp @@ -37,7 +37,14 @@ QMap updateBroadcastMap; RsGxsUpdateBroadcast::RsGxsUpdateBroadcast(RsGxsIfaceHelper *ifaceImpl) : QObject(NULL), mIfaceImpl(ifaceImpl) { - connect(NotifyQt::getInstance(), SIGNAL(gxsChange(RsGxsChanges)), this, SLOT(onChangesReceived(RsGxsChanges))); + mEventHandlerId = 0; // forces initialization in registerEventsHandler() + + rsEvents->registerEventsHandler( [this](std::shared_ptr event) + { + if(event->mType == RsEventType::GXS_CHANGES) + onChangesReceived(*dynamic_cast(event.get())); + + }, mEventHandlerId ); } void RsGxsUpdateBroadcast::cleanup() diff --git a/retroshare-gui/src/util/RsGxsUpdateBroadcast.h b/retroshare-gui/src/util/RsGxsUpdateBroadcast.h index 1a776f2c4..1383c18dd 100644 --- a/retroshare-gui/src/util/RsGxsUpdateBroadcast.h +++ b/retroshare-gui/src/util/RsGxsUpdateBroadcast.h @@ -24,6 +24,7 @@ #include #include +#include struct RsGxsIfaceHelper; struct RsGxsChanges; @@ -53,6 +54,7 @@ private: private: RsGxsIfaceHelper* mIfaceImpl; + RsEventsHandlerId_t mEventHandlerId ; }; #endif // RSGXSUPDATEBROADCAST_H From eef5a5a8ef84df8d5fc7863a5822b5b395d3d0fe Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 12 Dec 2019 00:00:51 +0100 Subject: [PATCH 16/39] added new events for circles --- libretroshare/src/chat/p3chatservice.cc | 8 +- libretroshare/src/pqi/pqissl.cc | 24 ++- libretroshare/src/retroshare/rsevents.h | 3 + libretroshare/src/retroshare/rsgxscircles.h | 45 +++++- libretroshare/src/retroshare/rsnotify.h | 7 +- libretroshare/src/services/p3gxscircles.cc | 113 ++++++++++++-- libretroshare/src/services/p3gxscircles.h | 5 + retroshare-gui/src/gui/NewsFeed.cpp | 143 +++++++----------- retroshare-gui/src/gui/NewsFeed.h | 7 +- .../src/gui/feeds/GxsCircleItem.cpp | 54 ++++++- 10 files changed, 289 insertions(+), 120 deletions(-) diff --git a/libretroshare/src/chat/p3chatservice.cc b/libretroshare/src/chat/p3chatservice.cc index 67ca8f210..2f5df22fe 100644 --- a/libretroshare/src/chat/p3chatservice.cc +++ b/libretroshare/src/chat/p3chatservice.cc @@ -855,12 +855,8 @@ bool p3ChatService::handleRecvChatMsgItem(RsChatMsgItem *& ci) { #ifdef RS_DIRECT_CHAT /* notify public chat message */ - RsServer::notify()->AddPopupMessage( - RS_POPUP_GROUPCHAT, - ci->PeerId().toStdString(), "", message ); - RsServer::notify()->AddFeedItem( - RS_FEED_ITEM_CHAT_NEW, - ci->PeerId().toStdString(), message, "" ); + RsServer::notify()->AddPopupMessage( RS_POPUP_GROUPCHAT, ci->PeerId().toStdString(), "", message ); + //RsServer::notify()->AddFeedItem( RS_FEED_ITEM_CHAT_NEW, ci->PeerId().toStdString(), message, "" ); #else // def RS_DIRECT_CHAT /* Ignore deprecated direct node broadcast chat messages */ return false; diff --git a/libretroshare/src/pqi/pqissl.cc b/libretroshare/src/pqi/pqissl.cc index 017c3bbb2..7337fc627 100644 --- a/libretroshare/src/pqi/pqissl.cc +++ b/libretroshare/src/pqi/pqissl.cc @@ -1262,8 +1262,10 @@ int pqissl::accept_locked( SSL *ssl, int fd, if (rsPeers->servicePermissionFlags(PeerId()) & RS_NODE_PERM_REQUIRE_WL) checking_flags |= RSBANLIST_CHECKING_FLAGS_WHITELIST; - if(rsBanList && !rsBanList->isAddressAccepted( - foreign_addr, checking_flags, check_result )) + if( RsX509Cert::getCertSslId(*SSL_get_peer_certificate(ssl)) != PeerId()) + std::cerr << "(EE) pqissl::accept_locked(): PeerId() is " << PeerId() << " but certificate ID is " << RsX509Cert::getCertSslId(*SSL_get_peer_certificate(ssl)) << std::endl; + + if(rsBanList && !rsBanList->isAddressAccepted( foreign_addr, checking_flags, check_result )) { RsErr() << __PRETTY_FUNCTION__ << " Refusing incoming SSL connection from blacklisted " @@ -1273,11 +1275,19 @@ int pqissl::accept_locked( SSL *ssl, int fd, << std::endl; print_stacktrace(); - RsServer::notify()->AddFeedItem( - RS_FEED_ITEM_SEC_IP_BLACKLISTED, - PeerId().toStdString(), - sockaddr_storage_iptostring(foreign_addr), "", "", - check_result); + if(rsEvents) + { + auto ev = std::make_shared(); + + X509 *x509 = SSL_get_peer_certificate(ssl) ; + + ev->mSslId = RsX509Cert::getCertSslId(*x509); + ev->mLocator = RsUrl(foreign_addr); + ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::IP_IS_BLACKLISTED; + + rsEvents->postEvent(ev); + } + reset_locked(); return failure; } diff --git a/libretroshare/src/retroshare/rsevents.h b/libretroshare/src/retroshare/rsevents.h index 123cfaf3e..d03d3ab32 100644 --- a/libretroshare/src/retroshare/rsevents.h +++ b/libretroshare/src/retroshare/rsevents.h @@ -70,6 +70,9 @@ enum class RsEventType : uint32_t /// @see RsMailStatusEvent MAIL_STATUS_CHANGE = 7, + /// @see RsGxsCircleEvent + GXS_CIRCLES = 8, + MAX /// Used to detect invalid event type passed }; diff --git a/libretroshare/src/retroshare/rsgxscircles.h b/libretroshare/src/retroshare/rsgxscircles.h index 407871d80..f9262b3a8 100644 --- a/libretroshare/src/retroshare/rsgxscircles.h +++ b/libretroshare/src/retroshare/rsgxscircles.h @@ -123,7 +123,7 @@ struct RsGxsCircleDetails : RsSerializable { RsGxsCircleDetails() : mCircleType(static_cast(RsGxsCircleType::EXTERNAL)), - mAmIAllowed(false) {} + mAmIAllowed(false),mAmIAdmin(false) {} ~RsGxsCircleDetails() override; RsGxsCircleId mCircleId; @@ -136,6 +136,9 @@ struct RsGxsCircleDetails : RsSerializable * list & subscribed list). */ bool mAmIAllowed; + /// true when we're an administrator of the circle group, meaning that we can add/remove members from the invitee list. + bool mAmIAdmin; + /// This crosses admin list and subscribed list std::set mAllowedGxsIds; std::set mAllowedNodes; @@ -152,12 +155,41 @@ struct RsGxsCircleDetails : RsSerializable RS_SERIAL_PROCESS(mCircleType); RS_SERIAL_PROCESS(mRestrictedCircleId); RS_SERIAL_PROCESS(mAmIAllowed); + RS_SERIAL_PROCESS(mAmIAdmin); RS_SERIAL_PROCESS(mAllowedGxsIds); RS_SERIAL_PROCESS(mAllowedNodes); RS_SERIAL_PROCESS(mSubscriptionFlags); } }; +struct RsGxsCircleEvent: RsEvent +{ + RsGxsCircleEvent() + : RsEvent(RsEventType::GXS_CIRCLES), mCircleEventType(UNKNOWN) {} + + enum CircleEventType: uint8_t { + UNKNOWN = 0x00, + CIRCLE_MEMBERSHIP_REQUEST = 0x01, // mCircleId contains the circle id and mGxsId is the id requesting membership + CIRCLE_MEMBERSHIP_INVITE = 0x02, // mCircleId is the circle that invites me, and mGxsId is my own Id that is invited + CIRCLE_MEMBERSHIP_LEAVE = 0x03, // mCircleId contains the circle id and mGxsId is the id dropping membership + CIRCLE_MEMBERSHIP_JOIN = 0x04, // mCircleId contains the circle id and mGxsId is the id of the new member + CIRCLE_MEMBERSHIP_REVOQUED= 0x05, // mCircleId contains the circle id and mGxsId is the id that was revoqued by admin + }; + + CircleEventType mCircleEventType; + RsGxsCircleId mCircleId; + RsGxsId mGxsId; + + ///* @see RsEvent @see RsSerializable + void serial_process( RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) override + { + RsEvent::serial_process(j, ctx); + RS_SERIAL_PROCESS(mCircleEventType); + RS_SERIAL_PROCESS(mCircleId); + RS_SERIAL_PROCESS(mGxsId); + } +}; + class RsGxsCircles: public RsGxsIfaceHelper { public: @@ -243,6 +275,17 @@ public: */ virtual bool getCircleRequests( const RsGxsGroupId& circleId, std::vector& requests ) = 0; + /** + * @brief Get specific circle request + * @jsonapi{development} + * @param[in] circleId id of the circle of which the requests are requested + * @param[in] msgId id of the request + * @param[out] msg storage for the circle request + * @return false if something failed, true otherwhise + */ + virtual bool getCircleRequest(const RsGxsGroupId& circleId, + const RsGxsMessageId& msgId, + RsGxsCircleMsg& msg) =0; /** * @brief Invite identities to circle diff --git a/libretroshare/src/retroshare/rsnotify.h b/libretroshare/src/retroshare/rsnotify.h index 6cb55dd66..d69357cdb 100644 --- a/libretroshare/src/retroshare/rsnotify.h +++ b/libretroshare/src/retroshare/rsnotify.h @@ -115,8 +115,11 @@ const uint32_t RS_FEED_ITEM_CHAT_NEW = RS_FEED_TYPE_CHAT | 0x0001; const uint32_t RS_FEED_ITEM_MESSAGE = RS_FEED_TYPE_MSG | 0x0001; const uint32_t RS_FEED_ITEM_FILES_NEW = RS_FEED_TYPE_FILES | 0x0001; -const uint32_t RS_FEED_ITEM_CIRCLE_MEMB_REQ = RS_FEED_TYPE_CIRCLE | 0x0001; -const uint32_t RS_FEED_ITEM_CIRCLE_INVIT_REC = RS_FEED_TYPE_CIRCLE | 0x0002; +const uint32_t RS_FEED_ITEM_CIRCLE_MEMB_REQ = RS_FEED_TYPE_CIRCLE | 0x0001; +const uint32_t RS_FEED_ITEM_CIRCLE_INVIT_REC = RS_FEED_TYPE_CIRCLE | 0x0002; +const uint32_t RS_FEED_ITEM_CIRCLE_MEMB_LEAVE = RS_FEED_TYPE_CIRCLE | 0x0003; +const uint32_t RS_FEED_ITEM_CIRCLE_MEMB_JOIN = RS_FEED_TYPE_CIRCLE | 0x0004; +const uint32_t RS_FEED_ITEM_CIRCLE_MEMB_REVOQUED = RS_FEED_TYPE_CIRCLE | 0x0005; const uint32_t RS_MESSAGE_CONNECT_ATTEMPT = 0x0001; diff --git a/libretroshare/src/services/p3gxscircles.cc b/libretroshare/src/services/p3gxscircles.cc index eed23313d..658af5892 100644 --- a/libretroshare/src/services/p3gxscircles.cc +++ b/libretroshare/src/services/p3gxscircles.cc @@ -305,6 +305,32 @@ bool p3GxsCircles::getCircleRequests( const RsGxsGroupId& circleId, return getMsgData(token, requests); } +bool p3GxsCircles::getCircleRequest(const RsGxsGroupId& circleId,const RsGxsMessageId& msgId,RsGxsCircleMsg& msg) +{ + RsTokReqOptions opts; + opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA; + + std::set contentsIds; + contentsIds.insert(msgId); + + GxsMsgReq msgIds; + msgIds[circleId] = contentsIds; + + uint32_t token; + if( !requestMsgInfo(token, opts, msgIds) || waitToken(token) != RsTokenService::COMPLETE ) + return false; + + std::vector msgs; + + if(getMsgData(token, msgs) && msgs.size() == 1) + { + msg = msgs.front(); + return true; + } + else + return false; +} + bool p3GxsCircles::inviteIdsToCircle( const std::set& identities, const RsGxsCircleId& circleId ) { @@ -372,6 +398,7 @@ void p3GxsCircles::service_tick() return; } + void p3GxsCircles::notifyChanges(std::vector &changes) { #ifdef DEBUG_CIRCLES @@ -397,13 +424,35 @@ void p3GxsCircles::notifyChanges(std::vector &changes) #ifdef DEBUG_CIRCLES std::cerr << " Msgs for Group: " << mit->first << std::endl; #endif - force_cache_reload(RsGxsCircleId(mit->first)); + RsGxsCircleId circle_id(mit->first); - if (notify && (c->getType() == RsGxsNotify::TYPE_RECEIVED_NEW) ) + force_cache_reload(circle_id); + + RsGxsCircleDetails details; + getCircleDetails(circle_id,details); + + if(rsEvents && (c->getType() == RsGxsNotify::TYPE_RECEIVED_NEW) ) for (auto msgIdIt(mit->second.begin()), end(mit->second.end()); msgIdIt != end; ++msgIdIt) { - const RsGxsMessageId& msgId = *msgIdIt; - notify->AddFeedItem(RS_FEED_ITEM_CIRCLE_MEMB_REQ,RsGxsCircleId(mit->first).toStdString(),msgId.toStdString()); + // @Gio: should this be async? + RsGxsCircleMsg msg; + getCircleRequest(RsGxsGroupId(circle_id),*msgIdIt,msg); + + // notify->AddFeedItem(RS_FEED_ITEM_CIRCLE_MEMB_REQ,RsGxsCircleId(mit->first).toStdString(),msgId.toStdString()); + + auto ev = std::make_shared(); + + ev->mCircleId = circle_id; + ev->mGxsId = msg.mMeta.mAuthorId; + + if (msg.stuff == "SUBSCRIPTION_REQUEST_UNSUBSCRIBE") + ev->mCircleEventType = RsGxsCircleEvent::CIRCLE_MEMBERSHIP_LEAVE; + else if(details.mAllowedGxsIds.find(msg.mMeta.mAuthorId) != details.mAllowedGxsIds.end()) + ev->mCircleEventType = RsGxsCircleEvent::CIRCLE_MEMBERSHIP_JOIN; + else + ev->mCircleEventType = RsGxsCircleEvent::CIRCLE_MEMBERSHIP_REQUEST; + + rsEvents->sendEvent(ev); } } @@ -436,15 +485,60 @@ void p3GxsCircles::notifyChanges(std::vector &changes) } if(groupChange) + { + std::list own_ids; + rsIdentity->getOwnIds(own_ids); + for(std::list::const_iterator git(groupChange->mGrpIdList.begin());git!=groupChange->mGrpIdList.end();++git) { #ifdef DEBUG_CIRCLES std::cerr << " forcing cache loading for circle " << *git << " in order to trigger subscribe update." << std::endl; #endif - force_cache_reload(RsGxsCircleId(*git)) ; - if (notify && (c->getType() == RsGxsNotify::TYPE_RECEIVED_NEW) ) - notify->AddFeedItem(RS_FEED_ITEM_CIRCLE_INVIT_REC,RsGxsCircleId(*git).toStdString(),""); - } + +#ifdef TODO + // This code will not work: we would like to detect changes in the circle data that reflects the fact that one of the + // owned GXS ids is invited. But there's no way to compare the old circle data to the new if cache has to be updated. + // For this we need to add the old metadata and group data in the RsGxsGroupChange structure and account for it. + + if(rsEvents && (c->getType() == RsGxsNotify::TYPE_RECEIVED_NEW) ) + { + RsGxsCircleId circle_id(*git); + force_cache_reload(circle_id); + + RsGxsCircleDetails details; + getCircleDetails(circle_id,details); + + // We check that the change corresponds to one of our own ids. Since we do not know what the change is, we notify + // for whatever is different from what is currently known. Other ids, that get invited only trigger a notification when the + // ID also accepts the invitation, so it becomes a member of the circle. + + for(auto own_id: own_ids) + { + auto it = details.mSubscriptionFlags.find(own_id); + + if(it == details.mSubscriptionFlags.end()) + continue; + + bool invited ( it->second & GXS_EXTERNAL_CIRCLE_FLAGS_IN_ADMIN_LIST ); + bool subscrb ( it->second & GXS_EXTERNAL_CIRCLE_FLAGS_SUBSCRIBED ); + + if(std::find(details.mAllowedGxsIds.begin(),details.mAllowedGxsIds.end(),id) != details.mAllowedGxsIds.end() && !me_in_circle) + { + auto ev = std::make_shared(); + + ev->mType = RsGxsCircleEvent::CIRCLE_MEMBERSHIP_INVITE; + ev->mCircleId = circle_id; + ev->mGxsId = ; + + rsEvents->sendEvent(ev); + } + } + + //notify->AddFeedItem(RS_FEED_ITEM_CIRCLE_INVIT_REC,RsGxsCircleId(*git).toStdString(),""); + } +#endif + } + } } RsGxsIfaceHelper::receiveChanges(changes); // this clear up the vector and delete its elements @@ -479,6 +573,7 @@ bool p3GxsCircles:: getCircleDetails(const RsGxsCircleId &id, RsGxsCircleDetails details.mSubscriptionFlags.clear(); details.mAllowedGxsIds.clear(); details.mAmIAllowed = false ; + details.mAmIAdmin = bool(data.mGroupSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_ADMIN); for(std::map::const_iterator it(data.mMembershipStatus.begin());it!=data.mMembershipStatus.end();++it) { @@ -789,7 +884,7 @@ RsGxsCircleCache::RsGxsCircleCache() mUpdateTime = 0; mGroupStatus = 0; mGroupSubscribeFlags = 0; - mLastUpdatedMembershipTS = 0 ; + mLastUpdatedMembershipTS = 0 ; return; } diff --git a/libretroshare/src/services/p3gxscircles.h b/libretroshare/src/services/p3gxscircles.h index 9eb6c15bb..1b25fcf27 100644 --- a/libretroshare/src/services/p3gxscircles.h +++ b/libretroshare/src/services/p3gxscircles.h @@ -207,6 +207,11 @@ virtual RsServiceInfo getServiceInfo(); bool inviteIdsToCircle( const std::set& identities, const RsGxsCircleId& circleId ) override; + /// @see RsGxsCircles + bool getCircleRequest(const RsGxsGroupId& circleId, + const RsGxsMessageId& msgId, + RsGxsCircleMsg& msg) override; + virtual bool getCircleDetails(const RsGxsCircleId &id, RsGxsCircleDetails &details); virtual bool getCircleExternalIdList(std::list &circleIds); diff --git a/retroshare-gui/src/gui/NewsFeed.cpp b/retroshare-gui/src/gui/NewsFeed.cpp index b4f582db5..942262b8d 100644 --- a/retroshare-gui/src/gui/NewsFeed.cpp +++ b/retroshare-gui/src/gui/NewsFeed.cpp @@ -82,7 +82,6 @@ NewsFeed::NewsFeed(QWidget *parent) : ui->setupUi(this); mTokenQueueChannel = NULL; - mTokenQueueCircle = NULL; mTokenQueueForum = NULL; mTokenQueuePosted = NULL; @@ -139,9 +138,6 @@ NewsFeed::~NewsFeed() if (mTokenQueueChannel) { delete(mTokenQueueChannel); } - if (mTokenQueueCircle) { - delete(mTokenQueueCircle); - } if (mTokenQueueForum) { delete(mTokenQueueForum); } @@ -198,10 +194,61 @@ void NewsFeed::handleEvent_main_thread(std::shared_ptr event) if(event->mType == RsEventType::AUTHSSL_CONNECTION_AUTENTICATION && (flags & RS_FEED_TYPE_SECURITY)) handleSecurityEvent(event); - if(event->mType == RsEventType::PEER_CONNECTION && (flags & RS_FEED_TYPE_PEER)) + if(event->mType == RsEventType::PEER_CONNECTION && (flags & RS_FEED_TYPE_PEER)) handleConnectionEvent(event); + + if(event->mType == RsEventType::GXS_CIRCLES && (flags & RS_FEED_TYPE_CIRCLE)) + handleCircleEvent(event); } +void NewsFeed::handleCircleEvent(std::shared_ptr event) +{ + const RsGxsCircleEvent *pe = dynamic_cast(event.get()); + if(!pe) + return; + + RsGxsCircleDetails details; + + if(!rsGxsCircles->getCircleDetails(pe->mCircleId,details)) + { + std::cerr << "(EE) Cannot get information about circle " << pe->mCircleId << ". Not in cache?" << std::endl; + return; + } + + // Check if the circle is one of which we belong to. If so, then notify in the GUI about other members leaving/subscribing + + if(details.mAmIAllowed || details.mAmIAdmin) + { + switch(pe->mCircleEventType) + { + case RsGxsCircleEvent::CIRCLE_MEMBERSHIP_REQUEST: // only show membership requests if we're an admin of that circle + if(details.mAmIAdmin) + addFeedItemIfUnique(new GxsCircleItem(this, NEWSFEED_CIRCLELIST, pe->mCircleId, pe->mGxsId, RS_FEED_ITEM_CIRCLE_MEMB_REQ),true); + break; + + case RsGxsCircleEvent::CIRCLE_MEMBERSHIP_JOIN: + addFeedItemIfUnique(new GxsCircleItem(this, NEWSFEED_CIRCLELIST, pe->mCircleId, pe->mGxsId, RS_FEED_ITEM_CIRCLE_MEMB_JOIN),true); + break; + + case RsGxsCircleEvent::CIRCLE_MEMBERSHIP_LEAVE: + addFeedItemIfUnique(new GxsCircleItem(this, NEWSFEED_CIRCLELIST, pe->mCircleId, pe->mGxsId, RS_FEED_ITEM_CIRCLE_MEMB_LEAVE),true); + break; + + case RsGxsCircleEvent::CIRCLE_MEMBERSHIP_INVITE: + addFeedItemIfUnique(new GxsCircleItem(this, NEWSFEED_CIRCLELIST, pe->mCircleId, pe->mGxsId, RS_FEED_ITEM_CIRCLE_INVIT_REC),true); + break; + + case RsGxsCircleEvent::CIRCLE_MEMBERSHIP_REVOQUED: + addFeedItemIfUnique(new GxsCircleItem(this, NEWSFEED_CIRCLELIST, pe->mCircleId, pe->mGxsId, RS_FEED_ITEM_CIRCLE_MEMB_REVOQUED),true); + break; + + default: + break; + } + } +} + + void NewsFeed::handleConnectionEvent(std::shared_ptr event) { const RsConnectionEvent *pe = dynamic_cast(event.get()); @@ -422,51 +469,6 @@ void NewsFeed::updateDisplay() addFeedItemFilesNew(fi); break; - case RS_FEED_ITEM_CIRCLE_MEMB_REQ: - if (flags & RS_FEED_TYPE_CIRCLE) - { - if (!mTokenQueueCircle) { - mTokenQueueCircle = new TokenQueue(rsGxsCircles->getTokenService(), instance); - } - - RsGxsGroupId grpId(fi.mId1); - RsGxsMessageId msgId(fi.mId2); - if (!grpId.isNull() && !msgId.isNull()) { - RsTokReqOptions opts; - opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA; - - GxsMsgReq msgIds; - std::set &vect_msgIds = msgIds[grpId]; - vect_msgIds.insert(msgId); - - uint32_t token; - mTokenQueueCircle->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, msgIds, TOKEN_TYPE_MESSAGE); - } - } - // addFeedItemCircleMembReq(fi); - break; - case RS_FEED_ITEM_CIRCLE_INVIT_REC: - if (flags & RS_FEED_TYPE_CIRCLE) - { - if (!mTokenQueueCircle) { - mTokenQueueCircle = new TokenQueue(rsGxsCircles->getTokenService(), instance); - } - - RsGxsGroupId grpId(fi.mId1); - if (!grpId.isNull()) { - RsTokReqOptions opts; - opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA; - - std::list grpIds; - grpIds.push_back(grpId); - - uint32_t token; - mTokenQueueCircle->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_SUMMARY, opts, grpIds, TOKEN_TYPE_GROUP); - } - } - // addFeedItemCircleInvitRec(fi); - break; - default: std::cerr << "(EE) Unknown type " << std::hex << fi.mType << std::dec << " in news feed." << std::endl; break; @@ -658,6 +660,7 @@ void NewsFeed::testFeeds(uint notifyFlags) #endif } +#ifdef TO_REMOVE void NewsFeed::loadCircleGroup(const uint32_t &token) { std::vector groups; @@ -694,41 +697,7 @@ void NewsFeed::loadCircleGroup(const uint32_t &token) } } } - -void NewsFeed::loadCircleMessage(const uint32_t &token) -{ - std::vector msgs; - if (!rsGxsCircles->getMsgData(token, msgs)) { - std::cerr << "NewsFeed::loadCircleMessage() ERROR getting data"; - std::cerr << std::endl; - return; - } - - std::list own_identities; - rsIdentity->getOwnIds(own_identities); - - std::vector::iterator msgIt; - for (msgIt = msgs.begin(); msgIt != msgs.end(); ++msgIt) { - RsGxsCircleMsg msg = *(msgIt); - RsGxsCircleDetails details; - if(rsGxsCircles->getCircleDetails(RsGxsCircleId(msg.mMeta.mGroupId),details)) { - //for(std::list::const_iterator it(own_identities.begin());it!=own_identities.end();++it) { - // std::map::const_iterator vit = details.mSubscriptionFlags.find(*it); - // if (vit != details.mSubscriptionFlags.end()) { - RsFeedItem fi; - fi.mId1 = msgIt->mMeta.mGroupId.toStdString(); - fi.mId2 = msgIt->mMeta.mAuthorId.toStdString(); - - if (msgIt->stuff == "SUBSCRIPTION_REQUEST_UNSUBSCRIBE") - instance->remFeedItemCircleMembReq(fi); - else - instance->addFeedItemCircleMembReq(fi); - - //} - //} - } - } -} +#endif void NewsFeed::loadChannelGroup(const uint32_t &token) { @@ -1025,6 +994,7 @@ void NewsFeed::loadRequest(const TokenQueue *queue, const TokenRequest &req) } } +#ifdef TO_REMOVE if (queue == mTokenQueueCircle) { switch (req.mUserType) { case TOKEN_TYPE_GROUP: @@ -1041,6 +1011,7 @@ void NewsFeed::loadRequest(const TokenQueue *queue, const TokenRequest &req) break; } } +#endif if (queue == mTokenQueueForum) { switch (req.mUserType) { @@ -1562,6 +1533,7 @@ void NewsFeed::addFeedItemFilesNew(const RsFeedItem &/*fi*/) #endif } +#ifdef TO_REMOVE void NewsFeed::addFeedItemCircleMembReq(const RsFeedItem &fi) { RsGxsCircleId circleId(fi.mId1); @@ -1621,6 +1593,7 @@ void NewsFeed::addFeedItemCircleInvitRec(const RsFeedItem &fi) std::cerr << "NewsFeed::addFeedItemCircleInvitRec()" << std::endl; #endif } +#endif /* FeedHolder Functions (for FeedItem functionality) */ QScrollArea *NewsFeed::getScrollArea() diff --git a/retroshare-gui/src/gui/NewsFeed.h b/retroshare-gui/src/gui/NewsFeed.h index 52164330b..08cde3660 100644 --- a/retroshare-gui/src/gui/NewsFeed.h +++ b/retroshare-gui/src/gui/NewsFeed.h @@ -102,9 +102,11 @@ private slots: void sendNewsFeedChanged(); private: + void handleEvent_main_thread(std::shared_ptr event); + void handleSecurityEvent(std::shared_ptr event); void handleConnectionEvent(std::shared_ptr event); - void handleEvent_main_thread(std::shared_ptr event); + void handleCircleEvent(std::shared_ptr event); void addFeedItem(FeedItem *item); void addFeedItemIfUnique(FeedItem *item, bool replace); @@ -160,9 +162,6 @@ private: virtual void loadPostedGroup(const uint32_t &token); virtual void loadPostedMessage(const uint32_t &token); - virtual void loadCircleGroup(const uint32_t &token); - virtual void loadCircleMessage(const uint32_t &token); - private: TokenQueue *mTokenQueueChannel; TokenQueue *mTokenQueueCircle; diff --git a/retroshare-gui/src/gui/feeds/GxsCircleItem.cpp b/retroshare-gui/src/gui/feeds/GxsCircleItem.cpp index 8cd67d28f..582d1be47 100644 --- a/retroshare-gui/src/gui/feeds/GxsCircleItem.cpp +++ b/retroshare-gui/src/gui/feeds/GxsCircleItem.cpp @@ -91,12 +91,18 @@ void GxsCircleItem::setup() ui->iconLabel->setPixmap(pixmap); ui->gxsIdLabel->setId(mGxsId); - - - ui->acceptButton->setToolTip(tr("Grant membership request")); - ui->revokeButton->setToolTip(tr("Revoke membership request")); - connect(ui->acceptButton, SIGNAL(clicked()), this, SLOT(grantCircleMembership())); - connect(ui->revokeButton, SIGNAL(clicked()), this, SLOT(revokeCircleMembership())); + if(circleDetails.mAmIAdmin) + { + ui->acceptButton->setToolTip(tr("Grant membership request")); + ui->revokeButton->setToolTip(tr("Revoke membership request")); + connect(ui->acceptButton, SIGNAL(clicked()), this, SLOT(grantCircleMembership())); + connect(ui->revokeButton, SIGNAL(clicked()), this, SLOT(revokeCircleMembership())); + } + else + { + ui->acceptButton->setEnabled(false); + ui->revokeButton->setEnabled(false); + } } else if (mType == RS_FEED_ITEM_CIRCLE_INVIT_REC) { @@ -110,7 +116,43 @@ void GxsCircleItem::setup() connect(ui->acceptButton, SIGNAL(clicked()), this, SLOT(acceptCircleSubscription())); ui->revokeButton->setHidden(true); } + else if (mType == RS_FEED_ITEM_CIRCLE_MEMB_LEAVE) + { + ui->titleLabel->setText(idName + tr(" has left this circle you belong to.")); + ui->nameLabel->setText(QString::fromUtf8(circleDetails.mCircleName.c_str())); + ui->gxsIdLabel->setText(idName); + ui->iconLabel->setPixmap(pixmap); + ui->gxsIdLabel->setId(mGxsId); + ui->acceptButton->setHidden(true); + ui->revokeButton->setHidden(true); + } + else if (mType == RS_FEED_ITEM_CIRCLE_MEMB_JOIN) + { + ui->titleLabel->setText(idName + tr(" has join this circle you also belong to.")); + ui->nameLabel->setText(QString::fromUtf8(circleDetails.mCircleName.c_str())); + ui->gxsIdLabel->setText(idName); + ui->iconLabel->setPixmap(pixmap); + ui->gxsIdLabel->setId(mGxsId); + + ui->acceptButton->setHidden(true); + ui->revokeButton->setHidden(true); + } + else if (mType == RS_FEED_ITEM_CIRCLE_MEMB_REVOQUED) + { + if(rsIdentity->isOwnId(mGxsId)) + ui->titleLabel->setText(tr("Your identity %1 has been revoqued from this circle.").arg(idName)); + else + ui->titleLabel->setText(tr("Identity %1 has been revoqued from this circle you belong to.").arg(idName)); + + ui->nameLabel->setText(QString::fromUtf8(circleDetails.mCircleName.c_str())); + ui->gxsIdLabel->setText(idName); + ui->iconLabel->setPixmap(pixmap); + ui->gxsIdLabel->setId(mGxsId); + + ui->acceptButton->setHidden(true); + ui->revokeButton->setHidden(true); + } } else { From 4fe6e464100ba52c3d790c6b4a5449174913401c Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 12 Dec 2019 21:23:42 +0100 Subject: [PATCH 17/39] added handling of channel, forum and posted events in GUI --- libretroshare/src/retroshare/rsevents.h | 11 +- libretroshare/src/retroshare/rsgxschannels.h | 28 +++++ libretroshare/src/retroshare/rsgxsforums.h | 27 +++++ libretroshare/src/retroshare/rsposted.h | 26 +++++ retroshare-gui/src/gui/NewsFeed.cpp | 106 ++++++++++++++----- retroshare-gui/src/gui/NewsFeed.h | 50 +-------- 6 files changed, 174 insertions(+), 74 deletions(-) diff --git a/libretroshare/src/retroshare/rsevents.h b/libretroshare/src/retroshare/rsevents.h index d03d3ab32..9e0d81cc2 100644 --- a/libretroshare/src/retroshare/rsevents.h +++ b/libretroshare/src/retroshare/rsevents.h @@ -61,7 +61,7 @@ enum class RsEventType : uint32_t /// @see pqissl PEER_CONNECTION = 4, - /// @see RsGxsChanges + /// @see RsGxsChanges // this one should probably be removed because it's not used anywhere GXS_CHANGES = 5, /// Emitted when a peer state changes, @see RsPeers @@ -73,6 +73,15 @@ enum class RsEventType : uint32_t /// @see RsGxsCircleEvent GXS_CIRCLES = 8, + /// @see RsGxsChannelEvent + GXS_CHANNELS = 9, + + /// @see RsGxsForumEvent + GXS_FORUMS = 10, + + /// @see RsGxsPostedEvent + GXS_POSTED = 11, + MAX /// Used to detect invalid event type passed }; diff --git a/libretroshare/src/retroshare/rsgxschannels.h b/libretroshare/src/retroshare/rsgxschannels.h index 4b82792f2..378f6d1b6 100644 --- a/libretroshare/src/retroshare/rsgxschannels.h +++ b/libretroshare/src/retroshare/rsgxschannels.h @@ -102,6 +102,34 @@ struct RsGxsChannelPost : RsSerializable ~RsGxsChannelPost() override; }; +struct RsGxsChannelEvent: RsEvent +{ + RsGxsChannelEvent() + : RsEvent(RsEventType::GXS_CHANNELS), mChannelEventCode(UNKNOWN) {} + + enum ChannelEventCode: uint8_t { + UNKNOWN = 0x00, + NEW_CHANNEL = 0x01, // emitted when new channel is received + UPDATED_CHANNEL = 0x02, // emitted when existing channel is updated + NEW_MESSAGE = 0x03, // new message reeived in a particular channel (group and msg id) + UPDATED_MESSAGE = 0x04, // existing message has been updated in a particular channel (group and msg id) + RECEIVED_PUBLISH_KEY = 0x05, // publish key for this channel has been received. + }; + + ChannelEventCode mChannelEventCode; + RsGxsGroupId mChannelGroupId; + RsGxsMessageId mChannelMsgId; + + ///* @see RsEvent @see RsSerializable + void serial_process( RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) override + { + RsEvent::serial_process(j, ctx); + + RS_SERIAL_PROCESS(mChannelEventCode); + RS_SERIAL_PROCESS(mChannelGroupId); + RS_SERIAL_PROCESS(mChannelMsgId); + } +}; class RsGxsChannels: public RsGxsIfaceHelper, public RsGxsCommentService { diff --git a/libretroshare/src/retroshare/rsgxsforums.h b/libretroshare/src/retroshare/rsgxsforums.h index 3be38691d..cb3e42eb9 100644 --- a/libretroshare/src/retroshare/rsgxsforums.h +++ b/libretroshare/src/retroshare/rsgxsforums.h @@ -104,6 +104,33 @@ struct RsGxsForumMsg : RsSerializable ~RsGxsForumMsg() override; }; +struct RsGxsForumEvent: RsEvent +{ + RsGxsForumEvent() + : RsEvent(RsEventType::GXS_FORUMS), mForumEventCode(UNKNOWN) {} + + enum ForumEventCode: uint8_t { + UNKNOWN = 0x00, + NEW_FORUM = 0x01, // emitted when new forum is received + UPDATED_FORUM = 0x02, // emitted when existing forum is updated + NEW_MESSAGE = 0x03, // new message reeived in a particular forum (group and msg id) + UPDATED_MESSAGE = 0x04, // existing message has been updated in a particular forum (group and msg id) + }; + + ForumEventCode mForumEventCode; + RsGxsGroupId mForumGroupId; + RsGxsMessageId mForumMsgId; + + ///* @see RsEvent @see RsSerializable + void serial_process( RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) override + { + RsEvent::serial_process(j, ctx); + + RS_SERIAL_PROCESS(mForumEventCode); + RS_SERIAL_PROCESS(mForumGroupId); + RS_SERIAL_PROCESS(mForumMsgId); + } +}; class RsGxsForums: public RsGxsIfaceHelper { diff --git a/libretroshare/src/retroshare/rsposted.h b/libretroshare/src/retroshare/rsposted.h index a42f06c40..c5c565bb0 100644 --- a/libretroshare/src/retroshare/rsposted.h +++ b/libretroshare/src/retroshare/rsposted.h @@ -68,6 +68,32 @@ class RsPostedGroup std::ostream &operator<<(std::ostream &out, const RsPostedGroup &group); std::ostream &operator<<(std::ostream &out, const RsPostedPost &post); +struct RsGxsPostedEvent: RsEvent +{ + RsGxsPostedEvent() + : RsEvent(RsEventType::GXS_POSTED), mPostedEventCode(UNKNOWN) {} + + enum PostedEventCode: uint8_t { + UNKNOWN = 0x00, + NEW_POSTED_GROUP = 0x01, + NEW_MESSAGE = 0x02 + }; + + PostedEventCode mPostedEventCode; + RsPeerId mAuthorId; + RsGxsGroupId mPostedGroupId; + RsGxsMessageId mPostedMsgId; + + ///* @see RsEvent @see RsSerializable + void serial_process( RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) override + { + RsEvent::serial_process(j, ctx); + RS_SERIAL_PROCESS(mPostedEventCode); + RS_SERIAL_PROCESS(mAuthorId); + RS_SERIAL_PROCESS(mPostedGroupId); + RS_SERIAL_PROCESS(mPostedMsgId); + } +}; class RsPosted : public RsGxsIfaceHelper, public RsGxsCommentService { diff --git a/retroshare-gui/src/gui/NewsFeed.cpp b/retroshare-gui/src/gui/NewsFeed.cpp index 942262b8d..7be597630 100644 --- a/retroshare-gui/src/gui/NewsFeed.cpp +++ b/retroshare-gui/src/gui/NewsFeed.cpp @@ -81,10 +81,6 @@ NewsFeed::NewsFeed(QWidget *parent) : /* Invoke the Qt Designer generated object setup routine */ ui->setupUi(this); - mTokenQueueChannel = NULL; - mTokenQueueForum = NULL; - mTokenQueuePosted = NULL; - setUpdateWhenInvisible(true); if (!instance) { @@ -134,16 +130,6 @@ NewsFeed::~NewsFeed() if (instance == this) { instance = NULL; } - - if (mTokenQueueChannel) { - delete(mTokenQueueChannel); - } - if (mTokenQueueForum) { - delete(mTokenQueueForum); - } - if (mTokenQueuePosted) { - delete(mTokenQueuePosted); - } } UserNotify *NewsFeed::getUserNotify(QObject *parent) @@ -199,6 +185,79 @@ void NewsFeed::handleEvent_main_thread(std::shared_ptr event) if(event->mType == RsEventType::GXS_CIRCLES && (flags & RS_FEED_TYPE_CIRCLE)) handleCircleEvent(event); + + if(event->mType == RsEventType::GXS_CHANNELS && (flags & RS_FEED_TYPE_CHANNEL)) + handleChannelEvent(event); + + if(event->mType == RsEventType::GXS_FORUMS && (flags & RS_FEED_TYPE_FORUM)) + handleForumEvent(event); + + if(event->mType == RsEventType::GXS_POSTED && (flags & RS_FEED_TYPE_POSTED)) + handlePostedEvent(event); +} + +void NewsFeed::handlePostedEvent(std::shared_ptr event) +{ + const RsGxsPostedEvent *pe = dynamic_cast(event.get()); + if(!pe) + return; + + switch(pe->mPostedEventCode) + { + case RsGxsPostedEvent::NEW_POSTED_GROUP: addFeedItem( new PostedGroupItem(this, NEWSFEED_POSTEDNEWLIST, pe->mPostedGroupId, false, true)); + break; + + case RsGxsPostedEvent::NEW_MESSAGE: addFeedItem( new PostedItem(this, NEWSFEED_POSTEDMSGLIST, pe->mPostedGroupId, pe->mPostedMsgId, false, true)); + break; + + default: + break; + } +} + +void NewsFeed::handleForumEvent(std::shared_ptr event) +{ + const RsGxsForumEvent *pe = dynamic_cast(event.get()); + if(!pe) + return; + + switch(pe->mForumEventCode) + { + case RsGxsForumEvent::UPDATED_FORUM: + case RsGxsForumEvent::NEW_FORUM: addFeedItem(new GxsForumGroupItem(this, NEWSFEED_FORUMNEWLIST, pe->mForumGroupId, false, true)); + break; + + case RsGxsForumEvent::UPDATED_MESSAGE: + case RsGxsForumEvent::NEW_MESSAGE: addFeedItem(new GxsForumMsgItem(this, NEWSFEED_FORUMNEWLIST, pe->mForumGroupId, pe->mForumMsgId, false, true)); + break; + + default: + break; + } +} + +void NewsFeed::handleChannelEvent(std::shared_ptr event) +{ + const RsGxsChannelEvent *pe = dynamic_cast(event.get()); + if(!pe) + return; + + switch(pe->mChannelEventCode) + { + case RsGxsChannelEvent::UPDATED_CHANNEL: + case RsGxsChannelEvent::NEW_CHANNEL: addFeedItem(new GxsChannelGroupItem(this, NEWSFEED_CHANNELNEWLIST, pe->mChannelGroupId, false, true)); + break; + + case RsGxsChannelEvent::UPDATED_MESSAGE: + case RsGxsChannelEvent::NEW_MESSAGE: addFeedItem(new GxsChannelPostItem(this, NEWSFEED_CHANNELNEWLIST, pe->mChannelGroupId, pe->mChannelMsgId, false, true)); + break; + + case RsGxsChannelEvent::RECEIVED_PUBLISH_KEY: addFeedItem(new GxsChannelGroupItem(this, NEWSFEED_CHANNELPUBKEYLIST, pe->mChannelGroupId, false, true)); + break; + + default: + break; + } } void NewsFeed::handleCircleEvent(std::shared_ptr event) @@ -248,7 +307,6 @@ void NewsFeed::handleCircleEvent(std::shared_ptr event) } } - void NewsFeed::handleConnectionEvent(std::shared_ptr event) { const RsConnectionEvent *pe = dynamic_cast(event.get()); @@ -360,7 +418,6 @@ 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) @@ -442,6 +499,7 @@ void NewsFeed::updateDisplay() if (flags & RS_FEED_TYPE_POSTED) addFeedItemPostedMsg(fi); break; +#endif #if 0 case RS_FEED_ITEM_BLOG_NEW: @@ -494,7 +552,6 @@ void NewsFeed::updateDisplay() void NewsFeed::testFeeds(uint notifyFlags) { -#ifdef TODO if (!instance) { return; } @@ -510,6 +567,7 @@ void NewsFeed::testFeeds(uint notifyFlags) RsFeedItem fi; +#ifdef TODO switch(type) { case RS_FEED_TYPE_PEER: fi.mId1 = rsPeers->getOwnId().toStdString(); @@ -652,12 +710,12 @@ void NewsFeed::testFeeds(uint notifyFlags) break; } +#endif } instance->ui->feedWidget->enableCountChangedSignal(true); instance->sendNewsFeedChanged(); -#endif } #ifdef TO_REMOVE @@ -697,7 +755,6 @@ void NewsFeed::loadCircleGroup(const uint32_t &token) } } } -#endif void NewsFeed::loadChannelGroup(const uint32_t &token) { @@ -970,9 +1027,11 @@ void NewsFeed::loadPostedMessage(const uint32_t &token) instance->addFeedItemPostedMsg(fi); } } +#endif void NewsFeed::loadRequest(const TokenQueue *queue, const TokenRequest &req) { +#ifdef TO_REMOVE if (queue == mTokenQueueChannel) { switch (req.mUserType) { case TOKEN_TYPE_GROUP: @@ -994,7 +1053,6 @@ void NewsFeed::loadRequest(const TokenQueue *queue, const TokenRequest &req) } } -#ifdef TO_REMOVE if (queue == mTokenQueueCircle) { switch (req.mUserType) { case TOKEN_TYPE_GROUP: @@ -1011,7 +1069,6 @@ void NewsFeed::loadRequest(const TokenQueue *queue, const TokenRequest &req) break; } } -#endif if (queue == mTokenQueueForum) { switch (req.mUserType) { @@ -1050,6 +1107,7 @@ void NewsFeed::loadRequest(const TokenQueue *queue, const TokenRequest &req) break; } } +#endif } void NewsFeed::testFeed(FeedNotify *feedNotify) @@ -1167,7 +1225,6 @@ void NewsFeed::addFeedItemPeerHello(const RsFeedItem &fi) std::cerr << std::endl; #endif } -#endif void NewsFeed::addFeedItemPeerNew(const RsFeedItem &fi) { @@ -1183,7 +1240,6 @@ void NewsFeed::addFeedItemPeerNew(const RsFeedItem &fi) #endif } -#ifdef TO_REMOVE void NewsFeed::addFeedItemPeerOffset(const RsFeedItem &fi) { /* make new widget */ @@ -1254,7 +1310,6 @@ void NewsFeed::addFeedItemSecurityUnknownOut(const RsFeedItem &fi) std::cerr << std::endl; #endif } -#endif void NewsFeed::addFeedItemSecurityIpBlacklisted(const RsFeedItem &fi, bool isTest) { @@ -1270,7 +1325,6 @@ void NewsFeed::addFeedItemSecurityIpBlacklisted(const RsFeedItem &fi, bool isTes #endif } -#ifdef TO_REMOVE void NewsFeed::addFeedItemSecurityWrongExternalIpReported(const RsFeedItem &fi, bool isTest) { /* make new widget */ @@ -1284,7 +1338,6 @@ void NewsFeed::addFeedItemSecurityWrongExternalIpReported(const RsFeedItem &fi, std::cerr << std::endl; #endif } -#endif void NewsFeed::addFeedItemChannelNew(const RsFeedItem &fi) { @@ -1468,6 +1521,7 @@ void NewsFeed::addFeedItemPostedMsg(const RsFeedItem &fi) std::cerr << std::endl; #endif } +#endif #if 0 void NewsFeed::addFeedItemBlogNew(const RsFeedItem &fi) diff --git a/retroshare-gui/src/gui/NewsFeed.h b/retroshare-gui/src/gui/NewsFeed.h index 08cde3660..dba5f1f46 100644 --- a/retroshare-gui/src/gui/NewsFeed.h +++ b/retroshare-gui/src/gui/NewsFeed.h @@ -107,37 +107,13 @@ private: void handleSecurityEvent(std::shared_ptr event); void handleConnectionEvent(std::shared_ptr event); void handleCircleEvent(std::shared_ptr event); + void handleForumEvent(std::shared_ptr event); + void handlePostedEvent(std::shared_ptr event); + void handleChannelEvent(std::shared_ptr event); void addFeedItem(FeedItem *item); void addFeedItemIfUnique(FeedItem *item, bool replace); void remUniqueFeedItem(FeedItem *item); - - void addFeedItemPeerConnect(const RsFeedItem &fi); - void addFeedItemPeerDisconnect(const RsFeedItem &fi); - void addFeedItemPeerHello(const RsFeedItem &fi); - void addFeedItemPeerNew(const RsFeedItem &fi); - void addFeedItemPeerOffset(const RsFeedItem &fi); - - void addFeedItemSecurityConnectAttempt(const RsFeedItem &fi); - void addFeedItemSecurityAuthDenied(const RsFeedItem &fi); - void addFeedItemSecurityUnknownIn(const RsFeedItem &fi); - void addFeedItemSecurityUnknownOut(const RsFeedItem &fi); - void addFeedItemSecurityIpBlacklisted(const RsFeedItem &fi, bool isTest); - void addFeedItemSecurityWrongExternalIpReported(const RsFeedItem &fi, bool isTest); - - void addFeedItemChannelNew(const RsFeedItem &fi); -// void addFeedItemChannelUpdate(const RsFeedItem &fi); - void addFeedItemChannelMsg(const RsFeedItem &fi); - void addFeedItemChannelPublishKey(const RsFeedItem &fi); - - void addFeedItemForumNew(const RsFeedItem &fi); -// void addFeedItemForumUpdate(const RsFeedItem &fi); - void addFeedItemForumMsg(const RsFeedItem &fi); - - void addFeedItemPostedNew(const RsFeedItem &fi); -// void addFeedItemPostedUpdate(const RsFeedItem &fi); - void addFeedItemPostedMsg(const RsFeedItem &fi); - #if 0 void addFeedItemBlogNew(const RsFeedItem &fi); void addFeedItemBlogMsg(const RsFeedItem &fi); @@ -147,27 +123,7 @@ private: void addFeedItemMessage(const RsFeedItem &fi); void addFeedItemFilesNew(const RsFeedItem &fi); - void addFeedItemCircleMembReq(const RsFeedItem &fi); - void remFeedItemCircleMembReq(const RsFeedItem &fi); - void addFeedItemCircleInvitRec(const RsFeedItem &fi); - - virtual void loadChannelGroup(const uint32_t &token); - virtual void loadChannelPost(const uint32_t &token); - virtual void loadChannelPublishKey(const uint32_t &token); - - virtual void loadForumGroup(const uint32_t &token); - virtual void loadForumMessage(const uint32_t &token); - virtual void loadForumPublishKey(const uint32_t &token); - - virtual void loadPostedGroup(const uint32_t &token); - virtual void loadPostedMessage(const uint32_t &token); - private: - TokenQueue *mTokenQueueChannel; - TokenQueue *mTokenQueueCircle; - TokenQueue *mTokenQueueForum; - TokenQueue *mTokenQueuePosted; - /* UI - from Designer */ Ui::NewsFeed *ui; From 3a3fc252057e00b4a727ece2b38ea21697d3c18f Mon Sep 17 00:00:00 2001 From: csoler Date: Fri, 13 Dec 2019 23:40:21 +0100 Subject: [PATCH 18/39] finished removing last AddFeedItem from msg, posted, forums and channels --- libretroshare/src/retroshare/rsmsgs.h | 10 +++++ libretroshare/src/retroshare/rsposted.h | 2 - libretroshare/src/services/p3gxschannels.cc | 34 ++++++++++----- libretroshare/src/services/p3gxscircles.cc | 3 -- libretroshare/src/services/p3gxsforums.cc | 29 +++++++++---- libretroshare/src/services/p3msgservice.cc | 46 ++++++++++----------- libretroshare/src/services/p3postbase.cc | 33 ++++++++------- retroshare-gui/src/gui/NewsFeed.cpp | 28 ++++++++++++- retroshare-gui/src/gui/NewsFeed.h | 11 +++-- retroshare-gui/src/gui/feeds/FeedHolder.h | 4 +- 10 files changed, 127 insertions(+), 73 deletions(-) diff --git a/libretroshare/src/retroshare/rsmsgs.h b/libretroshare/src/retroshare/rsmsgs.h index 109084dd7..cbdd525bc 100644 --- a/libretroshare/src/retroshare/rsmsgs.h +++ b/libretroshare/src/retroshare/rsmsgs.h @@ -300,6 +300,15 @@ struct RsMailStatusEvent : RsEvent { RsMailStatusEvent() : RsEvent(RsEventType::MAIL_STATUS_CHANGE) {} + enum MailStatusEventCode: uint8_t { + NEW_MESSAGE = 0x00, + MESSAGE_REMOVED = 0x01, + MESSAGE_SENT = 0x02, + MESSAGE_RECEIVED_ACK = 0x03, // means the peer received the message + FAILED_SIGNATURE = 0x04, // means the signature of the message cannot be verified + }; + + MailStatusEventCode mMailStatusEventCode; std::set mChangedMsgIds; /// @see RsEvent @@ -308,6 +317,7 @@ struct RsMailStatusEvent : RsEvent { RsEvent::serial_process(j, ctx); RS_SERIAL_PROCESS(mChangedMsgIds); + RS_SERIAL_PROCESS(mMailStatusEventCode); } ~RsMailStatusEvent() override; diff --git a/libretroshare/src/retroshare/rsposted.h b/libretroshare/src/retroshare/rsposted.h index c5c565bb0..547c03188 100644 --- a/libretroshare/src/retroshare/rsposted.h +++ b/libretroshare/src/retroshare/rsposted.h @@ -80,7 +80,6 @@ struct RsGxsPostedEvent: RsEvent }; PostedEventCode mPostedEventCode; - RsPeerId mAuthorId; RsGxsGroupId mPostedGroupId; RsGxsMessageId mPostedMsgId; @@ -89,7 +88,6 @@ struct RsGxsPostedEvent: RsEvent { RsEvent::serial_process(j, ctx); RS_SERIAL_PROCESS(mPostedEventCode); - RS_SERIAL_PROCESS(mAuthorId); RS_SERIAL_PROCESS(mPostedGroupId); RS_SERIAL_PROCESS(mPostedMsgId); } diff --git a/libretroshare/src/services/p3gxschannels.cc b/libretroshare/src/services/p3gxschannels.cc index 70e0763bf..985dbbf5c 100644 --- a/libretroshare/src/services/p3gxschannels.cc +++ b/libretroshare/src/services/p3gxschannels.cc @@ -238,12 +238,6 @@ void p3GxsChannels::notifyChanges(std::vector &changes) std::cerr << "p3GxsChannels::notifyChanges() : " << changes.size() << "changes to notify" << std::endl; #endif - p3Notify* notify = nullptr; - if (!changes.empty()) - { - notify = RsServer::notify(); - } - /* iterate through and grab any new messages */ std::list unprocessedGroups; @@ -256,13 +250,19 @@ void p3GxsChannels::notifyChanges(std::vector &changes) if (msgChange->getType() == RsGxsNotify::TYPE_RECEIVED_NEW) { /* message received */ - if (notify) + if (rsEvents) { std::map > &msgChangeMap = msgChange->msgChangeMap; for (auto mit = msgChangeMap.begin(); mit != msgChangeMap.end(); ++mit) for (auto mit1 = mit->second.begin(); mit1 != mit->second.end(); ++mit1) { - notify->AddFeedItem(RS_FEED_ITEM_CHANNEL_MSG, mit->first.toStdString(), mit1->toStdString()); + auto ev = std::make_shared(); + + ev->mChannelMsgId = *mit1; + ev->mChannelGroupId = mit->first; + ev->mChannelEventCode = RsGxsChannelEvent::NEW_MESSAGE; + + rsEvents->sendEvent(ev); } } } @@ -298,7 +298,7 @@ void p3GxsChannels::notifyChanges(std::vector &changes) } else { - if (notify) + if (rsEvents) { RsGxsGroupChange *grpChange = dynamic_cast(*it); if (grpChange) @@ -320,8 +320,15 @@ void p3GxsChannels::notifyChanges(std::vector &changes) { if(mKnownChannels.find(*git) == mKnownChannels.end()) { - notify->AddFeedItem(RS_FEED_ITEM_CHANNEL_NEW, git->toStdString()); mKnownChannels.insert(std::make_pair(*git,time(NULL))) ; + IndicateConfigChanged(); + + auto ev = std::make_shared(); + + ev->mChannelGroupId = *git; + ev->mChannelEventCode = RsGxsChannelEvent::NEW_CHANNEL; + + rsEvents->sendEvent(ev); } else std::cerr << "(II) Not notifying already known channel " << *git << std::endl; @@ -336,7 +343,12 @@ void p3GxsChannels::notifyChanges(std::vector &changes) std::list::iterator git; for (git = grpList.begin(); git != grpList.end(); ++git) { - notify->AddFeedItem(RS_FEED_ITEM_CHANNEL_PUBLISHKEY, git->toStdString()); + auto ev = std::make_shared(); + + ev->mChannelGroupId = *git; + ev->mChannelEventCode = RsGxsChannelEvent::RECEIVED_PUBLISH_KEY; + + rsEvents->sendEvent(ev); } break; } diff --git a/libretroshare/src/services/p3gxscircles.cc b/libretroshare/src/services/p3gxscircles.cc index 658af5892..28311e22a 100644 --- a/libretroshare/src/services/p3gxscircles.cc +++ b/libretroshare/src/services/p3gxscircles.cc @@ -438,8 +438,6 @@ void p3GxsCircles::notifyChanges(std::vector &changes) RsGxsCircleMsg msg; getCircleRequest(RsGxsGroupId(circle_id),*msgIdIt,msg); - // notify->AddFeedItem(RS_FEED_ITEM_CIRCLE_MEMB_REQ,RsGxsCircleId(mit->first).toStdString(),msgId.toStdString()); - auto ev = std::make_shared(); ev->mCircleId = circle_id; @@ -534,7 +532,6 @@ void p3GxsCircles::notifyChanges(std::vector &changes) } } - //notify->AddFeedItem(RS_FEED_ITEM_CIRCLE_INVIT_REC,RsGxsCircleId(*git).toStdString(),""); } #endif } diff --git a/libretroshare/src/services/p3gxsforums.cc b/libretroshare/src/services/p3gxsforums.cc index 787ea22e1..08d80921c 100644 --- a/libretroshare/src/services/p3gxsforums.cc +++ b/libretroshare/src/services/p3gxsforums.cc @@ -183,9 +183,7 @@ void p3GxsForums::notifyChanges(std::vector &changes) { if (!changes.empty()) { - p3Notify *notify = RsServer::notify(); - - if (notify) + if (rsEvents) { std::vector::iterator it; for(it = changes.begin(); it != changes.end(); ++it) @@ -207,10 +205,17 @@ void p3GxsForums::notifyChanges(std::vector &changes) std::map > &msgChangeMap = msgChange->msgChangeMap; for (auto mit = msgChangeMap.begin(); mit != msgChangeMap.end(); ++mit) - { for (auto mit1 = mit->second.begin(); mit1 != mit->second.end(); ++mit1) - notify->AddFeedItem(RS_FEED_ITEM_FORUM_MSG, mit->first.toStdString(), mit1->toStdString()); - } + { + auto ev = std::make_shared(); + + ev->mForumGroupId = mit->first; + ev->mForumMsgId = *mit1; + ev->mForumEventCode = RsGxsForumEvent::NEW_MESSAGE; + + rsEvents->sendEvent(ev); + } + break; } @@ -225,9 +230,13 @@ void p3GxsForums::notifyChanges(std::vector &changes) { if(mKnownForums.find(*git) == mKnownForums.end()) { - notify->AddFeedItem(RS_FEED_ITEM_FORUM_NEW, git->toStdString()); - mKnownForums.insert(std::make_pair(*git,time(NULL))) ; + auto ev = std::make_shared(); + ev->mForumGroupId = *git; + ev->mForumEventCode = RsGxsForumEvent::NEW_FORUM; + rsEvents->sendEvent(ev); + + mKnownForums.insert(std::make_pair(*git,time(NULL))) ; IndicateConfigChanged(); } else @@ -237,6 +246,9 @@ void p3GxsForums::notifyChanges(std::vector &changes) } break; } +#ifdef UNUSED + // (Cyril) There's no publish key system for forums now. As a GXS group, it is possible to add one, just like channels + // but the possibility is not offered by the API yet. case RsGxsNotify::TYPE_RECEIVED_PUBLISHKEY: { @@ -254,6 +266,7 @@ void p3GxsForums::notifyChanges(std::vector &changes) } break; } +#endif } } } diff --git a/libretroshare/src/services/p3msgservice.cc b/libretroshare/src/services/p3msgservice.cc index 20697f2d6..dc67a0f60 100644 --- a/libretroshare/src/services/p3msgservice.cc +++ b/libretroshare/src/services/p3msgservice.cc @@ -175,15 +175,14 @@ void p3MsgService::processIncomingMsg(RsMsgItem *mi) mi->msgFlags &= (RS_MSG_FLAGS_DISTANT | RS_MSG_FLAGS_SYSTEM); // remove flags except those mi->msgFlags |= RS_MSG_FLAGS_NEW; - p3Notify *notify = RsServer::notify(); - if (notify) + if (rsEvents) { - notify->AddPopupMessage(RS_POPUP_MSG, mi->PeerId().toStdString(), mi->subject, mi->message); + auto ev = std::make_shared(); + ev->mMailStatusEventCode = RsMailStatusEvent::NEW_MESSAGE; + ev->mChangedMsgIds.insert(std::to_string(mi->msgId)); - std::string out; - rs_sprintf(out, "%lu", mi->msgId); - notify->AddFeedItem(RS_FEED_ITEM_MESSAGE, out, "", ""); - } + rsEvents->sendEvent(ev); + } imsg[mi->msgId] = mi; RsMsgSrcId* msi = new RsMsgSrcId(); @@ -207,13 +206,6 @@ void p3MsgService::processIncomingMsg(RsMsgItem *mi) } RsServer::notify()->notifyListChange(NOTIFY_LIST_MESSAGELIST,NOTIFY_TYPE_ADD); - - if(rsEvents) - { - std::shared_ptr pEvent(new RsMailStatusEvent()); - pEvent->mChangedMsgIds.insert(std::to_string(mi->msgId)); - rsEvents->postEvent(pEvent); - } } bool p3MsgService::checkAndRebuildPartialMessage(RsMsgItem *ci) @@ -345,8 +337,8 @@ int p3MsgService::checkOutgoingMessages() bool changed = false; std::list output_queue; - using Evt_t = RsMailStatusEvent; - std::shared_ptr pEvent(new Evt_t()); + auto pEvent = std::make_shared(); + pEvent->mMailStatusEventCode = RsMailStatusEvent::MESSAGE_SENT; { RS_STACK_MUTEX(mMsgMtx); /********** STACK LOCKED MTX ******/ @@ -905,8 +897,10 @@ bool p3MsgService::removeMsgId(const std::string &mid) } bool changed = false; - using Evt_t = RsMailStatusEvent; - std::shared_ptr pEvent(new Evt_t()); + + auto pEvent = std::make_shared(); + + pEvent->mMailStatusEventCode = RsMailStatusEvent::MESSAGE_REMOVED; { RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/ @@ -1273,8 +1267,9 @@ uint32_t p3MsgService::sendMail( std::back_inserter(msgInfo.files) ); uint32_t ret = 0; - using Evt_t = RsMailStatusEvent; - std::shared_ptr pEvent(new Evt_t()); + + auto pEvent = std::make_shared(); + pEvent->mMailStatusEventCode = RsMailStatusEvent::MESSAGE_SENT; auto pSend = [&](const std::set& sDest) { @@ -2088,9 +2083,11 @@ void p3MsgService::notifyDataStatus( const GRouterMsgPropagationId& id, NOTIFY_TYPE_ADD ); IndicateConfigChanged(); - using Evt_t = RsMailStatusEvent; - std::shared_ptr pEvent(new Evt_t()); + auto pEvent = std::make_shared(); + + pEvent->mMailStatusEventCode = RsMailStatusEvent::NEW_MESSAGE; pEvent->mChangedMsgIds.insert(std::to_string(msg_id)); + if(rsEvents) rsEvents->postEvent(pEvent); return; @@ -2188,11 +2185,11 @@ bool p3MsgService::notifyGxsTransSendStatus( RsGxsTransId mailId, Dbg2() << __PRETTY_FUNCTION__ << " " << mailId << ", " << static_cast(status) << std::endl; - using Evt_t = RsMailStatusEvent; - std::shared_ptr pEvent(new Evt_t()); + auto pEvent = std::make_shared(); if( status == GxsTransSendStatus::RECEIPT_RECEIVED ) { + pEvent->mMailStatusEventCode = RsMailStatusEvent::NEW_MESSAGE; uint32_t msg_id; { @@ -2247,6 +2244,7 @@ bool p3MsgService::notifyGxsTransSendStatus( RsGxsTransId mailId, else if( status >= GxsTransSendStatus::FAILED_RECEIPT_SIGNATURE ) { uint32_t msg_id; + pEvent->mMailStatusEventCode = RsMailStatusEvent::FAILED_SIGNATURE; { RS_STACK_MUTEX(gxsOngoingMutex); diff --git a/libretroshare/src/services/p3postbase.cc b/libretroshare/src/services/p3postbase.cc index 9fb939baa..b4dc9a903 100644 --- a/libretroshare/src/services/p3postbase.cc +++ b/libretroshare/src/services/p3postbase.cc @@ -29,7 +29,7 @@ #include "rsitems/rsgxscommentitems.h" #include "rsserver/p3face.h" -#include "retroshare/rsnotify.h" +#include "retroshare/rsposted.h" // For Dummy Msgs. #include "util/rsrandom.h" @@ -87,12 +87,6 @@ void p3PostBase::notifyChanges(std::vector &changes) std::cerr << std::endl; #endif - p3Notify *notify = NULL; - if (!changes.empty()) - { - notify = RsServer::notify(); - } - std::vector::iterator it; for(it = changes.begin(); it != changes.end(); ++it) @@ -118,13 +112,17 @@ void p3PostBase::notifyChanges(std::vector &changes) // It could be taken a step further and directly request these msgs for an update. addGroupForProcessing(mit->first); - if (notify && msgChange->getType() == RsGxsNotify::TYPE_RECEIVED_NEW) - { + if (rsEvents && msgChange->getType() == RsGxsNotify::TYPE_RECEIVED_NEW) for (auto mit1 = mit->second.begin(); mit1 != mit->second.end(); ++mit1) { - notify->AddFeedItem(RS_FEED_ITEM_POSTED_MSG, mit->first.toStdString(), mit1->toStdString()); + auto ev = std::make_shared(); + + ev->mPostedMsgId = *mit1; + ev->mPostedGroupId = mit->first; + ev->mPostedEventCode = RsGxsPostedEvent::NEW_MESSAGE; + + rsEvents->sendEvent(ev); } - } } } @@ -137,17 +135,22 @@ void p3PostBase::notifyChanges(std::vector &changes) #endif std::list &groupList = groupChange->mGrpIdList; - std::list::iterator git; - for(git = groupList.begin(); git != groupList.end(); ++git) + + for(auto git = groupList.begin(); git != groupList.end(); ++git) { #ifdef POSTBASE_DEBUG std::cerr << "p3PostBase::notifyChanges() Incoming Group: " << *git; std::cerr << std::endl; #endif - if (notify && groupChange->getType() == RsGxsNotify::TYPE_RECEIVED_NEW) + if (rsEvents && groupChange->getType() == RsGxsNotify::TYPE_RECEIVED_NEW) { - notify->AddFeedItem(RS_FEED_ITEM_POSTED_NEW, git->toStdString()); + auto ev = std::make_shared(); + + ev->mPostedGroupId = *git; + ev->mPostedEventCode = RsGxsPostedEvent::NEW_POSTED_GROUP; + + rsEvents->sendEvent(ev); } } } diff --git a/retroshare-gui/src/gui/NewsFeed.cpp b/retroshare-gui/src/gui/NewsFeed.cpp index 7be597630..0e3af2b6f 100644 --- a/retroshare-gui/src/gui/NewsFeed.cpp +++ b/retroshare-gui/src/gui/NewsFeed.cpp @@ -192,10 +192,30 @@ void NewsFeed::handleEvent_main_thread(std::shared_ptr event) if(event->mType == RsEventType::GXS_FORUMS && (flags & RS_FEED_TYPE_FORUM)) handleForumEvent(event); - if(event->mType == RsEventType::GXS_POSTED && (flags & RS_FEED_TYPE_POSTED)) + if(event->mType == RsEventType::GXS_POSTED && (flags & RS_FEED_TYPE_MSG)) + handleMailEvent(event); + + if(event->mType == RsEventType::MAIL_STATUS_CHANGE && (flags & RS_FEED_TYPE_MAIL)) handlePostedEvent(event); } +void NewsFeed::handleMailEvent(std::shared_ptr event) +{ + const RsMailStatusEvent *pe = dynamic_cast(event.get()); + if(!pe) + return; + + switch(pe->mMailStatusEventCode) + { + case RsMailStatusEvent::NEW_MESSAGE: + for(auto msgid: pe->mChangedMsgIds) + addFeedItem( new MsgItem(this, NEWSFEED_MESSAGELIST, msgid, false)); + break; + default: + break; + } +} + void NewsFeed::handlePostedEvent(std::shared_ptr event) { const RsGxsPostedEvent *pe = dynamic_cast(event.get()); @@ -517,10 +537,12 @@ void NewsFeed::updateDisplay() addFeedItemChatNew(fi, false); break; +#ifdef TO_REMOVE case RS_FEED_ITEM_MESSAGE: if (flags & RS_FEED_TYPE_MSG) addFeedItemMessage(fi); break; +#endif case RS_FEED_ITEM_FILES_NEW: if (flags & RS_FEED_TYPE_FILES) @@ -1565,6 +1587,7 @@ void NewsFeed::addFeedItemChatNew(const RsFeedItem &fi, bool addWithoutCheck) addFeedItem(cm); } +#ifdef TO_REMOVE void NewsFeed::addFeedItemMessage(const RsFeedItem &fi) { /* make new widget */ @@ -1587,7 +1610,6 @@ void NewsFeed::addFeedItemFilesNew(const RsFeedItem &/*fi*/) #endif } -#ifdef TO_REMOVE void NewsFeed::addFeedItemCircleMembReq(const RsFeedItem &fi) { RsGxsCircleId circleId(fi.mId1); @@ -1667,6 +1689,7 @@ void NewsFeed::deleteFeedItem(QWidget *item, uint32_t /*type*/) } } +#ifdef TO_REMOVE void NewsFeed::openChat(const RsPeerId &peerId) { #ifdef NEWS_DEBUG @@ -1682,6 +1705,7 @@ void NewsFeed::openComments(uint32_t /*type*/, const RsGxsGroupId &/*groupId*/, std::cerr << "NewsFeed::openComments() Not Handled Yet"; std::cerr << std::endl; } +#endif static void sendNewsFeedChangedCallback(FeedItem *feedItem, void *data) { diff --git a/retroshare-gui/src/gui/NewsFeed.h b/retroshare-gui/src/gui/NewsFeed.h index dba5f1f46..1d3c764bd 100644 --- a/retroshare-gui/src/gui/NewsFeed.h +++ b/retroshare-gui/src/gui/NewsFeed.h @@ -75,8 +75,8 @@ public: /* FeedHolder Functions (for FeedItem functionality) */ virtual QScrollArea *getScrollArea(); virtual void deleteFeedItem(QWidget *item, uint32_t type); - virtual void openChat(const RsPeerId& peerId); - virtual void openComments(uint32_t type, const RsGxsGroupId &groupId, const QVector &versions, const RsGxsMessageId &msgId, const QString &title); +// virtual void openChat(const RsPeerId& peerId); +// virtual void openComments(uint32_t type, const RsGxsGroupId &groupId, const QVector &versions, const RsGxsMessageId &msgId, const QString &title); static void testFeeds(uint notifyFlags); static void testFeed(FeedNotify *feedNotify); @@ -95,7 +95,6 @@ protected: virtual void loadRequest(const TokenQueue *queue, const TokenRequest &req); private slots: -// void toggleChanMsgItems(bool on); void feedoptions(); void sortChanged(int index); @@ -119,9 +118,9 @@ private: void addFeedItemBlogMsg(const RsFeedItem &fi); #endif - void addFeedItemChatNew(const RsFeedItem &fi, bool addWithoutCheck); - void addFeedItemMessage(const RsFeedItem &fi); - void addFeedItemFilesNew(const RsFeedItem &fi); +// void addFeedItemChatNew(const RsFeedItem &fi, bool addWithoutCheck); +// void addFeedItemMessage(const RsFeedItem &fi); +// void addFeedItemFilesNew(const RsFeedItem &fi); private: /* UI - from Designer */ diff --git a/retroshare-gui/src/gui/feeds/FeedHolder.h b/retroshare-gui/src/gui/feeds/FeedHolder.h index f683bca19..ea9d4dd77 100644 --- a/retroshare-gui/src/gui/feeds/FeedHolder.h +++ b/retroshare-gui/src/gui/feeds/FeedHolder.h @@ -35,8 +35,8 @@ public: virtual QScrollArea *getScrollArea() = 0; virtual void deleteFeedItem(QWidget *item, uint32_t type) = 0; - virtual void openChat(const RsPeerId& peerId) = 0; - virtual void openComments(uint32_t type, const RsGxsGroupId &groupId, const QVector &msg_versions, const RsGxsMessageId &msgId, const QString &title)=0; +// virtual void openChat(const RsPeerId& peerId) = 0; +// virtual void openComments(uint32_t type, const RsGxsGroupId &groupId, const QVector &msg_versions, const RsGxsMessageId &msgId, const QString &title)=0; // Workaround for QTBUG-3372 void lockLayout(QWidget *feedItem, bool lock); From 536c0852d449fe2f020a734016f3fba5064ffdf9 Mon Sep 17 00:00:00 2001 From: csoler Date: Fri, 13 Dec 2019 23:58:17 +0100 Subject: [PATCH 19/39] fixed compilation --- retroshare-gui/src/gui/NewsFeed.cpp | 12 ++++-------- retroshare-gui/src/gui/NewsFeed.h | 7 ++++--- retroshare-gui/src/gui/feeds/FeedHolder.h | 4 ++-- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/retroshare-gui/src/gui/NewsFeed.cpp b/retroshare-gui/src/gui/NewsFeed.cpp index 0e3af2b6f..f2fae0210 100644 --- a/retroshare-gui/src/gui/NewsFeed.cpp +++ b/retroshare-gui/src/gui/NewsFeed.cpp @@ -192,10 +192,10 @@ void NewsFeed::handleEvent_main_thread(std::shared_ptr event) if(event->mType == RsEventType::GXS_FORUMS && (flags & RS_FEED_TYPE_FORUM)) handleForumEvent(event); - if(event->mType == RsEventType::GXS_POSTED && (flags & RS_FEED_TYPE_MSG)) + if(event->mType == RsEventType::GXS_POSTED && (flags & RS_FEED_TYPE_POSTED)) handleMailEvent(event); - if(event->mType == RsEventType::MAIL_STATUS_CHANGE && (flags & RS_FEED_TYPE_MAIL)) + if(event->mType == RsEventType::MAIL_STATUS_CHANGE && (flags & RS_FEED_TYPE_MSG)) handlePostedEvent(event); } @@ -532,22 +532,22 @@ void NewsFeed::updateDisplay() break; #endif +#ifdef TO_REMOVE case RS_FEED_ITEM_CHAT_NEW: if (flags & RS_FEED_TYPE_CHAT) addFeedItemChatNew(fi, false); break; -#ifdef TO_REMOVE case RS_FEED_ITEM_MESSAGE: if (flags & RS_FEED_TYPE_MSG) addFeedItemMessage(fi); break; -#endif case RS_FEED_ITEM_FILES_NEW: if (flags & RS_FEED_TYPE_FILES) addFeedItemFilesNew(fi); break; +#endif default: std::cerr << "(EE) Unknown type " << std::hex << fi.mType << std::dec << " in news feed." << std::endl; @@ -1566,7 +1566,6 @@ void NewsFeed::addFeedItemBlogMsg(const RsFeedItem &fi) #endif } -#endif void NewsFeed::addFeedItemChatNew(const RsFeedItem &fi, bool addWithoutCheck) { @@ -1587,7 +1586,6 @@ void NewsFeed::addFeedItemChatNew(const RsFeedItem &fi, bool addWithoutCheck) addFeedItem(cm); } -#ifdef TO_REMOVE void NewsFeed::addFeedItemMessage(const RsFeedItem &fi) { /* make new widget */ @@ -1689,7 +1687,6 @@ void NewsFeed::deleteFeedItem(QWidget *item, uint32_t /*type*/) } } -#ifdef TO_REMOVE void NewsFeed::openChat(const RsPeerId &peerId) { #ifdef NEWS_DEBUG @@ -1705,7 +1702,6 @@ void NewsFeed::openComments(uint32_t /*type*/, const RsGxsGroupId &/*groupId*/, std::cerr << "NewsFeed::openComments() Not Handled Yet"; std::cerr << std::endl; } -#endif static void sendNewsFeedChangedCallback(FeedItem *feedItem, void *data) { diff --git a/retroshare-gui/src/gui/NewsFeed.h b/retroshare-gui/src/gui/NewsFeed.h index 1d3c764bd..7bb5a307e 100644 --- a/retroshare-gui/src/gui/NewsFeed.h +++ b/retroshare-gui/src/gui/NewsFeed.h @@ -56,7 +56,7 @@ class RsFeedItem; class FeedNotify; class FeedItem; -class NewsFeed : public RsAutoUpdatePage, public FeedHolder, public TokenResponse +class NewsFeed : public RsAutoUpdatePage, public FeedHolder { Q_OBJECT @@ -75,8 +75,8 @@ public: /* FeedHolder Functions (for FeedItem functionality) */ virtual QScrollArea *getScrollArea(); virtual void deleteFeedItem(QWidget *item, uint32_t type); -// virtual void openChat(const RsPeerId& peerId); -// virtual void openComments(uint32_t type, const RsGxsGroupId &groupId, const QVector &versions, const RsGxsMessageId &msgId, const QString &title); + virtual void openChat(const RsPeerId& peerId); + virtual void openComments(uint32_t type, const RsGxsGroupId &groupId, const QVector &versions, const RsGxsMessageId &msgId, const QString &title); static void testFeeds(uint notifyFlags); static void testFeed(FeedNotify *feedNotify); @@ -107,6 +107,7 @@ private: void handleConnectionEvent(std::shared_ptr event); void handleCircleEvent(std::shared_ptr event); void handleForumEvent(std::shared_ptr event); + void handleMailEvent(std::shared_ptr event); void handlePostedEvent(std::shared_ptr event); void handleChannelEvent(std::shared_ptr event); diff --git a/retroshare-gui/src/gui/feeds/FeedHolder.h b/retroshare-gui/src/gui/feeds/FeedHolder.h index ea9d4dd77..f683bca19 100644 --- a/retroshare-gui/src/gui/feeds/FeedHolder.h +++ b/retroshare-gui/src/gui/feeds/FeedHolder.h @@ -35,8 +35,8 @@ public: virtual QScrollArea *getScrollArea() = 0; virtual void deleteFeedItem(QWidget *item, uint32_t type) = 0; -// virtual void openChat(const RsPeerId& peerId) = 0; -// virtual void openComments(uint32_t type, const RsGxsGroupId &groupId, const QVector &msg_versions, const RsGxsMessageId &msgId, const QString &title)=0; + virtual void openChat(const RsPeerId& peerId) = 0; + virtual void openComments(uint32_t type, const RsGxsGroupId &groupId, const QVector &msg_versions, const RsGxsMessageId &msgId, const QString &title)=0; // Workaround for QTBUG-3372 void lockLayout(QWidget *feedItem, bool lock); From 8d121a1038162cfe0b483bf7d6f76d03045c97d7 Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 14 Dec 2019 18:24:46 +0100 Subject: [PATCH 20/39] fixed accepting connection attempts from unknown peers using short invite system --- retroshare-gui/src/gui/NewsFeed.cpp | 1185 +---------------- retroshare-gui/src/gui/NewsFeed.h | 11 +- .../src/gui/connect/ConnectFriendWizard.cpp | 70 +- .../src/gui/connect/ConnectFriendWizard.ui | 12 +- retroshare-gui/src/gui/feeds/SecurityItem.cpp | 56 +- retroshare-gui/src/gui/feeds/SecurityItem.ui | 18 +- 6 files changed, 102 insertions(+), 1250 deletions(-) diff --git a/retroshare-gui/src/gui/NewsFeed.cpp b/retroshare-gui/src/gui/NewsFeed.cpp index f2fae0210..bd6b350ef 100644 --- a/retroshare-gui/src/gui/NewsFeed.cpp +++ b/retroshare-gui/src/gui/NewsFeed.cpp @@ -71,9 +71,7 @@ static NewsFeed *instance = NULL; /** Constructor */ -NewsFeed::NewsFeed(QWidget *parent) : - RsAutoUpdatePage(1000,parent), - ui(new Ui::NewsFeed) +NewsFeed::NewsFeed(QWidget *parent) : MainPage(parent), ui(new Ui::NewsFeed) { mEventHandlerId =0; // needed to force intialization by registerEventsHandler() rsEvents->registerEventsHandler( [this](std::shared_ptr event) { handleEvent(event); }, mEventHandlerId ); @@ -81,8 +79,6 @@ NewsFeed::NewsFeed(QWidget *parent) : /* Invoke the Qt Designer generated object setup routine */ ui->setupUi(this); - setUpdateWhenInvisible(true); - if (!instance) { instance = this; } @@ -395,185 +391,9 @@ void NewsFeed::handleSecurityEvent(std::shared_ptr event) MessageComposer::addConnectAttemptMsg(e.mPgpId, e.mSslId, QString::fromStdString(det.name + "(" + det.location + ")")); } -void NewsFeed::updateDisplay() -{ - if (!rsNotify) - return; - - uint flags = Settings->getNewsFeedFlags(); - - /* check for new messages */ - RsFeedItem fi; - if (rsNotify->GetFeedItem(fi)) - { - switch(fi.mType) - { -#ifdef TO_REMOVE - case RS_FEED_ITEM_PEER_HELLO: - if (flags & RS_FEED_TYPE_PEER) - addFeedItemPeerHello(fi); - break; - case RS_FEED_ITEM_PEER_NEW: - if (flags & RS_FEED_TYPE_PEER) - addFeedItemPeerNew(fi); - break; - case RS_FEED_ITEM_PEER_OFFSET: - //if (flags & RS_FEED_TYPE_PEER) //Always allow this feed even if Friend notify is disabled. - addFeedItemPeerOffset(fi); - break; - - if (flags & RS_FEED_TYPE_SECURITY) - addFeedItemSecurityConnectAttempt(fi); - break; - case RS_FEED_ITEM_SEC_UNKNOWN_IN: - if (flags & RS_FEED_TYPE_SECURITY) - addFeedItemSecurityUnknownIn(fi); - break; - case RS_FEED_ITEM_SEC_UNKNOWN_OUT: - if (flags & RS_FEED_TYPE_SECURITY) - addFeedItemSecurityUnknownOut(fi); - break; - - case RS_FEED_ITEM_SEC_IP_WRONG_EXTERNAL_IP_REPORTED: - if (flags & RS_FEED_TYPE_SECURITY_IP) - addFeedItemSecurityWrongExternalIpReported(fi, false); - break; - - case RS_FEED_ITEM_CHANNEL_NEW: - if (flags & RS_FEED_TYPE_CHANNEL) - addFeedItemChannelNew(fi); - break; -// case RS_FEED_ITEM_CHANNEL_UPDATE: -// if (flags & RS_FEED_TYPE_CHANNEL) -// addFeedItemChannelUpdate(fi); -// break; - case RS_FEED_ITEM_CHANNEL_MSG: - if (flags & RS_FEED_TYPE_CHANNEL) - addFeedItemChannelMsg(fi); - break; - case RS_FEED_ITEM_CHANNEL_PUBLISHKEY: - { - if (!mTokenQueueChannel) { - mTokenQueueChannel = new TokenQueue(rsGxsChannels->getTokenService(), instance); - } - - addFeedItemChannelPublishKey(fi); - -// RsGxsGroupId grpId(fi.mId1); -// if (!grpId.isNull()) { -// RsTokReqOptions opts; -// opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA; -// -// std::list grpIds; -// grpIds.push_back(grpId); -// -// uint32_t token; -// mTokenQueueChannel->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_SUMMARY, opts, grpIds, TOKEN_TYPE_PUBLISHKEY); -// } - } - break; - - case RS_FEED_ITEM_FORUM_NEW: - if (flags & RS_FEED_TYPE_FORUM) - addFeedItemForumNew(fi); - break; -// case RS_FEED_ITEM_FORUM_UPDATE: -// if (flags & RS_FEED_TYPE_FORUM) -// addFeedItemForumUpdate(fi); -// break; - case RS_FEED_ITEM_FORUM_MSG: - if (flags & RS_FEED_TYPE_FORUM) - addFeedItemForumMsg(fi); - break; - case RS_FEED_ITEM_FORUM_PUBLISHKEY: - { - if (!mTokenQueueForum) { - mTokenQueueForum = new TokenQueue(rsGxsForums->getTokenService(), instance); - } - - RsGxsGroupId grpId(fi.mId1); - if (!grpId.isNull()) { - RsTokReqOptions opts; - opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA; - - std::list grpIds; - grpIds.push_back(grpId); - - uint32_t token; - mTokenQueueForum->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_SUMMARY, opts, grpIds, TOKEN_TYPE_PUBLISHKEY); - } - } -// if (flags & RS_FEED_TYPE_FORUM) -// addFeedItemForumPublishKey(fi); - break; - - case RS_FEED_ITEM_POSTED_NEW: - if (flags & RS_FEED_TYPE_POSTED) - addFeedItemPostedNew(fi); - break; -// case RS_FEED_ITEM_POSTED_UPDATE: -// if (flags & RS_FEED_TYPE_POSTED) -// addFeedItemPostedUpdate(fi); -// break; - case RS_FEED_ITEM_POSTED_MSG: - if (flags & RS_FEED_TYPE_POSTED) - addFeedItemPostedMsg(fi); - break; -#endif - -#if 0 - case RS_FEED_ITEM_BLOG_NEW: - if (flags & RS_FEED_TYPE_BLOG) - addFeedItemBlogNew(fi); - break; - case RS_FEED_ITEM_BLOG_MSG: - if (flags & RS_FEED_TYPE_BLOG) - addFeedItemBlogMsg(fi); - break; -#endif - -#ifdef TO_REMOVE - case RS_FEED_ITEM_CHAT_NEW: - if (flags & RS_FEED_TYPE_CHAT) - addFeedItemChatNew(fi, false); - break; - - case RS_FEED_ITEM_MESSAGE: - if (flags & RS_FEED_TYPE_MSG) - addFeedItemMessage(fi); - break; - - case RS_FEED_ITEM_FILES_NEW: - if (flags & RS_FEED_TYPE_FILES) - addFeedItemFilesNew(fi); - break; -#endif - - default: - std::cerr << "(EE) Unknown type " << std::hex << fi.mType << std::dec << " in news feed." << std::endl; - break; - } - } else { - /* process plugin feeds */ - int pluginCount = rsPlugins->nbPlugins(); - for (int i = 0; i < pluginCount; ++i) { - RsPlugin *rsPlugin = rsPlugins->plugin(i); - if (rsPlugin) { - FeedNotify *feedNotify = rsPlugin->qt_feedNotify(); - if (feedNotify && feedNotify->notifyEnabled()) { - FeedItem *item = feedNotify->feedItem(this); - if (item) { - addFeedItem(item); - break; - } - } - } - } - } -} - void NewsFeed::testFeeds(uint notifyFlags) { +#ifdef TO_REMOVE if (!instance) { return; } @@ -588,548 +408,13 @@ void NewsFeed::testFeeds(uint notifyFlags) ++pos; RsFeedItem fi; - -#ifdef TODO - switch(type) { - case RS_FEED_TYPE_PEER: - fi.mId1 = rsPeers->getOwnId().toStdString(); - - instance->addFeedItemPeerConnect(fi); - instance->addFeedItemPeerDisconnect(fi); - instance->addFeedItemPeerHello(fi); - instance->addFeedItemPeerNew(fi); - break; - - case RS_FEED_TYPE_SECURITY: - fi.mId1 = rsPeers->getGPGOwnId().toStdString(); - fi.mId2 = rsPeers->getOwnId().toStdString(); - - instance->addFeedItemSecurityConnectAttempt(fi); - instance->addFeedItemSecurityAuthDenied(fi); - instance->addFeedItemSecurityUnknownIn(fi); - instance->addFeedItemSecurityUnknownOut(fi); - - break; - - case RS_FEED_TYPE_SECURITY_IP: - fi.mId1 = rsPeers->getOwnId().toStdString(); - fi.mId2 = "0.0.0.0"; - fi.mResult1 = RSBANLIST_CHECK_RESULT_BLACKLISTED; - instance->addFeedItemSecurityIpBlacklisted(fi, true); - - //fi.mId1 = rsPeers->getOwnId().toStdString(); - fi.mId2 = "0.0.0.1"; - fi.mId3 = "0.0.0.2"; - fi.mResult1 = 0; - instance->addFeedItemSecurityWrongExternalIpReported(fi, true); - - break; - - case RS_FEED_TYPE_CHANNEL: - { - if (!instance->mTokenQueueChannel) { - instance->mTokenQueueChannel = new TokenQueue(rsGxsChannels->getTokenService(), instance); - } - - RsTokReqOptions opts; - opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA; - uint32_t token; - instance->mTokenQueueChannel->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_SUMMARY, opts, TOKEN_TYPE_GROUP); - - break; - } - - case RS_FEED_TYPE_FORUM: - { - if (!instance->mTokenQueueForum) { - instance->mTokenQueueForum = new TokenQueue(rsGxsForums->getTokenService(), instance); - } - - RsTokReqOptions opts; - opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA; - uint32_t token; - instance->mTokenQueueForum->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_SUMMARY, opts, TOKEN_TYPE_GROUP); - - break; - } - - case RS_FEED_TYPE_POSTED: - { - if (!instance->mTokenQueuePosted) { - instance->mTokenQueuePosted = new TokenQueue(rsPosted->getTokenService(), instance); - } - - RsTokReqOptions opts; - opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA; - uint32_t token; - instance->mTokenQueuePosted->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_SUMMARY, opts, TOKEN_TYPE_GROUP); - - break; - } - -#if 0 - case RS_FEED_TYPE_BLOG: -// not used -// instance->addFeedItemBlogNew(fi); -// instance->addFeedItemBlogMsg(fi); - break; -#endif - - case RS_FEED_TYPE_CHAT: - fi.mId1 = rsPeers->getOwnId().toStdString(); - fi.mId2 = tr("This is a test.").toUtf8().constData(); - - instance->addFeedItemChatNew(fi, true); - break; - - case RS_FEED_TYPE_MSG: - { - std::list msgList; - rsMail->getMessageSummaries(msgList); - - std::list::const_iterator msgIt; - for (msgIt = msgList.begin(); msgIt != msgList.end(); ++msgIt) { - if (fi.mId1.empty()) { - /* store first message */ - fi.mId1 = msgIt->msgId; - } - - if (msgIt->msgflags & RS_MSG_TRASH) { - continue; - } - - if ((msgIt->msgflags & RS_MSG_BOXMASK) == RS_MSG_INBOX) { - /* take message from inbox */ - fi.mId1 = msgIt->msgId; - break; - } - } - - instance->addFeedItemMessage(fi); - break; - } - - case RS_FEED_TYPE_FILES: -// not used -// instance->addFeedItemFilesNew(fi); - break; - - case RS_FEED_TYPE_CIRCLE: - { - if (!instance->mTokenQueueCircle) { - instance->mTokenQueueCircle = new TokenQueue(rsGxsCircles->getTokenService(), instance); - } - - RsTokReqOptions opts; - opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA; - uint32_t token; - instance->mTokenQueueCircle->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_SUMMARY, opts, TOKEN_TYPE_GROUP); - - break; - } -// instance->addFeedItemCircleMembReq(fi); -// instance->addFeedItemCircleInvitRec(fi); - break; - - } -#endif } instance->ui->feedWidget->enableCountChangedSignal(true); instance->sendNewsFeedChanged(); -} - -#ifdef TO_REMOVE -void NewsFeed::loadCircleGroup(const uint32_t &token) -{ - std::vector groups; - if (!rsGxsCircles->getGroupData(token, groups)) { - std::cerr << "NewsFeed::loadCircleGroup() ERROR getting data"; - std::cerr << std::endl; - return; - } - - std::list own_identities; - rsIdentity->getOwnIds(own_identities); - - std::vector::const_iterator circleIt; - for (circleIt = groups.begin(); circleIt != groups.end(); ++circleIt) { - RsGxsCircleGroup group = *(circleIt); - RsGxsCircleDetails details; - if(rsGxsCircles->getCircleDetails(group.mMeta.mCircleId,details)) - { - for(std::list::const_iterator it(own_identities.begin());it!=own_identities.end();++it) { - std::map::const_iterator vit = details.mSubscriptionFlags.find(*it); - uint32_t subscribe_flags = (vit == details.mSubscriptionFlags.end())?0:(vit->second); - - if( !(subscribe_flags & GXS_EXTERNAL_CIRCLE_FLAGS_SUBSCRIBED) - && (subscribe_flags & GXS_EXTERNAL_CIRCLE_FLAGS_IN_ADMIN_LIST) ) { - - RsFeedItem fi; - fi.mId1 = group.mMeta.mGroupId.toStdString(); - fi.mId2 = it->toStdString(); - - instance->addFeedItemCircleInvitRec(fi); - - } - } - } - } -} - -void NewsFeed::loadChannelGroup(const uint32_t &token) -{ - std::vector groups; - if (!rsGxsChannels->getGroupData(token, groups)) { - std::cerr << "NewsFeed::loadChannelGroup() ERROR getting data"; - std::cerr << std::endl; - return; - } - - RsFeedItem fi; - std::vector::iterator channelIt; - for (channelIt = groups.begin(); channelIt != groups.end(); ++channelIt) { - if (fi.mId1.empty()) { - /* store first channel */ - fi.mId1 = channelIt->mMeta.mGroupId.toStdString(); - } - - if (!channelIt->mDescription.empty()) { - /* take channel with description */ - fi.mId1 = channelIt->mMeta.mGroupId.toStdString(); - break; - } - } - - if (fi.mId1.empty()) { - return; - } - - instance->addFeedItemChannelNew(fi); -// instance->addFeedItemChanUpdate(fi); - - /* Prepare group ids for message request */ - std::list grpIds; - for (channelIt = groups.begin(); channelIt != groups.end(); ++channelIt) { - grpIds.push_back(channelIt->mMeta.mGroupId); - } - RsTokReqOptions opts; - opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA; - opts.mOptions = RS_TOKREQOPT_MSG_THREAD; - uint32_t msgToken; - instance->mTokenQueueChannel->requestMsgInfo(msgToken, RS_TOKREQ_ANSTYPE_SUMMARY, opts, grpIds, TOKEN_TYPE_MESSAGE); -} - -void NewsFeed::loadChannelPost(const uint32_t &token) -{ - std::vector posts; - if (!rsGxsChannels->getPostData(token, posts)) { - std::cerr << "NewsFeed::loadChannelPost() ERROR getting data"; - std::cerr << std::endl; - return; - } - - RsFeedItem fi; - std::vector::iterator postIt; - for (postIt = posts.begin(); postIt != posts.end(); ++postIt) { - if (fi.mId2.empty()) { - /* store first channel message */ - fi.mId1 = postIt->mMeta.mGroupId.toStdString(); - fi.mId2 = postIt->mMeta.mMsgId.toStdString(); - } - - if (!postIt->mMsg.empty()) { - /* take channel message with description */ - fi.mId1 = postIt->mMeta.mGroupId.toStdString(); - fi.mId2 = postIt->mMeta.mMsgId.toStdString(); - break; - } - } - - if (!fi.mId1.empty()) { - instance->addFeedItemChannelMsg(fi); - } -} - -void NewsFeed::loadChannelPublishKey(const uint32_t &token) -{ - std::vector groups; - if (!rsGxsChannels->getGroupData(token, groups)) { - std::cerr << "NewsFeed::loadChannelPublishKey() ERROR getting data"; - std::cerr << std::endl; - return; - } - - if (groups.size() != 1) - { - std::cerr << "NewsFeed::loadChannelPublishKey() Wrong number of Items"; - std::cerr << std::endl; - return; - } -#ifdef UNUSED_CODE - MessageComposer::sendChannelPublishKey(groups[0]); -#endif - - RsGxsChannelGroup& grp = *groups.begin(); - - RsFeedItem fi; - fi.mId1 = grp.mMeta.mGroupId.toStdString(); - - - addFeedItemChannelPublishKey(fi); -} - -void NewsFeed::loadForumGroup(const uint32_t &token) -{ - std::vector forums; - if (!rsGxsForums->getGroupData(token, forums)) { - std::cerr << "NewsFeed::loadForumGroup() ERROR getting data"; - std::cerr << std::endl; - return; - } - - RsFeedItem fi; - std::vector::iterator forumIt; - for (forumIt = forums.begin(); forumIt != forums.end(); ++forumIt) { - if (fi.mId1.empty()) { - /* store first forum */ - fi.mId1 = forumIt->mMeta.mGroupId.toStdString(); - } - - if (!forumIt->mDescription.empty()) { - /* take forum with description */ - fi.mId1 = forumIt->mMeta.mGroupId.toStdString(); - break; - } - } - - if (fi.mId1.empty()) { - return; - } - - instance->addFeedItemForumNew(fi); -// instance->addFeedItemForumUpdate(fi); - - /* Prepare group ids for message request */ - std::list grpIds; - for (forumIt = forums.begin(); forumIt != forums.end(); ++forumIt) { - grpIds.push_back(forumIt->mMeta.mGroupId); - } - RsTokReqOptions opts; - opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA; - opts.mOptions = RS_TOKREQOPT_MSG_THREAD; - uint32_t msgToken; - instance->mTokenQueueForum->requestMsgInfo(msgToken, RS_TOKREQ_ANSTYPE_SUMMARY, opts, grpIds, TOKEN_TYPE_MESSAGE); -} - -void NewsFeed::loadForumMessage(const uint32_t &token) -{ - std::vector msgs; - if (!rsGxsForums->getMsgData(token, msgs)) { - std::cerr << "NewsFeed::loadForumPost() ERROR getting data"; - std::cerr << std::endl; - return; - } - - RsFeedItem fi; - std::vector::iterator msgIt; - for (msgIt = msgs.begin(); msgIt != msgs.end(); ++msgIt) { - if (fi.mId2.empty()) { - /* store first forum message */ - fi.mId1 = msgIt->mMeta.mGroupId.toStdString(); - fi.mId2 = msgIt->mMeta.mMsgId.toStdString(); - } - - if (!msgIt->mMsg.empty()) { - /* take forum message with description */ - fi.mId1 = msgIt->mMeta.mGroupId.toStdString(); - fi.mId2 = msgIt->mMeta.mMsgId.toStdString(); - break; - } - } - - if (!fi.mId1.empty()) { - instance->addFeedItemForumMsg(fi); - } -} - -void NewsFeed::loadForumPublishKey(const uint32_t &token) -{ - std::vector groups; - if (!rsGxsForums->getGroupData(token, groups)) { - std::cerr << "NewsFeed::loadForumPublishKey() ERROR getting data"; - std::cerr << std::endl; - return; - } - - if (groups.size() != 1) - { - std::cerr << "NewsFeed::loadForumPublishKey() Wrong number of Items"; - std::cerr << std::endl; - return; - } -#ifdef UNUSED_CODE - MessageComposer::sendForumPublishKey(groups[0]); -#endif - - std::cerr << "(EE) Unimplemented code: received an order to load/display item for received forum publish key, but the implementation is missing." << std::endl; -} - -void NewsFeed::loadPostedGroup(const uint32_t &token) -{ - std::vector posted; - if (!rsPosted->getGroupData(token, posted)) { - std::cerr << "NewsFeed::loadPostedGroup() ERROR getting data"; - std::cerr << std::endl; - return; - } - - RsFeedItem fi; - std::vector::iterator postedIt; - for (postedIt = posted.begin(); postedIt != posted.end(); ++postedIt) { - if (fi.mId1.empty()) { - /* store first posted */ - fi.mId1 = postedIt->mMeta.mGroupId.toStdString(); - } - - if (!postedIt->mDescription.empty()) { - /* take posted with description */ - fi.mId1 = postedIt->mMeta.mGroupId.toStdString(); - break; - } - } - - if (fi.mId1.empty()) { - return; - } - - instance->addFeedItemPostedNew(fi); -// instance->addFeedItemPostedUpdate(fi); - - /* Prepare group ids for message request */ - std::list grpIds; - for (postedIt = posted.begin(); postedIt != posted.end(); ++postedIt) { - grpIds.push_back(postedIt->mMeta.mGroupId); - } - RsTokReqOptions opts; - opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA; - opts.mOptions = RS_TOKREQOPT_MSG_THREAD; - uint32_t msgToken; - instance->mTokenQueuePosted->requestMsgInfo(msgToken, RS_TOKREQ_ANSTYPE_SUMMARY, opts, grpIds, TOKEN_TYPE_MESSAGE); -} - -void NewsFeed::loadPostedMessage(const uint32_t &token) -{ - std::vector msgs; - if (!rsPosted->getPostData(token, msgs)) { - std::cerr << "NewsFeed::loadPostedPost() ERROR getting data"; - std::cerr << std::endl; - return; - } - - RsFeedItem fi; - std::vector::iterator msgIt; - for (msgIt = msgs.begin(); msgIt != msgs.end(); ++msgIt) { - if (fi.mId2.empty()) { - /* store first posted message */ - fi.mId1 = msgIt->mMeta.mGroupId.toStdString(); - fi.mId2 = msgIt->mMeta.mMsgId.toStdString(); - } - - if (!msgIt->mLink.empty()) { - /* take posted message with description */ - fi.mId1 = msgIt->mMeta.mGroupId.toStdString(); - fi.mId2 = msgIt->mMeta.mMsgId.toStdString(); - break; - } - } - - if (!fi.mId1.empty()) { - instance->addFeedItemPostedMsg(fi); - } -} -#endif - -void NewsFeed::loadRequest(const TokenQueue *queue, const TokenRequest &req) -{ -#ifdef TO_REMOVE - if (queue == mTokenQueueChannel) { - switch (req.mUserType) { - case TOKEN_TYPE_GROUP: - loadChannelGroup(req.mToken); - break; - - case TOKEN_TYPE_MESSAGE: - loadChannelPost(req.mToken); - break; - - case TOKEN_TYPE_PUBLISHKEY: - loadChannelPublishKey(req.mToken); - break; - - default: - std::cerr << "NewsFeed::loadRequest() ERROR: INVALID CHANNEL TYPE"; - std::cerr << std::endl; - break; - } - } - - if (queue == mTokenQueueCircle) { - switch (req.mUserType) { - case TOKEN_TYPE_GROUP: - loadCircleGroup(req.mToken); - break; - - case TOKEN_TYPE_MESSAGE: - loadCircleMessage(req.mToken); - break; - - default: - std::cerr << "NewsFeed::loadRequest() ERROR: INVALID CIRCLE TYPE"; - std::cerr << std::endl; - break; - } - } - - if (queue == mTokenQueueForum) { - switch (req.mUserType) { - case TOKEN_TYPE_GROUP: - loadForumGroup(req.mToken); - break; - - case TOKEN_TYPE_MESSAGE: - loadForumMessage(req.mToken); - break; - - case TOKEN_TYPE_PUBLISHKEY: - loadForumPublishKey(req.mToken); - break; - - default: - std::cerr << "NewsFeed::loadRequest() ERROR: INVALID FORUM TYPE"; - std::cerr << std::endl; - break; - } - } - - if (queue == mTokenQueuePosted) { - switch (req.mUserType) { - case TOKEN_TYPE_GROUP: - loadPostedGroup(req.mToken); - break; - - case TOKEN_TYPE_MESSAGE: - loadPostedMessage(req.mToken); - break; - - default: - std::cerr << "NewsFeed::loadRequest() ERROR: INVALID POSTED TYPE"; - std::cerr << std::endl; - break; - } - } #endif + std::cerr << "(EE) testFeeds() is currently disabled" << std::endl; } void NewsFeed::testFeed(FeedNotify *feedNotify) @@ -1205,470 +490,6 @@ void NewsFeed::remUniqueFeedItem(FeedItem *item) } } -#ifdef TO_REMOVE -void NewsFeed::addFeedItemPeerConnect(const RsFeedItem &fi) -{ - /* make new widget */ - PeerItem *pi = new PeerItem(this, NEWSFEED_PEERLIST, RsPeerId(fi.mId1), PEER_TYPE_CONNECT, false); - - /* add to layout */ - addFeedItem(pi); - -#ifdef NEWS_DEBUG - std::cerr << "NewsFeed::addFeedItemPeerConnect()"; - std::cerr << std::endl; -#endif -} - -void NewsFeed::addFeedItemPeerDisconnect(const RsFeedItem &fi) -{ - /* make new widget */ - PeerItem *pi = new PeerItem(this, NEWSFEED_PEERLIST, RsPeerId(fi.mId1), PEER_TYPE_STD, false); - - /* add to layout */ - addFeedItem(pi); - -#ifdef NEWS_DEBUG - std::cerr << "NewsFeed::addFeedItemPeerDisconnect()"; - std::cerr << std::endl; -#endif -} - -void NewsFeed::addFeedItemPeerHello(const RsFeedItem &fi) -{ - /* make new widget */ - PeerItem *pi = new PeerItem(this, NEWSFEED_PEERLIST, RsPeerId(fi.mId1), PEER_TYPE_HELLO, false); - - /* add to layout */ - addFeedItem(pi); - -#ifdef NEWS_DEBUG - std::cerr << "NewsFeed::addFeedItemPeerHello()"; - std::cerr << std::endl; -#endif -} - -void NewsFeed::addFeedItemPeerNew(const RsFeedItem &fi) -{ - /* make new widget */ - PeerItem *pi = new PeerItem(this, NEWSFEED_PEERLIST, RsPeerId(fi.mId1), PEER_TYPE_NEW_FOF, false); - - /* add to layout */ - addFeedItem(pi); - -#ifdef NEWS_DEBUG - std::cerr << "NewsFeed::addFeedItemPeerNew()"; - std::cerr << std::endl; -#endif -} - -void NewsFeed::addFeedItemPeerOffset(const RsFeedItem &fi) -{ - /* make new widget */ - PeerItem *pi = new PeerItem(this, NEWSFEED_PEERLIST, RsPeerId(fi.mId1), PEER_TYPE_OFFSET, false); - - /* add to layout */ - addFeedItemIfUnique(pi, false); - -#ifdef NEWS_DEBUG - std::cerr << "NewsFeed::addFeedItemPeerOffset()"; - std::cerr << std::endl; -#endif -} - - -void NewsFeed::addFeedItemSecurityConnectAttempt(const RsFeedItem &fi) -{ - /* make new widget */ - SecurityItem *pi = new SecurityItem(this, NEWSFEED_SECLIST, RsPgpId(fi.mId1), RsPeerId(fi.mId2), fi.mId3, fi.mId4, fi.mType, false); - - /* add to layout */ - addFeedItemIfUnique(pi, false); - -#ifdef NEWS_DEBUG - std::cerr << "NewsFeed::addFeedItemSecurityConnectAttempt()"; - std::cerr << std::endl; -#endif -} - -void NewsFeed::addFeedItemSecurityAuthDenied(const RsFeedItem &fi) -{ - /* make new widget */ - SecurityItem *pi = new SecurityItem(this, NEWSFEED_SECLIST, RsPgpId(fi.mId1), RsPeerId(fi.mId2), fi.mId3, fi.mId4, fi.mType, false); - - /* add to layout */ - addFeedItemIfUnique(pi, false); - -#ifdef NEWS_DEBUG - std::cerr << "NewsFeed::addFeedItemSecurityAuthDenied()"; - std::cerr << std::endl; -#endif -} - -void NewsFeed::addFeedItemSecurityUnknownIn(const RsFeedItem &fi) -{ - /* make new widget */ - SecurityItem *pi = new SecurityItem(this, NEWSFEED_SECLIST, RsPgpId(fi.mId1), RsPeerId(fi.mId2), fi.mId3, fi.mId4, RS_FEED_ITEM_SEC_UNKNOWN_IN, false); - - /* add to layout */ - addFeedItemIfUnique(pi, false); - -#ifdef NEWS_DEBUG - std::cerr << "NewsFeed::addFeedItemSecurityUnknownIn()"; - std::cerr << std::endl; -#endif -} - -void NewsFeed::addFeedItemSecurityUnknownOut(const RsFeedItem &fi) -{ - /* make new widget */ - SecurityItem *pi = new SecurityItem(this, NEWSFEED_SECLIST, RsPgpId(fi.mId1), RsPeerId(fi.mId2), fi.mId3, fi.mId4, RS_FEED_ITEM_SEC_UNKNOWN_OUT, false); - - /* add to layout */ - addFeedItemIfUnique(pi, false); - -#ifdef NEWS_DEBUG - std::cerr << "NewsFeed::addFeedItemSecurityUnknownOut()"; - std::cerr << std::endl; -#endif -} - -void NewsFeed::addFeedItemSecurityIpBlacklisted(const RsFeedItem &fi, bool isTest) -{ - /* make new widget */ - SecurityIpItem *pi = new SecurityIpItem(this, RsPeerId(fi.mId1), fi.mId2, fi.mResult1, RS_FEED_ITEM_SEC_IP_BLACKLISTED, isTest); - - /* add to layout */ - addFeedItemIfUnique(pi, false); - -#ifdef NEWS_DEBUG - std::cerr << "NewsFeed::addFeedItemSecurityIpBlacklisted()"; - std::cerr << std::endl; -#endif -} - -void NewsFeed::addFeedItemSecurityWrongExternalIpReported(const RsFeedItem &fi, bool isTest) -{ - /* make new widget */ - SecurityIpItem *pi = new SecurityIpItem(this, RsPeerId(fi.mId1), fi.mId2, fi.mId3, RS_FEED_ITEM_SEC_IP_WRONG_EXTERNAL_IP_REPORTED, isTest); - - /* add to layout */ - addFeedItemIfUnique(pi, false); - -#ifdef NEWS_DEBUG - std::cerr << "NewsFeed::addFeedItemSecurityWrongExternalIpReported()"; - std::cerr << std::endl; -#endif -} - -void NewsFeed::addFeedItemChannelNew(const RsFeedItem &fi) -{ - RsGxsGroupId grpId(fi.mId1); - - if (grpId.isNull()) { - return; - } - - /* make new widget */ - GxsChannelGroupItem *item = new GxsChannelGroupItem(this, NEWSFEED_CHANNELNEWLIST, grpId, false, true); - - /* add to layout */ - addFeedItem(item); - -#ifdef NEWS_DEBUG - std::cerr << "NewsFeed::addFeedItemChanNew()"; - std::cerr << std::endl; -#endif -} - -//void NewsFeed::addFeedItemChannelUpdate(const RsFeedItem &fi) -//{ -// /* make new widget */ -// ChanNewItem *cni = new ChanNewItem(this, NEWSFEED_CHANNEWLIST, fi.mId1, false, false); - -// /* add to layout */ -// addFeedItem(cni); - -//#ifdef NEWS_DEBUG -// std::cerr << "NewsFeed::addFeedItemChanUpdate()"; -// std::cerr << std::endl; -//#endif -//} - -void NewsFeed::addFeedItemChannelMsg(const RsFeedItem &fi) -{ - RsGxsGroupId grpId(fi.mId1); - RsGxsMessageId msgId(fi.mId2); - - if (grpId.isNull() || msgId.isNull()) { - return; - } - - /* make new widget */ - GxsChannelPostItem *item = new GxsChannelPostItem(this, NEWSFEED_CHANNELNEWLIST, grpId, msgId, false, true); - - /* add to layout */ - addFeedItem(item); - -#ifdef NEWS_DEBUG - std::cerr << "NewsFeed::addFeedItemChanMsg()"; - std::cerr << std::endl; -#endif -} -void NewsFeed::addFeedItemChannelPublishKey(const RsFeedItem &fi) -{ - RsGxsGroupId grpId(fi.mId1); - - if (grpId.isNull()) - return; - - /* make new widget */ - GxsChannelGroupItem *item = new GxsChannelGroupItem(this, NEWSFEED_CHANNELPUBKEYLIST, grpId, false, true); - - /* add to layout */ - addFeedItem(item); - -#ifdef NEWS_DEBUG - std::cerr << "NewsFeed::addFeedItemChanMsg()"; - std::cerr << std::endl; -#endif -} - -void NewsFeed::addFeedItemForumNew(const RsFeedItem &fi) -{ - RsGxsGroupId grpId(fi.mId1); - - if (grpId.isNull()) { - return; - } - - /* make new widget */ - GxsForumGroupItem *item = new GxsForumGroupItem(this, NEWSFEED_FORUMNEWLIST, grpId, false, true); - - /* add to layout */ - addFeedItem(item); - -#ifdef NEWS_DEBUG - std::cerr << "NewsFeed::addFeedItemForumNew()"; - std::cerr << std::endl; -#endif -} - -//void NewsFeed::addFeedItemForumUpdate(const RsFeedItem &fi) -//{ -// /* make new widget */ -// ForumNewItem *fni = new ForumNewItem(this, NEWSFEED_FORUMNEWLIST, fi.mId1, false, false); - -// /* add to layout */ -// addFeedItem(fni); - -//#ifdef NEWS_DEBUG -// std::cerr << "NewsFeed::addFeedItemForumUpdate()"; -// std::cerr << std::endl; -//#endif -//} - -void NewsFeed::addFeedItemForumMsg(const RsFeedItem &fi) -{ - RsGxsGroupId grpId(fi.mId1); - RsGxsMessageId msgId(fi.mId2); - - if (grpId.isNull() || msgId.isNull()) { - return; - } - - /* make new widget */ - GxsForumMsgItem *item = new GxsForumMsgItem(this, NEWSFEED_FORUMMSGLIST, grpId, msgId, false, true); - - /* add to layout */ - addFeedItem(item); - -#ifdef NEWS_DEBUG - std::cerr << "NewsFeed::addFeedItemForumMsg()"; - std::cerr << std::endl; -#endif -} - -void NewsFeed::addFeedItemPostedNew(const RsFeedItem &fi) -{ - RsGxsGroupId grpId(fi.mId1); - - if (grpId.isNull()) { - return; - } - - /* make new widget */ - PostedGroupItem *item = new PostedGroupItem(this, NEWSFEED_POSTEDNEWLIST, grpId, false, true); - - /* add to layout */ - addFeedItem(item); - -#ifdef NEWS_DEBUG - std::cerr << "NewsFeed::addFeedItemPostedNew()"; - std::cerr << std::endl; -#endif -} - -//void NewsFeed::addFeedItemPostedUpdate(const RsFeedItem &fi) -//{ -// /* make new widget */ -// GxsPostedGroupItem *item = new GxsPostedGroupItem(this, NEWSFEED_POSTEDNEWLIST, grpId, false, true); - -// /* add to layout */ -// addFeedItem(item); - -//#ifdef NEWS_DEBUG -// std::cerr << "NewsFeed::addFeedItemPostedUpdate()"; -// std::cerr << std::endl; -//#endif -//} - -void NewsFeed::addFeedItemPostedMsg(const RsFeedItem &fi) -{ - RsGxsGroupId grpId(fi.mId1); - RsGxsMessageId msgId(fi.mId2); - - if (grpId.isNull() || msgId.isNull()) { - return; - } - - /* make new widget */ - PostedItem *item = new PostedItem(this, NEWSFEED_POSTEDMSGLIST, grpId, msgId, false, true); - - /* add to layout */ - addFeedItem(item); - -#ifdef NEWS_DEBUG - std::cerr << "NewsFeed::addFeedItemPostedMsg()"; - std::cerr << std::endl; -#endif -} -#endif - -#if 0 -void NewsFeed::addFeedItemBlogNew(const RsFeedItem &fi) -{ - Q_UNUSED(fi); - -#ifdef NEWS_DEBUG - std::cerr << "NewsFeed::addFeedItemBlogNew()"; - std::cerr << std::endl; -#endif -} - -void NewsFeed::addFeedItemBlogMsg(const RsFeedItem &fi) -{ - Q_UNUSED(fi); - -#ifdef NEWS_DEBUG - std::cerr << "NewsFeed::addFeedItemBlogMsg()"; - std::cerr << std::endl; -#endif -} - - -void NewsFeed::addFeedItemChatNew(const RsFeedItem &fi, bool addWithoutCheck) -{ -#ifdef NEWS_DEBUG - std::cerr << "NewsFeed::addFeedItemChatNew()"; - std::cerr << std::endl; -#endif - - if (!addWithoutCheck && fi.mId1 == rsPeers->getOwnId().toStdString()) { - /* chat message from myself */ - return; - } - - /* make new widget */ - ChatMsgItem *cm = new ChatMsgItem(this, NEWSFEED_CHATMSGLIST, RsPeerId(fi.mId1), fi.mId2); - - /* add to layout */ - addFeedItem(cm); -} - -void NewsFeed::addFeedItemMessage(const RsFeedItem &fi) -{ - /* make new widget */ - MsgItem *mi = new MsgItem(this, NEWSFEED_MESSAGELIST, fi.mId1, false); - - /* add to layout */ - addFeedItem(mi); - -#ifdef NEWS_DEBUG - std::cerr << "NewsFeed::addFeedItemMessage()"; - std::cerr << std::endl; -#endif -} - -void NewsFeed::addFeedItemFilesNew(const RsFeedItem &/*fi*/) -{ -#ifdef NEWS_DEBUG - std::cerr << "NewsFeed::addFeedItemFilesNew()"; - std::cerr << std::endl; -#endif -} - -void NewsFeed::addFeedItemCircleMembReq(const RsFeedItem &fi) -{ - RsGxsCircleId circleId(fi.mId1); - RsGxsId gxsId(fi.mId2); - - if (circleId.isNull() || gxsId.isNull()) { - return; - } - - /* make new widget */ - GxsCircleItem *item = new GxsCircleItem(this, NEWSFEED_CIRCLELIST, circleId, gxsId, RS_FEED_ITEM_CIRCLE_MEMB_REQ); - - /* add to layout */ - addFeedItemIfUnique(item, false); - -#ifdef NEWS_DEBUG - std::cerr << "NewsFeed::addFeedItemCircleMembReq()" << std::endl; -#endif -} - -void NewsFeed::remFeedItemCircleMembReq(const RsFeedItem &fi) -{ - RsGxsCircleId circleId(fi.mId1); - RsGxsId gxsId(fi.mId2); - - if (circleId.isNull() || gxsId.isNull()) { - return; - } - - /* make new widget */ - GxsCircleItem *item = new GxsCircleItem(this, NEWSFEED_CIRCLELIST, circleId, gxsId, RS_FEED_ITEM_CIRCLE_MEMB_REQ); - - /* add to layout */ - remUniqueFeedItem(item); - -#ifdef NEWS_DEBUG - std::cerr << "NewsFeed::remFeedItemCircleMembReq()" << std::endl; -#endif -} - -void NewsFeed::addFeedItemCircleInvitRec(const RsFeedItem &fi) -{ - RsGxsCircleId circleId(fi.mId1); - RsGxsId gxsId(fi.mId2); - - if (circleId.isNull()) { - return; - } - - /* make new widget */ - GxsCircleItem *item = new GxsCircleItem(this, NEWSFEED_CIRCLELIST, circleId, gxsId, RS_FEED_ITEM_CIRCLE_INVIT_REC); - - /* add to layout */ - addFeedItem(item); - -#ifdef NEWS_DEBUG - std::cerr << "NewsFeed::addFeedItemCircleInvitRec()" << std::endl; -#endif -} -#endif - /* FeedHolder Functions (for FeedItem functionality) */ QScrollArea *NewsFeed::getScrollArea() { diff --git a/retroshare-gui/src/gui/NewsFeed.h b/retroshare-gui/src/gui/NewsFeed.h index 7bb5a307e..c255d56ac 100644 --- a/retroshare-gui/src/gui/NewsFeed.h +++ b/retroshare-gui/src/gui/NewsFeed.h @@ -56,7 +56,7 @@ class RsFeedItem; class FeedNotify; class FeedItem; -class NewsFeed : public RsAutoUpdatePage, public FeedHolder +class NewsFeed : public MainPage,public FeedHolder { Q_OBJECT @@ -81,8 +81,6 @@ public: static void testFeeds(uint notifyFlags); static void testFeed(FeedNotify *feedNotify); - virtual void updateDisplay(); - void handleEvent(std::shared_ptr event); // get events from libretroshare signals: @@ -91,9 +89,6 @@ signals: protected: void processSettings(bool load); - /* TokenResponse */ - virtual void loadRequest(const TokenQueue *queue, const TokenRequest &req); - private slots: void feedoptions(); void sortChanged(int index); @@ -119,10 +114,6 @@ private: void addFeedItemBlogMsg(const RsFeedItem &fi); #endif -// void addFeedItemChatNew(const RsFeedItem &fi, bool addWithoutCheck); -// void addFeedItemMessage(const RsFeedItem &fi); -// void addFeedItemFilesNew(const RsFeedItem &fi); - private: /* UI - from Designer */ Ui::NewsFeed *ui; diff --git a/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp b/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp index 7ea64e7b5..4ad6315b9 100755 --- a/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp +++ b/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp @@ -337,24 +337,49 @@ void ConnectFriendWizard::setCertificate(const QString &certificate, bool friend void ConnectFriendWizard::setGpgId(const RsPgpId &gpgId, const RsPeerId &sslId, bool friendRequest) { - if (!rsPeers->getGPGDetails(gpgId, peerDetails)) { - setField("errorMessage", tr("Cannot get peer details of PGP key %1").arg(QString::fromStdString(gpgId.toStdString()))); + if(sslId == rsPeers->getOwnId()) + { + setField("errorMessage", tr("This is your own certificate! You would not want to make friend with yourself. Wouldn't you?") ) ; setStartId(Page_ErrorMessage); - return; + error = false; } - /* Set ssl id when available */ - peerDetails.id = sslId; + if (!rsPeers->getGPGDetails(gpgId, peerDetails)) + { + mIsShortInvite = true; - //setStartId(friendRequest ? Page_FriendRequest : Page_Conclusion); - setStartId(Page_Conclusion); - if (friendRequest){ - ui->cp_Label->show(); - ui->requestinfolabel->show(); - setTitleText(ui->ConclusionPage,tr("Friend request")); - ui->ConclusionPage->setSubTitle(tr("Details about the request")); - setButtonText(QWizard::FinishButton , tr("Accept")); - } + peerDetails.id = sslId; + peerDetails.gpg_id = gpgId; + peerDetails.skip_pgp_signature_validation = true; + + mCertificate.clear(); + + setStartId(Page_Conclusion); + + if (friendRequest){ + ui->cp_Label->show(); + ui->requestinfolabel->show(); + setTitleText(ui->ConclusionPage, tr("Friend request")); + ui->ConclusionPage->setSubTitle(tr("Details about the request")); + setButtonText(QWizard::FinishButton , tr("Accept")); + } + } + else + { + /* Set ssl id when available */ + peerDetails.id = sslId; + mIsShortInvite = false; + + //setStartId(friendRequest ? Page_FriendRequest : Page_Conclusion); + setStartId(Page_Conclusion); + if (friendRequest){ + ui->cp_Label->show(); + ui->requestinfolabel->show(); + setTitleText(ui->ConclusionPage,tr("Friend request")); + ui->ConclusionPage->setSubTitle(tr("Details about the request")); + setButtonText(QWizard::FinishButton , tr("Accept")); + } + } } ConnectFriendWizard::~ConnectFriendWizard() @@ -507,7 +532,7 @@ void ConnectFriendWizard::initializePage(int id) ui->cp_Label->setText(tr("You have a friend request from") + " " + QString::fromUtf8(peerDetails.name.c_str())); ui->nameEdit->setText(QString::fromUtf8(peerDetails.name.c_str())); ui->trustEdit->setText(trustString); - ui->emailEdit->setText(QString::fromUtf8(peerDetails.email.c_str())); + ui->profileIdEdit->setText(QString::fromStdString(peerDetails.gpg_id.toStdString())); QString loc = QString::fromUtf8(peerDetails.location.c_str()); if (!loc.isEmpty()) { @@ -540,12 +565,19 @@ void ConnectFriendWizard::initializePage(int id) ui->ipLabel->setPixmap(QPixmap(":/images/anonymous_128_blue.png").scaledToHeight(S*2,Qt::SmoothTransformation)); ui->ipLabel->setToolTip("This is a Hidden node - you need tor/i2p proxy to connect"); } - - if(peerDetails.email.empty()) + if(mIsShortInvite) { - ui->emailLabel->hide(); // is it ever used? - ui->emailEdit->hide(); + ui->nameEdit->setText(tr("[Unknown]")); + ui->addKeyToKeyring_CB->setChecked(false); + ui->addKeyToKeyring_CB->setEnabled(false); + ui->signersEdit->hide(); + ui->signersLabel->hide(); + ui->signGPGCheckBox->setChecked(false); + ui->signGPGCheckBox->setEnabled(false); + ui->acceptNoSignGPGCheckBox->setChecked(true); + ui->acceptNoSignGPGCheckBox->setEnabled(false); } + ui->ipEdit->setTextInteractionFlags(Qt::TextSelectableByMouse); } diff --git a/retroshare-gui/src/gui/connect/ConnectFriendWizard.ui b/retroshare-gui/src/gui/connect/ConnectFriendWizard.ui index a950d3ceb..9cbd53ca0 100644 --- a/retroshare-gui/src/gui/connect/ConnectFriendWizard.ui +++ b/retroshare-gui/src/gui/connect/ConnectFriendWizard.ui @@ -6,8 +6,8 @@ 0 0 - 600 - 437 + 1139 + 1171 @@ -480,14 +480,14 @@ - + - Email: + Profile ID: - + Email @@ -794,8 +794,8 @@ - + diff --git a/retroshare-gui/src/gui/feeds/SecurityItem.cpp b/retroshare-gui/src/gui/feeds/SecurityItem.cpp index b14853ae2..8609069f0 100644 --- a/retroshare-gui/src/gui/feeds/SecurityItem.cpp +++ b/retroshare-gui/src/gui/feeds/SecurityItem.cpp @@ -174,40 +174,47 @@ void SecurityItem::updateItem() std::cerr << std::endl; #endif - if(!RsAutoUpdatePage::eventsLocked()) { + if(!RsAutoUpdatePage::eventsLocked()) + { RsPeerDetails details; - /* first try sslid */ - if (!rsPeers->getPeerDetails(mSslId, details)) + /* first try sslid */; + if (!rsPeers->getPeerDetails(mSslId, details) && !rsPeers->getGPGDetails(mGpgId, details)) { - /* then gpgid */ - if(!rsPeers->getGPGDetails(mGpgId, details)) - { - /* it is very likely that we will end up here for some of the + /* it is very likely that we will end up here for some of the * Unknown peer cases.... so allow them here */ - /* set peer name */ - peerNameLabel->setText(QString("%1 (%2)").arg(tr("Unknown Peer"), QString::fromUtf8(mSslCn.c_str()))); + /* set peer name */ + peerNameLabel->setText(tr("A unknown peer")); - nameLabel->setText(QString::fromUtf8(mSslCn.c_str()) + " (" + QString::fromStdString(mGpgId.toStdString()) + ")"); - idLabel->setText(QString::fromStdString(mSslId.toStdString())); + nameLabel->setText(tr("Unknown") + " (" + tr("Profile ID: ") + QString::fromStdString(mGpgId.toStdString()) + ")"); + idLabel->setText(QString::fromStdString(mSslId.toStdString())); - statusLabel->setText(tr("Unknown Peer")); - trustLabel->setText(tr("Unknown Peer")); - locLabel->setText(tr("Unknown Peer")); - ipLabel->setText(QString::fromStdString(mIP)) ; //tr("Unknown Peer")); - connLabel->setText(tr("Unknown Peer")); + statusLabel->hide(); + typeLabel->hide(); - chatButton->hide(); - //quickmsgButton->hide(); - requestLabel->hide(); + trustLabel->hide(); + trustLeftLabel->hide(); - removeFriendButton->setEnabled(false); - removeFriendButton->hide(); - peerDetailsButton->setEnabled(false); + locLabel->hide(); + locLeftLabel->hide(); - return; - } + ipLabel->setText(QString::fromStdString(mIP)) ; + connLabel->hide(); + connLeftLabel->hide(); + + chatButton->hide(); + //quickmsgButton->hide(); + requestLabel->hide(); + + removeFriendButton->setEnabled(false); + removeFriendButton->hide(); + peerDetailsButton->setEnabled(false); + + friendRequesttoolButton->show(); + requestLabel->show(); + + return; } /* set peer name */ @@ -344,6 +351,7 @@ void SecurityItem::friendRequest() #endif ConnectFriendWizard *connectFriendWizard = new ConnectFriendWizard; + connectFriendWizard->setAttribute(Qt::WA_DeleteOnClose, true); connectFriendWizard->setGpgId(mGpgId, mSslId, true); connectFriendWizard->show(); diff --git a/retroshare-gui/src/gui/feeds/SecurityItem.ui b/retroshare-gui/src/gui/feeds/SecurityItem.ui index 8e4d10967..54bb46645 100644 --- a/retroshare-gui/src/gui/feeds/SecurityItem.ui +++ b/retroshare-gui/src/gui/feeds/SecurityItem.ui @@ -6,8 +6,8 @@ 0 0 - 763 - 246 + 1196 + 491 @@ -354,7 +354,7 @@ - + 75 @@ -367,7 +367,7 @@ - + 75 @@ -380,7 +380,7 @@ - + 0 @@ -399,7 +399,7 @@ - + 75 @@ -412,7 +412,7 @@ - + 75 @@ -425,7 +425,7 @@ - + 75 @@ -578,8 +578,8 @@ - + From 11c520d28061a889db12bc24735b5a16e71921a1 Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 15 Dec 2019 16:46:22 +0100 Subject: [PATCH 21/39] replaced QString output of uniqueIdentifier() in feedItem classes by a std::string because QString caused random crashes --- libretroshare/src/services/p3rtt.cc | 1 + libretroshare/src/services/p3rtt.h | 2 ++ retroshare-gui/src/gui/Posted/PostedItem.h | 2 +- retroshare-gui/src/gui/common/RSFeedWidget.cpp | 4 ++-- retroshare-gui/src/gui/common/RSFeedWidget.h | 2 +- retroshare-gui/src/gui/feeds/ChatMsgItem.h | 2 +- retroshare-gui/src/gui/feeds/FeedItem.h | 2 +- retroshare-gui/src/gui/feeds/GxsChannelGroupItem.h | 2 +- retroshare-gui/src/gui/feeds/GxsChannelPostItem.h | 2 +- retroshare-gui/src/gui/feeds/GxsCircleItem.cpp | 4 ++-- retroshare-gui/src/gui/feeds/GxsCircleItem.h | 2 +- retroshare-gui/src/gui/feeds/GxsForumGroupItem.h | 2 +- retroshare-gui/src/gui/feeds/GxsForumMsgItem.h | 2 +- retroshare-gui/src/gui/feeds/MsgItem.h | 2 +- retroshare-gui/src/gui/feeds/PeerItem.cpp | 4 ++-- retroshare-gui/src/gui/feeds/PeerItem.h | 2 +- retroshare-gui/src/gui/feeds/PostedGroupItem.h | 2 +- retroshare-gui/src/gui/feeds/SecurityIpItem.cpp | 5 ++--- retroshare-gui/src/gui/feeds/SecurityIpItem.h | 2 +- retroshare-gui/src/gui/feeds/SecurityItem.cpp | 4 ++-- retroshare-gui/src/gui/feeds/SecurityItem.h | 2 +- 21 files changed, 27 insertions(+), 25 deletions(-) diff --git a/libretroshare/src/services/p3rtt.cc b/libretroshare/src/services/p3rtt.cc index dc3b37646..49d859b11 100644 --- a/libretroshare/src/services/p3rtt.cc +++ b/libretroshare/src/services/p3rtt.cc @@ -442,6 +442,7 @@ bool RttPeerInfo::initialisePeerInfo(const RsPeerId& id) mCurrentPingTS = 0; mCurrentPingCounter = 0; mCurrentPongRecvd = true; + mCurrentMeanOffset = 0; mSentPings = 0; mLostPongs = 0; diff --git a/libretroshare/src/services/p3rtt.h b/libretroshare/src/services/p3rtt.h index 80a369d17..c8df64034 100644 --- a/libretroshare/src/services/p3rtt.h +++ b/libretroshare/src/services/p3rtt.h @@ -34,6 +34,8 @@ class p3ServiceControl; class RttPeerInfo { public: + RttPeerInfo() + : mCurrentPingTS(0.0),mCurrentPingCounter(0.0),mCurrentPongRecvd(false),mCurrentMeanOffset(0.0),mLostPongs(0),mSentPings(0){} bool initialisePeerInfo(const RsPeerId& id); diff --git a/retroshare-gui/src/gui/Posted/PostedItem.h b/retroshare-gui/src/gui/Posted/PostedItem.h index ba8c04492..94bb12ed7 100644 --- a/retroshare-gui/src/gui/Posted/PostedItem.h +++ b/retroshare-gui/src/gui/Posted/PostedItem.h @@ -49,7 +49,7 @@ public: const RsPostedPost &getPost() const; RsPostedPost &post(); - QString uniqueIdentifier() const override { return "PostedItem " + QString::fromStdString(mMessageId.toStdString()); } + std::string uniqueIdentifier() const override { return "PostedItem " + mMessageId.toStdString(); } protected: /* FeedItem */ virtual void doExpand(bool open); diff --git a/retroshare-gui/src/gui/common/RSFeedWidget.cpp b/retroshare-gui/src/gui/common/RSFeedWidget.cpp index 8d853b55d..396520e3a 100644 --- a/retroshare-gui/src/gui/common/RSFeedWidget.cpp +++ b/retroshare-gui/src/gui/common/RSFeedWidget.cpp @@ -476,10 +476,10 @@ void RSFeedWidget::withAll(RSFeedWidgetCallbackFunction callback, void *data) } } -FeedItem *RSFeedWidget::findFeedItem(const QString& identifier) +FeedItem *RSFeedWidget::findFeedItem(const std::string& identifier) { QTreeWidgetItemIterator it(ui->treeWidget); - QTreeWidgetItem *treeItem; + QTreeWidgetItem *treeItem=NULL; // this search could probably be automatised by giving the tree items the identifier as data for some specific role, then calling QTreeWidget::findItems() #warning TODO diff --git a/retroshare-gui/src/gui/common/RSFeedWidget.h b/retroshare-gui/src/gui/common/RSFeedWidget.h index b83b9814a..e5997f806 100644 --- a/retroshare-gui/src/gui/common/RSFeedWidget.h +++ b/retroshare-gui/src/gui/common/RSFeedWidget.h @@ -71,7 +71,7 @@ public: bool scrollTo(FeedItem *feedItem, bool focus); void withAll(RSFeedWidgetCallbackFunction callback, void *data); - FeedItem *findFeedItem(const QString &identifier); + FeedItem *findFeedItem(const std::string &identifier); void selectedFeedItems(QList &feedItems); diff --git a/retroshare-gui/src/gui/feeds/ChatMsgItem.h b/retroshare-gui/src/gui/feeds/ChatMsgItem.h index 4222fb23c..6dad0d215 100644 --- a/retroshare-gui/src/gui/feeds/ChatMsgItem.h +++ b/retroshare-gui/src/gui/feeds/ChatMsgItem.h @@ -37,7 +37,7 @@ public: void updateItemStatic(); - virtual QString uniqueIdentifier() const override { return "ChatMsgItem " + QString::fromStdString(mPeerId.toStdString()) ;} + virtual std::string uniqueIdentifier() const override { return "ChatMsgItem " + mPeerId.toStdString(); } protected: /* FeedItem */ virtual void doExpand(bool /*open*/) {} diff --git a/retroshare-gui/src/gui/feeds/FeedItem.h b/retroshare-gui/src/gui/feeds/FeedItem.h index f7128e737..d377fb027 100644 --- a/retroshare-gui/src/gui/feeds/FeedItem.h +++ b/retroshare-gui/src/gui/feeds/FeedItem.h @@ -41,7 +41,7 @@ public: * \return returns a string that is unique to this specific item. The string will be used to search for an existing item that * would contain the same information. It should therefore sumarise the data represented by the item. */ - virtual QString uniqueIdentifier() const =0; + virtual std::string uniqueIdentifier() const =0; protected: virtual void doExpand(bool open) = 0; virtual void expandFill(bool /*first*/) {} diff --git a/retroshare-gui/src/gui/feeds/GxsChannelGroupItem.h b/retroshare-gui/src/gui/feeds/GxsChannelGroupItem.h index 273f50d39..5c51b396a 100644 --- a/retroshare-gui/src/gui/feeds/GxsChannelGroupItem.h +++ b/retroshare-gui/src/gui/feeds/GxsChannelGroupItem.h @@ -42,7 +42,7 @@ public: bool setGroup(const RsGxsChannelGroup &group); - QString uniqueIdentifier() const override { return "GxsChannelGroupItem " + QString::fromStdString(mGroup.mMeta.mGroupId.toStdString()) ; } + std::string uniqueIdentifier() const override { return "GxsChannelGroupItem " + mGroup.mMeta.mGroupId.toStdString() ; } protected: /* FeedItem */ virtual void doExpand(bool open); diff --git a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.h b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.h index 366637c0b..a68c25e5d 100644 --- a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.h +++ b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.h @@ -53,7 +53,7 @@ public: //GxsChannelPostItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsChannelPost &post, bool isHome, bool autoUpdate); virtual ~GxsChannelPostItem(); - virtual QString uniqueIdentifier() const override { "GxsChannelPostItem " + QString::fromStdString(mPost.mMeta.mMsgId.toStdString()) ; } + virtual std::string uniqueIdentifier() const override { "GxsChannelPostItem " + mPost.mMeta.mMsgId.toStdString() ; } bool setGroup(const RsGxsChannelGroup &group, bool doFill = true); bool setPost(const RsGxsChannelPost &post, bool doFill = true); diff --git a/retroshare-gui/src/gui/feeds/GxsCircleItem.cpp b/retroshare-gui/src/gui/feeds/GxsCircleItem.cpp index 582d1be47..c7175d4d4 100644 --- a/retroshare-gui/src/gui/feeds/GxsCircleItem.cpp +++ b/retroshare-gui/src/gui/feeds/GxsCircleItem.cpp @@ -167,9 +167,9 @@ void GxsCircleItem::setup() } -QString GxsCircleItem::uniqueIdentifier() const +std::string GxsCircleItem::uniqueIdentifier() const { - return "GxsCircle " + QString::fromStdString(mCircleId.toStdString()) + " " + QString::fromStdString(mGxsId.toStdString()) + " " + QString::number(mType); + return "GxsCircle " + mCircleId.toStdString() + " " + mGxsId.toStdString() + " " + QString::number(mType).toStdString(); } void GxsCircleItem::removeItem() diff --git a/retroshare-gui/src/gui/feeds/GxsCircleItem.h b/retroshare-gui/src/gui/feeds/GxsCircleItem.h index 7aeb457ca..f8c66edbb 100644 --- a/retroshare-gui/src/gui/feeds/GxsCircleItem.h +++ b/retroshare-gui/src/gui/feeds/GxsCircleItem.h @@ -52,7 +52,7 @@ public: GxsCircleItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsCircleId &circleId, const RsGxsId &gxsId, const uint32_t type); virtual ~GxsCircleItem(); - QString uniqueIdentifier() const override; + std::string uniqueIdentifier() const override; void loadRequest(const TokenQueue *queue, const TokenRequest &req); diff --git a/retroshare-gui/src/gui/feeds/GxsForumGroupItem.h b/retroshare-gui/src/gui/feeds/GxsForumGroupItem.h index 76587ad9c..a6cf6e129 100644 --- a/retroshare-gui/src/gui/feeds/GxsForumGroupItem.h +++ b/retroshare-gui/src/gui/feeds/GxsForumGroupItem.h @@ -42,7 +42,7 @@ public: bool setGroup(const RsGxsForumGroup &group); - virtual QString uniqueIdentifier() const override { return "GxsForumGroupItem " + QString::fromStdString(mGroup.mMeta.mGroupId.toStdString()) ; } + virtual std::string uniqueIdentifier() const override { return "GxsForumGroupItem " + mGroup.mMeta.mGroupId.toStdString() ; } protected: /* FeedItem */ virtual void doExpand(bool open); diff --git a/retroshare-gui/src/gui/feeds/GxsForumMsgItem.h b/retroshare-gui/src/gui/feeds/GxsForumMsgItem.h index b241fa594..3563ed63a 100644 --- a/retroshare-gui/src/gui/feeds/GxsForumMsgItem.h +++ b/retroshare-gui/src/gui/feeds/GxsForumMsgItem.h @@ -43,7 +43,7 @@ public: bool setGroup(const RsGxsForumGroup &group, bool doFill = true); bool setMessage(const RsGxsForumMsg &msg, bool doFill = true); - QString uniqueIdentifier() const override { return "GxsForumMsgItem " + QString::fromStdString(mMessage.mMeta.mMsgId.toStdString()) ; } + std::string uniqueIdentifier() const override { return "GxsForumMsgItem " + mMessage.mMeta.mMsgId.toStdString() ; } protected: /* FeedItem */ virtual void doExpand(bool open); diff --git a/retroshare-gui/src/gui/feeds/MsgItem.h b/retroshare-gui/src/gui/feeds/MsgItem.h index 5fe0d0485..bcf9af30f 100644 --- a/retroshare-gui/src/gui/feeds/MsgItem.h +++ b/retroshare-gui/src/gui/feeds/MsgItem.h @@ -38,7 +38,7 @@ public: void updateItemStatic(); - virtual QString uniqueIdentifier() const override { return "MsgItem " + QString::fromStdString(mMsgId) ; } + virtual std::string uniqueIdentifier() const override { return "MsgItem " + mMsgId ; } protected: /* FeedItem */ virtual void doExpand(bool open); diff --git a/retroshare-gui/src/gui/feeds/PeerItem.cpp b/retroshare-gui/src/gui/feeds/PeerItem.cpp index 324a0b78b..2db7aa8f5 100644 --- a/retroshare-gui/src/gui/feeds/PeerItem.cpp +++ b/retroshare-gui/src/gui/feeds/PeerItem.cpp @@ -67,9 +67,9 @@ PeerItem::PeerItem(FeedHolder *parent, uint32_t feedId, const RsPeerId &peerId, updateItem(); } -QString PeerItem::uniqueIdentifier() const +std::string PeerItem::uniqueIdentifier() const { - return "PeerItem " + QString::fromStdString(mPeerId.toStdString()) + " " + QString::number(mType) ; + return "PeerItem " + mPeerId.toStdString() + " " + QString::number(mType).toStdString() ; } void PeerItem::updateItemStatic() diff --git a/retroshare-gui/src/gui/feeds/PeerItem.h b/retroshare-gui/src/gui/feeds/PeerItem.h index 40b7d384b..ba108a92b 100644 --- a/retroshare-gui/src/gui/feeds/PeerItem.h +++ b/retroshare-gui/src/gui/feeds/PeerItem.h @@ -43,7 +43,7 @@ public: void updateItemStatic(); - virtual QString uniqueIdentifier() const; + std::string uniqueIdentifier() const override; protected: /* FeedItem */ diff --git a/retroshare-gui/src/gui/feeds/PostedGroupItem.h b/retroshare-gui/src/gui/feeds/PostedGroupItem.h index 2994971fd..f4ab14d39 100644 --- a/retroshare-gui/src/gui/feeds/PostedGroupItem.h +++ b/retroshare-gui/src/gui/feeds/PostedGroupItem.h @@ -42,7 +42,7 @@ public: bool setGroup(const RsPostedGroup &group); - virtual QString uniqueIdentifier() const override { return "PostedGroupItem " + QString::fromStdString(mGroup.mMeta.mGroupId.toStdString()) ; } + virtual std::string uniqueIdentifier() const override { return "PostedGroupItem " + mGroup.mMeta.mGroupId.toStdString() ; } protected: /* FeedItem */ diff --git a/retroshare-gui/src/gui/feeds/SecurityIpItem.cpp b/retroshare-gui/src/gui/feeds/SecurityIpItem.cpp index e7d7de5d9..0ddc24fa1 100644 --- a/retroshare-gui/src/gui/feeds/SecurityIpItem.cpp +++ b/retroshare-gui/src/gui/feeds/SecurityIpItem.cpp @@ -78,10 +78,9 @@ void SecurityIpItem::setup() updateItem(); } -QString SecurityIpItem::uniqueIdentifier() const +std::string SecurityIpItem::uniqueIdentifier() const { - return "SecurityItem " + QString::number(mType) + " " + QString::fromStdString(mSslId.toStdString()) - + " " + QString::fromStdString(mIpAddr) + " " + QString::fromStdString(mIpAddrReported) ; + return "SecurityItem " + QString::number(mType).toStdString() + " " + mSslId.toStdString() + " " + mIpAddr + " " + mIpAddrReported ; } void SecurityIpItem::updateItemStatic() diff --git a/retroshare-gui/src/gui/feeds/SecurityIpItem.h b/retroshare-gui/src/gui/feeds/SecurityIpItem.h index f7002ffb7..bba36a70b 100644 --- a/retroshare-gui/src/gui/feeds/SecurityIpItem.h +++ b/retroshare-gui/src/gui/feeds/SecurityIpItem.h @@ -43,7 +43,7 @@ public: void updateItemStatic(); - QString uniqueIdentifier() const override; + std::string uniqueIdentifier() const override; protected: /* FeedItem */ diff --git a/retroshare-gui/src/gui/feeds/SecurityItem.cpp b/retroshare-gui/src/gui/feeds/SecurityItem.cpp index 8609069f0..751c0c0da 100644 --- a/retroshare-gui/src/gui/feeds/SecurityItem.cpp +++ b/retroshare-gui/src/gui/feeds/SecurityItem.cpp @@ -81,9 +81,9 @@ SecurityItem::SecurityItem(FeedHolder *parent, uint32_t feedId, const RsPgpId &g updateItem(); } -QString SecurityItem::uniqueIdentifier() const +std::string SecurityItem::uniqueIdentifier() const { - return "SecurityItem " + QString::number(mType) + " " + QString::fromStdString(mSslId.toStdString()); + return "SecurityItem " + QString::number(mType).toStdString() + " " + mSslId.toStdString(); } void SecurityItem::updateItemStatic() diff --git a/retroshare-gui/src/gui/feeds/SecurityItem.h b/retroshare-gui/src/gui/feeds/SecurityItem.h index bc508edfc..99bb89673 100644 --- a/retroshare-gui/src/gui/feeds/SecurityItem.h +++ b/retroshare-gui/src/gui/feeds/SecurityItem.h @@ -42,7 +42,7 @@ public: void updateItemStatic(); - QString uniqueIdentifier() const override; + std::string uniqueIdentifier() const override; protected: /* FeedItem */ From 459ddc8883caf136d8f4381a12f30818dbe3180a Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 15 Dec 2019 18:40:42 +0100 Subject: [PATCH 22/39] fixed bug caused by comparing temporary object output of uniqueIdentifier() method to another string --- retroshare-gui/src/gui/common/RSFeedWidget.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/retroshare-gui/src/gui/common/RSFeedWidget.cpp b/retroshare-gui/src/gui/common/RSFeedWidget.cpp index 396520e3a..dab4ed5f8 100644 --- a/retroshare-gui/src/gui/common/RSFeedWidget.cpp +++ b/retroshare-gui/src/gui/common/RSFeedWidget.cpp @@ -491,7 +491,14 @@ FeedItem *RSFeedWidget::findFeedItem(const std::string& identifier) continue; } - if (feedItem->uniqueIdentifier() == identifier) + // (cyril) It seems that a local variable must be used to store this identifier. + // Directly comparing identifier such as in: + // if(feedItem->uniqueIdentifier() == identifier) + // causes a crash. I dont know why! If someone ever finds why, please tell me. + + std::string id = feedItem->uniqueIdentifier(); + + if (id == identifier) return feedItem; } From 301874e7563bfbab632a43b6f369344646c48884 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 16 Dec 2019 21:09:53 +0100 Subject: [PATCH 23/39] fixed output of IP in PeerItem --- retroshare-gui/src/gui/feeds/PeerItem.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/retroshare-gui/src/gui/feeds/PeerItem.cpp b/retroshare-gui/src/gui/feeds/PeerItem.cpp index 2db7aa8f5..1d663a7c3 100644 --- a/retroshare-gui/src/gui/feeds/PeerItem.cpp +++ b/retroshare-gui/src/gui/feeds/PeerItem.cpp @@ -187,7 +187,19 @@ void PeerItem::updateItem() statusLabel->setText(status); trustLabel->setText(QString::fromStdString(RsPeerTrustString(details.trustLvl))); - ipLabel->setText(QString("%1:%2/%3:%4").arg(QString::fromStdString(details.localAddr)).arg(details.localPort).arg(QString::fromStdString(details.extAddr)).arg(details.extPort)); + QString ip_string; + + if(details.localPort != 0) + ip_string += QString("%1:%2").arg(QString::fromStdString(details.localAddr)).arg(details.localPort); + + if(details.extPort != 0) + { + if(!ip_string.isNull()) + ip_string += "/" ; + + ip_string += ip_string += QString("%1:%2").arg(QString::fromStdString(details.extAddr)).arg(details.extPort); + } + ipLabel->setText(ip_string); connLabel->setText(StatusDefs::connectStateString(details)); From a54cf981a667a82024494c4dc2cbdfd39dd25f25 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 16 Dec 2019 22:44:37 +0100 Subject: [PATCH 24/39] fixed forum/channel subscribe notifications --- libretroshare/src/retroshare/rsgxschannels.h | 13 +- libretroshare/src/retroshare/rsgxsforums.h | 11 +- libretroshare/src/services/p3gxschannels.cc | 90 ++++--- libretroshare/src/services/p3gxsforums.cc | 220 +++++++++++------- libretroshare/src/services/p3gxsforums.h | 1 + .../src/gui/gxschannels/GxsChannelDialog.cpp | 22 ++ .../src/gui/gxschannels/GxsChannelDialog.h | 4 + .../src/gui/gxsforums/GxsForumsDialog.cpp | 24 ++ .../src/gui/gxsforums/GxsForumsDialog.h | 4 + 9 files changed, 254 insertions(+), 135 deletions(-) diff --git a/libretroshare/src/retroshare/rsgxschannels.h b/libretroshare/src/retroshare/rsgxschannels.h index 1ddccacb9..af0dc06b2 100644 --- a/libretroshare/src/retroshare/rsgxschannels.h +++ b/libretroshare/src/retroshare/rsgxschannels.h @@ -108,12 +108,13 @@ struct RsGxsChannelEvent: RsEvent : RsEvent(RsEventType::GXS_CHANNELS), mChannelEventCode(UNKNOWN) {} enum ChannelEventCode: uint8_t { - UNKNOWN = 0x00, - NEW_CHANNEL = 0x01, // emitted when new channel is received - UPDATED_CHANNEL = 0x02, // emitted when existing channel is updated - NEW_MESSAGE = 0x03, // new message reeived in a particular channel (group and msg id) - UPDATED_MESSAGE = 0x04, // existing message has been updated in a particular channel (group and msg id) - RECEIVED_PUBLISH_KEY = 0x05, // publish key for this channel has been received. + UNKNOWN = 0x00, + NEW_CHANNEL = 0x01, // emitted when new channel is received + UPDATED_CHANNEL = 0x02, // emitted when existing channel is updated + NEW_MESSAGE = 0x03, // new message reeived in a particular channel (group and msg id) + UPDATED_MESSAGE = 0x04, // existing message has been updated in a particular channel (group and msg id) + RECEIVED_PUBLISH_KEY = 0x05, // publish key for this channel has been received. + SUBSCRIBE_STATUS_CHANGED = 0x06, // subscription for channel mChannelGroupId changed. }; ChannelEventCode mChannelEventCode; diff --git a/libretroshare/src/retroshare/rsgxsforums.h b/libretroshare/src/retroshare/rsgxsforums.h index 20ee67ee9..1bb0d0e4e 100644 --- a/libretroshare/src/retroshare/rsgxsforums.h +++ b/libretroshare/src/retroshare/rsgxsforums.h @@ -110,11 +110,12 @@ struct RsGxsForumEvent: RsEvent : RsEvent(RsEventType::GXS_FORUMS), mForumEventCode(UNKNOWN) {} enum ForumEventCode: uint8_t { - UNKNOWN = 0x00, - NEW_FORUM = 0x01, // emitted when new forum is received - UPDATED_FORUM = 0x02, // emitted when existing forum is updated - NEW_MESSAGE = 0x03, // new message reeived in a particular forum (group and msg id) - UPDATED_MESSAGE = 0x04, // existing message has been updated in a particular forum (group and msg id) + UNKNOWN = 0x00, + NEW_FORUM = 0x01, // emitted when new forum is received + UPDATED_FORUM = 0x02, // emitted when existing forum is updated + NEW_MESSAGE = 0x03, // new message reeived in a particular forum (group and msg id) + UPDATED_MESSAGE = 0x04, // existing message has been updated in a particular forum (group and msg id) + SUBSCRIBE_STATUS_CHANGED = 0x05, // forum was subscribed or unsubscribed }; ForumEventCode mForumEventCode; diff --git a/libretroshare/src/services/p3gxschannels.cc b/libretroshare/src/services/p3gxschannels.cc index ecb354299..47a0cd1a6 100644 --- a/libretroshare/src/services/p3gxschannels.cc +++ b/libretroshare/src/services/p3gxschannels.cc @@ -256,13 +256,13 @@ void p3GxsChannels::notifyChanges(std::vector &changes) for (auto mit = msgChangeMap.begin(); mit != msgChangeMap.end(); ++mit) for (auto mit1 = mit->second.begin(); mit1 != mit->second.end(); ++mit1) { - auto ev = std::make_shared(); + auto ev = std::make_shared(); - ev->mChannelMsgId = *mit1; - ev->mChannelGroupId = mit->first; - ev->mChannelEventCode = RsGxsChannelEvent::NEW_MESSAGE; + ev->mChannelMsgId = *mit1; + ev->mChannelGroupId = mit->first; + ev->mChannelEventCode = RsGxsChannelEvent::NEW_MESSAGE; - rsEvents->sendEvent(ev); + rsEvents->sendEvent(ev); } } } @@ -305,53 +305,67 @@ void p3GxsChannels::notifyChanges(std::vector &changes) { switch (grpChange->getType()) { - default: - case RsGxsNotify::TYPE_PROCESSED: - case RsGxsNotify::TYPE_PUBLISHED: - break; - - case RsGxsNotify::TYPE_RECEIVED_NEW: + default: + case RsGxsNotify::TYPE_PROCESSED: // happens when the group is subscribed + { + std::list &grpList = grpChange->mGrpIdList; + std::list::iterator git; + for (git = grpList.begin(); git != grpList.end(); ++git) { - /* group received */ - std::list &grpList = grpChange->mGrpIdList; - std::list::iterator git; - RS_STACK_MUTEX(mKnownChannelsMutex); - for (git = grpList.begin(); git != grpList.end(); ++git) - { - if(mKnownChannels.find(*git) == mKnownChannels.end()) - { - mKnownChannels.insert(std::make_pair(*git,time(NULL))) ; - IndicateConfigChanged(); + auto ev = std::make_shared(); - auto ev = std::make_shared(); + ev->mChannelGroupId = *git; + ev->mChannelEventCode = RsGxsChannelEvent::SUBSCRIBE_STATUS_CHANGED; - ev->mChannelGroupId = *git; - ev->mChannelEventCode = RsGxsChannelEvent::NEW_CHANNEL; - - rsEvents->sendEvent(ev); - } - else - std::cerr << "(II) Not notifying already known channel " << *git << std::endl; - } - break; + rsEvents->sendEvent(ev); } - case RsGxsNotify::TYPE_RECEIVED_PUBLISHKEY: + } + break; + + case RsGxsNotify::TYPE_PUBLISHED: + case RsGxsNotify::TYPE_RECEIVED_NEW: + { + /* group received */ + std::list &grpList = grpChange->mGrpIdList; + std::list::iterator git; + RS_STACK_MUTEX(mKnownChannelsMutex); + for (git = grpList.begin(); git != grpList.end(); ++git) { - /* group received */ - std::list &grpList = grpChange->mGrpIdList; - std::list::iterator git; - for (git = grpList.begin(); git != grpList.end(); ++git) + if(mKnownChannels.find(*git) == mKnownChannels.end()) { + mKnownChannels.insert(std::make_pair(*git,time(NULL))) ; + IndicateConfigChanged(); + auto ev = std::make_shared(); ev->mChannelGroupId = *git; - ev->mChannelEventCode = RsGxsChannelEvent::RECEIVED_PUBLISH_KEY; + ev->mChannelEventCode = RsGxsChannelEvent::NEW_CHANNEL; rsEvents->sendEvent(ev); } - break; + else + std::cerr << "(II) Not notifying already known channel " << *git << std::endl; } + break; + } + + case RsGxsNotify::TYPE_RECEIVED_PUBLISHKEY: + { + /* group received */ + std::list &grpList = grpChange->mGrpIdList; + std::list::iterator git; + for (git = grpList.begin(); git != grpList.end(); ++git) + { + auto ev = std::make_shared(); + + ev->mChannelGroupId = *git; + ev->mChannelEventCode = RsGxsChannelEvent::RECEIVED_PUBLISH_KEY; + + rsEvents->sendEvent(ev); + } + break; + } } } } diff --git a/libretroshare/src/services/p3gxsforums.cc b/libretroshare/src/services/p3gxsforums.cc index 8750ca18d..f0e025a34 100644 --- a/libretroshare/src/services/p3gxsforums.cc +++ b/libretroshare/src/services/p3gxsforums.cc @@ -53,7 +53,7 @@ p3GxsForums::p3GxsForums( RsGeneralDataService *gds, RsGenExchange( gds, nes, new RsGxsForumSerialiser(), RS_SERVICE_GXS_TYPE_FORUMS, gixs, forumsAuthenPolicy()), RsGxsForums(static_cast(*this)), mGenToken(0), - mGenActive(false), mGenCount(0) + mGenActive(false), mGenCount(0), mKnownForumsMutex("GXS forums known forums timestamp cache") { // Test Data disabled in Repo. //RsTickEvent::schedule_in(FORUM_TESTEVENT_DUMMYDATA, DUMMYDATA_PERIOD); @@ -181,95 +181,143 @@ RsSerialiser* p3GxsForums::setupSerialiser() void p3GxsForums::notifyChanges(std::vector &changes) { - if (!changes.empty()) - { - if (rsEvents) - { - std::vector::iterator it; - for(it = changes.begin(); it != changes.end(); ++it) - { - RsGxsNotify *c = *it; - - switch (c->getType()) - { - default: - case RsGxsNotify::TYPE_PROCESSED: - case RsGxsNotify::TYPE_PUBLISHED: - break; - - case RsGxsNotify::TYPE_RECEIVED_NEW: - { - RsGxsMsgChange *msgChange = dynamic_cast(c); - if (msgChange) - { - std::map > &msgChangeMap = msgChange->msgChangeMap; - - for (auto mit = msgChangeMap.begin(); mit != msgChangeMap.end(); ++mit) - for (auto mit1 = mit->second.begin(); mit1 != mit->second.end(); ++mit1) - { - auto ev = std::make_shared(); - - ev->mForumGroupId = mit->first; - ev->mForumMsgId = *mit1; - ev->mForumEventCode = RsGxsForumEvent::NEW_MESSAGE; - - rsEvents->sendEvent(ev); - } - - break; - } - - RsGxsGroupChange *grpChange = dynamic_cast(*it); - if (grpChange) - { - /* group received */ - std::list &grpList = grpChange->mGrpIdList; - std::list::iterator git; - - for (git = grpList.begin(); git != grpList.end(); ++git) - { - if(mKnownForums.find(*git) == mKnownForums.end()) - { - auto ev = std::make_shared(); - - ev->mForumGroupId = *git; - ev->mForumEventCode = RsGxsForumEvent::NEW_FORUM; - rsEvents->sendEvent(ev); - - mKnownForums.insert(std::make_pair(*git,time(NULL))) ; - IndicateConfigChanged(); - } - else - std::cerr << "(II) Not notifying already known forum " << *git << std::endl; - } - break; - } - break; - } -#ifdef UNUSED - // (Cyril) There's no publish key system for forums now. As a GXS group, it is possible to add one, just like channels - // but the possibility is not offered by the API yet. - - case RsGxsNotify::TYPE_RECEIVED_PUBLISHKEY: - { - RsGxsGroupChange *grpChange = dynamic_cast(*it); - if (grpChange) - { - /* group received */ - std::list &grpList = grpChange->mGrpIdList; - std::list::iterator git; - for (git = grpList.begin(); git != grpList.end(); ++git) - { - notify->AddFeedItem(RS_FEED_ITEM_FORUM_PUBLISHKEY, git->toStdString()); - } - break; - } - break; - } +#ifdef GXSFORUMS_DEBUG + std::cerr << "p3GxsForums::notifyChanges() : " << changes.size() << "changes to notify" << std::endl; #endif + + std::vector::iterator it; + for(it = changes.begin(); it != changes.end(); ++it) + { + RsGxsMsgChange *msgChange = dynamic_cast(*it); + if (msgChange) + { + if (msgChange->getType() == RsGxsNotify::TYPE_RECEIVED_NEW) /* message received */ + if (rsEvents) + { + std::map >& msgChangeMap = msgChange->msgChangeMap; + for (auto mit = msgChangeMap.begin(); mit != msgChangeMap.end(); ++mit) + for (auto mit1 = mit->second.begin(); mit1 != mit->second.end(); ++mit1) + { + auto ev = std::make_shared(); + + ev->mForumMsgId = *mit1; + ev->mForumGroupId = mit->first; + ev->mForumEventCode = RsGxsForumEvent::NEW_MESSAGE; + + rsEvents->sendEvent(ev); + } + } + +#ifdef NOT_USED_YET + if (!msgChange->metaChange()) + { +#ifdef GXSCHANNELS_DEBUG + std::cerr << "p3GxsForums::notifyChanges() Found Message Change Notification"; + std::cerr << std::endl; +#endif + + std::map > &msgChangeMap = msgChange->msgChangeMap; + for(auto mit = msgChangeMap.begin(); mit != msgChangeMap.end(); ++mit) + { +#ifdef GXSCHANNELS_DEBUG + std::cerr << "p3GxsForums::notifyChanges() Msgs for Group: " << mit->first; + std::cerr << std::endl; +#endif + bool enabled = false; + if (autoDownloadEnabled(mit->first, enabled) && enabled) + { +#ifdef GXSCHANNELS_DEBUG + std::cerr << "p3GxsChannels::notifyChanges() AutoDownload for Group: " << mit->first; + std::cerr << std::endl; +#endif + + /* problem is most of these will be comments and votes, + * should make it occasional - every 5mins / 10minutes TODO */ + unprocessedGroups.push_back(mit->first); + } } } +#endif } + else + { + if (rsEvents) + { + RsGxsGroupChange *grpChange = dynamic_cast(*it); + if (grpChange) + { + switch (grpChange->getType()) + { + default: + case RsGxsNotify::TYPE_PROCESSED: // happens when the group is subscribed + { + std::list &grpList = grpChange->mGrpIdList; + std::list::iterator git; + for (git = grpList.begin(); git != grpList.end(); ++git) + { + auto ev = std::make_shared(); + + ev->mForumGroupId = *git; + ev->mForumEventCode = RsGxsForumEvent::SUBSCRIBE_STATUS_CHANGED; + + rsEvents->sendEvent(ev); + } + + } + break; + + case RsGxsNotify::TYPE_PUBLISHED: + case RsGxsNotify::TYPE_RECEIVED_NEW: + { + /* group received */ + std::list &grpList = grpChange->mGrpIdList; + std::list::iterator git; + + RS_STACK_MUTEX(mKnownForumsMutex); + for (git = grpList.begin(); git != grpList.end(); ++git) + { + if(mKnownForums.find(*git) == mKnownForums.end()) + { + mKnownForums.insert(std::make_pair(*git,time(NULL))) ; + IndicateConfigChanged(); + + auto ev = std::make_shared(); + + ev->mForumGroupId = *git; + ev->mForumEventCode = RsGxsForumEvent::NEW_FORUM; + + rsEvents->sendEvent(ev); + } + else + std::cerr << "(II) Not notifying already known channel " << *git << std::endl; + } + break; + } + +#ifdef NOT_USED_YET + case RsGxsNotify::TYPE_RECEIVED_PUBLISHKEY: + { + /* group received */ + std::list &grpList = grpChange->mGrpIdList; + std::list::iterator git; + for (git = grpList.begin(); git != grpList.end(); ++git) + { + auto ev = std::make_shared(); + + ev->mChannelGroupId = *git; + ev->mChannelEventCode = RsGxsChannelEvent::RECEIVED_PUBLISH_KEY; + + rsEvents->sendEvent(ev); + } + } + break; +#endif + } + } + } + } + + /* shouldn't need to worry about groups - as they need to be subscribed to */ } RsGxsIfaceHelper::receiveChanges(changes); diff --git a/libretroshare/src/services/p3gxsforums.h b/libretroshare/src/services/p3gxsforums.h index 8d2ea3294..ae2bf74bf 100644 --- a/libretroshare/src/services/p3gxsforums.h +++ b/libretroshare/src/services/p3gxsforums.h @@ -166,4 +166,5 @@ bool generateGroup(uint32_t &token, std::string groupName); RsGxsMessageId mGenThreadId; std::map mKnownForums ; + RsMutex mKnownForumsMutex; }; diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.cpp index 915d490f8..4b0a7684e 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.cpp @@ -50,6 +50,28 @@ public: GxsChannelDialog::GxsChannelDialog(QWidget *parent) : GxsGroupFrameDialog(rsGxsChannels, parent,true) { + mEventHandlerId = 0; + // Needs to be asynced because this function is likely to be called by another thread! + rsEvents->registerEventsHandler( [this](std::shared_ptr event) { RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); }, mEventHandlerId ); +} + +void GxsChannelDialog::handleEvent_main_thread(std::shared_ptr event) +{ + if(event->mType == RsEventType::GXS_CHANNELS) + { + const RsGxsChannelEvent *e = dynamic_cast(event.get()); + + if(!e) + return; + + switch(e->mChannelEventCode) + { + case RsGxsChannelEvent::SUBSCRIBE_STATUS_CHANGED: updateDisplay(true); + break; + default: + break; + } + } } GxsChannelDialog::~GxsChannelDialog() diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.h b/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.h index eedde4833..5d80be518 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.h +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.h @@ -74,6 +74,10 @@ private: virtual QWidget *createCommentHeaderWidget(const RsGxsGroupId &grpId, const RsGxsMessageId &msgId); virtual uint32_t requestGroupSummaryType() { return GXS_REQUEST_TYPE_GROUP_DATA; } // request complete group data virtual void loadGroupSummaryToken(const uint32_t &token, std::list &groupInfo, RsUserdata* &userdata); + + void handleEvent_main_thread(std::shared_ptr event); + + RsEventsHandlerId_t mEventHandlerId; }; #endif diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumsDialog.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumsDialog.cpp index 34c2818f1..9749b9a26 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumsDialog.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumsDialog.cpp @@ -25,6 +25,7 @@ #include "GxsForumUserNotify.h" #include "gui/notifyqt.h" #include "gui/gxs/GxsGroupShareKey.h" +#include "util/qtthreadsutils.h" #include "gui/common/GroupTreeWidget.h" class GxsForumGroupInfoData : public RsUserdata @@ -41,6 +42,29 @@ GxsForumsDialog::GxsForumsDialog(QWidget *parent) : GxsGroupFrameDialog(rsGxsForums, parent) { mCountChildMsgs = true; + mEventHandlerId = 0; + // Needs to be asynced because this function is likely to be called by another thread! + + rsEvents->registerEventsHandler( [this](std::shared_ptr event) { RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); }, mEventHandlerId ); +} + +void GxsForumsDialog::handleEvent_main_thread(std::shared_ptr event) +{ + if(event->mType == RsEventType::GXS_FORUMS) + { + const RsGxsForumEvent *e = dynamic_cast(event.get()); + + if(!e) + return; + + switch(e->mForumEventCode) + { + case RsGxsForumEvent::SUBSCRIBE_STATUS_CHANGED: updateDisplay(true); + break; + default: + break; + } + } } GxsForumsDialog::~GxsForumsDialog() diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumsDialog.h b/retroshare-gui/src/gui/gxsforums/GxsForumsDialog.h index 39e182c88..6a21c8de9 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumsDialog.h +++ b/retroshare-gui/src/gui/gxsforums/GxsForumsDialog.h @@ -58,6 +58,10 @@ private: virtual GxsMessageFrameWidget *createMessageFrameWidget(const RsGxsGroupId &groupId); virtual uint32_t requestGroupSummaryType() { return GXS_REQUEST_TYPE_GROUP_DATA; } // request complete group data virtual void loadGroupSummaryToken(const uint32_t &token, std::list &groupInfo, RsUserdata* &userdata); + + void handleEvent_main_thread(std::shared_ptr event); + + RsEventsHandlerId_t mEventHandlerId; }; #endif From c348366eefee89f6413cef65ce072b02cffdee6c Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 16 Dec 2019 23:52:09 +0100 Subject: [PATCH 25/39] added notifications for channel posts --- .../gui/gxschannels/GxsChannelPostsWidget.cpp | 31 +++++++++++++++++++ .../gui/gxschannels/GxsChannelPostsWidget.h | 3 ++ .../gui/gxsforums/GxsForumThreadWidget.cpp | 29 +++++++++++++++++ .../src/gui/gxsforums/GxsForumThreadWidget.h | 3 ++ 4 files changed, 66 insertions(+) diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp index 9a3afbc3c..3ec13eb1c 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp @@ -128,6 +128,35 @@ GxsChannelPostsWidget::GxsChannelPostsWidget(const RsGxsGroupId &channelId, QWid setAutoDownload(false); settingsChanged(); setGroupId(channelId); + + mEventHandlerId = 0; + // Needs to be asynced because this function is likely to be called by another thread! + + rsEvents->registerEventsHandler( [this](std::shared_ptr event) { RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); }, mEventHandlerId ); +} + +void GxsChannelPostsWidget::handleEvent_main_thread(std::shared_ptr event) +{ + if(event->mType == RsEventType::GXS_CHANNELS) + { + const RsGxsChannelEvent *e = dynamic_cast(event.get()); + + if(!e) + return; + + switch(e->mChannelEventCode) + { + case RsGxsChannelEvent::UPDATED_CHANNEL: + case RsGxsChannelEvent::NEW_CHANNEL: + case RsGxsChannelEvent::UPDATED_MESSAGE: + case RsGxsChannelEvent::NEW_MESSAGE: + if(e->mChannelGroupId == mChannelGroupId) + updateDisplay(true); + break; + default: + break; + } + } } GxsChannelPostsWidget::~GxsChannelPostsWidget() @@ -712,6 +741,7 @@ bool GxsChannelPostsWidget::insertGroupData(const uint32_t &token, RsGroupMetaDa { insertChannelDetails(groups[0]); metaData = groups[0].mMeta; + mChannelGroupId = groups[0].mMeta.mGroupId; return true; } else @@ -721,6 +751,7 @@ bool GxsChannelPostsWidget::insertGroupData(const uint32_t &token, RsGroupMetaDa { insertChannelDetails(distant_group); metaData = distant_group.mMeta; + mChannelGroupId = distant_group.mMeta.mGroupId; return true ; } } diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.h b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.h index 40160146c..a4723c18f 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.h +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.h @@ -97,11 +97,14 @@ private: void insertChannelPosts(std::vector &posts, GxsMessageFramePostThread *thread, bool related); void createPostItem(const RsGxsChannelPost &post, bool related); + void handleEvent_main_thread(std::shared_ptr event); private: QAction *mAutoDownloadAction; bool mUseThread; + RsGxsGroupId mChannelGroupId; + RsEventsHandlerId_t mEventHandlerId ; /* UI - from Designer */ Ui::GxsChannelPostsWidget *ui; diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp index 37681273d..8cd399b48 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp @@ -432,6 +432,35 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget #ifdef SUSPENDED_CODE ui->threadTreeWidget->enableColumnCustomize(true); #endif + + mEventHandlerId = 0; + // Needs to be asynced because this function is likely to be called by another thread! + + rsEvents->registerEventsHandler( [this](std::shared_ptr event) { RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); }, mEventHandlerId ); +} + +void GxsForumThreadWidget::handleEvent_main_thread(std::shared_ptr event) +{ + if(event->mType == RsEventType::GXS_FORUMS) + { + const RsGxsForumEvent *e = dynamic_cast(event.get()); + + if(!e) + return; + + switch(e->mForumEventCode) + { + case RsGxsForumEvent::UPDATED_FORUM: + case RsGxsForumEvent::NEW_FORUM: + case RsGxsForumEvent::UPDATED_MESSAGE: + case RsGxsForumEvent::NEW_MESSAGE: + if(e->mForumGroupId == mForumGroup.mMeta.mGroupId) + updateDisplay(true); + break; + default: + break; + } + } } void GxsForumThreadWidget::blank() diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.h b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.h index 83fb0ea37..a548cda07 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.h +++ b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.h @@ -172,6 +172,8 @@ private: void updateMessageData(const RsGxsMessageId& msgId); void updateForumDescription(); + void handleEvent_main_thread(std::shared_ptr event); + private: RsGxsGroupId mLastForumID; RsGxsMessageId mThreadId; @@ -201,6 +203,7 @@ private: QList mSavedExpandedMessages; Ui::GxsForumThreadWidget *ui; + RsEventsHandlerId_t mEventHandlerId; }; #endif // GXSFORUMTHREADWIDGET_H From bdf5d0f753e4dd11e40cddb7b5b3bbdf20e08f64 Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 17 Dec 2019 14:10:18 +0100 Subject: [PATCH 26/39] changed RsGxsForumNotifyRecord into more appropriate RsGxsGroupNotifyRecord --- libretroshare/src/services/p3gxschannels.cc | 12 ++++++------ libretroshare/src/services/p3gxsforums.cc | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/libretroshare/src/services/p3gxschannels.cc b/libretroshare/src/services/p3gxschannels.cc index 47a0cd1a6..cf43e314f 100644 --- a/libretroshare/src/services/p3gxschannels.cc +++ b/libretroshare/src/services/p3gxschannels.cc @@ -136,14 +136,14 @@ uint32_t p3GxsChannels::channelsAuthenPolicy() static const uint32_t GXS_CHANNELS_CONFIG_MAX_TIME_NOTIFY_STORAGE = 86400*30*2 ; // ignore notifications for 2 months static const uint8_t GXS_CHANNELS_CONFIG_SUBTYPE_NOTIFY_RECORD = 0x01 ; -struct RsGxsForumNotifyRecordsItem: public RsItem +struct RsGxsGroupNotifyRecordsItem: public RsItem { - RsGxsForumNotifyRecordsItem() + RsGxsGroupNotifyRecordsItem() : RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_GXS_TYPE_CHANNELS_CONFIG,GXS_CHANNELS_CONFIG_SUBTYPE_NOTIFY_RECORD) {} - virtual ~RsGxsForumNotifyRecordsItem() {} + virtual ~RsGxsGroupNotifyRecordsItem() {} void serial_process( RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext& ctx ) @@ -167,7 +167,7 @@ public: switch(item_sub_id) { - case GXS_CHANNELS_CONFIG_SUBTYPE_NOTIFY_RECORD: return new RsGxsForumNotifyRecordsItem(); + case GXS_CHANNELS_CONFIG_SUBTYPE_NOTIFY_RECORD: return new RsGxsGroupNotifyRecordsItem(); default: return NULL; } @@ -178,7 +178,7 @@ bool p3GxsChannels::saveList(bool &cleanup, std::list&saveList) { cleanup = true ; - RsGxsForumNotifyRecordsItem *item = new RsGxsForumNotifyRecordsItem ; + RsGxsGroupNotifyRecordsItem *item = new RsGxsGroupNotifyRecordsItem ; { RS_STACK_MUTEX(mKnownChannelsMutex); @@ -198,7 +198,7 @@ bool p3GxsChannels::loadList(std::list& loadList) rstime_t now = time(NULL); - RsGxsForumNotifyRecordsItem *fnr = dynamic_cast(item) ; + RsGxsGroupNotifyRecordsItem *fnr = dynamic_cast(item) ; if(fnr) { diff --git a/libretroshare/src/services/p3gxsforums.cc b/libretroshare/src/services/p3gxsforums.cc index f0e025a34..362d03cd1 100644 --- a/libretroshare/src/services/p3gxsforums.cc +++ b/libretroshare/src/services/p3gxsforums.cc @@ -96,14 +96,14 @@ uint32_t p3GxsForums::forumsAuthenPolicy() static const uint32_t GXS_FORUMS_CONFIG_MAX_TIME_NOTIFY_STORAGE = 86400*30*2 ; // ignore notifications for 2 months static const uint8_t GXS_FORUMS_CONFIG_SUBTYPE_NOTIFY_RECORD = 0x01 ; -struct RsGxsForumNotifyRecordsItem: public RsItem +struct RsGxsGroupNotifyRecordsItem: public RsItem { - RsGxsForumNotifyRecordsItem() + RsGxsGroupNotifyRecordsItem() : RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_GXS_TYPE_FORUMS_CONFIG,GXS_FORUMS_CONFIG_SUBTYPE_NOTIFY_RECORD) {} - virtual ~RsGxsForumNotifyRecordsItem() {} + virtual ~RsGxsGroupNotifyRecordsItem() {} void serial_process( RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext& ctx ) @@ -127,7 +127,7 @@ public: switch(item_sub_id) { - case GXS_FORUMS_CONFIG_SUBTYPE_NOTIFY_RECORD: return new RsGxsForumNotifyRecordsItem(); + case GXS_FORUMS_CONFIG_SUBTYPE_NOTIFY_RECORD: return new RsGxsGroupNotifyRecordsItem(); default: return NULL; } @@ -138,7 +138,7 @@ bool p3GxsForums::saveList(bool &cleanup, std::list&saveList) { cleanup = true ; - RsGxsForumNotifyRecordsItem *item = new RsGxsForumNotifyRecordsItem ; + RsGxsGroupNotifyRecordsItem *item = new RsGxsGroupNotifyRecordsItem ; item->records = mKnownForums ; @@ -155,7 +155,7 @@ bool p3GxsForums::loadList(std::list& loadList) rstime_t now = time(NULL); - RsGxsForumNotifyRecordsItem *fnr = dynamic_cast(item) ; + RsGxsGroupNotifyRecordsItem *fnr = dynamic_cast(item) ; if(fnr != NULL) { From 639db4519bb2c974761a6d4aae8c7ee8f6033eeb Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 17 Dec 2019 15:11:37 +0100 Subject: [PATCH 27/39] added notification to count feed items --- retroshare-gui/src/gui/NewsFeed.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/retroshare-gui/src/gui/NewsFeed.cpp b/retroshare-gui/src/gui/NewsFeed.cpp index bd6b350ef..6b5cfd66b 100644 --- a/retroshare-gui/src/gui/NewsFeed.cpp +++ b/retroshare-gui/src/gui/NewsFeed.cpp @@ -456,6 +456,7 @@ void NewsFeed::addFeedItem(FeedItem *item) } ui->feedWidget->addFeedItem(item, ROLE_RECEIVED, QDateTime::currentDateTime()); + sendNewsFeedChanged(); } void NewsFeed::addFeedItemIfUnique(FeedItem *item, bool replace) @@ -475,6 +476,7 @@ void NewsFeed::addFeedItemIfUnique(FeedItem *item, bool replace) } addFeedItem(item); + sendNewsFeedChanged(); } void NewsFeed::remUniqueFeedItem(FeedItem *item) From baaa67d2251dff45e85d8f5ca31fcac3643b7b6b Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 17 Dec 2019 15:16:24 +0100 Subject: [PATCH 28/39] changed NO_ERROR enum into something less likely to collide with existing define --- libretroshare/src/retroshare/rsevents.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libretroshare/src/retroshare/rsevents.h b/libretroshare/src/retroshare/rsevents.h index 9e0d81cc2..0c4f4f768 100644 --- a/libretroshare/src/retroshare/rsevents.h +++ b/libretroshare/src/retroshare/rsevents.h @@ -197,7 +197,7 @@ struct RsAuthSslConnectionAutenticationEvent : RsEvent RsAuthSslConnectionAutenticationEvent() : RsEvent(RsEventType::AUTHSSL_CONNECTION_AUTENTICATION) {} enum ConnectionErrorCode: uint8_t { - NO_ERROR = 0x00, + NO_CONNECTION_ERROR = 0x00, MISSING_AUTHENTICATION_INFO = 0x01, PGP_SIGNATURE_VALIDATION_FAILED = 0x02, MISMATCHED_PGP_ID = 0x03, From d7504c59b5080e69804102fd05f48459ec8001fd Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 17 Dec 2019 15:29:47 +0100 Subject: [PATCH 29/39] fixing compilation on Travis CI --- libretroshare/src/pqi/authssl.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libretroshare/src/pqi/authssl.cc b/libretroshare/src/pqi/authssl.cc index 62515970a..569c461c4 100644 --- a/libretroshare/src/pqi/authssl.cc +++ b/libretroshare/src/pqi/authssl.cc @@ -1313,8 +1313,9 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx) return verificationFailed; } - +#ifdef AUTHSSL_DEBUG std::cerr << "******* VerifyX509Callback cert: " << std::hex << ctx->cert <getGPGOwnId() && !AuthGPG::getAuthGPG()->isGPGAccepted(pgpId) ) { From 3d7ae59df73d141daff321d6dca954451d0c592e Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 17 Dec 2019 21:41:21 +0100 Subject: [PATCH 30/39] changed enum to enum class and made names globally more consistent for RsEvents --- libretroshare/src/pqi/authssl.cc | 14 ++-- libretroshare/src/pqi/p3linkmgr.cc | 4 +- libretroshare/src/pqi/p3peermgr.cc | 2 +- libretroshare/src/pqi/pqissl.cc | 4 +- libretroshare/src/pqi/pqissllistener.cc | 2 +- libretroshare/src/retroshare/rsevents.h | 76 ------------------ libretroshare/src/retroshare/rsgxschannels.h | 6 +- libretroshare/src/retroshare/rsgxscircles.h | 6 +- libretroshare/src/retroshare/rsgxsforums.h | 4 +- libretroshare/src/retroshare/rspeers.h | 79 +++++++++++++++++++ libretroshare/src/retroshare/rsposted.h | 4 +- libretroshare/src/services/p3gxschannels.cc | 8 +- libretroshare/src/services/p3gxscircles.cc | 6 +- libretroshare/src/services/p3gxsforums.cc | 6 +- libretroshare/src/services/p3postbase.cc | 4 +- libretroshare/src/services/p3rtt.cc | 3 +- retroshare-gui/src/gui/NewsFeed.cpp | 58 +++++++------- .../src/gui/gxschannels/GxsChannelDialog.cpp | 2 +- .../gui/gxschannels/GxsChannelPostsWidget.cpp | 8 +- .../gui/gxsforums/GxsForumThreadWidget.cpp | 8 +- .../src/gui/gxsforums/GxsForumsDialog.cpp | 2 +- 21 files changed, 155 insertions(+), 151 deletions(-) diff --git a/libretroshare/src/pqi/authssl.cc b/libretroshare/src/pqi/authssl.cc index 569c461c4..f1d8da6eb 100644 --- a/libretroshare/src/pqi/authssl.cc +++ b/libretroshare/src/pqi/authssl.cc @@ -1222,7 +1222,7 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx) ev->mSslId = sslId; ev->mPgpId = pgpId; ev->mErrorMsg = errMsg; - ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::MISSING_AUTHENTICATION_INFO; + ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::AuthenticationCode::MISSING_AUTHENTICATION_INFO; rsEvents->postEvent(std::move(ev)); } @@ -1242,7 +1242,7 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx) ev->mSslId = sslId; ev->mSslCn = sslCn; ev->mErrorMsg = errMsg; - ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::MISSING_AUTHENTICATION_INFO; + ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::AuthenticationCode::MISSING_AUTHENTICATION_INFO; rsEvents->postEvent(std::move(ev)); } @@ -1273,7 +1273,7 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx) ev->mSslCn = sslCn; ev->mPgpId = pgpId; ev->mErrorMsg = errorMsg; - ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::MISMATCHED_PGP_ID; + ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::AuthenticationCode::MISMATCHED_PGP_ID; rsEvents->postEvent(std::move(ev)); } @@ -1301,10 +1301,10 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx) switch(auth_diagnostic) { - case RS_SSL_HANDSHAKE_DIAGNOSTIC_ISSUER_UNKNOWN: ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::NOT_A_FRIEND; break; - case RS_SSL_HANDSHAKE_DIAGNOSTIC_WRONG_SIGNATURE: ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::PGP_SIGNATURE_VALIDATION_FAILED;break; + case RS_SSL_HANDSHAKE_DIAGNOSTIC_ISSUER_UNKNOWN: ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::AuthenticationCode::NOT_A_FRIEND; break; + case RS_SSL_HANDSHAKE_DIAGNOSTIC_WRONG_SIGNATURE: ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::AuthenticationCode::PGP_SIGNATURE_VALIDATION_FAILED;break; default: - ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::MISSING_AUTHENTICATION_INFO;break; + ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::AuthenticationCode::MISSING_AUTHENTICATION_INFO;break; } ev->mErrorMsg = errMsg; @@ -1331,7 +1331,7 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx) ev->mSslCn = sslCn; ev->mPgpId = pgpId; ev->mErrorMsg = errMsg; - ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::NOT_A_FRIEND; + ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::AuthenticationCode::NOT_A_FRIEND; rsEvents->postEvent(std::move(ev)); } diff --git a/libretroshare/src/pqi/p3linkmgr.cc b/libretroshare/src/pqi/p3linkmgr.cc index 4440176c7..fe3ea0889 100644 --- a/libretroshare/src/pqi/p3linkmgr.cc +++ b/libretroshare/src/pqi/p3linkmgr.cc @@ -477,7 +477,7 @@ void p3LinkMgrIMPL::tickMonitors() { auto e = std::make_shared() ; - e->mConnectionInfoCode = RsConnectionEvent::PEER_CONNECTED; + e->mConnectionInfoCode = RsConnectionEvent::ConnectionEventCode::PEER_CONNECTED; e->mSslId = peer.id; rsEvents->postEvent(e); @@ -486,7 +486,7 @@ void p3LinkMgrIMPL::tickMonitors() { auto e = std::make_shared() ; - e->mConnectionInfoCode = RsConnectionEvent::PEER_DISCONNECTED; + e->mConnectionInfoCode = RsConnectionEvent::ConnectionEventCode::PEER_DISCONNECTED; e->mSslId = peer.id; rsEvents->postEvent(e); diff --git a/libretroshare/src/pqi/p3peermgr.cc b/libretroshare/src/pqi/p3peermgr.cc index 3f6a5f6ee..daf997a01 100644 --- a/libretroshare/src/pqi/p3peermgr.cc +++ b/libretroshare/src/pqi/p3peermgr.cc @@ -1814,7 +1814,7 @@ bool p3PeerMgrIMPL::addCandidateForOwnExternalAddress(const RsPeerId &from, cons ev->mSslId = from; ev->mStrInfo1 = sockaddr_storage_iptostring(addr); ev->mStrInfo2 = sockaddr_storage_iptostring(own_addr); - ev->mConnectionInfoCode = RsConnectionEvent::PEER_REPORTS_WRONG_IP; + ev->mConnectionInfoCode = RsConnectionEvent::ConnectionEventCode::PEER_REPORTS_WRONG_IP; rsEvents->postEvent(ev); } diff --git a/libretroshare/src/pqi/pqissl.cc b/libretroshare/src/pqi/pqissl.cc index 7337fc627..6cd29690e 100644 --- a/libretroshare/src/pqi/pqissl.cc +++ b/libretroshare/src/pqi/pqissl.cc @@ -1114,7 +1114,7 @@ int pqissl::SSL_Connection_Complete() X509 *x509 = SSL_get_peer_certificate(ssl_connection) ; ev->mSslId = RsX509Cert::getCertSslId(*x509); - ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::PEER_REFUSED_CONNECTION; + ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::AuthenticationCode::PEER_REFUSED_CONNECTION; rsEvents->postEvent(ev); } @@ -1283,7 +1283,7 @@ int pqissl::accept_locked( SSL *ssl, int fd, ev->mSslId = RsX509Cert::getCertSslId(*x509); ev->mLocator = RsUrl(foreign_addr); - ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::IP_IS_BLACKLISTED; + ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::AuthenticationCode::IP_IS_BLACKLISTED; rsEvents->postEvent(ev); } diff --git a/libretroshare/src/pqi/pqissllistener.cc b/libretroshare/src/pqi/pqissllistener.cc index 98eabe951..7b2d6d36f 100644 --- a/libretroshare/src/pqi/pqissllistener.cc +++ b/libretroshare/src/pqi/pqissllistener.cc @@ -483,7 +483,7 @@ int pqissllistenbase::continueSSL(IncomingSSLInfo& incoming_connexion_info, bool auto ev = std::unique_ptr(new RsAuthSslConnectionAutenticationEvent); ev->mLocator = RsUrl(incoming_connexion_info.addr); - ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::MISSING_AUTHENTICATION_INFO; + ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::AuthenticationCode::MISSING_AUTHENTICATION_INFO; rsEvents->postEvent(std::move(ev)); } diff --git a/libretroshare/src/retroshare/rsevents.h b/libretroshare/src/retroshare/rsevents.h index 0c4f4f768..249a6f50b 100644 --- a/libretroshare/src/retroshare/rsevents.h +++ b/libretroshare/src/retroshare/rsevents.h @@ -184,79 +184,3 @@ public: virtual ~RsEvents(); }; -//===================================================================================================// -// Connexion and security events // -//===================================================================================================// - -/** - * Event triggered by AuthSSL when authentication of a connection attempt either - * fail or success - */ -struct RsAuthSslConnectionAutenticationEvent : RsEvent -{ - RsAuthSslConnectionAutenticationEvent() : RsEvent(RsEventType::AUTHSSL_CONNECTION_AUTENTICATION) {} - - enum ConnectionErrorCode: uint8_t { - NO_CONNECTION_ERROR = 0x00, - MISSING_AUTHENTICATION_INFO = 0x01, - PGP_SIGNATURE_VALIDATION_FAILED = 0x02, - MISMATCHED_PGP_ID = 0x03, - NO_CERTIFICATE_SUPPLIED = 0x04, - NOT_A_FRIEND = 0x05, - MISSING_CERTIFICATE = 0x06, - IP_IS_BLACKLISTED = 0x07, - PEER_REFUSED_CONNECTION = 0x08, - UNKNOWN_ERROR = 0x09, - }; - - RsPeerId mSslId; - std::string mSslCn; - RsPgpId mPgpId; - RsUrl mLocator; - std::string mErrorMsg; - ConnectionErrorCode mErrorCode; - - ///* @see RsEvent @see RsSerializable - void serial_process( RsGenericSerializer::SerializeJob j, - RsGenericSerializer::SerializeContext& ctx) override - { - RsEvent::serial_process(j, ctx); - RS_SERIAL_PROCESS(mSslId); - RS_SERIAL_PROCESS(mSslCn); - RS_SERIAL_PROCESS(mPgpId); - RS_SERIAL_PROCESS(mLocator); - RS_SERIAL_PROCESS(mErrorMsg); - RS_SERIAL_PROCESS(mErrorCode); - } -}; - -struct RsConnectionEvent : RsEvent -{ - RsConnectionEvent() - : RsEvent(RsEventType::PEER_CONNECTION), - 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 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(mConnectionInfoCode); - RS_SERIAL_PROCESS(mSslId); - RS_SERIAL_PROCESS(mStrInfo1); - RS_SERIAL_PROCESS(mStrInfo2); - } -}; - diff --git a/libretroshare/src/retroshare/rsgxschannels.h b/libretroshare/src/retroshare/rsgxschannels.h index af0dc06b2..f3a70cf9e 100644 --- a/libretroshare/src/retroshare/rsgxschannels.h +++ b/libretroshare/src/retroshare/rsgxschannels.h @@ -105,12 +105,12 @@ struct RsGxsChannelPost : RsSerializable struct RsGxsChannelEvent: RsEvent { RsGxsChannelEvent() - : RsEvent(RsEventType::GXS_CHANNELS), mChannelEventCode(UNKNOWN) {} + : RsEvent(RsEventType::GXS_CHANNELS), mChannelEventCode(ChannelEventCode::UNKNOWN) {} - enum ChannelEventCode: uint8_t { + enum class ChannelEventCode: uint8_t { UNKNOWN = 0x00, NEW_CHANNEL = 0x01, // emitted when new channel is received - UPDATED_CHANNEL = 0x02, // emitted when existing channel is updated + UPDATED_CHANNEL = 0x02, // emitted when existing channel is updated NEW_MESSAGE = 0x03, // new message reeived in a particular channel (group and msg id) UPDATED_MESSAGE = 0x04, // existing message has been updated in a particular channel (group and msg id) RECEIVED_PUBLISH_KEY = 0x05, // publish key for this channel has been received. diff --git a/libretroshare/src/retroshare/rsgxscircles.h b/libretroshare/src/retroshare/rsgxscircles.h index 9f074c673..93fe90319 100644 --- a/libretroshare/src/retroshare/rsgxscircles.h +++ b/libretroshare/src/retroshare/rsgxscircles.h @@ -165,9 +165,9 @@ struct RsGxsCircleDetails : RsSerializable struct RsGxsCircleEvent: RsEvent { RsGxsCircleEvent() - : RsEvent(RsEventType::GXS_CIRCLES), mCircleEventType(UNKNOWN) {} + : RsEvent(RsEventType::GXS_CIRCLES), mCircleEventType(CircleEventCode::UNKNOWN) {} - enum CircleEventType: uint8_t { + enum class CircleEventCode: uint8_t { UNKNOWN = 0x00, CIRCLE_MEMBERSHIP_REQUEST = 0x01, // mCircleId contains the circle id and mGxsId is the id requesting membership CIRCLE_MEMBERSHIP_INVITE = 0x02, // mCircleId is the circle that invites me, and mGxsId is my own Id that is invited @@ -176,7 +176,7 @@ struct RsGxsCircleEvent: RsEvent CIRCLE_MEMBERSHIP_REVOQUED= 0x05, // mCircleId contains the circle id and mGxsId is the id that was revoqued by admin }; - CircleEventType mCircleEventType; + CircleEventCode mCircleEventType; RsGxsCircleId mCircleId; RsGxsId mGxsId; diff --git a/libretroshare/src/retroshare/rsgxsforums.h b/libretroshare/src/retroshare/rsgxsforums.h index 1bb0d0e4e..91f4dcbf9 100644 --- a/libretroshare/src/retroshare/rsgxsforums.h +++ b/libretroshare/src/retroshare/rsgxsforums.h @@ -107,9 +107,9 @@ struct RsGxsForumMsg : RsSerializable struct RsGxsForumEvent: RsEvent { RsGxsForumEvent() - : RsEvent(RsEventType::GXS_FORUMS), mForumEventCode(UNKNOWN) {} + : RsEvent(RsEventType::GXS_FORUMS), mForumEventCode(ForumEventCode::UNKNOWN) {} - enum ForumEventCode: uint8_t { + enum class ForumEventCode: uint8_t { UNKNOWN = 0x00, NEW_FORUM = 0x01, // emitted when new forum is received UPDATED_FORUM = 0x02, // emitted when existing forum is updated diff --git a/libretroshare/src/retroshare/rspeers.h b/libretroshare/src/retroshare/rspeers.h index bc1254658..3976d6861 100644 --- a/libretroshare/src/retroshare/rspeers.h +++ b/libretroshare/src/retroshare/rspeers.h @@ -206,6 +206,85 @@ std::string RsPeerTrustString(uint32_t trustLvl); std::string RsPeerNetModeString(uint32_t netModel); std::string RsPeerLastConnectString(uint32_t lastConnect); +//===================================================================================================// +// Connexion and security events // +//===================================================================================================// + +/** + * Event triggered by AuthSSL when authentication of a connection attempt either + * fail or success + */ +struct RsAuthSslConnectionAutenticationEvent : RsEvent +{ + RsAuthSslConnectionAutenticationEvent() : RsEvent(RsEventType::AUTHSSL_CONNECTION_AUTENTICATION) {} + + enum class AuthenticationCode: uint8_t { + NO_CONNECTION_ERROR = 0x00, + MISSING_AUTHENTICATION_INFO = 0x01, + PGP_SIGNATURE_VALIDATION_FAILED = 0x02, + MISMATCHED_PGP_ID = 0x03, + NO_CERTIFICATE_SUPPLIED = 0x04, + NOT_A_FRIEND = 0x05, + MISSING_CERTIFICATE = 0x06, + IP_IS_BLACKLISTED = 0x07, + PEER_REFUSED_CONNECTION = 0x08, + UNKNOWN_ERROR = 0x09, + }; + + RsPeerId mSslId; + std::string mSslCn; + RsPgpId mPgpId; + RsUrl mLocator; + std::string mErrorMsg; + AuthenticationCode mErrorCode; + + ///* @see RsEvent @see RsSerializable + void serial_process( RsGenericSerializer::SerializeJob j, + RsGenericSerializer::SerializeContext& ctx) override + { + RsEvent::serial_process(j, ctx); + RS_SERIAL_PROCESS(mSslId); + RS_SERIAL_PROCESS(mSslCn); + RS_SERIAL_PROCESS(mPgpId); + RS_SERIAL_PROCESS(mLocator); + RS_SERIAL_PROCESS(mErrorMsg); + RS_SERIAL_PROCESS(mErrorCode); + } +}; + +struct RsConnectionEvent : RsEvent +{ + RsConnectionEvent() + : RsEvent(RsEventType::PEER_CONNECTION), + mConnectionInfoCode(ConnectionEventCode::UNKNOWN) {} + + enum class ConnectionEventCode: 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 + }; + + ConnectionEventCode 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(mConnectionInfoCode); + RS_SERIAL_PROCESS(mSslId); + RS_SERIAL_PROCESS(mStrInfo1); + RS_SERIAL_PROCESS(mStrInfo2); + } +}; + +//===================================================================================================// +// Peer Details // +//===================================================================================================// /* We should definitely split this into 2 sub-structures: * PGP info (or profile info) with all info related to PGP keys diff --git a/libretroshare/src/retroshare/rsposted.h b/libretroshare/src/retroshare/rsposted.h index 547c03188..75ab2fa0c 100644 --- a/libretroshare/src/retroshare/rsposted.h +++ b/libretroshare/src/retroshare/rsposted.h @@ -71,9 +71,9 @@ std::ostream &operator<<(std::ostream &out, const RsPostedPost &post); struct RsGxsPostedEvent: RsEvent { RsGxsPostedEvent() - : RsEvent(RsEventType::GXS_POSTED), mPostedEventCode(UNKNOWN) {} + : RsEvent(RsEventType::GXS_POSTED), mPostedEventCode(PostedEventCode::UNKNOWN) {} - enum PostedEventCode: uint8_t { + enum class PostedEventCode: uint8_t { UNKNOWN = 0x00, NEW_POSTED_GROUP = 0x01, NEW_MESSAGE = 0x02 diff --git a/libretroshare/src/services/p3gxschannels.cc b/libretroshare/src/services/p3gxschannels.cc index cf43e314f..7121db0be 100644 --- a/libretroshare/src/services/p3gxschannels.cc +++ b/libretroshare/src/services/p3gxschannels.cc @@ -260,7 +260,7 @@ void p3GxsChannels::notifyChanges(std::vector &changes) ev->mChannelMsgId = *mit1; ev->mChannelGroupId = mit->first; - ev->mChannelEventCode = RsGxsChannelEvent::NEW_MESSAGE; + ev->mChannelEventCode = RsGxsChannelEvent::ChannelEventCode::NEW_MESSAGE; rsEvents->sendEvent(ev); } @@ -315,7 +315,7 @@ void p3GxsChannels::notifyChanges(std::vector &changes) auto ev = std::make_shared(); ev->mChannelGroupId = *git; - ev->mChannelEventCode = RsGxsChannelEvent::SUBSCRIBE_STATUS_CHANGED; + ev->mChannelEventCode = RsGxsChannelEvent::ChannelEventCode::SUBSCRIBE_STATUS_CHANGED; rsEvents->sendEvent(ev); } @@ -340,7 +340,7 @@ void p3GxsChannels::notifyChanges(std::vector &changes) auto ev = std::make_shared(); ev->mChannelGroupId = *git; - ev->mChannelEventCode = RsGxsChannelEvent::NEW_CHANNEL; + ev->mChannelEventCode = RsGxsChannelEvent::ChannelEventCode::NEW_CHANNEL; rsEvents->sendEvent(ev); } @@ -360,7 +360,7 @@ void p3GxsChannels::notifyChanges(std::vector &changes) auto ev = std::make_shared(); ev->mChannelGroupId = *git; - ev->mChannelEventCode = RsGxsChannelEvent::RECEIVED_PUBLISH_KEY; + ev->mChannelEventCode = RsGxsChannelEvent::ChannelEventCode::RECEIVED_PUBLISH_KEY; rsEvents->sendEvent(ev); } diff --git a/libretroshare/src/services/p3gxscircles.cc b/libretroshare/src/services/p3gxscircles.cc index 0720f0d0f..79707d5cf 100644 --- a/libretroshare/src/services/p3gxscircles.cc +++ b/libretroshare/src/services/p3gxscircles.cc @@ -514,11 +514,11 @@ void p3GxsCircles::notifyChanges(std::vector &changes) ev->mGxsId = msg.mMeta.mAuthorId; if (msg.stuff == "SUBSCRIPTION_REQUEST_UNSUBSCRIBE") - ev->mCircleEventType = RsGxsCircleEvent::CIRCLE_MEMBERSHIP_LEAVE; + ev->mCircleEventType = RsGxsCircleEvent::CircleEventCode::CIRCLE_MEMBERSHIP_LEAVE; else if(details.mAllowedGxsIds.find(msg.mMeta.mAuthorId) != details.mAllowedGxsIds.end()) - ev->mCircleEventType = RsGxsCircleEvent::CIRCLE_MEMBERSHIP_JOIN; + ev->mCircleEventType = RsGxsCircleEvent::CircleEventCode::CIRCLE_MEMBERSHIP_JOIN; else - ev->mCircleEventType = RsGxsCircleEvent::CIRCLE_MEMBERSHIP_REQUEST; + ev->mCircleEventType = RsGxsCircleEvent::CircleEventCode::CIRCLE_MEMBERSHIP_REQUEST; rsEvents->sendEvent(ev); } diff --git a/libretroshare/src/services/p3gxsforums.cc b/libretroshare/src/services/p3gxsforums.cc index 362d03cd1..e69f1f06f 100644 --- a/libretroshare/src/services/p3gxsforums.cc +++ b/libretroshare/src/services/p3gxsforums.cc @@ -202,7 +202,7 @@ void p3GxsForums::notifyChanges(std::vector &changes) ev->mForumMsgId = *mit1; ev->mForumGroupId = mit->first; - ev->mForumEventCode = RsGxsForumEvent::NEW_MESSAGE; + ev->mForumEventCode = RsGxsForumEvent::ForumEventCode::NEW_MESSAGE; rsEvents->sendEvent(ev); } @@ -258,7 +258,7 @@ void p3GxsForums::notifyChanges(std::vector &changes) auto ev = std::make_shared(); ev->mForumGroupId = *git; - ev->mForumEventCode = RsGxsForumEvent::SUBSCRIBE_STATUS_CHANGED; + ev->mForumEventCode = RsGxsForumEvent::ForumEventCode::SUBSCRIBE_STATUS_CHANGED; rsEvents->sendEvent(ev); } @@ -284,7 +284,7 @@ void p3GxsForums::notifyChanges(std::vector &changes) auto ev = std::make_shared(); ev->mForumGroupId = *git; - ev->mForumEventCode = RsGxsForumEvent::NEW_FORUM; + ev->mForumEventCode = RsGxsForumEvent::ForumEventCode::NEW_FORUM; rsEvents->sendEvent(ev); } diff --git a/libretroshare/src/services/p3postbase.cc b/libretroshare/src/services/p3postbase.cc index b4dc9a903..222d6de25 100644 --- a/libretroshare/src/services/p3postbase.cc +++ b/libretroshare/src/services/p3postbase.cc @@ -119,7 +119,7 @@ void p3PostBase::notifyChanges(std::vector &changes) ev->mPostedMsgId = *mit1; ev->mPostedGroupId = mit->first; - ev->mPostedEventCode = RsGxsPostedEvent::NEW_MESSAGE; + ev->mPostedEventCode = RsGxsPostedEvent::PostedEventCode::NEW_MESSAGE; rsEvents->sendEvent(ev); } @@ -148,7 +148,7 @@ void p3PostBase::notifyChanges(std::vector &changes) auto ev = std::make_shared(); ev->mPostedGroupId = *git; - ev->mPostedEventCode = RsGxsPostedEvent::NEW_POSTED_GROUP; + ev->mPostedEventCode = RsGxsPostedEvent::PostedEventCode::NEW_POSTED_GROUP; rsEvents->sendEvent(ev); } diff --git a/libretroshare/src/services/p3rtt.cc b/libretroshare/src/services/p3rtt.cc index 49d859b11..5dcd5a225 100644 --- a/libretroshare/src/services/p3rtt.cc +++ b/libretroshare/src/services/p3rtt.cc @@ -23,6 +23,7 @@ #include "util/rsdir.h" #include "retroshare/rsiface.h" +#include "retroshare/rspeers.h" #include "pqi/pqibin.h" #include "pqi/pqistore.h" #include "pqi/p3linkmgr.h" @@ -373,7 +374,7 @@ int p3rtt::storePongResult(const RsPeerId& id, uint32_t counter, double recv_ts, ev->mSslId = peerInfo->mId; ev->mStrInfo1 = RsUtil::NumberToString(peerInfo->mCurrentMeanOffset,false); - ev->mConnectionInfoCode = RsConnectionEvent::PEER_TIME_SHIFT; + ev->mConnectionInfoCode = RsConnectionEvent::ConnectionEventCode::PEER_TIME_SHIFT; rsEvents->postEvent(ev); } diff --git a/retroshare-gui/src/gui/NewsFeed.cpp b/retroshare-gui/src/gui/NewsFeed.cpp index 6b5cfd66b..fb509c6e3 100644 --- a/retroshare-gui/src/gui/NewsFeed.cpp +++ b/retroshare-gui/src/gui/NewsFeed.cpp @@ -220,10 +220,10 @@ void NewsFeed::handlePostedEvent(std::shared_ptr event) switch(pe->mPostedEventCode) { - case RsGxsPostedEvent::NEW_POSTED_GROUP: addFeedItem( new PostedGroupItem(this, NEWSFEED_POSTEDNEWLIST, pe->mPostedGroupId, false, true)); + case RsGxsPostedEvent::PostedEventCode::NEW_POSTED_GROUP: addFeedItem( new PostedGroupItem(this, NEWSFEED_POSTEDNEWLIST, pe->mPostedGroupId, false, true)); break; - case RsGxsPostedEvent::NEW_MESSAGE: addFeedItem( new PostedItem(this, NEWSFEED_POSTEDMSGLIST, pe->mPostedGroupId, pe->mPostedMsgId, false, true)); + case RsGxsPostedEvent::PostedEventCode::NEW_MESSAGE: addFeedItem( new PostedItem(this, NEWSFEED_POSTEDMSGLIST, pe->mPostedGroupId, pe->mPostedMsgId, false, true)); break; default: @@ -239,12 +239,12 @@ void NewsFeed::handleForumEvent(std::shared_ptr event) switch(pe->mForumEventCode) { - case RsGxsForumEvent::UPDATED_FORUM: - case RsGxsForumEvent::NEW_FORUM: addFeedItem(new GxsForumGroupItem(this, NEWSFEED_FORUMNEWLIST, pe->mForumGroupId, false, true)); + case RsGxsForumEvent::ForumEventCode::UPDATED_FORUM: + case RsGxsForumEvent::ForumEventCode::NEW_FORUM: addFeedItem(new GxsForumGroupItem(this, NEWSFEED_FORUMNEWLIST, pe->mForumGroupId, false, true)); break; - case RsGxsForumEvent::UPDATED_MESSAGE: - case RsGxsForumEvent::NEW_MESSAGE: addFeedItem(new GxsForumMsgItem(this, NEWSFEED_FORUMNEWLIST, pe->mForumGroupId, pe->mForumMsgId, false, true)); + case RsGxsForumEvent::ForumEventCode::UPDATED_MESSAGE: + case RsGxsForumEvent::ForumEventCode::NEW_MESSAGE: addFeedItem(new GxsForumMsgItem(this, NEWSFEED_FORUMNEWLIST, pe->mForumGroupId, pe->mForumMsgId, false, true)); break; default: @@ -260,15 +260,15 @@ void NewsFeed::handleChannelEvent(std::shared_ptr event) switch(pe->mChannelEventCode) { - case RsGxsChannelEvent::UPDATED_CHANNEL: - case RsGxsChannelEvent::NEW_CHANNEL: addFeedItem(new GxsChannelGroupItem(this, NEWSFEED_CHANNELNEWLIST, pe->mChannelGroupId, false, true)); + case RsGxsChannelEvent::ChannelEventCode::UPDATED_CHANNEL: + case RsGxsChannelEvent::ChannelEventCode::NEW_CHANNEL: addFeedItem(new GxsChannelGroupItem(this, NEWSFEED_CHANNELNEWLIST, pe->mChannelGroupId, false, true)); break; - case RsGxsChannelEvent::UPDATED_MESSAGE: - case RsGxsChannelEvent::NEW_MESSAGE: addFeedItem(new GxsChannelPostItem(this, NEWSFEED_CHANNELNEWLIST, pe->mChannelGroupId, pe->mChannelMsgId, false, true)); + case RsGxsChannelEvent::ChannelEventCode::UPDATED_MESSAGE: + case RsGxsChannelEvent::ChannelEventCode::NEW_MESSAGE: addFeedItem(new GxsChannelPostItem(this, NEWSFEED_CHANNELNEWLIST, pe->mChannelGroupId, pe->mChannelMsgId, false, true)); break; - case RsGxsChannelEvent::RECEIVED_PUBLISH_KEY: addFeedItem(new GxsChannelGroupItem(this, NEWSFEED_CHANNELPUBKEYLIST, pe->mChannelGroupId, false, true)); + case RsGxsChannelEvent::ChannelEventCode::RECEIVED_PUBLISH_KEY: addFeedItem(new GxsChannelGroupItem(this, NEWSFEED_CHANNELPUBKEYLIST, pe->mChannelGroupId, false, true)); break; default: @@ -296,24 +296,24 @@ void NewsFeed::handleCircleEvent(std::shared_ptr event) { switch(pe->mCircleEventType) { - case RsGxsCircleEvent::CIRCLE_MEMBERSHIP_REQUEST: // only show membership requests if we're an admin of that circle + case RsGxsCircleEvent::CircleEventCode::CIRCLE_MEMBERSHIP_REQUEST: // only show membership requests if we're an admin of that circle if(details.mAmIAdmin) addFeedItemIfUnique(new GxsCircleItem(this, NEWSFEED_CIRCLELIST, pe->mCircleId, pe->mGxsId, RS_FEED_ITEM_CIRCLE_MEMB_REQ),true); break; - case RsGxsCircleEvent::CIRCLE_MEMBERSHIP_JOIN: + case RsGxsCircleEvent::CircleEventCode::CIRCLE_MEMBERSHIP_JOIN: addFeedItemIfUnique(new GxsCircleItem(this, NEWSFEED_CIRCLELIST, pe->mCircleId, pe->mGxsId, RS_FEED_ITEM_CIRCLE_MEMB_JOIN),true); break; - case RsGxsCircleEvent::CIRCLE_MEMBERSHIP_LEAVE: + case RsGxsCircleEvent::CircleEventCode::CIRCLE_MEMBERSHIP_LEAVE: addFeedItemIfUnique(new GxsCircleItem(this, NEWSFEED_CIRCLELIST, pe->mCircleId, pe->mGxsId, RS_FEED_ITEM_CIRCLE_MEMB_LEAVE),true); break; - case RsGxsCircleEvent::CIRCLE_MEMBERSHIP_INVITE: + case RsGxsCircleEvent::CircleEventCode::CIRCLE_MEMBERSHIP_INVITE: addFeedItemIfUnique(new GxsCircleItem(this, NEWSFEED_CIRCLELIST, pe->mCircleId, pe->mGxsId, RS_FEED_ITEM_CIRCLE_INVIT_REC),true); break; - case RsGxsCircleEvent::CIRCLE_MEMBERSHIP_REVOQUED: + case RsGxsCircleEvent::CircleEventCode::CIRCLE_MEMBERSHIP_REVOQUED: addFeedItemIfUnique(new GxsCircleItem(this, NEWSFEED_CIRCLELIST, pe->mCircleId, pe->mGxsId, RS_FEED_ITEM_CIRCLE_MEMB_REVOQUED),true); break; @@ -335,13 +335,13 @@ void NewsFeed::handleConnectionEvent(std::shared_ptr event) switch(e.mConnectionInfoCode) { - case RsConnectionEvent::PEER_CONNECTED: addFeedItemIfUnique(new PeerItem(this, NEWSFEED_PEERLIST, e.mSslId, PEER_TYPE_CONNECT, false), true); + case RsConnectionEvent::ConnectionEventCode::PEER_CONNECTED: addFeedItemIfUnique(new PeerItem(this, NEWSFEED_PEERLIST, e.mSslId, PEER_TYPE_CONNECT, false), true); break; - case RsConnectionEvent::PEER_DISCONNECTED: // not handled yet + case RsConnectionEvent::ConnectionEventCode::PEER_DISCONNECTED: // not handled yet break; - case RsConnectionEvent::PEER_TIME_SHIFT:addFeedItemIfUnique(new PeerItem(this, NEWSFEED_PEERLIST, e.mSslId, PEER_TYPE_OFFSET, false),false); + case RsConnectionEvent::ConnectionEventCode::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); + case RsConnectionEvent::ConnectionEventCode::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; default: break; @@ -357,10 +357,10 @@ void NewsFeed::handleSecurityEvent(std::shared_ptr event) auto& e(*pe); - std::cerr << "NotifyQt: handling security event from (" << e.mSslId << "," << e.mPgpId << ") error code: " << e.mErrorCode << std::endl; + std::cerr << "NotifyQt: handling security event from (" << e.mSslId << "," << e.mPgpId << ") error code: " << (int)e.mErrorCode << std::endl; uint flags = Settings->getNewsFeedFlags(); - if(e.mErrorCode == RsAuthSslConnectionAutenticationEvent::PEER_REFUSED_CONNECTION) + if(e.mErrorCode == RsAuthSslConnectionAutenticationEvent::AuthenticationCode::PEER_REFUSED_CONNECTION) { addFeedItemIfUnique(new PeerItem(this, NEWSFEED_PEERLIST, e.mSslId, PEER_TYPE_HELLO, false), true ); return; @@ -370,13 +370,13 @@ void NewsFeed::handleSecurityEvent(std::shared_ptr event) switch(e.mErrorCode) { - case RsAuthSslConnectionAutenticationEvent::NO_CERTIFICATE_SUPPLIED: - case RsAuthSslConnectionAutenticationEvent::MISMATCHED_PGP_ID: // fallthrough - case RsAuthSslConnectionAutenticationEvent::MISSING_AUTHENTICATION_INFO: FeedItemType = RS_FEED_ITEM_SEC_BAD_CERTIFICATE; break; - case RsAuthSslConnectionAutenticationEvent::PGP_SIGNATURE_VALIDATION_FAILED: FeedItemType = RS_FEED_ITEM_SEC_WRONG_SIGNATURE; break; - case RsAuthSslConnectionAutenticationEvent::NOT_A_FRIEND: FeedItemType = RS_FEED_ITEM_SEC_CONNECT_ATTEMPT; break; - case RsAuthSslConnectionAutenticationEvent::IP_IS_BLACKLISTED: FeedItemType = RS_FEED_ITEM_SEC_IP_BLACKLISTED; break; - case RsAuthSslConnectionAutenticationEvent::MISSING_CERTIFICATE: FeedItemType = RS_FEED_ITEM_SEC_MISSING_CERTIFICATE; break; + case RsAuthSslConnectionAutenticationEvent::AuthenticationCode::NO_CERTIFICATE_SUPPLIED: + case RsAuthSslConnectionAutenticationEvent::AuthenticationCode::MISMATCHED_PGP_ID: // fallthrough + case RsAuthSslConnectionAutenticationEvent::AuthenticationCode::MISSING_AUTHENTICATION_INFO: FeedItemType = RS_FEED_ITEM_SEC_BAD_CERTIFICATE; break; + case RsAuthSslConnectionAutenticationEvent::AuthenticationCode::PGP_SIGNATURE_VALIDATION_FAILED: FeedItemType = RS_FEED_ITEM_SEC_WRONG_SIGNATURE; break; + case RsAuthSslConnectionAutenticationEvent::AuthenticationCode::NOT_A_FRIEND: FeedItemType = RS_FEED_ITEM_SEC_CONNECT_ATTEMPT; break; + case RsAuthSslConnectionAutenticationEvent::AuthenticationCode::IP_IS_BLACKLISTED: FeedItemType = RS_FEED_ITEM_SEC_IP_BLACKLISTED; break; + case RsAuthSslConnectionAutenticationEvent::AuthenticationCode::MISSING_CERTIFICATE: FeedItemType = RS_FEED_ITEM_SEC_MISSING_CERTIFICATE; break; default: return; // display nothing diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.cpp index 4b0a7684e..137f37f26 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.cpp @@ -66,7 +66,7 @@ void GxsChannelDialog::handleEvent_main_thread(std::shared_ptr ev switch(e->mChannelEventCode) { - case RsGxsChannelEvent::SUBSCRIBE_STATUS_CHANGED: updateDisplay(true); + case RsGxsChannelEvent::ChannelEventCode::SUBSCRIBE_STATUS_CHANGED: updateDisplay(true); break; default: break; diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp index 3ec13eb1c..02abc3ba5 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp @@ -146,10 +146,10 @@ void GxsChannelPostsWidget::handleEvent_main_thread(std::shared_ptrmChannelEventCode) { - case RsGxsChannelEvent::UPDATED_CHANNEL: - case RsGxsChannelEvent::NEW_CHANNEL: - case RsGxsChannelEvent::UPDATED_MESSAGE: - case RsGxsChannelEvent::NEW_MESSAGE: + case RsGxsChannelEvent::ChannelEventCode::UPDATED_CHANNEL: + case RsGxsChannelEvent::ChannelEventCode::NEW_CHANNEL: + case RsGxsChannelEvent::ChannelEventCode::UPDATED_MESSAGE: + case RsGxsChannelEvent::ChannelEventCode::NEW_MESSAGE: if(e->mChannelGroupId == mChannelGroupId) updateDisplay(true); break; diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp index 8cd399b48..5b02a977e 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp @@ -450,10 +450,10 @@ void GxsForumThreadWidget::handleEvent_main_thread(std::shared_ptrmForumEventCode) { - case RsGxsForumEvent::UPDATED_FORUM: - case RsGxsForumEvent::NEW_FORUM: - case RsGxsForumEvent::UPDATED_MESSAGE: - case RsGxsForumEvent::NEW_MESSAGE: + case RsGxsForumEvent::ForumEventCode::UPDATED_FORUM: + case RsGxsForumEvent::ForumEventCode::NEW_FORUM: + case RsGxsForumEvent::ForumEventCode::UPDATED_MESSAGE: + case RsGxsForumEvent::ForumEventCode::NEW_MESSAGE: if(e->mForumGroupId == mForumGroup.mMeta.mGroupId) updateDisplay(true); break; diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumsDialog.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumsDialog.cpp index 9749b9a26..0e0a8447a 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumsDialog.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumsDialog.cpp @@ -59,7 +59,7 @@ void GxsForumsDialog::handleEvent_main_thread(std::shared_ptr eve switch(e->mForumEventCode) { - case RsGxsForumEvent::SUBSCRIBE_STATUS_CHANGED: updateDisplay(true); + case RsGxsForumEvent::ForumEventCode::SUBSCRIBE_STATUS_CHANGED: updateDisplay(true); break; default: break; From 93cd6a5df1a561b327aa20b906be8f20ee29327b Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 19 Dec 2019 21:03:08 +0100 Subject: [PATCH 31/39] fixed possible data race in mNotifications --- libretroshare/src/gxs/rsgenexchange.cc | 21 ++++++++++++++++++--- libretroshare/src/services/p3gxschannels.cc | 1 + 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/libretroshare/src/gxs/rsgenexchange.cc b/libretroshare/src/gxs/rsgenexchange.cc index 10c5a307d..c3347713f 100644 --- a/libretroshare/src/gxs/rsgenexchange.cc +++ b/libretroshare/src/gxs/rsgenexchange.cc @@ -163,10 +163,25 @@ void RsGenExchange::tick() processRoutingClues() ; - if(!mNotifications.empty()) { - notifyChanges(mNotifications); - mNotifications.clear(); + std::vector mNotifications_copy; + + // make a non-deep copy of mNotifications so that it can be passed off-mutex to notifyChanged() + // that will delete it. The potential high cost of notifyChanges() makes it preferable to call off-mutex. + { + RS_STACK_MUTEX(mGenMtx); + if(!mNotifications.empty()) + { + mNotifications_copy = mNotifications; + mNotifications.clear(); + } + } + + // Calling notifyChanges() calls back RsGxsIfaceHelper::receiveChanges() that deletes the pointers in the array + // and the array itself. This is pretty bad and we should normally delete the changes here. + + if(!mNotifications_copy.empty()) + notifyChanges(mNotifications_copy); } // implemented service tick function diff --git a/libretroshare/src/services/p3gxschannels.cc b/libretroshare/src/services/p3gxschannels.cc index 7121db0be..648098dec 100644 --- a/libretroshare/src/services/p3gxschannels.cc +++ b/libretroshare/src/services/p3gxschannels.cc @@ -377,6 +377,7 @@ void p3GxsChannels::notifyChanges(std::vector &changes) if(!unprocessedGroups.empty()) request_SpecificSubscribedGroups(unprocessedGroups); + // the call below deletes changes and its content. RsGxsIfaceHelper::receiveChanges(changes); } From 856d1b62a70f0820b90b9d623bd16f530192440d Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 19 Dec 2019 21:04:18 +0100 Subject: [PATCH 32/39] moved to QueuedConnection to update the feed count --- retroshare-gui/src/gui/NewsFeed.cpp | 3 +-- .../src/gui/common/RSFeedWidget.cpp | 18 +++++++++++++-- .../src/gui/feeds/GxsChannelPostItem.cpp | 1 + .../src/gui/feeds/GxsChannelPostItem.ui | 22 ++----------------- .../src/gui/feeds/NewsFeedUserNotify.cpp | 2 +- 5 files changed, 21 insertions(+), 25 deletions(-) diff --git a/retroshare-gui/src/gui/NewsFeed.cpp b/retroshare-gui/src/gui/NewsFeed.cpp index fb509c6e3..fbc8f1b6c 100644 --- a/retroshare-gui/src/gui/NewsFeed.cpp +++ b/retroshare-gui/src/gui/NewsFeed.cpp @@ -18,7 +18,6 @@ * * *******************************************************************************/ -#include #include #include "NewsFeed.h" @@ -91,7 +90,7 @@ NewsFeed::NewsFeed(QWidget *parent) : MainPage(parent), ui(new Ui::NewsFeed) connect(ui->sortComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(sortChanged(int))); connect(ui->removeAllButton, SIGNAL(clicked()), ui->feedWidget, SLOT(clear())); - connect(ui->feedWidget, SIGNAL(feedCountChanged()), this, SLOT(sendNewsFeedChanged())); + connect(ui->feedWidget, SIGNAL(feedCountChanged()), this, SLOT(sendNewsFeedChanged()),Qt::QueuedConnection); connect(ui->feedOptionsButton, SIGNAL(clicked()), this, SLOT(feedoptions())); ui->feedOptionsButton->hide(); // (csoler) Hidden until we repare the system to display a specific settings page. diff --git a/retroshare-gui/src/gui/common/RSFeedWidget.cpp b/retroshare-gui/src/gui/common/RSFeedWidget.cpp index dab4ed5f8..5be4eadcd 100644 --- a/retroshare-gui/src/gui/common/RSFeedWidget.cpp +++ b/retroshare-gui/src/gui/common/RSFeedWidget.cpp @@ -392,9 +392,20 @@ void RSFeedWidget::removeFeedItem(FeedItem *feedItem) QTreeWidgetItem *treeItem = findTreeWidgetItem(feedItem); feedRemoved(feedItem); - if (treeItem) { + + if (treeItem) + { + int treeItem_index = ui->treeWidget->indexOfTopLevelItem(treeItem); + + if(treeItem_index < 0) + { + std::cerr << "(EE) Cannot remove designated item \"" << feedItem->uniqueIdentifier() << "\": not found!" << std::endl; + return ; + } + + ui->treeWidget->takeTopLevelItem(treeItem_index); delete(treeItem); - } + } if (!mCountChangedDisabled) { emit feedCountChanged(); @@ -498,6 +509,9 @@ FeedItem *RSFeedWidget::findFeedItem(const std::string& identifier) std::string id = feedItem->uniqueIdentifier(); + std::cerr << "Comparing \"" << id << "\""; + std::cerr << " to " << identifier << "\"" << " pthread_t = " << pthread_self() << std::endl; + if (id == identifier) return feedItem; } diff --git a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp index c166d115b..d7a807d59 100644 --- a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp +++ b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp @@ -183,6 +183,7 @@ void GxsChannelPostItem::setup() connect(ui->downloadButton, SIGNAL(clicked()), this, SLOT(download())); // HACK FOR NOW. + ui->commentButton->hide();// hidden until properly enabled. connect(ui->commentButton, SIGNAL(clicked()), this, SLOT(loadComments())); connect(ui->playButton, SIGNAL(clicked()), this, SLOT(play(void))); diff --git a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.ui b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.ui index 3747fc5db..01d113665 100644 --- a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.ui +++ b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.ui @@ -6,7 +6,7 @@ 0 0 - 1140 + 1359 342 @@ -57,18 +57,6 @@ 0 - - - 82 - 108 - - - - - 156 - 107 - - @@ -138,12 +126,6 @@ 0 - - - 16777215 - 60 - - Short Description @@ -570,8 +552,8 @@ - + diff --git a/retroshare-gui/src/gui/feeds/NewsFeedUserNotify.cpp b/retroshare-gui/src/gui/feeds/NewsFeedUserNotify.cpp index e089aa946..e71c166f2 100644 --- a/retroshare-gui/src/gui/feeds/NewsFeedUserNotify.cpp +++ b/retroshare-gui/src/gui/feeds/NewsFeedUserNotify.cpp @@ -26,7 +26,7 @@ NewsFeedUserNotify::NewsFeedUserNotify(NewsFeed *newsFeed, QObject *parent) : { mNewFeedCount = 0; - connect(newsFeed, SIGNAL(newsFeedChanged(int)), this, SLOT(newsFeedChanged(int))); + connect(newsFeed, SIGNAL(newsFeedChanged(int)), this, SLOT(newsFeedChanged(int)),Qt::QueuedConnection); } void NewsFeedUserNotify::newsFeedChanged(int count) From ff86d3cd20482c77d81a0f6a8cf2cd6cf2c41972 Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 19 Dec 2019 23:34:10 +0100 Subject: [PATCH 33/39] removed dangerous mItems map from RSFeedWidget, replacing the search by data-based search --- .../src/gui/common/RSFeedWidget.cpp | 80 ++++++++++--------- retroshare-gui/src/gui/common/RSFeedWidget.h | 5 +- 2 files changed, 45 insertions(+), 40 deletions(-) diff --git a/retroshare-gui/src/gui/common/RSFeedWidget.cpp b/retroshare-gui/src/gui/common/RSFeedWidget.cpp index 5be4eadcd..de18e49e0 100644 --- a/retroshare-gui/src/gui/common/RSFeedWidget.cpp +++ b/retroshare-gui/src/gui/common/RSFeedWidget.cpp @@ -28,7 +28,8 @@ #include -#define COLUMN_FEED 0 +#define COLUMN_FEED 0 +#define COLUMN_IDENTIFIER 1 #define SINGLE_STEP 15 @@ -74,6 +75,8 @@ RSFeedWidget::RSFeedWidget(QWidget *parent) ui->treeWidget->installEventFilter(this); ui->treeWidget->setVerticalScrollBar(new RSFeedWidgetScrollBar); + ui->treeWidget->setColumnCount(2); + ui->treeWidget->setColumnHidden(COLUMN_IDENTIFIER,true); } RSFeedWidget::~RSFeedWidget() @@ -130,17 +133,14 @@ bool RSFeedWidget::eventFilter(QObject *object, QEvent *event) void RSFeedWidget::feedAdded(FeedItem *feedItem, QTreeWidgetItem *treeItem) { - mItems.insert(feedItem, treeItem); } void RSFeedWidget::feedRemoved(FeedItem *feedItem) { - mItems.remove(feedItem); } void RSFeedWidget::feedsCleared() { - mItems.clear(); } void RSFeedWidget::connectSignals(FeedItem *feedItem) @@ -179,6 +179,7 @@ void RSFeedWidget::addFeedItem(FeedItem *feedItem, Qt::ItemDataRole sortRole, co QTreeWidgetItem *treeItem = new RSTreeWidgetItem(mFeedCompareRole); treeItem->setData(COLUMN_FEED, sortRole, value); + treeItem->setData(COLUMN_IDENTIFIER, Qt::DisplayRole, QString::fromStdString(feedItem->uniqueIdentifier())); ui->treeWidget->addTopLevelItem(treeItem); ui->treeWidget->setItemWidget(treeItem, 0, feedItem); @@ -208,6 +209,7 @@ void RSFeedWidget::addFeedItem(FeedItem *feedItem, const QMaptreeWidget->addTopLevelItem(treeItem); + treeItem->setData(COLUMN_FEED, Qt::DisplayRole, QString::fromStdString(feedItem->uniqueIdentifier())); ui->treeWidget->setItemWidget(treeItem, 0, feedItem); feedAdded(feedItem, treeItem); @@ -223,14 +225,13 @@ void RSFeedWidget::addFeedItem(FeedItem *feedItem, const QMapuniqueIdentifier()); + + if (!treeItem) return; - } treeItem->setData(COLUMN_FEED, sortRole, value); } @@ -241,10 +242,9 @@ void RSFeedWidget::setSort(FeedItem *feedItem, const QMapuniqueIdentifier()); + if (!treeItem) return; - } QMap::const_iterator it; for (it = sort.begin(); it != sort.end(); ++it) { @@ -388,10 +388,7 @@ void RSFeedWidget::removeFeedItem(FeedItem *feedItem) return; } - disconnectSignals(feedItem); - - QTreeWidgetItem *treeItem = findTreeWidgetItem(feedItem); - feedRemoved(feedItem); + QTreeWidgetItem *treeItem = findTreeWidgetItem(feedItem->uniqueIdentifier()); if (treeItem) { @@ -403,8 +400,10 @@ void RSFeedWidget::removeFeedItem(FeedItem *feedItem) return ; } - ui->treeWidget->takeTopLevelItem(treeItem_index); - delete(treeItem); + feedRemoved(feedItem); + disconnectSignals(feedItem); + + delete ui->treeWidget->takeTopLevelItem(treeItem_index); } if (!mCountChangedDisabled) { @@ -429,40 +428,49 @@ void RSFeedWidget::feedItemDestroyed(FeedItem *feedItem) { /* No need to disconnect when object will be destroyed */ - QTreeWidgetItem *treeItem = findTreeWidgetItem(feedItem); - feedRemoved(feedItem); - if (treeItem) { - delete(treeItem); - } + QTreeWidgetItem *treeItem = findTreeWidgetItem(feedItem->uniqueIdentifier()); - if (!mCountChangedDisabled) { + feedRemoved(feedItem); + if (treeItem) + delete(treeItem); + + if (!mCountChangedDisabled) emit feedCountChanged(); - } } -QTreeWidgetItem *RSFeedWidget::findTreeWidgetItem(FeedItem *feedItem) +QTreeWidgetItem *RSFeedWidget::findTreeWidgetItem(const std::string& identifier) { - QMap::iterator it = mItems.find(feedItem); - if (it == mItems.end()) { - return NULL; - } + std::cerr << "FindTreeWidgetItem: looking for \"" << identifier << "\"" << std::endl; + QList list = ui->treeWidget->findItems(QString::fromStdString(identifier),Qt::MatchExactly,COLUMN_IDENTIFIER); - return it.value(); + if(list.empty()) + { + std::cerr << "not found!"<< std::endl; + return nullptr; + } + else if(list.size() == 1) + { + std::cerr << "found!"<< std::endl; + return list.front(); + } + else + { + std::cerr << "(EE) More than a single item with identifier \"" << identifier << "\" in the feed tree widget. This shouldn't happen!" << std::endl; + return nullptr; + } } bool RSFeedWidget::scrollTo(FeedItem *feedItem, bool focus) { - QTreeWidgetItem *item = findTreeWidgetItem(feedItem); - if (!feedItem) { + QTreeWidgetItem *item = findTreeWidgetItem(feedItem->uniqueIdentifier()); + if (!feedItem) return false; - } ui->treeWidget->scrollToItem(item); ui->treeWidget->setCurrentItem(item); - if (focus) { + if (focus) ui->treeWidget->setFocus(); - } return true; } diff --git a/retroshare-gui/src/gui/common/RSFeedWidget.h b/retroshare-gui/src/gui/common/RSFeedWidget.h index e5997f806..147c95595 100644 --- a/retroshare-gui/src/gui/common/RSFeedWidget.h +++ b/retroshare-gui/src/gui/common/RSFeedWidget.h @@ -98,7 +98,7 @@ private: void connectSignals(FeedItem *feedItem); void disconnectSignals(FeedItem *feedItem); FeedItem *feedItemFromTreeItem(QTreeWidgetItem *treeItem); - QTreeWidgetItem *findTreeWidgetItem(FeedItem *feedItem); + QTreeWidgetItem *findTreeWidgetItem(const std::string &identifier); void filterItems(); void filterItem(QTreeWidgetItem *treeItem, FeedItem *feedItem); @@ -117,9 +117,6 @@ private: /* Options */ int mCountChangedDisabled; - /* Items */ - QMap mItems; - Ui::RSFeedWidget *ui; }; From 137cb5271d9dbb39958a9cad60a278a1be9fcdd7 Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 21 Dec 2019 14:33:53 +0100 Subject: [PATCH 34/39] fixed feed bug by moving away from std::string as a return type to uniqueIdentifier(). Now uint64_ hash is used and cached --- retroshare-gui/src/gui/Posted/PostedItem.h | 2 +- retroshare-gui/src/gui/common/RSFeedWidget.cpp | 12 ++++++------ retroshare-gui/src/gui/common/RSFeedWidget.h | 4 ++-- retroshare-gui/src/gui/feeds/ChatMsgItem.h | 2 +- retroshare-gui/src/gui/feeds/FeedItem.cpp | 18 +++++++++++++++++- retroshare-gui/src/gui/feeds/FeedItem.h | 4 +++- .../src/gui/feeds/GxsChannelGroupItem.h | 3 +-- .../src/gui/feeds/GxsChannelPostItem.cpp | 1 + .../src/gui/feeds/GxsChannelPostItem.h | 2 +- retroshare-gui/src/gui/feeds/GxsCircleItem.cpp | 4 ++-- retroshare-gui/src/gui/feeds/GxsCircleItem.h | 2 +- .../src/gui/feeds/GxsForumGroupItem.h | 2 +- .../src/gui/feeds/GxsForumMsgItem.cpp | 2 ++ retroshare-gui/src/gui/feeds/GxsForumMsgItem.h | 2 +- retroshare-gui/src/gui/feeds/MsgItem.h | 2 +- retroshare-gui/src/gui/feeds/PeerItem.cpp | 4 ++-- retroshare-gui/src/gui/feeds/PeerItem.h | 2 +- retroshare-gui/src/gui/feeds/PostedGroupItem.h | 2 +- .../src/gui/feeds/SecurityIpItem.cpp | 4 ++-- retroshare-gui/src/gui/feeds/SecurityIpItem.h | 2 +- retroshare-gui/src/gui/feeds/SecurityItem.cpp | 4 ++-- retroshare-gui/src/gui/feeds/SecurityItem.h | 2 +- 22 files changed, 51 insertions(+), 31 deletions(-) diff --git a/retroshare-gui/src/gui/Posted/PostedItem.h b/retroshare-gui/src/gui/Posted/PostedItem.h index 94bb12ed7..7bb920a6c 100644 --- a/retroshare-gui/src/gui/Posted/PostedItem.h +++ b/retroshare-gui/src/gui/Posted/PostedItem.h @@ -49,7 +49,7 @@ public: const RsPostedPost &getPost() const; RsPostedPost &post(); - std::string uniqueIdentifier() const override { return "PostedItem " + mMessageId.toStdString(); } + uint64_t uniqueIdentifier() const override { return hash_64bits("PostedItem " + mMessageId.toStdString()); } protected: /* FeedItem */ virtual void doExpand(bool open); diff --git a/retroshare-gui/src/gui/common/RSFeedWidget.cpp b/retroshare-gui/src/gui/common/RSFeedWidget.cpp index de18e49e0..be8c1215d 100644 --- a/retroshare-gui/src/gui/common/RSFeedWidget.cpp +++ b/retroshare-gui/src/gui/common/RSFeedWidget.cpp @@ -179,7 +179,7 @@ void RSFeedWidget::addFeedItem(FeedItem *feedItem, Qt::ItemDataRole sortRole, co QTreeWidgetItem *treeItem = new RSTreeWidgetItem(mFeedCompareRole); treeItem->setData(COLUMN_FEED, sortRole, value); - treeItem->setData(COLUMN_IDENTIFIER, Qt::DisplayRole, QString::fromStdString(feedItem->uniqueIdentifier())); + treeItem->setData(COLUMN_IDENTIFIER, Qt::DisplayRole, QString("%1").arg(feedItem->uniqueIdentifier(),8,16,QChar('0'))); ui->treeWidget->addTopLevelItem(treeItem); ui->treeWidget->setItemWidget(treeItem, 0, feedItem); @@ -207,9 +207,9 @@ void RSFeedWidget::addFeedItem(FeedItem *feedItem, const QMapsetData(COLUMN_FEED, it.key(), it.value()); } + treeItem->setData(COLUMN_IDENTIFIER, Qt::DisplayRole, QString("%1").arg(feedItem->uniqueIdentifier(),8,16,QChar('0'))); ui->treeWidget->addTopLevelItem(treeItem); - treeItem->setData(COLUMN_FEED, Qt::DisplayRole, QString::fromStdString(feedItem->uniqueIdentifier())); ui->treeWidget->setItemWidget(treeItem, 0, feedItem); feedAdded(feedItem, treeItem); @@ -438,10 +438,10 @@ void RSFeedWidget::feedItemDestroyed(FeedItem *feedItem) emit feedCountChanged(); } -QTreeWidgetItem *RSFeedWidget::findTreeWidgetItem(const std::string& identifier) +QTreeWidgetItem *RSFeedWidget::findTreeWidgetItem(uint64_t identifier) { std::cerr << "FindTreeWidgetItem: looking for \"" << identifier << "\"" << std::endl; - QList list = ui->treeWidget->findItems(QString::fromStdString(identifier),Qt::MatchExactly,COLUMN_IDENTIFIER); + QList list = ui->treeWidget->findItems(QString("%1").arg(identifier,8,16,QChar('0')),Qt::MatchExactly,COLUMN_IDENTIFIER); if(list.empty()) { @@ -495,7 +495,7 @@ void RSFeedWidget::withAll(RSFeedWidgetCallbackFunction callback, void *data) } } -FeedItem *RSFeedWidget::findFeedItem(const std::string& identifier) +FeedItem *RSFeedWidget::findFeedItem(uint64_t identifier) { QTreeWidgetItemIterator it(ui->treeWidget); QTreeWidgetItem *treeItem=NULL; @@ -515,7 +515,7 @@ FeedItem *RSFeedWidget::findFeedItem(const std::string& identifier) // if(feedItem->uniqueIdentifier() == identifier) // causes a crash. I dont know why! If someone ever finds why, please tell me. - std::string id = feedItem->uniqueIdentifier(); + uint64_t id = feedItem->uniqueIdentifier(); std::cerr << "Comparing \"" << id << "\""; std::cerr << " to " << identifier << "\"" << " pthread_t = " << pthread_self() << std::endl; diff --git a/retroshare-gui/src/gui/common/RSFeedWidget.h b/retroshare-gui/src/gui/common/RSFeedWidget.h index 147c95595..bc38adf84 100644 --- a/retroshare-gui/src/gui/common/RSFeedWidget.h +++ b/retroshare-gui/src/gui/common/RSFeedWidget.h @@ -71,7 +71,7 @@ public: bool scrollTo(FeedItem *feedItem, bool focus); void withAll(RSFeedWidgetCallbackFunction callback, void *data); - FeedItem *findFeedItem(const std::string &identifier); + FeedItem *findFeedItem(uint64_t identifier); void selectedFeedItems(QList &feedItems); @@ -98,7 +98,7 @@ private: void connectSignals(FeedItem *feedItem); void disconnectSignals(FeedItem *feedItem); FeedItem *feedItemFromTreeItem(QTreeWidgetItem *treeItem); - QTreeWidgetItem *findTreeWidgetItem(const std::string &identifier); + QTreeWidgetItem *findTreeWidgetItem(uint64_t identifier); void filterItems(); void filterItem(QTreeWidgetItem *treeItem, FeedItem *feedItem); diff --git a/retroshare-gui/src/gui/feeds/ChatMsgItem.h b/retroshare-gui/src/gui/feeds/ChatMsgItem.h index 6dad0d215..fe946a4b9 100644 --- a/retroshare-gui/src/gui/feeds/ChatMsgItem.h +++ b/retroshare-gui/src/gui/feeds/ChatMsgItem.h @@ -37,7 +37,7 @@ public: void updateItemStatic(); - virtual std::string uniqueIdentifier() const override { return "ChatMsgItem " + mPeerId.toStdString(); } + virtual uint64_t uniqueIdentifier() const override { return hash_64bits("ChatMsgItem " + mPeerId.toStdString()); } protected: /* FeedItem */ virtual void doExpand(bool /*open*/) {} diff --git a/retroshare-gui/src/gui/feeds/FeedItem.cpp b/retroshare-gui/src/gui/feeds/FeedItem.cpp index 19cfdbf72..955298a24 100644 --- a/retroshare-gui/src/gui/feeds/FeedItem.cpp +++ b/retroshare-gui/src/gui/feeds/FeedItem.cpp @@ -18,10 +18,11 @@ * * *******************************************************************************/ +#include #include "FeedItem.h" /** Constructor */ -FeedItem::FeedItem(QWidget *parent) : QWidget(parent) +FeedItem::FeedItem(QWidget *parent) : QWidget(parent), mHash(0) { mWasExpanded = false; } @@ -43,3 +44,18 @@ void FeedItem::expand(bool open) mWasExpanded = true; } } + +uint64_t FeedItem::hash_64bits(const std::string& s) const +{ + if(mHash == 0) + { + mHash = 0x01110bbfa09; + + for(uint32_t i=0;i> 3)) + s[i]*0x217898fbba7 + 0x0294379); + + std::cerr << "Producing hash " << std::hex << mHash << std::dec << " from string \"" << s << "\"" << std::endl; + } + + return mHash; +} diff --git a/retroshare-gui/src/gui/feeds/FeedItem.h b/retroshare-gui/src/gui/feeds/FeedItem.h index d377fb027..7cd6808a1 100644 --- a/retroshare-gui/src/gui/feeds/FeedItem.h +++ b/retroshare-gui/src/gui/feeds/FeedItem.h @@ -41,17 +41,19 @@ public: * \return returns a string that is unique to this specific item. The string will be used to search for an existing item that * would contain the same information. It should therefore sumarise the data represented by the item. */ - virtual std::string uniqueIdentifier() const =0; + virtual uint64_t uniqueIdentifier() const =0; protected: virtual void doExpand(bool open) = 0; virtual void expandFill(bool /*first*/) {} + uint64_t hash_64bits(const std::string& s) const; signals: void sizeChanged(FeedItem *feedItem); void feedItemDestroyed(FeedItem *feedItem); private: bool mWasExpanded; + mutable uint64_t mHash; }; #endif diff --git a/retroshare-gui/src/gui/feeds/GxsChannelGroupItem.h b/retroshare-gui/src/gui/feeds/GxsChannelGroupItem.h index 5c51b396a..1a0c56a70 100644 --- a/retroshare-gui/src/gui/feeds/GxsChannelGroupItem.h +++ b/retroshare-gui/src/gui/feeds/GxsChannelGroupItem.h @@ -41,8 +41,7 @@ public: ~GxsChannelGroupItem(); bool setGroup(const RsGxsChannelGroup &group); - - std::string uniqueIdentifier() const override { return "GxsChannelGroupItem " + mGroup.mMeta.mGroupId.toStdString() ; } + uint64_t uniqueIdentifier() const override { return hash_64bits("GxsChannelGroupItem " + groupId().toStdString()) ; } protected: /* FeedItem */ virtual void doExpand(bool open); diff --git a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp index d7a807d59..cdb4eeaf2 100644 --- a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp +++ b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp @@ -71,6 +71,7 @@ void GxsChannelPostItem::init(const RsGxsMessageId& messageId,const std::set Date: Sat, 21 Dec 2019 14:44:16 +0100 Subject: [PATCH 35/39] removed debug output --- retroshare-gui/src/gui/common/RSFeedWidget.cpp | 18 +----------------- retroshare-gui/src/gui/feeds/FeedItem.cpp | 2 -- 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/retroshare-gui/src/gui/common/RSFeedWidget.cpp b/retroshare-gui/src/gui/common/RSFeedWidget.cpp index be8c1215d..fff41d11b 100644 --- a/retroshare-gui/src/gui/common/RSFeedWidget.cpp +++ b/retroshare-gui/src/gui/common/RSFeedWidget.cpp @@ -440,19 +440,12 @@ void RSFeedWidget::feedItemDestroyed(FeedItem *feedItem) QTreeWidgetItem *RSFeedWidget::findTreeWidgetItem(uint64_t identifier) { - std::cerr << "FindTreeWidgetItem: looking for \"" << identifier << "\"" << std::endl; QList list = ui->treeWidget->findItems(QString("%1").arg(identifier,8,16,QChar('0')),Qt::MatchExactly,COLUMN_IDENTIFIER); if(list.empty()) - { - std::cerr << "not found!"<< std::endl; return nullptr; - } else if(list.size() == 1) - { - std::cerr << "found!"<< std::endl; return list.front(); - } else { std::cerr << "(EE) More than a single item with identifier \"" << identifier << "\" in the feed tree widget. This shouldn't happen!" << std::endl; @@ -506,20 +499,11 @@ FeedItem *RSFeedWidget::findFeedItem(uint64_t identifier) ++it; FeedItem *feedItem = feedItemFromTreeItem(treeItem); - if (!feedItem) { + if (!feedItem) continue; - } - - // (cyril) It seems that a local variable must be used to store this identifier. - // Directly comparing identifier such as in: - // if(feedItem->uniqueIdentifier() == identifier) - // causes a crash. I dont know why! If someone ever finds why, please tell me. uint64_t id = feedItem->uniqueIdentifier(); - std::cerr << "Comparing \"" << id << "\""; - std::cerr << " to " << identifier << "\"" << " pthread_t = " << pthread_self() << std::endl; - if (id == identifier) return feedItem; } diff --git a/retroshare-gui/src/gui/feeds/FeedItem.cpp b/retroshare-gui/src/gui/feeds/FeedItem.cpp index 955298a24..2e5353e40 100644 --- a/retroshare-gui/src/gui/feeds/FeedItem.cpp +++ b/retroshare-gui/src/gui/feeds/FeedItem.cpp @@ -53,8 +53,6 @@ uint64_t FeedItem::hash_64bits(const std::string& s) const for(uint32_t i=0;i> 3)) + s[i]*0x217898fbba7 + 0x0294379); - - std::cerr << "Producing hash " << std::hex << mHash << std::dec << " from string \"" << s << "\"" << std::endl; } return mHash; From 1d9dc657fdc14d19d9c7dd691800134da2e78d3c Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 22 Dec 2019 22:29:14 +0100 Subject: [PATCH 36/39] removed some debug info --- retroshare-gui/src/gui/NewsFeed.cpp | 8 ++-- .../src/gui/Posted/PostedListWidget.cpp | 46 +++++++++++++++++++ retroshare-gui/src/gui/gxs/GxsIdChooser.cpp | 4 ++ 3 files changed, 54 insertions(+), 4 deletions(-) diff --git a/retroshare-gui/src/gui/NewsFeed.cpp b/retroshare-gui/src/gui/NewsFeed.cpp index fbc8f1b6c..ac44de06b 100644 --- a/retroshare-gui/src/gui/NewsFeed.cpp +++ b/retroshare-gui/src/gui/NewsFeed.cpp @@ -330,7 +330,9 @@ void NewsFeed::handleConnectionEvent(std::shared_ptr event) auto& e(*pe); +#ifdef NEWS_DEBUG std::cerr << "NotifyQt: handling connection event from peer " << e.mSslId << std::endl; +#endif switch(e.mConnectionInfoCode) { @@ -355,8 +357,9 @@ void NewsFeed::handleSecurityEvent(std::shared_ptr event) return; auto& e(*pe); - +#ifdef NEWS_DEBUG std::cerr << "NotifyQt: handling security event from (" << e.mSslId << "," << e.mPgpId << ") error code: " << (int)e.mErrorCode << std::endl; +#endif uint flags = Settings->getNewsFeedFlags(); if(e.mErrorCode == RsAuthSslConnectionAutenticationEvent::AuthenticationCode::PEER_REFUSED_CONNECTION) @@ -438,7 +441,6 @@ void NewsFeed::addFeedItem(FeedItem *item) { static const int MAX_FEEDITEM_COUNT = 500 ; - std::cerr << "Adding feed item thread " << pthread_self() << std::endl; item->setAttribute(Qt::WA_DeleteOnClose, true); // costly, but not really a problem here @@ -462,7 +464,6 @@ void NewsFeed::addFeedItemIfUnique(FeedItem *item, bool replace) { FeedItem *feedItem = ui->feedWidget->findFeedItem(item->uniqueIdentifier()); - std::cerr << "Adding feed item thread " << pthread_self() << std::endl; if (feedItem) { if (!replace) @@ -482,7 +483,6 @@ void NewsFeed::remUniqueFeedItem(FeedItem *item) { FeedItem *feedItem = ui->feedWidget->findFeedItem(item->uniqueIdentifier()); - std::cerr << "Adding feed item thread " << pthread_self() << std::endl; if (feedItem) { delete item; diff --git a/retroshare-gui/src/gui/Posted/PostedListWidget.cpp b/retroshare-gui/src/gui/Posted/PostedListWidget.cpp index 8a1973457..b3bf1793a 100644 --- a/retroshare-gui/src/gui/Posted/PostedListWidget.cpp +++ b/retroshare-gui/src/gui/Posted/PostedListWidget.cpp @@ -37,6 +37,8 @@ #define POSTED_DEFAULT_LISTING_LENGTH 10 #define POSTED_MAX_INDEX 10000 +#define DEBUG_POSTED_LIST_WIDGET + #define TOPIC_DEFAULT_IMAGE ":/icons/png/posted.png" /** Constructor */ @@ -143,15 +145,19 @@ QScrollArea *PostedListWidget::getScrollArea() void PostedListWidget::deleteFeedItem(QWidget */*item*/, uint32_t /*type*/) { +#ifdef DEBUG_POSTED_LIST_WIDGET std::cerr << "PostedListWidget::deleteFeedItem() Nah"; std::cerr << std::endl; +#endif return; } void PostedListWidget::openChat(const RsPeerId & /*peerId*/) { +#ifdef DEBUG_POSTED_LIST_WIDGET std::cerr << "PostedListWidget::openChat() Nah"; std::cerr << std::endl; +#endif return; } @@ -207,8 +213,10 @@ void PostedListWidget::getRankings(int i) if (groupId().isNull()) return; +#ifdef DEBUG_POSTED_LIST_WIDGET std::cerr << "PostedListWidget::getRankings()"; std::cerr << std::endl; +#endif int oldSortMethod = mSortMethod; @@ -268,6 +276,7 @@ void PostedListWidget::submitVote(const RsGxsGrpMsgIdPair &msgId, bool up) vote.mVoteType = GXS_VOTE_DOWN; }//if (up) +#ifdef DEBUG_POSTED_LIST_WIDGET std::cerr << "PostedListWidget::submitVote()"; std::cerr << std::endl; @@ -275,6 +284,7 @@ void PostedListWidget::submitVote(const RsGxsGrpMsgIdPair &msgId, bool up) std::cerr << "ThreadId : " << vote.mMeta.mThreadId << std::endl; std::cerr << "ParentId : " << vote.mMeta.mParentId << std::endl; std::cerr << "AuthorId : " << vote.mMeta.mAuthorId << std::endl; +#endif uint32_t token; rsPosted->createNewVote(token, vote); @@ -464,8 +474,10 @@ static bool CmpPINew(const GxsFeedItem *a, const GxsFeedItem *b) void PostedListWidget::applyRanking() { /* uses current settings to sort posts, then add to layout */ +#ifdef DEBUG_POSTED_LIST_WIDGET std::cerr << "PostedListWidget::applyRanking()"; std::cerr << std::endl; +#endif shallowClearPosts(); @@ -474,25 +486,33 @@ void PostedListWidget::applyRanking() { default: case RsPosted::HotRankType: +#ifdef DEBUG_POSTED_LIST_WIDGET std::cerr << "PostedListWidget::applyRanking() HOT"; std::cerr << std::endl; +#endif qSort(mPostItems.begin(), mPostItems.end(), CmpPIHot); break; case RsPosted::NewRankType: +#ifdef DEBUG_POSTED_LIST_WIDGET std::cerr << "PostedListWidget::applyRanking() NEW"; std::cerr << std::endl; +#endif qSort(mPostItems.begin(), mPostItems.end(), CmpPINew); break; case RsPosted::TopRankType: +#ifdef DEBUG_POSTED_LIST_WIDGET std::cerr << "PostedListWidget::applyRanking() TOP"; std::cerr << std::endl; +#endif qSort(mPostItems.begin(), mPostItems.end(), CmpPITop); break; } mLastSortMethod = mSortMethod; +#ifdef DEBUG_POSTED_LIST_WIDGET std::cerr << "PostedListWidget::applyRanking() Sorted mPostList"; std::cerr << std::endl; +#endif /* go through list (skipping out-of-date items) to get */ QLayout *alayout = ui->scrollAreaWidgetContents->layout(); @@ -500,42 +520,54 @@ void PostedListWidget::applyRanking() time_t min_ts = 0; foreach (PostedItem *item, mPostItems) { +#ifdef DEBUG_POSTED_LIST_WIDGET std::cerr << "PostedListWidget::applyRanking() Item: " << item; std::cerr << std::endl; +#endif if (item->getPost().mMeta.mPublishTs < min_ts) { +#ifdef DEBUG_POSTED_LIST_WIDGET std::cerr << "\t Skipping OLD"; std::cerr << std::endl; +#endif item->hide(); continue; } if (counter >= mPostIndex + mPostShow) { +#ifdef DEBUG_POSTED_LIST_WIDGET std::cerr << "\t END - Counter too high"; std::cerr << std::endl; +#endif item->hide(); } else if (counter >= mPostIndex) { +#ifdef DEBUG_POSTED_LIST_WIDGET std::cerr << "\t Adding to Layout"; std::cerr << std::endl; +#endif /* add it in! */ alayout->addWidget(item); item->show(); } else { +#ifdef DEBUG_POSTED_LIST_WIDGET std::cerr << "\t Skipping to Low"; std::cerr << std::endl; +#endif item->hide(); } ++counter; } +#ifdef DEBUG_POSTED_LIST_WIDGET std::cerr << "PostedListWidget::applyRanking() Loaded New Order"; std::cerr << std::endl; +#endif // trigger a redraw. ui->scrollAreaWidgetContents->update(); @@ -564,7 +596,9 @@ bool PostedListWidget::navigatePostItem(const RsGxsMessageId & /*msgId*/) void PostedListWidget::shallowClearPosts() { +#ifdef DEBUG_POSTED_LIST_WIDGET std::cerr << "PostedListWidget::shallowClearPosts()" << std::endl; +#endif std::list postedItems; std::list::iterator pit; @@ -576,24 +610,30 @@ void PostedListWidget::shallowClearPosts() QLayoutItem *litem = alayout->itemAt(i); if (!litem) { +#ifdef DEBUG_POSTED_LIST_WIDGET std::cerr << "PostedListWidget::shallowClearPosts() missing litem"; std::cerr << std::endl; +#endif continue; } PostedItem *item = dynamic_cast(litem->widget()); if (item) { +#ifdef DEBUG_POSTED_LIST_WIDGET std::cerr << "PostedListWidget::shallowClearPosts() item: " << item; std::cerr << std::endl; +#endif postedItems.push_back(item); } +#ifdef DEBUG_POSTED_LIST_WIDGET else { std::cerr << "PostedListWidget::shallowClearPosts() Found Child, which is not a PostedItem???"; std::cerr << std::endl; } +#endif } for(pit = postedItems.begin(); pit != postedItems.end(); ++pit) @@ -646,15 +686,19 @@ void PostedListWidget::insertPosts(const uint32_t &token) // modify post content if(mPosts.find(p.mMeta.mMsgId) != mPosts.end()) { +#ifdef DEBUG_POSTED_LIST_WIDGET std::cerr << "PostedListWidget::updateCurrentDisplayComplete() updating MsgId: " << p.mMeta.mMsgId; std::cerr << std::endl; +#endif mPosts[p.mMeta.mMsgId]->setPost(p); } else { +#ifdef DEBUG_POSTED_LIST_WIDGET std::cerr << "PostedListWidget::updateCurrentDisplayComplete() loading New MsgId: " << p.mMeta.mMsgId; std::cerr << std::endl; +#endif /* insert new entry */ loadPost(p); } @@ -689,8 +733,10 @@ void PostedListWidget::setAllMessagesReadDo(bool read, uint32_t &token) void PostedListWidget::loadRequest(const TokenQueue *queue, const TokenRequest &req) { +#ifdef DEBUG_POSTED_LIST_WIDGET std::cerr << "PostedListWidget::loadRequest() UserType: " << req.mUserType; std::cerr << std::endl; +#endif if (queue == mTokenQueue) { diff --git a/retroshare-gui/src/gui/gxs/GxsIdChooser.cpp b/retroshare-gui/src/gui/gxs/GxsIdChooser.cpp index 260121c7e..e4e20dfd8 100644 --- a/retroshare-gui/src/gui/gxs/GxsIdChooser.cpp +++ b/retroshare-gui/src/gui/gxs/GxsIdChooser.cpp @@ -351,7 +351,9 @@ void GxsIdChooser::setDefaultItem() if (def >= 0) { setCurrentIndex(def); +#ifdef IDCHOOSER_DEBUG std::cerr << "GxsIdChooser-002" << (void*)this << " setting current index to " << def << std::endl; +#endif } } @@ -363,7 +365,9 @@ bool GxsIdChooser::setChosenId(const RsGxsId &gxsId) int index = findData(id); if (index >= 0) { setCurrentIndex(index); +#ifdef IDCHOOSER_DEBUG std::cerr << "GxsIdChooser-001" << (void*)this << " setting current index to " << index << std::endl; +#endif return true; } return false; From a469647386e3340bd9962096aa8db455ed3ba49d Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 25 Dec 2019 19:24:52 +0100 Subject: [PATCH 37/39] replaced RsErr() by RsInfo() in pqissl when applicable --- libretroshare/src/pqi/pqissl.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libretroshare/src/pqi/pqissl.cc b/libretroshare/src/pqi/pqissl.cc index 6cd29690e..f1ddd1cef 100644 --- a/libretroshare/src/pqi/pqissl.cc +++ b/libretroshare/src/pqi/pqissl.cc @@ -1267,7 +1267,7 @@ int pqissl::accept_locked( SSL *ssl, int fd, if(rsBanList && !rsBanList->isAddressAccepted( foreign_addr, checking_flags, check_result )) { - RsErr() << __PRETTY_FUNCTION__ + RsInfo() << __PRETTY_FUNCTION__ << " Refusing incoming SSL connection from blacklisted " << "foreign address " << foreign_addr << ". Reason: " << check_result << ". This should never happen " @@ -1343,7 +1343,7 @@ int pqissl::accept_locked( SSL *ssl, int fd, /* shutdown existing - in all cases use the new one */ if ((ssl_connection) && (ssl_connection != ssl)) { - std::cerr << __PRETTY_FUNCTION__ + RsInfo() << __PRETTY_FUNCTION__ << " closing Previous/Existing ssl_connection" << std::endl; SSL_shutdown(ssl_connection); SSL_free (ssl_connection); @@ -1351,7 +1351,7 @@ int pqissl::accept_locked( SSL *ssl, int fd, if ((sockfd > -1) && (sockfd != fd)) { - std::cerr << __PRETTY_FUNCTION__ << " closing Previous/Existing sockfd" + RsInfo() << __PRETTY_FUNCTION__ << " closing Previous/Existing sockfd" << std::endl; net_internal_close(sockfd); } @@ -1367,7 +1367,7 @@ int pqissl::accept_locked( SSL *ssl, int fd, */ sockaddr_storage_copy(foreign_addr, remote_addr); - std::cerr << __PRETTY_FUNCTION__ << " SUCCESSFUL connection to: " + RsInfo() << __PRETTY_FUNCTION__ << " SUCCESSFUL connection to: " << PeerId().toStdString() << " remoteaddr: " << sockaddr_storage_iptostring(remote_addr) << std::endl; From 9fda64e8154f8a2ff1ec2e8d00268145b5123cb0 Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 26 Dec 2019 21:30:00 +0100 Subject: [PATCH 38/39] fixed geometry of buttons PostedFeedItem like other feed items --- retroshare-gui/src/gui/Posted/PostedItem.ui | 38 +++++++++++++++++---- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/retroshare-gui/src/gui/Posted/PostedItem.ui b/retroshare-gui/src/gui/Posted/PostedItem.ui index f8b19650c..162200560 100644 --- a/retroshare-gui/src/gui/Posted/PostedItem.ui +++ b/retroshare-gui/src/gui/Posted/PostedItem.ui @@ -7,7 +7,7 @@ 0 0 825 - 337 + 339 @@ -529,10 +529,22 @@ + + + 0 + 0 + + + + + 50 + 44 + + - 24 - 16777215 + 50 + 44 @@ -549,10 +561,22 @@ + + + 0 + 0 + + + + + 50 + 44 + + - 24 - 16777215 + 50 + 44 @@ -686,9 +710,9 @@ - - + + From 37b5d8f307b65a17dc9817aa1c9777a4cb49f460 Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Tue, 7 Jan 2020 00:54:49 +0100 Subject: [PATCH 39/39] Fix few glitches in Cyril PR --- libretroshare/src/pqi/authssl.cc | 51 ++-- libretroshare/src/pqi/authssl.h | 15 -- libretroshare/src/pqi/p3linkmgr.cc | 16 +- libretroshare/src/pqi/p3peermgr.cc | 31 +-- libretroshare/src/pqi/pqissl.cc | 25 +- libretroshare/src/pqi/pqissllistener.cc | 10 +- libretroshare/src/retroshare/rsevents.h | 2 +- libretroshare/src/retroshare/rsgxschannels.h | 41 +-- libretroshare/src/retroshare/rsgxscircles.h | 48 +++- libretroshare/src/retroshare/rsgxsforums.h | 44 ++-- libretroshare/src/retroshare/rsmsgs.h | 24 +- libretroshare/src/retroshare/rspeers.h | 77 +++--- libretroshare/src/retroshare/rsposted.h | 21 +- libretroshare/src/rsserver/p3peers.cc | 2 + libretroshare/src/services/p3gxschannels.cc | 24 +- libretroshare/src/services/p3gxscircles.cc | 13 +- libretroshare/src/services/p3gxsforums.cc | 26 +- libretroshare/src/services/p3msgservice.cc | 53 ++-- libretroshare/src/services/p3postbase.cc | 18 +- libretroshare/src/services/p3rtt.cc | 31 ++- retroshare-gui/src/gui/NewsFeed.cpp | 237 +++++++++--------- .../src/gui/gxschannels/GxsChannelDialog.cpp | 2 +- .../gui/gxschannels/GxsChannelPostsWidget.cpp | 8 +- .../gui/gxsforums/GxsForumThreadWidget.cpp | 33 ++- .../src/gui/gxsforums/GxsForumsDialog.cpp | 2 +- 25 files changed, 430 insertions(+), 424 deletions(-) diff --git a/libretroshare/src/pqi/authssl.cc b/libretroshare/src/pqi/authssl.cc index f1d8da6eb..1e5d3e58e 100644 --- a/libretroshare/src/pqi/authssl.cc +++ b/libretroshare/src/pqi/authssl.cc @@ -1222,7 +1222,7 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx) ev->mSslId = sslId; ev->mPgpId = pgpId; ev->mErrorMsg = errMsg; - ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::AuthenticationCode::MISSING_AUTHENTICATION_INFO; + ev->mErrorCode = RsAuthSslError::MISSING_AUTHENTICATION_INFO; rsEvents->postEvent(std::move(ev)); } @@ -1242,7 +1242,7 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx) ev->mSslId = sslId; ev->mSslCn = sslCn; ev->mErrorMsg = errMsg; - ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::AuthenticationCode::MISSING_AUTHENTICATION_INFO; + ev->mErrorCode = RsAuthSslError::MISSING_AUTHENTICATION_INFO; rsEvents->postEvent(std::move(ev)); } @@ -1273,7 +1273,7 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx) ev->mSslCn = sslCn; ev->mPgpId = pgpId; ev->mErrorMsg = errorMsg; - ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::AuthenticationCode::MISMATCHED_PGP_ID; + ev->mErrorCode = RsAuthSslError::MISMATCHED_PGP_ID; rsEvents->postEvent(std::move(ev)); } @@ -1299,13 +1299,18 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx) ev->mSslCn = sslCn; ev->mPgpId = pgpId; - switch(auth_diagnostic) - { - case RS_SSL_HANDSHAKE_DIAGNOSTIC_ISSUER_UNKNOWN: ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::AuthenticationCode::NOT_A_FRIEND; break; - case RS_SSL_HANDSHAKE_DIAGNOSTIC_WRONG_SIGNATURE: ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::AuthenticationCode::PGP_SIGNATURE_VALIDATION_FAILED;break; + switch(auth_diagnostic) + { + case RS_SSL_HANDSHAKE_DIAGNOSTIC_ISSUER_UNKNOWN: + ev->mErrorCode = RsAuthSslError::NOT_A_FRIEND; + break; + case RS_SSL_HANDSHAKE_DIAGNOSTIC_WRONG_SIGNATURE: + ev->mErrorCode = RsAuthSslError::PGP_SIGNATURE_VALIDATION_FAILED; + break; default: - ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::AuthenticationCode::MISSING_AUTHENTICATION_INFO;break; - } + ev->mErrorCode = RsAuthSslError::MISSING_AUTHENTICATION_INFO; + break; + } ev->mErrorMsg = errMsg; rsEvents->postEvent(std::move(ev)); @@ -1331,7 +1336,7 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx) ev->mSslCn = sslCn; ev->mPgpId = pgpId; ev->mErrorMsg = errMsg; - ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::AuthenticationCode::NOT_A_FRIEND; + ev->mErrorCode = RsAuthSslError::NOT_A_FRIEND; rsEvents->postEvent(std::move(ev)); } @@ -1595,32 +1600,6 @@ bool AuthSSLimpl::decrypt(void *&out, int &outlen, const void *in, int inlen) return true; } - -/********************************************************************************/ -/********************************************************************************/ -/********************* Cert Search / Add / Remove **************************/ -/********************************************************************************/ -/********************************************************************************/ - -// void AuthSSLimpl::setCurrentConnectionAttemptInfo(const RsPgpId& gpg_id,const RsPeerId& ssl_id,const std::string& ssl_cn) -// { -// #ifdef AUTHSSL_DEBUG -// std::cerr << "AuthSSL: registering connection attempt from:" << std::endl; -// std::cerr << " GPG id: " << gpg_id << std::endl; -// std::cerr << " SSL id: " << ssl_id << std::endl; -// std::cerr << " SSL cn: " << ssl_cn << std::endl; -// #endif -// _last_gpgid_to_connect = gpg_id ; -// _last_sslid_to_connect = ssl_id ; -// _last_sslcn_to_connect = ssl_cn ; -// } -// void AuthSSLimpl::getCurrentConnectionAttemptInfo(RsPgpId& gpg_id,RsPeerId& ssl_id,std::string& ssl_cn) -// { -// gpg_id = _last_gpgid_to_connect ; -// ssl_id = _last_sslid_to_connect ; -// ssl_cn = _last_sslcn_to_connect ; -// } - /* Locked search -> internal help function */ bool AuthSSLimpl::locked_FindCert(const RsPeerId& id, X509** cert) { diff --git a/libretroshare/src/pqi/authssl.h b/libretroshare/src/pqi/authssl.h index f15a323b3..b63bd0e7a 100644 --- a/libretroshare/src/pqi/authssl.h +++ b/libretroshare/src/pqi/authssl.h @@ -137,13 +137,6 @@ public: /// SSL specific functions used in pqissl/pqissllistener virtual SSL_CTX* getCTX() = 0; -// virtual void setCurrentConnectionAttemptInfo( -// const RsPgpId& gpg_id, const RsPeerId& ssl_id, -// const std::string& ssl_cn ) = 0; -// virtual void getCurrentConnectionAttemptInfo( -// RsPgpId& gpg_id, RsPeerId& ssl_id, std::string& ssl_cn ) = 0; - - /** * This function parse X509 certificate from the file and return some * verified informations, like ID and signer @@ -230,14 +223,6 @@ public: /* SSL specific functions used in pqissl/pqissllistener */ SSL_CTX* getCTX() override; - /* Restored these functions: */ -// void setCurrentConnectionAttemptInfo( -// const RsPgpId& gpg_id, const RsPeerId& ssl_id, -// const std::string& ssl_cn ) override; -// void getCurrentConnectionAttemptInfo( -// RsPgpId& gpg_id, RsPeerId& ssl_id, std::string& ssl_cn ) override; - - private: bool LocalStoreCert(X509* x509); diff --git a/libretroshare/src/pqi/p3linkmgr.cc b/libretroshare/src/pqi/p3linkmgr.cc index fe3ea0889..a63054093 100644 --- a/libretroshare/src/pqi/p3linkmgr.cc +++ b/libretroshare/src/pqi/p3linkmgr.cc @@ -475,22 +475,18 @@ void p3LinkMgrIMPL::tickMonitors() /* notify GUI */ if (rsEvents && (peer.actions & RS_PEER_CONNECTED)) { - auto e = std::make_shared() ; - - e->mConnectionInfoCode = RsConnectionEvent::ConnectionEventCode::PEER_CONNECTED; + auto e = std::make_shared(); + e->mConnectionInfoCode = RsConnectionEventCode::PEER_CONNECTED; e->mSslId = peer.id; - rsEvents->postEvent(e); } if (rsEvents && (peer.actions & RS_PEER_DISCONNECTED)) { - auto e = std::make_shared() ; - - e->mConnectionInfoCode = RsConnectionEvent::ConnectionEventCode::PEER_DISCONNECTED; + auto e = std::make_shared(); + e->mConnectionInfoCode = RsConnectionEventCode::PEER_DISCONNECTED; e->mSslId = peer.id; - - rsEvents->postEvent(e); - } + rsEvents->postEvent(e); + } } } diff --git a/libretroshare/src/pqi/p3peermgr.cc b/libretroshare/src/pqi/p3peermgr.cc index daf997a01..07eb180d4 100644 --- a/libretroshare/src/pqi/p3peermgr.cc +++ b/libretroshare/src/pqi/p3peermgr.cc @@ -1804,21 +1804,24 @@ bool p3PeerMgrIMPL::addCandidateForOwnExternalAddress(const RsPeerId &from, cons // Notify for every friend that has reported a wrong external address, except if that address is in the IP whitelist. - if((rsBanList!=NULL && !rsBanList->isAddressAccepted(addr_filtered,RSBANLIST_CHECKING_FLAGS_WHITELIST)) && (!sockaddr_storage_sameip(own_addr,addr_filtered))) - { - 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; + if((rsBanList && !rsBanList->isAddressAccepted(addr_filtered, RSBANLIST_CHECKING_FLAGS_WHITELIST)) + && !sockaddr_storage_sameip(own_addr, addr_filtered) ) + { + RsInfo() << __PRETTY_FUNCTION__ << " Peer " << from + << " reports a connection address (" << addr_filtered + <<") that is not your current external address (" + << own_addr << "). This is weird." << std::endl; - if(rsEvents) - { - auto ev = std::make_shared(); - ev->mSslId = from; - ev->mStrInfo1 = sockaddr_storage_iptostring(addr); - ev->mStrInfo2 = sockaddr_storage_iptostring(own_addr); - ev->mConnectionInfoCode = RsConnectionEvent::ConnectionEventCode::PEER_REPORTS_WRONG_IP; - - rsEvents->postEvent(ev); - } - } + if(rsEvents) + { + auto ev = std::make_shared(); + ev->mSslId = from; + ev->mOwnLocator = RsUrl(own_addr); + ev->mReportedLocator = RsUrl(addr); + ev->mConnectionInfoCode = RsConnectionEventCode::PEER_REPORTS_WRONG_IP; + rsEvents->postEvent(ev); + } + } // we could also sweep over all connected friends and see if some report a different address. diff --git a/libretroshare/src/pqi/pqissl.cc b/libretroshare/src/pqi/pqissl.cc index f1ddd1cef..0ef930fc2 100644 --- a/libretroshare/src/pqi/pqissl.cc +++ b/libretroshare/src/pqi/pqissl.cc @@ -1107,16 +1107,14 @@ int pqissl::SSL_Connection_Complete() return 0; } - if(rsEvents) - { + if(rsEvents) + { + X509 *x509 = SSL_get_peer_certificate(ssl_connection); auto ev = std::make_shared(); - - X509 *x509 = SSL_get_peer_certificate(ssl_connection) ; - ev->mSslId = RsX509Cert::getCertSslId(*x509); - ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::AuthenticationCode::PEER_REFUSED_CONNECTION; + ev->mErrorCode = RsAuthSslError::PEER_REFUSED_CONNECTION; rsEvents->postEvent(ev); - } + } std::string out; rs_sprintf(out, "pqissl::SSL_Connection_Complete()\nIssues with SSL Connect(%d)!\n", err); @@ -1275,18 +1273,15 @@ int pqissl::accept_locked( SSL *ssl, int fd, << std::endl; print_stacktrace(); - if(rsEvents) - { + if(rsEvents) + { + X509 *x509 = SSL_get_peer_certificate(ssl); auto ev = std::make_shared(); - - X509 *x509 = SSL_get_peer_certificate(ssl) ; - ev->mSslId = RsX509Cert::getCertSslId(*x509); ev->mLocator = RsUrl(foreign_addr); - ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::AuthenticationCode::IP_IS_BLACKLISTED; - + ev->mErrorCode = RsAuthSslError::IP_IS_BLACKLISTED; rsEvents->postEvent(ev); - } + } reset_locked(); return failure; diff --git a/libretroshare/src/pqi/pqissllistener.cc b/libretroshare/src/pqi/pqissllistener.cc index 7b2d6d36f..fa25bfe0b 100644 --- a/libretroshare/src/pqi/pqissllistener.cc +++ b/libretroshare/src/pqi/pqissllistener.cc @@ -480,14 +480,12 @@ int pqissllistenbase::continueSSL(IncomingSSLInfo& incoming_connexion_info, bool if(vres == X509_V_OK && nullptr != rsEvents) { - auto ev = std::unique_ptr(new RsAuthSslConnectionAutenticationEvent); - + auto ev = std::make_shared(); ev->mLocator = RsUrl(incoming_connexion_info.addr); - ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::AuthenticationCode::MISSING_AUTHENTICATION_INFO; - - rsEvents->postEvent(std::move(ev)); + ev->mErrorCode = RsAuthSslError::MISSING_AUTHENTICATION_INFO; + rsEvents->postEvent(ev); } - closeConnection(fd, incoming_connexion_info.ssl) ; + closeConnection(fd, incoming_connexion_info.ssl); // failure -1, pending 0, sucess 1. return -1; diff --git a/libretroshare/src/retroshare/rsevents.h b/libretroshare/src/retroshare/rsevents.h index 249a6f50b..98d95eba5 100644 --- a/libretroshare/src/retroshare/rsevents.h +++ b/libretroshare/src/retroshare/rsevents.h @@ -61,7 +61,7 @@ enum class RsEventType : uint32_t /// @see pqissl PEER_CONNECTION = 4, - /// @see RsGxsChanges // this one should probably be removed because it's not used anywhere + /// @see RsGxsChanges GXS_CHANGES = 5, /// Emitted when a peer state changes, @see RsPeers diff --git a/libretroshare/src/retroshare/rsgxschannels.h b/libretroshare/src/retroshare/rsgxschannels.h index f3a70cf9e..8e6939672 100644 --- a/libretroshare/src/retroshare/rsgxschannels.h +++ b/libretroshare/src/retroshare/rsgxschannels.h @@ -102,23 +102,36 @@ struct RsGxsChannelPost : RsSerializable ~RsGxsChannelPost() override; }; + +enum class RsChannelEventCode: uint8_t +{ + UNKNOWN = 0x00, + NEW_CHANNEL = 0x01, /// emitted when new channel is received + + /// emitted when existing channel is updated + UPDATED_CHANNEL = 0x02, + + /// new message reeived in a particular channel (group and msg id) + NEW_MESSAGE = 0x03, + + /// existing message has been updated in a particular channel + UPDATED_MESSAGE = 0x04, + + /// publish key for this channel has been received + RECEIVED_PUBLISH_KEY = 0x05, + + /// subscription for channel mChannelGroupId changed. + SUBSCRIBE_STATUS_CHANGED = 0x06, +}; + struct RsGxsChannelEvent: RsEvent { - RsGxsChannelEvent() - : RsEvent(RsEventType::GXS_CHANNELS), mChannelEventCode(ChannelEventCode::UNKNOWN) {} + RsGxsChannelEvent(): + RsEvent(RsEventType::GXS_CHANNELS), + mChannelEventCode(RsChannelEventCode::UNKNOWN) {} - enum class ChannelEventCode: uint8_t { - UNKNOWN = 0x00, - NEW_CHANNEL = 0x01, // emitted when new channel is received - UPDATED_CHANNEL = 0x02, // emitted when existing channel is updated - NEW_MESSAGE = 0x03, // new message reeived in a particular channel (group and msg id) - UPDATED_MESSAGE = 0x04, // existing message has been updated in a particular channel (group and msg id) - RECEIVED_PUBLISH_KEY = 0x05, // publish key for this channel has been received. - SUBSCRIBE_STATUS_CHANGED = 0x06, // subscription for channel mChannelGroupId changed. - }; - - ChannelEventCode mChannelEventCode; - RsGxsGroupId mChannelGroupId; + RsChannelEventCode mChannelEventCode; + RsGxsGroupId mChannelGroupId; RsGxsMessageId mChannelMsgId; ///* @see RsEvent @see RsSerializable diff --git a/libretroshare/src/retroshare/rsgxscircles.h b/libretroshare/src/retroshare/rsgxscircles.h index 93fe90319..5ef69fda8 100644 --- a/libretroshare/src/retroshare/rsgxscircles.h +++ b/libretroshare/src/retroshare/rsgxscircles.h @@ -162,32 +162,54 @@ struct RsGxsCircleDetails : RsSerializable } }; + +enum class RsGxsCircleEventCode: uint8_t +{ + UNKNOWN = 0x00, + + /** mCircleId contains the circle id and mGxsId is the id requesting + * membership */ + CIRCLE_MEMBERSHIP_REQUEST = 0x01, + + /** mCircleId is the circle that invites me, and mGxsId is my own Id that is + * invited */ + CIRCLE_MEMBERSHIP_INVITE = 0x02, + + /** mCircleId contains the circle id and mGxsId is the id dropping + * membership */ + CIRCLE_MEMBERSHIP_LEAVE = 0x03, + + /// mCircleId contains the circle id and mGxsId is the id of the new member + CIRCLE_MEMBERSHIP_JOIN = 0x04, + + /** mCircleId contains the circle id and mGxsId is the id that was revoqued + * by admin */ + CIRCLE_MEMBERSHIP_REVOQUED= 0x05, +}; + struct RsGxsCircleEvent: RsEvent { RsGxsCircleEvent() - : RsEvent(RsEventType::GXS_CIRCLES), mCircleEventType(CircleEventCode::UNKNOWN) {} + : RsEvent(RsEventType::GXS_CIRCLES), + mCircleEventType(RsGxsCircleEventCode::UNKNOWN) {} - enum class CircleEventCode: uint8_t { - UNKNOWN = 0x00, - CIRCLE_MEMBERSHIP_REQUEST = 0x01, // mCircleId contains the circle id and mGxsId is the id requesting membership - CIRCLE_MEMBERSHIP_INVITE = 0x02, // mCircleId is the circle that invites me, and mGxsId is my own Id that is invited - CIRCLE_MEMBERSHIP_LEAVE = 0x03, // mCircleId contains the circle id and mGxsId is the id dropping membership - CIRCLE_MEMBERSHIP_JOIN = 0x04, // mCircleId contains the circle id and mGxsId is the id of the new member - CIRCLE_MEMBERSHIP_REVOQUED= 0x05, // mCircleId contains the circle id and mGxsId is the id that was revoqued by admin - }; - CircleEventCode mCircleEventType; - RsGxsCircleId mCircleId; - RsGxsId mGxsId; + RsGxsCircleEventCode mCircleEventType; + RsGxsCircleId mCircleId; + RsGxsId mGxsId; ///* @see RsEvent @see RsSerializable - void serial_process( RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) override + void serial_process( + RsGenericSerializer::SerializeJob j, + RsGenericSerializer::SerializeContext& ctx ) override { RsEvent::serial_process(j, ctx); RS_SERIAL_PROCESS(mCircleEventType); RS_SERIAL_PROCESS(mCircleId); RS_SERIAL_PROCESS(mGxsId); } + + ~RsGxsCircleEvent() override; }; class RsGxsCircles: public RsGxsIfaceHelper diff --git a/libretroshare/src/retroshare/rsgxsforums.h b/libretroshare/src/retroshare/rsgxsforums.h index 91f4dcbf9..1ce658ab3 100644 --- a/libretroshare/src/retroshare/rsgxsforums.h +++ b/libretroshare/src/retroshare/rsgxsforums.h @@ -104,33 +104,45 @@ struct RsGxsForumMsg : RsSerializable ~RsGxsForumMsg() override; }; + +enum class RsForumEventCode: uint8_t +{ + UNKNOWN = 0x00, + NEW_FORUM = 0x01, /// emitted when new forum is received + UPDATED_FORUM = 0x02, /// emitted when existing forum is updated + + /// new message reeived in a particular forum + NEW_MESSAGE = 0x03, + + /// existing message has been updated in a particular forum + UPDATED_MESSAGE = 0x04, + + /// forum was subscribed or unsubscribed + SUBSCRIBE_STATUS_CHANGED = 0x05, +}; + struct RsGxsForumEvent: RsEvent { - RsGxsForumEvent() - : RsEvent(RsEventType::GXS_FORUMS), mForumEventCode(ForumEventCode::UNKNOWN) {} + RsGxsForumEvent() + : RsEvent(RsEventType::GXS_FORUMS), + mForumEventCode(RsForumEventCode::UNKNOWN) {} - enum class ForumEventCode: uint8_t { - UNKNOWN = 0x00, - NEW_FORUM = 0x01, // emitted when new forum is received - UPDATED_FORUM = 0x02, // emitted when existing forum is updated - NEW_MESSAGE = 0x03, // new message reeived in a particular forum (group and msg id) - UPDATED_MESSAGE = 0x04, // existing message has been updated in a particular forum (group and msg id) - SUBSCRIBE_STATUS_CHANGED = 0x05, // forum was subscribed or unsubscribed - }; - - ForumEventCode mForumEventCode; - RsGxsGroupId mForumGroupId; + RsForumEventCode mForumEventCode; + RsGxsGroupId mForumGroupId; RsGxsMessageId mForumMsgId; ///* @see RsEvent @see RsSerializable - void serial_process( RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) override + void serial_process( + RsGenericSerializer::SerializeJob j, + RsGenericSerializer::SerializeContext& ctx ) override { RsEvent::serial_process(j, ctx); - RS_SERIAL_PROCESS(mForumEventCode); RS_SERIAL_PROCESS(mForumGroupId); RS_SERIAL_PROCESS(mForumMsgId); - } + } + + ~RsGxsForumEvent() override; }; class RsGxsForums: public RsGxsIfaceHelper diff --git a/libretroshare/src/retroshare/rsmsgs.h b/libretroshare/src/retroshare/rsmsgs.h index cbdd525bc..915444360 100644 --- a/libretroshare/src/retroshare/rsmsgs.h +++ b/libretroshare/src/retroshare/rsmsgs.h @@ -296,19 +296,25 @@ struct MsgTagType : RsSerializable } //namespace Rs } //namespace Msgs + +enum class RsMailStatusEventCode: uint8_t +{ + NEW_MESSAGE = 0x00, + MESSAGE_REMOVED = 0x01, + MESSAGE_SENT = 0x02, + + /// means the peer received the message + MESSAGE_RECEIVED_ACK = 0x03, + + /// An error occurred attempting to sign the message + SIGNATURE_FAILED = 0x04, +}; + struct RsMailStatusEvent : RsEvent { RsMailStatusEvent() : RsEvent(RsEventType::MAIL_STATUS_CHANGE) {} - enum MailStatusEventCode: uint8_t { - NEW_MESSAGE = 0x00, - MESSAGE_REMOVED = 0x01, - MESSAGE_SENT = 0x02, - MESSAGE_RECEIVED_ACK = 0x03, // means the peer received the message - FAILED_SIGNATURE = 0x04, // means the signature of the message cannot be verified - }; - - MailStatusEventCode mMailStatusEventCode; + RsMailStatusEventCode mMailStatusEventCode; std::set mChangedMsgIds; /// @see RsEvent diff --git a/libretroshare/src/retroshare/rspeers.h b/libretroshare/src/retroshare/rspeers.h index 3976d6861..65b028326 100644 --- a/libretroshare/src/retroshare/rspeers.h +++ b/libretroshare/src/retroshare/rspeers.h @@ -210,33 +210,35 @@ std::string RsPeerLastConnectString(uint32_t lastConnect); // Connexion and security events // //===================================================================================================// +enum class RsAuthSslError: uint8_t +{ + NO_ERROR = 0x00, + MISSING_AUTHENTICATION_INFO = 0x01, + PGP_SIGNATURE_VALIDATION_FAILED = 0x02, + MISMATCHED_PGP_ID = 0x03, + NO_CERTIFICATE_SUPPLIED = 0x04, + NOT_A_FRIEND = 0x05, + MISSING_CERTIFICATE = 0x06, + IP_IS_BLACKLISTED = 0x07, + PEER_REFUSED_CONNECTION = 0x08, + UNKNOWN_ERROR = 0x09, +}; + /** * Event triggered by AuthSSL when authentication of a connection attempt either * fail or success */ struct RsAuthSslConnectionAutenticationEvent : RsEvent { - RsAuthSslConnectionAutenticationEvent() : RsEvent(RsEventType::AUTHSSL_CONNECTION_AUTENTICATION) {} - - enum class AuthenticationCode: uint8_t { - NO_CONNECTION_ERROR = 0x00, - MISSING_AUTHENTICATION_INFO = 0x01, - PGP_SIGNATURE_VALIDATION_FAILED = 0x02, - MISMATCHED_PGP_ID = 0x03, - NO_CERTIFICATE_SUPPLIED = 0x04, - NOT_A_FRIEND = 0x05, - MISSING_CERTIFICATE = 0x06, - IP_IS_BLACKLISTED = 0x07, - PEER_REFUSED_CONNECTION = 0x08, - UNKNOWN_ERROR = 0x09, - }; + RsAuthSslConnectionAutenticationEvent() : + RsEvent(RsEventType::AUTHSSL_CONNECTION_AUTENTICATION) {} RsPeerId mSslId; std::string mSslCn; RsPgpId mPgpId; - RsUrl mLocator; + RsUrl mLocator; std::string mErrorMsg; - AuthenticationCode mErrorCode; + RsAuthSslError mErrorCode; ///* @see RsEvent @see RsSerializable void serial_process( RsGenericSerializer::SerializeJob j, @@ -250,36 +252,49 @@ struct RsAuthSslConnectionAutenticationEvent : RsEvent RS_SERIAL_PROCESS(mErrorMsg); RS_SERIAL_PROCESS(mErrorCode); } + + ~RsAuthSslConnectionAutenticationEvent() override; +}; + +enum class RsConnectionEventCode: uint8_t +{ + UNKNOWN = 0x00, + PEER_CONNECTED = 0x01, + PEER_DISCONNECTED = 0x02, + PEER_TIME_SHIFT = 0x03, // mTimeShift = time shift in seconds + PEER_REPORTS_WRONG_IP = 0x04, // mPeerLocator = address reported, mOwnLocator = own address }; struct RsConnectionEvent : RsEvent { RsConnectionEvent() : RsEvent(RsEventType::PEER_CONNECTION), - mConnectionInfoCode(ConnectionEventCode::UNKNOWN) {} + mConnectionInfoCode(RsConnectionEventCode::UNKNOWN), mTimeShift(0) {} - enum class ConnectionEventCode: 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 - }; - - ConnectionEventCode mConnectionInfoCode; + RsConnectionEventCode mConnectionInfoCode; RsPeerId mSslId; - std::string mStrInfo1; - std::string mStrInfo2; + RsUrl mOwnLocator; + RsUrl mReportedLocator; + + /** If there is a time shift with the peer aka + * mConnectionInfoCode == PEER_TIME_SHIFT contains the time shift value in + * seconds */ + rstime_t mTimeShift; ///* @see RsEvent @see RsSerializable - void serial_process( RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) override + void serial_process( + RsGenericSerializer::SerializeJob j, + RsGenericSerializer::SerializeContext& ctx ) override { RsEvent::serial_process(j, ctx); RS_SERIAL_PROCESS(mConnectionInfoCode); RS_SERIAL_PROCESS(mSslId); - RS_SERIAL_PROCESS(mStrInfo1); - RS_SERIAL_PROCESS(mStrInfo2); + RS_SERIAL_PROCESS(mOwnLocator); + RS_SERIAL_PROCESS(mReportedLocator); + RS_SERIAL_PROCESS(mTimeShift); } + + ~RsConnectionEvent() override; }; //===================================================================================================// diff --git a/libretroshare/src/retroshare/rsposted.h b/libretroshare/src/retroshare/rsposted.h index 75ab2fa0c..211f67bb1 100644 --- a/libretroshare/src/retroshare/rsposted.h +++ b/libretroshare/src/retroshare/rsposted.h @@ -68,18 +68,21 @@ class RsPostedGroup std::ostream &operator<<(std::ostream &out, const RsPostedGroup &group); std::ostream &operator<<(std::ostream &out, const RsPostedPost &post); +enum class RsPostedEventCode: uint8_t +{ + UNKNOWN = 0x00, + NEW_POSTED_GROUP = 0x01, + NEW_MESSAGE = 0x02 +}; + + struct RsGxsPostedEvent: RsEvent { - RsGxsPostedEvent() - : RsEvent(RsEventType::GXS_POSTED), mPostedEventCode(PostedEventCode::UNKNOWN) {} + RsGxsPostedEvent(): + RsEvent(RsEventType::GXS_POSTED), + mPostedEventCode(RsPostedEventCode::UNKNOWN) {} - enum class PostedEventCode: uint8_t { - UNKNOWN = 0x00, - NEW_POSTED_GROUP = 0x01, - NEW_MESSAGE = 0x02 - }; - - PostedEventCode mPostedEventCode; + RsPostedEventCode mPostedEventCode; RsGxsGroupId mPostedGroupId; RsGxsMessageId mPostedMsgId; diff --git a/libretroshare/src/rsserver/p3peers.cc b/libretroshare/src/rsserver/p3peers.cc index 0ea163f35..d4c99d259 100644 --- a/libretroshare/src/rsserver/p3peers.cc +++ b/libretroshare/src/rsserver/p3peers.cc @@ -1859,3 +1859,5 @@ RsPeerStateChangedEvent::RsPeerStateChangedEvent(RsPeerId sslId) : RsEvent(RsEventType::PEER_STATE_CHANGED), mSslId(sslId) {} RsPeers::~RsPeers() = default; +RsAuthSslConnectionAutenticationEvent::~RsAuthSslConnectionAutenticationEvent() = default; +RsConnectionEvent::~RsConnectionEvent() = default; diff --git a/libretroshare/src/services/p3gxschannels.cc b/libretroshare/src/services/p3gxschannels.cc index 648098dec..8ee484d08 100644 --- a/libretroshare/src/services/p3gxschannels.cc +++ b/libretroshare/src/services/p3gxschannels.cc @@ -257,12 +257,10 @@ void p3GxsChannels::notifyChanges(std::vector &changes) for (auto mit1 = mit->second.begin(); mit1 != mit->second.end(); ++mit1) { auto ev = std::make_shared(); - ev->mChannelMsgId = *mit1; ev->mChannelGroupId = mit->first; - ev->mChannelEventCode = RsGxsChannelEvent::ChannelEventCode::NEW_MESSAGE; - - rsEvents->sendEvent(ev); + ev->mChannelEventCode = RsChannelEventCode::NEW_MESSAGE; + rsEvents->postEvent(ev); } } } @@ -313,11 +311,9 @@ void p3GxsChannels::notifyChanges(std::vector &changes) for (git = grpList.begin(); git != grpList.end(); ++git) { auto ev = std::make_shared(); - ev->mChannelGroupId = *git; - ev->mChannelEventCode = RsGxsChannelEvent::ChannelEventCode::SUBSCRIBE_STATUS_CHANGED; - - rsEvents->sendEvent(ev); + ev->mChannelEventCode = RsChannelEventCode::SUBSCRIBE_STATUS_CHANGED; + rsEvents->postEvent(ev); } } @@ -338,11 +334,9 @@ void p3GxsChannels::notifyChanges(std::vector &changes) IndicateConfigChanged(); auto ev = std::make_shared(); - ev->mChannelGroupId = *git; - ev->mChannelEventCode = RsGxsChannelEvent::ChannelEventCode::NEW_CHANNEL; - - rsEvents->sendEvent(ev); + ev->mChannelEventCode = RsChannelEventCode::NEW_CHANNEL; + rsEvents->postEvent(ev); } else std::cerr << "(II) Not notifying already known channel " << *git << std::endl; @@ -358,11 +352,9 @@ void p3GxsChannels::notifyChanges(std::vector &changes) for (git = grpList.begin(); git != grpList.end(); ++git) { auto ev = std::make_shared(); - ev->mChannelGroupId = *git; - ev->mChannelEventCode = RsGxsChannelEvent::ChannelEventCode::RECEIVED_PUBLISH_KEY; - - rsEvents->sendEvent(ev); + ev->mChannelEventCode = RsChannelEventCode::RECEIVED_PUBLISH_KEY; + rsEvents->postEvent(ev); } break; } diff --git a/libretroshare/src/services/p3gxscircles.cc b/libretroshare/src/services/p3gxscircles.cc index 79707d5cf..a2fac2db8 100644 --- a/libretroshare/src/services/p3gxscircles.cc +++ b/libretroshare/src/services/p3gxscircles.cc @@ -504,23 +504,21 @@ void p3GxsCircles::notifyChanges(std::vector &changes) if(rsEvents && (c->getType() == RsGxsNotify::TYPE_RECEIVED_NEW) ) for (auto msgIdIt(mit->second.begin()), end(mit->second.end()); msgIdIt != end; ++msgIdIt) { - // @Gio: should this be async? - RsGxsCircleMsg msg; + RsGxsCircleMsg msg; getCircleRequest(RsGxsGroupId(circle_id),*msgIdIt,msg); auto ev = std::make_shared(); - ev->mCircleId = circle_id; ev->mGxsId = msg.mMeta.mAuthorId; if (msg.stuff == "SUBSCRIPTION_REQUEST_UNSUBSCRIBE") - ev->mCircleEventType = RsGxsCircleEvent::CircleEventCode::CIRCLE_MEMBERSHIP_LEAVE; + ev->mCircleEventType = RsGxsCircleEventCode::CIRCLE_MEMBERSHIP_LEAVE; else if(details.mAllowedGxsIds.find(msg.mMeta.mAuthorId) != details.mAllowedGxsIds.end()) - ev->mCircleEventType = RsGxsCircleEvent::CircleEventCode::CIRCLE_MEMBERSHIP_JOIN; + ev->mCircleEventType = RsGxsCircleEventCode::CIRCLE_MEMBERSHIP_JOIN; else - ev->mCircleEventType = RsGxsCircleEvent::CircleEventCode::CIRCLE_MEMBERSHIP_REQUEST; + ev->mCircleEventType = RsGxsCircleEventCode::CIRCLE_MEMBERSHIP_REQUEST; - rsEvents->sendEvent(ev); + rsEvents->postEvent(ev); } } @@ -2416,3 +2414,4 @@ RsGxsCircles::~RsGxsCircles() = default; RsGxsCircleMsg::~RsGxsCircleMsg() = default; RsGxsCircleDetails::~RsGxsCircleDetails() = default; RsGxsCircleGroup::~RsGxsCircleGroup() = default; +RsGxsCircleEvent::~RsGxsCircleEvent() = default; diff --git a/libretroshare/src/services/p3gxsforums.cc b/libretroshare/src/services/p3gxsforums.cc index e69f1f06f..128b5db39 100644 --- a/libretroshare/src/services/p3gxsforums.cc +++ b/libretroshare/src/services/p3gxsforums.cc @@ -199,12 +199,10 @@ void p3GxsForums::notifyChanges(std::vector &changes) for (auto mit1 = mit->second.begin(); mit1 != mit->second.end(); ++mit1) { auto ev = std::make_shared(); - ev->mForumMsgId = *mit1; ev->mForumGroupId = mit->first; - ev->mForumEventCode = RsGxsForumEvent::ForumEventCode::NEW_MESSAGE; - - rsEvents->sendEvent(ev); + ev->mForumEventCode = RsForumEventCode::NEW_MESSAGE; + rsEvents->postEvent(ev); } } @@ -256,11 +254,9 @@ void p3GxsForums::notifyChanges(std::vector &changes) for (git = grpList.begin(); git != grpList.end(); ++git) { auto ev = std::make_shared(); - ev->mForumGroupId = *git; - ev->mForumEventCode = RsGxsForumEvent::ForumEventCode::SUBSCRIBE_STATUS_CHANGED; - - rsEvents->sendEvent(ev); + ev->mForumEventCode = RsForumEventCode::SUBSCRIBE_STATUS_CHANGED; + rsEvents->postEvent(ev); } } @@ -278,18 +274,19 @@ void p3GxsForums::notifyChanges(std::vector &changes) { if(mKnownForums.find(*git) == mKnownForums.end()) { - mKnownForums.insert(std::make_pair(*git,time(NULL))) ; + mKnownForums.insert( + std::make_pair(*git, time(nullptr))); IndicateConfigChanged(); auto ev = std::make_shared(); - ev->mForumGroupId = *git; - ev->mForumEventCode = RsGxsForumEvent::ForumEventCode::NEW_FORUM; - - rsEvents->sendEvent(ev); + ev->mForumEventCode = RsForumEventCode::NEW_FORUM; + rsEvents->postEvent(ev); } else - std::cerr << "(II) Not notifying already known channel " << *git << std::endl; + RsInfo() << __PRETTY_FUNCTION__ + << " Not notifying already known forum " + << *git << std::endl; } break; } @@ -1148,3 +1145,4 @@ bool RsGxsForumGroup::canEditPosts(const RsGxsId& id) const RsGxsForumGroup::~RsGxsForumGroup() = default; RsGxsForumMsg::~RsGxsForumMsg() = default; RsGxsForums::~RsGxsForums() = default; +RsGxsForumEvent::~RsGxsForumEvent() = default; diff --git a/libretroshare/src/services/p3msgservice.cc b/libretroshare/src/services/p3msgservice.cc index dc67a0f60..8acd44501 100644 --- a/libretroshare/src/services/p3msgservice.cc +++ b/libretroshare/src/services/p3msgservice.cc @@ -177,12 +177,11 @@ void p3MsgService::processIncomingMsg(RsMsgItem *mi) if (rsEvents) { - auto ev = std::make_shared(); - ev->mMailStatusEventCode = RsMailStatusEvent::NEW_MESSAGE; + auto ev = std::make_shared(); + ev->mMailStatusEventCode = RsMailStatusEventCode::NEW_MESSAGE; ev->mChangedMsgIds.insert(std::to_string(mi->msgId)); - - rsEvents->sendEvent(ev); - } + rsEvents->postEvent(ev); + } imsg[mi->msgId] = mi; RsMsgSrcId* msi = new RsMsgSrcId(); @@ -337,8 +336,8 @@ int p3MsgService::checkOutgoingMessages() bool changed = false; std::list output_queue; - auto pEvent = std::make_shared(); - pEvent->mMailStatusEventCode = RsMailStatusEvent::MESSAGE_SENT; + auto pEvent = std::make_shared(); + pEvent->mMailStatusEventCode = RsMailStatusEventCode::MESSAGE_SENT; { RS_STACK_MUTEX(mMsgMtx); /********** STACK LOCKED MTX ******/ @@ -898,9 +897,8 @@ bool p3MsgService::removeMsgId(const std::string &mid) bool changed = false; - auto pEvent = std::make_shared(); - - pEvent->mMailStatusEventCode = RsMailStatusEvent::MESSAGE_REMOVED; + auto pEvent = std::make_shared(); + pEvent->mMailStatusEventCode = RsMailStatusEventCode::MESSAGE_REMOVED; { RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/ @@ -1268,8 +1266,8 @@ uint32_t p3MsgService::sendMail( uint32_t ret = 0; - auto pEvent = std::make_shared(); - pEvent->mMailStatusEventCode = RsMailStatusEvent::MESSAGE_SENT; + auto pEvent = std::make_shared(); + pEvent->mMailStatusEventCode = RsMailStatusEventCode::MESSAGE_SENT; auto pSend = [&](const std::set& sDest) { @@ -2083,12 +2081,13 @@ void p3MsgService::notifyDataStatus( const GRouterMsgPropagationId& id, NOTIFY_TYPE_ADD ); IndicateConfigChanged(); - auto pEvent = std::make_shared(); - - pEvent->mMailStatusEventCode = RsMailStatusEvent::NEW_MESSAGE; - pEvent->mChangedMsgIds.insert(std::to_string(msg_id)); - - if(rsEvents) rsEvents->postEvent(pEvent); + if(rsEvents) + { + auto pEvent = std::make_shared(); + pEvent->mMailStatusEventCode = RsMailStatusEventCode::NEW_MESSAGE; + pEvent->mChangedMsgIds.insert(std::to_string(msg_id)); + rsEvents->postEvent(pEvent); + } return; } @@ -2185,11 +2184,11 @@ bool p3MsgService::notifyGxsTransSendStatus( RsGxsTransId mailId, Dbg2() << __PRETTY_FUNCTION__ << " " << mailId << ", " << static_cast(status) << std::endl; - auto pEvent = std::make_shared(); + auto pEvent = std::make_shared(); if( status == GxsTransSendStatus::RECEIPT_RECEIVED ) { - pEvent->mMailStatusEventCode = RsMailStatusEvent::NEW_MESSAGE; + pEvent->mMailStatusEventCode = RsMailStatusEventCode::NEW_MESSAGE; uint32_t msg_id; { @@ -2244,20 +2243,20 @@ bool p3MsgService::notifyGxsTransSendStatus( RsGxsTransId mailId, else if( status >= GxsTransSendStatus::FAILED_RECEIPT_SIGNATURE ) { uint32_t msg_id; - pEvent->mMailStatusEventCode = RsMailStatusEvent::FAILED_SIGNATURE; + pEvent->mMailStatusEventCode = RsMailStatusEventCode::SIGNATURE_FAILED; { RS_STACK_MUTEX(gxsOngoingMutex); - - std::cerr << __PRETTY_FUNCTION__ << " mail delivery " - << "mailId: " << mailId - << " failed with " << static_cast(status); + RsErr() << __PRETTY_FUNCTION__ << " mail delivery " + << "mailId: " << mailId + << " failed with " << static_cast(status); auto it = gxsOngoingMessages.find(mailId); if(it == gxsOngoingMessages.end()) { - std::cerr << " cannot find pending message to notify" - << std::endl; + RsErr() << __PRETTY_FUNCTION__ + << " cannot find pending message to notify" + << std::endl; return false; } diff --git a/libretroshare/src/services/p3postbase.cc b/libretroshare/src/services/p3postbase.cc index 222d6de25..51308194c 100644 --- a/libretroshare/src/services/p3postbase.cc +++ b/libretroshare/src/services/p3postbase.cc @@ -115,13 +115,11 @@ void p3PostBase::notifyChanges(std::vector &changes) if (rsEvents && msgChange->getType() == RsGxsNotify::TYPE_RECEIVED_NEW) for (auto mit1 = mit->second.begin(); mit1 != mit->second.end(); ++mit1) { - auto ev = std::make_shared(); - - ev->mPostedMsgId = *mit1; - ev->mPostedGroupId = mit->first; - ev->mPostedEventCode = RsGxsPostedEvent::PostedEventCode::NEW_MESSAGE; - - rsEvents->sendEvent(ev); + auto ev = std::make_shared(); + ev->mPostedMsgId = *mit1; + ev->mPostedGroupId = mit->first; + ev->mPostedEventCode = RsPostedEventCode::NEW_MESSAGE; + rsEvents->postEvent(ev); } } } @@ -146,11 +144,9 @@ void p3PostBase::notifyChanges(std::vector &changes) if (rsEvents && groupChange->getType() == RsGxsNotify::TYPE_RECEIVED_NEW) { auto ev = std::make_shared(); - ev->mPostedGroupId = *git; - ev->mPostedEventCode = RsGxsPostedEvent::PostedEventCode::NEW_POSTED_GROUP; - - rsEvents->sendEvent(ev); + ev->mPostedEventCode = RsPostedEventCode::NEW_POSTED_GROUP; + rsEvents->postEvent(ev); } } } diff --git a/libretroshare/src/services/p3rtt.cc b/libretroshare/src/services/p3rtt.cc index 5dcd5a225..0dc2f41e2 100644 --- a/libretroshare/src/services/p3rtt.cc +++ b/libretroshare/src/services/p3rtt.cc @@ -20,6 +20,8 @@ * * *******************************************************************************/ #include +#include +#include #include "util/rsdir.h" #include "retroshare/rsiface.h" @@ -28,12 +30,10 @@ #include "pqi/pqistore.h" #include "pqi/p3linkmgr.h" #include "rsserver/p3face.h" - +#include "util/cxx17retrocompat.h" #include "services/p3rtt.h" #include "rsitems/rsrttitems.h" -#include -#include /**** * #define DEBUG_RTT 1 @@ -353,32 +353,29 @@ int p3rtt::storePongResult(const RsPeerId& id, uint32_t counter, double recv_ts, while(peerInfo->mPongResults.size() > MAX_PONG_RESULTS) - { peerInfo->mPongResults.pop_front(); - } //Wait at least 20 pongs before compute mean time offset if(peerInfo->mPongResults.size() > 20) { double mean = 0; - for(std::list::const_iterator prIt = peerInfo->mPongResults.begin(), end = peerInfo->mPongResults.end(); prIt != end; ++ prIt) - { - mean += prIt->mOffset; - } + for(auto prIt : std::as_const(peerInfo->mPongResults)) + mean += prIt.mOffset; peerInfo->mCurrentMeanOffset = mean / peerInfo->mPongResults.size(); + if(fabs(peerInfo->mCurrentMeanOffset) > 120) { - if(rsEvents) - { + if(rsEvents) + { auto ev = std::make_shared(); - ev->mSslId = peerInfo->mId; - ev->mStrInfo1 = RsUtil::NumberToString(peerInfo->mCurrentMeanOffset,false); - ev->mConnectionInfoCode = RsConnectionEvent::ConnectionEventCode::PEER_TIME_SHIFT; - + ev->mTimeShift = static_cast(peerInfo->mCurrentMeanOffset); + ev->mConnectionInfoCode = RsConnectionEventCode::PEER_TIME_SHIFT; rsEvents->postEvent(ev); - } - std::cerr << "(WW) Peer:" << peerInfo->mId << " get time offset more than two minutes with you!!!" << std::endl; + } + RsWarn() << __PRETTY_FUNCTION__ << " Peer: " << peerInfo->mId + << " have a time offset of more than two minutes with you" + << std::endl; } } return 1; diff --git a/retroshare-gui/src/gui/NewsFeed.cpp b/retroshare-gui/src/gui/NewsFeed.cpp index ac44de06b..995ac13fc 100644 --- a/retroshare-gui/src/gui/NewsFeed.cpp +++ b/retroshare-gui/src/gui/NewsFeed.cpp @@ -196,83 +196,78 @@ void NewsFeed::handleEvent_main_thread(std::shared_ptr event) void NewsFeed::handleMailEvent(std::shared_ptr event) { - const RsMailStatusEvent *pe = dynamic_cast(event.get()); - if(!pe) - return; + const RsMailStatusEvent *pe = + dynamic_cast(event.get()); + if(!pe) return; - switch(pe->mMailStatusEventCode) - { - case RsMailStatusEvent::NEW_MESSAGE: - for(auto msgid: pe->mChangedMsgIds) - addFeedItem( new MsgItem(this, NEWSFEED_MESSAGELIST, msgid, false)); - break; - default: - break; - } + switch(pe->mMailStatusEventCode) + { + case RsMailStatusEventCode::NEW_MESSAGE: + for(auto msgid: pe->mChangedMsgIds) + addFeedItem( new MsgItem(this, NEWSFEED_MESSAGELIST, msgid, false)); + break; + default: break; + } } void NewsFeed::handlePostedEvent(std::shared_ptr event) { - const RsGxsPostedEvent *pe = dynamic_cast(event.get()); - if(!pe) - return; + const RsGxsPostedEvent *pe = + dynamic_cast(event.get()); + if(!pe) return; - switch(pe->mPostedEventCode) - { - case RsGxsPostedEvent::PostedEventCode::NEW_POSTED_GROUP: addFeedItem( new PostedGroupItem(this, NEWSFEED_POSTEDNEWLIST, pe->mPostedGroupId, false, true)); - break; - - case RsGxsPostedEvent::PostedEventCode::NEW_MESSAGE: addFeedItem( new PostedItem(this, NEWSFEED_POSTEDMSGLIST, pe->mPostedGroupId, pe->mPostedMsgId, false, true)); - break; - - default: - break; - } + switch(pe->mPostedEventCode) + { + case RsPostedEventCode::NEW_POSTED_GROUP: + addFeedItem( new PostedGroupItem(this, NEWSFEED_POSTEDNEWLIST, pe->mPostedGroupId, false, true)); + break; + case RsPostedEventCode::NEW_MESSAGE: + addFeedItem( new PostedItem(this, NEWSFEED_POSTEDMSGLIST, pe->mPostedGroupId, pe->mPostedMsgId, false, true)); + break; + default: break; + } } void NewsFeed::handleForumEvent(std::shared_ptr event) { - const RsGxsForumEvent *pe = dynamic_cast(event.get()); - if(!pe) - return; + const RsGxsForumEvent *pe = dynamic_cast(event.get()); + if(!pe) return; - switch(pe->mForumEventCode) - { - case RsGxsForumEvent::ForumEventCode::UPDATED_FORUM: - case RsGxsForumEvent::ForumEventCode::NEW_FORUM: addFeedItem(new GxsForumGroupItem(this, NEWSFEED_FORUMNEWLIST, pe->mForumGroupId, false, true)); - break; - - case RsGxsForumEvent::ForumEventCode::UPDATED_MESSAGE: - case RsGxsForumEvent::ForumEventCode::NEW_MESSAGE: addFeedItem(new GxsForumMsgItem(this, NEWSFEED_FORUMNEWLIST, pe->mForumGroupId, pe->mForumMsgId, false, true)); - break; - - default: - break; - } + switch(pe->mForumEventCode) + { + case RsForumEventCode::UPDATED_FORUM: + case RsForumEventCode::NEW_FORUM: + addFeedItem(new GxsForumGroupItem(this, NEWSFEED_FORUMNEWLIST, pe->mForumGroupId, false, true)); + break; + case RsForumEventCode::UPDATED_MESSAGE: + case RsForumEventCode::NEW_MESSAGE: + addFeedItem(new GxsForumMsgItem(this, NEWSFEED_FORUMNEWLIST, pe->mForumGroupId, pe->mForumMsgId, false, true)); + break; + default: break; + } } void NewsFeed::handleChannelEvent(std::shared_ptr event) { - const RsGxsChannelEvent *pe = dynamic_cast(event.get()); - if(!pe) - return; + const RsGxsChannelEvent* pe = + dynamic_cast(event.get()); + if(!pe) return; - switch(pe->mChannelEventCode) - { - case RsGxsChannelEvent::ChannelEventCode::UPDATED_CHANNEL: - case RsGxsChannelEvent::ChannelEventCode::NEW_CHANNEL: addFeedItem(new GxsChannelGroupItem(this, NEWSFEED_CHANNELNEWLIST, pe->mChannelGroupId, false, true)); - break; - - case RsGxsChannelEvent::ChannelEventCode::UPDATED_MESSAGE: - case RsGxsChannelEvent::ChannelEventCode::NEW_MESSAGE: addFeedItem(new GxsChannelPostItem(this, NEWSFEED_CHANNELNEWLIST, pe->mChannelGroupId, pe->mChannelMsgId, false, true)); - break; - - case RsGxsChannelEvent::ChannelEventCode::RECEIVED_PUBLISH_KEY: addFeedItem(new GxsChannelGroupItem(this, NEWSFEED_CHANNELPUBKEYLIST, pe->mChannelGroupId, false, true)); - break; - - default: - break; - } + switch(pe->mChannelEventCode) + { + case RsChannelEventCode::UPDATED_CHANNEL: // [[fallthrough]]; + case RsChannelEventCode::NEW_CHANNEL: + addFeedItem(new GxsChannelGroupItem(this, NEWSFEED_CHANNELNEWLIST, pe->mChannelGroupId, false, true)); + break; + case RsChannelEventCode::UPDATED_MESSAGE: // [[fallthrough]]; + case RsChannelEventCode::NEW_MESSAGE: + addFeedItem(new GxsChannelPostItem(this, NEWSFEED_CHANNELNEWLIST, pe->mChannelGroupId, pe->mChannelMsgId, false, true)); + break; + case RsChannelEventCode::RECEIVED_PUBLISH_KEY: + addFeedItem(new GxsChannelGroupItem(this, NEWSFEED_CHANNELPUBKEYLIST, pe->mChannelGroupId, false, true)); + break; + default: break; + } } void NewsFeed::handleCircleEvent(std::shared_ptr event) @@ -291,62 +286,62 @@ void NewsFeed::handleCircleEvent(std::shared_ptr event) // Check if the circle is one of which we belong to. If so, then notify in the GUI about other members leaving/subscribing - if(details.mAmIAllowed || details.mAmIAdmin) + if(details.mAmIAllowed || details.mAmIAdmin) { - switch(pe->mCircleEventType) - { - case RsGxsCircleEvent::CircleEventCode::CIRCLE_MEMBERSHIP_REQUEST: // only show membership requests if we're an admin of that circle - if(details.mAmIAdmin) - addFeedItemIfUnique(new GxsCircleItem(this, NEWSFEED_CIRCLELIST, pe->mCircleId, pe->mGxsId, RS_FEED_ITEM_CIRCLE_MEMB_REQ),true); - break; - - case RsGxsCircleEvent::CircleEventCode::CIRCLE_MEMBERSHIP_JOIN: - addFeedItemIfUnique(new GxsCircleItem(this, NEWSFEED_CIRCLELIST, pe->mCircleId, pe->mGxsId, RS_FEED_ITEM_CIRCLE_MEMB_JOIN),true); - break; - - case RsGxsCircleEvent::CircleEventCode::CIRCLE_MEMBERSHIP_LEAVE: - addFeedItemIfUnique(new GxsCircleItem(this, NEWSFEED_CIRCLELIST, pe->mCircleId, pe->mGxsId, RS_FEED_ITEM_CIRCLE_MEMB_LEAVE),true); - break; - - case RsGxsCircleEvent::CircleEventCode::CIRCLE_MEMBERSHIP_INVITE: - addFeedItemIfUnique(new GxsCircleItem(this, NEWSFEED_CIRCLELIST, pe->mCircleId, pe->mGxsId, RS_FEED_ITEM_CIRCLE_INVIT_REC),true); - break; - - case RsGxsCircleEvent::CircleEventCode::CIRCLE_MEMBERSHIP_REVOQUED: - addFeedItemIfUnique(new GxsCircleItem(this, NEWSFEED_CIRCLELIST, pe->mCircleId, pe->mGxsId, RS_FEED_ITEM_CIRCLE_MEMB_REVOQUED),true); - break; - - default: - break; - } + switch(pe->mCircleEventType) + { + case RsGxsCircleEventCode::CIRCLE_MEMBERSHIP_REQUEST: + // only show membership requests if we're an admin of that circle + if(details.mAmIAdmin) + addFeedItemIfUnique(new GxsCircleItem(this, NEWSFEED_CIRCLELIST, pe->mCircleId, pe->mGxsId, RS_FEED_ITEM_CIRCLE_MEMB_REQ),true); + break; + case RsGxsCircleEventCode::CIRCLE_MEMBERSHIP_JOIN: + addFeedItemIfUnique(new GxsCircleItem(this, NEWSFEED_CIRCLELIST, pe->mCircleId, pe->mGxsId, RS_FEED_ITEM_CIRCLE_MEMB_JOIN),true); + break; + case RsGxsCircleEventCode::CIRCLE_MEMBERSHIP_LEAVE: + addFeedItemIfUnique(new GxsCircleItem(this, NEWSFEED_CIRCLELIST, pe->mCircleId, pe->mGxsId, RS_FEED_ITEM_CIRCLE_MEMB_LEAVE),true); + break; + case RsGxsCircleEventCode::CIRCLE_MEMBERSHIP_INVITE: + addFeedItemIfUnique(new GxsCircleItem(this, NEWSFEED_CIRCLELIST, pe->mCircleId, pe->mGxsId, RS_FEED_ITEM_CIRCLE_INVIT_REC),true); + break; + case RsGxsCircleEventCode::CIRCLE_MEMBERSHIP_REVOQUED: + addFeedItemIfUnique(new GxsCircleItem(this, NEWSFEED_CIRCLELIST, pe->mCircleId, pe->mGxsId, RS_FEED_ITEM_CIRCLE_MEMB_REVOQUED),true); + break; + default: break; + } } } void NewsFeed::handleConnectionEvent(std::shared_ptr event) { - const RsConnectionEvent *pe = dynamic_cast(event.get()); - if(!pe) - return; + const RsConnectionEvent *pe = dynamic_cast(event.get()); + if(!pe) return; - auto& e(*pe); + auto& e(*pe); #ifdef NEWS_DEBUG std::cerr << "NotifyQt: handling connection event from peer " << e.mSslId << std::endl; #endif - switch(e.mConnectionInfoCode) - { - case RsConnectionEvent::ConnectionEventCode::PEER_CONNECTED: addFeedItemIfUnique(new PeerItem(this, NEWSFEED_PEERLIST, e.mSslId, PEER_TYPE_CONNECT, false), true); + switch(e.mConnectionInfoCode) + { + case RsConnectionEventCode::PEER_CONNECTED: + addFeedItemIfUnique(new PeerItem(this, NEWSFEED_PEERLIST, e.mSslId, PEER_TYPE_CONNECT, false), true); break; - case RsConnectionEvent::ConnectionEventCode::PEER_DISCONNECTED: // not handled yet - break; - case RsConnectionEvent::ConnectionEventCode::PEER_TIME_SHIFT:addFeedItemIfUnique(new PeerItem(this, NEWSFEED_PEERLIST, e.mSslId, PEER_TYPE_OFFSET, false),false); - break; - case RsConnectionEvent::ConnectionEventCode::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; - - default: break; - } + case RsConnectionEventCode::PEER_DISCONNECTED: // not handled yet + break; + case RsConnectionEventCode::PEER_TIME_SHIFT: + addFeedItemIfUnique(new PeerItem(this, NEWSFEED_PEERLIST, e.mSslId, PEER_TYPE_OFFSET, false),false); + break; + case RsConnectionEventCode::PEER_REPORTS_WRONG_IP: + addFeedItemIfUnique(new SecurityIpItem( + this, e.mSslId, e.mOwnLocator.toString(), + e.mReportedLocator.toString(), + RS_FEED_ITEM_SEC_IP_WRONG_EXTERNAL_IP_REPORTED, + false ), false); + break; + default: break; + } } void NewsFeed::handleSecurityEvent(std::shared_ptr event) @@ -362,27 +357,31 @@ void NewsFeed::handleSecurityEvent(std::shared_ptr event) #endif uint flags = Settings->getNewsFeedFlags(); - if(e.mErrorCode == RsAuthSslConnectionAutenticationEvent::AuthenticationCode::PEER_REFUSED_CONNECTION) - { + if(e.mErrorCode == RsAuthSslError::PEER_REFUSED_CONNECTION) + { addFeedItemIfUnique(new PeerItem(this, NEWSFEED_PEERLIST, e.mSslId, PEER_TYPE_HELLO, false), true ); - return; - } + return; + } uint32_t FeedItemType=0; switch(e.mErrorCode) { - case RsAuthSslConnectionAutenticationEvent::AuthenticationCode::NO_CERTIFICATE_SUPPLIED: - case RsAuthSslConnectionAutenticationEvent::AuthenticationCode::MISMATCHED_PGP_ID: // fallthrough - case RsAuthSslConnectionAutenticationEvent::AuthenticationCode::MISSING_AUTHENTICATION_INFO: FeedItemType = RS_FEED_ITEM_SEC_BAD_CERTIFICATE; break; - case RsAuthSslConnectionAutenticationEvent::AuthenticationCode::PGP_SIGNATURE_VALIDATION_FAILED: FeedItemType = RS_FEED_ITEM_SEC_WRONG_SIGNATURE; break; - case RsAuthSslConnectionAutenticationEvent::AuthenticationCode::NOT_A_FRIEND: FeedItemType = RS_FEED_ITEM_SEC_CONNECT_ATTEMPT; break; - case RsAuthSslConnectionAutenticationEvent::AuthenticationCode::IP_IS_BLACKLISTED: FeedItemType = RS_FEED_ITEM_SEC_IP_BLACKLISTED; break; - case RsAuthSslConnectionAutenticationEvent::AuthenticationCode::MISSING_CERTIFICATE: FeedItemType = RS_FEED_ITEM_SEC_MISSING_CERTIFICATE; break; - - default: - return; // display nothing - } + case RsAuthSslError::NO_CERTIFICATE_SUPPLIED: // fallthrough + case RsAuthSslError::MISMATCHED_PGP_ID: // fallthrough + case RsAuthSslError::MISSING_AUTHENTICATION_INFO: + FeedItemType = RS_FEED_ITEM_SEC_BAD_CERTIFICATE; break; + case RsAuthSslError::PGP_SIGNATURE_VALIDATION_FAILED: + FeedItemType = RS_FEED_ITEM_SEC_WRONG_SIGNATURE; break; + case RsAuthSslError::NOT_A_FRIEND: + FeedItemType = RS_FEED_ITEM_SEC_CONNECT_ATTEMPT; break; + case RsAuthSslError::IP_IS_BLACKLISTED: + FeedItemType = RS_FEED_ITEM_SEC_IP_BLACKLISTED; break; + case RsAuthSslError::MISSING_CERTIFICATE: + FeedItemType = RS_FEED_ITEM_SEC_MISSING_CERTIFICATE; break; + default: + return; // display nothing + } RsPeerDetails det; rsPeers->getPeerDetails(e.mSslId,det) || rsPeers->getGPGDetails(e.mPgpId,det); diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.cpp index 137f37f26..f346b3470 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.cpp @@ -66,7 +66,7 @@ void GxsChannelDialog::handleEvent_main_thread(std::shared_ptr ev switch(e->mChannelEventCode) { - case RsGxsChannelEvent::ChannelEventCode::SUBSCRIBE_STATUS_CHANGED: updateDisplay(true); + case RsChannelEventCode::SUBSCRIBE_STATUS_CHANGED: updateDisplay(true); break; default: break; diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp index 02abc3ba5..d463170af 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp @@ -146,10 +146,10 @@ void GxsChannelPostsWidget::handleEvent_main_thread(std::shared_ptrmChannelEventCode) { - case RsGxsChannelEvent::ChannelEventCode::UPDATED_CHANNEL: - case RsGxsChannelEvent::ChannelEventCode::NEW_CHANNEL: - case RsGxsChannelEvent::ChannelEventCode::UPDATED_MESSAGE: - case RsGxsChannelEvent::ChannelEventCode::NEW_MESSAGE: + case RsChannelEventCode::UPDATED_CHANNEL: + case RsChannelEventCode::NEW_CHANNEL: + case RsChannelEventCode::UPDATED_MESSAGE: + case RsChannelEventCode::NEW_MESSAGE: if(e->mChannelGroupId == mChannelGroupId) updateDisplay(true); break; diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp index 5b02a977e..f1306f79b 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp @@ -441,26 +441,23 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget void GxsForumThreadWidget::handleEvent_main_thread(std::shared_ptr event) { - if(event->mType == RsEventType::GXS_FORUMS) - { - const RsGxsForumEvent *e = dynamic_cast(event.get()); + if(event->mType == RsEventType::GXS_FORUMS) + { + const RsGxsForumEvent *e = dynamic_cast(event.get()); + if(!e) return; - if(!e) - return; - - switch(e->mForumEventCode) - { - case RsGxsForumEvent::ForumEventCode::UPDATED_FORUM: - case RsGxsForumEvent::ForumEventCode::NEW_FORUM: - case RsGxsForumEvent::ForumEventCode::UPDATED_MESSAGE: - case RsGxsForumEvent::ForumEventCode::NEW_MESSAGE: - if(e->mForumGroupId == mForumGroup.mMeta.mGroupId) + switch(e->mForumEventCode) + { + case RsForumEventCode::UPDATED_FORUM: // [[fallthrough]]; + case RsForumEventCode::NEW_FORUM: // [[fallthrough]]; + case RsForumEventCode::UPDATED_MESSAGE: // [[fallthrough]]; + case RsForumEventCode::NEW_MESSAGE: + if(e->mForumGroupId == mForumGroup.mMeta.mGroupId) updateDisplay(true); - break; - default: - break; - } - } + break; + default: break; + } + } } void GxsForumThreadWidget::blank() diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumsDialog.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumsDialog.cpp index 0e0a8447a..aa4177a72 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumsDialog.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumsDialog.cpp @@ -59,7 +59,7 @@ void GxsForumsDialog::handleEvent_main_thread(std::shared_ptr eve switch(e->mForumEventCode) { - case RsGxsForumEvent::ForumEventCode::SUBSCRIBE_STATUS_CHANGED: updateDisplay(true); + case RsForumEventCode::SUBSCRIBE_STATUS_CHANGED: updateDisplay(true); break; default: break;