mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-05 07:35:12 -04:00
merged upstream/master
This commit is contained in:
commit
1f0678075f
111 changed files with 3722 additions and 2428 deletions
|
@ -465,14 +465,17 @@ void JsonApiServer::registerHandler(
|
|||
const std::shared_ptr<rb::Session> session,
|
||||
const std::function<void (const std::shared_ptr<rb::Session>)>& callback )
|
||||
{
|
||||
/* Declare outside the lambda to avoid returning a dangling
|
||||
* reference on Android */
|
||||
RsWarn tWarn;
|
||||
const auto authFail =
|
||||
[&path, &session](int status) -> RsWarn::stream_type&
|
||||
[&](int status) -> RsWarn::stream_type&
|
||||
{
|
||||
/* Capture session by reference as it is cheaper then copying
|
||||
* shared_ptr by value which is not needed in this case */
|
||||
|
||||
session->close(status, corsOptionsHeaders);
|
||||
return RsWarn() << "JsonApiServer authentication handler "
|
||||
return tWarn << "JsonApiServer authentication handler "
|
||||
"blocked an attempt to call JSON API "
|
||||
"authenticated method: " << path;
|
||||
};
|
||||
|
|
|
@ -404,10 +404,16 @@ int AuthSSLimpl::InitAuth(
|
|||
|
||||
std::cout.flush() ;
|
||||
|
||||
#ifndef RS_DISABLE_DIFFIE_HELLMAN_INIT_CHECK
|
||||
if(DH_check(dh, &codes) && codes == 0)
|
||||
SSL_CTX_set_tmp_dh(sslctx, dh);
|
||||
SSL_CTX_set_tmp_dh(sslctx, dh);
|
||||
else
|
||||
pfs_enabled = false ;
|
||||
pfs_enabled = false;
|
||||
#else // ndef RS_DISABLE_DIFFIE_HELLMAN_INIT_CHECK
|
||||
/* DH_check(...) is not strictly necessary and on Android devices it
|
||||
* takes at least one minute which is untolerable there */
|
||||
SSL_CTX_set_tmp_dh(sslctx, dh);
|
||||
#endif // ndef RS_DISABLE_DIFFIE_HELLMAN_INIT_CHECK
|
||||
}
|
||||
else
|
||||
pfs_enabled = false ;
|
||||
|
|
|
@ -245,7 +245,7 @@ public:
|
|||
std::vector<RsMsgMetaData>& msgMetas) = 0;
|
||||
|
||||
/**
|
||||
* @brief Get specific list of messages from a single forums. Blocking API
|
||||
* @brief Get specific list of messages from a single forum. Blocking API
|
||||
* @jsonapi{development}
|
||||
* @param[in] forumId id of the forum of which the content is requested
|
||||
* @param[in] msgsIds list of message ids to request
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* *
|
||||
* libretroshare: retroshare core library *
|
||||
* *
|
||||
* Copyright 2012-2012 by Robert Fernie <retroshare@lunamutt.com> *
|
||||
* Copyright 2012-2020 by Robert Fernie <retroshare@lunamutt.com> *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
|
@ -45,11 +45,7 @@ class RsWireGroup
|
|||
|
||||
|
||||
/***********************************************************************
|
||||
* So pulses operate in the following modes.
|
||||
*
|
||||
* => Standard, a post to your own group.
|
||||
* => @User, gets duplicated on each user's group.
|
||||
* => RT, duplicated as child of original post.
|
||||
* RsWire - is intended to be a Twitter clone - but fully decentralised.
|
||||
*
|
||||
* From Twitter:
|
||||
* twitter can be: embedded, replied to, favourited, unfavourited,
|
||||
|
@ -73,6 +69,36 @@ class RsWirePlace
|
|||
|
||||
};
|
||||
|
||||
/************************************************************************
|
||||
* Pulse comes in three flavours.
|
||||
*
|
||||
*
|
||||
* Original Msg Pulse
|
||||
* - Spontaneous msg, on your own group.
|
||||
* - mPulseType = WIRE_PULSE_TYPE_ORIGINAL_MSG
|
||||
* - Ref fields are empty.
|
||||
*
|
||||
* Reply to a Pulse (i.e Retweet), has two parts.
|
||||
* as we want the retweet to reference the original, and the original to know about reply.
|
||||
* This info will be duplicated in two msgs - but allow data to spread easier.
|
||||
*
|
||||
* Reply Msg Pulse, will be Top-Level Msg on Publisher's Group.
|
||||
* - mPulseMode = WIRE_PULSE_TYPE_REPLY_MSG
|
||||
* - Ref fields refer to Parent (InReplyTo) Msg.
|
||||
*
|
||||
* Reply Reference, is Child Msg of Parent Msg, on Parent Publisher's Group.
|
||||
* - mPulseMode = WIRE_PULSE_TYPE_REPLY_REFERENCE
|
||||
* - Ref fields refer to Reply Msg.
|
||||
* - NB: This Msg requires Parent Msg for complete info, while other two are self-contained.
|
||||
***********************************************************************/
|
||||
|
||||
#define WIRE_PULSE_TYPE_ORIGINAL_MSG (0x0001)
|
||||
#define WIRE_PULSE_TYPE_REPLY_MSG (0x0002)
|
||||
#define WIRE_PULSE_TYPE_REPLY_REFERENCE (0x0004)
|
||||
|
||||
#define WIRE_PULSE_TYPE_SENTIMENT_POSITIVE (0x0010)
|
||||
#define WIRE_PULSE_TYPE_SENTIMENT_NEUTRAL (0x0020)
|
||||
#define WIRE_PULSE_TYPE_SENTIMENT_NEGATIVE (0x0040)
|
||||
|
||||
class RsWirePulse
|
||||
{
|
||||
|
@ -80,19 +106,26 @@ class RsWirePulse
|
|||
|
||||
RsMsgMetaData mMeta;
|
||||
|
||||
std::string mPulseText; // all the text is stored here.
|
||||
std::string mHashTags;
|
||||
// Store actual Pulse here.
|
||||
std::string mPulseText;
|
||||
|
||||
// These will be added at some point.
|
||||
// std::string mInReplyPulse;
|
||||
uint32_t mPulseType;
|
||||
|
||||
// uint32_t mPulseFlags;
|
||||
// These Ref to the related (parent or reply) if reply (MODE_REPLY_MSG set)
|
||||
// Mode REPLY_MSG only REPLY_REFERENCE
|
||||
RsGxsGroupId mRefGroupId; // PARENT_GrpId REPLY_GrpId
|
||||
std::string mRefGroupName; // PARENT_GrpName REPLY_GrpName
|
||||
RsGxsMessageId mRefOrigMsgId; // PARENT_OrigMsgId REPLY_OrigMsgId
|
||||
RsGxsId mRefAuthorId; // PARENT_AuthorId REPLY_AuthorId
|
||||
rstime_t mRefPublishTs; // PARENT_PublishTs REPLY_PublishTs
|
||||
std::string mRefPulseText; // PARENT_PulseText REPLY_PulseText
|
||||
|
||||
// std::list<std::string> mMentions;
|
||||
// std::list<std::string> mHashTags;
|
||||
// std::list<std::string> mUrls;
|
||||
|
||||
// RsWirePlace mPlace;
|
||||
// Open Question. Do we want these additional fields?
|
||||
// These can potentially be added at some point.
|
||||
// std::list<std::string> mMentions;
|
||||
// std::list<std::string> mHashTags;
|
||||
// std::list<std::string> mUrls;
|
||||
// RsWirePlace mPlace;
|
||||
};
|
||||
|
||||
|
||||
|
@ -107,6 +140,13 @@ class RsWire: public RsGxsIfaceHelper
|
|||
explicit RsWire(RsGxsIface& gxs) : RsGxsIfaceHelper(gxs) {}
|
||||
virtual ~RsWire() {}
|
||||
|
||||
/*!
|
||||
* To acquire a handle to token service handler
|
||||
* needed to make requests to the service
|
||||
* @return handle to token service for this gxs service
|
||||
*/
|
||||
virtual RsTokenService* getTokenService() = 0;
|
||||
|
||||
/* Specific Service Data */
|
||||
virtual bool getGroupData(const uint32_t &token, std::vector<RsWireGroup> &groups) = 0;
|
||||
virtual bool getPulseData(const uint32_t &token, std::vector<RsWirePulse> &pulses) = 0;
|
||||
|
|
|
@ -64,6 +64,7 @@ enum class RsServiceType : uint16_t
|
|||
GXS_TRANS = 0x0230,
|
||||
JSONAPI = 0x0240,
|
||||
FORUMS_CONFIG = 0x0315,
|
||||
POSTED_CONFIG = 0x0316,
|
||||
CHANNELS_CONFIG = 0x0317,
|
||||
RTT = 0x1011, /// Round Trip Time
|
||||
|
||||
|
@ -123,7 +124,9 @@ RS_DEPRECATED_FOR(RsServiceType) const uint16_t RS_SERVICE_GXS_TYPE_REPUTATION
|
|||
RS_DEPRECATED_FOR(RsServiceType) const uint16_t RS_SERVICE_TYPE_GXS_RECOGN = 0x0220;
|
||||
RS_DEPRECATED_FOR(RsServiceType) const uint16_t RS_SERVICE_TYPE_GXS_TRANS = 0x0230;
|
||||
RS_DEPRECATED_FOR(RsServiceType) const uint16_t RS_SERVICE_TYPE_JSONAPI = 0x0240;
|
||||
/// used to save notification records in GXS and possible other service-based configuration
|
||||
RS_DEPRECATED_FOR(RsServiceType) const uint16_t RS_SERVICE_GXS_TYPE_FORUMS_CONFIG = 0x0315;
|
||||
RS_DEPRECATED_FOR(RsServiceType) const uint16_t RS_SERVICE_GXS_TYPE_POSTED_CONFIG = 0x0316;
|
||||
RS_DEPRECATED_FOR(RsServiceType) const uint16_t RS_SERVICE_GXS_TYPE_CHANNELS_CONFIG = 0x0317;
|
||||
|
||||
// Experimental Services.
|
||||
|
|
|
@ -29,16 +29,16 @@
|
|||
|
||||
RsItem *RsGxsWireSerialiser::create_item(uint16_t service,uint8_t item_subtype) const
|
||||
{
|
||||
if(service != RS_SERVICE_GXS_TYPE_WIRE)
|
||||
return NULL ;
|
||||
if(service != RS_SERVICE_GXS_TYPE_WIRE)
|
||||
return NULL ;
|
||||
|
||||
switch(item_subtype)
|
||||
{
|
||||
case RS_PKT_SUBTYPE_WIRE_GROUP_ITEM: return new RsGxsWireGroupItem();
|
||||
case RS_PKT_SUBTYPE_WIRE_PULSE_ITEM: return new RsGxsWirePulseItem();
|
||||
default:
|
||||
return NULL ;
|
||||
}
|
||||
switch(item_subtype)
|
||||
{
|
||||
case RS_PKT_SUBTYPE_WIRE_GROUP_ITEM: return new RsGxsWireGroupItem();
|
||||
case RS_PKT_SUBTYPE_WIRE_PULSE_ITEM: return new RsGxsWirePulseItem();
|
||||
default:
|
||||
return NULL ;
|
||||
}
|
||||
}
|
||||
|
||||
void RsGxsWireGroupItem::clear()
|
||||
|
@ -48,18 +48,30 @@ void RsGxsWireGroupItem::clear()
|
|||
|
||||
void RsGxsWireGroupItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_DESCR,group.mDescription,"group.mDescription") ;
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_DESCR,group.mDescription,"group.mDescription") ;
|
||||
}
|
||||
|
||||
void RsGxsWirePulseItem::clear()
|
||||
{
|
||||
pulse.mPulseText.clear();
|
||||
pulse.mHashTags.clear();
|
||||
pulse.mPulseType = 0;
|
||||
pulse.mRefGroupId.clear();
|
||||
pulse.mRefGroupName.clear();
|
||||
pulse.mRefOrigMsgId.clear();
|
||||
pulse.mRefAuthorId.clear();
|
||||
pulse.mRefPulseText.clear();
|
||||
}
|
||||
|
||||
void RsGxsWirePulseItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_MSG,pulse.mPulseText,"pulse.mPulseText") ;
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_HASH_TAG,pulse.mHashTags,"pulse.mHashTags") ;
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_MSG,pulse.mPulseText,"pulse.mPulseText") ;
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_UINT32_PARAM,pulse.mPulseType,"pulse.mPulseType") ;
|
||||
RsTypeSerializer::serial_process(j,ctx,pulse.mRefGroupId,"pulse.mRefGroupId") ;
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_NAME,pulse.mRefGroupName,"pulse.mRefGroupName") ;
|
||||
RsTypeSerializer::serial_process(j,ctx,pulse.mRefOrigMsgId,"pulse.mRefOrigMsgId") ;
|
||||
RsTypeSerializer::serial_process(j,ctx,pulse.mRefAuthorId,"pulse.mRefAuthorId") ;
|
||||
RsTypeSerializer::serial_process(j,ctx,pulse.mRefPublishTs,"pulse.mRefPublishTs") ;
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_MSG,pulse.mRefPulseText,"pulse.mRefPulseText") ;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1381,8 +1381,7 @@ int RsServer::StartupRetroShare()
|
|||
#ifdef RS_USE_WIRE
|
||||
/**** Wire GXS service ****/
|
||||
RsGeneralDataService* wire_ds = new RsDataService(currGxsDir + "/", "wire_db",
|
||||
RS_SERVICE_GXS_TYPE_WIRE,
|
||||
NULL, rsInitConfig->gxs_passwd);
|
||||
RS_SERVICE_GXS_TYPE_WIRE, NULL, rsInitConfig->gxs_passwd);
|
||||
|
||||
p3Wire *mWire = new p3Wire(wire_ds, NULL, mGxsIdService);
|
||||
|
||||
|
@ -1633,6 +1632,7 @@ int RsServer::StartupRetroShare()
|
|||
mConfigMgr->addConfiguration("gxschannels_srv.cfg", mGxsChannels);
|
||||
mConfigMgr->addConfiguration("gxscircles.cfg" , gxscircles_ns);
|
||||
mConfigMgr->addConfiguration("posted.cfg" , posted_ns);
|
||||
mConfigMgr->addConfiguration("gxsposted_srv.cfg", mPosted);
|
||||
#ifdef RS_USE_WIKI
|
||||
mConfigMgr->addConfiguration("wiki.cfg", wiki_ns);
|
||||
#endif
|
||||
|
@ -1826,7 +1826,7 @@ int RsServer::StartupRetroShare()
|
|||
startServiceThread(mPhoto, "gxs photo");
|
||||
#endif
|
||||
#if RS_USE_WIRE
|
||||
startServiceThread(mPhoto, "gxs wire");
|
||||
startServiceThread(mWire, "gxs wire");
|
||||
#endif
|
||||
|
||||
// cores ready start up GXS net servers
|
||||
|
@ -1843,7 +1843,7 @@ int RsServer::StartupRetroShare()
|
|||
startServiceThread(photo_ns, "gxs photo ns");
|
||||
#endif
|
||||
#if RS_USE_WIRE
|
||||
startServiceThread(photo_ns, "gxs wire ns");
|
||||
startServiceThread(wire_ns, "gxs wire ns");
|
||||
#endif
|
||||
|
||||
# ifdef RS_GXS_TRANS
|
||||
|
|
|
@ -136,14 +136,14 @@ uint32_t p3GxsChannels::channelsAuthenPolicy()
|
|||
static const uint32_t GXS_CHANNELS_CONFIG_MAX_TIME_NOTIFY_STORAGE = 86400*30*2 ; // ignore notifications for 2 months
|
||||
static const uint8_t GXS_CHANNELS_CONFIG_SUBTYPE_NOTIFY_RECORD = 0x01 ;
|
||||
|
||||
struct RsGxsGroupNotifyRecordsItem: public RsItem
|
||||
struct RsGxsChannelNotifyRecordsItem: public RsItem
|
||||
{
|
||||
|
||||
RsGxsGroupNotifyRecordsItem()
|
||||
RsGxsChannelNotifyRecordsItem()
|
||||
: RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_GXS_TYPE_CHANNELS_CONFIG,GXS_CHANNELS_CONFIG_SUBTYPE_NOTIFY_RECORD)
|
||||
{}
|
||||
|
||||
virtual ~RsGxsGroupNotifyRecordsItem() {}
|
||||
virtual ~RsGxsChannelNotifyRecordsItem() {}
|
||||
|
||||
void serial_process( RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx )
|
||||
|
@ -167,7 +167,7 @@ public:
|
|||
|
||||
switch(item_sub_id)
|
||||
{
|
||||
case GXS_CHANNELS_CONFIG_SUBTYPE_NOTIFY_RECORD: return new RsGxsGroupNotifyRecordsItem();
|
||||
case GXS_CHANNELS_CONFIG_SUBTYPE_NOTIFY_RECORD: return new RsGxsChannelNotifyRecordsItem();
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
|
@ -178,7 +178,7 @@ bool p3GxsChannels::saveList(bool &cleanup, std::list<RsItem *>&saveList)
|
|||
{
|
||||
cleanup = true ;
|
||||
|
||||
RsGxsGroupNotifyRecordsItem *item = new RsGxsGroupNotifyRecordsItem ;
|
||||
RsGxsChannelNotifyRecordsItem *item = new RsGxsChannelNotifyRecordsItem ;
|
||||
|
||||
{
|
||||
RS_STACK_MUTEX(mKnownChannelsMutex);
|
||||
|
@ -198,7 +198,7 @@ bool p3GxsChannels::loadList(std::list<RsItem *>& loadList)
|
|||
|
||||
rstime_t now = time(NULL);
|
||||
|
||||
RsGxsGroupNotifyRecordsItem *fnr = dynamic_cast<RsGxsGroupNotifyRecordsItem*>(item) ;
|
||||
RsGxsChannelNotifyRecordsItem *fnr = dynamic_cast<RsGxsChannelNotifyRecordsItem*>(item) ;
|
||||
|
||||
if(fnr)
|
||||
{
|
||||
|
@ -206,7 +206,7 @@ bool p3GxsChannels::loadList(std::list<RsItem *>& loadList)
|
|||
mKnownChannels.clear();
|
||||
|
||||
for(auto it(fnr->records.begin());it!=fnr->records.end();++it)
|
||||
if( it->second + GXS_CHANNELS_CONFIG_MAX_TIME_NOTIFY_STORAGE < now)
|
||||
if( now < it->second + GXS_CHANNELS_CONFIG_MAX_TIME_NOTIFY_STORAGE)
|
||||
mKnownChannels.insert(*it) ;
|
||||
}
|
||||
|
||||
|
|
|
@ -96,14 +96,14 @@ uint32_t p3GxsForums::forumsAuthenPolicy()
|
|||
static const uint32_t GXS_FORUMS_CONFIG_MAX_TIME_NOTIFY_STORAGE = 86400*30*2 ; // ignore notifications for 2 months
|
||||
static const uint8_t GXS_FORUMS_CONFIG_SUBTYPE_NOTIFY_RECORD = 0x01 ;
|
||||
|
||||
struct RsGxsGroupNotifyRecordsItem: public RsItem
|
||||
struct RsGxsForumNotifyRecordsItem: public RsItem
|
||||
{
|
||||
|
||||
RsGxsGroupNotifyRecordsItem()
|
||||
RsGxsForumNotifyRecordsItem()
|
||||
: RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_GXS_TYPE_FORUMS_CONFIG,GXS_FORUMS_CONFIG_SUBTYPE_NOTIFY_RECORD)
|
||||
{}
|
||||
|
||||
virtual ~RsGxsGroupNotifyRecordsItem() {}
|
||||
virtual ~RsGxsForumNotifyRecordsItem() {}
|
||||
|
||||
void serial_process( RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx )
|
||||
|
@ -127,7 +127,7 @@ public:
|
|||
|
||||
switch(item_sub_id)
|
||||
{
|
||||
case GXS_FORUMS_CONFIG_SUBTYPE_NOTIFY_RECORD: return new RsGxsGroupNotifyRecordsItem();
|
||||
case GXS_FORUMS_CONFIG_SUBTYPE_NOTIFY_RECORD: return new RsGxsForumNotifyRecordsItem();
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
|
@ -138,7 +138,7 @@ bool p3GxsForums::saveList(bool &cleanup, std::list<RsItem *>&saveList)
|
|||
{
|
||||
cleanup = true ;
|
||||
|
||||
RsGxsGroupNotifyRecordsItem *item = new RsGxsGroupNotifyRecordsItem ;
|
||||
RsGxsForumNotifyRecordsItem *item = new RsGxsForumNotifyRecordsItem ;
|
||||
|
||||
item->records = mKnownForums ;
|
||||
|
||||
|
@ -155,14 +155,14 @@ bool p3GxsForums::loadList(std::list<RsItem *>& loadList)
|
|||
|
||||
rstime_t now = time(NULL);
|
||||
|
||||
RsGxsGroupNotifyRecordsItem *fnr = dynamic_cast<RsGxsGroupNotifyRecordsItem*>(item) ;
|
||||
RsGxsForumNotifyRecordsItem *fnr = dynamic_cast<RsGxsForumNotifyRecordsItem*>(item) ;
|
||||
|
||||
if(fnr != NULL)
|
||||
{
|
||||
mKnownForums.clear();
|
||||
|
||||
for(auto it(fnr->records.begin());it!=fnr->records.end();++it)
|
||||
if( it->second + GXS_FORUMS_CONFIG_MAX_TIME_NOTIFY_STORAGE < now)
|
||||
if( now < it->second + GXS_FORUMS_CONFIG_MAX_TIME_NOTIFY_STORAGE)
|
||||
mKnownForums.insert(*it) ;
|
||||
}
|
||||
|
||||
|
|
|
@ -157,15 +157,26 @@ void p3PostBase::notifyChanges(std::vector<RsGxsNotify *> &changes)
|
|||
const std::list<RsGxsGroupId>& grpList = grpChange->mGrpIdList;
|
||||
|
||||
for (auto git = grpList.begin(); git != grpList.end(); ++git)
|
||||
{
|
||||
{
|
||||
if(mKnownPosted.find(*git) == mKnownPosted.end())
|
||||
{
|
||||
mKnownPosted.insert(std::make_pair(*git, time(nullptr)));
|
||||
IndicateConfigChanged();
|
||||
|
||||
auto ev = std::make_shared<RsGxsPostedEvent>();
|
||||
ev->mPostedGroupId = *git;
|
||||
ev->mPostedEventCode = RsPostedEventCode::NEW_POSTED_GROUP;
|
||||
rsEvents->postEvent(ev);
|
||||
|
||||
#ifdef POSTBASE_DEBUG
|
||||
std::cerr << "p3PostBase::notifyChanges() Incoming Group: " << *git;
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "p3PostBase::notifyChanges() Incoming Group: " << *git;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
auto ev = std::make_shared<RsGxsPostedEvent>();
|
||||
ev->mPostedGroupId = *git;
|
||||
ev->mPostedEventCode = RsPostedEventCode::NEW_POSTED_GROUP;
|
||||
rsEvents->postEvent(ev);
|
||||
}
|
||||
else
|
||||
RsInfo() << __PRETTY_FUNCTION__
|
||||
<< " Not notifying already known forum "
|
||||
<< *git << std::endl;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -828,3 +839,89 @@ void p3PostBase::handleResponse(uint32_t token, uint32_t req_type)
|
|||
}
|
||||
}
|
||||
|
||||
static const uint32_t GXS_POSTED_CONFIG_MAX_TIME_NOTIFY_STORAGE = 86400*30*2 ; // ignore notifications for 2 months
|
||||
static const uint8_t GXS_POSTED_CONFIG_SUBTYPE_NOTIFY_RECORD = 0x01 ;
|
||||
|
||||
struct RsGxsPostedNotifyRecordsItem: public RsItem
|
||||
{
|
||||
|
||||
RsGxsPostedNotifyRecordsItem()
|
||||
: RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_GXS_TYPE_POSTED_CONFIG,GXS_POSTED_CONFIG_SUBTYPE_NOTIFY_RECORD)
|
||||
{}
|
||||
|
||||
virtual ~RsGxsPostedNotifyRecordsItem() {}
|
||||
|
||||
void serial_process( RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx )
|
||||
{ RS_SERIAL_PROCESS(records); }
|
||||
|
||||
void clear() {}
|
||||
|
||||
std::map<RsGxsGroupId,rstime_t> records;
|
||||
};
|
||||
|
||||
class GxsPostedConfigSerializer : public RsServiceSerializer
|
||||
{
|
||||
public:
|
||||
GxsPostedConfigSerializer() : RsServiceSerializer(RS_SERVICE_GXS_TYPE_POSTED_CONFIG) {}
|
||||
virtual ~GxsPostedConfigSerializer() {}
|
||||
|
||||
RsItem* create_item(uint16_t service_id, uint8_t item_sub_id) const
|
||||
{
|
||||
if(service_id != RS_SERVICE_GXS_TYPE_POSTED_CONFIG)
|
||||
return NULL;
|
||||
|
||||
switch(item_sub_id)
|
||||
{
|
||||
case GXS_POSTED_CONFIG_SUBTYPE_NOTIFY_RECORD: return new RsGxsPostedNotifyRecordsItem();
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
bool p3PostBase::saveList(bool &cleanup, std::list<RsItem *>&saveList)
|
||||
{
|
||||
cleanup = true ;
|
||||
|
||||
RsGxsPostedNotifyRecordsItem *item = new RsGxsPostedNotifyRecordsItem ;
|
||||
|
||||
item->records = mKnownPosted ;
|
||||
|
||||
saveList.push_back(item) ;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3PostBase::loadList(std::list<RsItem *>& loadList)
|
||||
{
|
||||
while(!loadList.empty())
|
||||
{
|
||||
RsItem *item = loadList.front();
|
||||
loadList.pop_front();
|
||||
|
||||
rstime_t now = time(NULL);
|
||||
|
||||
RsGxsPostedNotifyRecordsItem *fnr = dynamic_cast<RsGxsPostedNotifyRecordsItem*>(item) ;
|
||||
|
||||
if(fnr != NULL)
|
||||
{
|
||||
mKnownPosted.clear();
|
||||
|
||||
for(auto it(fnr->records.begin());it!=fnr->records.end();++it)
|
||||
if( now < it->second + GXS_POSTED_CONFIG_MAX_TIME_NOTIFY_STORAGE)
|
||||
mKnownPosted.insert(*it) ;
|
||||
}
|
||||
|
||||
delete item ;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
RsSerialiser* p3PostBase::setupSerialiser()
|
||||
{
|
||||
RsSerialiser* rss = new RsSerialiser;
|
||||
rss->addSerialType(new GxsPostedConfigSerializer());
|
||||
|
||||
return rss;
|
||||
}
|
||||
|
||||
|
|
|
@ -63,39 +63,44 @@ bool encodePostCache(std::string &str, const PostStats &s);
|
|||
bool extractPostCache(const std::string &str, PostStats &s);
|
||||
|
||||
|
||||
class p3PostBase: public RsGenExchange, public GxsTokenQueue, public RsTickEvent
|
||||
class p3PostBase: public RsGenExchange, public GxsTokenQueue, public RsTickEvent, public p3Config
|
||||
{
|
||||
public:
|
||||
public:
|
||||
|
||||
p3PostBase(RsGeneralDataService *gds, RsNetworkExchangeService *nes, RsGixs* gixs,
|
||||
RsSerialType* serviceSerialiser, uint16_t serviceType);
|
||||
RsSerialType* serviceSerialiser, uint16_t serviceType);
|
||||
|
||||
virtual void service_tick();
|
||||
virtual void service_tick();
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
virtual void notifyChanges(std::vector<RsGxsNotify*>& changes);
|
||||
virtual void notifyChanges(std::vector<RsGxsNotify*>& changes);
|
||||
|
||||
// Overloaded from GxsTokenQueue for Request callbacks.
|
||||
virtual void handleResponse(uint32_t token, uint32_t req_type);
|
||||
// Overloaded from GxsTokenQueue for Request callbacks.
|
||||
virtual void handleResponse(uint32_t token, uint32_t req_type);
|
||||
|
||||
// Overloaded from RsTickEvent.
|
||||
virtual void handle_event(uint32_t event_type, const std::string &elabel);
|
||||
// Overloaded from RsTickEvent.
|
||||
virtual void handle_event(uint32_t event_type, const std::string &elabel);
|
||||
|
||||
public:
|
||||
// overloads p3Config
|
||||
virtual RsSerialiser* setupSerialiser() override; // @see p3Config::setupSerialiser()
|
||||
virtual bool saveList(bool &cleanup, std::list<RsItem *>&saveList) override; // @see p3Config::saveList(bool &cleanup, std::list<RsItem *>&)
|
||||
virtual bool loadList(std::list<RsItem *>& loadList) override; // @see p3Config::loadList(std::list<RsItem *>&)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
public:
|
||||
|
||||
virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read);
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read);
|
||||
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
p3GxsCommentService *mCommentService;
|
||||
p3GxsCommentService *mCommentService;
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
static uint32_t postBaseAuthenPolicy();
|
||||
static uint32_t postBaseAuthenPolicy();
|
||||
|
||||
// Background processing.
|
||||
void background_tick();
|
||||
|
@ -116,13 +121,14 @@ static uint32_t postBaseAuthenPolicy();
|
|||
bool background_cleanup();
|
||||
|
||||
|
||||
RsMutex mPostBaseMtx;
|
||||
RsMutex mPostBaseMtx;
|
||||
|
||||
bool mBgProcessing;
|
||||
bool mBgIncremental;
|
||||
std::list<RsGxsGroupId> mBgGroupList;
|
||||
std::map<RsGxsMessageId, PostStats> mBgStatsMap;
|
||||
std::list<RsGxsGroupId> mBgGroupList;
|
||||
std::map<RsGxsMessageId, PostStats> mBgStatsMap;
|
||||
|
||||
std::map<RsGxsGroupId,rstime_t> mKnownPosted;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* *
|
||||
* libretroshare: retroshare core library *
|
||||
* *
|
||||
* Copyright 2012-2012 by Robert Fernie <retroshare@lunamutt.com> *
|
||||
* Copyright 2012-2020 by Robert Fernie <retroshare@lunamutt.com> *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
|
@ -83,6 +83,10 @@ void p3Wire::service_tick()
|
|||
return;
|
||||
}
|
||||
|
||||
RsTokenService* p3Wire::getTokenService() {
|
||||
|
||||
return RsGenExchange::getTokenService();
|
||||
}
|
||||
|
||||
void p3Wire::notifyChanges(std::vector<RsGxsNotify*>& changes)
|
||||
{
|
||||
|
@ -175,12 +179,12 @@ bool p3Wire::createGroup(uint32_t &token, RsWireGroup &group)
|
|||
groupItem->group = group;
|
||||
groupItem->meta = group.mMeta;
|
||||
|
||||
std::cerr << "p3Wire::createGroup(): ";
|
||||
std::cerr << "p3Wire::createGroup(): ";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << group;
|
||||
std::cerr << std::endl;
|
||||
|
||||
std::cerr << "p3Wire::createGroup() pushing to RsGenExchange";
|
||||
std::cerr << "p3Wire::createGroup() pushing to RsGenExchange";
|
||||
std::cerr << std::endl;
|
||||
|
||||
RsGenExchange::publishGroup(token, groupItem);
|
||||
|
@ -193,11 +197,11 @@ bool p3Wire::createPulse(uint32_t &token, RsWirePulse &pulse)
|
|||
std::cerr << "p3Wire::createPulse(): " << pulse;
|
||||
std::cerr << std::endl;
|
||||
|
||||
RsGxsWirePulseItem* pulseItem = new RsGxsWirePulseItem();
|
||||
pulseItem->pulse = pulse;
|
||||
pulseItem->meta = pulse.mMeta;
|
||||
RsGxsWirePulseItem* pulseItem = new RsGxsWirePulseItem();
|
||||
pulseItem->pulse = pulse;
|
||||
pulseItem->meta = pulse.mMeta;
|
||||
|
||||
RsGenExchange::publishMsg(token, pulseItem);
|
||||
RsGenExchange::publishMsg(token, pulseItem);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* *
|
||||
* libretroshare: retroshare core library *
|
||||
* *
|
||||
* Copyright 2012-2012 by Robert Fernie <retroshare@lunamutt.com> *
|
||||
* Copyright 2012-2020 by Robert Fernie <retroshare@lunamutt.com> *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
|
@ -34,37 +34,33 @@
|
|||
*
|
||||
*/
|
||||
|
||||
|
||||
class p3Wire: public RsGenExchange, public RsWire
|
||||
{
|
||||
public:
|
||||
p3Wire(RsGeneralDataService* gds, RsNetworkExchangeService* nes, RsGixs *gixs);
|
||||
virtual RsServiceInfo getServiceInfo();
|
||||
static uint32_t wireAuthenPolicy();
|
||||
p3Wire(RsGeneralDataService* gds, RsNetworkExchangeService* nes, RsGixs *gixs);
|
||||
virtual RsServiceInfo getServiceInfo();
|
||||
static uint32_t wireAuthenPolicy();
|
||||
|
||||
protected:
|
||||
|
||||
virtual void notifyChanges(std::vector<RsGxsNotify*>& changes) ;
|
||||
virtual void notifyChanges(std::vector<RsGxsNotify*>& changes) ;
|
||||
|
||||
public:
|
||||
virtual void service_tick();
|
||||
|
||||
virtual void service_tick();
|
||||
virtual RsTokenService* getTokenService();
|
||||
|
||||
/* Specific Service Data */
|
||||
virtual bool getGroupData(const uint32_t &token, std::vector<RsWireGroup> &groups);
|
||||
virtual bool getPulseData(const uint32_t &token, std::vector<RsWirePulse> &pulses);
|
||||
/* Specific Service Data */
|
||||
virtual bool getGroupData(const uint32_t &token, std::vector<RsWireGroup> &groups);
|
||||
virtual bool getPulseData(const uint32_t &token, std::vector<RsWirePulse> &pulses);
|
||||
|
||||
virtual bool createGroup(uint32_t &token, RsWireGroup &group);
|
||||
virtual bool createPulse(uint32_t &token, RsWirePulse &pulse);
|
||||
virtual bool createGroup(uint32_t &token, RsWireGroup &group);
|
||||
virtual bool createPulse(uint32_t &token, RsWirePulse &pulse);
|
||||
|
||||
private:
|
||||
|
||||
virtual void generateDummyData();
|
||||
std::string genRandomId();
|
||||
private:
|
||||
virtual void generateDummyData();
|
||||
std::string genRandomId();
|
||||
|
||||
RsMutex mWireMtx;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue