mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 22:25:04 -04:00
merged with upstream/master
This commit is contained in:
commit
ade6017f74
469 changed files with 88476 additions and 59565 deletions
|
@ -34,7 +34,6 @@
|
|||
#include "pqi/p3historymgr.h"
|
||||
#include "retroshare/rspeers.h"
|
||||
#include "retroshare/rsiface.h"
|
||||
#include "retroshare/rsreputations.h"
|
||||
#include "retroshare/rsidentity.h"
|
||||
#include "rsserver/p3face.h"
|
||||
#include "gxs/rsgixs.h"
|
||||
|
@ -139,7 +138,7 @@ bool DistributedChatService::handleRecvChatLobbyMsgItem(RsChatMsgItem *ci)
|
|||
return false ;
|
||||
}
|
||||
|
||||
if(rsReputations->isIdentityBanned(cli->signature.keyId))
|
||||
if(rsIdentity->isBanned(cli->signature.keyId))
|
||||
{
|
||||
std::cerr << "(WW) Received lobby msg/item from banned identity " << cli->signature.keyId << ". Dropping it." << std::endl;
|
||||
return false ;
|
||||
|
@ -169,7 +168,7 @@ bool DistributedChatService::handleRecvChatLobbyMsgItem(RsChatMsgItem *ci)
|
|||
if(it == _chat_lobbys.end())
|
||||
{
|
||||
#ifdef DEBUG_CHAT_LOBBIES
|
||||
std::cerr << "Chatlobby for id " << std::hex << item->lobby_id << " has no record. Dropping the msg." << std::dec << std::endl;
|
||||
std::cerr << "Chatlobby for id " << std::hex << cli->lobby_id << " has no record. Dropping the msg." << std::dec << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
@ -648,7 +647,7 @@ void DistributedChatService::handleRecvChatLobbyEventItem(RsChatLobbyEventItem *
|
|||
#endif
|
||||
time_t now = time(NULL) ;
|
||||
|
||||
if(rsReputations->isIdentityBanned(item->signature.keyId))
|
||||
if(rsIdentity->isBanned(item->signature.keyId))
|
||||
{
|
||||
std::cerr << "(WW) Received lobby msg/item from banned identity " << item->signature.keyId << ". Dropping it." << std::endl;
|
||||
return ;
|
||||
|
|
|
@ -431,7 +431,7 @@ int FileIndexMonitor::filterResults(std::list<FileEntry*>& firesults,std::list<D
|
|||
return !results.empty() ;
|
||||
}
|
||||
|
||||
bool FileIndexMonitor::findLocalFile(const RsFileHash& hash,FileSearchFlags hint_flags, const RsPeerId& peer_id,std::string &fullpath, uint64_t &size,FileStorageFlags& storage_flags,std::list<std::string>& parent_groups) const
|
||||
bool FileIndexMonitor::findLocalFile(const RsFileHash& hash,FileSearchFlags hint_flags, const RsPeerId& peer_id,std::string &fullpath, uint64_t &size,FileStorageFlags& storage_flags,std::list<RsNodeGroupId>& parent_groups) const
|
||||
{
|
||||
std::list<FileEntry *> results;
|
||||
bool ok = false;
|
||||
|
@ -1668,7 +1668,7 @@ int FileIndexMonitor::RequestDirDetails(void *ref, DirDetails &details, FileSear
|
|||
return true ;
|
||||
}
|
||||
|
||||
void FileIndexMonitor::locked_findShareFlagsAndParentGroups(FileEntry *file,FileStorageFlags& flags,std::list<std::string>& parent_groups) const
|
||||
void FileIndexMonitor::locked_findShareFlagsAndParentGroups(FileEntry *file,FileStorageFlags& flags,std::list<RsNodeGroupId>& parent_groups) const
|
||||
{
|
||||
flags.clear() ;
|
||||
static const FileStorageFlags PERMISSION_MASK = DIR_FLAGS_BROWSABLE_OTHERS | DIR_FLAGS_NETWORK_WIDE_OTHERS | DIR_FLAGS_BROWSABLE_GROUPS | DIR_FLAGS_NETWORK_WIDE_GROUPS ;
|
||||
|
|
|
@ -110,7 +110,7 @@ class FileIndexMonitor: public CacheSource, public RsTickingThread
|
|||
virtual ~FileIndexMonitor();
|
||||
|
||||
/* external interface for filetransfer */
|
||||
bool findLocalFile(const RsFileHash& hash,FileSearchFlags flags,const RsPeerId& peer_id, std::string &fullpath, uint64_t &size,FileStorageFlags& storage_flags,std::list<std::string>& parent_groups) const;
|
||||
bool findLocalFile(const RsFileHash& hash,FileSearchFlags flags,const RsPeerId& peer_id, std::string &fullpath, uint64_t &size,FileStorageFlags& storage_flags,std::list<RsNodeGroupId>& parent_groups) const;
|
||||
|
||||
int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags,const RsPeerId& peer_id) ;
|
||||
int SearchBoolExp(Expression *exp, std::list<DirDetails> &results,FileSearchFlags flags,const RsPeerId& peer_id) const ;
|
||||
|
@ -176,7 +176,7 @@ class FileIndexMonitor: public CacheSource, public RsTickingThread
|
|||
time_t locked_saveFileIndexes(bool update_cache) ;
|
||||
|
||||
// Finds the share flags associated with this file entry.
|
||||
void locked_findShareFlagsAndParentGroups(FileEntry *fe,FileStorageFlags& shareflags,std::list<std::string>& parent_groups) const ;
|
||||
void locked_findShareFlagsAndParentGroups(FileEntry *fe, FileStorageFlags& shareflags, std::list<RsNodeGroupId> &parent_groups) const ;
|
||||
|
||||
std::string locked_findRealRoot(std::string base) const;
|
||||
|
||||
|
|
|
@ -30,7 +30,11 @@
|
|||
#include "bitdht/bdstddht.h"
|
||||
|
||||
#include "tcponudp/udprelay.h"
|
||||
#ifdef RS_USE_DHT_STUNNER
|
||||
#include "tcponudp/udpstunner.h"
|
||||
#endif // RS_USE_DHT_STUNNER
|
||||
|
||||
#include "retroshare/rsbanlist.h"
|
||||
|
||||
#include <openssl/sha.h>
|
||||
|
||||
|
@ -76,6 +80,27 @@ virtual int dhtInfoCallback(const bdId *id, uint32_t type, uint32_t flags, std::
|
|||
return mParent->InfoCallback(id, type, flags, info);
|
||||
}
|
||||
|
||||
virtual int dhtIsBannedCallback(const sockaddr_in *addr, bool *isBanned)
|
||||
{
|
||||
// check whether ip filtering is enabled
|
||||
// if not return 0 to signal that no filter is available
|
||||
if(!rsBanList->ipFilteringEnabled())
|
||||
return 0;
|
||||
|
||||
// now check the filter
|
||||
if(rsBanList->isAddressAccepted(*(const sockaddr_storage*)addr, RSBANLIST_CHECKING_FLAGS_BLACKLIST, NULL)) {
|
||||
*isBanned = false;
|
||||
} else {
|
||||
#ifdef DEBUG_BITDHT
|
||||
std::cerr << "p3BitDht dhtIsBannedCallback: peer is banned " << sockaddr_storage_tostring(*(const sockaddr_storage*)addr) << std::endl;
|
||||
#endif
|
||||
*isBanned = true;
|
||||
}
|
||||
|
||||
// return 1 to signal that a filter is available
|
||||
return 1;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
p3BitDht *mParent;
|
||||
|
@ -86,8 +111,10 @@ p3BitDht::p3BitDht(const RsPeerId& id, pqiConnectCb *cb, p3NetMgr *nm,
|
|||
UdpStack *udpstack, std::string bootstrapfile,const std::string& filteredipfile)
|
||||
:p3Config(), pqiNetAssistConnect(id, cb), mNetMgr(nm), dhtMtx("p3BitDht")
|
||||
{
|
||||
#ifdef RS_USE_DHT_STUNNER
|
||||
mDhtStunner = NULL;
|
||||
mProxyStunner = NULL;
|
||||
#endif
|
||||
mRelay = NULL;
|
||||
|
||||
mPeerSharer = NULL;
|
||||
|
@ -168,13 +195,19 @@ bool p3BitDht::getOwnDhtId(std::string &ownDhtId)
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
#ifdef RS_USE_DHT_STUNNER
|
||||
void p3BitDht::setupConnectBits(UdpStunner *dhtStunner, UdpStunner *proxyStunner, UdpRelayReceiver *relay)
|
||||
{
|
||||
mDhtStunner = dhtStunner;
|
||||
mProxyStunner = proxyStunner;
|
||||
mRelay = relay;
|
||||
}
|
||||
#else // RS_USE_DHT_STUNNER
|
||||
void p3BitDht::setupConnectBits(UdpRelayReceiver *relay)
|
||||
{
|
||||
mRelay = relay;
|
||||
}
|
||||
#endif //RS_USE_DHT_STUNNER
|
||||
|
||||
void p3BitDht::setupPeerSharer(pqiNetAssistPeerShare *sharer)
|
||||
{
|
||||
|
|
|
@ -136,7 +136,9 @@ class p3BitDhtRelayHandler
|
|||
|
||||
|
||||
class UdpRelayReceiver;
|
||||
#ifdef RS_USE_DHT_STUNNER
|
||||
class UdpStunner;
|
||||
#endif // RS_USE_DHT_STUNNER
|
||||
class p3NetMgr;
|
||||
|
||||
class p3BitDht: public p3Config, public pqiNetAssistConnect, public RsDht
|
||||
|
@ -174,8 +176,11 @@ public:
|
|||
********** External RsDHT Interface (defined in libretroshare/src/retroshare/rsdht.h) *********
|
||||
************************************************************************************************/
|
||||
|
||||
|
||||
#ifdef RS_USE_DHT_STUNNER
|
||||
void setupConnectBits(UdpStunner *dhtStunner, UdpStunner *proxyStunner, UdpRelayReceiver *relay);
|
||||
#else // RS_USE_DHT_STUNNER
|
||||
void setupConnectBits(UdpRelayReceiver *relay);
|
||||
#endif // RS_USE_DHT_STUNNER
|
||||
void setupPeerSharer(pqiNetAssistPeerShare *sharer);
|
||||
void modifyNodesPerBucket(uint16_t count);
|
||||
|
||||
|
@ -359,8 +364,10 @@ private:
|
|||
int removeTranslation_locked(const RsPeerId& pid);
|
||||
|
||||
UdpBitDht *mUdpBitDht; /* has own mutex, is static except for creation/destruction */
|
||||
#ifdef RS_USE_DHT_STUNNER
|
||||
UdpStunner *mDhtStunner;
|
||||
UdpStunner *mProxyStunner;
|
||||
#endif // RS_USE_DHT_STUNNER
|
||||
UdpRelayReceiver *mRelay;
|
||||
|
||||
p3NetMgr *mNetMgr;
|
||||
|
|
|
@ -149,7 +149,7 @@ int p3BitDht::getNetFailedPeer(std::string peerId, PeerStatus &status)
|
|||
std::string p3BitDht::getUdpAddressString()
|
||||
{
|
||||
std::string out;
|
||||
|
||||
#ifdef RS_USE_DHT_STUNNER
|
||||
struct sockaddr_in extAddr;
|
||||
uint8_t extStable;
|
||||
|
||||
|
@ -187,7 +187,10 @@ std::string p3BitDht::getUdpAddressString()
|
|||
{
|
||||
out += " ProxyExtAddr: Unknown ";
|
||||
}
|
||||
|
||||
#else // RS_USE_DHT_STUNNER
|
||||
// whitespaces taken from above
|
||||
out = " DhtExtAddr: Unknown ProxyExtAddr: Unknown ";
|
||||
#endif // RS_USE_DHT_STUNNER
|
||||
return out;
|
||||
}
|
||||
|
||||
|
|
|
@ -81,6 +81,7 @@ int p3BitDht::InfoCallback(const bdId *id, uint32_t /*type*/, uint32_t /*flags*/
|
|||
mPeerSharer->updatePeer(rsid, tmpaddr, outtype, outreason, outage);
|
||||
}
|
||||
|
||||
#ifdef RS_USE_DHT_STUNNER
|
||||
/* call to the Stunners to drop the address as well */
|
||||
/* IDEALLY these addresses should all be filtered at UdpLayer level instead! */
|
||||
if (mDhtStunner)
|
||||
|
@ -91,6 +92,7 @@ int p3BitDht::InfoCallback(const bdId *id, uint32_t /*type*/, uint32_t /*flags*/
|
|||
{
|
||||
mProxyStunner->dropStunPeer(addr);
|
||||
}
|
||||
#endif // RS_USE_DHT_STUNNER
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -135,7 +137,7 @@ int p3BitDht::NodeCallback(const bdId *id, uint32_t peerflags)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef RS_USE_DHT_STUNNER
|
||||
if ((mProxyStunner) && (mProxyStunner->needStunPeers()))
|
||||
{
|
||||
#ifdef DEBUG_BITDHT_COMMON
|
||||
|
@ -156,6 +158,7 @@ int p3BitDht::NodeCallback(const bdId *id, uint32_t peerflags)
|
|||
#endif
|
||||
mDhtStunner->addStunPeer(id->addr, NULL);
|
||||
}
|
||||
#endif // RS_USE_DHT_STUNNER
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
@ -683,7 +686,6 @@ int p3BitDht::ConnectCallback(const bdId *srcId, const bdId *proxyId, const bdId
|
|||
#endif
|
||||
|
||||
struct sockaddr_in extaddr;
|
||||
uint8_t extStable = 0;
|
||||
sockaddr_clear(&extaddr);
|
||||
|
||||
bool connectOk = false;
|
||||
|
@ -731,6 +733,9 @@ int p3BitDht::ConnectCallback(const bdId *srcId, const bdId *proxyId, const bdId
|
|||
std::cerr << std::endl;
|
||||
}
|
||||
|
||||
#ifdef RS_USE_DHT_STUNNER
|
||||
uint8_t extStable = 0;
|
||||
|
||||
UdpStunner *stunner = mProxyStunner;
|
||||
if (!proxyPort)
|
||||
{
|
||||
|
@ -849,6 +854,11 @@ int p3BitDht::ConnectCallback(const bdId *srcId, const bdId *proxyId, const bdId
|
|||
std::cerr << std::endl;
|
||||
#endif
|
||||
}
|
||||
#else // RS_USE_DHT_STUNNER
|
||||
connectionAllowed = BITDHT_CONNECT_ERROR_TEMPUNAVAIL;
|
||||
(void) connectOk;
|
||||
(void) exclusivePort;
|
||||
#endif // RS_USE_DHT_STUNNER
|
||||
}
|
||||
|
||||
ca.mMode = mode;
|
||||
|
@ -1188,7 +1198,6 @@ int p3BitDht::doActions()
|
|||
else if (action.mMode == BITDHT_CONNECT_MODE_PROXY)
|
||||
{
|
||||
struct sockaddr_in extaddr;
|
||||
uint8_t extStable = 0;
|
||||
sockaddr_clear(&extaddr);
|
||||
bool proxyPort = true;
|
||||
bool exclusivePort = false;
|
||||
|
@ -1234,6 +1243,9 @@ int p3BitDht::doActions()
|
|||
std::cerr << std::endl;
|
||||
}
|
||||
}
|
||||
#ifdef RS_USE_DHT_STUNNER
|
||||
uint8_t extStable = 0;
|
||||
|
||||
UdpStunner *stunner = mProxyStunner;
|
||||
if (!proxyPort)
|
||||
{
|
||||
|
@ -1333,6 +1345,11 @@ int p3BitDht::doActions()
|
|||
connectionReqFailed = true;
|
||||
failReason = CSB_UPDATE_RETRY_ATTEMPT;
|
||||
}
|
||||
#else // RS_USE_DHT_STUNNER
|
||||
connectionReqFailed = true;
|
||||
failReason = CSB_UPDATE_RETRY_ATTEMPT;
|
||||
(void) connectOk;
|
||||
#endif //RS_USE_DHT_STUNNER
|
||||
}
|
||||
|
||||
if (doConnectionRequest)
|
||||
|
@ -1416,7 +1433,9 @@ int p3BitDht::doActions()
|
|||
{
|
||||
std::cerr << "PeerAction: ERROR ERROR, we grabd Exclusive Port to do this, trying emergency release";
|
||||
std::cerr << std::endl;
|
||||
#ifdef RS_USE_DHT_STUNNER
|
||||
mProxyStunner->releaseExclusiveMode(pid,false);
|
||||
#endif // RS_USE_DHT_STUNNER
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2378,6 +2397,7 @@ void p3BitDht::ReleaseProxyExclusiveMode_locked(DhtPeerDetails *dpd, bool addrCh
|
|||
|
||||
if (dpd->mExclusiveProxyLock)
|
||||
{
|
||||
#ifdef RS_USE_DHT_STUNNER
|
||||
if (mProxyStunner->releaseExclusiveMode(pid, addrChgLikely))
|
||||
{
|
||||
dpd->mExclusiveProxyLock = false;
|
||||
|
@ -2389,6 +2409,9 @@ void p3BitDht::ReleaseProxyExclusiveMode_locked(DhtPeerDetails *dpd, bool addrCh
|
|||
#endif
|
||||
}
|
||||
else
|
||||
#else // RS_USE_DHT_STUNNER
|
||||
(void)addrChgLikely;
|
||||
#endif // RS_USE_DHT_STUNNER
|
||||
{
|
||||
dpd->mExclusiveProxyLock = false;
|
||||
|
||||
|
|
|
@ -202,7 +202,7 @@ int p3BitDht::addBadPeer(const struct sockaddr_storage &addr, uint32_t /*reason*
|
|||
addrv4.sin_addr = ap->sin_addr;
|
||||
addrv4.sin_port = ap->sin_port;
|
||||
|
||||
|
||||
#ifdef RS_USE_DHT_STUNNER
|
||||
if (mDhtStunner)
|
||||
{
|
||||
mDhtStunner->dropStunPeer(addrv4);
|
||||
|
@ -211,7 +211,7 @@ int p3BitDht::addBadPeer(const struct sockaddr_storage &addr, uint32_t /*reason*
|
|||
{
|
||||
mProxyStunner->dropStunPeer(addrv4);
|
||||
}
|
||||
|
||||
#endif // RS_USE_DHT_STUNNER
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
#include "ft/ftdbase.h"
|
||||
#include "util/rsdir.h"
|
||||
#include "retroshare/rspeers.h"
|
||||
|
||||
#include "serialiser/rsconfigitems.h"
|
||||
|
||||
|
@ -237,11 +238,13 @@ bool ftFiMonitor::saveList(bool &cleanup, std::list<RsItem *>& sList)
|
|||
|
||||
for(it = dirList.begin(); it != dirList.end(); ++it)
|
||||
{
|
||||
RsFileConfigItem *fi = new RsFileConfigItem();
|
||||
RsFileConfigItem *fi = new RsFileConfigItem();
|
||||
fi->file.path = (*it).filename ;
|
||||
fi->file.name = (*it).virtualname ;
|
||||
fi->flags = (*it).shareflags.toUInt32() ;
|
||||
fi->parent_groups = (*it).parent_groups ;
|
||||
|
||||
for(std::list<RsNodeGroupId>::const_iterator it2( (*it).parent_groups.begin());it2!=(*it).parent_groups.end();++it2)
|
||||
fi->parent_groups.ids.insert(*it2) ;
|
||||
|
||||
sList.push_back(fi);
|
||||
}
|
||||
|
@ -332,25 +335,53 @@ bool ftFiMonitor::loadList(std::list<RsItem *>& load)
|
|||
continue ;
|
||||
}
|
||||
|
||||
RsFileConfigItem *fi = dynamic_cast<RsFileConfigItem *>(*it);
|
||||
if (!fi)
|
||||
{
|
||||
delete (*it);
|
||||
continue;
|
||||
}
|
||||
// 07/05/2016 - This ensures backward compatibility. Can be removed in a few weeks.
|
||||
RsFileConfigItem_deprecated *fib = dynamic_cast<RsFileConfigItem_deprecated *>(*it);
|
||||
if (fib)
|
||||
{
|
||||
/* ensure that it exists? */
|
||||
|
||||
/* ensure that it exists? */
|
||||
SharedDirInfo info ;
|
||||
info.filename = RsDirUtil::convertPathToUnix(fib->file.path);
|
||||
info.virtualname = fib->file.name;
|
||||
info.shareflags = FileStorageFlags(fib->flags) ;
|
||||
info.shareflags &= PERMISSION_MASK ;
|
||||
info.shareflags &= ~DIR_FLAGS_NETWORK_WIDE_GROUPS ; // disabling this flag for know, for consistency reasons
|
||||
|
||||
SharedDirInfo info ;
|
||||
info.filename = RsDirUtil::convertPathToUnix(fi->file.path);
|
||||
info.virtualname = fi->file.name;
|
||||
info.parent_groups = fi->parent_groups;
|
||||
info.shareflags = FileStorageFlags(fi->flags) ;
|
||||
info.shareflags &= PERMISSION_MASK ;
|
||||
info.shareflags &= ~DIR_FLAGS_NETWORK_WIDE_GROUPS ; // disabling this flag for know, for consistency reasons
|
||||
for(std::list<std::string>::const_iterator itt(fib->parent_groups.begin());itt!=fib->parent_groups.end();++itt)
|
||||
{
|
||||
RsGroupInfo ginfo;
|
||||
|
||||
if(rsPeers->getGroupInfoByName(*itt,ginfo) )
|
||||
{
|
||||
info.parent_groups.push_back(ginfo.id) ;
|
||||
std::cerr << "(II) converted old group ID \"" << *itt << "\" into corresponding new group id " << ginfo.id << std::endl;
|
||||
}
|
||||
else
|
||||
std::cerr << "(EE) cannot convert old group ID \"" << *itt << "\" into corresponding new group id: no candidate found. " << std::endl;
|
||||
}
|
||||
|
||||
dirList.push_back(info) ;
|
||||
}
|
||||
|
||||
RsFileConfigItem *fi = dynamic_cast<RsFileConfigItem *>(*it);
|
||||
if (fi)
|
||||
{
|
||||
/* ensure that it exists? */
|
||||
|
||||
SharedDirInfo info ;
|
||||
info.filename = RsDirUtil::convertPathToUnix(fi->file.path);
|
||||
info.virtualname = fi->file.name;
|
||||
info.shareflags = FileStorageFlags(fi->flags) ;
|
||||
info.shareflags &= PERMISSION_MASK ;
|
||||
info.shareflags &= ~DIR_FLAGS_NETWORK_WIDE_GROUPS ; // disabling this flag for know, for consistency reasons
|
||||
|
||||
for(std::set<RsNodeGroupId>::const_iterator itt(fi->parent_groups.ids.begin());itt!=fi->parent_groups.ids.end();++itt)
|
||||
info.parent_groups.push_back(*itt) ;
|
||||
|
||||
dirList.push_back(info) ;
|
||||
}
|
||||
|
||||
dirList.push_back(info) ;
|
||||
|
||||
delete *it ;
|
||||
}
|
||||
|
||||
|
|
|
@ -395,7 +395,7 @@ bool ftExtraList::saveList(bool &cleanup, std::list<RsItem *>& sList)
|
|||
std::map<RsFileHash, FileDetails>::const_iterator it;
|
||||
for(it = mFiles.begin(); it != mFiles.end(); ++it)
|
||||
{
|
||||
RsFileConfigItem *fi = new RsFileConfigItem();
|
||||
RsFileConfigItem_deprecated *fi = new RsFileConfigItem_deprecated();
|
||||
fi->file.path = (it->second).info.path;
|
||||
fi->file.name = (it->second).info.fname;
|
||||
fi->file.hash = (it->second).info.hash;
|
||||
|
@ -428,7 +428,7 @@ bool ftExtraList::loadList(std::list<RsItem *>& load)
|
|||
for(it = load.begin(); it != load.end(); ++it)
|
||||
{
|
||||
|
||||
RsFileConfigItem *fi = dynamic_cast<RsFileConfigItem *>(*it);
|
||||
RsFileConfigItem_deprecated *fi = dynamic_cast<RsFileConfigItem_deprecated *>(*it);
|
||||
if (!fi)
|
||||
{
|
||||
delete (*it);
|
||||
|
|
|
@ -39,7 +39,7 @@ static const uint16_t GROUTER_CLIENT_ID_MESSAGES = 0x1001 ;
|
|||
|
||||
static const uint32_t RS_GROUTER_MATRIX_MAX_HIT_ENTRIES = 10 ; // max number of clues to store
|
||||
static const uint32_t RS_GROUTER_MATRIX_MIN_TIME_BETWEEN_HITS = 60 ; // can be set to up to half the publish time interval. Prevents flooding routes.
|
||||
static const uint32_t RS_GROUTER_MIN_CONFIG_SAVE_PERIOD = 10 ; // at most save config every 10 seconds
|
||||
static const uint32_t RS_GROUTER_MIN_CONFIG_SAVE_PERIOD = 61 ; // at most save config every 10 seconds
|
||||
static const uint32_t RS_GROUTER_MAX_KEEP_TRACKING_CLUES = 86400*10 ; // max time for which we keep record of tracking info: 10 days.
|
||||
|
||||
static const float RS_GROUTER_BASE_WEIGHT_ROUTED_MSG = 1.0f ; // base contribution of routed message clue to routing matrix
|
||||
|
|
|
@ -191,7 +191,6 @@
|
|||
#include "turtle/p3turtle.h"
|
||||
#include "gxs/rsgixs.h"
|
||||
#include "retroshare/rspeers.h"
|
||||
#include "retroshare/rsreputations.h"
|
||||
|
||||
#include "p3grouter.h"
|
||||
#include "grouteritems.h"
|
||||
|
@ -1863,15 +1862,6 @@ bool p3GRouter::locked_getLocallyRegisteredClientFromServiceId(const GRouterServ
|
|||
return true ;
|
||||
}
|
||||
|
||||
void p3GRouter::addTrackingInfo(const RsGxsMessageId& mid,const RsPeerId& peer_id)
|
||||
{
|
||||
RS_STACK_MUTEX(grMtx) ;
|
||||
#ifdef GROUTER_DEBUG
|
||||
grouter_debug() << "Received new routing clue for key " << mid << " from peer " << peer_id << std::endl;
|
||||
#endif
|
||||
_routing_matrix.addTrackingInfo(mid,peer_id) ;
|
||||
_changed = true ;
|
||||
}
|
||||
void p3GRouter::addRoutingClue(const GRouterKeyId& id,const RsPeerId& peer_id)
|
||||
{
|
||||
RS_STACK_MUTEX(grMtx) ;
|
||||
|
@ -1994,7 +1984,7 @@ bool p3GRouter::verifySignedDataItem(RsGRouterAbstractMsgItem *item,uint32_t& er
|
|||
{
|
||||
try
|
||||
{
|
||||
if(rsReputations->isIdentityBanned(item->signature.keyId))
|
||||
if(rsIdentity->isBanned(item->signature.keyId))
|
||||
{
|
||||
std::cerr << "(WW) received global router message from banned identity " << item->signature.keyId << ". Rejecting the message." << std::endl;
|
||||
return false ;
|
||||
|
@ -2358,13 +2348,6 @@ bool p3GRouter::getRoutingCacheInfo(std::vector<GRouterRoutingCacheInfo>& infos)
|
|||
return true ;
|
||||
}
|
||||
|
||||
bool p3GRouter::getTrackingInfo(const RsGxsMessageId &mid, RsPeerId &provider_id)
|
||||
{
|
||||
RS_STACK_MUTEX(grMtx) ;
|
||||
|
||||
return _routing_matrix.getTrackingInfo(mid,provider_id) ;
|
||||
}
|
||||
|
||||
// Dump everything
|
||||
//
|
||||
void p3GRouter::debugDump()
|
||||
|
|
|
@ -130,7 +130,6 @@ public:
|
|||
//===================================================//
|
||||
|
||||
virtual void addRoutingClue(const GRouterKeyId& id,const RsPeerId& peer_id) ;
|
||||
virtual void addTrackingInfo(const RsGxsMessageId& mid,const RsPeerId& peer_id) ;
|
||||
|
||||
//===================================================//
|
||||
// Client/server request services //
|
||||
|
@ -168,7 +167,6 @@ public:
|
|||
// - Cache state (memory size, etc)
|
||||
//
|
||||
virtual bool getRoutingCacheInfo(std::vector<GRouterRoutingCacheInfo>& info) ;
|
||||
virtual bool getTrackingInfo(const RsGxsMessageId& mid, RsPeerId& provider_id) ;
|
||||
|
||||
//===================================================//
|
||||
// Derived from p3Service //
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
/*****
|
||||
* #define RS_DATA_SERVICE_DEBUG 1
|
||||
* #define RS_DATA_SERVICE_DEBUG_TIME 1
|
||||
* #define RS_DATA_SERVICE_DEBUG_CACHE 1
|
||||
****/
|
||||
|
||||
#include <fstream>
|
||||
|
@ -123,6 +124,7 @@ RsDataService::RsDataService(const std::string &serviceDir, const std::string &d
|
|||
: RsGeneralDataService(), mDbMutex("RsDataService"), mServiceDir(serviceDir), mDbName(dbName), mDbPath(mServiceDir + "/" + dbName), mServType(serviceType), mDb(NULL)
|
||||
{
|
||||
bool isNewDatabase = !RsDirUtil::fileExists(mDbPath);
|
||||
mGrpMetaDataCache_ContainsAllDatabase = false ;
|
||||
|
||||
mDb = new RetroDb(mDbPath, RetroDb::OPEN_READWRITE_CREATE, key);
|
||||
|
||||
|
@ -710,25 +712,25 @@ int RsDataService::storeMessage(std::map<RsNxsMsg *, RsGxsMsgMetaData *> &msg)
|
|||
// start a transaction
|
||||
mDb->beginTransaction();
|
||||
|
||||
for(; mit != msg.end(); ++mit){
|
||||
|
||||
for(; mit != msg.end(); ++mit)
|
||||
{
|
||||
RsNxsMsg* msgPtr = mit->first;
|
||||
RsGxsMsgMetaData* msgMetaPtr = mit->second;
|
||||
|
||||
#ifdef RS_DATA_SERVICE_DEBUG
|
||||
std::cerr << "RsDataService::storeMessage() ";
|
||||
std::cerr << " GroupId: " << msgMetaPtr->mGroupId.toStdString();
|
||||
std::cerr << " MessageId: " << msgMetaPtr->mMsgId.toStdString();
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "RsDataService::storeMessage() ";
|
||||
std::cerr << " GroupId: " << msgMetaPtr->mGroupId.toStdString();
|
||||
std::cerr << " MessageId: " << msgMetaPtr->mMsgId.toStdString();
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
// skip msg item if size if greater than
|
||||
if(!validSize(msgPtr))
|
||||
{
|
||||
std::cerr << "RsDataService::storeMessage() ERROR invalid size";
|
||||
std::cerr << std::endl;
|
||||
continue;
|
||||
}
|
||||
{
|
||||
std::cerr << "RsDataService::storeMessage() ERROR invalid size";
|
||||
std::cerr << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
ContentValue cv;
|
||||
|
||||
|
@ -771,14 +773,18 @@ int RsDataService::storeMessage(std::map<RsNxsMsg *, RsGxsMsgMetaData *> &msg)
|
|||
cv.put(KEY_CHILD_TS, (int32_t)msgMetaPtr->mChildTs);
|
||||
|
||||
if (!mDb->sqlInsert(MSG_TABLE_NAME, "", cv))
|
||||
{
|
||||
std::cerr << "RsDataService::storeMessage() sqlInsert Failed";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "\t For GroupId: " << msgMetaPtr->mGroupId.toStdString();
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "\t & MessageId: " << msgMetaPtr->mMsgId.toStdString();
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
{
|
||||
std::cerr << "RsDataService::storeMessage() sqlInsert Failed";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "\t For GroupId: " << msgMetaPtr->mGroupId.toStdString();
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "\t & MessageId: " << msgMetaPtr->mMsgId.toStdString();
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
|
||||
// This is needed so that mLastPost is correctly updated in the group meta when it is re-loaded.
|
||||
|
||||
locked_clearGrpMetaCache(msgMetaPtr->mGroupId);
|
||||
}
|
||||
|
||||
// finish transaction
|
||||
|
@ -881,6 +887,8 @@ int RsDataService::storeGroup(std::map<RsNxsGrp *, RsGxsGrpMetaData *> &grp)
|
|||
cv.put(KEY_GRP_STATUS, (int32_t)grpMetaPtr->mGroupStatus);
|
||||
cv.put(KEY_GRP_LAST_POST, (int32_t)grpMetaPtr->mLastPost);
|
||||
|
||||
locked_clearGrpMetaCache(grpMetaPtr->mGroupId);
|
||||
|
||||
if (!mDb->sqlInsert(GRP_TABLE_NAME, "", cv))
|
||||
{
|
||||
std::cerr << "RsDataService::storeGroup() sqlInsert Failed";
|
||||
|
@ -904,6 +912,12 @@ int RsDataService::storeGroup(std::map<RsNxsGrp *, RsGxsGrpMetaData *> &grp)
|
|||
return ret;
|
||||
}
|
||||
|
||||
void RsDataService::locked_clearGrpMetaCache(const RsGxsGroupId& gid)
|
||||
{
|
||||
mGrpMetaDataCache.erase(gid) ; // cleans existing cache entry
|
||||
mGrpMetaDataCache_ContainsAllDatabase = false;
|
||||
}
|
||||
|
||||
int RsDataService::updateGroup(std::map<RsNxsGrp *, RsGxsGrpMetaData *> &grp)
|
||||
{
|
||||
|
||||
|
@ -971,6 +985,8 @@ int RsDataService::updateGroup(std::map<RsNxsGrp *, RsGxsGrpMetaData *> &grp)
|
|||
cv.put(KEY_GRP_LAST_POST, (int32_t)grpMetaPtr->mLastPost);
|
||||
|
||||
mDb->sqlUpdate(GRP_TABLE_NAME, "grpId='" + grpPtr->grpId.toStdString() + "'", cv);
|
||||
|
||||
locked_clearGrpMetaCache(grpMetaPtr->mGroupId);
|
||||
}
|
||||
// finish transaction
|
||||
bool ret = mDb->commitTransaction();
|
||||
|
@ -1231,6 +1247,9 @@ int RsDataService::retrieveGxsMsgMetaData(const GxsMsgReq& reqIds, GxsMsgMetaRes
|
|||
if (c)
|
||||
{
|
||||
locked_retrieveMsgMeta(c, metaSet);
|
||||
#ifdef RS_DATA_SERVICE_DEBUG_CACHE
|
||||
std::cerr << "Retrieving (all) Msg metadata grpId=" << grpId << ", " << std::dec << metaSet.size() << " messages" << std::endl;
|
||||
#endif
|
||||
}
|
||||
}else{
|
||||
|
||||
|
@ -1245,6 +1264,9 @@ int RsDataService::retrieveGxsMsgMetaData(const GxsMsgReq& reqIds, GxsMsgMetaRes
|
|||
if (c)
|
||||
{
|
||||
locked_retrieveMsgMeta(c, metaSet);
|
||||
#ifdef RS_DATA_SERVICE_DEBUG_CACHE
|
||||
std::cerr << "Retrieving Msg metadata grpId=" << grpId << ", " << std::dec << metaSet.size() << " messages" << std::endl;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1296,11 +1318,21 @@ int RsDataService::retrieveGxsGrpMetaData(std::map<RsGxsGroupId, RsGxsGrpMetaDat
|
|||
int requestedGroups = grp.size();
|
||||
#endif
|
||||
|
||||
if(grp.empty()){
|
||||
if(grp.empty())
|
||||
{
|
||||
if(mGrpMetaDataCache_ContainsAllDatabase) // grab all the stash from the cache, so as to avoid decryption costs.
|
||||
{
|
||||
#ifdef RS_DATA_SERVICE_DEBUG_CACHE
|
||||
std::cerr << (void*)this << ": RsDataService::retrieveGxsGrpMetaData() retrieving all from cache!" << std::endl;
|
||||
#endif
|
||||
|
||||
for(std::map<RsGxsGroupId,RsGxsGrpMetaData>::const_iterator it(mGrpMetaDataCache.begin());it!=mGrpMetaDataCache.end();++it)
|
||||
grp[it->first] = new RsGxsGrpMetaData(it->second);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef RS_DATA_SERVICE_DEBUG
|
||||
std::cerr << "RsDataService::retrieveGxsGrpMetaData() retrieving all";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "RsDataService::retrieveGxsGrpMetaData() retrieving all" << std::endl;
|
||||
#endif
|
||||
|
||||
RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, mGrpMetaColumns, "", "");
|
||||
|
@ -1315,6 +1347,10 @@ int RsDataService::retrieveGxsGrpMetaData(std::map<RsGxsGroupId, RsGxsGrpMetaDat
|
|||
if(g)
|
||||
{
|
||||
grp[g->mGroupId] = g;
|
||||
mGrpMetaDataCache[g->mGroupId] = *g ;
|
||||
#ifdef RS_DATA_SERVICE_DEBUG_CACHE
|
||||
std::cerr << (void *)this << ": Retrieving (all) Grp metadata grpId=" << g->mGroupId << std::endl;
|
||||
#endif
|
||||
}
|
||||
valid = c->moveToNext();
|
||||
|
||||
|
@ -1325,12 +1361,29 @@ int RsDataService::retrieveGxsGrpMetaData(std::map<RsGxsGroupId, RsGxsGrpMetaDat
|
|||
delete c;
|
||||
}
|
||||
|
||||
mGrpMetaDataCache_ContainsAllDatabase = true ;
|
||||
}
|
||||
|
||||
}else
|
||||
{
|
||||
std::map<RsGxsGroupId, RsGxsGrpMetaData *>::iterator mit = grp.begin();
|
||||
|
||||
for(; mit != grp.end(); ++mit)
|
||||
{
|
||||
std::map<RsGxsGroupId, RsGxsGrpMetaData>::const_iterator itt = mGrpMetaDataCache.find(mit->first) ;
|
||||
if(itt != mGrpMetaDataCache.end())
|
||||
{
|
||||
#ifdef RS_DATA_SERVICE_DEBUG_CACHE
|
||||
std::cerr << "Retrieving Grp metadata grpId=" << mit->first << " from cache!" << std::endl;
|
||||
#endif
|
||||
grp[mit->first] = new RsGxsGrpMetaData(itt->second) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef RS_DATA_SERVICE_DEBUG_CACHE
|
||||
std::cerr << "Retrieving Grp metadata grpId=" << mit->first ;
|
||||
#endif
|
||||
|
||||
const RsGxsGroupId& grpId = mit->first;
|
||||
RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, mGrpMetaColumns, "grpId='" + grpId.toStdString() + "'", "");
|
||||
|
||||
|
@ -1338,6 +1391,10 @@ int RsDataService::retrieveGxsGrpMetaData(std::map<RsGxsGroupId, RsGxsGrpMetaDat
|
|||
{
|
||||
bool valid = c->moveToFirst();
|
||||
|
||||
#ifdef RS_DATA_SERVICE_DEBUG_CACHE
|
||||
if(!valid)
|
||||
std::cerr << " Empty query! GrpId " << grpId << " is not in database" << std::endl;
|
||||
#endif
|
||||
while(valid)
|
||||
{
|
||||
RsGxsGrpMetaData* g = locked_getGrpMeta(*c, 0);
|
||||
|
@ -1345,6 +1402,10 @@ int RsDataService::retrieveGxsGrpMetaData(std::map<RsGxsGroupId, RsGxsGrpMetaDat
|
|||
if(g)
|
||||
{
|
||||
grp[g->mGroupId] = g;
|
||||
mGrpMetaDataCache[g->mGroupId] = *g ;
|
||||
#ifdef RS_DATA_SERVICE_DEBUG_CACHE
|
||||
std::cerr << ". Got it. Updating cache." << std::endl;
|
||||
#endif
|
||||
}
|
||||
valid = c->moveToNext();
|
||||
|
||||
|
@ -1354,7 +1415,11 @@ int RsDataService::retrieveGxsGrpMetaData(std::map<RsGxsGroupId, RsGxsGrpMetaDat
|
|||
}
|
||||
delete c;
|
||||
}
|
||||
|
||||
#ifdef RS_DATA_SERVICE_DEBUG_CACHE
|
||||
else
|
||||
std::cerr << ". not found!" << std::endl;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1391,13 +1456,28 @@ int RsDataService::resetDataStore()
|
|||
|
||||
int RsDataService::updateGroupMetaData(GrpLocMetaData &meta)
|
||||
{
|
||||
RsStackMutex stack(mDbMutex);
|
||||
#ifdef RS_DATA_SERVICE_DEBUG_CACHE
|
||||
std::cerr << (void*)this << ": Updating Grp Meta data: grpId = " << meta.grpId << std::endl;
|
||||
#endif
|
||||
|
||||
RsStackMutex stack(mDbMutex);
|
||||
RsGxsGroupId& grpId = meta.grpId;
|
||||
|
||||
#ifdef RS_DATA_SERVICE_DEBUG_CACHE
|
||||
std::cerr << (void*)this << ": erasing old entry from cache." << std::endl;
|
||||
#endif
|
||||
|
||||
locked_clearGrpMetaCache(meta.grpId);
|
||||
|
||||
return mDb->sqlUpdate(GRP_TABLE_NAME, KEY_GRP_ID+ "='" + grpId.toStdString() + "'", meta.val) ? 1 : 0;
|
||||
}
|
||||
|
||||
int RsDataService::updateMessageMetaData(MsgLocMetaData &metaData)
|
||||
{
|
||||
#ifdef RS_DATA_SERVICE_DEBUG_CACHE
|
||||
std::cerr << (void*)this << ": Updating Msg Meta data: grpId = " << metaData.msgId.first << " msgId = " << metaData.msgId.second << std::endl;
|
||||
#endif
|
||||
|
||||
RsStackMutex stack(mDbMutex);
|
||||
RsGxsGroupId& grpId = metaData.msgId.first;
|
||||
RsGxsMessageId& msgId = metaData.msgId.second;
|
||||
|
|
|
@ -340,6 +340,15 @@ private:
|
|||
uint16_t mServType;
|
||||
|
||||
RetroDb* mDb;
|
||||
|
||||
// used to store metadata instead of reading it from the database.
|
||||
// The boolean variable below is also used to force re-reading when
|
||||
// the entre list of grp metadata is requested (which happens quite often)
|
||||
|
||||
void locked_clearGrpMetaCache(const RsGxsGroupId& gid);
|
||||
|
||||
std::map<RsGxsGroupId,RsGxsGrpMetaData> mGrpMetaDataCache ;
|
||||
bool mGrpMetaDataCache_ContainsAllDatabase ;
|
||||
};
|
||||
|
||||
#endif // RSDATASERVICE_H
|
||||
|
|
|
@ -881,8 +881,15 @@ int RsGenExchange::validateMsg(RsNxsMsg *msg, const uint32_t& grpFlag, const uin
|
|||
{
|
||||
|
||||
// now check reputation of the message author
|
||||
float reputation_threshold = ( (signFlag & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_GPG) && !(details.mFlags & RS_IDENTITY_FLAGS_PGP_LINKED)) ? (RsReputations::REPUTATION_THRESHOLD_ANTI_SPAM): (RsReputations::REPUTATION_THRESHOLD_DEFAULT) ;
|
||||
|
||||
float reputation_threshold = RsReputations::REPUTATION_THRESHOLD_DEFAULT;
|
||||
|
||||
if( (signFlag & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_GPG_KNOWN) && !(details.mFlags & RS_IDENTITY_FLAGS_PGP_KNOWN))
|
||||
reputation_threshold = RsReputations::REPUTATION_THRESHOLD_ANTI_SPAM;
|
||||
else if( (signFlag & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_GPG) && !(details.mFlags & RS_IDENTITY_FLAGS_PGP_LINKED))
|
||||
reputation_threshold = RsReputations::REPUTATION_THRESHOLD_ANTI_SPAM;
|
||||
else
|
||||
reputation_threshold = RsReputations::REPUTATION_THRESHOLD_DEFAULT;
|
||||
|
||||
if(details.mReputation.mOverallReputationScore < reputation_threshold)
|
||||
{
|
||||
#ifdef GEN_EXCH_DEBUG
|
||||
|
@ -2004,10 +2011,7 @@ void RsGenExchange::publishMsgs()
|
|||
|
||||
// FIXTESTS global variable rsPeers not available in unittests!
|
||||
if(rsPeers)
|
||||
{
|
||||
mRoutingClues[msg->metaData->mAuthorId].insert(rsPeers->getOwnId()) ;
|
||||
mTrackingClues.push_back(std::make_pair(msg->msgId,rsPeers->getOwnId())) ;
|
||||
}
|
||||
|
||||
computeHash(msg->msg, msg->metaData->mHash);
|
||||
mDataAccess->addMsgData(msg);
|
||||
|
@ -2015,6 +2019,9 @@ void RsGenExchange::publishMsgs()
|
|||
|
||||
delete[] metaDataBuff;
|
||||
|
||||
if(mNetService != NULL)
|
||||
mNetService->stampMsgServerUpdateTS(grpId) ;
|
||||
|
||||
// add to published to allow acknowledgement
|
||||
mMsgNotify.insert(std::make_pair(mit->first, std::make_pair(grpId, msgId)));
|
||||
mDataAccess->updatePublicRequestStatus(mit->first, RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE);
|
||||
|
@ -2152,11 +2159,6 @@ void RsGenExchange::processRoutingClues()
|
|||
rsGRouter->addRoutingClue(GRouterKeyId(it->first),(*it2) ) ;
|
||||
|
||||
mRoutingClues.clear() ;
|
||||
|
||||
for(std::list<std::pair<RsGxsMessageId,RsPeerId> >::const_iterator it = mTrackingClues.begin();it!=mTrackingClues.end();++it)
|
||||
rsGRouter->addTrackingInfo((*it).first,(*it).second) ;
|
||||
|
||||
mTrackingClues.clear() ;
|
||||
}
|
||||
|
||||
void RsGenExchange::processGroupDelete()
|
||||
|
@ -2285,231 +2287,240 @@ bool RsGenExchange::checkKeys(const RsTlvSecurityKeySet& keySet)
|
|||
|
||||
void RsGenExchange::publishGrps()
|
||||
{
|
||||
RS_STACK_MUTEX(mGenMtx) ;
|
||||
NxsGrpSignPendVect::iterator vit = mGrpsToPublish.begin();
|
||||
|
||||
typedef std::pair<bool, RsGxsGroupId> GrpNote;
|
||||
std::map<uint32_t, GrpNote> toNotify;
|
||||
|
||||
while( vit != mGrpsToPublish.end() )
|
||||
std::list<RsGxsGroupId> groups_to_subscribe ;
|
||||
|
||||
{
|
||||
GxsGrpPendingSign& ggps = *vit;
|
||||
RS_STACK_MUTEX(mGenMtx) ;
|
||||
NxsGrpSignPendVect::iterator vit = mGrpsToPublish.begin();
|
||||
|
||||
/* do intial checks to see if this entry has expired */
|
||||
time_t now = time(NULL) ;
|
||||
uint32_t token = ggps.mToken;
|
||||
typedef std::pair<bool, RsGxsGroupId> GrpNote;
|
||||
std::map<uint32_t, GrpNote> toNotify;
|
||||
|
||||
while( vit != mGrpsToPublish.end() )
|
||||
{
|
||||
GxsGrpPendingSign& ggps = *vit;
|
||||
|
||||
/* do intial checks to see if this entry has expired */
|
||||
time_t now = time(NULL) ;
|
||||
uint32_t token = ggps.mToken;
|
||||
|
||||
|
||||
if(now > (ggps.mStartTS + PENDING_SIGN_TIMEOUT) )
|
||||
{
|
||||
// timed out
|
||||
toNotify.insert(std::make_pair(
|
||||
token, GrpNote(false, RsGxsGroupId())));
|
||||
delete ggps.mItem;
|
||||
vit = mGrpsToPublish.erase(vit);
|
||||
if(now > (ggps.mStartTS + PENDING_SIGN_TIMEOUT) )
|
||||
{
|
||||
// timed out
|
||||
toNotify.insert(std::make_pair(
|
||||
token, GrpNote(false, RsGxsGroupId())));
|
||||
delete ggps.mItem;
|
||||
vit = mGrpsToPublish.erase(vit);
|
||||
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
RsGxsGroupId grpId;
|
||||
RsNxsGrp* grp = new RsNxsGrp(mServType);
|
||||
RsGxsGrpItem* grpItem = ggps.mItem;
|
||||
RsGxsGroupId grpId;
|
||||
RsNxsGrp* grp = new RsNxsGrp(mServType);
|
||||
RsGxsGrpItem* grpItem = ggps.mItem;
|
||||
|
||||
RsTlvSecurityKeySet fullKeySet;
|
||||
RsTlvSecurityKeySet fullKeySet;
|
||||
|
||||
if(!(ggps.mHaveKeys))
|
||||
{
|
||||
generateGroupKeys(fullKeySet, true);
|
||||
ggps.mHaveKeys = true;
|
||||
ggps.mKeys = fullKeySet;
|
||||
}
|
||||
else
|
||||
fullKeySet = ggps.mKeys;
|
||||
if(!(ggps.mHaveKeys))
|
||||
{
|
||||
generateGroupKeys(fullKeySet, true);
|
||||
ggps.mHaveKeys = true;
|
||||
ggps.mKeys = fullKeySet;
|
||||
}
|
||||
else
|
||||
fullKeySet = ggps.mKeys;
|
||||
|
||||
// find private admin key
|
||||
RsTlvPrivateRSAKey privAdminKey;
|
||||
bool privKeyFound = false;
|
||||
for(std::map<RsGxsId, RsTlvPrivateRSAKey>::iterator mit_keys = fullKeySet.private_keys.begin(); mit_keys != fullKeySet.private_keys.end(); ++mit_keys)
|
||||
{
|
||||
RsTlvPrivateRSAKey& key = mit_keys->second;
|
||||
// find private admin key
|
||||
RsTlvPrivateRSAKey privAdminKey;
|
||||
bool privKeyFound = false;
|
||||
for(std::map<RsGxsId, RsTlvPrivateRSAKey>::iterator mit_keys = fullKeySet.private_keys.begin(); mit_keys != fullKeySet.private_keys.end(); ++mit_keys)
|
||||
{
|
||||
RsTlvPrivateRSAKey& key = mit_keys->second;
|
||||
|
||||
if(key.keyFlags == (RSTLV_KEY_DISTRIB_ADMIN | RSTLV_KEY_TYPE_FULL))
|
||||
{
|
||||
privAdminKey = key;
|
||||
privKeyFound = true;
|
||||
}
|
||||
}
|
||||
if(key.keyFlags == (RSTLV_KEY_DISTRIB_ADMIN | RSTLV_KEY_TYPE_FULL))
|
||||
{
|
||||
privAdminKey = key;
|
||||
privKeyFound = true;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t create = CREATE_FAIL;
|
||||
uint8_t create = CREATE_FAIL;
|
||||
|
||||
if(privKeyFound)
|
||||
{
|
||||
// get group id from private admin key id
|
||||
grpItem->meta.mGroupId = grp->grpId = RsGxsGroupId(privAdminKey.keyId);
|
||||
if(privKeyFound)
|
||||
{
|
||||
// get group id from private admin key id
|
||||
grpItem->meta.mGroupId = grp->grpId = RsGxsGroupId(privAdminKey.keyId);
|
||||
|
||||
ServiceCreate_Return ret = service_CreateGroup(grpItem, fullKeySet);
|
||||
ServiceCreate_Return ret = service_CreateGroup(grpItem, fullKeySet);
|
||||
|
||||
bool serialOk = false, servCreateOk;
|
||||
bool serialOk = false, servCreateOk;
|
||||
|
||||
if(ret == SERVICE_CREATE_SUCCESS)
|
||||
{
|
||||
uint32_t size = mSerialiser->size(grpItem);
|
||||
char *gData = new char[size];
|
||||
serialOk = mSerialiser->serialise(grpItem, gData, &size);
|
||||
grp->grp.setBinData(gData, size);
|
||||
delete[] gData;
|
||||
servCreateOk = true;
|
||||
if(ret == SERVICE_CREATE_SUCCESS)
|
||||
{
|
||||
uint32_t size = mSerialiser->size(grpItem);
|
||||
char *gData = new char[size];
|
||||
serialOk = mSerialiser->serialise(grpItem, gData, &size);
|
||||
grp->grp.setBinData(gData, size);
|
||||
delete[] gData;
|
||||
servCreateOk = true;
|
||||
|
||||
}else
|
||||
{
|
||||
servCreateOk = false;
|
||||
}
|
||||
}else
|
||||
{
|
||||
servCreateOk = false;
|
||||
}
|
||||
|
||||
if(serialOk && servCreateOk)
|
||||
{
|
||||
grp->metaData = new RsGxsGrpMetaData();
|
||||
grpItem->meta.mPublishTs = time(NULL);
|
||||
*(grp->metaData) = grpItem->meta;
|
||||
if(serialOk && servCreateOk)
|
||||
{
|
||||
grp->metaData = new RsGxsGrpMetaData();
|
||||
grpItem->meta.mPublishTs = time(NULL);
|
||||
*(grp->metaData) = grpItem->meta;
|
||||
|
||||
// TODO: change when publish key optimisation added (public groups don't have publish key
|
||||
grp->metaData->mSubscribeFlags = GXS_SERV::GROUP_SUBSCRIBE_ADMIN | GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED
|
||||
| GXS_SERV::GROUP_SUBSCRIBE_PUBLISH;
|
||||
// TODO: change when publish key optimisation added (public groups don't have publish key
|
||||
grp->metaData->mSubscribeFlags = GXS_SERV::GROUP_SUBSCRIBE_ADMIN | GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED
|
||||
| GXS_SERV::GROUP_SUBSCRIBE_PUBLISH;
|
||||
|
||||
create = createGroup(grp, fullKeySet);
|
||||
create = createGroup(grp, fullKeySet);
|
||||
|
||||
#ifdef GEN_EXCH_DEBUG
|
||||
std::cerr << "RsGenExchange::publishGrps() ";
|
||||
std::cerr << " GrpId: " << grp->grpId;
|
||||
std::cerr << " CircleType: " << (uint32_t) grp->metaData->mCircleType;
|
||||
std::cerr << " CircleId: " << grp->metaData->mCircleId.toStdString();
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "RsGenExchange::publishGrps() ";
|
||||
std::cerr << " GrpId: " << grp->grpId;
|
||||
std::cerr << " CircleType: " << (uint32_t) grp->metaData->mCircleType;
|
||||
std::cerr << " CircleId: " << grp->metaData->mCircleId.toStdString();
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
if(create == CREATE_SUCCESS)
|
||||
{
|
||||
// Here we need to make sure that no private keys are included. This is very important since private keys
|
||||
// can be used to modify the group. Normally the private key set is whiped out by createGroup, but
|
||||
if(create == CREATE_SUCCESS)
|
||||
{
|
||||
// Here we need to make sure that no private keys are included. This is very important since private keys
|
||||
// can be used to modify the group. Normally the private key set is whiped out by createGroup, but
|
||||
|
||||
grp->metaData->keys.private_keys.clear() ;
|
||||
|
||||
uint32_t mdSize = grp->metaData->serial_size(RS_GXS_GRP_META_DATA_CURRENT_API_VERSION);
|
||||
|
||||
{
|
||||
RsTemporaryMemory metaData(mdSize);
|
||||
serialOk = grp->metaData->serialise(metaData, mdSize,RS_GXS_GRP_META_DATA_CURRENT_API_VERSION);
|
||||
grp->metaData->keys.private_keys.clear() ;
|
||||
|
||||
uint32_t mdSize = grp->metaData->serial_size(RS_GXS_GRP_META_DATA_CURRENT_API_VERSION);
|
||||
|
||||
{
|
||||
RsTemporaryMemory metaData(mdSize);
|
||||
serialOk = grp->metaData->serialise(metaData, mdSize,RS_GXS_GRP_META_DATA_CURRENT_API_VERSION);
|
||||
#warning TODO: grp->meta should be renamed grp->public_meta !
|
||||
grp->meta.setBinData(metaData, mdSize);
|
||||
}
|
||||
grp->meta.setBinData(metaData, mdSize);
|
||||
}
|
||||
|
||||
// Place back private keys for publisher and database storage
|
||||
grp->metaData->keys.private_keys = fullKeySet.private_keys;
|
||||
// Place back private keys for publisher and database storage
|
||||
grp->metaData->keys.private_keys = fullKeySet.private_keys;
|
||||
|
||||
if(mDataStore->validSize(grp) && serialOk)
|
||||
{
|
||||
grpId = grp->grpId;
|
||||
computeHash(grp->grp, grp->metaData->mHash);
|
||||
grp->metaData->mRecvTS = time(NULL);
|
||||
if(mDataStore->validSize(grp) && serialOk)
|
||||
{
|
||||
grpId = grp->grpId;
|
||||
computeHash(grp->grp, grp->metaData->mHash);
|
||||
grp->metaData->mRecvTS = time(NULL);
|
||||
|
||||
if(ggps.mIsUpdate)
|
||||
mDataAccess->updateGroupData(grp);
|
||||
else
|
||||
mDataAccess->addGroupData(grp);
|
||||
if(ggps.mIsUpdate)
|
||||
mDataAccess->updateGroupData(grp);
|
||||
else
|
||||
mDataAccess->addGroupData(grp);
|
||||
#warning this is bad: addGroupData/updateGroupData actially deletes grp. But it may be used below? grp should be a class object and not deleted manually!
|
||||
if(mNetService!=NULL)
|
||||
mNetService->subscribeStatusChanged(grpId,true) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
create = CREATE_FAIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(ret == SERVICE_CREATE_FAIL_TRY_LATER)
|
||||
{
|
||||
// if the service is not ready yet, reset the start timestamp to give the service more time
|
||||
// the service should have it's own timeout mechanism
|
||||
// services should return SERVICE_CREATE_FAIL if the action timed out
|
||||
// at the moment this is only important for the idservice:
|
||||
// the idservice may ask the user for a password, and the user needs time
|
||||
ggps.mStartTS = now;
|
||||
create = CREATE_FAIL_TRY_LATER;
|
||||
}
|
||||
else if(ret == SERVICE_CREATE_FAIL)
|
||||
create = CREATE_FAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef GEN_EXCH_DEBUG
|
||||
std::cerr << "RsGenExchange::publishGrps() Could not find private publish keys " << std::endl;
|
||||
#endif
|
||||
create = CREATE_FAIL;
|
||||
}
|
||||
|
||||
if(create == CREATE_FAIL)
|
||||
{
|
||||
groups_to_subscribe.push_back(grpId) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
create = CREATE_FAIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(ret == SERVICE_CREATE_FAIL_TRY_LATER)
|
||||
{
|
||||
// if the service is not ready yet, reset the start timestamp to give the service more time
|
||||
// the service should have it's own timeout mechanism
|
||||
// services should return SERVICE_CREATE_FAIL if the action timed out
|
||||
// at the moment this is only important for the idservice:
|
||||
// the idservice may ask the user for a password, and the user needs time
|
||||
ggps.mStartTS = now;
|
||||
create = CREATE_FAIL_TRY_LATER;
|
||||
}
|
||||
else if(ret == SERVICE_CREATE_FAIL)
|
||||
create = CREATE_FAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef GEN_EXCH_DEBUG
|
||||
std::cerr << "RsGenExchange::publishGrps() failed to publish grp " << std::endl;
|
||||
std::cerr << "RsGenExchange::publishGrps() Could not find private publish keys " << std::endl;
|
||||
#endif
|
||||
delete grp;
|
||||
delete grpItem;
|
||||
vit = mGrpsToPublish.erase(vit);
|
||||
toNotify.insert(std::make_pair(
|
||||
token, GrpNote(false, grpId)));
|
||||
create = CREATE_FAIL;
|
||||
}
|
||||
|
||||
}
|
||||
else if(create == CREATE_FAIL_TRY_LATER)
|
||||
{
|
||||
if(create == CREATE_FAIL)
|
||||
{
|
||||
#ifdef GEN_EXCH_DEBUG
|
||||
std::cerr << "RsGenExchange::publishGrps() failed grp, trying again " << std::endl;
|
||||
std::cerr << "RsGenExchange::publishGrps() failed to publish grp " << std::endl;
|
||||
#endif
|
||||
delete grp;
|
||||
ggps.mLastAttemptTS = time(NULL);
|
||||
++vit;
|
||||
}
|
||||
else if(create == CREATE_SUCCESS)
|
||||
{
|
||||
delete grpItem;
|
||||
vit = mGrpsToPublish.erase(vit);
|
||||
delete grp;
|
||||
delete grpItem;
|
||||
vit = mGrpsToPublish.erase(vit);
|
||||
toNotify.insert(std::make_pair(
|
||||
token, GrpNote(false, grpId)));
|
||||
|
||||
}
|
||||
else if(create == CREATE_FAIL_TRY_LATER)
|
||||
{
|
||||
#ifdef GEN_EXCH_DEBUG
|
||||
std::cerr << "RsGenExchange::publishGrps() failed grp, trying again " << std::endl;
|
||||
#endif
|
||||
delete grp;
|
||||
ggps.mLastAttemptTS = time(NULL);
|
||||
++vit;
|
||||
}
|
||||
else if(create == CREATE_SUCCESS)
|
||||
{
|
||||
delete grpItem;
|
||||
vit = mGrpsToPublish.erase(vit);
|
||||
|
||||
#ifdef GEN_EXCH_DEBUG
|
||||
std::cerr << "RsGenExchange::publishGrps() ok -> pushing to notifies"
|
||||
<< std::endl;
|
||||
std::cerr << "RsGenExchange::publishGrps() ok -> pushing to notifies"
|
||||
<< std::endl;
|
||||
#endif
|
||||
|
||||
// add to published to allow acknowledgement
|
||||
toNotify.insert(std::make_pair(token,
|
||||
GrpNote(true,grpId)));
|
||||
}
|
||||
}
|
||||
|
||||
std::map<uint32_t, GrpNote>::iterator mit = toNotify.begin();
|
||||
|
||||
std::list<RsGxsGroupId> grpChanged;
|
||||
for(; mit != toNotify.end(); ++mit)
|
||||
{
|
||||
GrpNote& note = mit->second;
|
||||
uint8_t status = note.first ? RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE
|
||||
: RsTokenService::GXS_REQUEST_V2_STATUS_FAILED;
|
||||
|
||||
mGrpNotify.insert(std::make_pair(mit->first, note.second));
|
||||
mDataAccess->updatePublicRequestStatus(mit->first, status);
|
||||
|
||||
if(note.first)
|
||||
grpChanged.push_back(note.second);
|
||||
}
|
||||
|
||||
if(!grpChanged.empty())
|
||||
{
|
||||
RsGxsGroupChange* gc = new RsGxsGroupChange(RsGxsNotify::TYPE_PUBLISH, false);
|
||||
gc->mGrpIdList = grpChanged;
|
||||
mNotifications.push_back(gc);
|
||||
#ifdef GEN_EXCH_DEBUG
|
||||
std::cerr << " adding the following grp ids to notification: " << std::endl;
|
||||
for(std::list<RsGxsGroupId>::const_iterator it(grpChanged.begin());it!=grpChanged.end();++it)
|
||||
std::cerr << " " << *it << std::endl;
|
||||
#endif
|
||||
// add to published to allow acknowledgement
|
||||
toNotify.insert(std::make_pair(token,
|
||||
GrpNote(true,grpId)));
|
||||
}
|
||||
}
|
||||
|
||||
std::map<uint32_t, GrpNote>::iterator mit = toNotify.begin();
|
||||
|
||||
std::list<RsGxsGroupId> grpChanged;
|
||||
for(; mit != toNotify.end(); ++mit)
|
||||
{
|
||||
GrpNote& note = mit->second;
|
||||
uint8_t status = note.first ? RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE
|
||||
: RsTokenService::GXS_REQUEST_V2_STATUS_FAILED;
|
||||
|
||||
mGrpNotify.insert(std::make_pair(mit->first, note.second));
|
||||
mDataAccess->updatePublicRequestStatus(mit->first, status);
|
||||
|
||||
if(note.first)
|
||||
grpChanged.push_back(note.second);
|
||||
}
|
||||
|
||||
if(!grpChanged.empty())
|
||||
{
|
||||
RsGxsGroupChange* gc = new RsGxsGroupChange(RsGxsNotify::TYPE_PUBLISH, false);
|
||||
gc->mGrpIdList = grpChanged;
|
||||
mNotifications.push_back(gc);
|
||||
#ifdef GEN_EXCH_DEBUG
|
||||
std::cerr << " adding the following grp ids to notification: " << std::endl;
|
||||
for(std::list<RsGxsGroupId>::const_iterator it(grpChanged.begin());it!=grpChanged.end();++it)
|
||||
std::cerr << " " << *it << std::endl;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
// This is done off-mutex to avoid possible cross deadlocks with the net service.
|
||||
|
||||
if(mNetService!=NULL)
|
||||
for(std::list<RsGxsGroupId>::const_iterator it(groups_to_subscribe.begin());it!=groups_to_subscribe.end();++it)
|
||||
mNetService->subscribeStatusChanged((*it),true) ;
|
||||
}
|
||||
|
||||
|
||||
|
@ -2590,228 +2601,243 @@ void RsGenExchange::computeHash(const RsTlvBinaryData& data, RsFileHash& hash)
|
|||
|
||||
void RsGenExchange::processRecvdMessages()
|
||||
{
|
||||
RS_STACK_MUTEX(mGenMtx) ;
|
||||
std::list<RsGxsMessageId> messages_to_reject ;
|
||||
|
||||
{
|
||||
RS_STACK_MUTEX(mGenMtx) ;
|
||||
|
||||
#ifdef GEN_EXCH_DEBUG
|
||||
if(!mMsgPendingValidate.empty())
|
||||
std::cerr << "processing received messages" << std::endl;
|
||||
if(!mMsgPendingValidate.empty())
|
||||
std::cerr << "processing received messages" << std::endl;
|
||||
#endif
|
||||
NxsMsgPendingVect::iterator pend_it = mMsgPendingValidate.begin();
|
||||
NxsMsgPendingVect::iterator pend_it = mMsgPendingValidate.begin();
|
||||
|
||||
#ifdef GEN_EXCH_DEBUG
|
||||
if(!mMsgPendingValidate.empty())
|
||||
std::cerr << " pending validation" << std::endl;
|
||||
if(!mMsgPendingValidate.empty())
|
||||
std::cerr << " pending validation" << std::endl;
|
||||
#endif
|
||||
for(; pend_it != mMsgPendingValidate.end();)
|
||||
{
|
||||
GxsPendingItem<RsNxsMsg*, RsGxsGrpMsgIdPair>& gpsi = *pend_it;
|
||||
for(; pend_it != mMsgPendingValidate.end();)
|
||||
{
|
||||
GxsPendingItem<RsNxsMsg*, RsGxsGrpMsgIdPair>& gpsi = *pend_it;
|
||||
|
||||
#ifdef GEN_EXCH_DEBUG
|
||||
std::cerr << " grp=" << gpsi.mId.first << ", msg=" << gpsi.mId.second << ", attempts=" << gpsi.mAttempts ;
|
||||
std::cerr << " grp=" << gpsi.mId.first << ", msg=" << gpsi.mId.second << ", attempts=" << gpsi.mAttempts ;
|
||||
#endif
|
||||
if(gpsi.mAttempts == VALIDATE_MAX_ATTEMPTS)
|
||||
{
|
||||
if(gpsi.mAttempts == VALIDATE_MAX_ATTEMPTS)
|
||||
{
|
||||
#ifdef GEN_EXCH_DEBUG
|
||||
std::cerr << " = max! deleting." << std::endl;
|
||||
std::cerr << " = max! deleting." << std::endl;
|
||||
#endif
|
||||
delete gpsi.mItem;
|
||||
pend_it = mMsgPendingValidate.erase(pend_it);
|
||||
}
|
||||
else
|
||||
{
|
||||
delete gpsi.mItem;
|
||||
pend_it = mMsgPendingValidate.erase(pend_it);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef GEN_EXCH_DEBUG
|
||||
std::cerr << " movign to recvd." << std::endl;
|
||||
std::cerr << " movign to recvd." << std::endl;
|
||||
#endif
|
||||
mReceivedMsgs.push_back(gpsi.mItem);
|
||||
++pend_it;
|
||||
}
|
||||
}
|
||||
mReceivedMsgs.push_back(gpsi.mItem);
|
||||
++pend_it;
|
||||
}
|
||||
}
|
||||
|
||||
if(mReceivedMsgs.empty())
|
||||
return;
|
||||
if(mReceivedMsgs.empty())
|
||||
return;
|
||||
|
||||
std::vector<RsNxsMsg*>::iterator vit = mReceivedMsgs.begin();
|
||||
GxsMsgReq msgIds;
|
||||
std::map<RsNxsMsg*, RsGxsMsgMetaData*> msgs;
|
||||
std::vector<RsNxsMsg*>::iterator vit = mReceivedMsgs.begin();
|
||||
GxsMsgReq msgIds;
|
||||
std::map<RsNxsMsg*, RsGxsMsgMetaData*> msgs;
|
||||
|
||||
std::map<RsGxsGroupId, RsGxsGrpMetaData*> grpMetas;
|
||||
std::map<RsGxsGroupId, RsGxsGrpMetaData*> grpMetas;
|
||||
|
||||
// coalesce group meta retrieval for performance
|
||||
for(; vit != mReceivedMsgs.end(); ++vit)
|
||||
{
|
||||
RsNxsMsg* msg = *vit;
|
||||
grpMetas.insert(std::make_pair(msg->grpId, (RsGxsGrpMetaData*)NULL));
|
||||
}
|
||||
// coalesce group meta retrieval for performance
|
||||
for(; vit != mReceivedMsgs.end(); ++vit)
|
||||
{
|
||||
RsNxsMsg* msg = *vit;
|
||||
grpMetas.insert(std::make_pair(msg->grpId, (RsGxsGrpMetaData*)NULL));
|
||||
}
|
||||
|
||||
mDataStore->retrieveGxsGrpMetaData(grpMetas);
|
||||
mDataStore->retrieveGxsGrpMetaData(grpMetas);
|
||||
|
||||
#ifdef GEN_EXCH_DEBUG
|
||||
std::cerr << " updating received messages:" << std::endl;
|
||||
std::cerr << " updating received messages:" << std::endl;
|
||||
#endif
|
||||
for(vit = mReceivedMsgs.begin(); vit != mReceivedMsgs.end(); ++vit)
|
||||
{
|
||||
RsNxsMsg* msg = *vit;
|
||||
RsGxsMsgMetaData* meta = new RsGxsMsgMetaData();
|
||||
for(vit = mReceivedMsgs.begin(); vit != mReceivedMsgs.end(); ++vit)
|
||||
{
|
||||
RsNxsMsg* msg = *vit;
|
||||
RsGxsMsgMetaData* meta = new RsGxsMsgMetaData();
|
||||
|
||||
bool ok = false;
|
||||
bool ok = false;
|
||||
|
||||
if(msg->meta.bin_len != 0)
|
||||
ok = meta->deserialise(msg->meta.bin_data, &(msg->meta.bin_len));
|
||||
if(msg->meta.bin_len != 0)
|
||||
ok = meta->deserialise(msg->meta.bin_data, &(msg->meta.bin_len));
|
||||
|
||||
msg->metaData = meta;
|
||||
msg->metaData = meta;
|
||||
|
||||
#ifdef GEN_EXCH_DEBUG
|
||||
std::cerr << " deserialised info: grp id=" << meta->mGroupId << ", msg id=" << meta->mMsgId ;
|
||||
std::cerr << " deserialised info: grp id=" << meta->mGroupId << ", msg id=" << meta->mMsgId ;
|
||||
#endif
|
||||
uint8_t validateReturn = VALIDATE_FAIL;
|
||||
uint8_t validateReturn = VALIDATE_FAIL;
|
||||
|
||||
if(ok)
|
||||
{
|
||||
std::map<RsGxsGroupId, RsGxsGrpMetaData*>::iterator mit = grpMetas.find(msg->grpId);
|
||||
if(ok)
|
||||
{
|
||||
std::map<RsGxsGroupId, RsGxsGrpMetaData*>::iterator mit = grpMetas.find(msg->grpId);
|
||||
|
||||
#ifdef GEN_EXCH_DEBUG
|
||||
std::cerr << " msg info : grp id=" << msg->grpId << ", msg id=" << msg->msgId << std::endl;
|
||||
std::cerr << " msg info : grp id=" << msg->grpId << ", msg id=" << msg->msgId << std::endl;
|
||||
#endif
|
||||
RsGxsGrpMetaData* grpMeta = NULL ;
|
||||
RsGxsGrpMetaData* grpMeta = NULL ;
|
||||
|
||||
// validate msg
|
||||
if(mit != grpMetas.end())
|
||||
{
|
||||
grpMeta = mit->second;
|
||||
validateReturn = validateMsg(msg, grpMeta->mGroupFlags, grpMeta->mSignFlags, grpMeta->keys);
|
||||
// validate msg
|
||||
if(mit != grpMetas.end())
|
||||
{
|
||||
grpMeta = mit->second;
|
||||
validateReturn = validateMsg(msg, grpMeta->mGroupFlags, grpMeta->mSignFlags, grpMeta->keys);
|
||||
|
||||
#ifdef GEN_EXCH_DEBUG
|
||||
std::cerr << " grpMeta.mSignFlags: " << std::hex << grpMeta->mSignFlags << std::dec << std::endl;
|
||||
std::cerr << " grpMeta.mAuthFlags: " << std::hex << grpMeta->mAuthenFlags << std::dec << std::endl;
|
||||
std::cerr << " message validation result: " << (int)validateReturn << std::endl;
|
||||
std::cerr << " grpMeta.mSignFlags: " << std::hex << grpMeta->mSignFlags << std::dec << std::endl;
|
||||
std::cerr << " grpMeta.mAuthFlags: " << std::hex << grpMeta->mAuthenFlags << std::dec << std::endl;
|
||||
std::cerr << " message validation result: " << (int)validateReturn << std::endl;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if(validateReturn == VALIDATE_SUCCESS)
|
||||
{
|
||||
meta->mMsgStatus = GXS_SERV::GXS_MSG_STATUS_UNPROCESSED | GXS_SERV::GXS_MSG_STATUS_GUI_NEW | GXS_SERV::GXS_MSG_STATUS_GUI_UNREAD;
|
||||
msgs.insert(std::make_pair(msg, meta));
|
||||
if(validateReturn == VALIDATE_SUCCESS)
|
||||
{
|
||||
meta->mMsgStatus = GXS_SERV::GXS_MSG_STATUS_UNPROCESSED | GXS_SERV::GXS_MSG_STATUS_GUI_NEW | GXS_SERV::GXS_MSG_STATUS_GUI_UNREAD;
|
||||
msgs.insert(std::make_pair(msg, meta));
|
||||
|
||||
std::vector<RsGxsMessageId> &msgv = msgIds[msg->grpId];
|
||||
if (std::find(msgv.begin(), msgv.end(), msg->msgId) == msgv.end())
|
||||
{
|
||||
msgv.push_back(msg->msgId);
|
||||
}
|
||||
std::vector<RsGxsMessageId> &msgv = msgIds[msg->grpId];
|
||||
if (std::find(msgv.begin(), msgv.end(), msg->msgId) == msgv.end())
|
||||
{
|
||||
msgv.push_back(msg->msgId);
|
||||
}
|
||||
|
||||
NxsMsgPendingVect::iterator validated_entry = std::find(mMsgPendingValidate.begin(), mMsgPendingValidate.end(),
|
||||
getMsgIdPair(*msg));
|
||||
NxsMsgPendingVect::iterator validated_entry = std::find(mMsgPendingValidate.begin(), mMsgPendingValidate.end(),
|
||||
getMsgIdPair(*msg));
|
||||
|
||||
if(validated_entry != mMsgPendingValidate.end()) mMsgPendingValidate.erase(validated_entry);
|
||||
if(validated_entry != mMsgPendingValidate.end()) mMsgPendingValidate.erase(validated_entry);
|
||||
|
||||
computeHash(msg->msg, meta->mHash);
|
||||
meta->recvTS = time(NULL);
|
||||
computeHash(msg->msg, meta->mHash);
|
||||
meta->recvTS = time(NULL);
|
||||
#ifdef GEN_EXCH_DEBUG
|
||||
std::cerr << " new status flags: " << meta->mMsgStatus << std::endl;
|
||||
std::cerr << " computed hash: " << meta->mHash << std::endl;
|
||||
std::cerr << "Message received. Identity=" << msg->metaData->mAuthorId << ", from peer " << msg->PeerId() << std::endl;
|
||||
std::cerr << " new status flags: " << meta->mMsgStatus << std::endl;
|
||||
std::cerr << " computed hash: " << meta->mHash << std::endl;
|
||||
std::cerr << "Message received. Identity=" << msg->metaData->mAuthorId << ", from peer " << msg->PeerId() << std::endl;
|
||||
#endif
|
||||
|
||||
if(!msg->metaData->mAuthorId.isNull())
|
||||
mRoutingClues[msg->metaData->mAuthorId].insert(msg->PeerId()) ;
|
||||
if(!msg->metaData->mAuthorId.isNull())
|
||||
mRoutingClues[msg->metaData->mAuthorId].insert(msg->PeerId()) ;
|
||||
}
|
||||
|
||||
if(grpMeta->mSignFlags & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_TRACK_MESSAGES)
|
||||
mTrackingClues.push_back(std::make_pair(msg->msgId,msg->PeerId())) ;
|
||||
}
|
||||
|
||||
if(validateReturn == VALIDATE_FAIL)
|
||||
{
|
||||
// In this case, we notify the network exchange service not to DL the message again, at least not yet.
|
||||
|
||||
#ifdef GEN_EXCH_DEBUG
|
||||
std::cerr << "Notifying the network service to not download this message again." << std::endl;
|
||||
#endif
|
||||
mNetService->rejectMessage(msg->msgId) ;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef GEN_EXCH_DEBUG
|
||||
std::cerr << " deserialisation failed!" <<std::endl;
|
||||
#endif
|
||||
validateReturn = VALIDATE_FAIL;
|
||||
}
|
||||
|
||||
if(validateReturn == VALIDATE_FAIL)
|
||||
{
|
||||
if(validateReturn == VALIDATE_FAIL)
|
||||
{
|
||||
// In this case, we notify the network exchange service not to DL the message again, at least not yet.
|
||||
|
||||
#ifdef GEN_EXCH_DEBUG
|
||||
std::cerr << "Validation failed for message id "
|
||||
<< "msg->grpId: " << msg->grpId << ", msgId: " << msg->msgId << std::endl;
|
||||
std::cerr << "Notifying the network service to not download this message again." << std::endl;
|
||||
#endif
|
||||
messages_to_reject.push_back(msg->msgId) ;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef GEN_EXCH_DEBUG
|
||||
std::cerr << " deserialisation failed!" <<std::endl;
|
||||
#endif
|
||||
validateReturn = VALIDATE_FAIL;
|
||||
}
|
||||
|
||||
NxsMsgPendingVect::iterator failed_entry = std::find(mMsgPendingValidate.begin(), mMsgPendingValidate.end(),
|
||||
getMsgIdPair(*msg));
|
||||
|
||||
if(failed_entry != mMsgPendingValidate.end()) mMsgPendingValidate.erase(failed_entry);
|
||||
delete msg;
|
||||
|
||||
|
||||
}
|
||||
else if(validateReturn == VALIDATE_FAIL_TRY_LATER)
|
||||
{
|
||||
if(validateReturn == VALIDATE_FAIL)
|
||||
{
|
||||
|
||||
#ifdef GEN_EXCH_DEBUG
|
||||
std::cerr << "failed to validate msg, trying again: "
|
||||
<< "msg->grpId: " << msg->grpId << ", msgId: " << msg->msgId << std::endl;
|
||||
std::cerr << "Validation failed for message id "
|
||||
<< "msg->grpId: " << msg->grpId << ", msgId: " << msg->msgId << std::endl;
|
||||
#endif
|
||||
|
||||
RsGxsGrpMsgIdPair id;
|
||||
id.first = msg->grpId;
|
||||
id.second = msg->msgId;
|
||||
NxsMsgPendingVect::iterator failed_entry = std::find(mMsgPendingValidate.begin(), mMsgPendingValidate.end(),
|
||||
getMsgIdPair(*msg));
|
||||
|
||||
// first check you haven't made too many attempts
|
||||
if(failed_entry != mMsgPendingValidate.end()) mMsgPendingValidate.erase(failed_entry);
|
||||
delete msg;
|
||||
|
||||
NxsMsgPendingVect::iterator vit = std::find(
|
||||
mMsgPendingValidate.begin(), mMsgPendingValidate.end(), id);
|
||||
|
||||
if(vit == mMsgPendingValidate.end())
|
||||
{
|
||||
GxsPendingItem<RsNxsMsg*, RsGxsGrpMsgIdPair> item(msg, id);
|
||||
mMsgPendingValidate.push_back(item);
|
||||
}else
|
||||
{
|
||||
vit->mAttempts++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// clean up resources from group meta retrieval
|
||||
freeAndClearContainerResource<std::map<RsGxsGroupId, RsGxsGrpMetaData*>,
|
||||
RsGxsGrpMetaData*>(grpMetas);
|
||||
|
||||
if(!msgIds.empty())
|
||||
{
|
||||
#ifdef GEN_EXCH_DEBUG
|
||||
std::cerr << " removing existing and old messages from incoming list." << std::endl;
|
||||
#endif
|
||||
removeDeleteExistingMessages(msgs, msgIds);
|
||||
}
|
||||
else if(validateReturn == VALIDATE_FAIL_TRY_LATER)
|
||||
{
|
||||
|
||||
#ifdef GEN_EXCH_DEBUG
|
||||
std::cerr << " storing remaining messages" << std::endl;
|
||||
std::cerr << "failed to validate msg, trying again: "
|
||||
<< "msg->grpId: " << msg->grpId << ", msgId: " << msg->msgId << std::endl;
|
||||
#endif
|
||||
mDataStore->storeMessage(msgs);
|
||||
|
||||
RsGxsMsgChange* c = new RsGxsMsgChange(RsGxsNotify::TYPE_RECEIVE, false);
|
||||
c->msgChangeMap = msgIds;
|
||||
mNotifications.push_back(c);
|
||||
}
|
||||
RsGxsGrpMsgIdPair id;
|
||||
id.first = msg->grpId;
|
||||
id.second = msg->msgId;
|
||||
|
||||
mReceivedMsgs.clear();
|
||||
// first check you haven't made too many attempts
|
||||
|
||||
NxsMsgPendingVect::iterator vit = std::find(
|
||||
mMsgPendingValidate.begin(), mMsgPendingValidate.end(), id);
|
||||
|
||||
if(vit == mMsgPendingValidate.end())
|
||||
{
|
||||
GxsPendingItem<RsNxsMsg*, RsGxsGrpMsgIdPair> item(msg, id);
|
||||
mMsgPendingValidate.push_back(item);
|
||||
}else
|
||||
{
|
||||
vit->mAttempts++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// clean up resources from group meta retrieval
|
||||
freeAndClearContainerResource<std::map<RsGxsGroupId, RsGxsGrpMetaData*>,
|
||||
RsGxsGrpMetaData*>(grpMetas);
|
||||
|
||||
if(!msgIds.empty())
|
||||
{
|
||||
#ifdef GEN_EXCH_DEBUG
|
||||
std::cerr << " removing existing and old messages from incoming list." << std::endl;
|
||||
#endif
|
||||
removeDeleteExistingMessages(msgs, msgIds);
|
||||
|
||||
#ifdef GEN_EXCH_DEBUG
|
||||
std::cerr << " storing remaining messages" << std::endl;
|
||||
#endif
|
||||
mDataStore->storeMessage(msgs);
|
||||
|
||||
RsGxsMsgChange* c = new RsGxsMsgChange(RsGxsNotify::TYPE_RECEIVE, false);
|
||||
c->msgChangeMap = msgIds;
|
||||
mNotifications.push_back(c);
|
||||
}
|
||||
|
||||
mReceivedMsgs.clear();
|
||||
}
|
||||
|
||||
// Done off-mutex to avoid cross deadlocks in the netservice that might call the RsGenExchange as an observer..
|
||||
|
||||
if(mNetService != NULL)
|
||||
for(std::list<RsGxsMessageId>::const_iterator it(messages_to_reject.begin());it!=messages_to_reject.end();++it)
|
||||
mNetService->rejectMessage(*it) ;
|
||||
}
|
||||
|
||||
bool RsGenExchange::acceptNewGroup(const RsGxsGrpMetaData *grpMeta)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void RsGenExchange::processRecvdGroups()
|
||||
{
|
||||
RS_STACK_MUTEX(mGenMtx) ;
|
||||
RS_STACK_MUTEX(mGenMtx) ;
|
||||
|
||||
if(mReceivedGrps.empty())
|
||||
return;
|
||||
|
||||
NxsGrpPendValidVect::iterator vit = mReceivedGrps.begin();
|
||||
#ifdef GEN_EXCH_DEBUG
|
||||
std::cerr << "RsGenExchange::Processing received groups" << std::endl;
|
||||
#endif
|
||||
NxsGrpPendValidVect::iterator vit = mReceivedGrps.begin();
|
||||
std::vector<RsGxsGroupId> existingGrpIds;
|
||||
std::list<RsGxsGroupId> grpIds;
|
||||
|
||||
|
@ -2826,12 +2852,12 @@ void RsGenExchange::processRecvdGroups()
|
|||
RsGxsGrpMetaData* meta = new RsGxsGrpMetaData();
|
||||
bool deserialOk = false;
|
||||
|
||||
if(grp->meta.bin_len != 0)
|
||||
if(grp->meta.bin_len != 0)
|
||||
deserialOk = meta->deserialise(grp->meta.bin_data, grp->meta.bin_len);
|
||||
|
||||
bool erase = true;
|
||||
|
||||
if(deserialOk)
|
||||
if(deserialOk && acceptNewGroup(meta))
|
||||
{
|
||||
#ifdef GEN_EXCH_DEBUG
|
||||
std::cerr << " processing validation for group " << meta->mGroupId << ", attempts number " << gpsi.mAttempts << std::endl;
|
||||
|
@ -2911,8 +2937,10 @@ void RsGenExchange::processRecvdGroups()
|
|||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "(EE) deserialise error in group meta data" << std::endl;
|
||||
delete grp;
|
||||
if(!deserialOk)
|
||||
std::cerr << "(EE) deserialise error in group meta data" << std::endl;
|
||||
|
||||
delete grp;
|
||||
delete meta;
|
||||
erase = true;
|
||||
}
|
||||
|
|
|
@ -259,6 +259,16 @@ public:
|
|||
*/
|
||||
virtual void receiveChanges(std::vector<RsGxsNotify*>& changes);
|
||||
|
||||
/*!
|
||||
* \brief acceptNewGroup
|
||||
* Early checks if the group can be accepted. This is mainly used to check wether the group is banned for some reasons.
|
||||
* Returns true unless derived in GXS services.
|
||||
*
|
||||
* \param grpMeta Group metadata to check
|
||||
* \return
|
||||
*/
|
||||
virtual bool acceptNewGroup(const RsGxsGrpMetaData *grpMeta) ;
|
||||
|
||||
bool subscribeToGroup(uint32_t& token, const RsGxsGroupId& grpId, bool subscribe);
|
||||
|
||||
/*!
|
||||
|
@ -595,6 +605,14 @@ public:
|
|||
*/
|
||||
void setGroupReputationCutOff(uint32_t& token, const RsGxsGroupId& grpId, int CutOff);
|
||||
|
||||
/*!
|
||||
*
|
||||
* @param token value set to be redeemed with acknowledgement
|
||||
* @param grpId group id of the group to update
|
||||
* @param CutOff The cut off value to set
|
||||
*/
|
||||
void updateGroupLastMsgTimeStamp(uint32_t& token, const RsGxsGroupId& grpId);
|
||||
|
||||
/*!
|
||||
* @return storage time of messages in months
|
||||
*/
|
||||
|
|
|
@ -96,7 +96,6 @@
|
|||
* as these will be used very frequently.
|
||||
*****/
|
||||
|
||||
typedef RsPeerId PeerId; // SHOULD BE REMOVED => RsPeerId (SSLID)
|
||||
typedef PGPIdType RsPgpId;
|
||||
|
||||
/* Identity Interface for GXS Message Verification.
|
||||
|
@ -150,7 +149,7 @@ public:
|
|||
* @param keyref the KeyRef of the key being requested
|
||||
* @return will
|
||||
*/
|
||||
virtual bool requestKey(const RsGxsId &id, const std::list<PeerId> &peers) = 0;
|
||||
virtual bool requestKey(const RsGxsId &id, const std::list<RsPeerId> &peers) = 0;
|
||||
virtual bool requestPrivateKey(const RsGxsId &id) = 0;
|
||||
|
||||
|
||||
|
|
|
@ -39,20 +39,20 @@ uint32_t RsGxsGrpMetaData::serial_size(uint32_t api_version)
|
|||
|
||||
s += mGroupId.serial_size();
|
||||
s += mOrigGrpId.serial_size();
|
||||
s += mParentGrpId.serial_size();
|
||||
s += GetTlvStringSize(mGroupName);
|
||||
s += 4;
|
||||
s += 4;
|
||||
s += 4; // mGroupFlags
|
||||
s += 4; // mPublishTs
|
||||
s += 4; // mCircleType
|
||||
s += 4; // mAuthenFlag
|
||||
s += mAuthorId.serial_size();
|
||||
s += GetTlvStringSize(mServiceString);
|
||||
s += mCircleId.serial_size();
|
||||
s += signSet.TlvSize();
|
||||
s += keys.TlvSize();
|
||||
s += 4; // for mCircleType
|
||||
s += mCircleId.serial_size();
|
||||
s += 4; // mAuthenFlag
|
||||
s += mParentGrpId.serial_size(); // mParentGroupId
|
||||
|
||||
if(api_version == RS_GXS_GRP_META_DATA_VERSION_ID_0002)
|
||||
s += 4; // mSignFlag
|
||||
s += 4; // mSignFlag
|
||||
else if(api_version != RS_GXS_GRP_META_DATA_VERSION_ID_0001)
|
||||
std::cerr << "(EE) wrong/unknown API version " << api_version << " requested in RsGxsGrpMetaData::serial_size()" << std::endl;
|
||||
|
||||
|
@ -203,7 +203,7 @@ bool RsGxsGrpMetaData::deserialise(void *data, uint32_t &pktsize)
|
|||
int RsGxsMsgMetaData::refcount = 0;
|
||||
|
||||
RsGxsMsgMetaData::RsGxsMsgMetaData(){
|
||||
|
||||
clear();
|
||||
//std::cout << "\nrefcount++ : " << ++refcount << std::endl;
|
||||
return;
|
||||
}
|
||||
|
@ -227,8 +227,8 @@ uint32_t RsGxsMsgMetaData::serial_size()
|
|||
|
||||
s += signSet.TlvSize();
|
||||
s += GetTlvStringSize(mMsgName);
|
||||
s += 4; // mPublishTS
|
||||
s += 4; // mMsgFlags
|
||||
s += 4; // mPublishTS
|
||||
s += 4; // mMsgFlags
|
||||
|
||||
return s;
|
||||
}
|
||||
|
@ -311,7 +311,7 @@ bool RsGxsMsgMetaData::deserialise(void *data, uint32_t *size)
|
|||
|
||||
ok &= signSet.GetTlv(data, *size, &offset);
|
||||
ok &= GetTlvString(data, *size, &offset, 0, mMsgName);
|
||||
uint32_t t;
|
||||
uint32_t t=0;
|
||||
ok &= getRawUInt32(data, *size, &offset, &t);
|
||||
mPublishTs = t;
|
||||
ok &= getRawUInt32(data, *size, &offset, &mMsgFlags);
|
||||
|
|
|
@ -56,24 +56,22 @@ public:
|
|||
void clear();
|
||||
void operator =(const RsGroupMetaData& rMeta);
|
||||
|
||||
//Sort data in same order than serialiser and deserializer
|
||||
RsGxsGroupId mGroupId;
|
||||
RsGxsGroupId mOrigGrpId;
|
||||
RsGxsGroupId mParentGrpId;
|
||||
std::string mGroupName;
|
||||
uint32_t mGroupFlags; // GXS_SERV::FLAG_PRIVACY_RESTRICTED | GXS_SERV::FLAG_PRIVACY_PRIVATE | GXS_SERV::FLAG_PRIVACY_PUBLIC
|
||||
uint32_t mPublishTs;
|
||||
uint32_t mSignFlags;
|
||||
uint32_t mCircleType;
|
||||
uint32_t mAuthenFlags;
|
||||
RsGxsId mAuthorId;
|
||||
|
||||
std::string mServiceString;
|
||||
RsGxsCircleId mCircleId;
|
||||
uint32_t mCircleType;
|
||||
|
||||
|
||||
RsTlvKeySignatureSet signSet;
|
||||
RsTlvSecurityKeySet keys;
|
||||
|
||||
std::string mServiceString;
|
||||
uint32_t mAuthenFlags;
|
||||
RsGxsGroupId mParentGrpId;
|
||||
uint32_t mSignFlags;
|
||||
|
||||
// BELOW HERE IS LOCAL DATA, THAT IS NOT FROM MSG.
|
||||
|
||||
|
@ -105,18 +103,17 @@ public:
|
|||
void clear();
|
||||
void operator =(const RsMsgMetaData& rMeta);
|
||||
|
||||
static int refcount;
|
||||
|
||||
//Sort data in same order than serialiser and deserializer
|
||||
RsGxsGroupId mGroupId;
|
||||
RsGxsMessageId mMsgId;
|
||||
static int refcount;
|
||||
RsGxsMessageId mThreadId;
|
||||
RsGxsMessageId mParentId;
|
||||
RsGxsMessageId mOrigMsgId;
|
||||
RsGxsId mAuthorId;
|
||||
|
||||
RsTlvKeySignatureSet signSet;
|
||||
|
||||
std::string mServiceString;
|
||||
|
||||
std::string mMsgName;
|
||||
time_t mPublishTs;
|
||||
uint32_t mMsgFlags; // Whats this for?
|
||||
|
@ -124,6 +121,7 @@ public:
|
|||
// BELOW HERE IS LOCAL DATA, THAT IS NOT FROM MSG.
|
||||
// normally READ / UNREAD flags. LOCAL Data.
|
||||
|
||||
std::string mServiceString;
|
||||
uint32_t mMsgStatus;
|
||||
uint32_t mMsgSize;
|
||||
time_t mChildTs;
|
||||
|
|
|
@ -204,9 +204,9 @@
|
|||
#include "rsgxsnetservice.h"
|
||||
#include "gxssecurity.h"
|
||||
#include "retroshare/rsconfig.h"
|
||||
#include "retroshare/rsreputations.h"
|
||||
#include "retroshare/rsgxsflags.h"
|
||||
#include "retroshare/rsgxscircles.h"
|
||||
#include "retroshare/rspeers.h"
|
||||
#include "pgp/pgpauxutils.h"
|
||||
#include "util/rsdir.h"
|
||||
#include "util/rsmemory.h"
|
||||
|
@ -220,7 +220,7 @@
|
|||
NXS_NET_DEBUG_3 publish key exchange
|
||||
NXS_NET_DEBUG_4 vetting
|
||||
NXS_NET_DEBUG_5 summary of transactions (useful to just know what comes in/out)
|
||||
NXS_NET_DEBUG_6
|
||||
NXS_NET_DEBUG_6 group sync statistics (e.g. number of posts at nighbour nodes, etc)
|
||||
NXS_NET_DEBUG_7 encryption/decryption of transactions
|
||||
|
||||
***/
|
||||
|
@ -233,7 +233,6 @@
|
|||
//#define NXS_NET_DEBUG_6 1
|
||||
//#define NXS_NET_DEBUG_7 1
|
||||
|
||||
#define GIXS_CUT_OFF 0
|
||||
//#define NXS_FRAG
|
||||
|
||||
// The constant below have a direct influence on how fast forums/channels/posted/identity groups propagate and on the overloading of queues:
|
||||
|
@ -244,6 +243,7 @@
|
|||
// A small value for MAX_REQLIST_SIZE is likely to help messages to propagate in a chaotic network, but will also slow them down.
|
||||
// A small SYNC_PERIOD fasten message propagation, but is likely to overload the server side of transactions (e.g. overload outqueues).
|
||||
//
|
||||
#define GIXS_CUT_OFF 0
|
||||
#define SYNC_PERIOD 60
|
||||
#define MAX_REQLIST_SIZE 20 // No more than 20 items per msg request list => creates smaller transactions that are less likely to be cancelled.
|
||||
#define TRANSAC_TIMEOUT 2000 // In seconds. Has been increased to avoid epidemic transaction cancelling due to overloaded outqueues.
|
||||
|
@ -266,8 +266,8 @@ static const uint32_t RS_NXS_ITEM_ENCRYPTION_STATUS_GXS_KEY_MISSING = 0x05 ;
|
|||
|| defined(NXS_NET_DEBUG_4) || defined(NXS_NET_DEBUG_5) || defined(NXS_NET_DEBUG_6) || defined(NXS_NET_DEBUG_7)
|
||||
|
||||
static const RsPeerId peer_to_print = RsPeerId(std::string("")) ;
|
||||
static const RsGxsGroupId group_id_to_print = RsGxsGroupId(std::string("" )) ; // use this to allow to this group id only, or "" for all IDs
|
||||
static const uint32_t service_to_print = 0x215 ; // use this to allow to this service id only, or 0 for all services
|
||||
static const RsGxsGroupId group_id_to_print = RsGxsGroupId(std::string("")) ; // use this to allow to this group id only, or "" for all IDs
|
||||
static const uint32_t service_to_print = 0x211 ; // use this to allow to this service id only, or 0 for all services
|
||||
// warning. Numbers should be SERVICE IDS (see serialiser/rsserviceids.h. E.g. 0x0215 for forums)
|
||||
|
||||
class nullstream: public std::ostream {};
|
||||
|
@ -761,11 +761,11 @@ void RsGxsNetService::syncWithPeers()
|
|||
msg->updateTS = updateTS;
|
||||
|
||||
if(encrypt_to_this_circle_id.isNull())
|
||||
msg->grpId = grpId;
|
||||
msg->grpId = grpId;
|
||||
else
|
||||
{
|
||||
msg->grpId = hashGrpId(grpId,mNetMgr->getOwnId()) ;
|
||||
msg->flag |= RsNxsSyncMsgReqItem::FLAG_USE_HASHED_GROUP_ID ;
|
||||
msg->grpId = hashGrpId(grpId,mNetMgr->getOwnId()) ;
|
||||
msg->flag |= RsNxsSyncMsgReqItem::FLAG_USE_HASHED_GROUP_ID ;
|
||||
}
|
||||
|
||||
#ifdef NXS_NET_DEBUG_7
|
||||
|
@ -928,17 +928,22 @@ void RsGxsNetService::handleRecvSyncGrpStatistics(RsNxsSyncGrpStatsItem *grs)
|
|||
#ifdef NXS_NET_DEBUG_6
|
||||
GXSNETDEBUG_PG(grs->PeerId(),grs->grpId) << "Received Grp update stats item from peer " << grs->PeerId() << " for group " << grs->grpId << ", reporting " << grs->number_of_posts << " posts." << std::endl;
|
||||
#endif
|
||||
RS_STACK_MUTEX(mNxsMutex) ;
|
||||
RsGroupNetworkStatsRecord& rec(mGroupNetworkStats[grs->grpId]) ;
|
||||
bool should_notify = false ;
|
||||
{
|
||||
RS_STACK_MUTEX(mNxsMutex) ;
|
||||
RsGroupNetworkStatsRecord& rec(mGroupNetworkStats[grs->grpId]) ;
|
||||
|
||||
uint32_t old_count = rec.max_visible_count ;
|
||||
uint32_t old_suppliers_count = rec.suppliers.size() ;
|
||||
|
||||
rec.suppliers.insert(grs->PeerId()) ;
|
||||
rec.max_visible_count = std::max(rec.max_visible_count,grs->number_of_posts) ;
|
||||
rec.update_TS = time(NULL) ;
|
||||
|
||||
if (old_count != rec.max_visible_count || old_suppliers_count != rec.suppliers.size())
|
||||
uint32_t old_count = rec.max_visible_count ;
|
||||
uint32_t old_suppliers_count = rec.suppliers.size() ;
|
||||
|
||||
rec.suppliers.insert(grs->PeerId()) ;
|
||||
rec.max_visible_count = std::max(rec.max_visible_count,grs->number_of_posts) ;
|
||||
rec.update_TS = time(NULL) ;
|
||||
|
||||
if (old_count != rec.max_visible_count || old_suppliers_count != rec.suppliers.size())
|
||||
should_notify = true ;
|
||||
}
|
||||
if(should_notify)
|
||||
mObserver->notifyChangedGroupStats(grs->grpId);
|
||||
}
|
||||
else
|
||||
|
@ -2091,14 +2096,19 @@ void RsGxsNetService::updateServerSyncTS()
|
|||
else
|
||||
msui = mapIT->second;
|
||||
|
||||
if(grpMeta->mLastPost > msui->msgUpdateTS )
|
||||
{
|
||||
change = true;
|
||||
msui->msgUpdateTS = grpMeta->mLastPost;
|
||||
// (cyril) I'm removing this, because the msgUpdateTS is updated when new messages are received by calling locked_stampMsgServerUpdateTS().
|
||||
// mLastPost is actually updated somewhere when loading group meta data. It's not clear yet whether it is set to the latest publish time (wrong)
|
||||
// or the latest receive time (right). The former would cause problems because it would need to compare times coming from different (potentially async-ed)
|
||||
// machines.
|
||||
//
|
||||
// if(grpMeta->mLastPost > msui->msgUpdateTS )
|
||||
// {
|
||||
// change = true;
|
||||
// msui->msgUpdateTS = grpMeta->mLastPost;
|
||||
#ifdef NXS_NET_DEBUG_0
|
||||
GXSNETDEBUG__G(grpId) << " updated msgUpdateTS to last post = " << time(NULL) - grpMeta->mLastPost << " secs ago for group "<< grpId << std::endl;
|
||||
// GXSNETDEBUG__G(grpId) << " updated msgUpdateTS to last post = " << time(NULL) - grpMeta->mLastPost << " secs ago for group "<< grpId << std::endl;
|
||||
#endif
|
||||
}
|
||||
// }
|
||||
|
||||
// This is needed for group metadata updates to actually propagate: only a new grpUpdateTS will trigger the exchange of groups mPublishTs which
|
||||
// will then be compared and pssibly trigger a MetaData transmission. mRecvTS is upated when creating, receiving for the first time, or receiving
|
||||
|
@ -2118,6 +2128,7 @@ void RsGxsNetService::updateServerSyncTS()
|
|||
if(change)
|
||||
IndicateConfigChanged();
|
||||
}
|
||||
|
||||
bool RsGxsNetService::locked_checkTransacTimedOut(NxsTransaction* tr)
|
||||
{
|
||||
return tr->mTimeOut < ((uint32_t) time(NULL));
|
||||
|
@ -2590,6 +2601,8 @@ void RsGxsNetService::locked_processCompletedIncomingTrans(NxsTransaction* tr)
|
|||
// for the grp id
|
||||
locked_doMsgUpdateWork(tr->mTransaction, grpId);
|
||||
|
||||
// also update server sync TS, since we need to send the new message list to friends for comparison
|
||||
locked_stampMsgServerUpdateTS(grpId);
|
||||
}
|
||||
}
|
||||
else if(tr->mFlag == NxsTransaction::FLAG_STATE_FAILED)
|
||||
|
@ -2923,9 +2936,8 @@ void RsGxsNetService::locked_genReqMsgTransaction(NxsTransaction* tr)
|
|||
#endif
|
||||
continue;
|
||||
}
|
||||
// FIXTESTS global variable rsReputations not available in unittests!
|
||||
if(rsReputations == 0){ std::cerr << "rsReputations==0, accepting all messages!" << std::endl; }
|
||||
if(rsReputations && rsReputations->isIdentityBanned(syncItem->authorId))
|
||||
|
||||
if(rsIdentity && rsIdentity->isBanned(syncItem->authorId))
|
||||
{
|
||||
#ifdef NXS_NET_DEBUG_1
|
||||
GXSNETDEBUG_PG(item->PeerId(),grpId) << ", Identity " << syncItem->authorId << " is banned. Not requesting message!" << std::endl;
|
||||
|
@ -3169,8 +3181,8 @@ void RsGxsNetService::locked_genReqGrpTransaction(NxsTransaction* tr)
|
|||
latestVersion = grpSyncItem->publishTs > metaIter->second->mPublishTs;
|
||||
}
|
||||
// FIXTESTS global variable rsReputations not available in unittests!
|
||||
if(rsReputations == 0){ std::cerr << "rsReputations==0, accepting all groups!" << std::endl; }
|
||||
if(!grpSyncItem->authorId.isNull() && rsReputations && rsReputations->isIdentityBanned(grpSyncItem->authorId))
|
||||
|
||||
if(!grpSyncItem->authorId.isNull() && rsIdentity && rsIdentity->isBanned(grpSyncItem->authorId))
|
||||
{
|
||||
#ifdef NXS_NET_DEBUG_0
|
||||
GXSNETDEBUG_PG(tr->mTransaction->PeerId(),grpId) << " Identity " << grpSyncItem->authorId << " is banned. Not syncing group." << std::endl;
|
||||
|
@ -4089,7 +4101,7 @@ void RsGxsNetService::handleRecvSyncGroup(RsNxsSyncGrpReqItem *item)
|
|||
|
||||
|
||||
|
||||
bool RsGxsNetService::canSendGrpId(const RsPeerId& sslId, RsGxsGrpMetaData& grpMeta, std::vector<GrpIdCircleVet>& toVet, bool& should_encrypt)
|
||||
bool RsGxsNetService::canSendGrpId(const RsPeerId& sslId, RsGxsGrpMetaData& grpMeta, std::vector<GrpIdCircleVet>& /* toVet */, bool& should_encrypt)
|
||||
{
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << "RsGxsNetService::canSendGrpId()"<< std::endl;
|
||||
|
@ -4120,101 +4132,21 @@ bool RsGxsNetService::canSendGrpId(const RsPeerId& sslId, RsGxsGrpMetaData& grpM
|
|||
#endif
|
||||
should_encrypt = true ;
|
||||
return true ;
|
||||
|
||||
#ifdef TO_BE_REMOVED_OLD_VETTING_FOR_EXTERNAL_CIRCLES
|
||||
const RsGxsCircleId& circleId = grpMeta.mCircleId;
|
||||
if(circleId.isNull())
|
||||
{
|
||||
std::cerr << " EXTERNAL_CIRCLE missing NULL CircleId: " << grpMeta.mGroupId<< std::endl;
|
||||
|
||||
// ERROR, will never be shared.
|
||||
return false;
|
||||
}
|
||||
|
||||
if(mCircles->isLoaded(circleId))
|
||||
{
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId)<< " EXTERNAL_CIRCLE, checking mCircles->canSend"<< std::endl;
|
||||
#endif
|
||||
// the sending authorisation is based on:
|
||||
// getPgpId(peer_id) being a signer of one GxsId in the Circle
|
||||
//
|
||||
const RsPgpId& pgpId = mPgpUtils->getPGPId(sslId);
|
||||
|
||||
bool res = mCircles->canSend(circleId, pgpId);
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId)<< " answer is: " << res << std::endl;
|
||||
#endif
|
||||
return res ;
|
||||
}
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId)<< " grp not ready. Adding to vetting list." << std::endl;
|
||||
#endif
|
||||
|
||||
toVet.push_back(GrpIdCircleVet(grpMeta.mGroupId, circleId, grpMeta.mAuthorId));
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
if(circleType == GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY)
|
||||
{
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " YOUREYESONLY, checking further" << std::endl;
|
||||
#endif
|
||||
bool res = checkPermissionsForFriendGroup(sslId,grpMeta) ;
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Final answer: " << res << std::endl;
|
||||
#endif
|
||||
return res ;
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId)<< " YOUREYESONLY, checking further"<< std::endl;
|
||||
#endif
|
||||
// a non empty internal circle id means this
|
||||
// is the personal circle owner
|
||||
if(!grpMeta.mInternalCircle.isNull())
|
||||
{
|
||||
const RsGxsCircleId& internalCircleId = grpMeta.mInternalCircle;
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " have mInternalCircle - we are Group creator" << std::endl;
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " mCircleId: " << grpMeta.mCircleId << std::endl;
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " mInternalCircle: " << grpMeta.mInternalCircle << std::endl;
|
||||
#endif
|
||||
|
||||
if(mCircles->isLoaded(internalCircleId))
|
||||
{
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " circle Loaded - checking mCircles->canSend" << std::endl;
|
||||
#endif
|
||||
const RsPgpId& pgpId = mPgpUtils->getPGPId(sslId);
|
||||
bool should_encrypt = false ;
|
||||
|
||||
bool res = mCircles->canSend(internalCircleId, pgpId,should_encrypt);
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " answer is: " << res << std::endl;
|
||||
#endif
|
||||
return res ;
|
||||
}
|
||||
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Circle Not Loaded - add to vetting"<< std::endl;
|
||||
#endif
|
||||
toVet.push_back(GrpIdCircleVet(grpMeta.mGroupId, internalCircleId, grpMeta.mAuthorId));
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// an empty internal circle id means this peer can only
|
||||
// send circle related info from peer he received it
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " mInternalCircle not set, someone else's personal circle"<< std::endl;
|
||||
#endif
|
||||
if(grpMeta.mOriginator == sslId)
|
||||
{
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Originator matches -> can send"<< std::endl;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Originator doesn't match -> cannot send"<< std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -4224,121 +4156,51 @@ bool RsGxsNetService::checkCanRecvMsgFromPeer(const RsPeerId& sslId, const RsGxs
|
|||
{
|
||||
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << "RsGxsNetService::checkCanRecvMsgFromPeer()";
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " peer Id = " << sslId << ", grpId=" << grpMeta.mGroupId <<std::endl;
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << "RsGxsNetService::checkCanRecvMsgFromPeer()";
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " peer Id = " << sslId << ", grpId=" << grpMeta.mGroupId <<std::endl;
|
||||
#endif
|
||||
// first do the simple checks
|
||||
uint8_t circleType = grpMeta.mCircleType;
|
||||
should_encrypt_id.clear() ;
|
||||
// first do the simple checks
|
||||
uint8_t circleType = grpMeta.mCircleType;
|
||||
should_encrypt_id.clear() ;
|
||||
|
||||
if(circleType == GXS_CIRCLE_TYPE_LOCAL)
|
||||
{
|
||||
if(circleType == GXS_CIRCLE_TYPE_LOCAL)
|
||||
{
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " LOCAL_CIRCLE, cannot request sync from peer" << std::endl;
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " LOCAL_CIRCLE, cannot request sync from peer" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if(circleType == GXS_CIRCLE_TYPE_PUBLIC)
|
||||
{
|
||||
if(circleType == GXS_CIRCLE_TYPE_PUBLIC)
|
||||
{
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " PUBLIC_CIRCLE, can request msg sync" << std::endl;
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " PUBLIC_CIRCLE, can request msg sync" << std::endl;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if(circleType == GXS_CIRCLE_TYPE_EXTERNAL)
|
||||
{
|
||||
if(circleType == GXS_CIRCLE_TYPE_EXTERNAL)
|
||||
{
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Circle type: EXTERNAL => returning true. Msgs will be encrypted." << std::endl;
|
||||
#endif
|
||||
should_encrypt_id = grpMeta.mCircleId ;
|
||||
return true ;
|
||||
#ifdef TO_BE_REMOVED_OLD_VETTING_FOR_EXTERNAL_CIRCLES
|
||||
const RsGxsCircleId& circleId = grpMeta.mCircleId;
|
||||
if(circleId.isNull())
|
||||
{
|
||||
#ifdef NXS_NET_DEBUG_0
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " ERROR; EXTERNAL_CIRCLE missing NULL CircleId";
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << grpMeta.mGroupId;
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << std::endl;
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Circle type: EXTERNAL => returning true. Msgs will be encrypted." << std::endl;
|
||||
#endif
|
||||
should_encrypt_id = grpMeta.mCircleId ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
// should just be shared. ? no - this happens for
|
||||
// Circle Groups which lose their CircleIds.
|
||||
// return true;
|
||||
}
|
||||
if(circleType == GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY) // do not attempt to sync msg unless to originator or those permitted
|
||||
{
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " YOUREYESONLY, checking further" << std::endl;
|
||||
#endif
|
||||
bool res = checkPermissionsForFriendGroup(sslId,grpMeta) ;
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Final answer: " << res << std::endl;
|
||||
#endif
|
||||
return res ;
|
||||
}
|
||||
|
||||
if(mCircles->isLoaded(circleId))
|
||||
{
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " EXTERNAL_CIRCLE, checking mCircles->canSend" << std::endl;
|
||||
#endif
|
||||
const RsPgpId& pgpId = mPgpUtils->getPGPId(sslId);
|
||||
return mCircles->canSend(circleId, pgpId);
|
||||
}
|
||||
else
|
||||
mCircles->loadCircle(circleId); // simply request for next pass
|
||||
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
if(circleType == GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY) // do not attempt to sync msg unless to originator or those permitted
|
||||
{
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " YOUREYESONLY, checking further" << std::endl;
|
||||
#endif
|
||||
// a non empty internal circle id means this
|
||||
// is the personal circle owner
|
||||
if(!grpMeta.mInternalCircle.isNull())
|
||||
{
|
||||
const RsGxsCircleId& internalCircleId = grpMeta.mInternalCircle;
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " have mInternalCircle - we are Group creator" << std::endl;
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " mCircleId: " << grpMeta.mCircleId << std::endl;
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " mInternalCircle: " << grpMeta.mInternalCircle << std::endl;
|
||||
#endif
|
||||
|
||||
if(mCircles->isLoaded(internalCircleId))
|
||||
{
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " circle Loaded - checking mCircles->canSend" << std::endl;
|
||||
#endif
|
||||
const RsPgpId& pgpId = mPgpUtils->getPGPId(sslId);
|
||||
bool should_encrypt ;
|
||||
return mCircles->canSend(internalCircleId, pgpId,should_encrypt);
|
||||
}
|
||||
else
|
||||
mCircles->loadCircle(internalCircleId); // request for next pass
|
||||
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// an empty internal circle id means this peer can only
|
||||
// send circle related info from peer he received it
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " mInternalCircle not set, someone else's personal circle" << std::endl;
|
||||
#endif
|
||||
if(grpMeta.mOriginator == sslId)
|
||||
{
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Originator matches -> can send" << std::endl;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Originator doesn't match -> cannot send"<< std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RsGxsNetService::locked_CanReceiveUpdate(RsNxsSyncMsgReqItem *item,bool& grp_is_known)
|
||||
|
@ -4615,17 +4477,17 @@ bool RsGxsNetService::canSendMsgIds(std::vector<RsGxsMsgMetaData*>& msgMetas, co
|
|||
if(circleType == GXS_CIRCLE_TYPE_LOCAL)
|
||||
{
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Circle type: LOCAL => returning false" << std::endl;
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Circle type: LOCAL => returning false" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(circleType == GXS_CIRCLE_TYPE_PUBLIC)
|
||||
{
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Circle type: PUBLIC => returning true" << std::endl;
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Circle type: PUBLIC => returning true" << std::endl;
|
||||
#endif
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
const RsGxsCircleId& circleId = grpMeta.mCircleId;
|
||||
|
@ -4633,119 +4495,116 @@ bool RsGxsNetService::canSendMsgIds(std::vector<RsGxsMsgMetaData*>& msgMetas, co
|
|||
if(circleType == GXS_CIRCLE_TYPE_EXTERNAL)
|
||||
{
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Circle type: EXTERNAL => returning true. Msgs ids list will be encrypted." << std::endl;
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Circle type: EXTERNAL => returning true. Msgs ids list will be encrypted." << std::endl;
|
||||
#endif
|
||||
should_encrypt_id = circleId ;
|
||||
should_encrypt_id = circleId ;
|
||||
|
||||
// For each message ID, check that the author is in the circle. If not, do not send the message, which means, remove it from the list.
|
||||
// Unsigned messages are still transmitted. This is because in some groups (channels) the posts are not signed. Whether an unsigned post
|
||||
// is allowed at this point is anyway already vetted by the RsGxsGenExchange service.
|
||||
// For each message ID, check that the author is in the circle. If not, do not send the message, which means, remove it from the list.
|
||||
// Unsigned messages are still transmitted. This is because in some groups (channels) the posts are not signed. Whether an unsigned post
|
||||
// is allowed at this point is anyway already vetted by the RsGxsGenExchange service.
|
||||
|
||||
// Messages that stay in the list will be sent. As a consequence true is always returned.
|
||||
// Messages put in vetting list will be dealt with later
|
||||
// Messages that stay in the list will be sent. As a consequence true is always returned.
|
||||
// Messages put in vetting list will be dealt with later
|
||||
|
||||
std::vector<MsgIdCircleVet> toVet;
|
||||
std::vector<MsgIdCircleVet> toVet;
|
||||
|
||||
for(uint32_t i=0;i<msgMetas.size();)
|
||||
if( msgMetas[i]->mAuthorId.isNull() ) // keep the message in this case
|
||||
++i ;
|
||||
else
|
||||
{
|
||||
if(mCircles->isLoaded(circleId) && mCircles->isRecipient(circleId, grpMeta.mGroupId, msgMetas[i]->mAuthorId))
|
||||
{
|
||||
++i ;
|
||||
continue ;
|
||||
}
|
||||
for(uint32_t i=0;i<msgMetas.size();)
|
||||
if( msgMetas[i]->mAuthorId.isNull() ) // keep the message in this case
|
||||
++i ;
|
||||
else
|
||||
{
|
||||
if(mCircles->isLoaded(circleId) && mCircles->isRecipient(circleId, grpMeta.mGroupId, msgMetas[i]->mAuthorId))
|
||||
{
|
||||
++i ;
|
||||
continue ;
|
||||
}
|
||||
|
||||
MsgIdCircleVet mic(msgMetas[i]->mMsgId, msgMetas[i]->mAuthorId);
|
||||
toVet.push_back(mic);
|
||||
MsgIdCircleVet mic(msgMetas[i]->mMsgId, msgMetas[i]->mAuthorId);
|
||||
toVet.push_back(mic);
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " deleting MsgMeta entry for msg ID " << msgMetas[i]->mMsgId << " signed by " << msgMetas[i]->mAuthorId << " who is not in group circle " << circleId << std::endl;
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " deleting MsgMeta entry for msg ID " << msgMetas[i]->mMsgId << " signed by " << msgMetas[i]->mAuthorId << " who is not in group circle " << circleId << std::endl;
|
||||
#endif
|
||||
|
||||
delete msgMetas[i] ;
|
||||
msgMetas[i] = msgMetas[msgMetas.size()-1] ;
|
||||
msgMetas.pop_back() ;
|
||||
}
|
||||
delete msgMetas[i] ;
|
||||
msgMetas[i] = msgMetas[msgMetas.size()-1] ;
|
||||
msgMetas.pop_back() ;
|
||||
}
|
||||
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Circle info not loaded. Putting in vetting list and returning false." << std::endl;
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Circle info not loaded. Putting in vetting list and returning false." << std::endl;
|
||||
#endif
|
||||
if(!toVet.empty())
|
||||
mPendingCircleVets.push_back(new MsgCircleIdsRequestVetting(mCircles, mPgpUtils, toVet, grpMeta.mGroupId, sslId, grpMeta.mCircleId));
|
||||
if(!toVet.empty())
|
||||
mPendingCircleVets.push_back(new MsgCircleIdsRequestVetting(mCircles, mPgpUtils, toVet, grpMeta.mGroupId, sslId, grpMeta.mCircleId));
|
||||
|
||||
return true ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
if(circleType == GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY)
|
||||
{
|
||||
if(circleType == GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY)
|
||||
{
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Circle type: YOUR EYES ONLY" << std::endl;
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " YOUREYESONLY, checking further" << std::endl;
|
||||
#endif
|
||||
// a non empty internal circle id means this
|
||||
// is the personal circle owner
|
||||
if(!grpMeta.mInternalCircle.isNull())
|
||||
{
|
||||
const RsGxsCircleId& internalCircleId = grpMeta.mInternalCircle;
|
||||
bool res = checkPermissionsForFriendGroup(sslId,grpMeta) ;
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Group internal circle: " << internalCircleId << std::endl;
|
||||
#endif
|
||||
if(mCircles->isLoaded(internalCircleId))
|
||||
{
|
||||
const RsPgpId& pgpId = mPgpUtils->getPGPId(sslId);
|
||||
bool should_encrypt = false ;
|
||||
|
||||
bool res= mCircles->canSend(internalCircleId, pgpId,should_encrypt);
|
||||
|
||||
if(should_encrypt)
|
||||
std::cerr << "(EE) inconsistent response: vetting requests to encrypt circle of type YOUR_EYES_ONLY" << std::endl;
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Answer from circle::canSend(): " << res << std::endl;
|
||||
#endif
|
||||
return res ;
|
||||
}
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Not loaded. Putting in vetting list and returning false." << std::endl;
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Final answer: " << res << std::endl;
|
||||
#endif
|
||||
return res ;
|
||||
}
|
||||
|
||||
std::vector<MsgIdCircleVet> toVet;
|
||||
std::vector<RsGxsMsgMetaData*>::const_iterator vit = msgMetas.begin();
|
||||
|
||||
for(; vit != msgMetas.end(); ++vit)
|
||||
{
|
||||
const RsGxsMsgMetaData* const& meta = *vit;
|
||||
|
||||
MsgIdCircleVet mic(meta->mMsgId, meta->mAuthorId);
|
||||
toVet.push_back(mic);
|
||||
}
|
||||
|
||||
if(!toVet.empty())
|
||||
mPendingCircleVets.push_back(new MsgCircleIdsRequestVetting(mCircles, mPgpUtils,
|
||||
toVet, grpMeta.mGroupId,
|
||||
sslId, grpMeta.mCircleId));
|
||||
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// an empty internal circle id means this peer can only
|
||||
// send circle related info from peer he received it
|
||||
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Empty internal circle: cannot only send info from Peer we received it (grpMeta.mOriginator=" << grpMeta.mOriginator << " answer is: " << (grpMeta.mOriginator == sslId) << std::endl;
|
||||
#endif
|
||||
if(grpMeta.mOriginator == sslId)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
/** inherited methods **/
|
||||
|
||||
bool RsGxsNetService::checkPermissionsForFriendGroup(const RsPeerId& sslId,const RsGxsGrpMetaData& grpMeta)
|
||||
{
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Circle type: YOUR EYES ONLY - ID = " << grpMeta.mInternalCircle << std::endl;
|
||||
#endif
|
||||
// a non empty internal circle id means this
|
||||
// is the personal circle owner
|
||||
if(!grpMeta.mInternalCircle.isNull())
|
||||
{
|
||||
RsGroupInfo ginfo ;
|
||||
RsPgpId pgpId = mPgpUtils->getPGPId(sslId) ;
|
||||
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Group internal circle: " << grpMeta.mInternalCircle << ", We're owner. Sending to everyone in the group." << std::endl;
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Current destination is PGP Id: " << pgpId << std::endl;
|
||||
#endif
|
||||
if(!rsPeers->getGroupInfo(RsNodeGroupId(grpMeta.mInternalCircle),ginfo))
|
||||
{
|
||||
std::cerr << "(EE) Cannot get information for internal circle (group node) ID " << grpMeta.mInternalCircle << " which conditions dissemination of GXS group " << grpMeta.mGroupId << std::endl;
|
||||
return false ;
|
||||
}
|
||||
|
||||
bool res = (ginfo.peerIds.find(pgpId) != ginfo.peerIds.end());
|
||||
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Final Answer is: " << res << std::endl;
|
||||
#endif
|
||||
return res ;
|
||||
}
|
||||
else
|
||||
{
|
||||
// An empty internal circle id means this peer can only
|
||||
// send circle related info from peer he received it from.
|
||||
// Normally this should be a pgp-based decision, but if we do that,
|
||||
// A ---> B ----> A' ---...--->B' , then A' will also send to B' since B is the
|
||||
// originator for A'. So A will lose control of who can see the data. This should
|
||||
// be discussed further...
|
||||
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Empty internal circle: cannot only send/recv info to/from Peer we received it from (grpMeta.mOriginator=" << grpMeta.mOriginator << ")" << std::endl;
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Final answer is: " << (grpMeta.mOriginator == sslId) << std::endl;
|
||||
#endif
|
||||
if(grpMeta.mOriginator == sslId)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void RsGxsNetService::pauseSynchronisation(bool /* enabled */)
|
||||
{
|
||||
|
||||
|
@ -4759,7 +4618,13 @@ void RsGxsNetService::setSyncAge(uint32_t /* age */)
|
|||
int RsGxsNetService::requestGrp(const std::list<RsGxsGroupId>& grpId, const RsPeerId& peerId)
|
||||
{
|
||||
RS_STACK_MUTEX(mNxsMutex) ;
|
||||
mExplicitRequest[peerId].assign(grpId.begin(), grpId.end());
|
||||
#ifdef NXS_NET_DEBUG_0
|
||||
GXSNETDEBUG_P_(peerId) << "RsGxsNetService::requestGrp(): adding explicit group requests to peer " << peerId << std::endl;
|
||||
|
||||
for(std::list<RsGxsGroupId>::const_iterator it(grpId.begin());it!=grpId.end();++it)
|
||||
GXSNETDEBUG_PG(peerId,*it) << " Group ID: " << *it << std::endl;
|
||||
#endif
|
||||
mExplicitRequest[peerId].assign(grpId.begin(), grpId.end());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -4771,7 +4636,10 @@ void RsGxsNetService::processExplicitGroupRequests()
|
|||
|
||||
for(; cit != mExplicitRequest.end(); ++cit)
|
||||
{
|
||||
const RsPeerId& peerId = cit->first;
|
||||
#ifdef NXS_NET_DEBUG_0
|
||||
GXSNETDEBUG_P_(cit->first) << "RsGxsNetService::sending pending explicit group requests to peer " << cit->first << std::endl;
|
||||
#endif
|
||||
const RsPeerId& peerId = cit->first;
|
||||
const std::list<RsGxsGroupId>& groupIdList = cit->second;
|
||||
|
||||
std::list<RsNxsItem*> grpSyncItems;
|
||||
|
@ -4779,7 +4647,10 @@ void RsGxsNetService::processExplicitGroupRequests()
|
|||
uint32_t transN = locked_getTransactionId();
|
||||
for(; git != groupIdList.end(); ++git)
|
||||
{
|
||||
RsNxsSyncGrpItem* item = new RsNxsSyncGrpItem(mServType);
|
||||
#ifdef NXS_NET_DEBUG_0
|
||||
GXSNETDEBUG_PG(peerId,*git) << " group request for grp ID " << *git << " to peer " << peerId << std::endl;
|
||||
#endif
|
||||
RsNxsSyncGrpItem* item = new RsNxsSyncGrpItem(mServType);
|
||||
item->grpId = *git;
|
||||
item->PeerId(peerId);
|
||||
item->flag = RsNxsSyncGrpItem::FLAG_REQUEST;
|
||||
|
@ -4956,6 +4827,10 @@ void RsGxsNetService::handleRecvPublishKeys(RsNxsGroupPublishKeyItem *item)
|
|||
// update the publish keys in this group meta info
|
||||
|
||||
RsGxsGrpMetaData *grpMeta = grpMetaMap[item->grpId] ;
|
||||
if (!grpMeta) {
|
||||
std::cerr << "(EE) RsGxsNetService::handleRecvPublishKeys() grpMeta not found." << std::endl;
|
||||
return ;
|
||||
}
|
||||
|
||||
// Check that the keys correspond, and that FULL keys are supplied, etc.
|
||||
|
||||
|
@ -5028,3 +4903,26 @@ bool RsGxsNetService::getGroupServerUpdateTS(const RsGxsGroupId& gid,time_t& gro
|
|||
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool RsGxsNetService::stampMsgServerUpdateTS(const RsGxsGroupId& gid)
|
||||
{
|
||||
RS_STACK_MUTEX(mNxsMutex) ;
|
||||
|
||||
return locked_stampMsgServerUpdateTS(gid) ;
|
||||
}
|
||||
|
||||
bool RsGxsNetService::locked_stampMsgServerUpdateTS(const RsGxsGroupId& gid)
|
||||
{
|
||||
std::map<RsGxsGroupId,RsGxsServerMsgUpdateItem*>::iterator it = mServerMsgUpdateMap.find(gid) ;
|
||||
|
||||
if(mServerMsgUpdateMap.end() == it)
|
||||
{
|
||||
RsGxsServerMsgUpdateItem *item = new RsGxsServerMsgUpdateItem(mServType);
|
||||
item->grpId = gid ;
|
||||
item->msgUpdateTS = time(NULL) ;
|
||||
}
|
||||
else
|
||||
it->second->msgUpdateTS = time(NULL) ;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -155,7 +155,8 @@ public:
|
|||
virtual void rejectMessage(const RsGxsMessageId& msg_id) ;
|
||||
|
||||
virtual bool getGroupServerUpdateTS(const RsGxsGroupId& gid,time_t& grp_server_update_TS,time_t& msg_server_update_TS) ;
|
||||
|
||||
virtual bool stampMsgServerUpdateTS(const RsGxsGroupId& gid) ;
|
||||
|
||||
/* p3Config methods */
|
||||
public:
|
||||
|
||||
|
@ -228,6 +229,13 @@ private:
|
|||
*/
|
||||
void locked_completeTransaction(NxsTransaction* trans);
|
||||
|
||||
/*!
|
||||
* \brief locked_stampMsgServerUpdateTS
|
||||
* updates the server msg time stamp. This function is the locked method for the one above with similar name
|
||||
* \param gid group id to stamp.
|
||||
* \return
|
||||
*/
|
||||
bool locked_stampMsgServerUpdateTS(const RsGxsGroupId& gid);
|
||||
/*!
|
||||
* This retrieves a unique transaction id that
|
||||
* can be used in an outgoing transaction
|
||||
|
@ -354,6 +362,15 @@ private:
|
|||
bool canSendGrpId(const RsPeerId& sslId, RsGxsGrpMetaData& grpMeta, std::vector<GrpIdCircleVet>& toVet, bool &should_encrypt);
|
||||
bool canSendMsgIds(std::vector<RsGxsMsgMetaData*>& msgMetas, const RsGxsGrpMetaData&, const RsPeerId& sslId, RsGxsCircleId &should_encrypt_id);
|
||||
|
||||
/*!
|
||||
* \brief checkPermissionsForFriendGroup
|
||||
* Checks that we can send/recv from that node, given that the grpMeta has a distribution limited to a local circle.
|
||||
* \param sslId Candidate peer to send to or to receive from.
|
||||
* \param grpMeta Contains info about the group id, internal circle id, etc.
|
||||
* \return true only when the internal exists and validates as a friend node group, and contains the owner of sslId.
|
||||
*/
|
||||
bool checkPermissionsForFriendGroup(const RsPeerId& sslId,const RsGxsGrpMetaData& grpMeta) ;
|
||||
|
||||
bool checkCanRecvMsgFromPeer(const RsPeerId& sslId, const RsGxsGrpMetaData& meta, RsGxsCircleId& should_encrypt_id);
|
||||
|
||||
void locked_createTransactionFromPending(MsgRespPending* grpPend);
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
#include "rsgxsutil.h"
|
||||
#include "retroshare/rsgxsflags.h"
|
||||
#include "retroshare/rspeers.h"
|
||||
#include "retroshare/rsreputations.h"
|
||||
#include "pqi/pqihash.h"
|
||||
#include "gxs/rsgixs.h"
|
||||
|
||||
|
@ -165,7 +164,7 @@ bool RsGxsIntegrityCheck::check()
|
|||
std::cerr << "TimeStamping group authors' key ID " << grp->metaData->mAuthorId << " in group ID " << grp->grpId << std::endl;
|
||||
#endif
|
||||
|
||||
if(rsReputations!=NULL && !rsReputations->isIdentityBanned(grp->metaData->mAuthorId))
|
||||
if(rsIdentity!=NULL && !rsIdentity->isBanned(grp->metaData->mAuthorId))
|
||||
used_gxs_ids.insert(grp->metaData->mAuthorId) ;
|
||||
}
|
||||
}
|
||||
|
@ -247,7 +246,7 @@ bool RsGxsIntegrityCheck::check()
|
|||
#ifdef GXSUTIL_DEBUG
|
||||
std::cerr << "TimeStamping message authors' key ID " << msg->metaData->mAuthorId << " in message " << msg->msgId << ", group ID " << msg->grpId<< std::endl;
|
||||
#endif
|
||||
if(rsReputations!=NULL && !rsReputations->isIdentityBanned(msg->metaData->mAuthorId))
|
||||
if(rsIdentity!=NULL && !rsIdentity->isBanned(msg->metaData->mAuthorId))
|
||||
used_gxs_ids.insert(msg->metaData->mAuthorId) ;
|
||||
}
|
||||
|
||||
|
|
|
@ -144,6 +144,15 @@ public:
|
|||
* \return false if the group is not found, true otherwise
|
||||
*/
|
||||
virtual bool getGroupServerUpdateTS(const RsGxsGroupId& gid,time_t& grp_server_update_TS,time_t& msg_server_update_TS) =0;
|
||||
|
||||
/*!
|
||||
* \brief stampMsgServerUpdateTS
|
||||
* Updates the msgServerUpdateMap structure to time(NULL), so as to trigger sending msg lists to friends.
|
||||
* This is needed when e.g. posting a new message to a group.
|
||||
* \param gid the group to stamp in msgServerUpdateMap
|
||||
* \return
|
||||
*/
|
||||
virtual bool stampMsgServerUpdateTS(const RsGxsGroupId& gid) =0;
|
||||
};
|
||||
|
||||
#endif // RSGNP_H
|
||||
|
|
|
@ -10,6 +10,10 @@ DESTDIR = lib
|
|||
|
||||
#CONFIG += dsdv
|
||||
|
||||
# the dht stunner is used to obtain RS' external ip addr. when it is natted
|
||||
# this system is unreliable and rs supports a newer and better one (asking connected peers)
|
||||
# CONFIG += useDhtStunner
|
||||
|
||||
profiling {
|
||||
QMAKE_CXXFLAGS -= -fomit-frame-pointer
|
||||
QMAKE_CXXFLAGS *= -pg -g -fno-omit-frame-pointer
|
||||
|
@ -65,8 +69,7 @@ SOURCES *= serialiser/rstlvdsdv.cc \
|
|||
bitdht {
|
||||
|
||||
HEADERS += dht/p3bitdht.h \
|
||||
dht/connectstatebox.h \
|
||||
dht/stunaddrassist.h
|
||||
dht/connectstatebox.h
|
||||
|
||||
SOURCES += dht/p3bitdht.cc \
|
||||
dht/p3bitdht_interface.cc \
|
||||
|
@ -80,7 +83,6 @@ HEADERS += tcponudp/udppeer.h \
|
|||
tcponudp/tcppacket.h \
|
||||
tcponudp/tcpstream.h \
|
||||
tcponudp/tou.h \
|
||||
tcponudp/udpstunner.h \
|
||||
tcponudp/udprelay.h \
|
||||
|
||||
SOURCES += tcponudp/udppeer.cc \
|
||||
|
@ -88,9 +90,17 @@ SOURCES += tcponudp/udppeer.cc \
|
|||
tcponudp/tcpstream.cc \
|
||||
tcponudp/tou.cc \
|
||||
tcponudp/bss_tou.c \
|
||||
tcponudp/udpstunner.cc \
|
||||
tcponudp/udprelay.cc \
|
||||
|
||||
useDhtStunner {
|
||||
HEADERS += dht/stunaddrassist.h \
|
||||
tcponudp/udpstunner.h
|
||||
|
||||
SOURCES += tcponudp/udpstunner.cc
|
||||
|
||||
DEFINES += RS_USE_DHT_STUNNER
|
||||
}
|
||||
|
||||
DEFINES *= RS_USE_BITDHT
|
||||
|
||||
BITDHT_DIR = ../../libbitdht/src
|
||||
|
|
|
@ -71,13 +71,13 @@ bool PgpAuxUtilsImpl::parseSignature(unsigned char *sign, unsigned int signlen,
|
|||
return AuthGPG::getAuthGPG()->parseSignature(sign,signlen,issuer);
|
||||
}
|
||||
|
||||
bool PgpAuxUtilsImpl::askForDeferredSelfSignature(const void *data,
|
||||
const uint32_t len,
|
||||
unsigned char *sign,
|
||||
bool PgpAuxUtilsImpl::askForDeferredSelfSignature(const void *data,
|
||||
const uint32_t len,
|
||||
unsigned char *sign,
|
||||
unsigned int *signlen,
|
||||
int& signature_result )
|
||||
int& signature_result , std::string reason)
|
||||
{
|
||||
return RsServer::notify()->askForDeferredSelfSignature(data, len, sign, signlen, signature_result);
|
||||
return RsServer::notify()->askForDeferredSelfSignature(data, len, sign, signlen, signature_result, reason);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ 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;
|
||||
virtual bool askForDeferredSelfSignature(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen,int& signature_result ) = 0;
|
||||
virtual bool askForDeferredSelfSignature(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen,int& signature_result, std::string reason) = 0;
|
||||
};
|
||||
|
||||
class PgpAuxUtilsImpl: public PgpAuxUtils
|
||||
|
@ -58,7 +58,7 @@ public:
|
|||
virtual bool getKeyFingerprint(const RsPgpId& id,PGPFingerprintType& fp) const;
|
||||
virtual bool VerifySignBin(const void *data, uint32_t len, unsigned char *sign, unsigned int signlen, const PGPFingerprintType& withfingerprint);
|
||||
virtual bool getGPGAllList(std::list<RsPgpId> &ids);
|
||||
virtual bool askForDeferredSelfSignature(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen,int& signature_result );
|
||||
virtual bool askForDeferredSelfSignature(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen,int& signature_result, std::string reason);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -61,25 +61,25 @@ ops_parse_cb_return_t cb_get_passphrase(const ops_parser_content_t *content_,ops
|
|||
{
|
||||
case OPS_PARSER_CMD_GET_SK_PASSPHRASE_PREV_WAS_BAD: prev_was_bad = true ;
|
||||
case OPS_PARSER_CMD_GET_SK_PASSPHRASE:
|
||||
{
|
||||
std::string passwd;
|
||||
std::string uid_hint ;
|
||||
|
||||
if(cbinfo->cryptinfo.keydata->nuids > 0)
|
||||
uid_hint = std::string((const char *)cbinfo->cryptinfo.keydata->uids[0].user_id) ;
|
||||
uid_hint += "(" + RsPgpId(cbinfo->cryptinfo.keydata->key_id).toStdString()+")" ;
|
||||
{
|
||||
std::string passwd;
|
||||
std::string uid_hint ;
|
||||
|
||||
bool cancelled = false ;
|
||||
passwd = PGPHandler::passphraseCallback()(NULL,uid_hint.c_str(),NULL,prev_was_bad,&cancelled) ;
|
||||
if(cbinfo->cryptinfo.keydata->nuids > 0)
|
||||
uid_hint = std::string((const char *)cbinfo->cryptinfo.keydata->uids[0].user_id) ;
|
||||
uid_hint += "(" + RsPgpId(cbinfo->cryptinfo.keydata->key_id).toStdString()+")" ;
|
||||
|
||||
if(cancelled)
|
||||
*(unsigned char *)cbinfo->arg = 1;
|
||||
bool cancelled = false ;
|
||||
passwd = PGPHandler::passphraseCallback()(NULL,"",uid_hint.c_str(),NULL,prev_was_bad,&cancelled) ;
|
||||
|
||||
*(content->secret_key_passphrase.passphrase)= (char *)ops_mallocz(passwd.length()+1) ;
|
||||
memcpy(*(content->secret_key_passphrase.passphrase),passwd.c_str(),passwd.length()) ;
|
||||
return OPS_KEEP_MEMORY;
|
||||
}
|
||||
break;
|
||||
if(cancelled)
|
||||
*(unsigned char *)cbinfo->arg = 1;
|
||||
|
||||
*(content->secret_key_passphrase.passphrase)= (char *)ops_mallocz(passwd.length()+1) ;
|
||||
memcpy(*(content->secret_key_passphrase.passphrase),passwd.c_str(),passwd.length()) ;
|
||||
return OPS_KEEP_MEMORY;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
|
@ -1326,7 +1326,7 @@ bool PGPHandler::decryptTextFromFile(const RsPgpId&,std::string& text,const std:
|
|||
return (bool)res ;
|
||||
}
|
||||
|
||||
bool PGPHandler::SignDataBin(const RsPgpId& id,const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen,bool use_raw_signature)
|
||||
bool PGPHandler::SignDataBin(const RsPgpId& id,const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen,bool use_raw_signature, std::string reason /* = "" */)
|
||||
{
|
||||
RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP memory structures.
|
||||
// need to find the key and to decrypt it.
|
||||
|
@ -1357,7 +1357,7 @@ ops_secret_key_t *secret_key = NULL ;
|
|||
for(int i=0;i<3;++i)
|
||||
{
|
||||
bool cancelled =false;
|
||||
std::string passphrase = _passphrase_callback(NULL,uid_hint.c_str(),"Please enter passwd for encrypting your key : ",last_passwd_was_wrong,&cancelled) ;
|
||||
std::string passphrase = _passphrase_callback(NULL,reason.c_str(),uid_hint.c_str(),"Please enter passwd for encrypting your key : ",last_passwd_was_wrong,&cancelled) ;//TODO reason
|
||||
|
||||
secret_key = ops_decrypt_secret_key_from_data(key,passphrase.c_str()) ;
|
||||
|
||||
|
@ -1448,8 +1448,8 @@ bool PGPHandler::privateSignCertificate(const RsPgpId& ownId,const RsPgpId& id_o
|
|||
return false ;
|
||||
}
|
||||
|
||||
bool cancelled = false;
|
||||
std::string passphrase = _passphrase_callback(NULL,RsPgpId(skey->key_id).toStdString().c_str(),"Please enter passwd for encrypting your key : ",false,&cancelled) ;
|
||||
bool cancelled = false;
|
||||
std::string passphrase = _passphrase_callback(NULL,"",RsPgpId(skey->key_id).toStdString().c_str(),"Please enter passwd for encrypting your key : ",false,&cancelled) ;
|
||||
|
||||
ops_secret_key_t *secret_key = ops_decrypt_secret_key_from_data(skey,passphrase.c_str()) ;
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ extern "C" {
|
|||
#include <openpgpsdk/keyring_local.h>
|
||||
}
|
||||
|
||||
typedef std::string (*PassphraseCallback)(void *data, const char *uid_hint, const char *passphrase_info, int prev_was_bad,bool *cancelled) ;
|
||||
typedef std::string (*PassphraseCallback)(void *data, const char *uid_title, const char *uid_hint, const char *passphrase_info, int prev_was_bad,bool *cancelled) ;
|
||||
|
||||
class PGPCertificateInfo
|
||||
{
|
||||
|
@ -85,8 +85,8 @@ class PGPHandler
|
|||
std::string SaveCertificateToString(const RsPgpId& id,bool include_signatures) const ;
|
||||
bool exportPublicKey(const RsPgpId& id,unsigned char *& mem,size_t& mem_size,bool armoured,bool include_signatures) const ;
|
||||
|
||||
bool parseSignature(unsigned char *sign, unsigned int signlen,RsPgpId& issuer_id) ;
|
||||
bool SignDataBin(const RsPgpId& id,const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen,bool make_raw_signature=false) ;
|
||||
bool parseSignature(unsigned char *sign, unsigned int signlen,RsPgpId& issuer_id) ;
|
||||
bool SignDataBin(const RsPgpId& id, const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen, bool make_raw_signature=false, std::string reason = "") ;
|
||||
bool VerifySignBin(const void *data, uint32_t data_len, unsigned char *sign, unsigned int sign_len, const PGPFingerprintType& withfingerprint) ;
|
||||
bool privateSignCertificate(const RsPgpId& own_id,const RsPgpId& id_of_key_to_sign) ;
|
||||
|
||||
|
|
|
@ -248,23 +248,25 @@ uint64_t PGPKeyParser::read_KeyID(unsigned char *& data)
|
|||
|
||||
uint32_t PGPKeyParser::write_125Size(unsigned char *data,uint32_t size)
|
||||
{
|
||||
if(size < 192)
|
||||
if(size < 192)//192 To know if size is coded with One Char < 0xC0
|
||||
{
|
||||
data[0] = size ;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(size < 8384)
|
||||
if(size < 8384)//8384 To know if size is coded with Two Chars < 0xE0. See RFC4880
|
||||
{
|
||||
data[0] = (size >> 8) + 192 ;
|
||||
data[1] = (size & 255) - 192 ;
|
||||
data[1] = (size - 192) & 0xFF ;//Warning data[1] could be "negative", recode it using 8bits type
|
||||
data[0] = ((size - 192 - data[1]) >> 8) + 192 ;
|
||||
|
||||
return 2 ;
|
||||
}
|
||||
|
||||
data[0] = 0xff ;
|
||||
data[1] = (size >> 24) & 255 ;
|
||||
data[2] = (size >> 16) & 255 ;
|
||||
data[3] = (size >> 8) & 255 ;
|
||||
data[4] = (size ) & 255 ;
|
||||
data[0] = 0xFF ; //Else size is coded with 4 Chars + 1 at 0xFF
|
||||
data[1] = (size >> 24) & 0xFF ;
|
||||
data[2] = (size >> 16) & 0xFF ;
|
||||
data[3] = (size >> 8) & 0xFF ;
|
||||
data[4] = (size ) & 0xFF ;
|
||||
|
||||
return 5 ;
|
||||
}
|
||||
|
@ -274,16 +276,16 @@ uint32_t PGPKeyParser::read_125Size(unsigned char *& data)
|
|||
uint8_t b1 = *data ;
|
||||
++data ;
|
||||
|
||||
if(b1 < 192)
|
||||
if(b1 < 192) //192 Size is coded with One Char. See RFC4880
|
||||
return b1 ;
|
||||
|
||||
uint8_t b2 = *data ;
|
||||
++data ;
|
||||
|
||||
if(b1 < 224)
|
||||
return ((b1-192) << 8) + b2 + 192 ;
|
||||
if(b1 < 224)//224 = 0xC0+0x20 Size is coded with Two Chars
|
||||
return ((b1-192) << 8) + b2 + 192 ; // see RFC4880
|
||||
|
||||
if(b1 != 0xff)
|
||||
if(b1 != 0xFF)// Else Coded with 4 Chars but first == 0xFF
|
||||
throw std::runtime_error("GPG parsing error") ;
|
||||
|
||||
uint8_t b3 = *data ; ++data ;
|
||||
|
|
|
@ -86,14 +86,14 @@ bool AuthGPG::encryptTextToFile(const std::string& text,const std::string& outfi
|
|||
// return PGPHandler::encryptTextToString(RsPgpId(pgp_id),text,outstr) ;
|
||||
// }
|
||||
|
||||
std::string pgp_pwd_callback(void * /*hook*/, const char *uid_hint, const char * /*passphrase_info*/, int prev_was_bad,bool *cancelled)
|
||||
std::string pgp_pwd_callback(void * /*hook*/, const char *uid_title, const char *uid_hint, const char * /*passphrase_info*/, int prev_was_bad,bool *cancelled)
|
||||
{
|
||||
#define GPG_DEBUG2
|
||||
#ifdef GPG_DEBUG2
|
||||
fprintf(stderr, "pgp_pwd_callback() called.\n");
|
||||
#endif
|
||||
std::string password;
|
||||
RsServer::notify()->askForPassword(uid_hint, prev_was_bad, password,cancelled) ;
|
||||
RsServer::notify()->askForPassword(uid_title, uid_hint, prev_was_bad, password,cancelled) ;
|
||||
|
||||
return password ;
|
||||
}
|
||||
|
@ -296,9 +296,9 @@ void AuthGPG::processServices()
|
|||
delete operation;
|
||||
}
|
||||
|
||||
bool AuthGPG::DoOwnSignature(const void *data, unsigned int datalen, void *buf_sigout, unsigned int *outl)
|
||||
bool AuthGPG::DoOwnSignature(const void *data, unsigned int datalen, void *buf_sigout, unsigned int *outl, std::string reason /* = "" */)
|
||||
{
|
||||
return PGPHandler::SignDataBin(mOwnGpgId,data,datalen,(unsigned char *)buf_sigout,outl) ;
|
||||
return PGPHandler::SignDataBin(mOwnGpgId,data,datalen,(unsigned char *)buf_sigout,outl,false,reason) ;
|
||||
}
|
||||
|
||||
|
||||
|
@ -605,9 +605,9 @@ bool AuthGPG::decryptDataBin(const void *data, unsigned int datalen, unsigned ch
|
|||
{
|
||||
return PGPHandler::decryptDataBin(mOwnGpgId,data,datalen,sign,signlen) ;
|
||||
}
|
||||
bool AuthGPG::SignDataBin(const void *data, unsigned int datalen, unsigned char *sign, unsigned int *signlen)
|
||||
bool AuthGPG::SignDataBin(const void *data, unsigned int datalen, unsigned char *sign, unsigned int *signlen, std::string reason /*= ""*/)
|
||||
{
|
||||
return DoOwnSignature(data, datalen, sign, signlen);
|
||||
return DoOwnSignature(data, datalen, sign, signlen, reason);
|
||||
}
|
||||
|
||||
bool AuthGPG::VerifySignBin(const void *data, uint32_t datalen, unsigned char *sign, unsigned int signlen, const PGPFingerprintType& withfingerprint)
|
||||
|
|
|
@ -208,7 +208,7 @@ class AuthGPG: public p3Config, public RsTickingThread, public PGPHandler
|
|||
* There should also be Encryption Functions... (do later).
|
||||
*
|
||||
****/
|
||||
virtual bool SignDataBin(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen);
|
||||
virtual bool SignDataBin(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen, std::string reason = "");
|
||||
virtual bool VerifySignBin(const void*, uint32_t, unsigned char*, unsigned int, const PGPFingerprintType& withfingerprint);
|
||||
virtual bool parseSignature(const void *sig, unsigned int siglen, RsPgpId& issuer_id);
|
||||
|
||||
|
@ -254,7 +254,7 @@ class AuthGPG: public p3Config, public RsTickingThread, public PGPHandler
|
|||
//void createDummyFriends(void); //NYI
|
||||
|
||||
/* Internal functions */
|
||||
bool DoOwnSignature(const void *, unsigned int, void *, unsigned int *);
|
||||
bool DoOwnSignature(const void *, unsigned int, void *, unsigned int *, std::string reason);
|
||||
bool VerifySignature(const void *data, int datalen, const void *sig, unsigned int siglen, const PGPFingerprintType& withfingerprint);
|
||||
|
||||
/* Sign/Trust stuff */
|
||||
|
|
|
@ -850,7 +850,7 @@ X509 *AuthSSLimpl::SignX509ReqWithGPG(X509_REQ *req, long /*days*/)
|
|||
std::cerr << "Digest Applied: len: " << hashoutl << std::endl;
|
||||
|
||||
/* NOW Sign via GPG Functions */
|
||||
if (!AuthGPG::getAuthGPG()->SignDataBin(buf_hashout, hashoutl, buf_sigout, (unsigned int *) &sigoutl))
|
||||
if (!AuthGPG::getAuthGPG()->SignDataBin(buf_hashout, hashoutl, buf_sigout, (unsigned int *) &sigoutl,"AuthSSLimpl::SignX509ReqWithGPG()"))
|
||||
{
|
||||
sigoutl = 0;
|
||||
goto err;
|
||||
|
|
|
@ -138,8 +138,6 @@ p3LinkMgrIMPL::p3LinkMgrIMPL(p3PeerMgrIMPL *peerMgr, p3NetMgrIMPL *netMgr)
|
|||
mDNSResolver = new DNSResolver();
|
||||
mRetryPeriod = MIN_RETRY_PERIOD;
|
||||
|
||||
lastGroupId = 1;
|
||||
|
||||
/* setup Banned Ip Address - static for now
|
||||
*/
|
||||
|
||||
|
|
|
@ -132,7 +132,7 @@ class peerConnectState
|
|||
};
|
||||
|
||||
class p3tunnel;
|
||||
class RsPeerGroupItem;
|
||||
class RsPeerGroupItem_deprecated;
|
||||
class RsGroupInfo;
|
||||
|
||||
class p3PeerMgr;
|
||||
|
@ -339,9 +339,6 @@ private:
|
|||
std::map<RsPeerId, peerConnectState> mFriendList;
|
||||
std::map<RsPeerId, peerConnectState> mOthersList;
|
||||
|
||||
std::list<RsPeerGroupItem *> groupList;
|
||||
uint32_t lastGroupId;
|
||||
|
||||
/* relatively static list of banned ip addresses */
|
||||
std::list<struct sockaddr_storage> mBannedIpList;
|
||||
};
|
||||
|
|
|
@ -169,12 +169,13 @@ void p3NetMgrIMPL::setManagers(p3PeerMgr *peerMgr, p3LinkMgr *linkMgr)
|
|||
// mDhtMgr = dhtMgr;
|
||||
//}
|
||||
|
||||
#ifdef RS_USE_DHT_STUNNER
|
||||
void p3NetMgrIMPL::setAddrAssist(pqiAddrAssist *dhtStun, pqiAddrAssist *proxyStun)
|
||||
{
|
||||
mDhtStunner = dhtStun;
|
||||
mProxyStunner = proxyStun;
|
||||
}
|
||||
|
||||
#endif // RS_USE_DHT_STUNNER
|
||||
|
||||
|
||||
/***** Framework / initial implementation for a connection manager.
|
||||
|
@ -445,6 +446,7 @@ void p3NetMgrIMPL::slowTick()
|
|||
netAssistTick();
|
||||
updateNetStateBox_temporal();
|
||||
|
||||
#ifdef RS_USE_DHT_STUNNER
|
||||
if (mDhtStunner)
|
||||
{
|
||||
mDhtStunner->tick();
|
||||
|
@ -454,7 +456,7 @@ void p3NetMgrIMPL::slowTick()
|
|||
{
|
||||
mProxyStunner->tick();
|
||||
}
|
||||
|
||||
#endif // RS_USE_DHT_STUNNER
|
||||
}
|
||||
|
||||
#define STARTUP_DELAY 5
|
||||
|
@ -1734,11 +1736,12 @@ void p3NetMgrIMPL::updateNetStateBox_temporal()
|
|||
std::cerr << "p3NetMgrIMPL::updateNetStateBox_temporal() ";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
uint8_t isstable = 0;
|
||||
struct sockaddr_storage tmpaddr;
|
||||
sockaddr_storage_clear(tmpaddr);
|
||||
|
||||
#ifdef RS_USE_DHT_STUNNER
|
||||
uint8_t isstable = 0;
|
||||
|
||||
if (mDhtStunner)
|
||||
{
|
||||
|
||||
|
@ -1776,6 +1779,7 @@ void p3NetMgrIMPL::updateNetStateBox_temporal()
|
|||
|
||||
}
|
||||
}
|
||||
#endif // RS_USE_DHT_STUNNER
|
||||
|
||||
|
||||
{
|
||||
|
@ -1789,7 +1793,7 @@ void p3NetMgrIMPL::updateNetStateBox_temporal()
|
|||
|
||||
/* now we check if a WebIP address is required? */
|
||||
|
||||
|
||||
#ifdef NETMGR_DEBUG_STATEBOX
|
||||
{
|
||||
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
|
@ -1805,7 +1809,6 @@ void p3NetMgrIMPL::updateNetStateBox_temporal()
|
|||
std::string nattypestr = NetStateNatTypeString(natType);
|
||||
std::string netmodestr = NetStateNetworkModeString(netMode);
|
||||
|
||||
#ifdef NETMGR_DEBUG_STATEBOX
|
||||
std::cerr << "p3NetMgrIMPL::updateNetStateBox_temporal() NetStateBox Thinking";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "\tNetState: " << netstatestr;
|
||||
|
@ -1818,10 +1821,9 @@ void p3NetMgrIMPL::updateNetStateBox_temporal()
|
|||
std::cerr << std::endl;
|
||||
std::cerr << "\tNatType: " << nattypestr;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
updateNatSetting();
|
||||
|
||||
|
@ -1869,7 +1871,7 @@ void p3NetMgrIMPL::updateNatSetting()
|
|||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef RS_USE_DHT_STUNNER
|
||||
switch(natType)
|
||||
{
|
||||
case RSNET_NATTYPE_RESTRICTED_CONE:
|
||||
|
@ -1894,7 +1896,7 @@ void p3NetMgrIMPL::updateNatSetting()
|
|||
mProxyStunner->setRefreshPeriod(NET_STUNNER_PERIOD_SLOW);
|
||||
break;
|
||||
}
|
||||
|
||||
#endif // RS_USE_DHT_STUNNER
|
||||
|
||||
/* This controls the Attach mode of the DHT...
|
||||
* which effectively makes the DHT "attach" to Open Nodes.
|
||||
|
|
|
@ -209,7 +209,9 @@ virtual bool getDHTEnabled();
|
|||
/************************************************************************************************/
|
||||
|
||||
void setManagers(p3PeerMgr *peerMgr, p3LinkMgr *linkMgr);
|
||||
#ifdef RS_USE_DHT_STUNNER
|
||||
void setAddrAssist(pqiAddrAssist *dhtStun, pqiAddrAssist *proxyStun);
|
||||
#endif // RS_USE_DHT_STUNNER
|
||||
|
||||
void tick();
|
||||
|
||||
|
@ -319,8 +321,10 @@ private:
|
|||
p3LinkMgr *mLinkMgr;
|
||||
|
||||
//p3BitDht *mBitDht;
|
||||
#ifdef RS_USE_DHT_STUNNER
|
||||
pqiAddrAssist *mDhtStunner;
|
||||
pqiAddrAssist *mProxyStunner;
|
||||
#endif // RS_USE_DHT_STUNNER
|
||||
|
||||
RsMutex mNetMtx; /* protects below */
|
||||
|
||||
|
|
|
@ -245,10 +245,10 @@ void p3Notify::notifyDownloadComplete (const std::string& fileHash )
|
|||
void p3Notify::notifyDownloadCompleteCount (uint32_t count ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyDownloadCompleteCount (count) ; }
|
||||
void p3Notify::notifyHistoryChanged (uint32_t msgId , int type) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyHistoryChanged (msgId,type) ; }
|
||||
|
||||
bool p3Notify::askForPassword (const std::string& key_details , bool prev_is_bad , std::string& password,bool *cancelled)
|
||||
bool p3Notify::askForPassword (const std::string& title , const std::string& key_details , bool prev_is_bad , std::string& password,bool *cancelled)
|
||||
{
|
||||
FOR_ALL_NOTIFY_CLIENTS
|
||||
if( (*it)->askForPassword(key_details,prev_is_bad,password,*cancelled))
|
||||
if( (*it)->askForPassword(title,key_details,prev_is_bad,password,*cancelled))
|
||||
return true ;
|
||||
|
||||
return false ;
|
||||
|
@ -261,10 +261,10 @@ bool p3Notify::askForPluginConfirmation (const std::string& plugin_filen
|
|||
|
||||
return false ;
|
||||
}
|
||||
bool p3Notify::askForDeferredSelfSignature (const void * data , const uint32_t len , unsigned char *sign, unsigned int *signlen,int& signature_result )
|
||||
bool p3Notify::askForDeferredSelfSignature (const void * data , const uint32_t len , unsigned char *sign, unsigned int *signlen,int& signature_result, std::string reason /*=""*/)
|
||||
{
|
||||
FOR_ALL_NOTIFY_CLIENTS
|
||||
if( (*it)->askForDeferredSelfSignature(data,len,sign,signlen,signature_result))
|
||||
if( (*it)->askForDeferredSelfSignature(data,len,sign,signlen,signature_result, reason))
|
||||
return true ;
|
||||
|
||||
return false ;
|
||||
|
|
|
@ -116,12 +116,12 @@ class p3Notify: public RsNotify
|
|||
void notifyPeerStatusChangedSummary () ;
|
||||
void notifyDiscInfoChanged () ;
|
||||
|
||||
bool askForDeferredSelfSignature (const void * /* data */, const uint32_t /* len */, unsigned char * /* sign */, unsigned int * /* signlen */,int& signature_result ) ;
|
||||
bool askForDeferredSelfSignature (const void * /* data */, const uint32_t /* len */, unsigned char * /* sign */, unsigned int * /* signlen */, int& signature_result , std::string reason = "") ;
|
||||
void notifyDownloadComplete (const std::string& /* fileHash */) ;
|
||||
void notifyDownloadCompleteCount (uint32_t /* count */) ;
|
||||
void notifyHistoryChanged (uint32_t /* msgId */, int /* type */) ;
|
||||
|
||||
bool askForPassword (const std::string& /* key_details */, bool /* prev_is_bad */, std::string&, bool *cancelled /* password */ ) ;
|
||||
bool askForPassword (const std::string& title, const std::string& /* key_details */, bool /* prev_is_bad */, std::string&, bool *cancelled /* password */ ) ;
|
||||
bool askForPluginConfirmation (const std::string& /* plugin_filename */, const std::string& /* plugin_file_hash */) ;
|
||||
|
||||
private:
|
||||
|
|
|
@ -75,7 +75,7 @@ static struct RsLog::logInfo p3peermgrzoneInfo = {RsLog::Default, "p3peermgr"};
|
|||
|
||||
static const std::string kConfigDefaultProxyServerIpAddr = "127.0.0.1";
|
||||
static const uint16_t kConfigDefaultProxyServerPortTor = 9050; // standard port.
|
||||
static const uint16_t kConfigDefaultProxyServerPortI2P = 10; // there is no standard port though
|
||||
static const uint16_t kConfigDefaultProxyServerPortI2P = 4447; // I2Pd's standard port
|
||||
|
||||
static const std::string kConfigKeyExtIpFinder = "USE_EXTR_IP_FINDER";
|
||||
static const std::string kConfigKeyProxyServerIpAddrTor = "PROXY_SERVER_IPADDR";
|
||||
|
@ -130,8 +130,6 @@ p3PeerMgrIMPL::p3PeerMgrIMPL(const RsPeerId& ssl_own_id, const RsPgpId& gpg_own_
|
|||
mOwnState.vs_disc = RS_VS_DISC_FULL;
|
||||
mOwnState.vs_dht = RS_VS_DHT_FULL;
|
||||
|
||||
lastGroupId = 1;
|
||||
|
||||
// setup default ProxyServerAddress.
|
||||
// Tor
|
||||
sockaddr_storage_clear(mProxyServerAddressTor);
|
||||
|
@ -1071,7 +1069,7 @@ bool p3PeerMgrIMPL::removeFriend(const RsPgpId &id)
|
|||
|
||||
std::list<RsPgpId> ids ;
|
||||
ids.push_back(id) ;
|
||||
assignPeersToGroup("", ids, false);
|
||||
assignPeersToGroup(RsNodeGroupId(), ids, false);
|
||||
|
||||
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
||||
|
||||
|
@ -1145,7 +1143,7 @@ bool p3PeerMgrIMPL::removeFriend(const RsPeerId &id, bool removePgpId)
|
|||
|
||||
/* remove id from all groups */
|
||||
|
||||
assignPeersToGroup("", pgpid_toRemove, false);
|
||||
assignPeersToGroup(RsNodeGroupId(), pgpid_toRemove, false);
|
||||
|
||||
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
||||
|
||||
|
@ -1915,7 +1913,7 @@ RsSerialiser *p3PeerMgrIMPL::setupSerialiser()
|
|||
bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
|
||||
{
|
||||
/* create a list of current peers */
|
||||
cleanup = false;
|
||||
cleanup = true;
|
||||
bool useExtAddrFinder = mNetMgr->getIPServersEnabled();
|
||||
|
||||
/* gather these information before mPeerMtx is locked! */
|
||||
|
@ -1971,7 +1969,6 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
|
|||
#endif
|
||||
|
||||
saveData.push_back(item);
|
||||
saveCleanupList.push_back(item);
|
||||
|
||||
/* iterate through all friends and save */
|
||||
std::map<RsPeerId, peerState>::iterator it;
|
||||
|
@ -2003,7 +2000,6 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
|
|||
item->domain_port = (it->second).hiddenPort;
|
||||
|
||||
saveData.push_back(item);
|
||||
saveCleanupList.push_back(item);
|
||||
#ifdef PEER_DEBUG
|
||||
std::cerr << "p3PeerMgrIMPL::saveList() Peer Config Item:" << std::endl;
|
||||
item->print(std::cerr, 10);
|
||||
|
@ -2024,7 +2020,6 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
|
|||
}
|
||||
|
||||
saveData.push_back(sitem) ;
|
||||
saveCleanupList.push_back(sitem);
|
||||
|
||||
// Now save config for network digging strategies
|
||||
|
||||
|
@ -2066,14 +2061,14 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
|
|||
vitem->tlvkvs.pairs.push_back(kv) ;
|
||||
|
||||
saveData.push_back(vitem);
|
||||
saveCleanupList.push_back(vitem);
|
||||
|
||||
/* save groups */
|
||||
|
||||
std::list<RsPeerGroupItem *>::iterator groupIt;
|
||||
for (groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt) {
|
||||
saveData.push_back(*groupIt); // no delete
|
||||
}
|
||||
for ( std::map<RsNodeGroupId,RsGroupInfo>::iterator groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt)
|
||||
{
|
||||
RsNodeGroupItem *itm = new RsNodeGroupItem(groupIt->second);
|
||||
saveData.push_back(itm) ;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -2294,7 +2289,8 @@ bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
|
|||
continue;
|
||||
}
|
||||
|
||||
RsPeerGroupItem *gitem = dynamic_cast<RsPeerGroupItem *>(*it) ;
|
||||
RsPeerGroupItem_deprecated *gitem = dynamic_cast<RsPeerGroupItem_deprecated *>(*it) ;
|
||||
|
||||
if (gitem)
|
||||
{
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
@ -2304,20 +2300,54 @@ bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
|
|||
gitem->print(std::cerr, 10);
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
RsGroupInfo ginfo ;
|
||||
ginfo.flag = gitem->flag ;
|
||||
ginfo.name = gitem->name ;
|
||||
ginfo.peerIds = gitem->pgpList.ids ;
|
||||
|
||||
groupList.push_back(gitem); // don't delete
|
||||
do { ginfo.id = RsNodeGroupId::random(); } while(groupList.find(ginfo.id) != groupList.end()) ;
|
||||
|
||||
if ((gitem->flag & RS_GROUP_FLAG_STANDARD) == 0) {
|
||||
/* calculate group id */
|
||||
uint32_t groupId = atoi(gitem->id.c_str());
|
||||
if (groupId > lastGroupId) {
|
||||
lastGroupId = groupId;
|
||||
}
|
||||
}
|
||||
// Ensure backward compatibility when loading the group in old format. The id must matchthe standard default id.
|
||||
|
||||
continue;
|
||||
if(gitem->id == std::string(RS_GROUP_DEFAULT_NAME_FRIENDS )) ginfo.id = RS_GROUP_ID_FRIENDS ;
|
||||
if(gitem->id == std::string(RS_GROUP_DEFAULT_NAME_COWORKERS)) ginfo.id = RS_GROUP_ID_COWORKERS ;
|
||||
if(gitem->id == std::string(RS_GROUP_DEFAULT_NAME_FAMILY )) ginfo.id = RS_GROUP_ID_FAMILY ;
|
||||
if(gitem->id == std::string(RS_GROUP_DEFAULT_NAME_FAVORITES)) ginfo.id = RS_GROUP_ID_FAVORITES ;
|
||||
if(gitem->id == std::string(RS_GROUP_DEFAULT_NAME_OTHERS )) ginfo.id = RS_GROUP_ID_OTHERS ;
|
||||
|
||||
if(!ginfo.id.isNull())
|
||||
{
|
||||
groupList[ginfo.id] = ginfo ;
|
||||
std::cerr << "(II) Creating new group for old format local group \"" << gitem->name << "\". Id=" << ginfo.id << std::endl;
|
||||
}
|
||||
else
|
||||
std::cerr << "(EE) no group corresponding to old format group with ID=\"" << gitem->id << "\"" << std::endl;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
RsNodeGroupItem *gitem2 = dynamic_cast<RsNodeGroupItem*>(*it) ;
|
||||
|
||||
if (gitem2)
|
||||
{
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
#ifdef PEER_DEBUG
|
||||
std::cerr << "p3PeerMgrIMPL::loadList() Peer group item:" << std::endl;
|
||||
gitem->print(std::cerr, 10);
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
RsGroupInfo info ;
|
||||
info.peerIds = gitem2->pgpList.ids ;
|
||||
info.id = gitem2->id ;
|
||||
info.name = gitem2->name ;
|
||||
info.flag = gitem2->flag ;
|
||||
|
||||
std::cerr << "(II) Loaded group in new format. ID = " << info.id << std::endl;
|
||||
groupList[info.id] = info ;
|
||||
|
||||
continue;
|
||||
}
|
||||
RsPeerBandwidthLimitsItem *pblitem = dynamic_cast<RsPeerBandwidthLimitsItem*>(*it) ;
|
||||
|
||||
if(pblitem)
|
||||
|
@ -2363,42 +2393,19 @@ bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
|
|||
|
||||
/* Standard groups */
|
||||
const int standardGroupCount = 5;
|
||||
const char *standardGroup[standardGroupCount] = { RS_GROUP_ID_FRIENDS, RS_GROUP_ID_FAMILY, RS_GROUP_ID_COWORKERS, RS_GROUP_ID_OTHERS, RS_GROUP_ID_FAVORITES };
|
||||
bool foundStandardGroup[standardGroupCount] = { false, false, false, false, false };
|
||||
const RsNodeGroupId standardGroupIds [standardGroupCount] = { RS_GROUP_ID_FRIENDS, RS_GROUP_ID_FAMILY, RS_GROUP_ID_COWORKERS, RS_GROUP_ID_OTHERS, RS_GROUP_ID_FAVORITES };
|
||||
const char *standardGroupNames[standardGroupCount] = { RS_GROUP_DEFAULT_NAME_FRIENDS, RS_GROUP_DEFAULT_NAME_FAMILY, RS_GROUP_DEFAULT_NAME_COWORKERS, RS_GROUP_DEFAULT_NAME_OTHERS, RS_GROUP_DEFAULT_NAME_FAVORITES };
|
||||
|
||||
std::list<RsPeerGroupItem *>::iterator groupIt;
|
||||
for (groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt) {
|
||||
if ((*groupIt)->flag & RS_GROUP_FLAG_STANDARD) {
|
||||
int i;
|
||||
for (i = 0; i < standardGroupCount; ++i) {
|
||||
if ((*groupIt)->id == standardGroup[i]) {
|
||||
foundStandardGroup[i] = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for(uint32_t k=0;k<standardGroupCount;++k)
|
||||
if(groupList.find(standardGroupIds[k]) == groupList.end())
|
||||
{
|
||||
RsGroupInfo info ;
|
||||
info.id = standardGroupIds[k];
|
||||
info.name = standardGroupNames[k];
|
||||
info.flag |= RS_GROUP_FLAG_STANDARD;
|
||||
|
||||
if (i >= standardGroupCount) {
|
||||
/* No more a standard group, remove the flag standard */
|
||||
(*groupIt)->flag &= ~RS_GROUP_FLAG_STANDARD;
|
||||
}
|
||||
} else {
|
||||
uint32_t groupId = atoi((*groupIt)->id.c_str());
|
||||
if (groupId == 0) {
|
||||
rs_sprintf((*groupIt)->id, "%lu", lastGroupId++);
|
||||
}
|
||||
groupList[info.id] = info;
|
||||
}
|
||||
}
|
||||
|
||||
/* Initialize standard groups */
|
||||
for (int i = 0; i < standardGroupCount; ++i) {
|
||||
if (foundStandardGroup[i] == false) {
|
||||
RsPeerGroupItem *gitem = new RsPeerGroupItem;
|
||||
gitem->id = standardGroup[i];
|
||||
gitem->name = standardGroup[i];
|
||||
gitem->flag |= RS_GROUP_FLAG_STANDARD;
|
||||
groupList.push_back(gitem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If we are hidden - don't want ExtAddrFinder - ever!
|
||||
|
@ -2478,19 +2485,16 @@ bool p3PeerMgrIMPL::addGroup(RsGroupInfo &groupInfo)
|
|||
{
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
RsPeerGroupItem *groupItem = new RsPeerGroupItem;
|
||||
groupItem->set(groupInfo);
|
||||
do { groupInfo.id = RsNodeGroupId::random(); } while(groupList.find(groupInfo.id) != groupList.end()) ;
|
||||
|
||||
rs_sprintf(groupItem->id, "%lu", ++lastGroupId);
|
||||
RsGroupInfo groupItem(groupInfo) ;
|
||||
|
||||
// remove standard flag
|
||||
groupItem->flag &= ~RS_GROUP_FLAG_STANDARD;
|
||||
|
||||
groupItem->PeerId(getOwnId());
|
||||
groupItem.flag &= ~RS_GROUP_FLAG_STANDARD;
|
||||
groupList[groupInfo.id] = groupItem;
|
||||
|
||||
groupList.push_back(groupItem);
|
||||
|
||||
groupInfo.id = groupItem->id;
|
||||
std::cerr << "(II) Added new group with ID " << groupInfo.id << ", name=\"" << groupInfo.name << "\"" << std::endl;
|
||||
}
|
||||
|
||||
RsServer::notify()->notifyListChange(NOTIFY_LIST_GROUPLIST, NOTIFY_TYPE_ADD);
|
||||
|
@ -2500,35 +2504,39 @@ bool p3PeerMgrIMPL::addGroup(RsGroupInfo &groupInfo)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool p3PeerMgrIMPL::editGroup(const std::string &groupId, RsGroupInfo &groupInfo)
|
||||
bool p3PeerMgrIMPL::editGroup(const RsNodeGroupId& groupId, RsGroupInfo &groupInfo)
|
||||
{
|
||||
if (groupId.empty()) {
|
||||
if (groupId.isNull())
|
||||
return false;
|
||||
}
|
||||
|
||||
bool changed = false;
|
||||
|
||||
{
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
{
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
std::list<RsPeerGroupItem*>::iterator groupIt;
|
||||
for (groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt) {
|
||||
if ((*groupIt)->id == groupId) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
std::map<RsNodeGroupId,RsGroupInfo>::iterator it = groupList.find(groupId) ;
|
||||
|
||||
if (groupIt != groupList.end()) {
|
||||
if ((*groupIt)->flag & RS_GROUP_FLAG_STANDARD) {
|
||||
// can't edit standard groups
|
||||
} else {
|
||||
changed = true;
|
||||
(*groupIt)->set(groupInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(it == groupList.end())
|
||||
{
|
||||
std::cerr << "(EE) cannot find local node group with ID " << groupId << std::endl;
|
||||
return false ;
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
if (it->second.flag & RS_GROUP_FLAG_STANDARD)
|
||||
{
|
||||
// can't edit standard groups
|
||||
std::cerr << "(EE) cannot edit standard group with ID " << groupId << std::endl;
|
||||
return false ;
|
||||
}
|
||||
else
|
||||
{
|
||||
changed = true;
|
||||
it->second = groupInfo;
|
||||
}
|
||||
}
|
||||
|
||||
if (changed)
|
||||
{
|
||||
RsServer::notify()->notifyListChange(NOTIFY_LIST_GROUPLIST, NOTIFY_TYPE_MOD);
|
||||
|
||||
IndicateConfigChanged();
|
||||
|
@ -2537,31 +2545,35 @@ bool p3PeerMgrIMPL::editGroup(const std::string &groupId, RsGroupInfo &groupInfo
|
|||
return changed;
|
||||
}
|
||||
|
||||
bool p3PeerMgrIMPL::removeGroup(const std::string &groupId)
|
||||
bool p3PeerMgrIMPL::removeGroup(const RsNodeGroupId& groupId)
|
||||
{
|
||||
if (groupId.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool changed = false;
|
||||
|
||||
{
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
std::list<RsPeerGroupItem*>::iterator groupIt;
|
||||
for (groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt) {
|
||||
if ((*groupIt)->id == groupId) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
std::map<RsNodeGroupId,RsGroupInfo>::iterator it = groupList.find(groupId) ;
|
||||
|
||||
if (groupIt != groupList.end()) {
|
||||
if ((*groupIt)->flag & RS_GROUP_FLAG_STANDARD) {
|
||||
if (it != groupList.end()) {
|
||||
if (it->second.flag & RS_GROUP_FLAG_STANDARD)
|
||||
{
|
||||
// can't remove standard groups
|
||||
} else {
|
||||
std::cerr << "(EE) cannot remove standard group with ID " << groupId << std::endl;
|
||||
return false ;
|
||||
}
|
||||
#warning we need to check that the local group is not used. Otherwise deleting it is going to cause problems!
|
||||
// else if(!it->second.used_gxs_groups.empty())
|
||||
// {
|
||||
// std::cerr << "(EE) cannot remove standard group with ID " << groupId << " because it is used in the following groups: " << std::endl;
|
||||
// for(std::set<RsGxsGroupId>::const_iterator it2(it->second.used_gxs_groups.begin());it2!=it->second.used_gxs_groups.end();++it2)
|
||||
// std::cerr << " " << *it2 << std::endl;
|
||||
//
|
||||
// return false ;
|
||||
// }
|
||||
else
|
||||
{
|
||||
changed = true;
|
||||
delete(*groupIt);
|
||||
groupList.erase(groupIt);
|
||||
groupList.erase(it);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2575,82 +2587,83 @@ bool p3PeerMgrIMPL::removeGroup(const std::string &groupId)
|
|||
return changed;
|
||||
}
|
||||
|
||||
bool p3PeerMgrIMPL::getGroupInfo(const std::string &groupId, RsGroupInfo &groupInfo)
|
||||
bool p3PeerMgrIMPL::getGroupInfoByName(const std::string& groupName, RsGroupInfo &groupInfo)
|
||||
{
|
||||
if (groupId.empty()) {
|
||||
return false;
|
||||
}
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
for(std::map<RsNodeGroupId,RsGroupInfo>::iterator it = groupList.begin();it!=groupList.end();++it)
|
||||
if(it->second.name == groupName)
|
||||
{
|
||||
groupInfo = it->second ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
std::cerr << "(EE) getGroupInfoByName: no known group for name " << groupName << std::endl;
|
||||
return false ;
|
||||
}
|
||||
bool p3PeerMgrIMPL::getGroupInfo(const RsNodeGroupId& groupId, RsGroupInfo &groupInfo)
|
||||
{
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
std::list<RsPeerGroupItem*>::iterator groupIt;
|
||||
for (groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt) {
|
||||
if ((*groupIt)->id == groupId) {
|
||||
(*groupIt)->get(groupInfo);
|
||||
std::map<RsNodeGroupId,RsGroupInfo>::iterator it = groupList.find(groupId) ;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if(it == groupList.end())
|
||||
return false ;
|
||||
|
||||
return false;
|
||||
groupInfo = it->second;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3PeerMgrIMPL::getGroupInfoList(std::list<RsGroupInfo> &groupInfoList)
|
||||
bool p3PeerMgrIMPL::getGroupInfoList(std::list<RsGroupInfo>& groupInfoList)
|
||||
{
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
std::list<RsPeerGroupItem*>::iterator groupIt;
|
||||
for (groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt) {
|
||||
RsGroupInfo groupInfo;
|
||||
(*groupIt)->get(groupInfo);
|
||||
groupInfoList.push_back(groupInfo);
|
||||
}
|
||||
for (std::map<RsNodeGroupId,RsGroupInfo> ::const_iterator groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt)
|
||||
groupInfoList.push_back(groupIt->second);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// groupId == "" && assign == false -> remove from all groups
|
||||
bool p3PeerMgrIMPL::assignPeersToGroup(const std::string &groupId, const std::list<RsPgpId> &peerIds, bool assign)
|
||||
{
|
||||
if (groupId.empty() && assign == true) {
|
||||
return false;
|
||||
}
|
||||
// groupId.isNull() && assign == false -> remove from all groups
|
||||
|
||||
if (peerIds.empty()) {
|
||||
bool p3PeerMgrIMPL::assignPeersToGroup(const RsNodeGroupId &groupId, const std::list<RsPgpId> &peerIds, bool assign)
|
||||
{
|
||||
if (groupId.isNull() && assign == true)
|
||||
return false;
|
||||
|
||||
if (peerIds.empty())
|
||||
return false;
|
||||
}
|
||||
|
||||
bool changed = false;
|
||||
|
||||
{
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
std::list<RsPeerGroupItem*>::iterator groupIt;
|
||||
for (groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt) {
|
||||
if (groupId.empty() || (*groupIt)->id == groupId) {
|
||||
RsPeerGroupItem *groupItem = *groupIt;
|
||||
for (std::map<RsNodeGroupId,RsGroupInfo>::iterator groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt)
|
||||
if (groupId.isNull() || groupIt->first == groupId)
|
||||
{
|
||||
RsGroupInfo& groupItem = groupIt->second;
|
||||
|
||||
std::list<RsPgpId>::const_iterator peerIt;
|
||||
for (peerIt = peerIds.begin(); peerIt != peerIds.end(); ++peerIt) {
|
||||
std::set<RsPgpId>::iterator peerIt1 = std::find(groupItem->pgpList.ids.begin(), groupItem->pgpList.ids.end(), *peerIt);
|
||||
if (assign) {
|
||||
if (peerIt1 == groupItem->pgpList.ids.end()) {
|
||||
groupItem->pgpList.ids.insert(*peerIt);
|
||||
changed = true;
|
||||
}
|
||||
} else {
|
||||
if (peerIt1 != groupItem->pgpList.ids.end()) {
|
||||
groupItem->pgpList.ids.erase(peerIt1);
|
||||
changed = true;
|
||||
}
|
||||
for (std::list<RsPgpId>::const_iterator peerIt = peerIds.begin(); peerIt != peerIds.end(); ++peerIt)
|
||||
{
|
||||
std::set<RsPgpId>::iterator peerIt1 = groupItem.peerIds.find(*peerIt);
|
||||
|
||||
if (assign)
|
||||
{
|
||||
groupItem.peerIds.insert(*peerIt);
|
||||
changed = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
groupItem.peerIds.erase(*peerIt);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (groupId.empty() == false) {
|
||||
if (!groupId.isNull())
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
|
|
|
@ -106,7 +106,7 @@ class peerState
|
|||
uint32_t maxDnRate ;
|
||||
};
|
||||
|
||||
class RsPeerGroupItem;
|
||||
class RsNodeGroupItem;
|
||||
class RsGroupInfo;
|
||||
|
||||
std::string textPeerState(peerState &state);
|
||||
|
@ -139,11 +139,12 @@ virtual bool removeAllFriendLocations(const RsPgpId &gpgid) = 0;
|
|||
/* This is solely used by p3peers - makes sense */
|
||||
|
||||
virtual bool addGroup(RsGroupInfo &groupInfo) = 0;
|
||||
virtual bool editGroup(const std::string &groupId, RsGroupInfo &groupInfo) = 0;
|
||||
virtual bool removeGroup(const std::string &groupId) = 0;
|
||||
virtual bool getGroupInfo(const std::string &groupId, RsGroupInfo &groupInfo) = 0;
|
||||
virtual bool editGroup(const RsNodeGroupId &groupId, RsGroupInfo &groupInfo) = 0;
|
||||
virtual bool removeGroup(const RsNodeGroupId &groupId) = 0;
|
||||
virtual bool getGroupInfo(const RsNodeGroupId &groupId, RsGroupInfo &groupInfo) = 0;
|
||||
virtual bool getGroupInfoByName(const std::string& groupName, RsGroupInfo &groupInfo) = 0;
|
||||
virtual bool getGroupInfoList(std::list<RsGroupInfo> &groupInfoList) = 0;
|
||||
virtual bool assignPeersToGroup(const std::string &groupId, const std::list<RsPgpId> &peerIds, bool assign) = 0;
|
||||
virtual bool assignPeersToGroup(const RsNodeGroupId &groupId, const std::list<RsPgpId> &peerIds, bool assign) = 0;
|
||||
|
||||
virtual bool resetOwnExternalAddressList() = 0 ;
|
||||
|
||||
|
@ -231,181 +232,182 @@ virtual bool locked_computeCurrentBestOwnExtAddressCandidate(sockaddr_storage
|
|||
|
||||
class p3PeerMgrIMPL: public p3PeerMgr, public p3Config
|
||||
{
|
||||
public:
|
||||
public:
|
||||
|
||||
/************************************************************************************************/
|
||||
/* EXTERNAL INTERFACE */
|
||||
/************************************************************************************************/
|
||||
/************************************************************************************************/
|
||||
/* EXTERNAL INTERFACE */
|
||||
/************************************************************************************************/
|
||||
|
||||
virtual bool addFriend(const RsPeerId&ssl_id, const RsPgpId&gpg_id, uint32_t netMode = RS_NET_MODE_UDP,
|
||||
uint16_t vsDisc = RS_VS_DISC_FULL, uint16_t vsDht = RS_VS_DHT_FULL,
|
||||
time_t lastContact = 0,ServicePermissionFlags = ServicePermissionFlags(RS_NODE_PERM_DEFAULT));
|
||||
virtual bool removeFriend(const RsPeerId &ssl_id, bool removePgpId);
|
||||
virtual bool removeFriend(const RsPgpId &pgp_id);
|
||||
virtual bool addFriend(const RsPeerId&ssl_id, const RsPgpId&gpg_id, uint32_t netMode = RS_NET_MODE_UDP,
|
||||
uint16_t vsDisc = RS_VS_DISC_FULL, uint16_t vsDht = RS_VS_DHT_FULL,
|
||||
time_t lastContact = 0,ServicePermissionFlags = ServicePermissionFlags(RS_NODE_PERM_DEFAULT));
|
||||
virtual bool removeFriend(const RsPeerId &ssl_id, bool removePgpId);
|
||||
virtual bool removeFriend(const RsPgpId &pgp_id);
|
||||
|
||||
virtual bool isFriend(const RsPeerId &ssl_id);
|
||||
virtual bool isFriend(const RsPeerId &ssl_id);
|
||||
|
||||
virtual bool getAssociatedPeers(const RsPgpId &gpg_id, std::list<RsPeerId> &ids);
|
||||
virtual bool removeAllFriendLocations(const RsPgpId &gpgid);
|
||||
virtual bool getAssociatedPeers(const RsPgpId &gpg_id, std::list<RsPeerId> &ids);
|
||||
virtual bool removeAllFriendLocations(const RsPgpId &gpgid);
|
||||
|
||||
|
||||
/******************** Groups **********************/
|
||||
/* This is solely used by p3peers - makes sense */
|
||||
/******************** Groups **********************/
|
||||
/* This is solely used by p3peers - makes sense */
|
||||
|
||||
virtual bool addGroup(RsGroupInfo &groupInfo);
|
||||
virtual bool editGroup(const std::string &groupId, RsGroupInfo &groupInfo);
|
||||
virtual bool removeGroup(const std::string &groupId);
|
||||
virtual bool getGroupInfo(const std::string &groupId, RsGroupInfo &groupInfo);
|
||||
virtual bool getGroupInfoList(std::list<RsGroupInfo> &groupInfoList);
|
||||
virtual bool assignPeersToGroup(const std::string &groupId, const std::list<RsPgpId> &peerIds, bool assign);
|
||||
virtual bool addGroup(RsGroupInfo &groupInfo);
|
||||
virtual bool editGroup(const RsNodeGroupId &groupId, RsGroupInfo &groupInfo);
|
||||
virtual bool removeGroup(const RsNodeGroupId &groupId);
|
||||
virtual bool getGroupInfo(const RsNodeGroupId &groupId, RsGroupInfo &groupInfo);
|
||||
virtual bool getGroupInfoByName(const std::string& groupName, RsGroupInfo &groupInfo) ;
|
||||
virtual bool getGroupInfoList(std::list<RsGroupInfo> &groupInfoList);
|
||||
virtual bool assignPeersToGroup(const RsNodeGroupId &groupId, const std::list<RsPgpId> &peerIds, bool assign);
|
||||
|
||||
virtual ServicePermissionFlags servicePermissionFlags(const RsPgpId& gpg_id) ;
|
||||
virtual ServicePermissionFlags servicePermissionFlags(const RsPeerId& ssl_id) ;
|
||||
virtual void setServicePermissionFlags(const RsPgpId& gpg_id,const ServicePermissionFlags& flags) ;
|
||||
virtual ServicePermissionFlags servicePermissionFlags(const RsPeerId& ssl_id) ;
|
||||
virtual void setServicePermissionFlags(const RsPgpId& gpg_id,const ServicePermissionFlags& flags) ;
|
||||
|
||||
/**************** Set Net Info ****************/
|
||||
/*
|
||||
* These functions are used by:
|
||||
* 1) p3linkmgr
|
||||
* 2) p3peers - reasonable
|
||||
* 3) p3disc - reasonable
|
||||
*/
|
||||
/**************** Set Net Info ****************/
|
||||
/*
|
||||
* These functions are used by:
|
||||
* 1) p3linkmgr
|
||||
* 2) p3peers - reasonable
|
||||
* 3) p3disc - reasonable
|
||||
*/
|
||||
|
||||
virtual bool setLocalAddress(const RsPeerId &id, const struct sockaddr_storage &addr);
|
||||
virtual bool setExtAddress(const RsPeerId &id, const struct sockaddr_storage &addr);
|
||||
virtual bool setDynDNS(const RsPeerId &id, const std::string &dyndns);
|
||||
virtual bool addCandidateForOwnExternalAddress(const RsPeerId& from, const struct sockaddr_storage &addr) ;
|
||||
virtual bool getExtAddressReportedByFriends(struct sockaddr_storage& addr, uint8_t &isstable) ;
|
||||
virtual bool setLocalAddress(const RsPeerId &id, const struct sockaddr_storage &addr);
|
||||
virtual bool setExtAddress(const RsPeerId &id, const struct sockaddr_storage &addr);
|
||||
virtual bool setDynDNS(const RsPeerId &id, const std::string &dyndns);
|
||||
virtual bool addCandidateForOwnExternalAddress(const RsPeerId& from, const struct sockaddr_storage &addr) ;
|
||||
virtual bool getExtAddressReportedByFriends(struct sockaddr_storage& addr, uint8_t &isstable) ;
|
||||
|
||||
virtual bool setNetworkMode(const RsPeerId &id, uint32_t netMode);
|
||||
virtual bool setVisState(const RsPeerId &id, uint16_t vs_disc, uint16_t vs_dht);
|
||||
virtual bool setNetworkMode(const RsPeerId &id, uint32_t netMode);
|
||||
virtual bool setVisState(const RsPeerId &id, uint16_t vs_disc, uint16_t vs_dht);
|
||||
|
||||
virtual bool setLocation(const RsPeerId &pid, const std::string &location);
|
||||
virtual bool setHiddenDomainPort(const RsPeerId &id, const std::string &domain_addr, const uint16_t domain_port);
|
||||
|
||||
virtual bool updateCurrentAddress(const RsPeerId& id, const pqiIpAddress &addr);
|
||||
virtual bool updateLastContact(const RsPeerId& id);
|
||||
virtual bool updateAddressList(const RsPeerId& id, const pqiIpAddrSet &addrs);
|
||||
virtual bool setLocation(const RsPeerId &pid, const std::string &location);
|
||||
virtual bool setHiddenDomainPort(const RsPeerId &id, const std::string &domain_addr, const uint16_t domain_port);
|
||||
|
||||
virtual bool updateCurrentAddress(const RsPeerId& id, const pqiIpAddress &addr);
|
||||
virtual bool updateLastContact(const RsPeerId& id);
|
||||
virtual bool updateAddressList(const RsPeerId& id, const pqiIpAddrSet &addrs);
|
||||
|
||||
virtual bool resetOwnExternalAddressList() ;
|
||||
|
||||
// THIS MUST ONLY BE CALLED BY NETMGR!!!!
|
||||
virtual bool UpdateOwnAddress(const struct sockaddr_storage &local_addr, const struct sockaddr_storage &ext_addr);
|
||||
/**************** Net Status Info ****************/
|
||||
/*
|
||||
* MUST RATIONALISE THE DATA FROM THESE FUNCTIONS
|
||||
* These functions are used by:
|
||||
* 1) p3face-config ... to remove!
|
||||
* 2) p3peers - reasonable
|
||||
* 3) p3disc - reasonable
|
||||
*/
|
||||
// THIS MUST ONLY BE CALLED BY NETMGR!!!!
|
||||
virtual bool UpdateOwnAddress(const struct sockaddr_storage &local_addr, const struct sockaddr_storage &ext_addr);
|
||||
/**************** Net Status Info ****************/
|
||||
/*
|
||||
* MUST RATIONALISE THE DATA FROM THESE FUNCTIONS
|
||||
* These functions are used by:
|
||||
* 1) p3face-config ... to remove!
|
||||
* 2) p3peers - reasonable
|
||||
* 3) p3disc - reasonable
|
||||
*/
|
||||
|
||||
virtual bool getOwnNetStatus(peerState &state);
|
||||
virtual bool getFriendNetStatus(const RsPeerId &id, peerState &state);
|
||||
virtual bool getOthersNetStatus(const RsPeerId &id, peerState &state);
|
||||
virtual bool getOwnNetStatus(peerState &state);
|
||||
virtual bool getFriendNetStatus(const RsPeerId &id, peerState &state);
|
||||
virtual bool getOthersNetStatus(const RsPeerId &id, peerState &state);
|
||||
|
||||
virtual bool getPeerName(const RsPeerId& ssl_id, std::string& name);
|
||||
virtual bool getGpgId(const RsPeerId& sslId, RsPgpId& gpgId);
|
||||
virtual uint32_t getConnectionType(const RsPeerId& sslId);
|
||||
virtual bool getPeerName(const RsPeerId& ssl_id, std::string& name);
|
||||
virtual bool getGpgId(const RsPeerId& sslId, RsPgpId& gpgId);
|
||||
virtual uint32_t getConnectionType(const RsPeerId& sslId);
|
||||
|
||||
virtual bool setProxyServerAddress(const uint32_t type, const struct sockaddr_storage &proxy_addr);
|
||||
virtual bool getProxyServerAddress(const uint32_t type, struct sockaddr_storage &proxy_addr);
|
||||
virtual bool getProxyServerStatus(const uint32_t type, uint32_t &proxy_status);
|
||||
virtual bool isHidden();
|
||||
virtual bool isHidden(const uint32_t type);
|
||||
virtual bool isHiddenPeer(const RsPeerId &ssl_id);
|
||||
virtual bool isHiddenPeer(const RsPeerId &ssl_id, const uint32_t type);
|
||||
virtual bool getProxyAddress(const RsPeerId& ssl_id, struct sockaddr_storage &proxy_addr, std::string &domain_addr, uint16_t &domain_port);
|
||||
virtual uint32_t hiddenDomainToHiddenType(const std::string &domain);
|
||||
virtual uint32_t getHiddenType(const RsPeerId &ssl_id);
|
||||
virtual bool setProxyServerAddress(const uint32_t type, const struct sockaddr_storage &proxy_addr);
|
||||
virtual bool getProxyServerAddress(const uint32_t type, struct sockaddr_storage &proxy_addr);
|
||||
virtual bool getProxyServerStatus(const uint32_t type, uint32_t &proxy_status);
|
||||
virtual bool isHidden();
|
||||
virtual bool isHidden(const uint32_t type);
|
||||
virtual bool isHiddenPeer(const RsPeerId &ssl_id);
|
||||
virtual bool isHiddenPeer(const RsPeerId &ssl_id, const uint32_t type);
|
||||
virtual bool getProxyAddress(const RsPeerId& ssl_id, struct sockaddr_storage &proxy_addr, std::string &domain_addr, uint16_t &domain_port);
|
||||
virtual uint32_t hiddenDomainToHiddenType(const std::string &domain);
|
||||
virtual uint32_t getHiddenType(const RsPeerId &ssl_id);
|
||||
|
||||
virtual int getFriendCount(bool ssl, bool online);
|
||||
virtual int getFriendCount(bool ssl, bool online);
|
||||
|
||||
/************* DEPRECIATED FUNCTIONS (TO REMOVE) ********/
|
||||
/************* DEPRECIATED FUNCTIONS (TO REMOVE) ********/
|
||||
|
||||
// Single Use Function... shouldn't be here. used by p3serverconfig.cc
|
||||
virtual bool haveOnceConnected();
|
||||
// Single Use Function... shouldn't be here. used by p3serverconfig.cc
|
||||
virtual bool haveOnceConnected();
|
||||
|
||||
virtual bool setMaxRates(const RsPgpId& pid,uint32_t maxUp,uint32_t maxDn);
|
||||
virtual bool getMaxRates(const RsPgpId& pid,uint32_t& maxUp,uint32_t& maxDn);
|
||||
virtual bool getMaxRates(const RsPeerId& pid,uint32_t& maxUp,uint32_t& maxDn);
|
||||
virtual bool setMaxRates(const RsPgpId& pid,uint32_t maxUp,uint32_t maxDn);
|
||||
virtual bool getMaxRates(const RsPgpId& pid,uint32_t& maxUp,uint32_t& maxDn);
|
||||
virtual bool getMaxRates(const RsPeerId& pid,uint32_t& maxUp,uint32_t& maxDn);
|
||||
|
||||
/************************************************************************************************/
|
||||
/* Extra IMPL Functions (used by p3LinkMgr, p3NetMgr + Setup) */
|
||||
/************************************************************************************************/
|
||||
/************************************************************************************************/
|
||||
/* Extra IMPL Functions (used by p3LinkMgr, p3NetMgr + Setup) */
|
||||
/************************************************************************************************/
|
||||
|
||||
p3PeerMgrIMPL( const RsPeerId& ssl_own_id,
|
||||
const RsPgpId& gpg_own_id,
|
||||
const std::string& gpg_own_name,
|
||||
const std::string& ssl_own_location) ;
|
||||
p3PeerMgrIMPL( const RsPeerId& ssl_own_id,
|
||||
const RsPgpId& gpg_own_id,
|
||||
const std::string& gpg_own_name,
|
||||
const std::string& ssl_own_location) ;
|
||||
|
||||
void setManagers(p3LinkMgrIMPL *linkMgr, p3NetMgrIMPL *netMgr);
|
||||
void setManagers(p3LinkMgrIMPL *linkMgr, p3NetMgrIMPL *netMgr);
|
||||
|
||||
bool forceHiddenNode();
|
||||
bool setupHiddenNode(const std::string &hiddenAddress, const uint16_t hiddenPort);
|
||||
bool forceHiddenNode();
|
||||
bool setupHiddenNode(const std::string &hiddenAddress, const uint16_t hiddenPort);
|
||||
|
||||
void tick();
|
||||
void tick();
|
||||
|
||||
const RsPeerId& getOwnId();
|
||||
bool setOwnNetworkMode(uint32_t netMode);
|
||||
bool setOwnVisState(uint16_t vs_disc, uint16_t vs_dht);
|
||||
const RsPeerId& getOwnId();
|
||||
bool setOwnNetworkMode(uint32_t netMode);
|
||||
bool setOwnVisState(uint16_t vs_disc, uint16_t vs_dht);
|
||||
|
||||
int getConnectAddresses(const RsPeerId &id,
|
||||
struct sockaddr_storage &lAddr, struct sockaddr_storage &eAddr,
|
||||
pqiIpAddrSet &histAddrs, std::string &dyndns);
|
||||
int getConnectAddresses(const RsPeerId &id,
|
||||
struct sockaddr_storage &lAddr, struct sockaddr_storage &eAddr,
|
||||
pqiIpAddrSet &histAddrs, std::string &dyndns);
|
||||
|
||||
|
||||
protected:
|
||||
/* Internal Functions */
|
||||
/* Internal Functions */
|
||||
|
||||
bool removeUnusedLocations();
|
||||
bool removeBannedIps();
|
||||
bool removeUnusedLocations();
|
||||
bool removeBannedIps();
|
||||
|
||||
void printPeerLists(std::ostream &out);
|
||||
void printPeerLists(std::ostream &out);
|
||||
|
||||
virtual bool locked_computeCurrentBestOwnExtAddressCandidate(sockaddr_storage &addr, uint32_t &count);
|
||||
virtual bool locked_computeCurrentBestOwnExtAddressCandidate(sockaddr_storage &addr, uint32_t &count);
|
||||
|
||||
protected:
|
||||
/*****************************************************************/
|
||||
/*********************** p3config ******************************/
|
||||
/* Key Functions to be overloaded for Full Configuration */
|
||||
virtual RsSerialiser *setupSerialiser();
|
||||
virtual bool saveList(bool &cleanup, std::list<RsItem *>&);
|
||||
virtual void saveDone();
|
||||
virtual bool loadList(std::list<RsItem *>& load);
|
||||
/*****************************************************************/
|
||||
protected:
|
||||
/*****************************************************************/
|
||||
/*********************** p3config ******************************/
|
||||
/* Key Functions to be overloaded for Full Configuration */
|
||||
virtual RsSerialiser *setupSerialiser();
|
||||
virtual bool saveList(bool &cleanup, std::list<RsItem *>&);
|
||||
virtual void saveDone();
|
||||
virtual bool loadList(std::list<RsItem *>& load);
|
||||
/*****************************************************************/
|
||||
|
||||
/* other important managers */
|
||||
/* other important managers */
|
||||
|
||||
p3LinkMgrIMPL *mLinkMgr;
|
||||
p3NetMgrIMPL *mNetMgr;
|
||||
|
||||
p3LinkMgrIMPL *mLinkMgr;
|
||||
p3NetMgrIMPL *mNetMgr;
|
||||
|
||||
private:
|
||||
RsMutex mPeerMtx; /* protects below */
|
||||
RsMutex mPeerMtx; /* protects below */
|
||||
|
||||
bool mStatusChanged;
|
||||
bool mStatusChanged;
|
||||
|
||||
std::list<pqiMonitor *> clients;
|
||||
std::list<pqiMonitor *> clients;
|
||||
|
||||
peerState mOwnState;
|
||||
peerState mOwnState;
|
||||
|
||||
std::map<RsPeerId, peerState> mFriendList; // <SSLid , peerState>
|
||||
std::map<RsPeerId, peerState> mOthersList;
|
||||
std::map<RsPeerId, peerState> mFriendList; // <SSLid , peerState>
|
||||
std::map<RsPeerId, peerState> mOthersList;
|
||||
|
||||
std::map<RsPeerId,sockaddr_storage> mReportedOwnAddresses ;
|
||||
|
||||
std::list<RsPeerGroupItem *> groupList;
|
||||
uint32_t lastGroupId;
|
||||
std::map<RsPeerId,sockaddr_storage> mReportedOwnAddresses ;
|
||||
|
||||
std::list<RsItem *> saveCleanupList; /* TEMPORARY LIST WHEN SAVING */
|
||||
std::map<RsNodeGroupId,RsGroupInfo> groupList;
|
||||
uint32_t lastGroupId;
|
||||
|
||||
std::map<RsPgpId, ServicePermissionFlags> mFriendsPermissionFlags ; // permission flags for each gpg key
|
||||
std::map<RsPgpId, PeerBandwidthLimits> mPeerBandwidthLimits ; // bandwidth limits for each gpg key
|
||||
std::list<RsItem *> saveCleanupList; /* TEMPORARY LIST WHEN SAVING */
|
||||
|
||||
struct sockaddr_storage mProxyServerAddressTor;
|
||||
struct sockaddr_storage mProxyServerAddressI2P;
|
||||
uint32_t mProxyServerStatusTor ;
|
||||
uint32_t mProxyServerStatusI2P ;
|
||||
std::map<RsPgpId, ServicePermissionFlags> mFriendsPermissionFlags ; // permission flags for each gpg key
|
||||
std::map<RsPgpId, PeerBandwidthLimits> mPeerBandwidthLimits ; // bandwidth limits for each gpg key
|
||||
|
||||
struct sockaddr_storage mProxyServerAddressTor;
|
||||
struct sockaddr_storage mProxyServerAddressI2P;
|
||||
uint32_t mProxyServerStatusTor ;
|
||||
uint32_t mProxyServerStatusI2P ;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -27,31 +27,10 @@
|
|||
#ifndef PQI_TOP_HEADER
|
||||
#define PQI_TOP_HEADER
|
||||
|
||||
/* This just includes the standard headers required.
|
||||
*/
|
||||
|
||||
|
||||
#include "pqi/pqi_base.h"
|
||||
#include "pqi/pqinetwork.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <functional>
|
||||
#include <algorithm>
|
||||
|
||||
/********************** SEARCH INTERFACE ***************************/
|
||||
// this is an interface.... so should be
|
||||
// classified as virtual = 0;
|
||||
|
||||
class SearchInterface
|
||||
{
|
||||
public:
|
||||
SearchInterface() { return; }
|
||||
|
||||
virtual ~SearchInterface() { return; }
|
||||
};
|
||||
|
||||
class P3Interface: public SearchInterface
|
||||
class P3Interface
|
||||
{
|
||||
public:
|
||||
P3Interface() {return; }
|
||||
|
@ -61,16 +40,13 @@ virtual int tick() { return 1; }
|
|||
virtual int status() { return 1; }
|
||||
|
||||
virtual int SendRsRawItem(RsRawItem *) = 0;
|
||||
#ifdef TO_BE_REMOVED
|
||||
virtual RsRawItem *GetRsRawItem() = 0;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
/* interface to allow outgoing messages to be sent directly
|
||||
* through to the pqiperson, rather than being queued
|
||||
/**
|
||||
* @brief Interface to allow outgoing messages to be sent directly through to
|
||||
* the pqiperson, rather than being queued
|
||||
*/
|
||||
|
||||
class pqiPublisher
|
||||
{
|
||||
public:
|
||||
|
@ -80,6 +56,4 @@ virtual bool sendItem(RsRawItem *item) = 0;
|
|||
};
|
||||
|
||||
|
||||
|
||||
#endif // PQI_TOP_HEADER
|
||||
|
||||
|
|
|
@ -115,6 +115,7 @@ virtual void updatePeer(const RsPeerId& id, const struct sockaddr_storage &addr
|
|||
};
|
||||
|
||||
|
||||
#ifdef RS_USE_DHT_STUNNER
|
||||
/* this is for the Stunners
|
||||
*
|
||||
*
|
||||
|
@ -132,7 +133,7 @@ virtual void setRefreshPeriod(int32_t period) = 0;
|
|||
virtual int tick() = 0; /* for internal accounting */
|
||||
|
||||
};
|
||||
|
||||
#endif // RS_USE_DHT_STUNNER
|
||||
|
||||
#define NETASSIST_KNOWN_PEER_OFFLINE 0x0001
|
||||
#define NETASSIST_KNOWN_PEER_ONLINE 0x0002
|
||||
|
|
|
@ -25,16 +25,23 @@
|
|||
|
||||
#include "pqi/pqihandler.h"
|
||||
|
||||
#include "util/rsdebug.h"
|
||||
#include "util/rsstring.h"
|
||||
#include "retroshare/rspeers.h"
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <stdlib.h> // for NULL
|
||||
#include <time.h> // for time, time_t
|
||||
#include <algorithm> // for sort
|
||||
#include <iostream> // for dec
|
||||
#include <string> // for string, char_traits, operator+, bas...
|
||||
#include <utility> // for pair
|
||||
|
||||
#include "pqi/pqi_base.h" // for PQInterface, RsBwRates
|
||||
#include "retroshare/rsconfig.h" // for RSTrafficClue
|
||||
#include "retroshare/rsids.h" // for t_RsGenericIdType
|
||||
#include "retroshare/rspeers.h" // for RsPeers, rsPeers
|
||||
#include "serialiser/rsserial.h" // for RsItem, RsRawItem
|
||||
#include "util/rsdebug.h" // for pqioutput, PQL_DEBUG_BASIC, PQL_ALERT
|
||||
#include "util/rsstring.h" // for rs_sprintf_append
|
||||
|
||||
using std::dec;
|
||||
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#ifdef WINDOWS_SYS
|
||||
#include <sys/timeb.h>
|
||||
#endif
|
||||
|
|
|
@ -26,15 +26,20 @@
|
|||
#ifndef MRK_PQI_HANDLER_HEADER
|
||||
#define MRK_PQI_HANDLER_HEADER
|
||||
|
||||
#include "pqi/pqi.h"
|
||||
#include "pqi/pqiqos.h"
|
||||
#include <stdint.h> // for uint32_t
|
||||
#include <time.h> // for time_t, NULL
|
||||
#include <list> // for list
|
||||
#include <map> // for map
|
||||
|
||||
#include "util/rsthreads.h"
|
||||
#include "retroshare/rstypes.h"
|
||||
#include "retroshare/rsconfig.h"
|
||||
#include "pqi/pqi.h" // for P3Interface, pqiPublisher
|
||||
#include "retroshare/rstypes.h" // for RsPeerId
|
||||
#include "util/rsthreads.h" // for RsStackMutex, RsMutex
|
||||
|
||||
#include <map>
|
||||
#include <list>
|
||||
class PQInterface;
|
||||
class RSTrafficClue;
|
||||
class RsBwRates;
|
||||
class RsItem;
|
||||
class RsRawItem;
|
||||
|
||||
class SearchModule
|
||||
{
|
||||
|
|
|
@ -23,9 +23,12 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "pqi/pqi.h"
|
||||
#include "pqi/pqiloopback.h"
|
||||
|
||||
#include <stddef.h> // for NULL
|
||||
|
||||
class RsItem;
|
||||
|
||||
/***
|
||||
#define LOOPBACK_DEBUG 1
|
||||
***/
|
||||
|
|
|
@ -26,12 +26,12 @@
|
|||
#ifndef MRK_PQI_LOOPBACK_HEADER
|
||||
#define MRK_PQI_LOOPBACK_HEADER
|
||||
|
||||
// The standard data types and the search interface.
|
||||
#include "pqi/pqi.h"
|
||||
#include <list> // for list
|
||||
|
||||
#include <map>
|
||||
#include <list>
|
||||
#include <iostream>
|
||||
#include "pqi/pqi_base.h" // for NetInterface (ptr only), PQInterface
|
||||
#include "retroshare/rstypes.h" // for RsPeerId
|
||||
|
||||
class RsItem;
|
||||
|
||||
class pqiloopback: public PQInterface
|
||||
{
|
||||
|
@ -47,8 +47,7 @@ virtual RsItem *GetItem();
|
|||
virtual int tick();
|
||||
virtual int status();
|
||||
|
||||
virtual int notifyEvent(NetInterface */*ni*/, int /*event*/) { return 0; } /* Not used */
|
||||
private:
|
||||
private:
|
||||
std::list<RsItem *> objs;
|
||||
};
|
||||
|
||||
|
|
|
@ -243,6 +243,7 @@ int pqiNetStateBox::updateNetState()
|
|||
|
||||
void pqiNetStateBox::clearOldNetworkData()
|
||||
{
|
||||
#ifdef RS_USE_DHT_STUNNER
|
||||
/* check if any measurements are too old to consider */
|
||||
time_t now = time(NULL);
|
||||
if (now - mStunProxyTS > NETSTATE_PARAM_TIMEOUT)
|
||||
|
@ -254,6 +255,14 @@ void pqiNetStateBox::clearOldNetworkData()
|
|||
{
|
||||
mStunDhtSet = false;
|
||||
}
|
||||
#else
|
||||
//Set values, as they are not updated.
|
||||
mStunProxySet = true;
|
||||
mStunDhtSet = true;
|
||||
mStunProxyStable = true;
|
||||
mStunDhtStable = true;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -63,8 +63,8 @@ public:
|
|||
virtual int connect(const struct sockaddr_storage &raddr) { return ni->connect(raddr); }
|
||||
virtual int listen() { return ni->listen(); }
|
||||
virtual int stoplistening() { return ni->stoplistening(); }
|
||||
virtual int reset() { return ni->reset(); }
|
||||
virtual int disconnect() { return ni->reset(); }
|
||||
virtual int reset() { pqistreamer::reset(); return ni->reset(); }
|
||||
virtual int disconnect() { return reset() ; }
|
||||
virtual bool connect_parameter(uint32_t type, uint32_t value) { return ni->connect_parameter(type, value);}
|
||||
virtual bool connect_parameter(uint32_t type, std::string value) { return ni->connect_parameter(type, value);}
|
||||
virtual bool connect_additional_address(uint32_t type, const struct sockaddr_storage &addr) { return ni->connect_additional_address(type, addr); }
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
|
||||
#include "pqiqosstreamer.h"
|
||||
|
||||
//#define DEBUG_PQIQOSSTREAMER 1
|
||||
|
||||
const float pqiQoSstreamer::PQI_QOS_STREAMER_ALPHA = 2.0f ;
|
||||
|
||||
pqiQoSstreamer::pqiQoSstreamer(PQInterface *parent, RsSerialiser *rss, const RsPeerId& peerid, BinInterface *bio_in, int bio_flagsin)
|
||||
|
@ -60,6 +62,11 @@ void pqiQoSstreamer::locked_storeInOutputQueue(void *ptr,int size,int priority)
|
|||
|
||||
void pqiQoSstreamer::locked_clear_out_queue()
|
||||
{
|
||||
#ifdef DEBUG_PQIQOSSTREAMER
|
||||
if(qos_queue_size() > 0)
|
||||
std::cerr << " pqiQoSstreamer::locked_clear_out_queue(): clearing " << qos_queue_size() << " pending outqueue elements." << std::endl;
|
||||
#endif
|
||||
|
||||
pqiQoS::clear() ;
|
||||
_total_item_size = 0 ;
|
||||
_total_item_count = 0 ;
|
||||
|
|
|
@ -1548,6 +1548,7 @@ int pqissl::senddata(void *data, int len)
|
|||
#ifdef PQISSL_DEBUG
|
||||
std::cout << "Sending data thread=" << pthread_self() << ", ssl=" << (void*)this << ", size=" << len << std::endl ;
|
||||
#endif
|
||||
ERR_clear_error();
|
||||
tmppktlen = SSL_write(ssl_connection, data, len) ;
|
||||
|
||||
if (len != tmppktlen)
|
||||
|
@ -1638,6 +1639,8 @@ int pqissl::readdata(void *data, int len)
|
|||
#ifdef PQISSL_DEBUG
|
||||
std::cerr << "calling SSL_read. len=" << len << ", total_len=" << total_len << std::endl ;
|
||||
#endif
|
||||
ERR_clear_error() ;
|
||||
|
||||
tmppktlen = SSL_read(ssl_connection, (void*)( &(((uint8_t*)data)[total_len])), len-total_len) ;
|
||||
#ifdef PQISSL_DEBUG
|
||||
std::cerr << "have read " << tmppktlen << " bytes" << std::endl ;
|
||||
|
@ -1661,8 +1664,6 @@ int pqissl::readdata(void *data, int len)
|
|||
int error = SSL_get_error(ssl_connection, tmppktlen);
|
||||
unsigned long err2 = ERR_get_error();
|
||||
|
||||
//printSSLError(ssl_connection, tmppktlen, error, err2, out);
|
||||
|
||||
if ((error == SSL_ERROR_ZERO_RETURN) && (err2 == 0))
|
||||
{
|
||||
/* this code will be called when
|
||||
|
@ -1761,7 +1762,10 @@ int pqissl::readdata(void *data, int len)
|
|||
rs_sprintf_append(out, "SSL_read() UNKNOWN ERROR: %d Resetting!", error);
|
||||
rslog(RSL_ALERT, pqisslzone, out);
|
||||
std::cerr << out << std::endl ;
|
||||
std::cerr << ", SSL_read() output is " << tmppktlen << std::endl ;
|
||||
|
||||
printSSLError(ssl_connection, tmppktlen, error, err2, out);
|
||||
|
||||
rslog(RSL_ALERT, pqisslzone, "pqissl::readdata() -> calling reset()");
|
||||
reset_locked();
|
||||
return -1;
|
||||
|
|
|
@ -24,18 +24,25 @@
|
|||
*/
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <time.h>
|
||||
#include "util/rsdebug.h"
|
||||
#include "util/rsstring.h"
|
||||
#include "util/rsprint.h"
|
||||
#include "util/rsscopetimer.h"
|
||||
|
||||
#include "pqi/pqistreamer.h"
|
||||
#include "rsserver/p3face.h"
|
||||
|
||||
#include "serialiser/rsserial.h"
|
||||
#include <stdlib.h> // for free, realloc, exit
|
||||
#include <string.h> // for memcpy, memset, memcmp
|
||||
#include <time.h> // for NULL, time, time_t
|
||||
#include <algorithm> // for min
|
||||
#include <iostream> // for operator<<, ostream, basic_ostream
|
||||
#include <string> // for string, allocator, operator<<, oper...
|
||||
#include <utility> // for pair
|
||||
|
||||
#include "pqi/p3notify.h" // for p3Notify
|
||||
#include "retroshare/rsids.h" // for operator<<
|
||||
#include "retroshare/rsnotify.h" // for RS_SYS_WARNING
|
||||
#include "rsserver/p3face.h" // for RsServer
|
||||
#include "serialiser/rsserial.h" // for RsItem, RsSerialiser, getRsItemSize
|
||||
#include "util/rsdebug.h" // for pqioutput, PQL_ALERT, PQL_DEBUG_ALL
|
||||
#include "util/rsmemory.h" // for rs_malloc
|
||||
#include "util/rsprint.h" // for BinToHex
|
||||
#include "util/rsstring.h" // for rs_sprintf_append, rs_sprintf
|
||||
|
||||
static struct RsLog::logInfo pqistreamerzoneInfo = {RsLog::Default, "pqistreamer"};
|
||||
#define pqistreamerzone &pqistreamerzoneInfo
|
||||
|
@ -135,17 +142,7 @@ pqistreamer::~pqistreamer()
|
|||
if (mRsSerialiser)
|
||||
delete mRsSerialiser;
|
||||
|
||||
// clean up outgoing. (cntrl packets)
|
||||
locked_clear_out_queue() ;
|
||||
|
||||
if (mPkt_wpending)
|
||||
{
|
||||
free(mPkt_wpending);
|
||||
mPkt_wpending = NULL;
|
||||
mPkt_wpending_size = 0 ;
|
||||
}
|
||||
|
||||
free_rpend_locked();
|
||||
free_pend_locked();
|
||||
|
||||
// clean up incoming.
|
||||
while(!mIncoming.empty())
|
||||
|
@ -156,6 +153,7 @@ pqistreamer::~pqistreamer()
|
|||
delete i;
|
||||
}
|
||||
|
||||
|
||||
if(mIncomingSize != 0)
|
||||
std::cerr << "(EE) inconsistency after deleting pqistreamer queue. Remaining items: " << mIncomingSize << std::endl;
|
||||
return;
|
||||
|
@ -282,7 +280,7 @@ int pqistreamer::tick_recv(uint32_t timeout)
|
|||
}
|
||||
if(!(mBio->isactive()))
|
||||
{
|
||||
free_rpend_locked();
|
||||
free_pend_locked();
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
@ -295,6 +293,7 @@ int pqistreamer::tick_send(uint32_t timeout)
|
|||
/* short circuit everything is bio isn't active */
|
||||
if (!(mBio->isactive()))
|
||||
{
|
||||
free_pend_locked();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -690,7 +689,7 @@ int pqistreamer::handleincoming_locked()
|
|||
if(!(mBio->isactive()))
|
||||
{
|
||||
mReading_state = reading_state_initial ;
|
||||
free_rpend_locked();
|
||||
free_pend_locked();
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
|
@ -762,7 +761,7 @@ start_packet_read:
|
|||
}
|
||||
}
|
||||
#ifdef DEBUG_PQISTREAMER
|
||||
std::cerr << "[" << (void*)pthread_self() << "] " << "block 0 : " << RsUtil::BinToHex(block,8) << std::endl;
|
||||
std::cerr << "[" << (void*)pthread_self() << "] " << "block 0 : " << RsUtil::BinToHex((unsigned char*)block,8) << std::endl;
|
||||
#endif
|
||||
|
||||
readbytes += blen;
|
||||
|
@ -806,12 +805,12 @@ continue_packet:
|
|||
else
|
||||
extralen = getRsItemSize(block) - blen; // old style packet type
|
||||
|
||||
#ifdef DEBUG_PQISTREAMER
|
||||
#ifdef DEBUG_PACKET_SLICING
|
||||
std::cerr << "[" << (void*)pthread_self() << "] " << "continuing packet getRsItemSize(block) = " << getRsItemSize(block) << std::endl ;
|
||||
std::cerr << "[" << (void*)pthread_self() << "] " << "continuing packet extralen = " << extralen << std::endl ;
|
||||
|
||||
std::cerr << "[" << (void*)pthread_self() << "] " << "continuing packet state=" << mReading_state << std::endl ;
|
||||
std::cerr << "[" << (void*)pthread_self() << "] " << "block 1 : " << RsUtil::BinToHex(block,8) << std::endl;
|
||||
std::cerr << "[" << (void*)pthread_self() << "] " << "block 1 : " << RsUtil::BinToHex((unsigned char*)block,8) << std::endl;
|
||||
#endif
|
||||
if (extralen + (uint32_t)blen > maxlen)
|
||||
{
|
||||
|
@ -874,7 +873,7 @@ continue_packet:
|
|||
|
||||
if (extralen != (uint32_t)(tmplen = mBio->readdata(extradata, extralen)))
|
||||
{
|
||||
#ifdef DEBUG_PQISTREAMER
|
||||
#ifdef DEBUG_PACKET_SLICING
|
||||
if(tmplen > 0)
|
||||
std::cerr << "[" << (void*)pthread_self() << "] " << "Incomplete packet read ! This is a real problem ;-)" << std::endl ;
|
||||
#endif
|
||||
|
@ -921,9 +920,9 @@ continue_packet:
|
|||
// we assume readdata() returned either -1 or the complete read size.
|
||||
}
|
||||
}
|
||||
#ifdef DEBUG_PQISTREAMER
|
||||
#ifdef DEBUG_PACKET_SLICING
|
||||
std::cerr << "[" << (void*)pthread_self() << "] " << "continuing packet state=" << mReading_state << std::endl ;
|
||||
std::cerr << "[" << (void*)pthread_self() << "] " << "block 2 : " << RsUtil::BinToHex(extradata,8) << std::endl;
|
||||
std::cerr << "[" << (void*)pthread_self() << "] " << "block 2 : " << RsUtil::BinToHex((unsigned char*)extradata,8) << std::endl;
|
||||
#endif
|
||||
|
||||
mFailed_read_attempts = 0 ;
|
||||
|
@ -952,7 +951,7 @@ continue_packet:
|
|||
std::cerr << "Inputing partial packet " << RsUtil::BinToHex((char*)block,8) << std::endl;
|
||||
#endif
|
||||
uint32_t packet_length = 0 ;
|
||||
pkt = addPartialPacket(block,pktlen,slice_packet_id,is_packet_starting,is_packet_ending,packet_length) ;
|
||||
pkt = addPartialPacket_locked(block,pktlen,slice_packet_id,is_packet_starting,is_packet_ending,packet_length) ;
|
||||
|
||||
pktlen = packet_length ;
|
||||
}
|
||||
|
@ -997,7 +996,7 @@ continue_packet:
|
|||
return 0;
|
||||
}
|
||||
|
||||
RsItem *pqistreamer::addPartialPacket(const void *block, uint32_t len, uint32_t slice_packet_id, bool is_packet_starting, bool is_packet_ending, uint32_t &total_len)
|
||||
RsItem *pqistreamer::addPartialPacket_locked(const void *block, uint32_t len, uint32_t slice_packet_id, bool is_packet_starting, bool is_packet_ending, uint32_t &total_len)
|
||||
{
|
||||
#ifdef DEBUG_PACKET_SLICING
|
||||
std::cerr << "Receiving partial packet. size=" << len << ", ID=" << std::hex << slice_packet_id << std::dec << ", starting:" << is_packet_starting << ", ending:" << is_packet_ending ;
|
||||
|
@ -1180,7 +1179,7 @@ void pqistreamer::outSentBytes_locked(uint32_t outb)
|
|||
#ifdef DEBUG_PQISTREAMER
|
||||
{
|
||||
std::string out;
|
||||
rs_sprintf(out, "pqistreamer::outSentBytes(): %d@%gkB/s", outb, getRate(false));
|
||||
rs_sprintf(out, "pqistreamer::outSentBytes(): %d@%gkB/s", outb, RateInterface::getRate(false));
|
||||
pqioutput(PQL_DEBUG_ALL, pqistreamerzone, out);
|
||||
}
|
||||
#endif
|
||||
|
@ -1210,7 +1209,7 @@ void pqistreamer::inReadBytes_locked(uint32_t inb)
|
|||
#ifdef DEBUG_PQISTREAMER
|
||||
{
|
||||
std::string out;
|
||||
rs_sprintf(out, "pqistreamer::inReadBytes(): %d@%gkB/s", inb, getRate(true));
|
||||
rs_sprintf(out, "pqistreamer::inReadBytes(): %d@%gkB/s", inb, RateInterface::getRate(true));
|
||||
pqioutput(PQL_DEBUG_ALL, pqistreamerzone, out);
|
||||
}
|
||||
#endif
|
||||
|
@ -1237,14 +1236,53 @@ void pqistreamer::allocate_rpend_locked()
|
|||
memset(mPkt_rpending,0,mPkt_rpend_size) ;
|
||||
}
|
||||
|
||||
void pqistreamer::free_rpend_locked()
|
||||
{
|
||||
if(!mPkt_rpending)
|
||||
return;
|
||||
// clean everything that is half-finished, to avoid causing issues when re-connecting later on.
|
||||
|
||||
free(mPkt_rpending);
|
||||
mPkt_rpending = 0;
|
||||
mPkt_rpend_size = 0;
|
||||
int pqistreamer::reset()
|
||||
{
|
||||
RsStackMutex stack(mStreamerMtx); /**** LOCKED MUTEX ****/
|
||||
#ifdef DEBUG_PQISTREAMER
|
||||
std::cerr << "pqistreamer::reset()" << std::endl;
|
||||
#endif
|
||||
free_pend_locked();
|
||||
|
||||
return 1 ;
|
||||
}
|
||||
|
||||
void pqistreamer::free_pend_locked()
|
||||
{
|
||||
if(mPkt_rpending)
|
||||
{
|
||||
#ifdef DEBUG_PQISTREAMER
|
||||
std::cerr << "pqistreamer::free_pend_locked(): pending input packet buffer" << std::endl;
|
||||
#endif
|
||||
free(mPkt_rpending);
|
||||
mPkt_rpending = 0;
|
||||
}
|
||||
mPkt_rpend_size = 0;
|
||||
|
||||
if (mPkt_wpending)
|
||||
{
|
||||
#ifdef DEBUG_PQISTREAMER
|
||||
std::cerr << "pqistreamer::free_pend_locked(): pending output packet buffer" << std::endl;
|
||||
#endif
|
||||
free(mPkt_wpending);
|
||||
mPkt_wpending = NULL;
|
||||
}
|
||||
mPkt_wpending_size = 0 ;
|
||||
|
||||
#ifdef DEBUG_PQISTREAMER
|
||||
if(!mPartialPackets.empty())
|
||||
std::cerr << "pqistreamer::free_pend_locked(): " << mPartialPackets.size() << " pending input partial packets" << std::endl;
|
||||
#endif
|
||||
// also delete any incoming partial packet
|
||||
for(std::map<uint32_t,PartialPacketRecord>::iterator it(mPartialPackets.begin());it!=mPartialPackets.end();++it)
|
||||
free(it->second.mem) ;
|
||||
|
||||
mPartialPackets.clear() ;
|
||||
|
||||
// clean up outgoing. (cntrl packets)
|
||||
locked_clear_out_queue() ;
|
||||
}
|
||||
|
||||
int pqistreamer::gatherStatistics(std::list<RSTrafficClue>& outqueue_lst,std::list<RSTrafficClue>& inqueue_lst)
|
||||
|
|
|
@ -27,18 +27,19 @@
|
|||
#ifndef MRK_PQI_STREAMER_HEADER
|
||||
#define MRK_PQI_STREAMER_HEADER
|
||||
|
||||
// Only dependent on the base stuff.
|
||||
#include "pqi/pqi_base.h"
|
||||
#include "util/rsthreads.h"
|
||||
#include "retroshare/rstypes.h"
|
||||
#include <stdint.h> // for uint32_t
|
||||
#include <time.h> // for time_t
|
||||
#include <iostream> // for operator<<, basic_ostream, cerr, endl
|
||||
#include <list> // for list
|
||||
#include <map> // for map
|
||||
|
||||
#include <list>
|
||||
#include "pqi/pqi_base.h" // for BinInterface (ptr only), PQInterface
|
||||
#include "retroshare/rsconfig.h" // for RSTrafficClue
|
||||
#include "retroshare/rstypes.h" // for RsPeerId
|
||||
#include "util/rsthreads.h" // for RsMutex
|
||||
|
||||
// Fully implements the PQInterface.
|
||||
// and communicates with peer etc via the BinInterface.
|
||||
//
|
||||
// The interface does not handle connection, just communication.
|
||||
// possible bioflags: BIN_FLAGS_NO_CLOSE | BIN_FLAGS_NO_DELETE
|
||||
class RsItem;
|
||||
class RsSerialiser;
|
||||
|
||||
struct PartialPacketRecord
|
||||
{
|
||||
|
@ -46,6 +47,12 @@ struct PartialPacketRecord
|
|||
uint32_t size ;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Fully implements the PQInterface and communicates with peer etc via
|
||||
* the BinInterface.
|
||||
* The interface does not handle connection, just communication.
|
||||
* Possible BIN_FLAGS: BIN_FLAGS_NO_CLOSE | BIN_FLAGS_NO_DELETE
|
||||
*/
|
||||
class pqistreamer: public PQInterface
|
||||
{
|
||||
public:
|
||||
|
@ -74,6 +81,7 @@ class pqistreamer: public PQInterface
|
|||
virtual float getRate(bool b) ;
|
||||
|
||||
protected:
|
||||
virtual int reset() ;
|
||||
|
||||
int tick_bio();
|
||||
int tick_send(uint32_t timeout);
|
||||
|
@ -117,7 +125,8 @@ class pqistreamer: public PQInterface
|
|||
int inAllowedBytes_locked();
|
||||
void inReadBytes_locked(uint32_t );
|
||||
|
||||
|
||||
// cleans up everything that's pending / half finished.
|
||||
void free_pend_locked();
|
||||
|
||||
// RsSerialiser - determines which packets can be serialised.
|
||||
RsSerialiser *mRsSerialiser;
|
||||
|
@ -126,7 +135,7 @@ class pqistreamer: public PQInterface
|
|||
uint32_t mPkt_wpending_size; // ... and its size.
|
||||
|
||||
void allocate_rpend_locked(); // use these two functions to allocate/free the buffer below
|
||||
void free_rpend_locked();
|
||||
|
||||
int mPkt_rpend_size; // size of pkt_rpending.
|
||||
void *mPkt_rpending; // storage for read in pending packets.
|
||||
|
||||
|
@ -170,7 +179,7 @@ class pqistreamer: public PQInterface
|
|||
bool mAcceptsPacketSlicing ;
|
||||
time_t mLastSentPacketSlicingProbe ;
|
||||
void locked_addTrafficClue(const RsItem *pqi, uint32_t pktsize, std::list<RSTrafficClue> &lst);
|
||||
RsItem *addPartialPacket(const void *block, uint32_t len, uint32_t slice_packet_id,bool packet_starting,bool packet_ending,uint32_t& total_len);
|
||||
RsItem *addPartialPacket_locked(const void *block, uint32_t len, uint32_t slice_packet_id,bool packet_starting,bool packet_ending,uint32_t& total_len);
|
||||
|
||||
std::map<uint32_t,PartialPacketRecord> mPartialPackets ;
|
||||
};
|
||||
|
|
|
@ -99,7 +99,7 @@ struct SharedDirInfo
|
|||
std::string filename ;
|
||||
std::string virtualname ;
|
||||
FileStorageFlags shareflags ; // DIR_FLAGS_NETWORK_WIDE_OTHERS | DIR_FLAGS_BROWSABLE_GROUPS | ...
|
||||
std::list<std::string> parent_groups ;
|
||||
std::list<RsNodeGroupId> parent_groups ;
|
||||
};
|
||||
|
||||
class RsFiles
|
||||
|
|
|
@ -103,9 +103,6 @@ public:
|
|||
//===================================================//
|
||||
|
||||
virtual void addRoutingClue(const GRouterKeyId& destination, const RsPeerId& source) =0;
|
||||
virtual void addTrackingInfo(const RsGxsMessageId& mid,const RsPeerId& peer_id) =0;
|
||||
|
||||
virtual bool getTrackingInfo(const RsGxsMessageId& mid, RsPeerId& provider_id) =0;
|
||||
};
|
||||
|
||||
// To access the GRouter from anywhere
|
||||
|
|
|
@ -33,7 +33,8 @@ namespace GXS_SERV {
|
|||
static const uint32_t FLAG_AUTHOR_AUTHENTICATION_GPG = 0x00000100;
|
||||
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;
|
||||
static const uint32_t FLAG_AUTHOR_AUTHENTICATION_TRACK_MESSAGES = 0x00000800; // not used anymore
|
||||
static const uint32_t FLAG_AUTHOR_AUTHENTICATION_GPG_KNOWN = 0x00001000;
|
||||
|
||||
static const uint32_t FLAG_GROUP_SIGN_PUBLISH_MASK = 0x000000ff;
|
||||
static const uint32_t FLAG_GROUP_SIGN_PUBLISH_ENCRYPTED = 0x00000001;
|
||||
|
@ -105,6 +106,7 @@ namespace GXS_SERV {
|
|||
#define IS_MSG_UNPROCESSED(status) (status & GXS_SERV::GXS_MSG_STATUS_UNPROCESSED)
|
||||
|
||||
#define IS_GROUP_PGP_AUTHED(signFlags) (signFlags & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_GPG)
|
||||
#define IS_GROUP_PGP_KNOWN_AUTHED(signFlags) (signFlags & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_GPG_KNOWN)
|
||||
#define IS_GROUP_MESSAGE_TRACKING(signFlags) (signFlags & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_TRACK_MESSAGES)
|
||||
|
||||
#define IS_GROUP_ADMIN(subscribeFlags) (subscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_ADMIN)
|
||||
|
|
|
@ -62,6 +62,7 @@ extern RsIdentity *rsIdentity;
|
|||
|
||||
// Unicode symbols. NOT utf-8 bytes, because of multi byte characters
|
||||
#define RSID_MAXIMUM_NICKNAME_SIZE 30
|
||||
#define RSID_MINIMUM_NICKNAME_SIZE 2
|
||||
|
||||
std::string rsIdTypeToString(uint32_t idtype);
|
||||
|
||||
|
@ -221,46 +222,48 @@ public:
|
|||
RsIdentity(RsGxsIface *gxs): RsGxsIfaceHelper(gxs) { return; }
|
||||
virtual ~RsIdentity() { return; }
|
||||
|
||||
/********************************************************************************************/
|
||||
/********************************************************************************************/
|
||||
|
||||
// For Other Services....
|
||||
// It should be impossible for them to get a message which we don't have the identity.
|
||||
// Its a major error if we don't have the identity.
|
||||
/********************************************************************************************/
|
||||
/********************************************************************************************/
|
||||
|
||||
// We cache all identities, and provide alternative (instantaneous)
|
||||
// functions to extract info, rather than the standard Token system.
|
||||
// For Other Services....
|
||||
// It should be impossible for them to get a message which we don't have the identity.
|
||||
// Its a major error if we don't have the identity.
|
||||
|
||||
//virtual bool getNickname(const RsGxsId &id, std::string &nickname) = 0;
|
||||
virtual bool getIdDetails(const RsGxsId &id, RsIdentityDetails &details) = 0;
|
||||
// We cache all identities, and provide alternative (instantaneous)
|
||||
// functions to extract info, rather than the standard Token system.
|
||||
|
||||
// Fills up list of all own ids. Returns false if ids are not yet loaded.
|
||||
virtual bool getOwnIds(std::list<RsGxsId> &ownIds) = 0;
|
||||
virtual bool isOwnId(const RsGxsId& id) = 0;
|
||||
//virtual bool getNickname(const RsGxsId &id, std::string &nickname) = 0;
|
||||
virtual bool getIdDetails(const RsGxsId &id, RsIdentityDetails &details) = 0;
|
||||
|
||||
//
|
||||
virtual bool submitOpinion(uint32_t& token, const RsGxsId &id,
|
||||
bool absOpinion, int score) = 0;
|
||||
virtual bool createIdentity(uint32_t& token, RsIdentityParameters ¶ms) = 0;
|
||||
// Fills up list of all own ids. Returns false if ids are not yet loaded.
|
||||
virtual bool getOwnIds(std::list<RsGxsId> &ownIds) = 0;
|
||||
virtual bool isOwnId(const RsGxsId& id) = 0;
|
||||
|
||||
virtual bool updateIdentity(uint32_t& token, RsGxsIdGroup &group) = 0;
|
||||
virtual bool deleteIdentity(uint32_t& token, RsGxsIdGroup &group) = 0;
|
||||
//
|
||||
virtual bool submitOpinion(uint32_t& token, const RsGxsId &id,
|
||||
bool absOpinion, int score) = 0;
|
||||
virtual bool createIdentity(uint32_t& token, RsIdentityParameters ¶ms) = 0;
|
||||
|
||||
virtual bool parseRecognTag(const RsGxsId &id, const std::string &nickname,
|
||||
const std::string &tag, RsRecognTagDetails &details) = 0;
|
||||
virtual bool getRecognTagRequest(const RsGxsId &id, const std::string &comment,
|
||||
uint16_t tag_class, uint16_t tag_type, std::string &tag) = 0;
|
||||
virtual bool updateIdentity(uint32_t& token, RsGxsIdGroup &group) = 0;
|
||||
virtual bool deleteIdentity(uint32_t& token, RsGxsIdGroup &group) = 0;
|
||||
|
||||
virtual bool parseRecognTag(const RsGxsId &id, const std::string &nickname,
|
||||
const std::string &tag, RsRecognTagDetails &details) = 0;
|
||||
virtual bool getRecognTagRequest(const RsGxsId &id, const std::string &comment,
|
||||
uint16_t tag_class, uint16_t tag_type, std::string &tag) = 0;
|
||||
|
||||
virtual bool setAsRegularContact(const RsGxsId& id,bool is_a_contact) = 0 ;
|
||||
virtual bool isARegularContact(const RsGxsId& id) = 0 ;
|
||||
|
||||
// Specific RsIdentity Functions....
|
||||
/* Specific Service Data */
|
||||
/* We expose these initially for testing / GUI purposes.
|
||||
virtual bool isBanned(const RsGxsId& id) =0;
|
||||
virtual time_t getLastUsageTS(const RsGxsId &id) =0;
|
||||
|
||||
// Specific RsIdentity Functions....
|
||||
/* Specific Service Data */
|
||||
/* We expose these initially for testing / GUI purposes.
|
||||
*/
|
||||
|
||||
virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsIdGroup> &groups) = 0;
|
||||
//virtual bool getMsgData(const uint32_t &token, std::vector<RsGxsIdOpinion> &opinions) = 0;
|
||||
virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsIdGroup> &groups) = 0;
|
||||
//virtual bool getMsgData(const uint32_t &token, std::vector<RsGxsIdOpinion> &opinions) = 0;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -73,14 +73,13 @@ template<uint32_t ID_SIZE_IN_BYTES,bool UPPER_CASE,uint32_t UNIQUE_IDENTIFIER> c
|
|||
memcpy(bytes,id.toByteArray(),ID_SIZE_IN_BYTES) ;
|
||||
}
|
||||
|
||||
// Random initialization. Can be useful for testing.
|
||||
// Random initialization. Can be useful for testing and to generate new ids.
|
||||
//
|
||||
static t_RsGenericIdType<ID_SIZE_IN_BYTES,UPPER_CASE,UNIQUE_IDENTIFIER> random()
|
||||
{
|
||||
t_RsGenericIdType<ID_SIZE_IN_BYTES,UPPER_CASE,UNIQUE_IDENTIFIER> id ;
|
||||
|
||||
for(uint32_t i=0;i<ID_SIZE_IN_BYTES;++i)
|
||||
id.bytes[i] = RSRandom::random_u32() & 0xff ;
|
||||
RSRandom::random_bytes(id.bytes,ID_SIZE_IN_BYTES) ;
|
||||
|
||||
return id ;
|
||||
}
|
||||
|
@ -163,8 +162,8 @@ template<uint32_t ID_SIZE_IN_BYTES,bool UPPER_CASE,uint32_t UNIQUE_IDENTIFIER> t
|
|||
int n=0;
|
||||
if(s.length() != ID_SIZE_IN_BYTES*2)
|
||||
{
|
||||
if(!s.empty())
|
||||
std::cerr << "t_RsGenericIdType<>::t_RsGenericIdType(std::string&): supplied string in constructor has wrong size. Expected ID size=" << ID_SIZE_IN_BYTES << " String=\"" << s << "\"" << std::endl;
|
||||
if(!s.empty())
|
||||
std::cerr << "t_RsGenericIdType<>::t_RsGenericIdType(std::string&): supplied string in constructor has wrong size. Expected ID size=" << ID_SIZE_IN_BYTES*2 << " String=\"" << s << "\" = " << s.length() << std::endl;
|
||||
|
||||
clear();
|
||||
return;
|
||||
|
@ -220,6 +219,7 @@ static const uint32_t RS_GENERIC_ID_GXS_CIRCLE_ID_TYPE = 0x0008 ;
|
|||
static const uint32_t RS_GENERIC_ID_GROUTER_ID_TYPE = 0x0009 ;
|
||||
static const uint32_t RS_GENERIC_ID_GXS_TUNNEL_ID_TYPE = 0x0010 ;
|
||||
static const uint32_t RS_GENERIC_ID_GXS_DISTANT_CHAT_ID_TYPE = 0x0011 ;
|
||||
static const uint32_t RS_GENERIC_ID_NODE_GROUP_ID_TYPE = 0x0012 ;
|
||||
|
||||
typedef t_RsGenericIdType< SSL_ID_SIZE , false, RS_GENERIC_ID_SSL_ID_TYPE> SSLIdType ;
|
||||
typedef t_RsGenericIdType< PGP_KEY_ID_SIZE , true, RS_GENERIC_ID_PGP_ID_TYPE> PGPIdType ;
|
||||
|
@ -231,4 +231,5 @@ typedef t_RsGenericIdType< CERT_SIGN_LEN , false, RS_GENERIC_ID_GXS_I
|
|||
typedef t_RsGenericIdType< CERT_SIGN_LEN , false, RS_GENERIC_ID_GXS_CIRCLE_ID_TYPE > GXSCircleId ;
|
||||
typedef t_RsGenericIdType< SSL_ID_SIZE , false, RS_GENERIC_ID_GXS_TUNNEL_ID_TYPE > GXSTunnelId ;
|
||||
typedef t_RsGenericIdType< SSL_ID_SIZE , false, RS_GENERIC_ID_GXS_DISTANT_CHAT_ID_TYPE > DistantChatPeerId ;
|
||||
typedef t_RsGenericIdType< CERT_SIGN_LEN , false, RS_GENERIC_ID_NODE_GROUP_ID_TYPE > RsNodeGroupId ;
|
||||
|
||||
|
|
|
@ -229,12 +229,12 @@ class NotifyClient
|
|||
virtual void notifyPeerStatusChangedSummary () {}
|
||||
virtual void notifyDiscInfoChanged () {}
|
||||
|
||||
virtual bool askForDeferredSelfSignature (const void * /* data */, const uint32_t /* len */, unsigned char * /* sign */, unsigned int * /* signlen */,int& signature_result ) { signature_result = false ;return true; }
|
||||
virtual bool askForDeferredSelfSignature (const void * /* data */, const uint32_t /* len */, unsigned char * /* sign */, unsigned int * /* signlen */,int& signature_result , std::string /*reason = ""*/) { signature_result = false ;return true; }
|
||||
virtual void notifyDownloadComplete (const std::string& /* fileHash */) {}
|
||||
virtual void notifyDownloadCompleteCount (uint32_t /* count */) {}
|
||||
virtual void notifyHistoryChanged (uint32_t /* msgId */, int /* type */) {}
|
||||
|
||||
virtual bool askForPassword (const std::string& /* key_details */, bool /* prev_is_bad */, std::string& /* password */,bool& /* cancelled */ ) { return false ;}
|
||||
virtual bool askForPassword (const std::string& /* title */, const std::string& /* key_details */, bool /* prev_is_bad */, std::string& /* password */,bool& /* cancelled */ ) { return false ;}
|
||||
virtual bool askForPluginConfirmation (const std::string& /* plugin_filename */, const std::string& /* plugin_file_hash */) { return false ;}
|
||||
|
||||
};
|
||||
|
|
|
@ -185,11 +185,17 @@ const uint32_t RS_NET_PROXY_STATUS_OK = 0x0001 ;
|
|||
|
||||
|
||||
/* Groups */
|
||||
#define RS_GROUP_ID_FRIENDS "Friends"
|
||||
#define RS_GROUP_ID_FAMILY "Family"
|
||||
#define RS_GROUP_ID_COWORKERS "Co-Workers"
|
||||
#define RS_GROUP_ID_OTHERS "Other Contacts"
|
||||
#define RS_GROUP_ID_FAVORITES "Favorites"
|
||||
static const RsNodeGroupId RS_GROUP_ID_FRIENDS ("00000000000000000000000000000001");
|
||||
static const RsNodeGroupId RS_GROUP_ID_FAMILY ("00000000000000000000000000000002");
|
||||
static const RsNodeGroupId RS_GROUP_ID_COWORKERS ("00000000000000000000000000000003");
|
||||
static const RsNodeGroupId RS_GROUP_ID_OTHERS ("00000000000000000000000000000004");
|
||||
static const RsNodeGroupId RS_GROUP_ID_FAVORITES ("00000000000000000000000000000005");
|
||||
|
||||
#define RS_GROUP_DEFAULT_NAME_FRIENDS "Friends"
|
||||
#define RS_GROUP_DEFAULT_NAME_FAMILY "Family"
|
||||
#define RS_GROUP_DEFAULT_NAME_COWORKERS "Co-Workers"
|
||||
#define RS_GROUP_DEFAULT_NAME_OTHERS "Other Contacts"
|
||||
#define RS_GROUP_DEFAULT_NAME_FAVORITES "Favorites"
|
||||
|
||||
const uint32_t RS_GROUP_FLAG_STANDARD = 0x0001;
|
||||
|
||||
|
@ -295,7 +301,7 @@ class RsGroupInfo
|
|||
public:
|
||||
RsGroupInfo();
|
||||
|
||||
std::string id;
|
||||
RsNodeGroupId id;
|
||||
std::string name;
|
||||
uint32_t flag;
|
||||
|
||||
|
@ -346,7 +352,7 @@ public:
|
|||
virtual bool getGPGValidList(std::list<RsPgpId> &gpg_ids) = 0;
|
||||
virtual bool getGPGAllList(std::list<RsPgpId> &gpg_ids) = 0;
|
||||
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) = 0;
|
||||
virtual bool gpgSignData(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen, std::string reason = "") = 0;
|
||||
|
||||
/* Add/Remove Friends */
|
||||
virtual bool addFriend(const RsPeerId &ssl_id, const RsPgpId &gpg_id,ServicePermissionFlags flags = RS_NODE_PERM_DEFAULT) = 0;
|
||||
|
@ -399,14 +405,15 @@ public:
|
|||
virtual bool trustGPGCertificate(const RsPgpId &gpg_id, uint32_t trustlvl) = 0;
|
||||
|
||||
/* Group Stuff */
|
||||
virtual bool addGroup(RsGroupInfo &groupInfo) = 0;
|
||||
virtual bool editGroup(const std::string &groupId, RsGroupInfo &groupInfo) = 0;
|
||||
virtual bool removeGroup(const std::string &groupId) = 0;
|
||||
virtual bool getGroupInfo(const std::string &groupId, RsGroupInfo &groupInfo) = 0;
|
||||
virtual bool getGroupInfoList(std::list<RsGroupInfo> &groupInfoList) = 0;
|
||||
virtual bool addGroup(RsGroupInfo& groupInfo) = 0;
|
||||
virtual bool editGroup(const RsNodeGroupId& groupId, RsGroupInfo& groupInfo) = 0;
|
||||
virtual bool removeGroup(const RsNodeGroupId& groupId) = 0;
|
||||
virtual bool getGroupInfo(const RsNodeGroupId& groupId, RsGroupInfo& groupInfo) = 0;
|
||||
virtual bool getGroupInfoByName(const std::string& groupId, RsGroupInfo& groupInfo) = 0;
|
||||
virtual bool getGroupInfoList(std::list<RsGroupInfo>& groupInfoList) = 0;
|
||||
// groupId == "" && assign == false -> remove from all groups
|
||||
virtual bool assignPeerToGroup(const std::string &groupId, const RsPgpId& peerId, bool assign) = 0;
|
||||
virtual bool assignPeersToGroup(const std::string &groupId, const std::list<RsPgpId> &peerIds, bool assign) = 0;
|
||||
virtual bool assignPeerToGroup(const RsNodeGroupId& groupId, const RsPgpId& peerId, bool assign) = 0;
|
||||
virtual bool assignPeersToGroup(const RsNodeGroupId& groupId, const std::list<RsPgpId>& peerIds, bool assign) = 0;
|
||||
|
||||
/* Group sharing permission */
|
||||
|
||||
|
@ -421,7 +428,7 @@ public:
|
|||
//
|
||||
virtual FileSearchFlags computePeerPermissionFlags(
|
||||
const RsPeerId& peer_id, FileStorageFlags file_sharing_flags,
|
||||
const std::list<std::string>& file_parent_groups) = 0;
|
||||
const std::list<RsNodeGroupId>& file_parent_groups) = 0;
|
||||
|
||||
/* Service permission flags */
|
||||
|
||||
|
|
|
@ -83,6 +83,7 @@ virtual ~RsPosted() { return; }
|
|||
|
||||
/* Specific Service Data */
|
||||
virtual bool getGroupData(const uint32_t &token, std::vector<RsPostedGroup> &groups) = 0;
|
||||
virtual bool getPostData(const uint32_t &token, std::vector<RsPostedPost> &posts, std::vector<RsGxsComment> &cmts) = 0;
|
||||
virtual bool getPostData(const uint32_t &token, std::vector<RsPostedPost> &posts) = 0;
|
||||
//Not currently used
|
||||
//virtual bool getRelatedPosts(const uint32_t &token, std::vector<RsPostedPost> &posts) = 0;
|
||||
|
|
|
@ -50,14 +50,25 @@ public:
|
|||
};
|
||||
|
||||
virtual bool setOwnOpinion(const RsGxsId& key_id, const Opinion& op) =0;
|
||||
virtual bool getReputationInfo(const RsGxsId& id,ReputationInfo& info) =0 ;
|
||||
virtual void setNodeAutoBanThreshold(uint32_t n) =0;
|
||||
virtual uint32_t nodeAutoBanThreshold() =0;
|
||||
|
||||
virtual bool getReputationInfo(const RsGxsId& id, const RsPgpId &ownerNode, ReputationInfo& info) =0;
|
||||
|
||||
// parameters
|
||||
|
||||
// virtual void setNodeAutoBanThreshold(uint32_t n) =0;
|
||||
// virtual uint32_t nodeAutoBanThreshold() =0;
|
||||
|
||||
virtual void setNodeAutoPositiveOpinionForContacts(bool b) =0;
|
||||
virtual bool nodeAutoPositiveOpinionForContacts() =0;
|
||||
virtual float nodeAutoBanIdentitiesLimit() =0;
|
||||
virtual void setNodeAutoBanIdentitiesLimit(float f) =0;
|
||||
|
||||
// This one is a proxy designed to allow fast checking of a GXS id.
|
||||
// it basically returns true if assessment is not ASSESSMENT_OK
|
||||
|
||||
virtual bool isIdentityBanned(const RsGxsId& id) =0;
|
||||
virtual bool isIdentityBanned(const RsGxsId& id) =0;
|
||||
|
||||
virtual bool isNodeBanned(const RsPgpId& id) =0;
|
||||
virtual void banNode(const RsPgpId& id,bool b) =0;
|
||||
};
|
||||
|
||||
// To access reputations from anywhere
|
||||
|
|
|
@ -212,7 +212,7 @@ class FileInfo
|
|||
DwlSpeed priority ;
|
||||
time_t lastTS;
|
||||
|
||||
std::list<std::string> parent_groups ;
|
||||
std::list<RsNodeGroupId> parent_groups ;
|
||||
};
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const FileInfo& info);
|
||||
|
@ -236,14 +236,14 @@ public:
|
|||
RsPeerId id;
|
||||
std::string name;
|
||||
RsFileHash hash;
|
||||
std::string path;
|
||||
uint64_t count;
|
||||
uint32_t age;
|
||||
FileStorageFlags flags;
|
||||
uint32_t min_age ; // minimum age of files in this subtree
|
||||
std::string path;
|
||||
uint64_t count;
|
||||
uint32_t age;
|
||||
FileStorageFlags flags;
|
||||
uint32_t min_age ; // minimum age of files in this subtree
|
||||
|
||||
std::vector<DirStub> children;
|
||||
std::list<std::string> parent_groups; // parent groups for the shared directory
|
||||
std::list<DirStub> children;
|
||||
std::list<RsNodeGroupId> parent_groups; // parent groups for the shared directory
|
||||
};
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const DirDetails& details);
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
#define RS_MAJOR_VERSION 0
|
||||
#define RS_MINOR_VERSION 6
|
||||
#define RS_BUILD_NUMBER 0
|
||||
#define RS_BUILD_NUMBER 1
|
||||
#define RS_BUILD_NUMBER_ADD "x" // <-- do we need this?
|
||||
|
||||
// The revision number should be the 4 first bytes of the git revision hash, which is obtained using:
|
||||
// git log --pretty="%H" | head -1 | cut -c1-8
|
||||
//
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#define RS_MAJOR_VERSION 0
|
||||
#define RS_MINOR_VERSION 6
|
||||
#define RS_BUILD_NUMBER 0
|
||||
#define RS_BUILD_NUMBER 1
|
||||
#define RS_BUILD_NUMBER_ADD ""
|
||||
|
||||
// The revision number should be the 4 first bytes of the git revision hash, which is obtained using:
|
||||
|
|
|
@ -635,9 +635,9 @@ bool p3Peers::getAssociatedSSLIds(const RsPgpId &gpg_id, std::list<RsPeerId> &id
|
|||
return mPeerMgr->getAssociatedPeers(gpg_id, ids);
|
||||
}
|
||||
|
||||
bool p3Peers::gpgSignData(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen)
|
||||
bool p3Peers::gpgSignData(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen, std::string reason /* = "" */)
|
||||
{
|
||||
return AuthGPG::getAuthGPG()->SignDataBin(data,len,sign,signlen);
|
||||
return AuthGPG::getAuthGPG()->SignDataBin(data,len,sign,signlen, reason);
|
||||
}
|
||||
|
||||
bool p3Peers::getGPGDetails(const RsPgpId &pgp_id, RsPeerDetails &d)
|
||||
|
@ -1280,7 +1280,7 @@ bool p3Peers::addGroup(RsGroupInfo &groupInfo)
|
|||
return res ;
|
||||
}
|
||||
|
||||
bool p3Peers::editGroup(const std::string &groupId, RsGroupInfo &groupInfo)
|
||||
bool p3Peers::editGroup(const RsNodeGroupId &groupId, RsGroupInfo &groupInfo)
|
||||
{
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::editGroup()" << std::endl;
|
||||
|
@ -1292,7 +1292,7 @@ bool p3Peers::editGroup(const std::string &groupId, RsGroupInfo &groupInfo)
|
|||
return res ;
|
||||
}
|
||||
|
||||
bool p3Peers::removeGroup(const std::string &groupId)
|
||||
bool p3Peers::removeGroup(const RsNodeGroupId &groupId)
|
||||
{
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::removeGroup()" << std::endl;
|
||||
|
@ -1303,7 +1303,15 @@ bool p3Peers::removeGroup(const std::string &groupId)
|
|||
return res ;
|
||||
}
|
||||
|
||||
bool p3Peers::getGroupInfo(const std::string &groupId, RsGroupInfo &groupInfo)
|
||||
bool p3Peers::getGroupInfoByName(const std::string& groupName, RsGroupInfo &groupInfo)
|
||||
{
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::getGroupInfo()" << std::endl;
|
||||
#endif
|
||||
|
||||
return mPeerMgr->getGroupInfoByName(groupName, groupInfo);
|
||||
}
|
||||
bool p3Peers::getGroupInfo(const RsNodeGroupId &groupId, RsGroupInfo &groupInfo)
|
||||
{
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::getGroupInfo()" << std::endl;
|
||||
|
@ -1321,7 +1329,7 @@ bool p3Peers::getGroupInfoList(std::list<RsGroupInfo> &groupInfoList)
|
|||
return mPeerMgr->getGroupInfoList(groupInfoList);
|
||||
}
|
||||
|
||||
bool p3Peers::assignPeerToGroup(const std::string &groupId, const RsPgpId& peerId, bool assign)
|
||||
bool p3Peers::assignPeerToGroup(const RsNodeGroupId &groupId, const RsPgpId& peerId, bool assign)
|
||||
{
|
||||
std::list<RsPgpId> peerIds;
|
||||
peerIds.push_back(peerId);
|
||||
|
@ -1329,7 +1337,7 @@ bool p3Peers::assignPeerToGroup(const std::string &groupId, const RsPgpId& peerI
|
|||
return assignPeersToGroup(groupId, peerIds, assign);
|
||||
}
|
||||
|
||||
bool p3Peers::assignPeersToGroup(const std::string &groupId, const std::list<RsPgpId> &peerIds, bool assign)
|
||||
bool p3Peers::assignPeersToGroup(const RsNodeGroupId &groupId, const std::list<RsPgpId> &peerIds, bool assign)
|
||||
{
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::assignPeersToGroup()" << std::endl;
|
||||
|
@ -1343,7 +1351,7 @@ bool p3Peers::assignPeersToGroup(const std::string &groupId, const std::list<RsP
|
|||
|
||||
FileSearchFlags p3Peers::computePeerPermissionFlags(const RsPeerId& peer_ssl_id,
|
||||
FileStorageFlags share_flags,
|
||||
const std::list<std::string>& directory_parent_groups)
|
||||
const std::list<RsNodeGroupId>& directory_parent_groups)
|
||||
{
|
||||
// We should be able to do that in O(1), using groups based on packs of bits.
|
||||
//
|
||||
|
@ -1354,7 +1362,7 @@ FileSearchFlags p3Peers::computePeerPermissionFlags(const RsPeerId& peer_ssl_id,
|
|||
bool found = false ;
|
||||
RsPgpId pgp_id = getGPGId(peer_ssl_id) ;
|
||||
|
||||
for(std::list<std::string>::const_iterator it(directory_parent_groups.begin());it!=directory_parent_groups.end() && !found;++it)
|
||||
for(std::list<RsNodeGroupId>::const_iterator it(directory_parent_groups.begin());it!=directory_parent_groups.end() && !found;++it)
|
||||
{
|
||||
RsGroupInfo info ;
|
||||
if(!getGroupInfo(*it,info))
|
||||
|
|
|
@ -70,7 +70,7 @@ public:
|
|||
virtual bool getGPGAllList(std::list<RsPgpId> &ids);
|
||||
virtual bool getGPGDetails(const RsPgpId &id, RsPeerDetails &d);
|
||||
virtual bool getAssociatedSSLIds(const RsPgpId& gpg_id, std::list<RsPeerId> &ids);
|
||||
virtual bool gpgSignData(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen) ;
|
||||
virtual bool gpgSignData(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen, std::string reason = "") ;
|
||||
|
||||
/* Add/Remove Friends */
|
||||
virtual bool addFriend(const RsPeerId &ssl_id, const RsPgpId &gpg_id,ServicePermissionFlags flags = RS_NODE_PERM_DEFAULT);
|
||||
|
@ -124,14 +124,15 @@ public:
|
|||
|
||||
/* Group Stuff */
|
||||
virtual bool addGroup(RsGroupInfo &groupInfo);
|
||||
virtual bool editGroup(const std::string &groupId, RsGroupInfo &groupInfo);
|
||||
virtual bool removeGroup(const std::string &groupId);
|
||||
virtual bool getGroupInfo(const std::string &groupId, RsGroupInfo &groupInfo);
|
||||
virtual bool getGroupInfoList(std::list<RsGroupInfo> &groupInfoList);
|
||||
virtual bool assignPeerToGroup(const std::string &groupId, const RsPgpId &peerId, bool assign);
|
||||
virtual bool assignPeersToGroup(const std::string &groupId, const std::list<RsPgpId>& peerIds, bool assign);
|
||||
virtual bool editGroup(const RsNodeGroupId &groupId, RsGroupInfo &groupInfo);
|
||||
virtual bool removeGroup(const RsNodeGroupId &groupId);
|
||||
virtual bool getGroupInfo(const RsNodeGroupId &groupId, RsGroupInfo &groupInfo);
|
||||
virtual bool getGroupInfoByName(const std::string& groupName, RsGroupInfo& groupInfo);
|
||||
virtual bool getGroupInfoList(std::list<RsGroupInfo> &groupInfoList);
|
||||
virtual bool assignPeerToGroup(const RsNodeGroupId &groupId, const RsPgpId &peerId, bool assign);
|
||||
virtual bool assignPeersToGroup(const RsNodeGroupId &groupId, const std::list<RsPgpId>& peerIds, bool assign);
|
||||
|
||||
virtual FileSearchFlags computePeerPermissionFlags(const RsPeerId& peer_id,FileStorageFlags share_flags,const std::list<std::string>& parent_groups);
|
||||
virtual FileSearchFlags computePeerPermissionFlags(const RsPeerId& peer_id, FileStorageFlags share_flags, const std::list<RsNodeGroupId> &parent_groups);
|
||||
|
||||
// service permission stuff
|
||||
|
||||
|
|
|
@ -78,7 +78,9 @@
|
|||
#include "grouter/p3grouter.h"
|
||||
#endif
|
||||
|
||||
#ifdef RS_USE_DHT_STUNNER
|
||||
#include "tcponudp/udpstunner.h"
|
||||
#endif // RS_USE_DHT_STUNNER
|
||||
|
||||
// #define GPG_DEBUG
|
||||
// #define AUTHSSL_DEBUG
|
||||
|
@ -902,7 +904,9 @@ RsGRouter *rsGRouter = NULL ;
|
|||
|
||||
#ifdef RS_USE_BITDHT
|
||||
#include "dht/p3bitdht.h"
|
||||
#ifdef RS_USE_DHT_STUNNER
|
||||
#include "dht/stunaddrassist.h"
|
||||
#endif // RS_USE_DHT_STUNNER
|
||||
|
||||
#include "udp/udpstack.h"
|
||||
#include "tcponudp/udppeer.h"
|
||||
|
@ -1138,6 +1142,7 @@ int RsServer::StartupRetroShare()
|
|||
UdpSubReceiver *udpReceivers[RSUDP_NUM_TOU_RECVERS];
|
||||
int udpTypes[RSUDP_NUM_TOU_RECVERS];
|
||||
|
||||
#ifdef RS_USE_DHT_STUNNER
|
||||
// FIRST DHT STUNNER.
|
||||
UdpStunner *mDhtStunner = new UdpStunner(mDhtStack);
|
||||
mDhtStunner->setTargetStunPeriod(300); /* slow (5mins) */
|
||||
|
@ -1146,9 +1151,11 @@ int RsServer::StartupRetroShare()
|
|||
#ifdef LOCALNET_TESTING
|
||||
mDhtStunner->SetAcceptLocalNet();
|
||||
#endif
|
||||
#endif // RS_USE_DHT_STUNNER
|
||||
|
||||
|
||||
// NEXT BITDHT.
|
||||
p3BitDht *mBitDht = new p3BitDht(ownId, mLinkMgr, mNetMgr, mDhtStack, bootstrapfile, filteredipfile);
|
||||
p3BitDht *mBitDht = new p3BitDht(ownId, mLinkMgr, mNetMgr, mDhtStack, bootstrapfile, filteredipfile);
|
||||
|
||||
/* install external Pointer for Interface */
|
||||
rsDht = mBitDht;
|
||||
|
@ -1189,6 +1196,7 @@ int RsServer::StartupRetroShare()
|
|||
rsFixedUdpStack *mProxyStack = new rsFixedUdpStack(sndladdr);
|
||||
#endif
|
||||
|
||||
#ifdef RS_USE_DHT_STUNNER
|
||||
// FIRSTLY THE PROXY STUNNER.
|
||||
UdpStunner *mProxyStunner = new UdpStunner(mProxyStack);
|
||||
mProxyStunner->setTargetStunPeriod(300); /* slow (5mins) */
|
||||
|
@ -1197,6 +1205,7 @@ int RsServer::StartupRetroShare()
|
|||
#ifdef LOCALNET_TESTING
|
||||
mProxyStunner->SetAcceptLocalNet();
|
||||
#endif
|
||||
#endif // RS_USE_DHT_STUNNER
|
||||
|
||||
|
||||
// FINALLY THE PROXY UDP CONNECTIONS
|
||||
|
@ -1207,9 +1216,15 @@ int RsServer::StartupRetroShare()
|
|||
// REAL INITIALISATION - WITH THREE MODES
|
||||
tou_init((void **) udpReceivers, udpTypes, RSUDP_NUM_TOU_RECVERS);
|
||||
|
||||
#ifdef RS_USE_DHT_STUNNER
|
||||
mBitDht->setupConnectBits(mDhtStunner, mProxyStunner, mRelay);
|
||||
#else // RS_USE_DHT_STUNNER
|
||||
mBitDht->setupConnectBits(mRelay);
|
||||
#endif // RS_USE_DHT_STUNNER
|
||||
|
||||
#ifdef RS_USE_DHT_STUNNER
|
||||
mNetMgr->setAddrAssist(new stunAddrAssist(mDhtStunner), new stunAddrAssist(mProxyStunner));
|
||||
#endif // RS_USE_DHT_STUNNER
|
||||
#else
|
||||
/* install NULL Pointer for rsDht Interface */
|
||||
rsDht = NULL;
|
||||
|
|
|
@ -43,34 +43,34 @@
|
|||
uint32_t RsFileConfigSerialiser::size(RsItem *i)
|
||||
{
|
||||
RsFileTransfer *rft;
|
||||
RsFileConfigItem *rfi;
|
||||
RsFileConfigItem *rfj;
|
||||
|
||||
if (NULL != (rft = dynamic_cast<RsFileTransfer *>(i)))
|
||||
{
|
||||
return sizeTransfer(rft);
|
||||
}
|
||||
if (NULL != (rfi = dynamic_cast<RsFileConfigItem *>(i)))
|
||||
{
|
||||
return sizeFileItem(rfi);
|
||||
}
|
||||
return 0;
|
||||
if (NULL != (rfj = dynamic_cast<RsFileConfigItem *>(i)))
|
||||
{
|
||||
return sizeFileItem(rfj);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* serialise the data to the buffer */
|
||||
bool RsFileConfigSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize)
|
||||
{
|
||||
RsFileTransfer *rft;
|
||||
RsFileConfigItem *rfi;
|
||||
RsFileConfigItem *rfj;
|
||||
|
||||
if (NULL != (rft = dynamic_cast<RsFileTransfer *>(i)))
|
||||
{
|
||||
return serialiseTransfer(rft, data, pktsize);
|
||||
}
|
||||
if (NULL != (rfi = dynamic_cast<RsFileConfigItem *>(i)))
|
||||
{
|
||||
return serialiseFileItem(rfi, data, pktsize);
|
||||
}
|
||||
return false;
|
||||
if (NULL != (rfj = dynamic_cast<RsFileConfigItem*>(i)))
|
||||
{
|
||||
return serialiseFileItem(rfj, data, pktsize);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
RsItem *RsFileConfigSerialiser::deserialise(void *data, uint32_t *pktsize)
|
||||
|
@ -90,10 +90,13 @@ RsItem *RsFileConfigSerialiser::deserialise(void *data, uint32_t *pktsize)
|
|||
case RS_PKT_SUBTYPE_FILE_TRANSFER:
|
||||
return deserialiseTransfer(data, pktsize);
|
||||
break;
|
||||
case RS_PKT_SUBTYPE_FILE_ITEM:
|
||||
return deserialiseFileItem(data, pktsize);
|
||||
case RS_PKT_SUBTYPE_FILE_ITEM_deprecated:
|
||||
return deserialiseFileItem_deprecated(data, pktsize);
|
||||
break;
|
||||
default:
|
||||
case RS_PKT_SUBTYPE_FILE_ITEM:
|
||||
return deserialiseFileItem(data, pktsize);
|
||||
break;
|
||||
default:
|
||||
return NULL;
|
||||
break;
|
||||
}
|
||||
|
@ -158,20 +161,20 @@ std::ostream &RsFileTransfer::print(std::ostream &out, uint16_t indent)
|
|||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
|
||||
RsFileConfigItem::~RsFileConfigItem()
|
||||
void RsFileConfigItem_deprecated::clear()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void RsFileConfigItem::clear()
|
||||
{
|
||||
|
||||
file.TlvClear();
|
||||
flags = 0;
|
||||
parent_groups.clear() ;
|
||||
}
|
||||
|
||||
std::ostream &RsFileConfigItem::print(std::ostream &out, uint16_t indent)
|
||||
void RsFileConfigItem::clear()
|
||||
{
|
||||
file.TlvClear();
|
||||
flags = 0;
|
||||
parent_groups.TlvClear() ;
|
||||
}
|
||||
std::ostream &RsFileConfigItem_deprecated::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsFileConfigItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
@ -188,6 +191,22 @@ std::ostream &RsFileConfigItem::print(std::ostream &out, uint16_t indent)
|
|||
return out;
|
||||
}
|
||||
|
||||
std::ostream &RsFileConfigItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsFileConfigItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
file.print(out, int_Indent);
|
||||
|
||||
printIndent(out, int_Indent); out << "flags: " << flags << std::endl;
|
||||
printIndent(out, int_Indent); out << "groups:" ;
|
||||
|
||||
for(std::set<RsNodeGroupId>::const_iterator it(parent_groups.ids.begin());it!=parent_groups.ids.end();++it)
|
||||
out << (*it) << " " ;
|
||||
out << std::endl;
|
||||
|
||||
printRsItemEnd(out, "RsFileConfigItem", indent);
|
||||
return out;
|
||||
}
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
|
||||
|
@ -351,8 +370,7 @@ uint32_t RsFileConfigSerialiser::sizeFileItem(RsFileConfigItem *item)
|
|||
s += item->file.TlvSize();
|
||||
s += 4; // flags
|
||||
|
||||
for(std::list<std::string>::const_iterator it(item->parent_groups.begin());it!=item->parent_groups.end();++it) // parent groups
|
||||
s += GetTlvStringSize(*it);
|
||||
s += item->parent_groups.TlvSize() ;
|
||||
|
||||
return s;
|
||||
}
|
||||
|
@ -382,9 +400,7 @@ bool RsFileConfigSerialiser::serialiseFileItem(RsFileConfigItem *item, void
|
|||
/* add mandatory parts first */
|
||||
ok &= item->file.SetTlv(data, tlvsize, &offset);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, item->flags);
|
||||
|
||||
for(std::list<std::string>::const_iterator it(item->parent_groups.begin());ok && it!=item->parent_groups.end();++it) // parent groups
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_GROUPID, *it);
|
||||
ok &= item->parent_groups.SetTlv(data, tlvsize, &offset);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
|
@ -397,6 +413,66 @@ bool RsFileConfigSerialiser::serialiseFileItem(RsFileConfigItem *item, void
|
|||
return ok;
|
||||
}
|
||||
|
||||
RsFileConfigItem_deprecated *RsFileConfigSerialiser::deserialiseFileItem_deprecated(void *data, uint32_t *pktsize)
|
||||
{
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) ||
|
||||
(RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) ||
|
||||
(RS_PKT_TYPE_FILE_CONFIG != getRsItemType(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_FILE_ITEM_deprecated != getRsItemSubType(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*pktsize < rssize) /* check size */
|
||||
return NULL; /* not enough data */
|
||||
|
||||
/* set the packet length */
|
||||
*pktsize = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
RsFileConfigItem_deprecated *item = new RsFileConfigItem_deprecated();
|
||||
item->clear();
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* get mandatory parts first */
|
||||
ok &= item->file.GetTlv(data, rssize, &offset);
|
||||
ok &= getRawUInt32(data, rssize, &offset, &(item->flags));
|
||||
|
||||
while(offset < rssize)
|
||||
{
|
||||
std::string tmp ;
|
||||
if(GetTlvString(data, rssize, &offset, TLV_TYPE_STR_GROUPID, tmp))
|
||||
item->parent_groups.push_back(tmp) ;
|
||||
else
|
||||
break ;
|
||||
}
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
RsFileConfigItem *RsFileConfigSerialiser::deserialiseFileItem(void *data, uint32_t *pktsize)
|
||||
{
|
||||
/* get the type and size */
|
||||
|
@ -409,7 +485,7 @@ RsFileConfigItem *RsFileConfigSerialiser::deserialiseFileItem(void *data, uint32
|
|||
if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) ||
|
||||
(RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) ||
|
||||
(RS_PKT_TYPE_FILE_CONFIG != getRsItemType(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_FILE_ITEM != getRsItemSubType(rstype)))
|
||||
(RS_PKT_SUBTYPE_FILE_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
@ -423,7 +499,7 @@ RsFileConfigItem *RsFileConfigSerialiser::deserialiseFileItem(void *data, uint32
|
|||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
RsFileConfigItem *item = new RsFileConfigItem();
|
||||
RsFileConfigItem *item = new RsFileConfigItem();
|
||||
item->clear();
|
||||
|
||||
/* skip the header */
|
||||
|
@ -432,15 +508,7 @@ RsFileConfigItem *RsFileConfigSerialiser::deserialiseFileItem(void *data, uint32
|
|||
/* get mandatory parts first */
|
||||
ok &= item->file.GetTlv(data, rssize, &offset);
|
||||
ok &= getRawUInt32(data, rssize, &offset, &(item->flags));
|
||||
|
||||
while(offset < rssize)
|
||||
{
|
||||
std::string tmp ;
|
||||
if(GetTlvString(data, rssize, &offset, TLV_TYPE_STR_GROUPID, tmp))
|
||||
item->parent_groups.push_back(tmp) ;
|
||||
else
|
||||
break ;
|
||||
}
|
||||
ok &= item->parent_groups.GetTlv(data, rssize, &offset) ;
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
|
@ -682,7 +750,7 @@ uint32_t RsPeerConfigSerialiser::size(RsItem *i)
|
|||
{
|
||||
RsPeerStunItem *psi;
|
||||
RsPeerNetItem *pni;
|
||||
RsPeerGroupItem *pgi;
|
||||
RsNodeGroupItem *pgi;
|
||||
RsPeerServicePermissionItem *pri;
|
||||
RsPeerBandwidthLimitsItem *pblitem;
|
||||
|
||||
|
@ -694,7 +762,7 @@ uint32_t RsPeerConfigSerialiser::size(RsItem *i)
|
|||
{
|
||||
return sizeStun(psi);
|
||||
}
|
||||
else if (NULL != (pgi = dynamic_cast<RsPeerGroupItem *>(i)))
|
||||
else if (NULL != (pgi = dynamic_cast<RsNodeGroupItem*>(i)))
|
||||
{
|
||||
return sizeGroup(pgi);
|
||||
}
|
||||
|
@ -715,7 +783,7 @@ bool RsPeerConfigSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsi
|
|||
{
|
||||
RsPeerNetItem *pni;
|
||||
RsPeerStunItem *psi;
|
||||
RsPeerGroupItem *pgi;
|
||||
RsNodeGroupItem *pgi;
|
||||
RsPeerServicePermissionItem *pri;
|
||||
RsPeerBandwidthLimitsItem *pblitem;
|
||||
|
||||
|
@ -727,7 +795,7 @@ bool RsPeerConfigSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsi
|
|||
{
|
||||
return serialiseStun(psi, data, pktsize);
|
||||
}
|
||||
else if (NULL != (pgi = dynamic_cast<RsPeerGroupItem *>(i)))
|
||||
else if (NULL != (pgi = dynamic_cast<RsNodeGroupItem*>(i)))
|
||||
{
|
||||
return serialiseGroup(pgi, data, pktsize);
|
||||
}
|
||||
|
@ -764,9 +832,11 @@ RsItem *RsPeerConfigSerialiser::deserialise(void *data, uint32_t *pktsize)
|
|||
return deserialiseNet(data, pktsize);
|
||||
case RS_PKT_SUBTYPE_PEER_STUN:
|
||||
return deserialiseStun(data, pktsize);
|
||||
case RS_PKT_SUBTYPE_PEER_GROUP:
|
||||
return deserialiseGroup(data, pktsize);
|
||||
case RS_PKT_SUBTYPE_PEER_PERMISSIONS:
|
||||
case RS_PKT_SUBTYPE_PEER_GROUP_deprecated:
|
||||
return deserialiseGroup_deprecated(data, pktsize);
|
||||
case RS_PKT_SUBTYPE_NODE_GROUP:
|
||||
return deserialiseGroup(data, pktsize);
|
||||
case RS_PKT_SUBTYPE_PEER_PERMISSIONS:
|
||||
return deserialisePermissions(data, pktsize);
|
||||
case RS_PKT_SUBTYPE_PEER_BANDLIMITS:
|
||||
return deserialisePeerBandwidthLimits(data, pktsize);
|
||||
|
@ -1312,16 +1382,64 @@ RsPeerStunItem *RsPeerConfigSerialiser::deserialiseStun(void *data, uint32_t *si
|
|||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
RsPeerGroupItem::RsPeerGroupItem() : RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_PEER_CONFIG, RS_PKT_SUBTYPE_PEER_GROUP)
|
||||
RsNodeGroupItem::RsNodeGroupItem() : RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_PEER_CONFIG, RS_PKT_SUBTYPE_NODE_GROUP)
|
||||
{
|
||||
}
|
||||
|
||||
RsPeerGroupItem::~RsPeerGroupItem()
|
||||
RsNodeGroupItem::RsNodeGroupItem(const RsGroupInfo& g)
|
||||
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_PEER_CONFIG, RS_PKT_SUBTYPE_NODE_GROUP)
|
||||
{
|
||||
id = g.id ;
|
||||
name = g.name ;
|
||||
flag = g.flag ;
|
||||
pgpList.ids = g.peerIds;
|
||||
}
|
||||
|
||||
void RsNodeGroupItem::clear()
|
||||
{
|
||||
id.clear();
|
||||
name.clear();
|
||||
flag = 0;
|
||||
pgpList.ids.clear();
|
||||
}
|
||||
|
||||
std::ostream &RsNodeGroupItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsNodeGroupItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "groupId: " << id << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "groupName: " << name << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "groupFlag: " << flag << std::endl;
|
||||
|
||||
std::set<RsPgpId>::iterator it;
|
||||
for (it = pgpList.ids.begin(); it != pgpList.ids.end(); ++it) {
|
||||
printIndent(out, int_Indent);
|
||||
out << "peerId: " << it->toStdString() << std::endl;
|
||||
}
|
||||
|
||||
printRsItemEnd(out, "RsNodeGroupItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
/* DEPRECATED CODE. SHOULD BE REMOVED WHEN EVERYONE USES THE NEW CLASS */
|
||||
/*************************************************************************/
|
||||
|
||||
RsPeerGroupItem_deprecated::RsPeerGroupItem_deprecated() : RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_PEER_CONFIG, RS_PKT_SUBTYPE_PEER_GROUP_deprecated)
|
||||
{
|
||||
}
|
||||
|
||||
void RsPeerGroupItem::clear()
|
||||
RsPeerGroupItem_deprecated::~RsPeerGroupItem_deprecated()
|
||||
{
|
||||
}
|
||||
|
||||
void RsPeerGroupItem_deprecated::clear()
|
||||
{
|
||||
id.clear();
|
||||
name.clear();
|
||||
|
@ -1329,7 +1447,7 @@ void RsPeerGroupItem::clear()
|
|||
pgpList.ids.clear();
|
||||
}
|
||||
|
||||
std::ostream &RsPeerGroupItem::print(std::ostream &out, uint16_t indent)
|
||||
std::ostream &RsPeerGroupItem_deprecated::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsPeerGroupItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
@ -1353,38 +1471,67 @@ std::ostream &RsPeerGroupItem::print(std::ostream &out, uint16_t indent)
|
|||
return out;
|
||||
}
|
||||
|
||||
/* set data from RsGroupInfo to RsPeerGroupItem */
|
||||
void RsPeerGroupItem::set(RsGroupInfo &groupInfo)
|
||||
RsPeerGroupItem_deprecated *RsPeerConfigSerialiser::deserialiseGroup_deprecated(void *data, uint32_t *size)
|
||||
{
|
||||
id = groupInfo.id;
|
||||
name = groupInfo.name;
|
||||
flag = groupInfo.flag;
|
||||
pgpList.ids = groupInfo.peerIds;
|
||||
}
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
/* get data from RsGroupInfo to RsPeerGroupItem */
|
||||
void RsPeerGroupItem::get(RsGroupInfo &groupInfo)
|
||||
{
|
||||
groupInfo.id = id;
|
||||
groupInfo.name = name;
|
||||
groupInfo.flag = flag;
|
||||
groupInfo.peerIds = pgpList.ids;
|
||||
}
|
||||
uint32_t offset = 0;
|
||||
|
||||
if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) ||
|
||||
(RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) ||
|
||||
(RS_PKT_TYPE_PEER_CONFIG != getRsItemType(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_PEER_GROUP_deprecated != getRsItemSubType(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
return NULL; /* not enough data */
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsPeerGroupItem_deprecated *item = new RsPeerGroupItem_deprecated();
|
||||
item->clear();
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* get mandatory parts first */
|
||||
uint32_t version;
|
||||
ok &= getRawUInt32(data, rssize, &offset, &version);
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_KEY, item->id);
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_NAME, item->name);
|
||||
ok &= getRawUInt32(data, rssize, &offset, &(item->flag));
|
||||
ok &= item->pgpList.GetTlv(data, rssize, &offset);
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
/*************************************************************************/
|
||||
|
||||
uint32_t RsPeerConfigSerialiser::sizeGroup(RsPeerGroupItem *i)
|
||||
uint32_t RsPeerConfigSerialiser::sizeGroup(RsNodeGroupItem *i)
|
||||
{
|
||||
uint32_t s = 8; /* header */
|
||||
s += 4; /* version */
|
||||
s += GetTlvStringSize(i->id);
|
||||
s += RsNodeGroupId::serial_size();
|
||||
s += GetTlvStringSize(i->name);
|
||||
s += 4; /* flag */
|
||||
s += i->pgpList.TlvSize();
|
||||
return s;
|
||||
}
|
||||
|
||||
bool RsPeerConfigSerialiser::serialiseGroup(RsPeerGroupItem *item, void *data, uint32_t *size)
|
||||
bool RsPeerConfigSerialiser::serialiseGroup(RsNodeGroupItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
uint32_t tlvsize = RsPeerConfigSerialiser::sizeGroup(item);
|
||||
uint32_t offset = 0;
|
||||
|
@ -1410,7 +1557,7 @@ bool RsPeerConfigSerialiser::serialiseGroup(RsPeerGroupItem *item, void *data, u
|
|||
|
||||
/* add mandatory parts first */
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, 0);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_KEY, item->id);
|
||||
ok &= item->id.serialise(data, tlvsize, offset);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_NAME, item->name);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, item->flag);
|
||||
ok &= item->pgpList.SetTlv(data, tlvsize, &offset);
|
||||
|
@ -1426,7 +1573,7 @@ bool RsPeerConfigSerialiser::serialiseGroup(RsPeerGroupItem *item, void *data, u
|
|||
return ok;
|
||||
}
|
||||
|
||||
RsPeerGroupItem *RsPeerConfigSerialiser::deserialiseGroup(void *data, uint32_t *size)
|
||||
RsNodeGroupItem *RsPeerConfigSerialiser::deserialiseGroup(void *data, uint32_t *size)
|
||||
{
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
@ -1437,7 +1584,7 @@ RsPeerGroupItem *RsPeerConfigSerialiser::deserialiseGroup(void *data, uint32_t *
|
|||
if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) ||
|
||||
(RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) ||
|
||||
(RS_PKT_TYPE_PEER_CONFIG != getRsItemType(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_PEER_GROUP != getRsItemSubType(rstype)))
|
||||
(RS_PKT_SUBTYPE_NODE_GROUP != getRsItemSubType(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
@ -1450,7 +1597,7 @@ RsPeerGroupItem *RsPeerConfigSerialiser::deserialiseGroup(void *data, uint32_t *
|
|||
|
||||
bool ok = true;
|
||||
|
||||
RsPeerGroupItem *item = new RsPeerGroupItem();
|
||||
RsNodeGroupItem *item = new RsNodeGroupItem();
|
||||
item->clear();
|
||||
|
||||
/* skip the header */
|
||||
|
@ -1459,7 +1606,7 @@ RsPeerGroupItem *RsPeerConfigSerialiser::deserialiseGroup(void *data, uint32_t *
|
|||
/* get mandatory parts first */
|
||||
uint32_t version;
|
||||
ok &= getRawUInt32(data, rssize, &offset, &version);
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_KEY, item->id);
|
||||
ok &= item->id.deserialise(data, rssize, offset);
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_NAME, item->name);
|
||||
ok &= getRawUInt32(data, rssize, &offset, &(item->flag));
|
||||
ok &= item->pgpList.GetTlv(data, rssize, &offset);
|
||||
|
|
|
@ -50,15 +50,17 @@ const uint8_t RS_PKT_TYPE_HISTORY_CONFIG = 0x06;
|
|||
const uint8_t RS_PKT_SUBTYPE_KEY_VALUE = 0x01;
|
||||
|
||||
/* PEER CONFIG SUBTYPES */
|
||||
const uint8_t RS_PKT_SUBTYPE_PEER_STUN = 0x02;
|
||||
const uint8_t RS_PKT_SUBTYPE_PEER_NET = 0x03;
|
||||
const uint8_t RS_PKT_SUBTYPE_PEER_GROUP = 0x04;
|
||||
const uint8_t RS_PKT_SUBTYPE_PEER_PERMISSIONS = 0x05;
|
||||
const uint8_t RS_PKT_SUBTYPE_PEER_BANDLIMITS = 0x06;
|
||||
const uint8_t RS_PKT_SUBTYPE_PEER_STUN = 0x02;
|
||||
const uint8_t RS_PKT_SUBTYPE_PEER_NET = 0x03;
|
||||
const uint8_t RS_PKT_SUBTYPE_PEER_GROUP_deprecated = 0x04;
|
||||
const uint8_t RS_PKT_SUBTYPE_PEER_PERMISSIONS = 0x05;
|
||||
const uint8_t RS_PKT_SUBTYPE_PEER_BANDLIMITS = 0x06;
|
||||
const uint8_t RS_PKT_SUBTYPE_NODE_GROUP = 0x07;
|
||||
|
||||
/* FILE CONFIG SUBTYPES */
|
||||
const uint8_t RS_PKT_SUBTYPE_FILE_TRANSFER = 0x01;
|
||||
const uint8_t RS_PKT_SUBTYPE_FILE_ITEM = 0x02;
|
||||
const uint8_t RS_PKT_SUBTYPE_FILE_TRANSFER = 0x01;
|
||||
const uint8_t RS_PKT_SUBTYPE_FILE_ITEM_deprecated = 0x02;
|
||||
const uint8_t RS_PKT_SUBTYPE_FILE_ITEM = 0x03;
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
|
@ -134,11 +136,11 @@ class RsPeerBandwidthLimitsItem : public RsItem
|
|||
std::map<RsPgpId,PeerBandwidthLimits> peers ;
|
||||
};
|
||||
|
||||
class RsPeerGroupItem : public RsItem
|
||||
class RsPeerGroupItem_deprecated : public RsItem
|
||||
{
|
||||
public:
|
||||
RsPeerGroupItem();
|
||||
virtual ~RsPeerGroupItem();
|
||||
RsPeerGroupItem_deprecated();
|
||||
virtual ~RsPeerGroupItem_deprecated();
|
||||
|
||||
virtual void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
@ -156,6 +158,29 @@ public:
|
|||
RsTlvPgpIdSet pgpList;
|
||||
};
|
||||
|
||||
class RsNodeGroupItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsNodeGroupItem();
|
||||
virtual ~RsNodeGroupItem() {}
|
||||
|
||||
virtual void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
explicit RsNodeGroupItem(const RsGroupInfo&) ;
|
||||
|
||||
// /* set data from RsGroupInfo to RsPeerGroupItem */
|
||||
// void set(RsGroupInfo &groupInfo);
|
||||
// /* get data from RsGroupInfo to RsPeerGroupItem */
|
||||
// void get(RsGroupInfo &groupInfo);
|
||||
|
||||
/* Mandatory */
|
||||
RsNodeGroupId id;
|
||||
std::string name;
|
||||
uint32_t flag;
|
||||
|
||||
RsTlvPgpIdSet pgpList;
|
||||
};
|
||||
|
||||
class RsPeerStunItem: public RsItem
|
||||
{
|
||||
|
@ -197,9 +222,10 @@ virtual uint32_t sizeStun(RsPeerStunItem *);
|
|||
virtual bool serialiseStun (RsPeerStunItem *item, void *data, uint32_t *size);
|
||||
virtual RsPeerStunItem * deserialiseStun(void *data, uint32_t *size);
|
||||
|
||||
virtual uint32_t sizeGroup(RsPeerGroupItem *);
|
||||
virtual bool serialiseGroup (RsPeerGroupItem *item, void *data, uint32_t *size);
|
||||
virtual RsPeerGroupItem * deserialiseGroup(void *data, uint32_t *size);
|
||||
virtual uint32_t sizeGroup(RsNodeGroupItem *);
|
||||
virtual bool serialiseGroup (RsNodeGroupItem *item, void *data, uint32_t *size);
|
||||
virtual RsNodeGroupItem *deserialiseGroup(void *data, uint32_t *size);
|
||||
virtual RsPeerGroupItem_deprecated * deserialiseGroup_deprecated(void *data, uint32_t *size);
|
||||
|
||||
virtual uint32_t sizePeerBandwidthLimits(RsPeerBandwidthLimitsItem *);
|
||||
virtual bool serialisePeerBandwidthLimits (RsPeerBandwidthLimitsItem *item, void *data, uint32_t *size);
|
||||
|
@ -303,23 +329,39 @@ class RsFileTransfer: public RsItem
|
|||
const uint32_t RS_FILE_CONFIG_CLEANUP_DELETE = 0x0001;
|
||||
|
||||
/* Used by ft / extralist / configdirs / anyone who wants a basic file */
|
||||
class RsFileConfigItem: public RsItem
|
||||
class RsFileConfigItem_deprecated: public RsItem
|
||||
{
|
||||
public:
|
||||
RsFileConfigItem()
|
||||
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG,
|
||||
RS_PKT_TYPE_FILE_CONFIG,
|
||||
RS_PKT_SUBTYPE_FILE_ITEM)
|
||||
{ return; }
|
||||
virtual ~RsFileConfigItem();
|
||||
virtual void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
public:
|
||||
RsFileConfigItem_deprecated()
|
||||
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG,
|
||||
RS_PKT_TYPE_FILE_CONFIG,
|
||||
RS_PKT_SUBTYPE_FILE_ITEM_deprecated)
|
||||
{}
|
||||
virtual ~RsFileConfigItem_deprecated() {}
|
||||
virtual void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
RsTlvFileItem file;
|
||||
uint32_t flags;
|
||||
std::list<std::string> parent_groups ;
|
||||
RsTlvFileItem file;
|
||||
uint32_t flags;
|
||||
std::list<std::string> parent_groups ;
|
||||
};
|
||||
|
||||
class RsFileConfigItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsFileConfigItem()
|
||||
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG,
|
||||
RS_PKT_TYPE_FILE_CONFIG,
|
||||
RS_PKT_SUBTYPE_FILE_ITEM)
|
||||
{}
|
||||
virtual ~RsFileConfigItem() {}
|
||||
virtual void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
RsTlvFileItem file;
|
||||
uint32_t flags;
|
||||
RsTlvNodeGroupIdSet parent_groups ;
|
||||
};
|
||||
/**************************************************************************/
|
||||
|
||||
class RsFileConfigSerialiser: public RsSerialType
|
||||
|
@ -341,9 +383,11 @@ virtual uint32_t sizeTransfer(RsFileTransfer *);
|
|||
virtual bool serialiseTransfer(RsFileTransfer *item, void *data, uint32_t *size);
|
||||
virtual RsFileTransfer * deserialiseTransfer(void *data, uint32_t *size);
|
||||
|
||||
virtual RsFileConfigItem_deprecated * deserialiseFileItem_deprecated(void *data, uint32_t *size);
|
||||
|
||||
virtual uint32_t sizeFileItem(RsFileConfigItem *);
|
||||
virtual bool serialiseFileItem(RsFileConfigItem *item, void *data, uint32_t *size);
|
||||
virtual RsFileConfigItem * deserialiseFileItem(void *data, uint32_t *size);
|
||||
virtual RsFileConfigItem *deserialiseFileItem(void *data, uint32_t *size);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -74,6 +74,11 @@ void RsGxsReputationUpdateItem::clear()
|
|||
mOpinions.clear() ;
|
||||
}
|
||||
|
||||
void RsGxsReputationBannedNodeSetItem::clear()
|
||||
{
|
||||
mKnownIdentities.TlvClear();
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
|
@ -82,10 +87,10 @@ std::ostream& RsGxsReputationConfigItem::print(std::ostream &out, uint16_t inden
|
|||
{
|
||||
printRsItemBase(out, "RsReputationConfigItem", indent);
|
||||
|
||||
out << "mPeerId: " << mPeerId << std::endl;
|
||||
out << "last update: " << time(NULL) - mLatestUpdate << " secs ago." << std::endl;
|
||||
out << "last query : " << time(NULL) - mLastQuery << " secs ago." << std::endl;
|
||||
|
||||
out << "mPeerId: " << mPeerId << std::endl;
|
||||
out << "last update: " << time(NULL) - mLatestUpdate << " secs ago." << std::endl;
|
||||
out << "last query : " << time(NULL) - mLastQuery << " secs ago." << std::endl;
|
||||
|
||||
printRsItemEnd(out, "RsReputationConfigItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
@ -94,14 +99,15 @@ std::ostream& RsGxsReputationSetItem::print(std::ostream &out, uint16_t indent)
|
|||
{
|
||||
printRsItemBase(out, "RsReputationSetItem", indent);
|
||||
|
||||
out << "GxsId: " << mGxsId << std::endl;
|
||||
out << "mOwnOpinion: " << mOwnOpinion << std::endl;
|
||||
out << "mOwnOpinionTS : " << time(NULL) - mOwnOpinionTS << " secs ago." << std::endl;
|
||||
out << "GxsId: " << mGxsId << std::endl;
|
||||
out << "Owner: " << mOwnerNodeId << std::endl;
|
||||
out << "mOwnOpinion: " << mOwnOpinion << std::endl;
|
||||
out << "mOwnOpinionTS : " << time(NULL) - mOwnOpinionTS << " secs ago." << std::endl;
|
||||
out << "Opinions from neighbors: " << std::endl;
|
||||
|
||||
|
||||
for(std::map<RsPeerId,uint32_t>::const_iterator it(mOpinions.begin());it!=mOpinions.end();++it)
|
||||
out << " " << it->first << ": " << it->second << std::endl;
|
||||
|
||||
out << " " << it->first << ": " << it->second << std::endl;
|
||||
|
||||
printRsItemEnd(out, "RsReputationSetItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
@ -109,12 +115,12 @@ std::ostream& RsGxsReputationUpdateItem::print(std::ostream &out, uint16_t inden
|
|||
{
|
||||
printRsItemBase(out, "RsReputationUpdateItem", indent);
|
||||
|
||||
out << "from: " << PeerId() << std::endl;
|
||||
out << "last update: " << time(NULL) - mLatestUpdate << " secs ago." << std::endl;
|
||||
|
||||
out << "from: " << PeerId() << std::endl;
|
||||
out << "last update: " << time(NULL) - mLatestUpdate << " secs ago." << std::endl;
|
||||
|
||||
for(std::map<RsGxsId,uint32_t>::const_iterator it(mOpinions.begin());it!=mOpinions.end();++it)
|
||||
out << " " << it->first << ": " << it->second << std::endl;
|
||||
|
||||
out << " " << it->first << ": " << it->second << std::endl;
|
||||
|
||||
printRsItemEnd(out, "RsReputationUpdateItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
@ -122,8 +128,19 @@ std::ostream& RsGxsReputationRequestItem::print(std::ostream &out, uint16_t inde
|
|||
{
|
||||
printRsItemBase(out, "RsReputationRequestItem", indent);
|
||||
|
||||
out << "last update: " << time(NULL) - mLastUpdate << " secs ago." << std::endl;
|
||||
|
||||
out << "last update: " << time(NULL) - mLastUpdate << " secs ago." << std::endl;
|
||||
|
||||
printRsItemEnd(out, "RsReputationRequestItem", indent);
|
||||
return out;
|
||||
}
|
||||
std::ostream& RsGxsReputationBannedNodeSetItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsReputationBannedNodeSetItem", indent);
|
||||
|
||||
out << "last update: " << time(NULL) - mLastActivityTS << " secs ago." << std::endl;
|
||||
out << "PGP id: " << mPgpId << std::endl;
|
||||
out << "Known ids: " << mKnownIdentities.ids.size() << std::endl;
|
||||
|
||||
printRsItemEnd(out, "RsReputationRequestItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
@ -134,26 +151,38 @@ uint32_t RsGxsReputationConfigItem::serial_size() const
|
|||
uint32_t s = 8; /* header */
|
||||
|
||||
s += mPeerId.serial_size() ; // PeerId
|
||||
s += 4 ; // mLatestUpdate
|
||||
s += 4 ; // mLastQuery
|
||||
s += 4 ; // mLatestUpdate
|
||||
s += 4 ; // mLastQuery
|
||||
|
||||
return s ;
|
||||
}
|
||||
|
||||
uint32_t RsGxsReputationSetItem::serial_size() const
|
||||
{
|
||||
uint32_t s = 8; /* header */
|
||||
|
||||
s += mGxsId.serial_size() ;
|
||||
uint32_t s = 8; /* header */
|
||||
|
||||
s += mGxsId.serial_size() ;
|
||||
s += 4 ; // mOwnOpinion
|
||||
s += 4 ; // mOwnOpinionTS
|
||||
s += 4 ; // mIdentityFlags
|
||||
|
||||
s += mOwnerNodeId.serial_size() ;
|
||||
|
||||
s += 4 ; // mOpinions.size()
|
||||
|
||||
|
||||
s += (4+RsPeerId::serial_size()) * mOpinions.size() ;
|
||||
|
||||
return s ;
|
||||
|
||||
return s ;
|
||||
}
|
||||
|
||||
uint32_t RsGxsReputationBannedNodeSetItem::serial_size() const
|
||||
{
|
||||
uint32_t s = 8; /* header */
|
||||
|
||||
s += RsPgpId::serial_size() ; // mPgpId
|
||||
s += 4 ; // mLastActivityTS;
|
||||
s += mKnownIdentities.TlvSize(); // mKnownIdentities
|
||||
|
||||
return s ;
|
||||
}
|
||||
|
||||
uint32_t RsGxsReputationUpdateItem::serial_size() const
|
||||
|
@ -216,8 +245,10 @@ bool RsGxsReputationSetItem::serialise(void *data, uint32_t& pktsize) const
|
|||
ok &= setRawUInt32(data, tlvsize, &offset, mOwnOpinion);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, mOwnOpinionTS);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, mIdentityFlags) ;
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, mOpinions.size());
|
||||
|
||||
ok &= mOwnerNodeId.serialise(data,tlvsize,offset) ;
|
||||
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, mOpinions.size());
|
||||
|
||||
for(std::map<RsPeerId,uint32_t>::const_iterator it(mOpinions.begin());it!=mOpinions.end();++it)
|
||||
{
|
||||
ok &= it->first.serialise(data,tlvsize,offset) ;
|
||||
|
@ -232,6 +263,29 @@ bool RsGxsReputationSetItem::serialise(void *data, uint32_t& pktsize) const
|
|||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool RsGxsReputationBannedNodeSetItem::serialise(void *data, uint32_t& pktsize) const
|
||||
{
|
||||
uint32_t tlvsize ;
|
||||
uint32_t offset=0;
|
||||
|
||||
if(!serialise_header(data,pktsize,tlvsize,offset))
|
||||
return false ;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= mPgpId.serialise(data, tlvsize, offset) ;
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, mLastActivityTS);
|
||||
ok &= mKnownIdentities.SetTlv(data, tlvsize, &offset) ;
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
std::cerr << "RsGxsReputationSetItem::serialisedata() size error! " << std::endl;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
bool RsGxsReputationUpdateItem::serialise(void *data, uint32_t& pktsize) const
|
||||
{
|
||||
uint32_t tlvsize ;
|
||||
|
@ -304,7 +358,28 @@ RsGxsReputationConfigItem *RsGxsReputationSerialiser::deserialiseReputationConfi
|
|||
|
||||
return item;
|
||||
}
|
||||
RsGxsReputationBannedNodeSetItem *RsGxsReputationSerialiser::deserialiseReputationBannedNodeSetItem(void *data,uint32_t size)
|
||||
{
|
||||
uint32_t offset = 8; // skip the header
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
bool ok = true ;
|
||||
|
||||
RsGxsReputationBannedNodeSetItem *item = new RsGxsReputationBannedNodeSetItem() ;
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= item->mPgpId.deserialise(data, size, offset) ;
|
||||
ok &= getRawUInt32(data, size, &offset, &item->mLastActivityTS);
|
||||
ok &= item->mKnownIdentities.GetTlv(data,size,&offset) ;
|
||||
|
||||
if (offset != rssize || !ok)
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl;
|
||||
delete item;
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
RsGxsReputationSetItem *RsGxsReputationSerialiser::deserialiseReputationSetItem_deprecated(void *data,uint32_t tlvsize)
|
||||
{
|
||||
uint32_t offset = 8; // skip the header
|
||||
|
@ -315,30 +390,32 @@ RsGxsReputationSetItem *RsGxsReputationSerialiser::deserialiseReputationSetItem_
|
|||
|
||||
/* add mandatory parts first */
|
||||
ok &= item->mGxsId.deserialise(data, tlvsize, offset) ;
|
||||
|
||||
item->mOwnerNodeId.clear(); // clears up, for backward compat.
|
||||
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &item->mOwnOpinion);
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &item->mOwnOpinionTS);
|
||||
|
||||
item->mIdentityFlags = REPUTATION_IDENTITY_FLAG_NEEDS_UPDATE; // special value that means please update me.
|
||||
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &item->mIdentityFlags);
|
||||
|
||||
uint32_t S ;
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &S);
|
||||
|
||||
|
||||
for(uint32_t i = 0; ok && (i < S); ++i)
|
||||
{
|
||||
RsPeerId pid ;
|
||||
uint32_t op ;
|
||||
|
||||
ok &= pid.deserialise(data, tlvsize, offset) ;
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &op);
|
||||
|
||||
|
||||
ok &= pid.deserialise(data, tlvsize, offset) ;
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &op);
|
||||
|
||||
if(ok)
|
||||
item->mOpinions[pid] = op ;
|
||||
item->mOpinions[pid] = op ;
|
||||
}
|
||||
|
||||
if (offset != rssize || !ok)
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl;
|
||||
delete item;
|
||||
delete item;
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
|
@ -357,7 +434,8 @@ RsGxsReputationSetItem *RsGxsReputationSerialiser::deserialiseReputationSetItem(
|
|||
ok &= getRawUInt32(data, tlvsize, &offset, &item->mOwnOpinion);
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &item->mOwnOpinionTS);
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &item->mIdentityFlags);
|
||||
|
||||
ok &= item->mOwnerNodeId.deserialise(data, tlvsize, offset) ;
|
||||
|
||||
uint32_t S ;
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &S);
|
||||
|
||||
|
@ -455,12 +533,13 @@ RsItem *RsGxsReputationSerialiser::deserialise(void *data, uint32_t *pktsize)
|
|||
|
||||
switch(getRsItemSubType(rstype))
|
||||
{
|
||||
case RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM : return deserialiseReputationSetItem (data, *pktsize);
|
||||
case RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM_deprecated: return deserialiseReputationSetItem_deprecated(data, *pktsize);
|
||||
case RS_PKT_SUBTYPE_GXS_REPUTATION_UPDATE_ITEM : return deserialiseReputationUpdateItem (data, *pktsize);
|
||||
case RS_PKT_SUBTYPE_GXS_REPUTATION_REQUEST_ITEM : return deserialiseReputationRequestItem (data, *pktsize);
|
||||
case RS_PKT_SUBTYPE_GXS_REPUTATION_CONFIG_ITEM : return deserialiseReputationConfigItem (data, *pktsize);
|
||||
|
||||
case RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM : return deserialiseReputationSetItem (data, *pktsize);
|
||||
case RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM_deprecated : return deserialiseReputationSetItem_deprecated(data, *pktsize);
|
||||
case RS_PKT_SUBTYPE_GXS_REPUTATION_BANNED_NODE_SET_ITEM: return deserialiseReputationBannedNodeSetItem(data, *pktsize);
|
||||
case RS_PKT_SUBTYPE_GXS_REPUTATION_UPDATE_ITEM : return deserialiseReputationUpdateItem (data, *pktsize);
|
||||
case RS_PKT_SUBTYPE_GXS_REPUTATION_REQUEST_ITEM : return deserialiseReputationRequestItem (data, *pktsize);
|
||||
case RS_PKT_SUBTYPE_GXS_REPUTATION_CONFIG_ITEM : return deserialiseReputationConfigItem (data, *pktsize);
|
||||
|
||||
default:
|
||||
std::cerr << "RsGxsReputationSerialiser::deserialise(): unknown item subtype " << std::hex<< rstype << std::dec << std::endl;
|
||||
return NULL;
|
||||
|
|
|
@ -30,13 +30,16 @@
|
|||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvidset.h"
|
||||
#include "retroshare/rsgxsifacetypes.h"
|
||||
|
||||
#define RS_PKT_SUBTYPE_GXS_REPUTATION_CONFIG_ITEM 0x01
|
||||
#define RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM_deprecated 0x02
|
||||
#define RS_PKT_SUBTYPE_GXS_REPUTATION_UPDATE_ITEM 0x03
|
||||
#define RS_PKT_SUBTYPE_GXS_REPUTATION_REQUEST_ITEM 0x04
|
||||
#define RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM 0x05
|
||||
#define RS_PKT_SUBTYPE_GXS_REPUTATION_CONFIG_ITEM 0x01
|
||||
#define RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM_deprecated2 0x02
|
||||
#define RS_PKT_SUBTYPE_GXS_REPUTATION_UPDATE_ITEM 0x03
|
||||
#define RS_PKT_SUBTYPE_GXS_REPUTATION_REQUEST_ITEM 0x04
|
||||
#define RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM_deprecated 0x05
|
||||
#define RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM 0x06
|
||||
#define RS_PKT_SUBTYPE_GXS_REPUTATION_BANNED_NODE_SET_ITEM 0x07
|
||||
|
||||
/**************************************************************************/
|
||||
class RsReputationItem: public RsItem
|
||||
|
@ -68,31 +71,71 @@ public:
|
|||
virtual void clear() {}
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
virtual bool serialise(void *data,uint32_t& size) const ;
|
||||
virtual bool serialise(void *data,uint32_t& size) const ;
|
||||
virtual uint32_t serial_size() const ;
|
||||
|
||||
RsPeerId mPeerId;
|
||||
uint32_t mLatestUpdate; // timestamp they returned.
|
||||
uint32_t mLastQuery; // when we sent out.
|
||||
uint32_t mLastQuery; // when we sent out.
|
||||
};
|
||||
|
||||
// This class should disappear. Deprecated since Aug 1, 2016. The class definition is actually not needed,
|
||||
// that is why it's commented out. Kept here in order to explains how the deserialisation works.
|
||||
//
|
||||
// class RsGxsReputationSetItem_deprecated: public RsReputationItem
|
||||
// {
|
||||
// public:
|
||||
// RsGxsReputationSetItem_deprecated() :RsReputationItem(RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM_deprecated) {}
|
||||
//
|
||||
// virtual ~RsGxsReputationSetItem_deprecated() {}
|
||||
// virtual void clear() {}
|
||||
// std::ostream &print(std::ostream &out, uint16_t indent = 0) { return out;}
|
||||
//
|
||||
// virtual bool serialise(void *data,uint32_t& size) const { std::cerr << "(EE) serialise attempt for a deprecated reputation item. This should not happen" << std::endl; return false ; }
|
||||
// virtual uint32_t serial_size() const ;
|
||||
//
|
||||
// RsGxsId mGxsId;
|
||||
// uint32_t mOwnOpinion;
|
||||
// uint32_t mOwnOpinionTS;
|
||||
// uint32_t mIdentityFlags;
|
||||
// std::map<RsPeerId, uint32_t> mOpinions; // RsPeerId -> Opinion.
|
||||
// };
|
||||
|
||||
class RsGxsReputationSetItem: public RsReputationItem
|
||||
{
|
||||
public:
|
||||
RsGxsReputationSetItem() :RsReputationItem(RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM) {}
|
||||
RsGxsReputationSetItem() :RsReputationItem(RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM) {}
|
||||
|
||||
virtual ~RsGxsReputationSetItem() {}
|
||||
virtual void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
virtual void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
virtual bool serialise(void *data,uint32_t& size) const ;
|
||||
virtual uint32_t serial_size() const ;
|
||||
|
||||
RsGxsId mGxsId;
|
||||
uint32_t mOwnOpinion;
|
||||
uint32_t mOwnOpinionTS;
|
||||
uint32_t mIdentityFlags ;
|
||||
std::map<RsPeerId, uint32_t> mOpinions; // RsPeerId -> Opinion.
|
||||
virtual bool serialise(void *data,uint32_t& size) const ;
|
||||
virtual uint32_t serial_size() const ;
|
||||
|
||||
RsGxsId mGxsId;
|
||||
uint32_t mOwnOpinion;
|
||||
uint32_t mOwnOpinionTS;
|
||||
uint32_t mIdentityFlags ;
|
||||
RsPgpId mOwnerNodeId;
|
||||
std::map<RsPeerId, uint32_t> mOpinions; // RsPeerId -> Opinion.
|
||||
};
|
||||
|
||||
class RsGxsReputationBannedNodeSetItem: public RsReputationItem
|
||||
{
|
||||
public:
|
||||
RsGxsReputationBannedNodeSetItem() :RsReputationItem(RS_PKT_SUBTYPE_GXS_REPUTATION_BANNED_NODE_SET_ITEM) {}
|
||||
|
||||
virtual ~RsGxsReputationBannedNodeSetItem() {}
|
||||
virtual void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
virtual bool serialise(void *data,uint32_t& size) const ;
|
||||
virtual uint32_t serial_size() const ;
|
||||
|
||||
RsPgpId mPgpId ;
|
||||
uint32_t mLastActivityTS ;
|
||||
RsTlvGxsIdSet mKnownIdentities ;
|
||||
};
|
||||
|
||||
class RsGxsReputationUpdateItem: public RsReputationItem
|
||||
|
@ -145,11 +188,12 @@ public:
|
|||
virtual RsItem * deserialise(void *data, uint32_t *size);
|
||||
|
||||
private:
|
||||
static RsGxsReputationConfigItem *deserialiseReputationConfigItem (void *data, uint32_t size);
|
||||
static RsGxsReputationSetItem *deserialiseReputationSetItem (void *data, uint32_t size);
|
||||
static RsGxsReputationSetItem *deserialiseReputationSetItem_deprecated (void *data, uint32_t size);
|
||||
static RsGxsReputationUpdateItem *deserialiseReputationUpdateItem (void *data, uint32_t size);
|
||||
static RsGxsReputationRequestItem *deserialiseReputationRequestItem (void *data, uint32_t size);
|
||||
static RsGxsReputationConfigItem *deserialiseReputationConfigItem (void *data, uint32_t size);
|
||||
static RsGxsReputationSetItem *deserialiseReputationSetItem (void *data, uint32_t size);
|
||||
static RsGxsReputationSetItem *deserialiseReputationSetItem_deprecated (void *data, uint32_t size);
|
||||
static RsGxsReputationUpdateItem *deserialiseReputationUpdateItem (void *data, uint32_t size);
|
||||
static RsGxsReputationRequestItem *deserialiseReputationRequestItem (void *data, uint32_t size);
|
||||
static RsGxsReputationBannedNodeSetItem *deserialiseReputationBannedNodeSetItem (void *data, uint32_t size);
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
||||
|
|
|
@ -298,7 +298,7 @@ uint32_t RsSerialiser::size(RsItem *item)
|
|||
{
|
||||
|
||||
#ifdef RSSERIAL_ERROR_DEBUG
|
||||
std::cerr << "RsSerialiser::size() ERROR serialiser missing!";
|
||||
std::cerr << "RsSerialiser::size() ERROR serialiser missing!" << std::endl;
|
||||
|
||||
std::string out;
|
||||
rs_sprintf(out, "%x", item->PacketId());
|
||||
|
|
|
@ -204,6 +204,7 @@ const uint16_t TLV_TYPE_PGPIDSET = 0x1023;
|
|||
const uint16_t TLV_TYPE_RECOGNSET = 0x1024;
|
||||
const uint16_t TLV_TYPE_GXSIDSET = 0x1025;
|
||||
const uint16_t TLV_TYPE_GXSCIRCLEIDSET= 0x1026;
|
||||
const uint16_t TLV_TYPE_NODEGROUPIDSET= 0x1027;
|
||||
|
||||
const uint16_t TLV_TYPE_SERVICESET = 0x1030;
|
||||
|
||||
|
|
|
@ -115,11 +115,12 @@ template<class ID_CLASS,uint32_t TLV_TYPE> class t_RsTlvIdSet: public RsTlvItem
|
|||
std::set<ID_CLASS> ids ;
|
||||
};
|
||||
|
||||
typedef t_RsTlvIdSet<RsPeerId,TLV_TYPE_PEERSET> RsTlvPeerIdSet ;
|
||||
typedef t_RsTlvIdSet<RsPgpId,TLV_TYPE_PGPIDSET> RsTlvPgpIdSet ;
|
||||
typedef t_RsTlvIdSet<Sha1CheckSum,TLV_TYPE_HASHSET> RsTlvHashSet ;
|
||||
typedef t_RsTlvIdSet<RsGxsId,TLV_TYPE_GXSIDSET> RsTlvGxsIdSet ;
|
||||
typedef t_RsTlvIdSet<RsGxsCircleId,TLV_TYPE_GXSCIRCLEIDSET> RsTlvGxsCircleIdSet ;
|
||||
typedef t_RsTlvIdSet<RsPeerId, TLV_TYPE_PEERSET> RsTlvPeerIdSet ;
|
||||
typedef t_RsTlvIdSet<RsPgpId, TLV_TYPE_PGPIDSET> RsTlvPgpIdSet ;
|
||||
typedef t_RsTlvIdSet<Sha1CheckSum, TLV_TYPE_HASHSET> RsTlvHashSet ;
|
||||
typedef t_RsTlvIdSet<RsGxsId, TLV_TYPE_GXSIDSET> RsTlvGxsIdSet ;
|
||||
typedef t_RsTlvIdSet<RsGxsCircleId,TLV_TYPE_GXSCIRCLEIDSET> RsTlvGxsCircleIdSet ;
|
||||
typedef t_RsTlvIdSet<RsNodeGroupId,TLV_TYPE_NODEGROUPIDSET> RsTlvNodeGroupIdSet ;
|
||||
|
||||
class RsTlvServiceIdSet: public RsTlvItem
|
||||
{
|
||||
|
|
|
@ -188,6 +188,76 @@ bool RsTlvRSAKey::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
|||
return ok && checkKey() ;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief RsTlvRSAKey::getKeyTypeTlv: Deserialize data in temp value to get type of key.
|
||||
* @param data: Serialized data
|
||||
* @param size: Size of the data
|
||||
* @param constoffset: Offset where find first data. Not updated by this function.
|
||||
* @return The keyFlag filtered by RSTLV_KEY_TYPE_MASK. 0 if failed
|
||||
*/
|
||||
uint32_t RsTlvRSAKey::getKeyTypeTlv(void *data, uint32_t size, uint32_t *constoffset) const
|
||||
{
|
||||
//Temporay Value. The same name than class to get same code than RsTlvRSAKey::GetTlv
|
||||
uint32_t offValue = *constoffset;
|
||||
uint32_t *offset = &offValue;
|
||||
RsGxsId keyId; // Mandatory :
|
||||
uint32_t keyFlags; // Mandatory ;
|
||||
//The Code below have to be same as RsTlvRSAKey::GetTlv excepted last lines until flag is desserialized.
|
||||
//Just comment TlvClear(); and unused values
|
||||
|
||||
if (size < *offset + TLV_HEADER_SIZE)
|
||||
return false;
|
||||
|
||||
uint16_t tlvtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
|
||||
uint32_t tlvsize = GetTlvSize( &(((uint8_t *) data)[*offset]) );
|
||||
uint32_t tlvend = *offset + tlvsize;
|
||||
|
||||
if (size < tlvend) /* check size */
|
||||
{
|
||||
#ifdef TLV_DEBUG
|
||||
std::cerr << "RsTlvSecurityKey::GetTlv() Fail, not enough space";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
return false; /* not enough space */
|
||||
}
|
||||
|
||||
if (tlvtype != TLV_TYPE_SECURITY_KEY) /* check type */
|
||||
{
|
||||
#ifdef TLV_DEBUG
|
||||
std::cerr << "RsTlvSecurityKey::GetTlv() Fail, wrong type";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
//TlvClear();//RsTlvRSAKey::getKeyTypeTlv
|
||||
|
||||
/* skip the header */
|
||||
(*offset) += TLV_HEADER_SIZE;
|
||||
#ifdef KEEP_OLD_SIGNATURE_SERIALISE_FORMAT
|
||||
std::string s ;
|
||||
ok &= GetTlvString(data, tlvend, offset, TLV_TYPE_STR_KEYID, s);
|
||||
keyId = RsGxsId(s) ;
|
||||
#else
|
||||
ok &= keyId.deserialise(data, tlvend, *offset) ;
|
||||
#endif
|
||||
ok &= getRawUInt32(data, tlvend, offset, &(keyFlags));
|
||||
//Stop here no need more data
|
||||
//RsTlvRSAKey::getKeyTypeTlv specific lines
|
||||
uint32_t ret = keyFlags & RSTLV_KEY_TYPE_MASK;
|
||||
if (!ok)
|
||||
{
|
||||
ret = 0;
|
||||
#ifdef TLV_DEBUG
|
||||
std::cerr << "RsTlvRSAKey::getKeyTypeTlv() Failed somewhere ok == false" << std::endl;
|
||||
#endif
|
||||
}
|
||||
return ret ;
|
||||
}
|
||||
|
||||
std::ostream& RsTlvRSAKey::print(std::ostream &out, uint16_t indent) const
|
||||
{
|
||||
printBase(out, "RsTlvSecurityKey", indent);
|
||||
|
@ -220,12 +290,36 @@ std::ostream& RsTlvRSAKey::print(std::ostream &out, uint16_t indent) const
|
|||
|
||||
bool RsTlvPrivateRSAKey::checkKey() const
|
||||
{
|
||||
return bool(keyFlags & RSTLV_KEY_TYPE_FULL) && !bool(keyFlags & RSTLV_KEY_TYPE_PUBLIC_ONLY) && GxsSecurity::checkPrivateKey(*this) ;
|
||||
bool keyFlags_TYPE_FULL = (keyFlags & RSTLV_KEY_TYPE_FULL);
|
||||
if (!keyFlags_TYPE_FULL) {std::cout << "RsTlvPrivateRSAKey::checkKey() keyFlags not Type Full " << std::hex << keyFlags << " & " << RSTLV_KEY_TYPE_FULL << std::dec << std::endl;}
|
||||
bool keyFlags_not_PUBLIC_ONLY = !(keyFlags & RSTLV_KEY_TYPE_PUBLIC_ONLY);
|
||||
if (!keyFlags_not_PUBLIC_ONLY) {std::cout << "RsTlvPrivateRSAKey::checkKey() keyFlags is Public Only " << std::hex << keyFlags << " & " << RSTLV_KEY_TYPE_PUBLIC_ONLY << std::dec << std::endl;}
|
||||
bool security_OK = false;
|
||||
if (keyFlags_TYPE_FULL && keyFlags_not_PUBLIC_ONLY)
|
||||
{
|
||||
//Don't trigg error if flags already wrong
|
||||
security_OK = GxsSecurity::checkPrivateKey(*this);
|
||||
if (!security_OK) {std::cout << "RsTlvPublicRSAKey::checkKey() key is not secure."<< std::endl;}
|
||||
}
|
||||
|
||||
return keyFlags_TYPE_FULL && keyFlags_not_PUBLIC_ONLY && security_OK ;
|
||||
}
|
||||
|
||||
bool RsTlvPublicRSAKey::checkKey() const
|
||||
{
|
||||
return bool(keyFlags & RSTLV_KEY_TYPE_PUBLIC_ONLY) && !bool(keyFlags & RSTLV_KEY_TYPE_FULL) && GxsSecurity::checkPublicKey(*this) ;
|
||||
{
|
||||
bool keyFlags_PUBLIC_ONLY = (keyFlags & RSTLV_KEY_TYPE_PUBLIC_ONLY);
|
||||
if (!keyFlags_PUBLIC_ONLY) {std::cout << "RsTlvPublicRSAKey::checkKey() keyFlags not Public Only " << std::hex << keyFlags << " & " << RSTLV_KEY_TYPE_PUBLIC_ONLY << std::dec << std::endl;}
|
||||
bool keyFlags_not_TYPE_FULL = !(keyFlags & RSTLV_KEY_TYPE_FULL);
|
||||
if (!keyFlags_not_TYPE_FULL) {std::cout << "RsTlvPublicRSAKey::checkKey() keyFlags is Type Full " << std::hex << keyFlags << " & " << RSTLV_KEY_TYPE_FULL << std::dec << std::endl;}
|
||||
bool security_OK = false;
|
||||
if (keyFlags_PUBLIC_ONLY && keyFlags_not_TYPE_FULL)
|
||||
{
|
||||
//Don't trigg error if flags already wrong
|
||||
security_OK = GxsSecurity::checkPublicKey(*this);
|
||||
if (!security_OK) {std::cout << "RsTlvPublicRSAKey::checkKey() key is not secure."<< std::endl;}
|
||||
}
|
||||
|
||||
return keyFlags_PUBLIC_ONLY && keyFlags_not_TYPE_FULL && security_OK ;
|
||||
}
|
||||
|
||||
/************************************* RsTlvSecurityKeySet ************************************/
|
||||
|
@ -320,21 +414,23 @@ bool RsTlvSecurityKeySet::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
|||
/* get the next type */
|
||||
uint16_t tlvsubtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
|
||||
|
||||
// Security key set can be composed of public or private keys. We sort them into the correct bins after deserialisation
|
||||
|
||||
// Security key set can be composed of public or private keys. We first ask type to desserialize in good one to not trigg errors.
|
||||
switch(tlvsubtype)
|
||||
{
|
||||
case TLV_TYPE_SECURITY_KEY:
|
||||
{
|
||||
uint32_t offset_save = *offset ;
|
||||
|
||||
RsTlvPublicRSAKey public_key;
|
||||
|
||||
if(public_key.GetTlv(data, tlvend, offset))
|
||||
public_keys[public_key.keyId] = public_key;
|
||||
else
|
||||
RsTlvPublicRSAKey gen_key;
|
||||
uint32_t keyType = gen_key.getKeyTypeTlv(data, tlvend, offset);
|
||||
if(keyType == RSTLV_KEY_TYPE_PUBLIC_ONLY)
|
||||
{
|
||||
|
||||
RsTlvPublicRSAKey public_key;
|
||||
|
||||
if(public_key.GetTlv(data, tlvend, offset))
|
||||
public_keys[public_key.keyId] = public_key;
|
||||
}
|
||||
else if(keyType == RSTLV_KEY_TYPE_FULL)
|
||||
{
|
||||
*offset = offset_save ;
|
||||
|
||||
RsTlvPrivateRSAKey private_key;
|
||||
|
||||
|
@ -342,7 +438,7 @@ bool RsTlvSecurityKeySet::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
|||
private_keys[private_key.keyId] = private_key;
|
||||
}
|
||||
}
|
||||
break ;
|
||||
break ;
|
||||
|
||||
default:
|
||||
ok &= SkipUnknownTlv(data, tlvend, offset);
|
||||
|
|
|
@ -63,7 +63,9 @@ public:
|
|||
|
||||
/* clears KeyData - but doesn't delete - to transfer ownership */
|
||||
void ShallowClear();
|
||||
|
||||
|
||||
uint32_t getKeyTypeTlv(void *data, uint32_t size, uint32_t *offset) const;
|
||||
|
||||
RsGxsId keyId; // Mandatory :
|
||||
uint32_t keyFlags; // Mandatory ;
|
||||
uint32_t startTS; // Mandatory :
|
||||
|
@ -75,17 +77,19 @@ public:
|
|||
|
||||
class RsTlvPrivateRSAKey: public RsTlvRSAKey
|
||||
{
|
||||
public:
|
||||
virtual ~RsTlvPrivateRSAKey() {}
|
||||
public:
|
||||
RsTlvPrivateRSAKey():RsTlvRSAKey() {}
|
||||
virtual ~RsTlvPrivateRSAKey() {}
|
||||
|
||||
virtual bool checkKey() const ;
|
||||
virtual bool checkKey() const ;
|
||||
};
|
||||
class RsTlvPublicRSAKey: public RsTlvRSAKey
|
||||
{
|
||||
public:
|
||||
virtual ~RsTlvPublicRSAKey() {}
|
||||
public:
|
||||
RsTlvPublicRSAKey():RsTlvRSAKey() {}
|
||||
virtual ~RsTlvPublicRSAKey() {}
|
||||
|
||||
virtual bool checkKey() const ;
|
||||
virtual bool checkKey() const ;
|
||||
};
|
||||
|
||||
class RsTlvSecurityKeySet: public RsTlvItem
|
||||
|
|
|
@ -206,6 +206,8 @@ void p3BanList::autoFigureOutBanRanges()
|
|||
{
|
||||
RS_STACK_MUTEX(mBanMtx) ;
|
||||
|
||||
bool changed = false ;
|
||||
|
||||
// clear automatic ban ranges
|
||||
|
||||
for(std::map<sockaddr_storage,BanListPeer>::iterator it(mBanRanges.begin());it!=mBanRanges.end();)
|
||||
|
@ -215,6 +217,8 @@ void p3BanList::autoFigureOutBanRanges()
|
|||
++it2 ;
|
||||
mBanRanges.erase(it) ;
|
||||
it=it2 ;
|
||||
|
||||
changed = true ;
|
||||
}
|
||||
else
|
||||
++it;
|
||||
|
@ -968,7 +972,9 @@ bool p3BanList::addBanEntry(const RsPeerId &peerId, const struct sockaddr_storag
|
|||
updated = true;
|
||||
}
|
||||
}
|
||||
IndicateConfigChanged();
|
||||
|
||||
if(updated)
|
||||
IndicateConfigChanged();
|
||||
|
||||
return updated;
|
||||
}
|
||||
|
|
|
@ -380,6 +380,7 @@ bool p3GxsCircles::loadCircle(const RsGxsCircleId &circleId)
|
|||
return cache_request_load(circleId);
|
||||
}
|
||||
|
||||
|
||||
int p3GxsCircles::canSend(const RsGxsCircleId &circleId, const RsPgpId &id, bool& should_encrypt)
|
||||
{
|
||||
RsStackMutex stack(mCircleMtx); /********** STACK LOCKED MTX ******/
|
||||
|
@ -1053,6 +1054,11 @@ bool p3GxsCircles::locked_processLoadingCacheEntry(RsGxsCircleCache& cache)
|
|||
std::cerr << "Processing External Circle " << cache.mCircleId << std::endl;
|
||||
#endif
|
||||
|
||||
// Do we actually need to retrieve the missing keys for all members of a circle???
|
||||
// These keys are needed for subscribtion request signature checking. But this is only
|
||||
// when a subscription msg is posted, which would trigger retrieval of the key anyway
|
||||
// Maybe this can be made an option of p3GxsCircles, or of rsIdentity.
|
||||
|
||||
// need to trigger the searches.
|
||||
for(std::map<RsGxsId,RsGxsCircleMembershipStatus>::iterator pit = cache.mMembershipStatus.begin(); pit != cache.mMembershipStatus.end(); ++pit)
|
||||
{
|
||||
|
@ -1072,7 +1078,7 @@ bool p3GxsCircles::locked_processLoadingCacheEntry(RsGxsCircleCache& cache)
|
|||
}
|
||||
else
|
||||
{
|
||||
std::list<PeerId> peers;
|
||||
std::list<RsPeerId> peers;
|
||||
|
||||
if(!cache.mOriginator.isNull())
|
||||
{
|
||||
|
|
|
@ -116,13 +116,13 @@
|
|||
* 10 | 1.0 | 0 | 0.25 | 1.0
|
||||
*
|
||||
* To check:
|
||||
* [ ] Opinions are saved/loaded accross restart
|
||||
* [ ] Opinions are transmitted to friends
|
||||
* [ ] Opinions are transmitted to friends when updated
|
||||
* [X] Opinions are saved/loaded accross restart
|
||||
* [X] Opinions are transmitted to friends
|
||||
* [X] Opinions are transmitted to friends when updated
|
||||
*
|
||||
* To do:
|
||||
* [ ] Add debug info
|
||||
* [ ] Test the whole thing
|
||||
* [X] Add debug info
|
||||
* [X] Test the whole thing
|
||||
* [X] Implement a system to allow not storing info when we don't have it
|
||||
*/
|
||||
|
||||
|
@ -134,10 +134,12 @@ static const int ACTIVE_FRIENDS_UPDATE_PERIOD = 600 ; // 10 minu
|
|||
static const int ACTIVE_FRIENDS_ONLINE_DELAY = 86400*7 ; // 1 week.
|
||||
static const int kReputationRequestPeriod = 600; // 10 mins
|
||||
static const int kReputationStoreWait = 180; // 3 minutes.
|
||||
static const float REPUTATION_ASSESSMENT_THRESHOLD_X1 = 0.5f ; // reputation under which the peer gets killed
|
||||
static const float REPUTATION_ASSESSMENT_THRESHOLD_X1 = 0.5f ; // reputation under which the peer gets killed. Warning there's a 1 shift with what's shown in GUI. Be careful.
|
||||
static const uint32_t PGP_AUTO_BAN_THRESHOLD_DEFAULT = 2 ; // above this, auto ban any GXS id signed by this node
|
||||
static const uint32_t IDENTITY_FLAGS_UPDATE_DELAY = 100 ; //
|
||||
static const uint32_t BANNED_NODES_UPDATE_DELAY = 313 ; // update approx every 5 mins. Chosen to not be a multiple of IDENTITY_FLAGS_UPDATE_DELAY
|
||||
static const uint32_t REPUTATION_INFO_KEEP_DELAY = 86400*35; // remove old reputation info 5 days after last usage limit, in case the ID would come back..
|
||||
static const uint32_t BANNED_NODES_INACTIVITY_KEEP = 86400*60; // remove all info about banned nodes after 2 months of inactivity
|
||||
|
||||
p3GxsReputation::p3GxsReputation(p3LinkMgr *lm)
|
||||
:p3Service(), p3Config(),
|
||||
|
@ -145,13 +147,18 @@ p3GxsReputation::p3GxsReputation(p3LinkMgr *lm)
|
|||
{
|
||||
addSerialType(new RsGxsReputationSerialiser());
|
||||
|
||||
mPgpAutoBanThreshold = PGP_AUTO_BAN_THRESHOLD_DEFAULT ;
|
||||
//mPgpAutoBanThreshold = PGP_AUTO_BAN_THRESHOLD_DEFAULT ;
|
||||
mRequestTime = 0;
|
||||
mStoreTime = 0;
|
||||
mReputationsUpdated = false;
|
||||
mLastActiveFriendsUpdate = 0 ;
|
||||
mLastActiveFriendsUpdate = time(NULL) - 0.5*ACTIVE_FRIENDS_UPDATE_PERIOD; // avoids doing it too soon since the TS from rsIdentity needs to be loaded already
|
||||
mLastIdentityFlagsUpdate = time(NULL) - 3;
|
||||
mAverageActiveFriends = 0 ;
|
||||
mLastBannedNodesUpdate = 0 ;
|
||||
mBannedNodesProxyNeedsUpdate = false;
|
||||
|
||||
mAutoBanIdentitiesLimit = REPUTATION_ASSESSMENT_THRESHOLD_X1;
|
||||
mAutoSetPositiveOptionToContacts = true; // default
|
||||
}
|
||||
|
||||
const std::string GXS_REPUTATION_APP_NAME = "gxsreputation";
|
||||
|
@ -185,22 +192,24 @@ int p3GxsReputation::tick()
|
|||
mLastActiveFriendsUpdate = now ;
|
||||
}
|
||||
|
||||
static time_t last_identity_flags_update = 0 ;
|
||||
|
||||
// no more than once per 5 second chunk.
|
||||
|
||||
if(now > IDENTITY_FLAGS_UPDATE_DELAY+last_identity_flags_update)
|
||||
if(now > IDENTITY_FLAGS_UPDATE_DELAY+mLastIdentityFlagsUpdate)
|
||||
{
|
||||
last_identity_flags_update = now ;
|
||||
|
||||
updateIdentityFlags() ;
|
||||
mLastIdentityFlagsUpdate = now ;
|
||||
}
|
||||
if(now > BANNED_NODES_UPDATE_DELAY+mLastBannedNodesUpdate) // 613 is not a multiple of 100, to avoid piling up work
|
||||
{
|
||||
mLastBannedNodesUpdate = now ;
|
||||
|
||||
updateIdentityFlags() ; // needed before updateBannedNodesList!
|
||||
updateBannedNodesList();
|
||||
updateBannedNodesProxy();
|
||||
mLastBannedNodesUpdate = now ;
|
||||
}
|
||||
|
||||
if(mBannedNodesProxyNeedsUpdate)
|
||||
{
|
||||
updateBannedNodesProxy();
|
||||
mBannedNodesProxyNeedsUpdate = false ;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_REPUTATION
|
||||
|
@ -215,20 +224,58 @@ int p3GxsReputation::tick()
|
|||
return 0;
|
||||
}
|
||||
|
||||
void p3GxsReputation::setNodeAutoBanThreshold(uint32_t n)
|
||||
// void p3GxsReputation::setNodeAutoBanThreshold(uint32_t n)
|
||||
// {
|
||||
// RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||
//
|
||||
// if(n != mPgpAutoBanThreshold)
|
||||
// {
|
||||
// mLastBannedNodesUpdate = 0 ;
|
||||
// mPgpAutoBanThreshold = n ;
|
||||
// IndicateConfigChanged() ;
|
||||
// }
|
||||
// }
|
||||
// uint32_t p3GxsReputation::nodeAutoBanThreshold()
|
||||
// {
|
||||
// return mPgpAutoBanThreshold ;
|
||||
// }
|
||||
|
||||
void p3GxsReputation::setNodeAutoPositiveOpinionForContacts(bool b)
|
||||
{
|
||||
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||
|
||||
if(n != mPgpAutoBanThreshold)
|
||||
if(b != mAutoSetPositiveOptionToContacts)
|
||||
{
|
||||
mLastBannedNodesUpdate = 0 ;
|
||||
mPgpAutoBanThreshold = n ;
|
||||
IndicateConfigChanged() ;
|
||||
mLastIdentityFlagsUpdate = 0 ;
|
||||
mAutoSetPositiveOptionToContacts = b ;
|
||||
IndicateConfigChanged() ;
|
||||
}
|
||||
}
|
||||
uint32_t p3GxsReputation::nodeAutoBanThreshold()
|
||||
bool p3GxsReputation::nodeAutoPositiveOpinionForContacts()
|
||||
{
|
||||
return mPgpAutoBanThreshold ;
|
||||
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||
return mAutoSetPositiveOptionToContacts ;
|
||||
}
|
||||
float p3GxsReputation::nodeAutoBanIdentitiesLimit()
|
||||
{
|
||||
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||
return mAutoBanIdentitiesLimit - 1.0f;
|
||||
}
|
||||
void p3GxsReputation::setNodeAutoBanIdentitiesLimit(float f)
|
||||
{
|
||||
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||
|
||||
if(f < -1.0 || f >= 0.0)
|
||||
{
|
||||
std::cerr << "(EE) Unexpected value for auto ban identities limit: " << f << std::endl;
|
||||
return ;
|
||||
}
|
||||
if(f != mAutoBanIdentitiesLimit)
|
||||
{
|
||||
mLastBannedNodesUpdate = 0 ;
|
||||
mAutoBanIdentitiesLimit = f+1.0 ;
|
||||
IndicateConfigChanged() ;
|
||||
}
|
||||
}
|
||||
|
||||
int p3GxsReputation::status()
|
||||
|
@ -245,33 +292,21 @@ class ZeroInitCnt
|
|||
operator uint32_t() const { return cnt ; }
|
||||
};
|
||||
|
||||
void p3GxsReputation::updateBannedNodesList()
|
||||
void p3GxsReputation::updateBannedNodesProxy()
|
||||
{
|
||||
#ifdef DEBUG_REPUTATION
|
||||
std::cerr << "Updating PGP ban list based on signed GxsIds to ban" << std::endl;
|
||||
#endif
|
||||
std::map<RsGxsId, Reputation> tmpreps ;
|
||||
//#ifdef DEBUG_REPUTATION
|
||||
// std::cerr << "Updating PGP ban list based on signed GxsIds to ban. Ban threshold = " << mPgpAutoBanThreshold << std::endl;
|
||||
//#endif
|
||||
// This function keeps the Banned GXS id proxy up to date.
|
||||
//
|
||||
|
||||
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||
tmpreps = mReputations ;
|
||||
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||
|
||||
std::map<RsPgpId,ZeroInitCnt> pgp_ids_to_ban ;
|
||||
mPerNodeBannedIdsProxy.clear();
|
||||
|
||||
for( std::map<RsGxsId, Reputation>::iterator rit = tmpreps.begin();rit!=tmpreps.end();++rit)
|
||||
if((rit->second.mIdentityFlags & REPUTATION_IDENTITY_FLAG_PGP_LINKED) && !rit->second.mOwnerNode.isNull() && rit->second.mOwnOpinion == p3GxsReputation::OPINION_NEGATIVE)
|
||||
++pgp_ids_to_ban[rit->second.mOwnerNode] ;
|
||||
|
||||
mBannedPgpIds.clear() ;
|
||||
|
||||
if(mPgpAutoBanThreshold > 0)
|
||||
for(std::map<RsPgpId,ZeroInitCnt>::const_iterator it(pgp_ids_to_ban.begin());it!=pgp_ids_to_ban.end();++it)
|
||||
{
|
||||
#ifdef DEBUG_REPUTATION
|
||||
std::cerr << "PGP Id: " << it->first << ". Ban count=" << it->second << " - " << (( it->second >= mPgpAutoBanThreshold)?"Banned!":"OK" ) << std::endl;
|
||||
#endif
|
||||
if(it->second >= mPgpAutoBanThreshold)
|
||||
mBannedPgpIds.insert(it->first) ;
|
||||
}
|
||||
for( std::map<RsPgpId, BannedNodeInfo>::iterator rit = mBannedPgpIds.begin();rit!=mBannedPgpIds.end();++rit)
|
||||
for(std::set<RsGxsId>::const_iterator it(rit->second.known_identities.begin());it!=rit->second.known_identities.end();++it)
|
||||
mPerNodeBannedIdsProxy.insert(*it) ;
|
||||
}
|
||||
|
||||
void p3GxsReputation::updateIdentityFlags()
|
||||
|
@ -287,10 +322,12 @@ void p3GxsReputation::updateIdentityFlags()
|
|||
#endif
|
||||
|
||||
for( std::map<RsGxsId, Reputation>::iterator rit = mReputations.begin();rit!=mReputations.end();++rit)
|
||||
if(rit->second.mIdentityFlags & REPUTATION_IDENTITY_FLAG_NEEDS_UPDATE)
|
||||
if( (rit->second.mIdentityFlags & REPUTATION_IDENTITY_FLAG_NEEDS_UPDATE) && (mPerNodeBannedIdsProxy.find(rit->first) == mPerNodeBannedIdsProxy.end()))
|
||||
to_update.push_back(rit->first) ;
|
||||
}
|
||||
|
||||
std::list<RsGxsId> should_set_to_positive ;
|
||||
|
||||
for(std::list<RsGxsId>::const_iterator rit(to_update.begin());rit!=to_update.end();++rit)
|
||||
{
|
||||
RsIdentityDetails details;
|
||||
|
@ -302,42 +339,114 @@ void p3GxsReputation::updateIdentityFlags()
|
|||
#endif
|
||||
continue ;
|
||||
}
|
||||
bool is_a_contact = rsIdentity->isARegularContact(*rit) ;
|
||||
|
||||
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||
{
|
||||
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||
std::map<RsGxsId,Reputation>::iterator it = mReputations.find(*rit) ;
|
||||
|
||||
std::map<RsGxsId,Reputation>::iterator it = mReputations.find(*rit) ;
|
||||
if(it == mReputations.end())
|
||||
{
|
||||
std::cerr << " Weird situation: item " << *rit << " has been deleted from the list??" << std::endl;
|
||||
continue ;
|
||||
}
|
||||
it->second.mIdentityFlags = 0 ;
|
||||
|
||||
if(it == mReputations.end())
|
||||
{
|
||||
std::cerr << " Weird situation: item " << *rit << " has been deleted from the list??" << std::endl;
|
||||
continue ;
|
||||
}
|
||||
it->second.mIdentityFlags = 0 ;
|
||||
if(details.mFlags & RS_IDENTITY_FLAGS_PGP_LINKED)
|
||||
{
|
||||
it->second.mIdentityFlags |= REPUTATION_IDENTITY_FLAG_PGP_LINKED ;
|
||||
it->second.mOwnerNode = details.mPgpId ;
|
||||
}
|
||||
if(details.mFlags & RS_IDENTITY_FLAGS_PGP_KNOWN ) it->second.mIdentityFlags |= REPUTATION_IDENTITY_FLAG_PGP_KNOWN ;
|
||||
|
||||
if(details.mFlags & RS_IDENTITY_FLAGS_PGP_LINKED)
|
||||
{
|
||||
it->second.mIdentityFlags |= REPUTATION_IDENTITY_FLAG_PGP_LINKED ;
|
||||
it->second.mOwnerNode = details.mPgpId ;
|
||||
}
|
||||
if(details.mFlags & RS_IDENTITY_FLAGS_PGP_KNOWN ) it->second.mIdentityFlags |= REPUTATION_IDENTITY_FLAG_PGP_KNOWN ;
|
||||
if(mAutoSetPositiveOptionToContacts && is_a_contact && it->second.mOwnOpinion == RsReputations::OPINION_NEUTRAL)
|
||||
should_set_to_positive.push_back(*rit) ;
|
||||
|
||||
#ifdef DEBUG_REPUTATION
|
||||
std::cerr << " updated flags for " << *rit << " to " << std::hex << it->second.mIdentityFlags << std::dec << std::endl;
|
||||
std::cerr << " updated flags for " << *rit << " to " << std::hex << it->second.mIdentityFlags << std::dec << std::endl;
|
||||
#endif
|
||||
|
||||
it->second.updateReputation() ;
|
||||
IndicateConfigChanged();
|
||||
it->second.updateReputation() ;
|
||||
IndicateConfigChanged();
|
||||
}
|
||||
}
|
||||
|
||||
for(std::list<RsGxsId>::const_iterator it(should_set_to_positive.begin());it!=should_set_to_positive.end();++it)
|
||||
setOwnOpinion(*it,RsReputations::OPINION_POSITIVE) ;
|
||||
}
|
||||
|
||||
void p3GxsReputation::cleanup()
|
||||
{
|
||||
// remove opinions from friends that havn't been seen online for more than the specified delay
|
||||
|
||||
// remove opinions from friends that havn't been seen online for more than the specified delay
|
||||
|
||||
#ifdef DEBUG_REPUTATION
|
||||
std::cerr << "p3GxsReputation::cleanup() " << std::endl;
|
||||
#endif
|
||||
std::cerr << __PRETTY_FUNCTION__ << ": not implemented. TODO!" << std::endl;
|
||||
std::cerr << "p3GxsReputation::cleanup() " << std::endl;
|
||||
|
||||
// Remove opinions about identities that do not exist anymore. That will in particular avoid asking p3idservice about deleted
|
||||
// identities, which would cause an excess of hits to the database. We do it in two steps to avoid a deadlock when calling rsIdentity from here.
|
||||
// Also, neutral opinions for banned PGP linked nodes are kept, so as to be able to not request them again.
|
||||
|
||||
bool updated = false ;
|
||||
time_t now = time(NULL) ;
|
||||
|
||||
std::list<RsGxsId> ids_to_check_for_last_usage_ts;
|
||||
|
||||
{
|
||||
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||
|
||||
for(std::map<RsGxsId,Reputation>::iterator it(mReputations.begin());it!=mReputations.end();)
|
||||
if(it->second.mOpinions.empty() && it->second.mOwnOpinion == RsReputations::OPINION_NEUTRAL && (it->second.mOwnerNode.isNull()))
|
||||
{
|
||||
#ifdef DEBUG_REPUTATION
|
||||
std::cerr << " ID " << it->first << ": own is neutral and no opinions from friends => remove entry" << std::endl;
|
||||
#endif
|
||||
std::map<RsGxsId,Reputation>::iterator tmp(it) ;
|
||||
++tmp ;
|
||||
mReputations.erase(it) ;
|
||||
it = tmp ;
|
||||
updated = true ;
|
||||
}
|
||||
else
|
||||
{
|
||||
ids_to_check_for_last_usage_ts.push_back(it->first) ;
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
for(std::list<RsGxsId>::const_iterator it(ids_to_check_for_last_usage_ts.begin());it!=ids_to_check_for_last_usage_ts.end();++it)
|
||||
if(rsIdentity->getLastUsageTS(*it) + REPUTATION_INFO_KEEP_DELAY < now)
|
||||
{
|
||||
#ifdef DEBUG_REPUTATION
|
||||
std::cerr << " Identity " << *it << " has a last usage TS of " << now - rsIdentity->getLastUsageTS(*it) << " secs ago: deleting it." << std::endl;
|
||||
#endif
|
||||
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||
mReputations.erase(*it) ;
|
||||
updated = true ;
|
||||
}
|
||||
|
||||
{
|
||||
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||
|
||||
for(std::map<RsPgpId,BannedNodeInfo>::iterator it(mBannedPgpIds.begin());it!=mBannedPgpIds.end();)
|
||||
if(it->second.last_activity_TS + BANNED_NODES_INACTIVITY_KEEP < now)
|
||||
{
|
||||
#ifdef DEBUG_REPUTATION
|
||||
std::cerr << " Removing all info about banned node " << it->first << " by lack of activity." << std::endl;
|
||||
#endif
|
||||
std::map<RsPgpId,BannedNodeInfo>::iterator tmp(it ) ;
|
||||
++tmp ;
|
||||
mBannedPgpIds.erase(it) ;
|
||||
it = tmp ;
|
||||
|
||||
updated = true ;
|
||||
}
|
||||
else
|
||||
++it ;
|
||||
}
|
||||
|
||||
if(updated)
|
||||
IndicateConfigChanged() ;
|
||||
}
|
||||
|
||||
void p3GxsReputation::updateActiveFriends()
|
||||
|
@ -399,8 +508,8 @@ bool p3GxsReputation::processIncoming()
|
|||
switch(item->PacketSubType())
|
||||
{
|
||||
default:
|
||||
case RS_PKT_SUBTYPE_GXS_REPUTATION_CONFIG_ITEM:
|
||||
case RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM:
|
||||
case RS_PKT_SUBTYPE_GXS_REPUTATION_CONFIG_ITEM:
|
||||
case RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM:
|
||||
std::cerr << "p3GxsReputation::processingIncoming() Unknown Item";
|
||||
std::cerr << std::endl;
|
||||
itemOk = false;
|
||||
|
@ -668,49 +777,113 @@ bool p3GxsReputation::updateLatestUpdate(RsPeerId peerid,time_t latest_update)
|
|||
* Opinion
|
||||
****/
|
||||
|
||||
bool p3GxsReputation::getReputationInfo(const RsGxsId& gxsid, RsReputations::ReputationInfo& info)
|
||||
bool p3GxsReputation::getReputationInfo(const RsGxsId& gxsid, const RsPgpId& ownerNode, RsReputations::ReputationInfo& info)
|
||||
{
|
||||
if(gxsid.isNull())
|
||||
return false ;
|
||||
|
||||
time_t now = time(NULL) ;
|
||||
|
||||
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||
|
||||
#ifdef DEBUG_REPUTATION
|
||||
#ifdef DEBUG_REPUTATION2
|
||||
std::cerr << "getReputationInfo() for " << gxsid << std::endl;
|
||||
#endif
|
||||
Reputation& rep(mReputations[gxsid]) ;
|
||||
std::map<RsGxsId,Reputation>::iterator it = mReputations.find(gxsid) ;
|
||||
RsPgpId owner_id ;
|
||||
|
||||
info.mOwnOpinion = RsReputations::Opinion(rep.mOwnOpinion) ;
|
||||
info.mOverallReputationScore = rep.mReputation ;
|
||||
info.mFriendAverage = rep.mFriendAverage ;
|
||||
|
||||
if( (rep.mIdentityFlags & REPUTATION_IDENTITY_FLAG_PGP_LINKED) && (mBannedPgpIds.find(rep.mOwnerNode) != mBannedPgpIds.end()))
|
||||
if(it == mReputations.end())
|
||||
{
|
||||
info.mAssessment = RsReputations::ASSESSMENT_BAD ;
|
||||
#ifdef DEBUG_REPUTATION
|
||||
std::cerr << "p3GxsReputations: identity " << gxsid << " is banned because owner node ID " << rep.mOwnerNode << " is banned." << std::endl;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
if(info.mOverallReputationScore > REPUTATION_ASSESSMENT_THRESHOLD_X1)
|
||||
info.mAssessment = RsReputations::ASSESSMENT_OK ;
|
||||
else
|
||||
info.mAssessment = RsReputations::ASSESSMENT_BAD ;
|
||||
info.mOwnOpinion = RsReputations::OPINION_NEUTRAL ;
|
||||
info.mOverallReputationScore = RsReputations::REPUTATION_THRESHOLD_DEFAULT ;
|
||||
info.mFriendAverage = REPUTATION_THRESHOLD_DEFAULT ;
|
||||
|
||||
#ifdef DEBUG_REPUTATION
|
||||
std::cerr << " information present. OwnOp = " << info.mOwnOpinion << ", overall score=" << info.mAssessment << std::endl;
|
||||
owner_id = ownerNode ;
|
||||
}
|
||||
else
|
||||
{
|
||||
Reputation& rep(it->second) ;
|
||||
|
||||
info.mOwnOpinion = RsReputations::Opinion(rep.mOwnOpinion) ;
|
||||
info.mOverallReputationScore = rep.mReputation ;
|
||||
info.mFriendAverage = rep.mFriendAverage ;
|
||||
|
||||
if(rep.mOwnerNode.isNull())
|
||||
rep.mOwnerNode = ownerNode ;
|
||||
|
||||
owner_id = rep.mOwnerNode ;
|
||||
}
|
||||
|
||||
std::map<RsPgpId,BannedNodeInfo>::iterator it2 ;
|
||||
|
||||
if(!owner_id.isNull() && (it2 = mBannedPgpIds.find(owner_id))!=mBannedPgpIds.end())
|
||||
{
|
||||
if(it2->second.known_identities.find(gxsid) == it2->second.known_identities.end())
|
||||
{
|
||||
it2->second.known_identities.insert(gxsid) ;
|
||||
it2->second.last_activity_TS = now ;
|
||||
mBannedNodesProxyNeedsUpdate = true ;
|
||||
}
|
||||
|
||||
info.mAssessment = RsReputations::ASSESSMENT_BAD ;
|
||||
#ifdef DEBUG_REPUTATION2
|
||||
std::cerr << "p3GxsReputations: identity " << gxsid << " is banned because owner node ID " << owner_id << " is banned (found in banned nodes list)." << std::endl;
|
||||
#endif
|
||||
}
|
||||
else if(mPerNodeBannedIdsProxy.find(gxsid) != mPerNodeBannedIdsProxy.end())
|
||||
{
|
||||
#ifdef DEBUG_REPUTATION2
|
||||
std::cerr << "p3GxsReputations: identity " << gxsid << " is banned because owner node ID " << owner_id << " is banned (found in proxy)." << std::endl;
|
||||
#endif
|
||||
info.mAssessment = RsReputations::ASSESSMENT_BAD ;
|
||||
}
|
||||
else if(info.mOverallReputationScore <= mAutoBanIdentitiesLimit)
|
||||
info.mAssessment = RsReputations::ASSESSMENT_BAD ;
|
||||
else
|
||||
info.mAssessment = RsReputations::ASSESSMENT_OK ;
|
||||
|
||||
#ifdef DEBUG_REPUTATION2
|
||||
std::cerr << " information present. OwnOp = " << info.mOwnOpinion << ", owner node=" << owner_id << ", overall score=" << info.mAssessment << std::endl;
|
||||
#endif
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
void p3GxsReputation::banNode(const RsPgpId& id,bool b)
|
||||
{
|
||||
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||
|
||||
if(b)
|
||||
{
|
||||
if(mBannedPgpIds.find(id) == mBannedPgpIds.end())
|
||||
{
|
||||
mBannedPgpIds[id] = BannedNodeInfo() ;
|
||||
IndicateConfigChanged();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(mBannedPgpIds.find(id) != mBannedPgpIds.end())
|
||||
{
|
||||
mBannedPgpIds.erase(id) ;
|
||||
IndicateConfigChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
bool p3GxsReputation::isNodeBanned(const RsPgpId& id)
|
||||
{
|
||||
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||
|
||||
return mBannedPgpIds.find(id) != mBannedPgpIds.end();
|
||||
}
|
||||
|
||||
bool p3GxsReputation::isIdentityBanned(const RsGxsId &id)
|
||||
{
|
||||
RsReputations::ReputationInfo info ;
|
||||
|
||||
getReputationInfo(id,info) ;
|
||||
|
||||
if(!getReputationInfo(id,RsPgpId(),info))
|
||||
return false ;
|
||||
|
||||
#ifdef DEBUG_REPUTATION
|
||||
std::cerr << "isIdentityBanned(): returning " << (info.mAssessment == RsReputations::ASSESSMENT_BAD) << " for GXS id " << id << std::endl;
|
||||
#endif
|
||||
|
@ -827,6 +1000,7 @@ bool p3GxsReputation::saveList(bool& cleanup, std::list<RsItem*> &savelist)
|
|||
item->mOwnOpinion = rit->second.mOwnOpinion;
|
||||
item->mOwnOpinionTS = rit->second.mOwnOpinionTs;
|
||||
item->mIdentityFlags = rit->second.mIdentityFlags;
|
||||
item->mOwnerNodeId = rit->second.mOwnerNode;
|
||||
|
||||
std::map<RsPeerId, RsReputations::Opinion>::iterator oit;
|
||||
for(oit = rit->second.mOpinions.begin(); oit != rit->second.mOpinions.end(); ++oit)
|
||||
|
@ -838,14 +1012,33 @@ bool p3GxsReputation::saveList(bool& cleanup, std::list<RsItem*> &savelist)
|
|||
savelist.push_back(item);
|
||||
count++;
|
||||
}
|
||||
|
||||
for(std::map<RsPgpId,BannedNodeInfo>::const_iterator it(mBannedPgpIds.begin());it!=mBannedPgpIds.end();++it)
|
||||
{
|
||||
RsGxsReputationBannedNodeSetItem *item = new RsGxsReputationBannedNodeSetItem();
|
||||
|
||||
item->mPgpId = it->first ;
|
||||
item->mLastActivityTS = it->second.last_activity_TS;
|
||||
item->mKnownIdentities.ids = it->second.known_identities;
|
||||
|
||||
savelist.push_back(item) ;
|
||||
}
|
||||
|
||||
RsConfigKeyValueSet *vitem = new RsConfigKeyValueSet ;
|
||||
RsTlvKeyValue kv;
|
||||
kv.key = "AUTO_BAN_NODES_THRESHOLD" ;
|
||||
rs_sprintf(kv.value, "%d", mPgpAutoBanThreshold);
|
||||
vitem->tlvkvs.pairs.push_back(kv) ;
|
||||
// kv.key = "AUTO_BAN_NODES_THRESHOLD" ;
|
||||
// rs_sprintf(kv.value, "%d", mPgpAutoBanThreshold);
|
||||
// vitem->tlvkvs.pairs.push_back(kv) ;
|
||||
|
||||
savelist.push_back(vitem) ;
|
||||
kv.key = "AUTO_BAN_IDENTITIES_THRESHOLD" ;
|
||||
rs_sprintf(kv.value, "%f", mAutoBanIdentitiesLimit);
|
||||
vitem->tlvkvs.pairs.push_back(kv) ;
|
||||
|
||||
kv.key = "AUTO_POSITIVE_CONTACTS" ;
|
||||
kv.value = mAutoSetPositiveOptionToContacts?"YES":"NO";
|
||||
vitem->tlvkvs.pairs.push_back(kv) ;
|
||||
|
||||
savelist.push_back(vitem) ;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -858,7 +1051,7 @@ void p3GxsReputation::saveDone()
|
|||
bool p3GxsReputation::loadList(std::list<RsItem *>& loadList)
|
||||
{
|
||||
#ifdef DEBUG_REPUTATION
|
||||
std::cerr << "p3GxsReputation::saveList()" << std::endl;
|
||||
std::cerr << "p3GxsReputation::loadList()" << std::endl;
|
||||
#endif
|
||||
std::list<RsItem *>::iterator it;
|
||||
std::set<RsPeerId> peerSet;
|
||||
|
@ -877,79 +1070,117 @@ bool p3GxsReputation::loadList(std::list<RsItem *>& loadList)
|
|||
config.mLatestUpdate = item->mLatestUpdate;
|
||||
config.mLastQuery = 0;
|
||||
|
||||
peerSet.insert(peerId);
|
||||
peerSet.insert(peerId);
|
||||
}
|
||||
|
||||
RsGxsReputationSetItem *set = dynamic_cast<RsGxsReputationSetItem *>(*it);
|
||||
|
||||
if (set)
|
||||
loadReputationSet(set, peerSet);
|
||||
|
||||
|
||||
RsGxsReputationBannedNodeSetItem *itm2 = dynamic_cast<RsGxsReputationBannedNodeSetItem*>(*it) ;
|
||||
|
||||
if(itm2 != NULL)
|
||||
{
|
||||
BannedNodeInfo& info(mBannedPgpIds[itm2->mPgpId]) ;
|
||||
info.last_activity_TS = itm2->mLastActivityTS ;
|
||||
info.known_identities = itm2->mKnownIdentities.ids ;
|
||||
}
|
||||
|
||||
RsConfigKeyValueSet *vitem = dynamic_cast<RsConfigKeyValueSet *>(*it);
|
||||
|
||||
if(vitem)
|
||||
for(std::list<RsTlvKeyValue>::const_iterator kit = vitem->tlvkvs.pairs.begin(); kit != vitem->tlvkvs.pairs.end(); ++kit)
|
||||
{
|
||||
if(kit->key == "AUTO_BAN_NODES_THRESHOLD")
|
||||
{
|
||||
int val ;
|
||||
if (sscanf(kit->value.c_str(), "%d", &val) == 1)
|
||||
{
|
||||
mPgpAutoBanThreshold = val ;
|
||||
std::cerr << "Setting AutoBanNode threshold to " << val << std::endl ;
|
||||
mLastBannedNodesUpdate = 0 ; // force update
|
||||
}
|
||||
};
|
||||
}
|
||||
// if(kit->key == "AUTO_BAN_NODES_THRESHOLD")
|
||||
// {
|
||||
// int val ;
|
||||
// if (sscanf(kit->value.c_str(), "%d", &val) == 1)
|
||||
// {
|
||||
// mPgpAutoBanThreshold = val ;
|
||||
// std::cerr << "Setting AutoBanNode threshold to " << val << std::endl ;
|
||||
// mLastBannedNodesUpdate = 0 ; // force update
|
||||
// }
|
||||
// };
|
||||
if(kit->key == "AUTO_BAN_IDENTITIES_THRESHOLD")
|
||||
{
|
||||
float val ;
|
||||
|
||||
if (sscanf(kit->value.c_str(), "%f", &val) == 1)
|
||||
{
|
||||
mAutoBanIdentitiesLimit = val ;
|
||||
std::cerr << "Setting AutoBanIdentity threshold to " << val << std::endl ;
|
||||
mLastBannedNodesUpdate = 0 ; // force update
|
||||
}
|
||||
};
|
||||
if(kit->key == "AUTO_POSITIVE_CONTACTS")
|
||||
{
|
||||
mAutoSetPositiveOptionToContacts = (kit->value == "YES");
|
||||
std::cerr << "Setting AutoPositiveContacts to " << kit->value << std::endl ;
|
||||
mLastBannedNodesUpdate = 0 ; // force update
|
||||
}
|
||||
}
|
||||
|
||||
delete (*it);
|
||||
}
|
||||
|
||||
updateBannedNodesProxy();
|
||||
loadList.clear() ;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3GxsReputation::loadReputationSet(RsGxsReputationSetItem *item, const std::set<RsPeerId> &peerSet)
|
||||
{
|
||||
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||
{
|
||||
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||
|
||||
std::map<RsGxsId, Reputation>::iterator rit;
|
||||
std::map<RsGxsId, Reputation>::iterator rit;
|
||||
|
||||
if(item->mGxsId.isNull()) // just a protection against potential errors having put 00000 into ids.
|
||||
if(item->mGxsId.isNull()) // just a protection against potential errors having put 00000 into ids.
|
||||
return false ;
|
||||
|
||||
/* find matching Reputation */
|
||||
RsGxsId gxsId(item->mGxsId);
|
||||
rit = mReputations.find(gxsId);
|
||||
if (rit != mReputations.end())
|
||||
{
|
||||
std::cerr << "ERROR";
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
|
||||
Reputation &reputation = mReputations[gxsId];
|
||||
/* find matching Reputation */
|
||||
RsGxsId gxsId(item->mGxsId);
|
||||
rit = mReputations.find(gxsId);
|
||||
if (rit != mReputations.end())
|
||||
{
|
||||
std::cerr << "ERROR";
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
|
||||
// install opinions.
|
||||
std::map<RsPeerId, uint32_t>::const_iterator oit;
|
||||
for(oit = item->mOpinions.begin(); oit != item->mOpinions.end(); ++oit)
|
||||
{
|
||||
// expensive ... but necessary.
|
||||
RsPeerId peerId(oit->first);
|
||||
if (peerSet.end() != peerSet.find(peerId))
|
||||
reputation.mOpinions[peerId] = safe_convert_uint32t_to_opinion(oit->second);
|
||||
}
|
||||
Reputation &reputation = mReputations[gxsId];
|
||||
|
||||
reputation.mOwnOpinion = item->mOwnOpinion;
|
||||
reputation.mOwnOpinionTs = item->mOwnOpinionTS;
|
||||
// install opinions.
|
||||
std::map<RsPeerId, uint32_t>::const_iterator oit;
|
||||
for(oit = item->mOpinions.begin(); oit != item->mOpinions.end(); ++oit)
|
||||
{
|
||||
// expensive ... but necessary.
|
||||
RsPeerId peerId(oit->first);
|
||||
if (peerSet.end() != peerSet.find(peerId))
|
||||
reputation.mOpinions[peerId] = safe_convert_uint32t_to_opinion(oit->second);
|
||||
}
|
||||
|
||||
// if dropping entries has changed the score -> must update.
|
||||
|
||||
//float old_reputation = reputation.mReputation ;
|
||||
//mUpdatedReputations.insert(gxsId) ;
|
||||
|
||||
reputation.updateReputation() ;
|
||||
reputation.mOwnOpinion = item->mOwnOpinion;
|
||||
reputation.mOwnOpinionTs = item->mOwnOpinionTS;
|
||||
reputation.mOwnerNode = item->mOwnerNodeId;
|
||||
reputation.mIdentityFlags = item->mIdentityFlags | REPUTATION_IDENTITY_FLAG_NEEDS_UPDATE;
|
||||
|
||||
mUpdated.insert(std::make_pair(reputation.mOwnOpinionTs, gxsId));
|
||||
return true;
|
||||
// if dropping entries has changed the score -> must update.
|
||||
|
||||
//float old_reputation = reputation.mReputation ;
|
||||
//mUpdatedReputations.insert(gxsId) ;
|
||||
|
||||
reputation.updateReputation() ;
|
||||
|
||||
mUpdated.insert(std::make_pair(reputation.mOwnOpinionTs, gxsId));
|
||||
}
|
||||
#ifdef DEBUG_REPUTATION
|
||||
RsReputations::ReputationInfo info ;
|
||||
getReputationInfo(item->mGxsId,item->mOwnerNodeId,info) ;
|
||||
std::cerr << item->mGxsId << " : own: " << info.mOwnOpinion << ", owner node: " << item->mOwnerNodeId << ", assessment: " << ((info.mAssessment==ASSESSMENT_BAD)?"BAD":"OK") << std::endl;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1129,16 +1360,33 @@ void p3GxsReputation::debug_print()
|
|||
{
|
||||
std::cerr << "Reputations database: " << std::endl;
|
||||
std::cerr << " Average number of peers: " << mAverageActiveFriends << std::endl;
|
||||
|
||||
std::cerr << " GXS ID data: " << std::endl;
|
||||
|
||||
time_t now = time(NULL) ;
|
||||
|
||||
|
||||
for(std::map<RsGxsId,Reputation>::const_iterator it(mReputations.begin());it!=mReputations.end();++it)
|
||||
{
|
||||
std::cerr << " ID=" << it->first << ", own: " << it->second.mOwnOpinion << ", Friend average: " << it->second.mFriendAverage << ", global_score: " << it->second.mReputation
|
||||
<< ", last own update: " << now - it->second.mOwnOpinionTs << " secs ago." << std::endl;
|
||||
|
||||
for(std::map<RsPeerId,RsReputations::Opinion>::const_iterator it2(it->second.mOpinions.begin());it2!=it->second.mOpinions.end();++it2)
|
||||
std::cerr << " " << it->first << ": own: " << it->second.mOwnOpinion << ", Friend average: " << it->second.mFriendAverage << ", global_score: " << it->second.mReputation
|
||||
<< ", last own update: " << now - it->second.mOwnOpinionTs << " secs ago." << std::endl;
|
||||
#ifdef DEBUG_REPUTATION2
|
||||
for(std::map<RsPeerId,RsReputations::Opinion>::const_iterator it2(it->second.mOpinions.begin());it2!=it->second.mOpinions.end();++it2)
|
||||
std::cerr << " " << it2->first << ": " << it2->second << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
std::cerr << " Banned RS nodes by ID: " << std::endl;
|
||||
|
||||
for(std::map<RsPgpId,BannedNodeInfo>::const_iterator it(mBannedPgpIds.begin());it!=mBannedPgpIds.end();++it)
|
||||
{
|
||||
std::cerr << " Node " << it->first << ", last activity: " << now - it->second.last_activity_TS << " secs ago." << std::endl;
|
||||
|
||||
for(std::set<RsGxsId>::const_iterator it2(it->second.known_identities.begin());it2!=it->second.known_identities.end();++it2)
|
||||
std::cerr << " " << *it2 << std::endl;
|
||||
}
|
||||
|
||||
std::cerr << " Per node Banned GXSIds proxy: " << std::endl;
|
||||
|
||||
for(std::set<RsGxsId>::const_iterator it(mPerNodeBannedIdsProxy.begin());it!=mPerNodeBannedIdsProxy.end();++it)
|
||||
std::cerr << " " << *it << std::endl;
|
||||
}
|
||||
|
||||
|
|
|
@ -59,6 +59,12 @@ public:
|
|||
time_t mLastQuery;
|
||||
};
|
||||
|
||||
struct BannedNodeInfo
|
||||
{
|
||||
time_t last_activity_TS ; // updated everytime a node or one of its former identities is required
|
||||
std::set<RsGxsId> known_identities ; // list of known identities from this node. This is kept for a while, and useful in order to avoid re-asking these keys.
|
||||
};
|
||||
|
||||
class Reputation
|
||||
{
|
||||
public:
|
||||
|
@ -77,7 +83,7 @@ public:
|
|||
float mFriendAverage ;
|
||||
float mReputation;
|
||||
|
||||
RsPgpId mOwnerNode;
|
||||
RsPgpId mOwnerNode;
|
||||
|
||||
uint32_t mIdentityFlags;
|
||||
};
|
||||
|
@ -91,76 +97,91 @@ public:
|
|||
|
||||
class p3GxsReputation: public p3Service, public p3Config, public RsReputations /* , public pqiMonitor */
|
||||
{
|
||||
public:
|
||||
p3GxsReputation(p3LinkMgr *lm);
|
||||
virtual RsServiceInfo getServiceInfo();
|
||||
public:
|
||||
p3GxsReputation(p3LinkMgr *lm);
|
||||
virtual RsServiceInfo getServiceInfo();
|
||||
|
||||
/***** Interface for RsReputations *****/
|
||||
virtual bool setOwnOpinion(const RsGxsId& key_id, const Opinion& op) ;
|
||||
virtual bool getReputationInfo(const RsGxsId& id,ReputationInfo& info) ;
|
||||
virtual bool isIdentityBanned(const RsGxsId& id) ;
|
||||
|
||||
virtual void setNodeAutoBanThreshold(uint32_t n) ;
|
||||
virtual uint32_t nodeAutoBanThreshold() ;
|
||||
|
||||
/***** overloaded from p3Service *****/
|
||||
virtual int tick();
|
||||
virtual int status();
|
||||
/***** Interface for RsReputations *****/
|
||||
virtual bool setOwnOpinion(const RsGxsId& key_id, const Opinion& op) ;
|
||||
virtual bool getReputationInfo(const RsGxsId& id, const RsPgpId &ownerNode, ReputationInfo& info) ;
|
||||
virtual bool isIdentityBanned(const RsGxsId& id) ;
|
||||
|
||||
/*!
|
||||
* Interface stuff.
|
||||
*/
|
||||
virtual bool isNodeBanned(const RsPgpId& id);
|
||||
virtual void banNode(const RsPgpId& id,bool b) ;
|
||||
|
||||
//virtual void setNodeAutoBanThreshold(uint32_t n) ;
|
||||
//virtual uint32_t nodeAutoBanThreshold() ;
|
||||
|
||||
virtual void setNodeAutoPositiveOpinionForContacts(bool b) ;
|
||||
virtual bool nodeAutoPositiveOpinionForContacts() ;
|
||||
virtual float nodeAutoBanIdentitiesLimit() ;
|
||||
virtual void setNodeAutoBanIdentitiesLimit(float f) ;
|
||||
|
||||
/***** overloaded from p3Service *****/
|
||||
virtual int tick();
|
||||
virtual int status();
|
||||
|
||||
/*!
|
||||
* Interface stuff.
|
||||
*/
|
||||
|
||||
/************* from p3Config *******************/
|
||||
virtual RsSerialiser *setupSerialiser() ;
|
||||
virtual bool saveList(bool& cleanup, std::list<RsItem*>&) ;
|
||||
virtual void saveDone();
|
||||
virtual bool loadList(std::list<RsItem*>& load) ;
|
||||
|
||||
/************* from p3Config *******************/
|
||||
virtual RsSerialiser *setupSerialiser() ;
|
||||
virtual bool saveList(bool& cleanup, std::list<RsItem*>&) ;
|
||||
virtual void saveDone();
|
||||
virtual bool loadList(std::list<RsItem*>& load) ;
|
||||
|
||||
private:
|
||||
|
||||
bool processIncoming();
|
||||
bool processIncoming();
|
||||
|
||||
bool SendReputations(RsGxsReputationRequestItem *request);
|
||||
bool RecvReputations(RsGxsReputationUpdateItem *item);
|
||||
bool updateLatestUpdate(RsPeerId peerid, time_t latest_update);
|
||||
void updateActiveFriends() ;
|
||||
void updateBannedNodesList();
|
||||
|
||||
// internal update of data. Takes care of cleaning empty boxes.
|
||||
void locked_updateOpinion(const RsPeerId &from, const RsGxsId &about, RsReputations::Opinion op);
|
||||
bool loadReputationSet(RsGxsReputationSetItem *item, const std::set<RsPeerId> &peerSet);
|
||||
bool SendReputations(RsGxsReputationRequestItem *request);
|
||||
bool RecvReputations(RsGxsReputationUpdateItem *item);
|
||||
bool updateLatestUpdate(RsPeerId peerid, time_t latest_update);
|
||||
void updateActiveFriends() ;
|
||||
|
||||
int sendPackets();
|
||||
void cleanup();
|
||||
void sendReputationRequests();
|
||||
int sendReputationRequest(RsPeerId peerid);
|
||||
void debug_print() ;
|
||||
void updateIdentityFlags();
|
||||
void updateBannedNodesProxy();
|
||||
|
||||
private:
|
||||
RsMutex mReputationMtx;
|
||||
// internal update of data. Takes care of cleaning empty boxes.
|
||||
void locked_updateOpinion(const RsPeerId &from, const RsGxsId &about, RsReputations::Opinion op);
|
||||
bool loadReputationSet(RsGxsReputationSetItem *item, const std::set<RsPeerId> &peerSet);
|
||||
|
||||
time_t mLastActiveFriendsUpdate;
|
||||
time_t mRequestTime;
|
||||
time_t mStoreTime;
|
||||
time_t mLastBannedNodesUpdate ;
|
||||
bool mReputationsUpdated;
|
||||
uint32_t mAverageActiveFriends ;
|
||||
int sendPackets();
|
||||
void cleanup();
|
||||
void sendReputationRequests();
|
||||
int sendReputationRequest(RsPeerId peerid);
|
||||
void debug_print() ;
|
||||
void updateIdentityFlags();
|
||||
|
||||
p3LinkMgr *mLinkMgr;
|
||||
private:
|
||||
RsMutex mReputationMtx;
|
||||
|
||||
// Data for Reputation.
|
||||
std::map<RsPeerId, ReputationConfig> mConfig;
|
||||
std::map<RsGxsId, Reputation> mReputations;
|
||||
std::multimap<time_t, RsGxsId> mUpdated;
|
||||
time_t mLastActiveFriendsUpdate;
|
||||
time_t mRequestTime;
|
||||
time_t mStoreTime;
|
||||
time_t mLastBannedNodesUpdate ;
|
||||
time_t mLastIdentityFlagsUpdate ;
|
||||
bool mReputationsUpdated;
|
||||
uint32_t mAverageActiveFriends ;
|
||||
|
||||
// set of Reputations to send to p3IdService.
|
||||
std::set<RsGxsId> mUpdatedReputations;
|
||||
|
||||
// PGP Ids auto-banned. This is updated regularly.
|
||||
std::set<RsPgpId> mBannedPgpIds ;
|
||||
uint32_t mPgpAutoBanThreshold ;
|
||||
float mAutoBanIdentitiesLimit ;
|
||||
bool mAutoSetPositiveOptionToContacts;
|
||||
|
||||
p3LinkMgr *mLinkMgr;
|
||||
|
||||
// Data for Reputation.
|
||||
std::map<RsPeerId, ReputationConfig> mConfig;
|
||||
std::map<RsGxsId, Reputation> mReputations;
|
||||
std::multimap<time_t, RsGxsId> mUpdated;
|
||||
|
||||
// set of Reputations to send to p3IdService.
|
||||
std::set<RsGxsId> mUpdatedReputations;
|
||||
|
||||
// PGP Ids auto-banned. This is updated regularly.
|
||||
std::map<RsPgpId,BannedNodeInfo> mBannedPgpIds ;
|
||||
std::set<RsGxsId> mPerNodeBannedIdsProxy ;
|
||||
//uint32_t mPgpAutoBanThreshold ;
|
||||
bool mBannedNodesProxyNeedsUpdate ;
|
||||
};
|
||||
|
||||
#endif //SERVICE_RSGXSREPUTATION_HEADER
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -218,34 +218,34 @@ private:
|
|||
|
||||
class p3IdService: public RsGxsIdExchange, public RsIdentity, public GxsTokenQueue, public RsTickEvent, public p3Config
|
||||
{
|
||||
public:
|
||||
public:
|
||||
p3IdService(RsGeneralDataService* gds, RsNetworkExchangeService* nes, PgpAuxUtils *pgpUtils);
|
||||
|
||||
virtual RsServiceInfo getServiceInfo();
|
||||
static uint32_t idAuthenPolicy();
|
||||
virtual RsServiceInfo getServiceInfo();
|
||||
static uint32_t idAuthenPolicy();
|
||||
|
||||
virtual void service_tick(); // needed for background processing.
|
||||
|
||||
|
||||
/*!
|
||||
* Design hack, id service must be constructed first as it
|
||||
* is need for construction of subsequent net services
|
||||
*/
|
||||
void setNes(RsNetworkExchangeService* nes);
|
||||
/*!
|
||||
* Design hack, id service must be constructed first as it
|
||||
* is need for construction of subsequent net services
|
||||
*/
|
||||
void setNes(RsNetworkExchangeService* nes);
|
||||
|
||||
/* General Interface is provided by RsIdentity / RsGxsIfaceImpl. */
|
||||
|
||||
/* Data Specific Interface */
|
||||
|
||||
// These are exposed via RsIdentity.
|
||||
virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsIdGroup> &groups);
|
||||
//virtual bool getMsgData(const uint32_t &token, std::vector<RsGxsIdOpinion> &opinions);
|
||||
virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsIdGroup> &groups);
|
||||
//virtual bool getMsgData(const uint32_t &token, std::vector<RsGxsIdOpinion> &opinions);
|
||||
|
||||
// These are local - and not exposed via RsIdentity.
|
||||
virtual bool createGroup(uint32_t& token, RsGxsIdGroup &group);
|
||||
virtual bool updateGroup(uint32_t& token, RsGxsIdGroup &group);
|
||||
virtual bool deleteGroup(uint32_t& token, RsGxsIdGroup &group);
|
||||
//virtual bool createMsg(uint32_t& token, RsGxsIdOpinion &opinion);
|
||||
virtual bool createGroup(uint32_t& token, RsGxsIdGroup &group);
|
||||
virtual bool updateGroup(uint32_t& token, RsGxsIdGroup &group);
|
||||
virtual bool deleteGroup(uint32_t& token, RsGxsIdGroup &group);
|
||||
//virtual bool createMsg(uint32_t& token, RsGxsIdOpinion &opinion);
|
||||
|
||||
/**************** RsIdentity External Interface.
|
||||
* Notes:
|
||||
|
@ -256,100 +256,105 @@ virtual bool deleteGroup(uint32_t& token, RsGxsIdGroup &group);
|
|||
* Also need to handle Cache updates / invalidation from internal changes.
|
||||
*
|
||||
*/
|
||||
//virtual bool getNickname(const RsGxsId &id, std::string &nickname);
|
||||
virtual bool getIdDetails(const RsGxsId &id, RsIdentityDetails &details);
|
||||
//virtual bool getNickname(const RsGxsId &id, std::string &nickname);
|
||||
virtual bool getIdDetails(const RsGxsId &id, RsIdentityDetails &details);
|
||||
|
||||
//
|
||||
virtual bool submitOpinion(uint32_t& token, const RsGxsId &id,
|
||||
bool absOpinion, int score);
|
||||
virtual bool createIdentity(uint32_t& token, RsIdentityParameters ¶ms);
|
||||
//
|
||||
virtual bool submitOpinion(uint32_t& token, const RsGxsId &id,
|
||||
bool absOpinion, int score);
|
||||
virtual bool createIdentity(uint32_t& token, RsIdentityParameters ¶ms);
|
||||
|
||||
virtual bool updateIdentity(uint32_t& token, RsGxsIdGroup &group);
|
||||
virtual bool deleteIdentity(uint32_t& token, RsGxsIdGroup &group);
|
||||
virtual bool updateIdentity(uint32_t& token, RsGxsIdGroup &group);
|
||||
virtual bool deleteIdentity(uint32_t& token, RsGxsIdGroup &group);
|
||||
|
||||
virtual bool parseRecognTag(const RsGxsId &id, const std::string &nickname,
|
||||
const std::string &tag, RsRecognTagDetails &details);
|
||||
virtual bool getRecognTagRequest(const RsGxsId &id, const std::string &comment,
|
||||
uint16_t tag_class, uint16_t tag_type, std::string &tag);
|
||||
virtual bool parseRecognTag(const RsGxsId &id, const std::string &nickname,
|
||||
const std::string &tag, RsRecognTagDetails &details);
|
||||
virtual bool getRecognTagRequest(const RsGxsId &id, const std::string &comment,
|
||||
uint16_t tag_class, uint16_t tag_type, std::string &tag);
|
||||
|
||||
virtual bool setAsRegularContact(const RsGxsId& id,bool is_a_contact) ;
|
||||
virtual bool isARegularContact(const RsGxsId& id) ;
|
||||
|
||||
/**************** RsGixs Implementation ***************/
|
||||
virtual bool setAsRegularContact(const RsGxsId& id,bool is_a_contact) ;
|
||||
virtual bool isARegularContact(const RsGxsId& id) ;
|
||||
virtual bool isBanned(const RsGxsId& id) ;
|
||||
virtual time_t getLastUsageTS(const RsGxsId &id) ;
|
||||
|
||||
virtual bool getOwnIds(std::list<RsGxsId> &ownIds);
|
||||
/**************** RsGixs Implementation ***************/
|
||||
|
||||
//virtual bool getPublicKey(const RsGxsId &id, RsTlvSecurityKey &key) ;
|
||||
//virtual void networkRequestPublicKey(const RsGxsId& key_id,const std::list<RsPeerId>& peer_ids) ;
|
||||
virtual bool getOwnIds(std::list<RsGxsId> &ownIds);
|
||||
|
||||
virtual bool isOwnId(const RsGxsId& key_id) ;
|
||||
//virtual bool getPublicKey(const RsGxsId &id, RsTlvSecurityKey &key) ;
|
||||
//virtual void networkRequestPublicKey(const RsGxsId& key_id,const std::list<RsPeerId>& peer_ids) ;
|
||||
|
||||
virtual bool signData(const uint8_t *data,uint32_t data_size,const RsGxsId& signer_id,RsTlvKeySignature& signature,uint32_t& signing_error) ;
|
||||
virtual bool validateData(const uint8_t *data,uint32_t data_size,const RsTlvKeySignature& signature,bool force_load,uint32_t& signing_error) ;
|
||||
virtual bool isOwnId(const RsGxsId& key_id) ;
|
||||
|
||||
virtual bool encryptData(const uint8_t *decrypted_data,uint32_t decrypted_data_size,uint8_t *& encrypted_data,uint32_t& encrypted_data_size,const RsGxsId& encryption_key_id,bool force_load,uint32_t& encryption_error) ;
|
||||
virtual bool decryptData(const uint8_t *encrypted_data,uint32_t encrypted_data_size,uint8_t *& decrypted_data,uint32_t& decrypted_data_size,const RsGxsId& encryption_key_id,uint32_t& encryption_error) ;
|
||||
virtual bool signData(const uint8_t *data,uint32_t data_size,const RsGxsId& signer_id,RsTlvKeySignature& signature,uint32_t& signing_error) ;
|
||||
virtual bool validateData(const uint8_t *data,uint32_t data_size,const RsTlvKeySignature& signature,bool force_load,uint32_t& signing_error) ;
|
||||
|
||||
virtual bool haveKey(const RsGxsId &id);
|
||||
virtual bool havePrivateKey(const RsGxsId &id);
|
||||
virtual bool encryptData(const uint8_t *decrypted_data,uint32_t decrypted_data_size,uint8_t *& encrypted_data,uint32_t& encrypted_data_size,const RsGxsId& encryption_key_id,bool force_load,uint32_t& encryption_error) ;
|
||||
virtual bool decryptData(const uint8_t *encrypted_data,uint32_t encrypted_data_size,uint8_t *& decrypted_data,uint32_t& decrypted_data_size,const RsGxsId& encryption_key_id,uint32_t& encryption_error) ;
|
||||
|
||||
virtual bool getKey(const RsGxsId &id, RsTlvPublicRSAKey &key);
|
||||
virtual bool getPrivateKey(const RsGxsId &id, RsTlvPrivateRSAKey &key);
|
||||
virtual bool haveKey(const RsGxsId &id);
|
||||
virtual bool havePrivateKey(const RsGxsId &id);
|
||||
|
||||
virtual bool requestKey(const RsGxsId &id, const std::list<PeerId> &peers);
|
||||
virtual bool requestPrivateKey(const RsGxsId &id);
|
||||
virtual bool getKey(const RsGxsId &id, RsTlvPublicRSAKey &key);
|
||||
virtual bool getPrivateKey(const RsGxsId &id, RsTlvPrivateRSAKey &key);
|
||||
|
||||
virtual bool requestKey(const RsGxsId &id, const std::list<RsPeerId> &peers);
|
||||
virtual bool requestPrivateKey(const RsGxsId &id);
|
||||
|
||||
|
||||
/**************** RsGixsReputation Implementation ****************/
|
||||
/**************** RsGixsReputation Implementation ****************/
|
||||
|
||||
// get Reputation.
|
||||
virtual bool haveReputation(const RsGxsId &id);
|
||||
virtual bool loadReputation(const RsGxsId &id, const std::list<RsPeerId>& peers);
|
||||
virtual bool getReputation(const RsGxsId &id, GixsReputation &rep);
|
||||
// get Reputation.
|
||||
virtual bool haveReputation(const RsGxsId &id);
|
||||
virtual bool loadReputation(const RsGxsId &id, const std::list<RsPeerId>& peers);
|
||||
virtual bool getReputation(const RsGxsId &id, GixsReputation &rep);
|
||||
|
||||
|
||||
protected:
|
||||
/** Notifications **/
|
||||
virtual void notifyChanges(std::vector<RsGxsNotify*>& changes);
|
||||
protected:
|
||||
/** Notifications **/
|
||||
virtual void notifyChanges(std::vector<RsGxsNotify*>& changes);
|
||||
|
||||
/** Overloaded to add PgpIdHash to Group Definition **/
|
||||
virtual ServiceCreate_Return service_CreateGroup(RsGxsGrpItem* grpItem, RsTlvSecurityKeySet& keySet);
|
||||
virtual ServiceCreate_Return service_CreateGroup(RsGxsGrpItem* grpItem, RsTlvSecurityKeySet& keySet);
|
||||
|
||||
// Overloaded from GxsTokenQueue for Request callbacks.
|
||||
virtual void handleResponse(uint32_t token, uint32_t req_type);
|
||||
// Overloads RsGxsGenExchange
|
||||
virtual bool acceptNewGroup(const RsGxsGrpMetaData *grpMeta) ;
|
||||
|
||||
// Overloaded from RsTickEvent.
|
||||
virtual void handle_event(uint32_t event_type, const std::string &elabel);
|
||||
// Overloaded from GxsTokenQueue for Request callbacks.
|
||||
virtual void handleResponse(uint32_t token, uint32_t req_type);
|
||||
|
||||
//===================================================//
|
||||
// p3Config methods //
|
||||
//===================================================//
|
||||
// Overloaded from RsTickEvent.
|
||||
virtual void handle_event(uint32_t event_type, const std::string &elabel);
|
||||
|
||||
// Load/save the routing info, the pending items in transit, and the config variables.
|
||||
//
|
||||
virtual bool loadList(std::list<RsItem*>& items) ;
|
||||
virtual bool saveList(bool& cleanup,std::list<RsItem*>& items) ;
|
||||
//===================================================//
|
||||
// p3Config methods //
|
||||
//===================================================//
|
||||
|
||||
virtual RsSerialiser *setupSerialiser() ;
|
||||
// Load/save the routing info, the pending items in transit, and the config variables.
|
||||
//
|
||||
virtual bool loadList(std::list<RsItem*>& items) ;
|
||||
virtual bool saveList(bool& cleanup,std::list<RsItem*>& items) ;
|
||||
|
||||
virtual RsSerialiser *setupSerialiser() ;
|
||||
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
/************************************************************************
|
||||
/************************************************************************
|
||||
* This is the Cache for minimising calls to the DataStore.
|
||||
*
|
||||
*/
|
||||
int cache_tick();
|
||||
|
||||
bool cache_request_load(const RsGxsId &id, const std::list<PeerId>& peers = std::list<PeerId>());
|
||||
bool cache_request_load(const RsGxsId &id, const std::list<RsPeerId>& peers = std::list<RsPeerId>());
|
||||
bool cache_start_load();
|
||||
bool cache_load_for_token(uint32_t token);
|
||||
|
||||
bool cache_store(const RsGxsIdGroupItem *item);
|
||||
bool cache_update_if_cached(const RsGxsId &id, std::string serviceString);
|
||||
|
||||
bool isPendingNetworkRequest(const RsGxsId& gxsId);
|
||||
void requestIdsFromNet();
|
||||
bool isPendingNetworkRequest(const RsGxsId& gxsId);
|
||||
void requestIdsFromNet();
|
||||
|
||||
// Mutex protected.
|
||||
|
||||
|
@ -359,7 +364,7 @@ virtual void handle_event(uint32_t event_type, const std::string &elabel);
|
|||
// Switching to RsMemCache for Key Caching.
|
||||
RsMemCache<RsGxsId, RsGxsIdCache> mKeyCache;
|
||||
|
||||
/************************************************************************
|
||||
/************************************************************************
|
||||
* Refreshing own Ids.
|
||||
*
|
||||
*/
|
||||
|
@ -368,7 +373,7 @@ virtual void handle_event(uint32_t event_type, const std::string &elabel);
|
|||
|
||||
std::list<RsGxsId> mOwnIds;
|
||||
|
||||
/************************************************************************
|
||||
/************************************************************************
|
||||
* Test fns for Caching.
|
||||
*
|
||||
*/
|
||||
|
@ -376,7 +381,7 @@ virtual void handle_event(uint32_t event_type, const std::string &elabel);
|
|||
bool cachetest_getlist();
|
||||
bool cachetest_handlerequest(uint32_t token);
|
||||
|
||||
/************************************************************************
|
||||
/************************************************************************
|
||||
* for processing background tasks that use the serviceString.
|
||||
* - must be mutually exclusive to avoid clashes.
|
||||
*/
|
||||
|
@ -386,7 +391,7 @@ virtual void handle_event(uint32_t event_type, const std::string &elabel);
|
|||
bool mBgSchedule_Active;
|
||||
uint32_t mBgSchedule_Mode;
|
||||
|
||||
/************************************************************************
|
||||
/************************************************************************
|
||||
* pgphash processing.
|
||||
*
|
||||
*/
|
||||
|
@ -394,7 +399,7 @@ virtual void handle_event(uint32_t event_type, const std::string &elabel);
|
|||
bool pgphash_handlerequest(uint32_t token);
|
||||
bool pgphash_process();
|
||||
|
||||
bool checkId(const RsGxsIdGroup &grp, RsPgpId &pgp_id, bool &error);
|
||||
bool checkId(const RsGxsIdGroup &grp, RsPgpId &pgp_id, bool &error);
|
||||
void getPgpIdList();
|
||||
|
||||
/* MUTEX PROTECTED DATA (mIdMtx - maybe should use a 2nd?) */
|
||||
|
@ -402,7 +407,7 @@ virtual void handle_event(uint32_t event_type, const std::string &elabel);
|
|||
std::map<RsPgpId, PGPFingerprintType> mPgpFingerprintMap;
|
||||
std::list<RsGxsIdGroup> mGroupsToProcess;
|
||||
|
||||
/************************************************************************
|
||||
/************************************************************************
|
||||
* recogn processing.
|
||||
*
|
||||
*/
|
||||
|
@ -420,7 +425,7 @@ virtual void handle_event(uint32_t event_type, const std::string &elabel);
|
|||
void loadRecognKeys();
|
||||
|
||||
|
||||
/************************************************************************
|
||||
/************************************************************************
|
||||
* opinion processing.
|
||||
*
|
||||
*/
|
||||
|
@ -448,24 +453,24 @@ virtual void handle_event(uint32_t event_type, const std::string &elabel);
|
|||
std::map<RsGxsId, RsGxsRecognSignerItem *> mRecognSignKeys;
|
||||
std::map<RsGxsId, uint32_t> mRecognOldSignKeys;
|
||||
|
||||
/************************************************************************
|
||||
/************************************************************************
|
||||
* Below is the background task for processing opinions => reputations
|
||||
*
|
||||
*/
|
||||
|
||||
virtual void generateDummyData();
|
||||
virtual void generateDummyData();
|
||||
void generateDummy_OwnIds();
|
||||
void generateDummy_FriendPGP();
|
||||
void generateDummy_UnknownPGP();
|
||||
void generateDummy_UnknownPseudo();
|
||||
|
||||
void cleanUnusedKeys() ;
|
||||
void slowIndicateConfigChanged() ;
|
||||
void cleanUnusedKeys() ;
|
||||
void slowIndicateConfigChanged() ;
|
||||
|
||||
virtual void timeStampKey(const RsGxsId& id) ;
|
||||
time_t locked_getLastUsageTS(const RsGxsId& gxs_id);
|
||||
virtual void timeStampKey(const RsGxsId& id) ;
|
||||
time_t locked_getLastUsageTS(const RsGxsId& gxs_id);
|
||||
|
||||
std::string genRandomId(int len = 20);
|
||||
std::string genRandomId(int len = 20);
|
||||
|
||||
#if 0
|
||||
bool reputation_start();
|
||||
|
@ -478,7 +483,7 @@ std::string genRandomId(int len = 20);
|
|||
bool background_processNewMessages();
|
||||
bool background_FullCalcRequest();
|
||||
bool background_processFullCalc();
|
||||
|
||||
|
||||
bool background_cleanup();
|
||||
#endif
|
||||
|
||||
|
@ -488,40 +493,40 @@ std::string genRandomId(int len = 20);
|
|||
/***** below here is locked *****/
|
||||
bool mLastBgCheck;
|
||||
bool mBgProcessing;
|
||||
|
||||
|
||||
uint32_t mBgToken;
|
||||
uint32_t mBgPhase;
|
||||
|
||||
|
||||
std::map<RsGxsGroupId, RsGroupMetaData> mBgGroupMap;
|
||||
std::list<RsGxsGroupId> mBgFullCalcGroups;
|
||||
#endif
|
||||
|
||||
/************************************************************************
|
||||
/************************************************************************
|
||||
* Other Data that is protected by the Mutex.
|
||||
*/
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
std::map<uint32_t, std::set<RsGxsGroupId> > mIdsPendingCache;
|
||||
std::map<uint32_t, std::list<RsGxsGroupId> > mGroupNotPresent;
|
||||
std::map<RsGxsId, std::list<RsPeerId> > mIdsNotPresent;
|
||||
std::map<RsGxsId,time_t> mKeysTS ;
|
||||
|
||||
// keep a list of regular contacts. This is useful to sort IDs, and allow some services to priviledged ids only.
|
||||
std::set<RsGxsId> mContacts;
|
||||
|
||||
// keep a list of regular contacts. This is useful to sort IDs, and allow some services to priviledged ids only.
|
||||
std::set<RsGxsId> mContacts;
|
||||
RsNetworkExchangeService* mNes;
|
||||
|
||||
/**************************
|
||||
* AuxUtils provides interface to Security Function (e.g. GPGAuth(), notify etc.)
|
||||
* AuxUtils provides interface to Security Function (e.g. GPGAuth(), notify etc.)
|
||||
* without depending directly on all these classes.
|
||||
*/
|
||||
|
||||
PgpAuxUtils *mPgpUtils;
|
||||
PgpAuxUtils *mPgpUtils;
|
||||
|
||||
time_t mLastKeyCleaningTime ;
|
||||
time_t mLastConfigUpdate ;
|
||||
time_t mLastKeyCleaningTime ;
|
||||
time_t mLastConfigUpdate ;
|
||||
|
||||
bool mOwnIdsLoaded ;
|
||||
bool mOwnIdsLoaded ;
|
||||
};
|
||||
|
||||
#endif // P3_IDENTITY_SERVICE_HEADER
|
||||
|
|
|
@ -98,8 +98,13 @@ bool p3Posted::getGroupData(const uint32_t &token, std::vector<RsPostedGroup> &g
|
|||
return ok;
|
||||
}
|
||||
|
||||
bool p3Posted::getPostData(const uint32_t &token, std::vector<RsPostedPost> &msgs)
|
||||
bool p3Posted::getPostData(const uint32_t &token, std::vector<RsPostedPost> &msgs, std::vector<RsGxsComment> &cmts)
|
||||
{
|
||||
#ifdef POSTED_DEBUG
|
||||
std::cerr << "p3Posted::getPostData()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
GxsMsgDataMap msgData;
|
||||
bool ok = RsGenExchange::getMsgData(token, msgData);
|
||||
time_t now = time(NULL);
|
||||
|
@ -110,32 +115,60 @@ bool p3Posted::getPostData(const uint32_t &token, std::vector<RsPostedPost> &msg
|
|||
|
||||
for(; mit != msgData.end(); ++mit)
|
||||
{
|
||||
RsGxsGroupId grpId = mit->first;
|
||||
std::vector<RsGxsMsgItem*>& msgItems = mit->second;
|
||||
std::vector<RsGxsMsgItem*>::iterator vit = msgItems.begin();
|
||||
|
||||
for(; vit != msgItems.end(); ++vit)
|
||||
{
|
||||
RsGxsPostedPostItem* item = dynamic_cast<RsGxsPostedPostItem*>(*vit);
|
||||
RsGxsPostedPostItem* postItem = dynamic_cast<RsGxsPostedPostItem*>(*vit);
|
||||
|
||||
if(item)
|
||||
if(postItem)
|
||||
{
|
||||
RsPostedPost msg = item->mPost;
|
||||
msg.mMeta = item->meta;
|
||||
RsPostedPost msg = postItem->mPost;
|
||||
msg.mMeta = postItem->meta;
|
||||
msg.calculateScores(now);
|
||||
|
||||
msgs.push_back(msg);
|
||||
delete item;
|
||||
delete postItem;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Not a PostedPostItem, deleting!" << std::endl;
|
||||
delete *vit;
|
||||
RsGxsCommentItem* cmtItem = dynamic_cast<RsGxsCommentItem*>(*vit);
|
||||
if(cmtItem)
|
||||
{
|
||||
RsGxsComment cmt;
|
||||
RsGxsMsgItem *mi = (*vit);
|
||||
cmt = cmtItem->mMsg;
|
||||
cmt.mMeta = mi->meta;
|
||||
#ifdef GXSCOMMENT_DEBUG
|
||||
std::cerr << "p3Posted::getPostData Found Comment:" << std::endl;
|
||||
cmt.print(std::cerr," ", "cmt");
|
||||
#endif
|
||||
cmts.push_back(cmt);
|
||||
delete cmtItem;
|
||||
}
|
||||
else
|
||||
{
|
||||
RsGxsMsgItem* msg = (*vit);
|
||||
//const uint16_t RS_SERVICE_GXS_TYPE_CHANNELS = 0x0217;
|
||||
//const uint8_t RS_PKT_SUBTYPE_GXSCHANNEL_POST_ITEM = 0x03;
|
||||
//const uint8_t RS_PKT_SUBTYPE_GXSCOMMENT_COMMENT_ITEM = 0xf1;
|
||||
std::cerr << "Not a PostedPostItem neither a RsGxsCommentItem"
|
||||
<< " PacketService=" << std::hex << (int)msg->PacketService() << std::dec
|
||||
<< " PacketSubType=" << std::hex << (int)msg->PacketSubType() << std::dec
|
||||
<< " , deleting!" << std::endl;
|
||||
delete *vit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
std::cerr << "p3GxsChannels::getPostData() ERROR in request";
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
|
|
@ -63,7 +63,8 @@ virtual void receiveHelperChanges(std::vector<RsGxsNotify*>& changes)
|
|||
|
||||
// Posted Specific DataTypes.
|
||||
virtual bool getGroupData(const uint32_t &token, std::vector<RsPostedGroup> &groups);
|
||||
virtual bool getPostData(const uint32_t &token, std::vector<RsPostedPost> &posts);
|
||||
virtual bool getPostData(const uint32_t &token, std::vector<RsPostedPost> &posts, std::vector<RsGxsComment> &cmts);
|
||||
virtual bool getPostData(const uint32_t &token, std::vector<RsPostedPost> &posts) { std::vector<RsGxsComment> cmts; return getPostData( token, posts, cmts);}
|
||||
//Not currently used
|
||||
//virtual bool getRelatedPosts(const uint32_t &token, std::vector<RsPostedPost> &posts);
|
||||
|
||||
|
|
|
@ -64,8 +64,8 @@ class rsUdpStack: public UdpStack, public pqiNetListener
|
|||
/* from pqiNetListener */
|
||||
virtual bool resetListener(const struct sockaddr_storage &local)
|
||||
{
|
||||
std::cerr << "rsUdpStack::resetListener(" << sockaddr_storage_tostring(local) << ")";
|
||||
std::cerr << std::endl;
|
||||
//std::cerr << "rsUdpStack::resetListener(" << sockaddr_storage_tostring(local) << ")";
|
||||
//std::cerr << std::endl;
|
||||
|
||||
if (local.ss_family != AF_INET)
|
||||
{
|
||||
|
@ -90,16 +90,16 @@ class rsFixedUdpStack: public UdpStack, public pqiNetListener
|
|||
:UdpStack(testmode, local) { return; }
|
||||
|
||||
/* from pqiNetListener */
|
||||
virtual bool resetListener(const struct sockaddr_storage &local)
|
||||
virtual bool resetListener(const struct sockaddr_storage & /* local */)
|
||||
{
|
||||
struct sockaddr_in addr;
|
||||
getLocalAddress(addr);
|
||||
|
||||
// The const_cast below is not so nice but without it, the compiler can't
|
||||
// find the correct operator<<(). No idea why!
|
||||
std::cerr << "rsFixedUdpStack::resetListener(" << sockaddr_storage_tostring(local) << ")";
|
||||
std::cerr << " Resetting with original addr: " << const_cast<const struct sockaddr_in &>(addr);
|
||||
std::cerr << std::endl;
|
||||
//std::cerr << "rsFixedUdpStack::resetListener(" << sockaddr_storage_tostring(local) << ")";
|
||||
//std::cerr << " Resetting with original addr: " << const_cast<const struct sockaddr_in &>(addr);
|
||||
//std::cerr << std::endl;
|
||||
|
||||
return resetAddress(addr);
|
||||
}
|
||||
|
|
|
@ -186,19 +186,26 @@ int TcpPacket::readPacket(void *buf, int size)
|
|||
if (data)
|
||||
{
|
||||
free(data);
|
||||
data = NULL ;
|
||||
}
|
||||
datasize = size - TCP_PSEUDO_HDR_SIZE;
|
||||
|
||||
if(datasize == 0) // this happens!
|
||||
{
|
||||
data = NULL ;
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
|
||||
// this happens for control packets (e.g. syn/ack/fin)
|
||||
if(datasize == 0)
|
||||
{
|
||||
// data is already NULL
|
||||
// just return packet size
|
||||
return size;
|
||||
}
|
||||
|
||||
data = (uint8 *) rs_malloc(datasize);
|
||||
|
||||
if(data == NULL)
|
||||
{
|
||||
// malloc failed!
|
||||
// return 0 to drop packet (will be retransmitted eventually)
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
/* now the data */
|
||||
memcpy(data, (void *) &(((uint8 *) buf)[20]), datasize);
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifndef WINDOWS_SYS
|
||||
#if !defined(WINDOWS_SYS) && !defined(__ANDROID__)
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <execinfo.h>
|
||||
|
@ -110,13 +110,13 @@ static inline void print_stacktrace(FILE *out = stderr, unsigned int max_frames
|
|||
free(symbollist);
|
||||
}
|
||||
|
||||
#else // WINDOWS_SYS
|
||||
#else // !defined(WINDOWS_SYS) && !defined(__ANDROID__)
|
||||
static inline void print_stacktrace(FILE *out = stderr, unsigned int max_frames = 63)
|
||||
{
|
||||
(void) max_frames;
|
||||
|
||||
fprintf(out, "TODO: 2016/01/01 print_stacktrace not implemented yet for WINDOWS_SYS\n");
|
||||
fprintf(out, "TODO: 2016/01/01 print_stacktrace not implemented yet for WINDOWS_SYS and ANDROID\n");
|
||||
}
|
||||
#endif // WINDOWS_SYS
|
||||
#endif // !defined(WINDOWS_SYS) && !defined(__ANDROID__)
|
||||
|
||||
#endif // _STACKTRACE_H_
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue