mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-31 11:54:22 -04:00
merged upstream/master
This commit is contained in:
commit
6419b03a2a
131 changed files with 6081 additions and 1473 deletions
|
@ -39,12 +39,12 @@
|
|||
|
||||
//#define DEBUG_CHAT_LOBBIES 1
|
||||
|
||||
static const int CONNECTION_CHALLENGE_MAX_COUNT = 20 ; // sends a connection challenge every 20 messages
|
||||
static const rstime_t CONNECTION_CHALLENGE_MAX_MSG_AGE = 30 ; // maximum age of a message to be used in a connection challenge
|
||||
static const int CONNECTION_CHALLENGE_MIN_DELAY = 15 ; // sends a connection at most every 15 seconds
|
||||
static const int LOBBY_CACHE_CLEANING_PERIOD = 10 ; // clean lobby caches every 10 secs (remove old messages)
|
||||
static const int CONNECTION_CHALLENGE_MAX_COUNT = 20 ; // sends a connection challenge every 20 messages
|
||||
static const rstime_t CONNECTION_CHALLENGE_MAX_MSG_AGE = 30 ; // maximum age of a message to be used in a connection challenge
|
||||
static const int CONNECTION_CHALLENGE_MIN_DELAY = 15 ; // sends a connection at most every 15 seconds
|
||||
static const int LOBBY_CACHE_CLEANING_PERIOD = 10 ; // clean lobby caches every 10 secs (remove old messages)
|
||||
|
||||
static const rstime_t MAX_KEEP_MSG_RECORD = 1200 ; // keep msg record for 1200 secs max.
|
||||
static const rstime_t MAX_KEEP_MSG_RECORD = 1200 ; // keep msg record for 1200 secs max.
|
||||
static const rstime_t MAX_KEEP_INACTIVE_NICKNAME = 180 ; // keep inactive nicknames for 3 mn max.
|
||||
static const rstime_t MAX_DELAY_BETWEEN_LOBBY_KEEP_ALIVE = 120 ; // send keep alive packet every 2 minutes.
|
||||
static const rstime_t MAX_KEEP_PUBLIC_LOBBY_RECORD = 60 ; // keep inactive lobbies records for 60 secs max.
|
||||
|
@ -52,7 +52,7 @@ static const rstime_t MIN_DELAY_BETWEEN_PUBLIC_LOBBY_REQ = 20 ; // don't ask
|
|||
static const rstime_t LOBBY_LIST_AUTO_UPDATE_TIME = 121 ; // regularly ask for available lobbies every 5 minutes, to allow auto-subscribe to work
|
||||
|
||||
static const uint32_t MAX_ALLOWED_LOBBIES_IN_LIST_WARNING = 50 ;
|
||||
//static const uint32_t MAX_MESSAGES_PER_SECONDS_NUMBER = 5 ; // max number of messages from a given peer in a window for duration below
|
||||
//static const uint32_t MAX_MESSAGES_PER_SECONDS_NUMBER = 5 ; // max number of messages from a given peer in a window for duration below
|
||||
static const uint32_t MAX_MESSAGES_PER_SECONDS_PERIOD = 10 ; // duration window for max number of messages before messages get dropped.
|
||||
|
||||
#define IS_PUBLIC_LOBBY(flags) (flags & RS_CHAT_LOBBY_FLAGS_PUBLIC )
|
||||
|
@ -933,7 +933,7 @@ void DistributedChatService::sendLobbyStatusPeerChangedNickname(const ChatLobbyI
|
|||
}
|
||||
|
||||
|
||||
void DistributedChatService::sendLobbyStatusPeerLiving(const ChatLobbyId& lobby_id)
|
||||
void DistributedChatService::sendLobbyStatusPeerLeaving(const ChatLobbyId& lobby_id)
|
||||
{
|
||||
sendLobbyStatusItem(lobby_id,RS_CHAT_LOBBY_EVENT_PEER_LEFT,std::string()) ;
|
||||
}
|
||||
|
@ -990,7 +990,7 @@ bool DistributedChatService::locked_initLobbyBouncableObject(const ChatLobbyId&
|
|||
while( lobby.msg_cache.find(item.msg_id) != lobby.msg_cache.end() ) ;
|
||||
|
||||
RsIdentityDetails details ;
|
||||
if(!rsIdentity->getIdDetails(lobby.gxs_id,details))
|
||||
if(!rsIdentity || !rsIdentity->getIdDetails(lobby.gxs_id,details))
|
||||
{
|
||||
std::cerr << "(EE) Cannot send chat lobby object. Signign identity " << lobby.gxs_id << " is unknown." << std::endl;
|
||||
return false ;
|
||||
|
@ -1580,6 +1580,9 @@ bool DistributedChatService::joinVisibleChatLobby(const ChatLobbyId& lobby_id,co
|
|||
}
|
||||
_chat_lobbys[lobby_id] = entry ;
|
||||
}
|
||||
setLobbyAutoSubscribe(lobby_id,true);
|
||||
|
||||
triggerConfigSave(); // so that we save the subscribed lobbies
|
||||
|
||||
for(std::list<RsPeerId>::const_iterator it(invited_friends.begin());it!=invited_friends.end();++it)
|
||||
invitePeerToLobby(lobby_id,*it) ;
|
||||
|
@ -1629,6 +1632,8 @@ ChatLobbyId DistributedChatService::createChatLobby(const std::string& lobby_nam
|
|||
|
||||
RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_ADD) ;
|
||||
|
||||
triggerConfigSave();
|
||||
|
||||
return lobby_id ;
|
||||
}
|
||||
|
||||
|
@ -1666,10 +1671,11 @@ void DistributedChatService::handleFriendUnsubscribeLobby(RsChatLobbyUnsubscribe
|
|||
void DistributedChatService::unsubscribeChatLobby(const ChatLobbyId& id)
|
||||
{
|
||||
// send AKN item
|
||||
sendLobbyStatusPeerLiving(id) ;
|
||||
sendLobbyStatusPeerLeaving(id) ;
|
||||
setLobbyAutoSubscribe(id, false);
|
||||
|
||||
{
|
||||
RsStackMutex stack(mDistributedChatMtx); /********** STACK LOCKED MTX ******/
|
||||
RS_STACK_MUTEX(mDistributedChatMtx);
|
||||
|
||||
std::map<ChatLobbyId,ChatLobbyEntry>::iterator it = _chat_lobbys.find(id) ;
|
||||
|
||||
|
@ -1704,6 +1710,7 @@ void DistributedChatService::unsubscribeChatLobby(const ChatLobbyId& id)
|
|||
_chat_lobbys.erase(it) ;
|
||||
}
|
||||
|
||||
triggerConfigSave(); // so that we save the subscribed lobbies
|
||||
RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_DEL) ;
|
||||
|
||||
// done!
|
||||
|
@ -1826,15 +1833,27 @@ bool DistributedChatService::setIdentityForChatLobby(const ChatLobbyId& lobby_id
|
|||
|
||||
void DistributedChatService::setLobbyAutoSubscribe(const ChatLobbyId& lobby_id, const bool autoSubscribe)
|
||||
{
|
||||
if(autoSubscribe){
|
||||
_known_lobbies_flags[lobby_id] |= RS_CHAT_LOBBY_FLAGS_AUTO_SUBSCRIBE;
|
||||
RsGxsId gxsId;
|
||||
if (getIdentityForChatLobby(lobby_id, gxsId))
|
||||
_lobby_default_identity[lobby_id] = gxsId;
|
||||
} else {
|
||||
_known_lobbies_flags[lobby_id] &= ~RS_CHAT_LOBBY_FLAGS_AUTO_SUBSCRIBE ;
|
||||
_lobby_default_identity.erase(lobby_id);
|
||||
}
|
||||
|
||||
if(autoSubscribe)
|
||||
{
|
||||
{
|
||||
RS_STACK_MUTEX(mDistributedChatMtx);
|
||||
_known_lobbies_flags[lobby_id] |= RS_CHAT_LOBBY_FLAGS_AUTO_SUBSCRIBE;
|
||||
}
|
||||
RsGxsId gxsId;
|
||||
|
||||
if (getIdentityForChatLobby(lobby_id, gxsId))
|
||||
{
|
||||
RS_STACK_MUTEX(mDistributedChatMtx);
|
||||
_lobby_default_identity[lobby_id] = gxsId;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
RS_STACK_MUTEX(mDistributedChatMtx);
|
||||
_known_lobbies_flags[lobby_id] &= ~RS_CHAT_LOBBY_FLAGS_AUTO_SUBSCRIBE ;
|
||||
_lobby_default_identity.erase(lobby_id);
|
||||
}
|
||||
|
||||
RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_ADD) ;
|
||||
triggerConfigSave();
|
||||
|
@ -1966,6 +1985,15 @@ void DistributedChatService::addToSaveList(std::list<RsItem*>& list) const
|
|||
list.push_back(clci) ;
|
||||
}
|
||||
|
||||
for(auto it(_chat_lobbys.begin());it!=_chat_lobbys.end();++it)
|
||||
{
|
||||
RsSubscribedChatLobbyConfigItem *scli = new RsSubscribedChatLobbyConfigItem;
|
||||
|
||||
scli->info = it->second; // copies the ChatLobbyInfo part only
|
||||
|
||||
list.push_back(scli);
|
||||
}
|
||||
|
||||
/* Save Default Nick Name */
|
||||
{
|
||||
RsConfigKeyValueSet *vitem = new RsConfigKeyValueSet ;
|
||||
|
@ -2061,6 +2089,59 @@ bool DistributedChatService::processLoadListItem(const RsItem *item)
|
|||
if(!own_ids.empty())
|
||||
_default_identity = own_ids.front() ;
|
||||
}
|
||||
|
||||
const RsSubscribedChatLobbyConfigItem *scli = dynamic_cast<const RsSubscribedChatLobbyConfigItem*>(item);
|
||||
|
||||
if(scli != NULL)
|
||||
{
|
||||
if(_chat_lobbys.find(scli->info.lobby_id) != _chat_lobbys.end()) // do nothing if the lobby is already subscribed
|
||||
return true;
|
||||
|
||||
std::cerr << "Re-subscribing to chat lobby " << (void*)scli->info.lobby_id << ", flags = " << scli->info.lobby_flags << std::endl;
|
||||
|
||||
rstime_t now = time(NULL);
|
||||
|
||||
// Add the chat room into visible chat rooms
|
||||
{
|
||||
RS_STACK_MUTEX(mDistributedChatMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
VisibleChatLobbyRecord& rec(_visible_lobbies[scli->info.lobby_id]) ;
|
||||
|
||||
rec.lobby_id = scli->info.lobby_id ;
|
||||
rec.lobby_name = scli->info.lobby_name ;
|
||||
rec.lobby_topic = scli->info.lobby_topic ;
|
||||
rec.participating_friends = scli->info.participating_friends;
|
||||
rec.total_number_of_peers = 0;
|
||||
rec.last_report_time = now ;
|
||||
rec.lobby_flags = EXTRACT_PRIVACY_FLAGS(scli->info.lobby_flags) ;
|
||||
|
||||
_known_lobbies_flags[scli->info.lobby_id] |= RS_CHAT_LOBBY_FLAGS_AUTO_SUBSCRIBE;
|
||||
}
|
||||
|
||||
// Add the chat room into subscribed chat rooms
|
||||
|
||||
ChatLobbyEntry entry ;
|
||||
(ChatLobbyInfo&)entry = scli->info;
|
||||
|
||||
entry.virtual_peer_id = makeVirtualPeerId(entry.lobby_id) ; // not random, so we keep the same id at restart
|
||||
entry.connexion_challenge_count = 0 ;
|
||||
entry.last_activity = now ;
|
||||
entry.last_connexion_challenge_time = now ;
|
||||
entry.last_keep_alive_packet_time = now ;
|
||||
|
||||
{
|
||||
RS_STACK_MUTEX(mDistributedChatMtx); /********** STACK LOCKED MTX ******/
|
||||
_chat_lobbys[entry.lobby_id] = entry ;
|
||||
}
|
||||
|
||||
// make the UI aware of the existing chat room
|
||||
|
||||
RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_ADD) ;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return false ;
|
||||
}
|
||||
|
||||
|
|
|
@ -72,6 +72,7 @@ class DistributedChatService
|
|||
void setLobbyAutoSubscribe(const ChatLobbyId& lobby_id, const bool autoSubscribe);
|
||||
bool getLobbyAutoSubscribe(const ChatLobbyId& lobby_id);
|
||||
void sendLobbyStatusString(const ChatLobbyId& id,const std::string& status_string) ;
|
||||
void sendLobbyStatusPeerLeaving(const ChatLobbyId& lobby_id) ;
|
||||
|
||||
ChatLobbyId createChatLobby(const std::string& lobby_name,const RsGxsId& lobby_identity,const std::string& lobby_topic, const std::set<RsPeerId>& invited_friends,ChatLobbyFlags flags) ;
|
||||
|
||||
|
@ -93,7 +94,7 @@ class DistributedChatService
|
|||
bool sendLobbyChat(const ChatLobbyId &lobby_id, const std::string&) ;
|
||||
bool handleRecvChatLobbyMsgItem(RsChatMsgItem *item) ;
|
||||
|
||||
bool checkSignature(RsChatLobbyBouncingObject *obj,const RsPeerId& peer_id) ;
|
||||
bool checkSignature(RsChatLobbyBouncingObject *obj,const RsPeerId& peer_id) ;
|
||||
|
||||
private:
|
||||
/// make some statistics about time shifts, to prevent various issues.
|
||||
|
@ -119,7 +120,6 @@ class DistributedChatService
|
|||
bool bounceLobbyObject(RsChatLobbyBouncingObject *obj, const RsPeerId& peer_id) ;
|
||||
|
||||
void sendLobbyStatusItem(const ChatLobbyId&, int type, const std::string& status_string) ;
|
||||
void sendLobbyStatusPeerLiving(const ChatLobbyId& lobby_id) ;
|
||||
void sendLobbyStatusPeerChangedNickname(const ChatLobbyId& lobby_id, const std::string& newnick) ;
|
||||
|
||||
void sendLobbyStatusNewPeer(const ChatLobbyId& lobby_id) ;
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
*******************************************************************************/
|
||||
|
||||
#include <stdexcept>
|
||||
#include "retroshare/rsmsgs.h"
|
||||
#include "util/rstime.h"
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
|
@ -52,6 +53,7 @@ RsItem *RsChatSerialiser::create_item(uint16_t service_id,uint8_t item_sub_id) c
|
|||
case RS_PKT_SUBTYPE_CHAT_LOBBY_LIST_REQUEST: return new RsChatLobbyListRequestItem();
|
||||
case RS_PKT_SUBTYPE_CHAT_LOBBY_LIST: return new RsChatLobbyListItem();
|
||||
case RS_PKT_SUBTYPE_CHAT_LOBBY_CONFIG: return new RsChatLobbyConfigItem();
|
||||
case RS_PKT_SUBTYPE_SUBSCRIBED_CHAT_LOBBY_CONFIG: return new RsSubscribedChatLobbyConfigItem();
|
||||
case RS_PKT_SUBTYPE_OUTGOING_MAP: return new PrivateOugoingMapItem();
|
||||
default:
|
||||
std::cerr << "Unknown packet type in chat!" << std::endl;
|
||||
|
@ -172,6 +174,11 @@ void RsChatAvatarItem::serial_process(RsGenericSerializer::SerializeJob j,RsGene
|
|||
RsTypeSerializer::serial_process(j,ctx,b,"image data") ;
|
||||
}
|
||||
|
||||
void RsSubscribedChatLobbyConfigItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
info.serial_process(j,ctx);
|
||||
}
|
||||
|
||||
void RsChatLobbyConfigItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint64_t>(j,ctx,lobby_Id,"lobby_Id") ;
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
|
||||
#include "serialiser/rstlvidset.h"
|
||||
#include "serialiser/rstlvfileitem.h"
|
||||
#include "retroshare/rsmsgs.h"
|
||||
|
||||
/* chat Flags */
|
||||
const uint32_t RS_CHAT_FLAG_PRIVATE = 0x0001;
|
||||
|
@ -82,6 +83,8 @@ const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE_DEPRECATED = 0x1A ; // to be remo
|
|||
const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE = 0x1B ;
|
||||
const uint8_t RS_PKT_SUBTYPE_OUTGOING_MAP = 0x1C ;
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_SUBSCRIBED_CHAT_LOBBY_CONFIG = 0x1D ;
|
||||
|
||||
typedef uint64_t ChatLobbyId ;
|
||||
typedef uint64_t ChatLobbyMsgId ;
|
||||
typedef std::string ChatLobbyNickName ;
|
||||
|
@ -298,6 +301,19 @@ struct RsPrivateChatMsgConfigItem : RsChatItem
|
|||
uint32_t recvTime;
|
||||
};
|
||||
|
||||
class RsSubscribedChatLobbyConfigItem: public RsChatItem
|
||||
{
|
||||
public:
|
||||
RsSubscribedChatLobbyConfigItem() :RsChatItem(RS_PKT_SUBTYPE_SUBSCRIBED_CHAT_LOBBY_CONFIG) {}
|
||||
virtual ~RsSubscribedChatLobbyConfigItem() {}
|
||||
|
||||
virtual void clear() { RsChatItem::clear(); info.clear(); }
|
||||
|
||||
void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
ChatLobbyInfo info;
|
||||
};
|
||||
|
||||
class RsChatLobbyConfigItem: public RsChatItem
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -968,16 +968,18 @@ int p3FileDatabase::getSharedDirStatistics(const RsPeerId& pid,SharedDirStats& s
|
|||
}
|
||||
}
|
||||
|
||||
void p3FileDatabase::removeExtraFile(const RsFileHash& hash)
|
||||
bool p3FileDatabase::removeExtraFile(const RsFileHash& hash)
|
||||
{
|
||||
bool ret = false;
|
||||
{
|
||||
RS_STACK_MUTEX(mFLSMtx) ;
|
||||
|
||||
mExtraFiles->removeExtraFile(hash);
|
||||
ret = mExtraFiles->removeExtraFile(hash);
|
||||
mLastExtraFilesCacheUpdate = 0 ; // forced cache reload
|
||||
}
|
||||
|
||||
RsServer::notify()->notifyListChange(NOTIFY_LIST_DIRLIST_LOCAL, 0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void p3FileDatabase::getExtraFilesDirDetails(void *ref,DirectoryStorage::EntryIndex e,DirDetails& d) const
|
||||
|
|
|
@ -109,8 +109,8 @@ class p3FileDatabase: public p3Service, public p3Config, public ftSearch //, pub
|
|||
virtual int SearchKeywords(const std::list<std::string>& keywords, std::list<DirDetails>& results,FileSearchFlags flags,const RsPeerId& peer_id) ;
|
||||
virtual int SearchBoolExp(RsRegularExpression::Expression *exp, std::list<DirDetails>& results,FileSearchFlags flags,const RsPeerId& peer_id) const ;
|
||||
|
||||
// Extra file list
|
||||
virtual void removeExtraFile(const RsFileHash& hash);
|
||||
// Extra file list
|
||||
virtual bool removeExtraFile(const RsFileHash& hash);
|
||||
|
||||
// Interface for browsing dir hierarchy
|
||||
//
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
* *
|
||||
* libretroshare: retroshare core library *
|
||||
* *
|
||||
* Copyright 2008 by Robert Fernie <retroshare@lunamutt.com> *
|
||||
* Copyright (C) 2008 Robert Fernie <retroshare@lunamutt.com> *
|
||||
* Copyright (C) 2018-2019 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
|
@ -272,7 +273,8 @@ bool ftExtraList::cleanupEntry(std::string /*path*/, TransferRequestFlags /*flag
|
|||
* file is removed after period.
|
||||
**/
|
||||
|
||||
bool ftExtraList::hashExtraFile(std::string path, uint32_t period, TransferRequestFlags flags)
|
||||
bool ftExtraList::hashExtraFile(
|
||||
std::string path, uint32_t period, TransferRequestFlags flags )
|
||||
{
|
||||
#ifdef DEBUG_ELIST
|
||||
std::cerr << "ftExtraList::hashExtraFile() path: " << path;
|
||||
|
@ -282,12 +284,25 @@ bool ftExtraList::hashExtraFile(std::string path, uint32_t period, TransferRequ
|
|||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
/* add into queue */
|
||||
RS_STACK_MUTEX(extMutex);
|
||||
auto failure = [](std::string errMsg)
|
||||
{
|
||||
RsErr() << __PRETTY_FUNCTION__ << " " << errMsg << std::endl;
|
||||
return false;
|
||||
};
|
||||
|
||||
if(!RsDirUtil::fileExists(path))
|
||||
return failure("file: " + path + "not found");
|
||||
|
||||
if(RsDirUtil::checkDirectory(path))
|
||||
return failure("Cannot add a directory: " + path + "as extra file");
|
||||
|
||||
FileDetails details(path, period, flags);
|
||||
details.info.age = time(NULL) + period;
|
||||
mToHash.push_back(details);
|
||||
details.info.age = static_cast<int>(time(nullptr) + period);
|
||||
|
||||
{
|
||||
RS_STACK_MUTEX(extMutex);
|
||||
mToHash.push_back(details); /* add into queue */
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -678,14 +678,13 @@ bool ftServer::ExtraFileAdd(std::string fname, const RsFileHash& hash, uint64_t
|
|||
}
|
||||
|
||||
bool ftServer::ExtraFileRemove(const RsFileHash& hash)
|
||||
{
|
||||
mFileDatabase->removeExtraFile(hash);
|
||||
return true;
|
||||
}
|
||||
{ return mFileDatabase->removeExtraFile(hash); }
|
||||
|
||||
bool ftServer::ExtraFileHash(std::string localpath, uint32_t period, TransferRequestFlags flags)
|
||||
bool ftServer::ExtraFileHash(
|
||||
std::string localpath, rstime_t period, TransferRequestFlags flags )
|
||||
{
|
||||
return mFtExtra->hashExtraFile(localpath, period, flags);
|
||||
return mFtExtra->hashExtraFile(
|
||||
localpath, static_cast<uint32_t>(period), flags );
|
||||
}
|
||||
|
||||
bool ftServer::ExtraFileStatus(std::string localpath, FileInfo &info)
|
||||
|
|
|
@ -181,7 +181,7 @@ public:
|
|||
***/
|
||||
virtual bool ExtraFileAdd(std::string fname, const RsFileHash& hash, uint64_t size, uint32_t period, TransferRequestFlags flags);
|
||||
virtual bool ExtraFileRemove(const RsFileHash& hash);
|
||||
virtual bool ExtraFileHash(std::string localpath, uint32_t period, TransferRequestFlags flags);
|
||||
virtual bool ExtraFileHash(std::string localpath, rstime_t period, TransferRequestFlags flags);
|
||||
virtual bool ExtraFileStatus(std::string localpath, FileInfo &info);
|
||||
virtual bool ExtraFileMove(std::string fname, const RsFileHash& hash, uint64_t size, std::string destpath);
|
||||
|
||||
|
|
|
@ -100,8 +100,9 @@ void DiscPgpInfo::mergeFriendList(const std::set<PGPID> &friends)
|
|||
p3discovery2::p3discovery2(
|
||||
p3PeerMgr* peerMgr, p3LinkMgr* linkMgr, p3NetMgr* netMgr,
|
||||
p3ServiceControl* sc, RsGixs* gixs ) :
|
||||
p3Service(), mRsEventsHandle(0), mPeerMgr(peerMgr), mLinkMgr(linkMgr), mNetMgr(netMgr),
|
||||
mServiceCtrl(sc), mGixs(gixs), mDiscMtx("p3discovery2"), mLastPgpUpdate(0)
|
||||
p3Service(), mRsEventsHandle(0), mPeerMgr(peerMgr), mLinkMgr(linkMgr),
|
||||
mNetMgr(netMgr), mServiceCtrl(sc), mGixs(gixs), mDiscMtx("p3discovery2"),
|
||||
mLastPgpUpdate(0)
|
||||
{
|
||||
Dbg3() << __PRETTY_FUNCTION__ << std::endl;
|
||||
|
||||
|
@ -111,9 +112,12 @@ p3discovery2::p3discovery2(
|
|||
// Add self into PGP FriendList.
|
||||
mFriendList[AuthGPG::getAuthGPG()->getGPGOwnId()] = DiscPgpInfo();
|
||||
|
||||
rsEvents->registerEventsHandler(
|
||||
[this](const RsEvent& event){ rsEventsHandler(event); },
|
||||
mRsEventsHandle );
|
||||
if(rsEvents)
|
||||
rsEvents->registerEventsHandler(
|
||||
[this](std::shared_ptr<const RsEvent> event)
|
||||
{
|
||||
rsEventsHandler(*event);
|
||||
}, mRsEventsHandle ); // mRsEventsHandle is zeroed in initializer list
|
||||
}
|
||||
|
||||
|
||||
|
@ -1240,12 +1244,9 @@ void p3discovery2::recvInvite(
|
|||
std::unique_ptr<RsGossipDiscoveryInviteItem> inviteItem )
|
||||
{
|
||||
typedef RsGossipDiscoveryFriendInviteReceivedEvent Evt_t;
|
||||
|
||||
// Ensure rsEvents is not deleted while we use it
|
||||
std::shared_ptr<RsEvents> lockedRsEvents = rsEvents;
|
||||
if(lockedRsEvents)
|
||||
lockedRsEvents->postEvent(
|
||||
std::unique_ptr<Evt_t>(new Evt_t(inviteItem->mInvite)) );
|
||||
if(rsEvents)
|
||||
rsEvents->postEvent(
|
||||
std::shared_ptr<Evt_t>(new Evt_t(inviteItem->mInvite)) );
|
||||
}
|
||||
|
||||
void p3discovery2::rsEventsHandler(const RsEvent& event)
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* *
|
||||
* libretroshare: retroshare core library *
|
||||
* *
|
||||
* Copyright (C) 2016-2017 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||
* Copyright (C) 2016-2019 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
|
@ -22,12 +22,13 @@
|
|||
#include "util/rsdir.h"
|
||||
#include "gxstrans/p3gxstrans.h"
|
||||
#include "util/stacktrace.h"
|
||||
#include "util/rsdebug.h"
|
||||
|
||||
//#define DEBUG_GXSTRANS 1
|
||||
|
||||
typedef unsigned int uint;
|
||||
|
||||
RsGxsTrans *rsGxsTrans = NULL ;
|
||||
/*extern*/ RsGxsTrans* rsGxsTrans = nullptr;
|
||||
|
||||
const uint32_t p3GxsTrans::MAX_DELAY_BETWEEN_CLEANUPS = 900; // every 15 mins. Could be less.
|
||||
|
||||
|
@ -240,10 +241,7 @@ void p3GxsTrans::handleResponse(uint32_t token, uint32_t req_type)
|
|||
if(!have_preferred_group)
|
||||
{
|
||||
/* This is true only at first run when we haven't received mail
|
||||
* distribuition groups from friends
|
||||
* TODO: We should check if we have some connected friend too, to
|
||||
* avoid to create yet another never used mail distribution group.
|
||||
*/
|
||||
* distribuition groups from friends */
|
||||
|
||||
#ifdef DEBUG_GXSTRANS
|
||||
std::cerr << "p3GxsTrans::handleResponse(...) preferredGroupId.isNu"
|
||||
|
@ -621,9 +619,10 @@ void p3GxsTrans::service_tick()
|
|||
}
|
||||
else
|
||||
{
|
||||
/* TODO: It is a receipt for a message sent by someone else
|
||||
/* It is a receipt for a message sent by someone else
|
||||
* we can delete original mail from our GXS DB without
|
||||
* waiting for GXS_STORAGE_PERIOD */
|
||||
* waiting for GXS_STORAGE_PERIOD, this has been implemented
|
||||
* already by Cyril into GxsTransIntegrityCleanupThread */
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -964,9 +963,9 @@ void p3GxsTrans::locked_processOutgoingRecord(OutgoingRecord& pr)
|
|||
{
|
||||
case RsGxsTransEncryptionMode::CLEAR_TEXT:
|
||||
{
|
||||
std::cerr << "p3GxsTrans::sendMail(...) you are sending a mail "
|
||||
<< "without encryption, everyone can read it!"
|
||||
<< std::endl;
|
||||
RsWarn() << __PRETTY_FUNCTION__ << " you are sending a mail "
|
||||
<< "without encryption, everyone can read it!"
|
||||
<< std::endl;
|
||||
break;
|
||||
}
|
||||
case RsGxsTransEncryptionMode::RSA:
|
||||
|
@ -986,15 +985,15 @@ void p3GxsTrans::locked_processOutgoingRecord(OutgoingRecord& pr)
|
|||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "p3GxsTrans::sendMail(...) RSA encryption failed! "
|
||||
<< "error_status: " << encryptError << std::endl;
|
||||
RsErr() << __PRETTY_FUNCTION__ << " RSA encryption failed! "
|
||||
<< "error_status: " << encryptError << std::endl;
|
||||
pr.status = GxsTransSendStatus::FAILED_ENCRYPTION;
|
||||
goto processingFailed;
|
||||
}
|
||||
}
|
||||
case RsGxsTransEncryptionMode::UNDEFINED_ENCRYPTION:
|
||||
default:
|
||||
std::cerr << "p3GxsTrans::sendMail(...) attempt to send mail with "
|
||||
RsErr() << __PRETTY_FUNCTION__ << " attempt to send mail with "
|
||||
<< "wrong EncryptionMode: "
|
||||
<< static_cast<uint>(pr.mailItem.cryptoType)
|
||||
<< " dropping mail!" << std::endl;
|
||||
|
@ -1040,7 +1039,8 @@ void p3GxsTrans::locked_processOutgoingRecord(OutgoingRecord& pr)
|
|||
{
|
||||
RS_STACK_MUTEX(mIngoingMutex);
|
||||
auto range = mIncomingQueue.equal_range(pr.mailItem.mailId);
|
||||
bool changed = false ;
|
||||
bool changed = false;
|
||||
bool received = false;
|
||||
|
||||
for( auto it = range.first; it != range.second; ++it)
|
||||
{
|
||||
|
@ -1051,14 +1051,21 @@ void p3GxsTrans::locked_processOutgoingRecord(OutgoingRecord& pr)
|
|||
mIncomingQueue.erase(it); delete rt;
|
||||
pr.status = GxsTransSendStatus::RECEIPT_RECEIVED;
|
||||
|
||||
changed = true ;
|
||||
changed = true;
|
||||
received = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!received && time(nullptr) - pr.sent_ts > GXS_STORAGE_PERIOD)
|
||||
{
|
||||
changed = true;
|
||||
pr.status = GxsTransSendStatus::FAILED_TIMED_OUT;
|
||||
}
|
||||
|
||||
if(changed)
|
||||
IndicateConfigChanged();
|
||||
|
||||
// TODO: Resend message if older then treshold
|
||||
break;
|
||||
}
|
||||
case GxsTransSendStatus::RECEIPT_RECEIVED:
|
||||
|
@ -1067,14 +1074,13 @@ void p3GxsTrans::locked_processOutgoingRecord(OutgoingRecord& pr)
|
|||
processingFailed:
|
||||
case GxsTransSendStatus::FAILED_RECEIPT_SIGNATURE:
|
||||
case GxsTransSendStatus::FAILED_ENCRYPTION:
|
||||
case GxsTransSendStatus::FAILED_TIMED_OUT:
|
||||
default:
|
||||
{
|
||||
std::cout << "p3GxsTrans::processRecord(" << pr.mailItem.mailId
|
||||
<< ") failed with: " << static_cast<uint>(pr.status)
|
||||
RsErr() << __PRETTY_FUNCTION__ << " processing:" << pr.mailItem.mailId
|
||||
<< " failed with: " << static_cast<uint>(pr.status)
|
||||
<< std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void p3GxsTrans::notifyClientService(const OutgoingRecord& pr)
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* *
|
||||
* libretroshare: retroshare core library *
|
||||
* *
|
||||
* Copyright (C) 2016-2017 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||
* Copyright (C) 2016-2019 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
|
@ -21,7 +21,7 @@
|
|||
*******************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <cstdint>
|
||||
#include <unordered_map>
|
||||
#include <map>
|
||||
|
||||
|
@ -70,7 +70,7 @@ struct MsgSizeCount
|
|||
};
|
||||
|
||||
/**
|
||||
* @brief p3GxsTrans is a mail delivery service based on GXS.
|
||||
* @brief p3GxsTrans asyncronous redundant small mail trasport on top of GXS.
|
||||
* p3GxsTrans is capable of asynchronous mail delivery and acknowledgement.
|
||||
* p3GxsTrans is meant to be capable of multiple encryption options,
|
||||
* @see RsGxsTransEncryptionMode at moment messages are encrypted using RSA
|
||||
|
|
|
@ -289,7 +289,8 @@ JsonApiServer::JsonApiServer(uint16_t port, const std::string& bindAddress,
|
|||
};
|
||||
session->yield(rb::OK, headers);
|
||||
|
||||
size_t reqSize = session->get_request()->get_header("Content-Length", 0);
|
||||
size_t reqSize = static_cast<size_t>(
|
||||
session->get_request()->get_header("Content-Length", 0) );
|
||||
session->fetch( reqSize, [this](
|
||||
const std::shared_ptr<rb::Session> session,
|
||||
const rb::Bytes& body )
|
||||
|
@ -302,24 +303,28 @@ JsonApiServer::JsonApiServer(uint16_t port, const std::string& bindAddress,
|
|||
|
||||
const std::weak_ptr<rb::Session> weakSession(session);
|
||||
RsEventsHandlerId_t hId = rsEvents->generateUniqueHandlerId();
|
||||
std::function<void(const RsEvent&)> multiCallback =
|
||||
[weakSession, hId](const RsEvent& event)
|
||||
std::function<void(std::shared_ptr<const RsEvent>)> multiCallback =
|
||||
[this, weakSession, hId](std::shared_ptr<const RsEvent> event)
|
||||
{
|
||||
auto session = weakSession.lock();
|
||||
if(!session || session->is_closed())
|
||||
mService.schedule( [weakSession, hId, event]()
|
||||
{
|
||||
if(rsEvents) rsEvents->unregisterEventsHandler(hId);
|
||||
return;
|
||||
}
|
||||
auto session = weakSession.lock();
|
||||
if(!session || session->is_closed())
|
||||
{
|
||||
if(rsEvents) rsEvents->unregisterEventsHandler(hId);
|
||||
return;
|
||||
}
|
||||
|
||||
RsGenericSerializer::SerializeContext ctx;
|
||||
RsTypeSerializer::serial_process(
|
||||
RsGenericSerializer::TO_JSON, ctx,
|
||||
const_cast<RsEvent&>(event), "event" );
|
||||
RsGenericSerializer::SerializeContext ctx;
|
||||
RsTypeSerializer::serial_process(
|
||||
RsGenericSerializer::TO_JSON, ctx,
|
||||
*const_cast<RsEvent*>(event.get()), "event" );
|
||||
|
||||
std::stringstream message;
|
||||
message << "data: " << compactJSON << ctx.mJson << "\n\n";
|
||||
session->yield(message.str());
|
||||
std::stringstream message;
|
||||
message << "data: " << compactJSON << ctx.mJson << "\n\n";
|
||||
|
||||
session->yield(message.str());
|
||||
} );
|
||||
};
|
||||
|
||||
bool retval = rsEvents->registerEventsHandler(multiCallback, hId);
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
#include "retroshare/rsids.h"
|
||||
#include "retroshare/rstypes.h"
|
||||
#include "util/rsdeprecate.h"
|
||||
|
||||
/* This is a small collection of PGP functions that are widely used in libretroshare.
|
||||
* This interface class allows these functions to be easily mocked for testing.
|
||||
|
@ -40,6 +41,9 @@ class PgpAuxUtils
|
|||
|
||||
virtual bool parseSignature(unsigned char *sign, unsigned int signlen, RsPgpId& issuer) const =0;
|
||||
virtual bool VerifySignBin(const void *data, uint32_t len, unsigned char *sign, unsigned int signlen, const PGPFingerprintType& withfingerprint) = 0;
|
||||
|
||||
/** @deprecated this method depends on retroshare-gui to work */
|
||||
RS_DEPRECATED_FOR("AuthGPG::SignDataBin")
|
||||
virtual bool askForDeferredSelfSignature(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen,int& signature_result, std::string reason) = 0;
|
||||
};
|
||||
|
||||
|
|
|
@ -311,7 +311,7 @@ bool AuthSSLimpl::active() { return init; }
|
|||
|
||||
int AuthSSLimpl::InitAuth(
|
||||
const char* cert_file, const char* priv_key_file, const char* passwd,
|
||||
std::string /*alternative_location_name*/ )
|
||||
std::string locationName )
|
||||
{
|
||||
/* single call here si don't need to invoke mutex yet */
|
||||
static int initLib = 0;
|
||||
|
@ -520,6 +520,8 @@ int AuthSSLimpl::InitAuth(
|
|||
else
|
||||
std::cerr << std::endl;
|
||||
|
||||
mOwnLocationName = locationName;
|
||||
|
||||
init = 1;
|
||||
return 1;
|
||||
}
|
||||
|
@ -575,7 +577,7 @@ const RsPeerId& AuthSSLimpl::OwnId()
|
|||
}
|
||||
|
||||
std::string AuthSSLimpl::getOwnLocation()
|
||||
{ return RsX509Cert::getCertLocation(*mOwnCert); }
|
||||
{ return mOwnLocationName; }
|
||||
|
||||
std::string AuthSSLimpl::SaveOwnCertificateToString()
|
||||
{ return saveX509ToPEM(mOwnCert); }
|
||||
|
|
|
@ -98,7 +98,7 @@ public:
|
|||
virtual bool active() = 0;
|
||||
virtual int InitAuth(
|
||||
const char* srvr_cert, const char* priv_key, const char* passwd,
|
||||
std::string alternative_location_name ) = 0;
|
||||
std::string locationName ) = 0;
|
||||
virtual bool CloseAuth() = 0;
|
||||
|
||||
/*********** Overloaded Functions from p3AuthMgr **********/
|
||||
|
@ -198,7 +198,7 @@ public:
|
|||
|
||||
bool active() override;
|
||||
int InitAuth( const char *srvr_cert, const char *priv_key,
|
||||
const char *passwd, std::string alternative_location_name )
|
||||
const char *passwd, std::string locationName )
|
||||
override;
|
||||
|
||||
bool CloseAuth() override;
|
||||
|
@ -278,6 +278,14 @@ private:
|
|||
RsPeerId mOwnId;
|
||||
X509* mOwnCert;
|
||||
|
||||
/**
|
||||
* If the location name is included in SSL certificate it becomes a public
|
||||
* information, because anyone able to open an SSL connection to the host is
|
||||
* able to read it. To avoid that location name is now stored separately and
|
||||
* and not included in the SSL certificate.
|
||||
*/
|
||||
std::string mOwnLocationName;
|
||||
|
||||
RsMutex sslMtx; /* protects all below */
|
||||
|
||||
EVP_PKEY* mOwnPrivateKey;
|
||||
|
|
|
@ -477,12 +477,24 @@ void p3LinkMgrIMPL::tickMonitors()
|
|||
if (peer.actions & RS_PEER_CONNECTED)
|
||||
{
|
||||
p3Notify *notify = RsServer::notify();
|
||||
|
||||
if (notify)
|
||||
{
|
||||
// normally these two below should disappear: there's no notion of popup in libretroshare.
|
||||
// all GUI-type display features should be chosen in NotifyQt.
|
||||
notify->AddPopupMessage(RS_POPUP_CONNECT, peer.id.toStdString(),"", "Online: ");
|
||||
notify->AddFeedItem(RS_FEED_ITEM_PEER_CONNECT, peer.id.toStdString());
|
||||
|
||||
notify->notifyPeerConnected(peer.id.toStdString());
|
||||
}
|
||||
}
|
||||
if (peer.actions & RS_PEER_DISCONNECTED)
|
||||
{
|
||||
p3Notify *notify = RsServer::notify();
|
||||
|
||||
if (notify)
|
||||
notify->notifyPeerDisconnected(peer.id.toStdString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -217,6 +217,8 @@ void p3Notify::notifyChatLobbyEvent(uint64_t lobby_id, uint32_t event_type,const
|
|||
void p3Notify::notifyListPreChange(int list, int type) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyListPreChange(list,type) ; }
|
||||
void p3Notify::notifyListChange (int list, int type) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyListChange (list,type) ; }
|
||||
|
||||
void p3Notify::notifyPeerConnected (const std::string& peer_id) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyPeerConnected(peer_id); }
|
||||
void p3Notify::notifyPeerDisconnected (const std::string& peer_id) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyPeerDisconnected(peer_id); }
|
||||
void p3Notify::notifyErrorMsg (int list, int sev, std::string msg) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyErrorMsg(list,sev,msg) ; }
|
||||
void p3Notify::notifyChatMessage (const ChatMessage &msg) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyChatMessage(msg) ; }
|
||||
void p3Notify::notifyChatStatus (const ChatId& chat_id, const std::string& status_string) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyChatStatus(chat_id,status_string) ; }
|
||||
|
|
|
@ -91,6 +91,8 @@ class p3Notify: public RsNotify
|
|||
|
||||
// Notifications of clients. Can be called from anywhere inside libretroshare.
|
||||
//
|
||||
void notifyPeerConnected (const std::string& /* peer_id */);
|
||||
void notifyPeerDisconnected (const std::string& /* peer_id */);
|
||||
void notifyListPreChange (int /* list */, int /* type */) ;
|
||||
void notifyListChange (int /* list */, int /* type */) ;
|
||||
void notifyErrorMsg (int /* list */, int /* sev */, std::string /* msg */) ;
|
||||
|
|
|
@ -46,19 +46,17 @@ extern std::shared_ptr<RsBroadcastDiscovery> rsBroadcastDiscovery;
|
|||
|
||||
struct RsBroadcastDiscoveryResult : RsSerializable
|
||||
{
|
||||
PGPFingerprintType mPgpFingerprint;
|
||||
RsPeerId mSslId;
|
||||
std::string mProfileName;
|
||||
RsUrl locator;
|
||||
RsUrl mLocator;
|
||||
|
||||
/// @see RsSerializable
|
||||
void serial_process( RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx) override
|
||||
{
|
||||
RS_SERIAL_PROCESS(mPgpFingerprint);
|
||||
RS_SERIAL_PROCESS(mSslId);
|
||||
RS_SERIAL_PROCESS(mProfileName);
|
||||
RS_SERIAL_PROCESS(locator);
|
||||
RS_SERIAL_PROCESS(mLocator);
|
||||
}
|
||||
|
||||
RsBroadcastDiscoveryResult() = default;
|
||||
|
|
|
@ -37,7 +37,7 @@ class RsEvents;
|
|||
* TODO: this should become std::weak_ptr once we have a reasonable services
|
||||
* management.
|
||||
*/
|
||||
extern std::shared_ptr<RsEvents> rsEvents;
|
||||
extern RsEvents* rsEvents;
|
||||
|
||||
/**
|
||||
* @brief Events types.
|
||||
|
@ -116,21 +116,20 @@ public:
|
|||
* @return False on error, true otherwise.
|
||||
*/
|
||||
virtual bool postEvent(
|
||||
std::unique_ptr<RsEvent> event,
|
||||
std::shared_ptr<const RsEvent> event,
|
||||
std::string& errorMessage = RS_DEFAULT_STORAGE_PARAM(std::string)
|
||||
) = 0;
|
||||
|
||||
/**
|
||||
* @brief Send event directly to handlers. Blocking API
|
||||
* The handlers get exectuded on the caller thread, ensuring the function
|
||||
* returns only after the event has been handled.
|
||||
* The handlers get exectuded on the caller thread.
|
||||
* @param[in] event
|
||||
* @param[out] errorMessage Optional storage for error messsage, meaningful
|
||||
* only on failure.
|
||||
* @return False on error, true otherwise.
|
||||
*/
|
||||
virtual bool sendEvent(
|
||||
const RsEvent& event,
|
||||
std::shared_ptr<const RsEvent> event,
|
||||
std::string& errorMessage = RS_DEFAULT_STORAGE_PARAM(std::string)
|
||||
) = 0;
|
||||
|
||||
|
@ -155,7 +154,7 @@ public:
|
|||
* @return False on error, true otherwise.
|
||||
*/
|
||||
virtual bool registerEventsHandler(
|
||||
std::function<void(const RsEvent&)> multiCallback,
|
||||
std::function<void(std::shared_ptr<const RsEvent>)> multiCallback,
|
||||
RsEventsHandlerId_t& hId = RS_DEFAULT_STORAGE_PARAM(RsEventsHandlerId_t, 0)
|
||||
) = 0;
|
||||
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
* *
|
||||
* libretroshare: retroshare core library *
|
||||
* *
|
||||
* Copyright 2008-2008 by Robert Fernie <retroshare@lunamutt.com> *
|
||||
* Copyright (C) 2008 Robert Fernie <retroshare@lunamutt.com> *
|
||||
* Copyright (C) 2018-2019 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
|
@ -208,7 +209,7 @@ public:
|
|||
virtual ~RsFiles() {}
|
||||
|
||||
/**
|
||||
* Provides file data for the gui, media streaming or rpc clients.
|
||||
* @brief Provides file data for the gui, media streaming or rpc clients.
|
||||
* It may return unverified chunks. This allows streaming without having to
|
||||
* wait for hashes or completion of the file.
|
||||
* This function returns an unspecified amount of bytes. Either as much data
|
||||
|
@ -224,7 +225,7 @@ public:
|
|||
* @param[in] offset where the desired block starts
|
||||
* @param[inout] requested_size size of pre-allocated data. Will be updated
|
||||
* by the function.
|
||||
* @param data pre-allocated memory chunk of size 'requested_size' by the
|
||||
* @param[out] data pre-allocated memory chunk of size 'requested_size' by the
|
||||
* client
|
||||
* @return Returns false in case
|
||||
* - the files is not available on the local node
|
||||
|
@ -422,22 +423,47 @@ public:
|
|||
* @brief Get details about the upload with given hash
|
||||
* @jsonapi{development}
|
||||
* @param[in] hash file identifier
|
||||
* @param[in] peer_id peer identifier
|
||||
* @param[in] peerId peer identifier
|
||||
* @param[out] map storage for chunk info
|
||||
* @return true if file found, false otherwise
|
||||
*/
|
||||
virtual bool FileUploadChunksDetails(
|
||||
const RsFileHash& hash, const RsPeerId& peer_id,
|
||||
const RsFileHash& hash, const RsPeerId& peerId,
|
||||
CompressedChunkMap& map ) = 0;
|
||||
|
||||
/***
|
||||
* Extra List Access
|
||||
***/
|
||||
//virtual bool ExtraFileAdd(std::string fname, std::string hash, uint64_t size, uint32_t period, TransferRequestFlags flags) = 0;
|
||||
virtual bool ExtraFileRemove(const RsFileHash& hash) = 0;
|
||||
virtual bool ExtraFileHash(std::string localpath, uint32_t period, TransferRequestFlags flags) = 0;
|
||||
virtual bool ExtraFileStatus(std::string localpath, FileInfo &info) = 0;
|
||||
virtual bool ExtraFileMove(std::string fname, const RsFileHash& hash, uint64_t size, std::string destpath) = 0;
|
||||
/**
|
||||
* @brief Remove file from extra fila shared list
|
||||
* @jsonapi{development}
|
||||
* @param[in] hash hash of the file to remove
|
||||
* @return return false on error, true otherwise
|
||||
*/
|
||||
virtual bool ExtraFileRemove(const RsFileHash& hash) = 0;
|
||||
|
||||
/**
|
||||
* @brief Add file to extra shared file list
|
||||
* @jsonapi{development}
|
||||
* @param[in] localpath path of the file
|
||||
* @param[in] period how much time the file will be kept in extra list in
|
||||
* seconds
|
||||
* @param[in] flags sharing policy flags ex: RS_FILE_REQ_ANONYMOUS_ROUTING
|
||||
* @return false on error, true otherwise
|
||||
*/
|
||||
virtual bool ExtraFileHash(
|
||||
std::string localpath, rstime_t period, TransferRequestFlags flags
|
||||
) = 0;
|
||||
|
||||
/**
|
||||
* @brief Get extra file information
|
||||
* @jsonapi{development}
|
||||
* @param[in] localpath path of the file
|
||||
* @param[out] info storage for the file information
|
||||
* @return false on error, true otherwise
|
||||
*/
|
||||
virtual bool ExtraFileStatus(std::string localpath, FileInfo &info) = 0;
|
||||
|
||||
virtual bool ExtraFileMove(
|
||||
std::string fname, const RsFileHash& hash, uint64_t size,
|
||||
std::string destpath ) = 0;
|
||||
|
||||
/**
|
||||
* @brief Request directory details, subsequent multiple call may be used to
|
||||
|
|
|
@ -1,6 +1,37 @@
|
|||
/*******************************************************************************
|
||||
* libretroshare/src/retroshare: rsflags.h *
|
||||
* *
|
||||
* libretroshare: retroshare core library *
|
||||
* *
|
||||
* Copyright 2012-2019 by Retroshare Team <contact@retroshare.cc> *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public License *
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
*******************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <cstdint>
|
||||
|
||||
/* G10h4ck: TODO we should redefine flags in a way that the flag declaration and
|
||||
* the flags values (bit fields) would be strongly logically linked.
|
||||
* A possible way is to take an enum class containing the names of each
|
||||
* bitfield and corresponding value as template parameter, this way would also
|
||||
* avoid the need of dumb template parameter that is used only to make the
|
||||
* types incompatible but that doesn't help finding what are the possible values
|
||||
* for a kind of flag. Another appealing approach seems the first one described
|
||||
* here https://softwareengineering.stackexchange.com/questions/194412/using-scoped-enums-for-bit-flags-in-c
|
||||
* a few simple macros could be used instead of the template class */
|
||||
|
||||
// This class provides a representation for flags that can be combined with bitwise
|
||||
// operations. However, because the class is templated with an id, it's not possible to
|
||||
|
|
|
@ -142,10 +142,13 @@ public:
|
|||
* posted
|
||||
* @param[in] threadId Id of the post (that is a thread) in the channel
|
||||
* where the comment is placed
|
||||
* @param[in] comment UTF-8 string containing the comment itself
|
||||
* @param[in] authorId Id of the author of the comment
|
||||
* @param[in] parentId Id of the parent of the comment that is either a
|
||||
* channel post Id or the Id of another comment.
|
||||
* @param[in] authorId Id of the author of the comment
|
||||
* @param[in] comment UTF-8 string containing the comment itself
|
||||
* @param[in] origCommentId If this is supposed to replace an already
|
||||
* existent comment, the id of the old post.
|
||||
* If left blank a new post will be created.
|
||||
* @param[out] commentMessageId Optional storage for the id of the comment
|
||||
* that was created, meaningful only on success.
|
||||
* @param[out] errorMessage Optional storage for error message, meaningful
|
||||
|
@ -155,9 +158,10 @@ public:
|
|||
virtual bool createCommentV2(
|
||||
const RsGxsGroupId& channelId,
|
||||
const RsGxsMessageId& threadId,
|
||||
const RsGxsMessageId& parentId,
|
||||
const RsGxsId& authorId,
|
||||
const std::string& comment,
|
||||
const RsGxsId& authorId,
|
||||
const RsGxsMessageId& parentId = RsGxsMessageId(),
|
||||
const RsGxsMessageId& origCommentId = RsGxsMessageId(),
|
||||
RsGxsMessageId& commentMessageId = RS_DEFAULT_STORAGE_PARAM(RsGxsMessageId),
|
||||
std::string& errorMessage = RS_DEFAULT_STORAGE_PARAM(std::string)
|
||||
) = 0;
|
||||
|
|
|
@ -142,19 +142,6 @@ struct RsGxsComment : RsSerializable
|
|||
RS_SERIAL_PROCESS(mOwnVote);
|
||||
RS_SERIAL_PROCESS(mVotes);
|
||||
}
|
||||
|
||||
const std::ostream &print(std::ostream &out, std::string indent = "", std::string varName = "") const {
|
||||
out << indent << varName << " of RsGxsComment Values ###################" << std::endl;
|
||||
mMeta.print(out, indent + " ", "mMeta");
|
||||
out << indent << " mComment: " << mComment << std::endl;
|
||||
out << indent << " mUpVotes: " << mUpVotes << std::endl;
|
||||
out << indent << " mDownVotes: " << mDownVotes << std::endl;
|
||||
out << indent << " mScore: " << mScore << std::endl;
|
||||
out << indent << " mOwnVote: " << mOwnVote << std::endl;
|
||||
out << indent << " mVotes.size(): " << mVotes.size() << std::endl;
|
||||
out << indent << "######################################################" << std::endl;
|
||||
return out;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -52,12 +52,11 @@ namespace GXS_SERV {
|
|||
static const uint32_t FLAG_AUTHOR_AUTHENTICATION_MASK = 0x0000ff00;
|
||||
static const uint32_t FLAG_AUTHOR_AUTHENTICATION_NONE = 0x00000000;
|
||||
static const uint32_t FLAG_AUTHOR_AUTHENTICATION_GPG = 0x00000100; // Anti-spam feature. Allows to ask higher reputation to anonymous IDs
|
||||
static const uint32_t FLAG_AUTHOR_AUTHENTICATION_REQUIRED = 0x00000200; // unused
|
||||
static const uint32_t FLAG_AUTHOR_AUTHENTICATION_REQUIRED = 0x00000200;
|
||||
static const uint32_t FLAG_AUTHOR_AUTHENTICATION_IFNOPUBSIGN = 0x00000400; // ???
|
||||
static const uint32_t FLAG_AUTHOR_AUTHENTICATION_TRACK_MESSAGES = 0x00000800; // not used anymore
|
||||
static const uint32_t FLAG_AUTHOR_AUTHENTICATION_GPG_KNOWN = 0x00001000; // Anti-spam feature. Allows to ask higher reputation to unknown IDs and anonymous IDs
|
||||
|
||||
// These are *not used*
|
||||
static const uint32_t FLAG_GROUP_SIGN_PUBLISH_MASK = 0x000000ff;
|
||||
static const uint32_t FLAG_GROUP_SIGN_PUBLISH_ENCRYPTED = 0x00000001;
|
||||
static const uint32_t FLAG_GROUP_SIGN_PUBLISH_ALLSIGNED = 0x00000002; // unused
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
* *
|
||||
* libretroshare: retroshare core library *
|
||||
* *
|
||||
* Copyright (C) 2012 by Robert Fernie <retroshare@lunamutt.com> *
|
||||
* Copyright (C) 2018 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||
* Copyright (C) 2012-2014 Robert Fernie <retroshare@lunamutt.com> *
|
||||
* Copyright (C) 2018-2019 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
|
@ -30,9 +30,9 @@
|
|||
#include "retroshare/rsgxsifacehelper.h"
|
||||
#include "serialiser/rstlvidset.h"
|
||||
#include "serialiser/rsserializable.h"
|
||||
#include "retroshare/rsgxscircles.h"
|
||||
|
||||
|
||||
/* The Main Interface Class - for information about your Peers */
|
||||
class RsGxsForums;
|
||||
|
||||
/**
|
||||
|
@ -43,8 +43,10 @@ extern RsGxsForums* rsGxsForums;
|
|||
|
||||
|
||||
/** Forum Service message flags, to be used in RsMsgMetaData::mMsgFlags
|
||||
* Gxs imposes to use the first two bytes (lower bytes) of mMsgFlags for
|
||||
* Gxs imposes to use the first two bytes (lower bytes) of mMsgFlags for
|
||||
* private forum flags, the upper bytes being used for internal GXS stuff.
|
||||
* @todo mixing service level flags and GXS level flag into the same member is
|
||||
* prone to confusion, use separated members for those things
|
||||
*/
|
||||
static const uint32_t RS_GXS_FORUM_MSG_FLAGS_MASK = 0x0000000f;
|
||||
static const uint32_t RS_GXS_FORUM_MSG_FLAGS_MODERATED = 0x00000001;
|
||||
|
@ -54,46 +56,52 @@ static const uint32_t RS_GXS_FORUM_MSG_FLAGS_MODERATED = 0x00000001;
|
|||
|
||||
struct RsGxsForumGroup : RsSerializable
|
||||
{
|
||||
virtual ~RsGxsForumGroup() {}
|
||||
|
||||
/** Forum GXS metadata */
|
||||
RsGroupMetaData mMeta;
|
||||
|
||||
/** @brief Forum desciption */
|
||||
std::string mDescription;
|
||||
|
||||
/* What's below is optional, and handled by the serialiser
|
||||
* TODO: run away from TLV old serializables as those types are opaque to
|
||||
* JSON API! */
|
||||
/** @brief List of forum moderators ids
|
||||
* @todo run away from TLV old serializables as those types are opaque to
|
||||
* JSON API! */
|
||||
RsTlvGxsIdSet mAdminList;
|
||||
|
||||
/** @brief List of forum pinned posts, those are usually displayed on top
|
||||
* @todo run away from TLV old serializables as those types are opaque to
|
||||
* JSON API! */
|
||||
RsTlvGxsMsgIdSet mPinnedPosts;
|
||||
|
||||
/// @see RsSerializable
|
||||
virtual void serial_process( RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx )
|
||||
{
|
||||
RS_SERIAL_PROCESS(mMeta);
|
||||
RS_SERIAL_PROCESS(mDescription);
|
||||
RS_SERIAL_PROCESS(mAdminList);
|
||||
RS_SERIAL_PROCESS(mPinnedPosts);
|
||||
}
|
||||
virtual void serial_process(
|
||||
RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx ) override;
|
||||
|
||||
// utility functions
|
||||
~RsGxsForumGroup() override;
|
||||
|
||||
bool canEditPosts(const RsGxsId& id) const { return mAdminList.ids.find(id) != mAdminList.ids.end() || id == mMeta.mAuthorId; }
|
||||
/* G10h4ck: We should avoid actual methods in this contexts as they are
|
||||
* invisible to JSON API */
|
||||
bool canEditPosts(const RsGxsId& id) const;
|
||||
};
|
||||
|
||||
struct RsGxsForumMsg : RsSerializable
|
||||
{
|
||||
virtual ~RsGxsForumMsg() {}
|
||||
|
||||
/** @brief Forum post GXS metadata */
|
||||
RsMsgMetaData mMeta;
|
||||
|
||||
/** @brief Forum post content */
|
||||
std::string mMsg;
|
||||
|
||||
/// @see RsSerializable
|
||||
virtual void serial_process( RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx )
|
||||
virtual void serial_process(
|
||||
RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx ) override
|
||||
{
|
||||
RS_SERIAL_PROCESS(mMeta);
|
||||
RS_SERIAL_PROCESS(mMsg);
|
||||
}
|
||||
|
||||
~RsGxsForumMsg() override;
|
||||
};
|
||||
|
||||
|
||||
|
@ -101,23 +109,67 @@ class RsGxsForums: public RsGxsIfaceHelper
|
|||
{
|
||||
public:
|
||||
explicit RsGxsForums(RsGxsIface& gxs) : RsGxsIfaceHelper(gxs) {}
|
||||
virtual ~RsGxsForums() {}
|
||||
virtual ~RsGxsForums();
|
||||
|
||||
/**
|
||||
* @brief Create forum. Blocking API.
|
||||
* @brief Create forum.
|
||||
* @jsonapi{development}
|
||||
* @param[inout] forum Forum data (name, description...)
|
||||
* @return false on error, true otherwise
|
||||
* @param[in] name Name of the forum
|
||||
* @param[in] description Optional description of the forum
|
||||
* @param[in] authorId Optional id of the froum owner author
|
||||
* @param[in] moderatorsIds Optional list of forum moderators
|
||||
* @param[in] circleType Optional visibility rule, default public.
|
||||
* @param[in] circleId If the forum is not public specify the id of
|
||||
* the circle who can see the forum. Depending on
|
||||
* the value you pass for circleType this should
|
||||
* be a circle if EXTERNAL is passed, a local
|
||||
* friends group id if NODES_GROUP is passed,
|
||||
* empty otherwise.
|
||||
* @param[out] forumId Optional storage for the id of the created
|
||||
* forum, meaningful only if creations succeeds.
|
||||
* @param[out] errorMessage Optional storage for error messsage, meaningful
|
||||
* only if creation fail.
|
||||
* @return False on error, true otherwise.
|
||||
*/
|
||||
virtual bool createForum(RsGxsForumGroup& forum) = 0;
|
||||
virtual bool createForumV2(
|
||||
const std::string& name, const std::string& description,
|
||||
const RsGxsId& authorId = RsGxsId(),
|
||||
const std::set<RsGxsId>& moderatorsIds = std::set<RsGxsId>(),
|
||||
RsGxsCircleType circleType = RsGxsCircleType::PUBLIC,
|
||||
const RsGxsCircleId& circleId = RsGxsCircleId(),
|
||||
RsGxsGroupId& forumId = RS_DEFAULT_STORAGE_PARAM(RsGxsGroupId),
|
||||
std::string& errorMessage = RS_DEFAULT_STORAGE_PARAM(std::string)
|
||||
) = 0;
|
||||
|
||||
/**
|
||||
* @brief Create forum message. Blocking API.
|
||||
* @brief Create a post on the given forum.
|
||||
* @jsonapi{development}
|
||||
* @param[inout] message
|
||||
* @param[in] forumId Id of the forum in which the post is to be
|
||||
* submitted
|
||||
* @param[in] title UTF-8 string containing the title of the post
|
||||
* @param[in] mBody UTF-8 string containing the text of the post
|
||||
* @param[in] authorId Id of the author of the comment
|
||||
* @param[in] parentId Optional Id of the parent post if this post is a
|
||||
* reply to another post, empty otherwise.
|
||||
* @param[in] origPostId If this is supposed to replace an already
|
||||
* existent post, the id of the old post.
|
||||
* If left blank a new post will be created.
|
||||
* @param[out] postMsgId Optional storage for the id of the created,
|
||||
* meaningful only on success.
|
||||
* @param[out] errorMessage Optional storage for error message, meaningful
|
||||
* only on failure.
|
||||
* @return false on error, true otherwise
|
||||
*/
|
||||
virtual bool createMessage(RsGxsForumMsg& message) = 0;
|
||||
virtual bool createPost(
|
||||
const RsGxsGroupId& forumId,
|
||||
const std::string& title,
|
||||
const std::string& mBody,
|
||||
const RsGxsId& authorId,
|
||||
const RsGxsMessageId& parentId = RsGxsMessageId(),
|
||||
const RsGxsMessageId& origPostId = RsGxsMessageId(),
|
||||
RsGxsMessageId& postMsgId = RS_DEFAULT_STORAGE_PARAM(RsGxsMessageId),
|
||||
std::string& errorMessage = RS_DEFAULT_STORAGE_PARAM(std::string)
|
||||
) = 0;
|
||||
|
||||
/**
|
||||
* @brief Edit forum details.
|
||||
|
@ -167,7 +219,7 @@ public:
|
|||
*/
|
||||
virtual bool getForumContent(
|
||||
const RsGxsGroupId& forumId,
|
||||
std::set<RsGxsMessageId>& msgsIds,
|
||||
const std::set<RsGxsMessageId>& msgsIds,
|
||||
std::vector<RsGxsForumMsg>& msgs) = 0;
|
||||
|
||||
/**
|
||||
|
@ -189,6 +241,26 @@ public:
|
|||
virtual bool subscribeToForum( const RsGxsGroupId& forumId,
|
||||
bool subscribe ) = 0;
|
||||
|
||||
/**
|
||||
* @brief Create forum. Blocking API.
|
||||
* @jsonapi{development}
|
||||
* @param[inout] forum Forum data (name, description...)
|
||||
* @return false on error, true otherwise
|
||||
* @deprecated @see createForumV2
|
||||
*/
|
||||
RS_DEPRECATED_FOR(createForumV2)
|
||||
virtual bool createForum(RsGxsForumGroup& forum) = 0;
|
||||
|
||||
/**
|
||||
* @brief Create forum message. Blocking API.
|
||||
* @jsonapi{development}
|
||||
* @param[inout] message
|
||||
* @return false on error, true otherwise
|
||||
* @deprecated @see createPost
|
||||
*/
|
||||
RS_DEPRECATED_FOR(createPost)
|
||||
virtual bool createMessage(RsGxsForumMsg& message) = 0;
|
||||
|
||||
/* Specific Service Data */
|
||||
RS_DEPRECATED_FOR("getForumsSummaries, getForumsInfo")
|
||||
virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsForumGroup> &groups) = 0;
|
||||
|
@ -203,4 +275,3 @@ public:
|
|||
RS_DEPRECATED_FOR(editForum)
|
||||
virtual bool updateGroup(uint32_t &token, RsGxsForumGroup &group) = 0;
|
||||
};
|
||||
|
||||
|
|
|
@ -91,6 +91,7 @@ struct RsGxsChanges : RsEvent
|
|||
void serial_process( RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx) override
|
||||
{
|
||||
RsEvent::serial_process(j,ctx);
|
||||
RS_SERIAL_PROCESS(mServiceType);
|
||||
RS_SERIAL_PROCESS(mMsgs);
|
||||
RS_SERIAL_PROCESS(mMsgsMeta);
|
||||
|
@ -99,7 +100,7 @@ struct RsGxsChanges : RsEvent
|
|||
RS_SERIAL_PROCESS(mDistantSearchReqs);
|
||||
}
|
||||
|
||||
RsTokenService* mService; // Weak pointer, not serialized
|
||||
RsTokenService* mService; /// Weak pointer, not serialized
|
||||
};
|
||||
|
||||
/*!
|
||||
|
|
|
@ -140,14 +140,20 @@ struct RsMsgMetaData : RsSerializable
|
|||
std::string mMsgName;
|
||||
rstime_t mPublishTs;
|
||||
|
||||
/// the lower 16 bits for service, upper 16 bits for GXS
|
||||
uint32_t mMsgFlags;
|
||||
/** the lower 16 bits for service, upper 16 bits for GXS
|
||||
* @todo mixing service level flags and GXS level flag into the same member
|
||||
* is prone to confusion, use separated members for those things, this could
|
||||
* be done without breaking network retro-compatibility */
|
||||
uint32_t mMsgFlags;
|
||||
|
||||
// BELOW HERE IS LOCAL DATA, THAT IS NOT FROM MSG.
|
||||
// normally READ / UNREAD flags. LOCAL Data.
|
||||
|
||||
/// the first 16 bits for service, last 16 for GXS
|
||||
uint32_t mMsgStatus;
|
||||
/** the first 16 bits for service, last 16 for GXS
|
||||
* @todo mixing service level flags and GXS level flag into the same member
|
||||
* is prone to confusion, use separated members for those things, this could
|
||||
* be done without breaking network retro-compatibility */
|
||||
uint32_t mMsgStatus;
|
||||
|
||||
rstime_t mChildTs;
|
||||
std::string mServiceString; // Service Specific Free-Form extra storage.
|
||||
|
@ -169,25 +175,6 @@ struct RsMsgMetaData : RsSerializable
|
|||
RS_SERIAL_PROCESS(mChildTs);
|
||||
RS_SERIAL_PROCESS(mServiceString);
|
||||
}
|
||||
|
||||
const std::ostream &print(std::ostream &out, std::string indent = "", std::string varName = "") const {
|
||||
out
|
||||
<< indent << varName << " of RsMsgMetaData Values ###################" << std::endl
|
||||
<< indent << " mGroupId: " << mGroupId.toStdString() << std::endl
|
||||
<< indent << " mMsgId: " << mMsgId.toStdString() << std::endl
|
||||
<< indent << " mThreadId: " << mThreadId.toStdString() << std::endl
|
||||
<< indent << " mParentId: " << mParentId.toStdString() << std::endl
|
||||
<< indent << " mOrigMsgId: " << mOrigMsgId.toStdString() << std::endl
|
||||
<< indent << " mAuthorId: " << mAuthorId.toStdString() << std::endl
|
||||
<< indent << " mMsgName: " << mMsgName << std::endl
|
||||
<< indent << " mPublishTs: " << mPublishTs << std::endl
|
||||
<< indent << " mMsgFlags: " << std::hex << mMsgFlags << std::dec << std::endl
|
||||
<< indent << " mMsgStatus: " << std::hex << mMsgStatus << std::dec << std::endl
|
||||
<< indent << " mChildTs: " << mChildTs << std::endl
|
||||
<< indent << " mServiceString: " << mServiceString << std::endl
|
||||
<< indent << "######################################################" << std::endl;
|
||||
return out;
|
||||
}
|
||||
};
|
||||
|
||||
class GxsGroupStatistic
|
||||
|
|
|
@ -1,3 +1,23 @@
|
|||
/*******************************************************************************
|
||||
* libretroshare/src/retroshare: rsgxstrans.h *
|
||||
* *
|
||||
* libretroshare: retroshare core library *
|
||||
* *
|
||||
* Copyright (C) 2016-2019 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License version 3 as *
|
||||
* published by the Free Software Foundation. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public License *
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
*******************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "retroshare/rstokenservice.h"
|
||||
|
@ -41,7 +61,8 @@ enum class GxsTransSendStatus : uint8_t
|
|||
/// Records with status >= RECEIPT_RECEIVED get deleted
|
||||
RECEIPT_RECEIVED = 0x0a,
|
||||
FAILED_RECEIPT_SIGNATURE = 0xf0,
|
||||
FAILED_ENCRYPTION = 0xf1
|
||||
FAILED_ENCRYPTION = 0xf1,
|
||||
FAILED_TIMED_OUT = 0xf2
|
||||
};
|
||||
|
||||
typedef uint64_t RsGxsTransId;
|
||||
|
@ -79,6 +100,7 @@ struct RsGxsTransOutgoingRecord
|
|||
RsGxsGroupId group_id ;
|
||||
};
|
||||
|
||||
/// RetroShare GxsTrans asyncronous redundant small mail trasport on top of GXS
|
||||
class RsGxsTrans: public RsGxsIfaceHelper
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -244,14 +244,22 @@ struct RsIdentityUsage : RsSerializable
|
|||
CIRCLE_MEMBERSHIP_CHECK = 0x13
|
||||
} ;
|
||||
|
||||
RS_DEPRECATED
|
||||
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() );
|
||||
|
||||
RsIdentityUsage( RsServiceType service,
|
||||
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;
|
||||
RsServiceType mServiceId;
|
||||
|
||||
/** Specific code to use. Will allow forming the correct translated message
|
||||
* in the GUI if necessary. */
|
||||
|
@ -380,6 +388,7 @@ struct RsIdentity : RsGxsIfaceHelper
|
|||
|
||||
/**
|
||||
* @brief Get identity details, from the cache
|
||||
* @jsonapi{development}
|
||||
* @param[in] id Id of the identity
|
||||
* @param[out] details Storage for the identity details
|
||||
* @return false on error, true otherwise
|
||||
|
@ -400,7 +409,7 @@ struct RsIdentity : RsGxsIfaceHelper
|
|||
* @param[out] ids storage for the ids
|
||||
* @return false on error, true otherwise
|
||||
*/
|
||||
virtual bool getOwnSignedIds(std::vector<RsGxsId> ids) = 0;
|
||||
virtual bool getOwnSignedIds(std::vector<RsGxsId>& ids) = 0;
|
||||
|
||||
/**
|
||||
* @brief Get own pseudonimous (unsigned) ids
|
||||
|
@ -408,7 +417,7 @@ struct RsIdentity : RsGxsIfaceHelper
|
|||
* @param[out] ids storage for the ids
|
||||
* @return false on error, true otherwise
|
||||
*/
|
||||
virtual bool getOwnPseudonimousIds(std::vector<RsGxsId> ids) = 0;
|
||||
virtual bool getOwnPseudonimousIds(std::vector<RsGxsId>& ids) = 0;
|
||||
|
||||
/**
|
||||
* @brief Check if an id is own
|
||||
|
@ -468,6 +477,7 @@ struct RsIdentity : RsGxsIfaceHelper
|
|||
|
||||
/**
|
||||
* @brief Set/unset identity as contact
|
||||
* @jsonapi{development}
|
||||
* @param[in] id Id of the identity
|
||||
* @param[in] isContact true to set, false to unset
|
||||
* @return false on error, true otherwise
|
||||
|
@ -503,6 +513,14 @@ struct RsIdentity : RsGxsIfaceHelper
|
|||
*/
|
||||
virtual void setDeleteBannedNodesThreshold(uint32_t days) = 0;
|
||||
|
||||
/**
|
||||
* @brief request details of a not yet known identity to the network
|
||||
* @jsonapi{development}
|
||||
* @param[in] id id of the identity to request
|
||||
* @return false on error, true otherwise
|
||||
*/
|
||||
virtual bool requestIdentity(const RsGxsId& id) = 0;
|
||||
|
||||
|
||||
RS_DEPRECATED
|
||||
virtual bool getGroupSerializedData(
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
/*******************************************************************************
|
||||
* libretroshare/src/retroshare: rsinit.h *
|
||||
* *
|
||||
* libretroshare: retroshare core library *
|
||||
* *
|
||||
* Copyright 2004-2006 by Robert Fernie <retroshare@lunamutt.com> *
|
||||
* Copyright (C) 2004-2014 Robert Fernie <retroshare@lunamutt.com> *
|
||||
* Copyright (C) 2016-2019 Gioacchino Mazzurco <gio@altermundi.net> *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
|
@ -19,8 +18,10 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
*******************************************************************************/
|
||||
#ifndef RETROSHARE_INIT_INTERFACE_H
|
||||
#define RETROSHARE_INIT_INTERFACE_H
|
||||
#pragma once
|
||||
|
||||
/// RetroShare initialization and login API
|
||||
|
||||
|
||||
// Initialize ok, result >= 0
|
||||
#define RS_INIT_OK 0 // Initialize ok
|
||||
|
@ -30,13 +31,6 @@
|
|||
#define RS_INIT_BASE_DIR_ERROR -2 // AuthGPG::InitAuth failed
|
||||
#define RS_INIT_NO_KEYRING -3 // Keyring is empty. Need to import it.
|
||||
|
||||
|
||||
/****
|
||||
* #define RS_USE_PGPSSL 1
|
||||
***/
|
||||
|
||||
#define RS_USE_PGPSSL 1
|
||||
|
||||
#include <stdint.h>
|
||||
#include <list>
|
||||
#include <map>
|
||||
|
@ -340,5 +334,3 @@ struct RsLoginHelper
|
|||
*/
|
||||
bool isLoggedIn();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -470,6 +470,8 @@ public:
|
|||
std::map<RsGxsId, rstime_t> gxs_ids ; // list of non direct friend who participate. Used to display only.
|
||||
rstime_t last_activity ; // last recorded activity. Useful for removing dead lobbies.
|
||||
|
||||
virtual void clear() { gxs_ids.clear(); lobby_id = 0; lobby_name.clear(); lobby_topic.clear(); participating_friends.clear(); }
|
||||
|
||||
// RsSerializable interface
|
||||
public:
|
||||
void serial_process(RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext &ctx) {
|
||||
|
@ -831,6 +833,13 @@ virtual void getOwnAvatarData(unsigned char *& data,int& size) = 0 ;
|
|||
*/
|
||||
virtual void unsubscribeChatLobby(const ChatLobbyId &lobby_id) = 0;
|
||||
|
||||
/**
|
||||
* @brief sendLobbyStatusPeerLeaving notify friend nodes that we're leaving a subscribed lobby
|
||||
* @jsonapi{development}
|
||||
* @param[in] lobby_id lobby to leave
|
||||
*/
|
||||
virtual void sendLobbyStatusPeerLeaving(const ChatLobbyId& lobby_id) = 0;
|
||||
|
||||
/**
|
||||
* @brief setIdentityForChatLobby set the chat identit
|
||||
* @jsonapi{development}
|
||||
|
|
|
@ -212,6 +212,8 @@ public:
|
|||
NotifyClient() {}
|
||||
virtual ~NotifyClient() {}
|
||||
|
||||
virtual void notifyPeerConnected (const std::string& /* peer_id */) {}
|
||||
virtual void notifyPeerDisconnected (const std::string& /* peer_id */) {}
|
||||
virtual void notifyListPreChange (int /* list */, int /* type */) {}
|
||||
virtual void notifyListChange (int /* list */, int /* type */) {}
|
||||
virtual void notifyErrorMsg (int /* list */, int /* sev */, std::string /* msg */) {}
|
||||
|
|
|
@ -231,7 +231,7 @@ struct RsPeerDetails : RsSerializable
|
|||
|
||||
RsPgpId issuer;
|
||||
|
||||
PGPFingerprintType fpr; /* pgp fingerprint */
|
||||
RsPgpFingerprint fpr; /* pgp fingerprint */
|
||||
std::string authcode; // TODO: 2015/12/31 (cyril) what is this used for ?????
|
||||
std::list<RsPgpId> gpgSigners;
|
||||
|
||||
|
@ -499,9 +499,9 @@ public:
|
|||
virtual RsPgpId getGPGId(const RsPeerId& sslId) = 0;
|
||||
virtual bool isKeySupported(const RsPgpId& gpg_ids) = 0;
|
||||
virtual bool getGPGAcceptedList(std::list<RsPgpId> &gpg_ids) = 0;
|
||||
virtual bool getGPGSignedList(std::list<RsPgpId> &gpg_ids) = 0;//friends that we accpet to connect with but we don't want to sign their gpg key
|
||||
virtual bool getGPGValidList(std::list<RsPgpId> &gpg_ids) = 0;
|
||||
virtual bool getGPGAllList(std::list<RsPgpId> &gpg_ids) = 0;
|
||||
virtual bool getGPGSignedList(std::list<RsPgpId> &gpg_ids) = 0;// keys signed by our own PGP key.
|
||||
virtual bool getGPGValidList(std::list<RsPgpId> &gpg_ids) = 0;// all PGP keys without filtering
|
||||
virtual bool getGPGAllList(std::list<RsPgpId> &gpg_ids) = 0;// all PGP keys as well
|
||||
virtual bool getAssociatedSSLIds(const RsPgpId& gpg_id, std::list<RsPeerId>& ids) = 0;
|
||||
virtual bool gpgSignData(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen, std::string reason = "") = 0;
|
||||
|
||||
|
|
|
@ -347,12 +347,12 @@ const std::string CUPnPLib::Element_GetAttributeByTag(
|
|||
|
||||
|
||||
CUPnPError::CUPnPError(
|
||||
const CUPnPLib &upnpLib,
|
||||
IXML_Document *errorDoc)
|
||||
:
|
||||
m_root (upnpLib.Element_GetRootElement(errorDoc)),
|
||||
m_ErrorCode (upnpLib.Element_GetChildValueByTag(m_root, "errorCode")),
|
||||
m_ErrorDescription(upnpLib.Element_GetChildValueByTag(m_root, "errorDescription"))
|
||||
const CUPnPLib &upnpLib,
|
||||
const IXML_Document *errorDoc)
|
||||
:
|
||||
m_root (upnpLib.Element_GetRootElement(errorDoc)),
|
||||
m_ErrorCode (upnpLib.Element_GetChildValueByTag(m_root, "errorCode")),
|
||||
m_ErrorDescription(upnpLib.Element_GetChildValueByTag(m_root, "errorDescription"))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -488,7 +488,8 @@ m_timeout(1801),
|
|||
m_SCPD(NULL)
|
||||
{
|
||||
int errcode;
|
||||
|
||||
m_SID[0]=0;
|
||||
|
||||
std::vector<char> vscpdURL(URLBase.length() + m_SCPDURL.length() + 1);
|
||||
char *scpdURL = &vscpdURL[0];
|
||||
errcode = UpnpResolveURL(
|
||||
|
@ -1333,6 +1334,12 @@ int CUPnPControlPoint::Callback(
|
|||
std::string devType(upnpCP->m_upnpLib.
|
||||
Element_GetChildValueByTag(rootDevice, "deviceType"));
|
||||
|
||||
#ifdef UPNP_DEBUG
|
||||
std::cerr << "CUPnPControlPoint::Callback() EventType==UPNP_DISCOVERY_SEARCH_RESULT" << std::endl
|
||||
<< "urlBase:" << urlBase << std::endl
|
||||
<< "devType:" << devType << std::endl;
|
||||
#endif
|
||||
|
||||
// Only add device if it is an InternetGatewayDevice
|
||||
if (stdStringIsEqualCI(devType, upnpCP->m_upnpLib.UPNP_DEVICE_IGW))
|
||||
{
|
||||
|
@ -1351,6 +1358,10 @@ int CUPnPControlPoint::Callback(
|
|||
rootDevice, urlBase,
|
||||
UpnpDiscovery_get_Location_cstr(d_event),
|
||||
UpnpDiscovery_get_Expires(d_event) );
|
||||
|
||||
#if (UPNP_VERSION > 10624) && (UPNP_VERSION < 10800)
|
||||
upnpCP->m_WaitForSearchTimeoutMutex.unlock();
|
||||
#endif
|
||||
}
|
||||
|
||||
// Free the XML doc tree
|
||||
|
@ -1359,6 +1370,13 @@ int CUPnPControlPoint::Callback(
|
|||
}
|
||||
case UPNP_DISCOVERY_SEARCH_TIMEOUT:
|
||||
{
|
||||
#if (UPNP_VERSION > 10624) && (UPNP_VERSION < 10800)
|
||||
std::cerr << "********************************************************************************" << std::endl
|
||||
<< "*** THIS SHOULD NOT HAPPEN !!! TELL IT TO DEVS ***" << std::endl
|
||||
<< "*** UPnPBase.cpp CUPnPControlPoint::Callback() UPNP_DISCOVERY_SEARCH_TIMEOUT ***" << std::endl
|
||||
<< "********************************************************************************" << std::endl;
|
||||
#endif
|
||||
|
||||
// Unlock the search timeout mutex
|
||||
upnpCP->m_WaitForSearchTimeoutMutex.unlock();
|
||||
break;
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
extern std::string stdEmptyString;
|
||||
#endif // UPNP_C
|
||||
|
||||
//#define UPNP_DEBUG 1
|
||||
|
||||
/**
|
||||
* Case insensitive std::string comparison
|
||||
|
@ -255,7 +256,7 @@ private:
|
|||
public:
|
||||
CUPnPError(
|
||||
const CUPnPLib &upnpLib,
|
||||
IXML_Document *errorDoc);
|
||||
const IXML_Document *errorDoc);
|
||||
~CUPnPError() {}
|
||||
const std::string &getErrorCode() const
|
||||
{ return m_ErrorCode; }
|
||||
|
|
|
@ -35,8 +35,6 @@
|
|||
#include "pqi/p3linkmgr.h"
|
||||
#include "pqi/p3netmgr.h"
|
||||
|
||||
int rsserverzone = 101;
|
||||
|
||||
#include "util/rsdebug.h"
|
||||
|
||||
#include "retroshare/rsevents.h"
|
||||
|
@ -86,7 +84,7 @@ RsServer::RsServer() :
|
|||
{
|
||||
{
|
||||
RsEventsService* tmpRsEvtPtr = new RsEventsService();
|
||||
rsEvents.reset(tmpRsEvtPtr);
|
||||
rsEvents = tmpRsEvtPtr;
|
||||
startServiceThread(tmpRsEvtPtr, "RsEventsService");
|
||||
}
|
||||
|
||||
|
@ -271,8 +269,6 @@ void RsServer::data_tick()
|
|||
std::string out;
|
||||
rs_sprintf(out, "RsServer::run() WARNING Excessively Long Cycle Time: %g secs => Please DEBUG", cycleTime);
|
||||
std::cerr << out << std::endl;
|
||||
|
||||
rslog(RSL_ALERT, rsserverzone, out);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -453,6 +453,10 @@ void p3Msgs::invitePeerToLobby(const ChatLobbyId& lobby_id, const RsPeerId& peer
|
|||
{
|
||||
mChatSrv->invitePeerToLobby(lobby_id,peer_id) ;
|
||||
}
|
||||
void p3Msgs::sendLobbyStatusPeerLeaving(const ChatLobbyId& lobby_id)
|
||||
{
|
||||
mChatSrv->sendLobbyStatusPeerLeaving(lobby_id) ;
|
||||
}
|
||||
void p3Msgs::unsubscribeChatLobby(const ChatLobbyId& lobby_id)
|
||||
{
|
||||
mChatSrv->unsubscribeChatLobby(lobby_id) ;
|
||||
|
|
|
@ -147,6 +147,7 @@ class p3Msgs: public RsMsgs
|
|||
virtual void denyLobbyInvite(const ChatLobbyId& id) ;
|
||||
virtual void getPendingChatLobbyInvites(std::list<ChatLobbyInvite>& invites) ;
|
||||
virtual void unsubscribeChatLobby(const ChatLobbyId& lobby_id) ;
|
||||
virtual void sendLobbyStatusPeerLeaving(const ChatLobbyId& lobby_id);
|
||||
virtual bool setIdentityForChatLobby(const ChatLobbyId& lobby_id,const RsGxsId&) ;
|
||||
virtual bool getIdentityForChatLobby(const ChatLobbyId&,RsGxsId& nick) ;
|
||||
virtual bool setDefaultIdentityForChatLobby(const RsGxsId&) ;
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
/*******************************************************************************
|
||||
* libretroshare/src/retroshare: rsinit.cc *
|
||||
* *
|
||||
* libretroshare: retroshare core library *
|
||||
* *
|
||||
* Copyright 2004-2006 by Robert Fernie <retroshare@lunamutt.com> *
|
||||
* Copyright (C) 2004-2014 Robert Fernie <retroshare@lunamutt.com> *
|
||||
* Copyright (C) 2016-2019 Gioacchino Mazzurco <gio@altermundi.net> *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
|
@ -20,8 +19,7 @@
|
|||
* *
|
||||
*******************************************************************************/
|
||||
|
||||
/* This is an updated startup class. Class variables are hidden from
|
||||
* the GUI / External via a hidden class */
|
||||
/// RetroShare initialization and login API implementation
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
* *
|
||||
* libretroshare: retroshare core library *
|
||||
* *
|
||||
* Copyright (C) 2017 Cyril Soler <csoler@users.sourceforge.net> *
|
||||
* Copyright (C) 2018 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||
* Copyright (C) 2017 Cyril Soler <csoler@users.sourceforge.net> *
|
||||
* Copyright (C) 2018-2019 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
|
@ -39,8 +39,7 @@
|
|||
#include <rapid_json/prettywriter.h>
|
||||
#endif // HAS_RAPIDJSON
|
||||
|
||||
//static const uint32_t MAX_SERIALIZED_ARRAY_SIZE = 500 ;
|
||||
static const uint32_t MAX_SERIALIZED_CHUNK_SIZE = 10*1024*1024 ; // 10 MB.
|
||||
static constexpr uint32_t MAX_SERIALIZED_CHUNK_SIZE = 10*1024*1024 ; // 10 MB.
|
||||
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
# define SAFE_GET_JSON_V() \
|
||||
|
@ -63,6 +62,61 @@ static const uint32_t MAX_SERIALIZED_CHUNK_SIZE = 10*1024*1024 ; // 10 MB.
|
|||
#endif // ifdef RSSERIAL_DEBUG
|
||||
|
||||
|
||||
//============================================================================//
|
||||
// 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(),
|
||||
static_cast<rapidjson::SizeType>(membername.length()),
|
||||
allocator );
|
||||
|
||||
rapidjson::Value value;
|
||||
value.SetString( member.c_str(),
|
||||
static_cast<rapidjson::SizeType>(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;
|
||||
}
|
||||
|
||||
//============================================================================//
|
||||
// Integer types //
|
||||
//============================================================================//
|
||||
|
@ -199,7 +253,9 @@ template<> bool RsTypeSerializer::to_JSON( const std::string& memberName, \
|
|||
rapidjson::Document::AllocatorType& allocator = jDoc.GetAllocator(); \
|
||||
\
|
||||
rapidjson::Value key; \
|
||||
key.SetString(memberName.c_str(), memberName.length(), allocator); \
|
||||
key.SetString( memberName.c_str(), \
|
||||
static_cast<rapidjson::SizeType>(memberName.length()), \
|
||||
allocator ); \
|
||||
\
|
||||
rapidjson::Value value(member); \
|
||||
\
|
||||
|
@ -210,12 +266,39 @@ template<> bool RsTypeSerializer::to_JSON( const std::string& memberName, \
|
|||
|
||||
SIMPLE_TO_JSON_DEF(bool)
|
||||
SIMPLE_TO_JSON_DEF(int32_t)
|
||||
SIMPLE_TO_JSON_DEF(rstime_t)
|
||||
|
||||
SIMPLE_TO_JSON_DEF(uint8_t)
|
||||
SIMPLE_TO_JSON_DEF(uint16_t)
|
||||
SIMPLE_TO_JSON_DEF(uint32_t)
|
||||
SIMPLE_TO_JSON_DEF(uint64_t)
|
||||
|
||||
/** Be very careful in changing this constant as it would break 64 bit integers
|
||||
* members JSON string representation retrocompatibility */
|
||||
static constexpr char strReprSuffix[] = "_sixtyfour_str";
|
||||
|
||||
/** While JSON doesn't have problems representing 64 bit integers JavaScript
|
||||
* standard represents numbers in a double-like format thus it is not capable to
|
||||
* handle safely integers outside the range [-(2^53 - 1), 2^53 - 1], so we add
|
||||
* to JSON also the string representation for this types as a workaround for the
|
||||
* sake of JavaScript clients @see https://stackoverflow.com/a/34989371
|
||||
*/
|
||||
#define SIXTYFOUR_INTEGERS_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(), \
|
||||
static_cast<rapidjson::SizeType>(memberName.length()), \
|
||||
allocator ); \
|
||||
rapidjson::Value value(member); \
|
||||
jDoc.AddMember(key, value, allocator); \
|
||||
\
|
||||
return to_JSON(memberName + strReprSuffix, std::to_string(member), jDoc); \
|
||||
}
|
||||
|
||||
SIXTYFOUR_INTEGERS_TO_JSON_DEF(int64_t);
|
||||
SIXTYFOUR_INTEGERS_TO_JSON_DEF(uint64_t);
|
||||
|
||||
template<> /*static*/
|
||||
bool RsTypeSerializer::from_JSON( const std::string& memberName, bool& member,
|
||||
|
@ -237,23 +320,13 @@ bool RsTypeSerializer::from_JSON( const std::string& memberName,
|
|||
return ret;
|
||||
}
|
||||
|
||||
template<> /*static*/
|
||||
bool RsTypeSerializer::from_JSON( const std::string& memberName, rstime_t& member,
|
||||
RsJson& jDoc )
|
||||
{
|
||||
SAFE_GET_JSON_V();
|
||||
ret = ret && v.IsInt64();
|
||||
if(ret) member = v.GetInt64();
|
||||
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();
|
||||
if(ret) member = static_cast<uint8_t>(v.GetUint());
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -263,7 +336,7 @@ bool RsTypeSerializer::from_JSON( const std::string& memberName,
|
|||
{
|
||||
SAFE_GET_JSON_V();
|
||||
ret = ret && v.IsUint();
|
||||
if(ret) member = v.GetUint();
|
||||
if(ret) member = static_cast<uint16_t>(v.GetUint());
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -277,14 +350,98 @@ bool RsTypeSerializer::from_JSON( const std::string& memberName,
|
|||
return ret;
|
||||
}
|
||||
|
||||
/** While JSON doesn't have problems representing 64 bit integers JavaScript
|
||||
* standard represents numbers in a double-like format thus it is not capable to
|
||||
* handle safely integers outside the range [-(2^53 - 1), 2^53 - 1], so we look
|
||||
* for the string representation in the JSON for this types as a workaround for
|
||||
* the sake of JavaScript clients @see https://stackoverflow.com/a/34989371
|
||||
*/
|
||||
template<> /*static*/
|
||||
bool RsTypeSerializer::from_JSON( const std::string& memberName,
|
||||
uint64_t& member, RsJson& jDoc )
|
||||
bool RsTypeSerializer::from_JSON(
|
||||
const std::string& memberName, int64_t& member, RsJson& jDoc )
|
||||
{
|
||||
SAFE_GET_JSON_V();
|
||||
ret = ret && v.IsUint64();
|
||||
if(ret) member = v.GetUint64();
|
||||
return ret;
|
||||
const char* mName = memberName.c_str();
|
||||
if(jDoc.HasMember(mName))
|
||||
{
|
||||
rapidjson::Value& v = jDoc[mName];
|
||||
if(v.IsInt64())
|
||||
{
|
||||
member = v.GetInt64();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Dbg4() << __PRETTY_FUNCTION__ << " int64_t " << memberName << " not found "
|
||||
<< "in JSON then attempt to look for string representation"
|
||||
<< std::endl;
|
||||
|
||||
const std::string str_key = memberName + strReprSuffix;
|
||||
std::string str_value;
|
||||
if(from_JSON(str_key, str_value, jDoc))
|
||||
{
|
||||
try { member = std::stoll(str_value); }
|
||||
catch (...)
|
||||
{
|
||||
RsErr() << __PRETTY_FUNCTION__ << " cannot convert "
|
||||
<< str_value << " to int64_t" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Dbg3() << __PRETTY_FUNCTION__ << " neither " << memberName << " nor its "
|
||||
<< "string representation " << str_key << " has been found "
|
||||
<< "in JSON" << std::endl;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/** While JSON doesn't have problems representing 64 bit integers JavaScript
|
||||
* standard represents numbers in a double-like format thus it is not capable to
|
||||
* handle safely integers outside the range [-(2^53 - 1), 2^53 - 1], so we look
|
||||
* for the string representation in the JSON for this types as a workaround for
|
||||
* the sake of JavaScript clients @see https://stackoverflow.com/a/34989371
|
||||
*/
|
||||
template<> /*static*/
|
||||
bool RsTypeSerializer::from_JSON(
|
||||
const std::string& memberName, uint64_t& member, RsJson& jDoc )
|
||||
{
|
||||
const char* mName = memberName.c_str();
|
||||
if(jDoc.HasMember(mName))
|
||||
{
|
||||
rapidjson::Value& v = jDoc[mName];
|
||||
if(v.IsUint64())
|
||||
{
|
||||
member = v.GetUint64();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Dbg4() << __PRETTY_FUNCTION__ << " uint64_t " << memberName << " not found "
|
||||
<< "in JSON then attempt to look for string representation"
|
||||
<< std::endl;
|
||||
|
||||
const std::string str_key = memberName + strReprSuffix;
|
||||
std::string str_value;
|
||||
if(from_JSON(str_key, str_value, jDoc))
|
||||
{
|
||||
try { member = std::stoull(str_value); }
|
||||
catch (...)
|
||||
{
|
||||
RsErr() << __PRETTY_FUNCTION__ << " cannot convert "
|
||||
<< str_value << " to uint64_t" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Dbg3() << __PRETTY_FUNCTION__ << " neither " << memberName << " nor its "
|
||||
<< "string representation " << str_key << " has been found "
|
||||
<< "in JSON" << std::endl;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
@ -363,59 +520,6 @@ bool RsTypeSerializer::from_JSON( const std::string& memberName,
|
|||
}
|
||||
|
||||
|
||||
//============================================================================//
|
||||
// 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 //
|
||||
//============================================================================//
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
* *
|
||||
* libretroshare: retroshare core library *
|
||||
* *
|
||||
* Copyright (C) 2017 Cyril Soler <csoler@users.sourceforge.net> *
|
||||
* Copyright (C) 2018 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||
* Copyright (C) 2017 Cyril Soler <csoler@users.sourceforge.net> *
|
||||
* Copyright (C) 2018-2019 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
|
@ -32,6 +32,7 @@
|
|||
#include "serialiser/rsserializer.h"
|
||||
#include "serialiser/rsserializable.h"
|
||||
#include "util/rsjson.h"
|
||||
#include "util/rsdebug.h"
|
||||
|
||||
#include <typeinfo> // for typeid
|
||||
#include <type_traits>
|
||||
|
@ -907,6 +908,8 @@ protected:
|
|||
static bool from_JSON( const std::string& memberName,
|
||||
t_RsTlvList<TLV_CLASS,TLV_TYPE>& member,
|
||||
RsJson& jDoc );
|
||||
|
||||
RS_SET_CONTEXT_DEBUG_LEVEL(1)
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -40,7 +40,6 @@ struct BroadcastDiscoveryPack : RsSerializable
|
|||
{
|
||||
BroadcastDiscoveryPack() : mLocalPort(0) {}
|
||||
|
||||
RsPgpFingerprint mPgpFingerprint;
|
||||
RsPeerId mSslId;
|
||||
uint16_t mLocalPort;
|
||||
std::string mProfileName;
|
||||
|
@ -48,7 +47,6 @@ struct BroadcastDiscoveryPack : RsSerializable
|
|||
void serial_process( RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx ) override
|
||||
{
|
||||
RS_SERIAL_PROCESS(mPgpFingerprint);
|
||||
RS_SERIAL_PROCESS(mSslId);
|
||||
RS_SERIAL_PROCESS(mLocalPort);
|
||||
RS_SERIAL_PROCESS(mProfileName);
|
||||
|
@ -57,7 +55,6 @@ struct BroadcastDiscoveryPack : RsSerializable
|
|||
static BroadcastDiscoveryPack fromPeerDetails(const RsPeerDetails& pd)
|
||||
{
|
||||
BroadcastDiscoveryPack bdp;
|
||||
bdp.mPgpFingerprint = pd.fpr;
|
||||
bdp.mSslId = pd.id;
|
||||
bdp.mLocalPort = pd.localPort;
|
||||
bdp.mProfileName = pd.name;
|
||||
|
@ -103,12 +100,12 @@ BroadcastDiscoveryService::BroadcastDiscoveryService(
|
|||
mUdcParameters.set_port(port);
|
||||
mUdcParameters.set_application_id(appId);
|
||||
|
||||
mUdcEndpoint.Start(mUdcParameters, "");
|
||||
mUdcPeer.Start(mUdcParameters, "");
|
||||
updatePublishedData();
|
||||
}
|
||||
|
||||
BroadcastDiscoveryService::~BroadcastDiscoveryService()
|
||||
{ mUdcEndpoint.Stop(true); }
|
||||
{ mUdcPeer.Stop(true); }
|
||||
|
||||
std::vector<RsBroadcastDiscoveryResult>
|
||||
BroadcastDiscoveryService::getDiscoveredPeers()
|
||||
|
@ -126,7 +123,7 @@ void BroadcastDiscoveryService::updatePublishedData()
|
|||
{
|
||||
RsPeerDetails od;
|
||||
mRsPeers.getPeerDetails(mRsPeers.getOwnId(), od);
|
||||
mUdcEndpoint.SetUserData(
|
||||
mUdcPeer.SetUserData(
|
||||
BroadcastDiscoveryPack::fromPeerDetails(od).serializeToString());
|
||||
}
|
||||
|
||||
|
@ -137,7 +134,7 @@ void BroadcastDiscoveryService::data_tick()
|
|||
if( mUdcParameters.can_discover() &&
|
||||
!mRsPeers.isHiddenNode(mRsPeers.getOwnId()) )
|
||||
{
|
||||
auto currentEndpoints = mUdcEndpoint.ListDiscovered();
|
||||
auto currentEndpoints = mUdcPeer.ListDiscovered();
|
||||
std::map<UDC::IpPort, std::string> currentMap;
|
||||
std::map<UDC::IpPort, std::string> updateMap;
|
||||
|
||||
|
@ -163,23 +160,20 @@ void BroadcastDiscoveryService::data_tick()
|
|||
createResult(pp.first, pp.second);
|
||||
|
||||
const bool isFriend = mRsPeers.isFriend(rbdr.mSslId);
|
||||
if( isFriend && rbdr.locator.hasPort() &&
|
||||
if( isFriend && rbdr.mLocator.hasPort() &&
|
||||
!mRsPeers.isOnline(rbdr.mSslId) )
|
||||
{
|
||||
mRsPeers.setLocalAddress(
|
||||
rbdr.mSslId, rbdr.locator.host(),
|
||||
rbdr.locator.port() );
|
||||
rbdr.mSslId, rbdr.mLocator.host(),
|
||||
rbdr.mLocator.port() );
|
||||
mRsPeers.connectAttempt(rbdr.mSslId);
|
||||
}
|
||||
else if(!isFriend)
|
||||
{
|
||||
typedef RsBroadcastDiscoveryPeerFoundEvent Evt_t;
|
||||
|
||||
// Ensure rsEvents is not deleted while we use it
|
||||
std::shared_ptr<RsEvents> lockedRsEvents = rsEvents;
|
||||
if(lockedRsEvents)
|
||||
lockedRsEvents->postEvent(
|
||||
std::unique_ptr<Evt_t>(new Evt_t(rbdr)) );
|
||||
if(rsEvents)
|
||||
rsEvents->postEvent(
|
||||
std::shared_ptr<Evt_t>(new Evt_t(rbdr)) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -199,10 +193,9 @@ RsBroadcastDiscoveryResult BroadcastDiscoveryService::createResult(
|
|||
BroadcastDiscoveryPack::fromSerializedString(uData);
|
||||
|
||||
RsBroadcastDiscoveryResult rbdr;
|
||||
rbdr.mPgpFingerprint = bdp.mPgpFingerprint;
|
||||
rbdr.mSslId = bdp.mSslId;
|
||||
rbdr.mProfileName = bdp.mProfileName;
|
||||
rbdr.locator.
|
||||
rbdr.mLocator.
|
||||
setScheme("ipv4").
|
||||
setHost(UDC::IpToString(ipp.ip())).
|
||||
setPort(bdp.mLocalPort);
|
||||
|
|
|
@ -22,10 +22,11 @@
|
|||
#include <cstdint>
|
||||
#include <map>
|
||||
#include <iostream>
|
||||
#include <endpoint.hpp>
|
||||
#include <memory>
|
||||
#include <forward_list>
|
||||
|
||||
#include <udp_discovery_peer.hpp>
|
||||
|
||||
#include "retroshare/rsbroadcastdiscovery.h"
|
||||
#include "util/rsthreads.h"
|
||||
|
||||
|
@ -52,8 +53,8 @@ protected:
|
|||
|
||||
void updatePublishedData();
|
||||
|
||||
UDC::EndpointParameters mUdcParameters;
|
||||
UDC::Endpoint mUdcEndpoint;
|
||||
UDC::PeerParameters mUdcParameters;
|
||||
UDC::Peer mUdcPeer;
|
||||
|
||||
std::map<UDC::IpPort, std::string> mDiscoveredData;
|
||||
RsMutex mDiscoveredDataMutex;
|
||||
|
|
|
@ -306,18 +306,23 @@ bool p3BanList::acceptedBanRanges_locked(const BanListPeer& blp)
|
|||
}
|
||||
return false ;
|
||||
}
|
||||
|
||||
bool p3BanList::isAddressAccepted(
|
||||
const sockaddr_storage& dAddr, uint32_t checking_flags,
|
||||
uint32_t& check_result )
|
||||
{
|
||||
check_result = RSBANLIST_CHECK_RESULT_NOCHECK;
|
||||
if(!mIPFilteringEnabled) return true;
|
||||
|
||||
sockaddr_storage addr; sockaddr_storage_copy(dAddr, addr);
|
||||
|
||||
if(!sockaddr_storage_ipv6_to_ipv4(addr)) return true;
|
||||
if(sockaddr_storage_isLoopbackNet(addr)) return true;
|
||||
|
||||
|
||||
RS_STACK_MUTEX(mBanMtx);
|
||||
|
||||
if(!mIPFilteringEnabled) return true;
|
||||
|
||||
#ifdef DEBUG_BANLIST
|
||||
std::cerr << "isAddressAccepted(): tested addr=" << sockaddr_storage_iptostring(addr) << ", checking flags=" << checking_flags ;
|
||||
#endif
|
||||
|
@ -409,6 +414,7 @@ bool p3BanList::isAddressAccepted(
|
|||
check_result = RSBANLIST_CHECK_RESULT_ACCEPTED;
|
||||
return true ;
|
||||
}
|
||||
|
||||
void p3BanList::getWhiteListedIps(std::list<BanListPeer> &lst)
|
||||
{
|
||||
RS_STACK_MUTEX(mBanMtx) ;
|
||||
|
@ -582,11 +588,6 @@ int p3BanList::tick()
|
|||
return 0;
|
||||
}
|
||||
|
||||
int p3BanList::status()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
void p3BanList::getDhtInfo()
|
||||
{
|
||||
// Get the list of masquerading peers from the DHT. Add them as potential IPs to be banned.
|
||||
|
|
|
@ -105,7 +105,6 @@ public:
|
|||
|
||||
*/
|
||||
virtual int tick();
|
||||
virtual int status();
|
||||
|
||||
int sendPackets();
|
||||
bool processIncoming();
|
||||
|
|
|
@ -1433,13 +1433,15 @@ bool p3GxsChannels::createPostV2(
|
|||
return false;
|
||||
}
|
||||
|
||||
bool p3GxsChannels::createCommentV2(const RsGxsGroupId& channelId,
|
||||
const RsGxsMessageId& threadId,
|
||||
const RsGxsMessageId& parentId,
|
||||
const RsGxsId& authorId,
|
||||
const std::string& comment,
|
||||
RsGxsMessageId& commentMessageId,
|
||||
std::string& errorMessage)
|
||||
bool p3GxsChannels::createCommentV2(
|
||||
const RsGxsGroupId& channelId,
|
||||
const RsGxsMessageId& threadId,
|
||||
const std::string& comment,
|
||||
const RsGxsId& authorId,
|
||||
const RsGxsMessageId& parentId,
|
||||
const RsGxsMessageId& origCommentId,
|
||||
RsGxsMessageId& commentMessageId,
|
||||
std::string& errorMessage )
|
||||
{
|
||||
std::vector<RsGxsChannelGroup> channelsInfo;
|
||||
if(!getChannelsInfo(std::list<RsGxsGroupId>({channelId}),channelsInfo))
|
||||
|
@ -1476,6 +1478,7 @@ bool p3GxsChannels::createCommentV2(const RsGxsGroupId& channelId,
|
|||
}
|
||||
|
||||
if(!parentId.isNull())
|
||||
{
|
||||
if(!getChannelContent( // does the post thread exist?
|
||||
channelId,std::set<RsGxsMessageId>({parentId}),posts,comments ))
|
||||
{
|
||||
|
@ -1485,17 +1488,50 @@ bool p3GxsChannels::createCommentV2(const RsGxsGroupId& channelId,
|
|||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
else if(comments.size() != 1 || comments[0].mMeta.mParentId.isNull())
|
||||
{ // is the comment parent actually a comment?
|
||||
errorMessage = "You cannot comment post " + parentId.toStdString()
|
||||
+ " of channel with Id " + channelId.toStdString() +
|
||||
": supplied mParentMsgId is not a comment Id!";
|
||||
std::cerr << __PRETTY_FUNCTION__ << " Error: " << errorMessage
|
||||
<< std::endl;
|
||||
else
|
||||
{
|
||||
if(comments.size() != 1 || comments[0].mMeta.mParentId.isNull())
|
||||
{ // is the comment parent actually a comment?
|
||||
errorMessage = "You cannot comment post "
|
||||
+ parentId.toStdString()
|
||||
+ " of channel with Id " + channelId.toStdString() +
|
||||
": supplied mParentMsgId is not a comment Id!";
|
||||
std::cerr << __PRETTY_FUNCTION__ << " Error: " << errorMessage
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!origCommentId.isNull())
|
||||
{
|
||||
std::set<RsGxsMessageId> s({origCommentId});
|
||||
std::vector<RsGxsChannelPost> posts;
|
||||
std::vector<RsGxsComment> comments;
|
||||
|
||||
if( !getChannelContent(channelId, s, posts, comments) ||
|
||||
comments.size() != 1 )
|
||||
{
|
||||
errorMessage = "You cannot edit comment "
|
||||
+ origCommentId.toStdString()
|
||||
+ " of channel with Id " + channelId.toStdString()
|
||||
+ ": this post does not exist locally!";
|
||||
RsErr() << __PRETTY_FUNCTION__ << " " << errorMessage << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!rsIdentity->isOwnId(authorId)) // is the voter ID actually ours?
|
||||
const RsGxsId& commentAuthor = comments[0].mMeta.mAuthorId;
|
||||
if(commentAuthor != authorId)
|
||||
{
|
||||
errorMessage = "Editor identity and creator doesn't match "
|
||||
+ authorId.toStdString() + " != "
|
||||
+ commentAuthor.toStdString();
|
||||
RsErr() << __PRETTY_FUNCTION__ << " " << errorMessage << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if(!rsIdentity->isOwnId(authorId)) // is the author ID actually ours?
|
||||
{
|
||||
errorMessage = "You cannot comment to channel with Id " +
|
||||
channelId.toStdString() + " with identity " +
|
||||
|
@ -1511,6 +1547,7 @@ bool p3GxsChannels::createCommentV2(const RsGxsGroupId& channelId,
|
|||
cmt.mMeta.mThreadId = threadId;
|
||||
cmt.mMeta.mParentId = parentId;
|
||||
cmt.mMeta.mAuthorId = authorId;
|
||||
cmt.mMeta.mOrigMsgId = origCommentId;
|
||||
cmt.mComment = comment;
|
||||
|
||||
uint32_t token;
|
||||
|
@ -1852,12 +1889,8 @@ bool p3GxsChannels::ExtraFileHash(const std::string& path)
|
|||
}
|
||||
|
||||
|
||||
bool p3GxsChannels::ExtraFileRemove(const RsFileHash &hash)
|
||||
{
|
||||
//TransferRequestFlags tflags = RS_FILE_REQ_ANONYMOUS_ROUTING | RS_FILE_REQ_EXTRA;
|
||||
RsFileHash fh = RsFileHash(hash);
|
||||
return rsFiles->ExtraFileRemove(fh);
|
||||
}
|
||||
bool p3GxsChannels::ExtraFileRemove(const RsFileHash& hash)
|
||||
{ return rsFiles->ExtraFileRemove(hash); }
|
||||
|
||||
|
||||
/********************************************************************************************/
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
#include "gxs/rsgenexchange.h"
|
||||
#include "gxs/gxstokenqueue.h"
|
||||
#include "util/rsmemory.h"
|
||||
|
||||
#include "util/rsdebug.h"
|
||||
#include "util/rstickevent.h"
|
||||
|
||||
#include <map>
|
||||
|
@ -213,11 +213,14 @@ virtual bool ExtraFileRemove(const RsFileHash &hash);
|
|||
|
||||
/// Implementation of @see RsGxsChannels::createComment
|
||||
virtual bool createCommentV2(
|
||||
const RsGxsGroupId& channelId, const RsGxsMessageId& threadId,
|
||||
const RsGxsMessageId& parentId, const RsGxsId& authorId,
|
||||
const RsGxsGroupId& channelId,
|
||||
const RsGxsMessageId& threadId,
|
||||
const std::string& comment,
|
||||
RsGxsMessageId& commentMessageId = RS_DEFAULT_STORAGE_PARAM(RsGxsMessageId),
|
||||
std::string& errorMessage = RS_DEFAULT_STORAGE_PARAM(std::string)
|
||||
const RsGxsId& authorId,
|
||||
const RsGxsMessageId& parentId = RsGxsMessageId(),
|
||||
const RsGxsMessageId& origCommentId = RsGxsMessageId(),
|
||||
RsGxsMessageId& commentMessageId = RS_DEFAULT_STORAGE_PARAM(RsGxsMessageId),
|
||||
std::string& errorMessage = RS_DEFAULT_STORAGE_PARAM(std::string)
|
||||
) override;
|
||||
|
||||
/// Implementation of @see RsGxsChannels::editChannel
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
* *
|
||||
* libretroshare: retroshare core library *
|
||||
* *
|
||||
* Copyright 2012-2012 Robert Fernie <retroshare@lunamutt.com> *
|
||||
* Copyright (C) 2012-2014 Robert Fernie <retroshare@lunamutt.com> *
|
||||
* Copyright (C) 2018-2019 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
|
@ -21,8 +22,8 @@
|
|||
*******************************************************************************/
|
||||
#include "services/p3gxsforums.h"
|
||||
#include "rsitems/rsgxsforumitems.h"
|
||||
|
||||
#include <retroshare/rsidentity.h>
|
||||
#include "retroshare/rspeers.h"
|
||||
#include "retroshare/rsidentity.h"
|
||||
|
||||
#include "rsserver/p3face.h"
|
||||
#include "retroshare/rsnotify.h"
|
||||
|
@ -384,6 +385,165 @@ bool p3GxsForums::getMsgData(const uint32_t &token, std::vector<RsGxsForumMsg> &
|
|||
|
||||
/********************************************************************************************/
|
||||
|
||||
bool p3GxsForums::createForumV2(
|
||||
const std::string& name, const std::string& description,
|
||||
const RsGxsId& authorId, const std::set<RsGxsId>& moderatorsIds,
|
||||
RsGxsCircleType circleType, const RsGxsCircleId& circleId,
|
||||
RsGxsGroupId& forumId, std::string& errorMessage )
|
||||
{
|
||||
auto createFail = [&](std::string mErr)
|
||||
{
|
||||
errorMessage = mErr;
|
||||
RsErr() << __PRETTY_FUNCTION__ << " " << errorMessage << std::endl;
|
||||
return false;
|
||||
};
|
||||
|
||||
if(name.empty()) return createFail("Forum name is required");
|
||||
|
||||
if(!authorId.isNull() && !rsIdentity->isOwnId(authorId))
|
||||
return createFail("Author must be iether null or and identity owned by "
|
||||
"this node");
|
||||
|
||||
switch(circleType)
|
||||
{
|
||||
case RsGxsCircleType::PUBLIC: // fallthrough
|
||||
case RsGxsCircleType::LOCAL: // fallthrough
|
||||
case RsGxsCircleType::YOUR_EYES_ONLY:
|
||||
break;
|
||||
case RsGxsCircleType::EXTERNAL:
|
||||
if(circleId.isNull())
|
||||
return createFail("circleType is EXTERNAL but circleId is null");
|
||||
break;
|
||||
case RsGxsCircleType::NODES_GROUP:
|
||||
{
|
||||
RsGroupInfo ginfo;
|
||||
if(!rsPeers->getGroupInfo(RsNodeGroupId(circleId), ginfo))
|
||||
return createFail("circleType is NODES_GROUP but circleId does not "
|
||||
"correspond to an actual group of friends");
|
||||
break;
|
||||
}
|
||||
default: return createFail("circleType has invalid value");
|
||||
}
|
||||
|
||||
// Create a consistent channel group meta from the information supplied
|
||||
RsGxsForumGroup forum;
|
||||
|
||||
forum.mMeta.mGroupName = name;
|
||||
forum.mMeta.mAuthorId = authorId;
|
||||
forum.mMeta.mCircleType = static_cast<uint32_t>(circleType);
|
||||
|
||||
forum.mMeta.mSignFlags = GXS_SERV::FLAG_GROUP_SIGN_PUBLISH_NONEREQ
|
||||
| GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_REQUIRED;
|
||||
|
||||
forum.mMeta.mGroupFlags = GXS_SERV::FLAG_PRIVACY_PUBLIC;
|
||||
|
||||
forum.mMeta.mCircleId.clear();
|
||||
forum.mMeta.mInternalCircle.clear();
|
||||
|
||||
switch(circleType)
|
||||
{
|
||||
case RsGxsCircleType::NODES_GROUP:
|
||||
forum.mMeta.mInternalCircle = circleId; break;
|
||||
case RsGxsCircleType::EXTERNAL:
|
||||
forum.mMeta.mCircleId = circleId; break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
forum.mDescription = description;
|
||||
forum.mAdminList.ids = moderatorsIds;
|
||||
|
||||
uint32_t token;
|
||||
if(!createGroup(token, forum))
|
||||
return createFail("Failed creating GXS group.");
|
||||
|
||||
// wait for the group creation to complete.
|
||||
RsTokenService::GxsRequestStatus wSt =
|
||||
waitToken( token, std::chrono::milliseconds(5000),
|
||||
std::chrono::milliseconds(20) );
|
||||
if(wSt != RsTokenService::COMPLETE)
|
||||
return createFail( "GXS operation waitToken failed with: "
|
||||
+ std::to_string(wSt) );
|
||||
|
||||
if(!RsGenExchange::getPublishedGroupMeta(token, forum.mMeta))
|
||||
return createFail("Failure getting updated group data.");
|
||||
|
||||
forumId = forum.mMeta.mGroupId;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3GxsForums::createPost(
|
||||
const RsGxsGroupId& forumId, const std::string& title,
|
||||
const std::string& mBody,
|
||||
const RsGxsId& authorId, const RsGxsMessageId& parentId,
|
||||
const RsGxsMessageId& origPostId, RsGxsMessageId& postMsgId,
|
||||
std::string& errorMessage )
|
||||
{
|
||||
RsGxsForumMsg post;
|
||||
|
||||
auto failure = [&](std::string errMsg)
|
||||
{
|
||||
errorMessage = errMsg;
|
||||
RsErr() << __PRETTY_FUNCTION__ << " " << errorMessage << std::endl;
|
||||
return false;
|
||||
};
|
||||
|
||||
if(title.empty()) return failure("Title is required");
|
||||
|
||||
if(authorId.isNull()) return failure("Author id is needed");
|
||||
|
||||
if(!rsIdentity->isOwnId(authorId))
|
||||
return failure( "Author id: " + authorId.toStdString() + " is not of"
|
||||
"own identity" );
|
||||
|
||||
if(!parentId.isNull())
|
||||
{
|
||||
std::vector<RsGxsForumMsg> msgs;
|
||||
if( getForumContent(forumId, std::set<RsGxsMessageId>({parentId}), msgs)
|
||||
&& msgs.size() == 1 )
|
||||
{
|
||||
post.mMeta.mParentId = parentId;
|
||||
post.mMeta.mThreadId = msgs[0].mMeta.mThreadId;
|
||||
}
|
||||
else return failure("Parent post " + parentId.toStdString()
|
||||
+ " doesn't exists locally");
|
||||
}
|
||||
|
||||
std::vector<RsGxsForumGroup> forumInfo;
|
||||
if(!getForumsInfo(std::list<RsGxsGroupId>({forumId}), forumInfo))
|
||||
return failure( "Forum with Id " + forumId.toStdString()
|
||||
+ " does not exist locally." );
|
||||
|
||||
if(!origPostId.isNull())
|
||||
{
|
||||
std::vector<RsGxsForumMsg> msgs;
|
||||
if( getForumContent( forumId,
|
||||
std::set<RsGxsMessageId>({origPostId}), msgs)
|
||||
&& msgs.size() == 1 )
|
||||
post.mMeta.mOrigMsgId = origPostId;
|
||||
else return failure("Original post " + origPostId.toStdString()
|
||||
+ " doesn't exists locally");
|
||||
}
|
||||
|
||||
post.mMeta.mGroupId = forumId;
|
||||
post.mMeta.mMsgName = title;
|
||||
post.mMeta.mAuthorId = authorId;
|
||||
post.mMsg = mBody;
|
||||
|
||||
uint32_t token;
|
||||
if( !createMsg(token, post)
|
||||
|| waitToken(
|
||||
token,
|
||||
std::chrono::milliseconds(5000) ) != RsTokenService::COMPLETE )
|
||||
return failure("Failure creating GXS message");
|
||||
|
||||
if(!RsGenExchange::getPublishedMsgMeta(token, post.mMeta))
|
||||
return failure("Failure getting created GXS message metadata");
|
||||
|
||||
postMsgId = post.mMeta.mMsgId;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3GxsForums::createForum(RsGxsForumGroup& forum)
|
||||
{
|
||||
uint32_t token;
|
||||
|
@ -461,8 +621,9 @@ bool p3GxsForums::getForumsInfo(
|
|||
}
|
||||
|
||||
bool p3GxsForums::getForumContent(
|
||||
const RsGxsGroupId& forumId, std::set<RsGxsMessageId>& msgs_to_request,
|
||||
std::vector<RsGxsForumMsg>& msgs )
|
||||
const RsGxsGroupId& forumId,
|
||||
const std::set<RsGxsMessageId>& msgs_to_request,
|
||||
std::vector<RsGxsForumMsg>& msgs )
|
||||
{
|
||||
uint32_t token;
|
||||
RsTokReqOptions opts;
|
||||
|
@ -813,3 +974,37 @@ void p3GxsForums::handle_event(uint32_t event_type, const std::string &/*elabel*
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void RsGxsForumGroup::serial_process(
|
||||
RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx )
|
||||
{
|
||||
RS_SERIAL_PROCESS(mMeta);
|
||||
RS_SERIAL_PROCESS(mDescription);
|
||||
|
||||
/* Work around to have usable JSON API, without breaking binary
|
||||
* serialization retrocompatibility */
|
||||
switch (j)
|
||||
{
|
||||
case RsGenericSerializer::TO_JSON: // fallthrough
|
||||
case RsGenericSerializer::FROM_JSON:
|
||||
RsTypeSerializer::serial_process( j, ctx,
|
||||
mAdminList.ids, "mAdminList" );
|
||||
RsTypeSerializer::serial_process( j, ctx,
|
||||
mPinnedPosts.ids, "mPinnedPosts" );
|
||||
break;
|
||||
default:
|
||||
RS_SERIAL_PROCESS(mAdminList);
|
||||
RS_SERIAL_PROCESS(mPinnedPosts);
|
||||
}
|
||||
}
|
||||
|
||||
bool RsGxsForumGroup::canEditPosts(const RsGxsId& id) const
|
||||
{
|
||||
return mAdminList.ids.find(id) != mAdminList.ids.end() ||
|
||||
id == mMeta.mAuthorId;
|
||||
}
|
||||
|
||||
RsGxsForumGroup::~RsGxsForumGroup() = default;
|
||||
RsGxsForumMsg::~RsGxsForumMsg() = default;
|
||||
RsGxsForums::~RsGxsForums() = default;
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
* *
|
||||
* libretroshare: retroshare core library *
|
||||
* *
|
||||
* Copyright 2012-2012 Robert Fernie <retroshare@lunamutt.com> *
|
||||
* Copyright (C) 2012-2014 Robert Fernie <retroshare@lunamutt.com> *
|
||||
* Copyright (C) 2018-2019 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
|
@ -19,21 +20,17 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
*******************************************************************************/
|
||||
#ifndef P3_GXSFORUMS_SERVICE_HEADER
|
||||
#define P3_GXSFORUMS_SERVICE_HEADER
|
||||
|
||||
|
||||
#include "retroshare/rsgxsforums.h"
|
||||
#include "gxs/rsgenexchange.h"
|
||||
|
||||
#include "util/rstickevent.h"
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
#include "retroshare/rsgxsforums.h"
|
||||
#include "gxs/rsgenexchange.h"
|
||||
#include "retroshare/rsgxscircles.h"
|
||||
#include "util/rstickevent.h"
|
||||
#include "util/rsdebug.h"
|
||||
|
||||
|
||||
class p3GxsForums: public RsGenExchange, public RsGxsForums, public p3Config,
|
||||
public RsTickEvent /* only needed for testing - remove after */
|
||||
|
@ -55,14 +52,39 @@ protected:
|
|||
virtual bool loadList(std::list<RsItem *>& loadList); // @see p3Config::loadList(std::list<RsItem *>&)
|
||||
|
||||
public:
|
||||
/// @see RsGxsForums::createForum
|
||||
/// @see RsGxsForums::createForumV2
|
||||
bool createForumV2(
|
||||
const std::string& name, const std::string& description,
|
||||
const RsGxsId& authorId = RsGxsId(),
|
||||
const std::set<RsGxsId>& moderatorsIds = std::set<RsGxsId>(),
|
||||
RsGxsCircleType circleType = RsGxsCircleType::PUBLIC,
|
||||
const RsGxsCircleId& circleId = RsGxsCircleId(),
|
||||
RsGxsGroupId& forumId = RS_DEFAULT_STORAGE_PARAM(RsGxsGroupId),
|
||||
std::string& errorMessage = RS_DEFAULT_STORAGE_PARAM(std::string)
|
||||
) override;
|
||||
|
||||
/// @see RsGxsForums::createPost
|
||||
bool createPost(
|
||||
const RsGxsGroupId& forumId,
|
||||
const std::string& title,
|
||||
const std::string& mBody,
|
||||
const RsGxsId& authorId,
|
||||
const RsGxsMessageId& parentId = RsGxsMessageId(),
|
||||
const RsGxsMessageId& origPostId = RsGxsMessageId(),
|
||||
RsGxsMessageId& postMsgId = RS_DEFAULT_STORAGE_PARAM(RsGxsMessageId),
|
||||
std::string& errorMessage = RS_DEFAULT_STORAGE_PARAM(std::string)
|
||||
) override;
|
||||
|
||||
/// @see RsGxsForums::createForum @deprecated
|
||||
RS_DEPRECATED_FOR(createForumV2)
|
||||
virtual bool createForum(RsGxsForumGroup& forum);
|
||||
|
||||
/// @see RsGxsForums::createMessage
|
||||
/// @see RsGxsForums::createMessage @deprecated
|
||||
RS_DEPRECATED_FOR(createPost)
|
||||
virtual bool createMessage(RsGxsForumMsg& message);
|
||||
|
||||
/// @see RsGxsForums::editForum
|
||||
virtual bool editForum(RsGxsForumGroup& forum);
|
||||
virtual bool editForum(RsGxsForumGroup& forum) override;
|
||||
|
||||
/// @see RsGxsForums::getForumsSummaries
|
||||
virtual bool getForumsSummaries(std::list<RsGroupMetaData>& forums);
|
||||
|
@ -78,7 +100,7 @@ public:
|
|||
/// @see RsGxsForums::getForumContent
|
||||
virtual bool getForumContent(
|
||||
const RsGxsGroupId& forumId,
|
||||
std::set<RsGxsMessageId>& msgs_to_request,
|
||||
const std::set<RsGxsMessageId>& msgs_to_request,
|
||||
std::vector<RsGxsForumMsg>& msgs );
|
||||
|
||||
/// @see RsGxsForums::markRead
|
||||
|
@ -130,5 +152,3 @@ bool generateGroup(uint32_t &token, std::string groupName);
|
|||
std::map<RsGxsGroupId,rstime_t> mKnownForums ;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
/*******************************************************************************
|
||||
* libretroshare/src/services: p3idservice.cc *
|
||||
* *
|
||||
* libretroshare: retroshare core library *
|
||||
* *
|
||||
* Copyright 2012-2012 Robert Fernie <retroshare@lunamutt.com> *
|
||||
* Copyright (C) 2018 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||
* Copyright (C) 2012-2014 Robert Fernie <retroshare@lunamutt.com> *
|
||||
* Copyright (C) 2017-2019 Gioacchino Mazzurco <gio@altermundi.net> *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
|
@ -20,8 +18,14 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
*******************************************************************************/
|
||||
|
||||
/// RetroShare GXS identities service
|
||||
|
||||
|
||||
#include <unistd.h>
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
#include <cstdio>
|
||||
|
||||
#include "services/p3idservice.h"
|
||||
#include "pgp/pgpauxutils.h"
|
||||
|
@ -36,15 +40,9 @@
|
|||
#include "crypto/hashstream.h"
|
||||
#include "gxs/gxssecurity.h"
|
||||
#include "retroshare/rspeers.h"
|
||||
#include "retroshare/rsnotify.h"
|
||||
|
||||
|
||||
//#include "pqi/authgpg.h"
|
||||
|
||||
//#include <retroshare/rspeers.h>
|
||||
|
||||
#include <sstream>
|
||||
#include <stdio.h>
|
||||
|
||||
/****
|
||||
* #define DEBUG_IDS 1
|
||||
* #define DEBUG_RECOGN 1
|
||||
|
@ -71,7 +69,7 @@ static const uint32_t MAX_DELAY_BEFORE_CLEANING= 1800 ; // clean old keys eve
|
|||
|
||||
static const uint32_t MAX_SERIALISED_IDENTITY_AGE = 600 ; // after 10 mins, a serialised identity record must be renewed.
|
||||
|
||||
RsIdentity *rsIdentity = NULL;
|
||||
RsIdentity* rsIdentity = nullptr;
|
||||
|
||||
/******
|
||||
* Some notes:
|
||||
|
@ -757,7 +755,7 @@ bool p3IdService::isOwnId(const RsGxsId& id)
|
|||
}
|
||||
|
||||
|
||||
bool p3IdService::getOwnSignedIds(std::vector<RsGxsId> ids)
|
||||
bool p3IdService::getOwnSignedIds(std::vector<RsGxsId>& ids)
|
||||
{
|
||||
ids.clear();
|
||||
|
||||
|
@ -769,27 +767,29 @@ bool p3IdService::getOwnSignedIds(std::vector<RsGxsId> ids)
|
|||
if(ownIdsAreLoaded())
|
||||
{
|
||||
RS_STACK_MUTEX(mIdMtx);
|
||||
ids.reserve(mOwnSignedIds.size());
|
||||
ids.insert(ids.end(), mOwnSignedIds.begin(), mOwnSignedIds.end());
|
||||
ids.resize(mOwnSignedIds.size());
|
||||
std::copy(mOwnSignedIds.begin(), mOwnSignedIds.end(), ids.begin());
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool p3IdService::getOwnPseudonimousIds(std::vector<RsGxsId> ids)
|
||||
bool p3IdService::getOwnPseudonimousIds(std::vector<RsGxsId>& ids)
|
||||
{
|
||||
ids.clear();
|
||||
std::vector<RsGxsId> signedV;
|
||||
|
||||
// this implicitely ensure ids are already loaded ;)
|
||||
if(!getOwnSignedIds(signedV)) return false;
|
||||
|
||||
std::set<RsGxsId> signedS(signedV.begin(), signedV.end());
|
||||
|
||||
{
|
||||
RS_STACK_MUTEX(mIdMtx);
|
||||
std::copy_if(mOwnIds.begin(), mOwnIds.end(), ids.end(),
|
||||
[&](const RsGxsId& id) {return !signedS.count(id);});
|
||||
ids.resize(mOwnIds.size() - signedV.size());
|
||||
std::copy_if( mOwnIds.begin(), mOwnIds.end(), ids.begin(),
|
||||
[&](const RsGxsId& id) {return !signedS.count(id);} );
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -908,40 +908,75 @@ bool p3IdService::createIdentity(
|
|||
const std::string& name, const RsGxsImage& avatar,
|
||||
bool pseudonimous, const std::string& pgpPassword)
|
||||
{
|
||||
if(!pgpPassword.empty())
|
||||
std::cerr<< __PRETTY_FUNCTION__ << " Warning! PGP Password handling "
|
||||
<< "not implemented yet!" << std::endl;
|
||||
|
||||
bool ret = true;
|
||||
RsIdentityParameters params;
|
||||
uint32_t token = 0;
|
||||
RsGroupMetaData meta;
|
||||
RsTokenService::GxsRequestStatus wtStatus = RsTokenService::CANCELLED;
|
||||
|
||||
if(!pseudonimous && !pgpPassword.empty())
|
||||
{
|
||||
if(!rsNotify->cachePgpPassphrase(pgpPassword))
|
||||
{
|
||||
RsErr() << __PRETTY_FUNCTION__ << " Failure caching password"
|
||||
<< std::endl;
|
||||
ret = false;
|
||||
goto LabelCreateIdentityCleanup;
|
||||
}
|
||||
|
||||
if(!rsNotify->setDisableAskPassword(true))
|
||||
{
|
||||
RsErr() << __PRETTY_FUNCTION__ << " Failure disabling password user"
|
||||
<< " request" << std::endl;
|
||||
ret = false;
|
||||
goto LabelCreateIdentityCleanup;
|
||||
}
|
||||
}
|
||||
|
||||
params.isPgpLinked = !pseudonimous;
|
||||
params.nickname = name;
|
||||
params.mImage = avatar;
|
||||
|
||||
uint32_t token;
|
||||
if(!createIdentity(token, params))
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << " Error! Failed creating group."
|
||||
<< std::endl;
|
||||
return false;
|
||||
RsErr() << __PRETTY_FUNCTION__ << " Failed creating GXS group."
|
||||
<< std::endl;
|
||||
ret = false;
|
||||
goto LabelCreateIdentityCleanup;
|
||||
}
|
||||
|
||||
if(waitToken(token) != RsTokenService::COMPLETE)
|
||||
/* Use custom timeout for waitToken because creating identities involves
|
||||
* creating multiple signatures, which can take a lot of time expecially on
|
||||
* slow hardware like phones or embedded devices */
|
||||
if( (wtStatus = waitToken(
|
||||
token, std::chrono::seconds(10), std::chrono::milliseconds(20) ))
|
||||
!= RsTokenService::COMPLETE )
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << " Error! GXS operation failed."
|
||||
<< std::endl;
|
||||
return false;
|
||||
RsErr() << __PRETTY_FUNCTION__ << " waitToken("<< token
|
||||
<< ") failed with: " << wtStatus << std::endl;
|
||||
ret = false;
|
||||
goto LabelCreateIdentityCleanup;
|
||||
}
|
||||
|
||||
RsGroupMetaData meta;
|
||||
if(!RsGenExchange::getPublishedGroupMeta(token, meta))
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << "Error! Failure getting updated "
|
||||
<< " group data." << std::endl;
|
||||
return false;
|
||||
RsErr() << __PRETTY_FUNCTION__ << " Failure getting updated group data."
|
||||
<< std::endl;
|
||||
ret = false;
|
||||
goto LabelCreateIdentityCleanup;
|
||||
}
|
||||
|
||||
id = RsGxsId(meta.mGroupId);
|
||||
return true;
|
||||
|
||||
|
||||
LabelCreateIdentityCleanup:
|
||||
if(!pseudonimous && !pgpPassword.empty())
|
||||
{
|
||||
rsNotify->setDisableAskPassword(false);
|
||||
rsNotify->clearPgpPassphrase();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool p3IdService::createIdentity(uint32_t& token, RsIdentityParameters ¶ms)
|
||||
|
@ -1151,6 +1186,16 @@ static void mergeIds(std::map<RsGxsId,std::list<RsPeerId> >& idmap,const RsGxsId
|
|||
old_peers.push_back(*it) ;
|
||||
}
|
||||
|
||||
bool p3IdService::requestIdentity(const RsGxsId& id)
|
||||
{
|
||||
RsIdentityUsage usageInfo( RsServiceType::GXSID,
|
||||
RsIdentityUsage::IDENTITY_DATA_UPDATE );
|
||||
std::list<RsPeerId> onlinePeers;
|
||||
|
||||
return rsPeers && rsPeers->getOnlineList(onlinePeers)
|
||||
&& requestKey(id, onlinePeers, usageInfo);
|
||||
}
|
||||
|
||||
bool p3IdService::requestKey(const RsGxsId &id, const std::list<RsPeerId>& peers,const RsIdentityUsage& use_info)
|
||||
{
|
||||
if(id.isNull())
|
||||
|
@ -3297,13 +3342,10 @@ static void calcPGPHash(const RsGxsId &id, const PGPFingerprintType &pgp, Sha1Ch
|
|||
|
||||
|
||||
// Must Use meta.
|
||||
RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(RsGxsGrpItem* grpItem, RsTlvSecurityKeySet& keySet)
|
||||
RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(
|
||||
RsGxsGrpItem* grpItem, RsTlvSecurityKeySet& keySet )
|
||||
{
|
||||
|
||||
#ifdef DEBUG_IDS
|
||||
std::cerr << "p3IdService::service_CreateGroup()";
|
||||
std::cerr << std::endl;
|
||||
#endif // DEBUG_IDS
|
||||
Dbg2() << __PRETTY_FUNCTION__ << std::endl;
|
||||
|
||||
RsGxsIdGroupItem *item = dynamic_cast<RsGxsIdGroupItem *>(grpItem);
|
||||
if (!item)
|
||||
|
@ -3313,30 +3355,23 @@ RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(RsGxsGrpIte
|
|||
return SERVICE_CREATE_FAIL;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_IDS
|
||||
std::cerr << "p3IdService::service_CreateGroup() Item is:";
|
||||
std::cerr << std::endl;
|
||||
item->print(std::cerr);
|
||||
std::cerr << std::endl;
|
||||
#endif // DEBUG_IDS
|
||||
|
||||
item->meta.mGroupId.clear();
|
||||
|
||||
/********************* TEMP HACK UNTIL GXS FILLS IN GROUP_ID *****************/
|
||||
// find private admin key
|
||||
for(std::map<RsGxsId, RsTlvPrivateRSAKey>::iterator mit = keySet.private_keys.begin();mit != keySet.private_keys.end(); ++mit)
|
||||
if(mit->second.keyFlags == (RSTLV_KEY_DISTRIB_ADMIN | RSTLV_KEY_TYPE_FULL))
|
||||
// find private admin key
|
||||
for( std::map<RsGxsId, RsTlvPrivateRSAKey>::iterator mit =
|
||||
keySet.private_keys.begin(); mit != keySet.private_keys.end(); ++mit )
|
||||
if(mit->second.keyFlags == (RSTLV_KEY_DISTRIB_ADMIN | RSTLV_KEY_TYPE_FULL))
|
||||
{
|
||||
item->meta.mGroupId = RsGxsGroupId(mit->second.keyId);
|
||||
break;
|
||||
}
|
||||
|
||||
if(item->meta.mGroupId.isNull())
|
||||
{
|
||||
std::cerr << "p3IdService::service_CreateGroup() ERROR no admin key";
|
||||
std::cerr << std::endl;
|
||||
return SERVICE_CREATE_FAIL;
|
||||
}
|
||||
if(item->meta.mGroupId.isNull())
|
||||
{
|
||||
RsErr() << __PRETTY_FUNCTION__ << " missing admin key!" << std::endl;
|
||||
return SERVICE_CREATE_FAIL;
|
||||
}
|
||||
mKeysTS[RsGxsId(item->meta.mGroupId)].TS = time(NULL) ;
|
||||
|
||||
/********************* TEMP HACK UNTIL GXS FILLS IN GROUP_ID *****************/
|
||||
|
@ -3384,8 +3419,7 @@ RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(RsGxsGrpIte
|
|||
/* create the hash */
|
||||
Sha1CheckSum hash;
|
||||
|
||||
/* */
|
||||
PGPFingerprintType ownFinger;
|
||||
RsPgpFingerprint ownFinger;
|
||||
RsPgpId ownId(mPgpUtils->getPGPOwnId());
|
||||
|
||||
#ifdef DEBUG_IDS
|
||||
|
@ -3400,12 +3434,12 @@ RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(RsGxsGrpIte
|
|||
// }
|
||||
#endif
|
||||
|
||||
if (!mPgpUtils->getKeyFingerprint(ownId,ownFinger))
|
||||
{
|
||||
std::cerr << "p3IdService::service_CreateGroup() ERROR Own Finger is stuck";
|
||||
std::cerr << std::endl;
|
||||
return SERVICE_CREATE_FAIL; // abandon attempt!
|
||||
}
|
||||
if(!mPgpUtils->getKeyFingerprint(ownId,ownFinger))
|
||||
{
|
||||
RsErr() << __PRETTY_FUNCTION__
|
||||
<< " failure retriving own PGP fingerprint" << std::endl;
|
||||
return SERVICE_CREATE_FAIL; // abandon attempt!
|
||||
}
|
||||
|
||||
#ifdef DEBUG_IDS
|
||||
std::cerr << "p3IdService::service_CreateGroup() OwnFingerprint: " << ownFinger.toStdString();
|
||||
|
@ -3427,60 +3461,69 @@ RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(RsGxsGrpIte
|
|||
|
||||
#define MAX_SIGN_SIZE 2048
|
||||
uint8_t signarray[MAX_SIGN_SIZE];
|
||||
unsigned int sign_size = MAX_SIGN_SIZE;
|
||||
int result ;
|
||||
|
||||
unsigned int sign_size = MAX_SIGN_SIZE;
|
||||
memset(signarray,0,MAX_SIGN_SIZE) ; // just in case.
|
||||
|
||||
mPgpUtils->askForDeferredSelfSignature((void *) hash.toByteArray(), hash.SIZE_IN_BYTES, signarray, &sign_size,result, "p3IdService::service_CreateGroup()") ;
|
||||
/* -10 is never returned by askForDeferredSelfSignature therefore we can
|
||||
* use it to properly detect and handle the case libretroshare is being
|
||||
* used outside retroshare-gui */
|
||||
int result = -10;
|
||||
|
||||
/* error */
|
||||
switch(result)
|
||||
{
|
||||
case SELF_SIGNATURE_RESULT_PENDING : createStatus = SERVICE_CREATE_FAIL_TRY_LATER;
|
||||
std::cerr << "p3IdService::service_CreateGroup() signature still pending" << std::endl;
|
||||
break ;
|
||||
default:
|
||||
case SELF_SIGNATURE_RESULT_FAILED: return SERVICE_CREATE_FAIL ;
|
||||
std::cerr << "p3IdService::service_CreateGroup() signature failed" << std::endl;
|
||||
break ;
|
||||
/* This method is DEPRECATED we call it only for retrocompatibility with
|
||||
* retroshare-gui, when called from something different then
|
||||
* retroshare-gui for example retroshare-service it miserably fail! */
|
||||
mPgpUtils->askForDeferredSelfSignature(
|
||||
static_cast<const void*>(hash.toByteArray()),
|
||||
hash.SIZE_IN_BYTES, signarray, &sign_size, result,
|
||||
__PRETTY_FUNCTION__ );
|
||||
|
||||
case SELF_SIGNATURE_RESULT_SUCCESS:
|
||||
{
|
||||
// Additional consistency checks.
|
||||
/* If askForDeferredSelfSignature left result untouched it means
|
||||
* libretroshare is being used by something different then
|
||||
* retroshare-gui so try calling AuthGPG::getAuthGPG()->SignDataBin
|
||||
* directly */
|
||||
if( result == -10 )
|
||||
result = AuthGPG::getAuthGPG()->SignDataBin(
|
||||
static_cast<const void*>(hash.toByteArray()),
|
||||
hash.SIZE_IN_BYTES, signarray, &sign_size,
|
||||
__PRETTY_FUNCTION__ )
|
||||
?
|
||||
SELF_SIGNATURE_RESULT_SUCCESS :
|
||||
SELF_SIGNATURE_RESULT_FAILED;
|
||||
|
||||
if(sign_size == MAX_SIGN_SIZE)
|
||||
{
|
||||
std::cerr << "Inconsistent result. Signature uses full buffer. This is probably an error." << std::endl;
|
||||
return SERVICE_CREATE_FAIL; // abandon attempt!
|
||||
}
|
||||
#ifdef DEBUG_IDS
|
||||
std::cerr << "p3IdService::service_CreateGroup() Signature: ";
|
||||
std::string strout;
|
||||
#endif
|
||||
/* push binary into string -> really bad! */
|
||||
item->mPgpIdSign = "";
|
||||
for(unsigned int i = 0; i < sign_size; i++)
|
||||
{
|
||||
#ifdef DEBUG_IDS
|
||||
rs_sprintf_append(strout, "%02x", (uint32_t) signarray[i]);
|
||||
#endif
|
||||
item->mPgpIdSign += signarray[i];
|
||||
}
|
||||
createStatus = SERVICE_CREATE_SUCCESS;
|
||||
switch(result)
|
||||
{
|
||||
case SELF_SIGNATURE_RESULT_PENDING:
|
||||
createStatus = SERVICE_CREATE_FAIL_TRY_LATER;
|
||||
Dbg1() << __PRETTY_FUNCTION__ << " signature still pending"
|
||||
<< std::endl;
|
||||
break;
|
||||
case SELF_SIGNATURE_RESULT_SUCCESS:
|
||||
{
|
||||
// Additional consistency checks.
|
||||
if(sign_size == MAX_SIGN_SIZE)
|
||||
{
|
||||
RsErr() << __PRETTY_FUNCTION__ << "Inconsistent result. "
|
||||
<< "Signature uses full buffer. This is probably an "
|
||||
<< "error." << std::endl;
|
||||
return SERVICE_CREATE_FAIL;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_IDS
|
||||
std::cerr << strout;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
/* done! */
|
||||
}
|
||||
else
|
||||
{
|
||||
createStatus = SERVICE_CREATE_SUCCESS;
|
||||
}
|
||||
/* push binary into string -> really bad! */
|
||||
item->mPgpIdSign = "";
|
||||
for(unsigned int i = 0; i < sign_size; i++)
|
||||
item->mPgpIdSign += static_cast<char>(signarray[i]);
|
||||
|
||||
createStatus = SERVICE_CREATE_SUCCESS;
|
||||
break;
|
||||
}
|
||||
case SELF_SIGNATURE_RESULT_FAILED: /* fall-through */
|
||||
default:
|
||||
RsErr() << __PRETTY_FUNCTION__ << " signature failed with: "
|
||||
<< result << std::endl;
|
||||
return SERVICE_CREATE_FAIL;
|
||||
}
|
||||
}
|
||||
else createStatus = SERVICE_CREATE_SUCCESS;
|
||||
|
||||
// Enforce no AuthorId.
|
||||
item->meta.mAuthorId.clear() ;
|
||||
|
@ -3491,17 +3534,18 @@ RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(RsGxsGrpIte
|
|||
// do it like p3gxscircles: save the new grp id
|
||||
// this allows the user interface
|
||||
// to see the grp id on the list of ownIds immediately after the group was created
|
||||
{
|
||||
RsStackMutex stack(mIdMtx);
|
||||
{
|
||||
RS_STACK_MUTEX(mIdMtx);
|
||||
RsGxsId gxsId(item->meta.mGroupId);
|
||||
if (std::find(mOwnIds.begin(), mOwnIds.end(), gxsId) == mOwnIds.end())
|
||||
{
|
||||
mOwnIds.push_back(gxsId);
|
||||
mKeysTS[gxsId].TS = time(NULL) ;
|
||||
mOwnIds.push_back(gxsId);
|
||||
mKeysTS[gxsId].TS = time(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
return createStatus;
|
||||
Dbg2() << __PRETTY_FUNCTION__ << " returns: " << createStatus << std::endl;
|
||||
return createStatus;
|
||||
}
|
||||
|
||||
|
||||
|
@ -4678,12 +4722,34 @@ void RsGxsIdGroup::serial_process(
|
|||
RS_SERIAL_PROCESS(mReputation);
|
||||
}
|
||||
|
||||
RsIdentityUsage::RsIdentityUsage(
|
||||
RsServiceType service, 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)
|
||||
{
|
||||
/* 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 << static_cast<uint32_t>(service); // G10h4ck: Why uint32 if it's 16 bits?
|
||||
hs << static_cast<uint8_t>(code);
|
||||
hs << gid;
|
||||
hs << mid;
|
||||
hs << static_cast<uint64_t>(additional_id);
|
||||
hs << comment;
|
||||
|
||||
mHash = hs.hash();
|
||||
}
|
||||
|
||||
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)
|
||||
mServiceId(static_cast<RsServiceType>(service)), mUsageCode(code),
|
||||
mGrpId(gid), mMsgId(mid), mAdditionalId(additional_id), mComment(comment)
|
||||
{
|
||||
#ifdef DEBUG_IDS
|
||||
std::cerr << "New identity usage: " << std::endl;
|
||||
|
@ -4700,7 +4766,7 @@ RsIdentityUsage::RsIdentityUsage(
|
|||
* be ok. */
|
||||
librs::crypto::HashStream hs(librs::crypto::HashStream::SHA1) ;
|
||||
|
||||
hs << (uint32_t)service ;
|
||||
hs << (uint32_t)service ; // G10h4ck: Why uint32 if it's 16 bits?
|
||||
hs << (uint8_t)code ;
|
||||
hs << gid ;
|
||||
hs << mid ;
|
||||
|
@ -4715,4 +4781,5 @@ RsIdentityUsage::RsIdentityUsage(
|
|||
}
|
||||
|
||||
RsIdentityUsage::RsIdentityUsage() :
|
||||
mServiceId(0), mUsageCode(UNKNOWN_USAGE), mAdditionalId(0) {}
|
||||
mServiceId(RsServiceType::NONE), mUsageCode(UNKNOWN_USAGE), mAdditionalId(0)
|
||||
{}
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
/*******************************************************************************
|
||||
* libretroshare/src/services: p3idservice.h *
|
||||
* *
|
||||
* libretroshare: retroshare core library *
|
||||
* *
|
||||
* Copyright 2012-2012 Robert Fernie <retroshare@lunamutt.com> *
|
||||
* Copyright (C) 2012-2014 Robert Fernie <retroshare@lunamutt.com> *
|
||||
* Copyright (C) 2017-2019 Gioacchino Mazzurco <gio@altermundi.net> *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
|
@ -19,51 +18,28 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
*******************************************************************************/
|
||||
#ifndef P3_IDENTITY_SERVICE_HEADER
|
||||
#define P3_IDENTITY_SERVICE_HEADER
|
||||
#pragma once
|
||||
|
||||
/// RetroShare GXS identities service
|
||||
|
||||
#include "retroshare/rsidentity.h" // External Interfaces.
|
||||
#include "gxs/rsgenexchange.h" // GXS service.
|
||||
#include "gxs/rsgixs.h" // Internal Interfaces.
|
||||
|
||||
#include "gxs/gxstokenqueue.h"
|
||||
#include "rsitems/rsgxsiditems.h"
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include "retroshare/rsidentity.h" // External Interfaces.
|
||||
#include "gxs/rsgenexchange.h" // GXS service.
|
||||
#include "gxs/rsgixs.h" // Internal Interfaces.
|
||||
#include "util/rsdebug.h"
|
||||
#include "gxs/gxstokenqueue.h"
|
||||
#include "rsitems/rsgxsiditems.h"
|
||||
#include "util/rsmemcache.h"
|
||||
#include "util/rstickevent.h"
|
||||
#include "util/rsrecogn.h"
|
||||
|
||||
#include "pqi/authgpg.h"
|
||||
|
||||
#include "rsitems/rsgxsrecognitems.h"
|
||||
|
||||
class PgpAuxUtils;
|
||||
|
||||
/*
|
||||
* Identity Service
|
||||
*
|
||||
*/
|
||||
|
||||
#if 0
|
||||
class GxsReputation
|
||||
{
|
||||
public:
|
||||
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;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
class OpinionRequest
|
||||
{
|
||||
public:
|
||||
|
@ -312,10 +288,10 @@ public:
|
|||
/**************** RsGixs Implementation ***************/
|
||||
|
||||
/// @see RsIdentity
|
||||
bool getOwnSignedIds(std::vector<RsGxsId> ids) override;
|
||||
bool getOwnSignedIds(std::vector<RsGxsId>& ids) override;
|
||||
|
||||
/// @see RsIdentity
|
||||
bool getOwnPseudonimousIds(std::vector<RsGxsId> ids) override;
|
||||
bool getOwnPseudonimousIds(std::vector<RsGxsId>& ids) override;
|
||||
|
||||
virtual bool getOwnIds(std::list<RsGxsId> &ownIds, bool signed_only = false);
|
||||
|
||||
|
@ -392,6 +368,9 @@ public:
|
|||
virtual bool deserialiseIdentityFromMemory(const std::string& radix_string,
|
||||
RsGxsId* id = nullptr);
|
||||
|
||||
/// @see RsIdentity
|
||||
bool requestIdentity(const RsGxsId& id) override;
|
||||
|
||||
/**************** RsGixsReputation Implementation ****************/
|
||||
|
||||
// get Reputation.
|
||||
|
@ -641,9 +620,6 @@ private:
|
|||
|
||||
bool mAutoAddFriendsIdentitiesAsContacts;
|
||||
uint32_t mMaxKeepKeysBanned ;
|
||||
|
||||
RS_SET_CONTEXT_DEBUG_LEVEL(1)
|
||||
};
|
||||
|
||||
#endif // P3_IDENTITY_SERVICE_HEADER
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -25,36 +25,43 @@
|
|||
#include "services/rseventsservice.h"
|
||||
|
||||
|
||||
/*extern*/ std::shared_ptr<RsEvents> rsEvents(nullptr);
|
||||
/*extern*/ RsEvents* rsEvents = nullptr;
|
||||
RsEvent::~RsEvent() {};
|
||||
RsEvents::~RsEvents() {};
|
||||
|
||||
bool isEventValid(const RsEvent& event, std::string& errorMessage)
|
||||
bool isEventValid(
|
||||
std::shared_ptr<const RsEvent> event, std::string& errorMessage )
|
||||
{
|
||||
if(event.mType <= RsEventType::NONE)
|
||||
if(!event)
|
||||
{
|
||||
errorMessage = "Event is null!";
|
||||
return false;
|
||||
}
|
||||
|
||||
if(event->mType <= RsEventType::NONE)
|
||||
{
|
||||
errorMessage = "Event has type NONE: " +
|
||||
std::to_string(
|
||||
static_cast<std::underlying_type<RsEventType>::type >(
|
||||
event.mType ) );
|
||||
event->mType ) );
|
||||
return false;
|
||||
}
|
||||
|
||||
if(event.mType >= RsEventType::MAX)
|
||||
if(event->mType >= RsEventType::MAX)
|
||||
{
|
||||
errorMessage = "Event has type >= RsEventType::MAX: " +
|
||||
std::to_string(
|
||||
static_cast<std::underlying_type<RsEventType>::type >(
|
||||
event.mType ) );
|
||||
event->mType ) );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RsEventsService::postEvent( std::unique_ptr<RsEvent> event,
|
||||
bool RsEventsService::postEvent( std::shared_ptr<const RsEvent> event,
|
||||
std::string& errorMessage )
|
||||
{
|
||||
if(!isEventValid(*event, errorMessage))
|
||||
if(!isEventValid(event, errorMessage))
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << " Error: "<< errorMessage
|
||||
<< std::endl;
|
||||
|
@ -62,17 +69,16 @@ bool RsEventsService::postEvent( std::unique_ptr<RsEvent> event,
|
|||
}
|
||||
|
||||
RS_STACK_MUTEX(mEventQueueMtx);
|
||||
mEventQueue.push_back(std::move(event));
|
||||
mEventQueue.push_back(event);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RsEventsService::sendEvent( const RsEvent& event,
|
||||
bool RsEventsService::sendEvent( std::shared_ptr<const RsEvent> event,
|
||||
std::string& errorMessage )
|
||||
{
|
||||
if(!isEventValid(event, errorMessage))
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << " Error: "<< errorMessage
|
||||
<< std::endl;
|
||||
RsErr() << __PRETTY_FUNCTION__ << " "<< errorMessage << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -93,12 +99,12 @@ RsEventsHandlerId_t RsEventsService::generateUniqueHandlerId_unlocked()
|
|||
}
|
||||
|
||||
bool RsEventsService::registerEventsHandler(
|
||||
std::function<void(const RsEvent&)> multiCallback,
|
||||
std::function<void(std::shared_ptr<const RsEvent>)> multiCallback,
|
||||
RsEventsHandlerId_t& hId )
|
||||
{
|
||||
RS_STACK_MUTEX(mHandlerMapMtx);
|
||||
if(!hId) hId = generateUniqueHandlerId_unlocked();
|
||||
mHandlerMap[hId] = std::move(multiCallback);
|
||||
mHandlerMap[hId] = multiCallback;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -116,19 +122,19 @@ void RsEventsService::data_tick()
|
|||
auto nextRunAt = std::chrono::system_clock::now() +
|
||||
std::chrono::milliseconds(1);
|
||||
|
||||
std::unique_ptr<RsEvent> eventPtr(nullptr);
|
||||
std::shared_ptr<const RsEvent> eventPtr(nullptr);
|
||||
size_t futureEventsCounter = 0;
|
||||
|
||||
dispatchEventFromQueueLock:
|
||||
mEventQueueMtx.lock();
|
||||
if(mEventQueue.size() > futureEventsCounter)
|
||||
{
|
||||
eventPtr = std::move(mEventQueue.front());
|
||||
eventPtr = mEventQueue.front();
|
||||
mEventQueue.pop_front();
|
||||
|
||||
if(eventPtr->mTimePoint >= nextRunAt)
|
||||
{
|
||||
mEventQueue.push_back(std::move(eventPtr));
|
||||
mEventQueue.push_back(eventPtr);
|
||||
++futureEventsCounter;
|
||||
}
|
||||
}
|
||||
|
@ -137,17 +143,17 @@ dispatchEventFromQueueLock:
|
|||
if(eventPtr)
|
||||
{
|
||||
/* It is relevant that this stays out of mEventQueueMtx */
|
||||
handleEvent(*eventPtr);
|
||||
eventPtr.reset(nullptr); // ensure memory is freed before sleep
|
||||
handleEvent(eventPtr);
|
||||
eventPtr = nullptr; // ensure refcounter is decremented before sleep
|
||||
goto dispatchEventFromQueueLock;
|
||||
}
|
||||
|
||||
std::this_thread::sleep_until(nextRunAt);
|
||||
}
|
||||
|
||||
void RsEventsService::handleEvent(const RsEvent& event)
|
||||
void RsEventsService::handleEvent(std::shared_ptr<const RsEvent> event)
|
||||
{
|
||||
std::function<void(const RsEvent&)> mCallback;
|
||||
std::function<void(std::shared_ptr<const RsEvent>)> mCallback;
|
||||
|
||||
mHandlerMapMtx.lock();
|
||||
auto cbpt = mHandlerMap.begin();
|
||||
|
@ -165,7 +171,7 @@ getHandlerFromMapLock:
|
|||
if(mCallback)
|
||||
{
|
||||
mCallback(event); // It is relevant that this happens outside mutex
|
||||
mCallback = std::function<void(const RsEvent&)>(nullptr);
|
||||
mCallback = std::function<void(std::shared_ptr<const RsEvent>)>(nullptr);
|
||||
goto getHandlerFromMapLock;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
#include "retroshare/rsevents.h"
|
||||
#include "util/rsthreads.h"
|
||||
#include "util/rsdebug.h"
|
||||
|
||||
class RsEventsService :
|
||||
public RsEvents, public RsTickingThread
|
||||
|
@ -38,13 +39,13 @@ public:
|
|||
|
||||
/// @see RsEvents
|
||||
bool postEvent(
|
||||
std::unique_ptr<RsEvent> event,
|
||||
std::shared_ptr<const RsEvent> event,
|
||||
std::string& errorMessage = RS_DEFAULT_STORAGE_PARAM(std::string)
|
||||
) override;
|
||||
|
||||
/// @see RsEvents
|
||||
bool sendEvent(
|
||||
const RsEvent& event,
|
||||
std::shared_ptr<const RsEvent> event,
|
||||
std::string& errorMessage = RS_DEFAULT_STORAGE_PARAM(std::string)
|
||||
) override;
|
||||
|
||||
|
@ -53,7 +54,7 @@ public:
|
|||
|
||||
/// @see RsEvents
|
||||
bool registerEventsHandler(
|
||||
std::function<void(const RsEvent&)> multiCallback,
|
||||
std::function<void(std::shared_ptr<const RsEvent>)> multiCallback,
|
||||
RsEventsHandlerId_t& hId = RS_DEFAULT_STORAGE_PARAM(RsEventsHandlerId_t, 0)
|
||||
) override;
|
||||
|
||||
|
@ -63,15 +64,18 @@ public:
|
|||
protected:
|
||||
RsMutex mHandlerMapMtx;
|
||||
RsEventsHandlerId_t mLastHandlerId;
|
||||
std::map< RsEventsHandlerId_t, std::function<void(const RsEvent&)> >
|
||||
mHandlerMap;
|
||||
std::map<
|
||||
RsEventsHandlerId_t,
|
||||
std::function<void(std::shared_ptr<const RsEvent>)> > mHandlerMap;
|
||||
|
||||
RsMutex mEventQueueMtx;
|
||||
std::deque< std::unique_ptr<RsEvent> > mEventQueue;
|
||||
std::deque< std::shared_ptr<const RsEvent> > mEventQueue;
|
||||
|
||||
/// @see RsTickingThread
|
||||
void data_tick() override;
|
||||
|
||||
void handleEvent(const RsEvent& event);
|
||||
void handleEvent(std::shared_ptr<const RsEvent> event);
|
||||
RsEventsHandlerId_t generateUniqueHandlerId_unlocked();
|
||||
|
||||
RS_SET_CONTEXT_DEBUG_LEVEL(3)
|
||||
};
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
* *
|
||||
* libretroshare: retroshare core library *
|
||||
* *
|
||||
* Copyright 2012 Christopher Evi-Parker <retroshare@lunamutt.com> *
|
||||
* Copyright (C) 2012 Christopher Evi-Parker <retroshare@lunamutt.com> *
|
||||
* Copyright (C) 2019 Gioacchino Mazzurco <gio@altermundi.net> *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
|
@ -22,106 +23,143 @@
|
|||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <memory.h>
|
||||
#include "util/rstime.h"
|
||||
#include <inttypes.h>
|
||||
#include <memory>
|
||||
#include <cstdint>
|
||||
#include <cerrno>
|
||||
|
||||
#include "retrodb.h"
|
||||
#include "rsdbbind.h"
|
||||
#include "util/rstime.h"
|
||||
#include "util/retrodb.h"
|
||||
#include "util/rsdbbind.h"
|
||||
#include "util/stacktrace.h"
|
||||
#include "util/rsdir.h"
|
||||
|
||||
//#define RETRODB_DEBUG
|
||||
|
||||
#ifndef NO_SQLCIPHER
|
||||
#define ENABLE_ENCRYPTED_DB
|
||||
#endif
|
||||
|
||||
const int RetroDb::OPEN_READONLY = SQLITE_OPEN_READONLY;
|
||||
const int RetroDb::OPEN_READWRITE = SQLITE_OPEN_READWRITE;
|
||||
const int RetroDb::OPEN_READWRITE_CREATE = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
|
||||
|
||||
RetroDb::RetroDb(const std::string &dbPath, int flags, const std::string& key) : mDb(NULL), mKey(key) {
|
||||
RetroDb::RetroDb(const std::string& dbPath, int flags, const std::string& key):
|
||||
mDb(nullptr), mKey(key)
|
||||
{
|
||||
bool alreadyExists = RsDirUtil::fileExists(dbPath);
|
||||
|
||||
int rc = sqlite3_open_v2(dbPath.c_str(), &mDb, flags, NULL);
|
||||
|
||||
if(rc){
|
||||
std::cerr << "Can't open database, Error code: " << sqlite3_errmsg(mDb)
|
||||
<< std::endl;
|
||||
sqlite3_close(mDb);
|
||||
mDb = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_ENCRYPTED_DB
|
||||
if(!mKey.empty())
|
||||
{
|
||||
rc = sqlite3_key(mDb, mKey.c_str(), mKey.size());
|
||||
|
||||
if(rc){
|
||||
std::cerr << "Can't key database: " << sqlite3_errmsg(mDb)
|
||||
<< std::endl;
|
||||
|
||||
sqlite3_close(mDb);
|
||||
mDb = NULL;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
char *err = NULL;
|
||||
rc = sqlite3_exec(mDb, "PRAGMA cipher_migrate;", NULL, NULL, &err);
|
||||
if (rc != SQLITE_OK)
|
||||
{
|
||||
std::cerr << "RetroDb::RetroDb(): Error upgrading database, error code: " << rc;
|
||||
if (err)
|
||||
{
|
||||
std::cerr << ", " << err;
|
||||
}
|
||||
std::cerr << std::endl;
|
||||
sqlite3_free(err);
|
||||
}
|
||||
|
||||
//Test DB for correct sqlcipher version
|
||||
if (sqlite3_exec(mDb, "PRAGMA user_version;", NULL, NULL, NULL) != SQLITE_OK)
|
||||
int rc = sqlite3_open_v2(dbPath.c_str(), &mDb, flags, nullptr);
|
||||
if(rc)
|
||||
{
|
||||
std::cerr << "RetroDb::RetroDb(): Failed to open database: " << dbPath << std::endl << "Trying with settings for sqlcipher version 3...";
|
||||
//Reopening the database with correct settings
|
||||
rc = sqlite3_close(mDb);
|
||||
mDb = NULL;
|
||||
if(!rc)
|
||||
rc = sqlite3_open_v2(dbPath.c_str(), &mDb, flags, NULL);
|
||||
if(!rc && !mKey.empty())
|
||||
rc = sqlite3_key(mDb, mKey.c_str(), mKey.size());
|
||||
if(!rc)
|
||||
rc = sqlite3_exec(mDb, "PRAGMA kdf_iter = 64000;", NULL, NULL, NULL);
|
||||
if (!rc && (sqlite3_exec(mDb, "PRAGMA user_version;", NULL, NULL, NULL) == SQLITE_OK))
|
||||
RsErr() << __PRETTY_FUNCTION__ << " Can't open database, Error: "
|
||||
<< rc << " " << sqlite3_errmsg(mDb) << std::endl;
|
||||
closeDb();
|
||||
print_stacktrace();
|
||||
return;
|
||||
}
|
||||
|
||||
if(alreadyExists)
|
||||
{
|
||||
/* If the database has been created by a RetroShare compiled without
|
||||
* SQLCipher, open it as a plain SQLite database instead of failing
|
||||
* miserably. If RetroShare has been compiled without SQLCipher but the
|
||||
* database seems encrypted print a meaningful error message instead of
|
||||
* crashing miserably.
|
||||
* At some point we could implement a migration SQLite <-> SQLCipher
|
||||
* mecanism and suggest it to the user, or give the option to the user
|
||||
* to choice between plain SQLite or SQLCipher database, is some cases
|
||||
* such as encrypted FS it might make sense to keep SQLite even if
|
||||
* SQLCipher is availble for performance, as encryption is already
|
||||
* provided at FS level. */
|
||||
|
||||
rc = sqlite3_exec( mDb, "PRAGMA schema_version;",
|
||||
nullptr, nullptr, nullptr );
|
||||
if( rc == SQLITE_OK )
|
||||
{
|
||||
std::cerr << "\tSuccess" << std::endl;
|
||||
} else {
|
||||
std::cerr << "\tFailed, giving up" << std::endl;
|
||||
sqlite3_close(mDb);
|
||||
mDb = NULL;
|
||||
#ifndef NO_SQLCIPHER
|
||||
RsWarn() << __PRETTY_FUNCTION__ << " The database is not encrypted: "
|
||||
<< dbPath << std::endl;
|
||||
#endif // ndef NO_SQLCIPHER
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef NO_SQLCIPHER
|
||||
RsErr() << __PRETTY_FUNCTION__ << " Error quering schema version."
|
||||
<< " Are you trying to open an encrypted database without "
|
||||
<< "compiling SQLCipher support?" << std::endl << std::endl;
|
||||
print_stacktrace();
|
||||
closeDb();
|
||||
#else // def NO_SQLCIPHER
|
||||
RsInfo() << __PRETTY_FUNCTION__ << " The database seems encrypted: "
|
||||
<< dbPath << std::endl;
|
||||
#endif // def NO_SQLCIPHER
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef NO_SQLCIPHER
|
||||
if(!mKey.empty())
|
||||
{
|
||||
rc = sqlite3_key(mDb, mKey.c_str(), static_cast<int>(mKey.size()));
|
||||
|
||||
if(rc)
|
||||
{
|
||||
RsErr() << __PRETTY_FUNCTION__ << " Can't key database: " << rc
|
||||
<< " " << sqlite3_errmsg(mDb) << std::endl;
|
||||
closeDb();
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
char* err = nullptr;
|
||||
rc = sqlite3_exec(mDb, "PRAGMA cipher_migrate;", nullptr, nullptr, &err);
|
||||
if (rc != SQLITE_OK)
|
||||
{
|
||||
RsErr() << __PRETTY_FUNCTION__ << " Error upgrading database, error "
|
||||
<< "code: " << rc << " " << err << std::endl;
|
||||
sqlite3_free(err);
|
||||
}
|
||||
|
||||
// Test DB for correct sqlcipher version
|
||||
if(sqlite3_exec(
|
||||
mDb, "PRAGMA user_version;",
|
||||
nullptr, nullptr, nullptr ) != SQLITE_OK)
|
||||
{
|
||||
RsWarn() << __PRETTY_FUNCTION__ << " Failed to open database: "
|
||||
<< dbPath << std::endl;
|
||||
|
||||
//Reopening the database with correct settings
|
||||
closeDb();
|
||||
if(!rc) rc = sqlite3_open_v2(dbPath.c_str(), &mDb, flags, nullptr);
|
||||
if(!rc && !mKey.empty())
|
||||
rc = sqlite3_key(mDb, mKey.c_str(), static_cast<int>(mKey.size()));
|
||||
if(!rc)
|
||||
rc = sqlite3_exec( mDb, "PRAGMA kdf_iter = 64000;",
|
||||
nullptr, nullptr, nullptr );
|
||||
if (!rc && (sqlite3_exec( mDb, "PRAGMA user_version;",
|
||||
nullptr, nullptr, nullptr ) == SQLITE_OK))
|
||||
{
|
||||
RsInfo() << __PRETTY_FUNCTION__ << " Re-trying with settings for "
|
||||
<< "sqlcipher version 3 successed" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
RsErr() << __PRETTY_FUNCTION__ << " Re-trying with settings for "
|
||||
<< "sqlcipher version 3 failed, giving up" << std::endl;
|
||||
closeDb();
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif // ndef NO_SQLCIPHER
|
||||
}
|
||||
|
||||
RetroDb::~RetroDb(){
|
||||
RetroDb::~RetroDb() { closeDb(); }
|
||||
|
||||
sqlite3_close(mDb); // no-op if mDb is NULL (https://www.sqlite.org/c3ref/close.html)
|
||||
mDb = NULL ;
|
||||
}
|
||||
|
||||
void RetroDb::closeDb(){
|
||||
|
||||
int rc= sqlite3_close(mDb);
|
||||
mDb = NULL ;
|
||||
|
||||
#ifdef RETRODB_DEBUG
|
||||
std::cerr << "RetroDb::closeDb(): Error code on close: " << rc << std::endl;
|
||||
#else
|
||||
(void)rc;
|
||||
#endif
|
||||
void RetroDb::closeDb()
|
||||
{
|
||||
// no-op if mDb is nullptr (https://www.sqlite.org/c3ref/close.html)
|
||||
int rc = sqlite3_close(mDb);
|
||||
mDb = nullptr;
|
||||
|
||||
Dbg2() << __PRETTY_FUNCTION__ << " sqlite3_close return: " << rc
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
#define TIME_LIMIT 3
|
||||
|
|
|
@ -19,8 +19,7 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
*******************************************************************************/
|
||||
#ifndef RSSQLITE_H
|
||||
#define RSSQLITE_H
|
||||
#pragma once
|
||||
|
||||
#ifdef NO_SQLCIPHER
|
||||
#include <sqlite3.h>
|
||||
|
@ -32,9 +31,10 @@
|
|||
#include <set>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include "rsdbbind.h"
|
||||
|
||||
#include "contentvalue.h"
|
||||
#include "util/rsdebug.h"
|
||||
#include "util/rsdbbind.h"
|
||||
#include "util/contentvalue.h"
|
||||
|
||||
class RetroCursor;
|
||||
|
||||
|
@ -202,6 +202,8 @@ private:
|
|||
|
||||
sqlite3* mDb;
|
||||
const std::string mKey;
|
||||
|
||||
RS_SET_CONTEXT_DEBUG_LEVEL(3)
|
||||
};
|
||||
|
||||
/*!
|
||||
|
@ -318,5 +320,3 @@ public:
|
|||
private:
|
||||
sqlite3_stmt* mStmt;
|
||||
};
|
||||
|
||||
#endif // RSSQLITE_H
|
||||
|
|
|
@ -242,6 +242,10 @@ RsTickingThread::RsTickingThread()
|
|||
#endif
|
||||
}
|
||||
|
||||
RsTickingThread::~RsTickingThread()
|
||||
{
|
||||
fullstop();
|
||||
}
|
||||
void RsSingleJobThread::runloop()
|
||||
{
|
||||
run() ;
|
||||
|
|
|
@ -287,6 +287,7 @@ class RsTickingThread: public RsThread
|
|||
{
|
||||
public:
|
||||
RsTickingThread();
|
||||
virtual ~RsTickingThread();
|
||||
|
||||
void shutdown();
|
||||
void fullstop();
|
||||
|
|
|
@ -23,12 +23,10 @@
|
|||
#include <cstdio>
|
||||
#include <csignal>
|
||||
#include <cstdlib>
|
||||
#include <stdio.h>
|
||||
|
||||
#if defined(__linux__) && defined(__GLIBC__)
|
||||
|
||||
#include <execinfo.h>
|
||||
#include <cxxabi.h>
|
||||
#ifdef __ANDROID__
|
||||
# include "util/rsdebug.h"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Print a backtrace to FILE* out.
|
||||
|
@ -40,7 +38,16 @@
|
|||
* @param[in] maxFrames maximum number of stack frames you want to bu printed
|
||||
*/
|
||||
static inline void print_stacktrace(
|
||||
bool demangle = true, FILE *out = stderr, unsigned int maxFrames = 63 )
|
||||
bool demangle = true, FILE *out = stderr, unsigned int maxFrames = 63 );
|
||||
|
||||
|
||||
#if defined(__linux__) && defined(__GLIBC__)
|
||||
|
||||
#include <execinfo.h>
|
||||
#include <cxxabi.h>
|
||||
|
||||
static inline void print_stacktrace(
|
||||
bool demangle, FILE* out, unsigned int maxFrames )
|
||||
{
|
||||
if(!out)
|
||||
{
|
||||
|
@ -140,15 +147,111 @@ static inline void print_stacktrace(
|
|||
free(funcname);
|
||||
free(symbollist);
|
||||
}
|
||||
#elif defined(__ANDROID__) // defined(__linux__) && defined(__GLIBC__)
|
||||
|
||||
/* Inspired by the solution proposed by Louis Semprini on this thread
|
||||
* https://stackoverflow.com/questions/8115192/android-ndk-getting-the-backtrace/35586148
|
||||
*/
|
||||
|
||||
#include <unwind.h>
|
||||
#include <dlfcn.h>
|
||||
#include <cxxabi.h>
|
||||
|
||||
struct RsAndroidBacktraceState
|
||||
{
|
||||
void** current;
|
||||
void** end;
|
||||
};
|
||||
|
||||
static inline _Unwind_Reason_Code android_unwind_callback(
|
||||
struct _Unwind_Context* context, void* arg )
|
||||
{
|
||||
RsAndroidBacktraceState* state = static_cast<RsAndroidBacktraceState*>(arg);
|
||||
uintptr_t pc = _Unwind_GetIP(context);
|
||||
if(pc)
|
||||
{
|
||||
if (state->current == state->end) return _URC_END_OF_STACK;
|
||||
|
||||
*state->current++ = reinterpret_cast<void*>(pc);
|
||||
}
|
||||
return _URC_NO_REASON;
|
||||
}
|
||||
|
||||
static inline void print_stacktrace(
|
||||
bool demangle, FILE* /*out*/, unsigned int /*maxFrames*/)
|
||||
{
|
||||
constexpr int max = 5000;
|
||||
void* buffer[max];
|
||||
|
||||
RsAndroidBacktraceState state;
|
||||
state.current = buffer;
|
||||
state.end = buffer + max;
|
||||
|
||||
_Unwind_Backtrace(android_unwind_callback, &state);
|
||||
|
||||
RsDbg() << std::endl << std::endl
|
||||
<< 0 << " " << buffer[0] << " " << __PRETTY_FUNCTION__ << std::endl;
|
||||
|
||||
// Skip first frame which is print_stacktrace
|
||||
int count = static_cast<int>(state.current - buffer);
|
||||
for(int idx = 1; idx < count; ++idx)
|
||||
{
|
||||
const void* addr = buffer[idx];
|
||||
|
||||
/* Ignore null addresses.
|
||||
* They sometimes happen when using _Unwind_Backtrace()
|
||||
* with compiler optimizations, when the Link Register is overwritten by
|
||||
* the inner stack frames. */
|
||||
if(!addr) continue;
|
||||
|
||||
/* Ignore duplicate addresses.
|
||||
* They sometimes happen when using _Unwind_Backtrace() with compiler
|
||||
* optimizations. */
|
||||
if(addr == buffer[idx-1]) continue;
|
||||
|
||||
Dl_info info;
|
||||
if( !(dladdr(addr, &info) && info.dli_sname) )
|
||||
{
|
||||
RsDbg() << idx << " " << addr << " " << info.dli_fname
|
||||
<< " symbol not found" << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(demangle)
|
||||
{
|
||||
int status = 0;
|
||||
char* demangled = __cxxabiv1::__cxa_demangle(
|
||||
info.dli_sname, nullptr, nullptr, &status );
|
||||
|
||||
if(demangled && (status == 0))
|
||||
RsDbg() << idx << " " << addr << " " << demangled << std::endl;
|
||||
else
|
||||
RsDbg() << idx << " " << addr << " "
|
||||
<< (info.dli_sname ? info.dli_sname : info.dli_fname)
|
||||
<< " __cxa_demangle failed with: " << status
|
||||
<< std::endl;
|
||||
|
||||
free(demangled);
|
||||
}
|
||||
else RsDbg() << idx << " " << addr << " "
|
||||
<< (info.dli_sname ? info.dli_sname : info.dli_fname)
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
RsDbg() << std::endl << std::endl;
|
||||
}
|
||||
|
||||
#else // defined(__linux__) && defined(__GLIBC__)
|
||||
static inline void print_stacktrace(
|
||||
bool demangle = true, FILE *out = stderr, unsigned int max_frames = 63 )
|
||||
{
|
||||
(void) demangle;
|
||||
(void) max_frames;
|
||||
|
||||
fprintf(out, "TODO: 2016/01/01 print_stacktrace not implemented yet for WINDOWS_SYS and ANDROID\n");
|
||||
static inline void print_stacktrace(
|
||||
bool /*demangle*/, FILE* out, unsigned int /*max_frames*/ )
|
||||
{
|
||||
/** Notify the user which signal was caught. We use printf, because this
|
||||
* is the most basic output function. Once you get a crash, it is
|
||||
* possible that more complex output systems like streams and the like
|
||||
* may be corrupted. So we make the most basic call possible to the
|
||||
* lowest level, most standard print function. */
|
||||
fprintf(out, "print_stacktrace Not implemented yet for this platform\n");
|
||||
}
|
||||
#endif // defined(__linux__) && defined(__GLIBC__)
|
||||
|
||||
|
@ -169,6 +272,7 @@ struct CrashStackTrace
|
|||
#endif
|
||||
}
|
||||
|
||||
[[ noreturn ]]
|
||||
static void abortHandler(int signum)
|
||||
{
|
||||
// associate each signal with a signal name string.
|
||||
|
@ -184,6 +288,7 @@ struct CrashStackTrace
|
|||
#endif
|
||||
}
|
||||
|
||||
#ifndef __ANDROID__
|
||||
/** Notify the user which signal was caught. We use printf, because this
|
||||
* is the most basic output function. Once you get a crash, it is
|
||||
* possible that more complex output systems like streams and the like
|
||||
|
@ -193,6 +298,11 @@ struct CrashStackTrace
|
|||
fprintf(stderr, "Caught signal %d (%s)\n", signum, name);
|
||||
else
|
||||
fprintf(stderr, "Caught signal %d\n", signum);
|
||||
#else // ndef __ANDROID__
|
||||
/** On Android the best we can to is to rely on RS debug utils */
|
||||
RsFatal() << __PRETTY_FUNCTION__ << " Caught signal " << signum << " "
|
||||
<< (name ? name : "") << std::endl;
|
||||
#endif
|
||||
|
||||
print_stacktrace(false);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue