2018-05-29 15:54:27 -04:00
|
|
|
/*******************************************************************************
|
|
|
|
* libretroshare/src/services: p3gxschannels.h *
|
|
|
|
* *
|
|
|
|
* libretroshare: retroshare core library *
|
|
|
|
* *
|
2018-10-10 00:40:56 -04:00
|
|
|
* Copyright (C) 2012 Robert Fernie <retroshare@lunamutt.com> *
|
|
|
|
* Copyright (C) 2018 Gioacchino Mazzurco <gio@eigenlab.org> *
|
2018-05-29 15:54:27 -04:00
|
|
|
* *
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU Lesser General Public License as *
|
|
|
|
* published by the Free Software Foundation, either version 3 of the *
|
|
|
|
* License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU Lesser General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License *
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
|
|
* *
|
|
|
|
*******************************************************************************/
|
2013-03-04 15:26:48 -05:00
|
|
|
#ifndef P3_GXSCHANNELS_SERVICE_HEADER
|
|
|
|
#define P3_GXSCHANNELS_SERVICE_HEADER
|
|
|
|
|
|
|
|
|
|
|
|
#include "retroshare/rsgxschannels.h"
|
|
|
|
#include "services/p3gxscommon.h"
|
|
|
|
#include "gxs/rsgenexchange.h"
|
2013-03-11 16:40:28 -04:00
|
|
|
#include "gxs/gxstokenqueue.h"
|
2013-03-04 15:26:48 -05:00
|
|
|
|
|
|
|
#include "util/rstickevent.h"
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
|
2013-03-11 16:40:28 -04:00
|
|
|
|
|
|
|
class SSGxsChannelGroup
|
|
|
|
{
|
|
|
|
public:
|
2016-02-17 13:27:28 -05:00
|
|
|
SSGxsChannelGroup(): mAutoDownload(false), mDownloadDirectory("") {}
|
2013-03-11 16:40:28 -04:00
|
|
|
bool load(const std::string &input);
|
|
|
|
std::string save() const;
|
|
|
|
|
|
|
|
bool mAutoDownload;
|
2016-02-17 13:27:28 -05:00
|
|
|
std::string mDownloadDirectory;
|
2013-03-11 16:40:28 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-03-04 15:26:48 -05:00
|
|
|
class p3GxsChannels: public RsGenExchange, public RsGxsChannels,
|
2018-02-16 17:51:43 -05:00
|
|
|
public GxsTokenQueue, public p3Config,
|
2013-03-04 15:26:48 -05:00
|
|
|
public RsTickEvent /* only needed for testing - remove after */
|
|
|
|
{
|
2018-08-16 17:34:29 -04:00
|
|
|
public:
|
|
|
|
p3GxsChannels( RsGeneralDataService* gds, RsNetworkExchangeService* nes,
|
|
|
|
RsGixs* gixs );
|
|
|
|
virtual RsServiceInfo getServiceInfo();
|
2013-03-04 15:26:48 -05:00
|
|
|
|
2018-08-16 17:34:29 -04:00
|
|
|
virtual void service_tick();
|
2013-03-04 15:26:48 -05:00
|
|
|
|
2018-08-16 17:34:29 -04:00
|
|
|
protected:
|
2013-03-04 15:26:48 -05:00
|
|
|
|
|
|
|
|
2018-02-16 17:51:43 -05:00
|
|
|
virtual RsSerialiser* setupSerialiser(); // @see p3Config::setupSerialiser()
|
|
|
|
virtual bool saveList(bool &cleanup, std::list<RsItem *>&saveList); // @see p3Config::saveList(bool &cleanup, std::list<RsItem *>&)
|
|
|
|
virtual bool loadList(std::list<RsItem *>& loadList); // @see p3Config::loadList(std::list<RsItem *>&)
|
|
|
|
|
2018-06-13 16:46:27 -04:00
|
|
|
virtual TurtleRequestId turtleGroupRequest(const RsGxsGroupId& group_id);
|
|
|
|
virtual TurtleRequestId turtleSearchRequest(const std::string& match_string);
|
2018-06-24 10:55:38 -04:00
|
|
|
virtual bool retrieveDistantSearchResults(TurtleRequestId req, std::map<RsGxsGroupId, RsGxsGroupSummary> &results) ;
|
|
|
|
virtual bool clearDistantSearchResults(TurtleRequestId req);
|
2018-06-26 16:20:02 -04:00
|
|
|
virtual bool retrieveDistantGroup(const RsGxsGroupId& group_id,RsGxsChannelGroup& distant_group);
|
2018-06-06 17:15:29 -04:00
|
|
|
|
2013-03-16 08:31:31 -04:00
|
|
|
// Overloaded to cache new groups.
|
|
|
|
virtual RsGenExchange::ServiceCreate_Return service_CreateGroup(RsGxsGrpItem* grpItem, RsTlvSecurityKeySet& keySet);
|
|
|
|
|
2013-03-04 15:26:48 -05:00
|
|
|
virtual void notifyChanges(std::vector<RsGxsNotify*>& changes);
|
|
|
|
|
|
|
|
// Overloaded from RsTickEvent.
|
|
|
|
virtual void handle_event(uint32_t event_type, const std::string &elabel);
|
|
|
|
|
2018-08-16 17:34:29 -04:00
|
|
|
public:
|
2013-03-04 15:26:48 -05:00
|
|
|
|
|
|
|
virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsChannelGroup> &groups);
|
2016-06-18 14:03:55 -04:00
|
|
|
virtual bool getPostData(const uint32_t &token, std::vector<RsGxsChannelPost> &posts, std::vector<RsGxsComment> &cmts);
|
2018-10-29 00:50:11 -04:00
|
|
|
virtual bool getPostData(const uint32_t &token, std::vector<RsGxsChannelPost> &posts);
|
2016-06-18 14:03:55 -04:00
|
|
|
//Not currently used
|
|
|
|
//virtual bool getRelatedPosts(const uint32_t &token, std::vector<RsGxsChannelPost> &posts);
|
2013-03-04 15:26:48 -05:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
//virtual bool setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask);
|
|
|
|
//virtual bool setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask);
|
|
|
|
|
|
|
|
//virtual bool groupRestoreKeys(const std::string &groupId);
|
2018-06-26 07:20:24 -04:00
|
|
|
virtual bool groupShareKeys(
|
|
|
|
const RsGxsGroupId &groupId, const std::set<RsPeerId>& peers);
|
2013-03-04 15:26:48 -05:00
|
|
|
|
|
|
|
virtual bool createGroup(uint32_t &token, RsGxsChannelGroup &group);
|
|
|
|
virtual bool createPost(uint32_t &token, RsGxsChannelPost &post);
|
|
|
|
|
2014-02-19 06:08:37 -05:00
|
|
|
virtual bool updateGroup(uint32_t &token, RsGxsChannelGroup &group);
|
2014-02-09 05:33:16 -05:00
|
|
|
|
2013-03-16 08:31:31 -04:00
|
|
|
// no tokens... should be cached.
|
|
|
|
virtual bool setChannelAutoDownload(const RsGxsGroupId &groupId, bool enabled);
|
2015-07-06 20:52:52 -04:00
|
|
|
virtual bool getChannelAutoDownload(const RsGxsGroupId &groupid, bool& enabled);
|
|
|
|
virtual bool setChannelDownloadDirectory(const RsGxsGroupId &groupId, const std::string& directory);
|
|
|
|
virtual bool getChannelDownloadDirectory(const RsGxsGroupId &groupId, std::string& directory);
|
2013-03-04 15:26:48 -05:00
|
|
|
|
2018-08-16 17:34:29 -04:00
|
|
|
/// @see RsGxsChannels::turtleSearchRequest
|
|
|
|
virtual bool turtleSearchRequest(const std::string& matchString,
|
|
|
|
const std::function<void (const RsGxsGroupSummary&)>& multiCallback,
|
2018-10-06 19:34:05 -04:00
|
|
|
rstime_t maxWait = 300 );
|
2018-08-16 17:34:29 -04:00
|
|
|
|
2018-11-01 02:04:01 -04:00
|
|
|
/// @see RsGxsChannels::turtleChannelRequest
|
|
|
|
virtual bool turtleChannelRequest(
|
|
|
|
const RsGxsGroupId& channelId,
|
|
|
|
const std::function<void (const RsGxsChannelGroup& result)>& multiCallback,
|
|
|
|
rstime_t maxWait = 300 );
|
|
|
|
|
2018-11-17 11:19:13 -05:00
|
|
|
/// @see RsGxsChannels::localSearchRequest
|
|
|
|
virtual bool localSearchRequest(const std::string& matchString,
|
|
|
|
const std::function<void (const RsGxsGroupSummary& result)>& multiCallback,
|
|
|
|
rstime_t maxWait = 30 ) override;
|
|
|
|
|
2018-08-16 17:34:29 -04:00
|
|
|
/**
|
|
|
|
* Receive results from turtle search @see RsGenExchange @see RsNxsObserver
|
2018-10-20 07:39:13 -04:00
|
|
|
* @see RsGxsNetService::receiveTurtleSearchResults
|
2018-08-16 17:34:29 -04:00
|
|
|
* @see p3turtle::handleSearchResult
|
|
|
|
*/
|
|
|
|
void receiveDistantSearchResults( TurtleRequestId id,
|
2018-10-20 07:39:13 -04:00
|
|
|
const RsGxsGroupId& grpId ) override;
|
2018-08-16 17:34:29 -04:00
|
|
|
|
2013-03-04 15:26:48 -05:00
|
|
|
/* Comment service - Provide RsGxsCommentService - redirect to p3GxsCommentService */
|
2019-02-14 15:58:33 -05:00
|
|
|
virtual bool getCommentData(uint32_t token, std::vector<RsGxsComment> &msgs) override
|
2018-03-28 10:30:35 -04:00
|
|
|
{ return mCommentService->getGxsCommentData(token, msgs); }
|
2013-03-04 15:26:48 -05:00
|
|
|
|
2018-03-28 10:30:35 -04:00
|
|
|
virtual bool getRelatedComments( uint32_t token,
|
2019-02-14 15:58:33 -05:00
|
|
|
std::vector<RsGxsComment> &msgs ) override
|
2018-03-28 10:30:35 -04:00
|
|
|
{ return mCommentService->getGxsRelatedComments(token, msgs); }
|
2013-03-04 15:26:48 -05:00
|
|
|
|
2019-02-14 15:58:33 -05:00
|
|
|
virtual bool createNewComment(uint32_t &token, RsGxsComment &msg) override
|
2013-03-04 15:26:48 -05:00
|
|
|
{
|
|
|
|
return mCommentService->createGxsComment(token, msg);
|
|
|
|
}
|
|
|
|
|
2019-02-14 15:58:33 -05:00
|
|
|
virtual bool createNewVote(uint32_t &token, RsGxsVote &msg) override
|
2013-03-04 15:26:48 -05:00
|
|
|
{
|
|
|
|
return mCommentService->createGxsVote(token, msg);
|
|
|
|
}
|
|
|
|
|
2019-02-14 15:58:33 -05:00
|
|
|
virtual bool acknowledgeComment(uint32_t token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId) override
|
2013-03-04 15:26:48 -05:00
|
|
|
{
|
|
|
|
return acknowledgeMsg(token, msgId);
|
|
|
|
}
|
|
|
|
|
2019-02-14 15:58:33 -05:00
|
|
|
virtual bool acknowledgeVote(uint32_t token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId) override
|
2013-03-15 16:46:49 -04:00
|
|
|
{
|
|
|
|
if (mCommentService->acknowledgeVote(token, msgId))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return acknowledgeMsg(token, msgId);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-11 16:40:28 -04:00
|
|
|
// Overloaded from RsGxsIface.
|
2013-03-24 12:32:20 -04:00
|
|
|
virtual bool subscribeToGroup(uint32_t &token, const RsGxsGroupId &groupId, bool subscribe);
|
2013-03-11 16:40:28 -04:00
|
|
|
|
|
|
|
// Set Statuses.
|
|
|
|
virtual void setMessageProcessedStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool processed);
|
|
|
|
virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read);
|
|
|
|
|
2013-03-12 20:24:57 -04:00
|
|
|
// File Interface
|
2018-06-26 07:20:24 -04:00
|
|
|
virtual bool ExtraFileHash(const std::string& path);
|
2014-03-17 16:56:06 -04:00
|
|
|
virtual bool ExtraFileRemove(const RsFileHash &hash);
|
2013-03-12 20:24:57 -04:00
|
|
|
|
2013-03-11 16:40:28 -04:00
|
|
|
|
2018-06-26 07:20:24 -04:00
|
|
|
/// Implementation of @see RsGxsChannels::getChannelsSummaries
|
|
|
|
virtual bool getChannelsSummaries(std::list<RsGroupMetaData>& channels);
|
|
|
|
|
|
|
|
/// Implementation of @see RsGxsChannels::getChannelsInfo
|
|
|
|
virtual bool getChannelsInfo(
|
|
|
|
const std::list<RsGxsGroupId>& chanIds,
|
|
|
|
std::vector<RsGxsChannelGroup>& channelsInfo );
|
|
|
|
|
|
|
|
/// Implementation of @see RsGxsChannels::getChannelContent
|
2018-12-12 15:35:31 -05:00
|
|
|
virtual bool getChannelContent( const RsGxsGroupId& channelId,
|
|
|
|
const std::set<RsGxsMessageId>& contentsIds,
|
|
|
|
std::vector<RsGxsChannelPost>& posts,
|
|
|
|
std::vector<RsGxsComment>& comments );
|
|
|
|
|
|
|
|
/// Implementation of @see RsGxsChannels::getContentSummaries
|
|
|
|
virtual bool getContentSummaries( const RsGxsGroupId& channelId,
|
|
|
|
std::vector<RsMsgMetaData>& summaries );
|
2018-06-26 07:20:24 -04:00
|
|
|
|
2018-10-04 17:36:01 -04:00
|
|
|
/// Implementation of @see RsGxsChannels::createChannel
|
|
|
|
virtual bool createChannel(RsGxsChannelGroup& channel);
|
|
|
|
|
2019-03-30 17:53:14 -04:00
|
|
|
/// Implementation of @see RsGxsChannels::createChannel
|
|
|
|
virtual bool createChannel(const std::string& name,
|
|
|
|
const std::string& description,
|
|
|
|
const RsGxsImage& image,
|
|
|
|
const RsGxsId& author_id,
|
|
|
|
uint32_t circle_type,
|
|
|
|
RsGxsCircleId& circle_id,
|
|
|
|
RsGxsGroupId& channel_group_id,
|
|
|
|
std::string& error_message);
|
|
|
|
|
2018-11-16 11:50:34 -05:00
|
|
|
/// Implementation of @see RsGxsChannels::createComment
|
|
|
|
virtual bool createComment(RsGxsComment& comment);
|
|
|
|
|
2018-11-01 02:04:01 -04:00
|
|
|
/// Implementation of @see RsGxsChannels::editChannel
|
|
|
|
virtual bool editChannel(RsGxsChannelGroup& channel);
|
|
|
|
|
2018-10-04 17:36:01 -04:00
|
|
|
/// Implementation of @see RsGxsChannels::createPost
|
|
|
|
virtual bool createPost(RsGxsChannelPost& post);
|
|
|
|
|
2018-11-16 11:50:34 -05:00
|
|
|
/// Implementation of @see RsGxsChannels::createVote
|
|
|
|
virtual bool createVote(RsGxsVote& vote);
|
|
|
|
|
2018-10-29 00:50:11 -04:00
|
|
|
/// Implementation of @see RsGxsChannels::subscribeToChannel
|
|
|
|
virtual bool subscribeToChannel( const RsGxsGroupId &groupId,
|
|
|
|
bool subscribe );
|
|
|
|
|
2018-11-01 02:04:01 -04:00
|
|
|
/// Implementation of @see RsGxsChannels::setPostRead
|
|
|
|
virtual bool markRead(const RsGxsGrpMsgIdPair& msgId, bool read);
|
|
|
|
|
|
|
|
virtual bool shareChannelKeys(
|
|
|
|
const RsGxsGroupId& channelId, const std::set<RsPeerId>& peers );
|
|
|
|
|
2018-06-26 07:20:24 -04:00
|
|
|
protected:
|
2013-03-11 16:40:28 -04:00
|
|
|
// Overloaded from GxsTokenQueue for Request callbacks.
|
2018-06-26 07:20:24 -04:00
|
|
|
virtual void handleResponse(uint32_t token, uint32_t req_type);
|
|
|
|
|
2013-03-11 16:40:28 -04:00
|
|
|
|
2018-06-26 07:20:24 -04:00
|
|
|
private:
|
2013-03-04 15:26:48 -05:00
|
|
|
|
|
|
|
static uint32_t channelsAuthenPolicy();
|
|
|
|
|
2013-03-11 16:40:28 -04:00
|
|
|
// Handle Processing.
|
|
|
|
void request_AllSubscribedGroups();
|
|
|
|
void request_SpecificSubscribedGroups(const std::list<RsGxsGroupId> &groups);
|
|
|
|
void load_SubscribedGroups(const uint32_t &token);
|
|
|
|
|
|
|
|
void request_SpecificUnprocessedPosts(std::list<std::pair<RsGxsGroupId, RsGxsMessageId> > &ids);
|
|
|
|
void request_GroupUnprocessedPosts(const std::list<RsGxsGroupId> &grouplist);
|
2018-11-09 15:24:31 -05:00
|
|
|
void load_unprocessedPosts(uint32_t token);
|
2013-03-11 16:40:28 -04:00
|
|
|
|
|
|
|
void handleUnprocessedPost(const RsGxsChannelPost &msg);
|
|
|
|
|
|
|
|
// Local Cache of Subscribed Groups. and AutoDownload Flag.
|
|
|
|
void updateSubscribedGroup(const RsGroupMetaData &group);
|
|
|
|
void clearUnsubscribedGroup(const RsGxsGroupId &id);
|
|
|
|
bool setAutoDownload(const RsGxsGroupId &groupId, bool enabled);
|
2016-02-17 13:27:28 -05:00
|
|
|
bool autoDownloadEnabled(const RsGxsGroupId &groupId, bool &enabled);
|
2013-03-11 16:40:28 -04:00
|
|
|
|
2013-03-04 15:26:48 -05:00
|
|
|
// DUMMY DATA,
|
|
|
|
virtual bool generateDummyData();
|
|
|
|
|
|
|
|
std::string genRandomId();
|
|
|
|
|
|
|
|
void dummy_tick();
|
|
|
|
|
|
|
|
bool generatePost(uint32_t &token, const RsGxsGroupId &grpId);
|
|
|
|
bool generateComment(uint32_t &token, const RsGxsGroupId &grpId,
|
|
|
|
const RsGxsMessageId &parentId, const RsGxsMessageId &threadId);
|
2013-03-12 20:24:57 -04:00
|
|
|
bool generateVote(uint32_t &token, const RsGxsGroupId &grpId,
|
|
|
|
const RsGxsMessageId &parentId, const RsGxsMessageId &threadId);
|
|
|
|
|
2013-03-04 15:26:48 -05:00
|
|
|
bool generateGroup(uint32_t &token, std::string groupName);
|
|
|
|
|
|
|
|
class ChannelDummyRef
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ChannelDummyRef() { return; }
|
|
|
|
ChannelDummyRef(const RsGxsGroupId &grpId, const RsGxsMessageId &threadId, const RsGxsMessageId &msgId)
|
|
|
|
:mGroupId(grpId), mThreadId(threadId), mMsgId(msgId) { return; }
|
|
|
|
|
|
|
|
RsGxsGroupId mGroupId;
|
|
|
|
RsGxsMessageId mThreadId;
|
|
|
|
RsGxsMessageId mMsgId;
|
|
|
|
};
|
|
|
|
|
2018-10-29 00:50:11 -04:00
|
|
|
std::map<RsGxsGroupId, RsGroupMetaData> mSubscribedGroups;
|
|
|
|
RsMutex mSubscribedGroupsMutex;
|
|
|
|
|
|
|
|
/** G10h4ck: Is this stuff really used? And for what? BEGIN */
|
2013-03-04 15:26:48 -05:00
|
|
|
uint32_t mGenToken;
|
|
|
|
bool mGenActive;
|
|
|
|
int mGenCount;
|
|
|
|
std::vector<ChannelDummyRef> mGenRefs;
|
|
|
|
RsGxsMessageId mGenThreadId;
|
2018-10-29 00:50:11 -04:00
|
|
|
/** G10h4ck: Is this stuff really used? And for what? END */
|
|
|
|
|
|
|
|
p3GxsCommentService* mCommentService;
|
2013-03-04 15:26:48 -05:00
|
|
|
|
2018-10-29 00:50:11 -04:00
|
|
|
std::map<RsGxsGroupId,rstime_t> mKnownChannels;
|
|
|
|
RsMutex mKnownChannelsMutex;
|
2018-08-16 17:34:29 -04:00
|
|
|
|
|
|
|
/** Store search callbacks with timeout*/
|
|
|
|
std::map<
|
|
|
|
TurtleRequestId,
|
|
|
|
std::pair<
|
|
|
|
std::function<void (const RsGxsGroupSummary&)>,
|
|
|
|
std::chrono::system_clock::time_point >
|
|
|
|
> mSearchCallbacksMap;
|
|
|
|
RsMutex mSearchCallbacksMapMutex;
|
|
|
|
|
2018-11-01 02:04:01 -04:00
|
|
|
/** Store distant channels requests callbacks with timeout*/
|
|
|
|
std::map<
|
|
|
|
TurtleRequestId,
|
|
|
|
std::pair<
|
|
|
|
std::function<void (const RsGxsChannelGroup&)>,
|
|
|
|
std::chrono::system_clock::time_point >
|
|
|
|
> mDistantChannelsCallbacksMap;
|
|
|
|
RsMutex mDistantChannelsCallbacksMapMutex;
|
|
|
|
|
|
|
|
/// Cleanup mSearchCallbacksMap and mDistantChannelsCallbacksMap
|
|
|
|
void cleanTimedOutCallbacks();
|
2013-03-04 15:26:48 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|