Merge pull request #1580 from G10h4ck/gxs_trans_refinements

GxsTrans refinements
This commit is contained in:
G10h4ck 2019-07-30 12:45:24 +02:00 committed by GitHub
commit 3ffb57f998
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 25 deletions

View file

@ -3,7 +3,7 @@
* * * *
* libretroshare: retroshare core library * * libretroshare: retroshare core library *
* * * *
* Copyright (C) 2016-2017 Gioacchino Mazzurco <gio@eigenlab.org> * * Copyright (C) 2016-2019 Gioacchino Mazzurco <gio@eigenlab.org> *
* * * *
* This program is free software: you can redistribute it and/or modify * * This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as * * it under the terms of the GNU Lesser General Public License as *
@ -22,12 +22,13 @@
#include "util/rsdir.h" #include "util/rsdir.h"
#include "gxstrans/p3gxstrans.h" #include "gxstrans/p3gxstrans.h"
#include "util/stacktrace.h" #include "util/stacktrace.h"
#include "util/rsdebug.h"
//#define DEBUG_GXSTRANS 1 //#define DEBUG_GXSTRANS 1
typedef unsigned int uint; 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. const uint32_t p3GxsTrans::MAX_DELAY_BETWEEN_CLEANUPS = 900; // every 15 mins. Could be less.
@ -240,10 +241,7 @@ void p3GxsTrans::handleResponse(uint32_t token, uint32_t req_type)
if(!have_preferred_group) if(!have_preferred_group)
{ {
/* This is true only at first run when we haven't received mail /* This is true only at first run when we haven't received mail
* distribuition groups from friends * 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.
*/
#ifdef DEBUG_GXSTRANS #ifdef DEBUG_GXSTRANS
std::cerr << "p3GxsTrans::handleResponse(...) preferredGroupId.isNu" std::cerr << "p3GxsTrans::handleResponse(...) preferredGroupId.isNu"
@ -621,9 +619,10 @@ void p3GxsTrans::service_tick()
} }
else 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 * 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; break;
} }
@ -964,7 +963,7 @@ void p3GxsTrans::locked_processOutgoingRecord(OutgoingRecord& pr)
{ {
case RsGxsTransEncryptionMode::CLEAR_TEXT: case RsGxsTransEncryptionMode::CLEAR_TEXT:
{ {
std::cerr << "p3GxsTrans::sendMail(...) you are sending a mail " RsWarn() << __PRETTY_FUNCTION__ << " you are sending a mail "
<< "without encryption, everyone can read it!" << "without encryption, everyone can read it!"
<< std::endl; << std::endl;
break; break;
@ -986,7 +985,7 @@ void p3GxsTrans::locked_processOutgoingRecord(OutgoingRecord& pr)
} }
else else
{ {
std::cerr << "p3GxsTrans::sendMail(...) RSA encryption failed! " RsErr() << __PRETTY_FUNCTION__ << " RSA encryption failed! "
<< "error_status: " << encryptError << std::endl; << "error_status: " << encryptError << std::endl;
pr.status = GxsTransSendStatus::FAILED_ENCRYPTION; pr.status = GxsTransSendStatus::FAILED_ENCRYPTION;
goto processingFailed; goto processingFailed;
@ -994,7 +993,7 @@ void p3GxsTrans::locked_processOutgoingRecord(OutgoingRecord& pr)
} }
case RsGxsTransEncryptionMode::UNDEFINED_ENCRYPTION: case RsGxsTransEncryptionMode::UNDEFINED_ENCRYPTION:
default: default:
std::cerr << "p3GxsTrans::sendMail(...) attempt to send mail with " RsErr() << __PRETTY_FUNCTION__ << " attempt to send mail with "
<< "wrong EncryptionMode: " << "wrong EncryptionMode: "
<< static_cast<uint>(pr.mailItem.cryptoType) << static_cast<uint>(pr.mailItem.cryptoType)
<< " dropping mail!" << std::endl; << " dropping mail!" << std::endl;
@ -1040,7 +1039,8 @@ void p3GxsTrans::locked_processOutgoingRecord(OutgoingRecord& pr)
{ {
RS_STACK_MUTEX(mIngoingMutex); RS_STACK_MUTEX(mIngoingMutex);
auto range = mIncomingQueue.equal_range(pr.mailItem.mailId); 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) for( auto it = range.first; it != range.second; ++it)
{ {
@ -1051,14 +1051,21 @@ void p3GxsTrans::locked_processOutgoingRecord(OutgoingRecord& pr)
mIncomingQueue.erase(it); delete rt; mIncomingQueue.erase(it); delete rt;
pr.status = GxsTransSendStatus::RECEIPT_RECEIVED; pr.status = GxsTransSendStatus::RECEIPT_RECEIVED;
changed = true ; changed = true;
received = true;
break; break;
} }
} }
if(!received && time(nullptr) - pr.sent_ts > GXS_STORAGE_PERIOD)
{
changed = true;
pr.status = GxsTransSendStatus::FAILED_TIMED_OUT;
}
if(changed) if(changed)
IndicateConfigChanged(); IndicateConfigChanged();
// TODO: Resend message if older then treshold
break; break;
} }
case GxsTransSendStatus::RECEIPT_RECEIVED: case GxsTransSendStatus::RECEIPT_RECEIVED:
@ -1067,14 +1074,13 @@ void p3GxsTrans::locked_processOutgoingRecord(OutgoingRecord& pr)
processingFailed: processingFailed:
case GxsTransSendStatus::FAILED_RECEIPT_SIGNATURE: case GxsTransSendStatus::FAILED_RECEIPT_SIGNATURE:
case GxsTransSendStatus::FAILED_ENCRYPTION: case GxsTransSendStatus::FAILED_ENCRYPTION:
case GxsTransSendStatus::FAILED_TIMED_OUT:
default: default:
{ RsErr() << __PRETTY_FUNCTION__ << " processing:" << pr.mailItem.mailId
std::cout << "p3GxsTrans::processRecord(" << pr.mailItem.mailId << " failed with: " << static_cast<uint>(pr.status)
<< ") failed with: " << static_cast<uint>(pr.status)
<< std::endl; << std::endl;
break; break;
} }
}
} }
void p3GxsTrans::notifyClientService(const OutgoingRecord& pr) void p3GxsTrans::notifyClientService(const OutgoingRecord& pr)

View file

@ -3,7 +3,7 @@
* * * *
* libretroshare: retroshare core library * * libretroshare: retroshare core library *
* * * *
* Copyright (C) 2016-2017 Gioacchino Mazzurco <gio@eigenlab.org> * * Copyright (C) 2016-2019 Gioacchino Mazzurco <gio@eigenlab.org> *
* * * *
* This program is free software: you can redistribute it and/or modify * * This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as * * it under the terms of the GNU Lesser General Public License as *
@ -21,7 +21,7 @@
*******************************************************************************/ *******************************************************************************/
#pragma once #pragma once
#include <stdint.h> #include <cstdint>
#include <unordered_map> #include <unordered_map>
#include <map> #include <map>
@ -70,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 capable of asynchronous mail delivery and acknowledgement.
* p3GxsTrans is meant to be capable of multiple encryption options, * p3GxsTrans is meant to be capable of multiple encryption options,
* @see RsGxsTransEncryptionMode at moment messages are encrypted using RSA * @see RsGxsTransEncryptionMode at moment messages are encrypted using RSA

View file

@ -1,3 +1,23 @@
/*******************************************************************************
* libretroshare/src/retroshare: rsgxstrans.h *
* *
* libretroshare: retroshare core library *
* *
* Copyright (C) 2016-2019 Gioacchino Mazzurco <gio@eigenlab.org> *
* *
* 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 <https://www.gnu.org/licenses/>. *
* *
*******************************************************************************/
#pragma once #pragma once
#include "retroshare/rstokenservice.h" #include "retroshare/rstokenservice.h"
@ -41,7 +61,8 @@ enum class GxsTransSendStatus : uint8_t
/// Records with status >= RECEIPT_RECEIVED get deleted /// Records with status >= RECEIPT_RECEIVED get deleted
RECEIPT_RECEIVED = 0x0a, RECEIPT_RECEIVED = 0x0a,
FAILED_RECEIPT_SIGNATURE = 0xf0, FAILED_RECEIPT_SIGNATURE = 0xf0,
FAILED_ENCRYPTION = 0xf1 FAILED_ENCRYPTION = 0xf1,
FAILED_TIMED_OUT = 0xf2
}; };
typedef uint64_t RsGxsTransId; typedef uint64_t RsGxsTransId;
@ -79,6 +100,7 @@ struct RsGxsTransOutgoingRecord
RsGxsGroupId group_id ; RsGxsGroupId group_id ;
}; };
/// RetroShare GxsTrans asyncronous redundant small mail trasport on top of GXS
class RsGxsTrans: public RsGxsIfaceHelper class RsGxsTrans: public RsGxsIfaceHelper
{ {
public: public: