From 7a237c11d34c5fd2655b57c39d3fc403e6d48dcc Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Wed, 12 Jun 2019 15:04:20 +0200 Subject: [PATCH 1/2] GxsTrans delete own timed out mails Mails sent in the past end never received were lingering in the outgoing queue forever as displayed by statistics. If a mail is older then GXS_STORAGE_PERIOD all nodes delete it from the GXS group so it can never arrive to destination, there is no point in keeping it in the outgoing queue, instead notify sending timed out and delete the mail. --- libretroshare/src/gxstrans/p3gxstrans.cc | 42 +++++++++++++---------- libretroshare/src/gxstrans/p3gxstrans.h | 6 ++-- libretroshare/src/retroshare/rsgxstrans.h | 21 +++++++++++- 3 files changed, 46 insertions(+), 23 deletions(-) diff --git a/libretroshare/src/gxstrans/p3gxstrans.cc b/libretroshare/src/gxstrans/p3gxstrans.cc index b0fa4b3f0..59344627a 100644 --- a/libretroshare/src/gxstrans/p3gxstrans.cc +++ b/libretroshare/src/gxstrans/p3gxstrans.cc @@ -1,9 +1,7 @@ /******************************************************************************* - * libretroshare/src/gxstrans: p3gxstrans.cc * + * RetroShare GxsTrans asyncronous redundant small mail trasport on top of GXS * * * - * libretroshare: retroshare core library * - * * - * Copyright (C) 2016-2017 Gioacchino Mazzurco * + * Copyright (C) 2016-2019 Gioacchino Mazzurco * * * * This program is free software: you can redistribute it and/or modify * * it under the terms of the GNU Lesser General Public License as * @@ -22,12 +20,13 @@ #include "util/rsdir.h" #include "gxstrans/p3gxstrans.h" #include "util/stacktrace.h" +#include "util/rsdebug.h" //#define DEBUG_GXSTRANS 1 typedef unsigned int uint; -RsGxsTrans *rsGxsTrans = NULL ; +/*extern*/ RsGxsTrans* rsGxsTrans = nullptr; const uint32_t p3GxsTrans::MAX_DELAY_BETWEEN_CLEANUPS = 900; // every 15 mins. Could be less. @@ -964,9 +963,9 @@ void p3GxsTrans::locked_processOutgoingRecord(OutgoingRecord& pr) { case RsGxsTransEncryptionMode::CLEAR_TEXT: { - std::cerr << "p3GxsTrans::sendMail(...) you are sending a mail " - << "without encryption, everyone can read it!" - << std::endl; + RsWarn() << __PRETTY_FUNCTION__ << " you are sending a mail " + << "without encryption, everyone can read it!" + << std::endl; break; } case RsGxsTransEncryptionMode::RSA: @@ -986,15 +985,15 @@ void p3GxsTrans::locked_processOutgoingRecord(OutgoingRecord& pr) } else { - std::cerr << "p3GxsTrans::sendMail(...) RSA encryption failed! " - << "error_status: " << encryptError << std::endl; + RsErr() << __PRETTY_FUNCTION__ << " RSA encryption failed! " + << "error_status: " << encryptError << std::endl; pr.status = GxsTransSendStatus::FAILED_ENCRYPTION; goto processingFailed; } } case RsGxsTransEncryptionMode::UNDEFINED_ENCRYPTION: default: - std::cerr << "p3GxsTrans::sendMail(...) attempt to send mail with " + RsErr() << __PRETTY_FUNCTION__ << " attempt to send mail with " << "wrong EncryptionMode: " << static_cast(pr.mailItem.cryptoType) << " dropping mail!" << std::endl; @@ -1040,7 +1039,8 @@ void p3GxsTrans::locked_processOutgoingRecord(OutgoingRecord& pr) { RS_STACK_MUTEX(mIngoingMutex); auto range = mIncomingQueue.equal_range(pr.mailItem.mailId); - bool changed = false ; + bool changed = false; + bool received = false; for( auto it = range.first; it != range.second; ++it) { @@ -1051,14 +1051,21 @@ void p3GxsTrans::locked_processOutgoingRecord(OutgoingRecord& pr) mIncomingQueue.erase(it); delete rt; pr.status = GxsTransSendStatus::RECEIPT_RECEIVED; - changed = true ; + changed = true; + received = true; break; } } + + if(!received && time(nullptr) - pr.sent_ts > GXS_STORAGE_PERIOD) + { + changed = true; + pr.status = GxsTransSendStatus::FAILED_TIMED_OUT; + } + if(changed) IndicateConfigChanged(); - // TODO: Resend message if older then treshold break; } case GxsTransSendStatus::RECEIPT_RECEIVED: @@ -1067,14 +1074,13 @@ void p3GxsTrans::locked_processOutgoingRecord(OutgoingRecord& pr) processingFailed: case GxsTransSendStatus::FAILED_RECEIPT_SIGNATURE: case GxsTransSendStatus::FAILED_ENCRYPTION: + case GxsTransSendStatus::FAILED_TIMED_OUT: default: - { - std::cout << "p3GxsTrans::processRecord(" << pr.mailItem.mailId - << ") failed with: " << static_cast(pr.status) + RsErr() << __PRETTY_FUNCTION__ << " processing:" << pr.mailItem.mailId + << " failed with: " << static_cast(pr.status) << std::endl; break; } - } } void p3GxsTrans::notifyClientService(const OutgoingRecord& pr) diff --git a/libretroshare/src/gxstrans/p3gxstrans.h b/libretroshare/src/gxstrans/p3gxstrans.h index c730d8177..6deffb081 100644 --- a/libretroshare/src/gxstrans/p3gxstrans.h +++ b/libretroshare/src/gxstrans/p3gxstrans.h @@ -1,9 +1,7 @@ /******************************************************************************* - * libretroshare/src/gxstrans: p3gxstrans.h * + * RetroShare GxsTrans asyncronous redundant small mail trasport on top of GXS * * * - * libretroshare: retroshare core library * - * * - * Copyright (C) 2016-2017 Gioacchino Mazzurco * + * Copyright (C) 2016-2019 Gioacchino Mazzurco * * * * This program is free software: you can redistribute it and/or modify * * it under the terms of the GNU Lesser General Public License as * diff --git a/libretroshare/src/retroshare/rsgxstrans.h b/libretroshare/src/retroshare/rsgxstrans.h index bee1e11ec..b71b59c54 100644 --- a/libretroshare/src/retroshare/rsgxstrans.h +++ b/libretroshare/src/retroshare/rsgxstrans.h @@ -1,3 +1,21 @@ +/******************************************************************************* + * RetroShare GxsTrans asyncronous redundant small mail trasport on top of GXS * + * * + * Copyright (C) 2016-2019 Gioacchino Mazzurco * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License version 3 as * + * published by the Free Software Foundation. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public License * + * along with this program. If not, see . * + * * + *******************************************************************************/ #pragma once #include "retroshare/rstokenservice.h" @@ -41,7 +59,8 @@ enum class GxsTransSendStatus : uint8_t /// Records with status >= RECEIPT_RECEIVED get deleted RECEIPT_RECEIVED = 0x0a, FAILED_RECEIPT_SIGNATURE = 0xf0, - FAILED_ENCRYPTION = 0xf1 + FAILED_ENCRYPTION = 0xf1, + FAILED_TIMED_OUT = 0xf2 }; typedef uint64_t RsGxsTransId; From c80b6db42342d7dd38f2621dceceec83fcb7ca8c Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Wed, 12 Jun 2019 15:30:02 +0200 Subject: [PATCH 2/2] GxsTrans update outdated comments --- libretroshare/src/gxstrans/p3gxstrans.cc | 14 +++++++------- libretroshare/src/gxstrans/p3gxstrans.h | 8 +++++--- libretroshare/src/retroshare/rsgxstrans.h | 5 ++++- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/libretroshare/src/gxstrans/p3gxstrans.cc b/libretroshare/src/gxstrans/p3gxstrans.cc index 59344627a..85292c383 100644 --- a/libretroshare/src/gxstrans/p3gxstrans.cc +++ b/libretroshare/src/gxstrans/p3gxstrans.cc @@ -1,5 +1,7 @@ /******************************************************************************* - * RetroShare GxsTrans asyncronous redundant small mail trasport on top of GXS * + * libretroshare/src/gxstrans: p3gxstrans.cc * + * * + * libretroshare: retroshare core library * * * * Copyright (C) 2016-2019 Gioacchino Mazzurco * * * @@ -239,10 +241,7 @@ void p3GxsTrans::handleResponse(uint32_t token, uint32_t req_type) if(!have_preferred_group) { /* This is true only at first run when we haven't received mail - * distribuition groups from friends - * TODO: We should check if we have some connected friend too, to - * avoid to create yet another never used mail distribution group. - */ + * distribuition groups from friends */ #ifdef DEBUG_GXSTRANS std::cerr << "p3GxsTrans::handleResponse(...) preferredGroupId.isNu" @@ -620,9 +619,10 @@ void p3GxsTrans::service_tick() } else { - /* TODO: It is a receipt for a message sent by someone else + /* It is a receipt for a message sent by someone else * we can delete original mail from our GXS DB without - * waiting for GXS_STORAGE_PERIOD */ + * waiting for GXS_STORAGE_PERIOD, this has been implemented + * already by Cyril into GxsTransIntegrityCleanupThread */ } break; } diff --git a/libretroshare/src/gxstrans/p3gxstrans.h b/libretroshare/src/gxstrans/p3gxstrans.h index 6deffb081..32b07e1b9 100644 --- a/libretroshare/src/gxstrans/p3gxstrans.h +++ b/libretroshare/src/gxstrans/p3gxstrans.h @@ -1,5 +1,7 @@ /******************************************************************************* - * RetroShare GxsTrans asyncronous redundant small mail trasport on top of GXS * + * libretroshare/src/gxstrans: p3gxstrans.h * + * * + * libretroshare: retroshare core library * * * * Copyright (C) 2016-2019 Gioacchino Mazzurco * * * @@ -19,7 +21,7 @@ *******************************************************************************/ #pragma once -#include +#include #include #include @@ -68,7 +70,7 @@ struct MsgSizeCount }; /** - * @brief p3GxsTrans is a mail delivery service based on GXS. + * @brief p3GxsTrans asyncronous redundant small mail trasport on top of GXS. * p3GxsTrans is capable of asynchronous mail delivery and acknowledgement. * p3GxsTrans is meant to be capable of multiple encryption options, * @see RsGxsTransEncryptionMode at moment messages are encrypted using RSA diff --git a/libretroshare/src/retroshare/rsgxstrans.h b/libretroshare/src/retroshare/rsgxstrans.h index b71b59c54..a491f7bfe 100644 --- a/libretroshare/src/retroshare/rsgxstrans.h +++ b/libretroshare/src/retroshare/rsgxstrans.h @@ -1,5 +1,7 @@ /******************************************************************************* - * RetroShare GxsTrans asyncronous redundant small mail trasport on top of GXS * + * libretroshare/src/retroshare: rsgxstrans.h * + * * + * libretroshare: retroshare core library * * * * Copyright (C) 2016-2019 Gioacchino Mazzurco * * * @@ -98,6 +100,7 @@ struct RsGxsTransOutgoingRecord RsGxsGroupId group_id ; }; +/// RetroShare GxsTrans asyncronous redundant small mail trasport on top of GXS class RsGxsTrans: public RsGxsIfaceHelper { public: