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 *
* *
* 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 *
* it under the terms of the GNU Lesser General Public License as *
@ -22,12 +22,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.
@ -240,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"
@ -621,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;
}
@ -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<uint>(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<uint>(pr.status)
RsErr() << __PRETTY_FUNCTION__ << " processing:" << pr.mailItem.mailId
<< " failed with: " << static_cast<uint>(pr.status)
<< std::endl;
break;
}
}
}
void p3GxsTrans::notifyClientService(const OutgoingRecord& pr)

View File

@ -3,7 +3,7 @@
* *
* 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 *
* it under the terms of the GNU Lesser General Public License as *
@ -21,7 +21,7 @@
*******************************************************************************/
#pragma once
#include <stdint.h>
#include <cstdint>
#include <unordered_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 meant to be capable of multiple encryption options,
* @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
#include "retroshare/rstokenservice.h"
@ -41,7 +61,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;
@ -79,6 +100,7 @@ struct RsGxsTransOutgoingRecord
RsGxsGroupId group_id ;
};
/// RetroShare GxsTrans asyncronous redundant small mail trasport on top of GXS
class RsGxsTrans: public RsGxsIfaceHelper
{
public: