Fix few glitches in Cyril PR

This commit is contained in:
Gioacchino Mazzurco 2020-01-07 00:54:49 +01:00
parent c96223a2a8
commit 37b5d8f307
No known key found for this signature in database
GPG key ID: A1FBCA3872E87051
25 changed files with 430 additions and 424 deletions

View file

@ -1222,7 +1222,7 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx)
ev->mSslId = sslId; ev->mSslId = sslId;
ev->mPgpId = pgpId; ev->mPgpId = pgpId;
ev->mErrorMsg = errMsg; ev->mErrorMsg = errMsg;
ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::AuthenticationCode::MISSING_AUTHENTICATION_INFO; ev->mErrorCode = RsAuthSslError::MISSING_AUTHENTICATION_INFO;
rsEvents->postEvent(std::move(ev)); rsEvents->postEvent(std::move(ev));
} }
@ -1242,7 +1242,7 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx)
ev->mSslId = sslId; ev->mSslId = sslId;
ev->mSslCn = sslCn; ev->mSslCn = sslCn;
ev->mErrorMsg = errMsg; ev->mErrorMsg = errMsg;
ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::AuthenticationCode::MISSING_AUTHENTICATION_INFO; ev->mErrorCode = RsAuthSslError::MISSING_AUTHENTICATION_INFO;
rsEvents->postEvent(std::move(ev)); rsEvents->postEvent(std::move(ev));
} }
@ -1273,7 +1273,7 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx)
ev->mSslCn = sslCn; ev->mSslCn = sslCn;
ev->mPgpId = pgpId; ev->mPgpId = pgpId;
ev->mErrorMsg = errorMsg; ev->mErrorMsg = errorMsg;
ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::AuthenticationCode::MISMATCHED_PGP_ID; ev->mErrorCode = RsAuthSslError::MISMATCHED_PGP_ID;
rsEvents->postEvent(std::move(ev)); rsEvents->postEvent(std::move(ev));
} }
@ -1299,13 +1299,18 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx)
ev->mSslCn = sslCn; ev->mSslCn = sslCn;
ev->mPgpId = pgpId; ev->mPgpId = pgpId;
switch(auth_diagnostic) switch(auth_diagnostic)
{ {
case RS_SSL_HANDSHAKE_DIAGNOSTIC_ISSUER_UNKNOWN: ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::AuthenticationCode::NOT_A_FRIEND; break; case RS_SSL_HANDSHAKE_DIAGNOSTIC_ISSUER_UNKNOWN:
case RS_SSL_HANDSHAKE_DIAGNOSTIC_WRONG_SIGNATURE: ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::AuthenticationCode::PGP_SIGNATURE_VALIDATION_FAILED;break; ev->mErrorCode = RsAuthSslError::NOT_A_FRIEND;
break;
case RS_SSL_HANDSHAKE_DIAGNOSTIC_WRONG_SIGNATURE:
ev->mErrorCode = RsAuthSslError::PGP_SIGNATURE_VALIDATION_FAILED;
break;
default: default:
ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::AuthenticationCode::MISSING_AUTHENTICATION_INFO;break; ev->mErrorCode = RsAuthSslError::MISSING_AUTHENTICATION_INFO;
} break;
}
ev->mErrorMsg = errMsg; ev->mErrorMsg = errMsg;
rsEvents->postEvent(std::move(ev)); rsEvents->postEvent(std::move(ev));
@ -1331,7 +1336,7 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx)
ev->mSslCn = sslCn; ev->mSslCn = sslCn;
ev->mPgpId = pgpId; ev->mPgpId = pgpId;
ev->mErrorMsg = errMsg; ev->mErrorMsg = errMsg;
ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::AuthenticationCode::NOT_A_FRIEND; ev->mErrorCode = RsAuthSslError::NOT_A_FRIEND;
rsEvents->postEvent(std::move(ev)); rsEvents->postEvent(std::move(ev));
} }
@ -1595,32 +1600,6 @@ bool AuthSSLimpl::decrypt(void *&out, int &outlen, const void *in, int inlen)
return true; 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 */ /* Locked search -> internal help function */
bool AuthSSLimpl::locked_FindCert(const RsPeerId& id, X509** cert) bool AuthSSLimpl::locked_FindCert(const RsPeerId& id, X509** cert)
{ {

View file

@ -137,13 +137,6 @@ public:
/// SSL specific functions used in pqissl/pqissllistener /// SSL specific functions used in pqissl/pqissllistener
virtual SSL_CTX* getCTX() = 0; 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 * This function parse X509 certificate from the file and return some
* verified informations, like ID and signer * verified informations, like ID and signer
@ -230,14 +223,6 @@ public:
/* SSL specific functions used in pqissl/pqissllistener */ /* SSL specific functions used in pqissl/pqissllistener */
SSL_CTX* getCTX() override; 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: private:
bool LocalStoreCert(X509* x509); bool LocalStoreCert(X509* x509);

View file

@ -475,22 +475,18 @@ void p3LinkMgrIMPL::tickMonitors()
/* notify GUI */ /* notify GUI */
if (rsEvents && (peer.actions & RS_PEER_CONNECTED)) if (rsEvents && (peer.actions & RS_PEER_CONNECTED))
{ {
auto e = std::make_shared<RsConnectionEvent>() ; auto e = std::make_shared<RsConnectionEvent>();
e->mConnectionInfoCode = RsConnectionEventCode::PEER_CONNECTED;
e->mConnectionInfoCode = RsConnectionEvent::ConnectionEventCode::PEER_CONNECTED;
e->mSslId = peer.id; e->mSslId = peer.id;
rsEvents->postEvent(e); rsEvents->postEvent(e);
} }
if (rsEvents && (peer.actions & RS_PEER_DISCONNECTED)) if (rsEvents && (peer.actions & RS_PEER_DISCONNECTED))
{ {
auto e = std::make_shared<RsConnectionEvent>() ; auto e = std::make_shared<RsConnectionEvent>();
e->mConnectionInfoCode = RsConnectionEventCode::PEER_DISCONNECTED;
e->mConnectionInfoCode = RsConnectionEvent::ConnectionEventCode::PEER_DISCONNECTED;
e->mSslId = peer.id; e->mSslId = peer.id;
rsEvents->postEvent(e);
rsEvents->postEvent(e); }
}
} }
} }

View file

@ -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. // 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))) if((rsBanList && !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; {
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) if(rsEvents)
{ {
auto ev = std::make_shared<RsConnectionEvent>(); auto ev = std::make_shared<RsConnectionEvent>();
ev->mSslId = from; ev->mSslId = from;
ev->mStrInfo1 = sockaddr_storage_iptostring(addr); ev->mOwnLocator = RsUrl(own_addr);
ev->mStrInfo2 = sockaddr_storage_iptostring(own_addr); ev->mReportedLocator = RsUrl(addr);
ev->mConnectionInfoCode = RsConnectionEvent::ConnectionEventCode::PEER_REPORTS_WRONG_IP; ev->mConnectionInfoCode = RsConnectionEventCode::PEER_REPORTS_WRONG_IP;
rsEvents->postEvent(ev);
rsEvents->postEvent(ev); }
} }
}
// we could also sweep over all connected friends and see if some report a different address. // we could also sweep over all connected friends and see if some report a different address.

View file

@ -1107,16 +1107,14 @@ int pqissl::SSL_Connection_Complete()
return 0; return 0;
} }
if(rsEvents) if(rsEvents)
{ {
X509 *x509 = SSL_get_peer_certificate(ssl_connection);
auto ev = std::make_shared<RsAuthSslConnectionAutenticationEvent>(); auto ev = std::make_shared<RsAuthSslConnectionAutenticationEvent>();
X509 *x509 = SSL_get_peer_certificate(ssl_connection) ;
ev->mSslId = RsX509Cert::getCertSslId(*x509); ev->mSslId = RsX509Cert::getCertSslId(*x509);
ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::AuthenticationCode::PEER_REFUSED_CONNECTION; ev->mErrorCode = RsAuthSslError::PEER_REFUSED_CONNECTION;
rsEvents->postEvent(ev); rsEvents->postEvent(ev);
} }
std::string out; std::string out;
rs_sprintf(out, "pqissl::SSL_Connection_Complete()\nIssues with SSL Connect(%d)!\n", err); 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; << std::endl;
print_stacktrace(); print_stacktrace();
if(rsEvents) if(rsEvents)
{ {
X509 *x509 = SSL_get_peer_certificate(ssl);
auto ev = std::make_shared<RsAuthSslConnectionAutenticationEvent>(); auto ev = std::make_shared<RsAuthSslConnectionAutenticationEvent>();
X509 *x509 = SSL_get_peer_certificate(ssl) ;
ev->mSslId = RsX509Cert::getCertSslId(*x509); ev->mSslId = RsX509Cert::getCertSslId(*x509);
ev->mLocator = RsUrl(foreign_addr); ev->mLocator = RsUrl(foreign_addr);
ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::AuthenticationCode::IP_IS_BLACKLISTED; ev->mErrorCode = RsAuthSslError::IP_IS_BLACKLISTED;
rsEvents->postEvent(ev); rsEvents->postEvent(ev);
} }
reset_locked(); reset_locked();
return failure; return failure;

View file

@ -480,14 +480,12 @@ int pqissllistenbase::continueSSL(IncomingSSLInfo& incoming_connexion_info, bool
if(vres == X509_V_OK && nullptr != rsEvents) if(vres == X509_V_OK && nullptr != rsEvents)
{ {
auto ev = std::unique_ptr<RsAuthSslConnectionAutenticationEvent>(new RsAuthSslConnectionAutenticationEvent); auto ev = std::make_shared<RsAuthSslConnectionAutenticationEvent>();
ev->mLocator = RsUrl(incoming_connexion_info.addr); ev->mLocator = RsUrl(incoming_connexion_info.addr);
ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::AuthenticationCode::MISSING_AUTHENTICATION_INFO; ev->mErrorCode = RsAuthSslError::MISSING_AUTHENTICATION_INFO;
rsEvents->postEvent(ev);
rsEvents->postEvent(std::move(ev));
} }
closeConnection(fd, incoming_connexion_info.ssl) ; closeConnection(fd, incoming_connexion_info.ssl);
// failure -1, pending 0, sucess 1. // failure -1, pending 0, sucess 1.
return -1; return -1;

View file

@ -61,7 +61,7 @@ enum class RsEventType : uint32_t
/// @see pqissl /// @see pqissl
PEER_CONNECTION = 4, PEER_CONNECTION = 4,
/// @see RsGxsChanges // this one should probably be removed because it's not used anywhere /// @see RsGxsChanges
GXS_CHANGES = 5, GXS_CHANGES = 5,
/// Emitted when a peer state changes, @see RsPeers /// Emitted when a peer state changes, @see RsPeers

View file

@ -102,23 +102,36 @@ struct RsGxsChannelPost : RsSerializable
~RsGxsChannelPost() override; ~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 struct RsGxsChannelEvent: RsEvent
{ {
RsGxsChannelEvent() RsGxsChannelEvent():
: RsEvent(RsEventType::GXS_CHANNELS), mChannelEventCode(ChannelEventCode::UNKNOWN) {} RsEvent(RsEventType::GXS_CHANNELS),
mChannelEventCode(RsChannelEventCode::UNKNOWN) {}
enum class ChannelEventCode: uint8_t { RsChannelEventCode mChannelEventCode;
UNKNOWN = 0x00, RsGxsGroupId mChannelGroupId;
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;
RsGxsMessageId mChannelMsgId; RsGxsMessageId mChannelMsgId;
///* @see RsEvent @see RsSerializable ///* @see RsEvent @see RsSerializable

View file

@ -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 struct RsGxsCircleEvent: RsEvent
{ {
RsGxsCircleEvent() 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; RsGxsCircleEventCode mCircleEventType;
RsGxsCircleId mCircleId; RsGxsCircleId mCircleId;
RsGxsId mGxsId; RsGxsId mGxsId;
///* @see RsEvent @see RsSerializable ///* @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); RsEvent::serial_process(j, ctx);
RS_SERIAL_PROCESS(mCircleEventType); RS_SERIAL_PROCESS(mCircleEventType);
RS_SERIAL_PROCESS(mCircleId); RS_SERIAL_PROCESS(mCircleId);
RS_SERIAL_PROCESS(mGxsId); RS_SERIAL_PROCESS(mGxsId);
} }
~RsGxsCircleEvent() override;
}; };
class RsGxsCircles: public RsGxsIfaceHelper class RsGxsCircles: public RsGxsIfaceHelper

View file

@ -104,33 +104,45 @@ struct RsGxsForumMsg : RsSerializable
~RsGxsForumMsg() override; ~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 struct RsGxsForumEvent: RsEvent
{ {
RsGxsForumEvent() RsGxsForumEvent()
: RsEvent(RsEventType::GXS_FORUMS), mForumEventCode(ForumEventCode::UNKNOWN) {} : RsEvent(RsEventType::GXS_FORUMS),
mForumEventCode(RsForumEventCode::UNKNOWN) {}
enum class ForumEventCode: uint8_t { RsForumEventCode mForumEventCode;
UNKNOWN = 0x00, RsGxsGroupId mForumGroupId;
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;
RsGxsMessageId mForumMsgId; RsGxsMessageId mForumMsgId;
///* @see RsEvent @see RsSerializable ///* @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); RsEvent::serial_process(j, ctx);
RS_SERIAL_PROCESS(mForumEventCode); RS_SERIAL_PROCESS(mForumEventCode);
RS_SERIAL_PROCESS(mForumGroupId); RS_SERIAL_PROCESS(mForumGroupId);
RS_SERIAL_PROCESS(mForumMsgId); RS_SERIAL_PROCESS(mForumMsgId);
} }
~RsGxsForumEvent() override;
}; };
class RsGxsForums: public RsGxsIfaceHelper class RsGxsForums: public RsGxsIfaceHelper

View file

@ -296,19 +296,25 @@ struct MsgTagType : RsSerializable
} //namespace Rs } //namespace Rs
} //namespace Msgs } //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 struct RsMailStatusEvent : RsEvent
{ {
RsMailStatusEvent() : RsEvent(RsEventType::MAIL_STATUS_CHANGE) {} RsMailStatusEvent() : RsEvent(RsEventType::MAIL_STATUS_CHANGE) {}
enum MailStatusEventCode: uint8_t { RsMailStatusEventCode mMailStatusEventCode;
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<RsMailMessageId> mChangedMsgIds; std::set<RsMailMessageId> mChangedMsgIds;
/// @see RsEvent /// @see RsEvent

View file

@ -210,33 +210,35 @@ std::string RsPeerLastConnectString(uint32_t lastConnect);
// Connexion and security events // // 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 * Event triggered by AuthSSL when authentication of a connection attempt either
* fail or success * fail or success
*/ */
struct RsAuthSslConnectionAutenticationEvent : RsEvent struct RsAuthSslConnectionAutenticationEvent : RsEvent
{ {
RsAuthSslConnectionAutenticationEvent() : RsEvent(RsEventType::AUTHSSL_CONNECTION_AUTENTICATION) {} 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; RsPeerId mSslId;
std::string mSslCn; std::string mSslCn;
RsPgpId mPgpId; RsPgpId mPgpId;
RsUrl mLocator; RsUrl mLocator;
std::string mErrorMsg; std::string mErrorMsg;
AuthenticationCode mErrorCode; RsAuthSslError mErrorCode;
///* @see RsEvent @see RsSerializable ///* @see RsEvent @see RsSerializable
void serial_process( RsGenericSerializer::SerializeJob j, void serial_process( RsGenericSerializer::SerializeJob j,
@ -250,36 +252,49 @@ struct RsAuthSslConnectionAutenticationEvent : RsEvent
RS_SERIAL_PROCESS(mErrorMsg); RS_SERIAL_PROCESS(mErrorMsg);
RS_SERIAL_PROCESS(mErrorCode); 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 struct RsConnectionEvent : RsEvent
{ {
RsConnectionEvent() RsConnectionEvent()
: RsEvent(RsEventType::PEER_CONNECTION), : RsEvent(RsEventType::PEER_CONNECTION),
mConnectionInfoCode(ConnectionEventCode::UNKNOWN) {} mConnectionInfoCode(RsConnectionEventCode::UNKNOWN), mTimeShift(0) {}
enum class ConnectionEventCode: uint8_t { RsConnectionEventCode mConnectionInfoCode;
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; RsPeerId mSslId;
std::string mStrInfo1; RsUrl mOwnLocator;
std::string mStrInfo2; 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 ///* @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); RsEvent::serial_process(j, ctx);
RS_SERIAL_PROCESS(mConnectionInfoCode); RS_SERIAL_PROCESS(mConnectionInfoCode);
RS_SERIAL_PROCESS(mSslId); RS_SERIAL_PROCESS(mSslId);
RS_SERIAL_PROCESS(mStrInfo1); RS_SERIAL_PROCESS(mOwnLocator);
RS_SERIAL_PROCESS(mStrInfo2); RS_SERIAL_PROCESS(mReportedLocator);
RS_SERIAL_PROCESS(mTimeShift);
} }
~RsConnectionEvent() override;
}; };
//===================================================================================================// //===================================================================================================//

View file

@ -68,18 +68,21 @@ class RsPostedGroup
std::ostream &operator<<(std::ostream &out, const RsPostedGroup &group); std::ostream &operator<<(std::ostream &out, const RsPostedGroup &group);
std::ostream &operator<<(std::ostream &out, const RsPostedPost &post); 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 struct RsGxsPostedEvent: RsEvent
{ {
RsGxsPostedEvent() RsGxsPostedEvent():
: RsEvent(RsEventType::GXS_POSTED), mPostedEventCode(PostedEventCode::UNKNOWN) {} RsEvent(RsEventType::GXS_POSTED),
mPostedEventCode(RsPostedEventCode::UNKNOWN) {}
enum class PostedEventCode: uint8_t { RsPostedEventCode mPostedEventCode;
UNKNOWN = 0x00,
NEW_POSTED_GROUP = 0x01,
NEW_MESSAGE = 0x02
};
PostedEventCode mPostedEventCode;
RsGxsGroupId mPostedGroupId; RsGxsGroupId mPostedGroupId;
RsGxsMessageId mPostedMsgId; RsGxsMessageId mPostedMsgId;

View file

@ -1859,3 +1859,5 @@ RsPeerStateChangedEvent::RsPeerStateChangedEvent(RsPeerId sslId) :
RsEvent(RsEventType::PEER_STATE_CHANGED), mSslId(sslId) {} RsEvent(RsEventType::PEER_STATE_CHANGED), mSslId(sslId) {}
RsPeers::~RsPeers() = default; RsPeers::~RsPeers() = default;
RsAuthSslConnectionAutenticationEvent::~RsAuthSslConnectionAutenticationEvent() = default;
RsConnectionEvent::~RsConnectionEvent() = default;

View file

@ -257,12 +257,10 @@ void p3GxsChannels::notifyChanges(std::vector<RsGxsNotify *> &changes)
for (auto mit1 = mit->second.begin(); mit1 != mit->second.end(); ++mit1) for (auto mit1 = mit->second.begin(); mit1 != mit->second.end(); ++mit1)
{ {
auto ev = std::make_shared<RsGxsChannelEvent>(); auto ev = std::make_shared<RsGxsChannelEvent>();
ev->mChannelMsgId = *mit1; ev->mChannelMsgId = *mit1;
ev->mChannelGroupId = mit->first; ev->mChannelGroupId = mit->first;
ev->mChannelEventCode = RsGxsChannelEvent::ChannelEventCode::NEW_MESSAGE; ev->mChannelEventCode = RsChannelEventCode::NEW_MESSAGE;
rsEvents->postEvent(ev);
rsEvents->sendEvent(ev);
} }
} }
} }
@ -313,11 +311,9 @@ void p3GxsChannels::notifyChanges(std::vector<RsGxsNotify *> &changes)
for (git = grpList.begin(); git != grpList.end(); ++git) for (git = grpList.begin(); git != grpList.end(); ++git)
{ {
auto ev = std::make_shared<RsGxsChannelEvent>(); auto ev = std::make_shared<RsGxsChannelEvent>();
ev->mChannelGroupId = *git; ev->mChannelGroupId = *git;
ev->mChannelEventCode = RsGxsChannelEvent::ChannelEventCode::SUBSCRIBE_STATUS_CHANGED; ev->mChannelEventCode = RsChannelEventCode::SUBSCRIBE_STATUS_CHANGED;
rsEvents->postEvent(ev);
rsEvents->sendEvent(ev);
} }
} }
@ -338,11 +334,9 @@ void p3GxsChannels::notifyChanges(std::vector<RsGxsNotify *> &changes)
IndicateConfigChanged(); IndicateConfigChanged();
auto ev = std::make_shared<RsGxsChannelEvent>(); auto ev = std::make_shared<RsGxsChannelEvent>();
ev->mChannelGroupId = *git; ev->mChannelGroupId = *git;
ev->mChannelEventCode = RsGxsChannelEvent::ChannelEventCode::NEW_CHANNEL; ev->mChannelEventCode = RsChannelEventCode::NEW_CHANNEL;
rsEvents->postEvent(ev);
rsEvents->sendEvent(ev);
} }
else else
std::cerr << "(II) Not notifying already known channel " << *git << std::endl; std::cerr << "(II) Not notifying already known channel " << *git << std::endl;
@ -358,11 +352,9 @@ void p3GxsChannels::notifyChanges(std::vector<RsGxsNotify *> &changes)
for (git = grpList.begin(); git != grpList.end(); ++git) for (git = grpList.begin(); git != grpList.end(); ++git)
{ {
auto ev = std::make_shared<RsGxsChannelEvent>(); auto ev = std::make_shared<RsGxsChannelEvent>();
ev->mChannelGroupId = *git; ev->mChannelGroupId = *git;
ev->mChannelEventCode = RsGxsChannelEvent::ChannelEventCode::RECEIVED_PUBLISH_KEY; ev->mChannelEventCode = RsChannelEventCode::RECEIVED_PUBLISH_KEY;
rsEvents->postEvent(ev);
rsEvents->sendEvent(ev);
} }
break; break;
} }

View file

@ -504,23 +504,21 @@ void p3GxsCircles::notifyChanges(std::vector<RsGxsNotify *> &changes)
if(rsEvents && (c->getType() == RsGxsNotify::TYPE_RECEIVED_NEW) ) if(rsEvents && (c->getType() == RsGxsNotify::TYPE_RECEIVED_NEW) )
for (auto msgIdIt(mit->second.begin()), end(mit->second.end()); msgIdIt != end; ++msgIdIt) 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); getCircleRequest(RsGxsGroupId(circle_id),*msgIdIt,msg);
auto ev = std::make_shared<RsGxsCircleEvent>(); auto ev = std::make_shared<RsGxsCircleEvent>();
ev->mCircleId = circle_id; ev->mCircleId = circle_id;
ev->mGxsId = msg.mMeta.mAuthorId; ev->mGxsId = msg.mMeta.mAuthorId;
if (msg.stuff == "SUBSCRIPTION_REQUEST_UNSUBSCRIBE") 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()) 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 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; RsGxsCircleMsg::~RsGxsCircleMsg() = default;
RsGxsCircleDetails::~RsGxsCircleDetails() = default; RsGxsCircleDetails::~RsGxsCircleDetails() = default;
RsGxsCircleGroup::~RsGxsCircleGroup() = default; RsGxsCircleGroup::~RsGxsCircleGroup() = default;
RsGxsCircleEvent::~RsGxsCircleEvent() = default;

View file

@ -199,12 +199,10 @@ void p3GxsForums::notifyChanges(std::vector<RsGxsNotify *> &changes)
for (auto mit1 = mit->second.begin(); mit1 != mit->second.end(); ++mit1) for (auto mit1 = mit->second.begin(); mit1 != mit->second.end(); ++mit1)
{ {
auto ev = std::make_shared<RsGxsForumEvent>(); auto ev = std::make_shared<RsGxsForumEvent>();
ev->mForumMsgId = *mit1; ev->mForumMsgId = *mit1;
ev->mForumGroupId = mit->first; ev->mForumGroupId = mit->first;
ev->mForumEventCode = RsGxsForumEvent::ForumEventCode::NEW_MESSAGE; ev->mForumEventCode = RsForumEventCode::NEW_MESSAGE;
rsEvents->postEvent(ev);
rsEvents->sendEvent(ev);
} }
} }
@ -256,11 +254,9 @@ void p3GxsForums::notifyChanges(std::vector<RsGxsNotify *> &changes)
for (git = grpList.begin(); git != grpList.end(); ++git) for (git = grpList.begin(); git != grpList.end(); ++git)
{ {
auto ev = std::make_shared<RsGxsForumEvent>(); auto ev = std::make_shared<RsGxsForumEvent>();
ev->mForumGroupId = *git; ev->mForumGroupId = *git;
ev->mForumEventCode = RsGxsForumEvent::ForumEventCode::SUBSCRIBE_STATUS_CHANGED; ev->mForumEventCode = RsForumEventCode::SUBSCRIBE_STATUS_CHANGED;
rsEvents->postEvent(ev);
rsEvents->sendEvent(ev);
} }
} }
@ -278,18 +274,19 @@ void p3GxsForums::notifyChanges(std::vector<RsGxsNotify *> &changes)
{ {
if(mKnownForums.find(*git) == mKnownForums.end()) if(mKnownForums.find(*git) == mKnownForums.end())
{ {
mKnownForums.insert(std::make_pair(*git,time(NULL))) ; mKnownForums.insert(
std::make_pair(*git, time(nullptr)));
IndicateConfigChanged(); IndicateConfigChanged();
auto ev = std::make_shared<RsGxsForumEvent>(); auto ev = std::make_shared<RsGxsForumEvent>();
ev->mForumGroupId = *git; ev->mForumGroupId = *git;
ev->mForumEventCode = RsGxsForumEvent::ForumEventCode::NEW_FORUM; ev->mForumEventCode = RsForumEventCode::NEW_FORUM;
rsEvents->postEvent(ev);
rsEvents->sendEvent(ev);
} }
else else
std::cerr << "(II) Not notifying already known channel " << *git << std::endl; RsInfo() << __PRETTY_FUNCTION__
<< " Not notifying already known forum "
<< *git << std::endl;
} }
break; break;
} }
@ -1148,3 +1145,4 @@ bool RsGxsForumGroup::canEditPosts(const RsGxsId& id) const
RsGxsForumGroup::~RsGxsForumGroup() = default; RsGxsForumGroup::~RsGxsForumGroup() = default;
RsGxsForumMsg::~RsGxsForumMsg() = default; RsGxsForumMsg::~RsGxsForumMsg() = default;
RsGxsForums::~RsGxsForums() = default; RsGxsForums::~RsGxsForums() = default;
RsGxsForumEvent::~RsGxsForumEvent() = default;

View file

@ -177,12 +177,11 @@ void p3MsgService::processIncomingMsg(RsMsgItem *mi)
if (rsEvents) if (rsEvents)
{ {
auto ev = std::make_shared<RsMailStatusEvent>(); auto ev = std::make_shared<RsMailStatusEvent>();
ev->mMailStatusEventCode = RsMailStatusEvent::NEW_MESSAGE; ev->mMailStatusEventCode = RsMailStatusEventCode::NEW_MESSAGE;
ev->mChangedMsgIds.insert(std::to_string(mi->msgId)); ev->mChangedMsgIds.insert(std::to_string(mi->msgId));
rsEvents->postEvent(ev);
rsEvents->sendEvent(ev); }
}
imsg[mi->msgId] = mi; imsg[mi->msgId] = mi;
RsMsgSrcId* msi = new RsMsgSrcId(); RsMsgSrcId* msi = new RsMsgSrcId();
@ -337,8 +336,8 @@ int p3MsgService::checkOutgoingMessages()
bool changed = false; bool changed = false;
std::list<RsMsgItem*> output_queue; std::list<RsMsgItem*> output_queue;
auto pEvent = std::make_shared<RsMailStatusEvent>(); auto pEvent = std::make_shared<RsMailStatusEvent>();
pEvent->mMailStatusEventCode = RsMailStatusEvent::MESSAGE_SENT; pEvent->mMailStatusEventCode = RsMailStatusEventCode::MESSAGE_SENT;
{ {
RS_STACK_MUTEX(mMsgMtx); /********** STACK LOCKED MTX ******/ RS_STACK_MUTEX(mMsgMtx); /********** STACK LOCKED MTX ******/
@ -898,9 +897,8 @@ bool p3MsgService::removeMsgId(const std::string &mid)
bool changed = false; bool changed = false;
auto pEvent = std::make_shared<RsMailStatusEvent>(); auto pEvent = std::make_shared<RsMailStatusEvent>();
pEvent->mMailStatusEventCode = RsMailStatusEventCode::MESSAGE_REMOVED;
pEvent->mMailStatusEventCode = RsMailStatusEvent::MESSAGE_REMOVED;
{ {
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/ RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
@ -1268,8 +1266,8 @@ uint32_t p3MsgService::sendMail(
uint32_t ret = 0; uint32_t ret = 0;
auto pEvent = std::make_shared<RsMailStatusEvent>(); auto pEvent = std::make_shared<RsMailStatusEvent>();
pEvent->mMailStatusEventCode = RsMailStatusEvent::MESSAGE_SENT; pEvent->mMailStatusEventCode = RsMailStatusEventCode::MESSAGE_SENT;
auto pSend = [&](const std::set<RsGxsId>& sDest) auto pSend = [&](const std::set<RsGxsId>& sDest)
{ {
@ -2083,12 +2081,13 @@ void p3MsgService::notifyDataStatus( const GRouterMsgPropagationId& id,
NOTIFY_TYPE_ADD ); NOTIFY_TYPE_ADD );
IndicateConfigChanged(); IndicateConfigChanged();
auto pEvent = std::make_shared<RsMailStatusEvent>(); if(rsEvents)
{
pEvent->mMailStatusEventCode = RsMailStatusEvent::NEW_MESSAGE; auto pEvent = std::make_shared<RsMailStatusEvent>();
pEvent->mChangedMsgIds.insert(std::to_string(msg_id)); pEvent->mMailStatusEventCode = RsMailStatusEventCode::NEW_MESSAGE;
pEvent->mChangedMsgIds.insert(std::to_string(msg_id));
if(rsEvents) rsEvents->postEvent(pEvent); rsEvents->postEvent(pEvent);
}
return; return;
} }
@ -2185,11 +2184,11 @@ bool p3MsgService::notifyGxsTransSendStatus( RsGxsTransId mailId,
Dbg2() << __PRETTY_FUNCTION__ << " " << mailId << ", " Dbg2() << __PRETTY_FUNCTION__ << " " << mailId << ", "
<< static_cast<uint32_t>(status) << std::endl; << static_cast<uint32_t>(status) << std::endl;
auto pEvent = std::make_shared<RsMailStatusEvent>(); auto pEvent = std::make_shared<RsMailStatusEvent>();
if( status == GxsTransSendStatus::RECEIPT_RECEIVED ) if( status == GxsTransSendStatus::RECEIPT_RECEIVED )
{ {
pEvent->mMailStatusEventCode = RsMailStatusEvent::NEW_MESSAGE; pEvent->mMailStatusEventCode = RsMailStatusEventCode::NEW_MESSAGE;
uint32_t msg_id; uint32_t msg_id;
{ {
@ -2244,20 +2243,20 @@ bool p3MsgService::notifyGxsTransSendStatus( RsGxsTransId mailId,
else if( status >= GxsTransSendStatus::FAILED_RECEIPT_SIGNATURE ) else if( status >= GxsTransSendStatus::FAILED_RECEIPT_SIGNATURE )
{ {
uint32_t msg_id; uint32_t msg_id;
pEvent->mMailStatusEventCode = RsMailStatusEvent::FAILED_SIGNATURE; pEvent->mMailStatusEventCode = RsMailStatusEventCode::SIGNATURE_FAILED;
{ {
RS_STACK_MUTEX(gxsOngoingMutex); RS_STACK_MUTEX(gxsOngoingMutex);
RsErr() << __PRETTY_FUNCTION__ << " mail delivery "
std::cerr << __PRETTY_FUNCTION__ << " mail delivery " << "mailId: " << mailId
<< "mailId: " << mailId << " failed with " << static_cast<uint32_t>(status);
<< " failed with " << static_cast<uint32_t>(status);
auto it = gxsOngoingMessages.find(mailId); auto it = gxsOngoingMessages.find(mailId);
if(it == gxsOngoingMessages.end()) if(it == gxsOngoingMessages.end())
{ {
std::cerr << " cannot find pending message to notify" RsErr() << __PRETTY_FUNCTION__
<< std::endl; << " cannot find pending message to notify"
<< std::endl;
return false; return false;
} }

View file

@ -115,13 +115,11 @@ void p3PostBase::notifyChanges(std::vector<RsGxsNotify *> &changes)
if (rsEvents && 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) for (auto mit1 = mit->second.begin(); mit1 != mit->second.end(); ++mit1)
{ {
auto ev = std::make_shared<RsGxsPostedEvent>(); auto ev = std::make_shared<RsGxsPostedEvent>();
ev->mPostedMsgId = *mit1;
ev->mPostedMsgId = *mit1; ev->mPostedGroupId = mit->first;
ev->mPostedGroupId = mit->first; ev->mPostedEventCode = RsPostedEventCode::NEW_MESSAGE;
ev->mPostedEventCode = RsGxsPostedEvent::PostedEventCode::NEW_MESSAGE; rsEvents->postEvent(ev);
rsEvents->sendEvent(ev);
} }
} }
} }
@ -146,11 +144,9 @@ void p3PostBase::notifyChanges(std::vector<RsGxsNotify *> &changes)
if (rsEvents && groupChange->getType() == RsGxsNotify::TYPE_RECEIVED_NEW) if (rsEvents && groupChange->getType() == RsGxsNotify::TYPE_RECEIVED_NEW)
{ {
auto ev = std::make_shared<RsGxsPostedEvent>(); auto ev = std::make_shared<RsGxsPostedEvent>();
ev->mPostedGroupId = *git; ev->mPostedGroupId = *git;
ev->mPostedEventCode = RsGxsPostedEvent::PostedEventCode::NEW_POSTED_GROUP; ev->mPostedEventCode = RsPostedEventCode::NEW_POSTED_GROUP;
rsEvents->postEvent(ev);
rsEvents->sendEvent(ev);
} }
} }
} }

View file

@ -20,6 +20,8 @@
* * * *
*******************************************************************************/ *******************************************************************************/
#include <iomanip> #include <iomanip>
#include <sys/time.h>
#include <cmath>
#include "util/rsdir.h" #include "util/rsdir.h"
#include "retroshare/rsiface.h" #include "retroshare/rsiface.h"
@ -28,12 +30,10 @@
#include "pqi/pqistore.h" #include "pqi/pqistore.h"
#include "pqi/p3linkmgr.h" #include "pqi/p3linkmgr.h"
#include "rsserver/p3face.h" #include "rsserver/p3face.h"
#include "util/cxx17retrocompat.h"
#include "services/p3rtt.h" #include "services/p3rtt.h"
#include "rsitems/rsrttitems.h" #include "rsitems/rsrttitems.h"
#include <sys/time.h>
#include <math.h>
/**** /****
* #define DEBUG_RTT 1 * #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) while(peerInfo->mPongResults.size() > MAX_PONG_RESULTS)
{
peerInfo->mPongResults.pop_front(); peerInfo->mPongResults.pop_front();
}
//Wait at least 20 pongs before compute mean time offset //Wait at least 20 pongs before compute mean time offset
if(peerInfo->mPongResults.size() > 20) if(peerInfo->mPongResults.size() > 20)
{ {
double mean = 0; double mean = 0;
for(std::list<RsRttPongResult>::const_iterator prIt = peerInfo->mPongResults.begin(), end = peerInfo->mPongResults.end(); prIt != end; ++ prIt) for(auto prIt : std::as_const(peerInfo->mPongResults))
{ mean += prIt.mOffset;
mean += prIt->mOffset;
}
peerInfo->mCurrentMeanOffset = mean / peerInfo->mPongResults.size(); peerInfo->mCurrentMeanOffset = mean / peerInfo->mPongResults.size();
if(fabs(peerInfo->mCurrentMeanOffset) > 120) if(fabs(peerInfo->mCurrentMeanOffset) > 120)
{ {
if(rsEvents) if(rsEvents)
{ {
auto ev = std::make_shared<RsConnectionEvent>(); auto ev = std::make_shared<RsConnectionEvent>();
ev->mSslId = peerInfo->mId; ev->mSslId = peerInfo->mId;
ev->mStrInfo1 = RsUtil::NumberToString(peerInfo->mCurrentMeanOffset,false); ev->mTimeShift = static_cast<rstime_t>(peerInfo->mCurrentMeanOffset);
ev->mConnectionInfoCode = RsConnectionEvent::ConnectionEventCode::PEER_TIME_SHIFT; ev->mConnectionInfoCode = RsConnectionEventCode::PEER_TIME_SHIFT;
rsEvents->postEvent(ev); 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; return 1;

View file

@ -196,83 +196,78 @@ void NewsFeed::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)
void NewsFeed::handleMailEvent(std::shared_ptr<const RsEvent> event) void NewsFeed::handleMailEvent(std::shared_ptr<const RsEvent> event)
{ {
const RsMailStatusEvent *pe = dynamic_cast<const RsMailStatusEvent*>(event.get()); const RsMailStatusEvent *pe =
if(!pe) dynamic_cast<const RsMailStatusEvent*>(event.get());
return; if(!pe) return;
switch(pe->mMailStatusEventCode) switch(pe->mMailStatusEventCode)
{ {
case RsMailStatusEvent::NEW_MESSAGE: case RsMailStatusEventCode::NEW_MESSAGE:
for(auto msgid: pe->mChangedMsgIds) for(auto msgid: pe->mChangedMsgIds)
addFeedItem( new MsgItem(this, NEWSFEED_MESSAGELIST, msgid, false)); addFeedItem( new MsgItem(this, NEWSFEED_MESSAGELIST, msgid, false));
break; break;
default: default: break;
break; }
}
} }
void NewsFeed::handlePostedEvent(std::shared_ptr<const RsEvent> event) void NewsFeed::handlePostedEvent(std::shared_ptr<const RsEvent> event)
{ {
const RsGxsPostedEvent *pe = dynamic_cast<const RsGxsPostedEvent*>(event.get()); const RsGxsPostedEvent *pe =
if(!pe) dynamic_cast<const RsGxsPostedEvent*>(event.get());
return; if(!pe) return;
switch(pe->mPostedEventCode) switch(pe->mPostedEventCode)
{ {
case RsGxsPostedEvent::PostedEventCode::NEW_POSTED_GROUP: addFeedItem( new PostedGroupItem(this, NEWSFEED_POSTEDNEWLIST, pe->mPostedGroupId, false, true)); case RsPostedEventCode::NEW_POSTED_GROUP:
break; 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)); case RsPostedEventCode::NEW_MESSAGE:
break; addFeedItem( new PostedItem(this, NEWSFEED_POSTEDMSGLIST, pe->mPostedGroupId, pe->mPostedMsgId, false, true));
break;
default: default: break;
break; }
}
} }
void NewsFeed::handleForumEvent(std::shared_ptr<const RsEvent> event) void NewsFeed::handleForumEvent(std::shared_ptr<const RsEvent> event)
{ {
const RsGxsForumEvent *pe = dynamic_cast<const RsGxsForumEvent*>(event.get()); const RsGxsForumEvent *pe = dynamic_cast<const RsGxsForumEvent*>(event.get());
if(!pe) if(!pe) return;
return;
switch(pe->mForumEventCode) switch(pe->mForumEventCode)
{ {
case RsGxsForumEvent::ForumEventCode::UPDATED_FORUM: case RsForumEventCode::UPDATED_FORUM:
case RsGxsForumEvent::ForumEventCode::NEW_FORUM: addFeedItem(new GxsForumGroupItem(this, NEWSFEED_FORUMNEWLIST, pe->mForumGroupId, false, true)); case RsForumEventCode::NEW_FORUM:
break; addFeedItem(new GxsForumGroupItem(this, NEWSFEED_FORUMNEWLIST, pe->mForumGroupId, false, true));
break;
case RsGxsForumEvent::ForumEventCode::UPDATED_MESSAGE: case RsForumEventCode::UPDATED_MESSAGE:
case RsGxsForumEvent::ForumEventCode::NEW_MESSAGE: addFeedItem(new GxsForumMsgItem(this, NEWSFEED_FORUMNEWLIST, pe->mForumGroupId, pe->mForumMsgId, false, true)); case RsForumEventCode::NEW_MESSAGE:
break; addFeedItem(new GxsForumMsgItem(this, NEWSFEED_FORUMNEWLIST, pe->mForumGroupId, pe->mForumMsgId, false, true));
break;
default: default: break;
break; }
}
} }
void NewsFeed::handleChannelEvent(std::shared_ptr<const RsEvent> event) void NewsFeed::handleChannelEvent(std::shared_ptr<const RsEvent> event)
{ {
const RsGxsChannelEvent *pe = dynamic_cast<const RsGxsChannelEvent*>(event.get()); const RsGxsChannelEvent* pe =
if(!pe) dynamic_cast<const RsGxsChannelEvent*>(event.get());
return; if(!pe) return;
switch(pe->mChannelEventCode) switch(pe->mChannelEventCode)
{ {
case RsGxsChannelEvent::ChannelEventCode::UPDATED_CHANNEL: case RsChannelEventCode::UPDATED_CHANNEL: // [[fallthrough]];
case RsGxsChannelEvent::ChannelEventCode::NEW_CHANNEL: addFeedItem(new GxsChannelGroupItem(this, NEWSFEED_CHANNELNEWLIST, pe->mChannelGroupId, false, true)); case RsChannelEventCode::NEW_CHANNEL:
break; addFeedItem(new GxsChannelGroupItem(this, NEWSFEED_CHANNELNEWLIST, pe->mChannelGroupId, false, true));
break;
case RsGxsChannelEvent::ChannelEventCode::UPDATED_MESSAGE: case RsChannelEventCode::UPDATED_MESSAGE: // [[fallthrough]];
case RsGxsChannelEvent::ChannelEventCode::NEW_MESSAGE: addFeedItem(new GxsChannelPostItem(this, NEWSFEED_CHANNELNEWLIST, pe->mChannelGroupId, pe->mChannelMsgId, false, true)); case RsChannelEventCode::NEW_MESSAGE:
break; 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)); case RsChannelEventCode::RECEIVED_PUBLISH_KEY:
break; addFeedItem(new GxsChannelGroupItem(this, NEWSFEED_CHANNELPUBKEYLIST, pe->mChannelGroupId, false, true));
break;
default: default: break;
break; }
}
} }
void NewsFeed::handleCircleEvent(std::shared_ptr<const RsEvent> event) void NewsFeed::handleCircleEvent(std::shared_ptr<const RsEvent> event)
@ -291,62 +286,62 @@ void NewsFeed::handleCircleEvent(std::shared_ptr<const RsEvent> event)
// Check if the circle is one of which we belong to. If so, then notify in the GUI about other members leaving/subscribing // 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) switch(pe->mCircleEventType)
{ {
case RsGxsCircleEvent::CircleEventCode::CIRCLE_MEMBERSHIP_REQUEST: // only show membership requests if we're an admin of that circle case RsGxsCircleEventCode::CIRCLE_MEMBERSHIP_REQUEST:
if(details.mAmIAdmin) // only show membership requests if we're an admin of that circle
addFeedItemIfUnique(new GxsCircleItem(this, NEWSFEED_CIRCLELIST, pe->mCircleId, pe->mGxsId, RS_FEED_ITEM_CIRCLE_MEMB_REQ),true); if(details.mAmIAdmin)
break; addFeedItemIfUnique(new GxsCircleItem(this, NEWSFEED_CIRCLELIST, pe->mCircleId, pe->mGxsId, RS_FEED_ITEM_CIRCLE_MEMB_REQ),true);
break;
case RsGxsCircleEvent::CircleEventCode::CIRCLE_MEMBERSHIP_JOIN: case RsGxsCircleEventCode::CIRCLE_MEMBERSHIP_JOIN:
addFeedItemIfUnique(new GxsCircleItem(this, NEWSFEED_CIRCLELIST, pe->mCircleId, pe->mGxsId, RS_FEED_ITEM_CIRCLE_MEMB_JOIN),true); addFeedItemIfUnique(new GxsCircleItem(this, NEWSFEED_CIRCLELIST, pe->mCircleId, pe->mGxsId, RS_FEED_ITEM_CIRCLE_MEMB_JOIN),true);
break; break;
case RsGxsCircleEventCode::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);
addFeedItemIfUnique(new GxsCircleItem(this, NEWSFEED_CIRCLELIST, pe->mCircleId, pe->mGxsId, RS_FEED_ITEM_CIRCLE_MEMB_LEAVE),true); break;
break; case RsGxsCircleEventCode::CIRCLE_MEMBERSHIP_INVITE:
addFeedItemIfUnique(new GxsCircleItem(this, NEWSFEED_CIRCLELIST, pe->mCircleId, pe->mGxsId, RS_FEED_ITEM_CIRCLE_INVIT_REC),true);
case RsGxsCircleEvent::CircleEventCode::CIRCLE_MEMBERSHIP_INVITE: break;
addFeedItemIfUnique(new GxsCircleItem(this, NEWSFEED_CIRCLELIST, pe->mCircleId, pe->mGxsId, RS_FEED_ITEM_CIRCLE_INVIT_REC),true); case RsGxsCircleEventCode::CIRCLE_MEMBERSHIP_REVOQUED:
break; addFeedItemIfUnique(new GxsCircleItem(this, NEWSFEED_CIRCLELIST, pe->mCircleId, pe->mGxsId, RS_FEED_ITEM_CIRCLE_MEMB_REVOQUED),true);
break;
case RsGxsCircleEvent::CircleEventCode::CIRCLE_MEMBERSHIP_REVOQUED: default: break;
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<const RsEvent> event) void NewsFeed::handleConnectionEvent(std::shared_ptr<const RsEvent> event)
{ {
const RsConnectionEvent *pe = dynamic_cast<const RsConnectionEvent*>(event.get()); const RsConnectionEvent *pe = dynamic_cast<const RsConnectionEvent*>(event.get());
if(!pe) if(!pe) return;
return;
auto& e(*pe); auto& e(*pe);
#ifdef NEWS_DEBUG #ifdef NEWS_DEBUG
std::cerr << "NotifyQt: handling connection event from peer " << e.mSslId << std::endl; std::cerr << "NotifyQt: handling connection event from peer " << e.mSslId << std::endl;
#endif #endif
switch(e.mConnectionInfoCode) switch(e.mConnectionInfoCode)
{ {
case RsConnectionEvent::ConnectionEventCode::PEER_CONNECTED: addFeedItemIfUnique(new PeerItem(this, NEWSFEED_PEERLIST, e.mSslId, PEER_TYPE_CONNECT, false), true); case RsConnectionEventCode::PEER_CONNECTED:
addFeedItemIfUnique(new PeerItem(this, NEWSFEED_PEERLIST, e.mSslId, PEER_TYPE_CONNECT, false), true);
break; break;
case RsConnectionEvent::ConnectionEventCode::PEER_DISCONNECTED: // not handled yet case RsConnectionEventCode::PEER_DISCONNECTED: // not handled yet
break; break;
case RsConnectionEvent::ConnectionEventCode::PEER_TIME_SHIFT:addFeedItemIfUnique(new PeerItem(this, NEWSFEED_PEERLIST, e.mSslId, PEER_TYPE_OFFSET, false),false); case RsConnectionEventCode::PEER_TIME_SHIFT:
break; addFeedItemIfUnique(new PeerItem(this, NEWSFEED_PEERLIST, e.mSslId, PEER_TYPE_OFFSET, 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;
break; case RsConnectionEventCode::PEER_REPORTS_WRONG_IP:
addFeedItemIfUnique(new SecurityIpItem(
default: break; 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<const RsEvent> event) void NewsFeed::handleSecurityEvent(std::shared_ptr<const RsEvent> event)
@ -362,27 +357,31 @@ void NewsFeed::handleSecurityEvent(std::shared_ptr<const RsEvent> event)
#endif #endif
uint flags = Settings->getNewsFeedFlags(); 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 ); addFeedItemIfUnique(new PeerItem(this, NEWSFEED_PEERLIST, e.mSslId, PEER_TYPE_HELLO, false), true );
return; return;
} }
uint32_t FeedItemType=0; uint32_t FeedItemType=0;
switch(e.mErrorCode) switch(e.mErrorCode)
{ {
case RsAuthSslConnectionAutenticationEvent::AuthenticationCode::NO_CERTIFICATE_SUPPLIED: case RsAuthSslError::NO_CERTIFICATE_SUPPLIED: // fallthrough
case RsAuthSslConnectionAutenticationEvent::AuthenticationCode::MISMATCHED_PGP_ID: // fallthrough case RsAuthSslError::MISMATCHED_PGP_ID: // fallthrough
case RsAuthSslConnectionAutenticationEvent::AuthenticationCode::MISSING_AUTHENTICATION_INFO: FeedItemType = RS_FEED_ITEM_SEC_BAD_CERTIFICATE; break; case RsAuthSslError::MISSING_AUTHENTICATION_INFO:
case RsAuthSslConnectionAutenticationEvent::AuthenticationCode::PGP_SIGNATURE_VALIDATION_FAILED: FeedItemType = RS_FEED_ITEM_SEC_WRONG_SIGNATURE; break; FeedItemType = RS_FEED_ITEM_SEC_BAD_CERTIFICATE; break;
case RsAuthSslConnectionAutenticationEvent::AuthenticationCode::NOT_A_FRIEND: FeedItemType = RS_FEED_ITEM_SEC_CONNECT_ATTEMPT; break; case RsAuthSslError::PGP_SIGNATURE_VALIDATION_FAILED:
case RsAuthSslConnectionAutenticationEvent::AuthenticationCode::IP_IS_BLACKLISTED: FeedItemType = RS_FEED_ITEM_SEC_IP_BLACKLISTED; break; FeedItemType = RS_FEED_ITEM_SEC_WRONG_SIGNATURE; break;
case RsAuthSslConnectionAutenticationEvent::AuthenticationCode::MISSING_CERTIFICATE: FeedItemType = RS_FEED_ITEM_SEC_MISSING_CERTIFICATE; break; case RsAuthSslError::NOT_A_FRIEND:
FeedItemType = RS_FEED_ITEM_SEC_CONNECT_ATTEMPT; break;
default: case RsAuthSslError::IP_IS_BLACKLISTED:
return; // display nothing 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; RsPeerDetails det;
rsPeers->getPeerDetails(e.mSslId,det) || rsPeers->getGPGDetails(e.mPgpId,det); rsPeers->getPeerDetails(e.mSslId,det) || rsPeers->getGPGDetails(e.mPgpId,det);

View file

@ -66,7 +66,7 @@ void GxsChannelDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent> ev
switch(e->mChannelEventCode) switch(e->mChannelEventCode)
{ {
case RsGxsChannelEvent::ChannelEventCode::SUBSCRIBE_STATUS_CHANGED: updateDisplay(true); case RsChannelEventCode::SUBSCRIBE_STATUS_CHANGED: updateDisplay(true);
break; break;
default: default:
break; break;

View file

@ -146,10 +146,10 @@ void GxsChannelPostsWidget::handleEvent_main_thread(std::shared_ptr<const RsEven
switch(e->mChannelEventCode) switch(e->mChannelEventCode)
{ {
case RsGxsChannelEvent::ChannelEventCode::UPDATED_CHANNEL: case RsChannelEventCode::UPDATED_CHANNEL:
case RsGxsChannelEvent::ChannelEventCode::NEW_CHANNEL: case RsChannelEventCode::NEW_CHANNEL:
case RsGxsChannelEvent::ChannelEventCode::UPDATED_MESSAGE: case RsChannelEventCode::UPDATED_MESSAGE:
case RsGxsChannelEvent::ChannelEventCode::NEW_MESSAGE: case RsChannelEventCode::NEW_MESSAGE:
if(e->mChannelGroupId == mChannelGroupId) if(e->mChannelGroupId == mChannelGroupId)
updateDisplay(true); updateDisplay(true);
break; break;

View file

@ -441,26 +441,23 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget
void GxsForumThreadWidget::handleEvent_main_thread(std::shared_ptr<const RsEvent> event) void GxsForumThreadWidget::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)
{ {
if(event->mType == RsEventType::GXS_FORUMS) if(event->mType == RsEventType::GXS_FORUMS)
{ {
const RsGxsForumEvent *e = dynamic_cast<const RsGxsForumEvent*>(event.get()); const RsGxsForumEvent *e = dynamic_cast<const RsGxsForumEvent*>(event.get());
if(!e) return;
if(!e) switch(e->mForumEventCode)
return; {
case RsForumEventCode::UPDATED_FORUM: // [[fallthrough]];
switch(e->mForumEventCode) case RsForumEventCode::NEW_FORUM: // [[fallthrough]];
{ case RsForumEventCode::UPDATED_MESSAGE: // [[fallthrough]];
case RsGxsForumEvent::ForumEventCode::UPDATED_FORUM: case RsForumEventCode::NEW_MESSAGE:
case RsGxsForumEvent::ForumEventCode::NEW_FORUM: if(e->mForumGroupId == mForumGroup.mMeta.mGroupId)
case RsGxsForumEvent::ForumEventCode::UPDATED_MESSAGE:
case RsGxsForumEvent::ForumEventCode::NEW_MESSAGE:
if(e->mForumGroupId == mForumGroup.mMeta.mGroupId)
updateDisplay(true); updateDisplay(true);
break; break;
default: default: break;
break; }
} }
}
} }
void GxsForumThreadWidget::blank() void GxsForumThreadWidget::blank()

View file

@ -59,7 +59,7 @@ void GxsForumsDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent> eve
switch(e->mForumEventCode) switch(e->mForumEventCode)
{ {
case RsGxsForumEvent::ForumEventCode::SUBSCRIBE_STATUS_CHANGED: updateDisplay(true); case RsForumEventCode::SUBSCRIBE_STATUS_CHANGED: updateDisplay(true);
break; break;
default: default:
break; break;