mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-28 00:49:28 -05:00
Renamed GxsMails to GxsTrans
GxsTrans is a generic transport service, use more generic name trans instead of mail to avoid confusion Renamed size(...) to seria_size(...) for costistence whit the codebase Moved GxsTrans and related things to gxstrans directory Removed outdated and now uncompatible gxsmail test service Avoid expose internal items in public interface methods
This commit is contained in:
parent
08161db43b
commit
da459c884e
@ -40,6 +40,7 @@
|
||||
#include "pqi/p3historymgr.h"
|
||||
#include "rsserver/p3face.h"
|
||||
#include "services/p3idservice.h"
|
||||
#include "gxstrans/p3gxstrans.h"
|
||||
|
||||
#include "chat/p3chatservice.h"
|
||||
#include "serialiser/rsconfigitems.h"
|
||||
@ -55,16 +56,16 @@ static const uint32_t MAX_AVATAR_JPEG_SIZE = 32767; // Maximum size
|
||||
|
||||
p3ChatService::p3ChatService( p3ServiceControl *sc, p3IdService *pids,
|
||||
p3LinkMgr *lm, p3HistoryMgr *historyMgr,
|
||||
p3GxsMails& gxsMailService ) :
|
||||
p3GxsTrans& gxsTransService ) :
|
||||
DistributedChatService(getServiceInfo().mServiceType, sc, historyMgr,pids),
|
||||
mChatMtx("p3ChatService"), mServiceCtrl(sc), mLinkMgr(lm),
|
||||
mHistoryMgr(historyMgr), _own_avatar(NULL),
|
||||
_serializer(new RsChatSerialiser()),
|
||||
mDGMutex("p3ChatService distant id - gxs id map mutex"),
|
||||
mGxsTransport(gxsMailService)
|
||||
mGxsTransport(gxsTransService)
|
||||
{
|
||||
addSerialType(_serializer);
|
||||
mGxsTransport.registerGxsMailsClient( GxsMailSubServices::P3_CHAT_SERVICE,
|
||||
mGxsTransport.registerGxsTransClient( GxsTransSubServices::P3_CHAT_SERVICE,
|
||||
this );
|
||||
}
|
||||
|
||||
@ -335,7 +336,7 @@ bool p3ChatService::sendChat(ChatId destination, std::string msg)
|
||||
// this is not very nice, because the user may think the message was send, while it is still in the queue
|
||||
mHistoryMgr->addMessage(message);
|
||||
|
||||
RsGxsMailId tId = RSRandom::random_u64();
|
||||
RsGxsTransId tId = RSRandom::random_u64();
|
||||
|
||||
if(destination.isDistantChatId())
|
||||
{
|
||||
@ -348,7 +349,7 @@ bool p3ChatService::sendChat(ChatId destination, std::string msg)
|
||||
uint32_t sz = ci->serial_size();
|
||||
std::vector<uint8_t> data; data.resize(sz);
|
||||
ci->serialise(&data[0], sz);
|
||||
mGxsTransport.sendMail(tId, GxsMailSubServices::P3_CHAT_SERVICE,
|
||||
mGxsTransport.sendMail(tId, GxsTransSubServices::P3_CHAT_SERVICE,
|
||||
de.from, de.to, &data[0], sz);
|
||||
}
|
||||
else
|
||||
@ -706,9 +707,10 @@ bool p3ChatService::initiateDistantChatConnexion( const RsGxsId& to_gxs_id,
|
||||
return false;
|
||||
}
|
||||
|
||||
bool p3ChatService::receiveGxsMail( const RsGxsId& authorId,
|
||||
const RsGxsId& recipientId,
|
||||
const uint8_t* data, uint32_t dataSize )
|
||||
bool p3ChatService::receiveGxsTransMail( const RsGxsId& authorId,
|
||||
const RsGxsId& recipientId,
|
||||
const uint8_t* data,
|
||||
uint32_t dataSize )
|
||||
{
|
||||
DistantChatPeerId pid;
|
||||
uint32_t error_code;
|
||||
@ -724,22 +726,22 @@ bool p3ChatService::receiveGxsMail( const RsGxsId& authorId,
|
||||
return true;
|
||||
}
|
||||
|
||||
std::cerr << "p3ChatService::receiveGxsMail(...) (EE) failed initiating"
|
||||
std::cerr << __PRETTY_FUNCTION__ << " (EE) failed initiating"
|
||||
<< " distant chat connection error: "<< error_code
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool p3ChatService::notifySendMailStatus( const RsGxsMailItem& originalMessage,
|
||||
GxsMailStatus status )
|
||||
bool p3ChatService::notifyGxsTransSendStatus(RsGxsTransId mailId,
|
||||
GxsTransSendStatus status )
|
||||
{
|
||||
if ( status != GxsMailStatus::RECEIPT_RECEIVED ) return true;
|
||||
if ( status != GxsTransSendStatus::RECEIPT_RECEIVED ) return true;
|
||||
|
||||
bool changed = false;
|
||||
|
||||
{
|
||||
RS_STACK_MUTEX(mChatMtx);
|
||||
auto it = privateOutgoingMap.find(originalMessage.mailId);
|
||||
auto it = privateOutgoingMap.find(mailId);
|
||||
if( it != privateOutgoingMap.end() )
|
||||
{
|
||||
privateOutgoingMap.erase(it);
|
||||
|
@ -37,7 +37,7 @@
|
||||
#include "chat/distantchat.h"
|
||||
#include "chat/distributedchat.h"
|
||||
#include "retroshare/rsmsgs.h"
|
||||
#include "services/p3gxsmails.h"
|
||||
#include "gxstrans/p3gxstrans.h"
|
||||
#include "util/rsdeprecate.h"
|
||||
|
||||
class p3ServiceControl;
|
||||
@ -55,10 +55,10 @@ typedef RsPeerId ChatLobbyVirtualPeerId ;
|
||||
*/
|
||||
struct p3ChatService :
|
||||
p3Service, DistantChatService, DistributedChatService, p3Config,
|
||||
pqiServiceMonitor, GxsMailsClient
|
||||
pqiServiceMonitor, GxsTransClient
|
||||
{
|
||||
p3ChatService( p3ServiceControl *cs, p3IdService *pids,p3LinkMgr *cm,
|
||||
p3HistoryMgr *historyMgr, p3GxsMails& gxsMailService );
|
||||
p3ChatService(p3ServiceControl *cs, p3IdService *pids, p3LinkMgr *cm,
|
||||
p3HistoryMgr *historyMgr, p3GxsTrans& gxsTransService );
|
||||
|
||||
virtual RsServiceInfo getServiceInfo();
|
||||
|
||||
@ -171,14 +171,14 @@ struct p3ChatService :
|
||||
uint32_t& error_code,
|
||||
bool notify = true );
|
||||
|
||||
/// @see GxsMailsClient::receiveGxsMail(...)
|
||||
virtual bool receiveGxsMail( const RsGxsId& authorId,
|
||||
const RsGxsId& recipientId,
|
||||
const uint8_t* data, uint32_t dataSize );
|
||||
/// @see GxsTransClient::receiveGxsTransMail(...)
|
||||
virtual bool receiveGxsTransMail( const RsGxsId& authorId,
|
||||
const RsGxsId& recipientId,
|
||||
const uint8_t* data, uint32_t dataSize );
|
||||
|
||||
/// @see GxsMailsClient::notifySendMailStatus(...)
|
||||
virtual bool notifySendMailStatus( const RsGxsMailItem& originalMessage,
|
||||
GxsMailStatus status );
|
||||
/// @see GxsTransClient::notifySendMailStatus(...)
|
||||
virtual bool notifyGxsTransSendStatus( RsGxsTransId mailId,
|
||||
GxsTransSendStatus status );
|
||||
|
||||
|
||||
protected:
|
||||
@ -270,7 +270,7 @@ private:
|
||||
DIDEMap mDistantGxsMap;
|
||||
RsMutex mDGMutex;
|
||||
|
||||
p3GxsMails& mGxsTransport;
|
||||
p3GxsTrans& mGxsTransport;
|
||||
};
|
||||
|
||||
class p3ChatService::StateStringInfo
|
||||
|
@ -16,39 +16,39 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "p3gxsmails.h"
|
||||
#include "gxstrans/p3gxstrans.h"
|
||||
#include "util/stacktrace.h"
|
||||
|
||||
typedef unsigned int uint;
|
||||
|
||||
p3GxsMails::~p3GxsMails()
|
||||
p3GxsTrans::~p3GxsTrans()
|
||||
{
|
||||
p3Config::saveConfiguration();
|
||||
|
||||
{
|
||||
RS_STACK_MUTEX(ingoingMutex);
|
||||
for ( auto& kv : ingoingQueue ) delete kv.second;
|
||||
RS_STACK_MUTEX(mIngoingMutex);
|
||||
for ( auto& kv : mIngoingQueue ) delete kv.second;
|
||||
}
|
||||
}
|
||||
|
||||
bool p3GxsMails::sendMail( RsGxsMailId& mailId,
|
||||
GxsMailSubServices service,
|
||||
bool p3GxsTrans::sendMail( RsGxsTransId& mailId,
|
||||
GxsTransSubServices service,
|
||||
const RsGxsId& own_gxsid, const RsGxsId& recipient,
|
||||
const uint8_t* data, uint32_t size,
|
||||
RsGxsMailEncryptionMode cm )
|
||||
RsGxsTransEncryptionMode cm )
|
||||
{
|
||||
std::cout << "p3GxsMails::sendEmail(...)" << std::endl;
|
||||
std::cout << "p3GxsTrans::sendEmail(...)" << std::endl;
|
||||
|
||||
if(!idService.isOwnId(own_gxsid))
|
||||
if(!mIdService.isOwnId(own_gxsid))
|
||||
{
|
||||
std::cerr << "p3GxsMails::sendEmail(...) isOwnId(own_gxsid) false!"
|
||||
std::cerr << "p3GxsTrans::sendEmail(...) isOwnId(own_gxsid) false!"
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(recipient.isNull())
|
||||
{
|
||||
std::cerr << "p3GxsMails::sendEmail(...) got invalid recipient"
|
||||
std::cerr << "p3GxsTrans::sendEmail(...) got invalid recipient"
|
||||
<< std::endl;
|
||||
print_stacktrace();
|
||||
return false;
|
||||
@ -60,18 +60,19 @@ bool p3GxsMails::sendMail( RsGxsMailId& mailId,
|
||||
pr.mailItem.mailId = RSRandom::random_u64();
|
||||
|
||||
{
|
||||
RS_STACK_MUTEX(outgoingMutex);
|
||||
outgoingQueue.insert(prMap::value_type(pr.mailItem.mailId, pr));
|
||||
RS_STACK_MUTEX(mOutgoingMutex);
|
||||
mOutgoingQueue.insert(prMap::value_type(pr.mailItem.mailId, pr));
|
||||
}
|
||||
|
||||
mailId = pr.mailItem.mailId;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3GxsMails::querySendMailStatus(RsGxsMailId mailId, GxsMailStatus& st)
|
||||
bool p3GxsTrans::querySendStatus(RsGxsTransId mailId, GxsTransSendStatus& st)
|
||||
{
|
||||
auto it = outgoingQueue.find(mailId);
|
||||
if( it != outgoingQueue.end() )
|
||||
RS_STACK_MUTEX(mOutgoingMutex);
|
||||
auto it = mOutgoingQueue.find(mailId);
|
||||
if( it != mOutgoingQueue.end() )
|
||||
{
|
||||
st = it->second.status;
|
||||
return true;
|
||||
@ -79,16 +80,16 @@ bool p3GxsMails::querySendMailStatus(RsGxsMailId mailId, GxsMailStatus& st)
|
||||
return false;
|
||||
}
|
||||
|
||||
void p3GxsMails::registerGxsMailsClient(
|
||||
GxsMailSubServices serviceType, GxsMailsClient* service)
|
||||
void p3GxsTrans::registerGxsTransClient(
|
||||
GxsTransSubServices serviceType, GxsTransClient* service)
|
||||
{
|
||||
RS_STACK_MUTEX(servClientsMutex);
|
||||
servClients[serviceType] = service;
|
||||
RS_STACK_MUTEX(mServClientsMutex);
|
||||
mServClients[serviceType] = service;
|
||||
}
|
||||
|
||||
void p3GxsMails::handleResponse(uint32_t token, uint32_t req_type)
|
||||
void p3GxsTrans::handleResponse(uint32_t token, uint32_t req_type)
|
||||
{
|
||||
std::cout << "p3GxsMails::handleResponse(" << token << ", " << req_type
|
||||
std::cout << "p3GxsTrans::handleResponse(" << token << ", " << req_type
|
||||
<< ")" << std::endl;
|
||||
switch (req_type)
|
||||
{
|
||||
@ -116,7 +117,7 @@ void p3GxsMails::handleResponse(uint32_t token, uint32_t req_type)
|
||||
|
||||
bool shoudlSubscribe = !subscribed && ( !old || supersede );
|
||||
bool shoudlUnSubscribe = subscribed && old
|
||||
&& meta.mGroupId != preferredGroupId;
|
||||
&& meta.mGroupId != mPreferredGroupId;
|
||||
|
||||
if(shoudlSubscribe)
|
||||
subscribeToGroup(token, meta.mGroupId, true);
|
||||
@ -129,7 +130,7 @@ void p3GxsMails::handleResponse(uint32_t token, uint32_t req_type)
|
||||
timeinfo = localtime(&meta.mLastPost);
|
||||
strftime(buff, sizeof(buff), "%Y %b %d %H:%M", timeinfo);
|
||||
|
||||
std::cout << "p3GxsMails::handleResponse(...) GROUPS_LIST "
|
||||
std::cout << "p3GxsTrans::handleResponse(...) GROUPS_LIST "
|
||||
<< "meta.mGroupId: " << meta.mGroupId
|
||||
<< " meta.mLastPost: " << buff
|
||||
<< " subscribed: " << subscribed
|
||||
@ -142,7 +143,7 @@ void p3GxsMails::handleResponse(uint32_t token, uint32_t req_type)
|
||||
delete grp;
|
||||
}
|
||||
|
||||
if(preferredGroupId.isNull())
|
||||
if(mPreferredGroupId.isNull())
|
||||
{
|
||||
/* This is true only at first run when we haven't received mail
|
||||
* distribuition groups from friends
|
||||
@ -150,10 +151,10 @@ void p3GxsMails::handleResponse(uint32_t token, uint32_t req_type)
|
||||
* avoid to create yet another never used mail distribution group.
|
||||
*/
|
||||
|
||||
std::cerr << "p3GxsMails::handleResponse(...) preferredGroupId.isNu"
|
||||
std::cerr << "p3GxsTrans::handleResponse(...) preferredGroupId.isNu"
|
||||
<< "ll() let's create a new group." << std::endl;
|
||||
uint32_t token;
|
||||
publishGroup(token, new RsGxsMailGroupItem());
|
||||
publishGroup(token, new RsGxsTransGroupItem());
|
||||
queueRequest(token, GROUP_CREATE);
|
||||
}
|
||||
|
||||
@ -161,7 +162,7 @@ void p3GxsMails::handleResponse(uint32_t token, uint32_t req_type)
|
||||
}
|
||||
case GROUP_CREATE:
|
||||
{
|
||||
std::cerr << "p3GxsMails::handleResponse(...) GROUP_CREATE" << std::endl;
|
||||
std::cerr << "p3GxsTrans::handleResponse(...) GROUP_CREATE" << std::endl;
|
||||
RsGxsGroupId grpId;
|
||||
acknowledgeTokenGrp(token, grpId);
|
||||
supersedePreferredGroup(grpId);
|
||||
@ -169,7 +170,7 @@ void p3GxsMails::handleResponse(uint32_t token, uint32_t req_type)
|
||||
}
|
||||
case MAILS_UPDATE:
|
||||
{
|
||||
std::cout << "p3GxsMails::handleResponse(...) MAILS_UPDATE" << std::endl;
|
||||
std::cout << "p3GxsTrans::handleResponse(...) MAILS_UPDATE" << std::endl;
|
||||
typedef std::map<RsGxsGroupId, std::vector<RsGxsMsgItem*> > GxsMsgDataMap;
|
||||
GxsMsgDataMap gpMsgMap;
|
||||
getMsgData(token, gpMsgMap);
|
||||
@ -181,27 +182,27 @@ void p3GxsMails::handleResponse(uint32_t token, uint32_t req_type)
|
||||
for( vT::const_iterator mIt = mv.begin(); mIt != mv.end(); ++mIt )
|
||||
{
|
||||
RsGxsMsgItem* gIt = *mIt;
|
||||
switch(static_cast<GxsMailItemsSubtypes>(gIt->PacketSubType()))
|
||||
switch(static_cast<GxsTransItemsSubtypes>(gIt->PacketSubType()))
|
||||
{
|
||||
case GxsMailItemsSubtypes::GXS_MAIL_SUBTYPE_MAIL:
|
||||
case GxsMailItemsSubtypes::GXS_MAIL_SUBTYPE_RECEIPT:
|
||||
case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_MAIL:
|
||||
case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_RECEIPT:
|
||||
{
|
||||
RsGxsMailBaseItem* mb =
|
||||
dynamic_cast<RsGxsMailBaseItem*>(*mIt);
|
||||
RsGxsTransBaseItem* mb =
|
||||
dynamic_cast<RsGxsTransBaseItem*>(*mIt);
|
||||
if(mb)
|
||||
{
|
||||
RS_STACK_MUTEX(ingoingMutex);
|
||||
ingoingQueue.insert(inMap::value_type(mb->mailId, mb));
|
||||
RS_STACK_MUTEX(mIngoingMutex);
|
||||
mIngoingQueue.insert(inMap::value_type(mb->mailId, mb));
|
||||
}
|
||||
else
|
||||
std::cerr << "p3GxsMails::handleResponse(...) "
|
||||
std::cerr << "p3GxsTrans::handleResponse(...) "
|
||||
<< "GXS_MAIL_SUBTYPE_MAIL cast error, "
|
||||
<< "something really wrong is happening"
|
||||
<< std::endl;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
std::cerr << "p3GxsMails::handleResponse(...) MAILS_UPDATE "
|
||||
std::cerr << "p3GxsTrans::handleResponse(...) MAILS_UPDATE "
|
||||
<< "Unknown mail subtype : "
|
||||
<< static_cast<uint>(gIt->PacketSubType())
|
||||
<< std::endl;
|
||||
@ -213,51 +214,51 @@ void p3GxsMails::handleResponse(uint32_t token, uint32_t req_type)
|
||||
break;
|
||||
}
|
||||
default:
|
||||
std::cerr << "p3GxsMails::handleResponse(...) Unknown req_type: "
|
||||
std::cerr << "p3GxsTrans::handleResponse(...) Unknown req_type: "
|
||||
<< req_type << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void p3GxsMails::service_tick()
|
||||
void p3GxsTrans::service_tick()
|
||||
{
|
||||
GxsTokenQueue::checkRequests();
|
||||
|
||||
{
|
||||
RS_STACK_MUTEX(outgoingMutex);
|
||||
for ( auto it = outgoingQueue.begin(); it != outgoingQueue.end(); )
|
||||
RS_STACK_MUTEX(mOutgoingMutex);
|
||||
for ( auto it = mOutgoingQueue.begin(); it != mOutgoingQueue.end(); )
|
||||
{
|
||||
OutgoingRecord& pr(it->second);
|
||||
GxsMailStatus oldStatus = pr.status;
|
||||
GxsTransSendStatus oldStatus = pr.status;
|
||||
processOutgoingRecord(pr);
|
||||
if (oldStatus != pr.status) notifyClientService(pr);
|
||||
if( pr.status >= GxsMailStatus::RECEIPT_RECEIVED )
|
||||
it = outgoingQueue.erase(it);
|
||||
if( pr.status >= GxsTransSendStatus::RECEIPT_RECEIVED )
|
||||
it = mOutgoingQueue.erase(it);
|
||||
else ++it;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
RS_STACK_MUTEX(ingoingMutex);
|
||||
for( auto it = ingoingQueue.begin(); it != ingoingQueue.end(); )
|
||||
RS_STACK_MUTEX(mIngoingMutex);
|
||||
for( auto it = mIngoingQueue.begin(); it != mIngoingQueue.end(); )
|
||||
{
|
||||
switch(static_cast<GxsMailItemsSubtypes>(
|
||||
switch(static_cast<GxsTransItemsSubtypes>(
|
||||
it->second->PacketSubType()))
|
||||
{
|
||||
case GxsMailItemsSubtypes::GXS_MAIL_SUBTYPE_MAIL:
|
||||
case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_MAIL:
|
||||
{
|
||||
RsGxsMailItem* msg = dynamic_cast<RsGxsMailItem*>(it->second);
|
||||
RsGxsTransMailItem* msg = dynamic_cast<RsGxsTransMailItem*>(it->second);
|
||||
if(!msg)
|
||||
{
|
||||
std::cerr << "p3GxsMails::service_tick() (EE) "
|
||||
std::cerr << "p3GxsTrans::service_tick() (EE) "
|
||||
<< "GXS_MAIL_SUBTYPE_MAIL dynamic_cast failed, "
|
||||
<< "something really wrong is happening!"
|
||||
<< std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "p3GxsMails::service_tick() "
|
||||
std::cout << "p3GxsTrans::service_tick() "
|
||||
<< "GXS_MAIL_SUBTYPE_MAIL handling: "
|
||||
<< msg->meta.mMsgId
|
||||
<< " with cryptoType: "
|
||||
@ -270,18 +271,18 @@ void p3GxsMails::service_tick()
|
||||
}
|
||||
break;
|
||||
}
|
||||
case GxsMailItemsSubtypes::GXS_MAIL_SUBTYPE_RECEIPT:
|
||||
case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_RECEIPT:
|
||||
{
|
||||
RsGxsMailPresignedReceipt* rcpt =
|
||||
dynamic_cast<RsGxsMailPresignedReceipt*>(it->second);
|
||||
RsGxsTransPresignedReceipt* rcpt =
|
||||
dynamic_cast<RsGxsTransPresignedReceipt*>(it->second);
|
||||
if(!rcpt)
|
||||
{
|
||||
std::cerr << "p3GxsMails::service_tick() (EE) "
|
||||
std::cerr << "p3GxsTrans::service_tick() (EE) "
|
||||
<< "GXS_MAIL_SUBTYPE_RECEIPT dynamic_cast failed,"
|
||||
<< " something really wrong is happening!"
|
||||
<< std::endl;
|
||||
}
|
||||
else if(idService.isOwnId(rcpt->meta.mAuthorId))
|
||||
else if(mIdService.isOwnId(rcpt->meta.mAuthorId))
|
||||
{
|
||||
/* It is a receipt for a mail sent by this node live it in
|
||||
* ingoingQueue so processOutgoingRecord(...) will take care
|
||||
@ -298,27 +299,27 @@ void p3GxsMails::service_tick()
|
||||
break;
|
||||
}
|
||||
default:
|
||||
std::cerr << "p3GxsMails::service_tick() (EE) got something "
|
||||
std::cerr << "p3GxsTrans::service_tick() (EE) got something "
|
||||
<< "really unknown into ingoingQueue!!" << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
delete it->second; it = ingoingQueue.erase(it);
|
||||
delete it->second; it = mIngoingQueue.erase(it);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RsGenExchange::ServiceCreate_Return p3GxsMails::service_CreateGroup(
|
||||
RsGenExchange::ServiceCreate_Return p3GxsTrans::service_CreateGroup(
|
||||
RsGxsGrpItem* grpItem, RsTlvSecurityKeySet& /*keySet*/ )
|
||||
{
|
||||
std::cout << "p3GxsMails::service_CreateGroup(...) "
|
||||
std::cout << "p3GxsTrans::service_CreateGroup(...) "
|
||||
<< grpItem->meta.mGroupId << std::endl;
|
||||
return SERVICE_CREATE_SUCCESS;
|
||||
}
|
||||
|
||||
void p3GxsMails::notifyChanges(std::vector<RsGxsNotify*>& changes)
|
||||
void p3GxsTrans::notifyChanges(std::vector<RsGxsNotify*>& changes)
|
||||
{
|
||||
std::cout << "p3GxsMails::notifyChanges(...)" << std::endl;
|
||||
std::cout << "p3GxsTrans::notifyChanges(...)" << std::endl;
|
||||
for( std::vector<RsGxsNotify*>::const_iterator it = changes.begin();
|
||||
it != changes.end(); ++it )
|
||||
{
|
||||
@ -327,12 +328,12 @@ void p3GxsMails::notifyChanges(std::vector<RsGxsNotify*>& changes)
|
||||
|
||||
if (grpChange)
|
||||
{
|
||||
std::cout << "p3GxsMails::notifyChanges(...) grpChange" << std::endl;
|
||||
std::cout << "p3GxsTrans::notifyChanges(...) grpChange" << std::endl;
|
||||
requestGroupsData(&(grpChange->mGrpIdList));
|
||||
}
|
||||
else if(msgChange)
|
||||
{
|
||||
std::cout << "p3GxsMails::notifyChanges(...) msgChange" << std::endl;
|
||||
std::cout << "p3GxsTrans::notifyChanges(...) msgChange" << std::endl;
|
||||
uint32_t token;
|
||||
RsTokReqOptions opts; opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA;
|
||||
getTokenService()->requestMsgInfo( token, 0xcaca,
|
||||
@ -348,7 +349,7 @@ void p3GxsMails::notifyChanges(std::vector<RsGxsNotify*>& changes)
|
||||
for(itT vit = msgsIds.begin(); vit != msgsIds.end(); ++vit)
|
||||
{
|
||||
const RsGxsMessageId& msgId = *vit;
|
||||
std::cout << "p3GxsMails::notifyChanges(...) got "
|
||||
std::cout << "p3GxsTrans::notifyChanges(...) got "
|
||||
<< "notification for message " << msgId
|
||||
<< " in group " << grpId << std::endl;
|
||||
}
|
||||
@ -357,7 +358,7 @@ void p3GxsMails::notifyChanges(std::vector<RsGxsNotify*>& changes)
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t p3GxsMails::AuthenPolicy()
|
||||
uint32_t p3GxsTrans::AuthenPolicy()
|
||||
{
|
||||
uint32_t policy = 0;
|
||||
uint32_t flag = 0;
|
||||
@ -386,9 +387,9 @@ uint32_t p3GxsMails::AuthenPolicy()
|
||||
return policy;
|
||||
}
|
||||
|
||||
bool p3GxsMails::requestGroupsData(const std::list<RsGxsGroupId>* groupIds)
|
||||
bool p3GxsTrans::requestGroupsData(const std::list<RsGxsGroupId>* groupIds)
|
||||
{
|
||||
// std::cout << "p3GxsMails::requestGroupsList()" << std::endl;
|
||||
// std::cout << "p3GxsTrans::requestGroupsList()" << std::endl;
|
||||
uint32_t token;
|
||||
RsTokReqOptions opts; opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
|
||||
if(!groupIds) getTokenService()->requestGroupInfo(token, 0xcaca, opts);
|
||||
@ -397,26 +398,26 @@ bool p3GxsMails::requestGroupsData(const std::list<RsGxsGroupId>* groupIds)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3GxsMails::handleEcryptedMail(const RsGxsMailItem* mail)
|
||||
bool p3GxsTrans::handleEcryptedMail(const RsGxsTransMailItem* mail)
|
||||
{
|
||||
std::cout << "p3GxsMails::handleEcryptedMail(...)" << std::endl;
|
||||
std::cout << "p3GxsTrans::handleEcryptedMail(...)" << std::endl;
|
||||
|
||||
std::set<RsGxsId> decryptIds;
|
||||
std::list<RsGxsId> ownIds;
|
||||
idService.getOwnIds(ownIds);
|
||||
mIdService.getOwnIds(ownIds);
|
||||
for(auto it = ownIds.begin(); it != ownIds.end(); ++it)
|
||||
if(mail->maybeRecipient(*it)) decryptIds.insert(*it);
|
||||
|
||||
// Hint match none of our own ids
|
||||
if(decryptIds.empty())
|
||||
{
|
||||
std::cout << "p3GxsMails::handleEcryptedMail(...) hint doesn't match" << std::endl;
|
||||
std::cout << "p3GxsTrans::handleEcryptedMail(...) hint doesn't match" << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (mail->cryptoType)
|
||||
{
|
||||
case RsGxsMailEncryptionMode::CLEAR_TEXT:
|
||||
case RsGxsTransEncryptionMode::CLEAR_TEXT:
|
||||
{
|
||||
uint16_t csri = 0;
|
||||
uint32_t off = 0;
|
||||
@ -428,7 +429,7 @@ bool p3GxsMails::handleEcryptedMail(const RsGxsMailItem* mail)
|
||||
return dispatchDecryptedMail( mail->meta.mAuthorId, mail->recipientHint,
|
||||
&mail->payload[0], mail->payload.size() );
|
||||
}
|
||||
case RsGxsMailEncryptionMode::RSA:
|
||||
case RsGxsTransEncryptionMode::RSA:
|
||||
{
|
||||
bool ok = true;
|
||||
for( std::set<RsGxsId>::const_iterator it = decryptIds.begin();
|
||||
@ -438,7 +439,7 @@ bool p3GxsMails::handleEcryptedMail(const RsGxsMailItem* mail)
|
||||
uint8_t* decrypted_data = NULL;
|
||||
uint32_t decrypted_data_size = 0;
|
||||
uint32_t decryption_error;
|
||||
if( idService.decryptData( &mail->payload[0],
|
||||
if( mIdService.decryptData( &mail->payload[0],
|
||||
mail->payload.size(), decrypted_data,
|
||||
decrypted_data_size, decryptId,
|
||||
decryption_error ) )
|
||||
@ -456,108 +457,108 @@ bool p3GxsMails::handleEcryptedMail(const RsGxsMailItem* mail)
|
||||
}
|
||||
}
|
||||
|
||||
bool p3GxsMails::dispatchDecryptedMail( const RsGxsId& authorId,
|
||||
bool p3GxsTrans::dispatchDecryptedMail( const RsGxsId& authorId,
|
||||
const RsGxsId& decryptId,
|
||||
const uint8_t* decrypted_data,
|
||||
uint32_t decrypted_data_size )
|
||||
{
|
||||
std::cout << "p3GxsMails::dispatchDecryptedMail(, , " << decrypted_data_size
|
||||
std::cout << "p3GxsTrans::dispatchDecryptedMail(, , " << decrypted_data_size
|
||||
<< ")" << std::endl;
|
||||
|
||||
uint16_t csri = 0;
|
||||
uint32_t offset = 0;
|
||||
if(!getRawUInt16( decrypted_data, decrypted_data_size, &offset, &csri))
|
||||
{
|
||||
std::cerr << "p3GxsMails::dispatchDecryptedMail(...) (EE) fatal error "
|
||||
std::cerr << "p3GxsTrans::dispatchDecryptedMail(...) (EE) fatal error "
|
||||
<< "deserializing service type, something really wrong is "
|
||||
<< "happening!" << std::endl;
|
||||
return false;
|
||||
}
|
||||
GxsMailSubServices rsrvc = static_cast<GxsMailSubServices>(csri);
|
||||
GxsTransSubServices rsrvc = static_cast<GxsTransSubServices>(csri);
|
||||
|
||||
RsNxsMailPresignedReceipt* receipt = new RsNxsMailPresignedReceipt();
|
||||
RsNxsTransPresignedReceipt* receipt = new RsNxsTransPresignedReceipt();
|
||||
uint32_t rcptsize = decrypted_data_size;
|
||||
if(!receipt->deserialize(decrypted_data, rcptsize, offset))
|
||||
{
|
||||
std::cerr << "p3GxsMails::dispatchDecryptedMail(...) (EE) fatal error "
|
||||
std::cerr << "p3GxsTrans::dispatchDecryptedMail(...) (EE) fatal error "
|
||||
<< "deserializing presigned return receipt , something really"
|
||||
<< " wrong is happening!" << std::endl;
|
||||
delete receipt;
|
||||
return false;
|
||||
}
|
||||
std::cout << "p3GxsMails::dispatchDecryptedMail(...) dispatching receipt "
|
||||
std::cout << "p3GxsTrans::dispatchDecryptedMail(...) dispatching receipt "
|
||||
<< "with: msgId: " << receipt->msgId << std::endl;
|
||||
|
||||
std::vector<RsNxsMsg*> rcct; rcct.push_back(receipt);
|
||||
RsGenExchange::notifyNewMessages(rcct);
|
||||
|
||||
GxsMailsClient* recipientService = NULL;
|
||||
GxsTransClient* recipientService = NULL;
|
||||
{
|
||||
RS_STACK_MUTEX(servClientsMutex);
|
||||
recipientService = servClients[rsrvc];
|
||||
RS_STACK_MUTEX(mServClientsMutex);
|
||||
recipientService = mServClients[rsrvc];
|
||||
}
|
||||
|
||||
if(recipientService)
|
||||
return recipientService->receiveGxsMail( authorId, decryptId,
|
||||
&decrypted_data[offset],
|
||||
decrypted_data_size-offset );
|
||||
return recipientService->receiveGxsTransMail(
|
||||
authorId, decryptId, &decrypted_data[offset],
|
||||
decrypted_data_size-offset );
|
||||
else
|
||||
{
|
||||
std::cerr << "p3GxsMails::dispatchReceivedMail(...) "
|
||||
std::cerr << "p3GxsTrans::dispatchReceivedMail(...) "
|
||||
<< "got message for unknown service: "
|
||||
<< csri << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void p3GxsMails::processOutgoingRecord(OutgoingRecord& pr)
|
||||
void p3GxsTrans::processOutgoingRecord(OutgoingRecord& pr)
|
||||
{
|
||||
//std::cout << "p3GxsMails::processRecord(...)" << std::endl;
|
||||
//std::cout << "p3GxsTrans::processRecord(...)" << std::endl;
|
||||
|
||||
switch (pr.status)
|
||||
{
|
||||
case GxsMailStatus::PENDING_PROCESSING:
|
||||
case GxsTransSendStatus::PENDING_PROCESSING:
|
||||
{
|
||||
pr.mailItem.saltRecipientHint(pr.recipient);
|
||||
pr.mailItem.saltRecipientHint(RsGxsId::random());
|
||||
}
|
||||
case GxsMailStatus::PENDING_PREFERRED_GROUP:
|
||||
case GxsTransSendStatus::PENDING_PREFERRED_GROUP:
|
||||
{
|
||||
if(preferredGroupId.isNull())
|
||||
if(mPreferredGroupId.isNull())
|
||||
{
|
||||
requestGroupsData();
|
||||
pr.status = GxsMailStatus::PENDING_PREFERRED_GROUP;
|
||||
pr.status = GxsTransSendStatus::PENDING_PREFERRED_GROUP;
|
||||
break;
|
||||
}
|
||||
|
||||
pr.mailItem.meta.mGroupId = preferredGroupId;
|
||||
pr.mailItem.meta.mGroupId = mPreferredGroupId;
|
||||
}
|
||||
case GxsMailStatus::PENDING_RECEIPT_CREATE:
|
||||
case GxsTransSendStatus::PENDING_RECEIPT_CREATE:
|
||||
{
|
||||
RsGxsMailPresignedReceipt grcpt;
|
||||
RsGxsTransPresignedReceipt grcpt;
|
||||
grcpt.meta = pr.mailItem.meta;
|
||||
grcpt.meta.mPublishTs = time(NULL);
|
||||
grcpt.mailId = pr.mailItem.mailId;
|
||||
uint32_t groff = 0, grsz = grcpt.size();
|
||||
uint32_t groff = 0, grsz = grcpt.serial_size();
|
||||
std::vector<uint8_t> grsrz;
|
||||
grsrz.resize(grsz);
|
||||
grcpt.serialize(&grsrz[0], grsz, groff);
|
||||
|
||||
pr.presignedReceipt.grpId = preferredGroupId;
|
||||
pr.presignedReceipt.grpId = mPreferredGroupId;
|
||||
pr.presignedReceipt.metaData = new RsGxsMsgMetaData();
|
||||
*pr.presignedReceipt.metaData = grcpt.meta;
|
||||
pr.presignedReceipt.msg.setBinData(&grsrz[0], grsz);
|
||||
}
|
||||
case GxsMailStatus::PENDING_RECEIPT_SIGNATURE:
|
||||
case GxsTransSendStatus::PENDING_RECEIPT_SIGNATURE:
|
||||
{
|
||||
switch (RsGenExchange::createMessage(&pr.presignedReceipt))
|
||||
{
|
||||
case CREATE_SUCCESS: break;
|
||||
case CREATE_FAIL_TRY_LATER:
|
||||
pr.status = GxsMailStatus::PENDING_RECEIPT_CREATE;
|
||||
pr.status = GxsTransSendStatus::PENDING_RECEIPT_CREATE;
|
||||
return;
|
||||
default:
|
||||
pr.status = GxsMailStatus::FAILED_RECEIPT_SIGNATURE;
|
||||
pr.status = GxsTransSendStatus::FAILED_RECEIPT_SIGNATURE;
|
||||
goto processingFailed;
|
||||
}
|
||||
|
||||
@ -566,7 +567,7 @@ void p3GxsMails::processOutgoingRecord(OutgoingRecord& pr)
|
||||
pr.presignedReceipt.metaData->serialise(&srx[0], &metaSize);
|
||||
pr.presignedReceipt.meta.setBinData(&srx[0], metaSize);
|
||||
}
|
||||
case GxsMailStatus::PENDING_PAYLOAD_CREATE:
|
||||
case GxsTransSendStatus::PENDING_PAYLOAD_CREATE:
|
||||
{
|
||||
uint16_t serv = static_cast<uint16_t>(pr.clientService);
|
||||
uint32_t rcptsize = pr.presignedReceipt.serial_size();
|
||||
@ -579,23 +580,23 @@ void p3GxsMails::processOutgoingRecord(OutgoingRecord& pr)
|
||||
offset += rcptsize;
|
||||
memcpy(&pr.mailItem.payload[offset], &pr.mailData[0], datasize);
|
||||
}
|
||||
case GxsMailStatus::PENDING_PAYLOAD_ENCRYPT:
|
||||
case GxsTransSendStatus::PENDING_PAYLOAD_ENCRYPT:
|
||||
{
|
||||
switch (pr.mailItem.cryptoType)
|
||||
{
|
||||
case RsGxsMailEncryptionMode::CLEAR_TEXT:
|
||||
case RsGxsTransEncryptionMode::CLEAR_TEXT:
|
||||
{
|
||||
std::cerr << "p3GxsMails::sendMail(...) you are sending a mail "
|
||||
std::cerr << "p3GxsTrans::sendMail(...) you are sending a mail "
|
||||
<< "without encryption, everyone can read it!"
|
||||
<< std::endl;
|
||||
break;
|
||||
}
|
||||
case RsGxsMailEncryptionMode::RSA:
|
||||
case RsGxsTransEncryptionMode::RSA:
|
||||
{
|
||||
uint8_t* encryptedData = NULL;
|
||||
uint32_t encryptedSize = 0;
|
||||
uint32_t encryptError = 0;
|
||||
if( idService.encryptData( &pr.mailItem.payload[0],
|
||||
if( mIdService.encryptData( &pr.mailItem.payload[0],
|
||||
pr.mailItem.payload.size(),
|
||||
encryptedData, encryptedSize,
|
||||
pr.recipient, encryptError, true ) )
|
||||
@ -608,25 +609,25 @@ void p3GxsMails::processOutgoingRecord(OutgoingRecord& pr)
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "p3GxsMails::sendMail(...) RSA encryption failed! "
|
||||
std::cerr << "p3GxsTrans::sendMail(...) RSA encryption failed! "
|
||||
<< "error_status: " << encryptError << std::endl;
|
||||
pr.status = GxsMailStatus::FAILED_ENCRYPTION;
|
||||
pr.status = GxsTransSendStatus::FAILED_ENCRYPTION;
|
||||
goto processingFailed;
|
||||
}
|
||||
}
|
||||
case RsGxsMailEncryptionMode::UNDEFINED_ENCRYPTION:
|
||||
case RsGxsTransEncryptionMode::UNDEFINED_ENCRYPTION:
|
||||
default:
|
||||
std::cerr << "p3GxsMails::sendMail(...) attempt to send mail with "
|
||||
std::cerr << "p3GxsTrans::sendMail(...) attempt to send mail with "
|
||||
<< "wrong EncryptionMode: "
|
||||
<< static_cast<uint>(pr.mailItem.cryptoType)
|
||||
<< " dropping mail!" << std::endl;
|
||||
pr.status = GxsMailStatus::FAILED_ENCRYPTION;
|
||||
pr.status = GxsTransSendStatus::FAILED_ENCRYPTION;
|
||||
goto processingFailed;
|
||||
}
|
||||
}
|
||||
case GxsMailStatus::PENDING_PUBLISH:
|
||||
case GxsTransSendStatus::PENDING_PUBLISH:
|
||||
{
|
||||
std::cout << "p3GxsMails::sendEmail(...) sending mail to: "
|
||||
std::cout << "p3GxsTrans::sendEmail(...) sending mail to: "
|
||||
<< pr.recipient
|
||||
<< " with cryptoType: "
|
||||
<< static_cast<uint>(pr.mailItem.cryptoType)
|
||||
@ -636,38 +637,38 @@ void p3GxsMails::processOutgoingRecord(OutgoingRecord& pr)
|
||||
<< std::endl;
|
||||
|
||||
uint32_t token;
|
||||
publishMsg(token, new RsGxsMailItem(pr.mailItem));
|
||||
pr.status = GxsMailStatus::PENDING_RECEIPT_RECEIVE;
|
||||
publishMsg(token, new RsGxsTransMailItem(pr.mailItem));
|
||||
pr.status = GxsTransSendStatus::PENDING_RECEIPT_RECEIVE;
|
||||
break;
|
||||
}
|
||||
//case GxsMailStatus::PENDING_TRANSFER:
|
||||
case GxsMailStatus::PENDING_RECEIPT_RECEIVE:
|
||||
//case GxsTransSendStatus::PENDING_TRANSFER:
|
||||
case GxsTransSendStatus::PENDING_RECEIPT_RECEIVE:
|
||||
{
|
||||
RS_STACK_MUTEX(ingoingMutex);
|
||||
auto range = ingoingQueue.equal_range(pr.mailItem.mailId);
|
||||
RS_STACK_MUTEX(mIngoingMutex);
|
||||
auto range = mIngoingQueue.equal_range(pr.mailItem.mailId);
|
||||
for( auto it = range.first; it != range.second; ++it)
|
||||
{
|
||||
RsGxsMailPresignedReceipt* rt =
|
||||
dynamic_cast<RsGxsMailPresignedReceipt*>(it->second);
|
||||
if(rt && idService.isOwnId(rt->meta.mAuthorId))
|
||||
RsGxsTransPresignedReceipt* rt =
|
||||
dynamic_cast<RsGxsTransPresignedReceipt*>(it->second);
|
||||
if(rt && mIdService.isOwnId(rt->meta.mAuthorId))
|
||||
{
|
||||
ingoingQueue.erase(it); delete rt;
|
||||
pr.status = GxsMailStatus::RECEIPT_RECEIVED;
|
||||
mIngoingQueue.erase(it); delete rt;
|
||||
pr.status = GxsTransSendStatus::RECEIPT_RECEIVED;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// TODO: Resend message if older then treshold
|
||||
break;
|
||||
}
|
||||
case GxsMailStatus::RECEIPT_RECEIVED:
|
||||
case GxsTransSendStatus::RECEIPT_RECEIVED:
|
||||
break;
|
||||
|
||||
processingFailed:
|
||||
case GxsMailStatus::FAILED_RECEIPT_SIGNATURE:
|
||||
case GxsMailStatus::FAILED_ENCRYPTION:
|
||||
case GxsTransSendStatus::FAILED_RECEIPT_SIGNATURE:
|
||||
case GxsTransSendStatus::FAILED_ENCRYPTION:
|
||||
default:
|
||||
{
|
||||
std::cout << "p3GxsMails::processRecord(" << pr.mailItem.mailId
|
||||
std::cout << "p3GxsTrans::processRecord(" << pr.mailItem.mailId
|
||||
<< ") failed with: " << static_cast<uint>(pr.status)
|
||||
<< std::endl;
|
||||
break;
|
||||
@ -675,21 +676,21 @@ processingFailed:
|
||||
}
|
||||
}
|
||||
|
||||
void p3GxsMails::notifyClientService(const OutgoingRecord& pr)
|
||||
void p3GxsTrans::notifyClientService(const OutgoingRecord& pr)
|
||||
{
|
||||
RS_STACK_MUTEX(servClientsMutex);
|
||||
auto it = servClients.find(pr.clientService);
|
||||
if( it != servClients.end())
|
||||
RS_STACK_MUTEX(mServClientsMutex);
|
||||
auto it = mServClients.find(pr.clientService);
|
||||
if( it != mServClients.end())
|
||||
{
|
||||
GxsMailsClient* serv(it->second);
|
||||
GxsTransClient* serv(it->second);
|
||||
if(serv)
|
||||
{
|
||||
serv->notifySendMailStatus(pr.mailItem, pr.status);
|
||||
serv->notifyGxsTransSendStatus(pr.mailItem.mailId, pr.status);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
std::cerr << "p3GxsMails::processRecord(...) (EE) processed"
|
||||
std::cerr << "p3GxsTrans::processRecord(...) (EE) processed"
|
||||
<< " mail for unkown service: "
|
||||
<< static_cast<uint32_t>(pr.clientService)
|
||||
<< " fatally failed with: "
|
||||
@ -697,74 +698,74 @@ void p3GxsMails::notifyClientService(const OutgoingRecord& pr)
|
||||
print_stacktrace();
|
||||
}
|
||||
|
||||
RsSerialiser* p3GxsMails::setupSerialiser()
|
||||
RsSerialiser* p3GxsTrans::setupSerialiser()
|
||||
{
|
||||
RsSerialiser* rss = new RsSerialiser;
|
||||
rss->addSerialType(new RsGxsMailSerializer);
|
||||
rss->addSerialType(new RsGxsTransSerializer);
|
||||
return rss;
|
||||
}
|
||||
|
||||
bool p3GxsMails::saveList(bool &cleanup, std::list<RsItem *>& saveList)
|
||||
bool p3GxsTrans::saveList(bool &cleanup, std::list<RsItem *>& saveList)
|
||||
{
|
||||
std::cout << "p3GxsMails::saveList(...)" << saveList.size() << " "
|
||||
<< ingoingQueue.size() << " " << outgoingQueue.size()
|
||||
std::cout << "p3GxsTrans::saveList(...)" << saveList.size() << " "
|
||||
<< mIngoingQueue.size() << " " << mOutgoingQueue.size()
|
||||
<< std::endl;
|
||||
|
||||
outgoingMutex.lock();
|
||||
ingoingMutex.lock();
|
||||
mOutgoingMutex.lock();
|
||||
mIngoingMutex.lock();
|
||||
|
||||
for ( auto& kv : outgoingQueue ) saveList.push_back(&kv.second);
|
||||
for ( auto& kv : ingoingQueue ) saveList.push_back(kv.second);
|
||||
for ( auto& kv : mOutgoingQueue ) saveList.push_back(&kv.second);
|
||||
for ( auto& kv : mIngoingQueue ) saveList.push_back(kv.second);
|
||||
|
||||
std::cout << "p3GxsMails::saveList(...)" << saveList.size() << " "
|
||||
<< ingoingQueue.size() << " " << outgoingQueue.size()
|
||||
std::cout << "p3GxsTrans::saveList(...)" << saveList.size() << " "
|
||||
<< mIngoingQueue.size() << " " << mOutgoingQueue.size()
|
||||
<< std::endl;
|
||||
|
||||
cleanup = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void p3GxsMails::saveDone()
|
||||
void p3GxsTrans::saveDone()
|
||||
{
|
||||
outgoingMutex.unlock();
|
||||
ingoingMutex.unlock();
|
||||
mOutgoingMutex.unlock();
|
||||
mIngoingMutex.unlock();
|
||||
}
|
||||
|
||||
bool p3GxsMails::loadList(std::list<RsItem *>&loadList)
|
||||
bool p3GxsTrans::loadList(std::list<RsItem *>&loadList)
|
||||
{
|
||||
std::cout << "p3GxsMails::loadList(...) " << loadList.size() << " "
|
||||
<< ingoingQueue.size() << " " << outgoingQueue.size()
|
||||
std::cout << "p3GxsTrans::loadList(...) " << loadList.size() << " "
|
||||
<< mIngoingQueue.size() << " " << mOutgoingQueue.size()
|
||||
<< std::endl;
|
||||
|
||||
for(auto& v : loadList)
|
||||
switch(static_cast<GxsMailItemsSubtypes>(v->PacketSubType()))
|
||||
switch(static_cast<GxsTransItemsSubtypes>(v->PacketSubType()))
|
||||
{
|
||||
case GxsMailItemsSubtypes::GXS_MAIL_SUBTYPE_MAIL:
|
||||
case GxsMailItemsSubtypes::GXS_MAIL_SUBTYPE_RECEIPT:
|
||||
case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_MAIL:
|
||||
case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_RECEIPT:
|
||||
{
|
||||
RsGxsMailBaseItem* mi = dynamic_cast<RsGxsMailBaseItem*>(v);
|
||||
RsGxsTransBaseItem* mi = dynamic_cast<RsGxsTransBaseItem*>(v);
|
||||
if(mi)
|
||||
{
|
||||
RS_STACK_MUTEX(ingoingMutex);
|
||||
ingoingQueue.insert(inMap::value_type(mi->mailId, mi));
|
||||
RS_STACK_MUTEX(mIngoingMutex);
|
||||
mIngoingQueue.insert(inMap::value_type(mi->mailId, mi));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case GxsMailItemsSubtypes::OUTGOING_RECORD_ITEM:
|
||||
case GxsTransItemsSubtypes::OUTGOING_RECORD_ITEM:
|
||||
{
|
||||
OutgoingRecord* ot = dynamic_cast<OutgoingRecord*>(v);
|
||||
if(ot)
|
||||
{
|
||||
RS_STACK_MUTEX(outgoingMutex);
|
||||
outgoingQueue.insert(
|
||||
RS_STACK_MUTEX(mOutgoingMutex);
|
||||
mOutgoingQueue.insert(
|
||||
prMap::value_type(ot->mailItem.mailId, *ot));
|
||||
}
|
||||
delete v;
|
||||
break;
|
||||
}
|
||||
case GxsMailItemsSubtypes::GXS_MAIL_SUBTYPE_GROUP:
|
||||
case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_GROUP:
|
||||
default:
|
||||
std::cerr << "p3GxsMails::loadList(...) (EE) got item with "
|
||||
std::cerr << "p3GxsTrans::loadList(...) (EE) got item with "
|
||||
<< "unhandled type: "
|
||||
<< static_cast<uint>(v->PacketSubType())
|
||||
<< std::endl;
|
||||
@ -772,8 +773,8 @@ bool p3GxsMails::loadList(std::list<RsItem *>&loadList)
|
||||
break;
|
||||
}
|
||||
|
||||
std::cout << "p3GxsMails::loadList(...) " << loadList.size() << " "
|
||||
<< ingoingQueue.size() << " " << outgoingQueue.size()
|
||||
std::cout << "p3GxsTrans::loadList(...) " << loadList.size() << " "
|
||||
<< mIngoingQueue.size() << " " << mOutgoingQueue.size()
|
||||
<< std::endl;
|
||||
|
||||
return true;
|
@ -23,102 +23,103 @@
|
||||
|
||||
#include "retroshare/rsgxsifacetypes.h" // For RsGxsId, RsGxsCircleId
|
||||
#include "gxs/gxstokenqueue.h" // For GxsTokenQueue
|
||||
#include "serialiser/rsgxsmailitems.h" // For RS_SERVICE_TYPE_GXS_MAIL
|
||||
#include "gxstrans/p3gxstransitems.h"
|
||||
#include "services/p3idservice.h" // For p3IdService
|
||||
#include "util/rsthreads.h"
|
||||
|
||||
struct p3GxsMails;
|
||||
struct p3GxsTrans;
|
||||
|
||||
/// Services who want to make use of p3GxsMails should inherit this struct
|
||||
struct GxsMailsClient
|
||||
/// Services who want to make use of p3GxsTrans should inherit this struct
|
||||
struct GxsTransClient
|
||||
{
|
||||
/**
|
||||
* This will be called by p3GxsMails to dispatch mails to the subservice
|
||||
* This will be called by p3GxsTrans to dispatch mails to the subservice
|
||||
* @param authorId message sender
|
||||
* @param decryptId recipient id
|
||||
* @param data buffer containing the decrypted data
|
||||
* @param dataSize size of the buffer
|
||||
* @return true if dispatching goes fine, false otherwise
|
||||
*/
|
||||
virtual bool receiveGxsMail( const RsGxsId& authorId,
|
||||
const RsGxsId& recipientId,
|
||||
const uint8_t* data, uint32_t dataSize ) = 0;
|
||||
virtual bool receiveGxsTransMail( const RsGxsId& authorId,
|
||||
const RsGxsId& recipientId,
|
||||
const uint8_t* data, uint32_t dataSize
|
||||
) = 0;
|
||||
|
||||
/**
|
||||
* This will be called by p3GxsMails to notify the subservice about the
|
||||
* This will be called by p3GxsTrans to notify the subservice about the
|
||||
* status of a sent email.
|
||||
* @param originalMessage message for with the notification is made
|
||||
* @param status the new status of the message
|
||||
* @return true if notification goes fine, false otherwise (ignored ATM)
|
||||
*/
|
||||
virtual bool notifySendMailStatus( const RsGxsMailItem& originalMessage,
|
||||
GxsMailStatus status ) = 0;
|
||||
virtual bool notifyGxsTransSendStatus( RsGxsTransId mailId,
|
||||
GxsTransSendStatus status ) = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief p3GxsMails is a mail delivery service based on GXS.
|
||||
* p3GxsMails is capable of asynchronous mail delivery and acknowledgement.
|
||||
* p3GxsMails is meant to be capable of multiple encryption options,
|
||||
* @see RsGxsMailEncryptionMode at moment messages are encrypted using RSA
|
||||
* @brief p3GxsTrans is a mail delivery service based on 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
|
||||
* unless the user ask for them being sent in clear text ( this is not supposed
|
||||
* to happen in non testing environment so warnings and stack traces are printed
|
||||
* in the log if an attempt to send something in clear text is made ).
|
||||
* p3GxsMails try to hide metadata so the travelling message signed by the author
|
||||
* p3GxsTrans try to hide metadata so the travelling message signed by the author
|
||||
* but the recipient is not disclosed, instead to avoid everyone trying to
|
||||
* decrypt every message a hint has been introduced, the hint is calculated in a
|
||||
* way that one can easily prove that a message is not destined to someone, but
|
||||
* cannot prove the message is destined to someone
|
||||
* @see RsGxsMailItem::recipientsHint for more details.
|
||||
* p3GxsMails expose a simple API to send and receive mails, the API also
|
||||
* @see RsGxsTransMailItem::recipientHint for more details.
|
||||
* p3GxsTrans expose a simple API to send and receive mails, the API also
|
||||
* provide notification for the sending mail status @see sendMail(...),
|
||||
* @see querySendMailStatus(...), @see registerGxsMailsClient(...),
|
||||
* @see GxsMailsClient::receiveGxsMail(...),
|
||||
* @see GxsMailsClient::notifySendMailStatus(...).
|
||||
* @see querySendStatus(...), @see registerGxsTransClient(...),
|
||||
* @see GxsTransClient::receiveGxsTransMail(...),
|
||||
* @see GxsTransClient::notifyGxsTransSendStatus(...).
|
||||
*/
|
||||
struct p3GxsMails : RsGenExchange, GxsTokenQueue, p3Config
|
||||
struct p3GxsTrans : RsGenExchange, GxsTokenQueue, p3Config
|
||||
{
|
||||
p3GxsMails( RsGeneralDataService* gds, RsNetworkExchangeService* nes,
|
||||
p3GxsTrans( RsGeneralDataService* gds, RsNetworkExchangeService* nes,
|
||||
p3IdService& identities ) :
|
||||
RsGenExchange( gds, nes, new RsGxsMailSerializer(),
|
||||
RS_SERVICE_TYPE_GXS_MAIL, &identities,
|
||||
RsGenExchange( gds, nes, new RsGxsTransSerializer(),
|
||||
RS_SERVICE_TYPE_GXS_TRANS, &identities,
|
||||
AuthenPolicy(), GXS_STORAGE_PERIOD ),
|
||||
GxsTokenQueue(this), idService(identities),
|
||||
servClientsMutex("p3GxsMails client services map mutex"),
|
||||
outgoingMutex("p3GxsMails outgoing queue map mutex"),
|
||||
ingoingMutex("p3GxsMails ingoing queue map mutex") {}
|
||||
~p3GxsMails();
|
||||
GxsTokenQueue(this), mIdService(identities),
|
||||
mServClientsMutex("p3GxsTrans client services map mutex"),
|
||||
mOutgoingMutex("p3GxsTrans outgoing queue map mutex"),
|
||||
mIngoingMutex("p3GxsTrans ingoing queue map mutex") {}
|
||||
~p3GxsTrans();
|
||||
|
||||
/**
|
||||
* Send an email to recipient, in the process author of the email is
|
||||
* disclosed to the network (because the sent GXS item is signed), while
|
||||
* recipient is not @see RsGxsMailBaseItem::recipientsHint for details on
|
||||
* recipient is not @see RsGxsTransMailItem::recipientHint for details on
|
||||
* recipient protection.
|
||||
* This method is part of the public interface of this service.
|
||||
* @return true if the mail will be sent, false if not
|
||||
*/
|
||||
bool sendMail( RsGxsMailId& mailId,
|
||||
GxsMailSubServices service,
|
||||
bool sendMail( RsGxsTransId& mailId,
|
||||
GxsTransSubServices service,
|
||||
const RsGxsId& own_gxsid, const RsGxsId& recipient,
|
||||
const uint8_t* data, uint32_t size,
|
||||
RsGxsMailEncryptionMode cm = RsGxsMailEncryptionMode::RSA
|
||||
RsGxsTransEncryptionMode cm = RsGxsTransEncryptionMode::RSA
|
||||
);
|
||||
|
||||
/**
|
||||
* This method is part of the public interface of this service.
|
||||
* @return false if mail is not found in outgoing queue, true otherwise
|
||||
*/
|
||||
bool querySendMailStatus( RsGxsMailId mailId, GxsMailStatus& st );
|
||||
bool querySendStatus( RsGxsTransId mailId, GxsTransSendStatus& st );
|
||||
|
||||
/**
|
||||
* Register a client service to p3GxsMails to receive mails via
|
||||
* GxsMailsClient::receiveGxsMail(...) callback
|
||||
* Register a client service to p3GxsTrans to receive mails via
|
||||
* GxsTransClient::receiveGxsTransMail(...) callback
|
||||
* This method is part of the public interface of this service.
|
||||
*/
|
||||
void registerGxsMailsClient( GxsMailSubServices serviceType,
|
||||
GxsMailsClient* service );
|
||||
void registerGxsTransClient( GxsTransSubServices serviceType,
|
||||
GxsTransClient* service );
|
||||
|
||||
/// @see RsGenExchange::getServiceInfo()
|
||||
virtual RsServiceInfo getServiceInfo() { return RsServiceInfo( RS_SERVICE_TYPE_GXS_MAIL, "GXS Mails", 0, 1, 0, 1 ); }
|
||||
virtual RsServiceInfo getServiceInfo() { return RsServiceInfo( RS_SERVICE_TYPE_GXS_TRANS, "GXS Mails", 0, 1, 0, 1 ); }
|
||||
|
||||
private:
|
||||
/** Time interval of inactivity before a distribution group is unsubscribed.
|
||||
@ -152,14 +153,14 @@ private:
|
||||
};
|
||||
|
||||
/// Store the id of the preferred GXS group to send emails
|
||||
RsGxsGroupId preferredGroupId;
|
||||
RsGxsGroupId mPreferredGroupId;
|
||||
|
||||
/// Used for items {de,en}cryption
|
||||
p3IdService& idService;
|
||||
p3IdService& mIdService;
|
||||
|
||||
/// Stores pointers to client services to notify them about new mails
|
||||
std::map<GxsMailSubServices, GxsMailsClient*> servClients;
|
||||
RsMutex servClientsMutex;
|
||||
std::map<GxsTransSubServices, GxsTransClient*> mServClients;
|
||||
RsMutex mServClientsMutex;
|
||||
|
||||
/**
|
||||
* @brief Keep track of outgoing mails.
|
||||
@ -167,9 +168,9 @@ private:
|
||||
* receipt has been received or sending is considered definetly failed.
|
||||
* Items are saved in config for consistence accross RetroShare shutdowns.
|
||||
*/
|
||||
typedef std::map<RsGxsMailId, OutgoingRecord> prMap;
|
||||
prMap outgoingQueue;
|
||||
RsMutex outgoingMutex;
|
||||
typedef std::map<RsGxsTransId, OutgoingRecord> prMap;
|
||||
prMap mOutgoingQueue;
|
||||
RsMutex mOutgoingMutex;
|
||||
void processOutgoingRecord(OutgoingRecord& r);
|
||||
|
||||
/**
|
||||
@ -181,9 +182,9 @@ private:
|
||||
* item to not being processed and memleaked multimap is used instead of map
|
||||
* for incoming queue.
|
||||
*/
|
||||
typedef std::unordered_multimap<RsGxsMailId, RsGxsMailBaseItem*> inMap;
|
||||
inMap ingoingQueue;
|
||||
RsMutex ingoingMutex;
|
||||
typedef std::unordered_multimap<RsGxsTransId, RsGxsTransBaseItem*> inMap;
|
||||
inMap mIngoingQueue;
|
||||
RsMutex mIngoingMutex;
|
||||
|
||||
/// @see GxsTokenQueue::handleResponse(uint32_t token, uint32_t req_type)
|
||||
virtual void handleResponse(uint32_t token, uint32_t req_type);
|
||||
@ -223,11 +224,11 @@ private:
|
||||
*/
|
||||
bool inline supersedePreferredGroup(const RsGxsGroupId& potentialGrId)
|
||||
{
|
||||
if(preferredGroupId < potentialGrId)
|
||||
if(mPreferredGroupId < potentialGrId)
|
||||
{
|
||||
std::cerr << "supersedePreferredGroup(...) " << potentialGrId
|
||||
<< " supersed " << preferredGroupId << std::endl;
|
||||
preferredGroupId = potentialGrId;
|
||||
<< " supersed " << mPreferredGroupId << std::endl;
|
||||
mPreferredGroupId = potentialGrId;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -241,7 +242,7 @@ private:
|
||||
|
||||
|
||||
/// Decrypt email content and pass it to dispatchDecryptedMail(...)
|
||||
bool handleEcryptedMail(const RsGxsMailItem* mail);
|
||||
bool handleEcryptedMail(const RsGxsTransMailItem* mail);
|
||||
|
||||
/// Dispatch the message to the recipient service
|
||||
bool dispatchDecryptedMail( const RsGxsId& authorId,
|
||||
@ -252,72 +253,3 @@ private:
|
||||
void notifyClientService(const OutgoingRecord& pr);
|
||||
};
|
||||
|
||||
#ifdef TEST_RS_GXS_MAIL
|
||||
|
||||
struct TestGxsMailClientService : GxsMailsClient, RsSingleJobThread
|
||||
{
|
||||
TestGxsMailClientService( p3GxsMails& gxsMailService,
|
||||
p3IdService& gxsIdService ) :
|
||||
mailService(gxsMailService), idService(gxsIdService)
|
||||
{
|
||||
mailService.registerGxsMailsClient( GxsMailSubServices::TEST_SERVICE,
|
||||
this );
|
||||
}
|
||||
|
||||
/// @see GxsMailsClient::receiveGxsMail(...)
|
||||
virtual bool receiveGxsMail( const RsGxsMailItem& originalMessage,
|
||||
const uint8_t* data, uint32_t dataSize )
|
||||
{
|
||||
std::cout << "TestGxsMailClientService::receiveGxsMail(...) got message"
|
||||
<< " from: " << originalMessage.meta.mAuthorId << std::endl
|
||||
<< "\t>" << std::string((char*)data, dataSize) << "<"
|
||||
<< std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// @see GxsMailsClient::notifyMailStatus(...)
|
||||
virtual bool notifySendMailStatus( const RsGxsMailItem& originalMessage,
|
||||
GxsMailStatus status )
|
||||
{
|
||||
std::cout << "TestGxsMailClientService::notifyMailsStatus(...) for: "
|
||||
<< originalMessage.mailId << " status: "
|
||||
<< static_cast<uint>(status) << std::endl;
|
||||
if( status == GxsMailStatus::RECEIPT_RECEIVED )
|
||||
std::cout << "\t It mean Receipt has been Received!" << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// @see RsSingleJobThread::run()
|
||||
virtual void run()
|
||||
{
|
||||
#if 0
|
||||
usleep(10*1000*1000);
|
||||
RsGxsId gxsidA("d0df7474bdde0464679e6ef787890287");
|
||||
RsGxsId gxsidB("d060bea09dfa14883b5e6e517eb580cd");
|
||||
RsGxsMailId mailId = 0;
|
||||
if(idService.isOwnId(gxsidA))
|
||||
{
|
||||
std::string ciao("CiAone!");
|
||||
mailService.sendMail( mailId, GxsMailSubServices::TEST_SERVICE,
|
||||
gxsidA, gxsidB,
|
||||
reinterpret_cast<const uint8_t*>(ciao.data()),
|
||||
ciao.size() );
|
||||
}
|
||||
else if(idService.isOwnId(gxsidB))
|
||||
{
|
||||
std::string ciao("CiBuono!");
|
||||
mailService.sendMail( mailId, GxsMailSubServices::TEST_SERVICE,
|
||||
gxsidB, gxsidA,
|
||||
reinterpret_cast<const uint8_t*>(ciao.data()),
|
||||
ciao.size() );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
p3GxsMails& mailService;
|
||||
p3IdService& idService;
|
||||
};
|
||||
|
||||
#endif // TEST_RS_GXS_MAIL
|
||||
|
@ -16,12 +16,12 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "serialiser/rsgxsmailitems.h"
|
||||
#include "gxstrans/p3gxstransitems.h"
|
||||
|
||||
const RsGxsId RsGxsMailItem::allRecipientsHint("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
|
||||
const RsGxsId RsGxsTransMailItem::allRecipientsHint("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
|
||||
|
||||
|
||||
bool RsGxsMailBaseItem::serialize(uint8_t* data, uint32_t size,
|
||||
bool RsGxsTransBaseItem::serialize(uint8_t* data, uint32_t size,
|
||||
uint32_t& offset) const
|
||||
{
|
||||
bool ok = setRsItemHeader(data+offset, size, PacketId(), size);
|
||||
@ -30,8 +30,8 @@ bool RsGxsMailBaseItem::serialize(uint8_t* data, uint32_t size,
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool RsGxsMailBaseItem::deserialize(const uint8_t* data, uint32_t& size,
|
||||
uint32_t& offset)
|
||||
bool RsGxsTransBaseItem::deserialize( const uint8_t* data, uint32_t& size,
|
||||
uint32_t& offset)
|
||||
{
|
||||
void* hdrPtr = const_cast<uint8_t*>(data+offset);
|
||||
uint32_t rssize = getRsItemSize(hdrPtr);
|
||||
@ -45,42 +45,42 @@ bool RsGxsMailBaseItem::deserialize(const uint8_t* data, uint32_t& size,
|
||||
return ok;
|
||||
}
|
||||
|
||||
std::ostream& RsGxsMailBaseItem::print(std::ostream &out, uint16_t)
|
||||
{ return out << " RsGxsMailBaseItem::mailId: " << mailId; }
|
||||
std::ostream& RsGxsTransBaseItem::print(std::ostream &out, uint16_t)
|
||||
{ return out << __PRETTY_FUNCTION__ << " mailId: " << mailId; }
|
||||
|
||||
bool RsGxsMailSerializer::serialise(RsItem* item, void* data, uint32_t* size)
|
||||
bool RsGxsTransSerializer::serialise(RsItem* item, void* data, uint32_t* size)
|
||||
{
|
||||
uint32_t itemSize = RsGxsMailSerializer::size(item);
|
||||
uint32_t itemSize = RsGxsTransSerializer::size(item);
|
||||
if(*size < itemSize)
|
||||
{
|
||||
std::cout << "RsGxsMailSerializer::serialise(...) failed due to wrong size: "
|
||||
std::cout << __PRETTY_FUNCTION__ << " failed due to wrong size: "
|
||||
<< size << " < " << itemSize << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t* dataPtr = reinterpret_cast<uint8_t*>(data);
|
||||
bool ok = false;
|
||||
switch(static_cast<GxsMailItemsSubtypes>(item->PacketSubType()))
|
||||
switch(static_cast<GxsTransItemsSubtypes>(item->PacketSubType()))
|
||||
{
|
||||
case GxsMailItemsSubtypes::GXS_MAIL_SUBTYPE_MAIL:
|
||||
case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_MAIL:
|
||||
{
|
||||
uint32_t offset = 0;
|
||||
RsGxsMailItem* i = dynamic_cast<RsGxsMailItem*>(item);
|
||||
RsGxsTransMailItem* i = dynamic_cast<RsGxsTransMailItem*>(item);
|
||||
ok = i && i->serialize(dataPtr, itemSize, offset);
|
||||
break;
|
||||
}
|
||||
case GxsMailItemsSubtypes::GXS_MAIL_SUBTYPE_RECEIPT:
|
||||
case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_RECEIPT:
|
||||
{
|
||||
RsGxsMailPresignedReceipt* i =
|
||||
dynamic_cast<RsGxsMailPresignedReceipt*>(item);
|
||||
RsGxsTransPresignedReceipt* i =
|
||||
dynamic_cast<RsGxsTransPresignedReceipt*>(item);
|
||||
uint32_t offset = 0;
|
||||
ok = i && i->serialize(dataPtr, itemSize, offset);
|
||||
break;
|
||||
}
|
||||
case GxsMailItemsSubtypes::GXS_MAIL_SUBTYPE_GROUP:
|
||||
case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_GROUP:
|
||||
ok = setRsItemHeader(data, itemSize, item->PacketId(), itemSize);
|
||||
break;
|
||||
case GxsMailItemsSubtypes::OUTGOING_RECORD_ITEM:
|
||||
case GxsTransItemsSubtypes::OUTGOING_RECORD_ITEM:
|
||||
{
|
||||
uint32_t offset = 0;
|
||||
OutgoingRecord* i = dynamic_cast<OutgoingRecord*>(item);
|
||||
@ -96,15 +96,15 @@ bool RsGxsMailSerializer::serialise(RsItem* item, void* data, uint32_t* size)
|
||||
return true;
|
||||
}
|
||||
|
||||
std::cout << "RsGxsMailSerializer::serialise(...) failed!" << std::endl;
|
||||
std::cout << __PRETTY_FUNCTION__ << " failed!" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
OutgoingRecord::OutgoingRecord( RsGxsId rec, GxsMailSubServices cs,
|
||||
OutgoingRecord::OutgoingRecord( RsGxsId rec, GxsTransSubServices cs,
|
||||
const uint8_t* data, uint32_t size ) :
|
||||
RsItem( RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_GXS_MAIL,
|
||||
static_cast<uint8_t>(GxsMailItemsSubtypes::OUTGOING_RECORD_ITEM) ),
|
||||
status(GxsMailStatus::PENDING_PROCESSING), recipient(rec),
|
||||
RsItem( RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_GXS_TRANS,
|
||||
static_cast<uint8_t>(GxsTransItemsSubtypes::OUTGOING_RECORD_ITEM) ),
|
||||
status(GxsTransSendStatus::PENDING_PROCESSING), recipient(rec),
|
||||
clientService(cs)
|
||||
{
|
||||
mailData.resize(size);
|
||||
@ -113,11 +113,11 @@ OutgoingRecord::OutgoingRecord( RsGxsId rec, GxsMailSubServices cs,
|
||||
|
||||
void OutgoingRecord::clear()
|
||||
{
|
||||
status = GxsMailStatus::UNKNOWN;
|
||||
status = GxsTransSendStatus::UNKNOWN;
|
||||
recipient.clear();
|
||||
mailItem.clear();
|
||||
mailData.clear();
|
||||
clientService = GxsMailSubServices::UNKNOWN;
|
||||
clientService = GxsTransSubServices::UNKNOWN;
|
||||
presignedReceipt.clear();
|
||||
}
|
||||
|
||||
@ -125,8 +125,8 @@ std::ostream& OutgoingRecord::print(std::ostream& out, uint16_t)
|
||||
{ return out << "TODO: OutgoingRecordItem::print(...)"; }
|
||||
|
||||
OutgoingRecord::OutgoingRecord() :
|
||||
RsItem( RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_GXS_MAIL,
|
||||
static_cast<uint8_t>(GxsMailItemsSubtypes::OUTGOING_RECORD_ITEM) )
|
||||
RsItem( RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_GXS_TRANS,
|
||||
static_cast<uint8_t>(GxsTransItemsSubtypes::OUTGOING_RECORD_ITEM) )
|
||||
{ clear();}
|
||||
|
||||
uint32_t OutgoingRecord::size() const
|
||||
@ -134,7 +134,7 @@ uint32_t OutgoingRecord::size() const
|
||||
return 8 + // Header
|
||||
1 + // status
|
||||
recipient.serial_size() +
|
||||
mailItem.size() +
|
||||
mailItem.serial_size() +
|
||||
4 + // sizeof(mailData.size())
|
||||
mailData.size() +
|
||||
2 + // clientService
|
||||
@ -154,7 +154,7 @@ bool OutgoingRecord::serialize( uint8_t* data, uint32_t size,
|
||||
ok = ok && recipient.serialise(data, size, offset);
|
||||
|
||||
uint32_t tmpOffset = 0;
|
||||
uint32_t tmpSize = mailItem.size();
|
||||
uint32_t tmpSize = mailItem.serial_size();
|
||||
ok = ok && mailItem.serialize(data+offset, tmpSize, tmpOffset)
|
||||
&& (offset += tmpOffset);
|
||||
|
||||
@ -182,7 +182,7 @@ bool OutgoingRecord::deserialize(
|
||||
|
||||
uint8_t tmpStatus = 0;
|
||||
ok = ok && getRawUInt8(dataPtr, size, &offset, &tmpStatus);
|
||||
status = static_cast<GxsMailStatus>(tmpStatus);
|
||||
status = static_cast<GxsTransSendStatus>(tmpStatus);
|
||||
|
||||
uint32_t tmpSize = size;
|
||||
ok = ok && recipient.deserialise(dataPtr, tmpSize, offset);
|
||||
@ -202,7 +202,7 @@ bool OutgoingRecord::deserialize(
|
||||
|
||||
uint16_t cs = 0;
|
||||
ok = ok && getRawUInt16(dataPtr, offset+2, &offset, &cs);
|
||||
clientService = static_cast<GxsMailSubServices>(cs);
|
||||
clientService = static_cast<GxsTransSubServices>(cs);
|
||||
|
||||
tmpSize = size;
|
||||
ok = ok && presignedReceipt.deserialize(data, tmpSize, offset);
|
@ -19,7 +19,7 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "rsgxsitems.h"
|
||||
#include "serialiser/rsgxsitems.h"
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "serialiser/rstlvidset.h"
|
||||
#include "retroshare/rsgxsflags.h"
|
||||
@ -27,7 +27,7 @@
|
||||
#include "services/p3idservice.h"
|
||||
|
||||
/// Subservices identifiers (like port for TCP)
|
||||
enum class GxsMailSubServices : uint16_t
|
||||
enum class GxsTransSubServices : uint16_t
|
||||
{
|
||||
UNKNOWN = 0,
|
||||
TEST_SERVICE = 1,
|
||||
@ -36,28 +36,28 @@ enum class GxsMailSubServices : uint16_t
|
||||
};
|
||||
|
||||
/// Values must fit into uint8_t
|
||||
enum class GxsMailItemsSubtypes : uint8_t
|
||||
enum class GxsTransItemsSubtypes : uint8_t
|
||||
{
|
||||
GXS_MAIL_SUBTYPE_MAIL = 1,
|
||||
GXS_MAIL_SUBTYPE_RECEIPT = 2,
|
||||
GXS_MAIL_SUBTYPE_GROUP = 3,
|
||||
OUTGOING_RECORD_ITEM = 4
|
||||
GXS_TRANS_SUBTYPE_MAIL = 1,
|
||||
GXS_TRANS_SUBTYPE_RECEIPT = 2,
|
||||
GXS_TRANS_SUBTYPE_GROUP = 3,
|
||||
OUTGOING_RECORD_ITEM = 4
|
||||
};
|
||||
|
||||
typedef uint64_t RsGxsMailId;
|
||||
typedef uint64_t RsGxsTransId;
|
||||
|
||||
struct RsNxsMailPresignedReceipt : RsNxsMsg
|
||||
struct RsNxsTransPresignedReceipt : RsNxsMsg
|
||||
{
|
||||
RsNxsMailPresignedReceipt() : RsNxsMsg(RS_SERVICE_TYPE_GXS_MAIL) {}
|
||||
RsNxsTransPresignedReceipt() : RsNxsMsg(RS_SERVICE_TYPE_GXS_TRANS) {}
|
||||
};
|
||||
|
||||
struct RsGxsMailBaseItem : RsGxsMsgItem
|
||||
struct RsGxsTransBaseItem : RsGxsMsgItem
|
||||
{
|
||||
RsGxsMailBaseItem(GxsMailItemsSubtypes subtype) :
|
||||
RsGxsMsgItem( RS_SERVICE_TYPE_GXS_MAIL,
|
||||
RsGxsTransBaseItem(GxsTransItemsSubtypes subtype) :
|
||||
RsGxsMsgItem( RS_SERVICE_TYPE_GXS_TRANS,
|
||||
static_cast<uint8_t>(subtype) ), mailId(0) {}
|
||||
|
||||
RsGxsMailId mailId;
|
||||
RsGxsTransId mailId;
|
||||
|
||||
void inline clear()
|
||||
{
|
||||
@ -65,7 +65,7 @@ struct RsGxsMailBaseItem : RsGxsMsgItem
|
||||
meta = RsMsgMetaData();
|
||||
}
|
||||
|
||||
static uint32_t inline size()
|
||||
static uint32_t inline serial_size()
|
||||
{
|
||||
return 8 + // Header
|
||||
8; // mailId
|
||||
@ -75,29 +75,29 @@ struct RsGxsMailBaseItem : RsGxsMsgItem
|
||||
std::ostream &print(std::ostream &out, uint16_t /*indent = 0*/);
|
||||
};
|
||||
|
||||
struct RsGxsMailPresignedReceipt : RsGxsMailBaseItem
|
||||
struct RsGxsTransPresignedReceipt : RsGxsTransBaseItem
|
||||
{
|
||||
RsGxsMailPresignedReceipt() :
|
||||
RsGxsMailBaseItem(GxsMailItemsSubtypes::GXS_MAIL_SUBTYPE_RECEIPT) {}
|
||||
RsGxsTransPresignedReceipt() :
|
||||
RsGxsTransBaseItem(GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_RECEIPT) {}
|
||||
};
|
||||
|
||||
enum class RsGxsMailEncryptionMode : uint8_t
|
||||
enum class RsGxsTransEncryptionMode : uint8_t
|
||||
{
|
||||
CLEAR_TEXT = 1,
|
||||
RSA = 2,
|
||||
UNDEFINED_ENCRYPTION = 250
|
||||
};
|
||||
|
||||
struct RsGxsMailItem : RsGxsMailBaseItem
|
||||
struct RsGxsTransMailItem : RsGxsTransBaseItem
|
||||
{
|
||||
RsGxsMailItem() :
|
||||
RsGxsMailBaseItem(GxsMailItemsSubtypes::GXS_MAIL_SUBTYPE_MAIL),
|
||||
cryptoType(RsGxsMailEncryptionMode::UNDEFINED_ENCRYPTION) {}
|
||||
RsGxsTransMailItem() :
|
||||
RsGxsTransBaseItem(GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_MAIL),
|
||||
cryptoType(RsGxsTransEncryptionMode::UNDEFINED_ENCRYPTION) {}
|
||||
|
||||
RsGxsMailEncryptionMode cryptoType;
|
||||
RsGxsTransEncryptionMode cryptoType;
|
||||
|
||||
/**
|
||||
* @brief recipientsHint used instead of plain recipient id, so sender can
|
||||
* @brief recipientHint used instead of plain recipient id, so sender can
|
||||
* decide the equilibrium between exposing the recipient and the cost of
|
||||
* completely anonymize it. So a bunch of luky non recipient can conclude
|
||||
* rapidly that they are not the recipient without trying to decrypt the
|
||||
@ -112,7 +112,7 @@ struct RsGxsMailItem : RsGxsMailBaseItem
|
||||
* keys and an arbitrary salt, the more recipients has the mail and the more
|
||||
* 1 bits has the salt the less accurate is the hint.
|
||||
* This way the sender is able to adjust the metadata privacy needed for the
|
||||
* message, in the more private case (recipientsHint == 0xFFF...FFF) no one
|
||||
* message, in the more private case (recipientHint == 0xFFF...FFF) no one
|
||||
* has a clue about who is the actual recipient, while this imply the cost
|
||||
* that every potencial recipient has to try to decrypt it to know if it is
|
||||
* for herself. This way a bunch of non recipients can rapidly discover that
|
||||
@ -149,9 +149,9 @@ struct RsGxsMailItem : RsGxsMailBaseItem
|
||||
* is specified */
|
||||
std::vector<uint8_t> payload;
|
||||
|
||||
uint32_t size() const
|
||||
uint32_t serial_size() const
|
||||
{
|
||||
return RsGxsMailBaseItem::size() +
|
||||
return RsGxsTransBaseItem::serial_size() +
|
||||
1 + // cryptoType
|
||||
recipientHint.serial_size() +
|
||||
payload.size();
|
||||
@ -159,7 +159,7 @@ struct RsGxsMailItem : RsGxsMailBaseItem
|
||||
bool serialize(uint8_t* data, uint32_t size, uint32_t& offset) const
|
||||
{
|
||||
bool ok = size < MAX_SIZE;
|
||||
ok = ok && RsGxsMailBaseItem::serialize(data, size, offset);
|
||||
ok = ok && RsGxsTransBaseItem::serialize(data, size, offset);
|
||||
ok = ok && setRawUInt8( data, size, &offset,
|
||||
static_cast<uint8_t>(cryptoType) );
|
||||
ok = ok && recipientHint.serialise(data, size, offset);
|
||||
@ -175,12 +175,12 @@ struct RsGxsMailItem : RsGxsMailBaseItem
|
||||
|
||||
uint32_t roffset = offset;
|
||||
bool ok = rssize <= size && size < MAX_SIZE;
|
||||
ok = ok && RsGxsMailBaseItem::deserialize(data, rssize, roffset);
|
||||
ok = ok && RsGxsTransBaseItem::deserialize(data, rssize, roffset);
|
||||
|
||||
void* dataPtr = const_cast<uint8_t*>(data);
|
||||
uint8_t crType;
|
||||
ok = ok && getRawUInt8(dataPtr, rssize, &roffset, &crType);
|
||||
cryptoType = static_cast<RsGxsMailEncryptionMode>(crType);
|
||||
cryptoType = static_cast<RsGxsTransEncryptionMode>(crType);
|
||||
ok = ok && recipientHint.deserialise(dataPtr, rssize, roffset);
|
||||
uint32_t psz = rssize - roffset;
|
||||
ok = ok && (payload.resize(psz), memcpy(&payload[0], data+roffset, psz));
|
||||
@ -191,8 +191,8 @@ struct RsGxsMailItem : RsGxsMailBaseItem
|
||||
}
|
||||
void clear()
|
||||
{
|
||||
RsGxsMailBaseItem::clear();
|
||||
cryptoType = RsGxsMailEncryptionMode::UNDEFINED_ENCRYPTION;
|
||||
RsGxsTransBaseItem::clear();
|
||||
cryptoType = RsGxsTransEncryptionMode::UNDEFINED_ENCRYPTION;
|
||||
recipientHint.clear();
|
||||
payload.clear();
|
||||
}
|
||||
@ -201,12 +201,12 @@ struct RsGxsMailItem : RsGxsMailBaseItem
|
||||
const static uint32_t MAX_SIZE = 10*8*1024*1024;
|
||||
};
|
||||
|
||||
struct RsGxsMailGroupItem : RsGxsGrpItem
|
||||
struct RsGxsTransGroupItem : RsGxsGrpItem
|
||||
{
|
||||
RsGxsMailGroupItem() :
|
||||
RsGxsGrpItem( RS_SERVICE_TYPE_GXS_MAIL,
|
||||
RsGxsTransGroupItem() :
|
||||
RsGxsGrpItem( RS_SERVICE_TYPE_GXS_TRANS,
|
||||
static_cast<uint8_t>(
|
||||
GxsMailItemsSubtypes::GXS_MAIL_SUBTYPE_GROUP) )
|
||||
GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_GROUP) )
|
||||
{
|
||||
meta.mGroupFlags = GXS_SERV::FLAG_PRIVACY_PUBLIC;
|
||||
meta.mGroupName = "Mail";
|
||||
@ -218,7 +218,7 @@ struct RsGxsMailGroupItem : RsGxsGrpItem
|
||||
{ return out; }
|
||||
};
|
||||
|
||||
enum class GxsMailStatus : uint8_t
|
||||
enum class GxsTransSendStatus : uint8_t
|
||||
{
|
||||
UNKNOWN = 0,
|
||||
PENDING_PROCESSING,
|
||||
@ -239,19 +239,19 @@ enum class GxsMailStatus : uint8_t
|
||||
FAILED_ENCRYPTION
|
||||
};
|
||||
|
||||
class RsGxsMailSerializer;
|
||||
class RsGxsTransSerializer;
|
||||
struct OutgoingRecord : RsItem
|
||||
{
|
||||
OutgoingRecord( RsGxsId rec, GxsMailSubServices cs,
|
||||
OutgoingRecord( RsGxsId rec, GxsTransSubServices cs,
|
||||
const uint8_t* data, uint32_t size );
|
||||
|
||||
GxsMailStatus status;
|
||||
GxsTransSendStatus status;
|
||||
RsGxsId recipient;
|
||||
/// Don't use a pointer would be invalid after publish
|
||||
RsGxsMailItem mailItem;
|
||||
RsGxsTransMailItem mailItem;
|
||||
std::vector<uint8_t> mailData;
|
||||
GxsMailSubServices clientService;
|
||||
RsNxsMailPresignedReceipt presignedReceipt;
|
||||
GxsTransSubServices clientService;
|
||||
RsNxsTransPresignedReceipt presignedReceipt;
|
||||
|
||||
uint32_t size() const;
|
||||
bool serialize(uint8_t* data, uint32_t size, uint32_t& offset) const;
|
||||
@ -261,32 +261,32 @@ struct OutgoingRecord : RsItem
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
private:
|
||||
friend class RsGxsMailSerializer;
|
||||
friend class RsGxsTransSerializer;
|
||||
OutgoingRecord();
|
||||
};
|
||||
|
||||
|
||||
struct RsGxsMailSerializer : RsSerialType
|
||||
struct RsGxsTransSerializer : RsSerialType
|
||||
{
|
||||
RsGxsMailSerializer() : RsSerialType( RS_PKT_VERSION_SERVICE,
|
||||
RS_SERVICE_TYPE_GXS_MAIL ) {}
|
||||
~RsGxsMailSerializer() {}
|
||||
RsGxsTransSerializer() : RsSerialType( RS_PKT_VERSION_SERVICE,
|
||||
RS_SERVICE_TYPE_GXS_TRANS ) {}
|
||||
~RsGxsTransSerializer() {}
|
||||
|
||||
uint32_t size(RsItem* item)
|
||||
{
|
||||
uint32_t sz = 0;
|
||||
switch(static_cast<GxsMailItemsSubtypes>(item->PacketSubType()))
|
||||
switch(static_cast<GxsTransItemsSubtypes>(item->PacketSubType()))
|
||||
{
|
||||
case GxsMailItemsSubtypes::GXS_MAIL_SUBTYPE_MAIL:
|
||||
case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_MAIL:
|
||||
{
|
||||
RsGxsMailItem* i = dynamic_cast<RsGxsMailItem*>(item);
|
||||
if(i) sz = i->size();
|
||||
RsGxsTransMailItem* i = dynamic_cast<RsGxsTransMailItem*>(item);
|
||||
if(i) sz = i->serial_size();
|
||||
break;
|
||||
}
|
||||
case GxsMailItemsSubtypes::GXS_MAIL_SUBTYPE_RECEIPT:
|
||||
sz = RsGxsMailPresignedReceipt::size(); break;
|
||||
case GxsMailItemsSubtypes::GXS_MAIL_SUBTYPE_GROUP: sz = 8; break;
|
||||
case GxsMailItemsSubtypes::OUTGOING_RECORD_ITEM:
|
||||
case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_RECEIPT:
|
||||
sz = RsGxsTransPresignedReceipt::serial_size(); break;
|
||||
case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_GROUP: sz = 8; break;
|
||||
case GxsTransItemsSubtypes::OUTGOING_RECORD_ITEM:
|
||||
{
|
||||
OutgoingRecord* ci = dynamic_cast<OutgoingRecord*>(item);
|
||||
if(ci) sz = ci->size();
|
||||
@ -309,7 +309,7 @@ struct RsGxsMailSerializer : RsSerialType
|
||||
const uint8_t* dataPtr = reinterpret_cast<uint8_t*>(data);
|
||||
|
||||
if ( (RS_PKT_VERSION_SERVICE != pktv) || // 0x02
|
||||
(RS_SERVICE_TYPE_GXS_MAIL != srvc) || // 0x0230 = 560
|
||||
(RS_SERVICE_TYPE_GXS_TRANS != srvc) || // 0x0230 = 560
|
||||
(*size < rssize) )
|
||||
{
|
||||
print_stacktrace();
|
||||
@ -320,30 +320,30 @@ struct RsGxsMailSerializer : RsSerialType
|
||||
bool ok = true;
|
||||
RsItem* ret = NULL;
|
||||
|
||||
switch (static_cast<GxsMailItemsSubtypes>(getRsItemSubType(rstype)))
|
||||
switch (static_cast<GxsTransItemsSubtypes>(getRsItemSubType(rstype)))
|
||||
{
|
||||
case GxsMailItemsSubtypes::GXS_MAIL_SUBTYPE_MAIL:
|
||||
case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_MAIL:
|
||||
{
|
||||
RsGxsMailItem* i = new RsGxsMailItem();
|
||||
RsGxsTransMailItem* i = new RsGxsTransMailItem();
|
||||
uint32_t offset = 0;
|
||||
ok = ok && i->deserialize(dataPtr, *size, offset);
|
||||
ret = i;
|
||||
break;
|
||||
}
|
||||
case GxsMailItemsSubtypes::GXS_MAIL_SUBTYPE_RECEIPT:
|
||||
case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_RECEIPT:
|
||||
{
|
||||
RsGxsMailPresignedReceipt* i = new RsGxsMailPresignedReceipt();
|
||||
RsGxsTransPresignedReceipt* i = new RsGxsTransPresignedReceipt();
|
||||
uint32_t offset = 0;
|
||||
ok &= i->deserialize(dataPtr, *size, offset);
|
||||
ret = i;
|
||||
break;
|
||||
}
|
||||
case GxsMailItemsSubtypes::GXS_MAIL_SUBTYPE_GROUP:
|
||||
case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_GROUP:
|
||||
{
|
||||
ret = new RsGxsMailGroupItem();
|
||||
ret = new RsGxsTransGroupItem();
|
||||
break;
|
||||
}
|
||||
case GxsMailItemsSubtypes::OUTGOING_RECORD_ITEM:
|
||||
case GxsTransItemsSubtypes::OUTGOING_RECORD_ITEM:
|
||||
{
|
||||
OutgoingRecord* i = new OutgoingRecord();
|
||||
uint32_t offset = 0;
|
@ -852,9 +852,9 @@ gxsphotoshare {
|
||||
serialiser/rsphotoitems.cc \
|
||||
}
|
||||
|
||||
rs_gxs_mail {
|
||||
HEADERS += serialiser/rsgxsmailitems.h services/p3gxsmails.h
|
||||
SOURCES += serialiser/rsgxsmailitems.cc services/p3gxsmails.cpp
|
||||
rs_gxs_trans {
|
||||
HEADERS += gxstrans/p3gxstransitems.h gxstrans/p3gxstrans.h
|
||||
SOURCES += gxstrans/p3gxstransitems.cc gxstrans/p3gxstrans.cc
|
||||
}
|
||||
|
||||
|
||||
|
@ -122,7 +122,7 @@ RsServer::RsServer()
|
||||
|
||||
RsServer::~RsServer()
|
||||
{
|
||||
delete mGxsMails;
|
||||
delete mGxsTrans;
|
||||
}
|
||||
|
||||
/* General Internal Helper Functions
|
||||
|
@ -179,7 +179,7 @@ class RsServer: public RsControl, public RsTickingThread
|
||||
// p3GxsForums *mGxsForums;
|
||||
// p3GxsChannels *mGxsChannels;
|
||||
// p3Wire *mWire;
|
||||
p3GxsMails* mGxsMails;
|
||||
p3GxsTrans* mGxsTrans;
|
||||
|
||||
/* Config */
|
||||
p3ConfigMgr *mConfigMgr;
|
||||
|
@ -82,8 +82,8 @@
|
||||
#include "tcponudp/udpstunner.h"
|
||||
#endif // RS_USE_DHT_STUNNER
|
||||
|
||||
#ifdef RS_GXS_MAIL
|
||||
# include "services/p3gxsmails.h"
|
||||
#ifdef RS_GXS_TRANS
|
||||
# include "gxstrans/p3gxstrans.h"
|
||||
#endif
|
||||
|
||||
// #define GPG_DEBUG
|
||||
@ -1484,22 +1484,18 @@ int RsServer::StartupRetroShare()
|
||||
pqih->addService(gxschannels_ns, true);
|
||||
//pqih->addService(photo_ns, true);
|
||||
|
||||
# ifdef RS_GXS_MAIL
|
||||
RsGeneralDataService* gxsmail_ds = new RsDataService(
|
||||
currGxsDir + "/", "gxsmails_db", RS_SERVICE_TYPE_GXS_MAIL,
|
||||
# ifdef RS_GXS_TRANS
|
||||
RsGeneralDataService* gxstrans_ds = new RsDataService(
|
||||
currGxsDir + "/", "gxstrans_db", RS_SERVICE_TYPE_GXS_TRANS,
|
||||
NULL, rsInitConfig->gxs_passwd );
|
||||
mGxsMails = new p3GxsMails(gxsmail_ds, NULL, *mGxsIdService);
|
||||
RsGxsNetService* gxsmails_ns = new RsGxsNetService(
|
||||
RS_SERVICE_TYPE_GXS_MAIL, gxsmail_ds, nxsMgr, mGxsMails,
|
||||
mGxsMails->getServiceInfo(), mReputations, mGxsCircles,
|
||||
mGxsTrans = new p3GxsTrans(gxstrans_ds, NULL, *mGxsIdService);
|
||||
RsGxsNetService* gxstrans_ns = new RsGxsNetService(
|
||||
RS_SERVICE_TYPE_GXS_TRANS, gxstrans_ds, nxsMgr, mGxsTrans,
|
||||
mGxsTrans->getServiceInfo(), mReputations, mGxsCircles,
|
||||
mGxsIdService, pgpAuxUtils);
|
||||
mGxsMails->setNetworkExchangeService(gxsmails_ns);
|
||||
pqih->addService(gxsmails_ns, true);
|
||||
# ifdef TEST_RS_GXS_MAIL
|
||||
TestGxsMailClientService* tgms =
|
||||
new TestGxsMailClientService(*mGxsMails, *mGxsIdService);
|
||||
# endif // TEST_RS_GXS_MAIL
|
||||
# endif // RS_GXS_MAIL
|
||||
mGxsTrans->setNetworkExchangeService(gxstrans_ns);
|
||||
pqih->addService(gxstrans_ns, true);
|
||||
# endif // RS_GXS_TRANS
|
||||
|
||||
// remove pword from memory
|
||||
rsInitConfig->gxs_passwd = "";
|
||||
@ -1510,9 +1506,9 @@ int RsServer::StartupRetroShare()
|
||||
p3ServiceInfo *serviceInfo = new p3ServiceInfo(serviceCtrl);
|
||||
mDisc = new p3discovery2(mPeerMgr, mLinkMgr, mNetMgr, serviceCtrl);
|
||||
mHeart = new p3heartbeat(serviceCtrl, pqih);
|
||||
msgSrv = new p3MsgService( serviceCtrl, mGxsIdService, *mGxsMails );
|
||||
msgSrv = new p3MsgService( serviceCtrl, mGxsIdService, *mGxsTrans );
|
||||
chatSrv = new p3ChatService( serviceCtrl,mGxsIdService, mLinkMgr,
|
||||
mHistoryMgr, *mGxsMails );
|
||||
mHistoryMgr, *mGxsTrans );
|
||||
mStatusSrv = new p3StatusService(serviceCtrl);
|
||||
|
||||
#ifdef ENABLE_GROUTER
|
||||
@ -1678,10 +1674,10 @@ int RsServer::StartupRetroShare()
|
||||
|
||||
#ifdef RS_ENABLE_GXS
|
||||
|
||||
# ifdef RS_GXS_MAIL
|
||||
mConfigMgr->addConfiguration("gxs_mail_ns.cfg", gxsmails_ns);
|
||||
mConfigMgr->addConfiguration("gxs_mail.cfg", mGxsMails);
|
||||
# endif
|
||||
# ifdef RS_GXS_TRANS
|
||||
mConfigMgr->addConfiguration("gxs_trans_ns.cfg", gxstrans_ns);
|
||||
mConfigMgr->addConfiguration("gxs_trans.cfg", mGxsTrans);
|
||||
# endif // RS_GXS_TRANS
|
||||
|
||||
mConfigMgr->addConfiguration("p3identity.cfg", mGxsIdService);
|
||||
|
||||
@ -1830,13 +1826,10 @@ int RsServer::StartupRetroShare()
|
||||
//createThread(*photo_ns);
|
||||
//createThread(*wire_ns);
|
||||
|
||||
# ifdef RS_GXS_MAIL
|
||||
startServiceThread(mGxsMails, "gxs mail");
|
||||
startServiceThread(gxsmails_ns, "gxs mail ns");
|
||||
# ifdef TEST_RS_GXS_MAIL
|
||||
tgms->start("Gxs Mail Test Service");
|
||||
# endif // TEST_RS_GXS_MAIL
|
||||
# endif // RS_GXS_MAIL
|
||||
# ifdef RS_GXS_TRANS
|
||||
startServiceThread(mGxsTrans, "gxs trans");
|
||||
startServiceThread(gxstrans_ns, "gxs trans ns");
|
||||
# endif // RS_GXS_TRANS
|
||||
|
||||
#endif // RS_ENABLE_GXS
|
||||
|
||||
|
@ -82,7 +82,7 @@ const uint16_t RS_SERVICE_GXS_TYPE_GXSCIRCLE = 0x0218;
|
||||
// not gxs, but used with identities.
|
||||
const uint16_t RS_SERVICE_GXS_TYPE_REPUTATION = 0x0219;
|
||||
const uint16_t RS_SERVICE_TYPE_GXS_RECOGN = 0x0220;
|
||||
const uint16_t RS_SERVICE_TYPE_GXS_MAIL = 0x0230;
|
||||
const uint16_t RS_SERVICE_TYPE_GXS_TRANS = 0x0230;
|
||||
|
||||
// Experimental Services.
|
||||
/* DSDV Testing at the moment - Service Only */
|
||||
|
@ -86,12 +86,12 @@ static const uint32_t RS_MSG_DISTANT_MESSAGE_HASH_KEEP_TIME = 2*30*86400 ; // ke
|
||||
*/
|
||||
|
||||
p3MsgService::p3MsgService( p3ServiceControl *sc, p3IdService *id_serv,
|
||||
p3GxsMails& gxsMS )
|
||||
p3GxsTrans& gxsMS )
|
||||
: p3Service(), p3Config(),
|
||||
gxsOngoingMutex("p3MsgService Gxs Outgoing Mutex"), mIdService(id_serv),
|
||||
mServiceCtrl(sc), mMsgMtx("p3MsgService"), mMsgUniqueId(0),
|
||||
recentlyReceivedMutex("p3MsgService recently received hash mutex"),
|
||||
gxsMailService(gxsMS)
|
||||
mGxsTransServ(gxsMS)
|
||||
{
|
||||
/* this serialiser is used for services. It's not the same than the one
|
||||
* returned by setupSerialiser(). We need both!! */
|
||||
@ -108,8 +108,8 @@ p3MsgService::p3MsgService( p3ServiceControl *sc, p3IdService *id_serv,
|
||||
|
||||
if(sc) initStandardTagTypes(); // Initialize standard tag types
|
||||
|
||||
gxsMailService.registerGxsMailsClient( GxsMailSubServices::P3_MSG_SERVICE,
|
||||
this );
|
||||
mGxsTransServ.registerGxsTransClient( GxsTransSubServices::P3_MSG_SERVICE,
|
||||
this );
|
||||
}
|
||||
|
||||
const std::string MSG_APP_NAME = "msg";
|
||||
@ -1990,12 +1990,12 @@ uint32_t p3MsgService::getDistantMessagingPermissionFlags()
|
||||
return mDistantMessagePermissions ;
|
||||
}
|
||||
|
||||
bool p3MsgService::receiveGxsMail( const RsGxsId& authorId,
|
||||
const RsGxsId& recipientId,
|
||||
const uint8_t* data, uint32_t dataSize )
|
||||
bool p3MsgService::receiveGxsTransMail( const RsGxsId& authorId,
|
||||
const RsGxsId& recipientId,
|
||||
const uint8_t* data, uint32_t dataSize )
|
||||
{
|
||||
std::cout << "p3MsgService::receiveGxsMail(" << authorId
|
||||
<< ", " << recipientId << ", " << dataSize << ")" << std::endl;
|
||||
std::cout << __PRETTY_FUNCTION__ << " " << authorId << ", " << recipientId
|
||||
<< ",, " << dataSize << std::endl;
|
||||
|
||||
Sha1CheckSum hash = RsDirUtil::sha1sum(data, dataSize);
|
||||
|
||||
@ -2004,7 +2004,7 @@ bool p3MsgService::receiveGxsMail( const RsGxsId& authorId,
|
||||
if( mRecentlyReceivedMessageHashes.find(hash) !=
|
||||
mRecentlyReceivedMessageHashes.end() )
|
||||
{
|
||||
std::cerr << "p3MsgService::receiveGxsMail(...) (II) receiving "
|
||||
std::cerr << __PRETTY_FUNCTION__ << " (II) receiving "
|
||||
<< "message of hash " << hash << " more than once. "
|
||||
<< "Probably it has arrived before by other means."
|
||||
<< std::endl;
|
||||
@ -2020,8 +2020,8 @@ bool p3MsgService::receiveGxsMail( const RsGxsId& authorId,
|
||||
|
||||
if(msg_item)
|
||||
{
|
||||
std::cerr << "p3MsgService::receiveGxsMail(...) Encrypted item "
|
||||
<< "correctly deserialised. Passing on to incoming list."
|
||||
std::cerr << __PRETTY_FUNCTION__ << " Encrypted item correctly "
|
||||
<< "deserialised. Passing on to incoming list."
|
||||
<< std::endl;
|
||||
|
||||
msg_item->msgFlags |= RS_MSG_FLAGS_DISTANT;
|
||||
@ -2035,7 +2035,7 @@ bool p3MsgService::receiveGxsMail( const RsGxsId& authorId,
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "p3MsgService::receiveGxsMail(...) Item could not be "
|
||||
std::cerr << __PRETTY_FUNCTION__ << " Item could not be "
|
||||
<< "deserialised. Format error??" << std::endl;
|
||||
return false;
|
||||
}
|
||||
@ -2043,26 +2043,26 @@ bool p3MsgService::receiveGxsMail( const RsGxsId& authorId,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3MsgService::notifySendMailStatus( const RsGxsMailItem& originalMessage,
|
||||
GxsMailStatus status )
|
||||
bool p3MsgService::notifyGxsTransSendStatus( RsGxsTransId mailId,
|
||||
GxsTransSendStatus status )
|
||||
{
|
||||
std::cout << "p3MsgService::notifySendMailStatus(" << originalMessage.mailId
|
||||
<< ", " << static_cast<uint>(status) << ")" << std::endl;
|
||||
std::cout << __PRETTY_FUNCTION__ << " " << mailId << ", "
|
||||
<< static_cast<uint>(status) << std::endl;
|
||||
|
||||
if( status == GxsMailStatus::RECEIPT_RECEIVED )
|
||||
if( status == GxsTransSendStatus::RECEIPT_RECEIVED )
|
||||
{
|
||||
uint32_t msg_id;
|
||||
|
||||
{
|
||||
RS_STACK_MUTEX(gxsOngoingMutex);
|
||||
|
||||
auto it = gxsOngoingMessages.find(originalMessage.mailId);
|
||||
auto it = gxsOngoingMessages.find(mailId);
|
||||
if(it == gxsOngoingMessages.end())
|
||||
{
|
||||
std::cerr << "p3MsgService::notifySendMailStatus("
|
||||
<< originalMessage.mailId
|
||||
<< ", " << static_cast<uint>(status) << ") "
|
||||
<< "(EE) cannot find pending message to acknowledge!"
|
||||
std::cerr << __PRETTY_FUNCTION__<< " "
|
||||
<< mailId
|
||||
<< ", " << static_cast<uint>(status)
|
||||
<< " (EE) cannot find pending message to acknowledge!"
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
@ -2078,9 +2078,8 @@ bool p3MsgService::notifySendMailStatus( const RsGxsMailItem& originalMessage,
|
||||
auto it2 = msgOutgoing.find(msg_id);
|
||||
if(it2 == msgOutgoing.end())
|
||||
{
|
||||
std::cerr << "p3MsgService::notifySendMailStatus("
|
||||
<< originalMessage.mailId
|
||||
<< ", " << static_cast<uint>(status) << ") (II) "
|
||||
std::cerr << __PRETTY_FUNCTION__ << " " << mailId
|
||||
<< ", " << static_cast<uint>(status) << " (II) "
|
||||
<< "received receipt for message that is not in "
|
||||
<< "outgoing list, probably it has been acknoweldged "
|
||||
<< "before by other means." << std::endl;
|
||||
@ -2098,18 +2097,18 @@ bool p3MsgService::notifySendMailStatus( const RsGxsMailItem& originalMessage,
|
||||
return true;
|
||||
}
|
||||
|
||||
if( status >= GxsMailStatus::FAILED_RECEIPT_SIGNATURE )
|
||||
if( status >= GxsTransSendStatus::FAILED_RECEIPT_SIGNATURE )
|
||||
{
|
||||
uint32_t msg_id;
|
||||
|
||||
{
|
||||
RS_STACK_MUTEX(gxsOngoingMutex);
|
||||
|
||||
std::cerr << "p3MsgService::notifySendMailStatus(...) mail delivery"
|
||||
<< "mailId: " << originalMessage.mailId
|
||||
std::cerr << __PRETTY_FUNCTION__ << " mail delivery "
|
||||
<< "mailId: " << mailId
|
||||
<< " failed with " << static_cast<uint32_t>(status);
|
||||
|
||||
auto it = gxsOngoingMessages.find(originalMessage.mailId);
|
||||
auto it = gxsOngoingMessages.find(mailId);
|
||||
if(it == gxsOngoingMessages.end())
|
||||
{
|
||||
std::cerr << " cannot find pending message to notify"
|
||||
@ -2258,8 +2257,8 @@ void p3MsgService::sendDistantMsgItem(RsMsgItem *msgitem)
|
||||
mGRouter->sendData( destination_key_id, GROUTER_CLIENT_ID_MESSAGES,
|
||||
msg_serialized_data, msg_serialized_rssize,
|
||||
signing_key_id, grouter_message_id );
|
||||
RsGxsMailId gxsMailId;
|
||||
gxsMailService.sendMail( gxsMailId, GxsMailSubServices::P3_MSG_SERVICE,
|
||||
RsGxsTransId gxsMailId;
|
||||
mGxsTransServ.sendMail( gxsMailId, GxsTransSubServices::P3_MSG_SERVICE,
|
||||
signing_key_id, destination_key_id,
|
||||
msg_serialized_data, msg_serialized_rssize );
|
||||
|
||||
|
@ -49,7 +49,7 @@
|
||||
#include "grouter/grouterclientservice.h"
|
||||
#include "turtle/p3turtle.h"
|
||||
#include "turtle/turtleclientservice.h"
|
||||
#include "services/p3gxsmails.h"
|
||||
#include "gxstrans/p3gxstrans.h"
|
||||
|
||||
class p3LinkMgr;
|
||||
class p3IdService;
|
||||
@ -57,9 +57,9 @@ class p3IdService;
|
||||
// Temp tweak to test grouter
|
||||
struct p3MsgService :
|
||||
p3Service, p3Config, pqiServiceMonitor, GRouterClientService,
|
||||
GxsMailsClient
|
||||
GxsTransClient
|
||||
{
|
||||
p3MsgService(p3ServiceControl *sc, p3IdService *id_service, p3GxsMails& gxsMS);
|
||||
p3MsgService(p3ServiceControl *sc, p3IdService *id_service, p3GxsTrans& gxsMS);
|
||||
|
||||
virtual RsServiceInfo getServiceInfo();
|
||||
|
||||
@ -135,14 +135,14 @@ struct p3MsgService :
|
||||
void setDistantMessagingPermissionFlags(uint32_t flags) ;
|
||||
uint32_t getDistantMessagingPermissionFlags() ;
|
||||
|
||||
/// @see GxsMailsClient::receiveGxsMail(...)
|
||||
virtual bool receiveGxsMail( const RsGxsId& authorId,
|
||||
const RsGxsId& recipientId,
|
||||
const uint8_t* data, uint32_t dataSize );
|
||||
/// @see GxsTransClient::receiveGxsTransMail(...)
|
||||
virtual bool receiveGxsTransMail( const RsGxsId& authorId,
|
||||
const RsGxsId& recipientId,
|
||||
const uint8_t* data, uint32_t dataSize );
|
||||
|
||||
/// @see GxsMailsClient::notifySendMailStatus(...)
|
||||
virtual bool notifySendMailStatus( const RsGxsMailItem& originalMessage,
|
||||
GxsMailStatus status );
|
||||
/// @see GxsTransClient::notifyGxsTransSendStatus(...)
|
||||
virtual bool notifyGxsTransSendStatus( RsGxsTransId mailId,
|
||||
GxsTransSendStatus status );
|
||||
|
||||
private:
|
||||
void sendDistantMsgItem(RsMsgItem *msgitem);
|
||||
@ -152,7 +152,7 @@ private:
|
||||
std::map<GRouterMsgPropagationId, uint32_t> _ongoing_messages;
|
||||
|
||||
/// Contains ongoing messages handed to gxs mail
|
||||
std::map<RsGxsMailId, uint32_t> gxsOngoingMessages;
|
||||
std::map<RsGxsTransId, uint32_t> gxsOngoingMessages;
|
||||
RsMutex gxsOngoingMutex;
|
||||
|
||||
// Overloaded from GRouterClientService
|
||||
@ -229,7 +229,7 @@ private:
|
||||
uint32_t mDistantMessagePermissions ;
|
||||
bool mShouldEnableDistantMessaging ;
|
||||
|
||||
p3GxsMails& gxsMailService;
|
||||
p3GxsTrans& mGxsTransServ;
|
||||
};
|
||||
|
||||
#endif // MESSAGE_SERVICE_HEADER
|
||||
|
@ -61,9 +61,9 @@ CONFIG *= no_rs_nocppwarning
|
||||
rs_nocppwarning:CONFIG -= no_rs_nocppwarning
|
||||
|
||||
# To disable GXS mail append the following assignation to qmake command line
|
||||
# "CONFIG+=no_rs_gxs_mail"
|
||||
CONFIG *= rs_gxs_mail
|
||||
#no_rs_gxs_mail:CONFIG -= rs_gxs_mail ## Disabing not supported ATM
|
||||
# "CONFIG+=no_rs_gxs_trans"
|
||||
CONFIG *= rs_gxs_trans
|
||||
#no_rs_gxs_trans:CONFIG -= rs_gxs_trans ## Disabing not supported ATM
|
||||
|
||||
|
||||
unix {
|
||||
@ -173,17 +173,17 @@ rs_nodeprecatedwarning {
|
||||
QMAKE_CXXFLAGS += -Wno-deprecated
|
||||
QMAKE_CXXFLAGS += -Wno-deprecated-declarations
|
||||
DEFINES *= RS_NO_WARN_DEPRECATED
|
||||
warning("QMAKE: You have disable deprecated warnings.")
|
||||
warning("QMAKE: You have disabled deprecated warnings.")
|
||||
}
|
||||
|
||||
rs_nocppwarning {
|
||||
QMAKE_CXXFLAGS += -Wno-cpp
|
||||
DEFINES *= RS_NO_WARN_CPP
|
||||
warning("QMAKE: You have disable C preprocessor warnings.")
|
||||
warning("QMAKE: You have disabled C preprocessor warnings.")
|
||||
}
|
||||
|
||||
rs_gxs_mail {
|
||||
DEFINES *= RS_GXS_MAIL
|
||||
rs_gxs_trans {
|
||||
DEFINES *= RS_GXS_TRANS
|
||||
greaterThan(QT_MAJOR_VERSION, 4) {
|
||||
CONFIG += c++11
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user