From 7a237c11d34c5fd2655b57c39d3fc403e6d48dcc Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Wed, 12 Jun 2019 15:04:20 +0200 Subject: [PATCH] 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;