From 37b5d8f307b65a17dc9817aa1c9777a4cb49f460 Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Tue, 7 Jan 2020 00:54:49 +0100 Subject: [PATCH] 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;