mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
moved metadata info to members of OutgoingRecord, so that the un-serialized meta is not lost when saved. Ensured backward compatibility when reloading old items.
This commit is contained in:
parent
1e652d6577
commit
f62028b2c1
@ -48,8 +48,8 @@ bool p3GxsTrans::getStatistics(GxsTransStatistics& stats)
|
||||
|
||||
RsGxsTransOutgoingRecord rec ;
|
||||
rec.status = pr.status ;
|
||||
rec.send_TS = pr.mailItem.meta.mPublishTs ;
|
||||
rec.group_id = pr.mailItem.meta.mGroupId ;
|
||||
rec.send_TS = pr.sent_ts ;
|
||||
rec.group_id = pr.group_id ;
|
||||
rec.trans_id = pr.mailItem.mailId ;
|
||||
rec.recipient = pr.recipient ;
|
||||
rec.data_size = pr.mailData.size();
|
||||
@ -89,8 +89,7 @@ bool p3GxsTrans::sendData( RsGxsTransId& mailId,
|
||||
OutgoingRecord pr( recipient, service, data, size );
|
||||
|
||||
pr.mailItem.clear();
|
||||
pr.mailItem.meta.mAuthorId = own_gxsid;
|
||||
pr.mailItem.meta.mMsgId.clear();
|
||||
pr.author = own_gxsid; //pr.mailItem.meta.mAuthorId = own_gxsid;
|
||||
pr.mailItem.cryptoType = cm;
|
||||
pr.mailItem.mailId = RSRandom::random_u64();
|
||||
|
||||
@ -225,7 +224,7 @@ void p3GxsTrans::handleResponse(uint32_t token, uint32_t req_type)
|
||||
case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_MAIL:
|
||||
case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_RECEIPT:
|
||||
{
|
||||
RsGxsTransBaseItem* mb = dynamic_cast<RsGxsTransBaseItem*>(*mIt);
|
||||
RsGxsTransBaseMsgItem* mb = dynamic_cast<RsGxsTransBaseMsgItem*>(*mIt);
|
||||
|
||||
if(mb)
|
||||
{
|
||||
@ -706,7 +705,7 @@ void p3GxsTrans::locked_processOutgoingRecord(OutgoingRecord& pr)
|
||||
{
|
||||
pr.mailItem.saltRecipientHint(pr.recipient);
|
||||
pr.mailItem.saltRecipientHint(RsGxsId::random());
|
||||
pr.mailItem.meta.mPublishTs = time(NULL);
|
||||
pr.sent_ts = time(NULL) ; //pr.mailItem.meta.mPublishTs = time(NULL);
|
||||
}
|
||||
case GxsTransSendStatus::PENDING_PREFERRED_GROUP:
|
||||
{
|
||||
@ -717,12 +716,16 @@ void p3GxsTrans::locked_processOutgoingRecord(OutgoingRecord& pr)
|
||||
break;
|
||||
}
|
||||
|
||||
pr.mailItem.meta.mGroupId = mPreferredGroupId;
|
||||
pr.group_id = mPreferredGroupId ; //pr.mailItem.meta.mGroupId = mPreferredGroupId;
|
||||
}
|
||||
case GxsTransSendStatus::PENDING_RECEIPT_CREATE:
|
||||
{
|
||||
RsGxsTransPresignedReceipt grcpt;
|
||||
grcpt.meta = pr.mailItem.meta;
|
||||
grcpt.meta.mAuthorId = pr.author ; //grcpt.meta = pr.mailItem.meta;
|
||||
grcpt.meta.mGroupId = pr.group_id ; //grcpt.meta = pr.mailItem.meta;
|
||||
grcpt.meta.mMsgId.clear() ;
|
||||
grcpt.meta.mParentId.clear() ;
|
||||
grcpt.meta.mOrigMsgId.clear() ;
|
||||
grcpt.meta.mPublishTs = time(NULL);
|
||||
grcpt.mailId = pr.mailItem.mailId;
|
||||
uint32_t grsz = RsGxsTransSerializer().size(&grcpt);
|
||||
@ -735,7 +738,7 @@ void p3GxsTrans::locked_processOutgoingRecord(OutgoingRecord& pr)
|
||||
*pr.presignedReceipt.metaData = grcpt.meta;
|
||||
pr.presignedReceipt.msg.setBinData(&grsrz[0], grsz);
|
||||
}
|
||||
case GxsTransSendStatus::PENDING_RECEIPT_SIGNATURE:
|
||||
case GxsTransSendStatus::PENDING_RECEIPT_SIGNATURE: // (cyril) This step is never actually used.
|
||||
{
|
||||
switch (RsGenExchange::createMessage(&pr.presignedReceipt))
|
||||
{
|
||||
@ -822,11 +825,23 @@ void p3GxsTrans::locked_processOutgoingRecord(OutgoingRecord& pr)
|
||||
<< " payload size: " << pr.mailItem.payload.size()
|
||||
<< std::endl;
|
||||
|
||||
RsGxsTransMailItem *mail_item = new RsGxsTransMailItem(pr.mailItem);
|
||||
|
||||
// pr.mailItem.meta is *not* serialised. So it is important to not rely on what's in it!
|
||||
|
||||
mail_item->meta.mGroupId = pr.group_id ;
|
||||
mail_item->meta.mAuthorId = pr.author ;
|
||||
|
||||
mail_item->meta.mMsgId.clear();
|
||||
mail_item->meta.mParentId.clear();
|
||||
mail_item->meta.mOrigMsgId.clear();
|
||||
|
||||
uint32_t token;
|
||||
publishMsg(token, new RsGxsTransMailItem(pr.mailItem));
|
||||
publishMsg(token, mail_item) ;
|
||||
|
||||
pr.status = GxsTransSendStatus::PENDING_RECEIPT_RECEIVE;
|
||||
|
||||
IndicateConfigChanged(); // This causes the saving of the message after all data has been filled in.
|
||||
IndicateConfigChanged(); // This causes the saving of the message after pr.status has changed.
|
||||
break;
|
||||
}
|
||||
//case GxsTransSendStatus::PENDING_TRANSFER:
|
||||
@ -909,7 +924,7 @@ bool p3GxsTrans::saveList(bool &cleanup, std::list<RsItem *>& saveList)
|
||||
|
||||
for ( auto& kv : mOutgoingQueue )
|
||||
{
|
||||
std::cerr << "Saving outgoing item, ID " << std::hex << std::setfill('0') << std::setw(16) << kv.first << std::dec << "Group id: " << kv.second.mailItem.meta.mGroupId << ", TS=" << kv.second.mailItem.meta.mPublishTs << std::endl;
|
||||
std::cerr << "Saving outgoing item, ID " << std::hex << std::setfill('0') << std::setw(16) << kv.first << std::dec << "Group id: " << kv.second.group_id << ", TS=" << kv.second.sent_ts << std::endl;
|
||||
saveList.push_back(&kv.second);
|
||||
}
|
||||
for ( auto& kv : mIncomingQueue )
|
||||
@ -942,7 +957,7 @@ bool p3GxsTrans::loadList(std::list<RsItem *>&loadList)
|
||||
case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_MAIL:
|
||||
case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_RECEIPT:
|
||||
{
|
||||
RsGxsTransBaseItem* mi = dynamic_cast<RsGxsTransBaseItem*>(v);
|
||||
RsGxsTransBaseMsgItem* mi = dynamic_cast<RsGxsTransBaseMsgItem*>(v);
|
||||
if(mi)
|
||||
{
|
||||
RS_STACK_MUTEX(mIngoingMutex);
|
||||
@ -950,6 +965,34 @@ bool p3GxsTrans::loadList(std::list<RsItem *>&loadList)
|
||||
}
|
||||
break;
|
||||
}
|
||||
case GxsTransItemsSubtypes::OUTGOING_RECORD_ITEM_deprecated:
|
||||
{
|
||||
OutgoingRecord_deprecated* dot = dynamic_cast<OutgoingRecord_deprecated*>(v);
|
||||
|
||||
if(dot)
|
||||
{
|
||||
std::cerr << "(EE) Read a deprecated GxsTrans outgoing item. Converting to new format..." << std::endl;
|
||||
|
||||
OutgoingRecord ot(dot->recipient,dot->clientService,&dot->mailData[0],dot->mailData.size()) ;
|
||||
|
||||
ot.status = dot->status ;
|
||||
|
||||
ot.author.clear(); // These 3 fields cannot be stored in mailItem.meta, which is not serialised, so they are lost.
|
||||
ot.group_id.clear() ;
|
||||
ot.sent_ts = 0;
|
||||
|
||||
ot.mailItem = dot->mailItem ;
|
||||
ot.presignedReceipt = dot->presignedReceipt;
|
||||
|
||||
RS_STACK_MUTEX(mOutgoingMutex);
|
||||
mOutgoingQueue.insert(prMap::value_type(ot.mailItem.mailId, ot));
|
||||
|
||||
std::cerr << "Loaded outgoing item (converted), ID " << std::hex << std::setfill('0') << std::setw(16) << ot.mailItem.mailId<< std::dec << ", Group id: " << ot.group_id << ", TS=" << ot.sent_ts << std::endl;
|
||||
}
|
||||
delete v;
|
||||
break;
|
||||
}
|
||||
|
||||
case GxsTransItemsSubtypes::OUTGOING_RECORD_ITEM:
|
||||
{
|
||||
OutgoingRecord* ot = dynamic_cast<OutgoingRecord*>(v);
|
||||
@ -959,7 +1002,7 @@ bool p3GxsTrans::loadList(std::list<RsItem *>&loadList)
|
||||
mOutgoingQueue.insert(
|
||||
prMap::value_type(ot->mailItem.mailId, *ot));
|
||||
|
||||
std::cerr << "Loading outgoing item, ID " << std::hex << std::setfill('0') << std::setw(16) << ot->mailItem.mailId<< std::dec << "Group id: " << ot->mailItem.meta.mGroupId << ", TS=" << ot->mailItem.meta.mPublishTs << std::endl;
|
||||
std::cerr << "Loading outgoing item, ID " << std::hex << std::setfill('0') << std::setw(16) << ot->mailItem.mailId<< std::dec << "Group id: " << ot->group_id << ", TS=" << ot->sent_ts << std::endl;
|
||||
}
|
||||
delete v;
|
||||
break;
|
||||
|
@ -204,7 +204,7 @@ private:
|
||||
* item to not being processed and memleaked multimap is used instead of map
|
||||
* for incoming queue.
|
||||
*/
|
||||
typedef std::unordered_multimap<RsGxsTransId, RsGxsTransBaseItem*> inMap;
|
||||
typedef std::unordered_multimap<RsGxsTransId, RsGxsTransBaseMsgItem*> inMap;
|
||||
inMap mIncomingQueue;
|
||||
RsMutex mIngoingMutex;
|
||||
|
||||
|
@ -21,10 +21,11 @@
|
||||
|
||||
const RsGxsId RsGxsTransMailItem::allRecipientsHint("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
|
||||
|
||||
OutgoingRecord::OutgoingRecord() :
|
||||
RsItem( RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_GXS_TRANS,
|
||||
static_cast<uint8_t>(GxsTransItemsSubtypes::OUTGOING_RECORD_ITEM) )
|
||||
{ clear();}
|
||||
OutgoingRecord_deprecated::OutgoingRecord_deprecated()
|
||||
: RsItem( RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_GXS_TRANS, static_cast<uint8_t>(GxsTransItemsSubtypes::OUTGOING_RECORD_ITEM_deprecated) ) { clear();}
|
||||
|
||||
OutgoingRecord::OutgoingRecord()
|
||||
: RsItem( RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_GXS_TRANS, static_cast<uint8_t>(GxsTransItemsSubtypes::OUTGOING_RECORD_ITEM) ) { clear();}
|
||||
|
||||
OutgoingRecord::OutgoingRecord( RsGxsId rec, GxsTransSubServices cs,
|
||||
const uint8_t* data, uint32_t size ) :
|
||||
@ -41,8 +42,7 @@ OutgoingRecord::OutgoingRecord( RsGxsId rec, GxsTransSubServices cs,
|
||||
RS_REGISTER_ITEM_TYPE(RsGxsTransMailItem) // for mailItem
|
||||
RS_REGISTER_ITEM_TYPE(RsNxsTransPresignedReceipt) // for presignedReceipt
|
||||
|
||||
void OutgoingRecord::serial_process(RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx)
|
||||
void OutgoingRecord_deprecated::serial_process(RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RS_REGISTER_SERIAL_MEMBER_TYPED(status, uint8_t);
|
||||
RS_REGISTER_SERIAL_MEMBER(recipient);
|
||||
@ -51,3 +51,17 @@ void OutgoingRecord::serial_process(RsGenericSerializer::SerializeJob j,
|
||||
RS_REGISTER_SERIAL_MEMBER_TYPED(clientService, uint16_t);
|
||||
RS_REGISTER_SERIAL_MEMBER(presignedReceipt);
|
||||
}
|
||||
|
||||
void OutgoingRecord::serial_process(RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RS_REGISTER_SERIAL_MEMBER_TYPED(status, uint8_t);
|
||||
RS_REGISTER_SERIAL_MEMBER(recipient);
|
||||
RS_REGISTER_SERIAL_MEMBER(author);
|
||||
RS_REGISTER_SERIAL_MEMBER(group_id);
|
||||
RS_REGISTER_SERIAL_MEMBER(sent_ts);
|
||||
RS_REGISTER_SERIAL_MEMBER(mailItem);
|
||||
RS_REGISTER_SERIAL_MEMBER(mailData);
|
||||
RS_REGISTER_SERIAL_MEMBER_TYPED(clientService, uint16_t);
|
||||
RS_REGISTER_SERIAL_MEMBER(presignedReceipt);
|
||||
}
|
||||
|
@ -36,14 +36,14 @@ public:
|
||||
virtual ~RsNxsTransPresignedReceipt() {}
|
||||
};
|
||||
|
||||
class RsGxsTransBaseItem : public RsGxsMsgItem
|
||||
class RsGxsTransBaseMsgItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
RsGxsTransBaseItem(GxsTransItemsSubtypes subtype) :
|
||||
RsGxsTransBaseMsgItem(GxsTransItemsSubtypes subtype) :
|
||||
RsGxsMsgItem( RS_SERVICE_TYPE_GXS_TRANS,
|
||||
static_cast<uint8_t>(subtype) ), mailId(0) {}
|
||||
|
||||
virtual ~RsGxsTransBaseItem() {}
|
||||
virtual ~RsGxsTransBaseMsgItem() {}
|
||||
|
||||
RsGxsTransId mailId;
|
||||
|
||||
@ -58,10 +58,10 @@ public:
|
||||
{ RS_REGISTER_SERIAL_MEMBER_TYPED(mailId, uint64_t); }
|
||||
};
|
||||
|
||||
class RsGxsTransPresignedReceipt : public RsGxsTransBaseItem
|
||||
class RsGxsTransPresignedReceipt : public RsGxsTransBaseMsgItem
|
||||
{
|
||||
public:
|
||||
RsGxsTransPresignedReceipt() : RsGxsTransBaseItem(GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_RECEIPT) {}
|
||||
RsGxsTransPresignedReceipt() : RsGxsTransBaseMsgItem(GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_RECEIPT) {}
|
||||
virtual ~RsGxsTransPresignedReceipt() {}
|
||||
};
|
||||
|
||||
@ -72,11 +72,11 @@ enum class RsGxsTransEncryptionMode : uint8_t
|
||||
UNDEFINED_ENCRYPTION = 250
|
||||
};
|
||||
|
||||
class RsGxsTransMailItem : public RsGxsTransBaseItem
|
||||
class RsGxsTransMailItem : public RsGxsTransBaseMsgItem
|
||||
{
|
||||
public:
|
||||
RsGxsTransMailItem() :
|
||||
RsGxsTransBaseItem(GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_MAIL),
|
||||
RsGxsTransBaseMsgItem(GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_MAIL),
|
||||
cryptoType(RsGxsTransEncryptionMode::UNDEFINED_ENCRYPTION) {}
|
||||
|
||||
virtual ~RsGxsTransMailItem() {}
|
||||
@ -139,7 +139,7 @@ public:
|
||||
void serial_process( RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx )
|
||||
{
|
||||
RsGxsTransBaseItem::serial_process(j, ctx);
|
||||
RsGxsTransBaseMsgItem::serial_process(j, ctx);
|
||||
RS_REGISTER_SERIAL_MEMBER_TYPED(cryptoType, uint8_t);
|
||||
RS_REGISTER_SERIAL_MEMBER(recipientHint);
|
||||
RS_REGISTER_SERIAL_MEMBER(payload);
|
||||
@ -147,7 +147,7 @@ public:
|
||||
|
||||
void clear()
|
||||
{
|
||||
RsGxsTransBaseItem::clear();
|
||||
RsGxsTransBaseMsgItem::clear();
|
||||
cryptoType = RsGxsTransEncryptionMode::UNDEFINED_ENCRYPTION;
|
||||
recipientHint.clear();
|
||||
payload.clear();
|
||||
@ -183,6 +183,33 @@ public:
|
||||
|
||||
class RsGxsTransSerializer;
|
||||
|
||||
class OutgoingRecord_deprecated : public RsItem
|
||||
{
|
||||
public:
|
||||
OutgoingRecord_deprecated( RsGxsId rec, GxsTransSubServices cs, const uint8_t* data, uint32_t size );
|
||||
|
||||
virtual ~OutgoingRecord_deprecated() {}
|
||||
|
||||
GxsTransSendStatus status;
|
||||
RsGxsId recipient;
|
||||
/// Don't use a pointer would be invalid after publish
|
||||
RsGxsTransMailItem mailItem;
|
||||
|
||||
std::vector<uint8_t> mailData;
|
||||
GxsTransSubServices clientService;
|
||||
|
||||
RsNxsTransPresignedReceipt presignedReceipt;
|
||||
|
||||
void serial_process( RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx );
|
||||
|
||||
void clear() {}
|
||||
|
||||
private:
|
||||
friend class RsGxsTransSerializer;
|
||||
OutgoingRecord_deprecated();
|
||||
};
|
||||
|
||||
class OutgoingRecord : public RsItem
|
||||
{
|
||||
public:
|
||||
@ -191,12 +218,19 @@ public:
|
||||
|
||||
virtual ~OutgoingRecord() {}
|
||||
|
||||
GxsTransSendStatus status;
|
||||
RsGxsId recipient;
|
||||
GxsTransSendStatus status;
|
||||
RsGxsId recipient;
|
||||
|
||||
RsGxsId author; // These 3 fields cannot be stored in mailItem.meta, which is not serialised.
|
||||
RsGxsGroupId group_id ;
|
||||
uint32_t sent_ts ;
|
||||
|
||||
/// Don't use a pointer would be invalid after publish
|
||||
RsGxsTransMailItem mailItem;
|
||||
|
||||
std::vector<uint8_t> mailData;
|
||||
GxsTransSubServices clientService;
|
||||
|
||||
RsNxsTransPresignedReceipt presignedReceipt;
|
||||
|
||||
void serial_process( RsGenericSerializer::SerializeJob j,
|
||||
@ -225,6 +259,7 @@ public:
|
||||
case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_MAIL: return new RsGxsTransMailItem();
|
||||
case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_RECEIPT: return new RsGxsTransPresignedReceipt();
|
||||
case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_GROUP: return new RsGxsTransGroupItem();
|
||||
case GxsTransItemsSubtypes::OUTGOING_RECORD_ITEM_deprecated: return new OutgoingRecord_deprecated();
|
||||
case GxsTransItemsSubtypes::OUTGOING_RECORD_ITEM: return new OutgoingRecord();
|
||||
default: return NULL;
|
||||
}
|
||||
|
@ -16,10 +16,11 @@ enum class GxsTransSubServices : uint16_t
|
||||
/// Values must fit into uint8_t
|
||||
enum class GxsTransItemsSubtypes : uint8_t
|
||||
{
|
||||
GXS_TRANS_SUBTYPE_MAIL = 0x01,
|
||||
GXS_TRANS_SUBTYPE_RECEIPT = 0x02,
|
||||
GXS_TRANS_SUBTYPE_GROUP = 0x03,
|
||||
OUTGOING_RECORD_ITEM = 0x04
|
||||
GXS_TRANS_SUBTYPE_MAIL = 0x01,
|
||||
GXS_TRANS_SUBTYPE_RECEIPT = 0x02,
|
||||
GXS_TRANS_SUBTYPE_GROUP = 0x03,
|
||||
OUTGOING_RECORD_ITEM_deprecated = 0x04,
|
||||
OUTGOING_RECORD_ITEM = 0x05
|
||||
};
|
||||
|
||||
enum class GxsTransSendStatus : uint8_t
|
||||
|
Loading…
Reference in New Issue
Block a user