Merge branch 'master' into extra_locators_merge

This commit is contained in:
Gioacchino Mazzurco 2018-07-02 12:22:23 +02:00
commit 1dd707710b
No known key found for this signature in database
GPG key ID: A1FBCA3872E87051
241 changed files with 20454 additions and 3066 deletions

View file

@ -30,7 +30,7 @@
typedef RsPeerId ChatLobbyVirtualPeerId ;
class RsItem ;
struct RsItem;
class p3HistoryMgr ;
class p3IdService ;
class p3ServiceControl;

View file

@ -205,11 +205,8 @@ void RsPrivateChatMsgConfigItem::get(RsChatMsgItem *ci)
ci->recvTime = recvTime;
}
/* Necessary to serialize `store` that is an STL container with RsChatMsgItem
* inside which is a subtype of RsItem */
RS_REGISTER_ITEM_TYPE(RsChatMsgItem)
void PrivateOugoingMapItem::serial_process(
RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx )
{ RS_REGISTER_SERIAL_MEMBER(store); }
{ RS_SERIAL_PROCESS(store); }

View file

@ -623,7 +623,7 @@ bool LocalDirectoryStorage::locked_getFileSharingPermissions(const EntryIndex& i
if(it == mLocalDirs.end())
{
std::cerr << "(EE) very weird bug: base directory \"" << base_dir << "\" not found in shared dir list." << std::endl;
std::cerr << "(II) base directory \"" << base_dir << "\" not found in shared dir list." << std::endl;
return false ;
}

View file

@ -73,10 +73,23 @@ void LocalDirectoryUpdater::data_tick()
{
if(now > mDelayBetweenDirectoryUpdates + mLastSweepTime)
{
if(sweepSharedDirectories())
bool some_files_not_ready = false ;
if(sweepSharedDirectories(some_files_not_ready))
{
mNeedsFullRecheck = false;
mLastSweepTime = now ;
if(some_files_not_ready)
{
mNeedsFullRecheck = true ;
mLastSweepTime = now - mDelayBetweenDirectoryUpdates + 60 ; // retry 20 secs from now
std::cerr << "(II) some files being modified. Will re-scan in 60 secs." << std::endl;
}
else
{
mNeedsFullRecheck = false ;
mLastSweepTime = now ;
}
mSharedDirectories->notifyTSChanged();
mForceUpdate = false ;
}
@ -111,7 +124,7 @@ void LocalDirectoryUpdater::forceUpdate()
mHashCache->togglePauseHashingProcess();
}
bool LocalDirectoryUpdater::sweepSharedDirectories()
bool LocalDirectoryUpdater::sweepSharedDirectories(bool& some_files_not_ready)
{
if(mHashSalt.isNull())
{
@ -158,8 +171,8 @@ bool LocalDirectoryUpdater::sweepSharedDirectories()
#endif
existing_dirs.insert(RsDirUtil::removeSymLinks(stored_dir_it.name()));
recursUpdateSharedDir(stored_dir_it.name(), *stored_dir_it,existing_dirs,1) ; // here we need to use the list that was stored, instead of the shared dir list, because the two
// are not necessarily in the same order.
recursUpdateSharedDir(stored_dir_it.name(), *stored_dir_it,existing_dirs,1,some_files_not_ready) ; // here we need to use the list that was stored, instead of the shared dir list, because the two
// are not necessarily in the same order.
}
RsServer::notify()->notifyListChange(NOTIFY_LIST_DIRLIST_LOCAL, 0);
@ -168,7 +181,7 @@ bool LocalDirectoryUpdater::sweepSharedDirectories()
return true ;
}
void LocalDirectoryUpdater::recursUpdateSharedDir(const std::string& cumulated_path, DirectoryStorage::EntryIndex indx,std::set<std::string>& existing_directories,uint32_t current_depth)
void LocalDirectoryUpdater::recursUpdateSharedDir(const std::string& cumulated_path, DirectoryStorage::EntryIndex indx,std::set<std::string>& existing_directories,uint32_t current_depth,bool& some_files_not_ready)
{
#ifdef DEBUG_LOCAL_DIR_UPDATER
std::cerr << "[directory storage] parsing directory " << cumulated_path << ", index=" << indx << std::endl;
@ -187,6 +200,8 @@ void LocalDirectoryUpdater::recursUpdateSharedDir(const std::string& cumulated_p
return;
}
time_t now = time(NULL) ;
if(mNeedsFullRecheck || dirIt.dir_modtime() > dir_local_mod_time) // the > is because we may have changed the virtual name, and therefore the TS wont match.
// we only want to detect when the directory has changed on the disk
{
@ -200,11 +215,23 @@ void LocalDirectoryUpdater::recursUpdateSharedDir(const std::string& cumulated_p
{
switch(dirIt.file_type())
{
case librs::util::FolderIterator::TYPE_FILE: subfiles[dirIt.file_name()].modtime = dirIt.file_modtime() ;
subfiles[dirIt.file_name()].size = dirIt.file_size();
case librs::util::FolderIterator::TYPE_FILE:
if(dirIt.file_modtime() + MIN_TIME_AFTER_LAST_MODIFICATION < now)
{
subfiles[dirIt.file_name()].modtime = dirIt.file_modtime() ;
subfiles[dirIt.file_name()].size = dirIt.file_size();
#ifdef DEBUG_LOCAL_DIR_UPDATER
std::cerr << " adding sub-file \"" << dirIt.file_name() << "\"" << std::endl;
std::cerr << " adding sub-file \"" << dirIt.file_name() << "\"" << std::endl;
#endif
}
else
{
some_files_not_ready = true ;
std::cerr << "(WW) file " << dirIt.file_fullpath() << " is probably being modified. Keeping it for later." << std::endl;
}
break;
case librs::util::FolderIterator::TYPE_DIR:
@ -276,7 +303,7 @@ void LocalDirectoryUpdater::recursUpdateSharedDir(const std::string& cumulated_p
#ifdef DEBUG_LOCAL_DIR_UPDATER
std::cerr << " recursing into " << stored_dir_it.name() << std::endl;
#endif
recursUpdateSharedDir(cumulated_path + "/" + stored_dir_it.name(), *stored_dir_it,existing_directories,current_depth+1) ;
recursUpdateSharedDir(cumulated_path + "/" + stored_dir_it.name(), *stored_dir_it,existing_directories,current_depth+1,some_files_not_ready) ;
}
}

View file

@ -70,8 +70,8 @@ protected:
virtual void hash_callback(uint32_t client_param, const std::string& name, const RsFileHash& hash, uint64_t size);
virtual bool hash_confirm(uint32_t client_param) ;
void recursUpdateSharedDir(const std::string& cumulated_path, DirectoryStorage::EntryIndex indx, std::set<std::string>& existing_directories, uint32_t current_depth);
bool sweepSharedDirectories();
void recursUpdateSharedDir(const std::string& cumulated_path, DirectoryStorage::EntryIndex indx, std::set<std::string>& existing_directories, uint32_t current_depth,bool& files_not_ready);
bool sweepSharedDirectories(bool &some_files_not_ready);
private:
bool filterFile(const std::string& fname) const ; // reponds true if the file passes the ignore lists test.

View file

@ -34,16 +34,16 @@ static const uint32_t DELAY_BETWEEN_REMOTE_DIRECTORIES_SWEEP = 60 ; // 60 se
static const uint32_t DELAY_BEFORE_DELETE_NON_EMPTY_REMOTE_DIR = 60*24*86400 ; // delete non empty remoe directories after 60 days of inactivity
static const uint32_t DELAY_BEFORE_DELETE_EMPTY_REMOTE_DIR = 5*24*86400 ; // delete empty remote directories after 5 days of inactivity
static const std::string HASH_CACHE_DURATION_SS = "HASH_CACHE_DURATION" ; // key string to store hash remembering time
static const std::string WATCH_FILE_DURATION_SS = "WATCH_FILES_DELAY" ; // key to store delay before re-checking for new files
static const std::string WATCH_FILE_ENABLED_SS = "WATCH_FILES_ENABLED"; // key to store ON/OFF flags for file whatch
static const std::string FOLLOW_SYMLINKS_SS = "FOLLOW_SYMLINKS"; // dereference symbolic links, or just ignore them.
static const std::string IGNORE_DUPLICATES = "IGNORE_DUPLICATES"; // do not index files that are referenced multiple times because of links
static const std::string WATCH_HASH_SALT_SS = "WATCH_HASH_SALT"; // Salt that is used to hash directory names
static const std::string IGNORED_PREFIXES_SS = "IGNORED_PREFIXES"; // ignore file prefixes
static const std::string IGNORED_SUFFIXES_SS = "IGNORED_SUFFIXES"; // ignore file suffixes
static const std::string IGNORE_LIST_FLAGS_SS = "IGNORED_FLAGS"; // ignore file flags
static const std::string MAX_SHARE_DEPTH = "MAX_SHARE_DEPTH"; // maximum depth of shared directories
static const std::string HASH_CACHE_DURATION_SS = "HASH_CACHE_DURATION" ; // key string to store hash remembering time
static const std::string WATCH_FILE_DURATION_SS = "WATCH_FILES_DELAY" ; // key to store delay before re-checking for new files
static const std::string WATCH_FILE_ENABLED_SS = "WATCH_FILES_ENABLED"; // key to store ON/OFF flags for file whatch
static const std::string FOLLOW_SYMLINKS_SS = "FOLLOW_SYMLINKS"; // dereference symbolic links, or just ignore them.
static const std::string IGNORE_DUPLICATES = "IGNORE_DUPLICATES"; // do not index files that are referenced multiple times because of links
static const std::string WATCH_HASH_SALT_SS = "WATCH_HASH_SALT"; // Salt that is used to hash directory names
static const std::string IGNORED_PREFIXES_SS = "IGNORED_PREFIXES"; // ignore file prefixes
static const std::string IGNORED_SUFFIXES_SS = "IGNORED_SUFFIXES"; // ignore file suffixes
static const std::string IGNORE_LIST_FLAGS_SS = "IGNORED_FLAGS"; // ignore file flags
static const std::string MAX_SHARE_DEPTH = "MAX_SHARE_DEPTH"; // maximum depth of shared directories
static const std::string FILE_SHARING_DIR_NAME = "file_sharing" ; // hard-coded directory name to store friend file lists, hash cache, etc.
static const std::string HASH_CACHE_FILE_NAME = "hash_cache.bin" ; // hard-coded directory name to store encrypted hash cache.
@ -51,6 +51,7 @@ static const std::string LOCAL_SHARED_DIRS_FILE_NAME = "local_dir_hierarchy.bin"
static const uint32_t MIN_INTERVAL_BETWEEN_HASH_CACHE_SAVE = 20 ; // never save hash cache more often than every 20 secs.
static const uint32_t MIN_INTERVAL_BETWEEN_REMOTE_DIRECTORY_SAVE = 23 ; // never save remote directories more often than this
static const uint32_t MIN_TIME_AFTER_LAST_MODIFICATION = 20 ; // never hash a file that is just being modified, otherwise we end up with a corrupted hash
static const uint32_t MAX_DIR_SYNC_RESPONSE_DATA_SIZE = 20000 ; // Maximum RsItem data size in bytes for serialised directory transmission
static const uint32_t DEFAULT_HASH_STORAGE_DURATION_DAYS = 30 ; // remember deleted/inaccessible files for 30 days

View file

@ -1,3 +1,28 @@
/*
* RetroShare C++ File lists IO methods.
*
* file_sharing/file_tree.h
*
* Copyright 2017 by csoler
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare.project@gmail.com".
*
*/
#include "retroshare/rsfiles.h"
class FileTreeImpl: public FileTree

View file

@ -39,6 +39,7 @@
static const uint32_t SOURCE_CHUNK_MAP_UPDATE_PERIOD = 60 ; //! TTL for chunkmap info
static const uint32_t INACTIVE_CHUNK_TIME_LAPSE = 3600 ; //! TTL for an inactive chunk
static const uint32_t FT_CHUNKMAP_MAX_CHUNK_JUMP = 50 ; //! Maximum chunk jump in progressive DL mode
static const uint32_t FT_CHUNKMAP_MAX_SLICE_REASK_DELAY = 10 ; //! Maximum time to re-ask a slice to another peer at end of transfer
std::ostream& operator<<(std::ostream& o,const ftChunk& c)
{
@ -120,7 +121,7 @@ void ChunkMap::setAvailabilityMap(const CompressedChunkMap& map)
}
}
void ChunkMap::dataReceived(const ftChunk::ChunkId& cid)
void ChunkMap::dataReceived(const ftChunk::OffsetInFile& cid)
{
// 1 - find which chunk contains the received data.
//
@ -139,7 +140,7 @@ void ChunkMap::dataReceived(const ftChunk::ChunkId& cid)
return ;
}
std::map<ftChunk::ChunkId,uint32_t>::iterator it(itc->second._slices.find(cid)) ;
std::map<ftChunk::OffsetInFile,ChunkDownloadInfo::SliceRequestInfo>::iterator it(itc->second._slices.find(cid)) ;
if(it == itc->second._slices.end())
{
@ -150,8 +151,8 @@ void ChunkMap::dataReceived(const ftChunk::ChunkId& cid)
return ;
}
_total_downloaded += it->second ;
itc->second._remains -= it->second ;
_total_downloaded += it->second.size ;
itc->second._remains -= it->second.size ;
itc->second._slices.erase(it) ;
itc->second._last_data_received = time(NULL) ; // update time stamp
@ -256,6 +257,38 @@ void ChunkMap::setChunkCheckingResult(uint32_t chunk_number,bool check_succeeded
}
}
bool ChunkMap::reAskPendingChunk( const RsPeerId& peer_id,
uint32_t /*size_hint*/,
uint64_t& offset, uint32_t& size)
{
// make sure that we're at the end of the file. No need to be too greedy in the middle of it.
for(uint32_t i=0;i<_map.size();++i)
if(_map[i] == FileChunksInfo::CHUNK_OUTSTANDING)
return false ;
time_t now = time(NULL);
for(std::map<uint32_t,ChunkDownloadInfo>::iterator it(_slices_to_download.begin());it!=_slices_to_download.end();++it)
for(std::map<ftChunk::OffsetInFile,ChunkDownloadInfo::SliceRequestInfo >::iterator it2(it->second._slices.begin());it2!=it->second._slices.end();++it2)
if(it2->second.request_time + FT_CHUNKMAP_MAX_SLICE_REASK_DELAY < now && it2->second.peers.end()==it2->second.peers.find(peer_id))
{
offset = it2->first;
size = it2->second.size ;
#ifdef DEBUG_FTCHUNK
std::cerr << "*** ChunkMap::reAskPendingChunk: re-asking slice (" << offset << ", " << size << ") to peer " << peer_id << std::endl;
#endif
it2->second.request_time = now ;
it2->second.peers.insert(peer_id) ;
return true ;
}
return false ;
}
// Warning: a chunk may be empty, but still being downloaded, so asking new slices from it
// will produce slices of size 0. This happens at the end of each chunk.
// --> I need to get slices from the next chunk, in such a case.
@ -295,7 +328,7 @@ bool ChunkMap::getDataChunk(const RsPeerId& peer_id,uint32_t size_hint,ftChunk&
ChunkDownloadInfo& cdi(_slices_to_download[c]) ;
falsafe_it = pit ; // let's keep this one just in case.
if(cdi._slices.rbegin() != cdi._slices.rend() && cdi._slices.rbegin()->second*0.7 <= (float)size_hint)
if(cdi._slices.rbegin() != cdi._slices.rend() && cdi._slices.rbegin()->second.size*0.7 <= (float)size_hint)
{
it = pit ;
#ifdef DEBUG_FTCHUNK
@ -348,9 +381,14 @@ bool ChunkMap::getDataChunk(const RsPeerId& peer_id,uint32_t size_hint,ftChunk&
// Get the first slice of the chunk, that is at most of length size
//
it->second.getSlice(size_hint,chunk) ;
_slices_to_download[chunk.offset/_chunk_size]._slices[chunk.id] = chunk.size ;
_slices_to_download[chunk.offset/_chunk_size]._last_data_received = time(NULL) ;
ChunkDownloadInfo::SliceRequestInfo& r(_slices_to_download[chunk.offset/_chunk_size]._slices[chunk.id]);
r.size = chunk.size ;
r.request_time = time(NULL);
r.peers.insert(peer_id);
chunk.peer_id = peer_id ;
#ifdef DEBUG_FTCHUNK
@ -362,7 +400,7 @@ bool ChunkMap::getDataChunk(const RsPeerId& peer_id,uint32_t size_hint,ftChunk&
return true ;
}
void ChunkMap::removeInactiveChunks(std::vector<ftChunk::ChunkId>& to_remove)
void ChunkMap::removeInactiveChunks(std::vector<ftChunk::OffsetInFile>& to_remove)
{
to_remove.clear() ;
time_t now = time(NULL) ;
@ -377,7 +415,7 @@ void ChunkMap::removeInactiveChunks(std::vector<ftChunk::ChunkId>& to_remove)
//
std::map<ChunkNumber,ChunkDownloadInfo>::iterator tmp(it) ;
for(std::map<ftChunk::ChunkId,uint32_t>::const_iterator it2(it->second._slices.begin());it2!=it->second._slices.end();++it2)
for(std::map<ftChunk::OffsetInFile,ChunkDownloadInfo::SliceRequestInfo>::const_iterator it2(it->second._slices.begin());it2!=it->second._slices.end();++it2)
to_remove.push_back(it2->first) ;
_map[it->first] = FileChunksInfo::CHUNK_OUTSTANDING ; // reset the chunk

View file

@ -32,7 +32,7 @@ class ftController ;
class ftChunk
{
public:
typedef uint64_t ChunkId ;
typedef uint64_t OffsetInFile ;
ftChunk():offset(0), size(0), id(0), ts(0),ref_cnt(NULL) {}
@ -40,7 +40,7 @@ class ftChunk
uint64_t offset; // current offset of the slice
uint64_t size; // size remaining to download
ChunkId id ; // id of the chunk. Equal to the starting offset of the chunk
OffsetInFile id ; // id of the chunk. Equal to the starting offset of the chunk
time_t ts; // time of last data received
int *ref_cnt; // shared counter of number of sub-blocks. Used when a slice gets split.
RsPeerId peer_id ;
@ -70,10 +70,17 @@ class Chunk
uint64_t _end ; // const
};
class ChunkDownloadInfo
struct ChunkDownloadInfo
{
public:
std::map<ftChunk::ChunkId,uint32_t> _slices ;
struct SliceRequestInfo
{
uint32_t size ; // size of the slice
time_t request_time ; // last request time
std::set<RsPeerId> peers ; // peers the slice was requested to. Normally only one, except at the end of the file.
};
std::map<ftChunk::OffsetInFile,SliceRequestInfo> _slices ;
uint32_t _remains ;
time_t _last_data_received ;
};
@ -109,24 +116,29 @@ class ChunkMap
/// destructor
virtual ~ChunkMap() {}
/// Returns an slice of data to be asked to the peer within a chunk.
/// Returns an slice of data to be asked to the peer within a chunk.
/// If a chunk is already been downloaded by this peer, take a slice at
/// the beginning of this chunk, or at least where it starts.
/// If not, randomly/streamly select a new chunk depending on the strategy.
/// adds an entry in the chunk_ids map, and sets up 1 interval for it.
/// the chunk should be available from the designated peer.
/// If not, randomly/streamly select a new chunk depending on the strategy.
/// adds an entry in the chunk_ids map, and sets up 1 interval for it.
/// the chunk should be available from the designated peer.
/// On return:
/// - source_chunk_map_needed = true if the source map should be asked
virtual bool getDataChunk(const RsPeerId& peer_id,uint32_t size_hint,ftChunk& chunk,bool& source_chunk_map_needed) ;
/// Notify received a slice of data. This needs to
/// - carve in the map of chunks what is received, what is not.
/// - tell which chunks are finished. For this, each interval must know what chunk number it has been attributed
/// when the interval is split in the middle, the number of intervals for the chunk is increased. If the interval is
/// completely covered by the data, the interval number is decreased.
/// Returns an already pending slice that was being downloaded but hasn't arrived yet. This is mostly used at the end of the file
/// in order to re-ask pendign slices to active peers while slow peers take a lot of time to send their remaining slices.
///
bool reAskPendingChunk(const RsPeerId& peer_id,uint32_t size_hint,uint64_t& offset,uint32_t& size);
virtual void dataReceived(const ftChunk::ChunkId& c_id) ;
/// Notify received a slice of data. This needs to
/// - carve in the map of chunks what is received, what is not.
/// - tell which chunks are finished. For this, each interval must know what chunk number it has been attributed
/// when the interval is split in the middle, the number of intervals for the chunk is increased. If the interval is
/// completely covered by the data, the interval number is decreased.
virtual void dataReceived(const ftChunk::OffsetInFile& c_id) ;
/// Decides how chunks are selected.
/// STREAMING: the 1st chunk is always returned
@ -163,7 +175,7 @@ class ChunkMap
/// Remove active chunks that have not received any data for the last 60 seconds, and return
/// the list of slice numbers that should be canceled.
void removeInactiveChunks(std::vector<ftChunk::ChunkId>& to_remove) ;
void removeInactiveChunks(std::vector<ftChunk::OffsetInFile>& to_remove) ;
/// Updates the peer's availablility map
//
@ -214,7 +226,7 @@ class ChunkMap
uint32_t _chunk_size ; //! Size of chunks. Common to all chunks.
FileChunksInfo::ChunkStrategy _strategy ; //! how do we allocate new chunks
std::map<RsPeerId,Chunk> _active_chunks_feed ; //! vector of chunks being downloaded. Exactly 1 chunk per peer.
std::map<ChunkNumber,ChunkDownloadInfo> _slices_to_download ; //! list of (slice id,slice size)
std::map<ChunkNumber,ChunkDownloadInfo> _slices_to_download ; //! list of (slice offset,slice size) currently being downloaded
std::vector<FileChunksInfo::ChunkState> _map ; //! vector of chunk state over the whole file
std::map<RsPeerId,SourceChunksInfo> _peers_chunks_availability ; //! what does each source peer have
uint64_t _total_downloaded ; //! completion for the file

View file

@ -88,16 +88,13 @@ ftFileControl::ftFileControl()
return;
}
ftFileControl::ftFileControl(std::string fname,
std::string tmppath, std::string dest,
uint64_t size, const RsFileHash &hash, TransferRequestFlags flags,
ftFileCreator *fc, ftTransferModule *tm)
:mName(fname), mCurrentPath(tmppath), mDestination(dest),
mTransfer(tm), mCreator(fc), mState(DOWNLOADING), mHash(hash),
mSize(size), mFlags(flags), mCreateTime(0), mQueuePriority(0), mQueuePosition(0)
{
return;
}
ftFileControl::ftFileControl(const std::string& fname, const std::string& tmppath, const std::string& dest
, uint64_t size, const RsFileHash &hash, TransferRequestFlags flags
, ftFileCreator *fc, ftTransferModule *tm)
: mName(fname), mCurrentPath(tmppath), mDestination(dest)
, mTransfer(tm), mCreator(fc), mState(DOWNLOADING), mHash(hash)
, mSize(size), mFlags(flags), mCreateTime(0), mQueuePriority(0), mQueuePosition(0)
{}
ftController::ftController(ftDataMultiplex *dm, p3ServiceControl *sc, uint32_t ftServiceId)
: p3Config(),
@ -1475,24 +1472,24 @@ bool ftController::setPartialsDirectory(std::string path)
/* check it is not a subdir of download / shared directories (BAD) - TODO */
{
RsStackMutex stack(ctrlMutex);
RsStackMutex stack(ctrlMutex);
path = RsDirUtil::convertPathToUnix(path);
path = RsDirUtil::convertPathToUnix(path);
if (!path.find(mDownloadPath)) {
return false;
}
if (path.find(mDownloadPath) != std::string::npos) {
return false;
}
if (rsFiles) {
std::list<SharedDirInfo>::iterator it;
std::list<SharedDirInfo> dirs;
rsFiles->getSharedDirectories(dirs);
for (it = dirs.begin(); it != dirs.end(); ++it) {
if (!path.find((*it).filename)) {
return false;
}
}
}
if (rsFiles) {
std::list<SharedDirInfo>::iterator it;
std::list<SharedDirInfo> dirs;
rsFiles->getSharedDirectories(dirs);
for (it = dirs.begin(); it != dirs.end(); ++it) {
if (path.find((*it).filename) != std::string::npos) {
return false;
}
}
}
}
/* check if it exists */

View file

@ -73,9 +73,9 @@ class ftFileControl
};
ftFileControl();
ftFileControl(std::string fname, std::string tmppath, std::string dest,
uint64_t size, const RsFileHash& hash, TransferRequestFlags flags,
ftFileCreator *fc, ftTransferModule *tm);
ftFileControl( const std::string& fname, const std::string& tmppath, const std::string& dest
, uint64_t size, const RsFileHash& hash, TransferRequestFlags flags
, ftFileCreator *fc, ftTransferModule *tm);
std::string mName;
std::string mCurrentPath; /* current full path (including name) */
@ -175,8 +175,8 @@ class ftController: public RsTickingThread, public pqiServiceMonitor, public p3C
void FileDownloads(std::list<RsFileHash> &hashs);
/* Directory Handling */
bool setDownloadDirectory(std::string path);
bool setPartialsDirectory(std::string path);
bool setDownloadDirectory(std::string path);
bool setPartialsDirectory(std::string path);
std::string getDownloadDirectory();
std::string getPartialsDirectory();
bool FileDetails(const RsFileHash &hash, FileInfo &info);

View file

@ -240,7 +240,7 @@ void ftFileCreator::removeInactiveChunks()
#ifdef FILE_DEBUG
std::cerr << "ftFileCreator::removeInactiveChunks(): looking for old chunks." << std::endl ;
#endif
std::vector<ftChunk::ChunkId> to_remove ;
std::vector<ftChunk::OffsetInFile> to_remove ;
chunkMap.removeInactiveChunks(to_remove) ;
@ -421,7 +421,9 @@ int ftFileCreator::locked_notifyReceived(uint64_t offset, uint32_t chunk_size)
if(!found)
{
#ifdef FILE_DEBUG
std::cerr << "ftFileCreator::locked_notifyReceived(): failed to find an active slice for " << offset << "+" << chunk_size << ", hash = " << hash << ": dropping data." << std::endl;
#endif
return 0; /* ignoring */
}
}
@ -531,7 +533,14 @@ bool ftFileCreator::getMissingChunk(const RsPeerId& peer_id,uint32_t size_hint,u
ftChunk chunk ;
if(!chunkMap.getDataChunk(peer_id,size_hint,chunk,source_chunk_map_needed))
{
// No chunks are available. We brutally re-ask an ongoing chunk to another peer.
if(chunkMap.reAskPendingChunk(peer_id,size_hint,offset,size))
return true ;
return false ;
}
#ifdef FILE_DEBUG
std::cerr << "ffc::getMissingChunk() Retrieved new chunk: " << chunk << std::endl ;

View file

@ -23,35 +23,40 @@
*
*/
#include <iostream>
#include <time.h>
#include "util/rsdebug.h"
#include "util/rsdir.h"
#include "util/rsprint.h"
#include "crypto/chacha20.h"
#include "retroshare/rstypes.h"
#include "retroshare/rspeers.h"
//const int ftserverzone = 29539;
#include "file_sharing/p3filelists.h"
#include "ft/ftturtlefiletransferitem.h"
#include "ft/ftserver.h"
#include "ft/ftextralist.h"
#include "ft/ftfilesearch.h"
#include "ft/ftcontroller.h"
#include "ft/ftfileprovider.h"
#include "ft/ftdatamultiplex.h"
//#include "ft/ftdwlqueue.h"
#include "turtle/p3turtle.h"
#include "pqi/p3notify.h"
#include "rsserver/p3face.h"
#include "ft/ftextralist.h"
#include "ft/ftfileprovider.h"
#include "ft/ftfilesearch.h"
#include "ft/ftserver.h"
#include "ft/ftturtlefiletransferitem.h"
#include "pqi/pqi.h"
#include "pqi/p3linkmgr.h"
#include "pqi/p3notify.h"
#include "pqi/pqi.h"
#include "retroshare/rstypes.h"
#include "retroshare/rspeers.h"
#include "rsitems/rsfiletransferitems.h"
#include "rsitems/rsserviceids.h"
#include "rsserver/p3face.h"
#include "rsserver/rsaccounts.h"
#include "turtle/p3turtle.h"
#include "util/rsdebug.h"
#include "util/rsdir.h"
#include "util/rsprint.h"
#include <iostream>
#include <time.h>
/***
* #define SERVER_DEBUG 1
* #define SERVER_DEBUG_CACHE 1
@ -145,9 +150,19 @@ void ftServer::SetupFtServer()
/* make Controller */
mFtController = new ftController(mFtDataplex, mServiceCtrl, getServiceInfo().mServiceType);
mFtController -> setFtSearchNExtra(mFtSearch, mFtExtra);
std::string tmppath = ".";
mFtController->setPartialsDirectory(tmppath);
mFtController->setDownloadDirectory(tmppath);
std::string emergencySaveDir = rsAccounts->PathAccountDirectory();
std::string emergencyPartialsDir = rsAccounts->PathAccountDirectory();
if (emergencySaveDir != "")
{
emergencySaveDir += "/";
emergencyPartialsDir += "/";
}
emergencySaveDir += "Downloads";
emergencyPartialsDir += "Partials";
mFtController->setDownloadDirectory(emergencySaveDir);
mFtController->setPartialsDirectory(emergencyPartialsDir);
/* complete search setup */
mFtSearch->addSearchMode(mFtExtra, RS_FILE_HINTS_EXTRA);
@ -412,9 +427,9 @@ void ftServer::requestDirUpdate(void *ref)
}
/* Directory Handling */
void ftServer::setDownloadDirectory(std::string path)
bool ftServer::setDownloadDirectory(std::string path)
{
mFtController->setDownloadDirectory(path);
return mFtController->setDownloadDirectory(path);
}
std::string ftServer::getDownloadDirectory()
@ -422,9 +437,9 @@ std::string ftServer::getDownloadDirectory()
return mFtController->getDownloadDirectory();
}
void ftServer::setPartialsDirectory(std::string path)
bool ftServer::setPartialsDirectory(std::string path)
{
mFtController->setPartialsDirectory(path);
return mFtController->setPartialsDirectory(path);
}
std::string ftServer::getPartialsDirectory()

View file

@ -202,8 +202,8 @@ public:
* Directory Handling
***/
virtual void requestDirUpdate(void *ref) ; // triggers the update of the given reference. Used when browsing.
virtual void setDownloadDirectory(std::string path);
virtual void setPartialsDirectory(std::string path);
virtual bool setDownloadDirectory(std::string path);
virtual bool setPartialsDirectory(std::string path);
virtual std::string getDownloadDirectory();
virtual std::string getPartialsDirectory();

View file

@ -34,7 +34,7 @@
#include <stdlib.h>
#include <grouter/grouteritems.h>
class RsItem ;
struct RsItem;
static const uint32_t GROUTER_CLIENT_SERVICE_DATA_STATUS_UNKNOWN = 0x0000 ; // unused.
static const uint32_t GROUTER_CLIENT_SERVICE_DATA_STATUS_RECEIVED = 0x0001 ; // sent when data has been received and a receipt is available.

View file

@ -31,7 +31,7 @@
#include "retroshare/rsgrouter.h"
#include "groutertypes.h"
class RsItem ;
struct RsItem;
// The routing matrix records the event clues received from each friend
//

View file

@ -540,7 +540,7 @@ if(itm == NULL)
void GRouterTunnelInfo::removeVirtualPeer(const TurtleVirtualPeerId& vpid)
{
std::set<TurtleVirtualPeerId,RsGRouterTransactionChunkItem*>::iterator it = virtual_peers.find(vpid) ;
std::set<TurtleVirtualPeerId>::iterator it = virtual_peers.find(vpid) ;
if(it == virtual_peers.end())
{

View file

@ -952,6 +952,8 @@ void RsDataService::locked_updateGrpMetaCache(const RsGxsGrpMetaData& meta)
if(it != mGrpMetaDataCache.end())
*(it->second) = meta ;
else
mGrpMetaDataCache[meta.mGroupId] = new RsGxsGrpMetaData(meta) ;
}
void RsDataService::locked_clearGrpMetaCache(const RsGxsGroupId& gid)
@ -1215,7 +1217,7 @@ int RsDataService::retrieveNxsMsgs(const GxsMsgReq &reqIds, GxsMsgResult &msg, b
const RsGxsGroupId& grpId = mit->first;
// if vector empty then request all messages
const std::vector<RsGxsMessageId>& msgIdV = mit->second;
const std::set<RsGxsMessageId>& msgIdV = mit->second;
std::vector<RsNxsMsg*> msgSet;
if(msgIdV.empty()){
@ -1233,7 +1235,7 @@ int RsDataService::retrieveNxsMsgs(const GxsMsgReq &reqIds, GxsMsgResult &msg, b
}else{
// request each grp
std::vector<RsGxsMessageId>::const_iterator sit = msgIdV.begin();
std::set<RsGxsMessageId>::const_iterator sit = msgIdV.begin();
for(; sit!=msgIdV.end();++sit){
const RsGxsMessageId& msgId = *sit;
@ -1303,7 +1305,7 @@ int RsDataService::retrieveGxsMsgMetaData(const GxsMsgReq& reqIds, GxsMsgMetaRes
const RsGxsGroupId& grpId = mit->first;
// if vector empty then request all messages
const std::vector<RsGxsMessageId>& msgIdV = mit->second;
const std::set<RsGxsMessageId>& msgIdV = mit->second;
std::vector<RsGxsMsgMetaData*> metaSet;
if(msgIdV.empty()){
@ -1319,7 +1321,7 @@ int RsDataService::retrieveGxsMsgMetaData(const GxsMsgReq& reqIds, GxsMsgMetaRes
}else{
// request each grp
std::vector<RsGxsMessageId>::const_iterator sit = msgIdV.begin();
std::set<RsGxsMessageId>::const_iterator sit = msgIdV.begin();
for(; sit!=msgIdV.end(); ++sit){
const RsGxsMessageId& msgId = *sit;
@ -1559,7 +1561,7 @@ int RsDataService::removeMsgs(const GxsMsgReq& msgIds)
for(; mit != msgIds.end(); ++mit)
{
const std::vector<RsGxsMessageId>& msgIdV = mit->second;
const std::set<RsGxsMessageId>& msgIdV = mit->second;
const RsGxsGroupId& grpId = mit->first;
// delete messages
@ -1620,7 +1622,7 @@ int RsDataService::retrieveGroupIds(std::vector<RsGxsGroupId> &grpIds)
return 1;
}
int RsDataService::retrieveMsgIds(const RsGxsGroupId& grpId, RsGxsMessageId::std_vector& msgIds)
int RsDataService::retrieveMsgIds(const RsGxsGroupId& grpId, RsGxsMessageId::std_set& msgIds)
{
#ifdef RS_DATA_SERVICE_DEBUG_TIME
rstime::RsScopeTimer timer("");
@ -1641,7 +1643,7 @@ int RsDataService::retrieveMsgIds(const RsGxsGroupId& grpId, RsGxsMessageId::std
if(c->columnCount() != 1)
std::cerr << "(EE) ********* not retrieving all columns!!" << std::endl;
msgIds.push_back(RsGxsMessageId(msgId));
msgIds.insert(RsGxsMessageId(msgId));
valid = c->moveToNext();
#ifdef RS_DATA_SERVICE_DEBUG_TIME
@ -1672,8 +1674,8 @@ bool RsDataService::locked_removeMessageEntries(const GxsMsgReq& msgIds)
for(; mit != msgIds.end(); ++mit)
{
const RsGxsGroupId& grpId = mit->first;
const std::vector<RsGxsMessageId>& msgsV = mit->second;
std::vector<RsGxsMessageId>::const_iterator vit = msgsV.begin();
const std::set<RsGxsMessageId>& msgsV = mit->second;
std::set<RsGxsMessageId>::const_iterator vit = msgsV.begin();
for(; vit != msgsV.end(); ++vit)
{

View file

@ -110,7 +110,7 @@ public:
* @param msgId msgsids retrieved
* @return error code
*/
int retrieveMsgIds(const RsGxsGroupId& grpId, RsGxsMessageId::std_vector& msgId);
int retrieveMsgIds(const RsGxsGroupId& grpId, RsGxsMessageId::std_set& msgId);
/*!
* @return the cache size set for this RsGeneralDataService in bytes

View file

@ -208,7 +208,7 @@ public:
* @param msgId msgsids retrieved
* @return error code
*/
virtual int retrieveMsgIds(const RsGxsGroupId& grpId, RsGxsMessageId::std_vector& msgId) = 0;
virtual int retrieveMsgIds(const RsGxsGroupId& grpId, RsGxsMessageId::std_set& msgId) = 0;
/*!
* @return the cache size set for this RsGeneralDataService in bytes

View file

@ -217,7 +217,7 @@ void RsGenExchange::tick()
RS_STACK_MUTEX(mGenMtx) ;
std::list<RsGxsGroupId> grpIds;
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > msgIds;
std::map<RsGxsGroupId, std::set<RsGxsMessageId> > msgIds;
mIntegrityCheck->getDeletedIds(grpIds, msgIds);
if (!grpIds.empty())
@ -1078,23 +1078,19 @@ bool RsGenExchange::checkAuthenFlag(const PrivacyBitPos& pos, const uint8_t& fla
}
}
static void addMessageChanged(std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &msgs, const std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &msgChanged)
static void addMessageChanged(std::map<RsGxsGroupId, std::set<RsGxsMessageId> > &msgs, const std::map<RsGxsGroupId, std::set<RsGxsMessageId> > &msgChanged)
{
if (msgs.empty()) {
msgs = msgChanged;
} else {
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> >::const_iterator mapIt;
for (mapIt = msgChanged.begin(); mapIt != msgChanged.end(); ++mapIt) {
for (auto mapIt = msgChanged.begin(); mapIt != msgChanged.end(); ++mapIt)
{
const RsGxsGroupId &grpId = mapIt->first;
const std::vector<RsGxsMessageId> &srcMsgIds = mapIt->second;
std::vector<RsGxsMessageId> &destMsgIds = msgs[grpId];
const std::set<RsGxsMessageId> &srcMsgIds = mapIt->second;
std::set<RsGxsMessageId> &destMsgIds = msgs[grpId];
std::vector<RsGxsMessageId>::const_iterator msgIt;
for (msgIt = srcMsgIds.begin(); msgIt != srcMsgIds.end(); ++msgIt) {
if (std::find(destMsgIds.begin(), destMsgIds.end(), *msgIt) == destMsgIds.end()) {
destMsgIds.push_back(*msgIt);
}
}
for (auto msgIt = srcMsgIds.begin(); msgIt != srcMsgIds.end(); ++msgIt)
destMsgIds.insert(*msgIt) ;
}
}
}
@ -1789,8 +1785,8 @@ void RsGenExchange::deleteMsgs(uint32_t& token, const GxsMsgReq& msgs)
if(mNetService != NULL)
for(GxsMsgReq::const_iterator it(msgs.begin());it!=msgs.end();++it)
for(uint32_t i=0;i<it->second.size();++i)
mNetService->rejectMessage(it->second[i]) ;
for(auto it2(it->second.begin());it2!=it->second.end();++it2)
mNetService->rejectMessage(*it2);
}
void RsGenExchange::publishMsg(uint32_t& token, RsGxsMsgItem *msgItem)
@ -1961,8 +1957,8 @@ void RsGenExchange::processMsgMetaChanges()
if(m.val.getAsInt32(RsGeneralDataService::MSG_META_STATUS+GXS_MASK, mask))
{
GxsMsgReq req;
std::vector<RsGxsMessageId> msgIdV;
msgIdV.push_back(m.msgId.second);
std::set<RsGxsMessageId> msgIdV;
msgIdV.insert(m.msgId.second);
req.insert(std::make_pair(m.msgId.first, msgIdV));
GxsMsgMetaResult result;
mDataStore->retrieveGxsMsgMetaData(req, result);
@ -1994,7 +1990,7 @@ void RsGenExchange::processMsgMetaChanges()
mDataAccess->updatePublicRequestStatus(token, RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE);
if (changed)
{
msgIds[m.msgId.first].push_back(m.msgId.second);
msgIds[m.msgId.first].insert(m.msgId.second);
}
}
else
@ -2010,7 +2006,7 @@ void RsGenExchange::processMsgMetaChanges()
if (!msgIds.empty()) {
RS_STACK_MUTEX(mGenMtx);
RsGxsMsgChange* c = new RsGxsMsgChange(RsGxsNotify::TYPE_PROCESSED, true);
RsGxsMsgChange* c = new RsGxsMsgChange(RsGxsNotify::TYPE_PROCESSED, false);
c->msgChangeMap = msgIds;
mNotifications.push_back(c);
}
@ -2145,7 +2141,7 @@ void RsGenExchange::publishMsgs()
mMsgsToPublish.insert(std::make_pair(sign_it->first, item.mItem));
}
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > msgChangeMap;
std::map<RsGxsGroupId, std::set<RsGxsMessageId> > msgChangeMap;
std::map<uint32_t, RsGxsMsgItem*>::iterator mit = mMsgsToPublish.begin();
for(; mit != mMsgsToPublish.end(); ++mit)
@ -2273,7 +2269,7 @@ void RsGenExchange::publishMsgs()
mDataAccess->addMsgData(msg);
delete msg ;
msgChangeMap[grpId].push_back(msgId);
msgChangeMap[grpId].insert(msgId);
delete[] metaDataBuff;
@ -2860,8 +2856,10 @@ void RsGenExchange::processRecvdMessages()
time_t now = time(NULL);
if(mMsgPendingValidate.empty())
return ;
#ifdef GEN_EXCH_DEBUG
if(!mMsgPendingValidate.empty())
else
std::cerr << "processing received messages" << std::endl;
#endif
// 1 - First, make sure items metadata is deserialised, clean old failed items, and collect the groups Ids we have to check
@ -2904,9 +2902,11 @@ void RsGenExchange::processRecvdMessages()
}
}
// 2 - Retrieve the metadata for the associated groups.
// 2 - Retrieve the metadata for the associated groups. The test is here to avoid the default behavior to
// retrieve all groups when the list is empty
mDataStore->retrieveGxsGrpMetaData(grpMetas);
if(!grpMetas.empty())
mDataStore->retrieveGxsGrpMetaData(grpMetas);
GxsMsgReq msgIds;
RsNxsMsgDataTemporaryList msgs_to_store;
@ -2934,7 +2934,7 @@ void RsGenExchange::processRecvdMessages()
// }
#ifdef GEN_EXCH_DEBUG
std::cerr << " deserialised info: grp id=" << meta->mGroupId << ", msg id=" << meta->mMsgId ;
std::cerr << " deserialised info: grp id=" << msg->grpId << ", msg id=" << msg->msgId ;
#endif
std::map<RsGxsGroupId, RsGxsGrpMetaData*>::iterator mit = grpMetas.find(msg->grpId);
@ -2968,17 +2968,17 @@ void RsGenExchange::processRecvdMessages()
msg->metaData->mMsgStatus = GXS_SERV::GXS_MSG_STATUS_UNPROCESSED | GXS_SERV::GXS_MSG_STATUS_GUI_NEW | GXS_SERV::GXS_MSG_STATUS_GUI_UNREAD;
msgs_to_store.push_back(msg);
std::vector<RsGxsMessageId> &msgv = msgIds[msg->grpId];
if (std::find(msgv.begin(), msgv.end(), msg->msgId) == msgv.end())
msgv.push_back(msg->msgId);
msgIds[msg->grpId].insert(msg->msgId);
// std::vector<RsGxsMessageId> &msgv = msgIds[msg->grpId];
// if (std::find(msgv.begin(), msgv.end(), msg->msgId) == msgv.end())
// msgv.push_back(msg->msgId);
computeHash(msg->msg, msg->metaData->mHash);
msg->metaData->recvTS = time(NULL);
#ifdef GEN_EXCH_DEBUG
std::cerr << " new status flags: " << meta->mMsgStatus << std::endl;
std::cerr << " computed hash: " << meta->mHash << std::endl;
std::cerr << " new status flags: " << msg->metaData->mMsgStatus << std::endl;
std::cerr << " computed hash: " << msg->metaData->mHash << std::endl;
std::cerr << "Message received. Identity=" << msg->metaData->mAuthorId << ", from peer " << msg->PeerId() << std::endl;
#endif
@ -3062,9 +3062,6 @@ void RsGenExchange::processRecvdGroups()
GxsPendingItem<RsNxsGrp*, RsGxsGroupId>& gpsi = vit->second;
RsNxsGrp* grp = gpsi.mItem;
#ifdef GEN_EXCH_DEBUG
std::cerr << " processing validation for group " << meta->mGroupId << ", original attempt time: " << time(NULL) - gpsi.mFirstTryTS << " seconds ago" << std::endl;
#endif
if(grp->metaData == NULL)
{
RsGxsGrpMetaData* meta = new RsGxsGrpMetaData();
@ -3074,6 +3071,9 @@ void RsGenExchange::processRecvdGroups()
else
delete meta ;
}
#ifdef GEN_EXCH_DEBUG
std::cerr << " processing validation for group " << grp->metaData->mGroupId << ", original attempt time: " << time(NULL) - gpsi.mFirstTryTS << " seconds ago" << std::endl;
#endif
// early deletion of group from the pending list if it's malformed, not accepted, or has been tried unsuccessfully for too long
@ -3102,7 +3102,7 @@ void RsGenExchange::processRecvdGroups()
if(!grp->metaData->mAuthorId.isNull())
{
#ifdef GEN_EXCH_DEBUG
std::cerr << "Group routage info: Identity=" << meta->mAuthorId << " from " << grp->PeerId() << std::endl;
std::cerr << "Group routage info: Identity=" << grp->metaData->mAuthorId << " from " << grp->PeerId() << std::endl;
#endif
mRoutingClues[grp->metaData->mAuthorId].insert(grp->PeerId()) ;
}
@ -3326,7 +3326,7 @@ void RsGenExchange::removeDeleteExistingMessages( std::list<RsNxsMsg*>& msgs, Gx
//RsGxsGroupId::std_list grpIds(mGrpIdsUnique.begin(), mGrpIdsUnique.end());
//RsGxsGroupId::std_list::const_iterator it = grpIds.begin();
typedef std::map<RsGxsGroupId, RsGxsMessageId::std_vector> MsgIdReq;
typedef std::map<RsGxsGroupId, RsGxsMessageId::std_set> MsgIdReq;
MsgIdReq msgIdReq;
// now get a list of all msgs ids for each group
@ -3346,20 +3346,21 @@ void RsGenExchange::removeDeleteExistingMessages( std::list<RsNxsMsg*>& msgs, Gx
// now for each msg to be stored that exist in the retrieved msg/grp "index" delete and erase from map
for(std::list<RsNxsMsg*>::iterator cit2 = msgs.begin(); cit2 != msgs.end();)
{
const RsGxsMessageId::std_vector& msgIds = msgIdReq[(*cit2)->metaData->mGroupId];
const RsGxsMessageId::std_set& msgIds = msgIdReq[(*cit2)->metaData->mGroupId];
#ifdef GEN_EXCH_DEBUG
std::cerr << " grpid=" << cit2->second->mGroupId << ", msgid=" << cit2->second->mMsgId ;
std::cerr << " grpid=" << (*cit2)->grpId << ", msgid=" << (*cit2)->msgId ;
#endif
// Avoid storing messages that are already in the database, as well as messages that are too old (or generally do not pass the database storage test)
//
if(std::find(msgIds.begin(), msgIds.end(), (*cit2)->metaData->mMsgId) != msgIds.end() || !messagePublicationTest( *(*cit2)->metaData))
if(msgIds.find((*cit2)->metaData->mMsgId) != msgIds.end() || !messagePublicationTest( *(*cit2)->metaData))
{
// msg exist in retrieved index. We should use a std::set here instead of a vector.
RsGxsMessageId::std_vector& notifyIds = msgIdsNotify[ (*cit2)->metaData->mGroupId];
RsGxsMessageId::std_vector::iterator it2 = std::find(notifyIds.begin(), notifyIds.end(), (*cit2)->metaData->mMsgId);
RsGxsMessageId::std_set& notifyIds = msgIdsNotify[ (*cit2)->metaData->mGroupId];
RsGxsMessageId::std_set::iterator it2 = notifyIds.find((*cit2)->metaData->mMsgId);
if(it2 != notifyIds.end())
{
notifyIds.erase(it2);
@ -3369,7 +3370,7 @@ void RsGenExchange::removeDeleteExistingMessages( std::list<RsNxsMsg*>& msgs, Gx
}
}
#ifdef GEN_EXCH_DEBUG
std::cerr << " discarding " << cit2->second->mMsgId << std::endl;
std::cerr << " discarding " << (*cit2)->msgId << std::endl;
#endif
delete *cit2;

View file

@ -225,7 +225,7 @@ bool RsGxsDataAccess::requestMsgInfo(uint32_t &token, uint32_t ansType,
MsgMetaReq* mmr = new MsgMetaReq();
for(; lit != grpIds.end(); ++lit)
mmr->mMsgIds[*lit] = std::vector<RsGxsMessageId>();
mmr->mMsgIds[*lit] = std::set<RsGxsMessageId>();
req = mmr;
}else if(reqType & GXS_REQUEST_TYPE_MSG_DATA)
@ -233,7 +233,7 @@ bool RsGxsDataAccess::requestMsgInfo(uint32_t &token, uint32_t ansType,
MsgDataReq* mdr = new MsgDataReq();
for(; lit != grpIds.end(); ++lit)
mdr->mMsgIds[*lit] = std::vector<RsGxsMessageId>();
mdr->mMsgIds[*lit] = std::set<RsGxsMessageId>();
req = mdr;
}else if(reqType & GXS_REQUEST_TYPE_MSG_IDS)
@ -241,7 +241,7 @@ bool RsGxsDataAccess::requestMsgInfo(uint32_t &token, uint32_t ansType,
MsgIdReq* mir = new MsgIdReq();
for(; lit != grpIds.end(); ++lit)
mir->mMsgIds[*lit] = std::vector<RsGxsMessageId>();
mir->mMsgIds[*lit] = std::set<RsGxsMessageId>();
req = mir;
}
@ -1191,7 +1191,7 @@ bool RsGxsDataAccess::getMsgList(const GxsMsgReq& msgIds, const RsTokReqOptions&
// Add the discovered Latest Msgs.
for(oit = origMsgTs.begin(); oit != origMsgTs.end(); ++oit)
{
msgIdsOut[grpId].push_back(oit->second.first);
msgIdsOut[grpId].insert(oit->second.first);
}
}
@ -1228,7 +1228,7 @@ bool RsGxsDataAccess::getMsgList(const GxsMsgReq& msgIds, const RsTokReqOptions&
if (add)
{
msgIdsOut[grpId].push_back(msgMeta->mMsgId);
msgIdsOut[grpId].insert(msgMeta->mMsgId);
metaFilter[grpId].insert(std::make_pair(msgMeta->mMsgId, msgMeta));
}
@ -1373,7 +1373,7 @@ bool RsGxsDataAccess::getMsgRelatedInfo(MsgRelatedInfoReq *req)
// get meta data for all in group
GxsMsgMetaResult result;
GxsMsgReq msgIds;
msgIds.insert(std::make_pair(grpMsgIdPair.first, std::vector<RsGxsMessageId>()));
msgIds.insert(std::make_pair(grpMsgIdPair.first, std::set<RsGxsMessageId>()));
mDataStore->retrieveGxsMsgMetaData(msgIds, result);
std::vector<RsGxsMsgMetaData*>& metaV = result[grpMsgIdPair.first];
std::vector<RsGxsMsgMetaData*>::iterator vit_meta;
@ -1382,7 +1382,7 @@ bool RsGxsDataAccess::getMsgRelatedInfo(MsgRelatedInfoReq *req)
const RsGxsMessageId& msgId = grpMsgIdPair.second;
const RsGxsGroupId& grpId = grpMsgIdPair.first;
std::vector<RsGxsMessageId> outMsgIds;
std::set<RsGxsMessageId> outMsgIds;
RsGxsMsgMetaData* origMeta = NULL;
for(vit_meta = metaV.begin(); vit_meta != metaV.end(); ++vit_meta)
@ -1477,7 +1477,7 @@ bool RsGxsDataAccess::getMsgRelatedInfo(MsgRelatedInfoReq *req)
// Add the discovered Latest Msgs.
for(oit = origMsgTs.begin(); oit != origMsgTs.end(); ++oit)
{
outMsgIds.push_back(oit->second.first);
outMsgIds.insert(oit->second.first);
}
}
else
@ -1502,7 +1502,7 @@ bool RsGxsDataAccess::getMsgRelatedInfo(MsgRelatedInfoReq *req)
}
}
}
outMsgIds.push_back(latestMsgId);
outMsgIds.insert(latestMsgId);
metaMap.insert(std::make_pair(latestMsgId, latestMeta));
}
}
@ -1514,7 +1514,7 @@ bool RsGxsDataAccess::getMsgRelatedInfo(MsgRelatedInfoReq *req)
if (meta->mOrigMsgId == origMsgId)
{
outMsgIds.push_back(meta->mMsgId);
outMsgIds.insert(meta->mMsgId);
metaMap.insert(std::make_pair(meta->mMsgId, meta));
}
}
@ -1556,7 +1556,7 @@ bool RsGxsDataAccess::getGroupStatistic(GroupStatisticRequest *req)
{
// filter based on options
GxsMsgIdResult metaReq;
metaReq[req->mGrpId] = std::vector<RsGxsMessageId>();
metaReq[req->mGrpId] = std::set<RsGxsMessageId>();
GxsMsgMetaResult metaResult;
mDataStore->retrieveGxsMsgMetaData(metaReq, metaResult);
@ -1672,7 +1672,7 @@ bool RsGxsDataAccess::getMsgList(MsgIdReq* req)
for(; vit != vit_end; ++vit)
{
RsGxsMsgMetaData* meta = *vit;
req->mMsgIdResult[grpId].push_back(meta->mMsgId);
req->mMsgIdResult[grpId].insert(meta->mMsgId);
delete meta; // discard meta data mem
}
}
@ -1718,8 +1718,8 @@ void RsGxsDataAccess::filterMsgList(GxsMsgIdResult& msgIds, const RsTokReqOption
if(cit == msgMetas.end())
continue;
std::vector<RsGxsMessageId>& msgs = mit->second;
std::vector<RsGxsMessageId>::iterator vit = msgs.begin();
std::set<RsGxsMessageId>& msgs = mit->second;
std::set<RsGxsMessageId>::iterator vit = msgs.begin();
const std::map<RsGxsMessageId, RsGxsMsgMetaData*>& meta = cit->second;
std::map<RsGxsMessageId, RsGxsMsgMetaData*>::const_iterator cit2;

View file

@ -784,7 +784,7 @@ void RsGxsNetService::handleRecvSyncGrpStatistics(RsNxsSyncGrpStatsItem *grs)
// now count available messages
GxsMsgReq reqIds;
reqIds[grs->grpId] = std::vector<RsGxsMessageId>();
reqIds[grs->grpId] = std::set<RsGxsMessageId>();
GxsMsgMetaResult result;
#ifdef NXS_NET_DEBUG_6
@ -2757,7 +2757,7 @@ void RsGxsNetService::locked_genReqMsgTransaction(NxsTransaction* tr)
#endif
GxsMsgReq reqIds;
reqIds[grpId] = std::vector<RsGxsMessageId>();
reqIds[grpId] = std::set<RsGxsMessageId>();
GxsMsgMetaResult result;
mDataStore->retrieveGxsMsgMetaData(reqIds, result);
std::vector<RsGxsMsgMetaData*> &msgMetaV = result[grpId];
@ -3296,7 +3296,7 @@ void RsGxsNetService::locked_genSendMsgsTransaction(NxsTransaction* tr)
RsNxsSyncMsgItem* item = dynamic_cast<RsNxsSyncMsgItem*>(*lit);
if (item)
{
msgIds[item->grpId].push_back(item->msgId);
msgIds[item->grpId].insert(item->msgId);
if(grpId.isNull())
grpId = item->grpId;
@ -4127,7 +4127,7 @@ void RsGxsNetService::handleRecvSyncMessage(RsNxsSyncMsgReqItem *item,bool item_
}
GxsMsgReq req;
req[item->grpId] = std::vector<RsGxsMessageId>();
req[item->grpId] = std::set<RsGxsMessageId>();
GxsMsgMetaResult metaResult;
mDataStore->retrieveGxsMsgMetaData(req, metaResult);

View file

@ -67,7 +67,7 @@ bool RsGxsMessageCleanUp::clean()
GxsMsgReq req;
GxsMsgMetaResult result;
req[grpId] = std::vector<RsGxsMessageId>();
req[grpId] = std::set<RsGxsMessageId>();
mDs->retrieveGxsMsgMetaData(req, result);
GxsMsgMetaResult::iterator mit = result.begin();
@ -117,7 +117,7 @@ bool RsGxsMessageCleanUp::clean()
if( remove )
{
req[grpId].push_back(meta->mMsgId);
req[grpId].insert(meta->mMsgId);
#ifdef DEBUG_GXSUTIL
std::cerr << " Scheduling for removal." << std::endl;
@ -241,9 +241,9 @@ bool RsGxsIntegrityCheck::check()
for (msgIdsIt = msgIds.begin(); msgIdsIt != msgIds.end(); ++msgIdsIt)
{
const RsGxsGroupId& grpId = msgIdsIt->first;
std::vector<RsGxsMessageId> &msgIdV = msgIdsIt->second;
std::set<RsGxsMessageId> &msgIdV = msgIdsIt->second;
std::vector<RsGxsMessageId>::iterator msgIdIt;
std::set<RsGxsMessageId>::iterator msgIdIt;
for (msgIdIt = msgIdV.begin(); msgIdIt != msgIdV.end(); ++msgIdIt)
{
const RsGxsMessageId& msgId = *msgIdIt;
@ -261,7 +261,7 @@ bool RsGxsIntegrityCheck::check()
if (nxsMsgIt == nxsMsgV.end())
{
msgsToDel[grpId].push_back(msgId);
msgsToDel[grpId].insert(msgId);
}
}
}
@ -284,7 +284,7 @@ bool RsGxsIntegrityCheck::check()
if(msg->metaData == NULL || currHash != msg->metaData->mHash)
{
std::cerr << "(EE) deleting message data with wrong hash or null meta data. meta=" << (void*)msg->metaData << std::endl;
msgsToDel[msg->grpId].push_back(msg->msgId);
msgsToDel[msg->grpId].insert(msg->msgId);
}
else if(!msg->metaData->mAuthorId.isNull() && subscribed_groups.find(msg->metaData->mGroupId)!=subscribed_groups.end())
{
@ -377,7 +377,7 @@ bool RsGxsIntegrityCheck::isDone()
return mDone;
}
void RsGxsIntegrityCheck::getDeletedIds(std::list<RsGxsGroupId>& grpIds, std::map<RsGxsGroupId, std::vector<RsGxsMessageId> >& msgIds)
void RsGxsIntegrityCheck::getDeletedIds(std::list<RsGxsGroupId>& grpIds, std::map<RsGxsGroupId, std::set<RsGxsMessageId> >& msgIds)
{
RsStackMutex stack(mIntegrityMutex);

View file

@ -208,7 +208,7 @@ public:
void run();
void getDeletedIds(std::list<RsGxsGroupId>& grpIds, std::map<RsGxsGroupId, std::vector<RsGxsMessageId> >& msgIds);
void getDeletedIds(std::list<RsGxsGroupId>& grpIds, std::map<RsGxsGroupId, std::set<RsGxsMessageId> > &msgIds);
private:
@ -217,7 +217,7 @@ private:
bool mDone;
RsMutex mIntegrityMutex;
std::list<RsGxsGroupId> mDeletedGrps;
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > mDeletedMsgs;
std::map<RsGxsGroupId, std::set<RsGxsMessageId> > mDeletedMsgs;
RsGixs *mGixs ;
};

View file

@ -455,7 +455,7 @@ void p3GxsTrans::GxsTransIntegrityCleanupThread::run()
if(stored_msgs.end() != it2)
{
msgsToDel[it2->second.first].push_back(it2->second.second);
msgsToDel[it2->second.first].insert(it2->second.second);
#ifdef DEBUG_GXSTRANS
std::cerr << " scheduling msg " << std::hex << it2->second.first << "," << it2->second.second << " for deletion." << std::endl;

View file

@ -1,6 +1,6 @@
/*
* GXS Mailing Service
* Copyright (C) 2016-2017 Gioacchino Mazzurco <gio@eigenlab.org>
* Copyright (C) 2016-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 Affero General Public License as
@ -38,30 +38,28 @@ OutgoingRecord::OutgoingRecord( RsGxsId rec, GxsTransSubServices cs,
memcpy(&mailData[0], data, size);
}
RS_REGISTER_ITEM_TYPE(RsGxsTransMailItem) // for mailItem
RS_REGISTER_ITEM_TYPE(RsNxsTransPresignedReceipt) // for presignedReceipt
void OutgoingRecord_deprecated::serial_process(RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext& ctx)
void OutgoingRecord_deprecated::serial_process(
RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx )
{
RS_REGISTER_SERIAL_MEMBER_TYPED(status, uint8_t);
RS_REGISTER_SERIAL_MEMBER(recipient);
RS_REGISTER_SERIAL_MEMBER(mailItem);
RS_REGISTER_SERIAL_MEMBER(mailData);
RS_REGISTER_SERIAL_MEMBER_TYPED(clientService, uint16_t);
RS_REGISTER_SERIAL_MEMBER(presignedReceipt);
RS_SERIAL_PROCESS(status);
RS_SERIAL_PROCESS(recipient);
RS_SERIAL_PROCESS(mailItem);
RS_SERIAL_PROCESS(mailData);
RS_SERIAL_PROCESS(clientService);
RS_SERIAL_PROCESS(presignedReceipt);
}
void OutgoingRecord::serial_process(RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx)
{
RS_REGISTER_SERIAL_MEMBER_TYPED(status, uint8_t);
RS_REGISTER_SERIAL_MEMBER(recipient);
RS_REGISTER_SERIAL_MEMBER(author);
RS_REGISTER_SERIAL_MEMBER(group_id);
RS_REGISTER_SERIAL_MEMBER(sent_ts);
RS_REGISTER_SERIAL_MEMBER(mailItem);
RS_REGISTER_SERIAL_MEMBER(mailData);
RS_REGISTER_SERIAL_MEMBER_TYPED(clientService, uint16_t);
RS_REGISTER_SERIAL_MEMBER(presignedReceipt);
RS_SERIAL_PROCESS(status);
RS_SERIAL_PROCESS(recipient);
RS_SERIAL_PROCESS(author);
RS_SERIAL_PROCESS(group_id);
RS_SERIAL_PROCESS(sent_ts);
RS_SERIAL_PROCESS(mailItem);
RS_SERIAL_PROCESS(mailData);
RS_SERIAL_PROCESS(clientService);
RS_SERIAL_PROCESS(presignedReceipt);
}

View file

@ -55,7 +55,7 @@ public:
void serial_process( RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx )
{ RS_REGISTER_SERIAL_MEMBER_TYPED(mailId, uint64_t); }
{ RS_SERIAL_PROCESS(mailId); }
};
class RsGxsTransPresignedReceipt : public RsGxsTransBaseMsgItem
@ -140,9 +140,9 @@ public:
RsGenericSerializer::SerializeContext& ctx )
{
RsGxsTransBaseMsgItem::serial_process(j, ctx);
RS_REGISTER_SERIAL_MEMBER_TYPED(cryptoType, uint8_t);
RS_REGISTER_SERIAL_MEMBER(recipientHint);
RS_REGISTER_SERIAL_MEMBER(payload);
RS_SERIAL_PROCESS(cryptoType);
RS_SERIAL_PROCESS(recipientHint);
RS_SERIAL_PROCESS(payload);
}
void clear()

View file

@ -102,6 +102,9 @@ template<> void RsTypeSerializer::print_data(const std::string& name,BIGNUM
std::cerr << "[BIGNUM] : " << name << std::endl;
}
RS_TYPE_SERIALIZER_TO_JSON_NOT_IMPLEMENTED_DEF(BIGNUM*)
RS_TYPE_SERIALIZER_FROM_JSON_NOT_IMPLEMENTED_DEF(BIGNUM*)
void RsGxsTunnelStatusItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint32_t>(j,ctx,status,"status") ;

View file

@ -2,30 +2,17 @@
TEMPLATE = lib
CONFIG += staticlib
CONFIG += create_prl
CONFIG -= qt
TARGET = retroshare
TARGET_PRL = libretroshare
DESTDIR = lib
#CONFIG += dsdv
retrotor {
DEFINES *= RETROTOR
CONFIG -= bitdht
} else {
CONFIG += bitdht
}
!include("use_libretroshare.pri"):error("Including")
# the dht stunner is used to obtain RS external ip addr. when it is natted
# this system is unreliable and rs supports a newer and better one (asking connected peers)
# CONFIG += useDhtStunner
profiling {
QMAKE_CXXFLAGS -= -fomit-frame-pointer
QMAKE_CXXFLAGS *= -pg -g -fno-omit-frame-pointer
}
# treat warnings as error for better removing
#QMAKE_CFLAGS += -Werror
#QMAKE_CXXFLAGS += -Werror
@ -203,21 +190,11 @@ linux-* {
PKGCONFIG *= libssl libupnp
PKGCONFIG *= libcrypto zlib
LIBS *= -lpthread -ldl
}
no_sqlcipher:PKGCONFIG *= sqlite3
LIBS *= -ldl
linux-* {
DEFINES *= PLUGIN_DIR=\"\\\"$${PLUGIN_DIR}\\\"\"
DEFINES *= DATA_DIR=\"\\\"$${DATA_DIR}\\\"\"
## where to put the librarys interface
#include_rsiface.path = "$${INC_DIR}"
#include_rsiface.files = $$PUBLIC_HEADERS
#INSTALLS += include_rsiface
## where to put the shared library itself
#target.path = "$$LIB_DIR"
#INSTALLS *= target
}
linux-g++ {
@ -234,7 +211,7 @@ version_detail_bash_script {
PRE_TARGETDEPS = write_version_detail
write_version_detail.commands = $$PWD/version_detail.sh
}
win32 {
win32-* {
QMAKE_EXTRA_TARGETS += write_version_detail
PRE_TARGETDEPS = write_version_detail
write_version_detail.commands = $$PWD/version_detail.bat
@ -263,13 +240,11 @@ win32-x-g++ {
}
################################# Windows ##########################################
win32 {
win32-g++ {
QMAKE_CC = $${QMAKE_CXX}
OBJECTS_DIR = temp/obj
MOC_DIR = temp/moc
DEFINES *= WINDOWS_SYS WIN32 STATICLIB MINGW WIN32_LEAN_AND_MEAN _USE_32BIT_TIME_T
# This defines the platform to be WinXP or later and is needed for getaddrinfo (_WIN32_WINNT_WINXP)
DEFINES *= WINVER=0x0501
DEFINES *= STATICLIB
# Switch on extra warnings
QMAKE_CFLAGS += -Wextra
@ -287,17 +262,8 @@ win32 {
DEFINES += USE_CMD_ARGS
CONFIG += upnp_miniupnpc
no_sqlcipher {
PKGCONFIG *= sqlite3
LIBS += -lsqlite3
} else {
LIBS += -lsqlcipher
}
DEPENDPATH += . $$INC_DIR
INCLUDEPATH += . $$INC_DIR
wLibs = ws2_32 gdi32 uuid iphlpapi crypt32 ole32 winmm
LIBS += $$linkDynamicLibs(wLibs)
}
################################# MacOSX ##########################################
@ -306,22 +272,10 @@ mac {
QMAKE_CC = $${QMAKE_CXX}
OBJECTS_DIR = temp/obj
MOC_DIR = temp/moc
#DEFINES = WINDOWS_SYS WIN32 STATICLIB MINGW
#DEFINES *= MINIUPNPC_VERSION=13
CONFIG += upnp_miniupnpc
CONFIG += c++11
# zeroconf disabled at the end of libretroshare.pro (but need the code)
#CONFIG += zeroconf
#CONFIG += zcnatassist
# Beautiful Hack to fix 64bit file access.
QMAKE_CXXFLAGS *= -Dfseeko64=fseeko -Dftello64=ftello -Dfopen64=fopen -Dvstatfs64=vstatfs
#GPG_ERROR_DIR = ../../../../libgpg-error-1.7
#GPGME_DIR = ../../../../gpgme-1.1.8
for(lib, LIB_DIR):LIBS += -L"$$lib"
for(bin, BIN_DIR):LIBS += -L"$$bin"
@ -562,7 +516,7 @@ SOURCES += ft/ftchunkmap.cc \
ft/ftfilesearch.cc \
ft/ftserver.cc \
ft/fttransfermodule.cc \
ft/ftturtlefiletransferitem.cc
ft/ftturtlefiletransferitem.cc
SOURCES += crypto/chacha20.cpp \
crypto/hashstream.cc
@ -656,6 +610,7 @@ SOURCES += serialiser/rsbaseserial.cc \
rsitems/rsgxsupdateitems.cc \
rsitems/rsserviceinfoitems.cc \
SOURCES += services/autoproxy/rsautoproxymonitor.cc \
services/autoproxy/p3i2pbob.cc \
services/p3msgservice.cc \
@ -699,13 +654,16 @@ SOURCES += util/folderiterator.cc \
util/rstime.cc \
util/rsurl.cc
upnp_miniupnpc {
HEADERS += upnp/upnputil.h upnp/upnphandler_miniupnp.h
SOURCES += upnp/upnputil.c upnp/upnphandler_miniupnp.cc
## Added for retrocompatibility remove ASAP
isEmpty(RS_UPNP_LIB) {
upnp_miniupnpc:RS_UPNP_LIB=miniupnpc
upnp_libupnp:RS_UPNP_LIB="upnp ixml threadutil"
}
upnp_libupnp {
equals(RS_UPNP_LIB, miniupnpc) {
HEADERS += upnp/upnputil.h upnp/upnphandler_miniupnp.h
SOURCES += upnp/upnputil.c upnp/upnphandler_miniupnp.cc
} else {
HEADERS += upnp/UPnPBase.h upnp/upnphandler_linux.h
SOURCES += upnp/UPnPBase.cpp upnp/upnphandler_linux.cc
DEFINES *= RS_USE_LIBUPNP
@ -795,7 +753,8 @@ SOURCES += gxstunnel/p3gxstunnel.cc \
gxstunnel/rsgxstunnelitems.cc
# new serialization code
HEADERS += serialiser/rsserializer.h \
HEADERS += serialiser/rsserializable.h \
serialiser/rsserializer.h \
serialiser/rstypeserializer.h
SOURCES += serialiser/rsserializer.cc \
@ -936,19 +895,13 @@ android-* {
DEFINES *= "fopen64=fopen"
DEFINES *= "fseeko64=fseeko"
DEFINES *= "ftello64=ftello"
LIBS *= -lbz2 -lupnp -lixml -lthreadutil -lsqlite3
## Static library are verysensible to order in command line, has to be in the
## end of file for this reason
## Static library are very susceptible to order in command line
sLibs = bz2 $$RS_UPNP_LIB $$RS_SQL_LIB ssl crypto
LIBS += -L$$NATIVE_LIBS_TOOLCHAIN_PATH/sysroot/usr/lib/ -lsqlcipher
PRE_TARGETDEPS += $$NATIVE_LIBS_TOOLCHAIN_PATH/sysroot/usr/lib/libsqlcipher.a
LIBS += -L$$NATIVE_LIBS_TOOLCHAIN_PATH/sysroot/usr/lib/ -lssl
PRE_TARGETDEPS += $$NATIVE_LIBS_TOOLCHAIN_PATH/sysroot/usr/lib/libssl.a
LIBS += -L$$NATIVE_LIBS_TOOLCHAIN_PATH/sysroot/usr/lib/ -lcrypto
PRE_TARGETDEPS += $$NATIVE_LIBS_TOOLCHAIN_PATH/sysroot/usr/lib/libcrypto.a
LIBS += $$linkStaticLibs(sLibs)
PRE_TARGETDEPS += $$pretargetStaticLibs(sLibs)
HEADERS += util/androiddebug.h
}

View file

@ -67,7 +67,7 @@ p3HistoryMgr::~p3HistoryMgr()
/***** p3HistoryMgr *****/
//void p3HistoryMgr::addMessage(bool incoming, const RsPeerId &chatPeerId, const RsPeerId &peerId, const RsChatMsgItem *chatItem)
//void p3HistoryMgr::addMessage(bool incoming, const RsPeerId &chatPeerId, const RsPeerId &msgPeerId, const RsChatMsgItem *chatItem)
void p3HistoryMgr::addMessage(const ChatMessage& cm)
{
uint32_t addMsgId = 0;
@ -84,48 +84,48 @@ void p3HistoryMgr::addMessage(const ChatMessage& cm)
RsStackMutex stack(mHistoryMtx); /********** STACK LOCKED MTX ******/
RsPeerId peerId; // id of sending peer
RsPeerId chatPeerId; // id of chat endpoint
std::string peerName; //name of sending peer
RsPeerId msgPeerId; // id of sending peer
RsPeerId chatPeerId; // id of chat endpoint
std::string peerName; //name of sending peer
bool enabled = false;
if (cm.chat_id.isBroadcast() && mPublicEnable == true) {
peerName = rsPeers->getPeerName(cm.broadcast_peer_id);
enabled = true;
bool enabled = false;
if (cm.chat_id.isBroadcast() && mPublicEnable == true) {
peerName = rsPeers->getPeerName(cm.broadcast_peer_id);
enabled = true;
}
if (cm.chat_id.isPeerId() && mPrivateEnable == true) {
msgPeerId = cm.incoming ? cm.chat_id.toPeerId() : rsPeers->getOwnId();
peerName = rsPeers->getPeerName(msgPeerId);
enabled = true;
}
if (cm.chat_id.isLobbyId() && mLobbyEnable == true) {
peerName = cm.lobby_peer_gxs_id.toStdString();
enabled = true;
}
if (cm.chat_id.isPeerId() && mPrivateEnable == true) {
peerId = cm.incoming ? cm.chat_id.toPeerId() : rsPeers->getOwnId();
peerName = rsPeers->getPeerName(peerId);
enabled = true;
}
if (cm.chat_id.isLobbyId() && mLobbyEnable == true) {
peerName = cm.lobby_peer_gxs_id.toStdString();
enabled = true;
}
if(cm.chat_id.isDistantChatId())
{
DistantChatPeerInfo dcpinfo;
if (rsMsgs->getDistantChatStatus(cm.chat_id.toDistantChatId(), dcpinfo))
peerName = cm.chat_id.toPeerId().toStdString();
enabled = true;
}
if(cm.chat_id.isDistantChatId())
{
DistantChatPeerInfo dcpinfo;
if (rsMsgs->getDistantChatStatus(cm.chat_id.toDistantChatId(), dcpinfo))
peerName = cm.chat_id.toPeerId().toStdString();
enabled = true;
}
if(enabled == false)
return;
if(enabled == false)
return;
if(!chatIdToVirtualPeerId(cm.chat_id, chatPeerId))
return;
if(!chatIdToVirtualPeerId(cm.chat_id, chatPeerId))
return;
RsHistoryMsgItem* item = new RsHistoryMsgItem;
item->chatPeerId = chatPeerId;
item->incoming = cm.incoming;
item->peerId = peerId;
item->peerName = peerName;
item->sendTime = cm.sendTime;
item->recvTime = cm.recvTime;
item->incoming = cm.incoming;
item->msgPeerId = msgPeerId;
item->peerName = peerName;
item->sendTime = cm.sendTime;
item->recvTime = cm.recvTime;
item->message = cm.msg ;
item->message = cm.msg ;
//librs::util::ConvertUtf16ToUtf8(chatItem->message, item->message);
std::map<RsPeerId, std::map<uint32_t, RsHistoryMsgItem*> >::iterator mit = mMessages.find(item->chatPeerId);
@ -138,7 +138,7 @@ void p3HistoryMgr::addMessage(const ChatMessage& cm)
uint32_t limit;
if (chatPeerId.isNull())
limit = mPublicSaveCount;
else if (cm.chat_id.isLobbyId())
else if (cm.chat_id.isLobbyId())
limit = mLobbySaveCount;
else
limit = mPrivateSaveCount;
@ -424,7 +424,7 @@ static void convertMsg(const RsHistoryMsgItem* item, HistoryMsg &msg)
msg.msgId = item->msgId;
msg.chatPeerId = item->chatPeerId;
msg.incoming = item->incoming;
msg.peerId = item->peerId;
msg.peerId = item->msgPeerId;
msg.peerName = item->peerName;
msg.sendTime = item->sendTime;
msg.recvTime = item->recvTime;

View file

@ -57,6 +57,7 @@ static struct RsLog::logInfo p3connectzoneInfo = {RsLog::Default, "p3connect"};
/****
* #define LINKMGR_DEBUG 1
* #define LINKMGR_DEBUG_LOG 1
* #define LINKMGR_DEBUG_CONNFAIL 1
* #define LINKMGR_DEBUG_ACTIONS 1
* #define LINKMGR_DEBUG_LINKTYPE 1
@ -621,7 +622,9 @@ bool p3LinkMgrIMPL::connectAttempt(const RsPeerId &id, struct sockaddr_storage &
}
#ifdef LINKMGR_DEBUG_LOG
rslog(RSL_WARNING, p3connectzone, "p3LinkMgrIMPL::connectAttempt() called id: " + id.toStdString());
#endif
it->second.lastattempt = time(NULL);
it->second.inConnAttempt = true;
@ -824,7 +827,9 @@ bool p3LinkMgrIMPL::connectResult(const RsPeerId &id, bool success, bool isIncom
out += " FAILED ATTEMPT (Not Connected)";
}
}
#ifdef LINKMGR_DEBUG_LOG
rslog(RSL_WARNING, p3connectzone, out);
#endif
}
@ -2060,8 +2065,9 @@ bool p3LinkMgrIMPL::locked_ConnectAttempt_Complete(peerConnectState *peer)
int p3LinkMgrIMPL::addFriend(const RsPeerId &id, bool isVisible)
{
#ifdef LINKMGR_DEBUG_LOG
rslog(RSL_WARNING, p3connectzone, "p3LinkMgr::addFriend() id: " + id.toStdString());
#endif
{
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/

View file

@ -987,8 +987,8 @@ bool p3NetMgrIMPL::checkNetAddress()
bool addrChanged = false;
bool validAddr = false;
struct sockaddr_storage prefAddr;
struct sockaddr_storage oldAddr;
sockaddr_storage prefAddr;
sockaddr_storage oldAddr;
if (mNetMode & RS_NET_MODE_TRY_LOOPBACK)
{
@ -996,7 +996,7 @@ bool p3NetMgrIMPL::checkNetAddress()
std::cerr << "p3NetMgrIMPL::checkNetAddress() LOOPBACK ... forcing to 127.0.0.1";
std::cerr << std::endl;
#endif
sockaddr_storage_ipv4_aton(prefAddr, "127.0.0.1");
sockaddr_storage_ipv4_aton(prefAddr, "127.0.0.1");
validAddr = true;
}
else
@ -1012,7 +1012,7 @@ bool p3NetMgrIMPL::checkNetAddress()
std::vector<sockaddr_storage> addrs;
if (getLocalAddresses(addrs))
{
for (auto it = addrs.begin(); it!=addrs.end(); ++it)
for (auto it = addrs.begin(); it != addrs.end(); ++it)
{
sockaddr_storage& addr(*it);
if( sockaddr_storage_isValidNet(addr) &&
@ -1060,8 +1060,8 @@ bool p3NetMgrIMPL::checkNetAddress()
{
RS_STACK_MUTEX(mNetMtx);
oldAddr = mLocalAddr;
sockaddr_storage_copy(mLocalAddr, oldAddr);
addrChanged = !sockaddr_storage_sameip(prefAddr, mLocalAddr);
#ifdef NETMGR_DEBUG_TICK
@ -1087,7 +1087,7 @@ bool p3NetMgrIMPL::checkNetAddress()
// update address.
sockaddr_storage_copyip(mLocalAddr, prefAddr);
mNetFlags.mLocalAddr = mLocalAddr;
sockaddr_storage_copy(mLocalAddr, mNetFlags.mLocalAddr);
if(sockaddr_storage_isLoopbackNet(mLocalAddr))
{
@ -1129,9 +1129,13 @@ bool p3NetMgrIMPL::checkNetAddress()
* are the same (modify server)... this mismatch can
* occur when the local port is changed....
*/
if (sockaddr_storage_sameip(mLocalAddr, mExtAddr))
if (sockaddr_storage_sameip(mLocalAddr, mExtAddr) && sockaddr_storage_port(mLocalAddr) != sockaddr_storage_port(mExtAddr))
{
#ifdef NETMGR_DEBUG_RESET
std::cerr << "p3NetMgrIMPL::checkNetAddress() local and external ports are not the same. Setting external port to " << sockaddr_storage_port(mLocalAddr) << std::endl;
#endif
sockaddr_storage_setport(mExtAddr, sockaddr_storage_port(mLocalAddr));
addrChanged = true;
}
// ensure that address family is set, otherwise windows Barfs.

View file

@ -74,6 +74,7 @@ static struct RsLog::logInfo p3peermgrzoneInfo = {RsLog::Default, "p3peermgr"};
/****
* #define PEER_DEBUG 1
* #define PEER_DEBUG_LOG 1
***/
#define MAX_AVAIL_PERIOD 230 //times a peer stay in available state when not connected
@ -909,8 +910,9 @@ bool p3PeerMgrIMPL::addFriend(const RsPeerId& input_id, const RsPgpId& input_gpg
RsPeerId id = input_id ;
RsPgpId gpg_id = input_gpg_id ;
#ifdef PEER_DEBUG_LOG
rslog(RSL_WARNING, p3peermgrzone, "p3PeerMgr::addFriend() id: " + id.toStdString());
#endif
{
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
@ -1237,11 +1239,11 @@ bool p3PeerMgrIMPL::UpdateOwnAddress( const sockaddr_storage& pLocalAddr,
sockaddr_storage_copy(pExtAddr, extAddr);
sockaddr_storage_ipv6_to_ipv4(extAddr);
#ifdef PEER_DEBUG
//#ifdef PEER_DEBUG
std::cerr << "p3PeerMgrIMPL::UpdateOwnAddress("
<< sockaddr_storage_tostring(localAddr) << ", "
<< sockaddr_storage_tostring(extAddr) << ")" << std::endl;
#endif
//#endif
if( rsBanList &&
!rsBanList->isAddressAccepted(localAddr,
@ -1472,21 +1474,25 @@ bool p3PeerMgrIMPL::setLocalAddress( const RsPeerId &id,
return changed;
}
bool p3PeerMgrIMPL::setExtAddress(const RsPeerId &id, const struct sockaddr_storage &addr)
bool p3PeerMgrIMPL::setExtAddress( const RsPeerId &id,
const sockaddr_storage &addr )
{
bool changed = false;
uint32_t check_res = 0 ;
bool changed = false;
uint32_t check_res = 0;
if(rsBanList!=NULL && !rsBanList->isAddressAccepted(addr,RSBANLIST_CHECKING_FLAGS_BLACKLIST,&check_res))
{
std::cerr << "(SS) trying to set external contact address for peer " << id << " to a banned address " << sockaddr_storage_iptostring(addr )<< std::endl;
return false ;
}
if( rsBanList!=NULL && !rsBanList->isAddressAccepted(
addr, RSBANLIST_CHECKING_FLAGS_BLACKLIST, &check_res) )
{
std::cerr << "(SS) trying to set external contact address for peer "
<< id << " to a banned address "
<< sockaddr_storage_iptostring(addr) << std::endl;
return false;
}
if (id == AuthSSL::getAuthSSL()->OwnId())
{
{
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
RS_STACK_MUTEX(mPeerMtx);
if (!sockaddr_storage_same(mOwnState.serveraddr, addr))
{
mOwnState.serveraddr = addr;
@ -1499,7 +1505,7 @@ bool p3PeerMgrIMPL::setExtAddress(const RsPeerId &id, const struct sockaddr_s
return changed;
}
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
RS_STACK_MUTEX(mPeerMtx);
/* check if it is a friend */
std::map<RsPeerId, peerState>::iterator it;
if (mFriendList.end() == (it = mFriendList.find(id)))
@ -1507,7 +1513,9 @@ bool p3PeerMgrIMPL::setExtAddress(const RsPeerId &id, const struct sockaddr_s
if (mOthersList.end() == (it = mOthersList.find(id)))
{
#ifdef PEER_DEBUG
std::cerr << "p3PeerMgrIMPL::setLocalAddress() cannot add addres info : peer id not found in friend list id: " << id << std::endl;
std::cerr << "p3PeerMgrIMPL::setLocalAddress() cannot add addres "
<< "info : peer id not found in friend list id: " << id
<< std::endl;
#endif
return false;
}
@ -2058,7 +2066,7 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
RsPeerNetItem *item = new RsPeerNetItem();
item->clear();
item->peerId = getOwnId();
item->nodePeerId = getOwnId();
item->pgpId = mOwnState.gpg_id;
item->location = mOwnState.location;
@ -2109,7 +2117,7 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
item = new RsPeerNetItem();
item->clear();
item->peerId = it->first;
item->nodePeerId = it->first;
item->pgpId = (it->second).gpg_id;
item->location = (it->second).location;
item->netMode = (it->second).netMode;
@ -2309,7 +2317,7 @@ bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
RsPeerNetItem *pitem = dynamic_cast<RsPeerNetItem *>(*it);
if (pitem)
{
RsPeerId peer_id = pitem->peerId ;
RsPeerId peer_id = pitem->nodePeerId ;
RsPgpId peer_pgp_id = pitem->pgpId ;
if (peer_id == ownId)
@ -2336,7 +2344,7 @@ bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
/* ************* */
// permission flags is used as a mask for the existing perms, so we set it to 0xffff
addFriend(peer_id, peer_pgp_id, pitem->netMode, pitem->vs_disc, pitem->vs_dht, pitem->lastContact, RS_NODE_PERM_ALL);
setLocation(pitem->peerId, pitem->location);
setLocation(pitem->nodePeerId, pitem->location);
}
if (pitem->netMode == RS_NET_MODE_HIDDEN)

View file

@ -38,7 +38,7 @@
class PQInterface;
class RSTrafficClue;
class RsBwRates;
class RsItem;
struct RsItem;
class RsRawItem;
class SearchModule

View file

@ -27,7 +27,7 @@
#include <stddef.h> // for NULL
class RsItem;
struct RsItem;
/***
#define LOOPBACK_DEBUG 1

View file

@ -31,7 +31,7 @@
#include "pqi/pqi_base.h" // for NetInterface (ptr only), PQInterface
#include "retroshare/rstypes.h" // for RsPeerId
class RsItem;
struct RsItem;
class pqiloopback: public PQInterface
{

View file

@ -45,6 +45,7 @@ static std::list<RsPeerId> waitingIds;
/****
*#define PGRP_DEBUG 1
*#define PGRP_DEBUG_LOG 1
****/
#define DEFAULT_DOWNLOAD_KB_RATE (200.0)
@ -420,7 +421,9 @@ int pqipersongrp::addPeer(const RsPeerId& id)
sm -> pqi = pqip;
// reset it to start it working.
#ifdef PGRP_DEBUG_LOG
pqioutput(PQL_WARNING, pqipersongrpzone, "pqipersongrp::addPeer() => reset() called to initialise new person");
#endif
pqip -> reset();
pqip -> listen();

View file

@ -67,7 +67,7 @@ const int PQISSL_UDP_FLAG = 0x02;
//#define PQISSL_DEBUG 1
//#define PQISSL_LOG_DEBUG 1
//#define PQISSL_LOG_DEBUG2 1
static const int PQISSL_MAX_READ_ZERO_COUNT = 20;
static const time_t PQISSL_MAX_READ_ZERO_TIME = 15; // 15 seconds of no data => reset. (atm HeartBeat pkt sent 5 secs)
@ -238,7 +238,9 @@ int pqissl::reset_locked()
#endif
}
#ifdef PQISSL_LOG_DEBUG2
rslog(RSL_ALERT, pqisslzone, outLog);
#endif
// notify people of problem!
// but only if we really shut something down.
@ -585,12 +587,12 @@ int pqissl::Delay_Connection()
int pqissl::Initiate_Connection()
{
#ifdef PQISSL_DEBUG
std::cout << __PRETTY_FUNCTION__ << std::endl;
std::cerr << __PRETTY_FUNCTION__ << " "
<< sockaddr_storage_tostring(remote_addr) << std::endl;
#endif
int err;
sockaddr_storage addr = remote_addr;
sockaddr_storage addr; sockaddr_storage_copy(remote_addr, addr);
if(waiting != WAITING_DELAY)
{
@ -638,13 +640,6 @@ int pqissl::Initiate_Connection()
return -1;
}
{
std::string out;
rs_sprintf(out, "pqissl::Initiate_Connection() Connecting To: %s via: ", PeerId().toStdString().c_str());
out += sockaddr_storage_tostring(addr);
rslog(RSL_WARNING, pqisslzone, out);
}
if (sockaddr_storage_isnull(addr))
{
rslog(RSL_WARNING, pqisslzone, "pqissl::Initiate_Connection() Invalid (0.0.0.0) Remote Address, Aborting Connect.");
@ -721,6 +716,12 @@ int pqissl::Initiate_Connection()
//std::cerr << "Setting Connect Timeout " << mConnectTimeout << " Seconds into Future " << std::endl;
sockaddr_storage_ipv4_to_ipv6(addr);
#ifdef PQISSL_DEBUG
std::cerr << __PRETTY_FUNCTION__ << " Connecting To: "
<< PeerId().toStdString() <<" via: "
<< sockaddr_storage_tostring(addr) << std::endl;
#endif
if (0 != (err = unix_connect(osock, addr)))
{
switch (errno)
@ -730,11 +731,13 @@ int pqissl::Initiate_Connection()
sockfd = osock;
return 0;
default:
#ifdef PQISSL_DEBUG
std::cerr << __PRETTY_FUNCTION__ << " Failure connect "
<< sockaddr_storage_tostring(addr)
<< " returns: "
<< err << " -> errno: " << errno << " "
<< socket_errorType(errno) << std::endl;
#endif
net_internal_close(osock);
osock = -1;
@ -777,10 +780,14 @@ bool pqissl::CheckConnectionTimeout()
std::string out;
rs_sprintf(out, "pqissl::Basic_Connection_Complete() Connection Timed Out. Peer: %s Period: %lu", PeerId().toStdString().c_str(), mConnectTimeout);
#ifdef PQISSL_LOG_DEBUG2
rslog(RSL_WARNING, pqisslzone, out);
#endif
/* as sockfd is valid, this should close it all up */
#ifdef PQISSL_LOG_DEBUG2
rslog(RSL_ALERT, pqisslzone, "pqissl::Basic_Connection_Complete() -> calling reset()");
#endif
reset_locked();
return true;
}
@ -919,7 +926,9 @@ int pqissl::Basic_Connection_Complete()
{
std::string out;
rs_sprintf(out, "pqissl::Basic_Connection_Complete() TCP Connection Complete: cert: %s on osock: ", PeerId().toStdString().c_str(), sockfd);
#ifdef PQISSL_LOG_DEBUG2
rslog(RSL_WARNING, pqisslzone, out);
#endif
}
return 1;
}

View file

@ -60,8 +60,10 @@ static struct RsLog::logInfo pqissllistenzoneInfo = {RsLog::Default, "p3peermgr"
pqissllistenbase::pqissllistenbase(const sockaddr_storage &addr, p3PeerMgr *pm)
: laddr(addr), mPeerMgr(pm), active(false)
: mPeerMgr(pm), active(false)
{
sockaddr_storage_copy(addr, laddr);
if (!(AuthSSL::getAuthSSL()-> active()))
{
pqioutput(PQL_ALERT, pqissllistenzone,
@ -117,8 +119,10 @@ int pqissllistenbase::setuplisten()
reinterpret_cast<uint8_t*>(&no), sizeof(no));
if (err) std::cerr << __PRETTY_FUNCTION__
<< ": Error setting IPv6 socket dual stack" << std::endl;
#ifdef DEBUG_LISTENNER
else std::cerr << __PRETTY_FUNCTION__
<< ": Success setting IPv6 socket dual stack" << std::endl;
#endif
#endif // IPV6_V6ONLY
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
@ -208,26 +212,20 @@ int pqissllistenbase::setuplisten()
}
}
#ifdef OPEN_UNIVERSAL_PORT
struct sockaddr_storage tmpaddr = laddr;
if (!mPeerMgr->isHidden())
{
tmpaddr.ss_family = PF_INET6;
sockaddr_storage_zeroip(tmpaddr);
}
struct sockaddr_storage tmpaddr;
sockaddr_storage_copy(laddr, tmpaddr);
sockaddr_storage_ipv4_to_ipv6(tmpaddr);
if (!mPeerMgr->isHidden()) sockaddr_storage_zeroip(tmpaddr);
if (0 != (err = rs_bind(lsock, tmpaddr)))
#else
if (0 != (err = universal_bind(lsock, laddr)))
#endif
{
std::string out = "pqissllistenbase::setuplisten() Cannot Bind to Local Address!\n";
showSocketError(out);
pqioutput(PQL_ALERT, pqissllistenzone, out);
std::cerr << out << std::endl;
std::cerr << "laddr: " << sockaddr_storage_tostring(laddr) << std::endl;
#ifdef OPEN_UNIVERSAL_PORT
if (!mPeerMgr->isHidden()) std::cerr << "Zeroed tmpaddr: " << sockaddr_storage_tostring(tmpaddr) << std::endl;
#endif
std::cerr << out << std::endl
<< "tmpaddr: " << sockaddr_storage_tostring(tmpaddr)
<< std::endl;
print_stacktrace();
return -1;
}

View file

@ -42,6 +42,7 @@ static struct RsLog::logInfo pqisslproxyzoneInfo = {RsLog::Default, "pqisslproxy
#define pqisslproxyzone &pqisslproxyzoneInfo
// #define PROXY_DEBUG 1
// #define PROXY_DEBUG_LOG 1
#define PROXY_STATE_FAILED 0
#define PROXY_STATE_INIT 1
@ -593,8 +594,9 @@ bool pqisslproxy::connect_parameter(uint32_t type, const std::string &value)
{
std::string out;
rs_sprintf(out, "pqisslproxy::connect_parameter() Peer: %s DOMAIN_ADDRESS: %s", PeerId().toStdString().c_str(), value.c_str());
#ifdef PROXY_DEBUG_LOG
rslog(RSL_WARNING, pqisslproxyzone, out);
#endif
mDomainAddress = value;
#ifdef PROXY_DEBUG
std::cerr << out << std::endl;
@ -615,8 +617,9 @@ bool pqisslproxy::connect_parameter(uint32_t type, uint32_t value)
{
std::string out;
rs_sprintf(out, "pqisslproxy::connect_parameter() Peer: %s REMOTE_PORT: %lu", PeerId().toStdString().c_str(), value);
#ifdef PROXY_DEBUG_LOG
rslog(RSL_WARNING, pqisslproxyzone, out);
#endif
mRemotePort = value;
#ifdef PROXY_DEBUG
std::cerr << out << std::endl;

View file

@ -227,6 +227,15 @@ int pqissludp::Initiate_Connection()
return -1;
}
if(!sockaddr_storage_ipv6_to_ipv4(remote_addr))
{
std::cerr << __PRETTY_FUNCTION__ << "Error: remote_addr is not "
<< "valid IPv4!" << std::endl;
sockaddr_storage_dump(remote_addr);
print_stacktrace();
return -EINVAL;
}
mTimeoutTS = time(NULL) + mConnectTimeout;
//std::cerr << "Setting Connect Timeout " << mConnectTimeout << " Seconds into Future " << std::endl;
//std::cerr << " Connect Period is:" << mConnectPeriod << std::endl;
@ -254,32 +263,22 @@ int pqissludp::Initiate_Connection()
struct sockaddr_in proxyaddr;
struct sockaddr_in remoteaddr;
bool nonIpV4 = false;
if(!sockaddr_storage_ipv6_to_ipv4(remote_addr))
{
nonIpV4 = true;
std::cerr << __PRETTY_FUNCTION__ << "Error: remote_addr is not "
<< "valid IPv4!" << std::endl;
sockaddr_storage_dump(remote_addr);
}
if(!sockaddr_storage_ipv6_to_ipv4(mConnectSrcAddr))
{
nonIpV4 = true;
std::cerr << __PRETTY_FUNCTION__ << "Error: mConnectSrcAddr is "
<< "not valid IPv4!" << std::endl;
sockaddr_storage_dump(mConnectSrcAddr);
print_stacktrace();
return -EINVAL;
}
if(!sockaddr_storage_ipv6_to_ipv4(mConnectProxyAddr))
{
nonIpV4 = true;
std::cerr << __PRETTY_FUNCTION__ << "Error: mConnectProxyAddr "
<< "is not valid IPv4!" << std::endl;
sockaddr_storage_dump(mConnectProxyAddr);
}
if(!nonIpV4)
{
print_stacktrace();
return -EINVAL;
}
struct sockaddr_in *rap = (struct sockaddr_in *) &remote_addr;
@ -301,7 +300,6 @@ int pqissludp::Initiate_Connection()
err = tou_connect_via_relay(sockfd, &srcaddr, &proxyaddr, &remoteaddr);
}
/*** It seems that the UDP Layer sees x 1.2 the traffic of the SSL layer.
* We need to compensate somewhere... we drop the maximum traffic to 75% of limit

View file

@ -38,7 +38,7 @@
#include "retroshare/rstypes.h" // for RsPeerId
#include "util/rsthreads.h" // for RsMutex
class RsItem;
struct RsItem;
class RsSerialiser;
struct PartialPacketRecord

View file

@ -182,7 +182,7 @@ private:
class StringExpression: public Expression
{
public:
StringExpression(enum StringOperator op, std::list<std::string> &t, bool ic): Op(op),terms(t), IgnoreCase(ic){}
StringExpression(enum StringOperator op, const std::list<std::string> &t, bool ic): Op(op),terms(t), IgnoreCase(ic){}
virtual void linearize(LinearizedExpression& e) const ;
virtual std::string toStdString(const std::string& varstr) const;
@ -275,7 +275,7 @@ Some implementations of StringExpressions.
class NameExpression: public StringExpression
{
public:
NameExpression(enum StringOperator op, std::list<std::string> &t, bool ic):
NameExpression(enum StringOperator op, const std::list<std::string> &t, bool ic):
StringExpression(op,t,ic) {}
bool eval(const ExpFileEntry& file);
@ -290,7 +290,7 @@ public:
class PathExpression: public StringExpression {
public:
PathExpression(enum StringOperator op, std::list<std::string> &t, bool ic):
PathExpression(enum StringOperator op, const std::list<std::string> &t, bool ic):
StringExpression(op,t,ic) {}
bool eval(const ExpFileEntry& file);
@ -305,7 +305,7 @@ public:
class ExtExpression: public StringExpression {
public:
ExtExpression(enum StringOperator op, std::list<std::string> &t, bool ic):
ExtExpression(enum StringOperator op, const std::list<std::string> &t, bool ic):
StringExpression(op,t,ic) {}
bool eval(const ExpFileEntry& file);
@ -320,7 +320,7 @@ public:
class HashExpression: public StringExpression {
public:
HashExpression(enum StringOperator op, std::list<std::string> &t):
HashExpression(enum StringOperator op, const std::list<std::string> &t):
StringExpression(op,t, true) {}
bool eval(const ExpFileEntry& file);

View file

@ -168,10 +168,9 @@ public:
class RsFiles
{
public:
RsFiles() { return; }
virtual ~RsFiles() { return; }
public:
RsFiles() {}
virtual ~RsFiles() {}
/**
* Provides file data for the gui: media streaming or rpc clients.
@ -278,8 +277,8 @@ class RsFiles
***/
virtual void requestDirUpdate(void *ref) =0 ; // triggers the update of the given reference. Used when browsing.
virtual void setDownloadDirectory(std::string path) = 0;
virtual void setPartialsDirectory(std::string path) = 0;
virtual bool setDownloadDirectory(std::string path) = 0;
virtual bool setPartialsDirectory(std::string path) = 0;
virtual std::string getDownloadDirectory() = 0;
virtual std::string getPartialsDirectory() = 0;

View file

@ -124,24 +124,27 @@ class RsGxsComment
};
class RsGxsCommentService
struct RsGxsCommentService
{
public:
RsGxsCommentService() {}
virtual ~RsGxsCommentService() {}
RsGxsCommentService() { return; }
virtual ~RsGxsCommentService() { return; }
/** Get previously requested comment data with token */
virtual bool getCommentData( uint32_t token,
std::vector<RsGxsComment> &comments ) = 0;
virtual bool getRelatedComments( uint32_t token,
std::vector<RsGxsComment> &comments ) = 0;
virtual bool getCommentData(const uint32_t &token, std::vector<RsGxsComment> &comments) = 0;
virtual bool getRelatedComments(const uint32_t &token, std::vector<RsGxsComment> &comments) = 0;
virtual bool createComment(uint32_t &token, RsGxsComment &comment) = 0;
virtual bool createVote(uint32_t &token, RsGxsVote &vote) = 0;
//virtual bool getDetailedCommentData(const uint32_t &token, std::vector<RsGxsComment> &comments);
virtual bool createComment(uint32_t &token, RsGxsComment &comment) = 0;
virtual bool createVote(uint32_t &token, RsGxsVote &vote) = 0;
virtual bool acknowledgeComment(const uint32_t& token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId) = 0;
virtual bool acknowledgeVote(const uint32_t& token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId) = 0;
virtual bool acknowledgeComment(
uint32_t token,
std::pair<RsGxsGroupId, RsGxsMessageId>& msgId ) = 0;
virtual bool acknowledgeVote(
uint32_t token,
std::pair<RsGxsGroupId, RsGxsMessageId>& msgId ) = 0;
};

View file

@ -40,8 +40,8 @@ class RsGxsChanges
public:
RsGxsChanges(): mService(0){}
RsTokenService *mService;
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > mMsgs;
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > mMsgsMeta;
std::map<RsGxsGroupId, std::set<RsGxsMessageId> > mMsgs;
std::map<RsGxsGroupId, std::set<RsGxsMessageId> > mMsgsMeta;
std::list<RsGxsGroupId> mGrps;
std::list<RsGxsGroupId> mGrpsMeta;
};

View file

@ -1,3 +1,23 @@
/*
* rsgxsifacetypes.h
*
* Copyright (C) 2013 crispy
* 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 Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* rsgxsifacetypes.h
*
@ -13,18 +33,20 @@
#include <string>
#include <inttypes.h>
#include <retroshare/rstypes.h>
#include <retroshare/rsids.h>
#include "retroshare/rstypes.h"
#include "retroshare/rsids.h"
#include "serialiser/rsserializable.h"
#include "serialiser/rstypeserializer.h"
typedef GXSGroupId RsGxsGroupId;
typedef Sha1CheckSum RsGxsMessageId;
typedef GXSId RsGxsId;
typedef GXSCircleId RsGxsCircleId;
typedef std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > GxsMsgIdResult;
typedef std::map<RsGxsGroupId, std::set<RsGxsMessageId> > GxsMsgIdResult;
typedef std::pair<RsGxsGroupId, RsGxsMessageId> RsGxsGrpMsgIdPair;
typedef std::map<RsGxsGrpMsgIdPair, std::vector<RsGxsMessageId> > MsgRelatedIdResult;
typedef std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > GxsMsgReq;
typedef std::map<RsGxsGrpMsgIdPair, std::set<RsGxsMessageId> > MsgRelatedIdResult;
typedef std::map<RsGxsGroupId, std::set<RsGxsMessageId> > GxsMsgReq;
struct RsMsgMetaData;
@ -34,7 +56,7 @@ typedef std::map<RsGxsGroupId, std::vector<RsMsgMetaData> > MsgMetaResult;
class RsGxsGrpMetaData;
class RsGxsMsgMetaData;
struct RsGroupMetaData
struct RsGroupMetaData : RsSerializable
{
// (csoler) The correct default value to be used in mCircleType is GXS_CIRCLE_TYPE_PUBLIC, which is defined in rsgxscircles.h,
// but because of a loop in the includes, I cannot include it here. So I replaced with its current value 0x0001.
@ -73,6 +95,30 @@ struct RsGroupMetaData
std::string mServiceString; // Service Specific Free-Form extra storage.
RsPeerId mOriginator;
RsGxsCircleId mInternalCircle;
/// @see RsSerializable
void serial_process( RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx )
{
RS_SERIAL_PROCESS(mGroupId);
RS_SERIAL_PROCESS(mGroupName);
RS_SERIAL_PROCESS(mGroupFlags);
RS_SERIAL_PROCESS(mSignFlags);
RS_SERIAL_PROCESS(mPublishTs);
RS_SERIAL_PROCESS(mAuthorId);
RS_SERIAL_PROCESS(mCircleId);
RS_SERIAL_PROCESS(mCircleType);
RS_SERIAL_PROCESS(mAuthenFlags);
RS_SERIAL_PROCESS(mParentGrpId);
RS_SERIAL_PROCESS(mSubscribeFlags);
RS_SERIAL_PROCESS(mPop);
RS_SERIAL_PROCESS(mVisibleMsgCount);
RS_SERIAL_PROCESS(mLastPost);
RS_SERIAL_PROCESS(mGroupStatus);
RS_SERIAL_PROCESS(mServiceString);
RS_SERIAL_PROCESS(mOriginator);
RS_SERIAL_PROCESS(mInternalCircle);
}
};

View file

@ -46,7 +46,7 @@ class RsGxsMsgChange : public RsGxsNotify
{
public:
RsGxsMsgChange(NotifyType type, bool metaChange) : NOTIFY_TYPE(type), mMetaChange(metaChange) {}
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > msgChangeMap;
std::map<RsGxsGroupId, std::set<RsGxsMessageId> > msgChangeMap;
NotifyType getType(){ return NOTIFY_TYPE;}
bool metaChange() { return mMetaChange; }
private:

View file

@ -6,7 +6,8 @@
*
* RetroShare C++ Interface.
*
* Copyright 2012-2012 by Robert Fernie.
* Copyright (C) 2012 Robert Fernie.
* 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
@ -36,9 +37,12 @@
#include "retroshare/rsids.h"
#include "serialiser/rstlvimage.h"
#include "retroshare/rsgxscommon.h"
#include "serialiser/rsserializable.h"
#include "serialiser/rstypeserializer.h"
#include "util/rsdeprecate.h"
/* The Main Interface Class - for information about your Peers */
class RsIdentity;
struct RsIdentity;
extern RsIdentity *rsIdentity;
@ -63,6 +67,7 @@ extern RsIdentity *rsIdentity;
#define RSID_RELATION_OTHER 0x0008
#define RSID_RELATION_UNKNOWN 0x0010
/// @deprecated remove toghether with RsGxsIdGroup::mRecognTags
#define RSRECOGN_MAX_TAGINFO 5
// Unicode symbols. NOT utf-8 bytes, because of multi byte characters
@ -77,27 +82,36 @@ static const uint32_t RS_IDENTITY_FLAGS_PGP_KNOWN = 0x0004;
static const uint32_t RS_IDENTITY_FLAGS_IS_OWN_ID = 0x0008;
static const uint32_t RS_IDENTITY_FLAGS_IS_DEPRECATED= 0x0010; // used to denote keys with deprecated fingerprint format.
class GxsReputation
struct GxsReputation : RsSerializable
{
public:
GxsReputation();
GxsReputation();
bool updateIdScore(bool pgpLinked, bool pgpKnown);
bool update(); // checks ranges and calculates overall score.
int mOverallScore;
int mIdScore; // PGP, Known, etc.
int mOwnOpinion;
int mPeerOpinion;
bool updateIdScore(bool pgpLinked, bool pgpKnown);
bool update(); /// checks ranges and calculates overall score.
int32_t mOverallScore;
int32_t mIdScore; /// PGP, Known, etc.
int32_t mOwnOpinion;
int32_t mPeerOpinion;
/// @see RsSerializable
void serial_process( RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx )
{
RS_SERIAL_PROCESS(mOverallScore);
RS_SERIAL_PROCESS(mIdScore);
RS_SERIAL_PROCESS(mOwnOpinion);
RS_SERIAL_PROCESS(mPeerOpinion);
}
};
struct RsGxsIdGroup
struct RsGxsIdGroup : RsSerializable
{
RsGxsIdGroup() :
mLastUsageTS(0), mPgpKnown(false), mIsAContact(false) {}
~RsGxsIdGroup() {}
RsGroupMetaData mMeta;
// In GroupMetaData.
@ -120,7 +134,7 @@ struct RsGxsIdGroup
std::string mPgpIdSign;
// Recognition Strings. MAX# defined above.
std::list<std::string> mRecognTags;
RS_DEPRECATED std::list<std::string> mRecognTags;
// Avatar
RsGxsImage mImage ;
@ -131,8 +145,11 @@ struct RsGxsIdGroup
bool mIsAContact; // change that into flags one day
RsPgpId mPgpId;
GxsReputation mReputation;
};
/// @see RsSerializable
void serial_process( RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx );
};
std::ostream &operator<<(std::ostream &out, const RsGxsIdGroup &group);
@ -149,12 +166,11 @@ class RsRecognTag
};
class RsRecognTagDetails
struct RsRecognTagDetails
{
public:
RsRecognTagDetails()
:valid_from(0), valid_to(0), tag_class(0), tag_type(0),
is_valid(false), is_pending(false) { return; }
RsRecognTagDetails() :
valid_from(0), valid_to(0), tag_class(0), tag_type(0), is_valid(false),
is_pending(false) {}
time_t valid_from;
time_t valid_to;
@ -167,105 +183,166 @@ class RsRecognTagDetails
bool is_pending;
};
class RsIdOpinion
{
public:
RsGxsId id;
int rating;
};
class RsIdentityParameters
struct RsIdentityParameters
{
public:
RsIdentityParameters(): isPgpLinked(false) { return; }
RsIdentityParameters() :
isPgpLinked(false) {}
bool isPgpLinked;
std::string nickname;
RsGxsImage mImage ;
std::string nickname;
RsGxsImage mImage;
};
class RsIdentityUsage
struct RsIdentityUsage : RsSerializable
{
public:
enum UsageCode { UNKNOWN_USAGE = 0x00,
GROUP_ADMIN_SIGNATURE_CREATION = 0x01, // These 2 are normally not normal GXS identities, but nothing prevents it to happen either.
GROUP_ADMIN_SIGNATURE_VALIDATION = 0x02,
GROUP_AUTHOR_SIGNATURE_CREATION = 0x03, // not typically used, since most services do not require group author signatures
GROUP_AUTHOR_SIGNATURE_VALIDATION = 0x04,
MESSAGE_AUTHOR_SIGNATURE_CREATION = 0x05, // most common use case. Messages are signed by authors in e.g. forums.
MESSAGE_AUTHOR_SIGNATURE_VALIDATION = 0x06,
GROUP_AUTHOR_KEEP_ALIVE = 0x07, // Identities are stamped regularly by crawlign the set of messages for all groups. That helps keepign the useful identities in hand.
MESSAGE_AUTHOR_KEEP_ALIVE = 0x08, // Identities are stamped regularly by crawlign the set of messages for all groups. That helps keepign the useful identities in hand.
CHAT_LOBBY_MSG_VALIDATION = 0x09, // Chat lobby msgs are signed, so each time one comes, or a chat lobby event comes, a signature verificaiton happens.
GLOBAL_ROUTER_SIGNATURE_CHECK = 0x0a, // Global router message validation
GLOBAL_ROUTER_SIGNATURE_CREATION = 0x0b, // Global router message signature
GXS_TUNNEL_DH_SIGNATURE_CHECK = 0x0c, //
GXS_TUNNEL_DH_SIGNATURE_CREATION = 0x0d, //
IDENTITY_DATA_UPDATE = 0x0e, // Group update on that identity data. Can be avatar, name, etc.
IDENTITY_GENERIC_SIGNATURE_CHECK = 0x0f, // Any signature verified for that identity
IDENTITY_GENERIC_SIGNATURE_CREATION = 0x10, // Any signature made by that identity
IDENTITY_GENERIC_ENCRYPTION = 0x11,
IDENTITY_GENERIC_DECRYPTION = 0x12,
CIRCLE_MEMBERSHIP_CHECK = 0x13
} ;
enum UsageCode : uint8_t
{
UNKNOWN_USAGE = 0x00,
explicit RsIdentityUsage(uint16_t service,const RsIdentityUsage::UsageCode& code,const RsGxsGroupId& gid=RsGxsGroupId(),const RsGxsMessageId& mid=RsGxsMessageId(),uint64_t additional_id=0,const std::string& comment = std::string());
/** These 2 are normally not normal GXS identities, but nothing prevents
* it to happen either. */
GROUP_ADMIN_SIGNATURE_CREATION = 0x01,
GROUP_ADMIN_SIGNATURE_VALIDATION = 0x02,
uint16_t mServiceId; // Id of the service using that identity, as understood by rsServiceControl
UsageCode mUsageCode; // Specific code to use. Will allow forming the correct translated message in the GUI if necessary.
RsGxsGroupId mGrpId; // Group ID using the identity
/** Not typically used, since most services do not require group author
* signatures */
GROUP_AUTHOR_SIGNATURE_CREATION = 0x03,
GROUP_AUTHOR_SIGNATURE_VALIDATION = 0x04,
RsGxsMessageId mMsgId; // Message ID using the identity
uint64_t mAdditionalId; // Some additional ID. Can be used for e.g. chat lobbies.
std::string mComment ; // additional comment to be used mainly for debugging, but not GUI display
/// most common use case. Messages are signed by authors in e.g. forums.
MESSAGE_AUTHOR_SIGNATURE_CREATION = 0x05,
MESSAGE_AUTHOR_SIGNATURE_VALIDATION = 0x06,
bool operator<(const RsIdentityUsage& u) const
{
return mHash < u.mHash ;
}
RsFileHash mHash ;
/** Identities are stamped regularly by crawlign the set of messages for
* all groups. That helps keepign the useful identities in hand. */
GROUP_AUTHOR_KEEP_ALIVE = 0x07,
MESSAGE_AUTHOR_KEEP_ALIVE = 0x08,
/** Chat lobby msgs are signed, so each time one comes, or a chat lobby
* event comes, a signature verificaiton happens. */
CHAT_LOBBY_MSG_VALIDATION = 0x09,
/// Global router message validation
GLOBAL_ROUTER_SIGNATURE_CHECK = 0x0a,
/// Global router message signature
GLOBAL_ROUTER_SIGNATURE_CREATION = 0x0b,
GXS_TUNNEL_DH_SIGNATURE_CHECK = 0x0c,
GXS_TUNNEL_DH_SIGNATURE_CREATION = 0x0d,
/// Group update on that identity data. Can be avatar, name, etc.
IDENTITY_DATA_UPDATE = 0x0e,
/// Any signature verified for that identity
IDENTITY_GENERIC_SIGNATURE_CHECK = 0x0f,
/// Any signature made by that identity
IDENTITY_GENERIC_SIGNATURE_CREATION = 0x10,
IDENTITY_GENERIC_ENCRYPTION = 0x11,
IDENTITY_GENERIC_DECRYPTION = 0x12,
CIRCLE_MEMBERSHIP_CHECK = 0x13
} ;
RsIdentityUsage( uint16_t service, const RsIdentityUsage::UsageCode& code,
const RsGxsGroupId& gid = RsGxsGroupId(),
const RsGxsMessageId& mid = RsGxsMessageId(),
uint64_t additional_id=0,
const std::string& comment = std::string() );
/// Id of the service using that identity, as understood by rsServiceControl
uint16_t mServiceId;
/** Specific code to use. Will allow forming the correct translated message
* in the GUI if necessary. */
UsageCode mUsageCode;
/// Group ID using the identity
RsGxsGroupId mGrpId;
/// Message ID using the identity
RsGxsMessageId mMsgId;
/// Some additional ID. Can be used for e.g. chat lobbies.
uint64_t mAdditionalId;
/// additional comment to be used mainly for debugging, but not GUI display
std::string mComment;
bool operator<(const RsIdentityUsage& u) const { return mHash < u.mHash; }
RsFileHash mHash ;
/// @see RsSerializable
void serial_process( RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx )
{
RS_SERIAL_PROCESS(mServiceId);
RS_SERIAL_PROCESS(mUsageCode);
RS_SERIAL_PROCESS(mGrpId);
RS_SERIAL_PROCESS(mMsgId);
RS_SERIAL_PROCESS(mAdditionalId);
RS_SERIAL_PROCESS(mComment);
RS_SERIAL_PROCESS(mHash);
}
friend struct RsTypeSerializer;
private:
/** Accessible only to friend class RsTypeSerializer needed for
* deserialization */
RsIdentityUsage();
};
class RsIdentityDetails
struct RsIdentityDetails : RsSerializable
{
public:
RsIdentityDetails()
: mFlags(0), mLastUsageTS(0) { return; }
RsIdentityDetails() : mFlags(0), mLastUsageTS(0) {}
RsGxsId mId;
// identity details.
std::string mNickname;
uint32_t mFlags ;
uint32_t mFlags;
// PGP Stuff.
RsPgpId mPgpId;
RsPgpId mPgpId;
// Recogn details.
std::list<RsRecognTag> mRecognTags;
/// @deprecated Recogn details.
RS_DEPRECATED std::list<RsRecognTag> mRecognTags;
// Cyril: Reputation details. At some point we might want to merge information
// between the two into a single global score. Since the old reputation system
// is not finished yet, I leave this in place. We should decide what to do with it.
RsReputations::ReputationInfo mReputation;
/** Cyril: Reputation details. At some point we might want to merge
* information between the two into a single global score. Since the old
* reputation system is not finished yet, I leave this in place. We should
* decide what to do with it.
*/
RsReputations::ReputationInfo mReputation;
// avatar
RsGxsImage mAvatar ;
RsGxsImage mAvatar;
// last usage
time_t mLastUsageTS ;
std::map<RsIdentityUsage,time_t> mUseCases ;
time_t mLastUsageTS;
std::map<RsIdentityUsage,time_t> mUseCases;
/// @see RsSerializable
virtual void serial_process(RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx)
{
RS_SERIAL_PROCESS(mId);
RS_SERIAL_PROCESS(mNickname);
RS_SERIAL_PROCESS(mFlags);
RS_SERIAL_PROCESS(mPgpId);
//RS_SERIAL_PROCESS(mReputation);
//RS_SERIAL_PROCESS(mAvatar);
RS_SERIAL_PROCESS(mLastUsageTS);
RS_SERIAL_PROCESS(mUseCases);
}
};
class RsIdentity: public RsGxsIfaceHelper
struct RsIdentity : RsGxsIfaceHelper
{
public:
explicit RsIdentity(RsGxsIface *gxs): RsGxsIfaceHelper(gxs) {}
virtual ~RsIdentity() {}

View file

@ -61,14 +61,17 @@
/* TODO CLEANUP: RS_TOKREQ_ANSTYPE_* values are meaningless and not used by
* RsTokenService or its implementation, and may be arbitrarly defined by each
* GXS client as they are of no usage, their use is deprecated */
* GXS client as they are of no usage, their use is deprecated, up until the
* definitive cleanup is done new code must use RS_DEPRECATED_TOKREQ_ANSTYPE for
* easier cleanup. */
#ifndef RS_NO_WARN_DEPRECATED
# warning RS_TOKREQ_ANSTYPE_* macros are deprecated!
#endif
#define RS_TOKREQ_ANSTYPE_LIST 0x0001
#define RS_TOKREQ_ANSTYPE_SUMMARY 0x0002
#define RS_TOKREQ_ANSTYPE_DATA 0x0003
#define RS_TOKREQ_ANSTYPE_ACK 0x0004
#define RS_DEPRECATED_TOKREQ_ANSTYPE 0x0000
#define RS_TOKREQ_ANSTYPE_LIST 0x0001
#define RS_TOKREQ_ANSTYPE_SUMMARY 0x0002
#define RS_TOKREQ_ANSTYPE_DATA 0x0003
#define RS_TOKREQ_ANSTYPE_ACK 0x0004
/*!

View file

@ -36,6 +36,8 @@
#include <retroshare/rsids.h>
#include <retroshare/rsflags.h>
#include <serialiser/rsserializable.h>
#include <serialiser/rstypeserializer.h>
#define USE_NEW_CHUNK_CHECKING_CODE
@ -118,13 +120,21 @@ class Condition
std::string name;
};
class PeerBandwidthLimits
struct PeerBandwidthLimits : RsSerializable
{
public:
PeerBandwidthLimits() : max_up_rate_kbs(0), max_dl_rate_kbs(0) {}
uint32_t max_up_rate_kbs ;
uint32_t max_dl_rate_kbs ;
PeerBandwidthLimits() : max_up_rate_kbs(0), max_dl_rate_kbs(0) {}
uint32_t max_up_rate_kbs;
uint32_t max_dl_rate_kbs;
/// @see RsSerializable
void serial_process(RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx)
{
RS_SERIAL_PROCESS(max_up_rate_kbs);
RS_SERIAL_PROCESS(max_dl_rate_kbs);
}
};
//class SearchRequest // unused stuff.
@ -295,7 +305,7 @@ class FileChunksInfo
std::map<uint32_t, std::vector<SliceInfo> > pending_slices ;
};
class CompressedChunkMap
class CompressedChunkMap : public RsSerializable
{
public:
CompressedChunkMap() {}
@ -345,10 +355,16 @@ class CompressedChunkMap
inline void set(uint32_t j) { _map[j >> 5] |= (1 << (j & 31)) ; }
inline void reset(uint32_t j) { _map[j >> 5] &= ~(1 << (j & 31)) ; }
/// compressed map, one bit per chunk
std::vector<uint32_t> _map ;
/// compressed map, one bit per chunk
std::vector<uint32_t> _map;
/// @see RsSerializable
void serial_process(RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx)
{ RS_SERIAL_PROCESS(_map); }
};
template<class CRCTYPE> class t_CRCMap
{
public:

View file

@ -48,8 +48,8 @@ void RsBanListItem::serial_process(RsGenericSerializer::SerializeJob j,RsGeneric
void RsBanListConfigItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint32_t>(j,ctx,type,"type") ;
RsTypeSerializer::serial_process (j,ctx,peerId,"peerId") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,banListType,"type") ;
RsTypeSerializer::serial_process (j,ctx,banListPeerId,"peerId") ;
RsTypeSerializer::serial_process<time_t> (j,ctx,update_time,"update_time") ;
RsTypeSerializer::serial_process (j,ctx,banned_peers,"banned_peers") ;
}

View file

@ -60,18 +60,20 @@ class RsBanListItem: public RsItem
class RsBanListConfigItem: public RsItem
{
public:
RsBanListConfigItem()
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_BANLIST, RS_PKT_SUBTYPE_BANLIST_CONFIG_ITEM) {}
RsBanListConfigItem()
: RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_BANLIST, RS_PKT_SUBTYPE_BANLIST_CONFIG_ITEM)
, banListType(0), update_time(0)
{}
virtual ~RsBanListConfigItem(){}
virtual void clear() { banned_peers.TlvClear() ; }
virtual ~RsBanListConfigItem(){}
virtual void clear() { banned_peers.TlvClear() ; }
void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
uint32_t type ;
RsPeerId peerId ;
time_t update_time ;
RsTlvBanList banned_peers;
uint32_t banListType ;
RsPeerId banListPeerId ;
time_t update_time ;
RsTlvBanList banned_peers;
};
class RsBanListSerialiser: public RsServiceSerializer

View file

@ -28,6 +28,7 @@
#include "rsitems/rsconfigitems.h"
#include "retroshare/rspeers.h" // Needed for RsGroupInfo.
#include "serialiser/rsserializable.h"
#include "serialiser/rstypeserializer.h"
/***
* #define RSSERIAL_DEBUG 1
@ -89,7 +90,7 @@ void RsFileTransfer::serial_process(RsGenericSerializer::SerializeJob j,RsGeneri
RsTypeSerializer::serial_process<uint32_t> (j,ctx,flags,"flags") ;
RsTypeSerializer::serial_process<uint32_t> (j,ctx,chunk_strategy,"chunk_strategy") ;
RsTypeSerializer::serial_process (j,ctx,compressed_chunk_map,"compressed_chunk_map") ;
RS_SERIAL_PROCESS(compressed_chunk_map);
}
void RsFileConfigItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
@ -136,9 +137,9 @@ RsItem *RsPeerConfigSerialiser::create_item(uint8_t item_type,uint8_t item_subty
void RsPeerNetItem::clear()
{
peerId.clear();
pgpId.clear();
location.clear();
nodePeerId.clear();
pgpId.clear();
location.clear();
netMode = 0;
vs_disc = 0;
vs_dht = 0;
@ -159,7 +160,7 @@ void RsPeerNetItem::clear()
}
void RsPeerNetItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process(j,ctx,peerId,"peerId") ;
RsTypeSerializer::serial_process(j,ctx,nodePeerId,"peerId") ;
RsTypeSerializer::serial_process(j,ctx,pgpId,"pgpId") ;
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_LOCATION,location,"location") ;
@ -192,31 +193,6 @@ void RsPeerStunItem::serial_process(RsGenericSerializer::SerializeJob j,RsGeneri
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,stunList,"stunList") ;
}
template<> uint32_t RsTypeSerializer::serial_size(const PeerBandwidthLimits& /*s*/)
{
return 4+4 ;
}
template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset,const PeerBandwidthLimits& s)
{
bool ok = true ;
ok = ok && setRawUInt32(data,size,&offset,s.max_up_rate_kbs);
ok = ok && setRawUInt32(data,size,&offset,s.max_dl_rate_kbs);
return ok;
}
template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size,uint32_t& offset,PeerBandwidthLimits& s)
{
bool ok = true ;
ok = ok && getRawUInt32(data,size,&offset,&s.max_up_rate_kbs);
ok = ok && getRawUInt32(data,size,&offset,&s.max_dl_rate_kbs);
return ok;
}
template<> void RsTypeSerializer::print_data(const std::string& /*n*/, const PeerBandwidthLimits& s)
{
std::cerr << " [Peer BW limit] " << s.max_up_rate_kbs << " / " << s.max_dl_rate_kbs << std::endl;
}
RsNodeGroupItem::RsNodeGroupItem(const RsGroupInfo& g)
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_PEER_CONFIG, RS_PKT_SUBTYPE_NODE_GROUP)

View file

@ -84,7 +84,7 @@ public:
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
/* networking information */
RsPeerId peerId; /* Mandatory */
RsPeerId nodePeerId; /* Mandatory */
RsPgpId pgpId; /* Mandatory */
std::string location; /* Mandatory */
uint32_t netMode; /* Mandatory */

View file

@ -91,48 +91,6 @@ void RsFileTransferSingleChunkCrcItem::serial_process(RsGenericSerializer::Seria
RsTypeSerializer::serial_process (j,ctx,check_sum, "check_sum") ;
}
//===================================================================================================//
// CompressedChunkMap //
//===================================================================================================//
template<> uint32_t RsTypeSerializer::serial_size(const CompressedChunkMap& s)
{
return 4 + 4*s._map.size() ;
}
template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset,const CompressedChunkMap& s)
{
bool ok = true ;
ok &= setRawUInt32(data, size, &offset, s._map.size());
for(uint32_t i=0;i<s._map.size() && ok;++i)
ok &= setRawUInt32(data, size, &offset, s._map[i]);
return ok;
}
template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size,uint32_t& offset,CompressedChunkMap& s)
{
uint32_t S =0;
bool ok = getRawUInt32(data, size, &offset, &S);
if(ok)
{
s._map.resize(S) ;
for(uint32_t i=0;i<S && ok;++i)
ok &= getRawUInt32(data, size, &offset, &(s._map[i]));
}
return ok;
}
template<> void RsTypeSerializer::print_data(const std::string& n, const CompressedChunkMap& s)
{
std::cerr << " [Compressed chunk map] " << n << " : length=" << s._map.size() << std::endl;
}
//===================================================================================================//
// Serializer //
//===================================================================================================//

View file

@ -97,31 +97,6 @@ void RsGxsMsgUpdateItem::serial_process(RsGenericSerializer::SerializeJob j,RsGe
RsTypeSerializer::serial_process(j,ctx,msgUpdateInfos,"msgUpdateInfos");
}
template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset, const RsGxsMsgUpdateItem::MsgUpdateInfo& info)
{
bool ok = true ;
ok = ok && setRawUInt32(data,size,&offset,info.time_stamp);
ok = ok && setRawUInt32(data,size,&offset,info.message_count);
return ok;
}
template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, RsGxsMsgUpdateItem::MsgUpdateInfo& info)
{
bool ok = true ;
ok = ok && getRawUInt32(data,size,&offset,&info.time_stamp);
ok = ok && getRawUInt32(data,size,&offset,&info.message_count);
return ok;
}
template<> uint32_t RsTypeSerializer::serial_size(const RsGxsMsgUpdateItem::MsgUpdateInfo& /* info */) { return 8; }
template<> void RsTypeSerializer::print_data(const std::string& name,const RsGxsMsgUpdateItem::MsgUpdateInfo& info)
{
std::cerr << "[MsgUpdateInfo]: " << name << ": " << info.time_stamp << ", " << info.message_count << std::endl;
}
void RsGxsServerMsgUpdateItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process (j,ctx,grpId,"grpId");
@ -134,5 +109,3 @@ void RsGxsGrpConfigItem::serial_process(RsGenericSerializer::SerializeJob j,RsGe
RsTypeSerializer::serial_process<uint32_t>(j,ctx,msg_send_delay,"msg_send_delay") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,msg_req_delay,"msg_req_delay") ;
}

View file

@ -28,18 +28,11 @@
#if 0
#include <map>
#include "rsitems/rsserviceids.h"
#include "serialiser/rsserial.h"
#include "serialiser/rstlvbase.h"
#include "serialiser/rstlvtypes.h"
#include "serialiser/rstlvkeys.h"
#endif
#include "gxs/rsgxs.h"
#include "gxs/rsgxsdata.h"
#include "serialiser/rstlvidset.h"
#include "serialiser/rstypeserializer.h"
#include "serialiser/rsserializable.h"
const uint8_t RS_PKT_SUBTYPE_GXS_GRP_UPDATE = 0x01;
@ -140,17 +133,26 @@ public:
class RsGxsMsgUpdate
{
public:
struct MsgUpdateInfo
struct MsgUpdateInfo : RsSerializable
{
MsgUpdateInfo(): time_stamp(0), message_count(0) {}
uint32_t time_stamp ;
uint32_t message_count ;
/// @see RsSerializable
void serial_process(RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx)
{
RS_SERIAL_PROCESS(time_stamp);
RS_SERIAL_PROCESS(message_count);
}
};
std::map<RsGxsGroupId, MsgUpdateInfo> msgUpdateInfos;
};
class RsGxsMsgUpdateItem : public RsGxsNetServiceItem, public RsGxsMsgUpdate
{
public:

View file

@ -44,7 +44,7 @@ void RsHistoryMsgItem::serial_process(RsGenericSerializer::SerializeJob j,RsGene
RsTypeSerializer::serial_process<uint16_t>(j,ctx,version,"version") ;
RsTypeSerializer::serial_process (j,ctx,chatPeerId,"chatPeerId") ;
RsTypeSerializer::serial_process<bool> (j,ctx,incoming,"incoming") ;
RsTypeSerializer::serial_process (j,ctx,peerId,"peerId") ;
RsTypeSerializer::serial_process (j,ctx,msgPeerId,"peerId") ;
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_NAME,peerName,"peerName") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,sendTime,"sendTime") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,recvTime,"recvTime") ;

View file

@ -46,7 +46,7 @@ public:
RsPeerId chatPeerId; // empty for global chat
bool incoming;
RsPeerId peerId;
RsPeerId msgPeerId;
std::string peerName;
uint32_t sendTime;
uint32_t recvTime;

View file

@ -1,76 +1,96 @@
#pragma once
/*
* RetroShare Serialiser.
* 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 Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <typeinfo> // for typeid
#include "util/smallobject.h"
#include "retroshare/rstypes.h"
#include "serialiser/rsserializer.h"
#include "serialiser/rsserializable.h"
#include "util/stacktrace.h"
#include <typeinfo>
class RsItem: public RsMemoryManagement::SmallObject
struct RsItem : RsMemoryManagement::SmallObject, RsSerializable
{
public:
explicit RsItem(uint32_t t);
RsItem(uint8_t ver, uint8_t cls, uint8_t t, uint8_t subtype);
explicit RsItem(uint32_t t);
RsItem(uint8_t ver, uint8_t cls, uint8_t t, uint8_t subtype);
#ifdef DO_STATISTICS
void *operator new(size_t s) ;
void operator delete(void *,size_t s) ;
void *operator new(size_t s) ;
void operator delete(void *,size_t s) ;
#endif
virtual ~RsItem();
virtual ~RsItem();
/// TODO: Do this make sense with the new serialization system?
virtual void clear() = 0;
/// TODO: Do this make sense with the new serialization system?
virtual void clear() = 0;
virtual std::ostream &print(std::ostream &out, uint16_t /* indent */ = 0)
{
RsGenericSerializer::SerializeContext ctx(NULL,0,RsGenericSerializer::FORMAT_BINARY,RsGenericSerializer::SERIALIZATION_FLAG_NONE);
serial_process(RsGenericSerializer::PRINT,ctx) ;
return out;
}
virtual std::ostream &print(std::ostream &out, uint16_t /* indent */ = 0)
{
RsGenericSerializer::SerializeContext ctx(
NULL, 0, RsGenericSerializer::FORMAT_BINARY,
RsGenericSerializer::SERIALIZATION_FLAG_NONE );
serial_process(RsGenericSerializer::PRINT,ctx);
return out;
}
void print_string(std::string &out, uint16_t indent = 0);
void print_string(std::string &out, uint16_t indent = 0);
/* source / destination id */
const RsPeerId& PeerId() const { return peerId; }
void PeerId(const RsPeerId& id) { peerId = id; }
/// source / destination id
const RsPeerId& PeerId() const { return peerId; }
void PeerId(const RsPeerId& id) { peerId = id; }
/* complete id */
uint32_t PacketId() const;
/// complete id
uint32_t PacketId() const;
/* id parts */
uint8_t PacketVersion();
uint8_t PacketClass();
uint8_t PacketType();
uint8_t PacketSubType() const;
/// id parts
uint8_t PacketVersion();
uint8_t PacketClass();
uint8_t PacketType();
uint8_t PacketSubType() const;
/* For Service Packets */
RsItem(uint8_t ver, uint16_t service, uint8_t subtype);
uint16_t PacketService() const; /* combined Packet class/type (mid 16bits) */
void setPacketService(uint16_t service);
/// For Service Packets
RsItem(uint8_t ver, uint16_t service, uint8_t subtype);
uint16_t PacketService() const; /* combined Packet class/type (mid 16bits) */
void setPacketService(uint16_t service);
inline uint8_t priority_level() const { return _priority_level ;}
inline void setPriorityLevel(uint8_t l) { _priority_level = l ;}
inline uint8_t priority_level() const { return _priority_level ;}
inline void setPriorityLevel(uint8_t l) { _priority_level = l ;}
/**
* TODO: This should be made pure virtual as soon as all the codebase
* is ported to the new serialization system
*/
virtual void serial_process(RsGenericSerializer::SerializeJob,
RsGenericSerializer::SerializeContext&)// = 0;
{
std::cerr << "(EE) RsItem::serial_process() called by an item using"
<< "new serialization classes, but not derived! Class is "
<< typeid(*this).name() << std::endl;
print_stacktrace();
}
/**
* TODO: This default implementation should be removed and childs structs
* implement ::serial_process(...) as soon as all the codebase is ported to
* the new serialization system
*/
virtual void serial_process(RsGenericSerializer::SerializeJob,
RsGenericSerializer::SerializeContext&)// = 0;
{
std::cerr << "(EE) RsItem::serial_process(...) called by an item using"
<< "new serialization classes, but not derived! Class is "
<< typeid(*this).name() << std::endl;
print_stacktrace();
}
protected:
uint32_t type;
RsPeerId peerId;
uint8_t _priority_level ;
protected:
uint32_t type;
RsPeerId peerId;
uint8_t _priority_level;
};
/// TODO: Do this make sense with the new serialization system?

View file

@ -73,12 +73,12 @@ void RsNxsSyncMsgItem::serial_process(RsGenericSerializer::SerializeJob j,RsGene
void RsNxsMsg::serial_process( RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx )
{
RS_REGISTER_SERIAL_MEMBER_TYPED(transactionNumber, uint32_t);
RS_REGISTER_SERIAL_MEMBER_TYPED(pos, uint8_t);
RS_REGISTER_SERIAL_MEMBER(msgId);
RS_REGISTER_SERIAL_MEMBER(grpId);
RS_REGISTER_SERIAL_MEMBER_TYPED(msg, RsTlvItem);
RS_REGISTER_SERIAL_MEMBER_TYPED(meta, RsTlvItem);
RS_SERIAL_PROCESS(transactionNumber);
RS_SERIAL_PROCESS(pos);
RS_SERIAL_PROCESS(msgId);
RS_SERIAL_PROCESS(grpId);
RS_SERIAL_PROCESS(msg);
RS_SERIAL_PROCESS(meta);
}
void RsNxsGrp::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)

View file

@ -61,24 +61,23 @@ void RsGxsPhotoAlbumItem::serial_process(RsGenericSerializer::SerializeJob j,RsG
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_LOCATION, album.mWhere, "mWhere");
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_PIC_TYPE, album.mThumbnail.type,"mThumbnail.type");
RsTlvBinaryDataRef b(RS_SERVICE_GXS_TYPE_PHOTO, album.mThumbnail.data,album.mThumbnail.size);
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,b,"thumbnail binary data") ;
RsTlvBinaryDataRef b(RS_SERVICE_GXS_TYPE_PHOTO, album.mThumbnail.data, album.mThumbnail.size);
RsTypeSerializer::serial_process<RsTlvItem>(j, ctx, b, "thumbnail binary data") ;
}
void RsGxsPhotoPhotoItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process(j,ctx, TLV_TYPE_STR_CAPTION, photo.mCaption);
RsTypeSerializer::serial_process(j,ctx, TLV_TYPE_STR_CATEGORY, photo.mCategory);
RsTypeSerializer::serial_process(j,ctx, TLV_TYPE_STR_DESCR, photo.mDescription);
RsTypeSerializer::serial_process(j,ctx, TLV_TYPE_STR_HASH_TAG, photo.mHashTags);
RsTypeSerializer::serial_process(j,ctx, TLV_TYPE_STR_MSG, photo.mOther);
RsTypeSerializer::serial_process(j,ctx, TLV_TYPE_STR_PIC_AUTH, photo.mPhotographer);
RsTypeSerializer::serial_process(j,ctx, TLV_TYPE_STR_DATE, photo.mWhen);
RsTypeSerializer::serial_process(j,ctx, TLV_TYPE_STR_LOCATION, photo.mWhere);
RsTypeSerializer::serial_process(j,ctx, TLV_TYPE_STR_PIC_TYPE, photo.mThumbnail.type);
RsTypeSerializer::serial_process(j, ctx, TLV_TYPE_STR_CAPTION, photo.mCaption, "mCaption");
RsTypeSerializer::serial_process(j, ctx, TLV_TYPE_STR_CATEGORY, photo.mCategory, "mCategory");
RsTypeSerializer::serial_process(j, ctx, TLV_TYPE_STR_DESCR, photo.mDescription, "mDescription");
RsTypeSerializer::serial_process(j, ctx, TLV_TYPE_STR_HASH_TAG, photo.mHashTags, "mHashTags");
RsTypeSerializer::serial_process(j, ctx, TLV_TYPE_STR_MSG, photo.mOther, "mOther");
RsTypeSerializer::serial_process(j, ctx, TLV_TYPE_STR_PIC_AUTH, photo.mPhotographer, "mPhotographer");
RsTypeSerializer::serial_process(j, ctx, TLV_TYPE_STR_DATE, photo.mWhen, "mWhen");
RsTypeSerializer::serial_process(j, ctx, TLV_TYPE_STR_LOCATION, photo.mWhere, "mWhere");
RsTypeSerializer::serial_process(j, ctx, TLV_TYPE_STR_PIC_TYPE, photo.mThumbnail.type, "mThumbnail.type");
RsTlvBinaryDataRef b(RS_SERVICE_GXS_TYPE_PHOTO,photo.mThumbnail.data, photo.mThumbnail.size);
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx, b, "mThumbnail") ;
RsTlvBinaryDataRef b(RS_SERVICE_GXS_TYPE_PHOTO, photo.mThumbnail.data, photo.mThumbnail.size);
RsTypeSerializer::serial_process<RsTlvItem>(j, ctx, b, "mThumbnail") ;
}
void RsGxsPhotoCommentItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{

View file

@ -50,7 +50,7 @@ public:
virtual ~RsGxsPhotoAlbumItem() { return;}
void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
// std::ostream &print(std::ostream &out, uint16_t indent = 0);
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);

View file

@ -336,8 +336,8 @@ bool p3Peers::getPeerDetails(const RsPeerId& id, RsPeerDetails &d)
if(!sockaddr_storage_isnull(ps.localaddr))
{
sockaddr_storage_ipv6_to_ipv4(ps.localaddr);
d.localAddr = sockaddr_storage_iptostring(ps.localaddr);
d.localPort = sockaddr_storage_port(ps.localaddr);
d.localAddr = sockaddr_storage_iptostring(ps.localaddr);
d.localPort = sockaddr_storage_port(ps.localaddr);
}
else
{

View file

@ -1351,11 +1351,11 @@ int RsServer::StartupRetroShare()
p3Wiki *mWiki = new p3Wiki(wiki_ds, NULL, mGxsIdService);
// create GXS wiki service
RsGxsNetService* wiki_ns = new RsGxsNetService(
RS_SERVICE_GXS_TYPE_WIKI, wiki_ds, nxsMgr,
mWiki, mWiki->getServiceInfo(),
mGxsIdService, mGxsCircles,
pgpAuxUtils);
RsGxsNetService* wiki_ns = new RsGxsNetService(
RS_SERVICE_GXS_TYPE_WIKI, wiki_ds, nxsMgr,
mWiki, mWiki->getServiceInfo(),
mReputations, mGxsCircles, mGxsIdService,
pgpAuxUtils);
mWiki->setNetworkExchangeService(wiki_ns) ;
#endif

View file

@ -109,6 +109,19 @@ GnomeKeyringPasswordSchema my_schema = {
NULL,
NULL
};
#elif defined(HAS_LIBSECRET)
#include <libsecret-1/libsecret/secret.h>
const SecretSchema *libsecret_get_schema(void)
{
static const SecretSchema the_schema = {
"org.Retroshare.Password", SECRET_SCHEMA_NONE,
{
{ "RetroShare SSL Id", SECRET_SCHEMA_ATTRIBUTE_STRING },
{ "NULL", (SecretSchemaAttributeType)0 },
}
};
return &the_schema;
}
#endif
@ -209,7 +222,7 @@ bool RsLoginHandler::tryAutoLogin(const RsPeerId& ssl_id,std::string& ssl_passwd
#endif
if( gnome_keyring_find_password_sync(&my_schema, &passwd,"RetroShare SSL Id",ssl_id.toStdString().c_str(),NULL) == GNOME_KEYRING_RESULT_OK )
{
std::cerr << "Got SSL passwd ********************" /*<< passwd*/ << " from gnome keyring" << std::endl;
std::cout << "Got SSL passwd ********************" /*<< passwd*/ << " from gnome keyring" << std::endl;
ssl_passwd = std::string(passwd);
return true ;
}
@ -220,7 +233,41 @@ bool RsLoginHandler::tryAutoLogin(const RsPeerId& ssl_id,std::string& ssl_passwd
#endif
return false ;
}
#elif defined(HAS_LIBSECRET)
// do synchronous lookup
#ifdef DEBUG_RSLOGINHANDLER
std::cerr << "Using attribute: " << ssl_id << std::endl;
#endif
GError *error = NULL;
gchar *password = secret_password_lookup_sync (libsecret_get_schema(), NULL, &error,
"RetroShare SSL Id", ssl_id.toStdString().c_str(),
NULL);
if (error != NULL) {
g_error_free (error);
#ifdef DEBUG_RSLOGINHANDLER
std::cerr << "Could not get passwd using libsecret: error" << std::endl;
#endif
return false;
} else if (password == NULL) {
/* password will be null, if no matching password found */
#ifdef DEBUG_RSLOGINHANDLER
std::cerr << "Could not get passwd using libsecret: not found" << std::endl;
#endif
return false;
} else {
std::cout << "Got SSL passwd ********************" /*<< passwd*/ << " using libsecret" << std::endl;
ssl_passwd = std::string(password);
secret_password_free (password);
return true;
}
#ifdef DEBUG_RSLOGINHANDLER
std::cerr << "Could not get passwd from gnome keyring: unknown" << std::endl;
#endif
return false;
#else
/******************** OSX KeyChain stuff *****************************/
#ifdef __APPLE__
@ -281,7 +328,7 @@ bool RsLoginHandler::tryAutoLogin(const RsPeerId& ssl_id,std::string& ssl_passwd
/******************** OSX KeyChain stuff *****************************/
#endif // APPLE
#endif // HAS_GNOME_KEYRING
#endif // HAS_GNOME_KEYRING / HAS_LIBSECRET
#else /******* WINDOWS BELOW *****/
/* try to load from file */
@ -405,9 +452,9 @@ bool RsLoginHandler::enableAutoLogin(const RsPeerId& ssl_id,const std::string& s
#ifndef __HAIKU__
#ifndef WINDOWS_SYS /* UNIX */
#if defined(HAS_GNOME_KEYRING) || defined(__FreeBSD__) || defined(__OpenBSD__)
if(GNOME_KEYRING_RESULT_OK == gnome_keyring_store_password_sync(&my_schema, NULL, (gchar*)("RetroShare password for SSL Id "+ssl_id.toStdString()).c_str(),(gchar*)ssl_passwd.c_str(),"RetroShare SSL Id",ssl_id.toStdString().c_str(),NULL))
if(GNOME_KEYRING_RESULT_OK == gnome_keyring_store_password_sync(&my_schema, NULL, (gchar*)("RetroShare password for SSL Id "+ssl_id.toStdString()).c_str(),(gchar*)ssl_passwd.c_str(),"RetroShare SSL Id",ssl_id.toStdString().c_str(),NULL))
{
std::cerr << "Stored passwd " << "************************" << " into gnome keyring" << std::endl;
std::cout << "Stored passwd " << "************************" << " into gnome keyring" << std::endl;
return true ;
}
else
@ -415,6 +462,24 @@ bool RsLoginHandler::enableAutoLogin(const RsPeerId& ssl_id,const std::string& s
std::cerr << "Could not store passwd into gnome keyring" << std::endl;
return false ;
}
#elif defined(HAS_LIBSECRET)
// do synchronous store
GError *error = NULL;
secret_password_store_sync (libsecret_get_schema(), SECRET_COLLECTION_DEFAULT,
(gchar*)("RetroShare password for SSL Id " + ssl_id.toStdString()).c_str(),
(gchar*)ssl_passwd.c_str(),
NULL, &error,
"RetroShare SSL Id", ssl_id.toStdString().c_str(),
NULL);
if (error != NULL) {
g_error_free (error);
std::cerr << "Could not store passwd using libsecret" << std::endl;
return false;
}
std::cout << "Stored passwd " << "************************" << " using libsecret" << std::endl;
return true;
#else
#ifdef __APPLE__
/***************** OSX KEYCHAIN ****************/
@ -484,7 +549,7 @@ bool RsLoginHandler::enableAutoLogin(const RsPeerId& ssl_id,const std::string& s
return true;
#endif // TODO_CODE_ROTTEN
#endif // __APPLE__
#endif // HAS_GNOME_KEYRING.
#endif // HAS_GNOME_KEYRING / HAS_LIBSECRET
#else /* windows */
/* store password encrypted in a file */
@ -571,7 +636,7 @@ bool RsLoginHandler::clearAutoLogin(const RsPeerId& ssl_id)
#ifdef HAS_GNOME_KEYRING
if(GNOME_KEYRING_RESULT_OK == gnome_keyring_delete_password_sync(&my_schema,"RetroShare SSL Id", ssl_id.toStdString().c_str(),NULL))
{
std::cerr << "Successfully Cleared gnome keyring passwd for SSLID " << ssl_id << std::endl;
std::cout << "Successfully Cleared gnome keyring passwd for SSLID " << ssl_id << std::endl;
return true ;
}
else
@ -579,7 +644,26 @@ bool RsLoginHandler::clearAutoLogin(const RsPeerId& ssl_id)
std::cerr << "Could not clear gnome keyring passwd for SSLID " << ssl_id << std::endl;
return false ;
}
#else
#elif defined(HAS_LIBSECRET)
// do synchronous clear
GError *error = NULL;
gboolean removed = secret_password_clear_sync (libsecret_get_schema(), NULL, &error,
"RetroShare SSL Id", ssl_id.toStdString().c_str(),
NULL);
if (error != NULL) {
g_error_free (error);
std::cerr << "Could not clearpasswd for SSLID " << ssl_id << " using libsecret: error" << std::endl;
return false ;
} else if (removed == FALSE) {
std::cerr << "Could not clearpasswd for SSLID " << ssl_id << " using libsecret: false" << std::endl;
return false ;
}
std::cout << "Successfully Cleared passwd for SSLID " << ssl_id << " using libsecret" << std::endl;
return true ;
#else // HAS_GNOME_KEYRING / HAS_LIBSECRET
#ifdef __APPLE__
std::cerr << "clearAutoLogin() OSX Version" << std::endl;

View file

@ -75,5 +75,3 @@ std::ostream &operator<<(std::ostream &out, const FileInfo &info)
out << "Hash: " << info.hash;
return out;
}

View file

@ -238,8 +238,7 @@ uint32_t getRawStringSize(const std::string &outStr)
bool getRawString(const void *data, uint32_t size, uint32_t *offset, std::string &outStr)
{
#warning Gio: "I had to change this. It seems like a bug to not clear the string. Should make sure it's not introducing any side effect."
outStr.clear();
outStr.clear();
uint32_t len = 0;
if (!getRawUInt32(data, size, offset, &len))

View file

@ -64,7 +64,7 @@ const uint8_t RS_PKT_CLASS_CONFIG = 0x02;
const uint8_t RS_PKT_SUBTYPE_DEFAULT = 0x01; /* if only one subtype */
class RsItem ;
struct RsItem;
class RsSerialType ;

View file

@ -0,0 +1,48 @@
#pragma once
/*
* RetroShare Serialiser.
* Copyright (C) 2016-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 Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "serialiser/rsserializer.h"
/** @brief Minimal ancestor for all serializable structs in RetroShare.
* If you want your struct to be easly serializable you should inherit from this
* struct.
*/
struct RsSerializable
{
/** Process struct members to serialize in this method taking advantage of
* the helper macro @see RS_SERIAL_PROCESS(I)
*/
virtual void serial_process(RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx) = 0;
};
/** @def RS_SERIAL_PROCESS(I)
* Use this macro to process the members of `YourSerializable` for serial
* processing inside `YourSerializable::serial_process(j, ctx)`
*
* Pay special attention for member of enum type which must be declared
* specifying the underlying type otherwise the serialization format may differ
* in an uncompatible way depending on the compiler/platform.
*
* Inspired by http://stackoverflow.com/a/39345864
*/
#define RS_SERIAL_PROCESS(I) do { \
RsTypeSerializer::serial_process(j, ctx, I, #I ); \
} while(0)

View file

@ -3,7 +3,8 @@
*
* RetroShare Serialiser.
*
* Copyright 2016 by Cyril Soler
* Copyright (C) 2016 Cyril Soler
* 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
@ -153,11 +154,13 @@
#include <string.h>
#include <iostream>
#include <string>
#include <rapid_json/document.h>
#include "retroshare/rsflags.h"
#include "serialiser/rsserial.h"
#include "util/rsdeprecate.h"
class RsItem ;
struct RsItem;
#define SERIALIZE_ERROR() std::cerr << __PRETTY_FUNCTION__ << " : "
@ -194,106 +197,132 @@ class RsRawSerialiser: public RsSerialType
virtual RsItem * deserialise(void *data, uint32_t *size);
};
// Top class for all services and config serializers.
typedef rapidjson::Document RsJson;
class RsGenericSerializer: public RsSerialType
/// Top class for all services and config serializers.
struct RsGenericSerializer : RsSerialType
{
public:
typedef enum { SIZE_ESTIMATE = 0x01, SERIALIZE = 0x02, DESERIALIZE = 0x03, PRINT=0x04 } SerializeJob ;
typedef enum { FORMAT_BINARY = 0x01, FORMAT_JSON = 0x02 } SerializationFormat ;
class SerializeContext
{
public:
typedef enum
{
SIZE_ESTIMATE = 0x01,
SERIALIZE = 0x02,
DESERIALIZE = 0x03,
PRINT = 0x04,
TO_JSON,
FROM_JSON
} SerializeJob;
SerializeContext(uint8_t *data,uint32_t size,SerializationFormat format,SerializationFlags flags)
: mData(data),mSize(size),mOffset(0),mOk(true),mFormat(format),mFlags(flags) {}
/** @deprecated use SerializeJob instead */
RS_DEPRECATED typedef enum
{
FORMAT_BINARY = 0x01,
FORMAT_JSON = 0x02
} SerializationFormat;
unsigned char *mData ;
uint32_t mSize ;
uint32_t mOffset ;
bool mOk ;
SerializationFormat mFormat ;
SerializationFlags mFlags ;
};
struct SerializeContext
{
/** Allow shared allocator usage to avoid costly JSON deepcopy for
* nested RsSerializable */
SerializeContext(
uint8_t *data, uint32_t size,
SerializationFlags flags = SERIALIZATION_FLAG_NONE,
RsJson::AllocatorType* allocator = nullptr) :
mData(data), mSize(size), mOffset(0), mOk(true), mFlags(flags),
mJson(rapidjson::kObjectType, allocator) {}
// These are convenience flags to be used by the items when processing the data. The names of the flags
// are not very important. What matters is that the serial_process() method of each item correctly
// deals with the data when it sees the flags, if the serialiser sets them. By default the flags are not
// set and shouldn't be handled.
// When deriving a new serializer, the user can set his own flags, using compatible values
RS_DEPRECATED SerializeContext(
uint8_t *data, uint32_t size, SerializationFormat format,
SerializationFlags flags,
RsJson::AllocatorType* allocator = nullptr) :
mData(data), mSize(size), mOffset(0), mOk(true), mFormat(format),
mFlags(flags), mJson(rapidjson::kObjectType, allocator) {}
static const SerializationFlags SERIALIZATION_FLAG_NONE ; // 0x0000
static const SerializationFlags SERIALIZATION_FLAG_CONFIG ; // 0x0001
static const SerializationFlags SERIALIZATION_FLAG_SIGNATURE ; // 0x0002
static const SerializationFlags SERIALIZATION_FLAG_SKIP_HEADER ; // 0x0004
unsigned char *mData;
uint32_t mSize;
uint32_t mOffset;
bool mOk;
RS_DEPRECATED SerializationFormat mFormat;
SerializationFlags mFlags;
RsJson mJson;
};
// The following functions overload RsSerialType. They *should not* need to be further overloaded.
/** These are convenience flags to be used by the items when processing the
* data. The names of the flags are not very important. What matters is that
* the serial_process() method of each item correctly deals with the data
* when it sees the flags, if the serialiser sets them.
* By default the flags are not set and shouldn't be handled.
* When deriving a new serializer, the user can set his own flags, using
* compatible values
*/
static const SerializationFlags SERIALIZATION_FLAG_NONE; // 0x0000
static const SerializationFlags SERIALIZATION_FLAG_CONFIG; // 0x0001
static const SerializationFlags SERIALIZATION_FLAG_SIGNATURE; // 0x0002
static const SerializationFlags SERIALIZATION_FLAG_SKIP_HEADER; // 0x0004
RsItem *deserialise(void *data,uint32_t *size) =0;
bool serialise(RsItem *item,void *data,uint32_t *size) ;
uint32_t size(RsItem *item) ;
void print(RsItem *item) ;
/**
* The following functions overload RsSerialType.
* They *should not* need to be further overloaded.
*/
RsItem *deserialise(void *data,uint32_t *size) = 0;
bool serialise(RsItem *item,void *data,uint32_t *size);
uint32_t size(RsItem *item);
void print(RsItem *item);
protected:
RsGenericSerializer(uint8_t serial_class,
uint8_t serial_type,
SerializationFormat format,
SerializationFlags flags )
: RsSerialType(RS_PKT_VERSION1,serial_class,serial_type), mFormat(format),mFlags(flags)
{}
RsGenericSerializer(
uint8_t serial_class, uint8_t serial_type,
SerializationFormat format, SerializationFlags flags ) :
RsSerialType( RS_PKT_VERSION1, serial_class, serial_type),
mFormat(format), mFlags(flags) {}
RsGenericSerializer(uint16_t service,
SerializationFormat format,
SerializationFlags flags )
: RsSerialType(RS_PKT_VERSION_SERVICE,service), mFormat(format),mFlags(flags)
{}
SerializationFormat mFormat ;
SerializationFlags mFlags ;
RsGenericSerializer(
uint16_t service, SerializationFormat format,
SerializationFlags flags ) :
RsSerialType( RS_PKT_VERSION_SERVICE, service ), mFormat(format),
mFlags(flags) {}
SerializationFormat mFormat;
SerializationFlags mFlags;
};
// Top class for service serializers. Derive your on service serializer from this class and overload creat_item().
class RsServiceSerializer: public RsGenericSerializer
/** Top class for service serializers.
* Derive your on service serializer from this class and overload creat_item().
*/
struct RsServiceSerializer : RsGenericSerializer
{
public:
RsServiceSerializer(uint16_t service_id,
SerializationFormat format = FORMAT_BINARY,
SerializationFlags flags = SERIALIZATION_FLAG_NONE)
RsServiceSerializer(
uint16_t service_id, SerializationFormat format = FORMAT_BINARY,
SerializationFlags flags = SERIALIZATION_FLAG_NONE ) :
RsGenericSerializer(service_id, format, flags) {}
: RsGenericSerializer(service_id,format,flags) {}
/*! should be overloaded to create the correct type of item depending on the
* data */
virtual RsItem *create_item( uint16_t /* service */,
uint8_t /* item_sub_id */ ) const = 0;
/*! create_item
* should be overloaded to create the correct type of item depending on the data
*/
virtual RsItem *create_item(uint16_t /* service */, uint8_t /* item_sub_id */) const=0;
RsItem *deserialise(void *data,uint32_t *size) ;
RsItem *deserialise(void *data, uint32_t *size);
};
// Top class for config serializers. Config serializers are only used internally by RS core. The development of new services or plugins do not need this.
class RsConfigSerializer: public RsGenericSerializer
/** Top class for config serializers.
* Config serializers are only used internally by RS core.
* The development of new services or plugins do not need this.
*/
struct RsConfigSerializer : RsGenericSerializer
{
public:
RsConfigSerializer(uint8_t config_class,
uint8_t config_type,
SerializationFormat format = FORMAT_BINARY,
SerializationFlags flags = SERIALIZATION_FLAG_NONE)
SerializationFlags flags = SERIALIZATION_FLAG_NONE) :
RsGenericSerializer(config_class,config_type,format,flags) {}
: RsGenericSerializer(config_class,config_type,format,flags) {}
/*! should be overloaded to create the correct type of item depending on the
* data */
virtual RsItem *create_item(uint8_t /* item_type */,
uint8_t /* item_sub_type */) const = 0;
/*! create_item
* should be overloaded to create the correct type of item depending on the data
*/
virtual RsItem *create_item(uint8_t /* item_type */, uint8_t /* item_sub_type */) const=0;
RsItem *deserialise(void *data,uint32_t *size) ;
RsItem *deserialise(void *data,uint32_t *size);
};

View file

@ -3,7 +3,8 @@
*
* RetroShare Serialiser.
*
* Copyright 2017 by Cyril Soler
* Copyright (C) 2017 Cyril Soler
* 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,27 +27,49 @@
#include "serialiser/rstypeserializer.h"
#include "serialiser/rsbaseserial.h"
#include "serialiser/rstlvkeys.h"
#include "rsitems/rsitem.h"
#include "serialiser/rsserializable.h"
#include "util/rsprint.h"
#include <iomanip>
#include <typeinfo>
#include <time.h>
#include <string>
#include <typeinfo> // for typeid
#include <rapid_json/document.h>
#include <rapid_json/prettywriter.h>
//static const uint32_t MAX_SERIALIZED_ARRAY_SIZE = 500 ;
static const uint32_t MAX_SERIALIZED_CHUNK_SIZE = 10*1024*1024 ; // 10 MB.
//=================================================================================================//
// Integer types //
//=================================================================================================//
#define SAFE_GET_JSON_V() \
const char* mName = memberName.c_str(); \
bool ret = jDoc.HasMember(mName); \
if(!ret) \
{ \
std::cerr << __PRETTY_FUNCTION__ << " \"" << memberName \
<< "\" not found in JSON:" << std::endl \
<< jDoc << std::endl << std::endl; \
print_stacktrace(); \
return false; \
} \
rapidjson::Value& v = jDoc[mName]
//============================================================================//
// Integer types //
//============================================================================//
template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset, const bool& member)
{
return setRawUInt8(data,size,&offset,member);
}
template<> bool RsTypeSerializer::serialize(uint8_t /*data*/[], uint32_t /*size*/, uint32_t& /*offset*/, const int32_t& /*member*/)
{
std::cerr << __PRETTY_FUNCTION__ << " Not implemented!" << std::endl;
print_stacktrace();
return false;
}
template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset, const uint8_t& member)
{
return setRawUInt8(data,size,&offset,member);
@ -70,10 +93,16 @@ template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint3
template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, bool& member)
{
uint8_t m ;
uint8_t m;
bool ok = getRawUInt8(data,size,&offset,&m);
member = m ;
return ok;
member = m;
return ok;
}
template<> bool RsTypeSerializer::deserialize(const uint8_t /*data*/[], uint32_t /*size*/, uint32_t& /*offset*/, int32_t& /*member*/)
{
std::cerr << __PRETTY_FUNCTION__ << " Not implemented!" << std::endl;
print_stacktrace();
return false;
}
template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, uint8_t& member)
{
@ -100,6 +129,12 @@ template<> uint32_t RsTypeSerializer::serial_size(const bool& /* member*/)
{
return 1;
}
template<> uint32_t RsTypeSerializer::serial_size(const int32_t& /* member*/)
{
std::cerr << __PRETTY_FUNCTION__ << " Not implemented!" << std::endl;
print_stacktrace();
return 0;
}
template<> uint32_t RsTypeSerializer::serial_size(const uint8_t& /* member*/)
{
return 1;
@ -125,6 +160,10 @@ template<> void RsTypeSerializer::print_data(const std::string& n, const bool &
{
std::cerr << " [bool ] " << n << ": " << V << std::endl;
}
template<> void RsTypeSerializer::print_data(const std::string& n, const int32_t& V)
{
std::cerr << " [int32_t ] " << n << ": " << V << std::endl;
}
template<> void RsTypeSerializer::print_data(const std::string& n, const uint8_t & V)
{
std::cerr << " [uint8_t ] " << n << ": " << V << std::endl;
@ -146,10 +185,121 @@ template<> void RsTypeSerializer::print_data(const std::string& n, const time_t&
std::cerr << " [time_t ] " << n << ": " << V << " (" << time(NULL)-V << " secs ago)" << std::endl;
}
#define SIMPLE_TO_JSON_DEF(T) \
template<> bool RsTypeSerializer::to_JSON( const std::string& memberName, \
const T& member, RsJson& jDoc ) \
{ \
rapidjson::Document::AllocatorType& allocator = jDoc.GetAllocator(); \
\
rapidjson::Value key; \
key.SetString(memberName.c_str(), memberName.length(), allocator); \
\
rapidjson::Value value(member); \
\
jDoc.AddMember(key, value, allocator); \
\
return true; \
}
//=================================================================================================//
// FLoats //
//=================================================================================================//
SIMPLE_TO_JSON_DEF(bool)
SIMPLE_TO_JSON_DEF(int32_t)
template<> bool RsTypeSerializer::to_JSON( const std::string& memberName,
const time_t& member, RsJson& jDoc )
{
rapidjson::Document::AllocatorType& allocator = jDoc.GetAllocator();
rapidjson::Value key;
key.SetString(memberName.c_str(), memberName.length(), allocator);
// without this compilation may break depending on how time_t is defined
int64_t tValue = member;
rapidjson::Value value(tValue);
jDoc.AddMember(key, value, allocator);
return true;
}
SIMPLE_TO_JSON_DEF(uint8_t)
SIMPLE_TO_JSON_DEF(uint16_t)
SIMPLE_TO_JSON_DEF(uint32_t)
SIMPLE_TO_JSON_DEF(uint64_t)
template<> /*static*/
bool RsTypeSerializer::from_JSON( const std::string& memberName, bool& member,
RsJson& jDoc )
{
SAFE_GET_JSON_V();
ret = ret && v.IsBool();
if(ret) member = v.GetBool();
return ret;
}
template<> /*static*/
bool RsTypeSerializer::from_JSON( const std::string& memberName,
int32_t& member, RsJson& jDoc )
{
SAFE_GET_JSON_V();
ret = ret && v.IsInt();
if(ret) member = v.GetInt();
return ret;
}
template<> /*static*/
bool RsTypeSerializer::from_JSON( const std::string& memberName, time_t& member,
RsJson& jDoc )
{
SAFE_GET_JSON_V();
ret = ret && v.IsInt();
if(ret) member = v.GetInt();
return ret;
}
template<> /*static*/
bool RsTypeSerializer::from_JSON( const std::string& memberName,
uint8_t& member, RsJson& jDoc )
{
SAFE_GET_JSON_V();
ret = ret && v.IsUint();
if(ret) member = v.GetUint();
return ret;
}
template<> /*static*/
bool RsTypeSerializer::from_JSON( const std::string& memberName,
uint16_t& member, RsJson& jDoc )
{
SAFE_GET_JSON_V();
ret = ret && v.IsUint();
if(ret) member = v.GetUint();
return ret;
}
template<> /*static*/
bool RsTypeSerializer::from_JSON( const std::string& memberName,
uint32_t& member, RsJson& jDoc )
{
SAFE_GET_JSON_V();
ret = ret && v.IsUint();
if(ret) member = v.GetUint();
return ret;
}
template<> /*static*/
bool RsTypeSerializer::from_JSON( const std::string& memberName,
uint64_t& member, RsJson& jDoc )
{
SAFE_GET_JSON_V();
ret = ret && v.IsUint64();
if(ret) member = v.GetUint64();
return ret;
}
//============================================================================//
// Floats //
//============================================================================//
template<> uint32_t RsTypeSerializer::serial_size(const float&){ return 4; }
@ -166,10 +316,75 @@ template<> void RsTypeSerializer::print_data(const std::string& n, const float&
std::cerr << " [float ] " << n << ": " << V << std::endl;
}
SIMPLE_TO_JSON_DEF(float)
//=================================================================================================//
// TlvString with subtype //
//=================================================================================================//
template<> /*static*/
bool RsTypeSerializer::from_JSON( const std::string& memberName,
float& member, RsJson& jDoc )
{
SAFE_GET_JSON_V();
ret = ret && v.IsFloat();
if(ret) member = v.GetFloat();
return ret;
}
//============================================================================//
// std::string //
//============================================================================//
template<> uint32_t RsTypeSerializer::serial_size(const std::string& str)
{
return getRawStringSize(str);
}
template<> bool RsTypeSerializer::serialize( uint8_t data[], uint32_t size,
uint32_t& offset,
const std::string& str )
{
return setRawString(data, size, &offset, str);
}
template<> bool RsTypeSerializer::deserialize( const uint8_t data[],
uint32_t size, uint32_t &offset,
std::string& str )
{
return getRawString(data, size, &offset, str);
}
template<> void RsTypeSerializer::print_data( const std::string& n,
const std::string& str )
{
std::cerr << " [std::string] " << n << ": " << str << std::endl;
}
template<> /*static*/
bool RsTypeSerializer::to_JSON( const std::string& membername,
const std::string& member, RsJson& jDoc )
{
rapidjson::Document::AllocatorType& allocator = jDoc.GetAllocator();
rapidjson::Value key;
key.SetString(membername.c_str(), membername.length(), allocator);
rapidjson::Value value;;
value.SetString(member.c_str(), member.length(), allocator);
jDoc.AddMember(key, value, allocator);
return true;
}
template<> /*static*/
bool RsTypeSerializer::from_JSON( const std::string& memberName,
std::string& member, RsJson& jDoc )
{
SAFE_GET_JSON_V();
ret = ret && v.IsString();
if(ret) member = v.GetString();
return ret;
}
//============================================================================//
// TlvString with subtype //
//============================================================================//
template<> uint32_t RsTypeSerializer::serial_size(uint16_t /* type_subtype */,const std::string& s)
{
@ -188,46 +403,131 @@ template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t siz
template<> void RsTypeSerializer::print_data(const std::string& n, uint16_t type_substring,const std::string& V)
{
std::cerr << " [TlvString ] " << n << ": type=" << std::hex <<std::setw(4)<<std::setfill('0') << type_substring << std::dec << " s=\"" << V<< "\"" << std::endl;
std::cerr << " [TlvString ] " << n << ": type=" << std::hex <<std::setw(4)<<std::setfill('0') << type_substring << std::dec << " s=\"" << V<< "\"" << std::endl;
}
//=================================================================================================//
// TlvInt with subtype //
//=================================================================================================//
template<> uint32_t RsTypeSerializer::serial_size(uint16_t /* type_subtype */,const uint32_t& /*s*/)
template<> /*static*/
bool RsTypeSerializer::to_JSON( const std::string& memberName,
uint16_t /*sub_type*/,
const std::string& member, RsJson& jDoc )
{
return GetTlvUInt32Size() ;
return to_JSON<std::string>(memberName, member, jDoc);
}
template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset,uint16_t sub_type,const uint32_t& s)
template<> /*static*/
bool RsTypeSerializer::from_JSON( const std::string& memberName,
uint16_t /*sub_type*/,
std::string& member, RsJson& jDoc )
{
return SetTlvUInt32(data,size,&offset,sub_type,s) ;
return from_JSON<std::string>(memberName, member, jDoc);
}
template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size,uint32_t& offset,uint16_t sub_type,uint32_t& s)
//============================================================================//
// TlvInt with subtype //
//============================================================================//
template<> uint32_t RsTypeSerializer::serial_size( uint16_t /* type_subtype */,
const uint32_t& /*s*/ )
{
return GetTlvUInt32((void*)data,size,&offset,sub_type,&s) ;
return GetTlvUInt32Size();
}
template<> bool RsTypeSerializer::serialize( uint8_t data[], uint32_t size,
uint32_t &offset,uint16_t sub_type,
const uint32_t& s)
{
return SetTlvUInt32(data,size,&offset,sub_type,s);
}
template<> bool RsTypeSerializer::deserialize( const uint8_t data[],
uint32_t size, uint32_t& offset,
uint16_t sub_type, uint32_t& s)
{
return GetTlvUInt32((void*)data, size, &offset, sub_type, &s);
}
template<> void RsTypeSerializer::print_data(const std::string& n, uint16_t sub_type,const uint32_t& V)
{
std::cerr << " [TlvUInt32 ] " << n << ": type=" << std::hex <<std::setw(4)<<std::setfill('0') << sub_type << std::dec << " s=\"" << V<< "\"" << std::endl;
std::cerr << " [TlvUInt32 ] " << n << ": type=" << std::hex
<< std::setw(4) << std::setfill('0') << sub_type << std::dec
<< " s=\"" << V << "\"" << std::endl;
}
//=================================================================================================//
// std::string //
//=================================================================================================//
template<> void RsTypeSerializer::print_data(const std::string& n, const std::string& V)
template<> /*static*/
bool RsTypeSerializer::to_JSON( const std::string& memberName,
uint16_t /*sub_type*/,
const uint32_t& member, RsJson& jDoc )
{
std::cerr << " [std::string] " << n << ": " << V << std::endl;
return to_JSON<uint32_t>(memberName, member, jDoc);
}
//=================================================================================================//
// Binary blocks //
//=================================================================================================//
template<> /*static*/
bool RsTypeSerializer::from_JSON( const std::string& memberName,
uint16_t /*sub_type*/,
uint32_t& member, RsJson& jDoc )
{
return from_JSON<uint32_t>(memberName, member, jDoc);
}
//============================================================================//
// TlvItems //
//============================================================================//
template<> uint32_t RsTypeSerializer::serial_size(const RsTlvItem& s)
{
return s.TlvSize();
}
template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size,
uint32_t &offset,const RsTlvItem& s)
{
return s.SetTlv(data,size,&offset);
}
template<> bool RsTypeSerializer::deserialize(const uint8_t data[],
uint32_t size,uint32_t& offset,
RsTlvItem& s)
{
return s.GetTlv((void*)data,size,&offset) ;
}
template<> void RsTypeSerializer::print_data( const std::string& n,
const RsTlvItem& s )
{
std::cerr << " [" << typeid(s).name() << "] " << n << std::endl;
}
template<> /*static*/
bool RsTypeSerializer::to_JSON( const std::string& memberName,
const RsTlvItem& member, RsJson& jDoc )
{
rapidjson::Document::AllocatorType& allocator = jDoc.GetAllocator();
rapidjson::Value key;
key.SetString(memberName.c_str(), memberName.length(), allocator);
rapidjson::Value value;
const char* tName = typeid(member).name();
value.SetString(tName, allocator);
jDoc.AddMember(key, value, allocator);
return true;
}
template<> /*static*/
bool RsTypeSerializer::from_JSON( const std::string& /*memberName*/,
RsTlvItem& member, RsJson& /*jDoc*/)
{
member.TlvClear();
return true;
}
//============================================================================//
// Binary blocks //
//============================================================================//
template<> uint32_t RsTypeSerializer::serial_size(const RsTypeSerializer::TlvMemBlock_proxy& r) { return 4 + r.second ; }
@ -286,82 +586,40 @@ template<> void RsTypeSerializer::print_data(const std::string& n, const RsTypeS
std::cerr << " [Binary data] " << n << ", length=" << s.second << " data=" << RsUtil::BinToHex((uint8_t*)s.first,std::min(50u,s.second)) << ((s.second>50)?"...":"") << std::endl;
}
//=================================================================================================//
// TlvItems //
//=================================================================================================//
template<> uint32_t RsTypeSerializer::serial_size(const RsTlvItem& s)
template<> /*static*/
bool RsTypeSerializer::to_JSON(
const std::string& memberName,
const RsTypeSerializer::TlvMemBlock_proxy& member, RsJson& jDoc )
{
return s.TlvSize() ;
}
rapidjson::Document::AllocatorType& allocator = jDoc.GetAllocator();
template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset,const RsTlvItem& s)
{
return s.SetTlv(data,size,&offset) ;
}
rapidjson::Value key;
key.SetString(memberName.c_str(), memberName.length(), allocator);
template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size,uint32_t& offset,RsTlvItem& s)
{
return s.GetTlv((void*)data,size,&offset) ;
}
rapidjson::Value value;
const char* tName = typeid(member).name();
value.SetString(tName, allocator);
template<> void RsTypeSerializer::print_data(const std::string& n, const RsTlvItem& s)
{
// can we call TlvPrint inside this?
jDoc.AddMember(key, value, allocator);
std::cerr << " [" << typeid(s).name() << "] " << n << std::endl;
}
//============================================================================//
// RsItem and derivated //
//============================================================================//
template<> uint32_t RsTypeSerializer::serial_size(const RsItem& s)
{
RsGenericSerializer::SerializeContext ctx(
NULL, 0, RsGenericSerializer::FORMAT_BINARY,
RsGenericSerializer::SERIALIZATION_FLAG_NONE );
ctx.mOffset = 8; // header size
const_cast<RsItem&>(s).serial_process(RsGenericSerializer::SIZE_ESTIMATE,
ctx);
return ctx.mOffset;
}
template<> bool RsTypeSerializer::serialize( uint8_t data[], uint32_t size,
uint32_t &offset, const RsItem& s )
{
RsGenericSerializer::SerializeContext ctx(
data, size, RsGenericSerializer::FORMAT_BINARY,
RsGenericSerializer::SERIALIZATION_FLAG_NONE );
ctx.mOffset = offset;
const_cast<RsItem&>(s).serial_process(RsGenericSerializer::SERIALIZE,
ctx);
return true;
}
template<> bool RsTypeSerializer::deserialize( const uint8_t data[],
uint32_t size, uint32_t& offset,
RsItem& s )
{
RsGenericSerializer::SerializeContext ctx(
const_cast<uint8_t*>(data), size,
RsGenericSerializer::FORMAT_BINARY,
RsGenericSerializer::SERIALIZATION_FLAG_NONE );
ctx.mOffset = offset;
const_cast<RsItem&>(s).serial_process(RsGenericSerializer::DESERIALIZE,
ctx);
return true;
}
template<> /*static*/
bool RsTypeSerializer::from_JSON( const std::string& /*memberName*/,
RsTypeSerializer::TlvMemBlock_proxy&,
RsJson& /*jDoc*/)
{ return true; }
template<> void RsTypeSerializer::print_data( const std::string& /*n*/,
const RsItem& s )
//============================================================================//
// RsJson std:ostream support //
//============================================================================//
std::ostream &operator<<(std::ostream &out, const RsJson &jDoc)
{
RsGenericSerializer::SerializeContext ctx(
NULL, 0,
RsGenericSerializer::FORMAT_BINARY,
RsGenericSerializer::SERIALIZATION_FLAG_NONE );
const_cast<RsItem&>(s).serial_process(RsGenericSerializer::PRINT,
ctx);
rapidjson::StringBuffer buffer; buffer.Clear();
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer);
jDoc.Accept(writer);
return out << buffer.GetString();
}

View file

@ -3,7 +3,8 @@
*
* RetroShare Serialiser.
*
* Copyright 2017 by Cyril Soler
* Copyright (C) 2017 Cyril Soler
* 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
@ -32,83 +33,95 @@
#include "retroshare/rsids.h"
#include "serialiser/rsserializer.h"
#include "serialiser/rsserializable.h"
/** @def RS_REGISTER_SERIAL_MEMBER(I)
* Use this macro to register the members of `YourItem` for serial processing
* inside `YourItem::serial_process(j, ctx)`
*
* Inspired by http://stackoverflow.com/a/39345864
#include <rapid_json/document.h>
#include <typeinfo> // for typeid
#include <type_traits>
#include <errno.h>
/** INTERNAL ONLY helper to avoid copy paste code for std::{vector,list,set}<T>
* Can't use a template function because T is needed for const_cast */
#define RsTypeSerializer_PRIVATE_TO_JSON_ARRAY() do \
{ \
using namespace rapidjson; \
\
Document::AllocatorType& allocator = ctx.mJson.GetAllocator(); \
\
Value arrKey; arrKey.SetString(memberName.c_str(), allocator); \
\
Value arr(kArrayType); \
\
for (auto& el : v) \
{ \
/* Use same allocator to avoid deep copy */\
RsGenericSerializer::SerializeContext elCtx(\
nullptr, 0, RsGenericSerializer::FORMAT_BINARY,\
RsGenericSerializer::SERIALIZATION_FLAG_NONE,\
&allocator );\
\
/* If el is const the default serial_process template is matched */ \
/* also when specialization is necessary so the compilation break */ \
serial_process(j, elCtx, const_cast<T&>(el), memberName); \
\
elCtx.mOk = elCtx.mOk && elCtx.mJson.HasMember(arrKey);\
if(elCtx.mOk) arr.PushBack(elCtx.mJson[arrKey], allocator);\
else\
{\
ctx.mOk = false;\
break;\
}\
}\
\
ctx.mJson.AddMember(arrKey, arr, allocator);\
} while (false)
/** INTERNAL ONLY helper to avoid copy paste code for std::{vector,list,set}<T>
* Can't use a template function because std::{vector,list,set}<T> has different
* name for insert/push_back function
*/
#define RS_REGISTER_SERIAL_MEMBER(I) \
do { RsTypeSerializer::serial_process(j, ctx, I, #I); } while(0)
#define RsTypeSerializer_PRIVATE_FROM_JSON_ARRAY(INSERT_FUN) do\
{\
using namespace rapidjson;\
\
bool& ok(ctx.mOk);\
Document& jDoc(ctx.mJson);\
Document::AllocatorType& allocator = jDoc.GetAllocator();\
\
Value arrKey;\
arrKey.SetString(memberName.c_str(), memberName.length());\
\
ok = ok && jDoc.IsObject();\
ok = ok && jDoc.HasMember(arrKey);\
\
if(ok && jDoc[arrKey].IsArray())\
{\
for (auto&& arrEl : jDoc[arrKey].GetArray())\
{\
RsGenericSerializer::SerializeContext elCtx(\
nullptr, 0, RsGenericSerializer::FORMAT_BINARY,\
RsGenericSerializer::SERIALIZATION_FLAG_NONE,\
&allocator );\
elCtx.mJson.AddMember(arrKey, arrEl, allocator);\
\
T el;\
serial_process(j, elCtx, el, memberName); \
ok = ok && elCtx.mOk;\
\
if(ok) v.INSERT_FUN(el);\
else break;\
}\
}\
} while(false)
/** @def RS_REGISTER_SERIAL_MEMBER_TYPED(I, T)
* This macro usage is similar to @see RS_REGISTER_SERIAL_MEMBER(I) but it
* permit to force serialization/deserialization type, it is expecially useful
* with enum class members or RsTlvItem derivative members, be very careful with
* the type you pass, as reinterpret_cast on a reference is used that is
* expecially permissive so you can shot your feet if not carefull enough.
*
* If you are using this with an RsItem derivative (so passing RsItem as T)
* consider to register your item type with @see RS_REGISTER_ITEM_TYPE(T) in
* association with @see RS_REGISTER_SERIAL_MEMBER(I) that rely on template
* function generation, as in this particular case
* RS_REGISTER_SERIAL_MEMBER_TYPED(I, T) would cause the serial code rely on
* C++ dynamic dispatching that may have a noticeable impact on runtime
* performances.
*/
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
#define RS_REGISTER_SERIAL_MEMBER_TYPED(I, T) do {\
RsTypeSerializer::serial_process<T>(j, ctx, reinterpret_cast<T&>(I), #I);\
} while(0)
#pragma GCC diagnostic pop
/** @def RS_REGISTER_ITEM_TYPE(T)
* Use this macro into `youritem.cc` only if you need to process members of
* subtypes of RsItem.
*
* The usage of this macro is strictly needed only in some cases, for example if
* you are registering for serialization a member of a container that contains
* items of subclasses of RsItem like * `std::map<uint64_t, RsChatMsgItem>`
*
* @code{.cpp}
struct PrivateOugoingMapItem : RsChatItem
{
PrivateOugoingMapItem() : RsChatItem(RS_PKT_SUBTYPE_OUTGOING_MAP) {}
void serial_process( RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx );
std::map<uint64_t, RsChatMsgItem> store;
};
RS_REGISTER_ITEM_TYPE(RsChatMsgItem)
void PrivateOugoingMapItem::serial_process(
RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx )
{
// store is of type
RS_REGISTER_SERIAL_MEMBER(store);
}
* @endcode
*
* If you use this macro with a lot of different item types this can cause the
* generated binary grow in size, consider the usage of
* @see RS_REGISTER_SERIAL_MEMBER_TYPED(I, T) passing RsItem as type in that
* case.
*/
#define RS_REGISTER_ITEM_TYPE(T) template<> \
void RsTypeSerializer::serial_process<T>( \
RsGenericSerializer::SerializeJob j,\
RsGenericSerializer::SerializeContext& ctx, T& item,\
const std::string& /*name*/) { item.serial_process(j, ctx); }
std::ostream &operator<<(std::ostream &out, const RsJson &jDoc);
struct RsTypeSerializer
{
/** This type should be used to pass a parameter to drive the serialisation
* if needed */
struct TlvMemBlock_proxy: public std::pair<void*&,uint32_t&>
struct TlvMemBlock_proxy : std::pair<void*&,uint32_t&>
{
TlvMemBlock_proxy(void*& p, uint32_t& s) :
std::pair<void*&,uint32_t&>(p,s) {}
@ -118,9 +131,10 @@ struct RsTypeSerializer
/// Generic types
template<typename T>
static void serial_process( RsGenericSerializer::SerializeJob j,
typename std::enable_if<std::is_same<RsTlvItem,T>::value || !(std::is_base_of<RsSerializable,T>::value || std::is_enum<T>::value || std::is_base_of<RsTlvItem,T>::value)>::type
static /*void*/ serial_process( RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx,
T& member,const std::string& member_name)
T& member, const std::string& member_name)
{
switch(j)
{
@ -138,9 +152,17 @@ struct RsTypeSerializer
case RsGenericSerializer::PRINT:
print_data(member_name,member);
break;
case RsGenericSerializer::TO_JSON:
ctx.mOk = ctx.mOk && to_JSON(member_name, member, ctx.mJson);
break;
case RsGenericSerializer::FROM_JSON:
ctx.mOk = ctx.mOk && from_JSON(member_name, member, ctx.mJson);
break;
default:
ctx.mOk = false;
throw std::runtime_error("Unknown serial job");
std::cerr << __PRETTY_FUNCTION__ << " Unknown serial job: "
<< static_cast<std::underlying_type<decltype(j)>::type>(j)
<< std::endl;
exit(EINVAL);
}
}
@ -165,11 +187,21 @@ struct RsTypeSerializer
serialize(ctx.mData,ctx.mSize,ctx.mOffset,type_id,member);
break;
case RsGenericSerializer::PRINT:
print_data(member_name,type_id,member);
print_data(member_name, member);
break;
case RsGenericSerializer::TO_JSON:
ctx.mOk = ctx.mOk &&
to_JSON(member_name, type_id, member, ctx.mJson);
break;
case RsGenericSerializer::FROM_JSON:
ctx.mOk = ctx.mOk &&
from_JSON(member_name, type_id, member, ctx.mJson);
break;
default:
ctx.mOk = false;
throw std::runtime_error("Unknown serial job");
std::cerr << __PRETTY_FUNCTION__ << " Unknown serial job: "
<< static_cast<std::underlying_type<decltype(j)>::type>(j)
<< std::endl;
exit(EINVAL);
}
}
@ -178,7 +210,7 @@ struct RsTypeSerializer
static void serial_process( RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx,
std::map<T,U>& v,
const std::string& member_name )
const std::string& memberName )
{
switch(j)
{
@ -225,11 +257,11 @@ struct RsTypeSerializer
case RsGenericSerializer::PRINT:
{
if(v.empty())
std::cerr << " Empty map \"" << member_name << "\""
std::cerr << " Empty map \"" << memberName << "\""
<< std::endl;
else
std::cerr << " std::map of " << v.size() << " elements: \""
<< member_name << "\"" << std::endl;
<< memberName << "\"" << std::endl;
for(typename std::map<T,U>::iterator it(v.begin());it!=v.end();++it)
{
@ -242,6 +274,95 @@ struct RsTypeSerializer
}
break;
}
case RsGenericSerializer::TO_JSON:
{
using namespace rapidjson;
Document::AllocatorType& allocator = ctx.mJson.GetAllocator();
Value arrKey; arrKey.SetString(memberName.c_str(),
memberName.length(), allocator);
Value arr(kArrayType);
for (auto& kv : v)
{
// Use same allocator to avoid deep copy
RsGenericSerializer::SerializeContext kCtx(
nullptr, 0, RsGenericSerializer::FORMAT_BINARY,
RsGenericSerializer::SERIALIZATION_FLAG_NONE,
&allocator );
serial_process<T>(j, kCtx, const_cast<T&>(kv.first), "key");
RsGenericSerializer::SerializeContext vCtx(
nullptr, 0, RsGenericSerializer::FORMAT_BINARY,
RsGenericSerializer::SERIALIZATION_FLAG_NONE,
&allocator );
serial_process<U>(j, vCtx, const_cast<U&>(kv.second), "value");
if(kCtx.mOk && vCtx.mOk)
{
Value el(kObjectType);
el.AddMember("key", kCtx.mJson["key"], allocator);
el.AddMember("value", vCtx.mJson["value"], allocator);
arr.PushBack(el, allocator);
}
}
ctx.mJson.AddMember(arrKey, arr, allocator);
break;
}
case RsGenericSerializer::FROM_JSON:
{
using namespace rapidjson;
bool& ok(ctx.mOk);
Document& jDoc(ctx.mJson);
Document::AllocatorType& allocator = jDoc.GetAllocator();
Value arrKey;
arrKey.SetString(memberName.c_str(), memberName.length());
ok = ok && jDoc.IsObject();
ok = ok && jDoc.HasMember(arrKey);
if(ok && jDoc[arrKey].IsArray())
{
for (auto&& kvEl : jDoc[arrKey].GetArray())
{
ok = ok && kvEl.IsObject();
ok = ok && kvEl.HasMember("key");
ok = ok && kvEl.HasMember("value");
if (!ok) break;
RsGenericSerializer::SerializeContext kCtx(
nullptr, 0, RsGenericSerializer::FORMAT_BINARY,
RsGenericSerializer::SERIALIZATION_FLAG_NONE,
&allocator );
if(ok)
kCtx.mJson.AddMember("key", kvEl["key"], allocator);
T key;
ok = ok && (serial_process(j, kCtx, key, "key"), kCtx.mOk);
RsGenericSerializer::SerializeContext vCtx(
nullptr, 0, RsGenericSerializer::FORMAT_BINARY,
RsGenericSerializer::SERIALIZATION_FLAG_NONE,
&allocator );
if(ok)
vCtx.mJson.AddMember("value", kvEl["value"], allocator);
U value;
ok = ok && ( serial_process(j, vCtx, value, "value"),
vCtx.mOk );
if(ok) v.insert(std::pair<T,U>(key,value));
else break;
}
}
break;
}
default: break;
}
}
@ -251,7 +372,7 @@ struct RsTypeSerializer
static void serial_process( RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx,
std::vector<T>& v,
const std::string& member_name )
const std::string& memberName )
{
switch(j)
{
@ -259,7 +380,7 @@ struct RsTypeSerializer
{
ctx.mOffset += 4;
for(uint32_t i=0;i<v.size();++i)
serial_process(j,ctx,v[i],member_name);
serial_process(j,ctx,v[i],memberName);
break;
}
case RsGenericSerializer::DESERIALIZE:
@ -268,7 +389,7 @@ struct RsTypeSerializer
serial_process(j,ctx,n,"temporary size");
v.resize(n);
for(uint32_t i=0;i<v.size();++i)
serial_process(j,ctx,v[i],member_name);
serial_process(j,ctx,v[i],memberName);
break;
}
case RsGenericSerializer::SERIALIZE:
@ -276,7 +397,7 @@ struct RsTypeSerializer
uint32_t n=v.size();
serial_process(j,ctx,n,"temporary size");
for(uint32_t i=0; i<v.size(); ++i)
serial_process(j,ctx,v[i],member_name);
serial_process(j,ctx,v[i],memberName);
break;
}
case RsGenericSerializer::PRINT:
@ -289,10 +410,16 @@ struct RsTypeSerializer
for(uint32_t i=0;i<v.size();++i)
{
std::cerr << " " ;
serial_process(j,ctx,v[i],member_name);
serial_process(j,ctx,v[i],memberName);
}
break;
}
case RsGenericSerializer::TO_JSON:
RsTypeSerializer_PRIVATE_TO_JSON_ARRAY();
break;
case RsGenericSerializer::FROM_JSON:
RsTypeSerializer_PRIVATE_FROM_JSON_ARRAY(push_back);
break;
default: break;
}
}
@ -301,7 +428,7 @@ struct RsTypeSerializer
template<typename T>
static void serial_process( RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx,
std::set<T>& v, const std::string& member_name )
std::set<T>& v, const std::string& memberName )
{
switch(j)
{
@ -311,7 +438,7 @@ struct RsTypeSerializer
for(typename std::set<T>::iterator it(v.begin());it!=v.end();++it)
// the const cast here is a hack to avoid serial_process to
// instantiate serialise(const T&)
serial_process(j,ctx,const_cast<T&>(*it) ,member_name);
serial_process(j,ctx,const_cast<T&>(*it) ,memberName);
break;
}
case RsGenericSerializer::DESERIALIZE:
@ -321,7 +448,7 @@ struct RsTypeSerializer
for(uint32_t i=0; i<n; ++i)
{
T tmp;
serial_process<T>(j,ctx,tmp,member_name);
serial_process<T>(j,ctx,tmp,memberName);
v.insert(tmp);
}
break;
@ -333,7 +460,7 @@ struct RsTypeSerializer
for(typename std::set<T>::iterator it(v.begin());it!=v.end();++it)
// the const cast here is a hack to avoid serial_process to
// instantiate serialise(const T&)
serial_process(j,ctx,const_cast<T&>(*it) ,member_name);
serial_process(j,ctx,const_cast<T&>(*it) ,memberName);
break;
}
case RsGenericSerializer::PRINT:
@ -343,6 +470,12 @@ struct RsTypeSerializer
<< std::endl;
break;
}
case RsGenericSerializer::TO_JSON:
RsTypeSerializer_PRIVATE_TO_JSON_ARRAY();
break;
case RsGenericSerializer::FROM_JSON:
RsTypeSerializer_PRIVATE_FROM_JSON_ARRAY(insert);
break;
default: break;
}
}
@ -352,7 +485,7 @@ struct RsTypeSerializer
static void serial_process( RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx,
std::list<T>& v,
const std::string& member_name )
const std::string& memberName )
{
switch(j)
{
@ -360,7 +493,7 @@ struct RsTypeSerializer
{
ctx.mOffset += 4;
for(typename std::list<T>::iterator it(v.begin());it!=v.end();++it)
serial_process(j,ctx,*it ,member_name);
serial_process(j,ctx,*it ,memberName);
break;
}
case RsGenericSerializer::DESERIALIZE:
@ -370,7 +503,7 @@ struct RsTypeSerializer
for(uint32_t i=0;i<n;++i)
{
T tmp;
serial_process<T>(j,ctx,tmp,member_name);
serial_process<T>(j,ctx,tmp,memberName);
v.push_back(tmp);
}
break;
@ -380,7 +513,7 @@ struct RsTypeSerializer
uint32_t n=v.size();
serial_process(j,ctx,n,"temporary size");
for(typename std::list<T>::iterator it(v.begin());it!=v.end();++it)
serial_process(j,ctx,*it ,member_name);
serial_process(j,ctx,*it ,memberName);
break;
}
case RsGenericSerializer::PRINT:
@ -390,6 +523,12 @@ struct RsTypeSerializer
<< std::endl;
break;
}
case RsGenericSerializer::TO_JSON:
RsTypeSerializer_PRIVATE_TO_JSON_ARRAY();
break;
case RsGenericSerializer::FROM_JSON:
RsTypeSerializer_PRIVATE_FROM_JSON_ARRAY(push_back);
break;
default: break;
}
}
@ -399,7 +538,7 @@ struct RsTypeSerializer
static void serial_process( RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx,
t_RsFlags32<N>& v,
const std::string& /*member_name*/)
const std::string& memberName )
{
switch(j)
{
@ -421,16 +560,139 @@ struct RsTypeSerializer
std::cerr << " Flags of type " << std::hex << N << " : "
<< v.toUInt32() << std::endl;
break;
case RsGenericSerializer::TO_JSON:
ctx.mOk = to_JSON(memberName, v.toUInt32(), ctx.mJson);
break;
case RsGenericSerializer::FROM_JSON:
{
uint32_t f;
ctx.mOk = from_JSON(memberName, f, ctx.mJson);
v = t_RsFlags32<N>(f);
break;
}
default: break;
}
}
/** TODO
* Serialization format is inside context, but context is not passed to
* following functions, that need to know the format to do the job, actually
* RsGenericSerializer::FORMAT_BINARY is assumed in all of them!!
*/
/**
* @brief serial process enum types
*
* On declaration of your member of enum type you must specify the
* underlying type otherwise the serialization format may differ in an
* uncompatible way depending on the compiler/platform.
*/
template<typename E>
typename std::enable_if<std::is_enum<E>::value>::type
static /*void*/ serial_process( RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx,
E& member,
const std::string& memberName )
{
#ifdef RSSERIAL_DEBUG
std::cerr << __PRETTY_FUNCTION__ << " processing enum: "
<< typeid(E).name() << " as "
<< typeid(typename std::underlying_type<E>::type).name()
<< std::endl;
#endif
serial_process(
j, ctx,
reinterpret_cast<typename std::underlying_type<E>::type&>(member),
memberName );
}
/// RsSerializable and derivatives
template<typename T>
typename std::enable_if<std::is_base_of<RsSerializable,T>::value>::type
static /*void*/ serial_process( RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx,
T& member,
const std::string& memberName )
{
switch(j)
{
case RsGenericSerializer::SIZE_ESTIMATE: // fallthrough
case RsGenericSerializer::DESERIALIZE: // fallthrough
case RsGenericSerializer::SERIALIZE: // fallthrough
case RsGenericSerializer::PRINT:
member.serial_process(j, ctx);
break;
case RsGenericSerializer::TO_JSON:
{
rapidjson::Document& jDoc(ctx.mJson);
rapidjson::Document::AllocatorType& allocator = jDoc.GetAllocator();
// Reuse allocator to avoid deep copy later
RsGenericSerializer::SerializeContext lCtx(
nullptr, 0, RsGenericSerializer::FORMAT_BINARY,
RsGenericSerializer::SERIALIZATION_FLAG_NONE,
&allocator );
member.serial_process(j, lCtx);
rapidjson::Value key;
key.SetString(memberName.c_str(), memberName.length(), allocator);
/* Because the passed allocator is reused it doesn't go out of scope and
* there is no need of deep copy and we can take advantage of the much
* faster rapidjson move semantic */
jDoc.AddMember(key, lCtx.mJson, allocator);
ctx.mOk = ctx.mOk && lCtx.mOk;
break;
}
case RsGenericSerializer::FROM_JSON:
{
rapidjson::Document& jDoc(ctx.mJson);
const char* mName = memberName.c_str();
ctx.mOk = ctx.mOk && jDoc.HasMember(mName);
if(!ctx.mOk)
{
std::cerr << __PRETTY_FUNCTION__ << " \"" << memberName
<< "\" not found in JSON:" << std::endl
<< jDoc << std::endl << std::endl;
print_stacktrace();
break;
}
rapidjson::Value& v = jDoc[mName];
RsGenericSerializer::SerializeContext lCtx(
nullptr, 0, RsGenericSerializer::FORMAT_BINARY,
RsGenericSerializer::SERIALIZATION_FLAG_NONE );
lCtx.mJson.SetObject() = v; // Beware of move semantic!!
member.serial_process(j, lCtx);
ctx.mOk = ctx.mOk && lCtx.mOk;
break;
}
default:
std::cerr << __PRETTY_FUNCTION__ << " Unknown serial job: "
<< static_cast<std::underlying_type<decltype(j)>::type>(j)
<< std::endl;
exit(EINVAL);
break;
}
}
/// RsTlvItem derivatives only
template<typename T>
typename std::enable_if<std::is_base_of<RsTlvItem,T>::value && !std::is_same<RsTlvItem,T>::value>::type
static /*void*/ serial_process( RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx,
T& member,
const std::string& memberName )
{
serial_process(j, ctx, static_cast<RsTlvItem&>(member), memberName);
}
protected:
//============================================================================//
// Generic types declarations //
//============================================================================//
template<typename T> static bool serialize(
uint8_t data[], uint32_t size, uint32_t &offset, const T& member );
@ -442,17 +704,41 @@ protected:
template<typename T> static void print_data(
const std::string& name, const T& member);
template<typename T> static bool to_JSON( const std::string& membername,
const T& member, RsJson& jDoc );
template<typename T> static bool from_JSON( const std::string& memberName,
T& member, RsJson& jDoc );
//============================================================================//
// Generic types + type_id declarations //
//============================================================================//
template<typename T> static bool serialize(
uint8_t data[], uint32_t size, uint32_t &offset, uint16_t type_id,
const T& member );
template<typename T> static bool deserialize(
const uint8_t data[], uint32_t size, uint32_t &offset,
uint16_t type_id, T& member );
template<typename T> static uint32_t serial_size(
uint16_t type_id,const T& member );
template<typename T> static void print_data(
const std::string& name,uint16_t type_id,const T& member );
template<typename T> static void print_data( const std::string& n,
uint16_t type_id,const T& member );
template<typename T> static bool to_JSON( const std::string& membername,
uint16_t type_id,
const T& member, RsJson& jVal );
template<typename T> static bool from_JSON( const std::string& memberName,
uint16_t type_id,
T& member, RsJson& jDoc );
//============================================================================//
// t_RsGenericId<...> declarations //
//============================================================================//
template<uint32_t ID_SIZE_IN_BYTES,bool UPPER_CASE,uint32_t UNIQUE_IDENTIFIER>
static bool serialize(
@ -466,13 +752,29 @@ protected:
template<uint32_t ID_SIZE_IN_BYTES,bool UPPER_CASE,uint32_t UNIQUE_IDENTIFIER>
static uint32_t serial_size(
const t_RsGenericIdType<ID_SIZE_IN_BYTES,UPPER_CASE,UNIQUE_IDENTIFIER>& member );
const t_RsGenericIdType<
ID_SIZE_IN_BYTES,UPPER_CASE,UNIQUE_IDENTIFIER>& member );
template<uint32_t ID_SIZE_IN_BYTES,bool UPPER_CASE,uint32_t UNIQUE_IDENTIFIER>
static void print_data(
const std::string& name,
const t_RsGenericIdType<ID_SIZE_IN_BYTES,UPPER_CASE,UNIQUE_IDENTIFIER>& member );
template<uint32_t ID_SIZE_IN_BYTES,bool UPPER_CASE,uint32_t UNIQUE_IDENTIFIER>
static bool to_JSON(
const std::string& membername,
const t_RsGenericIdType<ID_SIZE_IN_BYTES,UPPER_CASE,UNIQUE_IDENTIFIER>& member,
RsJson& jVal );
template<uint32_t ID_SIZE_IN_BYTES,bool UPPER_CASE,uint32_t UNIQUE_IDENTIFIER>
static bool from_JSON(
const std::string& memberName,
t_RsGenericIdType<ID_SIZE_IN_BYTES,UPPER_CASE,UNIQUE_IDENTIFIER>& member,
RsJson& jDoc );
//============================================================================//
// t_RsTlvList<...> declarations //
//============================================================================//
template<class TLV_CLASS,uint32_t TLV_TYPE>
static bool serialize(
@ -491,16 +793,33 @@ protected:
static void print_data(
const std::string& name,
const t_RsTlvList<TLV_CLASS,TLV_TYPE>& member);
template<class TLV_CLASS,uint32_t TLV_TYPE>
static bool to_JSON( const std::string& membername,
const t_RsTlvList<TLV_CLASS,TLV_TYPE>& member,
RsJson& jVal );
template<class TLV_CLASS,uint32_t TLV_TYPE>
static bool from_JSON( const std::string& memberName,
t_RsTlvList<TLV_CLASS,TLV_TYPE>& member,
RsJson& jDoc );
};
//============================================================================//
// t_RsGenericId<...> //
//============================================================================//
// t_RsGenericId<>
template<uint32_t ID_SIZE_IN_BYTES,bool UPPER_CASE,uint32_t UNIQUE_IDENTIFIER>
bool RsTypeSerializer::serialize (
uint8_t data[], uint32_t size, uint32_t &offset,
const t_RsGenericIdType<ID_SIZE_IN_BYTES,UPPER_CASE,UNIQUE_IDENTIFIER>& member )
{ return (*const_cast<const t_RsGenericIdType<ID_SIZE_IN_BYTES,UPPER_CASE,UNIQUE_IDENTIFIER> *>(&member)).serialise(data,size,offset); }
const t_RsGenericIdType<
ID_SIZE_IN_BYTES,UPPER_CASE,UNIQUE_IDENTIFIER>& member )
{
return (*const_cast<const t_RsGenericIdType<
ID_SIZE_IN_BYTES,UPPER_CASE,UNIQUE_IDENTIFIER> *>(&member)
).serialise(data,size,offset);
}
template<uint32_t ID_SIZE_IN_BYTES,bool UPPER_CASE,uint32_t UNIQUE_IDENTIFIER>
bool RsTypeSerializer::deserialize(
@ -522,8 +841,45 @@ void RsTypeSerializer::print_data(
<< member << std::endl;
}
template<uint32_t ID_SIZE_IN_BYTES,bool UPPER_CASE,uint32_t UNIQUE_IDENTIFIER>
bool RsTypeSerializer::to_JSON( const std::string& memberName,
const t_RsGenericIdType<ID_SIZE_IN_BYTES,UPPER_CASE,UNIQUE_IDENTIFIER>& member,
RsJson& jDoc )
{
rapidjson::Document::AllocatorType& allocator = jDoc.GetAllocator();
rapidjson::Value key;
key.SetString(memberName.c_str(), memberName.length(), allocator);
const std::string vStr = member.toStdString();
rapidjson::Value value;
value.SetString(vStr.c_str(), vStr.length(), allocator);
jDoc.AddMember(key, value, allocator);
return true;
}
template<uint32_t ID_SIZE_IN_BYTES,bool UPPER_CASE,uint32_t UNIQUE_IDENTIFIER>
bool RsTypeSerializer::from_JSON( const std::string& membername,
t_RsGenericIdType<ID_SIZE_IN_BYTES,UPPER_CASE,UNIQUE_IDENTIFIER>& member,
RsJson& jVal )
{
const char* mName = membername.c_str();
bool ret = jVal.HasMember(mName);
if(ret)
{
rapidjson::Value& v = jVal[mName];
ret = ret && v.IsString();
if(ret) member = t_RsGenericIdType<ID_SIZE_IN_BYTES,UPPER_CASE,UNIQUE_IDENTIFIER>(std::string(v.GetString()));
}
return ret;
}
//============================================================================//
// t_RsTlvList<...> //
//============================================================================//
// t_RsTlvList<>
template<class TLV_CLASS,uint32_t TLV_TYPE>
bool RsTypeSerializer::serialize(
uint8_t data[], uint32_t size, uint32_t &offset,
@ -553,3 +909,86 @@ void RsTypeSerializer::print_data(
std::cerr << " [t_RsTlvString<" << std::hex << TLV_TYPE << ">] : size="
<< member.mList.size() << std::endl;
}
template<class TLV_CLASS,uint32_t TLV_TYPE> /* static */
bool RsTypeSerializer::to_JSON( const std::string& memberName,
const t_RsTlvList<TLV_CLASS,TLV_TYPE>& member,
RsJson& jDoc )
{
rapidjson::Document::AllocatorType& allocator = jDoc.GetAllocator();
rapidjson::Value key;
key.SetString(memberName.c_str(), memberName.length(), allocator);
rapidjson::Value value;
const char* tName = typeid(member).name();
value.SetString(tName, allocator);
jDoc.AddMember(key, value, allocator);
std::cerr << __PRETTY_FUNCTION__ << " JSON serialization for type "
<< typeid(member).name() << " " << memberName
<< " not available." << std::endl;
print_stacktrace();
return true;
}
template<class TLV_CLASS,uint32_t TLV_TYPE>
bool RsTypeSerializer::from_JSON( const std::string& memberName,
t_RsTlvList<TLV_CLASS,TLV_TYPE>& member,
RsJson& /*jVal*/ )
{
std::cerr << __PRETTY_FUNCTION__ << " JSON deserialization for type "
<< typeid(member).name() << " " << memberName
<< " not available." << std::endl;
print_stacktrace();
return true;
}
//============================================================================//
// Not implemented types macros //
//============================================================================//
/**
* @def RS_TYPE_SERIALIZER_TO_JSON_NOT_IMPLEMENTED_DEF(T)
* @def RS_TYPE_SERIALIZER_FROM_JSON_NOT_IMPLEMENTED_DEF(T)
* Helper macros for types that has not yet implemented to/from JSON
* should be deleted from the code as soon as they are not needed anymore
*/
#define RS_TYPE_SERIALIZER_TO_JSON_NOT_IMPLEMENTED_DEF(T) \
template<> /*static*/ \
bool RsTypeSerializer::to_JSON(const std::string& memberName, T const& member, \
RsJson& jDoc ) \
{ \
rapidjson::Document::AllocatorType& allocator = jDoc.GetAllocator(); \
\
rapidjson::Value key; \
key.SetString(memberName.c_str(), memberName.length(), allocator); \
\
rapidjson::Value value; \
const char* tName = typeid(member).name(); \
value.SetString(tName, allocator); \
\
jDoc.AddMember(key, value, allocator); \
\
std::cerr << __FILE__ << __LINE__ << __PRETTY_FUNCTION__ \
<< " JSON serialization for type " \
<< typeid(member).name() << " " << memberName \
<< " not available." << std::endl; \
print_stacktrace(); \
return true; \
}
#define RS_TYPE_SERIALIZER_FROM_JSON_NOT_IMPLEMENTED_DEF(T) \
template<> /*static*/ \
bool RsTypeSerializer::from_JSON( const std::string& memberName, \
T& member, RsJson& /*jDoc*/ ) \
{ \
std::cerr << __FILE__ << __LINE__ << __PRETTY_FUNCTION__ \
<< " JSON deserialization for type " \
<< typeid(member).name() << " " << memberName \
<< " not available." << std::endl; \
print_stacktrace(); \
return true; \
}

View file

@ -306,16 +306,14 @@ bool p3BanList::acceptedBanRanges_locked(const BanListPeer& blp)
}
return false ;
}
bool p3BanList::isAddressAccepted(const sockaddr_storage &addr, uint32_t checking_flags,uint32_t *check_result)
bool p3BanList::isAddressAccepted(const sockaddr_storage &dAddr, uint32_t checking_flags,uint32_t *check_result)
{
if(check_result != NULL)
*check_result = RSBANLIST_CHECK_RESULT_NOCHECK ;
sockaddr_storage addr; sockaddr_storage_copy(dAddr, addr);
if(sockaddr_storage_isLoopbackNet(addr))
return true ;
if(!mIPFilteringEnabled)
return true ;
if(!mIPFilteringEnabled) return true;
if(check_result != NULL) *check_result = RSBANLIST_CHECK_RESULT_NOCHECK;
if(!sockaddr_storage_ipv6_to_ipv4(addr)) return true;
if(sockaddr_storage_isLoopbackNet(addr)) return true;
#ifdef DEBUG_BANLIST
std::cerr << "isAddressAccepted(): tested addr=" << sockaddr_storage_iptostring(addr) << ", checking flags=" << checking_flags ;
@ -453,9 +451,20 @@ void p3BanList::getBannedIps(std::list<BanListPeer> &lst)
lst.push_back(it->second) ;
}
bool p3BanList::removeIpRange(const struct sockaddr_storage& addr,int masked_bytes,uint32_t list_type)
bool p3BanList::removeIpRange( const struct sockaddr_storage& dAddr,
int masked_bytes, uint32_t list_type )
{
RS_STACK_MUTEX(mBanMtx) ;
sockaddr_storage addr; sockaddr_storage_copy(dAddr, addr);
if(!sockaddr_storage_ipv6_to_ipv4(addr))
{
std::cerr << __PRETTY_FUNCTION__ << " Cannot handle "
<< sockaddr_storage_tostring(dAddr)
<< " IPv6 not implemented yet!"
<< std::endl;
return false;
}
RS_STACK_MUTEX(mBanMtx);
bool changed = false;
std::map<sockaddr_storage,BanListPeer>::iterator it ;
@ -485,9 +494,20 @@ bool p3BanList::removeIpRange(const struct sockaddr_storage& addr,int masked_byt
return changed;
}
bool p3BanList::addIpRange(const sockaddr_storage &addr, int masked_bytes,uint32_t list_type,const std::string& comment)
bool p3BanList::addIpRange( const sockaddr_storage &dAddr, int masked_bytes,
uint32_t list_type, const std::string& comment )
{
RS_STACK_MUTEX(mBanMtx) ;
sockaddr_storage addr; sockaddr_storage_copy(dAddr, addr);
if(!sockaddr_storage_ipv6_to_ipv4(addr))
{
std::cerr << __PRETTY_FUNCTION__ << " Cannot handle "
<< sockaddr_storage_tostring(dAddr)
<< " IPv6 not implemented yet!"
<< std::endl;
return false;
}
RS_STACK_MUTEX(mBanMtx);
if(getBitRange(addr) > uint32_t(masked_bytes))
{
@ -668,20 +688,31 @@ bool p3BanList::recvBanItem(RsBanListItem *item)
}
/* overloaded from pqiNetAssistSharePeer */
void p3BanList::updatePeer(const RsPeerId& /*id*/, const struct sockaddr_storage &addr, int /*type*/, int /*reason*/, int time_stamp)
void p3BanList::updatePeer( const RsPeerId& /*id*/,
const sockaddr_storage &dAddr,
int /*type*/, int /*reason*/, int time_stamp )
{
RsPeerId ownId = mServiceCtrl->getOwnId();
sockaddr_storage addr; sockaddr_storage_copy(dAddr, addr);
if(!sockaddr_storage_ipv6_to_ipv4(addr))
{
std::cerr << __PRETTY_FUNCTION__ << " Cannot handle "
<< sockaddr_storage_tostring(dAddr)
<< " IPv6 not implemented yet!"
<< std::endl;
return;
}
int int_reason = RSBANLIST_REASON_DHT;
RsPeerId ownId = mServiceCtrl->getOwnId();
addBanEntry(ownId, addr, RSBANLIST_ORIGIN_SELF, int_reason, time_stamp);
int int_reason = RSBANLIST_REASON_DHT;
/* process */
{
RsStackMutex stack(mBanMtx); /****** LOCKED MUTEX *******/
addBanEntry(ownId, addr, RSBANLIST_ORIGIN_SELF, int_reason, time_stamp);
condenseBanSources_locked();
}
/* process */
{
RS_STACK_MUTEX(mBanMtx);
condenseBanSources_locked();
}
}
RsSerialiser *p3BanList::setupSerialiser()
@ -704,9 +735,9 @@ bool p3BanList::saveList(bool &cleanup, std::list<RsItem*>& itemlist)
{
RsBanListConfigItem *item = new RsBanListConfigItem ;
item->type = RSBANLIST_TYPE_PEERLIST ;
item->peerId = it->second.mPeerId ;
item->update_time = it->second.mLastUpdate ;
item->banListType = RSBANLIST_TYPE_PEERLIST ;
item->banListPeerId = it->second.mPeerId ;
item->update_time = it->second.mLastUpdate ;
item->banned_peers.TlvClear() ;
for(std::map<sockaddr_storage,BanListPeer>::const_iterator it2 = it->second.mBanPeers.begin();it2!=it->second.mBanPeers.end();++it2)
@ -723,8 +754,8 @@ bool p3BanList::saveList(bool &cleanup, std::list<RsItem*>& itemlist)
// Add whitelist
RsBanListConfigItem *item = new RsBanListConfigItem ;
item->type = RSBANLIST_TYPE_WHITELIST ;
item->peerId.clear() ;
item->banListType = RSBANLIST_TYPE_WHITELIST ;
item->banListPeerId.clear() ;
item->update_time = 0 ;
item->banned_peers.TlvClear() ;
@ -742,8 +773,8 @@ bool p3BanList::saveList(bool &cleanup, std::list<RsItem*>& itemlist)
item = new RsBanListConfigItem ;
item->type = RSBANLIST_TYPE_BLACKLIST ;
item->peerId.clear();
item->banListType = RSBANLIST_TYPE_BLACKLIST ;
item->banListPeerId.clear();
item->update_time = 0 ;
item->banned_peers.TlvClear() ;
@ -819,11 +850,11 @@ bool p3BanList::loadList(std::list<RsItem*>& load)
if(citem != NULL)
{
if(citem->type == RSBANLIST_TYPE_PEERLIST)
if(citem->banListType == RSBANLIST_TYPE_PEERLIST)
{
BanList& bl(mBanSources[citem->peerId]) ;
BanList& bl(mBanSources[citem->banListPeerId]) ;
bl.mPeerId = citem->peerId ;
bl.mPeerId = citem->banListPeerId ;
bl.mLastUpdate = citem->update_time ;
bl.mBanPeers.clear() ;
@ -839,7 +870,7 @@ bool p3BanList::loadList(std::list<RsItem*>& load)
std::cerr << "(WW) removed wrong address " << sockaddr_storage_iptostring(blp.addr) << std::endl;
}
}
else if(citem->type == RSBANLIST_TYPE_BLACKLIST)
else if(citem->banListType == RSBANLIST_TYPE_BLACKLIST)
{
mBanRanges.clear() ;
@ -854,7 +885,7 @@ bool p3BanList::loadList(std::list<RsItem*>& load)
std::cerr << "(WW) removed wrong address " << sockaddr_storage_iptostring(blp.addr) << std::endl;
}
}
else if(citem->type == RSBANLIST_TYPE_WHITELIST)
else if(citem->banListType == RSBANLIST_TYPE_WHITELIST)
{
mWhiteListedRanges.clear() ;
@ -872,7 +903,7 @@ bool p3BanList::loadList(std::list<RsItem*>& load)
}
}
else
std::cerr << "(EE) BanList item unknown type " << citem->type << ". This is a bug." << std::endl;
std::cerr << "(EE) BanList item unknown type " << citem->banListType << ". This is a bug." << std::endl;
}
delete *it ;
@ -882,10 +913,21 @@ bool p3BanList::loadList(std::list<RsItem*>& load)
return true ;
}
bool p3BanList::addBanEntry(const RsPeerId &peerId, const struct sockaddr_storage &addr,
int level, uint32_t reason, time_t time_stamp)
bool p3BanList::addBanEntry( const RsPeerId &peerId,
const sockaddr_storage &dAddr,
int level, uint32_t reason, time_t time_stamp )
{
RsStackMutex stack(mBanMtx); /****** LOCKED MUTEX *******/
sockaddr_storage addr; sockaddr_storage_copy(dAddr, addr);
if(!sockaddr_storage_ipv6_to_ipv4(addr))
{
std::cerr << __PRETTY_FUNCTION__ << " Cannot handle "
<< sockaddr_storage_tostring(dAddr)
<< " IPv6 not implemented yet!"
<< std::endl;
return false;
}
RS_STACK_MUTEX(mBanMtx);
time_t now = time(NULL);
bool updated = false;

View file

@ -47,27 +47,31 @@ class BanList
std::map<struct sockaddr_storage, BanListPeer> mBanPeers;
};
//!The RS BanList service.
/**
*
* Exchange list of Banned IP addresses with peers.
*/
/**
* The RS BanList service.
* Exchange list of Banned IPv4 addresses with peers.
*
* @warning IPv4 only, IPv6 not supported yet!
*/
class p3BanList: public RsBanList, public p3Service, public pqiNetAssistPeerShare, public p3Config /*, public pqiMonitor */
{
public:
p3BanList(p3ServiceControl *sc, p3NetMgr *nm);
virtual RsServiceInfo getServiceInfo();
/***** overloaded from RsBanList *****/
/***** overloaded from RsBanList *****/
virtual bool isAddressAccepted(const struct sockaddr_storage& addr, uint32_t checking_flags,uint32_t *check_result=NULL) ;
virtual bool isAddressAccepted( const sockaddr_storage& addr,
uint32_t checking_flags,
uint32_t *check_result=NULL );
virtual void getBannedIps(std::list<BanListPeer>& list) ;
virtual void getWhiteListedIps(std::list<BanListPeer>& list) ;
virtual bool addIpRange(const struct sockaddr_storage& addr,int masked_bytes,uint32_t list_type,const std::string& comment) ;
virtual bool removeIpRange(const sockaddr_storage &addr, int masked_bytes, uint32_t list_type);
virtual bool addIpRange( const sockaddr_storage& addr, int masked_bytes,
uint32_t list_type, const std::string& comment );
virtual bool removeIpRange( const sockaddr_storage &addr, int masked_bytes,
uint32_t list_type );
virtual void enableIPFiltering(bool b) ;
virtual bool ipFilteringEnabled() ;
@ -86,7 +90,8 @@ public:
/***** overloaded from pqiNetAssistPeerShare *****/
virtual void updatePeer(const RsPeerId& id, const struct sockaddr_storage &addr, int type, int reason, int time_stamp);
virtual void updatePeer( const RsPeerId& id, const sockaddr_storage &addr,
int type, int reason, int time_stamp );
/*********************** p3config ******************************/
virtual RsSerialiser *setupSerialiser();
@ -108,8 +113,10 @@ public:
int sendPackets();
bool processIncoming();
bool recvBanItem(RsBanListItem *item);
bool addBanEntry(const RsPeerId &peerId, const struct sockaddr_storage &addr, int level, uint32_t reason, time_t time_stamp);
bool recvBanItem(RsBanListItem *item);
bool addBanEntry( const RsPeerId &peerId,
const sockaddr_storage &addr, int level, uint32_t reason,
time_t time_stamp );
void sendBanLists();
int sendBanSet(const RsPeerId& peerid);

View file

@ -132,10 +132,10 @@ struct RsGxsForumNotifyRecordsItem: public RsItem
virtual ~RsGxsForumNotifyRecordsItem() {}
void serial_process( RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext& ctx )
{
RS_REGISTER_SERIAL_MEMBER(records);
}
void serial_process( RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx )
{ RS_SERIAL_PROCESS(records); }
void clear() {}
std::map<RsGxsGroupId,time_t> records;
@ -218,8 +218,7 @@ RsGenExchange::ServiceCreate_Return p3GxsChannels::service_CreateGroup(RsGxsGrpI
void p3GxsChannels::notifyChanges(std::vector<RsGxsNotify *> &changes)
{
#ifdef GXSCHANNELS_DEBUG
std::cerr << "p3GxsChannels::notifyChanges()";
std::cerr << std::endl;
std::cerr << "p3GxsChannels::notifyChanges() : " << changes.size() << "changes to notify" << std::endl;
#endif
p3Notify *notify = NULL;
@ -242,16 +241,12 @@ void p3GxsChannels::notifyChanges(std::vector<RsGxsNotify *> &changes)
/* message received */
if (notify)
{
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &msgChangeMap = msgChange->msgChangeMap;
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> >::iterator mit;
for (mit = msgChangeMap.begin(); mit != msgChangeMap.end(); ++mit)
{
std::vector<RsGxsMessageId>::iterator mit1;
for (mit1 = mit->second.begin(); mit1 != mit->second.end(); ++mit1)
std::map<RsGxsGroupId, std::set<RsGxsMessageId> > &msgChangeMap = msgChange->msgChangeMap;
for (auto mit = msgChangeMap.begin(); mit != msgChangeMap.end(); ++mit)
for (auto mit1 = mit->second.begin(); mit1 != mit->second.end(); ++mit1)
{
notify->AddFeedItem(RS_FEED_ITEM_CHANNEL_MSG, mit->first.toStdString(), mit1->toStdString());
}
}
}
}
@ -262,9 +257,8 @@ void p3GxsChannels::notifyChanges(std::vector<RsGxsNotify *> &changes)
std::cerr << std::endl;
#endif
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &msgChangeMap = msgChange->msgChangeMap;
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> >::iterator mit;
for(mit = msgChangeMap.begin(); mit != msgChangeMap.end(); ++mit)
std::map<RsGxsGroupId, std::set<RsGxsMessageId> > &msgChangeMap = msgChange->msgChangeMap;
for(auto mit = msgChangeMap.begin(); mit != msgChangeMap.end(); ++mit)
{
#ifdef GXSCHANNELS_DEBUG
std::cerr << "p3GxsChannels::notifyChanges() Msgs for Group: " << mit->first;
@ -808,10 +802,7 @@ void p3GxsChannels::request_SpecificUnprocessedPosts(std::list<std::pair<RsGxsGr
GxsMsgReq msgIds;
std::list<std::pair<RsGxsGroupId, RsGxsMessageId> >::iterator it;
for(it = ids.begin(); it != ids.end(); ++it)
{
std::vector<RsGxsMessageId> &vect_msgIds = msgIds[it->first];
vect_msgIds.push_back(it->second);
}
msgIds[it->first].insert(it->second);
RsGenExchange::getTokenService()->requestMsgInfo(token, ansType, opts, msgIds);
GxsTokenQueue::queueRequest(token, GXSCHANNELS_UNPROCESSED_SPECIFIC);
@ -1179,7 +1170,9 @@ void p3GxsChannels::setMessageProcessedStatus(uint32_t& token, const RsGxsGrpMsg
setMsgStatusFlags(token, msgId, status, mask);
}
void p3GxsChannels::setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read)
void p3GxsChannels::setMessageReadStatus( uint32_t& token,
const RsGxsGrpMsgIdPair& msgId,
bool read )
{
#ifdef GXSCHANNELS_DEBUG
std::cerr << "p3GxsChannels::setMessageReadStatus()";
@ -1189,10 +1182,8 @@ void p3GxsChannels::setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPai
/* Always remove status unprocessed */
uint32_t mask = GXS_SERV::GXS_MSG_STATUS_GUI_NEW | GXS_SERV::GXS_MSG_STATUS_GUI_UNREAD;
uint32_t status = GXS_SERV::GXS_MSG_STATUS_GUI_UNREAD;
if (read)
{
status = 0;
}
if (read) status = 0;
setMsgStatusFlags(token, msgId, status, mask);
}

View file

@ -108,15 +108,12 @@ virtual bool setChannelDownloadDirectory(const RsGxsGroupId &groupId, const std:
virtual bool getChannelDownloadDirectory(const RsGxsGroupId &groupId, std::string& directory);
/* Comment service - Provide RsGxsCommentService - redirect to p3GxsCommentService */
virtual bool getCommentData(const uint32_t &token, std::vector<RsGxsComment> &msgs)
{
return mCommentService->getGxsCommentData(token, msgs);
}
virtual bool getCommentData(uint32_t token, std::vector<RsGxsComment> &msgs)
{ return mCommentService->getGxsCommentData(token, msgs); }
virtual bool getRelatedComments(const uint32_t &token, std::vector<RsGxsComment> &msgs)
{
return mCommentService->getGxsRelatedComments(token, msgs);
}
virtual bool getRelatedComments( uint32_t token,
std::vector<RsGxsComment> &msgs )
{ return mCommentService->getGxsRelatedComments(token, msgs); }
virtual bool createComment(uint32_t &token, RsGxsComment &msg)
{
@ -128,13 +125,13 @@ virtual bool createVote(uint32_t &token, RsGxsVote &msg)
return mCommentService->createGxsVote(token, msg);
}
virtual bool acknowledgeComment(const uint32_t& token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId)
virtual bool acknowledgeComment(uint32_t token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId)
{
return acknowledgeMsg(token, msgId);
}
virtual bool acknowledgeVote(const uint32_t& token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId)
virtual bool acknowledgeVote(uint32_t token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId)
{
if (mCommentService->acknowledgeVote(token, msgId))
{

View file

@ -212,14 +212,14 @@ void p3GxsCircles::notifyChanges(std::vector<RsGxsNotify *> &changes)
#ifdef DEBUG_CIRCLES
std::cerr << " Found circle Message Change Notification" << std::endl;
#endif
for(std::map<RsGxsGroupId, std::vector<RsGxsMessageId> >::iterator mit = msgChange->msgChangeMap.begin(); mit != msgChange->msgChangeMap.end(); ++mit)
for(auto mit = msgChange->msgChangeMap.begin(); mit != msgChange->msgChangeMap.end(); ++mit)
{
#ifdef DEBUG_CIRCLES
std::cerr << " Msgs for Group: " << mit->first << std::endl;
#endif
force_cache_reload(RsGxsCircleId(mit->first));
if (notify && (c->getType() == RsGxsNotify::TYPE_RECEIVE) )
for (std::vector<RsGxsMessageId>::const_iterator msgIdIt(mit->second.begin()), end(mit->second.end()); msgIdIt != end; ++msgIdIt)
for (auto msgIdIt(mit->second.begin()), end(mit->second.end()); msgIdIt != end; ++msgIdIt)
{
const RsGxsMessageId& msgId = *msgIdIt;
notify->AddFeedItem(RS_FEED_ITEM_CIRCLE_MEMB_REQ,RsGxsCircleId(mit->first).toStdString(),msgId.toStdString());
@ -2120,7 +2120,7 @@ bool p3GxsCircles::processMembershipRequests(uint32_t token)
#ifdef DEBUG_CIRCLES
std::cerr << " Older than last known (" << time(NULL)-info.last_subscription_TS << " seconds ago): deleting." << std::endl;
#endif
messages_to_delete[RsGxsGroupId(cid)].push_back(it->second[i]->meta.mMsgId) ;
messages_to_delete[RsGxsGroupId(cid)].insert(it->second[i]->meta.mMsgId) ;
}
}

View file

@ -502,8 +502,8 @@ bool p3GxsCommentService::createGxsVote(uint32_t &token, RsGxsVote &vote)
opts.mReqType = GXS_REQUEST_TYPE_MSG_META;
GxsMsgReq msgIds;
std::vector<RsGxsMessageId> &vect_msgIds = msgIds[parentId.first];
vect_msgIds.push_back(parentId.second);
std::set<RsGxsMessageId> &vect_msgIds = msgIds[parentId.first];
vect_msgIds.insert(parentId.second);
uint32_t int_token;
mExchange->getTokenService()->requestMsgInfo(int_token, RS_TOKREQ_ANSTYPE_SUMMARY, opts, msgIds);

View file

@ -107,10 +107,10 @@ struct RsGxsForumNotifyRecordsItem: public RsItem
virtual ~RsGxsForumNotifyRecordsItem() {}
void serial_process( RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext& ctx )
{
RS_REGISTER_SERIAL_MEMBER(records);
}
void serial_process( RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx )
{ RS_SERIAL_PROCESS(records); }
void clear() {}
std::map<RsGxsGroupId,time_t> records;
@ -205,15 +205,12 @@ void p3GxsForums::notifyChanges(std::vector<RsGxsNotify *> &changes)
RsGxsMsgChange *msgChange = dynamic_cast<RsGxsMsgChange*>(c);
if (msgChange)
{
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &msgChangeMap = msgChange->msgChangeMap;
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> >::iterator mit;
for (mit = msgChangeMap.begin(); mit != msgChangeMap.end(); ++mit)
std::map<RsGxsGroupId, std::set<RsGxsMessageId> > &msgChangeMap = msgChange->msgChangeMap;
for (auto mit = msgChangeMap.begin(); mit != msgChangeMap.end(); ++mit)
{
std::vector<RsGxsMessageId>::iterator mit1;
for (mit1 = mit->second.begin(); mit1 != mit->second.end(); ++mit1)
{
for (auto mit1 = mit->second.begin(); mit1 != mit->second.end(); ++mit1)
notify->AddFeedItem(RS_FEED_ITEM_FORUM_MSG, mit->first.toStdString(), mit1->toStdString());
}
}
break;
}

View file

@ -3,7 +3,8 @@
*
* Id interface for RetroShare.
*
* Copyright 2012-2012 by Robert Fernie.
* Copyright (C) 2012 Robert Fernie
* 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
@ -561,8 +562,8 @@ void p3IdService::notifyChanges(std::vector<RsGxsNotify *> &changes)
std::cerr << std::endl;
#endif
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &msgChangeMap = msgChange->msgChangeMap;
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> >::iterator mit;
std::map<RsGxsGroupId, std::set<RsGxsMessageId> > &msgChangeMap = msgChange->msgChangeMap;
std::map<RsGxsGroupId, std::set<RsGxsMessageId> >::iterator mit;
for(mit = msgChangeMap.begin(); mit != msgChangeMap.end(); ++mit)
{
#ifdef DEBUG_IDS
@ -4505,11 +4506,30 @@ void p3IdService::handle_event(uint32_t event_type, const std::string &/*elabel*
}
}
RsIdentityUsage::RsIdentityUsage(uint16_t service,const RsIdentityUsage::UsageCode& code,const RsGxsGroupId& gid,const RsGxsMessageId& mid,uint64_t additional_id,const std::string& comment)
: mServiceId(service), mUsageCode(code), mGrpId(gid), mMsgId(mid),mAdditionalId(additional_id),mComment(comment)
void RsGxsIdGroup::serial_process(
RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx )
{
RS_SERIAL_PROCESS(mMeta);
RS_SERIAL_PROCESS(mPgpIdHash);
//RS_SERIAL_PROCESS(mPgpIdSign);
RS_SERIAL_PROCESS(mRecognTags);
//RS_SERIAL_PROCESS(mImage);
RS_SERIAL_PROCESS(mLastUsageTS);
RS_SERIAL_PROCESS(mPgpKnown);
RS_SERIAL_PROCESS(mIsAContact);
RS_SERIAL_PROCESS(mPgpId);
RS_SERIAL_PROCESS(mReputation);
}
RsIdentityUsage::RsIdentityUsage(
uint16_t service, const RsIdentityUsage::UsageCode& code,
const RsGxsGroupId& gid, const RsGxsMessageId& mid,
uint64_t additional_id,const std::string& comment ) :
mServiceId(service), mUsageCode(code), mGrpId(gid), mMsgId(mid),
mAdditionalId(additional_id), mComment(comment)
{
#ifdef DEBUG_IDS
// This is a hack, since it will hash also mHash, but because it is initialized to 0, and only computed in the constructor here, it should be ok.
std::cerr << "New identity usage: " << std::endl;
std::cerr << " service=" << std::hex << service << std::endl;
std::cerr << " code =" << std::hex << code << std::endl;
@ -4519,6 +4539,9 @@ RsIdentityUsage::RsIdentityUsage(uint16_t service,const RsIdentityUsage::UsageCo
std::cerr << " commnt =\"" << std::hex << comment << "\"" << std::endl;
#endif
/* This is a hack, since it will hash also mHash, but because it is
* initialized to 0, and only computed in the constructor here, it should
* be ok. */
librs::crypto::HashStream hs(librs::crypto::HashStream::SHA1) ;
hs << (uint32_t)service ;
@ -4535,5 +4558,5 @@ RsIdentityUsage::RsIdentityUsage(uint16_t service,const RsIdentityUsage::UsageCo
#endif
}
RsIdentityUsage::RsIdentityUsage() :
mServiceId(0), mUsageCode(UNKNOWN_USAGE), mAdditionalId(0) {}

View file

@ -110,9 +110,8 @@ void p3PostBase::notifyChanges(std::vector<RsGxsNotify *> &changes)
std::cerr << std::endl;
#endif
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &msgChangeMap = msgChange->msgChangeMap;
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> >::iterator mit;
for(mit = msgChangeMap.begin(); mit != msgChangeMap.end(); ++mit)
std::map<RsGxsGroupId, std::set<RsGxsMessageId> > &msgChangeMap = msgChange->msgChangeMap;
for(auto mit = msgChangeMap.begin(); mit != msgChangeMap.end(); ++mit)
{
#ifdef POSTBASE_DEBUG
std::cerr << "p3PostBase::notifyChanges() Msgs for Group: " << mit->first;
@ -125,8 +124,7 @@ void p3PostBase::notifyChanges(std::vector<RsGxsNotify *> &changes)
if (notify && msgChange->getType() == RsGxsNotify::TYPE_RECEIVE)
{
std::vector<RsGxsMessageId>::iterator mit1;
for (mit1 = mit->second.begin(); mit1 != mit->second.end(); ++mit1)
for (auto mit1 = mit->second.begin(); mit1 != mit->second.end(); ++mit1)
{
notify->AddFeedItem(RS_FEED_ITEM_POSTED_MSG, mit->first.toStdString(), mit1->toStdString());
}
@ -431,7 +429,7 @@ void p3PostBase::background_loadMsgs(const uint32_t &token, bool unprocessed)
mBgIncremental = unprocessed;
}
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > postMap;
std::map<RsGxsGroupId, std::set<RsGxsMessageId> > postMap;
// generate vector of changes to push to the GUI.
std::vector<RsGxsNotify *> changes;
@ -487,7 +485,7 @@ void p3PostBase::background_loadMsgs(const uint32_t &token, bool unprocessed)
#endif
/* but we need to notify GUI about them */
msgChanges->msgChangeMap[mit->first].push_back((*vit)->meta.mMsgId);
msgChanges->msgChangeMap[mit->first].insert((*vit)->meta.mMsgId);
}
else if (NULL != (commentItem = dynamic_cast<RsGxsCommentItem *>(*vit)))
{
@ -546,7 +544,7 @@ void p3PostBase::background_loadMsgs(const uint32_t &token, bool unprocessed)
if (sit == mBgStatsMap.end())
{
// add to map of ones to update.
postMap[groupId].push_back(threadId);
postMap[groupId].insert(threadId);
mBgStatsMap[threadId] = PostStats(0,0,0);
sit = mBgStatsMap.find(threadId);
@ -704,7 +702,7 @@ void p3PostBase::background_updateVoteCounts(const uint32_t &token)
#endif
stats.increment(it->second);
msgChanges->msgChangeMap[mit->first].push_back(vit->mMsgId);
msgChanges->msgChangeMap[mit->first].insert(vit->mMsgId);
}
else
{

View file

@ -83,16 +83,14 @@ virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgI
}
/* Comment service - Provide RsGxsCommentService - redirect to p3GxsCommentService */
virtual bool getCommentData(const uint32_t &token, std::vector<RsGxsComment> &msgs)
{
return mCommentService->getGxsCommentData(token, msgs);
}
/** Comment service - Provide RsGxsCommentService -
* redirect to p3GxsCommentService */
virtual bool getCommentData(uint32_t token, std::vector<RsGxsComment> &msgs)
{ return mCommentService->getGxsCommentData(token, msgs); }
virtual bool getRelatedComments(const uint32_t &token, std::vector<RsGxsComment> &msgs)
{
return mCommentService->getGxsRelatedComments(token, msgs);
}
virtual bool getRelatedComments( uint32_t token,
std::vector<RsGxsComment> &msgs )
{ return mCommentService->getGxsRelatedComments(token, msgs); }
virtual bool createComment(uint32_t &token, RsGxsComment &msg)
{
@ -104,17 +102,14 @@ virtual bool createVote(uint32_t &token, RsGxsVote &msg)
return mCommentService->createGxsVote(token, msg);
}
virtual bool acknowledgeComment(const uint32_t& token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId)
{
return acknowledgeMsg(token, msgId);
}
virtual bool acknowledgeComment(
uint32_t token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId )
{ return acknowledgeMsg(token, msgId); }
virtual bool acknowledgeVote(const uint32_t& token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId)
virtual bool acknowledgeVote(
uint32_t token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId )
{
if (mCommentService->acknowledgeVote(token, msgId))
{
return true;
}
if (mCommentService->acknowledgeVote(token, msgId)) return true;
return acknowledgeMsg(token, msgId);
}
};

View file

@ -140,6 +140,9 @@ template<> void RsTypeSerializer::print_data(const std::string& n, const RsRegul
std::cerr << " [RegExpr ] " << n << ", tokens=" << expr._tokens.size() << " ints=" << expr._ints.size() << " strings=" << expr._strings.size() << std::endl;
}
RS_TYPE_SERIALIZER_TO_JSON_NOT_IMPLEMENTED_DEF(RsRegularExpression::LinearizedExpression)
RS_TYPE_SERIALIZER_FROM_JSON_NOT_IMPLEMENTED_DEF(RsRegularExpression::LinearizedExpression)
void RsTurtleSearchResultItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint32_t>(j,ctx,request_id,"request_id") ;
@ -193,6 +196,9 @@ template<> void RsTypeSerializer::print_data(const std::string& n, const TurtleF
std::cerr << " [FileInfo ] " << n << " size=" << i.size << " hash=" << i.hash << ", name=" << i.name << std::endl;
}
RS_TYPE_SERIALIZER_TO_JSON_NOT_IMPLEMENTED_DEF(TurtleFileInfo)
RS_TYPE_SERIALIZER_FROM_JSON_NOT_IMPLEMENTED_DEF(TurtleFileInfo)
void RsTurtleOpenTunnelItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process (j,ctx,file_hash ,"file_hash") ;

View file

@ -36,7 +36,7 @@
#include <serialiser/rsserial.h>
#include <turtle/rsturtleitem.h>
class RsItem ;
struct RsItem;
class p3turtle ;
class RsTurtleClientService

View file

@ -0,0 +1,38 @@
DEPENDPATH *= $$system_path($$clean_path($${PWD}/../../libretroshare/src/))
INCLUDEPATH *= $$system_path($$clean_path($${PWD}/../../libretroshare/src))
LIBS *= -L$$system_path($$clean_path($${OUT_PWD}/../../libretroshare/src/lib/)) -lretroshare
equals(TARGET, retroshare):equals(TEMPLATE, lib){
} else {
PRE_TARGETDEPS *= $$system_path($$clean_path($$OUT_PWD/../../libretroshare/src/lib/libretroshare.a))
}
!include("../../openpgpsdk/src/use_openpgpsdk.pri"):error("Including")
bitdht {
!include("../../libbitdht/src/use_libbitdht.pri"):error("Including")
}
# when rapidjson is mainstream on all distribs, we will not need the sources
# anymore in the meantime, they are part of the RS directory so that it is
# always possible to find them
INCLUDEPATH *= $$system_path($$clean_path($${PWD}/../../rapidjson-1.1.0))
sLibs =
mLibs = $$RS_SQL_LIB ssl crypto $$RS_THREAD_LIB $$RS_UPNP_LIB
dLibs =
linux-* {
mLibs += dl
}
static {
sLibs *= $$mLibs
} else {
dLibs *= $$mLibs
}
LIBS += $$linkStaticLibs(sLibs)
PRE_TARGETDEPS += $$pretargetStaticLibs(sLibs)
LIBS += $$linkDynamicLibs(dLibs)

View file

@ -58,6 +58,15 @@ int inet_aton(const char *name, struct in_addr *addr);
#endif
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
/**
* Workaround for binary compatibility between Windows XP (which miss
* IPV6_V6ONLY define), and newer Windows that has it.
* @see http://lua-users.org/lists/lua-l/2013-04/msg00191.html
*/
#ifndef IPV6_V6ONLY
# define IPV6_V6ONLY 27
#endif
/* 64 bit conversions */
#ifndef ntohll
uint64_t ntohll(uint64_t x);