fixed merged with upstream/master

This commit is contained in:
csoler 2018-08-28 23:42:24 +02:00
commit c9b30f5a72
No known key found for this signature in database
GPG key ID: 7BCA522266C0804C
88 changed files with 3867 additions and 977 deletions

View file

@ -19,18 +19,25 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
* *
*******************************************************************************/
#ifndef RS_FILES_GUI_INTERFACE_H
#define RS_FILES_GUI_INTERFACE_H
#pragma once
#include <list>
#include <iostream>
#include <string>
#include <functional>
#include <chrono>
#include "rstypes.h"
#include "serialiser/rsserializable.h"
#include "rsturtle.h"
class RsFiles;
extern RsFiles *rsFiles;
/**
* Pointer to global instance of RsFiles service implementation
* @jsonapi{development}
*/
extern RsFiles* rsFiles;
namespace RsRegularExpression { class Expression; }
@ -104,7 +111,7 @@ const TransferRequestFlags RS_FILE_REQ_NO_SEARCH ( 0x02000000 ); // di
const uint32_t RS_FILE_EXTRA_DELETE = 0x0010;
struct SharedDirInfo
struct SharedDirInfo : RsSerializable
{
static bool sameLists(const std::list<RsNodeGroupId>& l1,const std::list<RsNodeGroupId>& l2)
{
@ -118,10 +125,22 @@ struct SharedDirInfo
return it1 == l1.end() && it2 == l2.end() ;
}
std::string filename ;
std::string virtualname ;
FileStorageFlags shareflags ; // combnation of DIR_FLAGS_ANONYMOUS_DOWNLOAD | DIR_FLAGS_BROWSABLE | ...
std::list<RsNodeGroupId> parent_groups ;
std::string filename;
std::string virtualname;
/// combnation of DIR_FLAGS_ANONYMOUS_DOWNLOAD | DIR_FLAGS_BROWSABLE | ...
FileStorageFlags shareflags;
std::list<RsNodeGroupId> parent_groups;
/// @see RsSerializable::serial_process
virtual void serial_process(RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx)
{
RS_SERIAL_PROCESS(filename);
RS_SERIAL_PROCESS(virtualname);
RS_SERIAL_PROCESS(shareflags);
RS_SERIAL_PROCESS(parent_groups);
}
};
struct SharedDirStats
@ -177,38 +196,128 @@ public:
RsFiles() {}
virtual ~RsFiles() {}
/**
* Provides file data for the gui: media streaming or rpc clients.
* It may return unverified chunks. This allows streaming without having to wait for hashes or completion of the file.
* This function returns an unspecified amount of bytes. Either as much data as available or a sensible maximum. Expect a block size of around 1MiB.
* To get more data, call this function repeatedly with different offsets.
* Returns false in case
* - the files is not available on the local node
* - not downloading
* - the requested data was not downloaded yet
* - end of file was reached
* @param hash hash of a file. The file has to be available on this node or it has to be in downloading state.
* @param offset where the desired block starts
* @param requested_size size of pre-allocated data. Will be updated by the function.
* @param data pre-allocated memory chunk of size 'requested_size' by the client
*/
virtual bool getFileData(const RsFileHash& hash, uint64_t offset, uint32_t& requested_size,uint8_t *data)=0;
/**
* Provides file data for the gui, media streaming or rpc clients.
* It may return unverified chunks. This allows streaming without having to
* wait for hashes or completion of the file.
* This function returns an unspecified amount of bytes. Either as much data
* as available or a sensible maximum. Expect a block size of around 1MiB.
* To get more data, call this function repeatedly with different offsets.
*
* jsonapi{development}
* note the missing @ the wrapper for this is written manually not
* autogenerated @see JsonApiServer.
*
* @param[in] hash hash of the file. The file has to be available on this node
* or it has to be in downloading state.
* @param[in] offset where the desired block starts
* @param[inout] requested_size size of pre-allocated data. Will be updated
* by the function.
* @param data pre-allocated memory chunk of size 'requested_size' by the
* client
* @return Returns false in case
* - the files is not available on the local node
* - not downloading
* - the requested data was not downloaded yet
* - end of file was reached
*/
virtual bool getFileData( const RsFileHash& hash, uint64_t offset,
uint32_t& requested_size, uint8_t* data ) = 0;
/***
* Control of Downloads.
***/
/**
* @brief Check if we already have a file
* @jsonapi{development}
* @param[in] hash file identifier
* @param[out] info storage for the possibly found file information
* @return true if the file is already present, false otherwise
*/
virtual bool alreadyHaveFile(const RsFileHash& hash, FileInfo &info) = 0;
/**
* @brief Initiate downloading of a file
* @jsonapi{development}
* @param[in] fileName
* @param[in] hash
* @param[in] size
* @param[in] destPath in not empty specify a destination path
* @param[in] flags you usually want RS_FILE_REQ_ANONYMOUS_ROUTING
* @param[in] srcIds eventually specify known sources
* @return false if we already have the file, true otherwhise
*/
virtual bool FileRequest(
const std::string& fileName, const RsFileHash& hash, uint64_t size,
const std::string& destPath, TransferRequestFlags flags,
const std::list<RsPeerId>& srcIds ) = 0;
/**
* @brief Cancel file downloading
* @jsonapi{development}
* @param[in] hash
* @return false if the file is not in the download queue, true otherwhise
*/
virtual bool FileCancel(const RsFileHash& hash) = 0;
/**
* @brief Set destination directory for given file
* @jsonapi{development}
* @param[in] hash file identifier
* @param[in] newPath
* @return false if some error occurred, true otherwise
*/
virtual bool setDestinationDirectory(
const RsFileHash& hash, const std::string& newPath ) = 0;
/**
* @brief Set name for dowloaded file
* @jsonapi{development}
* @param[in] hash file identifier
* @param[in] newName
* @return false if some error occurred, true otherwise
*/
virtual bool setDestinationName(
const RsFileHash& hash, const std::string& newName ) = 0;
/**
* @brief Set chunk strategy for file, useful to set streaming mode to be
* able of see video or other media preview while it is still downloading
* @jsonapi{development}
* @param[in] hash file identifier
* @param[in] newStrategy
* @return false if some error occurred, true otherwise
*/
virtual bool setChunkStrategy(
const RsFileHash& hash,
FileChunksInfo::ChunkStrategy newStrategy ) = 0;
/**
* @brief Set default chunk strategy
* @jsonapi{development}
* @param[in] strategy
*/
virtual void setDefaultChunkStrategy(
FileChunksInfo::ChunkStrategy strategy ) = 0;
/**
* @brief Get default chunk strategy
* @jsonapi{development}
* @return current default chunck strategy
*/
virtual FileChunksInfo::ChunkStrategy defaultChunkStrategy() = 0;
/**
* @brief Get free disk space limit
* @jsonapi{development}
* @return current current minimum free space on disk in MB
*/
virtual uint32_t freeDiskSpaceLimit() const = 0;
/**
* @brief Set minimum free disk space limit
* @jsonapi{development}
* @param[in] minimumFreeMB minimum free space in MB
*/
virtual void setFreeDiskSpaceLimit(uint32_t minimumFreeMB) = 0;
virtual bool alreadyHaveFile(const RsFileHash& hash, FileInfo &info) = 0;
/// Returns false is we already have the file. Otherwise, initiates the dl and returns true.
virtual bool FileRequest(const std::string& fname, const RsFileHash& hash, uint64_t size, const std::string& dest, TransferRequestFlags flags, const std::list<RsPeerId>& srcIds) = 0;
virtual bool FileCancel(const RsFileHash& hash) = 0;
virtual bool setDestinationDirectory(const RsFileHash& hash,const std::string& new_path) = 0;
virtual bool setDestinationName(const RsFileHash& hash,const std::string& new_name) = 0;
virtual bool setChunkStrategy(const RsFileHash& hash,FileChunksInfo::ChunkStrategy) = 0;
virtual void setDefaultChunkStrategy(FileChunksInfo::ChunkStrategy) = 0;
virtual FileChunksInfo::ChunkStrategy defaultChunkStrategy() = 0;
virtual uint32_t freeDiskSpaceLimit() const =0;
virtual void setFreeDiskSpaceLimit(uint32_t size_in_mb) =0;
virtual bool FileControl(const RsFileHash& hash, uint32_t flags) = 0;
virtual bool FileClearCompleted() = 0;
virtual void setDefaultEncryptionPolicy(uint32_t policy)=0; // RS_FILE_CTRL_ENCRYPTION_POLICY_STRICT/PERMISSIVE
@ -217,8 +326,24 @@ public:
virtual uint32_t getMaxUploadSlotsPerFriend()=0;
virtual void setFilePermDirectDL(uint32_t perm)=0;
virtual uint32_t filePermDirectDL()=0;
virtual TurtleRequestId turtleSearch(const std::string& string_to_match) =0;
virtual TurtleRequestId turtleSearch(const RsRegularExpression::LinearizedExpression& expr) =0;
/**
* @brief Request remote files search
* @jsonapi{development}
* @param[in] matchString string to look for in the search
* @param multiCallback function that will be called each time a search
* result is received
* @param[in] maxWait maximum wait time in seconds for search results
* @return false on error, true otherwise
*/
virtual bool turtleSearchRequest(
const std::string& matchString,
const std::function<void (const std::list<TurtleFileInfo>& results)>& multiCallback,
std::time_t maxWait = 300 ) = 0;
virtual TurtleRequestId turtleSearch(const std::string& string_to_match) = 0;
virtual TurtleRequestId turtleSearch(
const RsRegularExpression::LinearizedExpression& expr) = 0;
/***
* Control of Downloads Priority.
@ -229,21 +354,56 @@ public:
virtual bool changeDownloadSpeed(const RsFileHash& hash, int speed) = 0;
virtual bool getDownloadSpeed(const RsFileHash& hash, int & speed) = 0;
virtual bool clearDownload(const RsFileHash& hash) = 0;
// virtual void getDwlDetails(std::list<DwlDetails> & details) = 0;
/***
* Download / Upload Details.
***/
virtual void FileDownloads(std::list<RsFileHash> &hashs) = 0;
virtual bool FileUploads(std::list<RsFileHash> &hashs) = 0;
virtual bool FileDetails(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info) = 0;
/**
* @brief Get incoming files list
* @jsonapi{development}
* @param[out] hashs storage for files identifiers list
*/
virtual void FileDownloads(std::list<RsFileHash>& hashs) = 0;
/**
* @brief Get outgoing files list
* @jsonapi{development}
* @param[out] hashs storage for files identifiers list
* @return false if some error occurred, true otherwise
*/
virtual bool FileUploads(std::list<RsFileHash>& hashs) = 0;
/**
* @brief Get file details
* @jsonapi{development}
* @param[in] hash file identifier
* @param[in] hintflags filtering hint (RS_FILE_HINTS_EXTRA|...|RS_FILE_HINTS_LOCAL)
* @param[out] info storage for file information
* @return true if file found, false otherwise
*/
virtual bool FileDetails(
const RsFileHash &hash, FileSearchFlags hintflags, FileInfo& info ) = 0;
virtual bool isEncryptedSource(const RsPeerId& virtual_peer_id) =0;
/// Gives chunk details about the downloaded file with given hash.
virtual bool FileDownloadChunksDetails(const RsFileHash& hash,FileChunksInfo& info) = 0 ;
/**
* @brief Get chunk details about the downloaded file with given hash.
* @jsonapi{development}
* @param[in] hash file identifier
* @param[out] info storage for file information
* @return true if file found, false otherwise
*/
virtual bool FileDownloadChunksDetails(
const RsFileHash& hash, FileChunksInfo& info) = 0;
/// details about the upload with given hash
virtual bool FileUploadChunksDetails(const RsFileHash& hash,const RsPeerId& peer_id,CompressedChunkMap& map) = 0 ;
/**
* @brief Get details about the upload with given hash
* @jsonapi{development}
* @param[in] hash file identifier
* @param[in] peer_id peer identifier
* @param[out] map storage for chunk info
* @return true if file found, false otherwise
*/
virtual bool FileUploadChunksDetails(
const RsFileHash& hash, const RsPeerId& peer_id,
CompressedChunkMap& map ) = 0;
/***
* Extra List Access
@ -289,16 +449,76 @@ public:
***/
virtual void requestDirUpdate(void *ref) =0 ; // triggers the update of the given reference. Used when browsing.
virtual bool setDownloadDirectory(std::string path) = 0;
virtual bool setPartialsDirectory(std::string path) = 0;
virtual std::string getDownloadDirectory() = 0;
virtual std::string getPartialsDirectory() = 0;
/**
* @brief Set default complete downloads directory
* @jsonapi{development}
* @param[in] path directory path
* @return false if something failed, true otherwhise
*/
virtual bool setDownloadDirectory(const std::string& path) = 0;
virtual bool getSharedDirectories(std::list<SharedDirInfo>& dirs) = 0;
virtual bool setSharedDirectories(const std::list<SharedDirInfo>& dirs) = 0;
virtual bool addSharedDirectory(const SharedDirInfo& dir) = 0;
virtual bool updateShareFlags(const SharedDirInfo& dir) = 0; // updates the flags. The directory should already exist !
virtual bool removeSharedDirectory(std::string dir) = 0;
/**
* @brief Set partial downloads directory
* @jsonapi{development}
* @param[in] path directory path
* @return false if something failed, true otherwhise
*/
virtual bool setPartialsDirectory(const std::string& path) = 0;
/**
* @brief Get default complete downloads directory
* @jsonapi{development}
* @return default completed downloads directory path
*/
virtual std::string getDownloadDirectory() = 0;
/**
* @brief Get partial downloads directory
* @jsonapi{development}
* @return partials downloads directory path
*/
virtual std::string getPartialsDirectory() = 0;
/**
* @brief Get list of current shared directories
* @jsonapi{development}
* @param[out] dirs storage for the list of share directories
* @return false if something failed, true otherwhise
*/
virtual bool getSharedDirectories(std::list<SharedDirInfo>& dirs) = 0;
/**
* @brief Set shared directories
* @jsonapi{development}
* @param[in] dirs list of shared directories with share options
* @return false if something failed, true otherwhise
*/
virtual bool setSharedDirectories(const std::list<SharedDirInfo>& dirs) = 0;
/**
* @brief Add shared directory
* @jsonapi{development}
* @param[in] dir directory to share with sharing options
* @return false if something failed, true otherwhise
*/
virtual bool addSharedDirectory(const SharedDirInfo& dir) = 0;
/**
* @brief Updates shared directory sharing flags.
* The directory should be already shared!
* @jsonapi{development}
* @param[in] dir Shared directory with updated sharing options
* @return false if something failed, true otherwhise
*/
virtual bool updateShareFlags(const SharedDirInfo& dir) = 0;
/**
* @brief Remove directory from shared list
* @jsonapi{development}
* @param[in] dir Path of the directory to remove from shared list
* @return false if something failed, true otherwhise
*/
virtual bool removeSharedDirectory(std::string dir) = 0;
virtual bool getIgnoreLists(std::list<std::string>& ignored_prefixes, std::list<std::string>& ignored_suffixes,uint32_t& flags) =0;
virtual void setIgnoreLists(const std::list<std::string>& ignored_prefixes, const std::list<std::string>& ignored_suffixes,uint32_t flags) =0;
@ -320,8 +540,4 @@ public:
virtual bool ignoreDuplicates() = 0;
virtual void setIgnoreDuplicates(bool ignore) = 0;
};
#endif

View file

@ -1,9 +1,11 @@
#pragma once
/*******************************************************************************
* libretroshare/src/retroshare: rsgxschannels.h *
* *
* libretroshare: retroshare core library *
* *
* Copyright 2012-2012 by Robert Fernie <retroshare@lunamutt.com> *
* Copyright (C) 2018 Gioacchino Mazzurco <gio@eigenlab.org> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
@ -19,44 +21,56 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
* *
*******************************************************************************/
#ifndef RETROSHARE_GXS_CHANNEL_GUI_INTERFACE_H
#define RETROSHARE_GXS_CHANNEL_GUI_INTERFACE_H
#include <inttypes.h>
#include <string>
#include <list>
#include <functional>
#include "retroshare/rstokenservice.h"
#include "retroshare/rsgxsifacehelper.h"
#include "retroshare/rsgxscommon.h"
#include "serialiser/rsserializable.h"
#include "retroshare/rsturtle.h"
/* The Main Interface Class - for information about your Peers */
class RsGxsChannels;
extern RsGxsChannels *rsGxsChannels;
/**
* Pointer to global instance of RsGxsChannels service implementation
* @jsonapi{development}
*/
extern RsGxsChannels* rsGxsChannels;
// These should be in rsgxscommon.h
class RsGxsChannelGroup
struct RsGxsChannelGroup : RsSerializable
{
public:
RsGroupMetaData mMeta;
std::string mDescription;
RsGxsImage mImage;
bool mAutoDownload;
/// @see RsSerializable
virtual void serial_process( RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx )
{
RS_SERIAL_PROCESS(mMeta);
RS_SERIAL_PROCESS(mDescription);
RS_SERIAL_PROCESS(mImage);
RS_SERIAL_PROCESS(mAutoDownload);
}
};
class RsGxsChannelPost
std::ostream &operator<<(std::ostream& out, const RsGxsChannelGroup& group);
struct RsGxsChannelPost : RsSerializable
{
public:
RsGxsChannelPost() : mCount(0), mSize(0) {}
public:
RsMsgMetaData mMeta;
std::set<RsGxsMessageId> mOlderVersions ;
std::set<RsGxsMessageId> mOlderVersions;
std::string mMsg; // UTF8 encoded.
std::list<RsGxsFile> mFiles;
@ -64,26 +78,217 @@ public:
uint64_t mSize; // auto calced.
RsGxsImage mThumbnail;
/// @see RsSerializable
virtual void serial_process( RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx )
{
RS_SERIAL_PROCESS(mMeta);
RS_SERIAL_PROCESS(mOlderVersions);
RS_SERIAL_PROCESS(mMsg);
RS_SERIAL_PROCESS(mFiles);
RS_SERIAL_PROCESS(mCount);
RS_SERIAL_PROCESS(mSize);
RS_SERIAL_PROCESS(mThumbnail);
}
};
std::ostream &operator<<(std::ostream& out, const RsGxsChannelPost& post);
std::ostream &operator<<(std::ostream &out, const RsGxsChannelGroup &group);
std::ostream &operator<<(std::ostream &out, const RsGxsChannelPost &post);
class RsGxsChannels: public RsGxsIfaceHelper, public RsGxsCommentService
{
public:
explicit RsGxsChannels(RsGxsIface *gxs)
:RsGxsIfaceHelper(gxs) {}
explicit RsGxsChannels(RsGxsIface& gxs) : RsGxsIfaceHelper(gxs) {}
virtual ~RsGxsChannels() {}
/* Specific Service Data */
/**
* @brief Get channels summaries list. Blocking API.
* @jsonapi{development}
* @param[out] channels list where to store the channels
* @return false if something failed, true otherwhise
*/
virtual bool getChannelsSummaries(std::list<RsGroupMetaData>& channels) = 0;
/**
* @brief Get channels information (description, thumbnail...).
* Blocking API.
* @jsonapi{development}
* @param[in] chanIds ids of the channels of which to get the informations
* @param[out] channelsInfo storage for the channels informations
* @return false if something failed, true otherwhise
*/
virtual bool getChannelsInfo(
const std::list<RsGxsGroupId>& chanIds,
std::vector<RsGxsChannelGroup>& channelsInfo ) = 0;
/**
* @brief Get content of specified channels. Blocking API
* @jsonapi{development}
* @param[in] chanIds id of the channels of which the content is requested
* @param[out] posts storage for the posts
* @param[out] comments storage for the comments
* @return false if something failed, true otherwhise
*/
virtual bool getChannelsContent(
const std::list<RsGxsGroupId>& chanIds,
std::vector<RsGxsChannelPost>& posts,
std::vector<RsGxsComment>& comments ) = 0;
/* Specific Service Data
* TODO: change the orrible const uint32_t &token to uint32_t token
* TODO: create a new typedef for token so code is easier to read
*/
virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsChannelGroup> &groups) = 0;
virtual bool getPostData(const uint32_t &token, std::vector<RsGxsChannelPost> &posts, std::vector<RsGxsComment> &cmts) = 0;
virtual bool getPostData(const uint32_t &token, std::vector<RsGxsChannelPost> &posts) = 0;
//////////////////////////////////////////////////////////////////////////////
/**
* @brief toggle message read status
* @jsonapi{development}
* @param[out] token GXS token queue token
* @param[in] msgId
* @param[in] read
*/
virtual void setMessageReadStatus(
uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read) = 0;
/**
* @brief Enable or disable auto-download for given channel
* @jsonapi{development}
* @param[in] groupId channel id
* @param[in] enable true to enable, false to disable
* @return false if something failed, true otherwhise
*/
virtual bool setChannelAutoDownload(
const RsGxsGroupId &groupId, bool enable) = 0;
/**
* @brief Get auto-download option value for given channel
* @jsonapi{development}
* @param[in] groupId channel id
* @param[in] enabled storage for the auto-download option value
* @return false if something failed, true otherwhise
*/
virtual bool getChannelAutoDownload(
const RsGxsGroupId &groupId, bool& enabled) = 0;
/**
* @brief Set download directory for the given channel
* @jsonapi{development}
* @param[in] channelId id of the channel
* @param[in] directory path
* @return false on error, true otherwise
*/
virtual bool setChannelDownloadDirectory(
const RsGxsGroupId& channelId, const std::string& directory) = 0;
/**
* @brief Get download directory for the given channel
* @jsonapi{development}
* @param[in] channelId id of the channel
* @param[out] directory reference to string where to store the path
* @return false on error, true otherwise
*/
virtual bool getChannelDownloadDirectory( const RsGxsGroupId& channelId,
std::string& directory ) = 0;
/**
* @brief Share channel publishing key
* This can be used to authorize other peers to post on the channel
* @jsonapi{development}
* param[in] groupId Channel id
* param[in] peers peers to which share the key
* @return false on error, true otherwise
*/
virtual bool groupShareKeys(
const RsGxsGroupId& groupId, const std::set<RsPeerId>& peers ) = 0;
/**
* @brief Request subscription to a group.
* The action is performed asyncronously, so it could fail in a subsequent
* phase even after returning true.
* @jsonapi{development}
* @param[out] token Storage for RsTokenService token to track request
* status.
* @param[in] groupId Channel id
* @param[in] subscribe
* @return false on error, true otherwise
*/
virtual bool subscribeToGroup( uint32_t& token, const RsGxsGroupId &groupId,
bool subscribe ) = 0;
/**
* @brief Request channel creation.
* The action is performed asyncronously, so it could fail in a subsequent
* phase even after returning true.
* @jsonapi{development}
* @param[out] token Storage for RsTokenService token to track request
* status.
* @param[in] group Channel data (name, description...)
* @return false on error, true otherwise
*/
virtual bool createGroup(uint32_t& token, RsGxsChannelGroup& group) = 0;
/**
* @brief Request post creation.
* The action is performed asyncronously, so it could fail in a subsequent
* phase even after returning true.
* @jsonapi{development}
* @param[out] token Storage for RsTokenService token to track request
* status.
* @param[in] post
* @return false on error, true otherwise
*/
virtual bool createPost(uint32_t& token, RsGxsChannelPost& post) = 0;
/**
* @brief Request channel change.
* The action is performed asyncronously, so it could fail in a subsequent
* phase even after returning true.
* @jsonapi{development}
* @param[out] token Storage for RsTokenService token to track request
* status.
* @param[in] group Channel data (name, description...) with modifications
* @return false on error, true otherwise
*/
virtual bool updateGroup(uint32_t& token, RsGxsChannelGroup& group) = 0;
/**
* @brief Share extra file
* Can be used to share extra file attached to a channel post
* @jsonapi{development}
* @param[in] path file path
* @return false on error, true otherwise
*/
virtual bool ExtraFileHash(const std::string& path) = 0;
/**
* @brief Remove extra file from shared files
* @jsonapi{development}
* @param[in] hash hash of the file to remove
* @return false on error, true otherwise
*/
virtual bool ExtraFileRemove(const RsFileHash& hash) = 0;
/**
* @brief Request remote channels search
* @jsonapi{development}
* @param[in] matchString string to look for in the search
* @param multiCallback function that will be called each time a search
* result is received
* @param[in] maxWait maximum wait time in seconds for search results
* @return false on error, true otherwise
*/
virtual bool turtleSearchRequest(
const std::string& matchString,
const std::function<void (const RsGxsGroupSummary& result)>& multiCallback,
std::time_t maxWait = 300 ) = 0;
//////////////////////////////////////////////////////////////////////////////
/// Distant synchronisation methods ///
//////////////////////////////////////////////////////////////////////////////
///
@ -94,29 +299,4 @@ public:
virtual bool retrieveDistantGroup(const RsGxsGroupId& group_id,RsGxsChannelGroup& distant_group)=0;
//////////////////////////////////////////////////////////////////////////////
virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read) = 0;
virtual bool setChannelAutoDownload(const RsGxsGroupId &groupId, bool enabled) = 0;
virtual bool getChannelAutoDownload(const RsGxsGroupId &groupid, bool& enabled) = 0;
virtual bool setChannelDownloadDirectory(const RsGxsGroupId &groupId, const std::string& directory)=0;
virtual bool getChannelDownloadDirectory(const RsGxsGroupId &groupId, std::string& directory)=0;
virtual bool groupShareKeys(const RsGxsGroupId &groupId, std::set<RsPeerId>& peers)=0;
// Overloaded subscribe fn.
virtual bool subscribeToGroup(uint32_t &token, const RsGxsGroupId &groupId, bool subscribe) = 0;
virtual bool createGroup(uint32_t &token, RsGxsChannelGroup &group) = 0;
virtual bool createPost(uint32_t &token, RsGxsChannelPost &post) = 0;
virtual bool updateGroup(uint32_t &token, RsGxsChannelGroup &group) = 0;
// File Interface
virtual bool ExtraFileHash(const std::string &path, std::string filename) = 0;
virtual bool ExtraFileRemove(const RsFileHash &hash) = 0;
};
#endif

View file

@ -122,8 +122,8 @@ class RsGxsCircles: public RsGxsIfaceHelper
{
public:
RsGxsCircles(RsGxsIface *gxs) :RsGxsIfaceHelper(gxs) { return; }
virtual ~RsGxsCircles() { return; }
RsGxsCircles(RsGxsIface& gxs) :RsGxsIfaceHelper(gxs) {}
virtual ~RsGxsCircles() {}
/* External Interface (Cached stuff) */
virtual bool getCircleDetails(const RsGxsCircleId &id, RsGxsCircleDetails &details) = 0;

View file

@ -31,37 +31,55 @@
#include <list>
#include "rsgxsifacetypes.h"
#include "serialiser/rsserializable.h"
class RsGxsFile
struct RsGxsFile : RsSerializable
{
public:
RsGxsFile();
std::string mName;
RsFileHash mHash;
uint64_t mSize;
//std::string mPath;
/// @see RsSerializable
virtual void serial_process( RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx )
{
RS_SERIAL_PROCESS(mName);
RS_SERIAL_PROCESS(mHash);
RS_SERIAL_PROCESS(mSize);
}
};
class RsGxsImage
struct RsGxsImage : RsSerializable
{
public:
RsGxsImage();
RsGxsImage();
~RsGxsImage();
RsGxsImage(const RsGxsImage& a); // TEMP use copy constructor and duplicate memory.
RsGxsImage &operator=(const RsGxsImage &a); // Need this as well?
//NB: Must make sure that we always use methods - to be consistent about malloc/free for this data.
static uint8_t *allocate(uint32_t size);
static void release(void *data);
/// Use copy constructor and duplicate memory.
RsGxsImage(const RsGxsImage& a);
RsGxsImage &operator=(const RsGxsImage &a); // Need this as well?
/** NB: Must make sure that we always use methods - to be consistent about
* malloc/free for this data. */
static uint8_t *allocate(uint32_t size);
static void release(void *data);
void take(uint8_t *data, uint32_t size); // Copies Pointer.
void copy(uint8_t *data, uint32_t size); // Allocates and Copies.
void clear(); // Frees.
void shallowClear(); // Clears Pointer.
uint8_t *mData;
uint32_t mSize;
uint8_t* mData;
/// @see RsSerializable
virtual void serial_process( RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx )
{
RsTypeSerializer::TlvMemBlock_proxy b(mData, mSize);
RsTypeSerializer::serial_process(j, ctx, b, "mData");
}
};
@ -84,17 +102,23 @@ namespace GXS_SERV {
class RsGxsVote
struct RsGxsVote : RsSerializable
{
public:
RsGxsVote();
RsMsgMetaData mMeta;
uint32_t mVoteType;
/// @see RsSerializable
virtual void serial_process( RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx )
{
RS_SERIAL_PROCESS(mMeta);
RS_SERIAL_PROCESS(mVoteType);
}
};
class RsGxsComment
struct RsGxsComment : RsSerializable
{
public:
RsGxsComment();
RsMsgMetaData mMeta;
std::string mComment;
@ -109,6 +133,19 @@ class RsGxsComment
// This is filled in if detailed Comment Data is called.
std::list<RsGxsVote> mVotes;
/// @see RsSerializable
virtual void serial_process( RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx )
{
RS_SERIAL_PROCESS(mMeta);
RS_SERIAL_PROCESS(mComment);
RS_SERIAL_PROCESS(mUpVotes);
RS_SERIAL_PROCESS(mDownVotes);
RS_SERIAL_PROCESS(mScore);
RS_SERIAL_PROCESS(mOwnVote);
RS_SERIAL_PROCESS(mVotes);
}
const std::ostream &print(std::ostream &out, std::string indent = "", std::string varName = "") const {
out << indent << varName << " of RsGxsComment Values ###################" << std::endl;
mMeta.print(out, indent + " ", "mMeta");

View file

@ -59,8 +59,7 @@ class RsGxsForums: public RsGxsIfaceHelper
{
public:
explicit RsGxsForums(RsGxsIface *gxs)
:RsGxsIfaceHelper(gxs) {}
explicit RsGxsForums(RsGxsIface& gxs) : RsGxsIfaceHelper(gxs) {}
virtual ~RsGxsForums() {}
/* Specific Service Data */

View file

@ -32,6 +32,7 @@
#include "gxs/rsgxsdata.h"
#include "retroshare/rsgxsifacetypes.h"
#include "util/rsdeprecate.h"
#include "serialiser/rsserializable.h"
/*!
* This structure is used to transport group summary information when a GXS
@ -76,9 +77,8 @@ struct RsGxsGroupSummary : RsSerializable
/*!
* Stores ids of changed gxs groups and messages. It is used to notify the GUI about changes.
*/
class RsGxsChanges
struct RsGxsChanges
{
public:
RsGxsChanges(): mService(0){}
RsTokenService *mService;
std::map<RsGxsGroupId, std::set<RsGxsMessageId> > mMsgs;
@ -91,13 +91,9 @@ public:
/*!
* All implementations must offer thread safety
*/
class RsGxsIface
struct RsGxsIface
{
public:
virtual ~RsGxsIface(){};
public:
virtual ~RsGxsIface() {}
/*!
* Gxs services should call this for automatic handling of

View file

@ -7,6 +7,7 @@
* RetroShare GXS. Convenience interface implementation
*
* Copyright 2012 by Christopher Evi-Parker
* Copyright (C) 2018 Gioacchino Mazzurco <gio@eigenlab.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@ -26,29 +27,30 @@
*
*/
#include <chrono>
#include <thread>
#include "retroshare/rsgxsiface.h"
#include "retroshare/rsreputations.h"
#include "rsgxsflags.h"
#include "util/rsdeprecate.h"
/*!
* The simple idea of this class is to implement the simple interface functions
* of gen exchange.
* This class provides convenience implementations of:
* - Handle msg and group changes (client class must pass changes sent by RsGenExchange to it)
* - subscription to groups
* - retrieval of msgs and group ids and meta info
* This class only make method of internal members visible tu upper level to
* offer a more friendly API.
* This is just a workaround to awkward GXS API design, do not take it as an
* example for your coding.
* To properly fix the API design many changes with the implied chain reactions
* are necessary, so at this point this workaround seems acceptable.
*/
class RsGxsIfaceHelper
struct RsGxsIfaceHelper
{
public:
/*!
*
* @param gxs handle to RsGenExchange instance of service (Usually the service class itself)
*/
RsGxsIfaceHelper(RsGxsIface* gxs)
: mGxs(gxs)
{}
/*!
* @param gxs handle to RsGenExchange instance of service (Usually the
* service class itself)
*/
RsGxsIfaceHelper(RsGxsIface& gxs) :
mGxs(gxs), mTokenService(*gxs.getTokenService()) {}
~RsGxsIfaceHelper(){}
@ -59,15 +61,7 @@ public:
*/
void receiveChanges(std::vector<RsGxsNotify *> &changes)
{
mGxs->receiveChanges(changes);
}
/*!
* @return handle to token service for this GXS service
*/
RsTokenService* getTokenService()
{
return mGxs->getTokenService();
mGxs.receiveChanges(changes);
}
/* Generic Lists */
@ -81,7 +75,7 @@ public:
bool getGroupList(const uint32_t &token,
std::list<RsGxsGroupId> &groupIds)
{
return mGxs->getGroupList(token, groupIds);
return mGxs.getGroupList(token, groupIds);
}
/*!
@ -93,7 +87,7 @@ public:
bool getMsgList(const uint32_t &token,
GxsMsgIdResult& msgIds)
{
return mGxs->getMsgList(token, msgIds);
return mGxs.getMsgList(token, msgIds);
}
/*!
@ -104,7 +98,7 @@ public:
*/
bool getMsgRelatedList(const uint32_t &token, MsgRelatedIdResult &msgIds)
{
return mGxs->getMsgRelatedList(token, msgIds);
return mGxs.getMsgRelatedList(token, msgIds);
}
/*!
@ -115,7 +109,7 @@ public:
bool getGroupSummary(const uint32_t &token,
std::list<RsGroupMetaData> &groupInfo)
{
return mGxs->getGroupMeta(token, groupInfo);
return mGxs.getGroupMeta(token, groupInfo);
}
/*!
@ -126,7 +120,7 @@ public:
bool getMsgSummary(const uint32_t &token,
GxsMsgMetaMap &msgInfo)
{
return mGxs->getMsgMeta(token, msgInfo);
return mGxs.getMsgMeta(token, msgInfo);
}
/*!
@ -136,7 +130,7 @@ public:
*/
bool getMsgRelatedSummary(const uint32_t &token, GxsMsgRelatedMetaMap &msgInfo)
{
return mGxs->getMsgRelatedMeta(token, msgInfo);
return mGxs.getMsgRelatedMeta(token, msgInfo);
}
/*!
@ -147,7 +141,7 @@ public:
*/
bool subscribeToGroup(uint32_t& token, const RsGxsGroupId& grpId, bool subscribe)
{
return mGxs->subscribeToGroup(token, grpId, subscribe);
return mGxs.subscribeToGroup(token, grpId, subscribe);
}
/*!
@ -159,7 +153,7 @@ public:
*/
bool acknowledgeMsg(const uint32_t& token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId)
{
return mGxs->acknowledgeTokenMsg(token, msgId);
return mGxs.acknowledgeTokenMsg(token, msgId);
}
/*!
@ -171,7 +165,7 @@ public:
*/
bool acknowledgeGrp(const uint32_t& token, RsGxsGroupId& grpId)
{
return mGxs->acknowledgeTokenGrp(token, grpId);
return mGxs.acknowledgeTokenGrp(token, grpId);
}
/*!
@ -182,7 +176,7 @@ public:
*/
bool getServiceStatistic(const uint32_t& token, GxsServiceStatistic& stats)
{
return mGxs->getServiceStatistic(token, stats);
return mGxs.getServiceStatistic(token, stats);
}
/*!
@ -193,7 +187,7 @@ public:
*/
bool getGroupStatistic(const uint32_t& token, GxsGroupStatistic& stats)
{
return mGxs->getGroupStatistic(token, stats);
return mGxs.getGroupStatistic(token, stats);
}
/*!
@ -206,7 +200,7 @@ public:
*/
void setGroupReputationCutOff(uint32_t& token, const RsGxsGroupId& grpId, int CutOff)
{
return mGxs->setGroupReputationCutOff(token, grpId, CutOff);
return mGxs.setGroupReputationCutOff(token, grpId, CutOff);
}
/*!
@ -214,36 +208,111 @@ public:
*/
uint32_t getDefaultStoragePeriod()
{
return mGxs->getDefaultStoragePeriod();
return mGxs.getDefaultStoragePeriod();
}
uint32_t getStoragePeriod(const RsGxsGroupId& grpId)
{
return mGxs->getStoragePeriod(grpId);
return mGxs.getStoragePeriod(grpId);
}
void setStoragePeriod(const RsGxsGroupId& grpId,uint32_t age_in_secs)
{
mGxs->setStoragePeriod(grpId,age_in_secs);
mGxs.setStoragePeriod(grpId,age_in_secs);
}
uint32_t getDefaultSyncPeriod()
{
return mGxs->getDefaultSyncPeriod();
return mGxs.getDefaultSyncPeriod();
}
uint32_t getSyncPeriod(const RsGxsGroupId& grpId)
{
return mGxs->getSyncPeriod(grpId);
return mGxs.getSyncPeriod(grpId);
}
void setSyncPeriod(const RsGxsGroupId& grpId,uint32_t age_in_secs)
{
mGxs->setSyncPeriod(grpId,age_in_secs);
mGxs.setSyncPeriod(grpId,age_in_secs);
}
RsReputations::ReputationLevel minReputationForForwardingMessages(uint32_t group_sign_flags,uint32_t identity_flags)
{
return mGxs->minReputationForForwardingMessages(group_sign_flags,identity_flags);
return mGxs.minReputationForForwardingMessages(group_sign_flags,identity_flags);
}
private:
RsGxsIface* mGxs;
/// @see RsTokenService::requestGroupInfo
bool requestGroupInfo( uint32_t& token, const RsTokReqOptions& opts,
const std::list<RsGxsGroupId> &groupIds )
{ return mTokenService.requestGroupInfo(token, 0, opts, groupIds); }
/// @see RsTokenService::requestGroupInfo
bool requestGroupInfo(uint32_t& token, const RsTokReqOptions& opts)
{ return mTokenService.requestGroupInfo(token, 0, opts); }
/// @see RsTokenService::requestMsgInfo
bool requestMsgInfo( uint32_t& token,
const RsTokReqOptions& opts, const GxsMsgReq& msgIds )
{ return mTokenService.requestMsgInfo(token, 0, opts, msgIds); }
/// @see RsTokenService::requestMsgInfo
bool requestMsgInfo(
uint32_t& token, const RsTokReqOptions& opts,
const std::list<RsGxsGroupId>& grpIds )
{ return mTokenService.requestMsgInfo(token, 0, opts, grpIds); }
/// @see RsTokenService::requestMsgRelatedInfo
bool requestMsgRelatedInfo(
uint32_t& token, const RsTokReqOptions& opts,
const std::vector<RsGxsGrpMsgIdPair>& msgIds )
{ return mTokenService.requestMsgRelatedInfo(token, 0, opts, msgIds); }
/**
* @jsonapi{development}
* @param[in] token
*/
RsTokenService::GxsRequestStatus requestStatus(uint32_t token)
{ return mTokenService.requestStatus(token); }
/// @see RsTokenService::requestServiceStatistic
void requestServiceStatistic(uint32_t& token)
{ mTokenService.requestServiceStatistic(token); }
/// @see RsTokenService::requestGroupStatistic
void requestGroupStatistic(uint32_t& token, const RsGxsGroupId& grpId)
{ mTokenService.requestGroupStatistic(token, grpId); }
/// @see RsTokenService::cancelRequest
bool cancelRequest(uint32_t token)
{ return mTokenService.cancelRequest(token); }
/**
* @deprecated
* Token service methods are already exposed by this helper, so you should
* not need to get token service pointer directly anymore.
*/
RS_DEPRECATED RsTokenService* getTokenService() { return &mTokenService; }
protected:
/**
* Block caller while request is being processed.
* Useful for blocking API implementation.
* @param[in] token token associated to the request caller is waiting for
* @param[in] maxWait maximum waiting time in milliseconds
*/
RsTokenService::GxsRequestStatus waitToken(
uint32_t token,
std::chrono::milliseconds maxWait = std::chrono::milliseconds(500) )
{
auto timeout = std::chrono::steady_clock::now() + maxWait;
auto st = requestStatus(token);
while( !(st == RsTokenService::FAILED || st >= RsTokenService::COMPLETE)
&& std::chrono::steady_clock::now() < timeout )
{
std::this_thread::sleep_for(std::chrono::milliseconds(2));
st = requestStatus(token);
}
return st;
}
private:
RsGxsIface& mGxs;
RsTokenService& mTokenService;
};
#endif // RSGXSIFACEIMPL_H

View file

@ -119,7 +119,7 @@ struct RsGroupMetaData : RsSerializable
struct RsMsgMetaData
struct RsMsgMetaData : RsSerializable
{
RsMsgMetaData() : mPublishTs(0), mMsgFlags(0), mMsgStatus(0), mChildTs(0) {}
@ -150,6 +150,24 @@ struct RsMsgMetaData
time_t mChildTs;
std::string mServiceString; // Service Specific Free-Form extra storage.
/// @see RsSerializable
virtual void serial_process( RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx )
{
RS_SERIAL_PROCESS(mGroupId);
RS_SERIAL_PROCESS(mMsgId);
RS_SERIAL_PROCESS(mThreadId);
RS_SERIAL_PROCESS(mParentId);
RS_SERIAL_PROCESS(mOrigMsgId);
RS_SERIAL_PROCESS(mAuthorId);
RS_SERIAL_PROCESS(mMsgName);
RS_SERIAL_PROCESS(mPublishTs);
RS_SERIAL_PROCESS(mMsgFlags);
RS_SERIAL_PROCESS(mMsgStatus);
RS_SERIAL_PROCESS(mChildTs);
RS_SERIAL_PROCESS(mServiceString);
}
const std::ostream &print(std::ostream &out, std::string indent = "", std::string varName = "") const {
out
<< indent << varName << " of RsMsgMetaData Values ###################" << std::endl

View file

@ -91,7 +91,7 @@ public:
std::vector<RsGxsTransOutgoingRecord> outgoing_records;
};
RsGxsTrans(RsGxsIface *gxs) : RsGxsIfaceHelper(gxs) {}
RsGxsTrans(RsGxsIface& gxs) : RsGxsIfaceHelper(gxs) {}
virtual ~RsGxsTrans() {}

View file

@ -339,7 +339,7 @@ struct RsIdentityDetails : RsSerializable
struct RsIdentity : RsGxsIfaceHelper
{
explicit RsIdentity(RsGxsIface *gxs): RsGxsIfaceHelper(gxs) {}
explicit RsIdentity(RsGxsIface& gxs): RsGxsIfaceHelper(gxs) {}
virtual ~RsIdentity() {}
/********************************************************************************************/

View file

@ -43,80 +43,89 @@
#include <vector>
#include <retroshare/rstypes.h>
struct RsLoginHelper;
/**
* Pointer to global instance of RsLoginHelper
* @jsonapi{development}
*/
extern RsLoginHelper* rsLoginHelper;
/*!
* Initialisation Class (not publicly disclosed to RsIFace)
*/
class RsInit
{
public:
/* reorganised RsInit system */
public:
enum LoadCertificateStatus : uint8_t
{
OK, /// Everything go as expected, no error occurred
ERR_ALREADY_RUNNING, /// Another istance is running already
ERR_CANT_ACQUIRE_LOCK, /// Another istance is already running?
ERR_UNKOWN /// Unkown error, maybe password is wrong?
};
/*!
* PreLogin
* Call before init retroshare, initialises rsinitconfig's public attributes
*/
static void InitRsConfig() ;
/* reorganised RsInit system */
/*!
* Should be called to load up ssl cert and private key, and intialises gpg
* this must be called before accessing rsserver (e.g. ::startupretroshare)
* @param argc passed from executable
* @param argv commandline arguments passed to executable
* @param strictCheck set to true if you want rs to continue executing if invalid argument passed and vice versa
* @return RS_INIT_...
*/
static int InitRetroShare(int argc, char **argv, bool strictCheck=true);
/*!
* PreLogin
* Call before init retroshare, initialises rsinitconfig's public attributes
*/
static void InitRsConfig();
static bool isPortable();
static bool isWindowsXP();
static bool collectEntropy(uint32_t bytes) ;
/*!
* Should be called to load up ssl cert and private key, and intialises gpg
* this must be called before accessing rsserver (e.g. ::startupretroshare)
* @param argc passed from executable
* @param argv commandline arguments passed to executable
* @param strictCheck set to true if you want rs to continue executing if
* invalid argument passed and vice versa
* @return RS_INIT_...
*/
static int InitRetroShare(int argc, char **argv, bool strictCheck=true);
/*!
* Setup Hidden Location;
*/
static void SetHiddenLocation(const std::string& hiddenaddress, uint16_t port, bool useBob);
static bool isPortable();
static bool isWindowsXP();
static bool collectEntropy(uint32_t bytes) ;
static bool LoadPassword(const std::string& passwd) ;
/*
* Setup Hidden Location;
*/
static void SetHiddenLocation(const std::string& hiddenaddress, uint16_t port, bool useBob);
/*!
static bool LoadPassword(const std::string& passwd) ;
/*
* Final Certificate load. This can be called if:
* a) InitRetroshare() returns RS_INIT_HAVE_ACCOUNT -> autoLoad/password Set.
* b) or LoadPassword()
*
* This uses the preferredId from RsAccounts.
* This wrapper also locks the profile before finalising the login
*/
static LoadCertificateStatus LockAndLoadCertificates(
bool autoLoginNT, std::string& lockFilePath );
* Final Certificate load. This can be called if:
* a) InitRetroshare() returns RS_INIT_HAVE_ACCOUNT -> autoLoad/password Set.
* b) or LoadPassword()
*
* This uses the preferredId from RsAccounts.
* This wrapper also locks the profile before finalising the login
*/
static int LockAndLoadCertificates(bool autoLoginNT, std::string& lockFilePath);
// Post Login Options
static bool getStartMinimised();
/*!
* Post Login Options
*/
static int getSslPwdLen();
static bool getAutoLogin();
static void setAutoLogin(bool autoLogin);
static bool RsClearAutoLogin() ;
static bool getStartMinimised();
private:
/** @brief Lock profile directory
* param[in] accountDir account directory to lock
* param[out] lockFilePath path of the created lock-file
*/
static LoadCertificateStatus LockConfigDirectory(
const std::string& accountDir, std::string& lockFilePath);
static int getSslPwdLen();
static bool getAutoLogin();
static void setAutoLogin(bool autoLogin);
static bool RsClearAutoLogin() ;
private:
#if 0
/* Auto Login */
static bool RsStoreAutoLogin() ;
static bool RsTryAutoLogin() ;
#endif
// THESE CAN BE REMOVED FROM THE CLASS TOO.
/* Lock/unlock profile directory */
static int LockConfigDirectory(const std::string& accountDir, std::string& lockFilePath);
static void UnlockConfigDirectory();
/* The true LoadCertificates() method */
static int LoadCertificates(bool autoLoginNT) ;
/// @brief Unlock profile directory
static void UnlockConfigDirectory();
static int LoadCertificates(bool autoLoginNT);
};
@ -170,7 +179,11 @@ public:
static bool GetAccountDetails(const RsPeerId &id, RsPgpId &gpgId, std::string &gpgName, std::string &gpgEmail, std::string &location);
static bool createNewAccount(const RsPgpId& pgp_id, const std::string& org, const std::string& loc, const std::string& country, bool ishiddenloc,bool is_auto_tor, const std::string& passwd, RsPeerId &sslId, std::string &errString);
static bool createNewAccount(
const RsPgpId& pgp_id, const std::string& org,
const std::string& loc, const std::string& country,
bool ishiddenloc, bool is_auto_tor, const std::string& passwd,
RsPeerId &sslId, std::string &errString );
static void storeSelectedAccount() ;
@ -198,6 +211,63 @@ private:
};
/**
* This helper class have been implemented because there was not reasonable way
* to login in the API that could be exposed via JSON API
*/
struct RsLoginHelper
{
/**
* @brief Normal way to attempt login
* @jsonapi{development}
* @param[in] account Id of the account to which attempt login
* @param[in] password Password for the given account
* @return RsInit::OK if login attempt success, error code otherwhise
*/
RsInit::LoadCertificateStatus attemptLogin(
const RsPeerId& account, const std::string& password );
struct Location : RsSerializable
{
RsPeerId mLocationId;
RsPgpId mPgpId;
std::string mLocationName;
std::string mPpgName;
/// @see RsSerializable::serial_process
void serial_process( RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx );
};
/**
* @brief Get locations and associated information
* @jsonapi{development}
* @param[out] locations storage for the retrived locations
*/
void getLocations(std::vector<RsLoginHelper::Location>& locations);
/**
* @brief Creates a new RetroShare location, and log in once is created
* @jsonapi{development}
* @param[inout] location provide input information to generate the location
* and storage to output the data of the generated location
* @param[in] password to protect and unlock the associated PGP key
* @param[in] makeHidden pass true to create an hidden location. UNTESTED!
* @param[in] makeAutoTor pass true to create an automatically configured
* Tor hidden location. UNTESTED!
* @param[out] errorMessage if some error occurred human readable error
* message
* @return true if success, false otherwise
*/
bool createLocation( RsLoginHelper::Location& location,
const std::string& password, bool makeHidden,
bool makeAutoTor, std::string& errorMessage );
/**
* @brief Close RetroShare session
* @jsonapi{development}
*/
void closeSession();
};
#endif

View file

@ -92,7 +92,7 @@ const ChatLobbyFlags RS_CHAT_LOBBY_FLAGS_PGP_SIGNED ( 0x00000010 ) ; // requi
typedef uint64_t ChatLobbyId ;
typedef uint64_t ChatLobbyMsgId ;
typedef std::string ChatLobbyNickName ;
typedef std::string ChatLobbyNickName ;
typedef uint64_t MessageId ;
@ -279,7 +279,7 @@ struct DistantChatPeerInfo
// Identifier for an chat endpoint like
// neighbour peer, distant peer, chatlobby, broadcast
class ChatId
class ChatId : RsSerializable
{
public:
ChatId();
@ -310,17 +310,28 @@ public:
// this defines from which peer the status string came from
RsPeerId broadcast_status_peer_id;
private:
enum Type { TYPE_NOT_SET,
TYPE_PRIVATE, // private chat with directly connected friend, peer_id is valid
TYPE_PRIVATE_DISTANT, // private chat with distant peer, gxs_id is valid
TYPE_LOBBY, // chat lobby id, lobby_id is valid
TYPE_BROADCAST // message to/from all connected peers
};
enum Type : uint8_t
{ TYPE_NOT_SET,
TYPE_PRIVATE, // private chat with directly connected friend, peer_id is valid
TYPE_PRIVATE_DISTANT, // private chat with distant peer, gxs_id is valid
TYPE_LOBBY, // chat lobby id, lobby_id is valid
TYPE_BROADCAST // message to/from all connected peers
};
Type type;
RsPeerId peer_id;
DistantChatPeerId distant_chat_id;
ChatLobbyId lobby_id;
// RsSerializable interface
public:
void serial_process(RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext &ctx) {
RS_SERIAL_PROCESS(broadcast_status_peer_id);
RS_SERIAL_PROCESS(type);
RS_SERIAL_PROCESS(peer_id);
RS_SERIAL_PROCESS(distant_chat_id);
RS_SERIAL_PROCESS(lobby_id);
}
};
class ChatMessage
@ -340,49 +351,90 @@ public:
//bool system_message;
};
class ChatLobbyInvite
class ChatLobbyInvite : RsSerializable
{
public:
ChatLobbyId lobby_id ;
RsPeerId peer_id ;
std::string lobby_name ;
std::string lobby_topic ;
ChatLobbyFlags lobby_flags ;
public:
ChatLobbyId lobby_id ;
RsPeerId peer_id ;
std::string lobby_name ;
std::string lobby_topic ;
ChatLobbyFlags lobby_flags ;
// RsSerializable interface
public:
void serial_process(RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext &ctx) {
RS_SERIAL_PROCESS(lobby_id);
RS_SERIAL_PROCESS(peer_id);
RS_SERIAL_PROCESS(lobby_name);
RS_SERIAL_PROCESS(lobby_topic);
RS_SERIAL_PROCESS(lobby_flags);
}
};
class VisibleChatLobbyRecord
class VisibleChatLobbyRecord : RsSerializable
{
public:
VisibleChatLobbyRecord(): lobby_id(0), total_number_of_peers(0), last_report_time(0){}
ChatLobbyId lobby_id ; // unique id of the lobby
std::string lobby_name ; // name to use for this lobby
std::string lobby_topic ; // topic to use for this lobby
std::set<RsPeerId> participating_friends ; // list of direct friend who participate.
ChatLobbyId lobby_id ; // unique id of the lobby
std::string lobby_name ; // name to use for this lobby
std::string lobby_topic ; // topic to use for this lobby
std::set<RsPeerId> participating_friends ; // list of direct friend who participate.
uint32_t total_number_of_peers ; // total number of particpating peers. Might not be
time_t last_report_time ; // last time the lobby was reported.
ChatLobbyFlags lobby_flags ; // see RS_CHAT_LOBBY_PRIVACY_LEVEL_PUBLIC / RS_CHAT_LOBBY_PRIVACY_LEVEL_PRIVATE
uint32_t total_number_of_peers ; // total number of particpating peers. Might not be
time_t last_report_time ; // last time the lobby was reported.
ChatLobbyFlags lobby_flags ; // see RS_CHAT_LOBBY_PRIVACY_LEVEL_PUBLIC / RS_CHAT_LOBBY_PRIVACY_LEVEL_PRIVATE
// RsSerializable interface
public:
void serial_process(RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext &ctx) {
RS_SERIAL_PROCESS(lobby_id);
RS_SERIAL_PROCESS(lobby_name);
RS_SERIAL_PROCESS(lobby_topic);
RS_SERIAL_PROCESS(participating_friends);
RS_SERIAL_PROCESS(total_number_of_peers);
RS_SERIAL_PROCESS(last_report_time);
RS_SERIAL_PROCESS(lobby_flags);
}
};
class ChatLobbyInfo
class ChatLobbyInfo : RsSerializable
{
public:
ChatLobbyId lobby_id ; // unique id of the lobby
std::string lobby_name ; // name to use for this lobby
std::string lobby_topic ; // topic to use for this lobby
std::set<RsPeerId> participating_friends ; // list of direct friend who participate. Used to broadcast sent messages.
RsGxsId gxs_id ; // ID to sign messages
public:
ChatLobbyId lobby_id ; // unique id of the lobby
std::string lobby_name ; // name to use for this lobby
std::string lobby_topic ; // topic to use for this lobby
std::set<RsPeerId> participating_friends ; // list of direct friend who participate. Used to broadcast sent messages.
RsGxsId gxs_id ; // ID to sign messages
ChatLobbyFlags lobby_flags ; // see RS_CHAT_LOBBY_PRIVACY_LEVEL_PUBLIC / RS_CHAT_LOBBY_PRIVACY_LEVEL_PRIVATE
std::map<RsGxsId,time_t> gxs_ids ; // list of non direct friend who participate. Used to display only.
time_t last_activity ; // last recorded activity. Useful for removing dead lobbies.
ChatLobbyFlags lobby_flags ; // see RS_CHAT_LOBBY_PRIVACY_LEVEL_PUBLIC / RS_CHAT_LOBBY_PRIVACY_LEVEL_PRIVATE
std::map<RsGxsId, time_t> gxs_ids ; // list of non direct friend who participate. Used to display only.
time_t last_activity ; // last recorded activity. Useful for removing dead lobbies.
// RsSerializable interface
public:
void serial_process(RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext &ctx) {
RS_SERIAL_PROCESS(lobby_id);
RS_SERIAL_PROCESS(lobby_name);
RS_SERIAL_PROCESS(lobby_topic);
RS_SERIAL_PROCESS(participating_friends);
RS_SERIAL_PROCESS(gxs_id);
RS_SERIAL_PROCESS(lobby_flags);
RS_SERIAL_PROCESS(gxs_ids);
RS_SERIAL_PROCESS(last_activity);
}
};
std::ostream &operator<<(std::ostream &out, const Rs::Msgs::MessageInfo &info);
class RsMsgs;
/**
* @brief Pointer to retroshare's message service
* @jsonapi{development}
*/
extern RsMsgs *rsMsgs;
class RsMsgs
@ -438,15 +490,59 @@ virtual bool resetMessageStandardTagTypes(Rs::Msgs::MsgTagType& tags) = 0;
// sendChat for broadcast, private, lobby and private distant chat
// note: for lobby chat, you first have to subscribe to a lobby
// for private distant chat, it is reqired to have an active distant chat session
virtual bool sendChat(ChatId id, std::string msg) = 0;
virtual uint32_t getMaxMessageSecuritySize(int type) = 0;
virtual void sendStatusString(const ChatId& id,const std::string& status_string) = 0;
virtual void clearChatLobby(const ChatId& id) = 0;
/**
* @brief sendChat send a chat message to a given id
* @jsonapi{development}
* @param[in] id id to send the message
* @param[in] msg message to send
* @return true on success
*/
virtual bool sendChat(ChatId id, std::string msg) = 0;
virtual void setCustomStateString(const std::string& status_string) = 0 ;
virtual std::string getCustomStateString() = 0 ;
virtual std::string getCustomStateString(const RsPeerId& peer_id) = 0 ;
/**
* @brief getMaxMessageSecuritySize get the maximum size of a chta message
* @jsonapi{development}
* @param[in] type chat type
* @return maximum size or zero for infinite
*/
virtual uint32_t getMaxMessageSecuritySize(int type) = 0;
/**
* @brief sendStatusString send a status string
* @jsonapi{development}
* @param[in] id chat id to send the status string to
* @param[in] status_string status string
*/
virtual void sendStatusString(const ChatId &id, const std::string &status_string) = 0;
/**
* @brief clearChatLobby clear a chat lobby
* @jsonapi{development}
* @param[in] id chat lobby id to clear
*/
virtual void clearChatLobby(const ChatId &id) = 0;
/**
* @brief setCustomStateString set your custom status message
* @jsonapi{development}
* @param[in] status_string status message
*/
virtual void setCustomStateString(const std::string &status_string) = 0;
/**
* @brief getCustomStateString get your custom status message
* @return status message
*/
virtual std::string getCustomStateString() = 0;
/**
* @brief getCustomStateString get the custom status message from a peer
* @jsonapi{development}
* @param[in] peer_id peer id to the peer you want to get the status message from
* @return status message
*/
virtual std::string getCustomStateString(const RsPeerId &peer_id) = 0;
// get avatar data for peer pid
virtual void getAvatarData(const RsPeerId& pid,unsigned char *& data,int& size) = 0 ;
@ -454,29 +550,139 @@ virtual void getAvatarData(const RsPeerId& pid,unsigned char *& data,int& size)
virtual void setOwnAvatarData(const unsigned char *data,int size) = 0 ;
virtual void getOwnAvatarData(unsigned char *& data,int& size) = 0 ;
/****************************************/
/* Chat lobbies */
/****************************************/
/****************************************/
/* Chat lobbies */
/****************************************/
/**
* @brief joinVisibleChatLobby join a lobby that is visible
* @jsonapi{development}
* @param[in] lobby_id lobby to join to
* @param[in] own_id chat id to use
* @return true on success
*/
virtual bool joinVisibleChatLobby(const ChatLobbyId &lobby_id, const RsGxsId &own_id) = 0 ;
virtual bool joinVisibleChatLobby(const ChatLobbyId& lobby_id,const RsGxsId& own_id) = 0 ;
/// get ids of subscribed lobbies
virtual void getChatLobbyList(std::list<ChatLobbyId>& cl_list) = 0;
/// get lobby info of a subscribed chat lobby. Returns true if lobby id is valid.
virtual bool getChatLobbyInfo(const ChatLobbyId& id,ChatLobbyInfo& info) = 0 ;
/// get info about all lobbies, subscribed and unsubscribed
virtual void getListOfNearbyChatLobbies(std::vector<VisibleChatLobbyRecord>& public_lobbies) = 0 ;
virtual void invitePeerToLobby(const ChatLobbyId& lobby_id,const RsPeerId& peer_id) = 0;
virtual bool acceptLobbyInvite(const ChatLobbyId& id,const RsGxsId& identity) = 0 ;
virtual void denyLobbyInvite(const ChatLobbyId& id) = 0 ;
virtual void getPendingChatLobbyInvites(std::list<ChatLobbyInvite>& invites) = 0;
virtual void unsubscribeChatLobby(const ChatLobbyId& lobby_id) = 0;
virtual bool setIdentityForChatLobby(const ChatLobbyId& lobby_id,const RsGxsId& nick) = 0;
virtual bool getIdentityForChatLobby(const ChatLobbyId& lobby_id,RsGxsId& nick) = 0 ;
virtual bool setDefaultIdentityForChatLobby(const RsGxsId& nick) = 0;
virtual void getDefaultIdentityForChatLobby(RsGxsId& id) = 0 ;
virtual void setLobbyAutoSubscribe(const ChatLobbyId& lobby_id, const bool autoSubscribe) = 0 ;
virtual bool getLobbyAutoSubscribe(const ChatLobbyId& lobby_id) = 0 ;
virtual ChatLobbyId createChatLobby(const std::string& lobby_name,const RsGxsId& lobby_identity,const std::string& lobby_topic,const std::set<RsPeerId>& invited_friends,ChatLobbyFlags lobby_privacy_type) = 0 ;
/**
* @brief getChatLobbyList get ids of subscribed lobbies
* @jsonapi{development}
* @param[out] cl_list lobby list
*/
virtual void getChatLobbyList(std::list<ChatLobbyId> &cl_list) = 0;
/**
* @brief getChatLobbyInfo get lobby info of a subscribed chat lobby. Returns true if lobby id is valid.
* @jsonapi{development}
* @param[in] id id to get infos from
* @param[out] info lobby infos
* @return true on success
*/
virtual bool getChatLobbyInfo(const ChatLobbyId &id, ChatLobbyInfo &info) = 0 ;
/**
* @brief getListOfNearbyChatLobbies get info about all lobbies, subscribed and unsubscribed
* @jsonapi{development}
* @param[out] public_lobbies list of all visible lobbies
*/
virtual void getListOfNearbyChatLobbies(std::vector<VisibleChatLobbyRecord> &public_lobbies) = 0 ;
/**
* @brief invitePeerToLobby invite a peer to join a lobby
* @jsonapi{development}
* @param[in] lobby_id lobby it to invite into
* @param[in] peer_id peer to invite
*/
virtual void invitePeerToLobby(const ChatLobbyId &lobby_id, const RsPeerId &peer_id) = 0;
/**
* @brief acceptLobbyInvite accept a chat invite
* @jsonapi{development}
* @param[in] id chat lobby id you were invited into and you want to join
* @param[in] identity chat identity to use
* @return true on success
*/
virtual bool acceptLobbyInvite(const ChatLobbyId &id, const RsGxsId &identity) = 0 ;
/**
* @brief denyLobbyInvite deny a chat lobby invite
* @jsonapi{development}
* @param[in] id chat lobby id you were invited into
*/
virtual void denyLobbyInvite(const ChatLobbyId &id) = 0 ;
/**
* @brief getPendingChatLobbyInvites get a list of all pending chat lobby invites
* @jsonapi{development}
* @param[out] invites list of all pending chat lobby invites
*/
virtual void getPendingChatLobbyInvites(std::list<ChatLobbyInvite> &invites) = 0;
/**
* @brief unsubscribeChatLobby leave a chat lobby
* @jsonapi{development}
* @param[in] lobby_id lobby to leave
*/
virtual void unsubscribeChatLobby(const ChatLobbyId &lobby_id) = 0;
/**
* @brief setIdentityForChatLobby set the chat identit
* @jsonapi{development}
* @param[in] lobby_id lobby to change the chat idnetity for
* @param[in] nick new chat identity
* @return true on success
*/
virtual bool setIdentityForChatLobby(const ChatLobbyId &lobby_id, const RsGxsId &nick) = 0;
/**
* @brief getIdentityForChatLobby
* @jsonapi{development}
* @param[in] lobby_id lobby to get the chat id from
* @param[out] nick chat identity
* @return true on success
*/
virtual bool getIdentityForChatLobby(const ChatLobbyId &lobby_id, RsGxsId &nick) = 0 ;
/**
* @brief setDefaultIdentityForChatLobby set the default identity used for chat lobbies
* @jsonapi{development}
* @param[in] nick chat identitiy to use
* @return true on success
*/
virtual bool setDefaultIdentityForChatLobby(const RsGxsId &nick) = 0;
/**
* @brief getDefaultIdentityForChatLobby get the default identity used for chat lobbies
* @jsonapi{development}
* @param[out] id chat identitiy to use
*/
virtual void getDefaultIdentityForChatLobby(RsGxsId &id) = 0 ;
/**
* @brief setLobbyAutoSubscribe enable or disable auto subscribe for a chat lobby
* @jsonapi{development}
* @param[in] lobby_id lobby to auto (un)subscribe
* @param[in] autoSubscribe set value for auto subscribe
*/
virtual void setLobbyAutoSubscribe(const ChatLobbyId &lobby_id, const bool autoSubscribe) = 0 ;
/**
* @brief getLobbyAutoSubscribe get current value of auto subscribe
* @jsonapi{development}
* @param[in] lobby_id lobby to get value from
* @return wether lobby has auto subscribe enabled or disabled
*/
virtual bool getLobbyAutoSubscribe(const ChatLobbyId &lobby_id) = 0 ;
/**
* @brief createChatLobby create a new chat lobby
* @jsonapi{development}
* @param[in] lobby_name lobby name
* @param[in] lobby_identity chat id to use for new lobby
* @param[in] lobby_topic lobby toppic
* @param[in] invited_friends list of friends to invite
* @param[in] lobby_privacy_type flag for new chat lobby
* @return chat id of new lobby
*/
virtual ChatLobbyId createChatLobby(const std::string &lobby_name, const RsGxsId &lobby_identity, const std::string &lobby_topic, const std::set<RsPeerId> &invited_friends, ChatLobbyFlags lobby_privacy_type) = 0 ;
/****************************************/
/* Distant chat */

View file

@ -181,7 +181,7 @@ class RsFeedItem
// This mechanism can be used in plugins, new services, etc.
//
class NotifyClient ;
class NotifyClient;
class RsNotify
{
@ -208,42 +208,41 @@ class RsNotify
class NotifyClient
{
public:
NotifyClient() {}
virtual ~NotifyClient() {}
public:
NotifyClient() {}
virtual ~NotifyClient() {}
virtual void notifyListPreChange (int /* list */, int /* type */) {}
virtual void notifyListChange (int /* list */, int /* type */) {}
virtual void notifyErrorMsg (int /* list */, int /* sev */, std::string /* msg */) {}
virtual void notifyChatMessage (const ChatMessage& /* msg */) {}
virtual void notifyChatStatus (const ChatId& /* chat_id */, const std::string& /* status_string */) {}
virtual void notifyChatCleared (const ChatId& /* chat_id */) {}
virtual void notifyChatLobbyEvent (uint64_t /* lobby id */, uint32_t /* event type */ ,const RsGxsId& /* nickname */,const std::string& /* any string */) {}
virtual void notifyChatLobbyTimeShift (int /* time_shift*/) {}
virtual void notifyCustomState (const std::string& /* peer_id */, const std::string& /* status_string */) {}
virtual void notifyHashingInfo (uint32_t /* type */, const std::string& /* fileinfo */) {}
virtual void notifyTurtleSearchResult (uint32_t /* search_id */, const std::list<TurtleFileInfo>& /* files */) {}
virtual void notifyListPreChange (int /* list */, int /* type */) {}
virtual void notifyListChange (int /* list */, int /* type */) {}
virtual void notifyErrorMsg (int /* list */, int /* sev */, std::string /* msg */) {}
virtual void notifyChatMessage (const ChatMessage& /* msg */) {}
virtual void notifyChatStatus (const ChatId& /* chat_id */, const std::string& /* status_string */) {}
virtual void notifyChatCleared (const ChatId& /* chat_id */) {}
virtual void notifyChatLobbyEvent (uint64_t /* lobby id */, uint32_t /* event type */ ,const RsGxsId& /* nickname */,const std::string& /* any string */) {}
virtual void notifyChatLobbyTimeShift (int /* time_shift*/) {}
virtual void notifyCustomState (const std::string& /* peer_id */, const std::string& /* status_string */) {}
virtual void notifyHashingInfo (uint32_t /* type */, const std::string& /* fileinfo */) {}
virtual void notifyTurtleSearchResult (uint32_t /* search_id */, const std::list<TurtleFileInfo>& /* files */) {}
#warning MISSING CODE HERE
// virtual void notifyTurtleSearchResult (uint32_t /* search_id */, const std::list<TurtleGxsInfo >& /* groups */) {}
virtual void notifyPeerHasNewAvatar (std::string /* peer_id */) {}
virtual void notifyOwnAvatarChanged () {}
virtual void notifyOwnStatusMessageChanged () {}
virtual void notifyDiskFull (uint32_t /* location */, uint32_t /* size limit in MB */) {}
virtual void notifyPeerStatusChanged (const std::string& /* peer_id */, uint32_t /* status */) {}
virtual void notifyGxsChange (const RsGxsChanges& /* changes */) {}
virtual void notifyConnectionWithoutCert () {}
// virtual void notifyTurtleSearchResult (uint32_t /* search_id */, const std::list<TurtleGxsInfo >& /* groups */) {}
virtual void notifyPeerHasNewAvatar (std::string /* peer_id */) {}
virtual void notifyOwnAvatarChanged () {}
virtual void notifyOwnStatusMessageChanged () {}
virtual void notifyDiskFull (uint32_t /* location */, uint32_t /* size limit in MB */) {}
virtual void notifyPeerStatusChanged (const std::string& /* peer_id */, uint32_t /* status */) {}
virtual void notifyGxsChange (const RsGxsChanges& /* changes */) {}
virtual void notifyConnectionWithoutCert () {}
/* one or more peers has changed the states */
virtual void notifyPeerStatusChangedSummary () {}
virtual void notifyDiscInfoChanged () {}
/* one or more peers has changed the states */
virtual void notifyPeerStatusChangedSummary () {}
virtual void notifyDiscInfoChanged () {}
virtual bool askForDeferredSelfSignature (const void * /* data */, const uint32_t /* len */, unsigned char * /* sign */, unsigned int * /* signlen */,int& signature_result , std::string /*reason = ""*/) { signature_result = false ;return true; }
virtual void notifyDownloadComplete (const std::string& /* fileHash */) {}
virtual void notifyDownloadCompleteCount (uint32_t /* count */) {}
virtual void notifyHistoryChanged (uint32_t /* msgId */, int /* type */) {}
virtual bool askForPassword (const std::string& /* title */, const std::string& /* key_details */, bool /* prev_is_bad */, std::string& /* password */,bool& /* cancelled */ ) { return false ;}
virtual bool askForPluginConfirmation (const std::string& /* plugin_filename */, const std::string& /* plugin_file_hash */,bool /* first_time */) { return false ;}
virtual bool askForDeferredSelfSignature (const void * /* data */, const uint32_t /* len */, unsigned char * /* sign */, unsigned int * /* signlen */,int& signature_result , std::string /*reason = ""*/) { signature_result = false ;return true; }
virtual void notifyDownloadComplete (const std::string& /* fileHash */) {}
virtual void notifyDownloadCompleteCount (uint32_t /* count */) {}
virtual void notifyHistoryChanged (uint32_t /* msgId */, int /* type */) {}
virtual bool askForPassword (const std::string& /* title */, const std::string& /* key_details */, bool /* prev_is_bad */, std::string& /* password */,bool& /* cancelled */ ) { return false ;}
virtual bool askForPluginConfirmation (const std::string& /* plugin_filename */, const std::string& /* plugin_file_hash */,bool /* first_time */) { return false ;}
};
#endif

View file

@ -293,16 +293,25 @@ public:
std::string cipher_version;
};
class RsGroupInfo
class RsGroupInfo : RsSerializable
{
public:
RsGroupInfo();
RsGroupInfo();
RsNodeGroupId id;
std::string name;
uint32_t flag;
RsNodeGroupId id;
std::string name;
uint32_t flag;
std::set<RsPgpId> peerIds;
std::set<RsPgpId> peerIds;
// RsSerializable interface
public:
void serial_process(RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext &ctx) {
RS_SERIAL_PROCESS(id);
RS_SERIAL_PROCESS(name);
RS_SERIAL_PROCESS(flag);
RS_SERIAL_PROCESS(peerIds);
}
};
std::ostream &operator<<(std::ostream &out, const RsPeerDetails &detail);

View file

@ -74,7 +74,7 @@ class RsPosted : public RsGxsIfaceHelper, public RsGxsCommentService
//static const uint32_t FLAG_MSGTYPE_POST;
//static const uint32_t FLAG_MSGTYPE_MASK;
explicit RsPosted(RsGxsIface* gxs) : RsGxsIfaceHelper(gxs) {}
explicit RsPosted(RsGxsIface& gxs) : RsGxsIfaceHelper(gxs) {}
virtual ~RsPosted() {}
/* Specific Service Data */

View file

@ -119,19 +119,19 @@ class RsTokenService
public:
// TODO CLEANUP: This should be an enum
static const uint8_t GXS_REQUEST_V2_STATUS_FAILED;
static const uint8_t GXS_REQUEST_V2_STATUS_PENDING;
static const uint8_t GXS_REQUEST_V2_STATUS_PARTIAL;
static const uint8_t GXS_REQUEST_V2_STATUS_FINISHED_INCOMPLETE;
static const uint8_t GXS_REQUEST_V2_STATUS_COMPLETE;
static const uint8_t GXS_REQUEST_V2_STATUS_DONE; // ONCE ALL DATA RETRIEVED.
static const uint8_t GXS_REQUEST_V2_STATUS_CANCELLED;
enum GxsRequestStatus : uint8_t
{
FAILED,
PENDING,
PARTIAL,
COMPLETE,
DONE, /// Once all data has been retrived
CANCELLED
};
public:
RsTokenService() { return; }
virtual ~RsTokenService() { return; }
RsTokenService() {}
virtual ~RsTokenService() {}
/* Data Requests */
@ -195,7 +195,7 @@ public:
* @param token value of token to check status for
* @return the current status of request
*/
virtual uint32_t requestStatus(const uint32_t token) = 0;
virtual GxsRequestStatus requestStatus(const uint32_t token) = 0;
/*!
* This request statistics on amount of data held
@ -216,19 +216,14 @@ public:
*/
virtual void requestGroupStatistic(uint32_t& token, const RsGxsGroupId& grpId) = 0;
/* Cancel Request */
/*!
* If this function returns false, it may be that the request has completed
* already. Useful for very expensive request. This is a blocking operation
* @param token the token of the request to cancel
* @return false if unusuccessful in cancelling request, true if successful
*/
virtual bool cancelRequest(const uint32_t &token) = 0;
/*!
* @brief Cancel Request
* If this function returns false, it may be that the request has completed
* already. Useful for very expensive request.
* @param token the token of the request to cancel
* @return false if unusuccessful in cancelling request, true if successful
*/
virtual bool cancelRequest(const uint32_t &token) = 0;
};
#endif // RSTOKENSERVICE_H

View file

@ -29,24 +29,42 @@
#include "serialiser/rstlvbinary.h"
#include "retroshare/rstypes.h"
#include "retroshare/rsgxsifacetypes.h"
#include "serialiser/rsserializable.h"
namespace RsRegularExpression { class LinearizedExpression ; }
class RsTurtleClientService ;
class RsTurtle;
extern RsTurtle *rsTurtle ;
/**
* Pointer to global instance of RsTurtle service implementation
*/
extern RsTurtle* rsTurtle;
typedef uint32_t TurtleRequestId ;
typedef RsPeerId TurtleVirtualPeerId;
// This is the structure used to send back results of the turtle search
// to the notifyBase class, or send info to the GUI.
struct TurtleFileInfo
/**
* This is the structure used to send back results of the turtle search,
* to other peers, to the notifyBase class, to the search caller or to the GUI.
*/
struct TurtleFileInfo : RsSerializable
{
RsFileHash hash ;
std::string name ;
uint64_t size ;
uint64_t size; /// File size
RsFileHash hash; /// File hash
std::string name; /// File name
/// @see RsSerializable::serial_process
void serial_process( RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx )
{
RS_SERIAL_PROCESS(size);
RS_SERIAL_PROCESS(hash);
// Use String TLV serial process for retrocompatibility
RsTypeSerializer::serial_process(
j, ctx, TLV_TYPE_STR_NAME, name, "name" );
}
};
struct TurtleTunnelRequestDisplayInfo
@ -90,7 +108,7 @@ class TurtleTrafficStatisticsInfo
//
class RsTurtle
{
public:
public:
RsTurtle() {}
virtual ~RsTurtle() {}
@ -106,7 +124,9 @@ class RsTurtle
// the request id, which will be further used by the gui to store results
// as they come back.
//
virtual TurtleRequestId turtleSearch(unsigned char *search_bin_data,uint32_t search_bin_data_len,RsTurtleClientService *client_service) =0;
virtual TurtleRequestId turtleSearch(
unsigned char *search_bin_data, uint32_t search_bin_data_len,
RsTurtleClientService* client_service ) = 0;
// Initiates tunnel handling for the given file hash. tunnels. Launches
// an exception if an error occurs during the initialization process. The

View file

@ -65,15 +65,25 @@ const uint32_t RS_CONFIG_DIRECTORY = 0x0002 ;
const uint32_t RS_PGP_DIRECTORY = 0x0003 ;
const uint32_t RS_DIRECTORY_COUNT = 0x0004 ;
class TransferInfo
struct TransferInfo : RsSerializable
{
public:
/**** Need Some of these Fields ****/
RsPeerId peerId;
std::string name; /* if has alternative name? */
double tfRate; /* kbytes */
int status; /* FT_STATE_... */
uint64_t transfered ; // used when no chunkmap data is available
/**** Need Some of these Fields ****/
RsPeerId peerId;
std::string name; /* if has alternative name? */
double tfRate; /* kbytes */
int status; /* FT_STATE_... */
uint64_t transfered ; // used when no chunkmap data is available
/// @see RsSerializable
void serial_process(RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx)
{
RS_SERIAL_PROCESS(peerId);
RS_SERIAL_PROCESS(name);
RS_SERIAL_PROCESS(tfRate);
RS_SERIAL_PROCESS(status);
RS_SERIAL_PROCESS(transfered);
}
};
enum QueueMove { QUEUE_TOP = 0x00,
@ -82,9 +92,11 @@ enum QueueMove { QUEUE_TOP = 0x00,
QUEUE_BOTTOM = 0x03
};
enum DwlSpeed { SPEED_LOW = 0x00,
SPEED_NORMAL = 0x01,
SPEED_HIGH = 0x02
enum DwlSpeed : uint8_t
{
SPEED_LOW = 0x00,
SPEED_NORMAL = 0x01,
SPEED_HIGH = 0x02
};
@ -171,54 +183,76 @@ const FileStorageFlags DIR_FLAGS_PERMISSIONS_MASK ( DIR_FLAGS_ANONYMOUS_DOW
const FileStorageFlags DIR_FLAGS_LOCAL ( 0x1000 );
const FileStorageFlags DIR_FLAGS_REMOTE ( 0x2000 );
class FileInfo
struct FileInfo : RsSerializable
{
/* old BaseInfo Entries */
public:
FileInfo():
mId(0), searchId(0), size(0), avail(0), rank(0), age(0),
queue_position(0), transfered(0), tfRate(0), downloadStatus(0),
priority(SPEED_NORMAL), lastTS(0) {}
FileInfo() : mId(0), searchId(0), size(0), avail(0), rank(0), age(0), queue_position(0),
transfered(0), tfRate(0), downloadStatus(0), priority(SPEED_NORMAL), lastTS(0){}
// RsCertId id; /* key for matching everything */
/// Combination of the four RS_DIR_FLAGS_*. Updated when the file is a local stored file.
FileStorageFlags storage_permission_flags;
FileStorageFlags storage_permission_flags; // Combination of the four RS_DIR_FLAGS_*. Updated when the file is a local stored file.
TransferRequestFlags transfer_info_flags ; // various flags from RS_FILE_HINTS_*
/// various flags from RS_FILE_HINTS_*
TransferRequestFlags transfer_info_flags;
/* allow this to be tweaked by the GUI Model */
mutable unsigned int mId; /* (GUI) Model Id -> unique number */
/** allow this to be tweaked by the GUI Model
* (GUI) Model Id -> unique number
*/
mutable unsigned int mId;
/* Old FileInfo Entries */
public:
static const int kRsFiStatusNone = 0;
static const int kRsFiStatusStall = 1;
static const int kRsFiStatusProgress = 2;
static const int kRsFiStatusDone = 2;
/// 0 if none
int searchId;
/* FileInfo(); */
std::string path;
std::string fname;
RsFileHash hash;
std::string ext;
int searchId; /* 0 if none */
std::string path;
std::string fname;
RsFileHash hash;
std::string ext;
uint64_t size;
uint64_t avail; /// how much we have
uint64_t size;
uint64_t avail; /* how much we have */
double rank;
int age;
uint32_t queue_position;
double rank;
int age;
uint32_t queue_position ;
/* Transfer Stuff */
uint64_t transfered;
double tfRate; /// in kbytes
uint32_t downloadStatus; /// FT_STATE_DOWNLOADING & co. See rstypes.h
std::vector<TransferInfo> peers;
/* Transfer Stuff */
uint64_t transfered;
double tfRate; /* in kbytes */
uint32_t downloadStatus; // FT_STATE_DOWNLOADING & co. See rstypes.h
std::vector<TransferInfo> peers;
DwlSpeed priority;
time_t lastTS;
DwlSpeed priority ;
time_t lastTS;
std::list<RsNodeGroupId> parent_groups ;
std::list<RsNodeGroupId> parent_groups;
/// @see RsSerializable
void serial_process(RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx)
{
RS_SERIAL_PROCESS(storage_permission_flags);
RS_SERIAL_PROCESS(transfer_info_flags);
RS_SERIAL_PROCESS(mId);
RS_SERIAL_PROCESS(searchId);
RS_SERIAL_PROCESS(path);
RS_SERIAL_PROCESS(fname);
RS_SERIAL_PROCESS(hash);
RS_SERIAL_PROCESS(ext);
RS_SERIAL_PROCESS(size);
RS_SERIAL_PROCESS(avail);
RS_SERIAL_PROCESS(rank);
RS_SERIAL_PROCESS(age);
RS_SERIAL_PROCESS(queue_position);
RS_SERIAL_PROCESS(transfered);
RS_SERIAL_PROCESS(tfRate);
RS_SERIAL_PROCESS(downloadStatus);
RS_SERIAL_PROCESS(peers);
RS_SERIAL_PROCESS(priority);
RS_SERIAL_PROCESS(lastTS);
RS_SERIAL_PROCESS(parent_groups);
}
};
std::ostream &operator<<(std::ostream &out, const FileInfo& info);
@ -268,36 +302,58 @@ class FileDetail
class CompressedChunkMap ;
class FileChunksInfo
struct FileChunksInfo : RsSerializable
{
public:
enum ChunkState { CHUNK_CHECKING=3, CHUNK_DONE=2, CHUNK_ACTIVE=1, CHUNK_OUTSTANDING=0 } ;
enum ChunkStrategy { CHUNK_STRATEGY_STREAMING, CHUNK_STRATEGY_RANDOM, CHUNK_STRATEGY_PROGRESSIVE } ;
enum ChunkState : uint8_t
{
CHUNK_OUTSTANDING = 0,
CHUNK_ACTIVE = 1,
CHUNK_DONE = 2,
CHUNK_CHECKING = 3
};
struct SliceInfo
{
uint32_t start ;
uint32_t size ;
RsPeerId peer_id ;
};
enum ChunkStrategy : uint8_t
{
CHUNK_STRATEGY_STREAMING,
CHUNK_STRATEGY_RANDOM,
CHUNK_STRATEGY_PROGRESSIVE
};
uint64_t file_size ; // real size of the file
uint32_t chunk_size ; // size of chunks
uint32_t strategy ;
struct SliceInfo
{
uint32_t start;
uint32_t size;
RsPeerId peer_id;
};
// dl state of chunks. Only the last chunk may have size < chunk_size
std::vector<ChunkState> chunks ;
uint64_t file_size; /// real size of the file
uint32_t chunk_size; /// size of chunks
ChunkStrategy strategy;
// For each source peer, gives the compressed bit map of have/don't have sate
std::map<RsPeerId, CompressedChunkMap> compressed_peer_availability_maps ;
/// dl state of chunks. Only the last chunk may have size < chunk_size
std::vector<ChunkState> chunks;
// For each chunk (by chunk number), gives the completion of the chunk.
//
std::vector<std::pair<uint32_t,uint32_t> > active_chunks ;
/// For each source peer, gives the compressed bit map of have/don't have sate
std::map<RsPeerId, CompressedChunkMap> compressed_peer_availability_maps;
// The list of pending requests, chunk per chunk (by chunk id)
//
std::map<uint32_t, std::vector<SliceInfo> > pending_slices ;
/// For each chunk (by chunk number), gives the completion of the chunk.
std::vector<std::pair<uint32_t,uint32_t> > active_chunks;
/// The list of pending requests, chunk per chunk (by chunk id)
std::map<uint32_t, std::vector<SliceInfo> > pending_slices;
/// @see RsSerializable
void serial_process(RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx)
{
RS_SERIAL_PROCESS(file_size);
RS_SERIAL_PROCESS(chunk_size);
RS_SERIAL_PROCESS(strategy);
RS_SERIAL_PROCESS(chunks);
RS_SERIAL_PROCESS(compressed_peer_availability_maps);
RS_SERIAL_PROCESS(active_chunks);
//RS_SERIAL_PROCESS(pending_slices);
}
};
class CompressedChunkMap : public RsSerializable

View file

@ -111,10 +111,10 @@ std::ostream &operator<<(std::ostream &out, const RsWikiComment &comment);
class RsWiki: public RsGxsIfaceHelper
{
public:
public:
RsWiki(RsGxsIface *gxs): RsGxsIfaceHelper(gxs) { return; }
virtual ~RsWiki() { return; }
RsWiki(RsGxsIface& gxs): RsGxsIfaceHelper(gxs) {}
virtual ~RsWiki() {}
/* Specific Service Data */
virtual bool getCollections(const uint32_t &token, std::vector<RsWikiCollection> &collections) = 0;

View file

@ -104,7 +104,7 @@ class RsWire: public RsGxsIfaceHelper
{
public:
explicit RsWire(RsGxsIface *gxs): RsGxsIfaceHelper(gxs) {}
explicit RsWire(RsGxsIface& gxs) : RsGxsIfaceHelper(gxs) {}
virtual ~RsWire() {}
/* Specific Service Data */