mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
merge of branch v0.6-idclean 7180
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7187 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
7815efb16f
commit
0f29d28b1b
@ -92,7 +92,7 @@ bool CacheSource::loadLocalCache(const RsCacheData &data)
|
||||
}
|
||||
|
||||
/* control Caches available */
|
||||
bool CacheSource::refreshCache(const RsCacheData &data,const std::set<std::string>& destination_peers)
|
||||
bool CacheSource::refreshCache(const RsCacheData &data,const std::set<RsPeerId>& destination_peers)
|
||||
{
|
||||
bool ret = false;
|
||||
{
|
||||
@ -122,9 +122,9 @@ bool CacheSource::refreshCache(const RsCacheData &data,const std::set<std::strin
|
||||
|
||||
if (mStrapper) /* allow testing without full feedback */
|
||||
{
|
||||
std::set<std::string> allowed_dest_peers ;
|
||||
std::set<RsPeerId> allowed_dest_peers ;
|
||||
|
||||
for(std::set<std::string>::const_iterator it(destination_peers.begin());it!=destination_peers.end();++it)
|
||||
for(std::set<RsPeerId>::const_iterator it(destination_peers.begin());it!=destination_peers.end();++it)
|
||||
if(isPeerAcceptedAsCacheReceiver(*it))
|
||||
allowed_dest_peers.insert(*it) ;
|
||||
|
||||
@ -161,14 +161,14 @@ bool CacheSource::refreshCache(const RsCacheData &data)
|
||||
}
|
||||
// Strip down destination peers to eliminate peers that are not allowed to receive cache items.
|
||||
|
||||
std::list<std::string> ids;
|
||||
std::list<RsPeerId> ids;
|
||||
rsPeers->getOnlineList(ids);
|
||||
|
||||
if (mStrapper) /* allow testing without full feedback */
|
||||
{
|
||||
std::set<std::string> allowed_dest_peers ;
|
||||
std::set<RsPeerId> allowed_dest_peers ;
|
||||
|
||||
for(std::list<std::string>::const_iterator it(ids.begin());it!=ids.end();++it)
|
||||
for(std::list<RsPeerId>::const_iterator it(ids.begin());it!=ids.end();++it)
|
||||
if(isPeerAcceptedAsCacheReceiver(*it))
|
||||
allowed_dest_peers.insert(*it) ;
|
||||
|
||||
@ -232,7 +232,7 @@ bool CacheSource::clearCache(CacheId id)
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool CacheSource::cachesAvailable(RsPeerId pid, std::map<CacheId, RsCacheData> &ids)
|
||||
bool CacheSource::cachesAvailable(const RsPeerId& pid, std::map<CacheId, RsCacheData> &ids)
|
||||
{
|
||||
if(!isPeerAcceptedAsCacheReceiver(pid))
|
||||
return false ;
|
||||
@ -253,7 +253,7 @@ bool CacheSource::cachesAvailable(RsPeerId pid, std::map<CacheId, RsCacheData
|
||||
}
|
||||
|
||||
|
||||
bool CacheSource::findCache(std::string hash, RsCacheData &data) const
|
||||
bool CacheSource::findCache(const RsFileHash &hash, RsCacheData &data) const
|
||||
{
|
||||
lockData(); /* LOCK MUTEX */
|
||||
|
||||
@ -271,7 +271,7 @@ bool CacheSource::findCache(std::string hash, RsCacheData &data) const
|
||||
|
||||
if (!found)
|
||||
{
|
||||
std::map<std::string, RsCacheData>::const_iterator oit;
|
||||
std::map<RsFileHash, RsCacheData>::const_iterator oit;
|
||||
oit = mOldCaches.find(hash);
|
||||
if (oit != mOldCaches.end())
|
||||
{
|
||||
@ -336,7 +336,7 @@ void CacheStore::listCaches(std::ostream &out)
|
||||
lockData(); /* LOCK MUTEX */
|
||||
|
||||
/* can overwrite for more control! */
|
||||
std::map<RsPeerId, CacheSet>::iterator pit;
|
||||
std::map<RsPeerId, CacheSet>::iterator pit;
|
||||
out << "CacheStore::listCaches() [" << getCacheType();
|
||||
out << "] Total People: " << caches.size();
|
||||
out << std::endl;
|
||||
@ -377,7 +377,7 @@ bool CacheStore::locked_getStoredCache(RsCacheData &data)
|
||||
return false;
|
||||
}
|
||||
|
||||
std::map<RsPeerId, CacheSet>::iterator pit;
|
||||
std::map<RsPeerId, CacheSet>::iterator pit;
|
||||
if (caches.end() == (pit = caches.find(data.pid)))
|
||||
{
|
||||
return false;
|
||||
@ -414,7 +414,7 @@ bool CacheStore::getAllStoredCaches(std::list<RsCacheData> &data)
|
||||
{
|
||||
lockData(); /* LOCK MUTEX */
|
||||
|
||||
std::map<RsPeerId, CacheSet>::iterator pit;
|
||||
std::map<RsPeerId, CacheSet>::iterator pit;
|
||||
for(pit = caches.begin(); pit != caches.end(); pit++)
|
||||
{
|
||||
CacheSet::iterator cit;
|
||||
@ -547,7 +547,7 @@ int CacheStore::nameCache(RsCacheData &data)
|
||||
std::cerr << "CacheStore::nameCache() for:" << data << std::endl;
|
||||
#endif
|
||||
|
||||
data.name = data.hash;
|
||||
data.name = data.hash.toStdString();
|
||||
data.path = getCacheDir();
|
||||
|
||||
#ifdef CS_DEBUG
|
||||
@ -585,7 +585,7 @@ int CacheStore::loadCache(const RsCacheData &data)
|
||||
void CacheStore::locked_storeCacheEntry(const RsCacheData &data)
|
||||
{
|
||||
/* store what we loaded - overwriting if necessary */
|
||||
std::map<RsPeerId, CacheSet>::iterator pit;
|
||||
std::map<RsPeerId, CacheSet>::iterator pit;
|
||||
if (caches.end() == (pit = caches.find(data.pid)))
|
||||
{
|
||||
/* add in a new CacheSet */
|
||||
@ -658,7 +658,7 @@ void CacheStrapper::statusChange(const std::list<pqipeer> &plist)
|
||||
|
||||
/**************** from pqimonclient ********************/
|
||||
|
||||
void CacheStrapper::refreshCache(const RsCacheData &data,const std::set<std::string>& destination_peers)
|
||||
void CacheStrapper::refreshCache(const RsCacheData &data,const std::set<RsPeerId>& destination_peers)
|
||||
{
|
||||
/* we've received an update
|
||||
* send to all online peers + self intersected with online peers.
|
||||
@ -666,13 +666,13 @@ void CacheStrapper::refreshCache(const RsCacheData &data,const std::set<std::str
|
||||
#ifdef CS_DEBUG
|
||||
std::cerr << "CacheStrapper::refreshCache() : " << data << std::endl;
|
||||
#endif
|
||||
std::string ownid = mLinkMgr->getOwnId() ;
|
||||
std::list<std::string> ids;
|
||||
const RsPeerId& ownid = mLinkMgr->getOwnId() ;
|
||||
std::list<RsPeerId> ids;
|
||||
mLinkMgr->getOnlineList(ids);
|
||||
ids.push_back(ownid) ;
|
||||
|
||||
RsStackMutex stack(csMtx); /******* LOCK STACK MUTEX *********/
|
||||
for(std::list<std::string>::const_iterator it = ids.begin(); it != ids.end(); ++it)
|
||||
for(std::list<RsPeerId>::const_iterator it = ids.begin(); it != ids.end(); ++it)
|
||||
if(destination_peers.find(*it) != destination_peers.end())
|
||||
{
|
||||
#ifdef CS_DEBUG
|
||||
@ -741,28 +741,7 @@ void CacheStrapper::recvCacheResponse(RsCacheData &data, time_t /* ts */)
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* generate periodically or at a change */
|
||||
#if 0
|
||||
bool CacheStrapper::sendCacheQuery(std::list<RsPeerId> &id, time_t ts)
|
||||
{
|
||||
/* iterate through peers, and see who we haven't got an answer from recently */
|
||||
std::map<RsPeerId, CacheTS>::iterator it;
|
||||
for(it = status.begin(); it != status.end(); it++)
|
||||
{
|
||||
if ((ts - (it->second).query) > queryPeriod)
|
||||
{
|
||||
/* query this one */
|
||||
id.push_back(it->first);
|
||||
(it->second).query = ts;
|
||||
}
|
||||
}
|
||||
return (id.size() > 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void CacheStrapper::handleCacheQuery(RsPeerId id, std::map<CacheId,RsCacheData> &hashs)
|
||||
void CacheStrapper::handleCacheQuery(const RsPeerId& id, std::map<CacheId,RsCacheData> &hashs)
|
||||
{
|
||||
/* basic version just iterates through ....
|
||||
* more complex could decide who gets what!
|
||||
@ -816,7 +795,7 @@ void CacheStrapper::listPeerStatus(std::ostream & /* out */)
|
||||
}
|
||||
|
||||
|
||||
bool CacheStrapper::findCache(std::string hash, RsCacheData &data) const
|
||||
bool CacheStrapper::findCache(const RsFileHash& hash, RsCacheData &data) const
|
||||
{
|
||||
/* can overwrite for more control! */
|
||||
std::map<uint16_t, CachePair>::const_iterator it;
|
||||
@ -875,7 +854,7 @@ bool CacheStrapper::saveList(bool &cleanup, std::list<RsItem *>& saveData)
|
||||
std::list<RsCacheData>::iterator cit;
|
||||
std::list<RsCacheData> ownCaches;
|
||||
std::list<RsCacheData> remoteCaches;
|
||||
std::string ownId = mLinkMgr->getOwnId();
|
||||
const RsPeerId& ownId = mLinkMgr->getOwnId();
|
||||
|
||||
std::map<uint16_t, CachePair>::iterator it;
|
||||
for(it = caches.begin(); it != caches.end(); it++)
|
||||
@ -899,7 +878,7 @@ bool CacheStrapper::saveList(bool &cleanup, std::list<RsItem *>& saveData)
|
||||
// Fixup lazy behaviour in clients...
|
||||
// This ensures correct loading later.
|
||||
// (used to be: rscc->pid = cit->pid;)
|
||||
rscc->pid = ownId;
|
||||
rscc->pid = ownId.toStdString();
|
||||
|
||||
//rscc->pname = cit->pname;
|
||||
rscc->cachetypeid = cit->cid.type;
|
||||
@ -926,7 +905,7 @@ bool CacheStrapper::saveList(bool &cleanup, std::list<RsItem *>& saveData)
|
||||
|
||||
RsCacheConfig *rscc = new RsCacheConfig();
|
||||
|
||||
rscc->pid = cit->pid;
|
||||
rscc->pid = cit->pid.toStdString();
|
||||
//rscc->pname = cit->pname;
|
||||
rscc->cachetypeid = cit->cid.type;
|
||||
rscc->cachesubid = cit->cid.subid;
|
||||
@ -955,7 +934,7 @@ bool CacheStrapper::loadList(std::list<RsItem *>& load)
|
||||
#endif
|
||||
std::list<RsCacheData> ownCaches;
|
||||
std::list<RsCacheData> remoteCaches;
|
||||
std::string ownId = mLinkMgr->getOwnId();
|
||||
const RsPeerId& ownId = mLinkMgr->getOwnId();
|
||||
|
||||
//peerConnectState ownState;
|
||||
//mPeerMgr->getOwnNetStatus(ownState);
|
||||
@ -977,7 +956,7 @@ bool CacheStrapper::loadList(std::list<RsItem *>& load)
|
||||
#endif
|
||||
RsCacheData cd;
|
||||
|
||||
cd.pid = rscc->pid;
|
||||
cd.pid = RsPeerId(rscc->pid) ;
|
||||
|
||||
#if 0
|
||||
if(cd.pid == ownId)
|
||||
@ -1073,7 +1052,7 @@ bool CacheStrapper::loadList(std::list<RsItem *>& load)
|
||||
std::list<std::string> cacheDirs;
|
||||
std::list<std::string>::iterator dit;
|
||||
#ifdef CS_DEBUG
|
||||
std::list<std::string>::iterator fit;
|
||||
std::set<std::string>::iterator fit;
|
||||
#endif
|
||||
std::map<uint16_t, CachePair>::iterator cit;
|
||||
for(cit = caches.begin(); cit != caches.end(); cit++)
|
||||
@ -1113,7 +1092,8 @@ bool CacheStrapper::loadList(std::list<RsItem *>& load)
|
||||
#ifdef CS_DEBUG
|
||||
std::cerr << "CacheStrapper::loadList() Cleaning cache dir: <" << *dit << ">" << std::endl;
|
||||
#endif
|
||||
sit = saveFiles.find(RsDirUtil::convertPathToUnix(*dit));
|
||||
sit = saveFiles.find(RsDirUtil::convertPathToUnix(*dit));
|
||||
|
||||
if (sit != saveFiles.end())
|
||||
{
|
||||
#ifdef CS_DEBUG
|
||||
@ -1153,8 +1133,8 @@ bool CacheTransfer::RequestCache(RsCacheData &data, CacheStore *cbStore)
|
||||
* - if duplicate hash -> Fail Transfer
|
||||
*/
|
||||
|
||||
std::map<std::string, RsCacheData>::iterator dit;
|
||||
std::map<std::string, CacheStore *>::iterator sit;
|
||||
std::map<RsFileHash, RsCacheData>::iterator dit;
|
||||
std::map<RsFileHash, CacheStore *>::iterator sit;
|
||||
|
||||
for(dit = cbData.begin(); dit != cbData.end(); dit++)
|
||||
{
|
||||
@ -1219,7 +1199,7 @@ bool CacheTransfer::RequestCache(RsCacheData &data, CacheStore *cbStore)
|
||||
|
||||
|
||||
/* to be overloaded */
|
||||
bool CacheTransfer::RequestCacheFile(RsPeerId id, std::string path, std::string hash, uint64_t size)
|
||||
bool CacheTransfer::RequestCacheFile(const RsPeerId& id, std::string path, const RsFileHash& hash, uint64_t size)
|
||||
{
|
||||
(void) id;
|
||||
(void) path;
|
||||
@ -1233,12 +1213,12 @@ bool CacheTransfer::RequestCacheFile(RsPeerId id, std::string path, std::string
|
||||
#endif
|
||||
|
||||
/* just tell them we've completed! */
|
||||
CompletedCache(hash);
|
||||
CompletedCache(hash);
|
||||
return true;
|
||||
}
|
||||
|
||||
/* to be overloaded */
|
||||
bool CacheTransfer::CancelCacheFile(RsPeerId id, std::string path, std::string hash, uint64_t size)
|
||||
bool CacheTransfer::CancelCacheFile(const RsPeerId& id, std::string path, const RsFileHash &hash, uint64_t size)
|
||||
{
|
||||
(void) id;
|
||||
(void) path;
|
||||
@ -1257,10 +1237,10 @@ bool CacheTransfer::CancelCacheFile(RsPeerId id, std::string path, std::string h
|
||||
|
||||
|
||||
/* internal completion -> does cb */
|
||||
bool CacheTransfer::CompletedCache(std::string hash)
|
||||
bool CacheTransfer::CompletedCache(const RsFileHash& hash)
|
||||
{
|
||||
std::map<std::string, RsCacheData>::iterator dit;
|
||||
std::map<std::string, CacheStore *>::iterator sit;
|
||||
std::map<RsFileHash, RsCacheData>::iterator dit;
|
||||
std::map<RsFileHash, CacheStore *>::iterator sit;
|
||||
|
||||
#ifdef CS_DEBUG
|
||||
std::cerr << "CacheTransfer::CompletedCache(" << hash << ")";
|
||||
@ -1296,13 +1276,13 @@ bool CacheTransfer::CompletedCache(std::string hash)
|
||||
}
|
||||
|
||||
/* internal completion -> does cb */
|
||||
bool CacheTransfer::FailedCache(std::string hash)
|
||||
bool CacheTransfer::FailedCache(const RsFileHash& hash)
|
||||
{
|
||||
std::map<std::string, RsCacheData>::iterator dit;
|
||||
std::map<std::string, CacheStore *>::iterator sit;
|
||||
std::map<RsFileHash, RsCacheData>::iterator dit;
|
||||
std::map<RsFileHash, CacheStore *>::iterator sit;
|
||||
|
||||
/* find in store.... */
|
||||
sit = cbStores.find(hash);
|
||||
sit = cbStores.find(hash);
|
||||
dit = cbData.find(hash);
|
||||
|
||||
if ((sit == cbStores.end()) || (dit == cbData.end()))
|
||||
@ -1321,7 +1301,7 @@ bool CacheTransfer::FailedCache(std::string hash)
|
||||
}
|
||||
|
||||
|
||||
bool CacheTransfer::FindCacheFile(std::string hash, std::string &path, uint64_t &size)
|
||||
bool CacheTransfer::FindCacheFile(const RsFileHash &hash, std::string &path, uint64_t &size)
|
||||
{
|
||||
RsCacheData data;
|
||||
if (strapper->findCache(hash, data))
|
||||
|
@ -60,11 +60,6 @@ class CacheSource; /* Interface for local File Index/Monitor */
|
||||
class CacheStore; /* Interface for the actual Cache */
|
||||
class CacheStrapper; /* Controlling Class */
|
||||
|
||||
/****
|
||||
typedef uint32_t RsPeerId;
|
||||
*****/
|
||||
typedef std::string RsPeerId;
|
||||
|
||||
/******************************** CacheId ********************************/
|
||||
|
||||
/*!
|
||||
@ -91,12 +86,12 @@ class RsCacheData
|
||||
{
|
||||
public:
|
||||
|
||||
RsPeerId pid; /// peer id
|
||||
RsPeerId pid; /// peer id
|
||||
/// REMOVED as a WASTE to look it up everywhere! std::string pname; /// peer name (can be used by cachestore)
|
||||
CacheId cid; /// cache id
|
||||
std::string path; /// file system path where physical cache data is located
|
||||
std::string name;
|
||||
std::string hash;
|
||||
RsFileHash hash;
|
||||
uint64_t size;
|
||||
time_t recvd; /// received timestamp
|
||||
};
|
||||
@ -119,7 +114,7 @@ class CacheTransfer
|
||||
/*!
|
||||
* upload side of things .... searches through CacheStrapper.
|
||||
*/
|
||||
bool FindCacheFile(std::string hash, std::string &path, uint64_t &size);
|
||||
bool FindCacheFile(const RsFileHash& hash, std::string &path, uint64_t &size);
|
||||
|
||||
/*!
|
||||
* At the download side RequestCache() => overloaded RequestCacheFile()
|
||||
@ -132,18 +127,18 @@ class CacheTransfer
|
||||
/*!
|
||||
* to be overloaded
|
||||
*/
|
||||
virtual bool RequestCacheFile(RsPeerId id, std::string path, std::string hash, uint64_t size);
|
||||
virtual bool CancelCacheFile(RsPeerId id, std::string path, std::string hash, uint64_t size);
|
||||
virtual bool RequestCacheFile(const RsPeerId& id, std::string path, const RsFileHash& hash, uint64_t size);
|
||||
virtual bool CancelCacheFile(const RsPeerId& id, std::string path, const RsFileHash& hash, uint64_t size);
|
||||
|
||||
bool CompletedCache(std::string hash); /* internal completion -> does cb */
|
||||
bool FailedCache(std::string hash); /* internal completion -> does cb */
|
||||
bool CompletedCache(const RsFileHash &hash); /* internal completion -> does cb */
|
||||
bool FailedCache(const RsFileHash &hash); /* internal completion -> does cb */
|
||||
|
||||
private:
|
||||
|
||||
CacheStrapper *strapper;
|
||||
|
||||
std::map<std::string, RsCacheData> cbData;
|
||||
std::map<std::string, CacheStore *> cbStores;
|
||||
std::map<RsFileHash, RsCacheData> cbData;
|
||||
std::map<RsFileHash, CacheStore *> cbStores;
|
||||
};
|
||||
|
||||
|
||||
@ -172,7 +167,7 @@ class CacheSource
|
||||
* called to determine available cache for peer -
|
||||
* default acceptable (returns all)
|
||||
*/
|
||||
virtual bool cachesAvailable(RsPeerId pid, std::map<CacheId, RsCacheData> &ids);
|
||||
virtual bool cachesAvailable(const RsPeerId& pid, std::map<CacheId, RsCacheData> &ids);
|
||||
|
||||
/*!
|
||||
* function called at startup to load from
|
||||
@ -182,12 +177,12 @@ class CacheSource
|
||||
virtual bool loadLocalCache(const RsCacheData &data);
|
||||
|
||||
/* control Caches available */
|
||||
bool refreshCache(const RsCacheData &data,const std::set<std::string>& destination_peers);
|
||||
bool refreshCache(const RsCacheData &data,const std::set<RsPeerId>& destination_peers);
|
||||
bool refreshCache(const RsCacheData &data);
|
||||
bool clearCache(CacheId id);
|
||||
|
||||
/* controls if peer is an accepted receiver for cache items. Default is yes. To be overloaded. */
|
||||
virtual bool isPeerAcceptedAsCacheReceiver(const std::string& /*peer_id*/) { return true ; }
|
||||
virtual bool isPeerAcceptedAsCacheReceiver(const RsPeerId& /*peer_id*/) { return true ; }
|
||||
|
||||
/* get private data */
|
||||
std::string getCacheDir() { return cacheDir; }
|
||||
@ -198,7 +193,7 @@ class CacheSource
|
||||
void listCaches(std::ostream &out);
|
||||
|
||||
/* search */
|
||||
bool findCache(std::string hash, RsCacheData &data) const;
|
||||
bool findCache(const RsFileHash& hash, RsCacheData &data) const;
|
||||
|
||||
protected:
|
||||
|
||||
@ -211,7 +206,7 @@ class CacheSource
|
||||
void unlockData() const;
|
||||
|
||||
CacheSet caches; /// all local cache data stored here
|
||||
std::map<std::string, RsCacheData> mOldCaches; /// replaced/cleared caches are pushed here (in case requested)
|
||||
std::map<RsFileHash, RsCacheData> mOldCaches; /// replaced/cleared caches are pushed here (in case requested)
|
||||
|
||||
private:
|
||||
|
||||
@ -276,7 +271,7 @@ class CacheStore
|
||||
/* virtual functions overloaded by cache implementor */
|
||||
|
||||
/* controls if peer is an accepted provider for cache items. Default is yes. To be overloaded. */
|
||||
virtual bool isPeerAcceptedAsCacheProvider(const std::string& /*peer_id*/) { return true ; }
|
||||
virtual bool isPeerAcceptedAsCacheProvider(const RsPeerId& /*peer_id*/) { return true ; }
|
||||
|
||||
/*!
|
||||
* @param data cache data is stored here
|
||||
@ -334,7 +329,7 @@ class CacheStore
|
||||
std::string cacheDir;
|
||||
|
||||
mutable RsMutex cMutex;
|
||||
std::map<RsPeerId, CacheSet> caches;
|
||||
std::map<RsPeerId, CacheSet> caches;
|
||||
|
||||
};
|
||||
|
||||
@ -407,7 +402,7 @@ virtual void statusChange(const std::list<pqipeer> &plist);
|
||||
*
|
||||
*/
|
||||
void refreshCache(const RsCacheData &data);
|
||||
void refreshCache(const RsCacheData &data,const std::set<std::string>& destination_peers); // specify a particular list of destination peers (self not added!)
|
||||
void refreshCache(const RsCacheData &data,const std::set<RsPeerId>& destination_peers); // specify a particular list of destination peers (self not added!)
|
||||
|
||||
/*!
|
||||
* forces config savelist
|
||||
@ -429,14 +424,14 @@ void addCachePair(CachePair pair);
|
||||
|
||||
/*** I/O (2) ***/
|
||||
void recvCacheResponse(RsCacheData &data, time_t ts);
|
||||
void handleCacheQuery(RsPeerId id, std::map<CacheId, RsCacheData> &data);
|
||||
void handleCacheQuery(const RsPeerId& id, std::map<CacheId, RsCacheData> &data);
|
||||
|
||||
|
||||
/*!
|
||||
* search through CacheSources.
|
||||
* @return false if cachedate mapping to hash not found
|
||||
*/
|
||||
bool findCache(std::string hash, RsCacheData &data) const;
|
||||
bool findCache(const RsFileHash &hash, RsCacheData &data) const;
|
||||
|
||||
/* display */
|
||||
void listCaches(std::ostream &out);
|
||||
@ -472,7 +467,7 @@ virtual bool loadList(std::list<RsItem *>& load);
|
||||
|
||||
RsMutex csMtx; /* protect below */
|
||||
|
||||
std::list<std::pair<RsPeerId, RsCacheData> > mCacheUpdates;
|
||||
std::list<std::pair<RsPeerId, RsCacheData> > mCacheUpdates;
|
||||
};
|
||||
|
||||
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "retroshare/rsiface.h"
|
||||
#include "pqi/p3notify.h"
|
||||
#include "retroshare/rspeers.h"
|
||||
#include "retroshare/rstypes.h"
|
||||
#include "util/folderiterator.h"
|
||||
#include <errno.h>
|
||||
|
||||
@ -52,7 +53,7 @@
|
||||
//#define FIM_DEBUG 1
|
||||
// ***********/
|
||||
|
||||
FileIndexMonitor::FileIndexMonitor(CacheStrapper *cs, std::string cachedir, std::string pid,const std::string& config_dir)
|
||||
FileIndexMonitor::FileIndexMonitor(CacheStrapper *cs, std::string cachedir, const RsPeerId& pid,const std::string& config_dir)
|
||||
:CacheSource(RS_SERVICE_TYPE_FILE_INDEX, false, cs, cachedir), fiMutex("FileIndexMonitor"), fi(pid),
|
||||
pendingDirs(false), pendingForceCacheWrite(false),
|
||||
mForceCheck(false), mInCheck(false), hashCache(config_dir+"/" + "file_cache.lst"),useHashCache(true)
|
||||
@ -142,12 +143,6 @@ HashCache::HashCache(const std::string& path)
|
||||
f.getline(buff,max_line_size,'\n') ; if(sscanf(buff,RsDirUtil::scanf_string_for_uint(sizeof(info.modf_stamp)),&info.modf_stamp) != 1) { std::cerr << "Could not read one entry! Giving up." << std::endl; break ; }
|
||||
f.getline(buff,max_line_size,'\n') ; info.hash = std::string(buff) ;
|
||||
|
||||
if(info.hash.length() != 40)
|
||||
{
|
||||
std::cerr << "Loaded hash is not a hash: " << info.hash << std::endl;
|
||||
break ;
|
||||
}
|
||||
|
||||
#ifdef FIM_DEBUG
|
||||
std::cerr << " (" << name << ", " << info.size << ", " << info.time_stamp << ", " << info.modf_stamp << ", " << info.hash << std::endl ;
|
||||
++n ;
|
||||
@ -194,7 +189,7 @@ void HashCache::save()
|
||||
#endif
|
||||
}
|
||||
|
||||
bool HashCache::find(const std::string& full_path,uint64_t size,time_t time_stamp,std::string& hash)
|
||||
bool HashCache::find(const std::string& full_path,uint64_t size,time_t time_stamp,RsFileHash& hash)
|
||||
{
|
||||
#ifdef FIM_DEBUG
|
||||
std::cerr << "HashCache: looking for " << full_path << std::endl ;
|
||||
@ -219,7 +214,7 @@ bool HashCache::find(const std::string& full_path,uint64_t size,time_t time_stam
|
||||
return false ;
|
||||
}
|
||||
}
|
||||
void HashCache::insert(const std::string& full_path,uint64_t size,time_t time_stamp,const std::string& hash)
|
||||
void HashCache::insert(const std::string& full_path,uint64_t size,time_t time_stamp,const RsFileHash& hash)
|
||||
{
|
||||
HashCacheInfo info ;
|
||||
info.size = size ;
|
||||
@ -271,7 +266,7 @@ FileIndexMonitor::~FileIndexMonitor()
|
||||
/* Data cleanup - TODO */
|
||||
}
|
||||
|
||||
int FileIndexMonitor::SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags,const std::string& peer_id)
|
||||
int FileIndexMonitor::SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags,const RsPeerId& peer_id)
|
||||
{
|
||||
results.clear();
|
||||
std::list<FileEntry *> firesults;
|
||||
@ -284,7 +279,7 @@ int FileIndexMonitor::SearchKeywords(std::list<std::string> keywords, std::list<
|
||||
return filterResults(firesults,results,flags,peer_id) ;
|
||||
}
|
||||
|
||||
int FileIndexMonitor::SearchBoolExp(Expression *exp, std::list<DirDetails>& results,FileSearchFlags flags,const std::string& peer_id) const
|
||||
int FileIndexMonitor::SearchBoolExp(Expression *exp, std::list<DirDetails>& results,FileSearchFlags flags,const RsPeerId& peer_id) const
|
||||
{
|
||||
results.clear();
|
||||
std::list<FileEntry *> firesults;
|
||||
@ -297,7 +292,7 @@ int FileIndexMonitor::SearchBoolExp(Expression *exp, std::list<DirDetails>& resu
|
||||
return filterResults(firesults,results,flags,peer_id) ;
|
||||
}
|
||||
|
||||
int FileIndexMonitor::filterResults(std::list<FileEntry*>& firesults,std::list<DirDetails>& results,FileSearchFlags flags,const std::string& peer_id) const
|
||||
int FileIndexMonitor::filterResults(std::list<FileEntry*>& firesults,std::list<DirDetails>& results,FileSearchFlags flags,const RsPeerId& peer_id) const
|
||||
{
|
||||
#ifdef DEBUG
|
||||
if((flags & ~RS_FILE_HINTS_PERMISSION_MASK) > 0)
|
||||
@ -313,13 +308,13 @@ int FileIndexMonitor::filterResults(std::list<FileEntry*>& firesults,std::list<D
|
||||
std::cerr << "Filtering candidate " << (*rit)->name << ", flags=" << cdetails.flags << ", peer=" << peer_id ;
|
||||
#endif
|
||||
|
||||
if(!peer_id.empty())
|
||||
if(!peer_id.isNull())
|
||||
{
|
||||
FileSearchFlags permission_flags = rsPeers->computePeerPermissionFlags(peer_id,cdetails.flags,cdetails.parent_groups) ;
|
||||
|
||||
if (cdetails.type == DIR_TYPE_FILE && ( permission_flags & flags ))
|
||||
{
|
||||
cdetails.id = "Local";
|
||||
cdetails.id.clear() ;
|
||||
results.push_back(cdetails);
|
||||
#ifdef FIM_DEBUG
|
||||
std::cerr << ": kept" << std::endl ;
|
||||
@ -337,7 +332,7 @@ int FileIndexMonitor::filterResults(std::list<FileEntry*>& firesults,std::list<D
|
||||
return !results.empty() ;
|
||||
}
|
||||
|
||||
bool FileIndexMonitor::findLocalFile(std::string hash,FileSearchFlags hint_flags, const std::string& 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<std::string>& parent_groups) const
|
||||
{
|
||||
std::list<FileEntry *> results;
|
||||
bool ok = false;
|
||||
@ -361,12 +356,12 @@ bool FileIndexMonitor::findLocalFile(std::string hash,FileSearchFlags hint_flags
|
||||
|
||||
// turn share flags into hint flags
|
||||
|
||||
FileSearchFlags shflh = peer_id.empty()?(RS_FILE_HINTS_BROWSABLE|RS_FILE_HINTS_NETWORK_WIDE):rsPeers->computePeerPermissionFlags(peer_id,storage_flags,parent_groups) ;
|
||||
FileSearchFlags shflh = peer_id.isNull()?(RS_FILE_HINTS_BROWSABLE|RS_FILE_HINTS_NETWORK_WIDE):rsPeers->computePeerPermissionFlags(peer_id,storage_flags,parent_groups) ;
|
||||
#ifdef FIM_DEBUG
|
||||
std::cerr << "FileIndexMonitor::findLocalFile: Filtering candidate " << fe->name << ", flags=" << storage_flags << ", hint_flags=" << hint_flags << ", peer_id = " << peer_id << std::endl ;
|
||||
#endif
|
||||
|
||||
if(peer_id.empty() || (shflh & hint_flags))
|
||||
if(peer_id.isNull() || (shflh & hint_flags))
|
||||
{
|
||||
#ifdef FIM_DEBUG
|
||||
std::cerr << "FileIndexMonitor::findLocalFile() Found Name: " << fe->name << std::endl;
|
||||
@ -451,14 +446,14 @@ bool FileIndexMonitor::loadLocalCache(const RsCacheData &data) /* called with s
|
||||
|
||||
std::string name = data.name ;
|
||||
|
||||
if ((ok = fi.loadIndex(data.path + '/' + name, "", data.size)))
|
||||
if ((ok = fi.loadIndex(data.path + '/' + name, RsFileHash(), data.size)))
|
||||
{
|
||||
#ifdef FIM_DEBUG
|
||||
std::cerr << "FileIndexMonitor::loadCache() Success!";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
fi.root->row = 0;
|
||||
fi.root->name = data.pid; // XXX Hack here - TODO
|
||||
fi.root->name = data.pid.toStdString(); // XXX Hack here - TODO
|
||||
|
||||
std::string fname_browsable = data.path + '/' + name ;
|
||||
struct stat64 buf;
|
||||
@ -516,7 +511,7 @@ bool FileIndexMonitor::loadLocalCache(const RsCacheData &data) /* called with s
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FileIndexMonitor::updateCache(const RsCacheData &data,const std::set<std::string>& destination_peers) /* we call this one */
|
||||
bool FileIndexMonitor::updateCache(const RsCacheData &data,const std::set<RsPeerId>& destination_peers) /* we call this one */
|
||||
{
|
||||
return refreshCache(data,destination_peers);
|
||||
}
|
||||
@ -1107,18 +1102,18 @@ time_t FileIndexMonitor::locked_saveFileIndexes(bool update_cache)
|
||||
// To figure out which sets are different, we index them by the set of forbidden indexes from the directory list.
|
||||
// This is probably a bit costly, but we can't suppose that the number of shared directories is bounded.
|
||||
//
|
||||
std::list<std::string> all_friend_ids ;
|
||||
std::list<RsPeerId> all_friend_ids ;
|
||||
rsPeers->getFriendList(all_friend_ids);
|
||||
|
||||
#ifdef FIM_DEBUG
|
||||
std::cerr << "FileIndexMonitor::updateCycle(): got list of all friends." << std::endl ;
|
||||
for(std::list<std::string>::const_iterator it(all_friend_ids.begin());it!=all_friend_ids.end();++it)
|
||||
for(std::list<RsPeerId>::const_iterator it(all_friend_ids.begin());it!=all_friend_ids.end();++it)
|
||||
std::cerr << " " << *it << std::endl;
|
||||
#endif
|
||||
|
||||
std::map<std::set<std::string>, std::set<std::string> > peers_per_directory_combination ;
|
||||
std::map<std::set<std::string>, std::set<RsPeerId> > peers_per_directory_combination ;
|
||||
|
||||
for(std::list<std::string>::const_iterator it(all_friend_ids.begin());it!=all_friend_ids.end();++it)
|
||||
for(std::list<RsPeerId>::const_iterator it(all_friend_ids.begin());it!=all_friend_ids.end();++it)
|
||||
{
|
||||
#ifdef FIM_DEBUG
|
||||
std::cerr << "About to save, with the following restrictions:" << std::endl ;
|
||||
@ -1153,14 +1148,14 @@ time_t FileIndexMonitor::locked_saveFileIndexes(bool update_cache)
|
||||
|
||||
peers_per_directory_combination[forbidden_dirs].insert(*it) ;
|
||||
}
|
||||
std::string ownId = rsPeers->getOwnId() ;
|
||||
RsPeerId ownId = rsPeers->getOwnId() ;
|
||||
peers_per_directory_combination[std::set<std::string>()].insert(ownId) ; // add full configuration to self, i.e. no forbidden directories.
|
||||
|
||||
int n=0 ;
|
||||
time_t now = time(NULL) ;
|
||||
time_t mod_time = 0 ;
|
||||
|
||||
for(std::map<std::set<std::string>, std::set<std::string> >::const_iterator it(peers_per_directory_combination.begin());
|
||||
for(std::map<std::set<std::string>, std::set<RsPeerId> >::const_iterator it(peers_per_directory_combination.begin());
|
||||
it!=peers_per_directory_combination.end();++it,++n)
|
||||
{
|
||||
std::string tmpname_browsable;
|
||||
@ -1176,14 +1171,14 @@ time_t FileIndexMonitor::locked_saveFileIndexes(bool update_cache)
|
||||
std::cerr << "Sending file list: " << std::endl;
|
||||
std::cerr << " filename : " << tmpname_browsable << std::endl;
|
||||
std::cerr << " to peers : " << std::endl;
|
||||
for(std::set<std::string>::const_iterator itt(it->second.begin());itt!= it->second.end();++itt)
|
||||
for(std::set<RsPeerId>::const_iterator itt(it->second.begin());itt!= it->second.end();++itt)
|
||||
std::cerr << " " << *itt << std::endl;
|
||||
std::cerr << " forbidden : " << std::endl;
|
||||
for(std::set<std::string>::const_iterator itt(it->first.begin());itt!= it->first.end();++itt)
|
||||
std::cerr << " " << *itt << std::endl;
|
||||
#endif
|
||||
|
||||
std::string hash ;
|
||||
RsFileHash hash ;
|
||||
uint64_t size ;
|
||||
|
||||
#ifdef FIM_DEBUG
|
||||
@ -1210,7 +1205,7 @@ time_t FileIndexMonitor::locked_saveFileIndexes(bool update_cache)
|
||||
data.size = size;
|
||||
data.recvd = time(NULL);
|
||||
|
||||
for(std::set<std::string>::const_iterator ff(it->second.begin());ff!=it->second.end();++ff)
|
||||
for(std::set<RsPeerId>::const_iterator ff(it->second.begin());ff!=it->second.end();++ff)
|
||||
_cache_items_per_peer[*ff] = data ;
|
||||
|
||||
data.cid.subid = 0;
|
||||
@ -1261,7 +1256,7 @@ bool FileIndexMonitor::cachesAvailable(RsPeerId pid,std::map<CacheId, RsCacheDat
|
||||
//
|
||||
ids.clear() ;
|
||||
std::map<RsPeerId,RsCacheData>::const_iterator it(_cache_items_per_peer.find(pid)) ;
|
||||
std::string ownId = rsPeers->getOwnId() ;
|
||||
RsPeerId ownId = rsPeers->getOwnId();
|
||||
|
||||
if(it != _cache_items_per_peer.end())
|
||||
{
|
||||
@ -1591,7 +1586,7 @@ int FileIndexMonitor::RequestDirDetails(void *ref, DirDetails &details, FileSear
|
||||
details.ref = NULL;
|
||||
details.type = DIR_TYPE_ROOT;
|
||||
details.name = "root";
|
||||
details.hash = "";
|
||||
details.hash.clear() ;
|
||||
details.path = "root";
|
||||
details.age = 0;
|
||||
details.flags.clear() ;
|
||||
|
@ -76,8 +76,8 @@ class HashCache
|
||||
HashCache(const std::string& save_file_name) ;
|
||||
|
||||
void save() ;
|
||||
void insert(const std::string& full_path,uint64_t size,time_t time_stamp,const std::string& hash) ;
|
||||
bool find(const std::string& full_path,uint64_t size,time_t time_stamp,std::string& hash) ;
|
||||
void insert(const std::string& full_path,uint64_t size,time_t time_stamp,const RsFileHash& hash) ;
|
||||
bool find(const std::string& full_path,uint64_t size,time_t time_stamp,RsFileHash& hash) ;
|
||||
void clean() ;
|
||||
|
||||
typedef struct
|
||||
@ -85,7 +85,7 @@ class HashCache
|
||||
uint64_t size ;
|
||||
uint64_t time_stamp ;
|
||||
uint64_t modf_stamp ;
|
||||
std::string hash ;
|
||||
RsFileHash hash ;
|
||||
} HashCacheInfo ;
|
||||
|
||||
void setRememberHashFilesDuration(uint32_t days) { _max_cache_duration_days = days ; }
|
||||
@ -94,7 +94,7 @@ class HashCache
|
||||
bool empty() const { return _files.empty() ; }
|
||||
private:
|
||||
uint32_t _max_cache_duration_days ; // maximum duration of un-requested cache entries
|
||||
std::map<std::string, HashCacheInfo> _files ;
|
||||
std::map<std::string, HashCacheInfo> _files ;
|
||||
std::string _path ;
|
||||
bool _changed ;
|
||||
};
|
||||
@ -106,16 +106,16 @@ class HashCache
|
||||
class FileIndexMonitor: public CacheSource, public RsThread
|
||||
{
|
||||
public:
|
||||
FileIndexMonitor(CacheStrapper *cs, std::string cachedir, std::string pid, const std::string& config_dir);
|
||||
FileIndexMonitor(CacheStrapper *cs, std::string cachedir, const RsPeerId& pid, const std::string& config_dir);
|
||||
virtual ~FileIndexMonitor();
|
||||
|
||||
/* external interface for filetransfer */
|
||||
bool findLocalFile(std::string hash,FileSearchFlags flags,const std::string& 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<std::string>& parent_groups) const;
|
||||
|
||||
int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags,const std::string& peer_id) ;
|
||||
int SearchBoolExp(Expression *exp, std::list<DirDetails> &results,FileSearchFlags flags,const std::string& peer_id) 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 ;
|
||||
|
||||
int filterResults(std::list<FileEntry*>& firesults,std::list<DirDetails>& results,FileSearchFlags flags,const std::string& peer_id) const ;
|
||||
int filterResults(std::list<FileEntry*>& firesults,std::list<DirDetails>& results,FileSearchFlags flags,const RsPeerId& peer_id) const ;
|
||||
|
||||
|
||||
/* external interface for local access to files */
|
||||
@ -125,7 +125,7 @@ class FileIndexMonitor: public CacheSource, public RsThread
|
||||
/* Interacting with CacheSource */
|
||||
/* overloaded from CacheSource */
|
||||
virtual bool loadLocalCache(const RsCacheData &data); /* called with stored data */
|
||||
bool updateCache(const RsCacheData &data,const std::set<std::string>& dest_peers); /* we call when we have a new cache for others */
|
||||
bool updateCache(const RsCacheData &data,const std::set<RsPeerId>& dest_peers); /* we call when we have a new cache for others */
|
||||
|
||||
|
||||
/* the FileIndexMonitor inner workings */
|
||||
|
@ -500,7 +500,7 @@ int FileEntry::print(std::string &out)
|
||||
else
|
||||
out += "[MISSING PARENT]";
|
||||
|
||||
rs_sprintf_append(out, " %s [ s: %lld ] ==> [ %s ]\n", name.c_str(), size, hash.c_str());
|
||||
rs_sprintf_append(out, " %s [ s: %lld ] ==> [ %s ]\n", name.c_str(), size, hash.toStdString().c_str());
|
||||
|
||||
return 1;
|
||||
}
|
||||
@ -524,7 +524,7 @@ int DirEntry::print(std::string &out)
|
||||
return 1;
|
||||
}
|
||||
|
||||
FileIndex::FileIndex(const std::string& pid)
|
||||
FileIndex::FileIndex(const RsPeerId& pid)
|
||||
{
|
||||
root = new PersonEntry(pid);
|
||||
registerEntry(root) ;
|
||||
@ -754,7 +754,7 @@ int FileIndex::printFileIndex(std::string &out)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int FileIndex::loadIndex(const std::string& filename, const std::string& expectedHash, uint64_t size)
|
||||
int FileIndex::loadIndex(const std::string& filename, const RsFileHash& expectedHash, uint64_t size)
|
||||
{
|
||||
FILE *file = RsDirUtil::rs_fopen(filename.c_str(),"rb") ;
|
||||
|
||||
@ -783,7 +783,7 @@ int FileIndex::loadIndex(const std::string& filename, const std::string& expecte
|
||||
}
|
||||
fclose(file) ;
|
||||
|
||||
std::string tmpout = RsDirUtil::sha1sum((unsigned char *)(compressed_data),size).toStdString() ;
|
||||
RsFileHash tmpout = RsDirUtil::sha1sum((unsigned char *)(compressed_data),size);
|
||||
|
||||
// /* calculate hash */
|
||||
// unsigned char sha_buf[SHA_DIGEST_LENGTH];
|
||||
@ -799,7 +799,7 @@ int FileIndex::loadIndex(const std::string& filename, const std::string& expecte
|
||||
// rs_sprintf_append(tmpout, "%02x", (unsigned int) (sha_buf[i]));
|
||||
// }
|
||||
|
||||
if (expectedHash != "" && expectedHash != tmpout)
|
||||
if (!expectedHash.isNull() && expectedHash != tmpout)
|
||||
{
|
||||
#ifdef FI_DEBUG
|
||||
std::cerr << "FileIndex::loadIndex expected hash does not match" << std::endl;
|
||||
@ -821,6 +821,11 @@ int FileIndex::loadIndex(const std::string& filename, const std::string& expecte
|
||||
}
|
||||
std::string s((char *)uncompressed_data,uncompressed_data_size) ;
|
||||
|
||||
std::cerr << " file = " << filename << std::endl;
|
||||
std::cerr << " uncompressed size = " << uncompressed_data_size << std::endl;
|
||||
std::cerr << " compressed size = " << size << std::endl;
|
||||
std::cerr << " hash = " << tmpout << std::endl;
|
||||
|
||||
delete[] compressed_data ;
|
||||
free(uncompressed_data) ;
|
||||
|
||||
@ -857,7 +862,7 @@ int FileIndex::loadIndex(const std::string& filename, const std::string& expecte
|
||||
/* finished parse, last dir is root */
|
||||
case 1:
|
||||
{
|
||||
std::string pid = root -> id;
|
||||
RsPeerId pid = root -> id;
|
||||
FileIndex::unregisterEntry((void*)root) ;
|
||||
delete root; /* to clean up old entries */
|
||||
root = new PersonEntry(pid);
|
||||
@ -991,9 +996,8 @@ error:
|
||||
}
|
||||
|
||||
|
||||
int FileIndex::saveIndex(const std::string& filename, std::string &fileHash, uint64_t &size,const std::set<std::string>& forbidden_dirs)
|
||||
int FileIndex::saveIndex(const std::string& filename, RsFileHash &fileHash, uint64_t &size,const std::set<std::string>& forbidden_dirs)
|
||||
{
|
||||
unsigned char sha_buf[SHA_DIGEST_LENGTH];
|
||||
std::string filenametmp = filename + ".tmp" ;
|
||||
std::string s;
|
||||
|
||||
@ -1049,6 +1053,7 @@ int FileIndex::saveIndex(const std::string& filename, std::string &fileHash, uin
|
||||
|
||||
fileHash = RsDirUtil::sha1sum((unsigned char *)compressed_data,compressed_data_size).toStdString() ;
|
||||
|
||||
std::cerr << " file = " << filename << std::endl;
|
||||
std::cerr << " old size = " << s.length() << std::endl;
|
||||
std::cerr << " new size = " << compressed_data_size << std::endl;
|
||||
std::cerr << " hash = " << fileHash << std::endl;
|
||||
@ -1138,7 +1143,7 @@ void DirEntry::writeFileInfo(std::string& s)
|
||||
{
|
||||
rs_sprintf_append(s, "f%s%c%s%c%lld%c%ld%c%d%c%ld%c\n",
|
||||
FixName((fit->second)->name).c_str(), FILE_CACHE_SEPARATOR_CHAR,
|
||||
(fit->second)->hash.c_str(), FILE_CACHE_SEPARATOR_CHAR,
|
||||
(fit->second)->hash.toStdString().c_str(), FILE_CACHE_SEPARATOR_CHAR,
|
||||
(fit->second)->size, FILE_CACHE_SEPARATOR_CHAR,
|
||||
(fit->second)->modtime, FILE_CACHE_SEPARATOR_CHAR,
|
||||
(fit->second)->pop, FILE_CACHE_SEPARATOR_CHAR,
|
||||
@ -1165,14 +1170,14 @@ int DirEntry::saveEntry(std::string &s)
|
||||
}
|
||||
|
||||
|
||||
int FileIndex::searchHash(const std::string& hash, std::list<FileEntry *> &results) const
|
||||
int FileIndex::searchHash(const RsFileHash& hash, std::list<FileEntry *> &results) const
|
||||
{
|
||||
#ifdef FI_DEBUG
|
||||
std::cerr << "FileIndex::searchHash(" << hash << ")";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
std::map<std::string,FileEntry*>::const_iterator it = _file_hashes.find(hash) ;
|
||||
std::map<RsFileHash,FileEntry*>::const_iterator it = _file_hashes.find(hash) ;
|
||||
|
||||
if(it!=_file_hashes.end() && isValid((void*)it->second))
|
||||
results.push_back(it->second) ;
|
||||
@ -1394,7 +1399,7 @@ bool FileIndex::extractData(void *ref,DirDetails& details)
|
||||
}
|
||||
|
||||
FileEntry *file = static_cast<FileEntry *>(ref);
|
||||
DirEntry *dir = (file->hash.empty())?static_cast<DirEntry *>(file):NULL ; // This is a hack to avoid doing a dynamic_cast
|
||||
DirEntry *dir = (file->hash.isNull())?static_cast<DirEntry *>(file):NULL ; // This is a hack to avoid doing a dynamic_cast
|
||||
|
||||
details.children.clear() ;
|
||||
time_t now = time(NULL) ;
|
||||
@ -1433,7 +1438,7 @@ bool FileIndex::extractData(void *ref,DirDetails& details)
|
||||
details.type = DIR_TYPE_PERSON ;
|
||||
else
|
||||
details.type = DIR_TYPE_DIR;
|
||||
details.hash = "";
|
||||
details.hash.clear() ;
|
||||
details.count = dir->subdirs.size() + dir->files.size();
|
||||
details.min_age = now - dir->most_recent_time ;
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ virtual int print(std::string &out);
|
||||
|
||||
/* Data */
|
||||
std::string name;
|
||||
std::string hash;
|
||||
RsFileHash hash;
|
||||
uint64_t size; /* file size */
|
||||
time_t modtime; /* modification time - most recent mod time for a sub entry for dirs */
|
||||
int pop; /* popularity rating */
|
||||
@ -174,7 +174,7 @@ class PersonEntry: public DirEntry
|
||||
{
|
||||
public:
|
||||
/* cleanup */
|
||||
PersonEntry(const std::string& pid) : id(pid) { return; }
|
||||
PersonEntry(const RsPeerId& pid) : id(pid) { return; }
|
||||
virtual ~PersonEntry() { return; }
|
||||
|
||||
DirEntry &operator=(DirEntry &src)
|
||||
@ -186,7 +186,7 @@ DirEntry &operator=(DirEntry &src)
|
||||
virtual uint32_t type() const { return DIR_TYPE_PERSON ; }
|
||||
|
||||
/* Data */
|
||||
std::string id;
|
||||
RsPeerId id;
|
||||
|
||||
/* Inherited members from FileEntry:
|
||||
int size - count for dirs
|
||||
@ -209,7 +209,7 @@ class Expression;
|
||||
class FileIndex
|
||||
{
|
||||
public:
|
||||
FileIndex(const std::string& pid);
|
||||
FileIndex(const RsPeerId& pid);
|
||||
~FileIndex();
|
||||
|
||||
/* control root entries */
|
||||
@ -230,12 +230,12 @@ class FileIndex
|
||||
int printFileIndex(std::ostream &out);
|
||||
|
||||
/* load/save to file */
|
||||
int loadIndex(const std::string& filename, const std::string& expectedHash, uint64_t size);
|
||||
int saveIndex(const std::string& filename, std::string &fileHash, uint64_t &size, const std::set<std::string>& forbidden_roots);
|
||||
int loadIndex(const std::string& filename, const RsFileHash &expectedHash, uint64_t size);
|
||||
int saveIndex(const std::string& filename, RsFileHash &fileHash, uint64_t &size, const std::set<std::string>& forbidden_roots);
|
||||
|
||||
/* search through this index */
|
||||
int searchTerms(const std::list<std::string>& terms, std::list<FileEntry *> &results) const;
|
||||
int searchHash(const std::string& hash, std::list<FileEntry *> &results) const;
|
||||
int searchHash(const RsFileHash& hash, std::list<FileEntry *> &results) const;
|
||||
int searchBoolExp(Expression * exp, std::list<FileEntry *> &results) const;
|
||||
|
||||
/// Recursively compute the maximum modification time of children.
|
||||
@ -262,7 +262,7 @@ class FileIndex
|
||||
void updateHashIndex() ;
|
||||
void recursUpdateHashIndex(DirEntry *) ;
|
||||
|
||||
std::map<std::string,FileEntry*> _file_hashes ;
|
||||
std::map<RsFileHash,FileEntry*> _file_hashes ;
|
||||
};
|
||||
|
||||
|
||||
|
@ -106,7 +106,7 @@ int FileIndexStore::loadCache(const RsCacheData &data)
|
||||
*
|
||||
* peername should not be used in dbase.
|
||||
*/
|
||||
finew->root->name = data.pid;
|
||||
finew->root->name = data.pid.toStdString();
|
||||
|
||||
if (local)
|
||||
{
|
||||
@ -168,7 +168,7 @@ int FileIndexStore::loadCache(const RsCacheData &data)
|
||||
|
||||
|
||||
/* Search Interface - For Directory Access */
|
||||
int FileIndexStore::RequestDirDetails(const std::string& uid, const std::string& path, DirDetails& details) const
|
||||
int FileIndexStore::RequestDirDetails(const RsPeerId& uid, const std::string& path, DirDetails& details) const
|
||||
{
|
||||
lockData();
|
||||
|
||||
@ -263,7 +263,7 @@ int FileIndexStore::RequestDirDetails(void *ref, DirDetails &details, FileSearch
|
||||
details.ref = NULL;
|
||||
details.type = DIR_TYPE_ROOT;
|
||||
details.name = "";
|
||||
details.hash = "";
|
||||
details.hash.clear() ;
|
||||
details.path = "";
|
||||
details.count = indices.size();
|
||||
details.age = 0;
|
||||
@ -288,7 +288,7 @@ uint32_t FileIndexStore::getType(void *ref) const
|
||||
return b;
|
||||
}
|
||||
|
||||
int FileIndexStore::SearchHash(std::string hash, std::list<FileDetail> &results) const
|
||||
int FileIndexStore::SearchHash(const RsFileHash& hash, std::list<FileDetail> &results) const
|
||||
{
|
||||
lockData();
|
||||
results.clear() ;
|
||||
@ -382,7 +382,7 @@ int FileIndexStore::SearchKeywords(std::list<std::string> keywords, std::list<Di
|
||||
if(!FileIndex::extractData(*rit, dd))
|
||||
continue ;
|
||||
|
||||
dd.id = "Local";
|
||||
dd.id.clear() ;
|
||||
results.push_back(dd);
|
||||
}
|
||||
|
||||
@ -431,7 +431,7 @@ int FileIndexStore::searchBoolExp(Expression * exp, std::list<DirDetails> &resul
|
||||
{
|
||||
DirDetails dd;
|
||||
FileIndex::extractData(*rit, dd);
|
||||
dd.id = "Local";
|
||||
dd.id.clear() ;
|
||||
results.push_back(dd);
|
||||
}
|
||||
|
||||
|
@ -73,7 +73,7 @@ virtual ~FileIndexStore();
|
||||
virtual int loadCache(const RsCacheData &data); /* actual load, once data available */
|
||||
|
||||
/* Search Interface - For FileTransfer Lookup */
|
||||
int SearchHash(std::string hash, std::list<FileDetail> &results) const;
|
||||
int SearchHash(const RsFileHash &hash, std::list<FileDetail> &results) const;
|
||||
|
||||
/* Search Interface - For Search Interface */
|
||||
int SearchKeywords(std::list<std::string> terms, std::list<DirDetails> &results,FileSearchFlags flags) const;
|
||||
@ -83,7 +83,7 @@ virtual int loadCache(const RsCacheData &data); /* actual load, once data avai
|
||||
|
||||
|
||||
/* Search Interface - For Directory Access */
|
||||
int RequestDirDetails(const std::string& uid, const std::string& path, DirDetails &details) const;
|
||||
int RequestDirDetails(const RsPeerId& uid, const std::string& path, DirDetails &details) const;
|
||||
int RequestDirDetails(void *ref, DirDetails &details, FileSearchFlags flags) const;
|
||||
uint32_t getType(void *ref) const ;
|
||||
|
||||
|
@ -98,7 +98,7 @@ bool ExtExpression::eval(FileEntry *file){
|
||||
}
|
||||
|
||||
bool HashExpression::eval(FileEntry *file){
|
||||
return evalStr(file->hash);
|
||||
return evalStr(file->hash.toStdString());
|
||||
}
|
||||
|
||||
/*Check whether two strings are 'equal' to each other*/
|
||||
@ -115,7 +115,7 @@ static bool StrEquals(const std::string & str1, const std::string & str2,
|
||||
}
|
||||
|
||||
/*Check whether one string contains the other*/
|
||||
static bool StrContains( std::string & str1, std::string & str2,
|
||||
static bool StrContains( const std::string & str1, const std::string & str2,
|
||||
bool IgnoreCase){
|
||||
|
||||
std::string::const_iterator iter ;
|
||||
@ -131,7 +131,7 @@ static bool StrContains( std::string & str1, std::string & str2,
|
||||
}
|
||||
|
||||
|
||||
bool StringExpression :: evalStr ( std::string &str ){
|
||||
bool StringExpression :: evalStr ( const std::string &str ){
|
||||
std::list<std::string>::iterator iter;
|
||||
switch (Op) {
|
||||
case ContainsAllStrings:
|
||||
|
@ -81,7 +81,7 @@ virtual int dhtInfoCallback(const bdId *id, uint32_t type, uint32_t flags, std::
|
||||
};
|
||||
|
||||
|
||||
p3BitDht::p3BitDht(std::string id, pqiConnectCb *cb, p3NetMgr *nm,
|
||||
p3BitDht::p3BitDht(const RsPeerId& id, pqiConnectCb *cb, p3NetMgr *nm,
|
||||
UdpStack *udpstack, std::string bootstrapfile)
|
||||
:p3Config(CONFIG_TYPE_BITDHT), pqiNetAssistConnect(id, cb), mNetMgr(nm), dhtMtx("p3BitDht")
|
||||
{
|
||||
@ -348,7 +348,7 @@ bool p3BitDht::dropPeer(std::string pid)
|
||||
|
||||
|
||||
/* extract current peer status */
|
||||
bool p3BitDht::getPeerStatus(std::string id,
|
||||
bool p3BitDht::getPeerStatus(const RsPeerId& id,
|
||||
struct sockaddr_storage &/*laddr*/, struct sockaddr_storage &/*raddr*/,
|
||||
uint32_t &/*type*/, uint32_t &/*mode*/)
|
||||
{
|
||||
|
@ -52,7 +52,7 @@ class DhtPeerDetails
|
||||
uint32_t mPeerType;
|
||||
|
||||
bdId mDhtId;
|
||||
std::string mRsId;
|
||||
RsPeerId mRsId;
|
||||
|
||||
/* direct from the DHT! */
|
||||
uint32_t mDhtState; // One of RSDHT_PEERDHT_[...]
|
||||
@ -142,7 +142,7 @@ class p3NetMgr;
|
||||
class p3BitDht: public p3Config, public pqiNetAssistConnect, public RsDht
|
||||
{
|
||||
public:
|
||||
p3BitDht(std::string id, pqiConnectCb *cb, p3NetMgr *nm,
|
||||
p3BitDht(const RsPeerId& id, pqiConnectCb *cb, p3NetMgr *nm,
|
||||
UdpStack *udpstack, std::string bootstrapfile);
|
||||
|
||||
|
||||
@ -155,8 +155,8 @@ virtual ~p3BitDht();
|
||||
|
||||
virtual uint32_t getNetState(uint32_t type);
|
||||
virtual int getDhtPeers(int lvl, std::list<RsDhtPeer> &peers);
|
||||
virtual int getNetPeerList(std::list<std::string> &peerIds);
|
||||
virtual int getNetPeerStatus(std::string peerId, RsDhtNetPeer &status);
|
||||
virtual int getNetPeerList(std::list<RsPeerId> &peerIds);
|
||||
virtual int getNetPeerStatus(const RsPeerId& peerId, RsDhtNetPeer &status);
|
||||
|
||||
virtual int getRelayEnds(std::list<RsDhtRelayEnd> &relayEnds);
|
||||
virtual int getRelayProxies(std::list<RsDhtRelayProxy> &relayProxies);
|
||||
@ -194,20 +194,20 @@ virtual bool getNetworkStats(uint32_t &netsize, uint32_t &localnetsize);
|
||||
/* pqiNetAssistConnect - external interface functions */
|
||||
|
||||
/* add / remove peers */
|
||||
virtual bool findPeer(std::string id);
|
||||
virtual bool dropPeer(std::string id);
|
||||
virtual bool findPeer(const RsPeerId& id);
|
||||
virtual bool dropPeer(const RsPeerId& id);
|
||||
|
||||
virtual int addBadPeer(const struct sockaddr_storage &addr, uint32_t reason, uint32_t flags, uint32_t age);
|
||||
virtual int addKnownPeer(const std::string &pid, const struct sockaddr_storage &addr, uint32_t flags);
|
||||
virtual int addKnownPeer(const RsPeerId &pid, const struct sockaddr_storage &addr, uint32_t flags);
|
||||
//virtual int addFriend(const std::string pid);
|
||||
//virtual int addFriendOfFriend(const std::string pid);
|
||||
//virtual int addOther(const std::string pid);
|
||||
|
||||
/* feedback on success failure of Connections */
|
||||
virtual void ConnectionFeedback(std::string pid, int state);
|
||||
virtual void ConnectionFeedback(const RsPeerId& pid, int state);
|
||||
|
||||
/* extract current peer status */
|
||||
virtual bool getPeerStatus(std::string id,
|
||||
virtual bool getPeerStatus(const RsPeerId& id,
|
||||
struct sockaddr_storage &laddr, struct sockaddr_storage &raddr,
|
||||
uint32_t &type, uint32_t &mode);
|
||||
|
||||
@ -255,18 +255,18 @@ int installRelayConnection(const bdId *srcId, const bdId *destId, uint32_t &ban
|
||||
int removeRelayConnection(const bdId *srcId, const bdId *destId);
|
||||
void monitorConnections();
|
||||
|
||||
void ConnectCallout(const std::string &peerId, struct sockaddr_in addr, uint32_t connectMode);
|
||||
void ConnectCallout(const RsPeerId &peerId, struct sockaddr_in addr, uint32_t connectMode);
|
||||
|
||||
void ConnectCalloutTCPAttempt(const std::string &peerId, struct sockaddr_in addr);
|
||||
void ConnectCalloutDirectOrProxy(const std::string &peerId, struct sockaddr_in raddr, uint32_t connectFlags, uint32_t delay);
|
||||
void ConnectCalloutRelay(const std::string &peerId, struct sockaddr_in srcaddr,
|
||||
void ConnectCalloutTCPAttempt(const RsPeerId &peerId, struct sockaddr_in addr);
|
||||
void ConnectCalloutDirectOrProxy(const RsPeerId &peerId, struct sockaddr_in raddr, uint32_t connectFlags, uint32_t delay);
|
||||
void ConnectCalloutRelay(const RsPeerId &peerId, struct sockaddr_in srcaddr,
|
||||
struct sockaddr_in proxyaddr, struct sockaddr_in destaddr,
|
||||
uint32_t connectMode, uint32_t bandwidth);
|
||||
|
||||
|
||||
void Feedback_Connected(std::string pid);
|
||||
void Feedback_ConnectionFailed(std::string pid);
|
||||
void Feedback_ConnectionClosed(std::string pid);
|
||||
void Feedback_Connected(const RsPeerId& pid);
|
||||
void Feedback_ConnectionFailed(const RsPeerId& pid);
|
||||
void Feedback_ConnectionClosed(const RsPeerId& pid);
|
||||
|
||||
void UdpConnectionFailed_locked(DhtPeerDetails *dpd);
|
||||
void ReleaseProxyExclusiveMode_locked(DhtPeerDetails *dpd, bool addrChgLikely);
|
||||
@ -337,24 +337,24 @@ int pushRelayServers();
|
||||
|
||||
public:
|
||||
|
||||
int removePeer(const std::string pid);
|
||||
int removePeer(const RsPeerId& pid);
|
||||
|
||||
// Can be used externally too.
|
||||
int calculateNodeId(const std::string pid, bdNodeId *id);
|
||||
int calculateNodeId(const RsPeerId& pid, bdNodeId *id);
|
||||
int addKnownNode(const bdId *id, uint32_t flags);
|
||||
|
||||
private:
|
||||
|
||||
DhtPeerDetails *addInternalPeer_locked(const std::string pid, uint32_t type);
|
||||
int removeInternalPeer_locked(const std::string pid);
|
||||
DhtPeerDetails *addInternalPeer_locked(const RsPeerId& pid, uint32_t type);
|
||||
int removeInternalPeer_locked(const RsPeerId& pid);
|
||||
DhtPeerDetails *findInternalDhtPeer_locked(const bdNodeId *id, uint32_t type);
|
||||
DhtPeerDetails *findInternalRsPeer_locked(const std::string &pid);
|
||||
DhtPeerDetails *findInternalRsPeer_locked(const RsPeerId &pid);
|
||||
|
||||
bool havePeerTranslation_locked(const std::string &pid);
|
||||
int lookupNodeId_locked(const std::string pid, bdNodeId *id);
|
||||
int lookupRsId_locked(const bdNodeId *id, std::string &pid);
|
||||
int storeTranslation_locked(const std::string pid);
|
||||
int removeTranslation_locked(const std::string pid);
|
||||
bool havePeerTranslation_locked(const RsPeerId &pid);
|
||||
int lookupNodeId_locked(const RsPeerId& pid, bdNodeId *id);
|
||||
int lookupRsId_locked(const bdNodeId *id, RsPeerId &pid);
|
||||
int storeTranslation_locked(const RsPeerId& pid);
|
||||
int removeTranslation_locked(const RsPeerId& pid);
|
||||
|
||||
UdpBitDht *mUdpBitDht; /* has own mutex, is static except for creation/destruction */
|
||||
UdpStunner *mDhtStunner;
|
||||
@ -372,14 +372,14 @@ int removeTranslation_locked(const std::string pid);
|
||||
|
||||
p3BitDhtRelayHandler *mRelayHandler;
|
||||
|
||||
std::string mOwnRsId;
|
||||
RsPeerId mOwnRsId;
|
||||
bdNodeId mOwnDhtId;
|
||||
|
||||
time_t mMinuteTS;
|
||||
|
||||
/* translation maps */
|
||||
std::map<std::string, bdNodeId> mTransToNodeId;
|
||||
std::map<bdNodeId, std::string> mTransToRsId;
|
||||
std::map<RsPeerId, bdNodeId> mTransToNodeId;
|
||||
std::map<bdNodeId, RsPeerId> mTransToRsId;
|
||||
|
||||
std::map<bdNodeId, DhtPeerDetails> mPeers;
|
||||
std::map<bdNodeId, DhtPeerDetails> mFailedPeers;
|
||||
|
@ -66,7 +66,7 @@ int p3BitDht::getDhtPeers(int lvl, std::list<RsDhtPeer> &peers)
|
||||
return (int_peers.entries.size() > 0);
|
||||
}
|
||||
|
||||
int p3BitDht::getNetPeerList(std::list<std::string> &peerIds)
|
||||
int p3BitDht::getNetPeerList(std::list<RsPeerId> &peerIds)
|
||||
{
|
||||
RsStackMutex stack(dhtMtx); /*********** LOCKED **********/
|
||||
std::map<bdNodeId, DhtPeerDetails>::iterator it;
|
||||
@ -78,7 +78,7 @@ int p3BitDht::getNetPeerList(std::list<std::string> &peerIds)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int p3BitDht::getNetPeerStatus(std::string peerId, RsDhtNetPeer &status)
|
||||
int p3BitDht::getNetPeerStatus(const RsPeerId& peerId, RsDhtNetPeer &status)
|
||||
{
|
||||
|
||||
RsStackMutex stack(dhtMtx); /*********** LOCKED **********/
|
||||
|
@ -48,7 +48,7 @@
|
||||
int p3BitDht::InfoCallback(const bdId *id, uint32_t /*type*/, uint32_t /*flags*/, std::string /*info*/)
|
||||
{
|
||||
/* translate info */
|
||||
std::string rsid;
|
||||
RsPeerId rsid;
|
||||
struct sockaddr_in addr = id->addr;
|
||||
int outtype = PNASS_TYPE_BADPEER;
|
||||
int outreason = PNASS_REASON_UNKNOWN;
|
||||
@ -143,7 +143,7 @@ int p3BitDht::NodeCallback(const bdId *id, uint32_t peerflags)
|
||||
bdStdPrintId(std::cerr, id);
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
mProxyStunner->addStunPeer(id->addr, "");
|
||||
//mProxyStunner->addStunPeer(id->addr, NULL);
|
||||
}
|
||||
/* else */ // removed else until we have lots of peers.
|
||||
|
||||
@ -154,7 +154,7 @@ int p3BitDht::NodeCallback(const bdId *id, uint32_t peerflags)
|
||||
bdStdPrintId(std::cerr, id);
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
mDhtStunner->addStunPeer(id->addr, "");
|
||||
//mDhtStunner->addStunPeer(id->addr, NULL);
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
@ -1569,7 +1569,7 @@ int p3BitDht::doActions()
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
std::string peerRsId;
|
||||
RsPeerId peerRsId;
|
||||
bool foundPeerId = false;
|
||||
{
|
||||
RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/
|
||||
@ -1774,7 +1774,7 @@ int p3BitDht::checkConnectionAllowed(const bdId *peerId, int mode)
|
||||
*/
|
||||
|
||||
|
||||
void p3BitDht::ConnectCalloutTCPAttempt(const std::string &peerId, struct sockaddr_in raddrv4)
|
||||
void p3BitDht::ConnectCalloutTCPAttempt(const RsPeerId &peerId, struct sockaddr_in raddrv4)
|
||||
{
|
||||
struct sockaddr_storage raddr;
|
||||
struct sockaddr_storage proxyaddr;
|
||||
@ -1802,7 +1802,7 @@ void p3BitDht::ConnectCalloutTCPAttempt(const std::string &peerId, struct sockad
|
||||
}
|
||||
|
||||
|
||||
void p3BitDht::ConnectCalloutDirectOrProxy(const std::string &peerId, struct sockaddr_in raddrv4, uint32_t connectFlags, uint32_t delay)
|
||||
void p3BitDht::ConnectCalloutDirectOrProxy(const RsPeerId &peerId, struct sockaddr_in raddrv4, uint32_t connectFlags, uint32_t delay)
|
||||
{
|
||||
struct sockaddr_storage raddr;
|
||||
struct sockaddr_storage proxyaddr;
|
||||
@ -1827,7 +1827,7 @@ void p3BitDht::ConnectCalloutDirectOrProxy(const std::string &peerId, struct soc
|
||||
mConnCb->peerConnectRequest(peerId, raddr, proxyaddr, srcaddr, source, connectFlags, delay, bandwidth);
|
||||
}
|
||||
|
||||
void p3BitDht::ConnectCalloutRelay(const std::string &peerId,
|
||||
void p3BitDht::ConnectCalloutRelay(const RsPeerId &peerId,
|
||||
struct sockaddr_in srcaddrv4, struct sockaddr_in proxyaddrv4, struct sockaddr_in destaddrv4,
|
||||
uint32_t connectFlags, uint32_t bandwidth)
|
||||
{
|
||||
@ -1944,7 +1944,7 @@ void p3BitDht::initiateConnection(const bdId *srcId, const bdId *proxyId, const
|
||||
#endif
|
||||
|
||||
// uint32_t touConnectMode = 0;
|
||||
std::string rsId;
|
||||
RsPeerId rsId;
|
||||
|
||||
{
|
||||
RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/
|
||||
@ -2054,10 +2054,10 @@ int p3BitDht::installRelayConnection(const bdId *srcId, const bdId *destId, uint
|
||||
int relayClass = UDP_RELAY_CLASS_GENERAL;
|
||||
|
||||
#ifdef DEBUG_PEERNET
|
||||
std::string strId1;
|
||||
RsPeerId strId1;
|
||||
bdStdPrintNodeId(strId1, &(srcId->id), false);
|
||||
|
||||
std::string strId2;
|
||||
RsPeerId strId2;
|
||||
bdStdPrintNodeId(strId2, &(destId->id), false);
|
||||
#endif
|
||||
|
||||
@ -2180,7 +2180,7 @@ void p3BitDht::monitorConnections()
|
||||
|
||||
|
||||
|
||||
void p3BitDht::Feedback_Connected(std::string pid)
|
||||
void p3BitDht::Feedback_Connected(const RsPeerId& pid)
|
||||
{
|
||||
RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/
|
||||
DhtPeerDetails *dpd = findInternalRsPeer_locked(pid);
|
||||
@ -2255,7 +2255,7 @@ void p3BitDht::Feedback_Connected(std::string pid)
|
||||
ReleaseProxyExclusiveMode_locked(dpd, true);
|
||||
}
|
||||
|
||||
void p3BitDht::Feedback_ConnectionFailed(std::string pid)
|
||||
void p3BitDht::Feedback_ConnectionFailed(const RsPeerId& pid)
|
||||
{
|
||||
RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/
|
||||
DhtPeerDetails *dpd = findInternalRsPeer_locked(pid);
|
||||
@ -2278,7 +2278,7 @@ void p3BitDht::Feedback_ConnectionFailed(std::string pid)
|
||||
return UdpConnectionFailed_locked(dpd);
|
||||
}
|
||||
|
||||
void p3BitDht::Feedback_ConnectionClosed(std::string pid)
|
||||
void p3BitDht::Feedback_ConnectionClosed(const RsPeerId& pid)
|
||||
{
|
||||
RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/
|
||||
DhtPeerDetails *dpd = findInternalRsPeer_locked(pid);
|
||||
@ -2419,7 +2419,7 @@ void p3BitDht::ReleaseProxyExclusiveMode_locked(DhtPeerDetails *dpd, bool addrCh
|
||||
}
|
||||
|
||||
|
||||
void p3BitDht::ConnectionFeedback(std::string pid, int mode)
|
||||
void p3BitDht::ConnectionFeedback(const RsPeerId& pid, int mode)
|
||||
{
|
||||
#ifdef DEBUG_PEERNET
|
||||
std::cerr << "p3BitDht::ConnectionFeedback() peer: " << pid;
|
||||
|
@ -54,7 +54,7 @@
|
||||
#define USE_OLD_DHT_INTERFACE 1
|
||||
|
||||
|
||||
bool p3BitDht::findPeer(std::string pid)
|
||||
bool p3BitDht::findPeer(const RsPeerId& pid)
|
||||
{
|
||||
#ifdef DEBUG_BITDHT
|
||||
std::cerr << "p3BitDht::findPeer(" << pid << ")";
|
||||
@ -133,7 +133,7 @@ bool p3BitDht::findPeer(std::string pid)
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool p3BitDht::dropPeer(std::string pid)
|
||||
bool p3BitDht::dropPeer(const RsPeerId& pid)
|
||||
{
|
||||
#ifdef DEBUG_BITDHT
|
||||
std::cerr << "p3BitDht::dropPeer(" << pid << ")";
|
||||
@ -216,7 +216,7 @@ int p3BitDht::addBadPeer(const struct sockaddr_storage &addr, uint32_t /*reason*
|
||||
}
|
||||
|
||||
|
||||
int p3BitDht::addKnownPeer(const std::string &pid, const struct sockaddr_storage &addr, uint32_t flags)
|
||||
int p3BitDht::addKnownPeer(const RsPeerId &pid, const struct sockaddr_storage &addr, uint32_t flags)
|
||||
{
|
||||
struct sockaddr_in addrv4;
|
||||
|
||||
@ -389,7 +389,7 @@ int p3BitDht::addOther(const std::string pid)
|
||||
#endif
|
||||
|
||||
|
||||
int p3BitDht::removePeer(const std::string pid)
|
||||
int p3BitDht::removePeer(const RsPeerId& pid)
|
||||
{
|
||||
RsStackMutex stack(dhtMtx); /********* LOCKED *********/
|
||||
|
||||
@ -401,7 +401,7 @@ int p3BitDht::removePeer(const std::string pid)
|
||||
********************************* Basic Peer Details *************************************
|
||||
******************************************************************************************/
|
||||
|
||||
DhtPeerDetails *p3BitDht::addInternalPeer_locked(const std::string pid, uint32_t type)
|
||||
DhtPeerDetails *p3BitDht::addInternalPeer_locked(const RsPeerId& pid, uint32_t type)
|
||||
{
|
||||
/* create the data structure */
|
||||
if (!havePeerTranslation_locked(pid))
|
||||
@ -435,7 +435,7 @@ DhtPeerDetails *p3BitDht::addInternalPeer_locked(const std::string pid, uint32_t
|
||||
}
|
||||
|
||||
|
||||
int p3BitDht::removeInternalPeer_locked(const std::string pid)
|
||||
int p3BitDht::removeInternalPeer_locked(const RsPeerId& pid)
|
||||
{
|
||||
bdNodeId id;
|
||||
if (!lookupNodeId_locked(pid, &id))
|
||||
@ -478,7 +478,7 @@ DhtPeerDetails *p3BitDht::findInternalDhtPeer_locked(const bdNodeId *id, uint32_
|
||||
|
||||
|
||||
/* interface to get with alt id */
|
||||
DhtPeerDetails *p3BitDht::findInternalRsPeer_locked(const std::string &pid)
|
||||
DhtPeerDetails *p3BitDht::findInternalRsPeer_locked(const RsPeerId &pid)
|
||||
{
|
||||
/* create the data structure */
|
||||
if (!havePeerTranslation_locked(pid))
|
||||
@ -502,14 +502,14 @@ DhtPeerDetails *p3BitDht::findInternalRsPeer_locked(const std::string &pid)
|
||||
*************************** Fundamental Node Translation *********************************
|
||||
******************************************************************************************/
|
||||
|
||||
bool p3BitDht::havePeerTranslation_locked(const std::string &pid)
|
||||
bool p3BitDht::havePeerTranslation_locked(const RsPeerId &pid)
|
||||
{
|
||||
#ifdef DEBUG_BITDHT_TRANSLATE
|
||||
std::cerr << "p3BitDht::havePeerTranslation_locked() for : " << pid;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
std::map<std::string, bdNodeId>::iterator it;
|
||||
std::map<RsPeerId, bdNodeId>::iterator it;
|
||||
it = mTransToNodeId.find(pid);
|
||||
if (it == mTransToNodeId.end())
|
||||
{
|
||||
@ -531,14 +531,14 @@ bool p3BitDht::havePeerTranslation_locked(const std::string &pid)
|
||||
}
|
||||
|
||||
|
||||
int p3BitDht::lookupNodeId_locked(const std::string pid, bdNodeId *id)
|
||||
int p3BitDht::lookupNodeId_locked(const RsPeerId& pid, bdNodeId *id)
|
||||
{
|
||||
#ifdef DEBUG_BITDHT_TRANSLATE
|
||||
std::cerr << "p3BitDht::lookupNodeId_locked() for : " << pid;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
std::map<std::string, bdNodeId>::iterator it;
|
||||
std::map<RsPeerId, bdNodeId>::iterator it;
|
||||
it = mTransToNodeId.find(pid);
|
||||
if (it == mTransToNodeId.end())
|
||||
{
|
||||
@ -562,7 +562,7 @@ int p3BitDht::lookupNodeId_locked(const std::string pid, bdNodeId *id)
|
||||
}
|
||||
|
||||
|
||||
int p3BitDht::lookupRsId_locked(const bdNodeId *id, std::string &pid)
|
||||
int p3BitDht::lookupRsId_locked(const bdNodeId *id, RsPeerId&pid)
|
||||
{
|
||||
#ifdef DEBUG_BITDHT_TRANSLATE
|
||||
std::cerr << "p3BitDht::lookupRsId_locked() for : ";
|
||||
@ -570,7 +570,7 @@ int p3BitDht::lookupRsId_locked(const bdNodeId *id, std::string &pid)
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
std::map<bdNodeId, std::string>::iterator nit;
|
||||
std::map<bdNodeId, RsPeerId>::iterator nit;
|
||||
nit = mTransToRsId.find(*id);
|
||||
if (nit == mTransToRsId.end())
|
||||
{
|
||||
@ -592,7 +592,7 @@ int p3BitDht::lookupRsId_locked(const bdNodeId *id, std::string &pid)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int p3BitDht::storeTranslation_locked(const std::string pid)
|
||||
int p3BitDht::storeTranslation_locked(const RsPeerId& pid)
|
||||
{
|
||||
#ifdef DEBUG_BITDHT_TRANSLATE
|
||||
std::cerr << "p3BitDht::storeTranslation_locked(" << pid << ")";
|
||||
@ -619,7 +619,7 @@ int p3BitDht::storeTranslation_locked(const std::string pid)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int p3BitDht::removeTranslation_locked(const std::string pid)
|
||||
int p3BitDht::removeTranslation_locked(const RsPeerId& pid)
|
||||
{
|
||||
|
||||
#ifdef DEBUG_BITDHT_TRANSLATE
|
||||
@ -627,7 +627,7 @@ int p3BitDht::removeTranslation_locked(const std::string pid)
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
std::map<std::string, bdNodeId>::iterator it = mTransToNodeId.find(pid);
|
||||
std::map<RsPeerId, bdNodeId>::iterator it = mTransToNodeId.find(pid);
|
||||
it = mTransToNodeId.find(pid);
|
||||
if (it == mTransToNodeId.end())
|
||||
{
|
||||
@ -646,7 +646,7 @@ int p3BitDht::removeTranslation_locked(const std::string pid)
|
||||
#endif
|
||||
|
||||
|
||||
std::map<bdNodeId, std::string>::iterator nit;
|
||||
std::map<bdNodeId, RsPeerId>::iterator nit;
|
||||
nit = mTransToRsId.find(nid);
|
||||
if (nit == mTransToRsId.end())
|
||||
{
|
||||
@ -676,7 +676,7 @@ const uint8_t RS_DHT_VERSION_LEN = 17;
|
||||
const uint8_t rs_dht_version_data[RS_DHT_VERSION_LEN] = "RS_VERSION_0.5.1";
|
||||
|
||||
/******************** Conversion Functions **************************/
|
||||
int p3BitDht::calculateNodeId(const std::string pid, bdNodeId *id)
|
||||
int p3BitDht::calculateNodeId(const RsPeerId& pid, bdNodeId *id)
|
||||
{
|
||||
/* generate node id from pid */
|
||||
#ifdef DEBUG_BITDHT_TRANSLATE
|
||||
@ -691,7 +691,7 @@ int p3BitDht::calculateNodeId(const std::string pid, bdNodeId *id)
|
||||
SHA1_Init(sha_ctx);
|
||||
|
||||
SHA1_Update(sha_ctx, rs_dht_version_data, RS_DHT_VERSION_LEN);
|
||||
SHA1_Update(sha_ctx, pid.c_str(), pid.length());
|
||||
SHA1_Update(sha_ctx, pid.toByteArray(), RsPeerId::SIZE_IN_BYTES);
|
||||
SHA1_Final(sha_hash, sha_ctx);
|
||||
|
||||
for(int i = 0; i < SHA_DIGEST_LENGTH && (i < BITDHT_KEY_LEN); i++)
|
||||
|
@ -267,15 +267,15 @@ void ChunkMap::setChunkCheckingResult(uint32_t chunk_number,bool check_succeeded
|
||||
// - chunks pushed when new chunks are needed
|
||||
// - chunks removed when completely downloaded
|
||||
//
|
||||
bool ChunkMap::getDataChunk(const std::string& peer_id,uint32_t size_hint,ftChunk& chunk,bool& source_chunk_map_needed)
|
||||
bool ChunkMap::getDataChunk(const RsPeerId& peer_id,uint32_t size_hint,ftChunk& chunk,bool& source_chunk_map_needed)
|
||||
{
|
||||
#ifdef DEBUG_FTCHUNK
|
||||
std::cerr << "*** ChunkMap::getDataChunk: size_hint = " << size_hint << std::endl ;
|
||||
#endif
|
||||
// 1 - find if this peer already has an active chunk.
|
||||
//
|
||||
std::map<std::string,Chunk>::iterator it = _active_chunks_feed.find(peer_id) ;
|
||||
std::map<std::string,Chunk>::iterator falsafe_it = _active_chunks_feed.end() ;
|
||||
std::map<RsPeerId,Chunk>::iterator it = _active_chunks_feed.find(peer_id) ;
|
||||
std::map<RsPeerId,Chunk>::iterator falsafe_it = _active_chunks_feed.end() ;
|
||||
|
||||
if(it == _active_chunks_feed.end())
|
||||
{
|
||||
@ -284,7 +284,7 @@ bool ChunkMap::getDataChunk(const std::string& peer_id,uint32_t size_hint,ftChun
|
||||
// 0 - Look into other pending chunks and slice from here. We only consider chunks with size smaller than
|
||||
// the requested size,
|
||||
//
|
||||
for(std::map<std::string,Chunk>::iterator pit(_active_chunks_feed.begin());pit!=_active_chunks_feed.end();++pit)
|
||||
for(std::map<RsPeerId,Chunk>::iterator pit(_active_chunks_feed.begin());pit!=_active_chunks_feed.end();++pit)
|
||||
{
|
||||
uint32_t c = pit->second._start / _chunk_size ;
|
||||
|
||||
@ -385,10 +385,10 @@ void ChunkMap::removeInactiveChunks(std::vector<ftChunk::ChunkId>& to_remove)
|
||||
|
||||
// Also remove the chunk from the chunk feed, to free the associated peer.
|
||||
//
|
||||
for(std::map<std::string,Chunk>::iterator it3=_active_chunks_feed.begin();it3!=_active_chunks_feed.end();)
|
||||
for(std::map<RsPeerId,Chunk>::iterator it3=_active_chunks_feed.begin();it3!=_active_chunks_feed.end();)
|
||||
if(it3->second._start == _chunk_size*uint64_t(it->first))
|
||||
{
|
||||
std::map<std::string,Chunk>::iterator tmp3 = it3 ;
|
||||
std::map<RsPeerId,Chunk>::iterator tmp3 = it3 ;
|
||||
++it3 ;
|
||||
_active_chunks_feed.erase(tmp3) ;
|
||||
}
|
||||
@ -428,7 +428,7 @@ bool ChunkMap::isChunkAvailable(uint64_t offset, uint32_t chunk_size) const
|
||||
return true ;
|
||||
}
|
||||
|
||||
void ChunkMap::setPeerAvailabilityMap(const std::string& peer_id,const CompressedChunkMap& cmap)
|
||||
void ChunkMap::setPeerAvailabilityMap(const RsPeerId& peer_id,const CompressedChunkMap& cmap)
|
||||
{
|
||||
#ifdef DEBUG_FTCHUNK
|
||||
std::cout << "ChunkMap::Receiving new availability map for peer " << peer_id << std::endl ;
|
||||
@ -469,9 +469,9 @@ uint32_t ChunkMap::sizeOfChunk(uint32_t cid) const
|
||||
return _chunk_size ;
|
||||
}
|
||||
|
||||
SourceChunksInfo *ChunkMap::getSourceChunksInfo(const std::string& peer_id)
|
||||
SourceChunksInfo *ChunkMap::getSourceChunksInfo(const RsPeerId& peer_id)
|
||||
{
|
||||
std::map<std::string,SourceChunksInfo>::iterator it(_peers_chunks_availability.find(peer_id)) ;
|
||||
std::map<RsPeerId,SourceChunksInfo>::iterator it(_peers_chunks_availability.find(peer_id)) ;
|
||||
|
||||
// Do we have a chunk map for this file source ?
|
||||
// - if yes, we use it
|
||||
@ -508,16 +508,16 @@ SourceChunksInfo *ChunkMap::getSourceChunksInfo(const std::string& peer_id)
|
||||
return &(it->second) ;
|
||||
}
|
||||
|
||||
void ChunkMap::getSourcesList(uint32_t chunk_number,std::vector<std::string>& sources)
|
||||
void ChunkMap::getSourcesList(uint32_t chunk_number,std::vector<RsPeerId>& sources)
|
||||
{
|
||||
sources.clear() ;
|
||||
|
||||
for(std::map<std::string,SourceChunksInfo>::const_iterator it(_peers_chunks_availability.begin());it!=_peers_chunks_availability.end();++it)
|
||||
for(std::map<RsPeerId,SourceChunksInfo>::const_iterator it(_peers_chunks_availability.begin());it!=_peers_chunks_availability.end();++it)
|
||||
if(it->second.cmap[chunk_number])
|
||||
sources.push_back(it->first) ;
|
||||
}
|
||||
|
||||
uint32_t ChunkMap::getAvailableChunk(const std::string& peer_id,bool& map_is_too_old)
|
||||
uint32_t ChunkMap::getAvailableChunk(const RsPeerId& peer_id,bool& map_is_too_old)
|
||||
{
|
||||
// Quite simple strategy: Check for 1st availabe chunk for this peer starting from the given start location.
|
||||
//
|
||||
@ -601,13 +601,13 @@ void ChunkMap::getChunksInfo(FileChunksInfo& info) const
|
||||
|
||||
info.compressed_peer_availability_maps.clear() ;
|
||||
|
||||
for(std::map<std::string,SourceChunksInfo>::const_iterator it(_peers_chunks_availability.begin());it!=_peers_chunks_availability.end();++it)
|
||||
for(std::map<RsPeerId,SourceChunksInfo>::const_iterator it(_peers_chunks_availability.begin());it!=_peers_chunks_availability.end();++it)
|
||||
info.compressed_peer_availability_maps[it->first] = it->second.cmap ;
|
||||
}
|
||||
|
||||
void ChunkMap::removeFileSource(const std::string& peer_id)
|
||||
void ChunkMap::removeFileSource(const RsPeerId& peer_id)
|
||||
{
|
||||
std::map<std::string,SourceChunksInfo>::iterator it(_peers_chunks_availability.find(peer_id)) ;
|
||||
std::map<RsPeerId,SourceChunksInfo>::iterator it(_peers_chunks_availability.find(peer_id)) ;
|
||||
|
||||
if(it == _peers_chunks_availability.end())
|
||||
return ;
|
||||
|
@ -43,7 +43,7 @@ class ftChunk
|
||||
ChunkId id ; // id of the chunk. Equal to the starting offset of the chunk
|
||||
time_t ts; // time of last data received
|
||||
int *ref_cnt; // shared counter of number of sub-blocks. Used when a slice gets split.
|
||||
std::string peer_id ;
|
||||
RsPeerId peer_id ;
|
||||
};
|
||||
|
||||
// This class handles a single fixed-sized chunk. Although each chunk is requested at once,
|
||||
@ -118,7 +118,7 @@ class ChunkMap
|
||||
/// On return:
|
||||
/// - source_chunk_map_needed = true if the source map should be asked
|
||||
|
||||
virtual bool getDataChunk(const std::string& peer_id,uint32_t size_hint,ftChunk& chunk,bool& source_chunk_map_needed) ;
|
||||
virtual bool getDataChunk(const RsPeerId& peer_id,uint32_t size_hint,ftChunk& chunk,bool& source_chunk_map_needed) ;
|
||||
|
||||
/// Notify received a slice of data. This needs to
|
||||
/// - carve in the map of chunks what is received, what is not.
|
||||
@ -145,7 +145,7 @@ class ChunkMap
|
||||
void setAvailabilityMap(const CompressedChunkMap& cmap) ;
|
||||
|
||||
/// Removes the source availability map. The map
|
||||
void removeFileSource(const std::string& peer_id) ;
|
||||
void removeFileSource(const RsPeerId& peer_id) ;
|
||||
|
||||
/// This function fills in a plain map for a file of the given size. This
|
||||
/// is used to ensure that the chunk size will be consistent with the rest
|
||||
@ -165,12 +165,12 @@ class ChunkMap
|
||||
|
||||
/// Updates the peer's availablility map
|
||||
//
|
||||
void setPeerAvailabilityMap(const std::string& peer_id,const CompressedChunkMap& peer_map) ;
|
||||
void setPeerAvailabilityMap(const RsPeerId& peer_id,const CompressedChunkMap& peer_map) ;
|
||||
|
||||
/// Returns a pointer to the availability chunk map of the given source, and possibly
|
||||
/// allocates it if necessary.
|
||||
//
|
||||
SourceChunksInfo *getSourceChunksInfo(const std::string& peer_id) ;
|
||||
SourceChunksInfo *getSourceChunksInfo(const RsPeerId& peer_id) ;
|
||||
|
||||
/// Returns the total size of downloaded data in the file.
|
||||
uint64_t getTotalReceived() const { return _total_downloaded ; }
|
||||
@ -188,7 +188,7 @@ class ChunkMap
|
||||
void getChunksToCheck(std::vector<uint32_t>& chunks_to_ask) ;
|
||||
|
||||
/// Get all available sources for this chunk
|
||||
void getSourcesList(uint32_t chunk_number,std::vector<std::string>& sources) ;
|
||||
void getSourcesList(uint32_t chunk_number,std::vector<RsPeerId>& sources) ;
|
||||
|
||||
/// sets all chunks to checking state
|
||||
void forceCheck() ;
|
||||
@ -203,16 +203,16 @@ class ChunkMap
|
||||
|
||||
/// Returns a chunk available for this peer_id, depending on the chunk strategy.
|
||||
//
|
||||
uint32_t getAvailableChunk(const std::string& peer_id,bool& chunk_map_too_old) ;
|
||||
uint32_t getAvailableChunk(const RsPeerId& peer_id,bool& chunk_map_too_old) ;
|
||||
|
||||
private:
|
||||
uint64_t _file_size ; //! total size of the file in bytes.
|
||||
uint32_t _chunk_size ; //! Size of chunks. Common to all chunks.
|
||||
FileChunksInfo::ChunkStrategy _strategy ; //! how do we allocate new chunks
|
||||
std::map<std::string,Chunk> _active_chunks_feed ; //! vector of chunks being downloaded. Exactly 1 chunk per peer.
|
||||
std::map<RsPeerId,Chunk> _active_chunks_feed ; //! vector of chunks being downloaded. Exactly 1 chunk per peer.
|
||||
std::map<ChunkNumber,ChunkDownloadInfo> _slices_to_download ; //! list of (slice id,slice size)
|
||||
std::vector<FileChunksInfo::ChunkState> _map ; //! vector of chunk state over the whole file
|
||||
std::map<std::string,SourceChunksInfo> _peers_chunks_availability ; //! what does each source peer have
|
||||
std::map<RsPeerId,SourceChunksInfo> _peers_chunks_availability ; //! what does each source peer have
|
||||
uint64_t _total_downloaded ; //! completion for the file
|
||||
bool _file_is_complete ; //! set to true when the file is complete.
|
||||
bool _assume_availability ; //! true if all sources always have the complete file.
|
||||
|
@ -89,7 +89,7 @@ ftFileControl::ftFileControl()
|
||||
|
||||
ftFileControl::ftFileControl(std::string fname,
|
||||
std::string tmppath, std::string dest,
|
||||
uint64_t size, std::string hash, TransferRequestFlags flags,
|
||||
uint64_t size, const RsFileHash &hash, TransferRequestFlags flags,
|
||||
ftFileCreator *fc, ftTransferModule *tm)
|
||||
:mName(fname), mCurrentPath(tmppath), mDestination(dest),
|
||||
mTransfer(tm), mCreator(fc), mState(DOWNLOADING), mHash(hash),
|
||||
@ -124,11 +124,11 @@ void ftController::setFtSearchNExtra(ftSearch *search, ftExtraList *list)
|
||||
mExtraList = list;
|
||||
}
|
||||
|
||||
bool ftController::getFileDownloadChunksDetails(const std::string& hash,FileChunksInfo& info)
|
||||
bool ftController::getFileDownloadChunksDetails(const RsFileHash& hash,FileChunksInfo& info)
|
||||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
|
||||
std::map<std::string, ftFileControl*>::iterator it = mDownloads.find(hash) ;
|
||||
std::map<RsFileHash, ftFileControl*>::iterator it = mDownloads.find(hash) ;
|
||||
|
||||
if(it != mDownloads.end())
|
||||
{
|
||||
@ -161,11 +161,11 @@ bool ftController::getFileDownloadChunksDetails(const std::string& hash,FileChun
|
||||
return false ;
|
||||
}
|
||||
|
||||
void ftController::addFileSource(const std::string& hash,const std::string& peer_id)
|
||||
void ftController::addFileSource(const RsFileHash& hash,const RsPeerId& peer_id)
|
||||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
|
||||
std::map<std::string, ftFileControl*>::iterator it = mDownloads.find(hash);
|
||||
std::map<RsFileHash, ftFileControl*>::iterator it = mDownloads.find(hash);
|
||||
|
||||
//#ifdef CONTROL_DEBUG
|
||||
std::cerr << "ftController: Adding source " << peer_id << " to current download hash=" << hash ;
|
||||
@ -184,11 +184,11 @@ void ftController::addFileSource(const std::string& hash,const std::string& peer
|
||||
std::cerr << "... not added: hash not found." << std::endl ;
|
||||
#endif
|
||||
}
|
||||
void ftController::removeFileSource(const std::string& hash,const std::string& peer_id)
|
||||
void ftController::removeFileSource(const RsFileHash& hash,const RsPeerId& peer_id)
|
||||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
|
||||
std::map<std::string, ftFileControl*>::iterator it = mDownloads.find(hash);
|
||||
std::map<RsFileHash, ftFileControl*>::iterator it = mDownloads.find(hash);
|
||||
|
||||
#ifdef CONTROL_DEBUG
|
||||
std::cerr << "ftController: Adding source " << peer_id << " to current download hash=" << hash ;
|
||||
@ -245,7 +245,7 @@ void ftController::run()
|
||||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
|
||||
for(std::map<std::string,ftFileControl*>::iterator it(mDownloads.begin());it!=mDownloads.end();++it)
|
||||
for(std::map<RsFileHash,ftFileControl*>::iterator it(mDownloads.begin());it!=mDownloads.end();++it)
|
||||
it->second->mCreator->removeInactiveChunks() ;
|
||||
|
||||
last_clean_time = now ;
|
||||
@ -263,7 +263,7 @@ void ftController::run()
|
||||
tickTransfers() ;
|
||||
|
||||
{
|
||||
std::list<std::string> files_to_complete ;
|
||||
std::list<RsFileHash> files_to_complete ;
|
||||
|
||||
{
|
||||
RsStackMutex stack2(doneMutex);
|
||||
@ -271,7 +271,7 @@ void ftController::run()
|
||||
mDone.clear();
|
||||
}
|
||||
|
||||
for(std::list<std::string>::iterator it(files_to_complete.begin()); it != files_to_complete.end(); ++it)
|
||||
for(std::list<RsFileHash>::iterator it(files_to_complete.begin()); it != files_to_complete.end(); ++it)
|
||||
completeFile(*it);
|
||||
}
|
||||
|
||||
@ -285,7 +285,7 @@ void ftController::searchForDirectSources()
|
||||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
|
||||
for(std::map<std::string,ftFileControl*>::iterator it(mDownloads.begin()); it != mDownloads.end(); it++)
|
||||
for(std::map<RsFileHash,ftFileControl*>::iterator it(mDownloads.begin()); it != mDownloads.end(); it++)
|
||||
if(it->second->mState != ftFileControl::QUEUED && it->second->mState != ftFileControl::PAUSED)
|
||||
if(! (it->second->mFlags & RS_FILE_REQ_CACHE))
|
||||
{
|
||||
@ -293,7 +293,7 @@ void ftController::searchForDirectSources()
|
||||
|
||||
if(mSearch->search(it->first, RS_FILE_HINTS_REMOTE | RS_FILE_HINTS_SPEC_ONLY, info))
|
||||
for(std::list<TransferInfo>::const_iterator pit = info.peers.begin(); pit != info.peers.end(); pit++)
|
||||
if(rsPeers->servicePermissionFlags_sslid(pit->peerId) & RS_SERVICE_PERM_DIRECT_DL)
|
||||
if(rsPeers->servicePermissionFlags(pit->peerId) & RS_SERVICE_PERM_DIRECT_DL)
|
||||
if(it->second->mTransfer->addFileSource(pit->peerId)) /* if the sources don't exist already - add in */
|
||||
setPeerState(it->second->mTransfer, pit->peerId, FT_CNTRL_STANDARD_RATE, mLinkMgr->isOnline( pit->peerId ));
|
||||
}
|
||||
@ -310,16 +310,16 @@ void ftController::tickTransfers()
|
||||
#endif
|
||||
// Collect all non queued files.
|
||||
//
|
||||
for(std::map<std::string,ftFileControl*>::iterator it(mDownloads.begin()); it != mDownloads.end(); it++)
|
||||
for(std::map<RsFileHash,ftFileControl*>::iterator it(mDownloads.begin()); it != mDownloads.end(); it++)
|
||||
if(it->second->mState != ftFileControl::QUEUED && it->second->mState != ftFileControl::PAUSED)
|
||||
it->second->mTransfer->tick() ;
|
||||
}
|
||||
|
||||
bool ftController::getPriority(const std::string& hash,DwlSpeed& p)
|
||||
bool ftController::getPriority(const RsFileHash& hash,DwlSpeed& p)
|
||||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
|
||||
std::map<std::string,ftFileControl*>::iterator it(mDownloads.find(hash)) ;
|
||||
std::map<RsFileHash,ftFileControl*>::iterator it(mDownloads.find(hash)) ;
|
||||
|
||||
if(it != mDownloads.end())
|
||||
{
|
||||
@ -330,11 +330,11 @@ bool ftController::getPriority(const std::string& hash,DwlSpeed& p)
|
||||
return false ;
|
||||
}
|
||||
|
||||
void ftController::setPriority(const std::string& hash,DwlSpeed p)
|
||||
void ftController::setPriority(const RsFileHash& hash,DwlSpeed p)
|
||||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
|
||||
std::map<std::string,ftFileControl*>::iterator it(mDownloads.find(hash)) ;
|
||||
std::map<RsFileHash,ftFileControl*>::iterator it(mDownloads.find(hash)) ;
|
||||
|
||||
if(it != mDownloads.end())
|
||||
it->second->mTransfer->setDownloadPriority(p) ;
|
||||
@ -342,13 +342,13 @@ void ftController::setPriority(const std::string& hash,DwlSpeed p)
|
||||
|
||||
void ftController::cleanCacheDownloads()
|
||||
{
|
||||
std::vector<std::string> toCancel ;
|
||||
std::vector<RsFileHash> toCancel ;
|
||||
time_t now = time(NULL) ;
|
||||
|
||||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
|
||||
for(std::map<std::string,ftFileControl*>::iterator it(mDownloads.begin());it!=mDownloads.end();++it)
|
||||
for(std::map<RsFileHash,ftFileControl*>::iterator it(mDownloads.begin());it!=mDownloads.end();++it)
|
||||
if (((it->second)->mFlags & RS_FILE_REQ_CACHE) && it->second->mState != ftFileControl::DOWNLOADING)
|
||||
// check if a cache file is downloaded, if the case, timeout the transfer after TIMOUT_CACHE_FILE_TRANSFER
|
||||
{
|
||||
@ -423,7 +423,7 @@ void ftController::checkDownloadQueue()
|
||||
time_t now = time(NULL) ;
|
||||
uint32_t nb_moved = 0 ; // don't move more files than the size of the queue.
|
||||
|
||||
for(std::map<std::string,ftFileControl*>::const_iterator it(mDownloads.begin());it!=mDownloads.end() && nb_moved <= _max_active_downloads;++it)
|
||||
for(std::map<RsFileHash,ftFileControl*>::const_iterator it(mDownloads.begin());it!=mDownloads.end() && nb_moved <= _max_active_downloads;++it)
|
||||
if( it->second->mState != ftFileControl::QUEUED
|
||||
&& (it->second->mState == ftFileControl::PAUSED
|
||||
|| now > it->second->mTransfer->lastActvTimeStamp() + (time_t)MAX_TIME_INACTIVE_REQUEUED))
|
||||
@ -557,11 +557,11 @@ uint32_t ftController::getQueueSize()
|
||||
return _max_active_downloads ;
|
||||
}
|
||||
|
||||
void ftController::moveInQueue(const std::string& hash,QueueMove mv)
|
||||
void ftController::moveInQueue(const RsFileHash& hash,QueueMove mv)
|
||||
{
|
||||
RsStackMutex mtx(ctrlMutex) ;
|
||||
|
||||
std::map<std::string,ftFileControl*>::iterator it(mDownloads.find(hash)) ;
|
||||
std::map<RsFileHash,ftFileControl*>::iterator it(mDownloads.find(hash)) ;
|
||||
|
||||
if(it == mDownloads.end())
|
||||
{
|
||||
@ -658,7 +658,7 @@ void ftController::locked_checkQueueElement(uint32_t pos)
|
||||
}
|
||||
}
|
||||
|
||||
bool ftController::FlagFileComplete(std::string hash)
|
||||
bool ftController::FlagFileComplete(const RsFileHash& hash)
|
||||
{
|
||||
RsStackMutex stack2(doneMutex);
|
||||
mDone.push_back(hash);
|
||||
@ -780,7 +780,7 @@ bool ftController::copyFile(const std::string& source,const std::string& dest)
|
||||
|
||||
|
||||
|
||||
bool ftController::completeFile(std::string hash)
|
||||
bool ftController::completeFile(const RsFileHash& hash)
|
||||
{
|
||||
/* variables... so we can drop mutex later */
|
||||
std::string path;
|
||||
@ -799,7 +799,7 @@ bool ftController::completeFile(std::string hash)
|
||||
std::cerr << "ftController:completeFile(" << hash << ")";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
std::map<std::string, ftFileControl*>::iterator it(mDownloads.find(hash));
|
||||
std::map<RsFileHash, ftFileControl*>::iterator it(mDownloads.find(hash));
|
||||
|
||||
if (it == mDownloads.end())
|
||||
{
|
||||
@ -840,7 +840,7 @@ bool ftController::completeFile(std::string hash)
|
||||
/* done - cleanup */
|
||||
|
||||
// (csoler) I'm copying this because "delete fc->mTransfer" deletes the hash string!
|
||||
std::string hash_to_suppress(fc->mTransfer->hash());
|
||||
RsFileHash hash_to_suppress(fc->mTransfer->hash());
|
||||
|
||||
// This should be done that early, because once the file creator is
|
||||
// deleted, it should not be accessed by the data multiplex anymore!
|
||||
@ -965,9 +965,9 @@ bool ftController::completeFile(std::string hash)
|
||||
|
||||
/* Notify GUI */
|
||||
if ((flags & RS_FILE_REQ_CACHE) == 0) {
|
||||
RsServer::notify()->AddPopupMessage(RS_POPUP_DOWNLOAD, hash, name, "");
|
||||
RsServer::notify()->AddPopupMessage(RS_POPUP_DOWNLOAD, hash.toStdString(), name, "");
|
||||
|
||||
RsServer::notify()->notifyDownloadComplete(hash);
|
||||
RsServer::notify()->notifyDownloadComplete(hash.toStdString());
|
||||
RsServer::notify()->notifyDownloadCompleteCount(completeCount);
|
||||
|
||||
rsFiles->ForceDirectoryCheck() ;
|
||||
@ -1019,12 +1019,12 @@ bool ftController::handleAPendingRequest()
|
||||
//
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
|
||||
std::map<std::string,RsFileTransfer*>::iterator it(mPendingChunkMaps.find(req.mHash)) ;
|
||||
std::map<RsFileHash,RsFileTransfer*>::iterator it(mPendingChunkMaps.find(req.mHash)) ;
|
||||
|
||||
if(it != mPendingChunkMaps.end())
|
||||
{
|
||||
RsFileTransfer *rsft = it->second ;
|
||||
std::map<std::string, ftFileControl*>::iterator fit = mDownloads.find(rsft->file.hash);
|
||||
std::map<RsFileHash, ftFileControl*>::iterator fit = mDownloads.find(rsft->file.hash);
|
||||
|
||||
if((fit==mDownloads.end() || (fit->second)->mCreator == NULL))
|
||||
{
|
||||
@ -1055,7 +1055,7 @@ bool ftController::handleAPendingRequest()
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool ftController::alreadyHaveFile(const std::string& hash, FileInfo &info)
|
||||
bool ftController::alreadyHaveFile(const RsFileHash& hash, FileInfo &info)
|
||||
{
|
||||
// check for downloads
|
||||
if (FileDetails(hash, info) && (info.downloadStatus == FT_STATE_COMPLETE))
|
||||
@ -1068,11 +1068,11 @@ bool ftController::alreadyHaveFile(const std::string& hash, FileInfo &info)
|
||||
return false ;
|
||||
}
|
||||
|
||||
bool ftController::FileRequest(const std::string& fname, const std::string& hash,
|
||||
bool ftController::FileRequest(const std::string& fname, const RsFileHash& hash,
|
||||
uint64_t size, const std::string& dest, TransferRequestFlags flags,
|
||||
const std::list<std::string> &_srcIds, uint16_t state)
|
||||
const std::list<RsPeerId> &_srcIds, uint16_t state)
|
||||
{
|
||||
std::list<std::string> srcIds(_srcIds) ;
|
||||
std::list<RsPeerId> srcIds(_srcIds) ;
|
||||
|
||||
/* check if we have the file */
|
||||
|
||||
@ -1134,10 +1134,10 @@ bool ftController::FileRequest(const std::string& fname, const std::string& has
|
||||
// remove the sources from the list, if they don't have clearance for direct transfer. This happens only for non cache files.
|
||||
//
|
||||
if(!(flags & RS_FILE_REQ_CACHE))
|
||||
for(std::list<std::string>::iterator it = srcIds.begin(); it != srcIds.end(); )
|
||||
if(!(rsPeers->servicePermissionFlags_sslid(*it) & RS_SERVICE_PERM_DIRECT_DL))
|
||||
for(std::list<RsPeerId>::iterator it = srcIds.begin(); it != srcIds.end(); )
|
||||
if(!(rsPeers->servicePermissionFlags(*it) & RS_SERVICE_PERM_DIRECT_DL))
|
||||
{
|
||||
std::list<std::string>::iterator tmp(it) ;
|
||||
std::list<RsPeerId>::iterator tmp(it) ;
|
||||
++tmp ;
|
||||
srcIds.erase(it) ;
|
||||
it = tmp ;
|
||||
@ -1145,7 +1145,7 @@ bool ftController::FileRequest(const std::string& fname, const std::string& has
|
||||
else
|
||||
++it ;
|
||||
|
||||
std::list<std::string>::const_iterator it;
|
||||
std::list<RsPeerId>::const_iterator it;
|
||||
std::list<TransferInfo>::const_iterator pit;
|
||||
|
||||
#ifdef CONTROL_DEBUG
|
||||
@ -1174,7 +1174,7 @@ bool ftController::FileRequest(const std::string& fname, const std::string& has
|
||||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
|
||||
std::map<std::string, ftFileControl*>::const_iterator dit = mDownloads.find(hash);
|
||||
std::map<RsFileHash, ftFileControl*>::const_iterator dit = mDownloads.find(hash);
|
||||
|
||||
if (dit != mDownloads.end())
|
||||
{
|
||||
@ -1191,7 +1191,7 @@ bool ftController::FileRequest(const std::string& fname, const std::string& has
|
||||
*/
|
||||
|
||||
for(it = srcIds.begin(); it != srcIds.end(); it++)
|
||||
if(rsPeers->servicePermissionFlags_sslid(*it) & RS_SERVICE_PERM_DIRECT_DL)
|
||||
if(rsPeers->servicePermissionFlags(*it) & RS_SERVICE_PERM_DIRECT_DL)
|
||||
{
|
||||
uint32_t i, j;
|
||||
if ((dit->second)->mTransfer->getPeerState(*it, i, j))
|
||||
@ -1248,7 +1248,7 @@ bool ftController::FileRequest(const std::string& fname, const std::string& has
|
||||
#endif
|
||||
// Because this is auto-add, we only add sources that we allow to DL from using direct transfers.
|
||||
|
||||
if ((srcIds.end() == std::find( srcIds.begin(), srcIds.end(), pit->peerId)) && (RS_SERVICE_PERM_DIRECT_DL & rsPeers->servicePermissionFlags_sslid(pit->peerId)))
|
||||
if ((srcIds.end() == std::find( srcIds.begin(), srcIds.end(), pit->peerId)) && (RS_SERVICE_PERM_DIRECT_DL & rsPeers->servicePermissionFlags(pit->peerId)))
|
||||
{
|
||||
srcIds.push_back(pit->peerId);
|
||||
|
||||
@ -1268,7 +1268,7 @@ bool ftController::FileRequest(const std::string& fname, const std::string& has
|
||||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
|
||||
savepath = mPartialsPath + "/" + hash;
|
||||
savepath = mPartialsPath + "/" + hash.toStdString();
|
||||
destination = dest + "/" + fname;
|
||||
|
||||
/* if no destpath - send to download directory */
|
||||
@ -1331,7 +1331,7 @@ bool ftController::FileRequest(const std::string& fname, const std::string& has
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ftController::setPeerState(ftTransferModule *tm, std::string id, uint32_t maxrate, bool online)
|
||||
bool ftController::setPeerState(ftTransferModule *tm, const RsPeerId& id, uint32_t maxrate, bool online)
|
||||
{
|
||||
if (id == mLinkMgr->getOwnId())
|
||||
{
|
||||
@ -1363,9 +1363,9 @@ bool ftController::setPeerState(ftTransferModule *tm, std::string id, uint32_t
|
||||
}
|
||||
|
||||
|
||||
bool ftController::setChunkStrategy(const std::string& hash,FileChunksInfo::ChunkStrategy s)
|
||||
bool ftController::setChunkStrategy(const RsFileHash& hash,FileChunksInfo::ChunkStrategy s)
|
||||
{
|
||||
std::map<std::string,ftFileControl*>::iterator mit=mDownloads.find(hash);
|
||||
std::map<RsFileHash,ftFileControl*>::iterator mit=mDownloads.find(hash);
|
||||
if (mit==mDownloads.end())
|
||||
{
|
||||
#ifdef CONTROL_DEBUG
|
||||
@ -1378,7 +1378,7 @@ bool ftController::setChunkStrategy(const std::string& hash,FileChunksInfo::Chun
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool ftController::FileCancel(const std::string& hash)
|
||||
bool ftController::FileCancel(const RsFileHash& hash)
|
||||
{
|
||||
rsTurtle->stopMonitoringTunnels(hash) ;
|
||||
|
||||
@ -1390,7 +1390,7 @@ bool ftController::FileCancel(const std::string& hash)
|
||||
{
|
||||
RsStackMutex mtx(ctrlMutex) ;
|
||||
|
||||
std::map<std::string,ftFileControl*>::iterator mit=mDownloads.find(hash);
|
||||
std::map<RsFileHash,ftFileControl*>::iterator mit=mDownloads.find(hash);
|
||||
if (mit==mDownloads.end())
|
||||
{
|
||||
#ifdef CONTROL_DEBUG
|
||||
@ -1461,7 +1461,7 @@ bool ftController::FileCancel(const std::string& hash)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ftController::FileControl(const std::string& hash, uint32_t flags)
|
||||
bool ftController::FileControl(const RsFileHash& hash, uint32_t flags)
|
||||
{
|
||||
#ifdef CONTROL_DEBUG
|
||||
std::cerr << "ftController::FileControl(" << hash << ",";
|
||||
@ -1470,7 +1470,7 @@ bool ftController::FileControl(const std::string& hash, uint32_t flags)
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
|
||||
/*check if the file in the download map*/
|
||||
std::map<std::string,ftFileControl*>::iterator mit=mDownloads.find(hash);
|
||||
std::map<RsFileHash,ftFileControl*>::iterator mit=mDownloads.find(hash);
|
||||
if (mit==mDownloads.end())
|
||||
{
|
||||
#ifdef CONTROL_DEBUG
|
||||
@ -1513,7 +1513,7 @@ bool ftController::FileClearCompleted()
|
||||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
|
||||
for(std::map<std::string, ftFileControl*>::iterator it(mCompleted.begin());it!=mCompleted.end();++it)
|
||||
for(std::map<RsFileHash, ftFileControl*>::iterator it(mCompleted.begin());it!=mCompleted.end();++it)
|
||||
delete it->second ;
|
||||
|
||||
mCompleted.clear();
|
||||
@ -1527,11 +1527,11 @@ bool ftController::FileClearCompleted()
|
||||
}
|
||||
|
||||
/* get Details of File Transfers */
|
||||
bool ftController::FileDownloads(std::list<std::string> &hashs)
|
||||
bool ftController::FileDownloads(std::list<RsFileHash> &hashs)
|
||||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
|
||||
std::map<std::string, ftFileControl*>::iterator it;
|
||||
std::map<RsFileHash, ftFileControl*>::iterator it;
|
||||
for(it = mDownloads.begin(); it != mDownloads.end(); it++)
|
||||
{
|
||||
hashs.push_back(it->second->mHash);
|
||||
@ -1611,7 +1611,7 @@ bool ftController::setPartialsDirectory(std::string path)
|
||||
|
||||
#if 0 /*** FIX ME !!!**************/
|
||||
/* move all existing files! */
|
||||
std::map<std::string, ftFileControl>::iterator it;
|
||||
std::map<RsFileHash, ftFileControl>::iterator it;
|
||||
for(it = mDownloads.begin(); it != mDownloads.end(); it++)
|
||||
{
|
||||
(it->second).mCreator->changePartialDirectory(mPartialPath);
|
||||
@ -1638,10 +1638,10 @@ std::string ftController::getPartialsDirectory()
|
||||
return mPartialsPath;
|
||||
}
|
||||
|
||||
bool ftController::setDestinationDirectory(const std::string& hash,const std::string& dest_dir)
|
||||
bool ftController::setDestinationDirectory(const RsFileHash& hash,const std::string& dest_dir)
|
||||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
std::map<std::string, ftFileControl*>::iterator it = mDownloads.find(hash);
|
||||
std::map<RsFileHash, ftFileControl*>::iterator it = mDownloads.find(hash);
|
||||
|
||||
if (it == mDownloads.end())
|
||||
return false;
|
||||
@ -1654,10 +1654,10 @@ bool ftController::setDestinationDirectory(const std::string& hash,const std::st
|
||||
|
||||
return true ;
|
||||
}
|
||||
bool ftController::setDestinationName(const std::string& hash,const std::string& dest_name)
|
||||
bool ftController::setDestinationName(const RsFileHash& hash,const std::string& dest_name)
|
||||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
std::map<std::string, ftFileControl*>::iterator it = mDownloads.find(hash);
|
||||
std::map<RsFileHash, ftFileControl*>::iterator it = mDownloads.find(hash);
|
||||
|
||||
if (it == mDownloads.end())
|
||||
return false;
|
||||
@ -1675,12 +1675,12 @@ bool ftController::setDestinationName(const std::string& hash,const std::string&
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool ftController::FileDetails(const std::string &hash, FileInfo &info)
|
||||
bool ftController::FileDetails(const RsFileHash &hash, FileInfo &info)
|
||||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
|
||||
bool completed = false;
|
||||
std::map<std::string, ftFileControl*>::iterator it = mDownloads.find(hash);
|
||||
std::map<RsFileHash, ftFileControl*>::iterator it = mDownloads.find(hash);
|
||||
if (it == mDownloads.end())
|
||||
{
|
||||
/* search completed files too */
|
||||
@ -1708,8 +1708,8 @@ bool ftController::FileDetails(const std::string &hash, FileInfo &info)
|
||||
info.storage_permission_flags |= DIR_FLAGS_NETWORK_WIDE_OTHERS ; // file being downloaded anonymously are always anonymously available.
|
||||
|
||||
/* get list of sources from transferModule */
|
||||
std::list<std::string> peerIds;
|
||||
std::list<std::string>::iterator pit;
|
||||
std::list<RsPeerId> peerIds;
|
||||
std::list<RsPeerId>::iterator pit;
|
||||
|
||||
if (!completed)
|
||||
{
|
||||
@ -1821,7 +1821,7 @@ void ftController::statusChange(const std::list<pqipeer> &plist)
|
||||
uint32_t rate = FT_CNTRL_STANDARD_RATE;
|
||||
|
||||
/* add online to all downloads */
|
||||
std::map<std::string, ftFileControl*>::iterator it;
|
||||
std::map<RsFileHash, ftFileControl*>::iterator it;
|
||||
std::list<pqipeer>::const_iterator pit;
|
||||
|
||||
#ifdef CONTROL_DEBUG
|
||||
@ -1913,7 +1913,7 @@ void ftController::statusChange(const std::list<pqipeer> &plist)
|
||||
}
|
||||
|
||||
/* Cache Interface */
|
||||
bool ftController::RequestCacheFile(RsPeerId id, std::string path, std::string hash, uint64_t size)
|
||||
bool ftController::RequestCacheFile(const RsPeerId& id, std::string path, const RsFileHash& hash, uint64_t size)
|
||||
{
|
||||
#ifdef CONTROL_DEBUG
|
||||
std::cerr << "ftController::RequestCacheFile(" << id << ",";
|
||||
@ -1922,7 +1922,7 @@ bool ftController::RequestCacheFile(RsPeerId id, std::string path, std::string h
|
||||
#endif
|
||||
|
||||
/* Request File */
|
||||
std::list<std::string> ids;
|
||||
std::list<RsPeerId> ids;
|
||||
ids.push_back(id);
|
||||
|
||||
FileInfo info ;
|
||||
@ -1937,7 +1937,7 @@ bool ftController::RequestCacheFile(RsPeerId id, std::string path, std::string h
|
||||
std::cerr << "Copying it !!" << std::endl ;
|
||||
#endif
|
||||
|
||||
if(info.size > 0 && copyFile(info.path,path+"/"+hash))
|
||||
if(info.size > 0 && copyFile(info.path,path+"/"+hash.toStdString()))
|
||||
{
|
||||
CompletedCache(hash);
|
||||
return true ;
|
||||
@ -1946,13 +1946,13 @@ bool ftController::RequestCacheFile(RsPeerId id, std::string path, std::string h
|
||||
return false ;
|
||||
}
|
||||
|
||||
FileRequest(hash, hash, size, path, RS_FILE_REQ_CACHE | RS_FILE_REQ_NO_SEARCH, ids);
|
||||
FileRequest(hash.toStdString(), hash, size, path, RS_FILE_REQ_CACHE | RS_FILE_REQ_NO_SEARCH, ids);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool ftController::CancelCacheFile(RsPeerId id, std::string path, std::string hash, uint64_t size)
|
||||
bool ftController::CancelCacheFile(const RsPeerId& id, std::string path, const RsFileHash& hash, uint64_t size)
|
||||
{
|
||||
std::cerr << "ftController::CancelCacheFile(" << id << ",";
|
||||
std::cerr << path << "," << hash << "," << size << ")";
|
||||
@ -1994,7 +1994,7 @@ bool ftController::saveList(bool &cleanup, std::list<RsItem *>& saveData)
|
||||
/* create a key/value set for most of the parameters */
|
||||
std::map<std::string, std::string> configMap;
|
||||
std::map<std::string, std::string>::iterator mit;
|
||||
std::list<std::string>::iterator it;
|
||||
std::list<RsFileHash>::iterator it;
|
||||
|
||||
/* basic control parameters */
|
||||
std::string s ;
|
||||
@ -2043,7 +2043,7 @@ bool ftController::saveList(bool &cleanup, std::list<RsItem *>& saveData)
|
||||
|
||||
|
||||
/* get Details of File Transfers */
|
||||
std::list<std::string> hashs;
|
||||
std::list<RsFileHash> hashs;
|
||||
FileDownloads(hashs);
|
||||
|
||||
for(it = hashs.begin(); it != hashs.end(); it++)
|
||||
@ -2051,7 +2051,7 @@ bool ftController::saveList(bool &cleanup, std::list<RsItem *>& saveData)
|
||||
/* stack mutex released each loop */
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
|
||||
std::map<std::string, ftFileControl*>::iterator fit = mDownloads.find(*it);
|
||||
std::map<RsFileHash, ftFileControl*>::iterator fit = mDownloads.find(*it);
|
||||
if (fit == mDownloads.end())
|
||||
continue;
|
||||
|
||||
@ -2083,24 +2083,18 @@ bool ftController::saveList(bool &cleanup, std::list<RsItem *>& saveData)
|
||||
RsDirUtil::removeTopDir(fit->second->mDestination, rft->file.path); /* remove fname */
|
||||
rft->flags = fit->second->mFlags.toUInt32();
|
||||
rft->state = fit->second->mState;
|
||||
fit->second->mTransfer->getFileSources(rft->allPeerIds.ids);
|
||||
|
||||
rft->transferred = fit->second->mCreator->getRecvd();
|
||||
std::list<RsPeerId> lst ;
|
||||
fit->second->mTransfer->getFileSources(lst);
|
||||
|
||||
// Remove turtle peers from sources, as they are not supposed to survive a reboot of RS, since they are dynamic sources.
|
||||
// Otherwize, such sources are unknown from the turtle router, at restart, and never get removed.
|
||||
//
|
||||
for(std::list<std::string>::iterator sit(rft->allPeerIds.ids.begin());sit!=rft->allPeerIds.ids.end();)
|
||||
if(mTurtle->isTurtlePeer(*sit))
|
||||
{
|
||||
std::list<std::string>::iterator sittmp(sit) ;
|
||||
++sittmp ;
|
||||
rft->allPeerIds.ids.erase(sit) ;
|
||||
sit = sittmp ;
|
||||
}
|
||||
else
|
||||
++sit ;
|
||||
for(std::list<RsPeerId>::const_iterator it(lst.begin());it!=lst.end();++it)
|
||||
if(!mTurtle->isTurtlePeer(*it))
|
||||
rft->allPeerIds.ids.push_back(*it) ;
|
||||
|
||||
rft->transferred = fit->second->mCreator->getRecvd();
|
||||
fit->second->mCreator->getAvailabilityMap(rft->compressed_chunk_map) ;
|
||||
rft->chunk_strategy = fit->second->mCreator->getChunkStrategy() ;
|
||||
|
||||
@ -2117,7 +2111,7 @@ bool ftController::saveList(bool &cleanup, std::list<RsItem *>& saveData)
|
||||
/* make RsFileTransfer item for save list */
|
||||
RsFileTransfer *rft = NULL;
|
||||
|
||||
std::map<std::string,RsFileTransfer*>::iterator rit = mPendingChunkMaps.find(pit->mHash);
|
||||
std::map<RsFileHash,RsFileTransfer*>::iterator rit = mPendingChunkMaps.find(pit->mHash);
|
||||
if (rit != mPendingChunkMaps.end()) {
|
||||
/* use item from the not loaded pending list */
|
||||
rft = new RsFileTransfer(*(rit->second));
|
||||
@ -2132,18 +2126,24 @@ bool ftController::saveList(bool &cleanup, std::list<RsItem *>& saveData)
|
||||
RsDirUtil::removeTopDir(pit->mDest, rft->file.path); /* remove fname */
|
||||
rft->flags = pit->mFlags.toUInt32();
|
||||
rft->state = pit->mState;
|
||||
rft->allPeerIds.ids = pit->mSrcIds;
|
||||
|
||||
rft->allPeerIds.ids.clear() ;
|
||||
for(std::list<RsPeerId>::const_iterator it(pit->mSrcIds.begin());it!=pit->mSrcIds.end();++it)
|
||||
rft->allPeerIds.ids.push_back( *it ) ;
|
||||
}
|
||||
|
||||
// Remove turtle peers from sources, as they are not supposed to survive a reboot of RS, since they are dynamic sources.
|
||||
// Otherwize, such sources are unknown from the turtle router, at restart, and never get removed.
|
||||
// Otherwize, such sources are unknown from the turtle router, at restart, and never get removed. We do that in post
|
||||
// process since the rft object may have been created from mPendingChunkMaps
|
||||
//
|
||||
for(std::list<std::string>::iterator sit(rft->allPeerIds.ids.begin());sit!=rft->allPeerIds.ids.end();)
|
||||
if(mTurtle->isTurtlePeer(*sit))
|
||||
{
|
||||
std::list<std::string>::iterator sittmp(sit) ;
|
||||
sit = rft->allPeerIds.ids.erase(sit) ;
|
||||
}
|
||||
for(std::list<RsPeerId>::iterator sit(rft->allPeerIds.ids.begin());sit!=rft->allPeerIds.ids.end();)
|
||||
if(mTurtle->isTurtlePeer(RsPeerId(*sit)))
|
||||
{
|
||||
std::list<RsPeerId>::iterator sittmp(sit) ;
|
||||
++sittmp ;
|
||||
rft->allPeerIds.ids.erase(sit) ;
|
||||
sit = sittmp ;
|
||||
}
|
||||
else
|
||||
++sit ;
|
||||
|
||||
@ -2201,12 +2201,16 @@ bool ftController::loadList(std::list<RsItem *>& load)
|
||||
#ifdef CONTROL_DEBUG
|
||||
std::cerr << "ftController::loadList(): requesting " << rsft->file.name << ", " << rsft->file.hash << ", " << rsft->file.filesize << std::endl ;
|
||||
#endif
|
||||
FileRequest(rsft->file.name, rsft->file.hash, rsft->file.filesize, rsft->file.path, TransferRequestFlags(rsft->flags), rsft->allPeerIds.ids, rsft->state);
|
||||
std::list<RsPeerId> src_lst ;
|
||||
for(std::list<RsPeerId>::const_iterator it(rsft->allPeerIds.ids.begin());it!=rsft->allPeerIds.ids.end();++it)
|
||||
src_lst.push_back(*it) ;
|
||||
|
||||
FileRequest(rsft->file.name, rsft->file.hash, rsft->file.filesize, rsft->file.path, TransferRequestFlags(rsft->flags), src_lst, rsft->state);
|
||||
|
||||
{
|
||||
RsStackMutex mtx(ctrlMutex) ;
|
||||
|
||||
std::map<std::string, ftFileControl*>::iterator fit = mDownloads.find(rsft->file.hash);
|
||||
std::map<RsFileHash, ftFileControl*>::iterator fit = mDownloads.find(rsft->file.hash);
|
||||
|
||||
if((fit==mDownloads.end() || (fit->second)->mCreator == NULL))
|
||||
{
|
||||
|
@ -74,7 +74,7 @@ class ftFileControl
|
||||
|
||||
ftFileControl();
|
||||
ftFileControl(std::string fname, std::string tmppath, std::string dest,
|
||||
uint64_t size, std::string hash, TransferRequestFlags flags,
|
||||
uint64_t size, const RsFileHash& hash, TransferRequestFlags flags,
|
||||
ftFileCreator *fc, ftTransferModule *tm);
|
||||
|
||||
std::string mName;
|
||||
@ -83,7 +83,7 @@ class ftFileControl
|
||||
ftTransferModule * mTransfer;
|
||||
ftFileCreator * mCreator;
|
||||
uint32_t mState;
|
||||
std::string mHash;
|
||||
RsFileHash mHash;
|
||||
uint64_t mSize;
|
||||
TransferRequestFlags mFlags;
|
||||
time_t mCreateTime;
|
||||
@ -94,20 +94,20 @@ class ftFileControl
|
||||
class ftPendingRequest
|
||||
{
|
||||
public:
|
||||
ftPendingRequest(const std::string& fname, const std::string& hash,
|
||||
ftPendingRequest(const std::string& fname, const RsFileHash& hash,
|
||||
uint64_t size, const std::string& dest, TransferRequestFlags flags,
|
||||
const std::list<std::string> &srcIds, uint16_t state)
|
||||
const std::list<RsPeerId> &srcIds, uint16_t state)
|
||||
: mName(fname), mHash(hash), mSize(size),
|
||||
mDest(dest), mFlags(flags), mSrcIds(srcIds), mState(state) { return; }
|
||||
|
||||
ftPendingRequest() : mSize(0), mFlags(0), mState(0) { return; }
|
||||
|
||||
std::string mName;
|
||||
std::string mHash;
|
||||
RsFileHash mHash;
|
||||
uint64_t mSize;
|
||||
std::string mDest;
|
||||
TransferRequestFlags mFlags;
|
||||
std::list<std::string> mSrcIds;
|
||||
std::list<RsPeerId> mSrcIds;
|
||||
uint16_t mState;
|
||||
};
|
||||
|
||||
@ -131,34 +131,34 @@ class ftController: public CacheTransfer, public RsThread, public pqiMonitor, pu
|
||||
/********************** Controller Access **********************/
|
||||
/***************************************************************/
|
||||
|
||||
bool FileRequest(const std::string& fname, const std::string& hash,
|
||||
bool FileRequest(const std::string& fname, const RsFileHash& hash,
|
||||
uint64_t size, const std::string& dest, TransferRequestFlags flags,
|
||||
const std::list<std::string> &sourceIds, uint16_t state = ftFileControl::DOWNLOADING);
|
||||
const std::list<RsPeerId> &sourceIds, uint16_t state = ftFileControl::DOWNLOADING);
|
||||
|
||||
/// Do we already have this file, either in download or in file lists ?
|
||||
bool alreadyHaveFile(const std::string& hash, FileInfo &info);
|
||||
bool alreadyHaveFile(const RsFileHash& hash, FileInfo &info);
|
||||
|
||||
bool setChunkStrategy(const std::string& hash,FileChunksInfo::ChunkStrategy s);
|
||||
bool setChunkStrategy(const RsFileHash& hash,FileChunksInfo::ChunkStrategy s);
|
||||
void setDefaultChunkStrategy(FileChunksInfo::ChunkStrategy s);
|
||||
FileChunksInfo::ChunkStrategy defaultChunkStrategy();
|
||||
uint32_t freeDiskSpaceLimit() const ;
|
||||
void setFreeDiskSpaceLimit(uint32_t size_in_mb) ;
|
||||
|
||||
bool FileCancel(const std::string& hash);
|
||||
bool FileControl(const std::string& hash, uint32_t flags);
|
||||
bool FileCancel(const RsFileHash& hash);
|
||||
bool FileControl(const RsFileHash& hash, uint32_t flags);
|
||||
bool FileClearCompleted();
|
||||
bool FlagFileComplete(std::string hash);
|
||||
bool getFileDownloadChunksDetails(const std::string& hash,FileChunksInfo& info);
|
||||
bool setDestinationName(const std::string& hash,const std::string& dest_name) ;
|
||||
bool setDestinationDirectory(const std::string& hash,const std::string& dest_name) ;
|
||||
bool FlagFileComplete(const RsFileHash& hash);
|
||||
bool getFileDownloadChunksDetails(const RsFileHash& hash,FileChunksInfo& info);
|
||||
bool setDestinationName(const RsFileHash& hash,const std::string& dest_name) ;
|
||||
bool setDestinationDirectory(const RsFileHash& hash,const std::string& dest_name) ;
|
||||
|
||||
// Download speed
|
||||
bool getPriority(const std::string& hash,DwlSpeed& p);
|
||||
void setPriority(const std::string& hash,DwlSpeed p);
|
||||
bool getPriority(const RsFileHash& hash,DwlSpeed& p);
|
||||
void setPriority(const RsFileHash& hash,DwlSpeed p);
|
||||
|
||||
// Action on queue position
|
||||
//
|
||||
void moveInQueue(const std::string& hash,QueueMove mv) ;
|
||||
void moveInQueue(const RsFileHash& hash,QueueMove mv) ;
|
||||
void clearQueue() ;
|
||||
void setQueueSize(uint32_t size) ;
|
||||
uint32_t getQueueSize() ;
|
||||
@ -166,14 +166,14 @@ class ftController: public CacheTransfer, public RsThread, public pqiMonitor, pu
|
||||
uint32_t getMinPrioritizedTransfers() ;
|
||||
|
||||
/* get Details of File Transfers */
|
||||
bool FileDownloads(std::list<std::string> &hashs);
|
||||
bool FileDownloads(std::list<RsFileHash> &hashs);
|
||||
|
||||
/* Directory Handling */
|
||||
bool setDownloadDirectory(std::string path);
|
||||
bool setDownloadDirectory(std::string path);
|
||||
bool setPartialsDirectory(std::string path);
|
||||
std::string getDownloadDirectory();
|
||||
std::string getPartialsDirectory();
|
||||
bool FileDetails(const std::string &hash, FileInfo &info);
|
||||
bool FileDetails(const RsFileHash &hash, FileInfo &info);
|
||||
|
||||
bool moveFile(const std::string& source,const std::string& dest) ;
|
||||
bool copyFile(const std::string& source,const std::string& dest) ;
|
||||
@ -184,17 +184,17 @@ class ftController: public CacheTransfer, public RsThread, public pqiMonitor, pu
|
||||
|
||||
/// Returns true is full source availability can be assumed for this peer.
|
||||
///
|
||||
bool assumeAvailability(const std::string& peer_id) const ;
|
||||
bool assumeAvailability(const RsPeerId& peer_id) const ;
|
||||
|
||||
/* pqiMonitor callback (also provided mConnMgr pointer!) */
|
||||
virtual void statusChange(const std::list<pqipeer> &plist);
|
||||
void addFileSource(const std::string& hash,const std::string& peer_id) ;
|
||||
void removeFileSource(const std::string& hash,const std::string& peer_id) ;
|
||||
void addFileSource(const RsFileHash& hash,const RsPeerId& peer_id) ;
|
||||
void removeFileSource(const RsFileHash& hash,const RsPeerId& peer_id) ;
|
||||
|
||||
protected:
|
||||
|
||||
virtual bool RequestCacheFile(RsPeerId id, std::string path, std::string hash, uint64_t size);
|
||||
virtual bool CancelCacheFile(RsPeerId id, std::string path, std::string hash, uint64_t size);
|
||||
virtual bool RequestCacheFile(const RsPeerId& id, std::string path, const RsFileHash& hash, uint64_t size);
|
||||
virtual bool CancelCacheFile(const RsPeerId& id, std::string path, const RsFileHash& hash, uint64_t size);
|
||||
|
||||
void cleanCacheDownloads() ;
|
||||
void searchForDirectSources() ;
|
||||
@ -223,10 +223,10 @@ class ftController: public CacheTransfer, public RsThread, public pqiMonitor, pu
|
||||
void locked_queueRemove(uint32_t pos) ; // delete this element from the queue
|
||||
void locked_swapQueue(uint32_t pos1,uint32_t pos2) ; // swap position of the two elements
|
||||
|
||||
bool completeFile(std::string hash);
|
||||
bool completeFile(const RsFileHash& hash);
|
||||
bool handleAPendingRequest();
|
||||
|
||||
bool setPeerState(ftTransferModule *tm, std::string id,
|
||||
bool setPeerState(ftTransferModule *tm, const RsPeerId& id,
|
||||
uint32_t maxrate, bool online);
|
||||
|
||||
time_t last_save_time ;
|
||||
@ -241,8 +241,8 @@ class ftController: public CacheTransfer, public RsThread, public pqiMonitor, pu
|
||||
|
||||
RsMutex ctrlMutex;
|
||||
|
||||
std::map<std::string, ftFileControl*> mCompleted;
|
||||
std::map<std::string, ftFileControl*> mDownloads;
|
||||
std::map<RsFileHash, ftFileControl*> mCompleted;
|
||||
std::map<RsFileHash, ftFileControl*> mDownloads;
|
||||
std::vector<ftFileControl*> _queue ;
|
||||
|
||||
std::string mConfigPath;
|
||||
@ -253,13 +253,13 @@ class ftController: public CacheTransfer, public RsThread, public pqiMonitor, pu
|
||||
|
||||
/* callback list (for File Completion) */
|
||||
RsMutex doneMutex;
|
||||
std::list<std::string> mDone;
|
||||
std::list<RsFileHash> mDone;
|
||||
|
||||
/* List to Pause File transfers until Caches are properly loaded */
|
||||
bool mFtActive;
|
||||
bool mFtPendingDone;
|
||||
std::list<ftPendingRequest> mPendingRequests;
|
||||
std::map<std::string,RsFileTransfer*> mPendingChunkMaps ;
|
||||
std::map<RsFileHash,RsFileTransfer*> mPendingChunkMaps ;
|
||||
|
||||
FileChunksInfo::ChunkStrategy mDefaultChunkStrategy ;
|
||||
|
||||
|
@ -38,7 +38,6 @@
|
||||
#include <string>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <util/rsid.h>
|
||||
#include <retroshare/rstypes.h>
|
||||
|
||||
/*************** SEND INTERFACE *******************/
|
||||
@ -51,23 +50,23 @@ class ftDataSend
|
||||
virtual ~ftDataSend() { return; }
|
||||
|
||||
/* Client Send */
|
||||
virtual bool sendDataRequest(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize) = 0;
|
||||
virtual bool sendDataRequest(const RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunksize) = 0;
|
||||
|
||||
/* Server Send */
|
||||
virtual bool sendData(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data) = 0;
|
||||
virtual bool sendData(const RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data) = 0;
|
||||
|
||||
/// Send a chunkmap[request]. Because requests/chunkmaps can go both
|
||||
//directions, but for different usages, we have this "is_client" flags,
|
||||
//that gives the ultimate goal of the data. "is_client==true" means that
|
||||
//the message is for a client (download) instead of a server.
|
||||
//
|
||||
virtual bool sendChunkMapRequest(const std::string& peer_id,const std::string& hash,bool is_client) = 0;
|
||||
virtual bool sendChunkMap(const std::string& peer_id,const std::string& hash,const CompressedChunkMap& cmap,bool is_client) = 0;
|
||||
virtual bool sendChunkMapRequest(const RsPeerId& peer_id,const RsFileHash& hash,bool is_client) = 0;
|
||||
virtual bool sendChunkMap(const RsPeerId& peer_id,const RsFileHash& hash,const CompressedChunkMap& cmap,bool is_client) = 0;
|
||||
|
||||
/// Send a request for a chunk crc map
|
||||
virtual bool sendSingleChunkCRCRequest(const std::string& peer_id,const std::string& hash,uint32_t chunk_number) = 0;
|
||||
virtual bool sendSingleChunkCRCRequest(const RsPeerId& peer_id,const RsFileHash& hash,uint32_t chunk_number) = 0;
|
||||
/// Send a chunk crc map
|
||||
virtual bool sendSingleChunkCRC(const std::string& peer_id,const std::string& hash,uint32_t chunk_number,const Sha1CheckSum& crc) = 0;
|
||||
virtual bool sendSingleChunkCRC(const RsPeerId& peer_id,const RsFileHash& hash,uint32_t chunk_number,const Sha1CheckSum& crc) = 0;
|
||||
};
|
||||
|
||||
|
||||
@ -80,19 +79,19 @@ class ftDataRecv
|
||||
virtual ~ftDataRecv() { return; }
|
||||
|
||||
/* Client Recv */
|
||||
virtual bool recvData(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data) = 0;
|
||||
virtual bool recvData(const RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data) = 0;
|
||||
|
||||
/* Server Recv */
|
||||
virtual bool recvDataRequest(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize) = 0;
|
||||
virtual bool recvDataRequest(const RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunksize) = 0;
|
||||
|
||||
/// Send a request for a chunk map
|
||||
virtual bool recvChunkMapRequest(const std::string& peer_id,const std::string& hash,bool is_client) = 0;
|
||||
virtual bool recvChunkMapRequest(const RsPeerId& peer_id,const RsFileHash& hash,bool is_client) = 0;
|
||||
|
||||
/// Send a chunk map
|
||||
virtual bool recvChunkMap(const std::string& peer_id,const std::string& hash,const CompressedChunkMap& cmap,bool is_client) = 0;
|
||||
virtual bool recvChunkMap(const RsPeerId& peer_id,const RsFileHash& hash,const CompressedChunkMap& cmap,bool is_client) = 0;
|
||||
|
||||
virtual bool recvSingleChunkCRCRequest(const std::string& peer_id,const std::string& hash,uint32_t chunk_id) = 0;
|
||||
virtual bool recvSingleChunkCRC(const std::string& peer_id,const std::string& hash,uint32_t chunk_id,const Sha1CheckSum& sum) = 0;
|
||||
virtual bool recvSingleChunkCRCRequest(const RsPeerId& peer_id,const RsFileHash& hash,uint32_t chunk_id) = 0;
|
||||
virtual bool recvSingleChunkCRC(const RsPeerId& peer_id,const RsFileHash& hash,uint32_t chunk_id,const Sha1CheckSum& sum) = 0;
|
||||
|
||||
};
|
||||
|
||||
|
@ -63,14 +63,14 @@ const uint32_t FT_SERVER_CHUNK_MAP_REQ = 0x0004; // chunk map request to be tre
|
||||
//const uint32_t FT_CRC32MAP_REQ = 0x0005; // crc32 map request to be treated by server
|
||||
const uint32_t FT_CLIENT_CHUNK_CRC_REQ = 0x0006; // chunk sha1 crc request to be treated
|
||||
|
||||
ftRequest::ftRequest(uint32_t type, std::string peerId, std::string hash, uint64_t size, uint64_t offset, uint32_t chunk, void *data)
|
||||
ftRequest::ftRequest(uint32_t type, const RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunk, void *data)
|
||||
:mType(type), mPeerId(peerId), mHash(hash), mSize(size),
|
||||
mOffset(offset), mChunk(chunk), mData(data)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ftDataMultiplex::ftDataMultiplex(std::string ownId, ftDataSend *server, ftSearch *search)
|
||||
ftDataMultiplex::ftDataMultiplex(const RsPeerId& ownId, ftDataSend *server, ftSearch *search)
|
||||
:RsQueueThread(DMULTIPLEX_MIN, DMULTIPLEX_MAX, DMULTIPLEX_RELAX), dataMtx("ftDataMultiplex"),
|
||||
mDataSend(server), mSearch(search), mOwnId(ownId)
|
||||
{
|
||||
@ -80,7 +80,7 @@ ftDataMultiplex::ftDataMultiplex(std::string ownId, ftDataSend *server, ftSearch
|
||||
bool ftDataMultiplex::addTransferModule(ftTransferModule *mod, ftFileCreator *f)
|
||||
{
|
||||
RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/
|
||||
std::map<std::string, ftClient>::iterator it;
|
||||
std::map<RsFileHash, ftClient>::iterator it;
|
||||
if (mClients.end() != (it = mClients.find(mod->hash())))
|
||||
{
|
||||
/* error */
|
||||
@ -91,11 +91,11 @@ bool ftDataMultiplex::addTransferModule(ftTransferModule *mod, ftFileCreator *f)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ftDataMultiplex::removeTransferModule(std::string hash)
|
||||
bool ftDataMultiplex::removeTransferModule(const RsFileHash& hash)
|
||||
{
|
||||
RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/
|
||||
|
||||
std::map<std::string, ftClient>::iterator it;
|
||||
std::map<RsFileHash, ftClient>::iterator it;
|
||||
if (mClients.end() == (it = mClients.find(hash)))
|
||||
{
|
||||
/* error */
|
||||
@ -111,7 +111,7 @@ bool ftDataMultiplex::removeTransferModule(std::string hash)
|
||||
// With the current action, the next server request will re-create the server as
|
||||
// a ftFileProvider.
|
||||
//
|
||||
std::map<std::string, ftFileProvider*>::iterator sit = mServers.find(hash) ;
|
||||
std::map<RsFileHash, ftFileProvider*>::iterator sit = mServers.find(hash) ;
|
||||
|
||||
if(sit != mServers.end())
|
||||
mServers.erase(sit);
|
||||
@ -120,10 +120,10 @@ bool ftDataMultiplex::removeTransferModule(std::string hash)
|
||||
}
|
||||
|
||||
|
||||
bool ftDataMultiplex::FileUploads(std::list<std::string> &hashs)
|
||||
bool ftDataMultiplex::FileUploads(std::list<RsFileHash> &hashs)
|
||||
{
|
||||
RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/
|
||||
std::map<std::string, ftFileProvider *>::iterator sit;
|
||||
std::map<RsFileHash, ftFileProvider *>::iterator sit;
|
||||
for(sit = mServers.begin(); sit != mServers.end(); sit++)
|
||||
{
|
||||
hashs.push_back(sit->first);
|
||||
@ -131,10 +131,10 @@ bool ftDataMultiplex::FileUploads(std::list<std::string> &hashs)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ftDataMultiplex::FileDownloads(std::list<std::string> &hashs)
|
||||
bool ftDataMultiplex::FileDownloads(std::list<RsFileHash> &hashs)
|
||||
{
|
||||
RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/
|
||||
std::map<std::string, ftClient>::iterator cit;
|
||||
std::map<RsFileHash, ftClient>::iterator cit;
|
||||
for(cit = mClients.begin(); cit != mClients.end(); cit++)
|
||||
{
|
||||
hashs.push_back(cit->first);
|
||||
@ -143,7 +143,7 @@ bool ftDataMultiplex::FileDownloads(std::list<std::string> &hashs)
|
||||
}
|
||||
|
||||
|
||||
bool ftDataMultiplex::FileDetails(const std::string &hash, FileSearchFlags hintsflag, FileInfo &info)
|
||||
bool ftDataMultiplex::FileDetails(const RsFileHash &hash, FileSearchFlags hintsflag, FileInfo &info)
|
||||
{
|
||||
#ifdef MPLEX_DEBUG
|
||||
std::cerr << "ftDataMultiplex::FileDetails(";
|
||||
@ -155,7 +155,7 @@ bool ftDataMultiplex::FileDetails(const std::string &hash, FileSearchFlags hi
|
||||
|
||||
if(hintsflag & RS_FILE_HINTS_DOWNLOAD)
|
||||
{
|
||||
std::map<std::string, ftClient>::iterator cit;
|
||||
std::map<RsFileHash, ftClient>::iterator cit;
|
||||
if (mClients.end() != (cit = mClients.find(hash)))
|
||||
{
|
||||
|
||||
@ -173,7 +173,7 @@ bool ftDataMultiplex::FileDetails(const std::string &hash, FileSearchFlags hi
|
||||
|
||||
if(hintsflag & RS_FILE_HINTS_UPLOAD)
|
||||
{
|
||||
std::map<std::string, ftFileProvider *>::iterator sit;
|
||||
std::map<RsFileHash, ftFileProvider *>::iterator sit;
|
||||
sit = mServers.find(hash);
|
||||
if (sit != mServers.end())
|
||||
{
|
||||
@ -204,7 +204,7 @@ bool ftDataMultiplex::FileDetails(const std::string &hash, FileSearchFlags hi
|
||||
/*************** SEND INTERFACE (calls ftDataSend) *******************/
|
||||
|
||||
/* Client Send */
|
||||
bool ftDataMultiplex::sendDataRequest(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize)
|
||||
bool ftDataMultiplex::sendDataRequest(const RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunksize)
|
||||
{
|
||||
#ifdef MPLEX_DEBUG
|
||||
std::cerr << "ftDataMultiplex::sendDataRequest() Client Send";
|
||||
@ -214,7 +214,7 @@ bool ftDataMultiplex::sendDataRequest(const std::string& peerId, const std::stri
|
||||
}
|
||||
|
||||
/* Server Send */
|
||||
bool ftDataMultiplex::sendData(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data)
|
||||
bool ftDataMultiplex::sendData(const RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data)
|
||||
{
|
||||
#ifdef MPLEX_DEBUG
|
||||
std::cerr << "ftDataMultiplex::sendData() Server Send";
|
||||
@ -227,7 +227,7 @@ bool ftDataMultiplex::sendData(const std::string& peerId, const std::string& has
|
||||
/*************** RECV INTERFACE (provides ftDataRecv) ****************/
|
||||
|
||||
/* Client Recv */
|
||||
bool ftDataMultiplex::recvData(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data)
|
||||
bool ftDataMultiplex::recvData(const RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data)
|
||||
{
|
||||
#ifdef MPLEX_DEBUG
|
||||
std::cerr << "ftDataMultiplex::recvData() Client Recv";
|
||||
@ -242,7 +242,7 @@ bool ftDataMultiplex::recvData(const std::string& peerId, const std::string& has
|
||||
|
||||
|
||||
/* Server Recv */
|
||||
bool ftDataMultiplex::recvDataRequest(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize)
|
||||
bool ftDataMultiplex::recvDataRequest(const RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunksize)
|
||||
{
|
||||
#ifdef MPLEX_DEBUG
|
||||
std::cerr << "ftDataMultiplex::recvDataRequest() Server Recv";
|
||||
@ -256,7 +256,7 @@ bool ftDataMultiplex::recvDataRequest(const std::string& peerId, const std::stri
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ftDataMultiplex::recvChunkMapRequest(const std::string& peerId, const std::string& hash,bool is_client)
|
||||
bool ftDataMultiplex::recvChunkMapRequest(const RsPeerId& peerId, const RsFileHash& hash,bool is_client)
|
||||
{
|
||||
#ifdef MPLEX_DEBUG
|
||||
std::cerr << "ftDataMultiplex::recvChunkMapRequest() Server Recv";
|
||||
@ -273,7 +273,7 @@ bool ftDataMultiplex::recvChunkMapRequest(const std::string& peerId, const std::
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ftDataMultiplex::recvSingleChunkCRCRequest(const std::string& peerId, const std::string& hash,uint32_t chunk_number)
|
||||
bool ftDataMultiplex::recvSingleChunkCRCRequest(const RsPeerId& peerId, const RsFileHash& hash,uint32_t chunk_number)
|
||||
{
|
||||
#ifdef MPLEX_DEBUG
|
||||
std::cerr << "ftDataMultiplex::recvChunkMapRequest() Server Recv";
|
||||
@ -406,7 +406,7 @@ bool ftDataMultiplex::doWork()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ftDataMultiplex::recvSingleChunkCRC(const std::string& peerId, const std::string& hash,uint32_t chunk_number,const Sha1CheckSum& crc)
|
||||
bool ftDataMultiplex::recvSingleChunkCRC(const RsPeerId& peerId, const RsFileHash& hash,uint32_t chunk_number,const Sha1CheckSum& crc)
|
||||
{
|
||||
RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/
|
||||
|
||||
@ -425,7 +425,7 @@ bool ftDataMultiplex::recvSingleChunkCRC(const std::string& peerId, const std::s
|
||||
|
||||
// update the cache: get size from the client.
|
||||
|
||||
std::map<std::string, ftClient>::iterator it = mClients.find(hash);
|
||||
std::map<RsFileHash, ftClient>::iterator it = mClients.find(hash);
|
||||
|
||||
if(it == mClients.end())
|
||||
{
|
||||
@ -456,9 +456,9 @@ bool ftDataMultiplex::dispatchReceivedChunkCheckSum()
|
||||
|
||||
uint32_t MAX_CHECKSUM_CHECK_PER_FILE = 25 ;
|
||||
|
||||
for(std::map<std::string,Sha1CacheEntry>::iterator it(_cached_sha1maps.begin());it!=_cached_sha1maps.end();)
|
||||
for(std::map<RsFileHash,Sha1CacheEntry>::iterator it(_cached_sha1maps.begin());it!=_cached_sha1maps.end();)
|
||||
{
|
||||
std::map<std::string, ftClient>::iterator itc = mClients.find(it->first);
|
||||
std::map<RsFileHash, ftClient>::iterator itc = mClients.find(it->first);
|
||||
|
||||
#ifdef MPLEX_DEBUG
|
||||
std::cerr << "ftDataMultiplex::dispatchReceivedChunkCheckSum(): treating hash " << it->first << std::endl;
|
||||
@ -470,7 +470,7 @@ bool ftDataMultiplex::dispatchReceivedChunkCheckSum()
|
||||
std::cerr << "ftDataMultiplex::dispatchReceivedChunkCheckSum() ERROR: No matching Client for hash. This is probably a late answer. Dropping the hash. Hash=" << it->first << std::endl;
|
||||
#endif
|
||||
|
||||
std::map<std::string,Sha1CacheEntry>::iterator tmp(it) ;
|
||||
std::map<RsFileHash,Sha1CacheEntry>::iterator tmp(it) ;
|
||||
++tmp ;
|
||||
_cached_sha1maps.erase(it) ;
|
||||
it = tmp ;
|
||||
@ -503,13 +503,13 @@ bool ftDataMultiplex::dispatchReceivedChunkCheckSum()
|
||||
// - an uploader has sent his chunk map, so we need to store it in the corresponding ftFileProvider
|
||||
// - a source for a download has sent his chunk map, so we need to send it to the corresponding ftFileCreator.
|
||||
//
|
||||
bool ftDataMultiplex::recvChunkMap(const std::string& peerId, const std::string& hash,const CompressedChunkMap& compressed_map,bool client)
|
||||
bool ftDataMultiplex::recvChunkMap(const RsPeerId& peerId, const RsFileHash& hash,const CompressedChunkMap& compressed_map,bool client)
|
||||
{
|
||||
RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/
|
||||
|
||||
if(client) // is the chunk map for a client, or for a server ?
|
||||
{
|
||||
std::map<std::string, ftClient>::iterator it = mClients.find(hash);
|
||||
std::map<RsFileHash, ftClient>::iterator it = mClients.find(hash);
|
||||
|
||||
if(it == mClients.end())
|
||||
{
|
||||
@ -531,7 +531,7 @@ bool ftDataMultiplex::recvChunkMap(const std::string& peerId, const std::string&
|
||||
}
|
||||
else
|
||||
{
|
||||
std::map<std::string, ftFileProvider *>::iterator it = mServers.find(hash) ;
|
||||
std::map<RsFileHash, ftFileProvider *>::iterator it = mServers.find(hash) ;
|
||||
|
||||
if(it == mServers.end())
|
||||
{
|
||||
@ -549,14 +549,14 @@ bool ftDataMultiplex::recvChunkMap(const std::string& peerId, const std::string&
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ftDataMultiplex::handleRecvClientChunkMapRequest(const std::string& peerId, const std::string& hash)
|
||||
bool ftDataMultiplex::handleRecvClientChunkMapRequest(const RsPeerId& peerId, const RsFileHash& hash)
|
||||
{
|
||||
CompressedChunkMap cmap ;
|
||||
|
||||
{
|
||||
RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/
|
||||
|
||||
std::map<std::string, ftClient>::iterator it = mClients.find(hash);
|
||||
std::map<RsFileHash, ftClient>::iterator it = mClients.find(hash);
|
||||
|
||||
if(it == mClients.end())
|
||||
{
|
||||
@ -581,7 +581,7 @@ bool ftDataMultiplex::handleRecvClientChunkMapRequest(const std::string& peerId,
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool ftDataMultiplex::handleRecvChunkCrcRequest(const std::string& peerId, const std::string& hash, uint32_t chunk_number)
|
||||
bool ftDataMultiplex::handleRecvChunkCrcRequest(const RsPeerId& peerId, const RsFileHash& hash, uint32_t chunk_number)
|
||||
{
|
||||
// look into the sha1sum cache
|
||||
|
||||
@ -614,7 +614,7 @@ bool ftDataMultiplex::handleRecvChunkCrcRequest(const std::string& peerId, const
|
||||
return true ;
|
||||
}
|
||||
|
||||
std::map<std::string, ftFileProvider *>::iterator it ;
|
||||
std::map<RsFileHash, ftFileProvider *>::iterator it ;
|
||||
std::string filename ;
|
||||
uint64_t filesize =0;
|
||||
found = true ;
|
||||
@ -705,10 +705,10 @@ bool ftDataMultiplex::handleRecvChunkCrcRequest(const std::string& peerId, const
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool ftDataMultiplex::handleRecvServerChunkMapRequest(const std::string& peerId, const std::string& hash)
|
||||
bool ftDataMultiplex::handleRecvServerChunkMapRequest(const RsPeerId& peerId, const RsFileHash& hash)
|
||||
{
|
||||
CompressedChunkMap cmap ;
|
||||
std::map<std::string, ftFileProvider *>::iterator it ;
|
||||
std::map<RsFileHash, ftFileProvider *>::iterator it ;
|
||||
bool found = true ;
|
||||
|
||||
{
|
||||
@ -754,15 +754,13 @@ bool ftDataMultiplex::handleRecvServerChunkMapRequest(const std::string& peerId,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ftDataMultiplex::handleRecvData(const std::string& peerId,
|
||||
const std::string& hash, uint64_t /*size*/,
|
||||
uint64_t offset, uint32_t chunksize, void *data)
|
||||
bool ftDataMultiplex::handleRecvData(const RsPeerId& peerId, const RsFileHash& hash, uint64_t /*size*/, uint64_t offset, uint32_t chunksize, void *data)
|
||||
{
|
||||
ftTransferModule *transfer_module = NULL ;
|
||||
|
||||
{
|
||||
RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/
|
||||
std::map<std::string, ftClient>::iterator it;
|
||||
std::map<RsFileHash, ftClient>::iterator it;
|
||||
if (mClients.end() == (it = mClients.find(hash)))
|
||||
{
|
||||
#ifdef MPLEX_DEBUG
|
||||
@ -787,12 +785,12 @@ bool ftDataMultiplex::handleRecvData(const std::string& peerId,
|
||||
|
||||
|
||||
/* called by ftTransferModule */
|
||||
bool ftDataMultiplex::handleRecvDataRequest(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize)
|
||||
bool ftDataMultiplex::handleRecvDataRequest(const RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunksize)
|
||||
{
|
||||
/**** Find Files *****/
|
||||
|
||||
RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/
|
||||
std::map<std::string, ftClient>::iterator cit;
|
||||
std::map<RsFileHash, ftClient>::iterator cit;
|
||||
if (mOwnId == peerId)
|
||||
{
|
||||
/* own requests must be passed to Servers */
|
||||
@ -811,7 +809,7 @@ bool ftDataMultiplex::handleRecvDataRequest(const std::string& peerId, const std
|
||||
return true;
|
||||
}
|
||||
|
||||
std::map<std::string, ftFileProvider *>::iterator sit;
|
||||
std::map<RsFileHash, ftFileProvider *>::iterator sit;
|
||||
if (mServers.end() != (sit = mServers.find(hash)))
|
||||
{
|
||||
#ifdef MPLEX_DEBUG
|
||||
@ -833,8 +831,7 @@ bool ftDataMultiplex::handleRecvDataRequest(const std::string& peerId, const std
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ftDataMultiplex::locked_handleServerRequest(ftFileProvider *provider,
|
||||
std::string peerId, std::string hash, uint64_t size,
|
||||
bool ftDataMultiplex::locked_handleServerRequest(ftFileProvider *provider, const RsPeerId& peerId, const RsFileHash& hash, uint64_t size,
|
||||
uint64_t offset, uint32_t chunksize)
|
||||
{
|
||||
if(chunksize > uint32_t(10*1024*1024))
|
||||
@ -875,13 +872,13 @@ bool ftDataMultiplex::locked_handleServerRequest(ftFileProvider *provider,
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ftDataMultiplex::getClientChunkMap(const std::string& upload_hash,const std::string& peerId,CompressedChunkMap& cmap)
|
||||
bool ftDataMultiplex::getClientChunkMap(const RsFileHash& upload_hash,const RsPeerId& peerId,CompressedChunkMap& cmap)
|
||||
{
|
||||
bool too_old = false;
|
||||
{
|
||||
RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/
|
||||
|
||||
std::map<std::string,ftFileProvider *>::iterator sit = mServers.find(upload_hash);
|
||||
std::map<RsFileHash,ftFileProvider *>::iterator sit = mServers.find(upload_hash);
|
||||
|
||||
if(mServers.end() == sit)
|
||||
return false ;
|
||||
@ -897,11 +894,11 @@ bool ftDataMultiplex::getClientChunkMap(const std::string& upload_hash,const std
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool ftDataMultiplex::sendChunkMapRequest(const std::string& peer_id,const std::string& hash,bool is_client)
|
||||
bool ftDataMultiplex::sendChunkMapRequest(const RsPeerId& peer_id,const RsFileHash& hash,bool is_client)
|
||||
{
|
||||
return mDataSend->sendChunkMapRequest(peer_id,hash,is_client);
|
||||
}
|
||||
bool ftDataMultiplex::sendSingleChunkCRCRequests(const std::string& hash, const std::vector<uint32_t>& to_ask)
|
||||
bool ftDataMultiplex::sendSingleChunkCRCRequests(const RsFileHash& hash, const std::vector<uint32_t>& to_ask)
|
||||
{
|
||||
RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/
|
||||
|
||||
@ -933,7 +930,7 @@ void ftDataMultiplex::handlePendingCrcRequests()
|
||||
// With this, only active sources are querried.
|
||||
//
|
||||
|
||||
for(std::map<std::string,Sha1CacheEntry>::iterator it(_cached_sha1maps.begin());it!=_cached_sha1maps.end();++it)
|
||||
for(std::map<RsFileHash,Sha1CacheEntry>::iterator it(_cached_sha1maps.begin());it!=_cached_sha1maps.end();++it)
|
||||
for(std::map<uint32_t,std::pair<time_t,ChunkCheckSumSourceList> >::iterator it2(it->second._to_ask.begin());it2!=it->second._to_ask.end();++it2)
|
||||
if(it2->second.first + MAX_CHECKING_CHUNK_WAIT_DELAY < now) // is the last request old enough?
|
||||
{
|
||||
@ -942,18 +939,18 @@ void ftDataMultiplex::handlePendingCrcRequests()
|
||||
#endif
|
||||
// 0 - ask which sources can be used for this chunk
|
||||
//
|
||||
std::map<std::string,ftClient>::const_iterator it4(mClients.find(it->first)) ;
|
||||
std::map<RsFileHash,ftClient>::const_iterator it4(mClients.find(it->first)) ;
|
||||
|
||||
if(it4 == mClients.end())
|
||||
continue ;
|
||||
|
||||
std::vector<std::string> sources ;
|
||||
std::vector<RsPeerId> sources ;
|
||||
it4->second.mCreator->getSourcesList(it2->first,sources) ;
|
||||
|
||||
// 1 - go through all sources. Take the oldest one.
|
||||
//
|
||||
|
||||
std::string best_source ;
|
||||
RsPeerId best_source ;
|
||||
time_t oldest_timestamp = now ;
|
||||
|
||||
for(uint32_t i=0;i<sources.size();++i)
|
||||
@ -961,7 +958,7 @@ void ftDataMultiplex::handlePendingCrcRequests()
|
||||
#ifdef MPLEX_DEBUG
|
||||
std::cerr << "ftDataMultiplex::handlePendingCrcRequests(): Examining source " << sources[i] << std::endl;
|
||||
#endif
|
||||
std::map<std::string,time_t>::const_iterator it3(it2->second.second.find(sources[i])) ;
|
||||
std::map<RsPeerId,time_t>::const_iterator it3(it2->second.second.find(sources[i])) ;
|
||||
|
||||
if(it3 == it2->second.second.end()) // source not found. So this one is surely the oldest one to have been requested.
|
||||
{
|
||||
@ -984,7 +981,7 @@ void ftDataMultiplex::handlePendingCrcRequests()
|
||||
std::cerr << "ftDataMultiplex::handlePendingCrcRequests(): Source too recently used! So using it directly." << std::endl;
|
||||
#endif
|
||||
}
|
||||
if(best_source != "")
|
||||
if(!best_source.isNull())
|
||||
{
|
||||
#ifdef MPLEX_DEBUG
|
||||
std::cerr << "ftDataMultiplex::handlePendingCrcRequests(): Asking crc of chunk " << it2->first << " to peer " << best_source << " for hash " << it->first << std::endl;
|
||||
@ -1014,7 +1011,7 @@ void ftDataMultiplex::deleteUnusedServers()
|
||||
//scan the uploads list in ftdatamultiplex and delete the items which time out
|
||||
time_t now = time(NULL);
|
||||
|
||||
for(std::map<std::string, ftFileProvider *>::iterator sit(mServers.begin());sit != mServers.end();)
|
||||
for(std::map<RsFileHash, ftFileProvider *>::iterator sit(mServers.begin());sit != mServers.end();)
|
||||
if(sit->second->purgeOldPeers(now,10))
|
||||
{
|
||||
#ifdef MPLEX_DEBUG
|
||||
@ -1033,7 +1030,7 @@ void ftDataMultiplex::deleteUnusedServers()
|
||||
std::cerr << "ftDataMultiplex::deleteUnusedServers(): " << (void*)sit->second << " was not deleted because it's also a file creator." << std::endl ;
|
||||
#endif
|
||||
|
||||
std::map<std::string, ftFileProvider *>::iterator tmp(sit);
|
||||
std::map<RsFileHash, ftFileProvider *>::iterator tmp(sit);
|
||||
++tmp ;
|
||||
|
||||
mServers.erase(sit);
|
||||
@ -1044,7 +1041,7 @@ void ftDataMultiplex::deleteUnusedServers()
|
||||
++sit ;
|
||||
}
|
||||
|
||||
bool ftDataMultiplex::handleSearchRequest(const std::string& peerId, const std::string& hash)
|
||||
bool ftDataMultiplex::handleSearchRequest(const RsPeerId& peerId, const RsFileHash& hash)
|
||||
{
|
||||
#ifdef MPLEX_DEBUG
|
||||
std::cerr << "ftDataMultiplex::handleSearchRequest(";
|
||||
@ -1085,7 +1082,7 @@ bool ftDataMultiplex::handleSearchRequest(const std::string& peerId, const std::
|
||||
std::cerr << "ftDataMultiplex::handleSearchRequest(";
|
||||
std::cerr << " Found Local File, sharing...";
|
||||
#endif
|
||||
std::map<std::string,ftFileProvider*>::const_iterator it = mServers.find(hash) ;
|
||||
std::map<RsFileHash,ftFileProvider*>::const_iterator it = mServers.find(hash) ;
|
||||
ftFileProvider *provider ;
|
||||
|
||||
if(it == mServers.end())
|
||||
@ -1116,7 +1113,7 @@ bool ftDataMultiplex::handleSearchRequest(const std::string& peerId, const std::
|
||||
{
|
||||
RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/
|
||||
|
||||
std::map<std::string,ftClient>::const_iterator it(mClients.find(hash)) ;
|
||||
std::map<RsFileHash,ftClient>::const_iterator it(mClients.find(hash)) ;
|
||||
|
||||
if(it != mClients.end())
|
||||
{
|
||||
|
@ -63,21 +63,21 @@ class ftRequest
|
||||
{
|
||||
public:
|
||||
|
||||
ftRequest(uint32_t type, std::string peerId, std::string hash, uint64_t size, uint64_t offset, uint32_t chunk, void *data);
|
||||
ftRequest(uint32_t type, const RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunk, void *data);
|
||||
|
||||
ftRequest()
|
||||
:mType(0), mSize(0), mOffset(0), mChunk(0), mData(NULL) { return; }
|
||||
|
||||
uint32_t mType;
|
||||
std::string mPeerId;
|
||||
std::string mHash;
|
||||
RsPeerId mPeerId;
|
||||
RsFileHash mHash;
|
||||
uint64_t mSize;
|
||||
uint64_t mOffset;
|
||||
uint32_t mChunk;
|
||||
void *mData;
|
||||
};
|
||||
|
||||
typedef std::map<std::string,time_t> ChunkCheckSumSourceList ;
|
||||
typedef std::map<RsPeerId,time_t> ChunkCheckSumSourceList ;
|
||||
|
||||
class Sha1CacheEntry
|
||||
{
|
||||
@ -93,17 +93,17 @@ class ftDataMultiplex: public ftDataRecv, public RsQueueThread
|
||||
|
||||
public:
|
||||
|
||||
ftDataMultiplex(std::string ownId, ftDataSend *server, ftSearch *search);
|
||||
ftDataMultiplex(const RsPeerId& ownId, ftDataSend *server, ftSearch *search);
|
||||
|
||||
/* ftController Interface */
|
||||
bool addTransferModule(ftTransferModule *mod, ftFileCreator *f);
|
||||
bool removeTransferModule(std::string hash);
|
||||
bool removeTransferModule(const RsFileHash& hash);
|
||||
|
||||
/* data interface */
|
||||
/* get Details of File Transfers */
|
||||
bool FileUploads(std::list<std::string> &hashs);
|
||||
bool FileDownloads(std::list<std::string> &hashs);
|
||||
bool FileDetails(const std::string &hash, FileSearchFlags hintsflag, FileInfo &info);
|
||||
bool FileUploads(std::list<RsFileHash> &hashs);
|
||||
bool FileDownloads(std::list<RsFileHash> &hashs);
|
||||
bool FileDetails(const RsFileHash &hash, FileSearchFlags hintsflag, FileInfo &info);
|
||||
|
||||
void deleteUnusedServers() ;
|
||||
void handlePendingCrcRequests() ;
|
||||
@ -112,39 +112,39 @@ class ftDataMultiplex: public ftDataRecv, public RsQueueThread
|
||||
/*************** SEND INTERFACE (calls ftDataSend) *******************/
|
||||
|
||||
/* Client Send */
|
||||
bool sendDataRequest(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize);
|
||||
bool sendDataRequest(const RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunksize);
|
||||
|
||||
/* Server Send */
|
||||
bool sendData(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data);
|
||||
bool sendData(const RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data);
|
||||
|
||||
/* Server/client Send */
|
||||
bool sendChunkMapRequest(const std::string& peerId, const std::string& hash,bool is_client) ;
|
||||
bool sendChunkMapRequest(const RsPeerId& peerId, const RsFileHash& hash,bool is_client) ;
|
||||
|
||||
|
||||
/* called from a separate thread */
|
||||
bool sendSingleChunkCRCRequests(const std::string& hash, const std::vector<uint32_t>& to_ask) ;
|
||||
bool sendSingleChunkCRCRequests(const RsFileHash& hash, const std::vector<uint32_t>& to_ask) ;
|
||||
|
||||
bool dispatchReceivedChunkCheckSum() ;
|
||||
|
||||
/*************** RECV INTERFACE (provides ftDataRecv) ****************/
|
||||
|
||||
/* Client Recv */
|
||||
virtual bool recvData(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data);
|
||||
virtual bool recvData(const RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data);
|
||||
/* Server Recv */
|
||||
virtual bool recvDataRequest(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize);
|
||||
virtual bool recvDataRequest(const RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunksize);
|
||||
|
||||
/// Receive a request for a chunk map
|
||||
virtual bool recvChunkMapRequest(const std::string& peer_id,const std::string& hash,bool is_client) ;
|
||||
virtual bool recvChunkMapRequest(const RsPeerId& peer_id,const RsFileHash& hash,bool is_client) ;
|
||||
/// Receive a chunk map
|
||||
virtual bool recvChunkMap(const std::string& peer_id,const std::string& hash,const CompressedChunkMap& cmap,bool is_client) ;
|
||||
virtual bool recvChunkMap(const RsPeerId& peer_id,const RsFileHash& hash,const CompressedChunkMap& cmap,bool is_client) ;
|
||||
|
||||
virtual bool recvSingleChunkCRCRequest(const std::string& peer_id,const std::string& hash,uint32_t chunk_id) ;
|
||||
virtual bool recvSingleChunkCRC(const std::string& peer_id,const std::string& hash,uint32_t chunk_id,const Sha1CheckSum& sum) ;
|
||||
virtual bool recvSingleChunkCRCRequest(const RsPeerId& peer_id,const RsFileHash& hash,uint32_t chunk_id) ;
|
||||
virtual bool recvSingleChunkCRC(const RsPeerId& peer_id,const RsFileHash& hash,uint32_t chunk_id,const Sha1CheckSum& sum) ;
|
||||
|
||||
// Returns the chunk map from the file uploading client. Also initiates a chunk map request if this
|
||||
// map is too old. This supposes that the caller will ask again in a few seconds.
|
||||
//
|
||||
bool getClientChunkMap(const std::string& upload_hash,const std::string& peer_id,CompressedChunkMap& map) ;
|
||||
bool getClientChunkMap(const RsFileHash& upload_hash,const RsPeerId& peer_id,CompressedChunkMap& map) ;
|
||||
|
||||
protected:
|
||||
|
||||
@ -155,30 +155,29 @@ class ftDataMultiplex: public ftDataRecv, public RsQueueThread
|
||||
private:
|
||||
|
||||
/* Handling Job Queues */
|
||||
bool handleRecvData(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data);
|
||||
bool handleRecvDataRequest(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize);
|
||||
bool handleSearchRequest(const std::string& peerId, const std::string& hash);
|
||||
bool handleRecvClientChunkMapRequest(const std::string& peerId, const std::string& hash) ;
|
||||
bool handleRecvServerChunkMapRequest(const std::string& peerId, const std::string& hash) ;
|
||||
bool handleRecvChunkCrcRequest(const std::string& peerId, const std::string& hash,uint32_t chunk_id) ;
|
||||
bool handleRecvData(const RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data);
|
||||
bool handleRecvDataRequest(const RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunksize);
|
||||
bool handleSearchRequest(const RsPeerId& peerId, const RsFileHash& hash);
|
||||
bool handleRecvClientChunkMapRequest(const RsPeerId& peerId, const RsFileHash& hash) ;
|
||||
bool handleRecvServerChunkMapRequest(const RsPeerId& peerId, const RsFileHash& hash) ;
|
||||
bool handleRecvChunkCrcRequest(const RsPeerId& peerId, const RsFileHash& hash,uint32_t chunk_id) ;
|
||||
|
||||
/* We end up doing the actual server job here */
|
||||
bool locked_handleServerRequest(ftFileProvider *provider, std::string peerId, std::string hash, uint64_t size, uint64_t offset, uint32_t chunksize);
|
||||
bool locked_handleServerRequest(ftFileProvider *provider, const RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunksize);
|
||||
|
||||
RsMutex dataMtx;
|
||||
|
||||
std::map<std::string, ftClient> mClients;
|
||||
std::map<std::string, ftFileProvider *> mServers;
|
||||
std::map<RsFileHash, ftClient> mClients;
|
||||
std::map<RsFileHash, ftFileProvider *> mServers;
|
||||
|
||||
std::list<ftRequest> mRequestQueue;
|
||||
std::list<ftRequest> mSearchQueue;
|
||||
// std::map<std::string, time_t> mUnknownHashs;
|
||||
|
||||
std::map<std::string,Sha1CacheEntry> _cached_sha1maps ; // one cache entry per file hash. Handled dynamically.
|
||||
std::map<RsFileHash,Sha1CacheEntry> _cached_sha1maps ; // one cache entry per file hash. Handled dynamically.
|
||||
|
||||
ftDataSend *mDataSend;
|
||||
ftSearch *mSearch;
|
||||
std::string mOwnId;
|
||||
RsPeerId mOwnId;
|
||||
|
||||
friend class ftServer;
|
||||
};
|
||||
|
@ -37,7 +37,7 @@ ftFiStore::ftFiStore(CacheStrapper *cs, CacheTransfer *cft, p3PeerMgr *pm,
|
||||
return;
|
||||
}
|
||||
|
||||
bool ftFiStore::search(const std::string &hash, FileSearchFlags hintflags, FileInfo &info) const
|
||||
bool ftFiStore::search(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info) const
|
||||
{
|
||||
/* could use hintflags to specify which bits of fileinfo to use additionally.
|
||||
eg. hintflags & FT_SEARCH_PEER_ID, then only return matching peers + hash.
|
||||
@ -122,17 +122,17 @@ bool ftFiStore::search(const std::string &hash, FileSearchFlags hintflags, FileI
|
||||
}
|
||||
|
||||
|
||||
ftFiMonitor::ftFiMonitor(CacheStrapper *cs,std::string cachedir, std::string pid,const std::string& config_dir)
|
||||
ftFiMonitor::ftFiMonitor(CacheStrapper *cs,std::string cachedir, const RsPeerId& pid,const std::string& config_dir)
|
||||
:FileIndexMonitor(cs,cachedir, pid,config_dir), p3Config(CONFIG_TYPE_FT_SHARED)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bool ftFiMonitor::search(const std::string &hash, FileSearchFlags hintflags, FileInfo &info) const
|
||||
bool ftFiMonitor::search(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info) const
|
||||
{
|
||||
return search(hash,hintflags,"",info) ;
|
||||
return search(hash,hintflags,RsPeerId(),info) ;
|
||||
}
|
||||
bool ftFiMonitor::search(const std::string &hash, FileSearchFlags hintflags, const std::string& peer_id,FileInfo &info) const
|
||||
bool ftFiMonitor::search(const RsFileHash &hash, FileSearchFlags hintflags, const RsPeerId& peer_id,FileInfo &info) const
|
||||
{
|
||||
#ifdef DB_DEBUG
|
||||
std::cerr << "ftFiMonitor::search(" << hash << "," << hintflags;
|
||||
@ -385,7 +385,7 @@ ftCacheStrapper::ftCacheStrapper(p3LinkMgr *lm)
|
||||
}
|
||||
|
||||
/* overloaded search function */
|
||||
bool ftCacheStrapper::search(const std::string &hash, FileSearchFlags hintflags, FileInfo &info) const
|
||||
bool ftCacheStrapper::search(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info) const
|
||||
{
|
||||
/* remove unused parameter warnings */
|
||||
(void) hintflags;
|
||||
|
@ -52,17 +52,17 @@ class ftFiStore: public FileIndexStore, public ftSearch
|
||||
RsPeerId ownid, std::string cachedir);
|
||||
|
||||
/* overloaded search function */
|
||||
virtual bool search(const std::string &hash, FileSearchFlags hintflags, FileInfo &info) const;
|
||||
virtual bool search(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info) const;
|
||||
};
|
||||
|
||||
class ftFiMonitor: public FileIndexMonitor, public ftSearch, public p3Config
|
||||
{
|
||||
public:
|
||||
ftFiMonitor(CacheStrapper *cs,std::string cachedir, std::string pid,const std::string& config_dir);
|
||||
ftFiMonitor(CacheStrapper *cs,std::string cachedir, const RsPeerId& pid,const std::string& config_dir);
|
||||
|
||||
/* overloaded search function */
|
||||
virtual bool search(const std::string &hash, FileSearchFlags hintflags, FileInfo &info) const;
|
||||
virtual bool search(const std::string &hash, FileSearchFlags hintflags, const std::string& peer_id, FileInfo &info) const;
|
||||
virtual bool search(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info) const;
|
||||
virtual bool search(const RsFileHash &hash, FileSearchFlags hintflags, const RsPeerId& peer_id, FileInfo &info) const;
|
||||
|
||||
/* overloaded set dirs enables config indication */
|
||||
virtual void setSharedDirectories(const std::list<SharedDirInfo>& dirList);
|
||||
@ -94,7 +94,7 @@ class ftCacheStrapper: public CacheStrapper, public ftSearch
|
||||
ftCacheStrapper(p3LinkMgr *cm);
|
||||
|
||||
/* overloaded search function */
|
||||
virtual bool search(const std::string &hash, FileSearchFlags hintflags, FileInfo &info) const;
|
||||
virtual bool search(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info) const;
|
||||
|
||||
};
|
||||
|
||||
|
@ -148,7 +148,7 @@ void ftExtraList::hashAFile()
|
||||
* If the File is alreay Hashed, then just add it in.
|
||||
**/
|
||||
|
||||
bool ftExtraList::addExtraFile(std::string path, std::string hash,
|
||||
bool ftExtraList::addExtraFile(std::string path, const RsFileHash& hash,
|
||||
uint64_t size, uint32_t period, TransferRequestFlags flags)
|
||||
{
|
||||
#ifdef DEBUG_ELIST
|
||||
@ -180,7 +180,7 @@ bool ftExtraList::addExtraFile(std::string path, std::string hash,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ftExtraList::removeExtraFile(std::string hash, TransferRequestFlags flags)
|
||||
bool ftExtraList::removeExtraFile(const RsFileHash& hash, TransferRequestFlags flags)
|
||||
{
|
||||
/* remove unused parameter warnings */
|
||||
(void) flags;
|
||||
@ -195,7 +195,7 @@ bool ftExtraList::removeExtraFile(std::string hash, TransferRequestFlags flags)
|
||||
|
||||
RsStackMutex stack(extMutex);
|
||||
|
||||
std::map<std::string, FileDetails>::iterator it;
|
||||
std::map<RsFileHash, FileDetails>::iterator it;
|
||||
it = mFiles.find(hash);
|
||||
if (it == mFiles.end())
|
||||
{
|
||||
@ -209,12 +209,12 @@ bool ftExtraList::removeExtraFile(std::string hash, TransferRequestFlags flags)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ftExtraList::moveExtraFile(std::string fname, std::string hash, uint64_t /*size*/,
|
||||
bool ftExtraList::moveExtraFile(std::string fname, const RsFileHash &hash, uint64_t /*size*/,
|
||||
std::string destpath)
|
||||
{
|
||||
RsStackMutex stack(extMutex);
|
||||
|
||||
std::map<std::string, FileDetails>::iterator it;
|
||||
std::map<RsFileHash, FileDetails>::iterator it;
|
||||
it = mFiles.find(hash);
|
||||
if (it == mFiles.end())
|
||||
{
|
||||
@ -246,10 +246,10 @@ bool ftExtraList::cleanupOldFiles()
|
||||
|
||||
time_t now = time(NULL);
|
||||
|
||||
std::list<std::string> toRemove;
|
||||
std::list<std::string>::iterator rit;
|
||||
std::list<RsFileHash> toRemove;
|
||||
std::list<RsFileHash>::iterator rit;
|
||||
|
||||
std::map<std::string, FileDetails>::iterator it;
|
||||
std::map<RsFileHash, FileDetails>::iterator it;
|
||||
for(it = mFiles.begin(); it != mFiles.end(); it++)
|
||||
{
|
||||
/* check timestamps */
|
||||
@ -317,12 +317,12 @@ bool ftExtraList::hashExtraFileDone(std::string path, FileInfo &info)
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
std::string hash;
|
||||
RsFileHash hash;
|
||||
{
|
||||
/* Find in the path->hash map */
|
||||
RsStackMutex stack(extMutex);
|
||||
|
||||
std::map<std::string, std::string>::iterator it;
|
||||
std::map<std::string, RsFileHash>::iterator it;
|
||||
if (mHashedList.end() == (it = mHashedList.find(path)))
|
||||
{
|
||||
return false;
|
||||
@ -336,7 +336,7 @@ bool ftExtraList::hashExtraFileDone(std::string path, FileInfo &info)
|
||||
* Search Function - used by File Transfer
|
||||
*
|
||||
**/
|
||||
bool ftExtraList::search(const std::string &hash, FileSearchFlags /*hintflags*/, FileInfo &info) const
|
||||
bool ftExtraList::search(const RsFileHash &hash, FileSearchFlags /*hintflags*/, FileInfo &info) const
|
||||
{
|
||||
|
||||
#ifdef DEBUG_ELIST
|
||||
@ -345,7 +345,7 @@ bool ftExtraList::search(const std::string &hash, FileSearchFlags /*hintflags
|
||||
#endif
|
||||
|
||||
/* find hash */
|
||||
std::map<std::string, FileDetails>::const_iterator fit;
|
||||
std::map<RsFileHash, FileDetails>::const_iterator fit;
|
||||
if (mFiles.end() == (fit = mFiles.find(hash)))
|
||||
{
|
||||
return false;
|
||||
@ -397,7 +397,7 @@ bool ftExtraList::saveList(bool &cleanup, std::list<RsItem *>& sList)
|
||||
RsStackMutex stack(extMutex);
|
||||
|
||||
|
||||
std::map<std::string, FileDetails>::const_iterator it;
|
||||
std::map<RsFileHash, FileDetails>::const_iterator it;
|
||||
for(it = mFiles.begin(); it != mFiles.end(); it++)
|
||||
{
|
||||
RsFileConfigItem *fi = new RsFileConfigItem();
|
||||
|
@ -90,7 +90,7 @@ class FileDetails
|
||||
std::list<std::string> sources;
|
||||
std::string path;
|
||||
std::string fname;
|
||||
std::string hash;
|
||||
RsFileHash hash;
|
||||
uint64_t size;
|
||||
#endif
|
||||
|
||||
@ -117,11 +117,11 @@ class ftExtraList: public RsThread, public p3Config, public ftSearch
|
||||
* If the File is alreay Hashed, then just add it in.
|
||||
**/
|
||||
|
||||
bool addExtraFile(std::string path, std::string hash,
|
||||
bool addExtraFile(std::string path, const RsFileHash &hash,
|
||||
uint64_t size, uint32_t period, TransferRequestFlags flags);
|
||||
|
||||
bool removeExtraFile(std::string hash, TransferRequestFlags flags);
|
||||
bool moveExtraFile(std::string fname, std::string hash, uint64_t size,
|
||||
bool removeExtraFile(const RsFileHash& hash, TransferRequestFlags flags);
|
||||
bool moveExtraFile(std::string fname, const RsFileHash& hash, uint64_t size,
|
||||
std::string destpath);
|
||||
|
||||
|
||||
@ -138,7 +138,7 @@ bool hashExtraFileDone(std::string path, FileInfo &info);
|
||||
* implementation of ftSearch.
|
||||
*
|
||||
**/
|
||||
virtual bool search(const std::string &hash, FileSearchFlags hintflags, FileInfo &info) const;
|
||||
virtual bool search(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info) const;
|
||||
|
||||
/***
|
||||
* Thread Main Loop
|
||||
@ -165,8 +165,8 @@ bool cleanupEntry(std::string path, TransferRequestFlags flags);
|
||||
|
||||
std::list<FileDetails> mToHash;
|
||||
|
||||
std::map<std::string, std::string> mHashedList; /* path -> hash ( not saved ) */
|
||||
std::map<std::string, FileDetails> mFiles;
|
||||
std::map<std::string, RsFileHash> mHashedList; /* path -> hash ( not saved ) */
|
||||
std::map<RsFileHash, FileDetails> mFiles;
|
||||
};
|
||||
|
||||
|
||||
|
@ -24,7 +24,7 @@
|
||||
*
|
||||
***********************************************************/
|
||||
|
||||
ftFileCreator::ftFileCreator(const std::string& path, uint64_t size, const std::string& hash,bool assume_availability)
|
||||
ftFileCreator::ftFileCreator(const std::string& path, uint64_t size, const RsFileHash& hash,bool assume_availability)
|
||||
: ftFileProvider(path,size,hash), chunkMap(size,assume_availability)
|
||||
{
|
||||
/*
|
||||
@ -65,7 +65,7 @@ ftFileCreator::ftFileCreator(const std::string& path, uint64_t size, const std::
|
||||
#endif
|
||||
}
|
||||
|
||||
bool ftFileCreator::getFileData(const std::string& peer_id,uint64_t offset, uint32_t &chunk_size, void *data)
|
||||
bool ftFileCreator::getFileData(const RsPeerId& peer_id,uint64_t offset, uint32_t &chunk_size, void *data)
|
||||
{
|
||||
// Only send the data if we actually have it.
|
||||
//
|
||||
@ -243,7 +243,7 @@ void ftFileCreator::removeInactiveChunks()
|
||||
#endif
|
||||
}
|
||||
|
||||
void ftFileCreator::removeFileSource(const std::string& peer_id)
|
||||
void ftFileCreator::removeFileSource(const RsPeerId& peer_id)
|
||||
{
|
||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||
#ifdef FILE_DEBUG
|
||||
@ -456,7 +456,7 @@ void ftFileCreator::setChunkStrategy(FileChunksInfo::ChunkStrategy s)
|
||||
* But can return size = 0, if we are still waiting for the data.
|
||||
*/
|
||||
|
||||
bool ftFileCreator::getMissingChunk(const std::string& peer_id,uint32_t size_hint,uint64_t &offset, uint32_t& size,bool& source_chunk_map_needed)
|
||||
bool ftFileCreator::getMissingChunk(const RsPeerId& peer_id,uint32_t size_hint,uint64_t &offset, uint32_t& size,bool& source_chunk_map_needed)
|
||||
{
|
||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||
#ifdef FILE_DEBUG
|
||||
@ -559,7 +559,7 @@ bool ftFileCreator::locked_printChunkMap()
|
||||
std::cerr << " " << it->second << std::endl ;
|
||||
|
||||
std::cerr << "Active chunks per peer:" << std::endl ;
|
||||
for(std::map<std::string,ZeroInitCounter>::const_iterator it(mChunksPerPeer.begin());it!=mChunksPerPeer.end();++it)
|
||||
for(std::map<RsPeerId,ZeroInitCounter>::const_iterator it(mChunksPerPeer.begin());it!=mChunksPerPeer.end();++it)
|
||||
std::cerr << " " << it->first << "\t: " << it->second.cnt << std::endl;
|
||||
|
||||
return true;
|
||||
@ -586,14 +586,14 @@ void ftFileCreator::getAvailabilityMap(CompressedChunkMap& map)
|
||||
chunkMap.getAvailabilityMap(map) ;
|
||||
}
|
||||
|
||||
bool ftFileCreator::sourceIsComplete(const std::string& peer_id)
|
||||
bool ftFileCreator::sourceIsComplete(const RsPeerId& peer_id)
|
||||
{
|
||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||
|
||||
return chunkMap.getSourceChunksInfo(peer_id)->is_full ;
|
||||
}
|
||||
|
||||
void ftFileCreator::setSourceMap(const std::string& peer_id,const CompressedChunkMap& compressed_map)
|
||||
void ftFileCreator::setSourceMap(const RsPeerId& peer_id,const CompressedChunkMap& compressed_map)
|
||||
{
|
||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||
|
||||
@ -617,7 +617,7 @@ bool ftFileCreator::finished()
|
||||
return chunkMap.isComplete() ;
|
||||
}
|
||||
|
||||
bool ftFileCreator::hashReceivedData(std::string& hash)
|
||||
bool ftFileCreator::hashReceivedData(RsFileHash& hash)
|
||||
{
|
||||
#ifdef FILE_DEBUG
|
||||
std::cerr << "file creator asked for hashing received data " << file_name << std::endl;
|
||||
@ -646,7 +646,7 @@ void ftFileCreator::forceCheck()
|
||||
chunkMap.forceCheck();
|
||||
}
|
||||
|
||||
void ftFileCreator::getSourcesList(uint32_t chunk_num,std::vector<std::string>& sources)
|
||||
void ftFileCreator::getSourcesList(uint32_t chunk_num,std::vector<RsPeerId>& sources)
|
||||
{
|
||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||
|
||||
|
@ -47,12 +47,12 @@ class ftFileCreator: public ftFileProvider
|
||||
{
|
||||
public:
|
||||
|
||||
ftFileCreator(const std::string& savepath, uint64_t size, const std::string& hash,bool assume_availability);
|
||||
ftFileCreator(const std::string& savepath, uint64_t size, const RsFileHash& hash,bool assume_availability);
|
||||
|
||||
~ftFileCreator();
|
||||
|
||||
/* overloaded from FileProvider */
|
||||
virtual bool getFileData(const std::string& peer_id,uint64_t offset, uint32_t &chunk_size, void *data);
|
||||
virtual bool getFileData(const RsPeerId& peer_id,uint64_t offset, uint32_t &chunk_size, void *data);
|
||||
bool finished() ;
|
||||
uint64_t getRecvd();
|
||||
|
||||
@ -69,7 +69,7 @@ class ftFileCreator: public ftFileProvider
|
||||
// long time. Therefore, we must pay attention not to call this function
|
||||
// at a time file_name nor hash can be modified, which is quite easy.
|
||||
|
||||
bool hashReceivedData(std::string& hash) ;
|
||||
bool hashReceivedData(RsFileHash& hash) ;
|
||||
|
||||
// Sets all chunks to checking state
|
||||
//
|
||||
@ -91,7 +91,7 @@ class ftFileCreator: public ftFileProvider
|
||||
// - no chunkmap info is available. In such a case, the chunk info is irrelevant and false is returned.
|
||||
// - the chunk info is too old. In tis case, true is returned, and the chunks info can be used.
|
||||
//
|
||||
bool getMissingChunk(const std::string& peer_id,uint32_t size_hint,uint64_t& offset, uint32_t& size,bool& is_chunk_map_too_old);
|
||||
bool getMissingChunk(const RsPeerId& peer_id,uint32_t size_hint,uint64_t& offset, uint32_t& size,bool& is_chunk_map_too_old);
|
||||
|
||||
// Takes care of purging any inactive chunks. This should be called regularly, because some peers may disconnect
|
||||
// and let inactive chunks not finished.
|
||||
@ -99,11 +99,11 @@ class ftFileCreator: public ftFileProvider
|
||||
void removeInactiveChunks() ;
|
||||
|
||||
// removes the designated file source from the chunkmap.
|
||||
void removeFileSource(const std::string& peer_id) ;
|
||||
void removeFileSource(const RsPeerId& peer_id) ;
|
||||
|
||||
// Get all available sources for this chunk
|
||||
//
|
||||
void getSourcesList(uint32_t chunk_number,std::vector<std::string>& sources) ;
|
||||
void getSourcesList(uint32_t chunk_number,std::vector<RsPeerId>& sources) ;
|
||||
|
||||
// Returns resets the time stamp of the last data receive.
|
||||
time_t lastRecvTimeStamp() ;
|
||||
@ -124,11 +124,11 @@ class ftFileCreator: public ftFileProvider
|
||||
|
||||
// This is called when receiving the availability map from a source peer, for the file being handled.
|
||||
//
|
||||
void setSourceMap(const std::string& peer_id,const CompressedChunkMap& map) ;
|
||||
void setSourceMap(const RsPeerId& peer_id,const CompressedChunkMap& map) ;
|
||||
|
||||
// Returns true id the given file source is complete.
|
||||
//
|
||||
bool sourceIsComplete(const std::string& peer_id) ;
|
||||
bool sourceIsComplete(const RsPeerId& peer_id) ;
|
||||
|
||||
protected:
|
||||
|
||||
@ -146,7 +146,7 @@ class ftFileCreator: public ftFileProvider
|
||||
uint64_t mEnd;
|
||||
|
||||
std::map<uint64_t, ftChunk> mChunks;
|
||||
std::map<std::string,ZeroInitCounter> mChunksPerPeer ;
|
||||
std::map<RsPeerId,ZeroInitCounter> mChunksPerPeer ;
|
||||
|
||||
ChunkMap chunkMap ;
|
||||
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
static const time_t UPLOAD_CHUNK_MAPS_TIME = 20 ; // time to ask for a new chunkmap from uploaders in seconds.
|
||||
|
||||
ftFileProvider::ftFileProvider(const std::string& path, uint64_t size, const std::string& hash)
|
||||
ftFileProvider::ftFileProvider(const std::string& path, uint64_t size, const RsFileHash& hash)
|
||||
: mSize(size), hash(hash), file_name(path), fd(NULL), ftcMutex("ftFileProvider")
|
||||
{
|
||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||
@ -53,7 +53,7 @@ bool ftFileProvider::fileOk()
|
||||
return (fd != NULL);
|
||||
}
|
||||
|
||||
std::string ftFileProvider::getHash()
|
||||
RsFileHash ftFileProvider::getHash()
|
||||
{
|
||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||
return hash;
|
||||
@ -80,7 +80,7 @@ bool ftFileProvider::FileDetails(FileInfo &info)
|
||||
info.peers.clear() ;
|
||||
float total_transfer_rate = 0.0f ;
|
||||
|
||||
for(std::map<std::string,PeerUploadInfo>::const_iterator it(uploading_peers.begin());it!=uploading_peers.end();++it)
|
||||
for(std::map<RsPeerId,PeerUploadInfo>::const_iterator it(uploading_peers.begin());it!=uploading_peers.end();++it)
|
||||
{
|
||||
TransferInfo inf ;
|
||||
inf.peerId = it->first ;
|
||||
@ -109,13 +109,13 @@ bool ftFileProvider::purgeOldPeers(time_t now,uint32_t max_duration)
|
||||
std::cerr << "ftFileProvider::purgeOldPeers(): " << (void*)this << ": examining peers." << std::endl ;
|
||||
#endif
|
||||
bool ret = true ;
|
||||
for(std::map<std::string,PeerUploadInfo>::iterator it(uploading_peers.begin());it!=uploading_peers.end();)
|
||||
for(std::map<RsPeerId,PeerUploadInfo>::iterator it(uploading_peers.begin());it!=uploading_peers.end();)
|
||||
if( (*it).second.lastTS+max_duration < (uint32_t)now)
|
||||
{
|
||||
#ifdef DEBUG_FT_FILE_PROVIDER
|
||||
std::cerr << "ftFileProvider::purgeOldPeers(): " << (void*)this << ": peer " << it->first << " is too old. Removing." << std::endl ;
|
||||
#endif
|
||||
std::map<std::string,PeerUploadInfo>::iterator tmp = it ;
|
||||
std::map<RsPeerId,PeerUploadInfo>::iterator tmp = it ;
|
||||
++tmp ;
|
||||
uploading_peers.erase(it) ;
|
||||
it=tmp ;
|
||||
@ -139,7 +139,7 @@ void ftFileProvider::getAvailabilityMap(CompressedChunkMap& cmap)
|
||||
}
|
||||
|
||||
|
||||
bool ftFileProvider::getFileData(const std::string& peer_id,uint64_t offset, uint32_t &chunk_size, void *data)
|
||||
bool ftFileProvider::getFileData(const RsPeerId& peer_id,uint64_t offset, uint32_t &chunk_size, void *data)
|
||||
{
|
||||
/* dodgey checking outside of mutex...
|
||||
* much check again inside FileAttrs().
|
||||
@ -250,7 +250,7 @@ void ftFileProvider::PeerUploadInfo::updateStatus(uint64_t offset,uint32_t data_
|
||||
total_size += req_size ;
|
||||
}
|
||||
|
||||
void ftFileProvider::setClientMap(const std::string& peer_id,const CompressedChunkMap& cmap)
|
||||
void ftFileProvider::setClientMap(const RsPeerId& peer_id,const CompressedChunkMap& cmap)
|
||||
{
|
||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||
|
||||
@ -259,7 +259,7 @@ void ftFileProvider::setClientMap(const std::string& peer_id,const CompressedChu
|
||||
uploading_peers[peer_id].client_chunk_map_stamp = time(NULL) ;
|
||||
}
|
||||
|
||||
void ftFileProvider::getClientMap(const std::string& peer_id,CompressedChunkMap& cmap,bool& map_is_too_old)
|
||||
void ftFileProvider::getClientMap(const RsPeerId& peer_id,CompressedChunkMap& cmap,bool& map_is_too_old)
|
||||
{
|
||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||
|
||||
|
@ -38,12 +38,12 @@
|
||||
class ftFileProvider
|
||||
{
|
||||
public:
|
||||
ftFileProvider(const std::string& path, uint64_t size, const std::string& hash);
|
||||
ftFileProvider(const std::string& path, uint64_t size, const RsFileHash& hash);
|
||||
virtual ~ftFileProvider();
|
||||
|
||||
virtual bool getFileData(const std::string& peer_id,uint64_t offset, uint32_t &chunk_size, void *data);
|
||||
virtual bool getFileData(const RsPeerId& peer_id,uint64_t offset, uint32_t &chunk_size, void *data);
|
||||
virtual bool FileDetails(FileInfo &info);
|
||||
std::string getHash();
|
||||
RsFileHash getHash();
|
||||
uint64_t getFileSize();
|
||||
bool fileOk();
|
||||
|
||||
@ -54,21 +54,21 @@ class ftFileProvider
|
||||
virtual void getAvailabilityMap(CompressedChunkMap& cmap) ;
|
||||
|
||||
// a ftFileProvider feeds a distant peer. To display what the peers already has, we need to store/read this info.
|
||||
void getClientMap(const std::string& peer_id,CompressedChunkMap& cmap,bool& map_is_too_old) ;
|
||||
void setClientMap(const std::string& peer_id,const CompressedChunkMap& cmap) ;
|
||||
void getClientMap(const RsPeerId& peer_id,CompressedChunkMap& cmap,bool& map_is_too_old) ;
|
||||
void setClientMap(const RsPeerId& peer_id,const CompressedChunkMap& cmap) ;
|
||||
|
||||
// Removes inactive peers from the client list. Returns true if all peers have been removed.
|
||||
//
|
||||
bool purgeOldPeers(time_t now,uint32_t max_duration) ;
|
||||
|
||||
const std::string& fileHash() const { return hash ; }
|
||||
const RsFileHash& fileHash() const { return hash ; }
|
||||
const std::string& fileName() const { return file_name ; }
|
||||
uint64_t fileSize() const { return mSize ; }
|
||||
protected:
|
||||
virtual int initializeFileAttrs(); /* does for both */
|
||||
|
||||
uint64_t mSize;
|
||||
std::string hash;
|
||||
RsFileHash hash;
|
||||
std::string file_name;
|
||||
FILE *fd;
|
||||
|
||||
@ -100,7 +100,7 @@ class ftFileProvider
|
||||
|
||||
// Contains statistics (speed, peer name, etc.) of all uploading peers for that file.
|
||||
//
|
||||
std::map<std::string,PeerUploadInfo> uploading_peers ;
|
||||
std::map<RsPeerId,PeerUploadInfo> uploading_peers ;
|
||||
|
||||
/*
|
||||
* Mutex Required for stuff below
|
||||
|
@ -75,7 +75,7 @@ bool ftFileSearch::addSearchMode(ftSearch *search, FileSearchFlags hintflags)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ftFileSearch::search(const std::string &hash, FileSearchFlags hintflags, FileInfo &info) const
|
||||
bool ftFileSearch::search(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info) const
|
||||
{
|
||||
uint32_t hints, i;
|
||||
|
||||
|
@ -45,7 +45,7 @@ class ftFileSearch: public ftSearch
|
||||
ftFileSearch();
|
||||
|
||||
bool addSearchMode(ftSearch *search, FileSearchFlags hintflags);
|
||||
virtual bool search(const std::string &hash, FileSearchFlags hintflags, FileInfo &info) const;
|
||||
virtual bool search(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info) const;
|
||||
|
||||
private:
|
||||
|
||||
|
@ -42,12 +42,12 @@ class ftSearch
|
||||
public:
|
||||
ftSearch() { return; }
|
||||
virtual ~ftSearch() { return; }
|
||||
virtual bool search(const std::string & /*hash*/, FileSearchFlags /*hintflags*/,const std::string& /*peer_id*/, FileInfo & /*info*/) const
|
||||
virtual bool search(const RsFileHash & /*hash*/, FileSearchFlags /*hintflags*/,const RsPeerId& /*peer_id*/, FileInfo & /*info*/) const
|
||||
{
|
||||
std::cerr << "Non overloaded search method called!!!" << std::endl;
|
||||
return false;
|
||||
}
|
||||
virtual bool search(const std::string &hash, FileSearchFlags hintflags, FileInfo &info) const = 0;
|
||||
virtual bool search(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info) const = 0;
|
||||
|
||||
};
|
||||
|
||||
|
@ -102,12 +102,14 @@ void ftServer::addConfigComponents(p3ConfigMgr */*mgr*/)
|
||||
/* NOT SURE ABOUT THIS ONE */
|
||||
}
|
||||
|
||||
std::string ftServer::OwnId()
|
||||
const RsPeerId& ftServer::OwnId()
|
||||
{
|
||||
std::string ownId;
|
||||
static RsPeerId null_id ;
|
||||
|
||||
if (mLinkMgr)
|
||||
ownId = mLinkMgr->getOwnId();
|
||||
return ownId;
|
||||
return mLinkMgr->getOwnId();
|
||||
else
|
||||
return null_id ;
|
||||
}
|
||||
|
||||
/* Final Setup (once everything is assigned) */
|
||||
@ -117,7 +119,7 @@ void ftServer::SetupFtServer()
|
||||
/* setup FiStore/Monitor */
|
||||
std::string localcachedir = mConfigPath + "/cache/local";
|
||||
std::string remotecachedir = mConfigPath + "/cache/remote";
|
||||
std::string ownId = mLinkMgr->getOwnId();
|
||||
RsPeerId ownId = mLinkMgr->getOwnId();
|
||||
|
||||
/* search/extras List */
|
||||
mFtExtra = new ftExtraList();
|
||||
@ -239,38 +241,23 @@ bool ftServer::ResumeTransfers()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ftServer::checkHash(const std::string& hash,std::string& error_string)
|
||||
bool ftServer::checkHash(const RsFileHash& hash,std::string& error_string)
|
||||
{
|
||||
static const uint32_t HASH_LENGTH = 40 ;
|
||||
|
||||
if(hash.length() != HASH_LENGTH)
|
||||
{
|
||||
rs_sprintf(error_string, "Line too long : %u chars, %ld expected.", hash.length(), HASH_LENGTH) ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
for(uint32_t i=0;i<hash.length();++i)
|
||||
if(!((hash[i] > 47 && hash[i] < 58) || (hash[i] > 96 && hash[i] < 103)))
|
||||
{
|
||||
rs_sprintf(error_string, "unexpected char code=%d '%c'", (int)hash[i], hash[i]) ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
return true ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool ftServer::alreadyHaveFile(const std::string& hash, FileInfo &info)
|
||||
bool ftServer::alreadyHaveFile(const RsFileHash& hash, FileInfo &info)
|
||||
{
|
||||
return mFtController->alreadyHaveFile(hash, info);
|
||||
}
|
||||
|
||||
bool ftServer::FileRequest(const std::string& fname, const std::string& hash, uint64_t size, const std::string& dest, TransferRequestFlags flags, const std::list<std::string>& srcIds)
|
||||
bool ftServer::FileRequest(const std::string& fname, const RsFileHash& hash, uint64_t size, const std::string& dest, TransferRequestFlags flags, const std::list<RsPeerId>& srcIds)
|
||||
{
|
||||
std::string error_string ;
|
||||
|
||||
if(!checkHash(hash,error_string))
|
||||
{
|
||||
RsServer::notify()->notifyErrorMsg(0,0,"Error handling hash \""+hash+"\". This hash appears to be invalid(Error string=\""+error_string+"\"). This is probably due an bad handling of strings.") ;
|
||||
RsServer::notify()->notifyErrorMsg(0,0,"Error handling hash \""+hash.toStdString()+"\". This hash appears to be invalid(Error string=\""+error_string+"\"). This is probably due an bad handling of strings.") ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
@ -282,15 +269,15 @@ bool ftServer::FileRequest(const std::string& fname, const std::string& hash, ui
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool ftServer::setDestinationName(const std::string& hash,const std::string& name)
|
||||
bool ftServer::setDestinationName(const RsFileHash& hash,const std::string& name)
|
||||
{
|
||||
return mFtController->setDestinationName(hash,name);
|
||||
}
|
||||
bool ftServer::setDestinationDirectory(const std::string& hash,const std::string& directory)
|
||||
bool ftServer::setDestinationDirectory(const RsFileHash& hash,const std::string& directory)
|
||||
{
|
||||
return mFtController->setDestinationDirectory(hash,directory);
|
||||
}
|
||||
bool ftServer::setChunkStrategy(const std::string& hash,FileChunksInfo::ChunkStrategy s)
|
||||
bool ftServer::setChunkStrategy(const RsFileHash& hash,FileChunksInfo::ChunkStrategy s)
|
||||
{
|
||||
return mFtController->setChunkStrategy(hash,s);
|
||||
}
|
||||
@ -310,7 +297,7 @@ FileChunksInfo::ChunkStrategy ftServer::defaultChunkStrategy()
|
||||
{
|
||||
return mFtController->defaultChunkStrategy() ;
|
||||
}
|
||||
bool ftServer::FileCancel(const std::string& hash)
|
||||
bool ftServer::FileCancel(const RsFileHash& hash)
|
||||
{
|
||||
// Remove from both queue and ftController, by default.
|
||||
//
|
||||
@ -319,7 +306,7 @@ bool ftServer::FileCancel(const std::string& hash)
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool ftServer::FileControl(const std::string& hash, uint32_t flags)
|
||||
bool ftServer::FileControl(const RsFileHash& hash, uint32_t flags)
|
||||
{
|
||||
return mFtController->FileControl(hash, flags);
|
||||
}
|
||||
@ -345,17 +332,17 @@ uint32_t ftServer::getQueueSize()
|
||||
return mFtController->getQueueSize() ;
|
||||
}
|
||||
/* Control of Downloads Priority. */
|
||||
bool ftServer::changeQueuePosition(const std::string hash, QueueMove mv)
|
||||
bool ftServer::changeQueuePosition(const RsFileHash& hash, QueueMove mv)
|
||||
{
|
||||
mFtController->moveInQueue(hash,mv) ;
|
||||
return true ;
|
||||
}
|
||||
bool ftServer::changeDownloadSpeed(const std::string hash, int speed)
|
||||
bool ftServer::changeDownloadSpeed(const RsFileHash& hash, int speed)
|
||||
{
|
||||
mFtController->setPriority(hash, (DwlSpeed)speed);
|
||||
return true ;
|
||||
}
|
||||
bool ftServer::getDownloadSpeed(const std::string hash, int & speed)
|
||||
bool ftServer::getDownloadSpeed(const RsFileHash& hash, int & speed)
|
||||
{
|
||||
DwlSpeed _speed;
|
||||
int ret = mFtController->getPriority(hash, _speed);
|
||||
@ -364,12 +351,12 @@ bool ftServer::getDownloadSpeed(const std::string hash, int & speed)
|
||||
|
||||
return ret;
|
||||
}
|
||||
bool ftServer::clearDownload(const std::string /*hash*/)
|
||||
bool ftServer::clearDownload(const RsFileHash& /*hash*/)
|
||||
{
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool ftServer::FileDownloadChunksDetails(const std::string& hash,FileChunksInfo& info)
|
||||
bool ftServer::FileDownloadChunksDetails(const RsFileHash& hash,FileChunksInfo& info)
|
||||
{
|
||||
return mFtController->getFileDownloadChunksDetails(hash,info);
|
||||
}
|
||||
@ -400,24 +387,24 @@ std::string ftServer::getPartialsDirectory()
|
||||
/************************* Other Access ************************/
|
||||
/***************************************************************/
|
||||
|
||||
bool ftServer::FileDownloads(std::list<std::string> &hashs)
|
||||
bool ftServer::FileDownloads(std::list<RsFileHash> &hashs)
|
||||
{
|
||||
return mFtController->FileDownloads(hashs);
|
||||
/* this only contains downloads.... not completed */
|
||||
//return mFtDataplex->FileDownloads(hashs);
|
||||
}
|
||||
|
||||
bool ftServer::FileUploadChunksDetails(const std::string& hash,const std::string& peer_id,CompressedChunkMap& cmap)
|
||||
bool ftServer::FileUploadChunksDetails(const RsFileHash& hash,const RsPeerId& peer_id,CompressedChunkMap& cmap)
|
||||
{
|
||||
return mFtDataplex->getClientChunkMap(hash,peer_id,cmap);
|
||||
}
|
||||
|
||||
bool ftServer::FileUploads(std::list<std::string> &hashs)
|
||||
bool ftServer::FileUploads(std::list<RsFileHash> &hashs)
|
||||
{
|
||||
return mFtDataplex->FileUploads(hashs);
|
||||
}
|
||||
|
||||
bool ftServer::FileDetails(const std::string &hash, FileSearchFlags hintflags, FileInfo &info)
|
||||
bool ftServer::FileDetails(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info)
|
||||
{
|
||||
if (hintflags & RS_FILE_HINTS_DOWNLOAD)
|
||||
if(mFtController->FileDetails(hash, info))
|
||||
@ -481,7 +468,7 @@ void ftServer::removeVirtualPeer(const TurtleFileHash& hash,const TurtleVirtualP
|
||||
mFtController->removeFileSource(hash,virtual_peer_id) ;
|
||||
}
|
||||
|
||||
bool ftServer::handleTunnelRequest(const std::string& hash,const std::string& peer_id)
|
||||
bool ftServer::handleTunnelRequest(const RsFileHash& hash,const RsPeerId& peer_id)
|
||||
{
|
||||
FileInfo info ;
|
||||
bool res = FileDetails(hash, RS_FILE_HINTS_NETWORK_WIDE | RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_SPEC_ONLY | RS_FILE_HINTS_DOWNLOAD, info);
|
||||
@ -513,13 +500,13 @@ bool ftServer::handleTunnelRequest(const std::string& hash,const std::string& pe
|
||||
/******************* ExtraFileList Access **********************/
|
||||
/***************************************************************/
|
||||
|
||||
bool ftServer::ExtraFileAdd(std::string fname, std::string hash, uint64_t size,
|
||||
bool ftServer::ExtraFileAdd(std::string fname, const RsFileHash& hash, uint64_t size,
|
||||
uint32_t period, TransferRequestFlags flags)
|
||||
{
|
||||
return mFtExtra->addExtraFile(fname, hash, size, period, flags);
|
||||
}
|
||||
|
||||
bool ftServer::ExtraFileRemove(std::string hash, TransferRequestFlags flags)
|
||||
bool ftServer::ExtraFileRemove(const RsFileHash& hash, TransferRequestFlags flags)
|
||||
{
|
||||
return mFtExtra->removeExtraFile(hash, flags);
|
||||
}
|
||||
@ -534,7 +521,7 @@ bool ftServer::ExtraFileStatus(std::string localpath, FileInfo &info)
|
||||
return mFtExtra->hashExtraFileDone(localpath, info);
|
||||
}
|
||||
|
||||
bool ftServer::ExtraFileMove(std::string fname, std::string hash, uint64_t size,
|
||||
bool ftServer::ExtraFileMove(std::string fname, const RsFileHash& hash, uint64_t size,
|
||||
std::string destpath)
|
||||
{
|
||||
return mFtExtra->moveExtraFile(fname, hash, size, destpath);
|
||||
@ -545,7 +532,7 @@ bool ftServer::ExtraFileMove(std::string fname, std::string hash, uint64_t size,
|
||||
/******************** Directory Listing ************************/
|
||||
/***************************************************************/
|
||||
|
||||
int ftServer::RequestDirDetails(const std::string& uid, const std::string& path, DirDetails &details)
|
||||
int ftServer::RequestDirDetails(const RsPeerId& uid, const std::string& path, DirDetails &details)
|
||||
{
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << "ftServer::RequestDirDetails(uid:" << uid;
|
||||
@ -610,12 +597,12 @@ uint32_t ftServer::getType(void *ref, FileSearchFlags flags)
|
||||
int ftServer::SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags)
|
||||
{
|
||||
if(flags & RS_FILE_HINTS_LOCAL)
|
||||
return mFiMon->SearchKeywords(keywords, results,flags,"");
|
||||
return mFiMon->SearchKeywords(keywords, results,flags,RsPeerId());
|
||||
else
|
||||
return mFiStore->SearchKeywords(keywords, results,flags);
|
||||
return 0 ;
|
||||
}
|
||||
int ftServer::SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags,const std::string& peer_id)
|
||||
int ftServer::SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags,const RsPeerId& peer_id)
|
||||
{
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << "ftServer::SearchKeywords()";
|
||||
@ -637,12 +624,12 @@ int ftServer::SearchKeywords(std::list<std::string> keywords, std::list<DirDetai
|
||||
int ftServer::SearchBoolExp(Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags)
|
||||
{
|
||||
if(flags & RS_FILE_HINTS_LOCAL)
|
||||
return mFiMon->SearchBoolExp(exp,results,flags,"") ;
|
||||
return mFiMon->SearchBoolExp(exp,results,flags,RsPeerId()) ;
|
||||
else
|
||||
return mFiStore->searchBoolExp(exp, results);
|
||||
return 0 ;
|
||||
}
|
||||
int ftServer::SearchBoolExp(Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags,const std::string& peer_id)
|
||||
int ftServer::SearchBoolExp(Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags,const RsPeerId& peer_id)
|
||||
{
|
||||
if(flags & RS_FILE_HINTS_LOCAL)
|
||||
return mFiMon->SearchBoolExp(exp,results,flags,peer_id) ;
|
||||
@ -870,7 +857,7 @@ bool ftServer::loadConfigMap(std::map<std::string, std::string> &/*configMap*/)
|
||||
/***************************************************************/
|
||||
|
||||
/* Client Send */
|
||||
bool ftServer::sendDataRequest(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize)
|
||||
bool ftServer::sendDataRequest(const RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunksize)
|
||||
{
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << "ftServer::sendDataRequest() to peer " << peerId << " for hash " << hash << ", offset=" << offset << ", chunk size="<< chunksize << std::endl;
|
||||
@ -908,7 +895,7 @@ bool ftServer::sendDataRequest(const std::string& peerId, const std::string& has
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ftServer::sendChunkMapRequest(const std::string& peerId,const std::string& hash,bool is_client)
|
||||
bool ftServer::sendChunkMapRequest(const RsPeerId& peerId,const RsFileHash& hash,bool is_client)
|
||||
{
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << "ftServer::sendChunkMapRequest() to peer " << peerId << " for hash " << hash << std::endl;
|
||||
@ -937,7 +924,7 @@ bool ftServer::sendChunkMapRequest(const std::string& peerId,const std::string&
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool ftServer::sendChunkMap(const std::string& peerId,const std::string& hash,const CompressedChunkMap& map,bool is_client)
|
||||
bool ftServer::sendChunkMap(const RsPeerId& peerId,const RsFileHash& hash,const CompressedChunkMap& map,bool is_client)
|
||||
{
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << "ftServer::sendChunkMap() to peer " << peerId << " for hash " << hash << std::endl;
|
||||
@ -968,7 +955,7 @@ bool ftServer::sendChunkMap(const std::string& peerId,const std::string& hash,co
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool ftServer::sendSingleChunkCRCRequest(const std::string& peerId,const std::string& hash,uint32_t chunk_number)
|
||||
bool ftServer::sendSingleChunkCRCRequest(const RsPeerId& peerId,const RsFileHash& hash,uint32_t chunk_number)
|
||||
{
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << "ftServer::sendSingleCRCRequest() to peer " << peerId << " for hash " << hash << ", chunk number=" << chunk_number << std::endl;
|
||||
@ -999,7 +986,7 @@ bool ftServer::sendSingleChunkCRCRequest(const std::string& peerId,const std::st
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool ftServer::sendSingleChunkCRC(const std::string& peerId,const std::string& hash,uint32_t chunk_number,const Sha1CheckSum& crc)
|
||||
bool ftServer::sendSingleChunkCRC(const RsPeerId& peerId,const RsFileHash& hash,uint32_t chunk_number,const Sha1CheckSum& crc)
|
||||
{
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << "ftServer::sendSingleCRC() to peer " << peerId << " for hash " << hash << ", chunk number=" << chunk_number << std::endl;
|
||||
@ -1033,7 +1020,7 @@ bool ftServer::sendSingleChunkCRC(const std::string& peerId,const std::string& h
|
||||
}
|
||||
|
||||
/* Server Send */
|
||||
bool ftServer::sendData(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t baseoffset, uint32_t chunksize, void *data)
|
||||
bool ftServer::sendData(const RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t baseoffset, uint32_t chunksize, void *data)
|
||||
{
|
||||
/* create a packet */
|
||||
/* push to networking part */
|
||||
@ -1130,8 +1117,8 @@ bool ftServer::sendData(const std::string& peerId, const std::string& hash, uint
|
||||
// Dont delete the item. The client (p3turtle) is doing it after calling this.
|
||||
//
|
||||
void ftServer::receiveTurtleData(RsTurtleGenericTunnelItem *i,
|
||||
const std::string& hash,
|
||||
const std::string& virtual_peer_id,
|
||||
const RsFileHash& hash,
|
||||
const RsPeerId& virtual_peer_id,
|
||||
RsTurtleGenericTunnelItem::Direction direction)
|
||||
{
|
||||
switch(i->PacketSubType())
|
||||
|
@ -94,7 +94,7 @@ class ftServer: public p3Service, public RsFiles, public ftDataSend, public RsTu
|
||||
virtual CacheStrapper *getCacheStrapper();
|
||||
virtual CacheTransfer *getCacheTransfer();
|
||||
|
||||
std::string OwnId();
|
||||
const RsPeerId& OwnId();
|
||||
|
||||
/* Final Setup (once everything is assigned) */
|
||||
void SetupFtServer() ;
|
||||
@ -102,12 +102,12 @@ class ftServer: public p3Service, public RsFiles, public ftDataSend, public RsTu
|
||||
|
||||
// Checks that the given hash is well formed. Used to chase
|
||||
// string bugs.
|
||||
static bool checkHash(const std::string& hash,std::string& error_string) ;
|
||||
static bool checkHash(const RsFileHash& hash,std::string& error_string) ;
|
||||
|
||||
// Implements RsTurtleClientService
|
||||
//
|
||||
virtual bool handleTunnelRequest(const std::string& hash,const std::string& peer_id) ;
|
||||
virtual void receiveTurtleData(RsTurtleGenericTunnelItem *item,const std::string& hash,const std::string& virtual_peer_id,RsTurtleGenericTunnelItem::Direction direction) ;
|
||||
virtual bool handleTunnelRequest(const RsFileHash& hash,const RsPeerId& peer_id) ;
|
||||
virtual void receiveTurtleData(RsTurtleGenericTunnelItem *item,const RsFileHash& hash,const RsPeerId& virtual_peer_id,RsTurtleGenericTunnelItem::Direction direction) ;
|
||||
virtual RsTurtleGenericTunnelItem *deserialiseItem(void *data,uint32_t size) const ;
|
||||
|
||||
void addVirtualPeer(const TurtleFileHash&, const TurtleVirtualPeerId&,RsTurtleGenericTunnelItem::Direction dir) ;
|
||||
@ -129,14 +129,14 @@ class ftServer: public p3Service, public RsFiles, public ftDataSend, public RsTu
|
||||
/***
|
||||
* Control of Downloads
|
||||
***/
|
||||
virtual bool alreadyHaveFile(const std::string& hash, FileInfo &info);
|
||||
virtual bool FileRequest(const std::string& fname, const std::string& hash, uint64_t size, const std::string& dest, TransferRequestFlags flags, const std::list<std::string>& srcIds);
|
||||
virtual bool FileCancel(const std::string& hash);
|
||||
virtual bool FileControl(const std::string& hash, uint32_t flags);
|
||||
virtual bool alreadyHaveFile(const RsFileHash& hash, FileInfo &info);
|
||||
virtual bool FileRequest(const std::string& fname, const RsFileHash& hash, uint64_t size, const std::string& dest, TransferRequestFlags flags, const std::list<RsPeerId>& srcIds);
|
||||
virtual bool FileCancel(const RsFileHash& hash);
|
||||
virtual bool FileControl(const RsFileHash& hash, uint32_t flags);
|
||||
virtual bool FileClearCompleted();
|
||||
virtual bool setDestinationDirectory(const std::string& hash,const std::string& new_path) ;
|
||||
virtual bool setDestinationName(const std::string& hash,const std::string& new_name) ;
|
||||
virtual bool setChunkStrategy(const std::string& hash,FileChunksInfo::ChunkStrategy s) ;
|
||||
virtual bool setDestinationDirectory(const RsFileHash& hash,const std::string& new_path) ;
|
||||
virtual bool setDestinationName(const RsFileHash& hash,const std::string& new_name) ;
|
||||
virtual bool setChunkStrategy(const RsFileHash& hash,FileChunksInfo::ChunkStrategy s) ;
|
||||
virtual void setDefaultChunkStrategy(FileChunksInfo::ChunkStrategy) ;
|
||||
virtual FileChunksInfo::ChunkStrategy defaultChunkStrategy() ;
|
||||
virtual uint32_t freeDiskSpaceLimit() const ;
|
||||
@ -150,43 +150,43 @@ class ftServer: public p3Service, public RsFiles, public ftDataSend, public RsTu
|
||||
virtual void setMinPrioritizedTransfers(uint32_t s) ;
|
||||
virtual uint32_t getQueueSize() ;
|
||||
virtual void setQueueSize(uint32_t s) ;
|
||||
virtual bool changeQueuePosition(const std::string hash, QueueMove queue_mv);
|
||||
virtual bool changeDownloadSpeed(const std::string hash, int speed);
|
||||
virtual bool getDownloadSpeed(const std::string hash, int & speed);
|
||||
virtual bool clearDownload(const std::string hash);
|
||||
virtual bool changeQueuePosition(const RsFileHash& hash, QueueMove queue_mv);
|
||||
virtual bool changeDownloadSpeed(const RsFileHash& hash, int speed);
|
||||
virtual bool getDownloadSpeed(const RsFileHash& hash, int & speed);
|
||||
virtual bool clearDownload(const RsFileHash& hash);
|
||||
//virtual void getDwlDetails(std::list<DwlDetails> & details);
|
||||
|
||||
/***
|
||||
* Download/Upload Details
|
||||
***/
|
||||
virtual bool FileDownloads(std::list<std::string> &hashs);
|
||||
virtual bool FileUploads(std::list<std::string> &hashs);
|
||||
virtual bool FileDetails(const std::string &hash, FileSearchFlags hintflags, FileInfo &info);
|
||||
virtual bool FileDownloadChunksDetails(const std::string& hash,FileChunksInfo& info) ;
|
||||
virtual bool FileUploadChunksDetails(const std::string& hash,const std::string& peer_id,CompressedChunkMap& map) ;
|
||||
virtual bool FileDownloads(std::list<RsFileHash> &hashs);
|
||||
virtual bool FileUploads(std::list<RsFileHash> &hashs);
|
||||
virtual bool FileDetails(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info);
|
||||
virtual bool FileDownloadChunksDetails(const RsFileHash& hash,FileChunksInfo& info) ;
|
||||
virtual bool FileUploadChunksDetails(const RsFileHash& hash,const RsPeerId& peer_id,CompressedChunkMap& map) ;
|
||||
|
||||
|
||||
/***
|
||||
* Extra List Access
|
||||
***/
|
||||
virtual bool ExtraFileAdd(std::string fname, std::string hash, uint64_t size, uint32_t period, TransferRequestFlags flags);
|
||||
virtual bool ExtraFileRemove(std::string hash, TransferRequestFlags flags);
|
||||
virtual bool ExtraFileAdd(std::string fname, const RsFileHash& hash, uint64_t size, uint32_t period, TransferRequestFlags flags);
|
||||
virtual bool ExtraFileRemove(const RsFileHash& hash, TransferRequestFlags flags);
|
||||
virtual bool ExtraFileHash(std::string localpath, uint32_t period, TransferRequestFlags flags);
|
||||
virtual bool ExtraFileStatus(std::string localpath, FileInfo &info);
|
||||
virtual bool ExtraFileMove(std::string fname, std::string hash, uint64_t size, std::string destpath);
|
||||
virtual bool ExtraFileMove(std::string fname, const RsFileHash& hash, uint64_t size, std::string destpath);
|
||||
|
||||
|
||||
/***
|
||||
* Directory Listing / Search Interface
|
||||
***/
|
||||
virtual int RequestDirDetails(const std::string& uid, const std::string& path, DirDetails &details);
|
||||
virtual int RequestDirDetails(const RsPeerId& uid, const std::string& path, DirDetails &details);
|
||||
virtual int RequestDirDetails(void *ref, DirDetails &details, FileSearchFlags flags);
|
||||
virtual uint32_t getType(void *ref,FileSearchFlags flags) ;
|
||||
|
||||
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags);
|
||||
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags,const std::string& peer_id);
|
||||
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags,const RsPeerId& peer_id);
|
||||
virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags);
|
||||
virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags,const std::string& peer_id);
|
||||
virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags,const RsPeerId& peer_id);
|
||||
|
||||
/***
|
||||
* Utility Functions
|
||||
@ -230,12 +230,12 @@ class ftServer: public p3Service, public RsFiles, public ftDataSend, public RsTu
|
||||
/*************** Data Transfer Interface ***********************/
|
||||
/***************************************************************/
|
||||
public:
|
||||
virtual bool sendData(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data);
|
||||
virtual bool sendDataRequest(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize);
|
||||
virtual bool sendChunkMapRequest(const std::string& peer_id,const std::string& hash,bool is_client) ;
|
||||
virtual bool sendChunkMap(const std::string& peer_id,const std::string& hash,const CompressedChunkMap& cmap,bool is_client) ;
|
||||
virtual bool sendSingleChunkCRCRequest(const std::string& peer_id,const std::string& hash,uint32_t chunk_number) ;
|
||||
virtual bool sendSingleChunkCRC(const std::string& peer_id,const std::string& hash,uint32_t chunk_number,const Sha1CheckSum& crc) ;
|
||||
virtual bool sendData(const RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data);
|
||||
virtual bool sendDataRequest(const RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunksize);
|
||||
virtual bool sendChunkMapRequest(const RsPeerId& peer_id,const RsFileHash& hash,bool is_client) ;
|
||||
virtual bool sendChunkMap(const RsPeerId& peer_id,const RsFileHash& hash,const CompressedChunkMap& cmap,bool is_client) ;
|
||||
virtual bool sendSingleChunkCRCRequest(const RsPeerId& peer_id,const RsFileHash& hash,uint32_t chunk_number) ;
|
||||
virtual bool sendSingleChunkCRC(const RsPeerId& peer_id,const RsFileHash& hash,uint32_t chunk_number,const Sha1CheckSum& crc) ;
|
||||
|
||||
/*************** Internal Transfer Fns *************************/
|
||||
virtual int tick();
|
||||
|
@ -103,7 +103,7 @@ ftTransferModule::~ftTransferModule()
|
||||
}
|
||||
|
||||
|
||||
bool ftTransferModule::setFileSources(const std::list<std::string>& peerIds)
|
||||
bool ftTransferModule::setFileSources(const std::list<RsPeerId>& peerIds)
|
||||
{
|
||||
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
|
||||
|
||||
@ -114,7 +114,7 @@ bool ftTransferModule::setFileSources(const std::list<std::string>& peerIds)
|
||||
std::cerr << " List of peers: " ;
|
||||
#endif
|
||||
|
||||
std::list<std::string>::const_iterator it;
|
||||
std::list<RsPeerId>::const_iterator it;
|
||||
for(it = peerIds.begin(); it != peerIds.end(); it++)
|
||||
{
|
||||
|
||||
@ -123,7 +123,7 @@ bool ftTransferModule::setFileSources(const std::list<std::string>& peerIds)
|
||||
#endif
|
||||
|
||||
peerInfo pInfo(*it);
|
||||
mFileSources.insert(std::pair<std::string,peerInfo>(*it,pInfo));
|
||||
mFileSources.insert(std::pair<RsPeerId,peerInfo>(*it,pInfo));
|
||||
}
|
||||
|
||||
#ifdef FT_DEBUG
|
||||
@ -133,10 +133,10 @@ bool ftTransferModule::setFileSources(const std::list<std::string>& peerIds)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ftTransferModule::getFileSources(std::list<std::string> &peerIds)
|
||||
bool ftTransferModule::getFileSources(std::list<RsPeerId> &peerIds)
|
||||
{
|
||||
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
|
||||
std::map<std::string,peerInfo>::iterator it;
|
||||
std::map<RsPeerId,peerInfo>::iterator it;
|
||||
for(it = mFileSources.begin(); it != mFileSources.end(); it++)
|
||||
{
|
||||
peerIds.push_back(it->first);
|
||||
@ -144,17 +144,17 @@ bool ftTransferModule::getFileSources(std::list<std::string> &peerIds)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ftTransferModule::addFileSource(const std::string& peerId)
|
||||
bool ftTransferModule::addFileSource(const RsPeerId& peerId)
|
||||
{
|
||||
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
|
||||
std::map<std::string,peerInfo>::iterator mit;
|
||||
std::map<RsPeerId,peerInfo>::iterator mit;
|
||||
mit = mFileSources.find(peerId);
|
||||
|
||||
if (mit == mFileSources.end())
|
||||
{
|
||||
/* add in new source */
|
||||
peerInfo pInfo(peerId);
|
||||
mFileSources.insert(std::pair<std::string,peerInfo>(peerId,pInfo));
|
||||
mFileSources.insert(std::pair<RsPeerId,peerInfo>(peerId,pInfo));
|
||||
mit = mFileSources.find(peerId);
|
||||
|
||||
mMultiplexor->sendChunkMapRequest(peerId, mHash,false) ;
|
||||
@ -177,10 +177,10 @@ bool ftTransferModule::addFileSource(const std::string& peerId)
|
||||
}
|
||||
}
|
||||
|
||||
bool ftTransferModule::removeFileSource(const std::string& peerId)
|
||||
bool ftTransferModule::removeFileSource(const RsPeerId& peerId)
|
||||
{
|
||||
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
|
||||
std::map<std::string,peerInfo>::iterator mit;
|
||||
std::map<RsPeerId,peerInfo>::iterator mit;
|
||||
mit = mFileSources.find(peerId);
|
||||
|
||||
if (mit != mFileSources.end())
|
||||
@ -199,7 +199,7 @@ bool ftTransferModule::removeFileSource(const std::string& peerId)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ftTransferModule::setPeerState(const std::string& peerId,uint32_t state,uint32_t maxRate)
|
||||
bool ftTransferModule::setPeerState(const RsPeerId& peerId,uint32_t state,uint32_t maxRate)
|
||||
{
|
||||
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
|
||||
#ifdef FT_DEBUG
|
||||
@ -209,7 +209,7 @@ bool ftTransferModule::setPeerState(const std::string& peerId,uint32_t state,uin
|
||||
std::cerr << " maxRate: " << maxRate << std::endl;
|
||||
#endif
|
||||
|
||||
std::map<std::string,peerInfo>::iterator mit;
|
||||
std::map<RsPeerId,peerInfo>::iterator mit;
|
||||
mit = mFileSources.find(peerId);
|
||||
|
||||
if (mit == mFileSources.end())
|
||||
@ -229,7 +229,7 @@ bool ftTransferModule::setPeerState(const std::string& peerId,uint32_t state,uin
|
||||
// Start it off at zero....
|
||||
// (mit->second).actualRate=maxRate; /* should give big kick in right direction */
|
||||
|
||||
std::list<std::string>::iterator it;
|
||||
std::list<RsPeerId>::iterator it;
|
||||
it = std::find(mOnlinePeers.begin(), mOnlinePeers.end(), peerId);
|
||||
|
||||
if (state!=PQIPEER_NOT_ONLINE)
|
||||
@ -247,10 +247,10 @@ bool ftTransferModule::setPeerState(const std::string& peerId,uint32_t state,uin
|
||||
}
|
||||
|
||||
|
||||
bool ftTransferModule::getPeerState(const std::string& peerId,uint32_t &state,uint32_t &tfRate)
|
||||
bool ftTransferModule::getPeerState(const RsPeerId& peerId,uint32_t &state,uint32_t &tfRate)
|
||||
{
|
||||
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
|
||||
std::map<std::string,peerInfo>::iterator mit;
|
||||
std::map<RsPeerId,peerInfo>::iterator mit;
|
||||
mit = mFileSources.find(peerId);
|
||||
|
||||
if (mit == mFileSources.end()) return false;
|
||||
@ -267,10 +267,10 @@ bool ftTransferModule::getPeerState(const std::string& peerId,uint32_t &state,ui
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32_t ftTransferModule::getDataRate(const std::string& peerId)
|
||||
uint32_t ftTransferModule::getDataRate(const RsPeerId& peerId)
|
||||
{
|
||||
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
|
||||
std::map<std::string,peerInfo>::iterator mit;
|
||||
std::map<RsPeerId,peerInfo>::iterator mit;
|
||||
mit = mFileSources.find(peerId);
|
||||
if (mit == mFileSources.end())
|
||||
{
|
||||
@ -296,7 +296,7 @@ time_t ftTransferModule::lastActvTimeStamp()
|
||||
}
|
||||
|
||||
//interface to client module
|
||||
bool ftTransferModule::recvFileData(const std::string& peerId, uint64_t offset, uint32_t chunk_size, void *data)
|
||||
bool ftTransferModule::recvFileData(const RsPeerId& peerId, uint64_t offset, uint32_t chunk_size, void *data)
|
||||
{
|
||||
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
|
||||
#ifdef FT_DEBUG
|
||||
@ -310,7 +310,7 @@ bool ftTransferModule::recvFileData(const std::string& peerId, uint64_t offset,
|
||||
|
||||
bool ok = false;
|
||||
|
||||
std::map<std::string,peerInfo>::iterator mit;
|
||||
std::map<RsPeerId,peerInfo>::iterator mit;
|
||||
mit = mFileSources.find(peerId);
|
||||
|
||||
if (mit == mFileSources.end())
|
||||
@ -332,7 +332,7 @@ bool ftTransferModule::recvFileData(const std::string& peerId, uint64_t offset,
|
||||
return ok;
|
||||
}
|
||||
|
||||
void ftTransferModule::locked_requestData(const std::string& peerId, uint64_t offset, uint32_t chunk_size)
|
||||
void ftTransferModule::locked_requestData(const RsPeerId& peerId, uint64_t offset, uint32_t chunk_size)
|
||||
{
|
||||
#ifdef FT_DEBUG
|
||||
std::cerr << "ftTransferModule::requestData()";
|
||||
@ -347,7 +347,7 @@ void ftTransferModule::locked_requestData(const std::string& peerId, uint64_t of
|
||||
mMultiplexor->sendDataRequest(peerId, mHash, mSize, offset,chunk_size);
|
||||
}
|
||||
|
||||
bool ftTransferModule::locked_getChunk(const std::string& peer_id,uint32_t size_hint,uint64_t &offset, uint32_t &chunk_size)
|
||||
bool ftTransferModule::locked_getChunk(const RsPeerId& peer_id,uint32_t size_hint,uint64_t &offset, uint32_t &chunk_size)
|
||||
{
|
||||
#ifdef FT_DEBUG
|
||||
std::cerr << "ftTransferModule::locked_getChunk()";
|
||||
@ -427,7 +427,7 @@ bool ftTransferModule::queryInactive()
|
||||
if (mFileStatus.stat == ftFileStatus::PQIFILE_CHECKING)
|
||||
return false ;
|
||||
|
||||
std::map<std::string,peerInfo>::iterator mit;
|
||||
std::map<RsPeerId,peerInfo>::iterator mit;
|
||||
for(mit = mFileSources.begin(); mit != mFileSources.end(); mit++)
|
||||
{
|
||||
locked_tickPeerTransfer(mit->second);
|
||||
@ -496,7 +496,7 @@ int ftTransferModule::tick()
|
||||
std::cerr << std::endl;
|
||||
|
||||
std::cerr << "Peers: ";
|
||||
std::map<std::string,peerInfo>::iterator it;
|
||||
std::map<RsPeerId,peerInfo>::iterator it;
|
||||
for(it = mFileSources.begin(); it != mFileSources.end(); it++)
|
||||
{
|
||||
std::cerr << " " << it->first;
|
||||
@ -553,14 +553,14 @@ class HashThread: public RsThread
|
||||
#ifdef FT_DEBUG
|
||||
std::cerr << "hash thread is running for file " << std::endl;
|
||||
#endif
|
||||
std::string tmphash ;
|
||||
RsFileHash tmphash ;
|
||||
_m->hashReceivedData(tmphash) ;
|
||||
|
||||
RsStackMutex stack(_hashThreadMtx) ;
|
||||
_hash = tmphash ;
|
||||
_finished = true ;
|
||||
}
|
||||
std::string hash()
|
||||
RsFileHash hash()
|
||||
{
|
||||
RsStackMutex stack(_hashThreadMtx) ;
|
||||
return _hash ;
|
||||
@ -574,7 +574,7 @@ class HashThread: public RsThread
|
||||
RsMutex _hashThreadMtx ;
|
||||
ftFileCreator *_m ;
|
||||
bool _finished ;
|
||||
std::string _hash ;
|
||||
RsFileHash _hash ;
|
||||
};
|
||||
|
||||
bool ftTransferModule::checkFile()
|
||||
@ -607,7 +607,7 @@ bool ftTransferModule::checkFile()
|
||||
return false ;
|
||||
}
|
||||
|
||||
std::string check_hash( _hash_thread->hash() ) ;
|
||||
RsFileHash check_hash( _hash_thread->hash() ) ;
|
||||
|
||||
_hash_thread->join(); // allow releasing of resources when finished.
|
||||
|
||||
@ -645,7 +645,7 @@ void ftTransferModule::adjustSpeed()
|
||||
{
|
||||
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
|
||||
|
||||
std::map<std::string,peerInfo>::iterator mit;
|
||||
std::map<RsPeerId,peerInfo>::iterator mit;
|
||||
|
||||
|
||||
actualRate = 0;
|
||||
|
@ -56,7 +56,7 @@ class HashThread ;
|
||||
class peerInfo
|
||||
{
|
||||
public:
|
||||
peerInfo(std::string peerId_in):peerId(peerId_in),state(PQIPEER_NOT_ONLINE),desiredRate(0),actualRate(0),
|
||||
peerInfo(const RsPeerId& peerId_in):peerId(peerId_in),state(PQIPEER_NOT_ONLINE),desiredRate(0),actualRate(0),
|
||||
lastTS(0),
|
||||
recvTS(0), lastTransfers(0), nResets(0),
|
||||
rtt(0), rttActive(false), rttStart(0), rttOffset(0),
|
||||
@ -64,7 +64,7 @@ public:
|
||||
{
|
||||
return;
|
||||
}
|
||||
peerInfo(std::string peerId_in,uint32_t state_in,uint32_t maxRate_in):
|
||||
peerInfo(const RsPeerId& peerId_in,uint32_t state_in,uint32_t maxRate_in):
|
||||
peerId(peerId_in),state(state_in),desiredRate(maxRate_in),actualRate(0),
|
||||
lastTS(0),
|
||||
recvTS(0), lastTransfers(0), nResets(0),
|
||||
@ -73,7 +73,7 @@ public:
|
||||
{
|
||||
return;
|
||||
}
|
||||
std::string peerId;
|
||||
RsPeerId peerId;
|
||||
uint32_t state;
|
||||
double desiredRate;
|
||||
double actualRate;
|
||||
@ -111,9 +111,9 @@ public:
|
||||
};
|
||||
|
||||
ftFileStatus():hash(""),stat(PQIFILE_INIT) {}
|
||||
ftFileStatus(std::string hash_in):hash(hash_in),stat(PQIFILE_INIT) {}
|
||||
ftFileStatus(const RsFileHash& hash_in):hash(hash_in),stat(PQIFILE_INIT) {}
|
||||
|
||||
std::string hash;
|
||||
RsFileHash hash;
|
||||
Status stat;
|
||||
};
|
||||
|
||||
@ -124,13 +124,13 @@ public:
|
||||
~ftTransferModule();
|
||||
|
||||
//interface to download controller
|
||||
bool setFileSources(const std::list<std::string>& peerIds);
|
||||
bool addFileSource(const std::string& peerId);
|
||||
bool removeFileSource(const std::string& peerId);
|
||||
bool setPeerState(const std::string& peerId,uint32_t state,uint32_t maxRate); //state = ONLINE/OFFLINE
|
||||
bool getFileSources(std::list<std::string> &peerIds);
|
||||
bool getPeerState(const std::string& peerId,uint32_t &state,uint32_t &tfRate);
|
||||
uint32_t getDataRate(const std::string& peerId);
|
||||
bool setFileSources(const std::list<RsPeerId>& peerIds);
|
||||
bool addFileSource(const RsPeerId& peerId);
|
||||
bool removeFileSource(const RsPeerId& peerId);
|
||||
bool setPeerState(const RsPeerId& peerId,uint32_t state,uint32_t maxRate); //state = ONLINE/OFFLINE
|
||||
bool getFileSources(std::list<RsPeerId> &peerIds);
|
||||
bool getPeerState(const RsPeerId& peerId,uint32_t &state,uint32_t &tfRate);
|
||||
uint32_t getDataRate(const RsPeerId& peerId);
|
||||
bool cancelTransfer();
|
||||
bool cancelFileTransferUpward();
|
||||
bool completeFileTransfer();
|
||||
@ -138,17 +138,17 @@ public:
|
||||
void forceCheck() ;
|
||||
|
||||
//interface to multiplex module
|
||||
bool recvFileData(const std::string& peerId, uint64_t offset, uint32_t chunk_size, void *data);
|
||||
void locked_requestData(const std::string& peerId, uint64_t offset, uint32_t chunk_size);
|
||||
bool recvFileData(const RsPeerId& peerId, uint64_t offset, uint32_t chunk_size, void *data);
|
||||
void locked_requestData(const RsPeerId& peerId, uint64_t offset, uint32_t chunk_size);
|
||||
|
||||
//interface to file creator
|
||||
bool locked_getChunk(const std::string& peer_id,uint32_t size_hint,uint64_t &offset, uint32_t &chunk_size);
|
||||
bool locked_getChunk(const RsPeerId& peer_id,uint32_t size_hint,uint64_t &offset, uint32_t &chunk_size);
|
||||
bool locked_storeData(uint64_t offset, uint32_t chunk_size, void *data);
|
||||
|
||||
int tick();
|
||||
|
||||
std::string hash() { return mHash; }
|
||||
uint64_t size() { return mSize; }
|
||||
const RsFileHash& hash() const { return mHash; }
|
||||
uint64_t size() const { return mSize; }
|
||||
|
||||
//internal used functions
|
||||
bool queryInactive();
|
||||
@ -175,13 +175,13 @@ private:
|
||||
ftDataMultiplex *mMultiplexor;
|
||||
ftController *mFtController;
|
||||
|
||||
std::string mHash;
|
||||
RsFileHash mHash;
|
||||
uint64_t mSize;
|
||||
|
||||
RsMutex tfMtx; /* below is mutex protected */
|
||||
|
||||
std::list<std::string> mOnlinePeers;
|
||||
std::map<std::string,peerInfo> mFileSources;
|
||||
std::list<RsPeerId> mOnlinePeers;
|
||||
std::map<RsPeerId,peerInfo> mFileSources;
|
||||
|
||||
uint16_t mFlag; //2:file canceled, 1:transfer complete, 0: not complete, 3: checking hash, 4: checking chunks
|
||||
double desiredRate;
|
||||
|
@ -79,15 +79,6 @@ uint32_t RsTurtleFileMapItem::serial_size()
|
||||
return s ;
|
||||
}
|
||||
|
||||
uint32_t RsTurtleFileCrcRequestItem::serial_size()
|
||||
{
|
||||
uint32_t s = 0 ;
|
||||
|
||||
s += 8 ; // header
|
||||
s += 4 ; // tunnel id
|
||||
|
||||
return s ;
|
||||
}
|
||||
uint32_t RsTurtleChunkCrcItem::serial_size()
|
||||
{
|
||||
uint32_t s = 0 ;
|
||||
@ -95,7 +86,7 @@ uint32_t RsTurtleChunkCrcItem::serial_size()
|
||||
s += 8 ; // header
|
||||
s += 4 ; // tunnel id
|
||||
s += 4 ; // chunk number
|
||||
s += 20 ; // check_sum
|
||||
s += check_sum.serial_size() ; // check_sum
|
||||
|
||||
return s ;
|
||||
}
|
||||
@ -179,40 +170,6 @@ bool RsTurtleFileMapItem::serialize(void *data,uint32_t& pktsize)
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool RsTurtleFileCrcRequestItem::serialize(void *data,uint32_t& pktsize)
|
||||
{
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << "RsTurtleFileCrcRequestItem::serialize(): serializing packet:" << std::endl ;
|
||||
print(std::cerr,2) ;
|
||||
#endif
|
||||
uint32_t tlvsize = serial_size();
|
||||
uint32_t offset = 0;
|
||||
|
||||
if (pktsize < tlvsize)
|
||||
return false; /* not enough space */
|
||||
|
||||
pktsize = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data,tlvsize,PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* add mandatory parts first */
|
||||
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, tunnel_id);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
std::cerr << "RsFileConfigSerialiser::serialiseTransfer() Size Error! " << std::endl;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool RsTurtleChunkCrcRequestItem::serialize(void *data,uint32_t& pktsize)
|
||||
{
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
@ -273,7 +230,7 @@ bool RsTurtleChunkCrcItem::serialize(void *data,uint32_t& pktsize)
|
||||
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, tunnel_id);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, chunk_number);
|
||||
ok &= setRawSha1(data, tlvsize, &offset, check_sum);
|
||||
ok &= check_sum.serialise(data, tlvsize, offset) ;
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
@ -353,7 +310,7 @@ RsTurtleChunkCrcItem::RsTurtleChunkCrcItem(void *data,uint32_t pktsize)
|
||||
bool ok = true ;
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &tunnel_id) ;
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &chunk_number) ;
|
||||
ok &= getRawSha1(data, pktsize, &offset, check_sum) ;
|
||||
ok &= check_sum.deserialise(data, pktsize, offset) ;
|
||||
|
||||
#ifdef WINDOWS_SYS // No Exceptions in Windows compile. (drbobs).
|
||||
#else
|
||||
@ -363,28 +320,7 @@ RsTurtleChunkCrcItem::RsTurtleChunkCrcItem(void *data,uint32_t pktsize)
|
||||
throw std::runtime_error("Unknown error while deserializing.") ;
|
||||
#endif
|
||||
}
|
||||
RsTurtleFileCrcRequestItem::RsTurtleFileCrcRequestItem(void *data,uint32_t pktsize)
|
||||
: RsTurtleGenericTunnelItem(RS_TURTLE_SUBTYPE_FILE_CRC_REQUEST)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_TURTLE_FILE_CRC_REQUEST) ;
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << " type = file map request item" << std::endl ;
|
||||
#endif
|
||||
uint32_t offset = 8; // skip the header
|
||||
|
||||
/* add mandatory parts first */
|
||||
|
||||
bool ok = true ;
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &tunnel_id);
|
||||
|
||||
#ifdef WINDOWS_SYS // No Exceptions in Windows compile. (drbobs).
|
||||
#else
|
||||
if (offset != pktsize)
|
||||
throw std::runtime_error("Size error while deserializing.") ;
|
||||
if (!ok)
|
||||
throw std::runtime_error("Unknown error while deserializing.") ;
|
||||
#endif
|
||||
}
|
||||
RsTurtleChunkCrcRequestItem::RsTurtleChunkCrcRequestItem(void *data,uint32_t pktsize)
|
||||
: RsTurtleGenericTunnelItem(RS_TURTLE_SUBTYPE_CHUNK_CRC_REQUEST)
|
||||
{
|
||||
@ -596,14 +532,6 @@ std::ostream& RsTurtleFileMapRequestItem::print(std::ostream& o, uint16_t)
|
||||
}
|
||||
|
||||
|
||||
std::ostream& RsTurtleFileCrcRequestItem::print(std::ostream& o, uint16_t)
|
||||
{
|
||||
o << "File CRC request item:" << std::endl ;
|
||||
|
||||
o << " tunnel id : " << std::hex << tunnel_id << std::dec << std::endl ;
|
||||
|
||||
return o ;
|
||||
}
|
||||
std::ostream& RsTurtleChunkCrcRequestItem::print(std::ostream& o, uint16_t)
|
||||
{
|
||||
o << "Chunk CRC request item:" << std::endl ;
|
||||
@ -615,7 +543,7 @@ std::ostream& RsTurtleChunkCrcRequestItem::print(std::ostream& o, uint16_t)
|
||||
}
|
||||
std::ostream& RsTurtleChunkCrcItem::print(std::ostream& o, uint16_t)
|
||||
{
|
||||
o << "Chunk CRC request item:" << std::endl ;
|
||||
o << "Chunk CRC item:" << std::endl ;
|
||||
|
||||
o << " tunnel id : " << std::hex << tunnel_id << std::dec << std::endl ;
|
||||
o << " chunk num : " << chunk_number << std::endl ;
|
||||
|
@ -100,21 +100,6 @@ class RsTurtleFileMapItem: public RsTurtleGenericTunnelItem
|
||||
virtual uint32_t serial_size() ;
|
||||
};
|
||||
|
||||
class RsTurtleFileCrcRequestItem: public RsTurtleGenericTunnelItem
|
||||
{
|
||||
public:
|
||||
RsTurtleFileCrcRequestItem() : RsTurtleGenericTunnelItem(RS_TURTLE_SUBTYPE_FILE_CRC_REQUEST) { setPriorityLevel(QOS_PRIORITY_RS_FILE_CRC_REQUEST);}
|
||||
RsTurtleFileCrcRequestItem(void *data,uint32_t size) ; // deserialization
|
||||
|
||||
virtual bool shouldStampTunnel() const { return false ; }
|
||||
virtual Direction travelingDirection() const { return DIRECTION_SERVER ; }
|
||||
|
||||
virtual std::ostream& print(std::ostream& o, uint16_t) ;
|
||||
|
||||
virtual bool serialize(void *data,uint32_t& size) ;
|
||||
virtual uint32_t serial_size() ;
|
||||
};
|
||||
|
||||
class RsTurtleChunkCrcRequestItem: public RsTurtleGenericTunnelItem
|
||||
{
|
||||
public:
|
||||
|
@ -1,36 +0,0 @@
|
||||
/*
|
||||
* libretroshare/src/services: grouterclient.h
|
||||
*
|
||||
* Services for RetroShare.
|
||||
*
|
||||
* Copyright 2013 by Cyril Soler
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "csoler@users.sourceforge.net".
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
// Derive from this class to be a client for the global router. Typical potential clients are:
|
||||
// - the messaging system
|
||||
//
|
||||
class GRouterClient
|
||||
{
|
||||
public:
|
||||
virtual void receiveLongDistanceItem(void *data,uint32_t size) = 0 ;
|
||||
};
|
||||
|
65
libretroshare/src/grouter/grouterclientservice.h
Normal file
65
libretroshare/src/grouter/grouterclientservice.h
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* libretroshare/src/grouter: grouterclientservice.h
|
||||
*
|
||||
* Services for RetroShare.
|
||||
*
|
||||
* Copyright 2013 by Cyril Soler
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "csoler@users.sourceforge.net".
|
||||
*
|
||||
*/
|
||||
|
||||
// This class is the parent class for any service that will use the global router to distribute its packets.
|
||||
// Typical representative clients include:
|
||||
//
|
||||
// p3msgservice: sends distant messages and advertise messaging keys
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <stdlib.h>
|
||||
#include <grouter/grouteritems.h>
|
||||
|
||||
class RsItem ;
|
||||
|
||||
class GRouterClientService
|
||||
{
|
||||
public:
|
||||
// This method is called by the turtle router to send data that comes out of a turtle tunnel.
|
||||
// The turtle router stays responsible for the memory management of data. Most of the time the
|
||||
// data chunk is a serialized item to be de-serialized by the client service.
|
||||
//
|
||||
// Parameters:
|
||||
// item : global router item. Handled by the client service.
|
||||
// destination_key : key that is associated with this item. Can be useful for the client.
|
||||
//
|
||||
// GRouter stays owner of the item, so the client should not delete it!
|
||||
//
|
||||
virtual void receiveGRouterData(RsGRouterGenericDataItem * /*item*/,const GRouterKeyId& destination_key)
|
||||
{
|
||||
std::cerr << "!!!!!! Received Data from global router, but the client service is not handling it !!!!!!!!!!" << std::endl ;
|
||||
std::cerr << " destination key_id = " << destination_key.toStdString() << std::endl;
|
||||
}
|
||||
|
||||
// This function is mandatory. It should do two things:
|
||||
// 1 - keep a pointer to the global router, so as to be able to send data (e.g. copy pt into a local variable)
|
||||
// 2 - call pt->registerTunnelService(this), so that the TR knows that service and can send back information to it.
|
||||
//
|
||||
virtual void connectToGlobalRouter(p3GRouter *pt) = 0 ;
|
||||
};
|
||||
|
||||
|
@ -55,12 +55,12 @@ bool RsGRouterPublishKeyItem::serialise(void *data, uint32_t& pktsize) const
|
||||
offset += 8 ;
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, diffusion_id);
|
||||
ok &= setRawSha1(data, tlvsize, &offset, published_key);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, diffusion_id);
|
||||
ok &= published_key.serialise(data, tlvsize, offset) ;
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, service_id);
|
||||
ok &= setRawUFloat32(data, tlvsize, &offset, randomized_distance);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_VALUE, description_string);
|
||||
ok &= setRawPGPFingerprint(data, tlvsize, &offset, fingerprint);
|
||||
ok &= fingerprint.serialise(data, tlvsize, offset) ;
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
@ -134,10 +134,9 @@ bool RsGRouterProofOfWorkObject::checkProofOfWork(unsigned char *mem,uint32_t si
|
||||
{
|
||||
Sha1CheckSum sum = RsDirUtil::sha1sum(mem,size) ;
|
||||
|
||||
for(uint32_t i=0;i<(7+PROOF_OF_WORK_REQUESTED_BYTES)/4;++i)
|
||||
for(int j=0;j<(PROOF_OF_WORK_REQUESTED_BYTES%4);++j)
|
||||
if(sum.fourbytes[i] & (0xff << (8*(3-j))) != 0)
|
||||
return false ;
|
||||
for(int i=0;i<PROOF_OF_WORK_REQUESTED_BYTES;++i)
|
||||
if(sum.toByteArray()[i] != 0)
|
||||
return false ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
@ -183,11 +182,11 @@ RsGRouterItem *RsGRouterSerialiser::deserialise_RsGRouterPublishKeyItem(void *da
|
||||
offset += 8 ;
|
||||
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &item->diffusion_id); // file hash
|
||||
ok &= getRawSha1(data, pktsize, &offset, item->published_key);
|
||||
ok &= item->published_key.deserialise(data, pktsize, offset) ;
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &item->service_id); // file hash
|
||||
ok &= getRawUFloat32(data, pktsize, &offset, item->randomized_distance); // file hash
|
||||
ok &= GetTlvString(data, pktsize, &offset, TLV_TYPE_STR_VALUE,item->description_string);
|
||||
ok &= getRawPGPFingerprint(data,pktsize,&offset,item->fingerprint) ;
|
||||
ok &= item->fingerprint.deserialise(data,pktsize,offset) ;
|
||||
|
||||
if (offset != rssize || !ok)
|
||||
{
|
||||
@ -207,7 +206,7 @@ RsGRouterItem *RsGRouterSerialiser::deserialise_RsGRouterGenericDataItem(void *d
|
||||
RsGRouterGenericDataItem *item = new RsGRouterGenericDataItem() ;
|
||||
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &item->routing_id); // file hash
|
||||
ok &= getRawSha1(data, pktsize, &offset, item->destination_key);
|
||||
ok &= item->destination_key.deserialise(data, pktsize, offset) ;
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &item->data_size); // file hash
|
||||
|
||||
if( NULL == (item->data_bytes = (uint8_t*)malloc(item->data_size)))
|
||||
@ -257,7 +256,7 @@ RsGRouterItem *RsGRouterSerialiser::deserialise_RsGRouterRoutingInfoItem(void *d
|
||||
RsGRouterRoutingInfoItem *item = new RsGRouterRoutingInfoItem() ;
|
||||
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &item->status_flags);
|
||||
ok &= getRawSSLId(data, pktsize, &offset, item->origin);
|
||||
ok &= item->origin.deserialise(data, pktsize, offset) ;
|
||||
ok &= getRawTimeT(data, pktsize, &offset, item->received_time);
|
||||
|
||||
uint32_t s = 0 ;
|
||||
@ -267,7 +266,7 @@ RsGRouterItem *RsGRouterSerialiser::deserialise_RsGRouterRoutingInfoItem(void *d
|
||||
{
|
||||
FriendTrialRecord ftr ;
|
||||
|
||||
ok &= getRawSSLId(data, pktsize, &offset, ftr.friend_id);
|
||||
ok &= ftr.friend_id.deserialise(data, pktsize, offset) ;
|
||||
ok &= getRawTimeT(data, pktsize, &offset, ftr.time_stamp) ;
|
||||
|
||||
item->tried_friends.push_back(ftr) ;
|
||||
@ -276,7 +275,7 @@ RsGRouterItem *RsGRouterSerialiser::deserialise_RsGRouterRoutingInfoItem(void *d
|
||||
item->data_item = new RsGRouterGenericDataItem ;
|
||||
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &item->data_item->routing_id);
|
||||
ok &= getRawSha1(data, pktsize, &offset, item->data_item->destination_key) ;
|
||||
ok &= item->data_item->destination_key.deserialise(data, pktsize, offset) ;
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &item->data_item->data_size) ;
|
||||
|
||||
item->data_item->data_bytes = (uint8_t*)malloc(item->data_item->data_size) ;
|
||||
@ -305,7 +304,7 @@ RsGRouterItem *RsGRouterSerialiser::deserialise_RsGRouterMatrixFriendListItem(vo
|
||||
item->reverse_friend_indices.resize(nb_friends) ;
|
||||
|
||||
for(uint32_t i=0;ok && i<nb_friends;++i)
|
||||
ok &= getRawSSLId(data, pktsize, &offset, item->reverse_friend_indices[i]) ;
|
||||
ok &= item->reverse_friend_indices[i].deserialise(data, pktsize, offset) ;
|
||||
|
||||
if (offset != rssize || !ok)
|
||||
{
|
||||
@ -323,7 +322,7 @@ RsGRouterItem *RsGRouterSerialiser::deserialise_RsGRouterMatrixCluesItem(void *d
|
||||
|
||||
RsGRouterMatrixCluesItem *item = new RsGRouterMatrixCluesItem() ;
|
||||
|
||||
ok &= getRawSha1(data,pktsize,&offset,item->destination_key) ;
|
||||
ok &= item->destination_key.deserialise(data,pktsize,offset) ;
|
||||
|
||||
uint32_t nb_clues = 0 ;
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &nb_clues);
|
||||
@ -395,7 +394,7 @@ bool RsGRouterGenericDataItem::serialise(void *data,uint32_t& size) const
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, routing_id);
|
||||
ok &= setRawSha1(data, tlvsize, &offset, destination_key);
|
||||
ok &= destination_key.serialise(data, tlvsize, offset) ;
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, data_size);
|
||||
|
||||
memcpy(&((uint8_t*)data)[offset],data_bytes,data_size) ;
|
||||
@ -445,24 +444,24 @@ uint32_t RsGRouterMatrixFriendListItem::serial_size() const
|
||||
{
|
||||
uint32_t s = 8 ; // header
|
||||
s += 4 ; // reverse_friend_indices.size()
|
||||
s += 16 * reverse_friend_indices.size() ; // sha1 for published_key
|
||||
s += RsFileHash::SIZE_IN_BYTES * reverse_friend_indices.size() ; // sha1 for published_key
|
||||
|
||||
return s ;
|
||||
}
|
||||
uint32_t RsGRouterRoutingInfoItem::serial_size() const
|
||||
{
|
||||
uint32_t s = 8 ; // header
|
||||
s += 4 ; // status_flags
|
||||
s += 16 ; // origin
|
||||
s += 8 ; // received_time
|
||||
s += 4 ; // tried_friends.size() ;
|
||||
uint32_t s = 8 ; // header
|
||||
s += 4 ; // status_flags
|
||||
s += origin.SIZE_IN_BYTES ; // origin
|
||||
s += 8 ; // received_time
|
||||
s += 4 ; // tried_friends.size() ;
|
||||
|
||||
s += tried_friends.size() * ( 16 + 8 ) ; // FriendTrialRecord
|
||||
s += tried_friends.size() * ( RsPeerId::SIZE_IN_BYTES + 8 ) ; // FriendTrialRecord
|
||||
|
||||
s += 4; // data_item->routing_id
|
||||
s += 20; // data_item->destination_key
|
||||
s += 4; // data_item->data_size
|
||||
s += data_item->data_size; // data_item->data_bytes
|
||||
s += 4; // data_item->routing_id
|
||||
s += data_item->destination_key.SIZE_IN_BYTES; // data_item->destination_key
|
||||
s += 4; // data_item->data_size
|
||||
s += data_item->data_size; // data_item->data_bytes
|
||||
|
||||
return s ;
|
||||
}
|
||||
@ -479,7 +478,7 @@ bool RsGRouterMatrixFriendListItem::serialise(void *data,uint32_t& size) const
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, reverse_friend_indices.size());
|
||||
|
||||
for(uint32_t i=0;ok && i<reverse_friend_indices.size();++i)
|
||||
ok &= setRawSSLId(data,tlvsize,&offset,reverse_friend_indices[i]) ;
|
||||
ok &= reverse_friend_indices[i].serialise(data,tlvsize,offset) ;
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
@ -498,7 +497,7 @@ bool RsGRouterMatrixCluesItem::serialise(void *data,uint32_t& size) const
|
||||
return false ;
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= setRawSha1(data,tlvsize,&offset,destination_key) ;
|
||||
ok &= destination_key.serialise(data,tlvsize,offset) ;
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, clues.size());
|
||||
|
||||
for(std::list<RoutingMatrixHitEntry>::const_iterator it2(clues.begin());it2!=clues.end();++it2)
|
||||
@ -518,37 +517,37 @@ bool RsGRouterMatrixCluesItem::serialise(void *data,uint32_t& size) const
|
||||
}
|
||||
bool RsGRouterRoutingInfoItem::serialise(void *data,uint32_t& size) const
|
||||
{
|
||||
uint32_t tlvsize,offset=0;
|
||||
bool ok = true;
|
||||
|
||||
if(!serialise_header(data,size,tlvsize,offset))
|
||||
return false ;
|
||||
uint32_t tlvsize,offset=0;
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, status_flags) ;
|
||||
ok &= setRawSSLId(data, tlvsize, &offset, origin) ;
|
||||
ok &= setRawTimeT(data, tlvsize, &offset, received_time) ;
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, tried_friends.size()) ;
|
||||
if(!serialise_header(data,size,tlvsize,offset))
|
||||
return false ;
|
||||
|
||||
for(std::list<FriendTrialRecord>::const_iterator it(tried_friends.begin());it!=tried_friends.end();++it)
|
||||
{
|
||||
ok &= setRawSSLId(data, tlvsize, &offset, (*it).friend_id) ;
|
||||
ok &= setRawTimeT(data, tlvsize, &offset, (*it).time_stamp) ;
|
||||
}
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, status_flags) ;
|
||||
ok &= origin.serialise(data, tlvsize, offset) ;
|
||||
ok &= setRawTimeT(data, tlvsize, &offset, received_time) ;
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, tried_friends.size()) ;
|
||||
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, data_item->routing_id) ;
|
||||
ok &= setRawSha1(data, tlvsize, &offset, data_item->destination_key) ;
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, data_item->data_size) ;
|
||||
for(std::list<FriendTrialRecord>::const_iterator it(tried_friends.begin());it!=tried_friends.end();++it)
|
||||
{
|
||||
ok &= (*it).friend_id.serialise(data, tlvsize, offset ) ;
|
||||
ok &= setRawTimeT(data, tlvsize, &offset, (*it).time_stamp) ;
|
||||
}
|
||||
|
||||
memcpy(&((uint8_t*)data)[offset],data_item->data_bytes,data_item->data_size) ;
|
||||
offset += data_item->data_size ;
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, data_item->routing_id) ;
|
||||
ok &= data_item->destination_key.serialise(data, tlvsize, offset) ;
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, data_item->data_size) ;
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
std::cerr << "rsfileitemserialiser::serialisedata() size error! " << std::endl;
|
||||
}
|
||||
memcpy(&((uint8_t*)data)[offset],data_item->data_bytes,data_item->data_size) ;
|
||||
offset += data_item->data_size ;
|
||||
|
||||
return ok;
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
std::cerr << "rsfileitemserialiser::serialisedata() size error! " << std::endl;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
@ -558,7 +557,7 @@ bool RsGRouterRoutingInfoItem::serialise(void *data,uint32_t& size) const
|
||||
std::ostream& RsGRouterPublishKeyItem::print(std::ostream& o, uint16_t)
|
||||
{
|
||||
o << "GRouterPublishKeyItem:" << std::endl ;
|
||||
o << " POW bytes : \""<< PGPIdType(pow_bytes).toStdString() << "\"" << std::endl ;
|
||||
o << " POW bytes : \""<< RsPgpId(pow_bytes).toStdString() << "\"" << std::endl ;
|
||||
o << " direct origin: \""<< PeerId() << "\"" << std::endl ;
|
||||
o << " Key: " << published_key.toStdString() << std::endl ;
|
||||
o << " Req. Id: " << std::hex << diffusion_id << std::dec << std::endl ;
|
||||
|
@ -26,7 +26,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "util/rsid.h"
|
||||
#include "retroshare/rstypes.h"
|
||||
#include "rsgrouter.h"
|
||||
#include "p3grouter.h"
|
||||
|
||||
@ -207,7 +207,7 @@ class RsGRouterMatrixFriendListItem: public RsGRouterItem
|
||||
|
||||
// packet data
|
||||
//
|
||||
std::vector<SSLIdType> reverse_friend_indices ;
|
||||
std::vector<RsPeerId> reverse_friend_indices ;
|
||||
};
|
||||
|
||||
class RsGRouterRoutingInfoItem: public RsGRouterItem, public GRouterRoutingInfo, public RsGRouterNonCopyableObject
|
||||
|
@ -33,7 +33,7 @@ GRouterMatrix::GRouterMatrix()
|
||||
}
|
||||
|
||||
bool GRouterMatrix::addRoutingClue( const GRouterKeyId& key_id,const GRouterServiceId& sid,float distance,
|
||||
const std::string& desc_string,const SSLIdType& source_friend)
|
||||
const std::string& desc_string,const RsPeerId& source_friend)
|
||||
{
|
||||
// 1 - get the friend index.
|
||||
//
|
||||
@ -76,18 +76,18 @@ bool GRouterMatrix::addRoutingClue( const GRouterKeyId& key_id,const GRouterServ
|
||||
|
||||
return true ;
|
||||
}
|
||||
uint32_t GRouterMatrix::getFriendId_const(const SSLIdType& source_friend) const
|
||||
uint32_t GRouterMatrix::getFriendId_const(const RsPeerId& source_friend) const
|
||||
{
|
||||
std::map<SSLIdType,uint32_t>::const_iterator it = _friend_indices.find(source_friend) ;
|
||||
std::map<RsPeerId,uint32_t>::const_iterator it = _friend_indices.find(source_friend) ;
|
||||
|
||||
if(it == _friend_indices.end())
|
||||
return _reverse_friend_indices.size() ;
|
||||
else
|
||||
return it->second ;
|
||||
}
|
||||
uint32_t GRouterMatrix::getFriendId(const SSLIdType& source_friend)
|
||||
uint32_t GRouterMatrix::getFriendId(const RsPeerId& source_friend)
|
||||
{
|
||||
std::map<SSLIdType,uint32_t>::const_iterator it = _friend_indices.find(source_friend) ;
|
||||
std::map<RsPeerId,uint32_t>::const_iterator it = _friend_indices.find(source_friend) ;
|
||||
|
||||
if(it == _friend_indices.end())
|
||||
{
|
||||
@ -130,7 +130,7 @@ void GRouterMatrix::debugDump() const
|
||||
}
|
||||
}
|
||||
|
||||
bool GRouterMatrix::computeRoutingProbabilities(const GRouterKeyId& key_id, const std::list<SSLIdType>& friends, std::map<SSLIdType,float>& probas) const
|
||||
bool GRouterMatrix::computeRoutingProbabilities(const GRouterKeyId& key_id, const std::list<RsPeerId>& friends, std::map<RsPeerId,float>& probas) const
|
||||
{
|
||||
// Routing probabilities are computed according to routing clues
|
||||
//
|
||||
@ -156,7 +156,7 @@ bool GRouterMatrix::computeRoutingProbabilities(const GRouterKeyId& key_id, cons
|
||||
}
|
||||
const std::vector<float>& w(it2->second) ;
|
||||
|
||||
for(std::list<SSLIdType>::const_iterator it(friends.begin());it!=friends.end();++it)
|
||||
for(std::list<RsPeerId>::const_iterator it(friends.begin());it!=friends.end();++it)
|
||||
{
|
||||
uint32_t findex = getFriendId_const(*it) ;
|
||||
|
||||
@ -170,7 +170,7 @@ bool GRouterMatrix::computeRoutingProbabilities(const GRouterKeyId& key_id, cons
|
||||
}
|
||||
|
||||
if(total > 0.0f)
|
||||
for(std::map<SSLIdType,float>::iterator it(probas.begin());it!=probas.end();++it)
|
||||
for(std::map<RsPeerId,float>::iterator it(probas.begin());it!=probas.end();++it)
|
||||
it->second /= total ;
|
||||
|
||||
return true ;
|
||||
|
@ -51,7 +51,7 @@ class GRouterMatrix
|
||||
// the computation accounts for the time at which the info was received and the
|
||||
// weight of each routing hit record.
|
||||
//
|
||||
bool computeRoutingProbabilities(const GRouterKeyId& id, const std::list<SSLIdType>& friends, std::map<SSLIdType,float>& probas) const ;
|
||||
bool computeRoutingProbabilities(const GRouterKeyId& id, const std::list<RsPeerId>& friends, std::map<RsPeerId,float>& probas) const ;
|
||||
|
||||
// Update routing probabilities for each key, accounting for all received events, but without
|
||||
// activity information
|
||||
@ -60,7 +60,7 @@ class GRouterMatrix
|
||||
|
||||
// Record one routing clue. The events can possibly be merged in time buckets.
|
||||
//
|
||||
bool addRoutingClue(const GRouterKeyId& id,const GRouterServiceId& sid,float distance,const std::string& desc_string,const SSLIdType& source_friend) ;
|
||||
bool addRoutingClue(const GRouterKeyId& id,const GRouterServiceId& sid,float distance,const std::string& desc_string,const RsPeerId& source_friend) ;
|
||||
|
||||
// Dump info in terminal.
|
||||
//
|
||||
@ -72,11 +72,11 @@ class GRouterMatrix
|
||||
private:
|
||||
// returns the friend id, possibly creating a new id.
|
||||
//
|
||||
uint32_t getFriendId(const SSLIdType& id) ;
|
||||
uint32_t getFriendId(const RsPeerId& id) ;
|
||||
|
||||
// returns the friend id. If not exist, returns _reverse_friend_indices.size()
|
||||
//
|
||||
uint32_t getFriendId_const(const SSLIdType& id) const;
|
||||
uint32_t getFriendId_const(const RsPeerId& id) const;
|
||||
|
||||
// List of events received and computed routing probabilities
|
||||
//
|
||||
@ -90,8 +90,8 @@ class GRouterMatrix
|
||||
// Routing weights. These are the result of a time convolution of the routing clues and weights
|
||||
// recorded in _routing_clues.
|
||||
//
|
||||
std::map<SSLIdType,uint32_t> _friend_indices ; // index for each friend to lookup in the routing matrix Not saved.
|
||||
std::vector<SSLIdType> _reverse_friend_indices ;// SSLid corresponding to each friend index. Saved.
|
||||
std::map<RsPeerId,uint32_t> _friend_indices ; // index for each friend to lookup in the routing matrix Not saved.
|
||||
std::vector<RsPeerId> _reverse_friend_indices ;// SSLid corresponding to each friend index. Saved.
|
||||
|
||||
};
|
||||
|
||||
|
@ -68,7 +68,7 @@ class GRouterPublishedKeyInfo
|
||||
|
||||
struct FriendTrialRecord
|
||||
{
|
||||
SSLIdType friend_id ; // id of the friend
|
||||
RsPeerId friend_id ; // id of the friend
|
||||
time_t time_stamp ; // time of the last tried
|
||||
};
|
||||
|
||||
@ -79,7 +79,7 @@ class GRouterRoutingInfo
|
||||
|
||||
uint32_t status_flags ; // pending, waiting, etc.
|
||||
std::list<FriendTrialRecord> tried_friends ; // list of friends to which the item was sent ordered with time.
|
||||
SSLIdType origin ; // which friend sent us that item
|
||||
RsPeerId origin ; // which friend sent us that item
|
||||
time_t received_time ; // time at which the item was received
|
||||
};
|
||||
|
||||
|
@ -23,6 +23,153 @@
|
||||
*
|
||||
*/
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Decentralized routing
|
||||
// =====================
|
||||
//
|
||||
// Use cases:
|
||||
// - Peer A asks for B's key, for which he has the signature, or the ID.
|
||||
// - Peer A wants to send a private msg to peer C, for which he has the public key
|
||||
// - Peer A wants to contact a channel's owner, a group owner, a forum owner, etc.
|
||||
// - Peer C needs to route msg/key requests from unknown peer, to unknown peer so that the information
|
||||
// eventually reach their destination.
|
||||
//
|
||||
// Main idea: Each peer holds a local routing table, a matrix with probabilities that each friend
|
||||
// is a correct path for a given key ID.
|
||||
//
|
||||
// The routing tables are updated as messages go back and forth. Successful
|
||||
// interactions feed the routing table with information of where to route the
|
||||
// packets.
|
||||
//
|
||||
// The routing is kept probabilistic, meaning that the optimal route is not
|
||||
// always chosen, but the randomness helps updating the routing probabilities.
|
||||
//
|
||||
// Services that might use the router (All services really...)
|
||||
// - Identity manager (p3Identity)
|
||||
// - asks identities i.e. RSA public keys (i.e. sends dentity requests through router)
|
||||
// - Messenger
|
||||
// - sends/receives messages to distant peers
|
||||
// - Channels, forums, posted, etc.
|
||||
// - send messages to the origin of the channel/forum/posted
|
||||
//
|
||||
// GUI
|
||||
// - a debug panel should show the routing info: probabilities for all known IDs
|
||||
// - routing probabilities for a given ID accordign to who's connected
|
||||
//
|
||||
// Decentralized routing algorithm:
|
||||
// - tick() method
|
||||
// * calls autoWash(), send() and receive()
|
||||
//
|
||||
// - message passing
|
||||
// - upward:
|
||||
// * Forward msg to friends according to probabilities.
|
||||
// * If all equal, send to all friends (or a rando subset of them).
|
||||
// * keep the local routing info in a cache that is saved (Which peer issued the msg)
|
||||
// - which probability was used to chose this friend (will be useful
|
||||
// to compute the routing contribution if the msg is ACK-ed)
|
||||
//
|
||||
// - downward: look into routing cache. If info not present, drop the item.
|
||||
// Forward item into stored direction.
|
||||
//
|
||||
// - routing probability computation: count number of times a reliable info is obtained from
|
||||
// which direction for which identity
|
||||
// * the count is a floating point number, since weights can be assigned to each info
|
||||
// (especially for importance sampling)
|
||||
// * init: all friends have equal count of 0 (or 1, well, we'll have to make this right).
|
||||
// * We use importance sampling, meaning that when peer relays a msg from ID:
|
||||
// count[ID, peer] += 1.0 / importance
|
||||
//
|
||||
// ... where importance was the probability of chosing peer for the
|
||||
// route upward.
|
||||
//
|
||||
// * probability of forward is proportional to count.
|
||||
//
|
||||
// - routing cache
|
||||
// * this cache stores messages IDs (like turtle router) but is saved on disk
|
||||
// * it is used to remember where to send back responses to messages, and
|
||||
// with what probability the route was chosen.
|
||||
// * cache items have a TTL and the cache is cleaned regularly.
|
||||
//
|
||||
// - routing matrix
|
||||
// * the structure is fed by other services, when they receive key IDs.
|
||||
// * stores for each identity the count of how many times each peer gave reliable info for that ID.
|
||||
// That information should be enough to route packets in the correct direction.
|
||||
// * saved to disk.
|
||||
// * all contributions should have a time stamp. Regularly, the oldest contributions are removed.
|
||||
//
|
||||
// struct RoutingMatrixHitEntry
|
||||
// {
|
||||
// float weight ;
|
||||
// time_t time_stamp ;
|
||||
// }
|
||||
// typedef std::map<std::string,std::list<RoutingMatrixHitEntry> > RSAKeyRoutingMap ;
|
||||
//
|
||||
// class RoutingMatrix
|
||||
// {
|
||||
// public:
|
||||
// // Computes the routing probabilities for this id for the given list of friends.
|
||||
// // the computation accounts for the time at which the info was received and the
|
||||
// // weight of each routing hit record.
|
||||
// //
|
||||
// bool computeRoutingProbabilities(RSAKeyIDType id, const std::vector<SSLIdType>& friends,
|
||||
// std::vector<float>& probas) const ;
|
||||
//
|
||||
// // remove oldest entries.
|
||||
// bool autoWash() ;
|
||||
//
|
||||
// // Record one routing clue. The events can possibly be merged in time buckets.
|
||||
// //
|
||||
// bool addRoutingEvent(RSAKeyIDType id,const SSLIdType& which friend) ;
|
||||
//
|
||||
// private:
|
||||
// std::map<RSAKeyIDType, RSAKeyRoutingMap> _known_keys ;
|
||||
// };
|
||||
//
|
||||
// - Routed packets: we use a common packet type for all services:
|
||||
//
|
||||
// We need two abstract item types:
|
||||
//
|
||||
// * Data packet
|
||||
// - packet unique ID (sha1, or uint64_t)
|
||||
// - destination ID (for Dn packets, the destination is the source!)
|
||||
// - packet type: Id request, Message, etc.
|
||||
// - packet service ID (Can be messenging, channels, etc).
|
||||
// - packet data (void* + size_t)
|
||||
// - flags (such as ACK or response required, and packet direction)
|
||||
// * ACK packet.
|
||||
// - packet unique ID (the id of the corresponding data)
|
||||
// - flags (reason for ACK. Could be data delivered, or error, too far, etc)
|
||||
//
|
||||
// - Data storage packets
|
||||
// * We need storage packets for the matrix states.
|
||||
// * General routing options info?
|
||||
//
|
||||
// - estimated memory cost
|
||||
// For each identity, the matrix needs
|
||||
// - hits for each friend peer with time stamps. That means 8 bytes per hit.
|
||||
// That is for 1000 identities, having at most 100 hits each (We keep
|
||||
// the hits below a maximum. 100 seems ok.), that is 1000*100*8 < 1MB. Not much.
|
||||
//
|
||||
// - Main difficulties:
|
||||
// * have a good re-try strategy if a msg does not arrive.
|
||||
// * handle peer availability. In forward mode: easy. In backward mode:
|
||||
// difficult. We should wait, and send back the packet if possible.
|
||||
// * robustness
|
||||
// * security: avoid flooding, and message alteration.
|
||||
//
|
||||
// - Questions to be solved
|
||||
// * how do we talk to other services?
|
||||
// - keep a list of services?
|
||||
//
|
||||
// - in practice, services will need to send requests, and expect responses.
|
||||
// * gxs (p3identity) asks for a key, gxs (p3identity) should get the key.
|
||||
// * msg service wants to send a distant msg, or msg receives a distant msg.
|
||||
//
|
||||
// => we need abstract packets and service ids.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "util/rsrandom.h"
|
||||
#include "pqi/p3linkmgr.h"
|
||||
#include "serialiser/rsconfigitems.h"
|
||||
@ -175,13 +322,9 @@ void p3GRouter::routePendingObjects()
|
||||
std::cerr << "p3GRouter::routeObjects() triage phase:" << std::endl;
|
||||
std::cerr << "Cached Items : " << _pending_messages.size() << std::endl;
|
||||
|
||||
std::list<std::string> lst_tmp ;
|
||||
std::list<SSLIdType> lst ;
|
||||
mLinkMgr->getOnlineList(lst_tmp) ;
|
||||
SSLIdType own_id( mLinkMgr->getOwnId() );
|
||||
|
||||
for(std::list<std::string>::const_iterator it(lst_tmp.begin());it!=lst_tmp.end();++it)
|
||||
lst.push_back(SSLIdType(*it)) ;
|
||||
std::list<RsPeerId> lst ;
|
||||
mLinkMgr->getOnlineList(lst) ;
|
||||
RsPeerId own_id( mLinkMgr->getOwnId() );
|
||||
|
||||
for(std::map<GRouterMsgPropagationId, GRouterRoutingInfo>::iterator it(_pending_messages.begin());it!=_pending_messages.end();)
|
||||
if((it->second.status_flags & RS_GROUTER_ROUTING_STATE_PEND) || (it->second.status_flags == RS_GROUTER_ROUTING_STATE_SENT && it->second.tried_friends.front().time_stamp+RS_GROUTER_ROUTING_WAITING_TIME < now))
|
||||
@ -193,8 +336,8 @@ void p3GRouter::routePendingObjects()
|
||||
std::cerr << " Flags : " << it->second.status_flags << std::endl;
|
||||
std::cerr << " Probabilities: " << std::endl;
|
||||
|
||||
std::map<SSLIdType,float> probas ; // friends probabilities for online friend list.
|
||||
SSLIdType routed_friend ; // friend chosen for the next hop
|
||||
std::map<RsPeerId,float> probas ; // friends probabilities for online friend list.
|
||||
RsPeerId routed_friend ; // friend chosen for the next hop
|
||||
float best_proba = 0.0f; // temp variable used to select the best proba
|
||||
bool should_remove = false ; // should we remove this from the map?
|
||||
|
||||
@ -223,7 +366,7 @@ void p3GRouter::routePendingObjects()
|
||||
|
||||
bool friend_found = false ;
|
||||
|
||||
for(std::map<SSLIdType,float>::const_iterator it2(probas.begin());it2!=probas.end();++it2)
|
||||
for(std::map<RsPeerId,float>::const_iterator it2(probas.begin());it2!=probas.end();++it2)
|
||||
{
|
||||
std::cerr << " " << it2->first.toStdString() << " : " << it2->second << std::endl;
|
||||
|
||||
@ -255,10 +398,10 @@ void p3GRouter::routePendingObjects()
|
||||
|
||||
std::cerr << " Sending..." << std::endl;
|
||||
// send
|
||||
new_item->PeerId(routed_friend.toStdString()) ;
|
||||
new_item->PeerId(routed_friend) ;
|
||||
sendItem(new_item) ;
|
||||
}
|
||||
else if(it->second.origin.toStdString() != mLinkMgr->getOwnId() || std::find(lst.begin(),lst.end(),it->second.origin) != lst.end())
|
||||
else if(it->second.origin != mLinkMgr->getOwnId() || std::find(lst.begin(),lst.end(),it->second.origin) != lst.end())
|
||||
{
|
||||
// There's no correct friend to send this item to. We keep it for a while. If it's too old,
|
||||
// we discard it. For now, the procedure is to send back an ACK.
|
||||
@ -320,7 +463,7 @@ void p3GRouter::publishKeys()
|
||||
item.randomized_distance = drand48() ;
|
||||
item.fingerprint = info.fpr;
|
||||
item.description_string = info.description_string ;
|
||||
item.PeerId("") ; // no peer id => key is forwarded to all friends.
|
||||
item.PeerId(RsPeerId()) ; // no peer id => key is forwarded to all friends.
|
||||
|
||||
locked_forwardKey(item) ;
|
||||
|
||||
@ -332,14 +475,14 @@ void p3GRouter::publishKeys()
|
||||
|
||||
void p3GRouter::locked_forwardKey(const RsGRouterPublishKeyItem& item)
|
||||
{
|
||||
std::list<std::string> connected_peers ;
|
||||
std::list<RsPeerId> connected_peers ;
|
||||
mLinkMgr->getOnlineList(connected_peers) ;
|
||||
|
||||
std::cerr << " Forwarding key item to all available friends..." << std::endl;
|
||||
|
||||
// get list of connected friends, and broadcast to all of them
|
||||
//
|
||||
for(std::list<std::string>::const_iterator it(connected_peers.begin());it!=connected_peers.end();++it)
|
||||
for(std::list<RsPeerId>::const_iterator it(connected_peers.begin());it!=connected_peers.end();++it)
|
||||
if(item.PeerId() != *it)
|
||||
{
|
||||
std::cerr << " sending to " << (*it) << std::endl;
|
||||
@ -432,7 +575,7 @@ void p3GRouter::handleRecvPublishKeyItem(RsGRouterPublishKeyItem *item)
|
||||
|
||||
// update the route matrix
|
||||
|
||||
_routing_matrix.addRoutingClue(item->published_key,item->service_id,item->randomized_distance,item->description_string,SSLIdType(item->PeerId())) ;
|
||||
_routing_matrix.addRoutingClue(item->published_key,item->service_id,item->randomized_distance,item->description_string,RsPeerId(item->PeerId())) ;
|
||||
|
||||
// forward the key to other peers according to key forwarding cache
|
||||
|
||||
@ -496,7 +639,7 @@ void p3GRouter::handleRecvACKItem(RsGRouterACKItem *item)
|
||||
break ;
|
||||
}
|
||||
|
||||
if(it->second.origin.toStdString() == mLinkMgr->getOwnId())
|
||||
if(it->second.origin == mLinkMgr->getOwnId())
|
||||
{
|
||||
// find the client service and notify it.
|
||||
std::cerr << " We're owner: should notify client id" << std::endl;
|
||||
@ -511,7 +654,7 @@ void p3GRouter::handleRecvACKItem(RsGRouterACKItem *item)
|
||||
void p3GRouter::handleRecvDataItem(RsGRouterGenericDataItem *item)
|
||||
{
|
||||
RsStackMutex mtx(grMtx) ;
|
||||
std::cerr << "Received data item for key " << item->destination_key.toStdString() << std::endl;
|
||||
std::cerr << "Received data item for key " << item->destination_key << std::endl;
|
||||
|
||||
// Do we have this item in the cache already?
|
||||
// - if not, add in the pending items
|
||||
@ -541,7 +684,7 @@ void p3GRouter::handleRecvDataItem(RsGRouterGenericDataItem *item)
|
||||
else
|
||||
info.status_flags = RS_GROUTER_ROUTING_STATE_PEND ;
|
||||
|
||||
info.origin = SSLIdType(item->PeerId()) ;
|
||||
info.origin = RsPeerId(item->PeerId()) ;
|
||||
info.received_time = time(NULL) ;
|
||||
|
||||
_pending_messages[item->routing_id] = info ;
|
||||
@ -588,7 +731,7 @@ void p3GRouter::sendData(const GRouterKeyId& destination, RsGRouterGenericDataIt
|
||||
|
||||
info.data_item = item ;
|
||||
info.status_flags = RS_GROUTER_ROUTING_STATE_PEND ;
|
||||
info.origin = SSLIdType(mLinkMgr->getOwnId()) ;
|
||||
info.origin = RsPeerId(mLinkMgr->getOwnId()) ;
|
||||
info.received_time = time(NULL) ;
|
||||
|
||||
// Make sure we have a unique id (at least locally).
|
||||
@ -606,13 +749,13 @@ void p3GRouter::sendData(const GRouterKeyId& destination, RsGRouterGenericDataIt
|
||||
_pending_messages[propagation_id] = info ;
|
||||
}
|
||||
|
||||
void p3GRouter::sendACK(const SSLIdType& peer, GRouterMsgPropagationId mid, uint32_t ack_flags)
|
||||
void p3GRouter::sendACK(const RsPeerId& peer, GRouterMsgPropagationId mid, uint32_t ack_flags)
|
||||
{
|
||||
RsGRouterACKItem *item = new RsGRouterACKItem ;
|
||||
|
||||
item->state = ack_flags ;
|
||||
item->mid = mid ;
|
||||
item->PeerId(peer.toStdString()) ;
|
||||
item->PeerId(peer) ;
|
||||
|
||||
sendItem(item) ;
|
||||
}
|
||||
|
@ -31,7 +31,7 @@
|
||||
#include "rsgrouter.h"
|
||||
#include "services/p3service.h"
|
||||
#include "pqi/p3cfgmgr.h"
|
||||
#include "util/rsid.h"
|
||||
#include "retroshare/rstypes.h"
|
||||
|
||||
#include "groutertypes.h"
|
||||
#include "groutermatrix.h"
|
||||
@ -92,7 +92,7 @@ class p3GRouter: public RsGRouter, public p3Service, public p3Config
|
||||
// Sends an ACK to the origin of the msg. This is used to notify for
|
||||
// unfound route, or message correctly received, depending on the particular situation.
|
||||
//
|
||||
void sendACK(const SSLIdType& peer,GRouterMsgPropagationId mid, uint32_t flags) ;
|
||||
void sendACK(const RsPeerId& peer,GRouterMsgPropagationId mid, uint32_t flags) ;
|
||||
|
||||
//===================================================//
|
||||
// Interface with RsGRouter //
|
||||
|
@ -278,17 +278,21 @@ RsGxsGrpMetaData* RsDataService::locked_getGrpMeta(RetroCursor &c)
|
||||
uint32_t data_len = 0;
|
||||
|
||||
// grpId
|
||||
c.getString(COL_GRP_ID, grpMeta->mGroupId);
|
||||
|
||||
// required definition of a group
|
||||
ok &= !grpMeta->mGroupId.empty();
|
||||
std::string tempId;
|
||||
c.getString(COL_GRP_ID, tempId);
|
||||
grpMeta->mGroupId = tempId;
|
||||
|
||||
|
||||
c.getString(COL_IDENTITY, grpMeta->mAuthorId);
|
||||
|
||||
c.getString(COL_IDENTITY, tempId);
|
||||
grpMeta->mAuthorId = tempId;
|
||||
c.getString(COL_GRP_NAME, grpMeta->mGroupName);
|
||||
c.getString(COL_ORIG_GRP_ID, grpMeta->mOrigGrpId);
|
||||
c.getString(COL_ORIG_GRP_ID, tempId);
|
||||
grpMeta->mOrigGrpId = tempId;
|
||||
c.getString(COL_GRP_SERV_STRING, grpMeta->mServiceString);
|
||||
c.getString(COL_HASH, grpMeta->mHash);
|
||||
std::string temp;
|
||||
c.getString(COL_HASH, temp);
|
||||
grpMeta->mHash = temp;
|
||||
grpMeta->mReputationCutOff = c.getInt32(COL_GRP_REP_CUTOFF);
|
||||
grpMeta->mSignFlags = c.getInt32(COL_GRP_SIGN_FLAGS);
|
||||
|
||||
@ -311,15 +315,20 @@ RsGxsGrpMetaData* RsDataService::locked_getGrpMeta(RetroCursor &c)
|
||||
grpMeta->mLastPost = c.getInt32(COL_GRP_LAST_POST);
|
||||
grpMeta->mGroupStatus = c.getInt32(COL_GRP_STATUS);
|
||||
|
||||
c.getString(COL_GRP_CIRCLE_ID, grpMeta->mCircleId);
|
||||
c.getString(COL_GRP_CIRCLE_ID, tempId);
|
||||
grpMeta->mCircleId = tempId;
|
||||
grpMeta->mCircleType = c.getInt32(COL_GRP_CIRCL_TYPE);
|
||||
c.getString(COL_GRP_INTERN_CIRCLE, grpMeta->mInternalCircle);
|
||||
c.getString(COL_GRP_ORIGINATOR, grpMeta->mOriginator);
|
||||
c.getString(COL_GRP_INTERN_CIRCLE, tempId);
|
||||
grpMeta->mInternalCircle = tempId;
|
||||
|
||||
std::string s ; c.getString(COL_GRP_ORIGINATOR, s) ;
|
||||
grpMeta->mOriginator = RsPeerId(s);
|
||||
grpMeta->mAuthenFlags = c.getInt32(COL_GRP_AUTHEN_FLAGS);
|
||||
grpMeta->mRecvTS = c.getInt32(COL_GRP_RECV_TS);
|
||||
|
||||
|
||||
c.getString(COL_PARENT_GRP_ID, grpMeta->mParentGrpId);
|
||||
c.getString(COL_PARENT_GRP_ID, tempId);
|
||||
grpMeta->mParentGrpId = tempId;
|
||||
|
||||
if(ok)
|
||||
return grpMeta;
|
||||
@ -344,8 +353,8 @@ RsNxsGrp* RsDataService::locked_getGroup(RetroCursor &c)
|
||||
uint32_t data_len = 0;
|
||||
|
||||
// grpId
|
||||
c.getString(COL_ACT_GROUP_ID, grp->grpId);
|
||||
ok &= !grp->grpId.empty();
|
||||
c.getStringT<RsGxsGroupId>(COL_ACT_GROUP_ID, grp->grpId);
|
||||
ok &= !grp->grpId.isNull();
|
||||
|
||||
offset = 0; data_len = 0;
|
||||
if(ok){
|
||||
@ -394,17 +403,24 @@ RsGxsMsgMetaData* RsDataService::locked_getMsgMeta(RetroCursor &c)
|
||||
char* data = NULL;
|
||||
|
||||
|
||||
c.getString(COL_GRP_ID, msgMeta->mGroupId);
|
||||
c.getString(COL_MSG_ID, msgMeta->mMsgId);
|
||||
|
||||
std::string gId;
|
||||
c.getString(COL_GRP_ID, gId);
|
||||
msgMeta->mGroupId = RsGxsGroupId(gId);
|
||||
std::string temp;
|
||||
c.getString(COL_MSG_ID, temp);
|
||||
msgMeta->mMsgId = temp;
|
||||
// without these, a msg is meaningless
|
||||
ok &= (!msgMeta->mGroupId.empty()) && (!msgMeta->mMsgId.empty());
|
||||
ok &= (!msgMeta->mGroupId.isNull()) && (!msgMeta->mMsgId.isNull());
|
||||
|
||||
c.getString(COL_ORIG_MSG_ID, msgMeta->mOrigMsgId);
|
||||
c.getString(COL_IDENTITY, msgMeta->mAuthorId);
|
||||
c.getString(COL_ORIG_MSG_ID, temp);
|
||||
msgMeta->mOrigMsgId = temp;
|
||||
c.getString(COL_IDENTITY, temp);
|
||||
msgMeta->mAuthorId = temp;
|
||||
c.getString(COL_MSG_NAME, msgMeta->mMsgName);
|
||||
c.getString(COL_MSG_SERV_STRING, msgMeta->mServiceString);
|
||||
c.getString(COL_HASH, msgMeta->mHash);
|
||||
|
||||
c.getString(COL_HASH, temp);
|
||||
msgMeta->mHash = temp;
|
||||
msgMeta->recvTS = c.getInt32(COL_MSG_RECV_TS);
|
||||
|
||||
offset = 0;
|
||||
@ -418,8 +434,10 @@ RsGxsMsgMetaData* RsDataService::locked_getMsgMeta(RetroCursor &c)
|
||||
offset = 0; data_len = 0;
|
||||
|
||||
// thread and parent id
|
||||
c.getString(COL_THREAD_ID, msgMeta->mThreadId);
|
||||
c.getString(COL_PARENT_ID, msgMeta->mParentId);
|
||||
c.getString(COL_THREAD_ID, temp);
|
||||
msgMeta->mThreadId = temp;
|
||||
c.getString(COL_PARENT_ID, temp);
|
||||
msgMeta->mParentId = temp;
|
||||
|
||||
// local meta
|
||||
msgMeta->mMsgStatus = c.getInt32(COL_MSG_STATUS);
|
||||
@ -444,10 +462,12 @@ RsNxsMsg* RsDataService::locked_getMessage(RetroCursor &c)
|
||||
uint32_t data_len = 0,
|
||||
offset = 0;
|
||||
char* data = NULL;
|
||||
c.getString(COL_ACT_GROUP_ID, msg->grpId);
|
||||
c.getString(COL_ACT_MSG_ID, msg->msgId);
|
||||
c.getStringT<RsGxsGroupId>(COL_ACT_GROUP_ID, msg->grpId);
|
||||
std::string temp;
|
||||
c.getString(COL_ACT_MSG_ID, temp);
|
||||
msg->msgId = temp;
|
||||
|
||||
ok &= (!msg->grpId.empty()) && (!msg->msgId.empty());
|
||||
ok &= (!msg->grpId.isNull()) && (!msg->msgId.isNull());
|
||||
|
||||
offset = 0; data_len = 0;
|
||||
if(ok){
|
||||
@ -504,7 +524,7 @@ int RsDataService::storeMessage(std::map<RsNxsMsg *, RsGxsMsgMetaData *> &msg)
|
||||
if(!validSize(msgPtr)) continue;
|
||||
|
||||
// create or access file in binary
|
||||
std::string msgFile = mServiceDir + "/" + msgPtr->grpId + "-msgs";
|
||||
std::string msgFile = mServiceDir + "/" + msgPtr->grpId.toStdString() + "-msgs";
|
||||
std::fstream ostrm(msgFile.c_str(), std::ios::binary | std::ios::app | std::ios::out);
|
||||
ostrm.seekg(0, std::ios::end); // go to end to append
|
||||
uint32_t offset = ostrm.tellg(); // get fill offset
|
||||
@ -514,10 +534,10 @@ int RsDataService::storeMessage(std::map<RsNxsMsg *, RsGxsMsgMetaData *> &msg)
|
||||
cv.put(KEY_NXS_FILE_OFFSET, (int32_t)offset);
|
||||
cv.put(KEY_NXS_FILE, msgFile);
|
||||
cv.put(KEY_NXS_FILE_LEN, (int32_t)msgPtr->msg.TlvSize());
|
||||
cv.put(KEY_MSG_ID, msgMetaPtr->mMsgId);
|
||||
cv.put(KEY_GRP_ID, msgMetaPtr->mGroupId);
|
||||
cv.put(KEY_MSG_ID, msgMetaPtr->mMsgId.toStdString());
|
||||
cv.put(KEY_GRP_ID, msgMetaPtr->mGroupId.toStdString());
|
||||
cv.put(KEY_NXS_SERV_STRING, msgMetaPtr->mServiceString);
|
||||
cv.put(KEY_NXS_HASH, msgMetaPtr->mHash);
|
||||
cv.put(KEY_NXS_HASH, msgMetaPtr->mHash.toStdString());
|
||||
cv.put(KEY_RECV_TS, (int32_t)msgMetaPtr->recvTS);
|
||||
|
||||
|
||||
@ -525,7 +545,7 @@ int RsDataService::storeMessage(std::map<RsNxsMsg *, RsGxsMsgMetaData *> &msg)
|
||||
offset = 0;
|
||||
msgMetaPtr->signSet.SetTlv(signSetData, msgMetaPtr->signSet.TlvSize(), &offset);
|
||||
cv.put(KEY_SIGN_SET, msgMetaPtr->signSet.TlvSize(), signSetData);
|
||||
cv.put(KEY_NXS_IDENTITY, msgMetaPtr->mAuthorId);
|
||||
cv.put(KEY_NXS_IDENTITY, msgMetaPtr->mAuthorId.toStdString());
|
||||
|
||||
|
||||
cv.put(KEY_NXS_FLAGS, (int32_t) msgMetaPtr->mMsgFlags);
|
||||
@ -536,9 +556,9 @@ int RsDataService::storeMessage(std::map<RsNxsMsg *, RsGxsMsgMetaData *> &msg)
|
||||
msgPtr->meta.SetTlv(metaData, msgPtr->meta.TlvSize(), &offset);
|
||||
cv.put(KEY_NXS_META, msgPtr->meta.TlvSize(), metaData);
|
||||
|
||||
cv.put(KEY_MSG_PARENT_ID, msgMetaPtr->mParentId);
|
||||
cv.put(KEY_MSG_THREAD_ID, msgMetaPtr->mThreadId);
|
||||
cv.put(KEY_ORIG_MSG_ID, msgMetaPtr->mOrigMsgId);
|
||||
cv.put(KEY_MSG_PARENT_ID, msgMetaPtr->mParentId.toStdString());
|
||||
cv.put(KEY_MSG_THREAD_ID, msgMetaPtr->mThreadId.toStdString());
|
||||
cv.put(KEY_ORIG_MSG_ID, msgMetaPtr->mOrigMsgId.toStdString());
|
||||
cv.put(KEY_MSG_NAME, msgMetaPtr->mMsgName);
|
||||
|
||||
// now local meta
|
||||
@ -598,7 +618,7 @@ int RsDataService::storeGroup(std::map<RsNxsGrp *, RsGxsGrpMetaData *> &grp)
|
||||
// if data is larger than max item size do not add
|
||||
if(!validSize(grpPtr)) continue;
|
||||
|
||||
std::string grpFile = mServiceDir + "/" + grpPtr->grpId;
|
||||
std::string grpFile = mServiceDir + "/" + grpPtr->grpId.toStdString();
|
||||
std::fstream ostrm(grpFile.c_str(), std::ios::binary | std::ios::app | std::ios::out);
|
||||
ostrm.seekg(0, std::ios::end); // go to end to append
|
||||
uint32_t offset = ostrm.tellg(); // get fill offset
|
||||
@ -613,25 +633,25 @@ int RsDataService::storeGroup(std::map<RsNxsGrp *, RsGxsGrpMetaData *> &grp)
|
||||
cv.put(KEY_NXS_FILE_OFFSET, (int32_t)offset);
|
||||
cv.put(KEY_NXS_FILE_LEN, (int32_t)grpPtr->grp.TlvSize());
|
||||
cv.put(KEY_NXS_FILE, grpFile);
|
||||
cv.put(KEY_GRP_ID, grpPtr->grpId);
|
||||
cv.put(KEY_GRP_ID, grpPtr->grpId.toStdString());
|
||||
cv.put(KEY_GRP_NAME, grpMetaPtr->mGroupName);
|
||||
cv.put(KEY_ORIG_GRP_ID, grpMetaPtr->mOrigGrpId);
|
||||
cv.put(KEY_ORIG_GRP_ID, grpMetaPtr->mOrigGrpId.toStdString());
|
||||
cv.put(KEY_NXS_SERV_STRING, grpMetaPtr->mServiceString);
|
||||
cv.put(KEY_NXS_FLAGS, (int32_t)grpMetaPtr->mGroupFlags);
|
||||
cv.put(KEY_TIME_STAMP, (int32_t)grpMetaPtr->mPublishTs);
|
||||
cv.put(KEY_GRP_SIGN_FLAGS, (int32_t)grpMetaPtr->mSignFlags);
|
||||
cv.put(KEY_GRP_CIRCLE_ID, grpMetaPtr->mCircleId);
|
||||
cv.put(KEY_GRP_CIRCLE_ID, grpMetaPtr->mCircleId.toStdString());
|
||||
cv.put(KEY_GRP_CIRCLE_TYPE, (int32_t)grpMetaPtr->mCircleType);
|
||||
cv.put(KEY_GRP_INTERNAL_CIRCLE, grpMetaPtr->mInternalCircle);
|
||||
cv.put(KEY_GRP_ORIGINATOR, grpMetaPtr->mOriginator);
|
||||
cv.put(KEY_GRP_INTERNAL_CIRCLE, grpMetaPtr->mInternalCircle.toStdString());
|
||||
cv.put(KEY_GRP_ORIGINATOR, grpMetaPtr->mOriginator.toStdString());
|
||||
cv.put(KEY_GRP_AUTHEN_FLAGS, (int32_t)grpMetaPtr->mAuthenFlags);
|
||||
cv.put(KEY_PARENT_GRP_ID, grpMetaPtr->mParentGrpId);
|
||||
cv.put(KEY_NXS_HASH, grpMetaPtr->mHash);
|
||||
cv.put(KEY_PARENT_GRP_ID, grpMetaPtr->mParentGrpId.toStdString());
|
||||
cv.put(KEY_NXS_HASH, grpMetaPtr->mHash.toStdString());
|
||||
cv.put(KEY_RECV_TS, (int32_t)grpMetaPtr->mRecvTS);
|
||||
cv.put(KEY_GRP_REP_CUTOFF, (int32_t)grpMetaPtr->mReputationCutOff);
|
||||
|
||||
if(! (grpMetaPtr->mAuthorId.empty()) ){
|
||||
cv.put(KEY_NXS_IDENTITY, grpMetaPtr->mAuthorId);
|
||||
if(! (grpMetaPtr->mAuthorId.isNull()) ){
|
||||
cv.put(KEY_NXS_IDENTITY, grpMetaPtr->mAuthorId.toStdString());
|
||||
}
|
||||
|
||||
offset = 0;
|
||||
@ -693,7 +713,7 @@ int RsDataService::updateGroup(std::map<RsNxsGrp *, RsGxsGrpMetaData *> &grp)
|
||||
// if data is larger than max item size do not add
|
||||
if(!validSize(grpPtr)) continue;
|
||||
|
||||
std::string grpFile = mServiceDir + "/" + grpPtr->grpId;
|
||||
std::string grpFile = mServiceDir + "/" + grpPtr->grpId.toStdString();
|
||||
std::ofstream ostrm(grpFile.c_str(), std::ios::binary | std::ios::trunc);
|
||||
uint32_t offset = 0; // get file offset
|
||||
|
||||
@ -707,22 +727,22 @@ int RsDataService::updateGroup(std::map<RsNxsGrp *, RsGxsGrpMetaData *> &grp)
|
||||
cv.put(KEY_NXS_FILE_OFFSET, (int32_t)offset);
|
||||
cv.put(KEY_NXS_FILE_LEN, (int32_t)grpPtr->grp.TlvSize());
|
||||
cv.put(KEY_NXS_FILE, grpFile);
|
||||
cv.put(KEY_GRP_ID, grpPtr->grpId);
|
||||
cv.put(KEY_GRP_ID, grpPtr->grpId.toStdString());
|
||||
cv.put(KEY_GRP_NAME, grpMetaPtr->mGroupName);
|
||||
cv.put(KEY_ORIG_GRP_ID, grpMetaPtr->mOrigGrpId);
|
||||
cv.put(KEY_ORIG_GRP_ID, grpMetaPtr->mOrigGrpId.toStdString());
|
||||
cv.put(KEY_NXS_SERV_STRING, grpMetaPtr->mServiceString);
|
||||
cv.put(KEY_NXS_FLAGS, (int32_t)grpMetaPtr->mGroupFlags);
|
||||
cv.put(KEY_TIME_STAMP, (int32_t)grpMetaPtr->mPublishTs);
|
||||
cv.put(KEY_GRP_SIGN_FLAGS, (int32_t)grpMetaPtr->mSignFlags);
|
||||
cv.put(KEY_GRP_CIRCLE_ID, grpMetaPtr->mCircleId);
|
||||
cv.put(KEY_GRP_CIRCLE_ID, grpMetaPtr->mCircleId.toStdString());
|
||||
cv.put(KEY_GRP_CIRCLE_TYPE, (int32_t)grpMetaPtr->mCircleType);
|
||||
cv.put(KEY_GRP_INTERNAL_CIRCLE, grpMetaPtr->mInternalCircle);
|
||||
cv.put(KEY_GRP_ORIGINATOR, grpMetaPtr->mOriginator);
|
||||
cv.put(KEY_GRP_INTERNAL_CIRCLE, grpMetaPtr->mInternalCircle.toStdString());
|
||||
cv.put(KEY_GRP_ORIGINATOR, grpMetaPtr->mOriginator.toStdString());
|
||||
cv.put(KEY_GRP_AUTHEN_FLAGS, (int32_t)grpMetaPtr->mAuthenFlags);
|
||||
cv.put(KEY_NXS_HASH, grpMetaPtr->mHash);
|
||||
cv.put(KEY_NXS_HASH, grpMetaPtr->mHash.toStdString());
|
||||
|
||||
if(! (grpMetaPtr->mAuthorId.empty()) ){
|
||||
cv.put(KEY_NXS_IDENTITY, grpMetaPtr->mAuthorId);
|
||||
if(! (grpMetaPtr->mAuthorId.isNull()) ){
|
||||
cv.put(KEY_NXS_IDENTITY, grpMetaPtr->mAuthorId.toStdString());
|
||||
}
|
||||
|
||||
offset = 0;
|
||||
@ -748,7 +768,7 @@ int RsDataService::updateGroup(std::map<RsNxsGrp *, RsGxsGrpMetaData *> &grp)
|
||||
ostrm.write(grpData, grpPtr->grp.TlvSize());
|
||||
ostrm.close();
|
||||
|
||||
mDb->sqlUpdate(GRP_TABLE_NAME, "grpId='" + grpPtr->grpId + "'", cv);
|
||||
mDb->sqlUpdate(GRP_TABLE_NAME, "grpId='" + grpPtr->grpId.toStdString() + "'", cv);
|
||||
}
|
||||
// finish transaction
|
||||
bool ret = mDb->execSQL("COMMIT;");
|
||||
@ -772,7 +792,7 @@ bool RsDataService::validSize(RsNxsGrp* grp) const
|
||||
return false;
|
||||
}
|
||||
|
||||
int RsDataService::retrieveNxsGrps(std::map<std::string, RsNxsGrp *> &grp, bool withMeta, bool cache){
|
||||
int RsDataService::retrieveNxsGrps(std::map<RsGxsGroupId, RsNxsGrp *> &grp, bool withMeta, bool cache){
|
||||
|
||||
if(grp.empty()){
|
||||
|
||||
@ -797,14 +817,14 @@ int RsDataService::retrieveNxsGrps(std::map<std::string, RsNxsGrp *> &grp, bool
|
||||
}else{
|
||||
|
||||
RsStackMutex stack(mDbMutex);
|
||||
std::map<std::string, RsNxsGrp *>::iterator mit = grp.begin();
|
||||
std::map<RsGxsGroupId, RsNxsGrp *>::iterator mit = grp.begin();
|
||||
|
||||
std::list<std::string> toRemove;
|
||||
std::list<RsGxsGroupId> toRemove;
|
||||
|
||||
for(; mit != grp.end(); mit++)
|
||||
{
|
||||
const std::string& grpId = mit->first;
|
||||
RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, grpColumns, "grpId='" + grpId + "'", "");
|
||||
const RsGxsGroupId& grpId = mit->first;
|
||||
RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, grpColumns, "grpId='" + grpId.toStdString() + "'", "");
|
||||
|
||||
if(c)
|
||||
{
|
||||
@ -823,7 +843,7 @@ int RsDataService::retrieveNxsGrps(std::map<std::string, RsNxsGrp *> &grp, bool
|
||||
}
|
||||
}
|
||||
|
||||
std::list<std::string>::iterator grpIdIt;
|
||||
std::list<RsGxsGroupId>::iterator grpIdIt;
|
||||
for (grpIdIt = toRemove.begin(); grpIdIt != toRemove.end(); ++grpIdIt)
|
||||
{
|
||||
grp.erase(*grpIdIt);
|
||||
@ -833,7 +853,7 @@ int RsDataService::retrieveNxsGrps(std::map<std::string, RsNxsGrp *> &grp, bool
|
||||
if(withMeta && !grp.empty())
|
||||
{
|
||||
std::map<RsGxsGroupId, RsGxsGrpMetaData*> metaMap;
|
||||
std::map<std::string, RsNxsGrp *>::iterator mit = grp.begin();
|
||||
std::map<RsGxsGroupId, RsNxsGrp *>::iterator mit = grp.begin();
|
||||
for(; mit != grp.end(); mit++)
|
||||
metaMap.insert(std::make_pair(mit->first, (RsGxsGrpMetaData*)(NULL)));
|
||||
|
||||
@ -878,17 +898,17 @@ int RsDataService::retrieveNxsMsgs(const GxsMsgReq &reqIds, GxsMsgResult &msg, b
|
||||
for(; mit != reqIds.end(); mit++)
|
||||
{
|
||||
|
||||
const std::string& grpId = mit->first;
|
||||
const RsGxsGroupId& grpId = mit->first;
|
||||
|
||||
// if vector empty then request all messages
|
||||
const std::vector<std::string>& msgIdV = mit->second;
|
||||
const std::vector<RsGxsMessageId>& msgIdV = mit->second;
|
||||
std::vector<RsNxsMsg*> msgSet;
|
||||
|
||||
if(msgIdV.empty()){
|
||||
|
||||
RsStackMutex stack(mDbMutex);
|
||||
|
||||
RetroCursor* c = mDb->sqlQuery(MSG_TABLE_NAME, msgColumns, KEY_GRP_ID+ "='" + grpId + "'", "");
|
||||
RetroCursor* c = mDb->sqlQuery(MSG_TABLE_NAME, msgColumns, KEY_GRP_ID+ "='" + grpId.toStdString() + "'", "");
|
||||
|
||||
if(c)
|
||||
locked_retrieveMessages(c, msgSet);
|
||||
@ -897,15 +917,15 @@ int RsDataService::retrieveNxsMsgs(const GxsMsgReq &reqIds, GxsMsgResult &msg, b
|
||||
}else{
|
||||
|
||||
// request each grp
|
||||
std::vector<std::string>::const_iterator sit = msgIdV.begin();
|
||||
std::vector<RsGxsMessageId>::const_iterator sit = msgIdV.begin();
|
||||
|
||||
for(; sit!=msgIdV.end();sit++){
|
||||
const std::string& msgId = *sit;
|
||||
const RsGxsMessageId& msgId = *sit;
|
||||
|
||||
RsStackMutex stack(mDbMutex);
|
||||
|
||||
RetroCursor* c = mDb->sqlQuery(MSG_TABLE_NAME, msgColumns, KEY_GRP_ID+ "='" + grpId
|
||||
+ "' AND " + KEY_MSG_ID + "='" + msgId + "'", "");
|
||||
RetroCursor* c = mDb->sqlQuery(MSG_TABLE_NAME, msgColumns, KEY_GRP_ID+ "='" + grpId.toStdString()
|
||||
+ "' AND " + KEY_MSG_ID + "='" + msgId.toStdString() + "'", "");
|
||||
|
||||
if(c)
|
||||
locked_retrieveMessages(c, msgSet);
|
||||
@ -1012,26 +1032,26 @@ int RsDataService::retrieveGxsMsgMetaData(const GxsMsgReq& reqIds, GxsMsgMetaRes
|
||||
for(; mit != reqIds.end(); mit++)
|
||||
{
|
||||
|
||||
const std::string& grpId = mit->first;
|
||||
const RsGxsGroupId& grpId = mit->first;
|
||||
|
||||
// if vector empty then request all messages
|
||||
const std::vector<RsGxsMessageId>& msgIdV = mit->second;
|
||||
std::vector<RsGxsMsgMetaData*> metaSet;
|
||||
|
||||
if(msgIdV.empty()){
|
||||
RetroCursor* c = mDb->sqlQuery(MSG_TABLE_NAME, msgMetaColumns, KEY_GRP_ID+ "='" + grpId + "'", "");
|
||||
RetroCursor* c = mDb->sqlQuery(MSG_TABLE_NAME, msgMetaColumns, KEY_GRP_ID+ "='" + grpId.toStdString() + "'", "");
|
||||
|
||||
locked_retrieveMsgMeta(c, metaSet);
|
||||
|
||||
}else{
|
||||
|
||||
// request each grp
|
||||
std::vector<std::string>::const_iterator sit = msgIdV.begin();
|
||||
std::vector<RsGxsMessageId>::const_iterator sit = msgIdV.begin();
|
||||
|
||||
for(; sit!=msgIdV.end();sit++){
|
||||
const std::string& msgId = *sit;
|
||||
RetroCursor* c = mDb->sqlQuery(MSG_TABLE_NAME, msgMetaColumns, KEY_GRP_ID+ "='" + grpId
|
||||
+ "' AND " + KEY_MSG_ID + "='" + msgId + "'", "");
|
||||
const RsGxsMessageId& msgId = *sit;
|
||||
RetroCursor* c = mDb->sqlQuery(MSG_TABLE_NAME, msgMetaColumns, KEY_GRP_ID+ "='" + grpId.toStdString()
|
||||
+ "' AND " + KEY_MSG_ID + "='" + msgId.toStdString() + "'", "");
|
||||
|
||||
locked_retrieveMsgMeta(c, metaSet);
|
||||
}
|
||||
@ -1094,7 +1114,7 @@ int RsDataService::retrieveGxsGrpMetaData(std::map<RsGxsGroupId, RsGxsGrpMetaDat
|
||||
for(; mit != grp.end(); mit++)
|
||||
{
|
||||
const RsGxsGroupId& grpId = mit->first;
|
||||
RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, grpMetaColumns, "grpId='" + grpId + "'", "");
|
||||
RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, grpMetaColumns, "grpId='" + grpId.toStdString() + "'", "");
|
||||
|
||||
if(c)
|
||||
{
|
||||
@ -1128,10 +1148,10 @@ int RsDataService::resetDataStore()
|
||||
std::cerr << "resetDataStore() " << std::endl;
|
||||
#endif
|
||||
|
||||
std::map<std::string, RsNxsGrp*> grps;
|
||||
std::map<RsGxsGroupId, RsNxsGrp*> grps;
|
||||
|
||||
retrieveNxsGrps(grps, false, false);
|
||||
std::map<std::string, RsNxsGrp*>::iterator mit
|
||||
std::map<RsGxsGroupId, RsNxsGrp*>::iterator mit
|
||||
= grps.begin();
|
||||
|
||||
{
|
||||
@ -1139,7 +1159,7 @@ int RsDataService::resetDataStore()
|
||||
|
||||
// remove all grp msgs files from service dir
|
||||
for(; mit != grps.end(); mit++){
|
||||
std::string file = mServiceDir + "/" + mit->first;
|
||||
std::string file = mServiceDir + "/" + mit->first.toStdString();
|
||||
std::string msgFile = file + "-msgs";
|
||||
remove(file.c_str()); // remove group file
|
||||
remove(msgFile.c_str()); // and remove messages file
|
||||
@ -1161,7 +1181,7 @@ int RsDataService::updateGroupMetaData(GrpLocMetaData &meta)
|
||||
{
|
||||
RsStackMutex stack(mDbMutex);
|
||||
RsGxsGroupId& grpId = meta.grpId;
|
||||
return mDb->sqlUpdate(GRP_TABLE_NAME, KEY_GRP_ID+ "='" + grpId + "'", meta.val) ? 1 : 0;
|
||||
return mDb->sqlUpdate(GRP_TABLE_NAME, KEY_GRP_ID+ "='" + grpId.toStdString() + "'", meta.val) ? 1 : 0;
|
||||
}
|
||||
|
||||
int RsDataService::updateMessageMetaData(MsgLocMetaData &metaData)
|
||||
@ -1169,8 +1189,8 @@ int RsDataService::updateMessageMetaData(MsgLocMetaData &metaData)
|
||||
RsStackMutex stack(mDbMutex);
|
||||
RsGxsGroupId& grpId = metaData.msgId.first;
|
||||
RsGxsMessageId& msgId = metaData.msgId.second;
|
||||
return mDb->sqlUpdate(MSG_TABLE_NAME, KEY_GRP_ID+ "='" + grpId
|
||||
+ "' AND " + KEY_MSG_ID + "='" + msgId + "'", metaData.val) ? 1 : 0;
|
||||
return mDb->sqlUpdate(MSG_TABLE_NAME, KEY_GRP_ID+ "='" + grpId.toStdString()
|
||||
+ "' AND " + KEY_MSG_ID + "='" + msgId.toStdString() + "'", metaData.val) ? 1 : 0;
|
||||
}
|
||||
|
||||
MsgOffset offSetAccum(const MsgOffset& x, const MsgOffset& y)
|
||||
@ -1210,8 +1230,8 @@ int RsDataService::removeMsgs(const GxsMsgReq& msgIds)
|
||||
std::vector<MsgOffset> msgOffsets;
|
||||
locked_getMessageOffsets(grpId, msgOffsets);
|
||||
|
||||
std::string oldFileName = mServiceDir + "/" + grpId + "-msgs";
|
||||
std::string newFileName = mServiceDir + "/" + grpId + "-msgs-temp";
|
||||
std::string oldFileName = mServiceDir + "/" + grpId.toStdString() + "-msgs";
|
||||
std::string newFileName = mServiceDir + "/" + grpId.toStdString() + "-msgs-temp";
|
||||
std::ifstream in(oldFileName.c_str(), std::ios::binary);
|
||||
std::vector<char> dataBuff, newBuffer;
|
||||
|
||||
@ -1281,7 +1301,7 @@ int RsDataService::removeMsgs(const GxsMsgReq& msgIds)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int RsDataService::removeGroups(const std::vector<std::string> &grpIds)
|
||||
int RsDataService::removeGroups(const std::vector<RsGxsGroupId> &grpIds)
|
||||
{
|
||||
|
||||
RsStackMutex stack(mDbMutex);
|
||||
@ -1290,10 +1310,10 @@ int RsDataService::removeGroups(const std::vector<std::string> &grpIds)
|
||||
// first remove file then remove group
|
||||
// from db
|
||||
|
||||
std::vector<std::string>::const_iterator vit = grpIds.begin();
|
||||
std::vector<RsGxsGroupId>::const_iterator vit = grpIds.begin();
|
||||
for(; vit != grpIds.end(); vit++)
|
||||
{
|
||||
const std::string grpFileName = mServiceDir + "/" + *vit;
|
||||
const std::string grpFileName = mServiceDir + "/" + (*vit).toStdString();
|
||||
remove(grpFileName.c_str());
|
||||
}
|
||||
|
||||
@ -1302,7 +1322,7 @@ int RsDataService::removeGroups(const std::vector<std::string> &grpIds)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int RsDataService::retrieveGroupIds(std::vector<std::string> &grpIds)
|
||||
int RsDataService::retrieveGroupIds(std::vector<RsGxsGroupId> &grpIds)
|
||||
{
|
||||
RsStackMutex stack(mDbMutex);
|
||||
|
||||
@ -1316,7 +1336,7 @@ int RsDataService::retrieveGroupIds(std::vector<std::string> &grpIds)
|
||||
{
|
||||
std::string grpId;
|
||||
c->getString(0, grpId);
|
||||
grpIds.push_back(grpId);
|
||||
grpIds.push_back(RsGxsGroupId(grpId));
|
||||
valid = c->moveToNext();
|
||||
}
|
||||
delete c;
|
||||
@ -1345,8 +1365,8 @@ bool RsDataService::locked_updateMessageEntries(const MsgUpdates& updates)
|
||||
for(; vit != updateV.end(); vit++)
|
||||
{
|
||||
const MsgUpdate& update = *vit;
|
||||
mDb->sqlUpdate(MSG_TABLE_NAME, KEY_GRP_ID+ "='" + grpId
|
||||
+ "' AND " + KEY_MSG_ID + "='" + update.msgId + "'", update.cv);
|
||||
mDb->sqlUpdate(MSG_TABLE_NAME, KEY_GRP_ID+ "='" + grpId.toStdString()
|
||||
+ "' AND " + KEY_MSG_ID + "='" + update.msgId.toStdString() + "'", update.cv);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1371,8 +1391,8 @@ bool RsDataService::locked_removeMessageEntries(const GxsMsgReq& msgIds)
|
||||
for(; vit != msgsV.end(); vit++)
|
||||
{
|
||||
const RsGxsMessageId& msgId = *vit;
|
||||
mDb->sqlDelete(MSG_TABLE_NAME, KEY_GRP_ID+ "='" + grpId
|
||||
+ "' AND " + KEY_MSG_ID + "='" + msgId + "'", "");
|
||||
mDb->sqlDelete(MSG_TABLE_NAME, KEY_GRP_ID+ "='" + grpId.toStdString()
|
||||
+ "' AND " + KEY_MSG_ID + "='" + msgId.toStdString() + "'", "");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1381,18 +1401,18 @@ bool RsDataService::locked_removeMessageEntries(const GxsMsgReq& msgIds)
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool RsDataService::locked_removeGroupEntries(const std::vector<std::string>& grpIds)
|
||||
bool RsDataService::locked_removeGroupEntries(const std::vector<RsGxsGroupId>& grpIds)
|
||||
{
|
||||
// start a transaction
|
||||
bool ret = mDb->execSQL("BEGIN;");
|
||||
|
||||
std::vector<std::string>::const_iterator vit = grpIds.begin();
|
||||
std::vector<RsGxsGroupId>::const_iterator vit = grpIds.begin();
|
||||
|
||||
for(; vit != grpIds.end(); vit++)
|
||||
{
|
||||
|
||||
const RsGxsGroupId& grpId = *vit;
|
||||
mDb->sqlDelete(GRP_TABLE_NAME, KEY_GRP_ID+ "='" + grpId + "'", "");
|
||||
mDb->sqlDelete(GRP_TABLE_NAME, KEY_GRP_ID+ "='" + grpId.toStdString() + "'", "");
|
||||
}
|
||||
|
||||
ret &= mDb->execSQL("COMMIT;");
|
||||
@ -1402,7 +1422,7 @@ bool RsDataService::locked_removeGroupEntries(const std::vector<std::string>& gr
|
||||
void RsDataService::locked_getMessageOffsets(const RsGxsGroupId& grpId, std::vector<MsgOffset>& offsets)
|
||||
{
|
||||
|
||||
RetroCursor* c = mDb->sqlQuery(MSG_TABLE_NAME, mMsgOffSetColumns, KEY_GRP_ID+ "='" + grpId + "'", "");
|
||||
RetroCursor* c = mDb->sqlQuery(MSG_TABLE_NAME, mMsgOffSetColumns, KEY_GRP_ID+ "='" + grpId.toStdString() + "'", "");
|
||||
|
||||
if(c)
|
||||
{
|
||||
@ -1413,7 +1433,9 @@ void RsDataService::locked_getMessageOffsets(const RsGxsGroupId& grpId, std::vec
|
||||
RsGxsMessageId msgId;
|
||||
int32_t msgLen;
|
||||
int32_t msgOffSet;
|
||||
c->getString(0, msgId);
|
||||
std::string temp;
|
||||
c->getString(0, temp);
|
||||
msgId = temp;
|
||||
msgOffSet = c->getInt32(1);
|
||||
msgLen = c->getInt32(2);
|
||||
|
||||
|
@ -73,7 +73,7 @@ public:
|
||||
* @param cache whether to store retrieval in mem for faster later retrieval
|
||||
* @return error code
|
||||
*/
|
||||
int retrieveNxsGrps(std::map<std::string, RsNxsGrp*>& grp, bool withMeta, bool cache);
|
||||
int retrieveNxsGrps(std::map<RsGxsGroupId, RsNxsGrp*>& grp, bool withMeta, bool cache);
|
||||
|
||||
/*!
|
||||
* Retrieves meta data of all groups stored (most current versions only)
|
||||
@ -111,7 +111,7 @@ public:
|
||||
* @param grpIds all grpids in store is inserted into this vector
|
||||
* @return error code
|
||||
*/
|
||||
int retrieveGroupIds(std::vector<std::string> &grpIds);
|
||||
int retrieveGroupIds(std::vector<RsGxsGroupId> &grpIds);
|
||||
|
||||
/*!
|
||||
* @return the cache size set for this RsGeneralDataService in bytes
|
||||
@ -226,7 +226,7 @@ private:
|
||||
* @param msgIds
|
||||
*/
|
||||
bool locked_removeMessageEntries(const GxsMsgReq& msgIds);
|
||||
bool locked_removeGroupEntries(const std::vector<std::string>& grpIds);
|
||||
bool locked_removeGroupEntries(const std::vector<RsGxsGroupId>& grpIds);
|
||||
|
||||
typedef std::map<RsGxsGroupId, std::vector<MsgUpdate> > MsgUpdates;
|
||||
|
||||
|
@ -421,7 +421,7 @@ int RsGenExchange::createGroupSignatures(RsTlvKeySignatureSet& signSet, RsTlvBin
|
||||
PrivacyBitPos pos = GRP_OPTION_BITS;
|
||||
|
||||
// Check required permissions, and allow them to sign it - if they want too - as well!
|
||||
if ((!grpMeta.mAuthorId.empty()) || checkAuthenFlag(pos, author_flag))
|
||||
if ((!grpMeta.mAuthorId.isNull()) || checkAuthenFlag(pos, author_flag))
|
||||
{
|
||||
needIdentitySign = true;
|
||||
std::cerr << "Needs Identity sign! (Service Flags)";
|
||||
@ -502,7 +502,7 @@ int RsGenExchange::createMsgSignatures(RsTlvKeySignatureSet& signSet, RsTlvBinar
|
||||
uint8_t author_flag = GXS_SERV::MSG_AUTHEN_ROOT_AUTHOR_SIGN;
|
||||
uint8_t publish_flag = GXS_SERV::MSG_AUTHEN_ROOT_PUBLISH_SIGN;
|
||||
|
||||
if(!msgMeta.mParentId.empty())
|
||||
if(!msgMeta.mParentId.isNull())
|
||||
{
|
||||
// Child Message.
|
||||
author_flag = GXS_SERV::MSG_AUTHEN_CHILD_AUTHOR_SIGN;
|
||||
@ -536,7 +536,7 @@ int RsGenExchange::createMsgSignatures(RsTlvKeySignatureSet& signSet, RsTlvBinar
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
|
||||
if (!msgMeta.mAuthorId.empty())
|
||||
if (!msgMeta.mAuthorId.isNull())
|
||||
{
|
||||
needIdentitySign = true;
|
||||
std::cerr << "Needs Identity sign! (AuthorId Exists)";
|
||||
@ -690,7 +690,9 @@ int RsGenExchange::createMessage(RsNxsMsg* msg)
|
||||
// get hash of msg data to create msg id
|
||||
pqihash hash;
|
||||
hash.addData(allMsgData, allMsgDataLen);
|
||||
hash.Complete(msg->msgId);
|
||||
RsFileHash hashId;
|
||||
hash.Complete(hashId);
|
||||
msg->msgId = hashId;
|
||||
|
||||
// assign msg id to msg meta
|
||||
msg->metaData->mMsgId = msg->msgId;
|
||||
@ -723,7 +725,7 @@ int RsGenExchange::validateMsg(RsNxsMsg *msg, const uint32_t& grpFlag, RsTlvSecu
|
||||
uint8_t author_flag = GXS_SERV::MSG_AUTHEN_ROOT_AUTHOR_SIGN;
|
||||
uint8_t publish_flag = GXS_SERV::MSG_AUTHEN_ROOT_PUBLISH_SIGN;
|
||||
|
||||
if(!msg->metaData->mParentId.empty())
|
||||
if(!msg->metaData->mParentId.isNull())
|
||||
{
|
||||
// Child Message.
|
||||
author_flag = GXS_SERV::MSG_AUTHEN_CHILD_AUTHOR_SIGN;
|
||||
@ -744,7 +746,7 @@ int RsGenExchange::validateMsg(RsNxsMsg *msg, const uint32_t& grpFlag, RsTlvSecu
|
||||
needPublishSign = true;
|
||||
|
||||
// Check required permissions, if they have signed it anyway - we need to validate it.
|
||||
if ((checkAuthenFlag(pos, author_flag)) || (!msg->metaData->mAuthorId.empty()))
|
||||
if ((checkAuthenFlag(pos, author_flag)) || (!msg->metaData->mAuthorId.isNull()))
|
||||
needIdentitySign = true;
|
||||
|
||||
|
||||
@ -814,7 +816,7 @@ int RsGenExchange::validateMsg(RsNxsMsg *msg, const uint32_t& grpFlag, RsTlvSecu
|
||||
|
||||
}else
|
||||
{
|
||||
std::list<std::string> peers;
|
||||
std::list<RsPeerId> peers;
|
||||
peers.push_back(msg->PeerId());
|
||||
mGixs->requestKey(metaData.mAuthorId, peers);
|
||||
return VALIDATE_FAIL_TRY_LATER;
|
||||
@ -853,7 +855,7 @@ int RsGenExchange::validateGrp(RsNxsGrp* grp, RsTlvSecurityKeySet& grpKeySet)
|
||||
PrivacyBitPos pos = GRP_OPTION_BITS;
|
||||
|
||||
// Check required permissions, and allow them to sign it - if they want too - as well!
|
||||
if (!(metaData.mAuthorId.empty()) || checkAuthenFlag(pos, author_flag))
|
||||
if (!(metaData.mAuthorId.isNull()) || checkAuthenFlag(pos, author_flag))
|
||||
{
|
||||
needIdentitySign = true;
|
||||
std::cerr << "Needs Identity sign! (Service Flags)";
|
||||
@ -888,7 +890,7 @@ int RsGenExchange::validateGrp(RsNxsGrp* grp, RsTlvSecurityKeySet& grpKeySet)
|
||||
|
||||
}else
|
||||
{
|
||||
std::list<std::string> peers;
|
||||
std::list<RsPeerId> peers;
|
||||
peers.push_back(grp->PeerId());
|
||||
mGixs->requestKey(metaData.mAuthorId, peers);
|
||||
return VALIDATE_FAIL_TRY_LATER;
|
||||
@ -1769,7 +1771,7 @@ void RsGenExchange::publishMsgs()
|
||||
{
|
||||
// empty orig msg id means this is the original
|
||||
// msg
|
||||
if(msg->metaData->mOrigMsgId.empty())
|
||||
if(msg->metaData->mOrigMsgId.isNull())
|
||||
{
|
||||
msg->metaData->mOrigMsgId = msg->metaData->mMsgId;
|
||||
}
|
||||
@ -1858,7 +1860,7 @@ void RsGenExchange::processGroupUpdatePublish()
|
||||
// get keys for group update publish
|
||||
|
||||
// first build meta request map for groups to be updated
|
||||
std::map<std::string, RsGxsGrpMetaData*> grpMeta;
|
||||
std::map<RsGxsGroupId, RsGxsGrpMetaData*> grpMeta;
|
||||
std::vector<GroupUpdatePublish>::iterator vit = mGroupUpdatePublish.begin();
|
||||
|
||||
for(; vit != mGroupUpdatePublish.end(); vit++)
|
||||
@ -1879,7 +1881,7 @@ void RsGenExchange::processGroupUpdatePublish()
|
||||
{
|
||||
GroupUpdatePublish& gup = *vit;
|
||||
const RsGxsGroupId& groupId = gup.grpItem->meta.mGroupId;
|
||||
std::map<std::string, RsGxsGrpMetaData*>::iterator mit = grpMeta.find(groupId);
|
||||
std::map<RsGxsGroupId, RsGxsGrpMetaData*>::iterator mit = grpMeta.find(groupId);
|
||||
|
||||
RsGxsGrpMetaData* meta = NULL;
|
||||
if(mit == grpMeta.end())
|
||||
@ -1966,7 +1968,7 @@ void RsGenExchange::publishGrps()
|
||||
{
|
||||
// timed out
|
||||
toNotify.insert(std::make_pair(
|
||||
token, GrpNote(false, "")));
|
||||
token, GrpNote(false, RsGxsGroupId())));
|
||||
delete ggps.mItem;
|
||||
vit = mGrpsToPublish.erase(vit);
|
||||
|
||||
@ -2013,7 +2015,7 @@ void RsGenExchange::publishGrps()
|
||||
if(privKeyFound)
|
||||
{
|
||||
// get group id from private admin key id
|
||||
grpItem->meta.mGroupId = grp->grpId = privAdminKey.keyId;
|
||||
grpItem->meta.mGroupId = grp->grpId = RsGxsGroupId(privAdminKey.keyId);
|
||||
|
||||
ServiceCreate_Return ret = service_CreateGroup(grpItem, privatekeySet);
|
||||
|
||||
@ -2174,7 +2176,7 @@ RsGeneralDataService* RsGenExchange::getDataStore()
|
||||
|
||||
bool RsGenExchange::getGroupKeys(const RsGxsGroupId &grpId, RsTlvSecurityKeySet &keySet)
|
||||
{
|
||||
if(grpId.empty())
|
||||
if(grpId.isNull())
|
||||
return false;
|
||||
|
||||
RsStackMutex stack(mGenMtx);
|
||||
@ -2205,7 +2207,7 @@ void RsGenExchange::processRecvdData()
|
||||
}
|
||||
|
||||
|
||||
void RsGenExchange::computeHash(const RsTlvBinaryData& data, std::string& hash)
|
||||
void RsGenExchange::computeHash(const RsTlvBinaryData& data, RsFileHash& hash)
|
||||
{
|
||||
pqihash pHash;
|
||||
pHash.addData(data.bin_data, data.bin_len);
|
||||
@ -2364,8 +2366,8 @@ void RsGenExchange::processRecvdGroups()
|
||||
return;
|
||||
|
||||
NxsGrpPendValidVect::iterator vit = mReceivedGrps.begin();
|
||||
std::vector<std::string> existingGrpIds;
|
||||
std::list<std::string> grpIds;
|
||||
std::vector<RsGxsGroupId> existingGrpIds;
|
||||
std::list<RsGxsGroupId> grpIds;
|
||||
|
||||
std::map<RsNxsGrp*, RsGxsGrpMetaData*> grps;
|
||||
|
||||
@ -2476,7 +2478,7 @@ void RsGenExchange::performUpdateValidation()
|
||||
if(mGroupUpdates.empty())
|
||||
return;
|
||||
|
||||
std::map<std::string, RsGxsGrpMetaData*> grpMetas;
|
||||
std::map<RsGxsGroupId, RsGxsGrpMetaData*> grpMetas;
|
||||
|
||||
std::vector<GroupUpdate>::iterator vit = mGroupUpdates.begin();
|
||||
for(; vit != mGroupUpdates.end(); vit++)
|
||||
@ -2491,7 +2493,7 @@ void RsGenExchange::performUpdateValidation()
|
||||
for(; vit != mGroupUpdates.end(); vit++)
|
||||
{
|
||||
GroupUpdate& gu = *vit;
|
||||
std::map<std::string, RsGxsGrpMetaData*>::iterator mit =
|
||||
std::map<RsGxsGroupId, RsGxsGrpMetaData*>::iterator mit =
|
||||
grpMetas.find(gu.newGrp->grpId);
|
||||
gu.oldGrpMeta = mit->second;
|
||||
gu.validUpdate = updateValid(*(gu.oldGrpMeta), *(gu.newGrp));
|
||||
@ -2544,7 +2546,7 @@ bool RsGenExchange::updateValid(RsGxsGrpMetaData& oldGrpMeta, RsNxsGrp& newGrp)
|
||||
RsTlvKeySignature adminSign = mit->second;
|
||||
|
||||
std::map<std::string, RsTlvSecurityKey>& keys = oldGrpMeta.keys.keys;
|
||||
std::map<std::string, RsTlvSecurityKey>::iterator keyMit = keys.find(oldGrpMeta.mGroupId);
|
||||
std::map<std::string, RsTlvSecurityKey>::iterator keyMit = keys.find(oldGrpMeta.mGroupId.toStdString());
|
||||
|
||||
if(keyMit == keys.end())
|
||||
{
|
||||
|
@ -763,7 +763,7 @@ private:
|
||||
|
||||
void groupShareKeys(std::list<std::string> peers);
|
||||
|
||||
static void computeHash(const RsTlvBinaryData& data, std::string& hash);
|
||||
static void computeHash(const RsTlvBinaryData& data, RsFileHash& hash);
|
||||
|
||||
/*!
|
||||
* Checks validation of recently received groups to be
|
||||
|
@ -32,7 +32,7 @@
|
||||
#include "retroshare/rsgxscircles.h"
|
||||
|
||||
#include "serialiser/rstlvkeys.h"
|
||||
|
||||
#include "retroshare/rsids.h"
|
||||
/*!
|
||||
* GIXP: General Identity Exchange Service.
|
||||
*
|
||||
@ -96,9 +96,8 @@
|
||||
* as these will be used very frequently.
|
||||
*****/
|
||||
|
||||
typedef std::string PeerId; // SHOULD BE REMOVED => RsPeerId (SSLID)
|
||||
typedef std::string RsPgpId;
|
||||
typedef std::string RsGxsId;
|
||||
typedef RsPeerId PeerId; // SHOULD BE REMOVED => RsPeerId (SSLID)
|
||||
typedef PGPIdType RsPgpId;
|
||||
|
||||
//
|
||||
//// External Interface -
|
||||
@ -176,7 +175,7 @@ class RsGixsReputation
|
||||
public:
|
||||
// get Reputation.
|
||||
virtual bool haveReputation(const RsGxsId &id) = 0;
|
||||
virtual bool loadReputation(const RsGxsId &id, const std::list<std::string>& peers) = 0;
|
||||
virtual bool loadReputation(const RsGxsId &id, const std::list<RsPeerId>& peers) = 0;
|
||||
virtual bool getReputation(const RsGxsId &id, GixsReputation &rep) = 0;
|
||||
};
|
||||
|
||||
|
@ -74,8 +74,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
typedef std::string SSLId ;
|
||||
typedef std::string GPGId ;
|
||||
typedef RsPeerId SSLId ;
|
||||
typedef RsPgpId GPGId ;
|
||||
typedef uint64_t RsGroupId ;
|
||||
|
||||
class RsPeerGroupInfo
|
||||
|
@ -37,19 +37,19 @@ uint32_t RsGxsGrpMetaData::serial_size()
|
||||
{
|
||||
uint32_t s = 8; // header size
|
||||
|
||||
s += GetTlvStringSize(mGroupId);
|
||||
s += GetTlvStringSize(mOrigGrpId);
|
||||
s += mGroupId.serial_size();
|
||||
s += mOrigGrpId.serial_size();
|
||||
s += GetTlvStringSize(mGroupName);
|
||||
s += 4;
|
||||
s += 4;
|
||||
s += GetTlvStringSize(mAuthorId);
|
||||
s += mAuthorId.serial_size();
|
||||
s += GetTlvStringSize(mServiceString);
|
||||
s += signSet.TlvSize();
|
||||
s += keys.TlvSize();
|
||||
s += 4; // for mCircleType
|
||||
s += GetTlvStringSize(mCircleId);
|
||||
s += mCircleId.serial_size();
|
||||
s += 4; // mAuthenFlag
|
||||
s += GetTlvStringSize(mParentGrpId);
|
||||
s += mParentGrpId.serial_size();
|
||||
|
||||
return s;
|
||||
}
|
||||
@ -105,17 +105,17 @@ bool RsGxsGrpMetaData::serialise(void *data, uint32_t &pktsize)
|
||||
/* skip header */
|
||||
offset += 8;
|
||||
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 0, mGroupId);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 0, mOrigGrpId);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 0, mParentGrpId);
|
||||
ok &= mGroupId.serialise(data, tlvsize, offset);
|
||||
ok &= mOrigGrpId.serialise(data, tlvsize, offset);
|
||||
ok &= mParentGrpId.serialise(data, tlvsize, offset);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 0, mGroupName);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, mGroupFlags);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, mPublishTs);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, mCircleType);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, mAuthenFlags);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 0, mAuthorId);
|
||||
ok &= mAuthorId.serialise(data, tlvsize, offset);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 0, mServiceString);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 0, mCircleId);
|
||||
ok &= mCircleId.serialise(data, tlvsize, offset);
|
||||
|
||||
ok &= signSet.SetTlv(data, tlvsize, &offset);
|
||||
ok &= keys.SetTlv(data, tlvsize, &offset);
|
||||
@ -136,17 +136,17 @@ bool RsGxsGrpMetaData::deserialise(void *data, uint32_t &pktsize)
|
||||
|
||||
if(!ok) return false;
|
||||
|
||||
ok &= GetTlvString(data, pktsize, &offset, 0, mGroupId);
|
||||
ok &= GetTlvString(data, pktsize, &offset, 0, mOrigGrpId);
|
||||
ok &= GetTlvString(data, pktsize, &offset, 0, mParentGrpId);
|
||||
ok &= mGroupId.deserialise(data, pktsize, offset);
|
||||
ok &= mOrigGrpId.deserialise(data, pktsize, offset);
|
||||
ok &= mParentGrpId.deserialise(data, pktsize, offset);
|
||||
ok &= GetTlvString(data, pktsize, &offset, 0, mGroupName);
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &mGroupFlags);
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &mPublishTs);
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &mCircleType);
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &mAuthenFlags);
|
||||
ok &= GetTlvString(data, pktsize, &offset, 0, mAuthorId);
|
||||
ok &= mAuthorId.deserialise(data, pktsize, offset);
|
||||
ok &= GetTlvString(data, pktsize, &offset, 0, mServiceString);
|
||||
ok &= GetTlvString(data, pktsize, &offset, 0, mCircleId);
|
||||
ok &= mCircleId.deserialise(data, pktsize, offset);
|
||||
ok &= signSet.GetTlv(data, pktsize, &offset);
|
||||
ok &= keys.GetTlv(data, pktsize, &offset);
|
||||
|
||||
@ -171,12 +171,12 @@ uint32_t RsGxsMsgMetaData::serial_size()
|
||||
|
||||
uint32_t s = 8; // header size
|
||||
|
||||
s += GetTlvStringSize(mGroupId);
|
||||
s += GetTlvStringSize(mMsgId);
|
||||
s += GetTlvStringSize(mThreadId);
|
||||
s += GetTlvStringSize(mParentId);
|
||||
s += GetTlvStringSize(mOrigMsgId);
|
||||
s += GetTlvStringSize(mAuthorId);
|
||||
s += mGroupId.serial_size();
|
||||
s += mMsgId.serial_size();
|
||||
s += mThreadId.serial_size();
|
||||
s += mParentId.serial_size();
|
||||
s += mOrigMsgId.serial_size();
|
||||
s += mAuthorId.serial_size();
|
||||
|
||||
s += signSet.TlvSize();
|
||||
s += GetTlvStringSize(mMsgName);
|
||||
@ -228,12 +228,12 @@ bool RsGxsMsgMetaData::serialise(void *data, uint32_t *size)
|
||||
/* skip header */
|
||||
offset += 8;
|
||||
|
||||
ok &= SetTlvString(data, *size, &offset, 0, mGroupId);
|
||||
ok &= SetTlvString(data, *size, &offset, 0, mMsgId);
|
||||
ok &= SetTlvString(data, *size, &offset, 0, mThreadId);
|
||||
ok &= SetTlvString(data, *size, &offset, 0, mParentId);
|
||||
ok &= SetTlvString(data, *size, &offset, 0, mOrigMsgId);
|
||||
ok &= SetTlvString(data, *size, &offset, 0, mAuthorId);
|
||||
ok &= mGroupId.serialise(data, *size, offset);
|
||||
ok &= mMsgId.serialise(data, *size, offset);
|
||||
ok &= mThreadId.serialise(data, *size, offset);
|
||||
ok &= mParentId.serialise(data, *size, offset);
|
||||
ok &= mOrigMsgId.serialise(data, *size, offset);
|
||||
ok &= mAuthorId.serialise(data, *size, offset);
|
||||
|
||||
ok &= signSet.SetTlv(data, *size, &offset);
|
||||
ok &= SetTlvString(data, *size, &offset, 0, mMsgName);
|
||||
@ -255,12 +255,12 @@ bool RsGxsMsgMetaData::deserialise(void *data, uint32_t *size)
|
||||
|
||||
if(!ok) return false;
|
||||
|
||||
ok &= GetTlvString(data, *size, &offset, 0, mGroupId);
|
||||
ok &= GetTlvString(data, *size, &offset, 0, mMsgId);
|
||||
ok &= GetTlvString(data, *size, &offset, 0, mThreadId);
|
||||
ok &= GetTlvString(data, *size, &offset, 0, mParentId);
|
||||
ok &= GetTlvString(data, *size, &offset, 0, mOrigMsgId);
|
||||
ok &= GetTlvString(data, *size, &offset, 0, mAuthorId);
|
||||
ok &= mGroupId.deserialise(data, *size, offset);
|
||||
ok &= mMsgId.deserialise(data, *size, offset);
|
||||
ok &= mThreadId.deserialise(data, *size, offset);
|
||||
ok &= mParentId.deserialise(data, *size, offset);
|
||||
ok &= mOrigMsgId.deserialise(data, *size, offset);
|
||||
ok &= mAuthorId.deserialise(data, *size, offset);
|
||||
|
||||
ok &= signSet.GetTlv(data, *size, &offset);
|
||||
ok &= GetTlvString(data, *size, &offset, 0, mMsgName);
|
||||
|
@ -52,9 +52,9 @@ public:
|
||||
uint32_t mGroupFlags;
|
||||
uint32_t mPublishTs;
|
||||
uint32_t mSignFlags;
|
||||
std::string mAuthorId;
|
||||
RsGxsId mAuthorId;
|
||||
|
||||
std::string mCircleId;
|
||||
RsGxsCircleId mCircleId;
|
||||
uint32_t mCircleType;
|
||||
|
||||
|
||||
@ -76,9 +76,9 @@ public:
|
||||
|
||||
uint32_t mGroupStatus;
|
||||
uint32_t mRecvTS;
|
||||
std::string mOriginator;
|
||||
std::string mInternalCircle;
|
||||
std::string mHash;
|
||||
RsPeerId mOriginator;
|
||||
RsGxsCircleId mInternalCircle;
|
||||
RsFileHash mHash;
|
||||
};
|
||||
|
||||
|
||||
@ -100,7 +100,7 @@ public:
|
||||
RsGxsMessageId mThreadId;
|
||||
RsGxsMessageId mParentId;
|
||||
RsGxsMessageId mOrigMsgId;
|
||||
std::string mAuthorId;
|
||||
RsGxsId mAuthorId;
|
||||
|
||||
RsTlvKeySignatureSet signSet;
|
||||
|
||||
@ -116,7 +116,7 @@ public:
|
||||
uint32_t mMsgStatus;
|
||||
time_t mChildTs;
|
||||
uint32_t recvTS;
|
||||
std::string mHash;
|
||||
RsFileHash mHash;
|
||||
bool validated;
|
||||
|
||||
};
|
||||
|
@ -65,7 +65,7 @@ RsGxsDataAccess::RsGxsDataAccess(RsGeneralDataService* ds)
|
||||
|
||||
|
||||
bool RsGxsDataAccess::requestGroupInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts,
|
||||
const std::list<std::string> &groupIds)
|
||||
const std::list<RsGxsGroupId> &groupIds)
|
||||
{
|
||||
if(groupIds.empty())
|
||||
{
|
||||
@ -854,7 +854,7 @@ bool RsGxsDataAccess::getGroupList(const std::list<RsGxsGroupId>& grpIdsIn, cons
|
||||
|
||||
mDataStore->retrieveGxsGrpMetaData(grpMeta);
|
||||
|
||||
std::map<std::string, RsGxsGrpMetaData*>::iterator mit = grpMeta.begin();
|
||||
std::map<RsGxsGroupId, RsGxsGrpMetaData*>::iterator mit = grpMeta.begin();
|
||||
|
||||
for(; mit != grpMeta.end(); mit++)
|
||||
{
|
||||
@ -958,8 +958,8 @@ bool RsGxsDataAccess::getMsgList(const GxsMsgReq& msgIds, const RsTokReqOptions&
|
||||
std::vector<RsGxsMsgMetaData*>::const_iterator vit = metaV.begin();
|
||||
|
||||
// RUN THROUGH ALL MSGS... in map origId -> TS.
|
||||
std::map<RsGxsGroupId, std::pair<RsGxsMessageId, time_t> > origMsgTs;
|
||||
std::map<RsGxsGroupId, std::pair<RsGxsMessageId, time_t> >::iterator oit;
|
||||
std::map<RsGxsMessageId, std::pair<RsGxsMessageId, time_t> > origMsgTs;
|
||||
std::map<RsGxsMessageId, std::pair<RsGxsMessageId, time_t> >::iterator oit;
|
||||
|
||||
for(; vit != metaV.end(); vit++)
|
||||
{
|
||||
@ -968,7 +968,7 @@ bool RsGxsDataAccess::getMsgList(const GxsMsgReq& msgIds, const RsTokReqOptions&
|
||||
/* if we are grabbing thread Head... then parentId == empty. */
|
||||
if (onlyThreadHeadMsgs)
|
||||
{
|
||||
if (!(msgMeta->mParentId.empty()))
|
||||
if (!(msgMeta->mParentId.isNull()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@ -1025,7 +1025,7 @@ bool RsGxsDataAccess::getMsgList(const GxsMsgReq& msgIds, const RsTokReqOptions&
|
||||
/* if we are grabbing thread Head... then parentId == empty. */
|
||||
if (onlyThreadHeadMsgs)
|
||||
{
|
||||
if (!(msgMeta->mParentId.empty()))
|
||||
if (!(msgMeta->mParentId.isNull()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@ -1209,8 +1209,8 @@ bool RsGxsDataAccess::getMsgRelatedInfo(MsgRelatedInfoReq *req)
|
||||
if (onlyChildMsgs || onlyThreadMsgs)
|
||||
{
|
||||
// RUN THROUGH ALL MSGS... in map origId -> TS.
|
||||
std::map<std::string, std::pair<std::string, time_t> > origMsgTs;
|
||||
std::map<std::string, std::pair<std::string, time_t> >::iterator oit;
|
||||
std::map<RsGxsMessageId, std::pair<RsGxsMessageId, time_t> > origMsgTs;
|
||||
std::map<RsGxsMessageId, std::pair<RsGxsMessageId, time_t> >::iterator oit;
|
||||
for(vit_meta = metaV.begin(); vit_meta != metaV.end(); vit_meta++)
|
||||
{
|
||||
|
||||
|
@ -164,7 +164,7 @@ public:
|
||||
* @param msgIds
|
||||
* @return false if token cannot be redeemed, if false you may have tried to redeem when not ready
|
||||
*/
|
||||
bool getGroupList(const uint32_t &token, std::list<std::string> &groupIds);
|
||||
bool getGroupList(const uint32_t &token, std::list<RsGxsGroupId> &groupIds);
|
||||
|
||||
/*!
|
||||
*
|
||||
|
@ -80,10 +80,10 @@ int RsGxsNetService::tick(){
|
||||
void RsGxsNetService::syncWithPeers()
|
||||
{
|
||||
|
||||
std::set<std::string> peers;
|
||||
std::set<RsPeerId> peers;
|
||||
mNetMgr->getOnlineList(peers);
|
||||
|
||||
std::set<std::string>::iterator sit = peers.begin();
|
||||
std::set<RsPeerId>::iterator sit = peers.begin();
|
||||
|
||||
if(mGrpAutoSync)
|
||||
{
|
||||
@ -91,7 +91,7 @@ void RsGxsNetService::syncWithPeers()
|
||||
for(; sit != peers.end(); sit++)
|
||||
{
|
||||
|
||||
const std::string peerId = *sit;
|
||||
const RsPeerId peerId = *sit;
|
||||
|
||||
ClientGrpMap::const_iterator cit = mClientGrpUpdateMap.find(peerId);
|
||||
uint32_t updateTS = 0;
|
||||
@ -108,7 +108,7 @@ void RsGxsNetService::syncWithPeers()
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef GXS_ENABLE_SYNC_MSGS
|
||||
#ifndef GXS_DISABLE_SYNC_MSGS
|
||||
std::map<RsGxsGroupId, RsGxsGrpMetaData* > grpMeta;
|
||||
mDataStore->retrieveGxsGrpMetaData(grpMeta);
|
||||
|
||||
@ -154,7 +154,7 @@ void RsGxsNetService::syncWithPeers()
|
||||
uint32_t updateTS = 0;
|
||||
if(mui)
|
||||
{
|
||||
std::map<std::string, uint32_t>::const_iterator cit2 = mui->msgUpdateTS.find(*vit);
|
||||
std::map<RsGxsGroupId, uint32_t>::const_iterator cit2 = mui->msgUpdateTS.find(*vit);
|
||||
|
||||
if(cit2 != mui->msgUpdateTS.end())
|
||||
{
|
||||
@ -432,7 +432,7 @@ void RsGxsNetService::locked_createTransactionFromPending(MsgCircleIdsRequestVet
|
||||
}
|
||||
|
||||
bool RsGxsNetService::locked_canReceive(const RsGxsGrpMetaData * const grpMeta,
|
||||
const std::string& peerId)
|
||||
const RsPeerId& peerId)
|
||||
{
|
||||
|
||||
double timeDelta = 0.2;
|
||||
@ -518,7 +518,7 @@ void RsGxsNetService::collateGrpFragments(GrpFragments fragments,
|
||||
|
||||
struct MsgFragCollate
|
||||
{
|
||||
RsGxsGroupId mMsgId;
|
||||
RsGxsMessageId mMsgId;
|
||||
MsgFragCollate(const RsGxsMessageId& msgId) : mMsgId(msgId){ }
|
||||
bool operator()(RsNxsMsg* msg) { return msg->msgId == mMsgId;}
|
||||
};
|
||||
@ -725,7 +725,7 @@ bool RsGxsNetService::handleTransaction(RsNxsItem* item)
|
||||
|
||||
RsStackMutex stack(mNxsMutex);
|
||||
|
||||
const std::string& peer = item->PeerId();
|
||||
const RsPeerId& peer = item->PeerId();
|
||||
|
||||
RsNxsTransac* transItem = dynamic_cast<RsNxsTransac*>(item);
|
||||
|
||||
@ -788,7 +788,7 @@ bool RsGxsNetService::locked_processTransac(RsNxsTransac* item)
|
||||
* For ending a transaction the
|
||||
*/
|
||||
|
||||
std::string peer;
|
||||
RsPeerId peer;
|
||||
|
||||
// for outgoing transaction use own id
|
||||
if(item->transactFlag & (RsNxsTransac::FLAG_BEGIN_P2 | RsNxsTransac::FLAG_END_SUCCESS))
|
||||
@ -1233,7 +1233,7 @@ void RsGxsNetService::locked_processCompletedIncomingTrans(NxsTransaction* tr)
|
||||
mObserver->notifyNewGroups(grps);
|
||||
|
||||
// now note this as the latest you've received from this peer
|
||||
std::string peerFrom = tr->mTransaction->PeerId();
|
||||
RsPeerId peerFrom = tr->mTransaction->PeerId();
|
||||
uint32_t updateTS = tr->mTransaction->updateTS;
|
||||
|
||||
ClientGrpMap::iterator it = mClientGrpUpdateMap.find(peerFrom);
|
||||
@ -1261,13 +1261,13 @@ void RsGxsNetService::locked_processCompletedIncomingTrans(NxsTransaction* tr)
|
||||
|
||||
std::vector<RsNxsMsg*> msgs;
|
||||
|
||||
std::string grpId;
|
||||
RsGxsGroupId grpId;
|
||||
while(tr->mItems.size() > 0)
|
||||
{
|
||||
RsNxsMsg* msg = dynamic_cast<RsNxsMsg*>(tr->mItems.front());
|
||||
if(msg)
|
||||
{
|
||||
if(grpId.empty())
|
||||
if(grpId.isNull())
|
||||
grpId = msg->grpId;
|
||||
|
||||
tr->mItems.pop_front();
|
||||
@ -1312,11 +1312,11 @@ void RsGxsNetService::locked_processCompletedIncomingTrans(NxsTransaction* tr)
|
||||
return;
|
||||
}
|
||||
|
||||
void RsGxsNetService::locked_doMsgUpdateWork(const RsNxsTransac *nxsTrans, const std::string &grpId)
|
||||
void RsGxsNetService::locked_doMsgUpdateWork(const RsNxsTransac *nxsTrans, const RsGxsGroupId &grpId)
|
||||
{
|
||||
|
||||
// firts check if peer exists
|
||||
const std::string& peerFrom = nxsTrans->PeerId();
|
||||
const RsPeerId& peerFrom = nxsTrans->PeerId();
|
||||
|
||||
ClientMsgMap::iterator it = mClientMsgUpdateMap.find(peerFrom);
|
||||
|
||||
@ -1406,7 +1406,7 @@ void RsGxsNetService::locked_processCompletedOutgoingTrans(NxsTransaction* tr)
|
||||
|
||||
|
||||
void RsGxsNetService::locked_pushMsgTransactionFromList(
|
||||
std::list<RsNxsItem*>& reqList, const std::string& peerId, const uint32_t& transN)
|
||||
std::list<RsNxsItem*>& reqList, const RsPeerId& peerId, const uint32_t& transN)
|
||||
{
|
||||
RsNxsTransac* transac = new RsNxsTransac(mServType);
|
||||
transac->transactFlag = RsNxsTransac::FLAG_TYPE_MSG_LIST_REQ
|
||||
@ -1462,7 +1462,7 @@ void RsGxsNetService::locked_genReqMsgTransaction(NxsTransaction* tr)
|
||||
|
||||
// get grp id for this transaction
|
||||
RsNxsSyncMsgItem* item = msgItemL.front();
|
||||
const std::string& grpId = item->grpId;
|
||||
const RsGxsGroupId& grpId = item->grpId;
|
||||
|
||||
std::map<std::string, RsGxsGrpMetaData*> grpMetaMap;
|
||||
grpMetaMap[grpId] = NULL;
|
||||
@ -1499,7 +1499,7 @@ void RsGxsNetService::locked_genReqMsgTransaction(NxsTransaction* tr)
|
||||
std::vector<RsGxsMsgMetaData*> &msgMetaV = result[grpId];
|
||||
|
||||
std::vector<RsGxsMsgMetaData*>::const_iterator vit = msgMetaV.begin();
|
||||
std::set<std::string> msgIdSet;
|
||||
std::set<RsGxsMessageId> msgIdSet;
|
||||
|
||||
// put ids in set for each searching
|
||||
for(; vit != msgMetaV.end(); vit++)
|
||||
@ -1516,17 +1516,17 @@ void RsGxsNetService::locked_genReqMsgTransaction(NxsTransaction* tr)
|
||||
std::list<RsNxsSyncMsgItem*>::iterator llit = msgItemL.begin();
|
||||
std::list<RsNxsItem*> reqList;
|
||||
|
||||
const std::string peerFrom = tr->mTransaction->PeerId();
|
||||
const RsPeerId peerFrom = tr->mTransaction->PeerId();
|
||||
|
||||
MsgAuthorV toVet;
|
||||
|
||||
std::list<std::string> peers;
|
||||
std::list<RsPeerId> peers;
|
||||
peers.push_back(tr->mTransaction->PeerId());
|
||||
|
||||
for(; llit != msgItemL.end(); llit++)
|
||||
{
|
||||
RsNxsSyncMsgItem*& syncItem = *llit;
|
||||
const std::string& msgId = syncItem->msgId;
|
||||
const RsGxsMessageId& msgId = syncItem->msgId;
|
||||
|
||||
if(msgIdSet.find(msgId) == msgIdSet.end()){
|
||||
|
||||
@ -1534,7 +1534,7 @@ void RsGxsNetService::locked_genReqMsgTransaction(NxsTransaction* tr)
|
||||
// or if there isn't an author (note as author requirement is
|
||||
// enforced at service level, if no author is needed then reputation
|
||||
// filtering is optional)
|
||||
bool noAuthor = syncItem->authorId.empty();
|
||||
bool noAuthor = syncItem->authorId.isNull();
|
||||
|
||||
// grp meta must be present if author present
|
||||
if(!noAuthor && grpMeta == NULL)
|
||||
@ -1586,7 +1586,7 @@ void RsGxsNetService::locked_genReqMsgTransaction(NxsTransaction* tr)
|
||||
}
|
||||
|
||||
void RsGxsNetService::locked_pushGrpTransactionFromList(
|
||||
std::list<RsNxsItem*>& reqList, const std::string& peerId, const uint32_t& transN)
|
||||
std::list<RsNxsItem*>& reqList, const RsPeerId& peerId, const uint32_t& transN)
|
||||
{
|
||||
RsNxsTransac* transac = new RsNxsTransac(mServType);
|
||||
transac->transactFlag = RsNxsTransac::FLAG_TYPE_GRP_LIST_REQ
|
||||
@ -1606,7 +1606,7 @@ void RsGxsNetService::locked_pushGrpTransactionFromList(
|
||||
delete newTrans;
|
||||
}
|
||||
void RsGxsNetService::addGroupItemToList(NxsTransaction*& tr,
|
||||
const std::string& grpId, uint32_t& transN,
|
||||
const RsGxsGroupId& grpId, uint32_t& transN,
|
||||
std::list<RsNxsItem*>& reqList)
|
||||
{
|
||||
RsNxsSyncGrpItem* grpItem = new RsNxsSyncGrpItem(mServType);
|
||||
@ -1643,8 +1643,8 @@ void RsGxsNetService::locked_genReqGrpTransaction(NxsTransaction* tr)
|
||||
}
|
||||
}
|
||||
|
||||
std::map<std::string, RsGxsGrpMetaData*> grpMetaMap;
|
||||
std::map<std::string, RsGxsGrpMetaData*>::const_iterator metaIter;
|
||||
std::map<RsGxsGroupId, RsGxsGrpMetaData*> grpMetaMap;
|
||||
std::map<RsGxsGroupId, RsGxsGrpMetaData*>::const_iterator metaIter;
|
||||
mDataStore->retrieveGxsGrpMetaData(grpMetaMap);
|
||||
|
||||
// now do compare and add loop
|
||||
@ -1654,13 +1654,13 @@ void RsGxsNetService::locked_genReqGrpTransaction(NxsTransaction* tr)
|
||||
uint32_t transN = locked_getTransactionId();
|
||||
|
||||
GrpAuthorV toVet;
|
||||
std::list<std::string> peers;
|
||||
std::list<RsPeerId> peers;
|
||||
peers.push_back(tr->mTransaction->PeerId());
|
||||
|
||||
for(; llit != grpItemL.end(); llit++)
|
||||
{
|
||||
RsNxsSyncGrpItem*& grpSyncItem = *llit;
|
||||
const std::string& grpId = grpSyncItem->grpId;
|
||||
const RsGxsGroupId& grpId = grpSyncItem->grpId;
|
||||
metaIter = grpMetaMap.find(grpId);
|
||||
bool haveItem = false;
|
||||
bool latestVersion = false;
|
||||
@ -1673,7 +1673,7 @@ void RsGxsNetService::locked_genReqGrpTransaction(NxsTransaction* tr)
|
||||
if(!haveItem || (haveItem && latestVersion) ){
|
||||
|
||||
// determine if you need to check reputation
|
||||
bool checkRep = !grpSyncItem->authorId.empty();
|
||||
bool checkRep = !grpSyncItem->authorId.isNull();
|
||||
|
||||
// check if you have reputation, if you don't then
|
||||
// place in holding pen
|
||||
@ -1708,7 +1708,7 @@ void RsGxsNetService::locked_genReqGrpTransaction(NxsTransaction* tr)
|
||||
|
||||
if(!toVet.empty())
|
||||
{
|
||||
std::string peerId = tr->mTransaction->PeerId();
|
||||
RsPeerId peerId = tr->mTransaction->PeerId();
|
||||
GrpRespPending* grp = new GrpRespPending(mReputations, peerId, toVet);
|
||||
mPendingResp.push_back(grp);
|
||||
}
|
||||
@ -1721,7 +1721,7 @@ void RsGxsNetService::locked_genReqGrpTransaction(NxsTransaction* tr)
|
||||
}
|
||||
|
||||
// clean up meta data
|
||||
std::map<std::string, RsGxsGrpMetaData*>::iterator mit = grpMetaMap.begin();
|
||||
std::map<RsGxsGroupId, RsGxsGrpMetaData*>::iterator mit = grpMetaMap.begin();
|
||||
|
||||
for(; mit != grpMetaMap.end(); mit++)
|
||||
delete mit->second;
|
||||
@ -1740,7 +1740,7 @@ void RsGxsNetService::locked_genSendGrpsTransaction(NxsTransaction* tr)
|
||||
|
||||
std::list<RsNxsItem*>::iterator lit = tr->mItems.begin();
|
||||
|
||||
std::map<std::string, RsNxsGrp*> grps;
|
||||
std::map<RsGxsGroupId, RsNxsGrp*> grps;
|
||||
|
||||
for(;lit != tr->mItems.end(); lit++)
|
||||
{
|
||||
@ -1771,8 +1771,8 @@ void RsGxsNetService::locked_genSendGrpsTransaction(NxsTransaction* tr)
|
||||
uint32_t transN = locked_getTransactionId();
|
||||
|
||||
// store grp items to send in transaction
|
||||
std::map<std::string, RsNxsGrp*>::iterator mit = grps.begin();
|
||||
std::string peerId = tr->mTransaction->PeerId();
|
||||
std::map<RsGxsGroupId, RsNxsGrp*>::iterator mit = grps.begin();
|
||||
RsPeerId peerId = tr->mTransaction->PeerId();
|
||||
for(;mit != grps.end(); mit++)
|
||||
{
|
||||
mit->second->PeerId(peerId); // set so it gets sent to right peer
|
||||
@ -1909,7 +1909,7 @@ void RsGxsNetService::locked_genSendMsgsTransaction(NxsTransaction* tr)
|
||||
return;
|
||||
}
|
||||
|
||||
std::string grpId = "";
|
||||
RsGxsGroupId grpId;
|
||||
|
||||
for(;lit != tr->mItems.end(); lit++)
|
||||
{
|
||||
@ -1918,7 +1918,7 @@ void RsGxsNetService::locked_genSendMsgsTransaction(NxsTransaction* tr)
|
||||
{
|
||||
msgIds[item->grpId].push_back(item->msgId);
|
||||
|
||||
if(grpId.empty())
|
||||
if(grpId.isNull())
|
||||
grpId = item->grpId;
|
||||
}
|
||||
else
|
||||
@ -1939,7 +1939,7 @@ void RsGxsNetService::locked_genSendMsgsTransaction(NxsTransaction* tr)
|
||||
|
||||
// store msg items to send in transaction
|
||||
GxsMsgResult::iterator mit = msgs.begin();
|
||||
std::string peerId = tr->mTransaction->PeerId();
|
||||
RsPeerId peerId = tr->mTransaction->PeerId();
|
||||
uint32_t msgSize = 0;
|
||||
|
||||
for(;mit != msgs.end(); mit++)
|
||||
@ -2008,7 +2008,7 @@ uint32_t RsGxsNetService::locked_getTransactionId()
|
||||
}
|
||||
bool RsGxsNetService::locked_addTransaction(NxsTransaction* tr)
|
||||
{
|
||||
const std::string& peer = tr->mTransaction->PeerId();
|
||||
const RsPeerId& peer = tr->mTransaction->PeerId();
|
||||
uint32_t transN = tr->mTransaction->transactionNumber;
|
||||
TransactionIdMap& transMap = mTransactions[peer];
|
||||
bool transNumExist = transMap.find(transN)
|
||||
@ -2041,7 +2041,7 @@ void RsGxsNetService::cleanTransactionItems(NxsTransaction* tr) const
|
||||
}
|
||||
|
||||
void RsGxsNetService::locked_pushGrpRespFromList(std::list<RsNxsItem*>& respList,
|
||||
const std::string& peer, const uint32_t& transN)
|
||||
const RsPeerId& peer, const uint32_t& transN)
|
||||
{
|
||||
NxsTransaction* tr = new NxsTransaction();
|
||||
tr->mItems = respList;
|
||||
@ -2085,17 +2085,17 @@ void RsGxsNetService::handleRecvSyncGroup(RsNxsSyncGrp* item)
|
||||
if(!locked_CanReceiveUpdate(item))
|
||||
return;
|
||||
|
||||
std::string peer = item->PeerId();
|
||||
RsPeerId peer = item->PeerId();
|
||||
|
||||
|
||||
|
||||
std::map<std::string, RsGxsGrpMetaData*> grp;
|
||||
std::map<RsGxsGroupId, RsGxsGrpMetaData*> grp;
|
||||
mDataStore->retrieveGxsGrpMetaData(grp);
|
||||
|
||||
if(grp.empty())
|
||||
return;
|
||||
|
||||
std::map<std::string, RsGxsGrpMetaData*>::iterator mit =
|
||||
std::map<RsGxsGroupId, RsGxsGrpMetaData*>::iterator mit =
|
||||
grp.begin();
|
||||
|
||||
std::list<RsNxsItem*> itemL;
|
||||
@ -2151,7 +2151,7 @@ void RsGxsNetService::handleRecvSyncGroup(RsNxsSyncGrp* item)
|
||||
|
||||
|
||||
|
||||
bool RsGxsNetService::canSendGrpId(const std::string& sslId, RsGxsGrpMetaData& grpMeta, std::vector<GrpIdCircleVet>& toVet)
|
||||
bool RsGxsNetService::canSendGrpId(const RsPeerId& sslId, RsGxsGrpMetaData& grpMeta, std::vector<GrpIdCircleVet>& toVet)
|
||||
{
|
||||
// first do the simple checks
|
||||
uint8_t circleType = grpMeta.mCircleType;
|
||||
@ -2180,7 +2180,7 @@ bool RsGxsNetService::canSendGrpId(const std::string& sslId, RsGxsGrpMetaData& g
|
||||
{
|
||||
// a non empty internal circle id means this
|
||||
// is the personal circle owner
|
||||
if(!grpMeta.mInternalCircle.empty())
|
||||
if(!grpMeta.mInternalCircle.isNull())
|
||||
{
|
||||
const RsGxsCircleId& internalCircleId = grpMeta.mCircleId;
|
||||
if(mCircles->isLoaded(internalCircleId))
|
||||
@ -2231,12 +2231,12 @@ void RsGxsNetService::handleRecvSyncMessage(RsNxsSyncMsg* item)
|
||||
if(!locked_CanReceiveUpdate(item))
|
||||
return;
|
||||
|
||||
const std::string& peer = item->PeerId();
|
||||
const RsPeerId& peer = item->PeerId();
|
||||
|
||||
GxsMsgMetaResult metaResult;
|
||||
GxsMsgReq req;
|
||||
|
||||
std::map<std::string, RsGxsGrpMetaData*> grpMetas;
|
||||
std::map<RsGxsGroupId, RsGxsGrpMetaData*> grpMetas;
|
||||
grpMetas[item->grpId] = NULL;
|
||||
mDataStore->retrieveGxsGrpMetaData(grpMetas);
|
||||
RsGxsGrpMetaData* grpMeta = grpMetas[item->grpId];
|
||||
@ -2244,7 +2244,7 @@ void RsGxsNetService::handleRecvSyncMessage(RsNxsSyncMsg* item)
|
||||
if(grpMeta == NULL)
|
||||
return;
|
||||
|
||||
req[item->grpId] = std::vector<std::string>();
|
||||
req[item->grpId] = std::vector<RsGxsMessageId>();
|
||||
mDataStore->retrieveGxsMsgMetaData(req, metaResult);
|
||||
std::vector<RsGxsMsgMetaData*>& msgMetas = metaResult[item->grpId];
|
||||
|
||||
@ -2289,7 +2289,7 @@ void RsGxsNetService::handleRecvSyncMessage(RsNxsSyncMsg* item)
|
||||
delete(grpMeta);
|
||||
}
|
||||
|
||||
void RsGxsNetService::locked_pushMsgRespFromList(std::list<RsNxsItem*>& itemL, const std::string& sslId,
|
||||
void RsGxsNetService::locked_pushMsgRespFromList(std::list<RsNxsItem*>& itemL, const RsPeerId& sslId,
|
||||
const uint32_t& transN)
|
||||
{
|
||||
NxsTransaction* tr = new NxsTransaction();
|
||||
@ -2317,7 +2317,7 @@ void RsGxsNetService::locked_pushMsgRespFromList(std::list<RsNxsItem*>& itemL, c
|
||||
}
|
||||
|
||||
bool RsGxsNetService::canSendMsgIds(const std::vector<RsGxsMsgMetaData*>& msgMetas,
|
||||
const RsGxsGrpMetaData& grpMeta, const std::string& sslId)
|
||||
const RsGxsGrpMetaData& grpMeta, const RsPeerId& sslId)
|
||||
{
|
||||
// first do the simple checks
|
||||
uint8_t circleType = grpMeta.mCircleType;
|
||||
@ -2360,7 +2360,7 @@ bool RsGxsNetService::canSendMsgIds(const std::vector<RsGxsMsgMetaData*>& msgMet
|
||||
{
|
||||
// a non empty internal circle id means this
|
||||
// is the personal circle owner
|
||||
if(!grpMeta.mInternalCircle.empty())
|
||||
if(!grpMeta.mInternalCircle.isNull())
|
||||
{
|
||||
const RsGxsCircleId& internalCircleId = grpMeta.mCircleId;
|
||||
if(mCircles->isLoaded(internalCircleId))
|
||||
@ -2412,7 +2412,7 @@ void RsGxsNetService::setSyncAge(uint32_t age)
|
||||
|
||||
}
|
||||
|
||||
int RsGxsNetService::requestGrp(const std::list<RsGxsGroupId>& grpId, const std::string& peerId)
|
||||
int RsGxsNetService::requestGrp(const std::list<RsGxsGroupId>& grpId, const RsPeerId& peerId)
|
||||
{
|
||||
RsStackMutex stack(mNxsMutex);
|
||||
mExplicitRequest[peerId].assign(grpId.begin(), grpId.end());
|
||||
@ -2423,11 +2423,11 @@ void RsGxsNetService::processExplicitGroupRequests()
|
||||
{
|
||||
RsStackMutex stack(mNxsMutex);
|
||||
|
||||
std::map<std::string, std::list<RsGxsGroupId> >::const_iterator cit = mExplicitRequest.begin();
|
||||
std::map<RsPeerId, std::list<RsGxsGroupId> >::const_iterator cit = mExplicitRequest.begin();
|
||||
|
||||
for(; cit != mExplicitRequest.end(); cit++)
|
||||
{
|
||||
const std::string& peerId = cit->first;
|
||||
const RsPeerId& peerId = cit->first;
|
||||
const std::list<RsGxsGroupId>& groupIdList = cit->second;
|
||||
|
||||
std::list<RsNxsItem*> grpSyncItems;
|
||||
|
@ -43,7 +43,7 @@
|
||||
typedef std::map<uint32_t, NxsTransaction*> TransactionIdMap;
|
||||
|
||||
/// to keep track of peers active transactions
|
||||
typedef std::map<std::string, TransactionIdMap > TransactionsPeerMap;
|
||||
typedef std::map<RsPeerId, TransactionIdMap > TransactionsPeerMap;
|
||||
|
||||
|
||||
/*!
|
||||
@ -92,7 +92,7 @@ public:
|
||||
* Circumvents polling of peers for message
|
||||
* @param peerId id of peer
|
||||
*/
|
||||
void requestGroupsOfPeer(const std::string& peerId){ return;}
|
||||
void requestGroupsOfPeer(const RsPeerId& peerId){ return;}
|
||||
|
||||
/*!
|
||||
* get messages of a peer for a given group id, this circumvents the normal
|
||||
@ -100,7 +100,7 @@ public:
|
||||
* @param peerId Id of peer
|
||||
* @param grpId id of group to request messages for
|
||||
*/
|
||||
void requestMessagesOfPeer(const std::string& peerId, const std::string& grpId){ return; }
|
||||
void requestMessagesOfPeer(const RsPeerId& peerId, const std::string& grpId){ return; }
|
||||
|
||||
/*!
|
||||
* pauses synchronisation of subscribed groups and request for group id
|
||||
@ -124,7 +124,7 @@ public:
|
||||
* @param enabled set to false to disable pause, and true otherwise
|
||||
* @return request token to be redeemed
|
||||
*/
|
||||
int requestGrp(const std::list<RsGxsGroupId>& grpId, const std::string& peerId);
|
||||
int requestGrp(const std::list<RsGxsGroupId>& grpId, const RsPeerId& peerId);
|
||||
|
||||
/* p3Config methods */
|
||||
|
||||
@ -302,30 +302,30 @@ private:
|
||||
* @param toVet groupid/peer to vet are stored here if their circle id is not cached
|
||||
* @return false, if you cannot send to this peer, true otherwise
|
||||
*/
|
||||
bool canSendGrpId(const std::string& sslId, RsGxsGrpMetaData& grpMeta, std::vector<GrpIdCircleVet>& toVet);
|
||||
bool canSendGrpId(const RsPeerId& sslId, RsGxsGrpMetaData& grpMeta, std::vector<GrpIdCircleVet>& toVet);
|
||||
|
||||
|
||||
bool canSendMsgIds(const std::vector<RsGxsMsgMetaData*>& msgMetas, const RsGxsGrpMetaData&, const std::string& sslId);
|
||||
bool canSendMsgIds(const std::vector<RsGxsMsgMetaData*>& msgMetas, const RsGxsGrpMetaData&, const RsPeerId& sslId);
|
||||
|
||||
void locked_createTransactionFromPending(MsgRespPending* grpPend);
|
||||
void locked_createTransactionFromPending(GrpRespPending* msgPend);
|
||||
void locked_createTransactionFromPending(GrpCircleIdRequestVetting* grpPend);
|
||||
void locked_createTransactionFromPending(MsgCircleIdsRequestVetting* grpPend);
|
||||
|
||||
void locked_pushMsgTransactionFromList(std::list<RsNxsItem*>& reqList, const std::string& peerId, const uint32_t& transN);
|
||||
void locked_pushGrpTransactionFromList(std::list<RsNxsItem*>& reqList, const std::string& peerId, const uint32_t& transN);
|
||||
void locked_pushGrpRespFromList(std::list<RsNxsItem*>& respList, const std::string& peer, const uint32_t& transN);
|
||||
void locked_pushMsgRespFromList(std::list<RsNxsItem*>& itemL, const std::string& sslId, const uint32_t& transN);
|
||||
void locked_pushMsgTransactionFromList(std::list<RsNxsItem*>& reqList, const RsPeerId& peerId, const uint32_t& transN);
|
||||
void locked_pushGrpTransactionFromList(std::list<RsNxsItem*>& reqList, const RsPeerId& peerId, const uint32_t& transN);
|
||||
void locked_pushGrpRespFromList(std::list<RsNxsItem*>& respList, const RsPeerId& peer, const uint32_t& transN);
|
||||
void locked_pushMsgRespFromList(std::list<RsNxsItem*>& itemL, const RsPeerId& sslId, const uint32_t& transN);
|
||||
void syncWithPeers();
|
||||
void addGroupItemToList(NxsTransaction*& tr,
|
||||
const std::string& grpId, uint32_t& transN,
|
||||
const RsGxsGroupId& grpId, uint32_t& transN,
|
||||
std::list<RsNxsItem*>& reqList);
|
||||
|
||||
bool locked_canReceive(const RsGxsGrpMetaData * const grpMeta, const std::string& peerId);
|
||||
bool locked_canReceive(const RsGxsGrpMetaData * const grpMeta, const RsPeerId& peerId);
|
||||
|
||||
void processExplicitGroupRequests();
|
||||
|
||||
void locked_doMsgUpdateWork(const RsNxsTransac* nxsTrans, const std::string& grpId);
|
||||
void locked_doMsgUpdateWork(const RsNxsTransac* nxsTrans, const RsGxsGroupId& grpId);
|
||||
|
||||
void updateServerSyncTS();
|
||||
|
||||
@ -415,7 +415,7 @@ private:
|
||||
uint32_t mTransactionTimeOut;
|
||||
|
||||
|
||||
std::string mOwnId;
|
||||
RsPeerId mOwnId;
|
||||
|
||||
RsNxsNetMgr* mNetMgr;
|
||||
|
||||
@ -434,16 +434,16 @@ private:
|
||||
std::vector<AuthorPending*> mPendingResp;
|
||||
std::vector<GrpCircleVetting*> mPendingCircleVets;
|
||||
|
||||
std::map<std::string, std::list<RsGxsGroupId> > mExplicitRequest;
|
||||
std::map<RsPeerId, std::list<RsGxsGroupId> > mExplicitRequest;
|
||||
|
||||
// nxs sync optimisation
|
||||
// can pull dynamically the latest timestamp for each message
|
||||
|
||||
public:
|
||||
|
||||
typedef std::map<std::string, RsGxsMsgUpdateItem*> ClientMsgMap;
|
||||
typedef std::map<std::string, RsGxsServerMsgUpdateItem*> ServerMsgMap;
|
||||
typedef std::map<std::string, RsGxsGrpUpdateItem*> ClientGrpMap;
|
||||
typedef std::map<RsPeerId, RsGxsMsgUpdateItem*> ClientMsgMap;
|
||||
typedef std::map<RsGxsGroupId, RsGxsServerMsgUpdateItem*> ServerMsgMap;
|
||||
typedef std::map<RsPeerId, RsGxsGrpUpdateItem*> ClientGrpMap;
|
||||
|
||||
private:
|
||||
|
||||
|
@ -47,14 +47,14 @@ bool AuthorPending::expired() const
|
||||
}
|
||||
|
||||
bool AuthorPending::getAuthorRep(GixsReputation& rep,
|
||||
const std::string& authorId, const std::string& peerId)
|
||||
const RsGxsId& authorId, const RsPeerId& peerId)
|
||||
{
|
||||
if(mRep->haveReputation(authorId))
|
||||
{
|
||||
return mRep->getReputation(authorId, rep);
|
||||
}
|
||||
|
||||
std::list<std::string> peers;
|
||||
std::list<RsPeerId> peers;
|
||||
peers.push_back(peerId);
|
||||
mRep->loadReputation(authorId, peers);
|
||||
return false;
|
||||
@ -70,12 +70,12 @@ GrpAuthEntry::GrpAuthEntry()
|
||||
|
||||
|
||||
|
||||
MsgRespPending::MsgRespPending(RsGixsReputation* rep, const std::string& peerId, const MsgAuthorV& msgAuthV, int cutOff)
|
||||
MsgRespPending::MsgRespPending(RsGixsReputation* rep, const RsPeerId& peerId, const MsgAuthorV& msgAuthV, int cutOff)
|
||||
: AuthorPending(rep, time(NULL)), mPeerId(peerId), mMsgAuthV(msgAuthV), mCutOff(cutOff)
|
||||
{
|
||||
}
|
||||
|
||||
GrpRespPending::GrpRespPending(RsGixsReputation* rep, const std::string& peerId, const GrpAuthorV& grpAuthV, int cutOff)
|
||||
GrpRespPending::GrpRespPending(RsGixsReputation* rep, const RsPeerId& peerId, const GrpAuthorV& grpAuthV, int cutOff)
|
||||
: AuthorPending(rep, time(NULL)), mPeerId(peerId), mGrpAuthV(grpAuthV), mCutOff(cutOff)
|
||||
{
|
||||
}
|
||||
@ -192,23 +192,23 @@ RsNxsNetMgrImpl::RsNxsNetMgrImpl(p3LinkMgr *lMgr)
|
||||
}
|
||||
|
||||
|
||||
std::string RsNxsNetMgrImpl::getOwnId()
|
||||
const RsPeerId& RsNxsNetMgrImpl::getOwnId()
|
||||
{
|
||||
RsStackMutex stack(mNxsNetMgrMtx);
|
||||
return mLinkMgr->getOwnId();
|
||||
}
|
||||
|
||||
void RsNxsNetMgrImpl::getOnlineList(std::set<std::string> &ssl_peers)
|
||||
void RsNxsNetMgrImpl::getOnlineList(std::set<RsPeerId> &ssl_peers)
|
||||
{
|
||||
ssl_peers.clear();
|
||||
|
||||
std::list<std::string> pList;
|
||||
std::list<RsPeerId> pList;
|
||||
{
|
||||
RsStackMutex stack(mNxsNetMgrMtx);
|
||||
mLinkMgr->getOnlineList(pList);
|
||||
}
|
||||
|
||||
std::list<std::string>::const_iterator lit = pList.begin();
|
||||
std::list<RsPeerId>::const_iterator lit = pList.begin();
|
||||
|
||||
for(; lit != pList.end(); lit++)
|
||||
ssl_peers.insert(*lit);
|
||||
@ -233,7 +233,7 @@ bool GrpCircleVetting::expired()
|
||||
{
|
||||
return time(NULL) > (mTimeStamp + EXPIRY_PERIOD_OFFSET);
|
||||
}
|
||||
bool GrpCircleVetting::canSend(const RsPgpId& peerId, const RsGxsCircleId& circleId)
|
||||
bool GrpCircleVetting::canSend(const SSLIdType& peerId, const RsGxsCircleId& circleId)
|
||||
{
|
||||
if(mCircles->isLoaded(circleId))
|
||||
{
|
||||
@ -247,7 +247,7 @@ bool GrpCircleVetting::canSend(const RsPgpId& peerId, const RsGxsCircleId& circl
|
||||
}
|
||||
|
||||
GrpCircleIdRequestVetting::GrpCircleIdRequestVetting(
|
||||
RsGcxs* const circles, std::vector<GrpIdCircleVet> grpCircleV, const std::string& peerId)
|
||||
RsGcxs* const circles, std::vector<GrpIdCircleVet> grpCircleV, const RsPeerId& peerId)
|
||||
: GrpCircleVetting(circles), mGrpCircleV(grpCircleV), mPeerId(peerId) {}
|
||||
|
||||
bool GrpCircleIdRequestVetting::cleared()
|
||||
@ -281,13 +281,13 @@ int GrpCircleIdRequestVetting::getType() const
|
||||
}
|
||||
|
||||
MsgIdCircleVet::MsgIdCircleVet(const RsGxsMessageId& msgId,
|
||||
const std::string& authorId)
|
||||
const RsGxsId& authorId)
|
||||
: mMsgId(msgId), mAuthorId(authorId) {
|
||||
}
|
||||
|
||||
MsgCircleIdsRequestVetting::MsgCircleIdsRequestVetting(RsGcxs* const circles,
|
||||
std::vector<MsgIdCircleVet> msgs, const RsGxsGroupId& grpId,
|
||||
const std::string& peerId, const RsGxsCircleId& circleId)
|
||||
const RsPeerId& peerId, const RsGxsCircleId& circleId)
|
||||
: GrpCircleVetting(circles), mMsgs(msgs), mGrpId(grpId), mPeerId(peerId), mCircleId(circleId) {}
|
||||
|
||||
bool MsgCircleIdsRequestVetting::cleared()
|
||||
|
@ -81,8 +81,8 @@ class RsNxsNetMgr
|
||||
public:
|
||||
|
||||
virtual ~RsNxsNetMgr(){};
|
||||
virtual std::string getOwnId() = 0;
|
||||
virtual void getOnlineList(std::set<std::string>& ssl_peers) = 0;
|
||||
virtual const RsPeerId& getOwnId() = 0;
|
||||
virtual void getOnlineList(std::set<RsPeerId>& ssl_peers) = 0;
|
||||
|
||||
};
|
||||
|
||||
@ -94,8 +94,8 @@ public:
|
||||
RsNxsNetMgrImpl(p3LinkMgr* lMgr);
|
||||
virtual ~RsNxsNetMgrImpl(){};
|
||||
|
||||
std::string getOwnId();
|
||||
void getOnlineList(std::set<std::string>& ssl_peers);
|
||||
const RsPeerId& getOwnId();
|
||||
void getOnlineList(std::set<RsPeerId>& ssl_peers);
|
||||
|
||||
private:
|
||||
|
||||
@ -141,7 +141,7 @@ protected:
|
||||
* @param authorId reputation to get
|
||||
* @return true if successfully retrieve repution
|
||||
*/
|
||||
bool getAuthorRep(GixsReputation& rep, const std::string& authorId, const std::string& peerId);
|
||||
bool getAuthorRep(GixsReputation& rep, const RsGxsId& authorId, const RsPeerId& peerId);
|
||||
|
||||
private:
|
||||
|
||||
@ -158,7 +158,7 @@ public:
|
||||
|
||||
RsGxsMessageId mMsgId;
|
||||
RsGxsGroupId mGrpId;
|
||||
std::string mAuthorId;
|
||||
RsGxsId mAuthorId;
|
||||
bool mPassedVetting;
|
||||
|
||||
};
|
||||
@ -171,7 +171,7 @@ public:
|
||||
GrpAuthEntry();
|
||||
|
||||
RsGxsGroupId mGrpId;
|
||||
std::string mAuthorId;
|
||||
RsGxsId mAuthorId;
|
||||
bool mPassedVetting;
|
||||
};
|
||||
|
||||
@ -182,11 +182,11 @@ class MsgRespPending : public AuthorPending
|
||||
{
|
||||
public:
|
||||
|
||||
MsgRespPending(RsGixsReputation* rep, const std::string& peerId, const MsgAuthorV& msgAuthV, int cutOff = 0);
|
||||
MsgRespPending(RsGixsReputation* rep, const RsPeerId& peerId, const MsgAuthorV& msgAuthV, int cutOff = 0);
|
||||
|
||||
int getType() const;
|
||||
bool accepted();
|
||||
std::string mPeerId;
|
||||
RsPeerId mPeerId;
|
||||
MsgAuthorV mMsgAuthV;
|
||||
int mCutOff;
|
||||
};
|
||||
@ -195,10 +195,10 @@ class GrpRespPending : public AuthorPending
|
||||
{
|
||||
public:
|
||||
|
||||
GrpRespPending(RsGixsReputation* rep, const std::string& peerId, const GrpAuthorV& grpAuthV, int cutOff = 0);
|
||||
GrpRespPending(RsGixsReputation* rep, const RsPeerId& peerId, const GrpAuthorV& grpAuthV, int cutOff = 0);
|
||||
int getType() const;
|
||||
bool accepted();
|
||||
std::string mPeerId;
|
||||
RsPeerId mPeerId;
|
||||
GrpAuthorV mGrpAuthV;
|
||||
int mCutOff;
|
||||
};
|
||||
@ -218,10 +218,10 @@ public:
|
||||
class MsgIdCircleVet
|
||||
{
|
||||
public:
|
||||
MsgIdCircleVet(const RsGxsMessageId& grpId, const std::string& authorId);
|
||||
MsgIdCircleVet(const RsGxsMessageId& grpId, const RsGxsId& authorId);
|
||||
|
||||
RsGxsMessageId mMsgId;
|
||||
std::string mAuthorId;
|
||||
RsGxsId mAuthorId;
|
||||
};
|
||||
|
||||
class GrpItemCircleVet
|
||||
@ -250,7 +250,7 @@ public:
|
||||
virtual bool cleared() = 0;
|
||||
|
||||
protected:
|
||||
bool canSend(const RsPgpId& peerId, const RsGxsCircleId& circleId);
|
||||
bool canSend(const RsPeerId& peerId, const RsGxsCircleId& circleId);
|
||||
|
||||
private:
|
||||
|
||||
@ -261,23 +261,23 @@ private:
|
||||
class GrpCircleIdRequestVetting : public GrpCircleVetting
|
||||
{
|
||||
public:
|
||||
GrpCircleIdRequestVetting(RsGcxs* const circles, std::vector<GrpIdCircleVet> mGrpCircleV, const std::string& peerId);
|
||||
GrpCircleIdRequestVetting(RsGcxs* const circles, std::vector<GrpIdCircleVet> mGrpCircleV, const RsPeerId& peerId);
|
||||
bool cleared();
|
||||
int getType() const;
|
||||
std::vector<GrpIdCircleVet> mGrpCircleV;
|
||||
std::string mPeerId;
|
||||
RsPeerId mPeerId;
|
||||
};
|
||||
|
||||
class MsgCircleIdsRequestVetting : public GrpCircleVetting
|
||||
{
|
||||
public:
|
||||
MsgCircleIdsRequestVetting(RsGcxs* const circles, std::vector<MsgIdCircleVet> msgs, const RsGxsGroupId& grpId,
|
||||
const std::string& peerId, const RsGxsCircleId& circleId);
|
||||
const RsPeerId& peerId, const RsGxsCircleId& circleId);
|
||||
bool cleared();
|
||||
int getType() const;
|
||||
std::vector<MsgIdCircleVet> mMsgs;
|
||||
RsGxsGroupId mGrpId;
|
||||
std::string mPeerId;
|
||||
RsPeerId mPeerId;
|
||||
RsGxsCircleId mCircleId;
|
||||
};
|
||||
|
||||
|
@ -50,7 +50,7 @@ class GroupMetaReq : public GxsRequest
|
||||
{
|
||||
|
||||
public:
|
||||
std::list<std::string> mGroupIds;
|
||||
std::list<RsGxsGroupId> mGroupIds;
|
||||
std::list<RsGxsGrpMetaData*> mGroupMetaData;
|
||||
};
|
||||
|
||||
@ -59,8 +59,8 @@ class GroupIdReq : public GxsRequest
|
||||
|
||||
public:
|
||||
|
||||
std::list<std::string> mGroupIds;
|
||||
std::list<std::string> mGroupIdResult;
|
||||
std::list<RsGxsGroupId> mGroupIds;
|
||||
std::list<RsGxsGroupId> mGroupIdResult;
|
||||
};
|
||||
|
||||
class GroupDataReq : public GxsRequest
|
||||
|
@ -130,7 +130,7 @@ bool RsGxsIntegrityCheck::check()
|
||||
for(; git != grp.end(); git++)
|
||||
{
|
||||
RsNxsGrp* grp = git->second;
|
||||
std::string currHash;
|
||||
RsFileHash currHash;
|
||||
pqihash pHash;
|
||||
pHash.addData(grp->grp.bin_data, grp->grp.bin_len);
|
||||
pHash.Complete(currHash);
|
||||
@ -157,7 +157,7 @@ bool RsGxsIntegrityCheck::check()
|
||||
for(; vit != msgV.end(); vit++)
|
||||
{
|
||||
RsNxsMsg* msg = *vit;
|
||||
std::string currHash;
|
||||
RsFileHash currHash;
|
||||
pqihash pHash;
|
||||
pHash.addData(msg->msg.bin_data, msg->msg.bin_len);
|
||||
pHash.Complete(currHash);
|
||||
|
@ -109,7 +109,7 @@ public:
|
||||
* @param enabled set to false to disable pause, and true otherwise
|
||||
* @return request token to be redeemed
|
||||
*/
|
||||
virtual int requestGrp(const std::list<RsGxsGroupId>& grpId, const std::string& peerId) = 0;
|
||||
virtual int requestGrp(const std::list<RsGxsGroupId>& grpId, const RsPeerId& peerId) = 0;
|
||||
|
||||
|
||||
};
|
||||
|
@ -62,7 +62,7 @@ ops_parse_cb_return_t cb_get_passphrase(const ops_parser_content_t *content_,ops
|
||||
|
||||
if(cbinfo->cryptinfo.keydata->nuids > 0)
|
||||
uid_hint = std::string((const char *)cbinfo->cryptinfo.keydata->uids[0].user_id) ;
|
||||
uid_hint += "(" + PGPIdType(cbinfo->cryptinfo.keydata->key_id).toStdString()+")" ;
|
||||
uid_hint += "(" + RsPgpId(cbinfo->cryptinfo.keydata->key_id).toStdString()+")" ;
|
||||
|
||||
passwd = PGPHandler::passphraseCallback()(NULL,uid_hint.c_str(),NULL,prev_was_bad) ;
|
||||
*(content->secret_key_passphrase.passphrase)= (char *)ops_mallocz(passwd.length()+1) ;
|
||||
@ -126,7 +126,7 @@ PGPHandler::PGPHandler(const std::string& pubring, const std::string& secring,co
|
||||
int i=0 ;
|
||||
while( (keydata = ops_keyring_get_key_by_index(_pubring,i)) != NULL )
|
||||
{
|
||||
PGPCertificateInfo& cert(_public_keyring_map[ PGPIdType(keydata->key_id).toStdString() ]) ;
|
||||
PGPCertificateInfo& cert(_public_keyring_map[ RsPgpId(keydata->key_id) ]) ;
|
||||
|
||||
// Init all certificates.
|
||||
|
||||
@ -152,7 +152,7 @@ PGPHandler::PGPHandler(const std::string& pubring, const std::string& secring,co
|
||||
i=0 ;
|
||||
while( (keydata = ops_keyring_get_key_by_index(_secring,i)) != NULL )
|
||||
{
|
||||
initCertificateInfo(_secret_keyring_map[ PGPIdType(keydata->key_id).toStdString() ],keydata,i) ;
|
||||
initCertificateInfo(_secret_keyring_map[ RsPgpId(keydata->key_id) ],keydata,i) ;
|
||||
++i ;
|
||||
}
|
||||
_secring_last_update_time = time(NULL) ;
|
||||
@ -246,11 +246,11 @@ bool PGPHandler::validateAndUpdateSignatures(PGPCertificateInfo& cert,const ops_
|
||||
if(result != NULL)
|
||||
for(size_t i=0;i<result->valid_count;++i)
|
||||
{
|
||||
std::string signer_str = PGPIdType(result->valid_sigs[i].signer_id).toStdString() ;
|
||||
RsPgpId signer_id(result->valid_sigs[i].signer_id);
|
||||
|
||||
if(cert.signers.find(signer_str) == cert.signers.end())
|
||||
if(cert.signers.find(signer_id) == cert.signers.end())
|
||||
{
|
||||
cert.signers.insert(signer_str) ;
|
||||
cert.signers.insert(signer_id) ;
|
||||
ret = true ;
|
||||
}
|
||||
}
|
||||
@ -282,9 +282,9 @@ bool PGPHandler::printKeys() const
|
||||
std::cerr << "Printing details of all " << std::dec << _public_keyring_map.size() << " keys: " << std::endl;
|
||||
#endif
|
||||
|
||||
for(std::map<std::string,PGPCertificateInfo>::const_iterator it(_public_keyring_map.begin()); it != _public_keyring_map.end(); it++)
|
||||
for(std::map<RsPgpId,PGPCertificateInfo>::const_iterator it(_public_keyring_map.begin()); it != _public_keyring_map.end(); it++)
|
||||
{
|
||||
std::cerr << "PGP Key: " << it->first << std::endl;
|
||||
std::cerr << "PGP Key: " << it->first.toStdString() << std::endl;
|
||||
|
||||
std::cerr << "\tName : " << it->second._name << std::endl;
|
||||
std::cerr << "\tEmail : " << it->second._email << std::endl;
|
||||
@ -296,11 +296,11 @@ bool PGPHandler::printKeys() const
|
||||
std::cerr << "\tfingerprint : " << it->second._fpr.toStdString() << std::endl;
|
||||
std::cerr << "\tSigners : " << it->second.signers.size() << std::endl;
|
||||
|
||||
std::set<std::string>::const_iterator sit;
|
||||
std::set<RsPgpId>::const_iterator sit;
|
||||
for(sit = it->second.signers.begin(); sit != it->second.signers.end(); sit++)
|
||||
{
|
||||
std::cerr << "\t\tSigner ID:" << *sit << ", Name: " ;
|
||||
const PGPCertificateInfo *info = PGPHandler::getCertificateInfo(PGPIdType(*sit)) ;
|
||||
std::cerr << "\t\tSigner ID:" << (*sit).toStdString() << ", Name: " ;
|
||||
const PGPCertificateInfo *info = PGPHandler::getCertificateInfo(*sit) ;
|
||||
|
||||
if(info != NULL)
|
||||
std::cerr << info->_name ;
|
||||
@ -314,18 +314,18 @@ bool PGPHandler::printKeys() const
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool PGPHandler::haveSecretKey(const PGPIdType& id) const
|
||||
bool PGPHandler::haveSecretKey(const RsPgpId& id) const
|
||||
{
|
||||
RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP memory structures.
|
||||
|
||||
return locked_getSecretKey(id) != NULL ;
|
||||
}
|
||||
|
||||
const PGPCertificateInfo *PGPHandler::getCertificateInfo(const PGPIdType& id) const
|
||||
const PGPCertificateInfo *PGPHandler::getCertificateInfo(const RsPgpId& id) const
|
||||
{
|
||||
RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP memory structures.
|
||||
|
||||
std::map<std::string,PGPCertificateInfo>::const_iterator it( _public_keyring_map.find(id.toStdString()) ) ;
|
||||
std::map<RsPgpId,PGPCertificateInfo>::const_iterator it( _public_keyring_map.find(id) ) ;
|
||||
|
||||
if(it != _public_keyring_map.end())
|
||||
return &it->second;
|
||||
@ -333,7 +333,7 @@ const PGPCertificateInfo *PGPHandler::getCertificateInfo(const PGPIdType& id) co
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
bool PGPHandler::availableGPGCertificatesWithPrivateKeys(std::list<PGPIdType>& ids)
|
||||
bool PGPHandler::availableGPGCertificatesWithPrivateKeys(std::list<RsPgpId>& ids)
|
||||
{
|
||||
RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP memory structures.
|
||||
// go through secret keyring, and check that we have the pubkey as well.
|
||||
@ -350,17 +350,17 @@ bool PGPHandler::availableGPGCertificatesWithPrivateKeys(std::list<PGPIdType>& i
|
||||
#else
|
||||
if(keydata->key.pkey.algorithm == OPS_PKA_RSA)
|
||||
#endif
|
||||
ids.push_back(PGPIdType(keydata->key_id)) ;
|
||||
ids.push_back(RsPgpId(keydata->key_id)) ;
|
||||
#ifdef DEBUG_PGPHANDLER
|
||||
else
|
||||
std::cerr << "Skipping keypair " << PGPIdType(keydata->key_id).toStdString() << ", unsupported algorithm: " << keydata->key.pkey.algorithm << std::endl;
|
||||
std::cerr << "Skipping keypair " << RsPgpId(keydata->key_id).toStdString() << ", unsupported algorithm: " << keydata->key.pkey.algorithm << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool PGPHandler::GeneratePGPCertificate(const std::string& name, const std::string& email, const std::string& passphrase, PGPIdType& pgpId, std::string& errString)
|
||||
bool PGPHandler::GeneratePGPCertificate(const std::string& name, const std::string& email, const std::string& passphrase, RsPgpId& pgpId, std::string& errString)
|
||||
{
|
||||
// Some basic checks
|
||||
|
||||
@ -430,9 +430,9 @@ bool PGPHandler::GeneratePGPCertificate(const std::string& name, const std::stri
|
||||
|
||||
// 4 - copy the encrypted private key to the private keyring
|
||||
|
||||
pgpId = PGPIdType(tmp_secring->keys[0].key_id) ;
|
||||
pgpId = RsPgpId(tmp_secring->keys[0].key_id) ;
|
||||
addNewKeyToOPSKeyring(_secring,tmp_secring->keys[0]) ;
|
||||
initCertificateInfo(_secret_keyring_map[ pgpId.toStdString() ],&tmp_secring->keys[0],_secring->nkeys-1) ;
|
||||
initCertificateInfo(_secret_keyring_map[ pgpId ],&tmp_secring->keys[0],_secring->nkeys-1) ;
|
||||
|
||||
#ifdef DEBUG_PGPHANDLER
|
||||
std::cerr << "Added new secret key with id " << pgpId.toStdString() << " to secret keyring." << std::endl;
|
||||
@ -546,18 +546,18 @@ std::string PGPHandler::makeRadixEncodedPGPKey(const ops_keydata_t *key,bool inc
|
||||
return res ;
|
||||
}
|
||||
|
||||
const ops_keydata_t *PGPHandler::locked_getSecretKey(const PGPIdType& id) const
|
||||
const ops_keydata_t *PGPHandler::locked_getSecretKey(const RsPgpId& id) const
|
||||
{
|
||||
std::map<std::string,PGPCertificateInfo>::const_iterator res = _secret_keyring_map.find(id.toStdString()) ;
|
||||
std::map<RsPgpId,PGPCertificateInfo>::const_iterator res = _secret_keyring_map.find(id) ;
|
||||
|
||||
if(res == _secret_keyring_map.end())
|
||||
return NULL ;
|
||||
else
|
||||
return ops_keyring_get_key_by_index(_secring,res->second._key_index) ;
|
||||
}
|
||||
const ops_keydata_t *PGPHandler::locked_getPublicKey(const PGPIdType& id,bool stamp_the_key) const
|
||||
const ops_keydata_t *PGPHandler::locked_getPublicKey(const RsPgpId& id,bool stamp_the_key) const
|
||||
{
|
||||
std::map<std::string,PGPCertificateInfo>::const_iterator res = _public_keyring_map.find(id.toStdString()) ;
|
||||
std::map<RsPgpId,PGPCertificateInfo>::const_iterator res = _public_keyring_map.find(id) ;
|
||||
|
||||
if(res == _public_keyring_map.end())
|
||||
return NULL ;
|
||||
@ -580,7 +580,7 @@ const ops_keydata_t *PGPHandler::locked_getPublicKey(const PGPIdType& id,bool st
|
||||
}
|
||||
}
|
||||
|
||||
std::string PGPHandler::SaveCertificateToString(const PGPIdType& id,bool include_signatures) const
|
||||
std::string PGPHandler::SaveCertificateToString(const RsPgpId& id,bool include_signatures) const
|
||||
{
|
||||
RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP memory structures.
|
||||
const ops_keydata_t *key = locked_getPublicKey(id,false) ;
|
||||
@ -594,12 +594,18 @@ std::string PGPHandler::SaveCertificateToString(const PGPIdType& id,bool include
|
||||
return makeRadixEncodedPGPKey(key,include_signatures) ;
|
||||
}
|
||||
|
||||
bool PGPHandler::exportPublicKey(const PGPIdType& id,unsigned char *& mem_block,size_t& mem_size,bool armoured,bool include_signatures) const
|
||||
bool PGPHandler::exportPublicKey(const RsPgpId& id,unsigned char *& mem_block,size_t& mem_size,bool armoured,bool include_signatures) const
|
||||
{
|
||||
RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP memory structures.
|
||||
const ops_keydata_t *key = locked_getPublicKey(id,false) ;
|
||||
mem_block = NULL ;
|
||||
|
||||
if(armoured)
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << ": should not be used with armoured=true, because there's a bug in the armoured export of OPS" << std::endl;
|
||||
return false ;
|
||||
}
|
||||
|
||||
if(key == NULL)
|
||||
{
|
||||
std::cerr << "Cannot output key " << id.toStdString() << ": not found in keyring." << std::endl;
|
||||
@ -634,7 +640,7 @@ bool PGPHandler::exportPublicKey(const PGPIdType& id,unsigned char *& mem_block,
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool PGPHandler::exportGPGKeyPair(const std::string& filename,const PGPIdType& exported_key_id) const
|
||||
bool PGPHandler::exportGPGKeyPair(const std::string& filename,const RsPgpId& exported_key_id) const
|
||||
{
|
||||
RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP memory structures.
|
||||
|
||||
@ -667,7 +673,7 @@ bool PGPHandler::exportGPGKeyPair(const std::string& filename,const PGPIdType& e
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool PGPHandler::getGPGDetailsFromBinaryBlock(const unsigned char *mem_block,size_t mem_size,std::string& key_id, std::string& name, std::list<std::string>& signers) const
|
||||
bool PGPHandler::getGPGDetailsFromBinaryBlock(const unsigned char *mem_block,size_t mem_size,RsPgpId& key_id, std::string& name, std::list<RsPgpId>& signers) const
|
||||
{
|
||||
ops_keyring_t *tmp_keyring = allocateOPSKeyring();
|
||||
ops_memory_t *mem = ops_memory_new() ;
|
||||
@ -699,7 +705,7 @@ bool PGPHandler::getGPGDetailsFromBinaryBlock(const unsigned char *mem_block,siz
|
||||
return false ;
|
||||
}
|
||||
|
||||
key_id = PGPIdType(tmp_keyring->keys[0].key_id).toStdString() ;
|
||||
key_id = RsPgpId(tmp_keyring->keys[0].key_id) ;
|
||||
name = std::string((char *)tmp_keyring->keys[0].uids[0].user_id) ;
|
||||
|
||||
// now parse signatures.
|
||||
@ -725,14 +731,11 @@ bool PGPHandler::getGPGDetailsFromBinaryBlock(const unsigned char *mem_block,siz
|
||||
// Parse signers.
|
||||
//
|
||||
|
||||
std::set<std::string> signers_set ; // Use a set to remove duplicates.
|
||||
std::set<RsPgpId> signers_set ; // Use a set to remove duplicates.
|
||||
|
||||
if(result != NULL)
|
||||
for(size_t i=0;i<result->valid_count;++i)
|
||||
{
|
||||
std::string signer_str = PGPIdType(result->valid_sigs[i].signer_id).toStdString() ;
|
||||
signers_set.insert(signer_str) ;
|
||||
}
|
||||
signers_set.insert(RsPgpId(result->valid_sigs[i].signer_id)) ;
|
||||
|
||||
ops_validate_result_free(result) ;
|
||||
|
||||
@ -743,13 +746,13 @@ bool PGPHandler::getGPGDetailsFromBinaryBlock(const unsigned char *mem_block,siz
|
||||
|
||||
signers.clear() ;
|
||||
|
||||
for(std::set<std::string>::const_iterator it(signers_set.begin());it!=signers_set.end();++it)
|
||||
for(std::set<RsPgpId>::const_iterator it(signers_set.begin());it!=signers_set.end();++it)
|
||||
signers.push_back(*it) ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool PGPHandler::importGPGKeyPair(const std::string& filename,PGPIdType& imported_key_id,std::string& import_error)
|
||||
bool PGPHandler::importGPGKeyPair(const std::string& filename,RsPgpId& imported_key_id,std::string& import_error)
|
||||
{
|
||||
import_error = "" ;
|
||||
|
||||
@ -863,7 +866,7 @@ bool PGPHandler::importGPGKeyPair(const std::string& filename,PGPIdType& importe
|
||||
{
|
||||
RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP memory structures.
|
||||
|
||||
imported_key_id = PGPIdType(pubkey->key_id) ;
|
||||
imported_key_id = RsPgpId(pubkey->key_id) ;
|
||||
|
||||
if(locked_getSecretKey(imported_key_id) == NULL)
|
||||
{
|
||||
@ -900,7 +903,7 @@ bool PGPHandler::importGPGKeyPair(const std::string& filename,PGPIdType& importe
|
||||
}
|
||||
|
||||
addNewKeyToOPSKeyring(_secring,*seckey) ;
|
||||
initCertificateInfo(_secret_keyring_map[ imported_key_id.toStdString() ],seckey,_secring->nkeys-1) ;
|
||||
initCertificateInfo(_secret_keyring_map[ imported_key_id ],seckey,_secring->nkeys-1) ;
|
||||
}
|
||||
else
|
||||
import_error = "Private key already exists! Not importing it again." ;
|
||||
@ -931,7 +934,7 @@ void PGPHandler::addNewKeyToOPSKeyring(ops_keyring_t *kr,const ops_keydata_t& ke
|
||||
kr->nkeys++ ;
|
||||
}
|
||||
|
||||
bool PGPHandler::LoadCertificateFromString(const std::string& pgp_cert,PGPIdType& id,std::string& error_string)
|
||||
bool PGPHandler::LoadCertificateFromString(const std::string& pgp_cert,RsPgpId& id,std::string& error_string)
|
||||
{
|
||||
RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP memory structures.
|
||||
#ifdef DEBUG_PGPHANDLER
|
||||
@ -1025,7 +1028,7 @@ bool PGPHandler::LoadCertificateFromString(const std::string& pgp_cert,PGPIdType
|
||||
std::cerr << "Key already in public keyring." << std::endl;
|
||||
|
||||
if(tmp_keyring->nkeys > 0)
|
||||
id = PGPIdType(tmp_keyring->keys[0].key_id) ;
|
||||
id = RsPgpId(tmp_keyring->keys[0].key_id) ;
|
||||
else
|
||||
return false ;
|
||||
|
||||
@ -1037,10 +1040,10 @@ bool PGPHandler::LoadCertificateFromString(const std::string& pgp_cert,PGPIdType
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool PGPHandler::locked_addOrMergeKey(ops_keyring_t *keyring,std::map<std::string,PGPCertificateInfo>& kmap,const ops_keydata_t *keydata)
|
||||
bool PGPHandler::locked_addOrMergeKey(ops_keyring_t *keyring,std::map<RsPgpId,PGPCertificateInfo>& kmap,const ops_keydata_t *keydata)
|
||||
{
|
||||
bool ret = false ;
|
||||
PGPIdType id(keydata->key_id) ;
|
||||
RsPgpId id(keydata->key_id) ;
|
||||
|
||||
#ifdef DEBUG_PGPHANDLER
|
||||
std::cerr << "AddOrMergeKey():" << std::endl;
|
||||
@ -1049,7 +1052,7 @@ bool PGPHandler::locked_addOrMergeKey(ops_keyring_t *keyring,std::map<std::strin
|
||||
|
||||
// See if the key is already in the keyring
|
||||
const ops_keydata_t *existing_key = NULL;
|
||||
std::map<std::string,PGPCertificateInfo>::const_iterator res = kmap.find(id.toStdString()) ;
|
||||
std::map<RsPgpId,PGPCertificateInfo>::const_iterator res = kmap.find(id) ;
|
||||
|
||||
// Checks that
|
||||
// - the key is referenced by keyid
|
||||
@ -1062,7 +1065,7 @@ bool PGPHandler::locked_addOrMergeKey(ops_keyring_t *keyring,std::map<std::strin
|
||||
std::cerr << " Key is new. Adding it to keyring" << std::endl;
|
||||
#endif
|
||||
addNewKeyToOPSKeyring(keyring,*keydata) ; // the key is new.
|
||||
initCertificateInfo(kmap[id.toStdString()],keydata,keyring->nkeys-1) ;
|
||||
initCertificateInfo(kmap[id],keydata,keyring->nkeys-1) ;
|
||||
existing_key = &(keyring->keys[keyring->nkeys-1]) ;
|
||||
ret = true ;
|
||||
}
|
||||
@ -1080,18 +1083,18 @@ bool PGPHandler::locked_addOrMergeKey(ops_keyring_t *keyring,std::map<std::strin
|
||||
ret = mergeKeySignatures(const_cast<ops_keydata_t*>(existing_key),keydata) ;
|
||||
|
||||
if(ret)
|
||||
initCertificateInfo(kmap[id.toStdString()],existing_key,res->second._key_index) ;
|
||||
initCertificateInfo(kmap[id],existing_key,res->second._key_index) ;
|
||||
}
|
||||
|
||||
if(ret)
|
||||
{
|
||||
validateAndUpdateSignatures(kmap[id.toStdString()],existing_key) ;
|
||||
kmap[id.toStdString()]._time_stamp = time(NULL) ;
|
||||
validateAndUpdateSignatures(kmap[id],existing_key) ;
|
||||
kmap[id]._time_stamp = time(NULL) ;
|
||||
}
|
||||
|
||||
return ret ;
|
||||
}
|
||||
// bool PGPHandler::encryptTextToString(const PGPIdType& key_id,const std::string& text,std::string& outstring)
|
||||
// bool PGPHandler::encryptTextToString(const RsPgpId& key_id,const std::string& text,std::string& outstring)
|
||||
// {
|
||||
// RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP memory structures.
|
||||
//
|
||||
@ -1122,7 +1125,7 @@ bool PGPHandler::locked_addOrMergeKey(ops_keyring_t *keyring,std::map<std::strin
|
||||
//
|
||||
// return true ;
|
||||
// }
|
||||
bool PGPHandler::encryptTextToFile(const PGPIdType& key_id,const std::string& text,const std::string& outfile)
|
||||
bool PGPHandler::encryptTextToFile(const RsPgpId& key_id,const std::string& text,const std::string& outfile)
|
||||
{
|
||||
RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP memory structures.
|
||||
|
||||
@ -1169,7 +1172,7 @@ bool PGPHandler::encryptTextToFile(const PGPIdType& key_id,const std::string& te
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool PGPHandler::encryptDataBin(const PGPIdType& key_id,const void *data, const uint32_t len, unsigned char *encrypted_data, unsigned int *encrypted_data_len)
|
||||
bool PGPHandler::encryptDataBin(const RsPgpId& key_id,const void *data, const uint32_t len, unsigned char *encrypted_data, unsigned int *encrypted_data_len)
|
||||
{
|
||||
RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP memory structures.
|
||||
|
||||
@ -1229,7 +1232,7 @@ bool PGPHandler::encryptDataBin(const PGPIdType& key_id,const void *data, const
|
||||
return res ;
|
||||
}
|
||||
|
||||
bool PGPHandler::decryptDataBin(const PGPIdType& /*key_id*/,const void *encrypted_data, const uint32_t encrypted_len, unsigned char *data, unsigned int *data_len)
|
||||
bool PGPHandler::decryptDataBin(const RsPgpId& /*key_id*/,const void *encrypted_data, const uint32_t encrypted_len, unsigned char *data, unsigned int *data_len)
|
||||
{
|
||||
int out_length ;
|
||||
unsigned char *out ;
|
||||
@ -1248,7 +1251,7 @@ bool PGPHandler::decryptDataBin(const PGPIdType& /*key_id*/,const void *encrypte
|
||||
return (bool)res ;
|
||||
}
|
||||
|
||||
bool PGPHandler::decryptTextFromFile(const PGPIdType&,std::string& text,const std::string& inputfile)
|
||||
bool PGPHandler::decryptTextFromFile(const RsPgpId&,std::string& text,const std::string& inputfile)
|
||||
{
|
||||
RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP memory structures.
|
||||
|
||||
@ -1282,7 +1285,7 @@ bool PGPHandler::decryptTextFromFile(const PGPIdType&,std::string& text,const st
|
||||
return (bool)res ;
|
||||
}
|
||||
|
||||
bool PGPHandler::SignDataBin(const PGPIdType& 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)
|
||||
{
|
||||
RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP memory structures.
|
||||
// need to find the key and to decrypt it.
|
||||
@ -1298,7 +1301,7 @@ bool PGPHandler::SignDataBin(const PGPIdType& id,const void *data, const uint32_
|
||||
std::string uid_hint ;
|
||||
if(key->nuids > 0)
|
||||
uid_hint = std::string((const char *)key->uids[0].user_id) ;
|
||||
uid_hint += "(" + PGPIdType(key->key_id).toStdString()+")" ;
|
||||
uid_hint += "(" + RsPgpId(key->key_id).toStdString()+")" ;
|
||||
|
||||
#ifdef DEBUG_PGPHANDLER
|
||||
ops_fingerprint_t f ;
|
||||
@ -1357,7 +1360,7 @@ bool PGPHandler::SignDataBin(const PGPIdType& id,const void *data, const uint32_
|
||||
return res ;
|
||||
}
|
||||
|
||||
bool PGPHandler::privateSignCertificate(const PGPIdType& ownId,const PGPIdType& id_of_key_to_sign)
|
||||
bool PGPHandler::privateSignCertificate(const RsPgpId& ownId,const RsPgpId& id_of_key_to_sign)
|
||||
{
|
||||
RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP memory structures.
|
||||
|
||||
@ -1386,7 +1389,7 @@ bool PGPHandler::privateSignCertificate(const PGPIdType& ownId,const PGPIdType&
|
||||
return false ;
|
||||
}
|
||||
|
||||
std::string passphrase = _passphrase_callback(NULL,PGPIdType(skey->key_id).toStdString().c_str(),"Please enter passwd for encrypting your key : ",false) ;
|
||||
std::string passphrase = _passphrase_callback(NULL,RsPgpId(skey->key_id).toStdString().c_str(),"Please enter passwd for encrypting your key : ",false) ;
|
||||
|
||||
ops_secret_key_t *secret_key = ops_decrypt_secret_key_from_data(skey,passphrase.c_str()) ;
|
||||
|
||||
@ -1413,36 +1416,34 @@ bool PGPHandler::privateSignCertificate(const PGPIdType& ownId,const PGPIdType&
|
||||
|
||||
// 4 - update signatures.
|
||||
//
|
||||
PGPCertificateInfo& cert(_public_keyring_map[ id_of_key_to_sign.toStdString() ]) ;
|
||||
PGPCertificateInfo& cert(_public_keyring_map[ id_of_key_to_sign ]) ;
|
||||
validateAndUpdateSignatures(cert,key_to_sign) ;
|
||||
cert._flags |= PGPCertificateInfo::PGP_CERTIFICATE_FLAG_HAS_OWN_SIGNATURE ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
void PGPHandler::updateOwnSignatureFlag(const PGPIdType& own_id)
|
||||
void PGPHandler::updateOwnSignatureFlag(const RsPgpId& own_id)
|
||||
{
|
||||
RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP memory structures.
|
||||
|
||||
std::string own_id_str = own_id.toStdString();
|
||||
|
||||
if(_public_keyring_map.find(own_id_str)==_public_keyring_map.end())
|
||||
if(_public_keyring_map.find(own_id)==_public_keyring_map.end())
|
||||
{
|
||||
std::cerr << __func__ << ": key with id=" << own_id_str << " not in keyring." << std::endl;
|
||||
std::cerr << __func__ << ": key with id=" << own_id.toStdString() << " not in keyring." << std::endl;
|
||||
// return now, because the following operation would add an entry to _public_keyring_map
|
||||
return;
|
||||
}
|
||||
|
||||
PGPCertificateInfo& own_cert(_public_keyring_map[ own_id_str ]) ;
|
||||
PGPCertificateInfo& own_cert(_public_keyring_map[ own_id ]) ;
|
||||
|
||||
for(std::map<std::string,PGPCertificateInfo>::iterator it=_public_keyring_map.begin();it!=_public_keyring_map.end();++it)
|
||||
locked_updateOwnSignatureFlag(it->second,it->first,own_cert,own_id_str) ;
|
||||
for(std::map<RsPgpId,PGPCertificateInfo>::iterator it=_public_keyring_map.begin();it!=_public_keyring_map.end();++it)
|
||||
locked_updateOwnSignatureFlag(it->second,it->first,own_cert,own_id) ;
|
||||
}
|
||||
void PGPHandler::updateOwnSignatureFlag(const PGPIdType& cert_id,const PGPIdType& own_id)
|
||||
void PGPHandler::updateOwnSignatureFlag(const RsPgpId& cert_id,const RsPgpId& own_id)
|
||||
{
|
||||
RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP memory structures.
|
||||
|
||||
std::map<std::string,PGPCertificateInfo>::iterator it( _public_keyring_map.find(cert_id.toStdString()) ) ;
|
||||
std::map<RsPgpId,PGPCertificateInfo>::iterator it( _public_keyring_map.find(cert_id) ) ;
|
||||
|
||||
if(it == _public_keyring_map.end())
|
||||
{
|
||||
@ -1452,25 +1453,24 @@ void PGPHandler::updateOwnSignatureFlag(const PGPIdType& cert_id,const PGPIdType
|
||||
|
||||
PGPCertificateInfo& cert( it->second );
|
||||
|
||||
std::string own_id_str = own_id.toStdString();
|
||||
PGPCertificateInfo& own_cert(_public_keyring_map[ own_id_str ]) ;
|
||||
PGPCertificateInfo& own_cert(_public_keyring_map[ own_id ]) ;
|
||||
|
||||
locked_updateOwnSignatureFlag(cert,cert_id.toStdString(),own_cert,own_id_str) ;
|
||||
locked_updateOwnSignatureFlag(cert,cert_id,own_cert,own_id) ;
|
||||
}
|
||||
void PGPHandler::locked_updateOwnSignatureFlag(PGPCertificateInfo& cert,const std::string& cert_id_str,PGPCertificateInfo& own_cert,const std::string& own_id_str)
|
||||
void PGPHandler::locked_updateOwnSignatureFlag(PGPCertificateInfo& cert,const RsPgpId& cert_id,PGPCertificateInfo& own_cert,const RsPgpId& own_id_str)
|
||||
{
|
||||
if(cert.signers.find(own_id_str) != cert.signers.end())
|
||||
cert._flags |= PGPCertificateInfo::PGP_CERTIFICATE_FLAG_HAS_OWN_SIGNATURE ;
|
||||
else
|
||||
cert._flags &= ~PGPCertificateInfo::PGP_CERTIFICATE_FLAG_HAS_OWN_SIGNATURE ;
|
||||
|
||||
if(own_cert.signers.find( cert_id_str ) != own_cert.signers.end())
|
||||
if(own_cert.signers.find( cert_id ) != own_cert.signers.end())
|
||||
cert._flags |= PGPCertificateInfo::PGP_CERTIFICATE_FLAG_HAS_SIGNED_ME ;
|
||||
else
|
||||
cert._flags &= ~PGPCertificateInfo::PGP_CERTIFICATE_FLAG_HAS_SIGNED_ME ;
|
||||
}
|
||||
|
||||
bool PGPHandler::getKeyFingerprint(const PGPIdType& id,PGPFingerprintType& fp) const
|
||||
bool PGPHandler::getKeyFingerprint(const RsPgpId& id,PGPFingerprintType& fp) const
|
||||
{
|
||||
RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP memory structures.
|
||||
|
||||
@ -1491,7 +1491,7 @@ bool PGPHandler::VerifySignBin(const void *literal_data, uint32_t literal_data_l
|
||||
{
|
||||
RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP memory structures.
|
||||
|
||||
PGPIdType id = PGPIdType(key_fingerprint.toByteArray() + PGPFingerprintType::SIZE_IN_BYTES - PGPIdType::SIZE_IN_BYTES) ;
|
||||
RsPgpId id = RsPgpId(key_fingerprint.toByteArray() + PGPFingerprintType::SIZE_IN_BYTES - RsPgpId::SIZE_IN_BYTES) ;
|
||||
const ops_keydata_t *key = locked_getPublicKey(id,true) ;
|
||||
|
||||
if(key == NULL)
|
||||
@ -1524,11 +1524,11 @@ bool PGPHandler::VerifySignBin(const void *literal_data, uint32_t literal_data_l
|
||||
return ops_validate_detached_signature(literal_data,literal_data_length,sign,sign_len,key) ;
|
||||
}
|
||||
|
||||
void PGPHandler::setAcceptConnexion(const PGPIdType& id,bool b)
|
||||
void PGPHandler::setAcceptConnexion(const RsPgpId& id,bool b)
|
||||
{
|
||||
RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP memory structures.
|
||||
|
||||
std::map<std::string,PGPCertificateInfo>::iterator res = _public_keyring_map.find(id.toStdString()) ;
|
||||
std::map<RsPgpId,PGPCertificateInfo>::iterator res = _public_keyring_map.find(id) ;
|
||||
|
||||
if(res != _public_keyring_map.end())
|
||||
{
|
||||
@ -1539,32 +1539,32 @@ void PGPHandler::setAcceptConnexion(const PGPIdType& id,bool b)
|
||||
}
|
||||
}
|
||||
|
||||
bool PGPHandler::getGPGFilteredList(std::list<PGPIdType>& list,bool (*filter)(const PGPCertificateInfo&)) const
|
||||
bool PGPHandler::getGPGFilteredList(std::list<RsPgpId>& list,bool (*filter)(const PGPCertificateInfo&)) const
|
||||
{
|
||||
RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP directory.
|
||||
list.clear() ;
|
||||
|
||||
for(std::map<std::string,PGPCertificateInfo>::const_iterator it(_public_keyring_map.begin());it!=_public_keyring_map.end();++it)
|
||||
for(std::map<RsPgpId,PGPCertificateInfo>::const_iterator it(_public_keyring_map.begin());it!=_public_keyring_map.end();++it)
|
||||
if( filter == NULL || (*filter)(it->second) )
|
||||
list.push_back(PGPIdType(it->first)) ;
|
||||
list.push_back(RsPgpId(it->first)) ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool PGPHandler::isGPGId(const std::string &id)
|
||||
bool PGPHandler::isGPGId(const RsPgpId &id)
|
||||
{
|
||||
return _public_keyring_map.find(id) != _public_keyring_map.end() ;
|
||||
}
|
||||
|
||||
bool PGPHandler::isGPGSigned(const std::string &id)
|
||||
bool PGPHandler::isGPGSigned(const RsPgpId &id)
|
||||
{
|
||||
std::map<std::string,PGPCertificateInfo>::const_iterator res = _public_keyring_map.find(id) ;
|
||||
std::map<RsPgpId,PGPCertificateInfo>::const_iterator res = _public_keyring_map.find(id) ;
|
||||
return res != _public_keyring_map.end() && (res->second._flags & PGPCertificateInfo::PGP_CERTIFICATE_FLAG_HAS_OWN_SIGNATURE) ;
|
||||
}
|
||||
|
||||
bool PGPHandler::isGPGAccepted(const std::string &id)
|
||||
bool PGPHandler::isGPGAccepted(const RsPgpId &id)
|
||||
{
|
||||
std::map<std::string,PGPCertificateInfo>::const_iterator res = _public_keyring_map.find(id) ;
|
||||
std::map<RsPgpId,PGPCertificateInfo>::const_iterator res = _public_keyring_map.find(id) ;
|
||||
return (res != _public_keyring_map.end()) && (res->second._flags & PGPCertificateInfo::PGP_CERTIFICATE_FLAG_ACCEPT_CONNEXION) ;
|
||||
}
|
||||
|
||||
@ -1592,7 +1592,7 @@ bool PGPHandler::mergeKeySignatures(ops_keydata_t *dst,const ops_keydata_t *src)
|
||||
// First sort all signatures into lists to see which is new, which is not new
|
||||
|
||||
#ifdef DEBUG_PGPHANDLER
|
||||
std::cerr << "Merging signatures for key " << PGPIdType(dst->key_id).toStdString() << std::endl;
|
||||
std::cerr << "Merging signatures for key " << RsPgpId(dst->key_id).toStdString() << std::endl;
|
||||
#endif
|
||||
std::set<ops_packet_t> dst_packets ;
|
||||
|
||||
@ -1627,7 +1627,7 @@ bool PGPHandler::mergeKeySignatures(ops_keydata_t *dst,const ops_keydata_t *src)
|
||||
return to_add.size() > 0 ;
|
||||
}
|
||||
|
||||
bool PGPHandler::privateTrustCertificate(const PGPIdType& id,int trustlvl)
|
||||
bool PGPHandler::privateTrustCertificate(const RsPgpId& id,int trustlvl)
|
||||
{
|
||||
if(trustlvl < 0 || trustlvl >= 6 || trustlvl == 1)
|
||||
{
|
||||
@ -1635,7 +1635,7 @@ bool PGPHandler::privateTrustCertificate(const PGPIdType& id,int trustlvl)
|
||||
return false ;
|
||||
}
|
||||
|
||||
std::map<std::string,PGPCertificateInfo>::iterator it = _public_keyring_map.find(id.toStdString());
|
||||
std::map<RsPgpId,PGPCertificateInfo>::iterator it = _public_keyring_map.find(id);
|
||||
|
||||
if(it == _public_keyring_map.end())
|
||||
{
|
||||
@ -1670,17 +1670,17 @@ void PGPHandler::locked_readPrivateTrustDatabase()
|
||||
std::cerr << " private trust database not found. No trust info loaded." << std::endl ;
|
||||
return ;
|
||||
}
|
||||
std::map<std::string,PGPCertificateInfo>::iterator it ;
|
||||
std::map<RsPgpId,PGPCertificateInfo>::iterator it ;
|
||||
PrivateTrustPacket trustpacket;
|
||||
int n_packets = 0 ;
|
||||
|
||||
while(fread((void*)&trustpacket,sizeof(PrivateTrustPacket),1,fdb) == 1)
|
||||
{
|
||||
it = _public_keyring_map.find(PGPIdType(trustpacket.user_id).toStdString()) ;
|
||||
it = _public_keyring_map.find(RsPgpId(trustpacket.user_id)) ;
|
||||
|
||||
if(it == _public_keyring_map.end())
|
||||
{
|
||||
std::cerr << " (WW) Trust packet found for unknown key id " << PGPIdType(trustpacket.user_id).toStdString() << std::endl;
|
||||
std::cerr << " (WW) Trust packet found for unknown key id " << RsPgpId(trustpacket.user_id).toStdString() << std::endl;
|
||||
continue ;
|
||||
}
|
||||
if(trustpacket.trust_level > 6)
|
||||
@ -1715,9 +1715,9 @@ bool PGPHandler::locked_writePrivateTrustDatabase()
|
||||
}
|
||||
PrivateTrustPacket trustpacket ;
|
||||
|
||||
for(std::map<std::string,PGPCertificateInfo>::iterator it = _public_keyring_map.begin();it!=_public_keyring_map.end() ;++it)
|
||||
for(std::map<RsPgpId,PGPCertificateInfo>::iterator it = _public_keyring_map.begin();it!=_public_keyring_map.end() ;++it)
|
||||
{
|
||||
memcpy(trustpacket.user_id,PGPIdType(it->first).toByteArray(),PGP_KEY_ID_SIZE) ;
|
||||
memcpy(trustpacket.user_id,RsPgpId(it->first).toByteArray(),PGP_KEY_ID_SIZE) ;
|
||||
trustpacket.trust_level = it->second._trustLvl ;
|
||||
trustpacket.time_stamp = it->second._time_stamp ;
|
||||
|
||||
@ -1843,7 +1843,7 @@ bool PGPHandler::locked_syncTrustDatabase()
|
||||
return true ;
|
||||
}
|
||||
void PGPHandler::locked_mergeKeyringFromDisk( ops_keyring_t *keyring,
|
||||
std::map<std::string,PGPCertificateInfo>& kmap,
|
||||
std::map<RsPgpId,PGPCertificateInfo>& kmap,
|
||||
const std::string& keyring_file)
|
||||
{
|
||||
#ifdef DEBUG_PGPHANDLER
|
||||
@ -1869,7 +1869,7 @@ void PGPHandler::locked_mergeKeyringFromDisk( ops_keyring_t *keyring,
|
||||
ops_keyring_free(tmp_keyring) ;
|
||||
}
|
||||
|
||||
bool PGPHandler::removeKeysFromPGPKeyring(const std::list<PGPIdType>& keys_to_remove,std::string& backup_file,uint32_t& error_code)
|
||||
bool PGPHandler::removeKeysFromPGPKeyring(const std::list<RsPgpId>& keys_to_remove,std::string& backup_file,uint32_t& error_code)
|
||||
{
|
||||
// 1 - lock everything.
|
||||
//
|
||||
@ -1878,7 +1878,7 @@ bool PGPHandler::removeKeysFromPGPKeyring(const std::list<PGPIdType>& keys_to_re
|
||||
|
||||
error_code = PGP_KEYRING_REMOVAL_ERROR_NO_ERROR ;
|
||||
|
||||
for(std::list<PGPIdType>::const_iterator it(keys_to_remove.begin());it!=keys_to_remove.end();++it)
|
||||
for(std::list<RsPgpId>::const_iterator it(keys_to_remove.begin());it!=keys_to_remove.end();++it)
|
||||
if(locked_getSecretKey(*it) != NULL)
|
||||
{
|
||||
std::cerr << "(EE) PGPHandler:: can't remove key " << (*it).toStdString() << " since its shared by a secret key! Operation cancelled." << std::endl;
|
||||
@ -1914,7 +1914,7 @@ bool PGPHandler::removeKeysFromPGPKeyring(const std::list<PGPIdType>& keys_to_re
|
||||
|
||||
// Remove keys from the keyring, and update the keyring map.
|
||||
//
|
||||
for(std::list<PGPIdType>::const_iterator it(keys_to_remove.begin());it!=keys_to_remove.end();++it)
|
||||
for(std::list<RsPgpId>::const_iterator it(keys_to_remove.begin());it!=keys_to_remove.end();++it)
|
||||
{
|
||||
if(locked_getSecretKey(*it) != NULL)
|
||||
{
|
||||
@ -1922,7 +1922,7 @@ bool PGPHandler::removeKeysFromPGPKeyring(const std::list<PGPIdType>& keys_to_re
|
||||
continue ;
|
||||
}
|
||||
|
||||
std::map<std::string,PGPCertificateInfo>::iterator res = _public_keyring_map.find((*it).toStdString()) ;
|
||||
std::map<RsPgpId,PGPCertificateInfo>::iterator res = _public_keyring_map.find(*it) ;
|
||||
|
||||
if(res == _public_keyring_map.end())
|
||||
{
|
||||
@ -1930,7 +1930,7 @@ bool PGPHandler::removeKeysFromPGPKeyring(const std::list<PGPIdType>& keys_to_re
|
||||
continue ;
|
||||
}
|
||||
|
||||
if(res->second._key_index >= (unsigned int)_pubring->nkeys || PGPIdType(_pubring->keys[res->second._key_index].key_id) != *it)
|
||||
if(res->second._key_index >= (unsigned int)_pubring->nkeys || RsPgpId(_pubring->keys[res->second._key_index].key_id) != *it)
|
||||
{
|
||||
std::cerr << "(EE) PGPHandler:: can't remove key " << (*it).toStdString() << ". Inconsistency found." << std::endl;
|
||||
error_code = PGP_KEYRING_REMOVAL_ERROR_DATA_INCONSISTENCY ;
|
||||
@ -1952,7 +1952,7 @@ bool PGPHandler::removeKeysFromPGPKeyring(const std::list<PGPIdType>& keys_to_re
|
||||
const ops_keydata_t *keydata ;
|
||||
while( (keydata = ops_keyring_get_key_by_index(_pubring,i)) != NULL )
|
||||
{
|
||||
PGPCertificateInfo& cert(_public_keyring_map[ PGPIdType(keydata->key_id).toStdString() ]) ;
|
||||
PGPCertificateInfo& cert(_public_keyring_map[ RsPgpId(keydata->key_id) ]) ;
|
||||
cert._key_index = i ;
|
||||
++i ;
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <util/rsthreads.h>
|
||||
#include <util/rsid.h>
|
||||
#include <retroshare/rstypes.h>
|
||||
|
||||
extern "C" {
|
||||
#include <openpgpsdk/types.h>
|
||||
@ -27,7 +27,7 @@ class PGPCertificateInfo
|
||||
std::string _email;
|
||||
std::string _comment;
|
||||
|
||||
std::set<std::string> signers;
|
||||
std::set<RsPgpId> signers;
|
||||
|
||||
uint32_t _trustLvl;
|
||||
uint32_t _validLvl;
|
||||
@ -37,7 +37,7 @@ class PGPCertificateInfo
|
||||
mutable time_t _time_stamp ; // last time the key was used (received, used for signature verification, etc)
|
||||
|
||||
PGPFingerprintType _fpr; /* fingerprint */
|
||||
// PGPIdType _key_id ;
|
||||
// RsPgpId _key_id ;
|
||||
|
||||
uint32_t _key_index ; // index to array of keys in the public keyring
|
||||
|
||||
@ -70,68 +70,68 @@ class PGPHandler
|
||||
/**
|
||||
* @param ids list of gpg certificate ids (note, not the actual certificates)
|
||||
*/
|
||||
bool getGPGFilteredList(std::list<PGPIdType>& list,bool (*filter)(const PGPCertificateInfo&) = NULL) const ;
|
||||
bool haveSecretKey(const PGPIdType& id) const ;
|
||||
bool getGPGFilteredList(std::list<RsPgpId>& list,bool (*filter)(const PGPCertificateInfo&) = NULL) const ;
|
||||
bool haveSecretKey(const RsPgpId& id) const ;
|
||||
|
||||
bool importGPGKeyPair(const std::string& filename,PGPIdType& imported_id,std::string& import_error) ;
|
||||
bool exportGPGKeyPair(const std::string& filename,const PGPIdType& exported_id) const ;
|
||||
bool importGPGKeyPair(const std::string& filename,RsPgpId& imported_id,std::string& import_error) ;
|
||||
bool exportGPGKeyPair(const std::string& filename,const RsPgpId& exported_id) const ;
|
||||
|
||||
bool availableGPGCertificatesWithPrivateKeys(std::list<PGPIdType>& ids);
|
||||
bool GeneratePGPCertificate(const std::string& name, const std::string& email, const std::string& passwd, PGPIdType& pgpId, std::string& errString) ;
|
||||
bool availableGPGCertificatesWithPrivateKeys(std::list<RsPgpId>& ids);
|
||||
bool GeneratePGPCertificate(const std::string& name, const std::string& email, const std::string& passwd, RsPgpId& pgpId, std::string& errString) ;
|
||||
|
||||
bool LoadCertificateFromString(const std::string& pem, PGPIdType& gpg_id, std::string& error_string);
|
||||
bool LoadCertificateFromString(const std::string& pem, RsPgpId& gpg_id, std::string& error_string);
|
||||
|
||||
std::string SaveCertificateToString(const PGPIdType& id,bool include_signatures) const ;
|
||||
bool exportPublicKey(const PGPIdType& id,unsigned char *& mem,size_t& mem_size,bool armoured,bool include_signatures) const ;
|
||||
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 SignDataBin(const PGPIdType& id,const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen,bool make_raw_signature=false) ;
|
||||
bool SignDataBin(const RsPgpId& id,const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen,bool make_raw_signature=false) ;
|
||||
bool VerifySignBin(const void *data, uint32_t data_len, unsigned char *sign, unsigned int sign_len, const PGPFingerprintType& withfingerprint) ;
|
||||
bool privateSignCertificate(const PGPIdType& own_id,const PGPIdType& id_of_key_to_sign) ;
|
||||
bool privateSignCertificate(const RsPgpId& own_id,const RsPgpId& id_of_key_to_sign) ;
|
||||
|
||||
// The client should supply a memory chunk to store the data. The length will be updated to the real length of the data.
|
||||
//
|
||||
bool encryptDataBin(const PGPIdType& key_id,const void *data, const uint32_t len, unsigned char *encrypted_data, unsigned int *encrypted_data_len) ;
|
||||
bool decryptDataBin(const PGPIdType& key_id,const void *data, const uint32_t len, unsigned char *decrypted_data, unsigned int *decrypted_data_len) ;
|
||||
bool encryptDataBin(const RsPgpId& key_id,const void *data, const uint32_t len, unsigned char *encrypted_data, unsigned int *encrypted_data_len) ;
|
||||
bool decryptDataBin(const RsPgpId& key_id,const void *data, const uint32_t len, unsigned char *decrypted_data, unsigned int *decrypted_data_len) ;
|
||||
|
||||
bool encryptTextToFile(const PGPIdType& key_id,const std::string& text,const std::string& outfile) ;
|
||||
bool decryptTextFromFile(const PGPIdType& key_id,std::string& text,const std::string& encrypted_inputfile) ;
|
||||
//bool encryptTextToString(const PGPIdType& key_id,const std::string& text,std::string& outstring) ;
|
||||
//bool decryptTextFromString(const PGPIdType& key_id,const std::string& encrypted_text,std::string& outstring) ;
|
||||
bool encryptTextToFile(const RsPgpId& key_id,const std::string& text,const std::string& outfile) ;
|
||||
bool decryptTextFromFile(const RsPgpId& key_id,std::string& text,const std::string& encrypted_inputfile) ;
|
||||
//bool encryptTextToString(const RsPgpId& key_id,const std::string& text,std::string& outstring) ;
|
||||
//bool decryptTextFromString(const RsPgpId& key_id,const std::string& encrypted_text,std::string& outstring) ;
|
||||
|
||||
bool getKeyFingerprint(const PGPIdType& id,PGPFingerprintType& fp) const ;
|
||||
void setAcceptConnexion(const PGPIdType&,bool) ;
|
||||
bool getKeyFingerprint(const RsPgpId& id,PGPFingerprintType& fp) const ;
|
||||
void setAcceptConnexion(const RsPgpId&,bool) ;
|
||||
|
||||
void updateOwnSignatureFlag(const PGPIdType& ownId) ;
|
||||
void updateOwnSignatureFlag(const PGPIdType& pgp_id,const PGPIdType& ownId) ;
|
||||
void updateOwnSignatureFlag(const RsPgpId& ownId) ;
|
||||
void updateOwnSignatureFlag(const RsPgpId& pgp_id,const RsPgpId& ownId) ;
|
||||
|
||||
void locked_updateOwnSignatureFlag(PGPCertificateInfo&, const std::string&, PGPCertificateInfo&, const std::string&) ;
|
||||
void locked_updateOwnSignatureFlag(PGPCertificateInfo&, const RsPgpId&, PGPCertificateInfo&, const RsPgpId&) ;
|
||||
|
||||
// Removes the given keys from the keyring. Also backup the keyring to a file which name is automatically generated
|
||||
// and given pack for proper display.
|
||||
//
|
||||
bool removeKeysFromPGPKeyring(const std::list<PGPIdType>& key_ids,std::string& backup_file,uint32_t& error_code) ;
|
||||
bool removeKeysFromPGPKeyring(const std::list<RsPgpId>& key_ids,std::string& backup_file,uint32_t& error_code) ;
|
||||
|
||||
//bool isKeySupported(const PGPIdType& id) const ;
|
||||
//bool isKeySupported(const RsPgpId& id) const ;
|
||||
|
||||
bool privateTrustCertificate(const PGPIdType& id,int valid_level) ;
|
||||
bool privateTrustCertificate(const RsPgpId& id,int valid_level) ;
|
||||
|
||||
// Write keyring
|
||||
|
||||
//bool writeSecretKeyring() ;
|
||||
//bool writePublicKeyring() ;
|
||||
|
||||
const PGPCertificateInfo *getCertificateInfo(const PGPIdType& id) const ;
|
||||
const PGPCertificateInfo *getCertificateInfo(const RsPgpId& id) const ;
|
||||
|
||||
bool isGPGId(const std::string &id);
|
||||
bool isGPGSigned(const std::string &id);
|
||||
bool isGPGAccepted(const std::string &id);
|
||||
bool isGPGId(const RsPgpId &id);
|
||||
bool isGPGSigned(const RsPgpId &id);
|
||||
bool isGPGAccepted(const RsPgpId &id);
|
||||
|
||||
static void setPassphraseCallback(PassphraseCallback cb) ;
|
||||
static PassphraseCallback passphraseCallback() { return _passphrase_callback ; }
|
||||
|
||||
// Gets info about the key. Who are the signers, what's the owner's name, etc.
|
||||
//
|
||||
bool getGPGDetailsFromBinaryBlock(const unsigned char *mem,size_t mem_size,std::string& key_id, std::string& name, std::list<std::string>& signers) const ;
|
||||
bool getGPGDetailsFromBinaryBlock(const unsigned char *mem,size_t mem_size,RsPgpId& key_id, std::string& name, std::list<RsPgpId>& signers) const ;
|
||||
|
||||
// Debug stuff.
|
||||
virtual bool printKeys() const ;
|
||||
@ -152,8 +152,8 @@ class PGPHandler
|
||||
//
|
||||
bool validateAndUpdateSignatures(PGPCertificateInfo& cert,const ops_keydata_t *keydata) ;
|
||||
|
||||
const ops_keydata_t *locked_getPublicKey(const PGPIdType&,bool stamp_the_key) const;
|
||||
const ops_keydata_t *locked_getSecretKey(const PGPIdType&) const ;
|
||||
const ops_keydata_t *locked_getPublicKey(const RsPgpId&,bool stamp_the_key) const;
|
||||
const ops_keydata_t *locked_getSecretKey(const RsPgpId&) const ;
|
||||
|
||||
void locked_readPrivateTrustDatabase() ;
|
||||
bool locked_writePrivateTrustDatabase() ;
|
||||
@ -161,8 +161,8 @@ class PGPHandler
|
||||
bool locked_syncPublicKeyring() ;
|
||||
bool locked_syncTrustDatabase() ;
|
||||
|
||||
void locked_mergeKeyringFromDisk(ops_keyring_t *keyring, std::map<std::string,PGPCertificateInfo>& kmap, const std::string& keyring_file) ;
|
||||
bool locked_addOrMergeKey(ops_keyring_t *keyring,std::map<std::string,PGPCertificateInfo>& kmap,const ops_keydata_t *keydata) ;
|
||||
void locked_mergeKeyringFromDisk(ops_keyring_t *keyring, std::map<RsPgpId,PGPCertificateInfo>& kmap, const std::string& keyring_file) ;
|
||||
bool locked_addOrMergeKey(ops_keyring_t *keyring,std::map<RsPgpId,PGPCertificateInfo>& kmap,const ops_keydata_t *keydata) ;
|
||||
|
||||
// Members.
|
||||
//
|
||||
@ -171,8 +171,8 @@ class PGPHandler
|
||||
ops_keyring_t *_pubring ;
|
||||
ops_keyring_t *_secring ;
|
||||
|
||||
std::map<std::string,PGPCertificateInfo> _public_keyring_map ; // used for fast access to keys. Gives the index in the keyring.
|
||||
std::map<std::string,PGPCertificateInfo> _secret_keyring_map ;
|
||||
std::map<RsPgpId,PGPCertificateInfo> _public_keyring_map ; // used for fast access to keys. Gives the index in the keyring.
|
||||
std::map<RsPgpId,PGPCertificateInfo> _secret_keyring_map ;
|
||||
|
||||
const std::string _pubring_path ;
|
||||
const std::string _secring_path ;
|
||||
|
@ -154,7 +154,7 @@ RsCertificate::RsCertificate(const RsPeerDetails& Detail, const unsigned char *b
|
||||
if(!Detail.isOnlyGPGdetail)
|
||||
{
|
||||
only_pgp = false ;
|
||||
location_id = SSLIdType( Detail.id ) ;
|
||||
location_id = RsPeerId( Detail.id ) ;
|
||||
location_name = Detail.location ;
|
||||
|
||||
if (Detail.isHiddenNode)
|
||||
@ -203,7 +203,7 @@ RsCertificate::RsCertificate(const RsPeerDetails& Detail, const unsigned char *b
|
||||
only_pgp = true ;
|
||||
hidden_node = false;
|
||||
hidden_node_address = "";
|
||||
location_id = SSLIdType() ;
|
||||
location_id = RsPeerId() ;
|
||||
location_name = "" ;
|
||||
memset(ipv4_internal_ip_and_port,0,6) ;
|
||||
memset(ipv4_external_ip_and_port,0,6) ;
|
||||
@ -304,7 +304,7 @@ bool RsCertificate::initFromString(const std::string& instr,uint32_t& err_code)
|
||||
return false ;
|
||||
}
|
||||
|
||||
location_id = SSLIdType(buf) ;
|
||||
location_id = RsPeerId(buf) ;
|
||||
buf = &buf[s] ;
|
||||
only_pgp = false ;
|
||||
break ;
|
||||
@ -410,19 +410,6 @@ std::string RsCertificate::hidden_node_string() const
|
||||
return empty;
|
||||
}
|
||||
|
||||
std::string RsCertificate::sslid_string() const
|
||||
{
|
||||
if (only_pgp)
|
||||
{
|
||||
std::string empty;
|
||||
return empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
return location_id.toStdString(false);
|
||||
}
|
||||
}
|
||||
|
||||
std::string RsCertificate::ext_ip_string() const
|
||||
{
|
||||
std::ostringstream os ;
|
||||
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <util/rsid.h>
|
||||
#include <retroshare/rstypes.h>
|
||||
|
||||
class RsPeerDetails ;
|
||||
|
||||
@ -30,7 +30,7 @@ class RsCertificate
|
||||
std::string loc_ip_string() const ;
|
||||
std::string location_name_string() const { return location_name; }
|
||||
std::string dns_string() const { return dns_name ; }
|
||||
std::string sslid_string() const;
|
||||
RsPeerId sslid() const { return location_id ; }
|
||||
std::string hidden_node_string() const;
|
||||
|
||||
std::string armouredPGPKey() const ;
|
||||
@ -61,7 +61,7 @@ class RsCertificate
|
||||
size_t binary_pgp_key_size ;
|
||||
|
||||
std::string location_name ;
|
||||
SSLIdType location_id ;
|
||||
RsPeerId location_id ;
|
||||
std::string pgp_version ;
|
||||
std::string dns_name ;
|
||||
std::string hidden_node_address;
|
||||
|
@ -40,7 +40,7 @@ p3LinkMgr *RsPluginManager::_linkmgr = NULL ;
|
||||
typedef RsPlugin *(*RetroSharePluginEntry)(void) ;
|
||||
RsPluginHandler *rsPlugins ;
|
||||
|
||||
RsPluginManager::RsPluginManager(const std::string& hash)
|
||||
RsPluginManager::RsPluginManager(const RsFileHash &hash)
|
||||
: p3Config(CONFIG_TYPE_PLUGINS),_current_executable_hash(hash)
|
||||
{
|
||||
_allow_all_plugins = false ;
|
||||
@ -48,7 +48,7 @@ RsPluginManager::RsPluginManager(const std::string& hash)
|
||||
|
||||
void RsPluginManager::loadConfiguration()
|
||||
{
|
||||
std::string dummyHash = "dummyHash";
|
||||
RsFileHash dummyHash ;
|
||||
p3Config::loadConfiguration(dummyHash);
|
||||
}
|
||||
|
||||
@ -81,9 +81,9 @@ bool RsPluginManager::acceptablePluginName(const std::string& name)
|
||||
#endif
|
||||
}
|
||||
|
||||
void RsPluginManager::disablePlugin(const std::string& hash)
|
||||
void RsPluginManager::disablePlugin(const RsFileHash& hash)
|
||||
{
|
||||
std::set<std::string>::iterator it = _accepted_hashes.find(hash) ;
|
||||
std::set<RsFileHash>::iterator it = _accepted_hashes.find(hash) ;
|
||||
|
||||
if(it != _accepted_hashes.end())
|
||||
{
|
||||
@ -101,7 +101,7 @@ void RsPluginManager::disablePlugin(const std::string& hash)
|
||||
}
|
||||
}
|
||||
|
||||
void RsPluginManager::enablePlugin(const std::string& hash)
|
||||
void RsPluginManager::enablePlugin(const RsFileHash& hash)
|
||||
{
|
||||
if(_accepted_hashes.find(hash) == _accepted_hashes.end())
|
||||
{
|
||||
@ -110,7 +110,7 @@ void RsPluginManager::enablePlugin(const std::string& hash)
|
||||
_accepted_hashes.insert(hash) ;
|
||||
IndicateConfigChanged() ;
|
||||
}
|
||||
std::set<std::string>::const_iterator it(_rejected_hashes.find(hash)) ;
|
||||
std::set<RsFileHash>::const_iterator it(_rejected_hashes.find(hash)) ;
|
||||
|
||||
if(it != _rejected_hashes.end())
|
||||
{
|
||||
@ -183,7 +183,7 @@ void RsPluginManager::stopPlugins()
|
||||
}
|
||||
}
|
||||
|
||||
void RsPluginManager::getPluginStatus(int i,uint32_t& status,std::string& file_name,std::string& hash,uint32_t& svn_revision,std::string& error_string) const
|
||||
void RsPluginManager::getPluginStatus(int i,uint32_t& status,std::string& file_name,RsFileHash &hash,uint32_t& svn_revision,std::string& error_string) const
|
||||
{
|
||||
if((uint32_t)i >= _plugins.size())
|
||||
return ;
|
||||
@ -267,7 +267,7 @@ bool RsPluginManager::loadPlugin(const std::string& plugin_name)
|
||||
if(!_allow_all_plugins)
|
||||
{
|
||||
if(_accepted_hashes.find(pinfo.file_hash) == _accepted_hashes.end() && _rejected_hashes.find(pinfo.file_hash) == _rejected_hashes.end() )
|
||||
if(!RsServer::notify()->askForPluginConfirmation(pinfo.file_name,pinfo.file_hash))
|
||||
if(!RsServer::notify()->askForPluginConfirmation(pinfo.file_name,pinfo.file_hash.toStdString()))
|
||||
_rejected_hashes.insert(pinfo.file_hash) ; // accepted hashes are treated at the end, for security.
|
||||
|
||||
if(_rejected_hashes.find(pinfo.file_hash) != _rejected_hashes.end() )
|
||||
@ -435,11 +435,11 @@ void RsPluginManager::addConfigurations(p3ConfigMgr *ConfigMgr)
|
||||
|
||||
bool RsPluginManager::loadList(std::list<RsItem*>& list)
|
||||
{
|
||||
std::set<std::string> accepted_hash_candidates ;
|
||||
std::set<std::string> rejected_hash_candidates ;
|
||||
std::set<RsFileHash> accepted_hash_candidates ;
|
||||
std::set<RsFileHash> rejected_hash_candidates ;
|
||||
|
||||
std::cerr << "RsPluginManager::loadList(): " << std::endl;
|
||||
std::string reference_executable_hash = "" ;
|
||||
RsFileHash reference_executable_hash ;
|
||||
|
||||
std::list<RsItem *>::iterator it;
|
||||
for(it = list.begin(); it != list.end(); it++)
|
||||
@ -463,12 +463,12 @@ bool RsPluginManager::loadList(std::list<RsItem*>& list)
|
||||
}
|
||||
else if((*kit).key == "ACCEPTED")
|
||||
{
|
||||
accepted_hash_candidates.insert((*kit).value) ;
|
||||
accepted_hash_candidates.insert(RsFileHash((*kit).value)) ;
|
||||
std::cerr << " Accepted hash: " << (*kit).value << std::endl;
|
||||
}
|
||||
else if((*kit).key == "REJECTED")
|
||||
{
|
||||
rejected_hash_candidates.insert((*kit).value) ;
|
||||
rejected_hash_candidates.insert(RsFileHash((*kit).value)) ;
|
||||
std::cerr << " Rejected hash: " << (*kit).value << std::endl;
|
||||
}
|
||||
}
|
||||
@ -501,22 +501,22 @@ bool RsPluginManager::saveList(bool& cleanup, std::list<RsItem*>& list)
|
||||
witem->tlvkvs.pairs.push_back(kv) ;
|
||||
|
||||
kv.key = "REFERENCE_EXECUTABLE_HASH" ;
|
||||
kv.value = _current_executable_hash ;
|
||||
kv.value = _current_executable_hash.toStdString() ;
|
||||
witem->tlvkvs.pairs.push_back(kv) ;
|
||||
|
||||
std::cerr << " Saving current executable hash: " << kv.value << std::endl;
|
||||
|
||||
// now push accepted and rejected hashes.
|
||||
|
||||
for(std::set<std::string>::const_iterator it(_accepted_hashes.begin());it!=_accepted_hashes.end();++it)
|
||||
for(std::set<RsFileHash>::const_iterator it(_accepted_hashes.begin());it!=_accepted_hashes.end();++it)
|
||||
{
|
||||
witem->tlvkvs.pairs.push_back( RsTlvKeyValue( "ACCEPTED", *it ) ) ;
|
||||
witem->tlvkvs.pairs.push_back( RsTlvKeyValue( "ACCEPTED", (*it).toStdString() ) ) ;
|
||||
std::cerr << " " << *it << " : " << "ACCEPTED" << std::endl;
|
||||
}
|
||||
|
||||
for(std::set<std::string>::const_iterator it(_rejected_hashes.begin());it!=_rejected_hashes.end();++it)
|
||||
for(std::set<RsFileHash>::const_iterator it(_rejected_hashes.begin());it!=_rejected_hashes.end();++it)
|
||||
{
|
||||
witem->tlvkvs.pairs.push_back( RsTlvKeyValue( "REJECTED", *it ) ) ;
|
||||
witem->tlvkvs.pairs.push_back( RsTlvKeyValue( "REJECTED", (*it).toStdString() ) ) ;
|
||||
std::cerr << " " << *it << " : " << "REJECTED" << std::endl;
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ class PluginInfo
|
||||
|
||||
// Information related to the file. Do not require the plugin to be loaded nor the DSO to be openned.
|
||||
//
|
||||
std::string file_hash ;
|
||||
RsFileHash file_hash ;
|
||||
std::string file_name ;
|
||||
|
||||
// Information coming from directly loaded symbols. The plugin is responsible for providing them.
|
||||
@ -38,7 +38,7 @@ class PluginInfo
|
||||
class RsPluginManager: public RsPluginHandler, public p3Config
|
||||
{
|
||||
public:
|
||||
RsPluginManager(const std::string& current_executable_sha1_hash) ;
|
||||
RsPluginManager(const RsFileHash& current_executable_sha1_hash) ;
|
||||
virtual ~RsPluginManager() {}
|
||||
|
||||
// ------------ Derived from RsPluginHandler ----------------//
|
||||
@ -46,9 +46,9 @@ class RsPluginManager: public RsPluginHandler, public p3Config
|
||||
virtual int nbPlugins() const { return _plugins.size() ; }
|
||||
virtual RsPlugin *plugin(int i) { return _plugins[i].plugin ; }
|
||||
virtual const std::vector<std::string>& getPluginDirectories() const { return _plugin_directories ; }
|
||||
virtual void getPluginStatus(int i, uint32_t& status,std::string& file_name, std::string& hash,uint32_t& svn_revision,std::string& error_string) const ;
|
||||
virtual void enablePlugin(const std::string& hash) ;
|
||||
virtual void disablePlugin(const std::string& hash) ;
|
||||
virtual void getPluginStatus(int i, uint32_t& status,std::string& file_name, RsFileHash& hash,uint32_t& svn_revision,std::string& error_string) const ;
|
||||
virtual void enablePlugin(const RsFileHash& hash) ;
|
||||
virtual void disablePlugin(const RsFileHash &hash) ;
|
||||
|
||||
virtual void slowTickPlugins(time_t sec) ;
|
||||
virtual const std::string& getLocalCacheDir() const ;
|
||||
@ -101,7 +101,7 @@ class RsPluginManager: public RsPluginHandler, public p3Config
|
||||
private:
|
||||
bool loadPlugin(RsPlugin *) ;
|
||||
bool loadPlugin(const std::string& shared_library_name) ;
|
||||
std::string hashPlugin(const std::string& shared_library_name) ;
|
||||
RsFileHash hashPlugin(const std::string& shared_library_name) ;
|
||||
|
||||
std::vector<PluginInfo> _plugins ;
|
||||
|
||||
@ -114,9 +114,9 @@ class RsPluginManager: public RsPluginHandler, public p3Config
|
||||
// - if different => flush all plugin hashes from cache
|
||||
// - if equal,
|
||||
//
|
||||
std::set<std::string> _accepted_hashes ; // accepted hash values for reference executable hash.
|
||||
std::set<std::string> _rejected_hashes ; // rejected hash values for reference executable hash.
|
||||
std::string _current_executable_hash ; // At all times, the list of accepted plugins should be related to the current hash of the executable.
|
||||
std::set<RsFileHash> _accepted_hashes ; // accepted hash values for reference executable hash.
|
||||
std::set<RsFileHash> _rejected_hashes ; // rejected hash values for reference executable hash.
|
||||
RsFileHash _current_executable_hash ; // At all times, the list of accepted plugins should be related to the current hash of the executable.
|
||||
bool _allow_all_plugins ;
|
||||
|
||||
static std::string _plugin_entry_symbol ;
|
||||
|
@ -61,12 +61,12 @@ bool AuthGPG::decryptTextFromFile(std::string& text,const std::string& inputfile
|
||||
return PGPHandler::decryptTextFromFile(mOwnGpgId,text,inputfile) ;
|
||||
}
|
||||
|
||||
bool AuthGPG::removeKeysFromPGPKeyring(const std::list<std::string>& pgp_ids,std::string& backup_file,uint32_t& error_code)
|
||||
bool AuthGPG::removeKeysFromPGPKeyring(const std::list<RsPgpId>& pgp_ids,std::string& backup_file,uint32_t& error_code)
|
||||
{
|
||||
std::list<PGPIdType> pids ;
|
||||
std::list<RsPgpId> pids ;
|
||||
|
||||
for(std::list<std::string>::const_iterator it(pgp_ids.begin());it!=pgp_ids.end();++it)
|
||||
pids.push_back(PGPIdType(*it)) ;
|
||||
for(std::list<RsPgpId>::const_iterator it(pgp_ids.begin());it!=pgp_ids.end();++it)
|
||||
pids.push_back(RsPgpId(*it)) ;
|
||||
|
||||
return PGPHandler::removeKeysFromPGPKeyring(pids,backup_file,error_code) ;
|
||||
}
|
||||
@ -83,7 +83,7 @@ bool AuthGPG::encryptTextToFile(const std::string& text,const std::string& outfi
|
||||
|
||||
// bool AuthGPG::encryptTextToString(const std::string& pgp_id,const std::string& text,std::string& outstr)
|
||||
// {
|
||||
// return PGPHandler::encryptTextToString(PGPIdType(pgp_id),text,outstr) ;
|
||||
// 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)
|
||||
@ -139,18 +139,18 @@ AuthGPG::AuthGPG(const std::string& path_to_public_keyring,const std::string& pa
|
||||
*
|
||||
* returns false if GnuPG is not available.
|
||||
*/
|
||||
bool AuthGPG::availableGPGCertificatesWithPrivateKeys(std::list<std::string> &ids)
|
||||
{
|
||||
std::list<PGPIdType> pids ;
|
||||
|
||||
PGPHandler::availableGPGCertificatesWithPrivateKeys(pids) ;
|
||||
|
||||
for(std::list<PGPIdType>::const_iterator it(pids.begin());it!=pids.end();++it)
|
||||
ids.push_back( (*it).toStdString() ) ;
|
||||
|
||||
/* return false if there are no private keys */
|
||||
return !ids.empty();
|
||||
}
|
||||
//bool AuthGPG::availableGPGCertificatesWithPrivateKeys(std::list<std::string> &ids)
|
||||
//{
|
||||
// std::list<RsPgpId> pids ;
|
||||
//
|
||||
// PGPHandler::availableGPGCertificatesWithPrivateKeys(pids) ;
|
||||
//
|
||||
// for(std::list<RsPgpId>::const_iterator it(pids.begin());it!=pids.end();++it)
|
||||
// ids.push_back( (*it).toStdString() ) ;
|
||||
//
|
||||
// /* return false if there are no private keys */
|
||||
// return !ids.empty();
|
||||
//}
|
||||
|
||||
/* You can initialise Retroshare with
|
||||
* (a) load existing certificate.
|
||||
@ -159,11 +159,11 @@ bool AuthGPG::availableGPGCertificatesWithPrivateKeys(std::list<std::string> &id
|
||||
* This function must be called successfully (return == 1)
|
||||
* before anything else can be done. (except above fn).
|
||||
*/
|
||||
int AuthGPG::GPGInit(const std::string &ownId)
|
||||
int AuthGPG::GPGInit(const RsPgpId &ownId)
|
||||
{
|
||||
std::cerr << "AuthGPG::GPGInit() called with own gpg id : " << ownId << std::endl;
|
||||
std::cerr << "AuthGPG::GPGInit() called with own gpg id : " << ownId.toStdString() << std::endl;
|
||||
|
||||
mOwnGpgId = PGPIdType(ownId);
|
||||
mOwnGpgId = RsPgpId(ownId);
|
||||
|
||||
//force the validity of the private key. When set to unknown, it caused signature and text encryptions bugs
|
||||
privateTrustCertificate(ownId, 5);
|
||||
@ -263,9 +263,9 @@ void AuthGPG::processServices()
|
||||
std::cerr << "AuthGPGimpl::processServices() Process load operation" << std::endl;
|
||||
#endif
|
||||
std::string error_string ;
|
||||
PGPIdType pgp_id ;
|
||||
RsPgpId pgp_id ;
|
||||
LoadCertificateFromString(loadOrSave->m_certGpg, pgp_id,error_string);
|
||||
loadOrSave->m_certGpgId = pgp_id.toStdString() ;
|
||||
loadOrSave->m_certGpgId = pgp_id;
|
||||
}
|
||||
|
||||
|
||||
@ -312,39 +312,19 @@ bool AuthGPG::DoOwnSignature(const void *data, unsigned int datalen, void *buf_s
|
||||
|
||||
|
||||
/* import to GnuPG and other Certificates */
|
||||
bool AuthGPG::VerifySignature(const void *data, int datalen, const void *sig, unsigned int siglen, const std::string &withfingerprint)
|
||||
bool AuthGPG::VerifySignature(const void *data, int datalen, const void *sig, unsigned int siglen, const PGPFingerprintType& withfingerprint)
|
||||
{
|
||||
if(withfingerprint.length() != 40)
|
||||
{
|
||||
static bool already_reported = false ;
|
||||
|
||||
if( !already_reported)
|
||||
{
|
||||
std::cerr << "AuthGPG::VerifySignature(): no (or dammaged) fingerprint. Nor verifying signature. This is likely to be an unknown peer. fingerprint=\"" << withfingerprint << "\". Not reporting other errors." << std::endl;
|
||||
already_reported = true ;
|
||||
}
|
||||
return false ;
|
||||
}
|
||||
|
||||
return PGPHandler::VerifySignBin((unsigned char*)data,datalen,(unsigned char*)sig,siglen,PGPFingerprintType(withfingerprint)) ;
|
||||
return PGPHandler::VerifySignBin((unsigned char*)data,datalen,(unsigned char*)sig,siglen,withfingerprint) ;
|
||||
}
|
||||
|
||||
bool AuthGPG::exportProfile(const std::string& fname,const std::string& exported_id)
|
||||
bool AuthGPG::exportProfile(const std::string& fname,const RsPgpId& exported_id)
|
||||
{
|
||||
return PGPHandler::exportGPGKeyPair(fname,PGPIdType(exported_id)) ;
|
||||
return PGPHandler::exportGPGKeyPair(fname,exported_id) ;
|
||||
}
|
||||
|
||||
bool AuthGPG::importProfile(const std::string& fname,std::string& imported_id,std::string& import_error)
|
||||
bool AuthGPG::importProfile(const std::string& fname,RsPgpId& imported_id,std::string& import_error)
|
||||
{
|
||||
PGPIdType id ;
|
||||
|
||||
if(PGPHandler::importGPGKeyPair(fname,id,import_error))
|
||||
{
|
||||
imported_id = id.toStdString() ;
|
||||
return true ;
|
||||
}
|
||||
else
|
||||
return false ;
|
||||
return PGPHandler::importGPGKeyPair(fname,imported_id,import_error) ;
|
||||
}
|
||||
|
||||
|
||||
@ -355,35 +335,19 @@ bool AuthGPG::active()
|
||||
return gpgKeySelected;
|
||||
}
|
||||
|
||||
bool AuthGPG::GeneratePGPCertificate(const std::string& name,
|
||||
const std::string& email, const std::string& passwd, std::string &pgpId, std::string& errString)
|
||||
bool AuthGPG::GeneratePGPCertificate(const std::string& name, const std::string& email, const std::string& passwd, RsPgpId& pgpId, std::string& errString)
|
||||
{
|
||||
RsStackMutex stack(gpgMtxEngine); /******* LOCKED ******/
|
||||
|
||||
PGPIdType id ;
|
||||
|
||||
bool res = PGPHandler::GeneratePGPCertificate(name, email, passwd, id, errString) ;
|
||||
|
||||
pgpId = id.toStdString() ;
|
||||
return res ;
|
||||
return PGPHandler::GeneratePGPCertificate(name, email, passwd, pgpId, errString) ;
|
||||
}
|
||||
|
||||
/**** These Two are common */
|
||||
std::string AuthGPG::getGPGName(const std::string &id,bool *success)
|
||||
std::string AuthGPG::getGPGName(const RsPgpId& id,bool *success)
|
||||
{
|
||||
if(id.length() != 16)
|
||||
{
|
||||
static int already = 0 ;
|
||||
if(already < 10)
|
||||
{
|
||||
std::cerr << "Wrong string passed to getGPGDetails: \"" << id << "\"" << std::endl;
|
||||
already++ ;
|
||||
}
|
||||
return std::string() ;
|
||||
}
|
||||
RsStackMutex stack(gpgMtxData); /******* LOCKED ******/
|
||||
|
||||
const PGPCertificateInfo *info = getCertInfoFromStdString(id) ;
|
||||
const PGPCertificateInfo *info = getCertificateInfo(id) ;
|
||||
|
||||
if(info != NULL)
|
||||
{
|
||||
@ -398,10 +362,10 @@ std::string AuthGPG::getGPGName(const std::string &id,bool *success)
|
||||
}
|
||||
|
||||
/**** These Two are common */
|
||||
std::string AuthGPG::getGPGEmail(const std::string &id,bool *success)
|
||||
std::string AuthGPG::getGPGEmail(const RsPgpId& id,bool *success)
|
||||
{
|
||||
RsStackMutex stack(gpgMtxData); /******* LOCKED ******/
|
||||
const PGPCertificateInfo *info = getCertInfoFromStdString(id) ;
|
||||
const PGPCertificateInfo *info = getCertificateInfo(id) ;
|
||||
|
||||
if(info != NULL)
|
||||
{
|
||||
@ -417,26 +381,22 @@ std::string AuthGPG::getGPGEmail(const std::string &id,bool *success)
|
||||
|
||||
/**** GPG versions ***/
|
||||
|
||||
std::string AuthGPG::getGPGOwnId()
|
||||
const RsPgpId& AuthGPG::getGPGOwnId()
|
||||
{
|
||||
RsStackMutex stack(gpgMtxData); /******* LOCKED ******/
|
||||
return mOwnGpgId.toStdString();
|
||||
return mOwnGpgId ;
|
||||
}
|
||||
|
||||
std::string AuthGPG::getGPGOwnName()
|
||||
{
|
||||
return getGPGName(mOwnGpgId.toStdString()) ;
|
||||
return getGPGName(mOwnGpgId) ;
|
||||
}
|
||||
|
||||
bool AuthGPG::getGPGAllList(std::list<std::string> &ids)
|
||||
bool AuthGPG::getGPGAllList(std::list<RsPgpId> &ids)
|
||||
{
|
||||
RsStackMutex stack(gpgMtxData); /******* LOCKED ******/
|
||||
|
||||
std::list<PGPIdType> list ;
|
||||
PGPHandler::getGPGFilteredList(list) ;
|
||||
|
||||
for(std::list<PGPIdType>::const_iterator it(list.begin());it!=list.end();++it)
|
||||
ids.push_back( (*it).toStdString() ) ;
|
||||
PGPHandler::getGPGFilteredList(ids) ;
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -444,7 +404,7 @@ const PGPCertificateInfo *AuthGPG::getCertInfoFromStdString(const std::string& p
|
||||
{
|
||||
try
|
||||
{
|
||||
return PGPHandler::getCertificateInfo(PGPIdType(pgp_id)) ;
|
||||
return PGPHandler::getCertificateInfo(RsPgpId(pgp_id)) ;
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
@ -452,13 +412,13 @@ const PGPCertificateInfo *AuthGPG::getCertInfoFromStdString(const std::string& p
|
||||
return NULL ;
|
||||
}
|
||||
}
|
||||
bool AuthGPG::haveSecretKey(const std::string& id) const
|
||||
bool AuthGPG::haveSecretKey(const RsPgpId& id) const
|
||||
{
|
||||
return PGPHandler::haveSecretKey(PGPIdType(id)) ;
|
||||
return PGPHandler::haveSecretKey(id) ;
|
||||
}
|
||||
bool AuthGPG::isKeySupported(const std::string& id) const
|
||||
bool AuthGPG::isKeySupported(const RsPgpId& id) const
|
||||
{
|
||||
const PGPCertificateInfo *pc = getCertInfoFromStdString(id) ;
|
||||
const PGPCertificateInfo *pc = getCertificateInfo(id) ;
|
||||
|
||||
if(pc == NULL)
|
||||
return false ;
|
||||
@ -466,31 +426,19 @@ bool AuthGPG::isKeySupported(const std::string& id) const
|
||||
return !(pc->_flags & PGPCertificateInfo::PGP_CERTIFICATE_FLAG_UNSUPPORTED_ALGORITHM) ;
|
||||
}
|
||||
|
||||
bool AuthGPG::getGPGDetails(const std::string& id, RsPeerDetails &d)
|
||||
bool AuthGPG::getGPGDetails(const RsPgpId& pgp_id, RsPeerDetails &d)
|
||||
{
|
||||
RsStackMutex stack(gpgMtxData); /******* LOCKED ******/
|
||||
|
||||
if(id.length() != 16)
|
||||
{
|
||||
static int already = 0 ;
|
||||
|
||||
if(already < 10)
|
||||
{
|
||||
std::cerr << "Wrong string passed to getGPGDetails: \"" << id << "\"" << std::endl;
|
||||
++already ;
|
||||
}
|
||||
return false ;
|
||||
}
|
||||
|
||||
const PGPCertificateInfo *pc = getCertInfoFromStdString(id) ;
|
||||
const PGPCertificateInfo *pc = PGPHandler::getCertificateInfo(pgp_id) ;
|
||||
|
||||
if(pc == NULL)
|
||||
return false ;
|
||||
|
||||
const PGPCertificateInfo& cert(*pc) ;
|
||||
|
||||
d.id = id ;
|
||||
d.gpg_id = id ;
|
||||
d.id.clear() ;
|
||||
d.gpg_id = pgp_id ;
|
||||
d.name = cert._name;
|
||||
d.lastUsed = cert._time_stamp;
|
||||
d.email = cert._email;
|
||||
@ -499,55 +447,49 @@ bool AuthGPG::getGPGDetails(const std::string& id, RsPeerDetails &d)
|
||||
d.ownsign = cert._flags & PGPCertificateInfo::PGP_CERTIFICATE_FLAG_HAS_OWN_SIGNATURE;
|
||||
d.gpgSigners.clear() ;
|
||||
|
||||
for(std::set<std::string>::const_iterator it(cert.signers.begin());it!=cert.signers.end();++it)
|
||||
for(std::set<RsPgpId>::const_iterator it(cert.signers.begin());it!=cert.signers.end();++it)
|
||||
d.gpgSigners.push_back( *it ) ;
|
||||
|
||||
d.fpr = cert._fpr.toStdString();
|
||||
d.accept_connection = cert._flags & PGPCertificateInfo::PGP_CERTIFICATE_FLAG_ACCEPT_CONNEXION;
|
||||
d.hasSignedMe = cert._flags & PGPCertificateInfo::PGP_CERTIFICATE_FLAG_HAS_SIGNED_ME;
|
||||
d.fpr = cert._fpr ;
|
||||
d.accept_connection = cert._flags & PGPCertificateInfo::PGP_CERTIFICATE_FLAG_ACCEPT_CONNEXION;
|
||||
d.hasSignedMe = cert._flags & PGPCertificateInfo::PGP_CERTIFICATE_FLAG_HAS_SIGNED_ME;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AuthGPG::getGPGFilteredList(std::list<std::string>& list,bool (*filter)(const PGPCertificateInfo&))
|
||||
bool AuthGPG::getGPGFilteredList(std::list<RsPgpId>& list,bool (*filter)(const PGPCertificateInfo&))
|
||||
{
|
||||
RsStackMutex stack(gpgMtxData); /******* LOCKED ******/
|
||||
std::list<PGPIdType> ids ;
|
||||
|
||||
PGPHandler::getGPGFilteredList(ids,filter) ;
|
||||
|
||||
for(std::list<PGPIdType>::const_iterator it(ids.begin());it!=ids.end();++it)
|
||||
list.push_back( (*it).toStdString() ) ;
|
||||
|
||||
return true ;
|
||||
return PGPHandler::getGPGFilteredList(list,filter) ;
|
||||
}
|
||||
|
||||
static bool filter_Validity(const PGPCertificateInfo& /*info*/) { return true ; } //{ return info._validLvl >= PGPCertificateInfo::GPGME_VALIDITY_MARGINAL ; }
|
||||
static bool filter_Accepted(const PGPCertificateInfo& info) { return info._flags & PGPCertificateInfo::PGP_CERTIFICATE_FLAG_ACCEPT_CONNEXION ; }
|
||||
static bool filter_OwnSigned(const PGPCertificateInfo& info) { return info._flags & PGPCertificateInfo::PGP_CERTIFICATE_FLAG_HAS_OWN_SIGNATURE ; }
|
||||
|
||||
bool AuthGPG::getGPGValidList(std::list<std::string> &ids)
|
||||
bool AuthGPG::getGPGValidList(std::list<RsPgpId> &ids)
|
||||
{
|
||||
return getGPGFilteredList(ids,&filter_Validity);
|
||||
}
|
||||
|
||||
bool AuthGPG::getGPGAcceptedList(std::list<std::string> &ids)
|
||||
bool AuthGPG::getGPGAcceptedList(std::list<RsPgpId> &ids)
|
||||
{
|
||||
return getGPGFilteredList(ids,&filter_Accepted);
|
||||
}
|
||||
|
||||
bool AuthGPG::getGPGSignedList(std::list<std::string> &ids)
|
||||
bool AuthGPG::getGPGSignedList(std::list<RsPgpId> &ids)
|
||||
{
|
||||
return getGPGFilteredList(ids,&filter_OwnSigned);
|
||||
}
|
||||
|
||||
bool AuthGPG::getCachedGPGCertificate(const std::string &id, std::string &certificate)
|
||||
bool AuthGPG::getCachedGPGCertificate(const RsPgpId &id, std::string &certificate)
|
||||
{
|
||||
RsStackMutex stack(gpgMtxData); /******* LOCKED ******/
|
||||
#ifdef LIMIT_CERTIFICATE_SIZE
|
||||
certificate = PGPHandler::SaveCertificateToString(PGPIdType(id),false) ;
|
||||
certificate = PGPHandler::SaveCertificateToString(RsPgpId(id),false) ;
|
||||
#else
|
||||
certificate = PGPHandler::SaveCertificateToString(PGPIdType(id),true) ;
|
||||
certificate = PGPHandler::SaveCertificateToString(RsPgpId(id),true) ;
|
||||
#endif
|
||||
|
||||
// #ifdef LIMIT_CERTIFICATE_SIZE
|
||||
@ -569,31 +511,15 @@ bool AuthGPG::getCachedGPGCertificate(const std::string &id, std::string &certif
|
||||
|
||||
|
||||
/* SKTAN : do not know how to use std::string id */
|
||||
std::string AuthGPG::SaveCertificateToString(const std::string &id,bool include_signatures)
|
||||
{
|
||||
|
||||
if (!isGPGId(id)) {
|
||||
std::cerr << "AuthGPG::SaveCertificateToString() unknown ID" << std::endl;
|
||||
return "";
|
||||
}
|
||||
|
||||
RsStackMutex stack(gpgMtxEngine); /******* LOCKED ******/
|
||||
|
||||
std::string tmp = PGPHandler::SaveCertificateToString(PGPIdType(id),include_signatures) ;
|
||||
|
||||
// // Try to remove signatures manually.
|
||||
// //
|
||||
// std::string cleaned_key ;
|
||||
//
|
||||
// if( (!include_signatures) && PGPKeyManagement::createMinimalKey(tmp,cleaned_key))
|
||||
// return cleaned_key ;
|
||||
// else
|
||||
|
||||
return tmp;
|
||||
}
|
||||
std::string AuthGPG::SaveCertificateToString(const RsPgpId &id,bool include_signatures)
|
||||
{
|
||||
RsStackMutex stack(gpgMtxEngine); /******* LOCKED ******/
|
||||
|
||||
return PGPHandler::SaveCertificateToString(id,include_signatures) ;
|
||||
}
|
||||
|
||||
/* import to GnuPG and other Certificates */
|
||||
bool AuthGPG::LoadCertificateFromString(const std::string &str, PGPIdType& gpg_id,std::string& error_string)
|
||||
bool AuthGPG::LoadCertificateFromString(const std::string &str, RsPgpId& gpg_id,std::string& error_string)
|
||||
{
|
||||
RsStackMutex stack(gpgMtxEngine); /******* LOCKED ******/
|
||||
|
||||
@ -620,7 +546,7 @@ bool AuthGPG::LoadCertificateFromString(const std::string &str, PGPIdType& gpg_i
|
||||
/*************************************/
|
||||
|
||||
/* These take PGP Ids */
|
||||
bool AuthGPG::AllowConnection(const std::string &gpg_id, bool accept)
|
||||
bool AuthGPG::AllowConnection(const RsPgpId& gpg_id, bool accept)
|
||||
{
|
||||
#ifdef GPG_DEBUG
|
||||
std::cerr << "AuthGPG::AllowConnection(" << gpg_id << ")" << std::endl;
|
||||
@ -629,7 +555,7 @@ bool AuthGPG::AllowConnection(const std::string &gpg_id, bool accept)
|
||||
/* Was a "Reload Certificates" here -> be shouldn't be needed -> and very expensive, try without. */
|
||||
{
|
||||
RsStackMutex stack(gpgMtxData);
|
||||
PGPHandler::setAcceptConnexion(PGPIdType(gpg_id),accept) ;
|
||||
PGPHandler::setAcceptConnexion(gpg_id,accept) ;
|
||||
}
|
||||
|
||||
IndicateConfigChanged();
|
||||
@ -640,7 +566,7 @@ bool AuthGPG::AllowConnection(const std::string &gpg_id, bool accept)
|
||||
}
|
||||
|
||||
/* These take PGP Ids */
|
||||
bool AuthGPG::SignCertificateLevel0(const std::string &id)
|
||||
bool AuthGPG::SignCertificateLevel0(const RsPgpId &id)
|
||||
{
|
||||
#ifdef GPG_DEBUG
|
||||
std::cerr << "AuthGPG::SignCertificat(" << id << ")" << std::endl;
|
||||
@ -649,7 +575,7 @@ bool AuthGPG::SignCertificateLevel0(const std::string &id)
|
||||
return privateSignCertificate(id) ;
|
||||
}
|
||||
|
||||
bool AuthGPG::RevokeCertificate(const std::string &id)
|
||||
bool AuthGPG::RevokeCertificate(const RsPgpId &id)
|
||||
{
|
||||
/* remove unused parameter warnings */
|
||||
(void) id;
|
||||
@ -661,7 +587,7 @@ bool AuthGPG::RevokeCertificate(const std::string &id)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AuthGPG::TrustCertificate(const std::string &id, int trustlvl)
|
||||
bool AuthGPG::TrustCertificate(const RsPgpId& id, int trustlvl)
|
||||
{
|
||||
#ifdef GPG_DEBUG
|
||||
std::cerr << "AuthGPG::TrustCertificate(" << id << ", " << trustlvl << ")" << std::endl;
|
||||
@ -669,9 +595,9 @@ bool AuthGPG::TrustCertificate(const std::string &id, int trustlvl)
|
||||
return privateTrustCertificate(id, trustlvl) ;
|
||||
}
|
||||
|
||||
bool AuthGPG::encryptDataBin(const std::string& pgp_id,const void *data, unsigned int datalen, unsigned char *sign, unsigned int *signlen)
|
||||
bool AuthGPG::encryptDataBin(const RsPgpId& pgp_id,const void *data, unsigned int datalen, unsigned char *sign, unsigned int *signlen)
|
||||
{
|
||||
return PGPHandler::encryptDataBin(PGPIdType(pgp_id),data,datalen,sign,signlen) ;
|
||||
return PGPHandler::encryptDataBin(RsPgpId(pgp_id),data,datalen,sign,signlen) ;
|
||||
}
|
||||
|
||||
bool AuthGPG::decryptDataBin(const void *data, unsigned int datalen, unsigned char *sign, unsigned int *signlen)
|
||||
@ -683,31 +609,32 @@ bool AuthGPG::SignDataBin(const void *data, unsigned int datalen, unsigned char
|
||||
return DoOwnSignature(data, datalen, sign, signlen);
|
||||
}
|
||||
|
||||
bool AuthGPG::VerifySignBin(const void *data, uint32_t datalen, unsigned char *sign, unsigned int signlen, const std::string &withfingerprint)
|
||||
bool AuthGPG::VerifySignBin(const void *data, uint32_t datalen, unsigned char *sign, unsigned int signlen, const PGPFingerprintType& withfingerprint)
|
||||
{
|
||||
return VerifySignature(data, datalen, sign, signlen, withfingerprint);
|
||||
}
|
||||
|
||||
/* Sign/Trust stuff */
|
||||
|
||||
int AuthGPG::privateSignCertificate(const std::string &id)
|
||||
int AuthGPG::privateSignCertificate(const RsPgpId &id)
|
||||
{
|
||||
RsStackMutex stack(gpgMtxData); /******* LOCKED ******/
|
||||
|
||||
int ret = PGPHandler::privateSignCertificate(mOwnGpgId,PGPIdType(id)) ;
|
||||
int ret = PGPHandler::privateSignCertificate(mOwnGpgId,id) ;
|
||||
_force_sync_database = true ;
|
||||
return ret ;
|
||||
}
|
||||
|
||||
/* revoke the signature on Certificate */
|
||||
int AuthGPG::privateRevokeCertificate(const std::string &/*id*/)
|
||||
int AuthGPG::privateRevokeCertificate(const RsPgpId &/*id*/)
|
||||
{
|
||||
//RsStackMutex stack(gpgMtx); /******* LOCKED ******/
|
||||
std::cerr << __PRETTY_FUNCTION__ << ": not implemented!" << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AuthGPG::privateTrustCertificate(const std::string &id, int trustlvl)
|
||||
int AuthGPG::privateTrustCertificate(const RsPgpId& id, int trustlvl)
|
||||
{
|
||||
RsStackMutex stack(gpgMtxData); /******* LOCKED ******/
|
||||
|
||||
@ -718,7 +645,7 @@ int AuthGPG::privateTrustCertificate(const std::string &id, int trustlvl)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int res = PGPHandler::privateTrustCertificate(PGPIdType(id),trustlvl) ;
|
||||
int res = PGPHandler::privateTrustCertificate(id,trustlvl) ;
|
||||
_force_sync_database = true ;
|
||||
return res ;
|
||||
}
|
||||
@ -739,7 +666,7 @@ bool AuthGPG::saveList(bool& cleanup, std::list<RsItem*>& lst)
|
||||
#ifdef GPG_DEBUG
|
||||
std::cerr << "AuthGPG::saveList() called" << std::endl ;
|
||||
#endif
|
||||
std::list<std::string> ids ;
|
||||
std::list<RsPgpId> ids ;
|
||||
getGPGAcceptedList(ids) ; // needs to be done before the lock
|
||||
|
||||
RsStackMutex stack(gpgMtxData); /******* LOCKED ******/
|
||||
@ -749,11 +676,11 @@ bool AuthGPG::saveList(bool& cleanup, std::list<RsItem*>& lst)
|
||||
// Now save config for network digging strategies
|
||||
RsConfigKeyValueSet *vitem = new RsConfigKeyValueSet ;
|
||||
|
||||
for (std::list<std::string>::const_iterator it(ids.begin()); it != ids.end(); ++it)
|
||||
if((*it) != mOwnGpgId.toStdString()) // skip our own id.
|
||||
for (std::list<RsPgpId>::const_iterator it(ids.begin()); it != ids.end(); ++it)
|
||||
if((*it) != mOwnGpgId) // skip our own id.
|
||||
{
|
||||
RsTlvKeyValue kv;
|
||||
kv.key = *it ;
|
||||
kv.key = (*it).toStdString() ;
|
||||
#ifdef GPG_DEBUG
|
||||
std::cerr << "AuthGPG::saveList() called (it->second) : " << (it->second) << std::endl ;
|
||||
#endif
|
||||
@ -788,7 +715,7 @@ bool AuthGPG::loadList(std::list<RsItem*>& load)
|
||||
std::list<RsTlvKeyValue>::iterator kit;
|
||||
for(kit = vitem->tlvkvs.pairs.begin(); kit != vitem->tlvkvs.pairs.end(); kit++)
|
||||
if (kit->key != mOwnGpgId.toStdString())
|
||||
PGPHandler::setAcceptConnexion(PGPIdType(kit->key), (kit->value == "TRUE"));
|
||||
PGPHandler::setAcceptConnexion(RsPgpId(kit->key), (kit->value == "TRUE"));
|
||||
}
|
||||
delete (*it);
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ public:
|
||||
class AuthGPGOperationLoadOrSave : public AuthGPGOperation
|
||||
{
|
||||
public:
|
||||
AuthGPGOperationLoadOrSave(bool load, const std::string &gpgId, const std::string &gpgCert, void *userdata)
|
||||
AuthGPGOperationLoadOrSave(bool load, const RsPgpId &gpgId, const std::string &gpgCert, void *userdata)
|
||||
: AuthGPGOperation(userdata)
|
||||
{
|
||||
m_load = load;
|
||||
@ -82,8 +82,8 @@ public:
|
||||
|
||||
public:
|
||||
bool m_load;
|
||||
std::string m_certGpgId; // set for save & load.
|
||||
std::string m_certGpg; // set for load
|
||||
RsPgpId m_certGpgId; // set for save & load.
|
||||
std::string m_certGpg; // set for load
|
||||
};
|
||||
|
||||
class AuthGPGService
|
||||
@ -111,7 +111,7 @@ class AuthGPG: public p3Config, public RsThread, public PGPHandler
|
||||
/**
|
||||
* @param ids list of gpg certificate ids (note, not the actual certificates)
|
||||
*/
|
||||
virtual bool availableGPGCertificatesWithPrivateKeys(std::list<std::string> &ids);
|
||||
//virtual bool availableGPGCertificatesWithPrivateKeys(std::list<RsPgpId> &ids);
|
||||
|
||||
/*********************************************************************************/
|
||||
/************************* STAGE 1 ***********************************************/
|
||||
@ -134,8 +134,8 @@ class AuthGPG: public p3Config, public RsThread, public PGPHandler
|
||||
|
||||
/* Init by generating new Own PGP Cert, or selecting existing PGP Cert */
|
||||
|
||||
virtual int GPGInit(const std::string &ownId);
|
||||
virtual bool GeneratePGPCertificate(const std::string& name, const std::string& email, const std::string& passwd, std::string &pgpId, std::string &errString);
|
||||
virtual int GPGInit(const RsPgpId &ownId);
|
||||
virtual bool GeneratePGPCertificate(const std::string& name, const std::string& email, const std::string& passwd, RsPgpId &pgpId, std::string &errString);
|
||||
|
||||
/*********************************************************************************/
|
||||
/************************* STAGE 3 ***********************************************/
|
||||
@ -148,25 +148,25 @@ class AuthGPG: public p3Config, public RsThread, public PGPHandler
|
||||
* provide access to details in cache list.
|
||||
*
|
||||
****/
|
||||
virtual std::string getGPGName(const std::string &pgp_id,bool *success = NULL);
|
||||
virtual std::string getGPGEmail(const std::string &pgp_id,bool *success = NULL);
|
||||
virtual std::string getGPGName(const RsPgpId &pgp_id,bool *success = NULL);
|
||||
virtual std::string getGPGEmail(const RsPgpId &pgp_id,bool *success = NULL);
|
||||
|
||||
/* PGP web of trust management */
|
||||
virtual std::string getGPGOwnId();
|
||||
virtual const RsPgpId& getGPGOwnId();
|
||||
virtual std::string getGPGOwnName();
|
||||
|
||||
//virtual std::string getGPGOwnEmail();
|
||||
virtual bool isKeySupported(const std::string &id) const ;
|
||||
virtual bool haveSecretKey(const std::string &id) const ;
|
||||
virtual bool getGPGDetails(const std::string &id, RsPeerDetails &d);
|
||||
virtual bool getGPGAllList(std::list<std::string> &ids);
|
||||
virtual bool getGPGValidList(std::list<std::string> &ids);
|
||||
virtual bool getGPGAcceptedList(std::list<std::string> &ids);
|
||||
virtual bool getGPGSignedList(std::list<std::string> &ids);
|
||||
virtual bool importProfile(const std::string& filename,std::string& gpg_id,std::string& import_error) ;
|
||||
virtual bool exportProfile(const std::string& filename,const std::string& gpg_id) ;
|
||||
virtual bool isKeySupported(const RsPgpId &id) const ;
|
||||
virtual bool haveSecretKey(const RsPgpId &id) const ;
|
||||
virtual bool getGPGDetails(const RsPgpId& id, RsPeerDetails &d);
|
||||
virtual bool getGPGAllList(std::list<RsPgpId> &ids);
|
||||
virtual bool getGPGValidList(std::list<RsPgpId> &ids);
|
||||
virtual bool getGPGAcceptedList(std::list<RsPgpId> &ids);
|
||||
virtual bool getGPGSignedList(std::list<RsPgpId> &ids);
|
||||
virtual bool importProfile(const std::string& filename,RsPgpId& gpg_id,std::string& import_error) ;
|
||||
virtual bool exportProfile(const std::string& filename,const RsPgpId& gpg_id) ;
|
||||
|
||||
virtual bool removeKeysFromPGPKeyring(const std::list<std::string>& pgp_ids,std::string& backup_file,uint32_t& error_code) ;
|
||||
virtual bool removeKeysFromPGPKeyring(const std::list<RsPgpId>& pgp_ids,std::string& backup_file,uint32_t& error_code) ;
|
||||
|
||||
/*********************************************************************************/
|
||||
/************************* STAGE 4 ***********************************************/
|
||||
@ -175,11 +175,11 @@ class AuthGPG: public p3Config, public RsThread, public PGPHandler
|
||||
* STAGE 4: Loading and Saving Certificates. (Strings and Files)
|
||||
*
|
||||
****/
|
||||
virtual bool LoadCertificateFromString(const std::string &pem, PGPIdType& gpg_id,std::string& error_string);
|
||||
virtual std::string SaveCertificateToString(const std::string &id,bool include_signatures) ;
|
||||
virtual bool LoadCertificateFromString(const std::string &pem, RsPgpId& gpg_id,std::string& error_string);
|
||||
virtual std::string SaveCertificateToString(const RsPgpId &id,bool include_signatures) ;
|
||||
|
||||
// Cached certificates.
|
||||
bool getCachedGPGCertificate(const std::string &id, std::string &certificate);
|
||||
bool getCachedGPGCertificate(const RsPgpId &id, std::string &certificate);
|
||||
|
||||
/*********************************************************************************/
|
||||
/************************* STAGE 6 ***********************************************/
|
||||
@ -191,12 +191,12 @@ class AuthGPG: public p3Config, public RsThread, public PGPHandler
|
||||
* done in gpgroot already.
|
||||
*
|
||||
****/
|
||||
virtual bool AllowConnection(const std::string &gpg_id, bool accept);
|
||||
virtual bool AllowConnection(const RsPgpId &gpg_id, bool accept);
|
||||
|
||||
virtual bool SignCertificateLevel0(const std::string &id);
|
||||
virtual bool RevokeCertificate(const std::string &id); /* Particularly hard - leave for later */
|
||||
virtual bool SignCertificateLevel0(const RsPgpId &id);
|
||||
virtual bool RevokeCertificate(const RsPgpId &id); /* Particularly hard - leave for later */
|
||||
|
||||
virtual bool TrustCertificate(const std::string &id, int trustlvl); //trustlvl is 2 for none, 3 for marginal and 4 for full trust
|
||||
virtual bool TrustCertificate(const RsPgpId& id, int trustlvl); //trustlvl is 2 for none, 3 for marginal and 4 for full trust
|
||||
|
||||
/*********************************************************************************/
|
||||
/************************* STAGE 7 ***********************************************/
|
||||
@ -208,9 +208,9 @@ class AuthGPG: public p3Config, public RsThread, public PGPHandler
|
||||
*
|
||||
****/
|
||||
virtual bool SignDataBin(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen);
|
||||
virtual bool VerifySignBin(const void*, uint32_t, unsigned char*, unsigned int, const std::string &withfingerprint);
|
||||
virtual bool VerifySignBin(const void*, uint32_t, unsigned char*, unsigned int, const PGPFingerprintType& withfingerprint);
|
||||
|
||||
virtual bool encryptDataBin(const std::string& pgp_id,const void *data, const uint32_t len, unsigned char *encr, unsigned int *encrlen);
|
||||
virtual bool encryptDataBin(const RsPgpId& pgp_id,const void *data, const uint32_t len, unsigned char *encr, unsigned int *encrlen);
|
||||
virtual bool decryptDataBin(const void *data, const uint32_t len, unsigned char *decr, unsigned int *decrlen);
|
||||
|
||||
virtual bool decryptTextFromFile( std::string& text,const std::string& filename);
|
||||
@ -219,7 +219,7 @@ class AuthGPG: public p3Config, public RsThread, public PGPHandler
|
||||
// virtual bool decryptTextFromString( std::string& encrypted_text,std::string& clear_string);
|
||||
// virtual bool encryptTextToString (const std::string& pgp_id,const std::string& clear_text,std::string& encrypted_string);
|
||||
|
||||
bool getGPGFilteredList(std::list<std::string>& list,bool (*filter)(const PGPCertificateInfo&) = NULL) ;
|
||||
bool getGPGFilteredList(std::list<RsPgpId>& list,bool (*filter)(const PGPCertificateInfo&) = NULL) ;
|
||||
|
||||
//END of PGP public functions
|
||||
|
||||
@ -253,12 +253,12 @@ class AuthGPG: public p3Config, public RsThread, public PGPHandler
|
||||
|
||||
/* Internal functions */
|
||||
bool DoOwnSignature(const void *, unsigned int, void *, unsigned int *);
|
||||
bool VerifySignature(const void *data, int datalen, const void *sig, unsigned int siglen, const std::string &withfingerprint);
|
||||
bool VerifySignature(const void *data, int datalen, const void *sig, unsigned int siglen, const PGPFingerprintType& withfingerprint);
|
||||
|
||||
/* Sign/Trust stuff */
|
||||
int privateSignCertificate(const std::string &id);
|
||||
int privateRevokeCertificate(const std::string &id); /* revoke the signature on Certificate */
|
||||
int privateTrustCertificate(const std::string &id, int trustlvl);
|
||||
int privateSignCertificate(const RsPgpId &id);
|
||||
int privateRevokeCertificate(const RsPgpId &id); /* revoke the signature on Certificate */
|
||||
int privateTrustCertificate(const RsPgpId& id, int trustlvl);
|
||||
|
||||
// store all keys in map mKeyList to avoid calling gpgme exe repeatedly
|
||||
//bool storeAllKeys();
|
||||
@ -293,7 +293,7 @@ class AuthGPG: public p3Config, public RsThread, public PGPHandler
|
||||
|
||||
time_t mStoreKeyTime;
|
||||
|
||||
PGPIdType mOwnGpgId;
|
||||
RsPgpId mOwnGpgId;
|
||||
bool gpgKeySelected;
|
||||
bool _force_sync_database ;
|
||||
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include "util/rsstring.h"
|
||||
|
||||
#include "retroshare/rspeers.h" // for RsPeerDetails structure
|
||||
#include "retroshare/rsids.h" // for RsPeerDetails structure
|
||||
#include "rsserver/p3face.h"
|
||||
|
||||
/******************** notify of new Cert **************************/
|
||||
@ -240,7 +241,7 @@ AuthSSL::AuthSSL()
|
||||
static int verify_x509_callback(int preverify_ok, X509_STORE_CTX *ctx);
|
||||
|
||||
|
||||
sslcert::sslcert(X509 *x509, std::string pid)
|
||||
sslcert::sslcert(X509 *x509, const RsPeerId& pid)
|
||||
{
|
||||
certificate = x509;
|
||||
id = pid;
|
||||
@ -249,7 +250,7 @@ sslcert::sslcert(X509 *x509, std::string pid)
|
||||
location = getX509LocString(x509->cert_info->subject);
|
||||
email = "";
|
||||
|
||||
issuer = getX509CNString(x509->cert_info->issuer);
|
||||
issuer = RsPgpId(std::string(getX509CNString(x509->cert_info->issuer)));
|
||||
|
||||
authed = false;
|
||||
}
|
||||
@ -426,7 +427,9 @@ static int initLib = 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!getX509id(x509, mOwnId))
|
||||
RsPeerId mownidstr ;
|
||||
|
||||
if (!getX509id(x509, mownidstr))
|
||||
{
|
||||
std::cerr << "AuthSSLimpl::InitAuth() getX509id() Failed";
|
||||
std::cerr << std::endl;
|
||||
@ -435,6 +438,10 @@ static int initLib = 0;
|
||||
CloseAuth();
|
||||
return -1;
|
||||
}
|
||||
mOwnId = mownidstr ;
|
||||
|
||||
assert(!mOwnId.isNull()) ;
|
||||
|
||||
/* Check that Certificate is Ok ( virtual function )
|
||||
* for gpg/pgp or CA verification
|
||||
*/
|
||||
@ -522,7 +529,7 @@ SSL_CTX *AuthSSLimpl::getCTX()
|
||||
return sslctx;
|
||||
}
|
||||
|
||||
std::string AuthSSLimpl::OwnId()
|
||||
const RsPeerId& AuthSSLimpl::OwnId()
|
||||
{
|
||||
#ifdef AUTHSSL_DEBUG
|
||||
// std::cerr << "AuthSSLimpl::OwnId()" << std::endl;
|
||||
@ -615,7 +622,7 @@ bool AuthSSLimpl::SignDataBin(const void *data, const uint32_t len,
|
||||
|
||||
|
||||
bool AuthSSLimpl::VerifySignBin(const void *data, const uint32_t len,
|
||||
unsigned char *sign, unsigned int signlen, SSL_id sslId)
|
||||
unsigned char *sign, unsigned int signlen, const RsPeerId& sslId)
|
||||
{
|
||||
/* find certificate.
|
||||
* if we don't have - fail.
|
||||
@ -677,7 +684,7 @@ X509 *AuthSSLimpl::SignX509ReqWithGPG(X509_REQ *req, long days)
|
||||
unsigned long chtype = MBSTRING_ASC;
|
||||
X509_NAME *issuer_name = X509_NAME_new();
|
||||
X509_NAME_add_entry_by_txt(issuer_name, "CN", chtype,
|
||||
(unsigned char *) AuthGPG::getAuthGPG()->getGPGOwnId().c_str(), -1, -1, 0);
|
||||
(unsigned char *) AuthGPG::getAuthGPG()->getGPGOwnId().toStdString().c_str(), -1, -1, 0);
|
||||
/****
|
||||
X509_NAME_add_entry_by_NID(issuer_name, 48, 0,
|
||||
(unsigned char *) "email@email.com", -1, -1, 0);
|
||||
@ -687,7 +694,7 @@ X509 *AuthSSLimpl::SignX509ReqWithGPG(X509_REQ *req, long days)
|
||||
(unsigned char *) "loc", -1, -1, 0);
|
||||
****/
|
||||
|
||||
std::cerr << "AuthSSLimpl::SignX509Req() Issuer name: " << AuthGPG::getAuthGPG()->getGPGOwnId() << std::endl;
|
||||
std::cerr << "AuthSSLimpl::SignX509Req() Issuer name: " << AuthGPG::getAuthGPG()->getGPGOwnId().toStdString() << std::endl;
|
||||
|
||||
BIGNUM *btmp = BN_new();
|
||||
if (!BN_pseudo_rand(btmp, SERIAL_RAND_BITS, 0, 0))
|
||||
@ -888,10 +895,10 @@ bool AuthSSLimpl::AuthX509WithGPG(X509 *x509,uint32_t& diagnostic)
|
||||
}
|
||||
|
||||
/* extract CN for peer Id */
|
||||
std::string issuer = getX509CNString(x509->cert_info->issuer);
|
||||
RsPgpId issuer(std::string(getX509CNString(x509->cert_info->issuer)));
|
||||
RsPeerDetails pd;
|
||||
#ifdef AUTHSSL_DEBUG
|
||||
std::cerr << "Checking GPG issuer : " << issuer << std::endl ;
|
||||
std::cerr << "Checking GPG issuer : " << issuer.toStdString() << std::endl ;
|
||||
#endif
|
||||
if (!AuthGPG::getAuthGPG()->getGPGDetails(issuer, pd)) {
|
||||
std::cerr << "AuthSSLimpl::AuthX509() X509 NOT authenticated : AuthGPG::getAuthGPG()->getGPGDetails() returned false." << std::endl;
|
||||
@ -1009,7 +1016,7 @@ err:
|
||||
|
||||
|
||||
/* validate + get id */
|
||||
bool AuthSSLimpl::ValidateCertificate(X509 *x509, std::string &peerId)
|
||||
bool AuthSSLimpl::ValidateCertificate(X509 *x509, RsPeerId &peerId)
|
||||
{
|
||||
uint32_t auth_diagnostic ;
|
||||
|
||||
@ -1022,7 +1029,9 @@ bool AuthSSLimpl::ValidateCertificate(X509 *x509, std::string &peerId)
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
if(!getX509id(x509, peerId))
|
||||
RsPeerId peerIdstr ;
|
||||
|
||||
if(!getX509id(x509, peerIdstr))
|
||||
{
|
||||
#ifdef AUTHSSL_DEBUG
|
||||
std::cerr << "AuthSSLimpl::ValidateCertificate() Cannot retrieve peer id from certificate..";
|
||||
@ -1030,6 +1039,7 @@ bool AuthSSLimpl::ValidateCertificate(X509 *x509, std::string &peerId)
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
peerId = peerIdstr ;
|
||||
|
||||
#ifdef AUTHSSL_DEBUG
|
||||
std::cerr << "AuthSSLimpl::ValidateCertificate() good certificate.";
|
||||
@ -1058,11 +1068,24 @@ static int verify_x509_callback(int preverify_ok, X509_STORE_CTX *ctx)
|
||||
|
||||
if(x509 != NULL)
|
||||
{
|
||||
std::string gpgid = getX509CNString(x509->cert_info->issuer);
|
||||
RsPgpId gpgid (std::string(getX509CNString(x509->cert_info->issuer)));
|
||||
if(gpgid.isNull())
|
||||
{
|
||||
std::cerr << "verify_x509_callback(): wrong PGP id \"" << std::string(getX509CNString(x509->cert_info->issuer)) << "\"" << std::endl;
|
||||
return false ;
|
||||
}
|
||||
|
||||
std::string sslcn = getX509CNString(x509->cert_info->subject);
|
||||
std::string sslid ;
|
||||
RsPeerId sslid ;
|
||||
|
||||
getX509id(x509,sslid);
|
||||
|
||||
if(sslid.isNull())
|
||||
{
|
||||
std::cerr << "verify_x509_callback(): wrong SSL id \"" << std::string(getX509CNString(x509->cert_info->subject)) << "\"" << std::endl;
|
||||
return false ;
|
||||
}
|
||||
|
||||
AuthSSL::getAuthSSL()->setCurrentConnectionAttemptInfo(gpgid,sslid,sslcn) ;
|
||||
}
|
||||
|
||||
@ -1130,7 +1153,7 @@ int AuthSSLimpl::VerifyX509Callback(int preverify_ok, X509_STORE_CTX *ctx)
|
||||
std::cerr << "(WW) Certificate was rejected because authentication failed. Diagnostic = " << auth_diagnostic << std::endl;
|
||||
return false;
|
||||
}
|
||||
std::string pgpid = getX509CNString(X509_STORE_CTX_get_current_cert(ctx)->cert_info->issuer);
|
||||
RsPgpId pgpid = RsPgpId(std::string(getX509CNString(X509_STORE_CTX_get_current_cert(ctx)->cert_info->issuer)));
|
||||
|
||||
if (pgpid != AuthGPG::getAuthGPG()->getGPGOwnId() && !AuthGPG::getAuthGPG()->isGPGAccepted(pgpid))
|
||||
{
|
||||
@ -1157,7 +1180,7 @@ int AuthSSLimpl::VerifyX509Callback(int preverify_ok, X509_STORE_CTX *ctx)
|
||||
if (preverify_ok) {
|
||||
|
||||
//sslcert *cert = NULL;
|
||||
std::string certId;
|
||||
RsPeerId certId;
|
||||
getX509id(X509_STORE_CTX_get_current_cert(ctx), certId);
|
||||
|
||||
}
|
||||
@ -1181,7 +1204,7 @@ int AuthSSLimpl::VerifyX509Callback(int preverify_ok, X509_STORE_CTX *ctx)
|
||||
/********************************************************************************/
|
||||
|
||||
|
||||
bool AuthSSLimpl::encrypt(void *&out, int &outlen, const void *in, int inlen, std::string peerId)
|
||||
bool AuthSSLimpl::encrypt(void *&out, int &outlen, const void *in, int inlen, const RsPeerId& peerId)
|
||||
{
|
||||
RsStackMutex stack(sslMtx); /******* LOCKED ******/
|
||||
|
||||
@ -1377,7 +1400,7 @@ bool AuthSSLimpl::decrypt(void *&out, int &outlen, const void *in, int inlen)
|
||||
/********************************************************************************/
|
||||
/********************************************************************************/
|
||||
|
||||
void AuthSSLimpl::setCurrentConnectionAttemptInfo(const std::string& gpg_id,const std::string& ssl_id,const std::string& ssl_cn)
|
||||
void AuthSSLimpl::setCurrentConnectionAttemptInfo(const RsPgpId& gpg_id,const RsPeerId& ssl_id,const std::string& ssl_cn)
|
||||
{
|
||||
#ifdef AUTHSSL_DEBUG
|
||||
std::cerr << "AuthSSL: registering connection attempt from:" << std::endl;
|
||||
@ -1389,7 +1412,7 @@ void AuthSSLimpl::setCurrentConnectionAttemptInfo(const std::string& gpg_id,cons
|
||||
_last_sslid_to_connect = ssl_id ;
|
||||
_last_sslcn_to_connect = ssl_cn ;
|
||||
}
|
||||
void AuthSSLimpl::getCurrentConnectionAttemptInfo(std::string& gpg_id,std::string& ssl_id,std::string& ssl_cn)
|
||||
void AuthSSLimpl::getCurrentConnectionAttemptInfo(RsPgpId& gpg_id,RsPeerId& ssl_id,std::string& ssl_cn)
|
||||
{
|
||||
gpg_id = _last_gpgid_to_connect ;
|
||||
ssl_id = _last_sslid_to_connect ;
|
||||
@ -1397,8 +1420,8 @@ void AuthSSLimpl::getCurrentConnectionAttemptInfo(std::string& gpg_id,std::strin
|
||||
}
|
||||
|
||||
/* store for discovery */
|
||||
bool AuthSSLimpl::FailedCertificate(X509 *x509, const std::string& gpgid,
|
||||
const std::string& sslid,
|
||||
bool AuthSSLimpl::FailedCertificate(X509 *x509, const RsPgpId& gpgid,
|
||||
const RsPeerId& sslid,
|
||||
const std::string& sslcn,
|
||||
const struct sockaddr_storage& addr,
|
||||
bool incoming)
|
||||
@ -1424,24 +1447,24 @@ bool AuthSSLimpl::FailedCertificate(X509 *x509, const std::string& gpgid,
|
||||
#endif
|
||||
if (incoming)
|
||||
{
|
||||
RsServer::notify()->AddPopupMessage(RS_POPUP_CONNECT_ATTEMPT, gpgid, sslcn, sslid);
|
||||
RsServer::notify()->AddPopupMessage(RS_POPUP_CONNECT_ATTEMPT, gpgid.toStdString(), sslcn, sslid.toStdString());
|
||||
|
||||
switch(auth_diagnostic)
|
||||
{
|
||||
case RS_SSL_HANDSHAKE_DIAGNOSTIC_CERTIFICATE_MISSING: RsServer::notify()->AddFeedItem(RS_FEED_ITEM_SEC_MISSING_CERTIFICATE, gpgid, sslid, sslcn, ip_address);
|
||||
case RS_SSL_HANDSHAKE_DIAGNOSTIC_CERTIFICATE_MISSING: RsServer::notify()->AddFeedItem(RS_FEED_ITEM_SEC_MISSING_CERTIFICATE, gpgid.toStdString(), sslid.toStdString(), sslcn, ip_address);
|
||||
break ;
|
||||
case RS_SSL_HANDSHAKE_DIAGNOSTIC_CERTIFICATE_NOT_VALID: RsServer::notify()->AddFeedItem(RS_FEED_ITEM_SEC_BAD_CERTIFICATE, gpgid, sslid, sslcn, ip_address);
|
||||
case RS_SSL_HANDSHAKE_DIAGNOSTIC_CERTIFICATE_NOT_VALID: RsServer::notify()->AddFeedItem(RS_FEED_ITEM_SEC_BAD_CERTIFICATE, gpgid.toStdString(), sslid.toStdString(), sslcn, ip_address);
|
||||
break ;
|
||||
case RS_SSL_HANDSHAKE_DIAGNOSTIC_ISSUER_UNKNOWN: RsServer::notify()->AddFeedItem(RS_FEED_ITEM_SEC_UNKNOWN_IN , gpgid, sslid, sslcn, ip_address);
|
||||
case RS_SSL_HANDSHAKE_DIAGNOSTIC_ISSUER_UNKNOWN: RsServer::notify()->AddFeedItem(RS_FEED_ITEM_SEC_UNKNOWN_IN , gpgid.toStdString(), sslid.toStdString(), sslcn, ip_address);
|
||||
break ;
|
||||
case RS_SSL_HANDSHAKE_DIAGNOSTIC_MALLOC_ERROR: RsServer::notify()->AddFeedItem(RS_FEED_ITEM_SEC_INTERNAL_ERROR , gpgid, sslid, sslcn, ip_address);
|
||||
case RS_SSL_HANDSHAKE_DIAGNOSTIC_MALLOC_ERROR: RsServer::notify()->AddFeedItem(RS_FEED_ITEM_SEC_INTERNAL_ERROR , gpgid.toStdString(), sslid.toStdString(), sslcn, ip_address);
|
||||
break ;
|
||||
case RS_SSL_HANDSHAKE_DIAGNOSTIC_WRONG_SIGNATURE: RsServer::notify()->AddFeedItem(RS_FEED_ITEM_SEC_WRONG_SIGNATURE, gpgid, sslid, sslcn, ip_address);
|
||||
case RS_SSL_HANDSHAKE_DIAGNOSTIC_WRONG_SIGNATURE: RsServer::notify()->AddFeedItem(RS_FEED_ITEM_SEC_WRONG_SIGNATURE, gpgid.toStdString(), sslid.toStdString(), sslcn, ip_address);
|
||||
break ;
|
||||
case RS_SSL_HANDSHAKE_DIAGNOSTIC_OK:
|
||||
case RS_SSL_HANDSHAKE_DIAGNOSTIC_UNKNOWN:
|
||||
default:
|
||||
RsServer::notify()->AddFeedItem(RS_FEED_ITEM_SEC_CONNECT_ATTEMPT, gpgid, sslid, sslcn, ip_address);
|
||||
RsServer::notify()->AddFeedItem(RS_FEED_ITEM_SEC_CONNECT_ATTEMPT, gpgid.toStdString(), sslid.toStdString(), sslcn, ip_address);
|
||||
}
|
||||
|
||||
#ifdef AUTHSSL_DEBUG
|
||||
@ -1451,9 +1474,9 @@ bool AuthSSLimpl::FailedCertificate(X509 *x509, const std::string& gpgid,
|
||||
else
|
||||
{
|
||||
if(authed)
|
||||
RsServer::notify()->AddFeedItem(RS_FEED_ITEM_SEC_AUTH_DENIED, gpgid, sslid, sslcn, ip_address);
|
||||
RsServer::notify()->AddFeedItem(RS_FEED_ITEM_SEC_AUTH_DENIED, gpgid.toStdString(), sslid.toStdString(), sslcn, ip_address);
|
||||
else
|
||||
RsServer::notify()->AddFeedItem(RS_FEED_ITEM_SEC_UNKNOWN_OUT, gpgid, sslid, sslcn, ip_address);
|
||||
RsServer::notify()->AddFeedItem(RS_FEED_ITEM_SEC_UNKNOWN_OUT, gpgid.toStdString(), sslid.toStdString(), sslcn, ip_address);
|
||||
|
||||
#ifdef AUTHSSL_DEBUG
|
||||
std::cerr << " Outgoing to: ";
|
||||
@ -1468,7 +1491,7 @@ bool AuthSSLimpl::FailedCertificate(X509 *x509, const std::string& gpgid,
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AuthSSLimpl::CheckCertificate(std::string id, X509 *x509)
|
||||
bool AuthSSLimpl::CheckCertificate(const RsPeerId& id, X509 *x509)
|
||||
{
|
||||
(void) id; /* remove unused parameter warning */
|
||||
|
||||
@ -1485,9 +1508,9 @@ bool AuthSSLimpl::CheckCertificate(std::string id, X509 *x509)
|
||||
|
||||
|
||||
/* Locked search -> internal help function */
|
||||
bool AuthSSLimpl::locked_FindCert(std::string id, sslcert **cert)
|
||||
bool AuthSSLimpl::locked_FindCert(const RsPeerId& id, sslcert **cert)
|
||||
{
|
||||
std::map<std::string, sslcert *>::iterator it;
|
||||
std::map<RsPeerId, sslcert *>::iterator it;
|
||||
|
||||
if (mCerts.end() != (it = mCerts.find(id)))
|
||||
{
|
||||
@ -1500,9 +1523,9 @@ bool AuthSSLimpl::locked_FindCert(std::string id, sslcert **cert)
|
||||
|
||||
/* Remove Certificate */
|
||||
|
||||
bool AuthSSLimpl::RemoveX509(std::string id)
|
||||
bool AuthSSLimpl::RemoveX509(RsPeerId id)
|
||||
{
|
||||
std::map<std::string, sslcert *>::iterator it;
|
||||
std::map<RsPeerId, sslcert *>::iterator it;
|
||||
|
||||
RsStackMutex stack(sslMtx); /******* LOCKED ******/
|
||||
|
||||
@ -1526,7 +1549,7 @@ bool AuthSSLimpl::RemoveX509(std::string id)
|
||||
bool AuthSSLimpl::LocalStoreCert(X509* x509)
|
||||
{
|
||||
//store the certificate in the local cert list
|
||||
std::string peerId;
|
||||
RsPeerId peerId ;
|
||||
if(!getX509id(x509, peerId))
|
||||
{
|
||||
std::cerr << "AuthSSLimpl::LocalStoreCert() Cannot retrieve peer id from certificate." << std::endl;
|
||||
@ -1535,6 +1558,12 @@ bool AuthSSLimpl::LocalStoreCert(X509* x509)
|
||||
return false;
|
||||
}
|
||||
|
||||
if(peerId.isNull())
|
||||
{
|
||||
std::cerr << "AuthSSLimpl::LocalStoreCert(): invalid peer id \"" << peerId << "\"" << std::endl;
|
||||
return false ;
|
||||
}
|
||||
|
||||
|
||||
RsStackMutex stack(sslMtx); /******* LOCKED ******/
|
||||
|
||||
@ -1547,7 +1576,7 @@ bool AuthSSLimpl::LocalStoreCert(X509* x509)
|
||||
}
|
||||
|
||||
/* do a search */
|
||||
std::map<std::string, sslcert *>::iterator it;
|
||||
std::map<RsPeerId, sslcert *>::iterator it;
|
||||
|
||||
if (mCerts.end() != (it = mCerts.find(peerId)))
|
||||
{
|
||||
@ -1603,13 +1632,13 @@ bool AuthSSLimpl::saveList(bool& cleanup, std::list<RsItem*>& lst)
|
||||
|
||||
// Now save config for network digging strategies
|
||||
RsConfigKeyValueSet *vitem = new RsConfigKeyValueSet ;
|
||||
std::map<std::string, sslcert*>::iterator mapIt;
|
||||
std::map<RsPeerId, sslcert*>::iterator mapIt;
|
||||
for (mapIt = mCerts.begin(); mapIt != mCerts.end(); mapIt++) {
|
||||
if (mapIt->first == mOwnId) {
|
||||
continue;
|
||||
}
|
||||
RsTlvKeyValue kv;
|
||||
kv.key = mapIt->first;
|
||||
kv.key = mapIt->first.toStdString();
|
||||
#ifdef AUTHSSL_DEBUG
|
||||
std::cerr << "AuthSSLimpl::saveList() called (mapIt->first) : " << (mapIt->first) << std::endl ;
|
||||
#endif
|
||||
@ -1641,7 +1670,7 @@ bool AuthSSLimpl::loadList(std::list<RsItem*>& load)
|
||||
|
||||
std::list<RsTlvKeyValue>::iterator kit;
|
||||
for(kit = vitem->tlvkvs.pairs.begin(); kit != vitem->tlvkvs.pairs.end(); kit++) {
|
||||
if (kit->key == mOwnId) {
|
||||
if (RsPeerId(kit->key) == mOwnId) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -51,8 +51,6 @@
|
||||
#include "pqi/pqinetwork.h"
|
||||
#include "pqi/p3cfgmgr.h"
|
||||
|
||||
typedef std::string SSL_id;
|
||||
|
||||
/* This #define removes Connection Manager references in AuthSSL.
|
||||
* They should not be here. What about Objects and orthogonality?
|
||||
* This code is also stopping immediate reconnections from working.
|
||||
@ -63,20 +61,18 @@ class AuthSSL;
|
||||
class sslcert
|
||||
{
|
||||
public:
|
||||
sslcert(X509* x509, std::string id);
|
||||
sslcert(X509* x509, const RsPeerId& id);
|
||||
sslcert();
|
||||
|
||||
/* certificate parameters */
|
||||
std::string id;
|
||||
RsPeerId id;
|
||||
std::string name;
|
||||
std::string location;
|
||||
std::string org;
|
||||
std::string email;
|
||||
|
||||
std::string issuer;
|
||||
|
||||
std::string fpr;
|
||||
//std::list<std::string> signers;
|
||||
RsPgpId issuer;
|
||||
PGPFingerprintType fpr;
|
||||
|
||||
/* Auth settings */
|
||||
bool authed;
|
||||
@ -106,19 +102,8 @@ virtual bool CloseAuth() = 0;
|
||||
/*********** Overloaded Functions from p3AuthMgr **********/
|
||||
|
||||
/* get Certificate Id */
|
||||
virtual std::string OwnId() = 0;
|
||||
virtual const RsPeerId& OwnId() = 0;
|
||||
virtual std::string getOwnLocation() = 0;
|
||||
//virtual bool getAllList(std::list<std::string> &ids);
|
||||
//virtual bool getAuthenticatedList(std::list<std::string> &ids);
|
||||
//virtual bool getUnknownList(std::list<std::string> &ids);
|
||||
//virtual bool getSSLChildListOfGPGId(std::string gpg_id, std::list<std::string> &ids);
|
||||
|
||||
/* get Details from the Certificates */
|
||||
//virtual bool isAuthenticated(std::string id);
|
||||
//virtual std::string getName(std::string id);
|
||||
//virtual std::string getIssuerName(std::string id);
|
||||
//virtual std::string getGPGId(SSL_id id);
|
||||
//virtual bool getCertDetails(std::string id, sslcert &cert);
|
||||
|
||||
/* Load/Save certificates */
|
||||
virtual std::string SaveOwnCertificateToString() = 0;
|
||||
@ -131,10 +116,10 @@ virtual bool SignDataBin(std::string, unsigned char*, unsigned int*) = 0;
|
||||
virtual bool SignDataBin(const void*, uint32_t, unsigned char*, unsigned int*) = 0;
|
||||
virtual bool VerifyOwnSignBin(const void*, uint32_t, unsigned char*, unsigned int) = 0;
|
||||
virtual bool VerifySignBin(const void *data, const uint32_t len,
|
||||
unsigned char *sign, unsigned int signlen, SSL_id sslId) = 0;
|
||||
unsigned char *sign, unsigned int signlen, const RsPeerId& sslId) = 0;
|
||||
|
||||
// return : false if encrypt failed
|
||||
virtual bool encrypt(void *&out, int &outlen, const void *in, int inlen, std::string peerId) = 0;
|
||||
virtual bool encrypt(void *&out, int &outlen, const void *in, int inlen, const RsPeerId& peerId) = 0;
|
||||
// return : false if decrypt fails
|
||||
virtual bool decrypt(void *&out, int &outlen, const void *in, int inlen) = 0;
|
||||
|
||||
@ -144,17 +129,17 @@ virtual bool AuthX509WithGPG(X509 *x509,uint32_t& auth_diagnostic)=0;
|
||||
|
||||
|
||||
virtual int VerifyX509Callback(int preverify_ok, X509_STORE_CTX *ctx) = 0;
|
||||
virtual bool ValidateCertificate(X509 *x509, std::string &peerId) = 0; /* validate + get id */
|
||||
virtual bool ValidateCertificate(X509 *x509, RsPeerId& peerId) = 0; /* validate + get id */
|
||||
|
||||
public: /* SSL specific functions used in pqissl/pqissllistener */
|
||||
virtual SSL_CTX *getCTX() = 0;
|
||||
|
||||
/* Restored these functions: */
|
||||
virtual void setCurrentConnectionAttemptInfo(const std::string& gpg_id,const std::string& ssl_id,const std::string& ssl_cn) = 0 ;
|
||||
virtual void getCurrentConnectionAttemptInfo( std::string& gpg_id, std::string& ssl_id, std::string& ssl_cn) = 0 ;
|
||||
virtual void setCurrentConnectionAttemptInfo(const RsPgpId& gpg_id,const RsPeerId& ssl_id,const std::string& ssl_cn) = 0 ;
|
||||
virtual void getCurrentConnectionAttemptInfo( RsPgpId& gpg_id, RsPeerId& ssl_id, std::string& ssl_cn) = 0 ;
|
||||
|
||||
virtual bool FailedCertificate(X509 *x509, const std::string& gpgid,const std::string& sslid,const std::string& sslcn,const struct sockaddr_storage &addr, bool incoming) = 0; /* store for discovery */
|
||||
virtual bool CheckCertificate(std::string peerId, X509 *x509) = 0; /* check that they are exact match */
|
||||
virtual bool FailedCertificate(X509 *x509, const RsPgpId& gpgid,const RsPeerId& sslid,const std::string& sslcn,const struct sockaddr_storage &addr, bool incoming) = 0; /* store for discovery */
|
||||
virtual bool CheckCertificate(const RsPeerId& peerId, X509 *x509) = 0; /* check that they are exact match */
|
||||
|
||||
static void setAuthSSL_debug(AuthSSL*) ; // used for debug only. The real function is InitSSL()
|
||||
static AuthSSL *instance_ssl ;
|
||||
@ -177,19 +162,8 @@ virtual bool CloseAuth();
|
||||
/*********** Overloaded Functions from p3AuthMgr **********/
|
||||
|
||||
/* get Certificate Id */
|
||||
virtual std::string OwnId();
|
||||
virtual const RsPeerId& OwnId();
|
||||
virtual std::string getOwnLocation();
|
||||
//virtual bool getAllList(std::list<std::string> &ids);
|
||||
//virtual bool getAuthenticatedList(std::list<std::string> &ids);
|
||||
//virtual bool getUnknownList(std::list<std::string> &ids);
|
||||
//virtual bool getSSLChildListOfGPGId(std::string gpg_id, std::list<std::string> &ids);
|
||||
|
||||
/* get Details from the Certificates */
|
||||
//virtual bool isAuthenticated(std::string id);
|
||||
//virtual std::string getName(std::string id);
|
||||
//virtual std::string getIssuerName(std::string id);
|
||||
//virtual std::string getGPGId(SSL_id id);
|
||||
//virtual bool getCertDetails(std::string id, sslcert &cert);
|
||||
|
||||
/* Load/Save certificates */
|
||||
virtual std::string SaveOwnCertificateToString();
|
||||
@ -202,10 +176,10 @@ virtual bool SignDataBin(std::string, unsigned char*, unsigned int*);
|
||||
virtual bool SignDataBin(const void*, uint32_t, unsigned char*, unsigned int*);
|
||||
virtual bool VerifyOwnSignBin(const void*, uint32_t, unsigned char*, unsigned int);
|
||||
virtual bool VerifySignBin(const void *data, const uint32_t len,
|
||||
unsigned char *sign, unsigned int signlen, SSL_id sslId);
|
||||
unsigned char *sign, unsigned int signlen, const RsPeerId& sslId);
|
||||
|
||||
// return : false if encrypt failed
|
||||
virtual bool encrypt(void *&out, int &outlen, const void *in, int inlen, std::string peerId);
|
||||
virtual bool encrypt(void *&out, int &outlen, const void *in, int inlen, const RsPeerId& peerId);
|
||||
// return : false if decrypt fails
|
||||
virtual bool decrypt(void *&out, int &outlen, const void *in, int inlen);
|
||||
|
||||
@ -215,7 +189,7 @@ virtual bool AuthX509WithGPG(X509 *x509,uint32_t& auth_diagnostic);
|
||||
|
||||
|
||||
virtual int VerifyX509Callback(int preverify_ok, X509_STORE_CTX *ctx);
|
||||
virtual bool ValidateCertificate(X509 *x509, std::string &peerId); /* validate + get id */
|
||||
virtual bool ValidateCertificate(X509 *x509, RsPeerId& peerId); /* validate + get id */
|
||||
|
||||
|
||||
/*****************************************************************/
|
||||
@ -230,24 +204,24 @@ virtual bool ValidateCertificate(X509 *x509, std::string &peerId); /* validate
|
||||
virtual SSL_CTX *getCTX();
|
||||
|
||||
/* Restored these functions: */
|
||||
virtual void setCurrentConnectionAttemptInfo(const std::string& gpg_id,const std::string& ssl_id,const std::string& ssl_cn) ;
|
||||
virtual void getCurrentConnectionAttemptInfo( std::string& gpg_id, std::string& ssl_id, std::string& ssl_cn) ;
|
||||
virtual bool FailedCertificate(X509 *x509, const std::string& gpgid,const std::string& sslid,const std::string& sslcn,const struct sockaddr_storage &addr, bool incoming); /* store for discovery */
|
||||
virtual bool CheckCertificate(std::string peerId, X509 *x509); /* check that they are exact match */
|
||||
virtual void setCurrentConnectionAttemptInfo(const RsPgpId& gpg_id,const RsPeerId& ssl_id,const std::string& ssl_cn) ;
|
||||
virtual void getCurrentConnectionAttemptInfo( RsPgpId& gpg_id, RsPeerId& ssl_id, std::string& ssl_cn) ;
|
||||
virtual bool FailedCertificate(X509 *x509, const RsPgpId& gpgid,const RsPeerId& sslid,const std::string& sslcn,const struct sockaddr_storage &addr, bool incoming); /* store for discovery */
|
||||
virtual bool CheckCertificate(const RsPeerId& peerId, X509 *x509); /* check that they are exact match */
|
||||
|
||||
|
||||
private:
|
||||
|
||||
bool LocalStoreCert(X509* x509);
|
||||
bool RemoveX509(std::string id);
|
||||
bool RemoveX509(const RsPeerId id);
|
||||
|
||||
/*********** LOCKED Functions ******/
|
||||
bool locked_FindCert(std::string id, sslcert **cert);
|
||||
bool locked_FindCert(const RsPeerId& id, sslcert **cert);
|
||||
|
||||
/* Data */
|
||||
/* these variables are constants -> don't need to protect */
|
||||
SSL_CTX *sslctx;
|
||||
std::string mOwnId;
|
||||
RsPeerId mOwnId;
|
||||
sslcert *mOwnCert;
|
||||
|
||||
RsMutex sslMtx; /* protects all below */
|
||||
@ -258,11 +232,11 @@ bool locked_FindCert(std::string id, sslcert **cert);
|
||||
|
||||
int init;
|
||||
|
||||
std::map<std::string, sslcert *> mCerts;
|
||||
std::map<RsPeerId, sslcert *> mCerts;
|
||||
|
||||
std::string _last_gpgid_to_connect ;
|
||||
RsPgpId _last_gpgid_to_connect ;
|
||||
std::string _last_sslcn_to_connect ;
|
||||
std::string _last_sslid_to_connect ;
|
||||
RsPeerId _last_sslid_to_connect ;
|
||||
};
|
||||
|
||||
#endif // MRK_AUTH_SSL_HEADER
|
||||
|
@ -132,7 +132,7 @@ void p3ConfigMgr::loadConfiguration()
|
||||
void p3ConfigMgr::loadConfig()
|
||||
{
|
||||
std::map<uint32_t, pqiConfig *>::iterator cit;
|
||||
std::string dummyHash = "dummyHash";
|
||||
RsFileHash dummyHash ;
|
||||
for (cit = configs.begin(); cit != configs.end(); cit++)
|
||||
{
|
||||
#ifdef CONFIG_DEBUG
|
||||
@ -195,7 +195,7 @@ p3Config::p3Config(uint32_t t)
|
||||
}
|
||||
|
||||
|
||||
bool p3Config::loadConfiguration(std::string &loadHash)
|
||||
bool p3Config::loadConfiguration(RsFileHash &loadHash)
|
||||
{
|
||||
return loadConfig();
|
||||
}
|
||||
@ -278,7 +278,7 @@ bool p3Config::loadAttempt(const std::string& cfgFname,const std::string& signFn
|
||||
uint32_t stream_flags = BIN_FLAGS_READABLE;
|
||||
|
||||
BinEncryptedFileInterface *bio = new BinEncryptedFileInterface(cfgFname.c_str(), bioflags);
|
||||
pqiSSLstore stream(setupSerialiser(), "CONFIG", bio, stream_flags);
|
||||
pqiSSLstore stream(setupSerialiser(), RsPeerId(), bio, stream_flags);
|
||||
|
||||
if(!stream.getEncryptedItems(load))
|
||||
{
|
||||
@ -302,8 +302,8 @@ bool p3Config::loadAttempt(const std::string& cfgFname,const std::string& signFn
|
||||
std::string signatureStored((char *) signbio->memptr(), signbio->memsize());
|
||||
|
||||
std::string signatureRead;
|
||||
std::string strHash(Hash());
|
||||
AuthSSL::getAuthSSL()->SignData(strHash.c_str(), strHash.length(), signatureRead);
|
||||
RsFileHash strHash(Hash());
|
||||
AuthSSL::getAuthSSL()->SignData(strHash.toByteArray(), RsFileHash::SIZE_IN_BYTES, signatureRead);
|
||||
|
||||
delete signbio;
|
||||
|
||||
@ -344,7 +344,7 @@ bool p3Config::saveConfig()
|
||||
stream_flags |= BIN_FLAGS_NO_DELETE;
|
||||
|
||||
BinEncryptedFileInterface *cfg_bio = new BinEncryptedFileInterface(newCfgFname.c_str(), bioflags);
|
||||
pqiSSLstore *stream = new pqiSSLstore(setupSerialiser(), "CONFIG", cfg_bio, stream_flags);
|
||||
pqiSSLstore *stream = new pqiSSLstore(setupSerialiser(), RsPeerId(), cfg_bio, stream_flags);
|
||||
|
||||
written = written && stream->encryptedSendItems(toSave);
|
||||
|
||||
@ -359,8 +359,8 @@ bool p3Config::saveConfig()
|
||||
|
||||
/* sign data */
|
||||
std::string signature;
|
||||
std::string strHash(Hash());
|
||||
AuthSSL::getAuthSSL()->SignData(strHash.c_str(),strHash.length(), signature);
|
||||
RsFileHash strHash(Hash());
|
||||
AuthSSL::getAuthSSL()->SignData(strHash.toByteArray(),strHash.SIZE_IN_BYTES, signature);
|
||||
|
||||
/* write signature to configuration */
|
||||
BinMemInterface *signbio = new BinMemInterface(signature.c_str(),
|
||||
@ -567,7 +567,7 @@ const std::string& pqiConfig::Filename()
|
||||
return filename;
|
||||
}
|
||||
|
||||
const std::string& pqiConfig::Hash()
|
||||
const RsFileHash& pqiConfig::Hash()
|
||||
{
|
||||
RsStackMutex stack(cfgMtx); /***** LOCK STACK MUTEX ****/
|
||||
return hash;
|
||||
@ -591,7 +591,7 @@ void pqiConfig::setFilename(const std::string& name)
|
||||
filename = name;
|
||||
}
|
||||
|
||||
void pqiConfig::setHash(const std::string& h)
|
||||
void pqiConfig::setHash(const RsFileHash& h)
|
||||
{
|
||||
RsStackMutex stack(cfgMtx); /***** LOCK STACK MUTEX ****/
|
||||
hash = h;
|
||||
|
@ -122,7 +122,7 @@ virtual ~pqiConfig();
|
||||
* @param loadHash This is the hash that will be compared to confirm saved configuration has not
|
||||
* been tampered with
|
||||
*/
|
||||
virtual bool loadConfiguration(std::string &loadHash) = 0;
|
||||
virtual bool loadConfiguration(RsFileHash &loadHash) = 0;
|
||||
|
||||
/**
|
||||
* save configuration of object
|
||||
@ -144,7 +144,7 @@ const std::string& Filename();
|
||||
* The hash computed for this configuration, can use this to compare to externally stored hash
|
||||
* for validation checking
|
||||
*/
|
||||
const std::string& Hash();
|
||||
const RsFileHash& Hash();
|
||||
|
||||
protected:
|
||||
|
||||
@ -152,7 +152,7 @@ const std::string& Hash();
|
||||
* Checks if configuration has changed
|
||||
*/
|
||||
virtual void IndicateConfigChanged();
|
||||
void setHash(const std::string& h);
|
||||
void setHash(const RsFileHash& h);
|
||||
|
||||
RsMutex cfgMtx;
|
||||
|
||||
@ -172,7 +172,7 @@ void setHash(const std::string& h);
|
||||
|
||||
uint32_t type;
|
||||
std::string filename;
|
||||
std::string hash;
|
||||
RsFileHash hash;
|
||||
|
||||
|
||||
friend class p3ConfigMgr;
|
||||
@ -268,7 +268,7 @@ class p3Config: public pqiConfig
|
||||
|
||||
p3Config(uint32_t t);
|
||||
|
||||
virtual bool loadConfiguration(std::string &loadHash);
|
||||
virtual bool loadConfiguration(RsFileHash &loadHash);
|
||||
virtual bool saveConfiguration();
|
||||
|
||||
|
||||
|
@ -63,7 +63,7 @@ p3HistoryMgr::~p3HistoryMgr()
|
||||
|
||||
/***** p3HistoryMgr *****/
|
||||
|
||||
void p3HistoryMgr::addMessage(bool incoming, const std::string &chatPeerId, const std::string &peerId, const RsChatMsgItem *chatItem)
|
||||
void p3HistoryMgr::addMessage(bool incoming, const RsPeerId &chatPeerId, const RsPeerId &peerId, const RsChatMsgItem *chatItem)
|
||||
{
|
||||
uint32_t addMsgId = 0;
|
||||
|
||||
@ -78,7 +78,7 @@ void p3HistoryMgr::addMessage(bool incoming, const std::string &chatPeerId, cons
|
||||
{
|
||||
RsStackMutex stack(mHistoryMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
if (mPublicEnable == false && chatPeerId.empty()) {
|
||||
if (mPublicEnable == false && chatPeerId.isNull()) {
|
||||
// public chat not enabled
|
||||
return;
|
||||
}
|
||||
@ -87,12 +87,12 @@ void p3HistoryMgr::addMessage(bool incoming, const std::string &chatPeerId, cons
|
||||
|
||||
if (cli)
|
||||
{
|
||||
if (mLobbyEnable == false && !chatPeerId.empty()) // lobby chat not enabled
|
||||
if (mLobbyEnable == false && !chatPeerId.isNull()) // lobby chat not enabled
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mPrivateEnable == false && !chatPeerId.empty()) // private chat not enabled
|
||||
if (mPrivateEnable == false && !chatPeerId.isNull()) // private chat not enabled
|
||||
return;
|
||||
}
|
||||
|
||||
@ -100,7 +100,7 @@ void p3HistoryMgr::addMessage(bool incoming, const std::string &chatPeerId, cons
|
||||
item->chatPeerId = chatPeerId;
|
||||
item->incoming = incoming;
|
||||
item->peerId = peerId;
|
||||
item->peerName = cli ? cli->nick : rsPeers->getPeerName(item->peerId);
|
||||
item->peerName = cli ? cli->nick : rsPeers->getPeerName(RsPeerId(item->peerId));
|
||||
item->sendTime = chatItem->sendTime;
|
||||
item->recvTime = chatItem->recvTime;
|
||||
|
||||
@ -112,7 +112,7 @@ void p3HistoryMgr::addMessage(bool incoming, const std::string &chatPeerId, cons
|
||||
item->message = chatItem->message ;
|
||||
//librs::util::ConvertUtf16ToUtf8(chatItem->message, item->message);
|
||||
|
||||
std::map<std::string, std::map<uint32_t, RsHistoryMsgItem*> >::iterator mit = mMessages.find(item->chatPeerId);
|
||||
std::map<RsPeerId, std::map<uint32_t, RsHistoryMsgItem*> >::iterator mit = mMessages.find(item->chatPeerId);
|
||||
if (mit != mMessages.end()) {
|
||||
item->msgId = nextMsgId++;
|
||||
mit->second.insert(std::make_pair(item->msgId, item));
|
||||
@ -120,7 +120,7 @@ void p3HistoryMgr::addMessage(bool incoming, const std::string &chatPeerId, cons
|
||||
|
||||
// check the limit
|
||||
uint32_t limit;
|
||||
if (chatPeerId.empty())
|
||||
if (chatPeerId.isNull())
|
||||
limit = mPublicSaveCount;
|
||||
else if (cli)
|
||||
limit = mLobbySaveCount;
|
||||
@ -159,7 +159,7 @@ void p3HistoryMgr::cleanOldMessages()
|
||||
time_t now = time(NULL) ;
|
||||
bool changed = false ;
|
||||
|
||||
for(std::map<std::string, std::map<uint32_t, RsHistoryMsgItem*> >::iterator mit = mMessages.begin(); mit != mMessages.end();)
|
||||
for(std::map<RsPeerId, std::map<uint32_t, RsHistoryMsgItem*> >::iterator mit = mMessages.begin(); mit != mMessages.end();)
|
||||
{
|
||||
if (mMaxStorageDurationSeconds > 0)
|
||||
{
|
||||
@ -183,7 +183,7 @@ void p3HistoryMgr::cleanOldMessages()
|
||||
|
||||
if(mit->second.empty())
|
||||
{
|
||||
std::map<std::string, std::map<uint32_t, RsHistoryMsgItem*> >::iterator mit2 = mit ;
|
||||
std::map<RsPeerId, std::map<uint32_t, RsHistoryMsgItem*> >::iterator mit2 = mit ;
|
||||
++mit2 ;
|
||||
std::cerr << " removing peer id " << mit->first << ", since it has no messages" << std::endl;
|
||||
mMessages.erase(mit) ;
|
||||
@ -216,7 +216,7 @@ bool p3HistoryMgr::saveList(bool& cleanup, std::list<RsItem*>& saveData)
|
||||
|
||||
mHistoryMtx.lock(); /********** STACK LOCKED MTX ******/
|
||||
|
||||
std::map<std::string, std::map<uint32_t, RsHistoryMsgItem*> >::iterator mit;
|
||||
std::map<RsPeerId, std::map<uint32_t, RsHistoryMsgItem*> >::iterator mit;
|
||||
std::map<uint32_t, RsHistoryMsgItem*>::iterator lit;
|
||||
for (mit = mMessages.begin(); mit != mMessages.end(); mit++) {
|
||||
for (lit = mit->second.begin(); lit != mit->second.end(); lit++) {
|
||||
@ -287,7 +287,7 @@ bool p3HistoryMgr::loadList(std::list<RsItem*>& load)
|
||||
for (it = load.begin(); it != load.end(); it++) {
|
||||
if (NULL != (msgItem = dynamic_cast<RsHistoryMsgItem*>(*it))) {
|
||||
|
||||
std::map<std::string, std::map<uint32_t, RsHistoryMsgItem*> >::iterator mit = mMessages.find(msgItem->chatPeerId);
|
||||
std::map<RsPeerId, std::map<uint32_t, RsHistoryMsgItem*> >::iterator mit = mMessages.find(msgItem->chatPeerId);
|
||||
msgItem->msgId = nextMsgId++;
|
||||
|
||||
std::cerr << "Loading msg history item: peer id=" << msgItem->chatPeerId << "), msg id =" << msgItem->msgId << std::endl;
|
||||
@ -371,7 +371,7 @@ static void convertMsg(const RsHistoryMsgItem* item, HistoryMsg &msg)
|
||||
msg.message = item->message;
|
||||
}
|
||||
|
||||
bool p3HistoryMgr::getMessages(const std::string &chatPeerId, std::list<HistoryMsg> &msgs, uint32_t loadCount)
|
||||
bool p3HistoryMgr::getMessages(const RsPeerId &chatPeerId, std::list<HistoryMsg> &msgs, uint32_t loadCount)
|
||||
{
|
||||
msgs.clear();
|
||||
|
||||
@ -379,20 +379,20 @@ bool p3HistoryMgr::getMessages(const std::string &chatPeerId, std::list<HistoryM
|
||||
|
||||
std::cerr << "Getting history for peer " << chatPeerId << std::endl;
|
||||
|
||||
if (mPublicEnable == false && chatPeerId.empty()) { // chatPeerId.empty() means it's public chat
|
||||
if (mPublicEnable == false && chatPeerId.isNull()) { // chatPeerId.empty() means it's public chat
|
||||
// public chat not enabled
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mPrivateEnable == false && chatPeerId.empty() == false) // private chat not enabled
|
||||
if (mPrivateEnable == false && chatPeerId.isNull() == false) // private chat not enabled
|
||||
return false;
|
||||
|
||||
if (mLobbyEnable == false && chatPeerId.empty() == false) // private chat not enabled
|
||||
if (mLobbyEnable == false && chatPeerId.isNull() == false) // private chat not enabled
|
||||
return false;
|
||||
|
||||
uint32_t foundCount = 0;
|
||||
|
||||
std::map<std::string, std::map<uint32_t, RsHistoryMsgItem*> >::iterator mit = mMessages.find(chatPeerId);
|
||||
std::map<RsPeerId, std::map<uint32_t, RsHistoryMsgItem*> >::iterator mit = mMessages.find(chatPeerId);
|
||||
|
||||
if (mit != mMessages.end())
|
||||
{
|
||||
@ -418,7 +418,7 @@ bool p3HistoryMgr::getMessage(uint32_t msgId, HistoryMsg &msg)
|
||||
{
|
||||
RsStackMutex stack(mHistoryMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
std::map<std::string, std::map<uint32_t, RsHistoryMsgItem*> >::iterator mit;
|
||||
std::map<RsPeerId, std::map<uint32_t, RsHistoryMsgItem*> >::iterator mit;
|
||||
for (mit = mMessages.begin(); mit != mMessages.end(); mit++) {
|
||||
std::map<uint32_t, RsHistoryMsgItem*>::iterator lit = mit->second.find(msgId);
|
||||
if (lit != mit->second.end()) {
|
||||
@ -430,14 +430,14 @@ bool p3HistoryMgr::getMessage(uint32_t msgId, HistoryMsg &msg)
|
||||
return false;
|
||||
}
|
||||
|
||||
void p3HistoryMgr::clear(const std::string &chatPeerId)
|
||||
void p3HistoryMgr::clear(const RsPeerId &chatPeerId)
|
||||
{
|
||||
{
|
||||
RsStackMutex stack(mHistoryMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
std::cerr << "********** p3History::clear()called for peer id " << chatPeerId << std::endl;
|
||||
|
||||
std::map<std::string, std::map<uint32_t, RsHistoryMsgItem*> >::iterator mit = mMessages.find(chatPeerId);
|
||||
std::map<RsPeerId, std::map<uint32_t, RsHistoryMsgItem*> >::iterator mit = mMessages.find(chatPeerId);
|
||||
if (mit == mMessages.end()) {
|
||||
return;
|
||||
}
|
||||
@ -465,7 +465,7 @@ void p3HistoryMgr::removeMessages(const std::list<uint32_t> &msgIds)
|
||||
{
|
||||
RsStackMutex stack(mHistoryMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
std::map<std::string, std::map<uint32_t, RsHistoryMsgItem*> >::iterator mit;
|
||||
std::map<RsPeerId, std::map<uint32_t, RsHistoryMsgItem*> >::iterator mit;
|
||||
for (mit = mMessages.begin(); mit != mMessages.end(); ++mit) {
|
||||
iit = ids.begin();
|
||||
while (iit != ids.end()) {
|
||||
|
@ -48,13 +48,13 @@ public:
|
||||
|
||||
/******** p3HistoryMgr *********/
|
||||
|
||||
void addMessage(bool incoming, const std::string &chatPeerId, const std::string &peerId, const RsChatMsgItem *chatItem);
|
||||
void addMessage(bool incoming, const RsPeerId &chatPeerId, const RsPeerId &peerId, const RsChatMsgItem *chatItem);
|
||||
|
||||
/********* RsHistory ***********/
|
||||
|
||||
bool getMessages(const std::string &chatPeerId, std::list<HistoryMsg> &msgs, uint32_t loadCount);
|
||||
bool getMessages(const RsPeerId &chatPeerId, std::list<HistoryMsg> &msgs, uint32_t loadCount);
|
||||
bool getMessage(uint32_t msgId, HistoryMsg &msg);
|
||||
void clear(const std::string &chatPeerId);
|
||||
void clear(const RsPeerId &chatPeerId);
|
||||
void removeMessages(const std::list<uint32_t> &msgIds);
|
||||
|
||||
virtual bool getEnable(uint32_t chat_type);
|
||||
@ -73,7 +73,7 @@ public:
|
||||
|
||||
private:
|
||||
uint32_t nextMsgId;
|
||||
std::map<std::string, std::map<uint32_t, RsHistoryMsgItem*> > mMessages;
|
||||
std::map<RsPeerId, std::map<uint32_t, RsHistoryMsgItem*> > mMessages;
|
||||
|
||||
// Removes messages stored for more than mMaxMsgStorageDurationSeconds seconds.
|
||||
// This avoids the stored list to grow crazy with time.
|
||||
|
@ -102,8 +102,7 @@ peerAddrInfo::peerAddrInfo()
|
||||
}
|
||||
|
||||
peerConnectState::peerConnectState()
|
||||
:id("unknown"),
|
||||
connecttype(0),
|
||||
: connecttype(0),
|
||||
lastavailable(0),
|
||||
lastattempt(0),
|
||||
name(""),
|
||||
@ -120,7 +119,7 @@ peerConnectState::peerConnectState()
|
||||
|
||||
std::string textPeerConnectState(peerConnectState &state)
|
||||
{
|
||||
return "Id: " + state.id + "\n";
|
||||
return "Id: " + state.id.toStdString() + "\n";
|
||||
}
|
||||
|
||||
/*********
|
||||
@ -182,11 +181,11 @@ bool p3LinkMgrIMPL::getLocalAddress(struct sockaddr_storage &addr)
|
||||
}
|
||||
|
||||
|
||||
bool p3LinkMgrIMPL::isOnline(const std::string &ssl_id)
|
||||
bool p3LinkMgrIMPL::isOnline(const RsPeerId &ssl_id)
|
||||
{
|
||||
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
std::map<std::string, peerConnectState>::iterator it;
|
||||
std::map<RsPeerId, peerConnectState>::iterator it;
|
||||
it = mFriendList.find(ssl_id);
|
||||
if (it == mFriendList.end())
|
||||
{
|
||||
@ -202,11 +201,11 @@ bool p3LinkMgrIMPL::isOnline(const std::string &ssl_id)
|
||||
|
||||
|
||||
|
||||
uint32_t p3LinkMgrIMPL::getLinkType(const std::string &ssl_id)
|
||||
uint32_t p3LinkMgrIMPL::getLinkType(const RsPeerId &ssl_id)
|
||||
{
|
||||
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
std::map<std::string, peerConnectState>::iterator it;
|
||||
std::map<RsPeerId, peerConnectState>::iterator it;
|
||||
it = mFriendList.find(ssl_id);
|
||||
if (it == mFriendList.end())
|
||||
{
|
||||
@ -222,11 +221,11 @@ uint32_t p3LinkMgrIMPL::getLinkType(const std::string &ssl_id)
|
||||
|
||||
|
||||
|
||||
void p3LinkMgrIMPL::getOnlineList(std::list<std::string> &ssl_peers)
|
||||
void p3LinkMgrIMPL::getOnlineList(std::list<RsPeerId> &ssl_peers)
|
||||
{
|
||||
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
std::map<std::string, peerConnectState>::iterator it;
|
||||
std::map<RsPeerId, peerConnectState>::iterator it;
|
||||
for(it = mFriendList.begin(); it != mFriendList.end(); it++)
|
||||
{
|
||||
if (it->second.state & RS_PEER_S_CONNECTED)
|
||||
@ -237,11 +236,11 @@ void p3LinkMgrIMPL::getOnlineList(std::list<std::string> &ssl_peers)
|
||||
return;
|
||||
}
|
||||
|
||||
void p3LinkMgrIMPL::getFriendList(std::list<std::string> &ssl_peers)
|
||||
void p3LinkMgrIMPL::getFriendList(std::list<RsPeerId> &ssl_peers)
|
||||
{
|
||||
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
std::map<std::string, peerConnectState>::iterator it;
|
||||
std::map<RsPeerId, peerConnectState>::iterator it;
|
||||
for(it = mFriendList.begin(); it != mFriendList.end(); it++)
|
||||
{
|
||||
ssl_peers.push_back(it->first);
|
||||
@ -249,17 +248,17 @@ void p3LinkMgrIMPL::getFriendList(std::list<std::string> &ssl_peers)
|
||||
return;
|
||||
}
|
||||
|
||||
bool p3LinkMgrIMPL::getPeerName(const std::string &ssl_id, std::string &name)
|
||||
bool p3LinkMgrIMPL::getPeerName(const RsPeerId &ssl_id, std::string &name)
|
||||
{
|
||||
return mPeerMgr->getPeerName(ssl_id, name);
|
||||
}
|
||||
|
||||
|
||||
bool p3LinkMgrIMPL::getFriendNetStatus(const std::string &id, peerConnectState &state)
|
||||
bool p3LinkMgrIMPL::getFriendNetStatus(const RsPeerId &id, peerConnectState &state)
|
||||
{
|
||||
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
std::map<std::string, peerConnectState>::iterator it;
|
||||
std::map<RsPeerId, peerConnectState>::iterator it;
|
||||
it = mFriendList.find(id);
|
||||
if (it == mFriendList.end())
|
||||
{
|
||||
@ -273,13 +272,13 @@ bool p3LinkMgrIMPL::getFriendNetStatus(const std::string &id, peerConnectStat
|
||||
|
||||
|
||||
|
||||
void p3LinkMgrIMPL::setFriendVisibility(const std::string &id, bool isVisible)
|
||||
void p3LinkMgrIMPL::setFriendVisibility(const RsPeerId &id, bool isVisible)
|
||||
{
|
||||
/* set visibility */
|
||||
{
|
||||
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
std::map<std::string, peerConnectState>::iterator it;
|
||||
std::map<RsPeerId, peerConnectState>::iterator it;
|
||||
it = mFriendList.find(id);
|
||||
if (it == mFriendList.end())
|
||||
{
|
||||
@ -327,8 +326,8 @@ void p3LinkMgrIMPL::statusTick()
|
||||
#ifdef LINKMGR_DEBUG_TICK
|
||||
std::cerr << "p3LinkMgrIMPL::statusTick()" << std::endl;
|
||||
#endif
|
||||
std::list<std::string> retryIds;
|
||||
std::list<std::string>::iterator it2;
|
||||
std::list<RsPeerId> retryIds;
|
||||
std::list<RsPeerId>::iterator it2;
|
||||
//std::list<std::string> dummyToRemove;
|
||||
|
||||
{
|
||||
@ -337,7 +336,7 @@ void p3LinkMgrIMPL::statusTick()
|
||||
time_t retry = now - mRetryPeriod;
|
||||
|
||||
RsStackMutex stack(mLinkMtx); /****** LOCK MUTEX ******/
|
||||
std::map<std::string, peerConnectState>::iterator it;
|
||||
std::map<RsPeerId, peerConnectState>::iterator it;
|
||||
for(it = mFriendList.begin(); it != mFriendList.end(); it++)
|
||||
{
|
||||
if (it->second.state & RS_PEER_S_CONNECTED)
|
||||
@ -421,7 +420,7 @@ void p3LinkMgrIMPL::tickMonitors()
|
||||
{
|
||||
bool doStatusChange = false;
|
||||
std::list<pqipeer> actionList;
|
||||
std::map<std::string, peerConnectState>::iterator it;
|
||||
std::map<RsPeerId, peerConnectState>::iterator it;
|
||||
|
||||
{
|
||||
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
||||
@ -449,7 +448,7 @@ void p3LinkMgrIMPL::tickMonitors()
|
||||
actionList.push_back(peer);
|
||||
|
||||
#ifdef LINKMGR_DEBUG_ACTIONS
|
||||
std::cerr << "Friend: " << peer.name << " Id: " << peer.id << " State: " << peer.state;
|
||||
std::cerr << "Friend: " << peer.name << " Id: " << peer.id.toStdString() << " State: " << peer.state;
|
||||
if (peer.state & RS_PEER_S_FRIEND)
|
||||
std::cerr << " S:RS_PEER_S_FRIEND";
|
||||
if (peer.state & RS_PEER_S_ONLINE)
|
||||
@ -477,8 +476,8 @@ void p3LinkMgrIMPL::tickMonitors()
|
||||
p3Notify *notify = RsServer::notify();
|
||||
if (notify)
|
||||
{
|
||||
notify->AddPopupMessage(RS_POPUP_CONNECT, peer.id,"", "Online: ");
|
||||
notify->AddFeedItem(RS_FEED_ITEM_PEER_CONNECT, peer.id, "", "");
|
||||
notify->AddPopupMessage(RS_POPUP_CONNECT, peer.id.toStdString(),"", "Online: ");
|
||||
notify->AddFeedItem(RS_FEED_ITEM_PEER_CONNECT, peer.id.toStdString(), "", "");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -500,7 +499,7 @@ void p3LinkMgrIMPL::tickMonitors()
|
||||
it->second.actions = 0;
|
||||
|
||||
#ifdef LINKMGR_DEBUG_ACTIONS
|
||||
std::cerr << "Other: " << peer.name << " Id: " << peer.id << " State: " << peer.state;
|
||||
std::cerr << "Other: " << peer.name << " Id: " << peer.id.toStdString() << " State: " << peer.state;
|
||||
if (peer.state & RS_PEER_S_FRIEND)
|
||||
std::cerr << " S:RS_PEER_S_FRIEND";
|
||||
if (peer.state & RS_PEER_S_ONLINE)
|
||||
@ -576,13 +575,13 @@ void p3LinkMgrIMPL::tickMonitors()
|
||||
}
|
||||
|
||||
|
||||
const std::string p3LinkMgrIMPL::getOwnId()
|
||||
const RsPeerId& p3LinkMgrIMPL::getOwnId()
|
||||
{
|
||||
return AuthSSL::getAuthSSL()->OwnId();
|
||||
return AuthSSL::getAuthSSL()->OwnId();
|
||||
}
|
||||
|
||||
|
||||
bool p3LinkMgrIMPL::connectAttempt(const std::string &id, struct sockaddr_storage &raddr,
|
||||
bool p3LinkMgrIMPL::connectAttempt(const RsPeerId &id, struct sockaddr_storage &raddr,
|
||||
struct sockaddr_storage &proxyaddr,
|
||||
struct sockaddr_storage &srcaddr,
|
||||
uint32_t &delay, uint32_t &period, uint32_t &type, uint32_t &flags, uint32_t &bandwidth,
|
||||
@ -592,7 +591,7 @@ bool p3LinkMgrIMPL::connectAttempt(const std::string &id, struct sockaddr_storag
|
||||
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
/* check for existing */
|
||||
std::map<std::string, peerConnectState>::iterator it;
|
||||
std::map<RsPeerId, peerConnectState>::iterator it;
|
||||
it = mFriendList.find(id);
|
||||
if (it == mFriendList.end())
|
||||
{
|
||||
@ -623,7 +622,7 @@ bool p3LinkMgrIMPL::connectAttempt(const std::string &id, struct sockaddr_storag
|
||||
|
||||
}
|
||||
|
||||
rslog(RSL_WARNING, p3connectzone, "p3LinkMgrIMPL::connectAttempt() called id: " + id);
|
||||
rslog(RSL_WARNING, p3connectzone, "p3LinkMgrIMPL::connectAttempt() called id: " + id.toStdString());
|
||||
|
||||
it->second.lastattempt = time(NULL);
|
||||
it->second.inConnAttempt = true;
|
||||
@ -774,7 +773,7 @@ bool p3LinkMgrIMPL::connectAttempt(const std::string &id, struct sockaddr_storag
|
||||
*
|
||||
*/
|
||||
|
||||
bool p3LinkMgrIMPL::connectResult(const std::string &id, bool success, uint32_t flags, const struct sockaddr_storage &remote_peer_address)
|
||||
bool p3LinkMgrIMPL::connectResult(const RsPeerId &id, bool success, uint32_t flags, const struct sockaddr_storage &remote_peer_address)
|
||||
{
|
||||
bool doDhtAssist = false ;
|
||||
bool updatePeerAddr = false;
|
||||
@ -786,16 +785,16 @@ bool p3LinkMgrIMPL::connectResult(const std::string &id, bool success, uint32_t
|
||||
|
||||
if (id == getOwnId())
|
||||
{
|
||||
rslog(RSL_ALERT, p3connectzone, "p3LinkMgrIMPL::connectResult() ERROR Trying to Connect to OwnId: " + id);
|
||||
rslog(RSL_ALERT, p3connectzone, "p3LinkMgrIMPL::connectResult() ERROR Trying to Connect to OwnId: " + id.toStdString());
|
||||
|
||||
return false;
|
||||
}
|
||||
/* check for existing */
|
||||
std::map<std::string, peerConnectState>::iterator it;
|
||||
std::map<RsPeerId, peerConnectState>::iterator it;
|
||||
it = mFriendList.find(id);
|
||||
if (it == mFriendList.end())
|
||||
{
|
||||
rslog(RSL_ALERT, p3connectzone, "p3LinkMgrIMPL::connectResult() ERROR Missing Friend: " + id);
|
||||
rslog(RSL_ALERT, p3connectzone, "p3LinkMgrIMPL::connectResult() ERROR Missing Friend: " + id.toStdString());
|
||||
|
||||
#ifdef LINKMGR_DEBUG
|
||||
std::cerr << "p3LinkMgrIMPL::connectResult() ERROR, missing Friend " << " id: " << id << std::endl;
|
||||
@ -806,7 +805,7 @@ bool p3LinkMgrIMPL::connectResult(const std::string &id, bool success, uint32_t
|
||||
/* now we can tell if we think we were connected - proper point to log */
|
||||
|
||||
{
|
||||
std::string out = "p3LinkMgrIMPL::connectResult() id: " + id;
|
||||
std::string out = "p3LinkMgrIMPL::connectResult() id: " + id.toStdString();
|
||||
if (success)
|
||||
{
|
||||
out += " SUCCESS ";
|
||||
@ -1030,7 +1029,7 @@ bool p3LinkMgrIMPL::connectResult(const std::string &id, bool success, uint32_t
|
||||
*/
|
||||
|
||||
// from pqissl, when a connection failed due to security
|
||||
void p3LinkMgrIMPL::notifyDeniedConnection(const std::string& gpgid,const std::string& sslid,const std::string& sslcn,const struct sockaddr_storage &addr, bool incoming)
|
||||
void p3LinkMgrIMPL::notifyDeniedConnection(const RsPgpId& gpgid,const RsPeerId& sslid,const std::string& sslcn,const struct sockaddr_storage &addr, bool incoming)
|
||||
{
|
||||
std::cerr << "p3LinkMgrIMPL::notifyDeniedConnection()";
|
||||
std::cerr << " pgpid: " << gpgid;
|
||||
@ -1040,7 +1039,7 @@ void p3LinkMgrIMPL::notifyDeniedConnection(const std::string& gpgid,const std::
|
||||
|
||||
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
std::map<std::string, peerConnectState>::iterator it;
|
||||
std::map<RsPeerId, peerConnectState>::iterator it;
|
||||
it = mFriendList.find(sslid);
|
||||
if (it == mFriendList.end())
|
||||
{
|
||||
@ -1070,12 +1069,12 @@ void p3LinkMgrIMPL::notifyDeniedConnection(const std::string& gpgid,const std::
|
||||
}
|
||||
|
||||
|
||||
void p3LinkMgrIMPL::peerStatus(std::string id, const pqiIpAddrSet &addrs,
|
||||
void p3LinkMgrIMPL::peerStatus(const RsPeerId& id, const pqiIpAddrSet &addrs,
|
||||
uint32_t type, uint32_t flags, uint32_t source)
|
||||
{
|
||||
/* HACKED UP FIX ****/
|
||||
|
||||
std::map<std::string, peerConnectState>::iterator it;
|
||||
std::map<RsPeerId, peerConnectState>::iterator it;
|
||||
bool isFriend = true;
|
||||
|
||||
time_t now = time(NULL);
|
||||
@ -1098,7 +1097,7 @@ void p3LinkMgrIMPL::peerStatus(std::string id, const pqiIpAddrSet &addrs,
|
||||
|
||||
{
|
||||
/* Log */
|
||||
std::string out = "p3LinkMgrIMPL::peerStatus() id: " + id;
|
||||
std::string out = "p3LinkMgrIMPL::peerStatus() id: " + id.toStdString();
|
||||
rs_sprintf_append(out, " type: %lu flags: %lu source: %lu\n", type, flags, source);
|
||||
addrs.printAddrs(out);
|
||||
|
||||
@ -1344,7 +1343,7 @@ void p3LinkMgrIMPL::peerStatus(std::string id, const pqiIpAddrSet &addrs,
|
||||
}
|
||||
|
||||
/* This has become very unwieldy - as extra arguments are required for UDP connections */
|
||||
void p3LinkMgrIMPL::peerConnectRequest(std::string id, const struct sockaddr_storage &raddr, const struct sockaddr_storage &proxyaddr, const struct sockaddr_storage &srcaddr,
|
||||
void p3LinkMgrIMPL::peerConnectRequest(const RsPeerId& id, const struct sockaddr_storage &raddr, const struct sockaddr_storage &proxyaddr, const struct sockaddr_storage &srcaddr,
|
||||
uint32_t source, uint32_t flags, uint32_t delay, uint32_t bandwidth)
|
||||
{
|
||||
#ifdef LINKMGR_DEBUG
|
||||
@ -1360,7 +1359,7 @@ void p3LinkMgrIMPL::peerConnectRequest(std::string id, const struct sockaddr_
|
||||
#endif
|
||||
{
|
||||
/* Log */
|
||||
std::string out = "p3LinkMgrIMPL::peerConnectRequest() id: " + id;
|
||||
std::string out = "p3LinkMgrIMPL::peerConnectRequest() id: " + id.toStdString();
|
||||
out += " raddr: ";
|
||||
out += sockaddr_storage_tostring(raddr);
|
||||
out += " proxyaddr: ";
|
||||
@ -1397,7 +1396,7 @@ void p3LinkMgrIMPL::peerConnectRequest(std::string id, const struct sockaddr_
|
||||
{
|
||||
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
std::map<std::string, peerConnectState>::iterator it;
|
||||
std::map<RsPeerId, peerConnectState>::iterator it;
|
||||
if (mFriendList.end() == (it = mFriendList.find(id)))
|
||||
{
|
||||
#ifdef LINKMGR_DEBUG
|
||||
@ -1449,7 +1448,7 @@ void p3LinkMgrIMPL::peerConnectRequest(std::string id, const struct sockaddr_
|
||||
/*******************************************************************/
|
||||
/*******************************************************************/
|
||||
/*************** External Control ****************/
|
||||
bool p3LinkMgrIMPL::retryConnect(const std::string &id)
|
||||
bool p3LinkMgrIMPL::retryConnect(const RsPeerId &id)
|
||||
{
|
||||
/* push all available addresses onto the connect addr stack */
|
||||
#ifdef LINKMGR_DEBUG
|
||||
@ -1467,7 +1466,7 @@ bool p3LinkMgrIMPL::retryConnect(const std::string &id)
|
||||
|
||||
|
||||
|
||||
bool p3LinkMgrIMPL::tryConnectUDP(const std::string &id, const struct sockaddr_storage &rUdpAddr,
|
||||
bool p3LinkMgrIMPL::tryConnectUDP(const RsPeerId &id, const struct sockaddr_storage &rUdpAddr,
|
||||
const struct sockaddr_storage &proxyaddr, const struct sockaddr_storage &srcaddr,
|
||||
uint32_t flags, uint32_t delay, uint32_t bandwidth)
|
||||
|
||||
@ -1514,7 +1513,7 @@ bool p3LinkMgrIMPL::tryConnectUDP(const std::string &id, const struct sockaddr
|
||||
}
|
||||
|
||||
/* look up the id */
|
||||
std::map<std::string, peerConnectState>::iterator it;
|
||||
std::map<RsPeerId, peerConnectState>::iterator it;
|
||||
if (mFriendList.end() == (it = mFriendList.find(id)))
|
||||
{
|
||||
#ifdef LINKMGR_DEBUG
|
||||
@ -1564,7 +1563,7 @@ bool p3LinkMgrIMPL::tryConnectUDP(const std::string &id, const struct sockaddr
|
||||
|
||||
|
||||
|
||||
bool p3LinkMgrIMPL::retryConnectTCP(const std::string &id)
|
||||
bool p3LinkMgrIMPL::retryConnectTCP(const RsPeerId &id)
|
||||
{
|
||||
/* Check if we should retry first */
|
||||
{
|
||||
@ -1589,7 +1588,7 @@ bool p3LinkMgrIMPL::retryConnectTCP(const std::string &id)
|
||||
}
|
||||
|
||||
/* look up the id */
|
||||
std::map<std::string, peerConnectState>::iterator it;
|
||||
std::map<RsPeerId, peerConnectState>::iterator it;
|
||||
if (mFriendList.end() == (it = mFriendList.find(id)))
|
||||
{
|
||||
#ifdef LINKMGR_DEBUG
|
||||
@ -1626,7 +1625,7 @@ bool p3LinkMgrIMPL::retryConnectTCP(const std::string &id)
|
||||
{
|
||||
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
std::map<std::string, peerConnectState>::iterator it;
|
||||
std::map<RsPeerId, peerConnectState>::iterator it;
|
||||
if (mFriendList.end() != (it = mFriendList.find(id)))
|
||||
{
|
||||
locked_ConnectAttempt_ProxyAddress(&(it->second), proxy_addr, domain_addr, domain_port);
|
||||
@ -1652,7 +1651,7 @@ bool p3LinkMgrIMPL::retryConnectTCP(const std::string &id)
|
||||
{
|
||||
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
std::map<std::string, peerConnectState>::iterator it;
|
||||
std::map<RsPeerId, peerConnectState>::iterator it;
|
||||
if (mFriendList.end() != (it = mFriendList.find(id)))
|
||||
{
|
||||
locked_ConnectAttempt_CurrentAddresses(&(it->second), lAddr, eAddr);
|
||||
@ -2125,9 +2124,9 @@ bool p3LinkMgrIMPL::locked_ConnectAttempt_Complete(peerConnectState *peer)
|
||||
************************************* Handling of Friends *************************************************
|
||||
***********************************************************************************************************/
|
||||
|
||||
int p3LinkMgrIMPL::addFriend(const std::string &id, bool isVisible)
|
||||
int p3LinkMgrIMPL::addFriend(const RsPeerId &id, bool isVisible)
|
||||
{
|
||||
rslog(RSL_WARNING, p3connectzone, "p3LinkMgr::addFriend() id: " + id);
|
||||
rslog(RSL_WARNING, p3connectzone, "p3LinkMgr::addFriend() id: " + id.toStdString());
|
||||
|
||||
{
|
||||
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
||||
@ -2137,7 +2136,7 @@ int p3LinkMgrIMPL::addFriend(const std::string &id, bool isVisible)
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
std::map<std::string, peerConnectState>::iterator it;
|
||||
std::map<RsPeerId, peerConnectState>::iterator it;
|
||||
it = mFriendList.find(id);
|
||||
|
||||
if (it != mFriendList.end())
|
||||
@ -2166,9 +2165,9 @@ int p3LinkMgrIMPL::addFriend(const std::string &id, bool isVisible)
|
||||
}
|
||||
|
||||
|
||||
int p3LinkMgrIMPL::removeFriend(const std::string &id)
|
||||
int p3LinkMgrIMPL::removeFriend(const RsPeerId &id)
|
||||
{
|
||||
rslog(RSL_WARNING, p3connectzone, "p3LinkMgr::removeFriend() id: " + id);
|
||||
rslog(RSL_WARNING, p3connectzone, "p3LinkMgr::removeFriend() id: " + id.toStdString());
|
||||
|
||||
{
|
||||
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
||||
@ -2178,7 +2177,7 @@ int p3LinkMgrIMPL::removeFriend(const std::string &id)
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
std::map<std::string, peerConnectState>::iterator it;
|
||||
std::map<RsPeerId, peerConnectState>::iterator it;
|
||||
it = mFriendList.find(id);
|
||||
|
||||
if (it == mFriendList.end())
|
||||
@ -2218,10 +2217,10 @@ void p3LinkMgrIMPL::printPeerLists(std::ostream &out)
|
||||
out << std::endl;
|
||||
|
||||
|
||||
std::map<std::string, peerConnectState>::iterator it;
|
||||
std::map<RsPeerId, peerConnectState>::iterator it;
|
||||
for(it = mFriendList.begin(); it != mFriendList.end(); it++)
|
||||
{
|
||||
out << "\t SSL ID: " << it->second.id;
|
||||
out << "\t SSL ID: " << it->second.id.toStdString();
|
||||
out << "\t State: " << it->second.state;
|
||||
out << std::endl;
|
||||
}
|
||||
@ -2230,7 +2229,7 @@ void p3LinkMgrIMPL::printPeerLists(std::ostream &out)
|
||||
out << std::endl;
|
||||
for(it = mOthersList.begin(); it != mOthersList.end(); it++)
|
||||
{
|
||||
out << "\t SSL ID: " << it->second.id;
|
||||
out << "\t SSL ID: " << it->second.id.toStdString();
|
||||
out << "\t State: " << it->second.state;
|
||||
}
|
||||
}
|
||||
@ -2242,7 +2241,7 @@ void p3LinkMgrIMPL::printPeerLists(std::ostream &out)
|
||||
void printConnectState(std::ostream &out, peerConnectState &peer)
|
||||
{
|
||||
|
||||
out << "Friend: " << peer.name << " Id: " << peer.id << " State: " << peer.state;
|
||||
out << "Friend: " << peer.name << " Id: " << peer.id.toStdString() << " State: " << peer.state;
|
||||
if (peer.state & RS_PEER_S_FRIEND)
|
||||
out << " S:RS_PEER_S_FRIEND";
|
||||
if (peer.state & RS_PEER_S_ONLINE)
|
||||
|
@ -94,7 +94,7 @@ class peerConnectState
|
||||
public:
|
||||
peerConnectState(); /* init */
|
||||
|
||||
std::string id;
|
||||
RsPeerId id;
|
||||
|
||||
/***** Below here not stored permanently *****/
|
||||
|
||||
@ -155,26 +155,26 @@ class p3LinkMgr: public pqiConnectCb
|
||||
virtual ~p3LinkMgr() { return; }
|
||||
|
||||
|
||||
virtual const std::string getOwnId() = 0;
|
||||
virtual bool isOnline(const std::string &ssl_id) = 0;
|
||||
virtual void getOnlineList(std::list<std::string> &ssl_peers) = 0;
|
||||
virtual bool getPeerName(const std::string &ssl_id, std::string &name) = 0;
|
||||
virtual uint32_t getLinkType(const std::string &ssl_id) = 0;
|
||||
virtual const RsPeerId& getOwnId() = 0;
|
||||
virtual bool isOnline(const RsPeerId &ssl_id) = 0;
|
||||
virtual void getOnlineList(std::list<RsPeerId> &ssl_peers) = 0;
|
||||
virtual bool getPeerName(const RsPeerId &ssl_id, std::string &name) = 0;
|
||||
virtual uint32_t getLinkType(const RsPeerId &ssl_id) = 0;
|
||||
|
||||
/**************** handle monitors *****************/
|
||||
virtual void addMonitor(pqiMonitor *mon) = 0;
|
||||
virtual void removeMonitor(pqiMonitor *mon) = 0;
|
||||
|
||||
/****************** Connections *******************/
|
||||
virtual bool connectAttempt(const std::string &id, struct sockaddr_storage &raddr,
|
||||
virtual bool connectAttempt(const RsPeerId &id, struct sockaddr_storage &raddr,
|
||||
struct sockaddr_storage &proxyaddr, struct sockaddr_storage &srcaddr,
|
||||
uint32_t &delay, uint32_t &period, uint32_t &type, uint32_t &flags, uint32_t &bandwidth,
|
||||
std::string &domain_addr, uint16_t &domain_port) = 0;
|
||||
|
||||
virtual bool connectResult(const std::string &id, bool success, uint32_t flags, const struct sockaddr_storage &remote_peer_address) = 0;
|
||||
virtual bool retryConnect(const std::string &id) = 0;
|
||||
virtual bool connectResult(const RsPeerId &id, bool success, uint32_t flags, const struct sockaddr_storage &remote_peer_address) = 0;
|
||||
virtual bool retryConnect(const RsPeerId &id) = 0;
|
||||
|
||||
virtual void notifyDeniedConnection(const std::string& gpgid,const std::string& sslid,const std::string& sslcn,const struct sockaddr_storage &addr, bool incoming) = 0;
|
||||
virtual void notifyDeniedConnection(const RsPgpId& gpgid,const RsPeerId& sslid,const std::string& sslcn,const struct sockaddr_storage &addr, bool incoming) = 0;
|
||||
|
||||
/* Network Addresses */
|
||||
virtual bool setLocalAddress(const struct sockaddr_storage &addr) = 0;
|
||||
@ -182,12 +182,12 @@ virtual bool getLocalAddress(struct sockaddr_storage &addr) = 0;
|
||||
|
||||
/************* DEPRECIATED FUNCTIONS (TO REMOVE) ********/
|
||||
|
||||
virtual void getFriendList(std::list<std::string> &ssl_peers) = 0; // ONLY used by p3peers.cc USE p3PeerMgr instead.
|
||||
virtual bool getFriendNetStatus(const std::string &id, peerConnectState &state) = 0; // ONLY used by p3peers.cc
|
||||
virtual void getFriendList(std::list<RsPeerId> &ssl_peers) = 0; // ONLY used by p3peers.cc USE p3PeerMgr instead.
|
||||
virtual bool getFriendNetStatus(const RsPeerId &id, peerConnectState &state) = 0; // ONLY used by p3peers.cc
|
||||
|
||||
|
||||
/************* DEPRECIATED FUNCTIONS (TO REMOVE) ********/
|
||||
virtual int addFriend(const std::string &ssl_id, bool isVisible) = 0;
|
||||
virtual int addFriend(const RsPeerId &ssl_id, bool isVisible) = 0;
|
||||
/******* overloaded from pqiConnectCb *************/
|
||||
// THESE MUSTn't BE specfied HERE - as overloaded from pqiConnectCb.
|
||||
//virtual void peerStatus(std::string id, const pqiIpAddrSet &addrs,
|
||||
@ -212,11 +212,11 @@ class p3LinkMgrIMPL: public p3LinkMgr
|
||||
/* EXTERNAL INTERFACE */
|
||||
/************************************************************************************************/
|
||||
|
||||
virtual const std::string getOwnId();
|
||||
virtual bool isOnline(const std::string &ssl_id);
|
||||
virtual void getOnlineList(std::list<std::string> &ssl_peers);
|
||||
virtual bool getPeerName(const std::string &ssl_id, std::string &name);
|
||||
virtual uint32_t getLinkType(const std::string &ssl_id);
|
||||
virtual const RsPeerId& getOwnId();
|
||||
virtual bool isOnline(const RsPeerId &ssl_id);
|
||||
virtual void getOnlineList(std::list<RsPeerId> &ssl_peers);
|
||||
virtual bool getPeerName(const RsPeerId &ssl_id, std::string &name);
|
||||
virtual uint32_t getLinkType(const RsPeerId &ssl_id);
|
||||
|
||||
|
||||
/**************** handle monitors *****************/
|
||||
@ -224,32 +224,32 @@ virtual void addMonitor(pqiMonitor *mon);
|
||||
virtual void removeMonitor(pqiMonitor *mon);
|
||||
|
||||
/****************** Connections *******************/
|
||||
virtual bool connectAttempt(const std::string &id, struct sockaddr_storage &raddr,
|
||||
virtual bool connectAttempt(const RsPeerId &id, struct sockaddr_storage &raddr,
|
||||
struct sockaddr_storage &proxyaddr, struct sockaddr_storage &srcaddr,
|
||||
uint32_t &delay, uint32_t &period, uint32_t &type, uint32_t &flags, uint32_t &bandwidth,
|
||||
std::string &domain_addr, uint16_t &domain_port);
|
||||
|
||||
virtual bool connectResult(const std::string &id, bool success, uint32_t flags, const struct sockaddr_storage &remote_peer_address);
|
||||
virtual bool retryConnect(const std::string &id);
|
||||
virtual bool connectResult(const RsPeerId &id, bool success, uint32_t flags, const struct sockaddr_storage &remote_peer_address);
|
||||
virtual bool retryConnect(const RsPeerId &id);
|
||||
|
||||
virtual void notifyDeniedConnection(const std::string& gpgid,const std::string& sslid,const std::string& sslcn,const struct sockaddr_storage &addr, bool incoming);
|
||||
virtual void notifyDeniedConnection(const RsPgpId& gpgid,const RsPeerId& sslid,const std::string& sslcn,const struct sockaddr_storage &addr, bool incoming);
|
||||
|
||||
/* Network Addresses */
|
||||
virtual bool setLocalAddress(const struct sockaddr_storage &addr);
|
||||
virtual bool getLocalAddress(struct sockaddr_storage &addr);
|
||||
|
||||
/******* overloaded from pqiConnectCb *************/
|
||||
virtual void peerStatus(std::string id, const pqiIpAddrSet &addrs,
|
||||
virtual void peerStatus(const RsPeerId& id, const pqiIpAddrSet &addrs,
|
||||
uint32_t type, uint32_t flags, uint32_t source);
|
||||
virtual void peerConnectRequest(std::string id, const struct sockaddr_storage &raddr,
|
||||
virtual void peerConnectRequest(const RsPeerId& id, const struct sockaddr_storage &raddr,
|
||||
const struct sockaddr_storage &proxyaddr, const struct sockaddr_storage &srcaddr,
|
||||
uint32_t source, uint32_t flags, uint32_t delay, uint32_t bandwidth);
|
||||
|
||||
|
||||
/************* DEPRECIATED FUNCTIONS (TO REMOVE) ********/
|
||||
|
||||
virtual void getFriendList(std::list<std::string> &ssl_peers); // ONLY used by p3peers.cc USE p3PeerMgr instead.
|
||||
virtual bool getFriendNetStatus(const std::string &id, peerConnectState &state); // ONLY used by p3peers.cc
|
||||
virtual void getFriendList(std::list<RsPeerId> &ssl_peers); // ONLY used by p3peers.cc USE p3PeerMgr instead.
|
||||
virtual bool getFriendNetStatus(const RsPeerId &id, peerConnectState &state); // ONLY used by p3peers.cc
|
||||
|
||||
/************************************************************************************************/
|
||||
/* Extra IMPL Functions (used by p3PeerMgr, p3NetMgr + Setup) */
|
||||
@ -260,11 +260,11 @@ virtual bool getFriendNetStatus(const std::string &id, peerConnectState &state);
|
||||
void tick();
|
||||
|
||||
/* THIS COULD BE ADDED TO INTERFACE */
|
||||
void setFriendVisibility(const std::string &id, bool isVisible);
|
||||
void setFriendVisibility(const RsPeerId &id, bool isVisible);
|
||||
|
||||
/* add/remove friends */
|
||||
virtual int addFriend(const std::string &ssl_id, bool isVisible);
|
||||
int removeFriend(const std::string &ssl_id);
|
||||
virtual int addFriend(const RsPeerId &ssl_id, bool isVisible);
|
||||
int removeFriend(const RsPeerId &ssl_id);
|
||||
|
||||
void printPeerLists(std::ostream &out);
|
||||
|
||||
@ -284,12 +284,12 @@ void statusTick();
|
||||
void tickMonitors();
|
||||
|
||||
/* connect attempts UDP */
|
||||
bool tryConnectUDP(const std::string &id, const struct sockaddr_storage &rUdpAddr,
|
||||
bool tryConnectUDP(const RsPeerId &id, const struct sockaddr_storage &rUdpAddr,
|
||||
const struct sockaddr_storage &proxyaddr, const struct sockaddr_storage &srcaddr,
|
||||
uint32_t flags, uint32_t delay, uint32_t bandwidth);
|
||||
|
||||
/* connect attempts TCP */
|
||||
bool retryConnectTCP(const std::string &id);
|
||||
bool retryConnectTCP(const RsPeerId &id);
|
||||
|
||||
void locked_ConnectAttempt_SpecificAddress(peerConnectState *peer, const struct sockaddr_storage &remoteAddr);
|
||||
void locked_ConnectAttempt_CurrentAddresses(peerConnectState *peer, const struct sockaddr_storage &localAddr, const struct sockaddr_storage &serverAddr);
|
||||
@ -330,8 +330,8 @@ private:
|
||||
|
||||
//peerConnectState mOwnState;
|
||||
|
||||
std::map<std::string, peerConnectState> mFriendList;
|
||||
std::map<std::string, peerConnectState> mOthersList;
|
||||
std::map<RsPeerId, peerConnectState> mFriendList;
|
||||
std::map<RsPeerId, peerConnectState> mOthersList;
|
||||
|
||||
std::list<RsPeerGroupItem *> groupList;
|
||||
uint32_t lastGroupId;
|
||||
|
@ -896,7 +896,7 @@ void p3NetMgrIMPL::netExtCheck()
|
||||
}
|
||||
|
||||
/* inform DHT about our external address */
|
||||
std::string fakeId;
|
||||
RsPeerId fakeId;
|
||||
netAssistKnownPeer(fakeId, mExtAddr, NETASSIST_KNOWN_PEER_SELF | NETASSIST_KNOWN_PEER_ONLINE);
|
||||
|
||||
rslog(RSL_WARNING, p3netmgrzone, "p3NetMgr::netExtCheck() Network Setup Complete");
|
||||
@ -1378,7 +1378,7 @@ bool p3NetMgrIMPL::netAssistConnectShutdown()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3NetMgrIMPL::netAssistFriend(const std::string &id, bool on)
|
||||
bool p3NetMgrIMPL::netAssistFriend(const RsPeerId &id, bool on)
|
||||
{
|
||||
std::map<uint32_t, pqiNetAssistConnect *>::iterator it;
|
||||
|
||||
@ -1398,7 +1398,7 @@ bool p3NetMgrIMPL::netAssistFriend(const std::string &id, bool on)
|
||||
}
|
||||
|
||||
|
||||
bool p3NetMgrIMPL::netAssistKnownPeer(const std::string &id, const struct sockaddr_storage &addr, uint32_t flags)
|
||||
bool p3NetMgrIMPL::netAssistKnownPeer(const RsPeerId &id, const struct sockaddr_storage &addr, uint32_t flags)
|
||||
{
|
||||
std::map<uint32_t, pqiNetAssistConnect *>::iterator it;
|
||||
|
||||
@ -1449,7 +1449,7 @@ bool p3NetMgrIMPL::netAssistAttach(bool on)
|
||||
|
||||
|
||||
|
||||
bool p3NetMgrIMPL::netAssistStatusUpdate(const std::string &id, int state)
|
||||
bool p3NetMgrIMPL::netAssistStatusUpdate(const RsPeerId &id, int state)
|
||||
{
|
||||
std::map<uint32_t, pqiNetAssistConnect *>::iterator it;
|
||||
|
||||
|
@ -118,10 +118,10 @@ virtual bool setNetworkMode(uint32_t netMode) = 0;
|
||||
virtual bool setVisState(uint16_t vs_disc, uint16_t vs_dht) = 0;
|
||||
|
||||
// Switch DHT On/Off.
|
||||
virtual bool netAssistFriend(const std::string &id, bool on) = 0;
|
||||
virtual bool netAssistKnownPeer(const std::string &id, const struct sockaddr_storage &addr, uint32_t flags) = 0;
|
||||
virtual bool netAssistFriend(const RsPeerId &id, bool on) = 0;
|
||||
virtual bool netAssistKnownPeer(const RsPeerId &id, const struct sockaddr_storage &addr, uint32_t flags) = 0;
|
||||
virtual bool netAssistBadPeer(const struct sockaddr_storage &addr, uint32_t reason, uint32_t flags, uint32_t age) = 0;
|
||||
virtual bool netAssistStatusUpdate(const std::string &id, int mode) = 0;
|
||||
virtual bool netAssistStatusUpdate(const RsPeerId &id, int mode) = 0;
|
||||
|
||||
/* Get Network State */
|
||||
virtual uint32_t getNetStateMode() = 0;
|
||||
@ -174,10 +174,10 @@ virtual bool setNetworkMode(uint32_t netMode);
|
||||
virtual bool setVisState(uint16_t vs_disc, uint16_t vs_dht);
|
||||
|
||||
// Switch DHT On/Off.
|
||||
virtual bool netAssistFriend(const std::string &id, bool on);
|
||||
virtual bool netAssistKnownPeer(const std::string &id, const struct sockaddr_storage &addr, uint32_t flags);
|
||||
virtual bool netAssistFriend(const RsPeerId &id, bool on);
|
||||
virtual bool netAssistKnownPeer(const RsPeerId &id, const struct sockaddr_storage &addr, uint32_t flags);
|
||||
virtual bool netAssistBadPeer(const struct sockaddr_storage &addr, uint32_t reason, uint32_t flags, uint32_t age);
|
||||
virtual bool netAssistStatusUpdate(const std::string &id, int mode);
|
||||
virtual bool netAssistStatusUpdate(const RsPeerId &id, int mode);
|
||||
|
||||
/* Get Network State */
|
||||
virtual uint32_t getNetStateMode();
|
||||
|
@ -83,9 +83,7 @@ static const std::string kConfigKeyProxyServerPort = "PROXY_SERVER_PORT";
|
||||
void printConnectState(std::ostream &out, peerState &peer);
|
||||
|
||||
peerState::peerState()
|
||||
:id("unknown"),
|
||||
gpg_id("unknown"),
|
||||
netMode(RS_NET_MODE_UNKNOWN), vs_disc(RS_VS_DISC_FULL), vs_dht(RS_VS_DHT_FULL), lastcontact(0),
|
||||
:netMode(RS_NET_MODE_UNKNOWN), vs_disc(RS_VS_DISC_FULL), vs_dht(RS_VS_DHT_FULL), lastcontact(0),
|
||||
hiddenNode(false), hiddenPort(0)
|
||||
{
|
||||
sockaddr_storage_clear(localaddr);
|
||||
@ -96,7 +94,7 @@ peerState::peerState()
|
||||
|
||||
std::string textPeerConnectState(peerState &state)
|
||||
{
|
||||
std::string out = "Id: " + state.id + "\n";
|
||||
std::string out = "Id: " + state.id.toStdString() + "\n";
|
||||
rs_sprintf_append(out, "NetMode: %lu\n", state.netMode);
|
||||
rs_sprintf_append(out, "VisState: Disc: %u Dht: %u\n", state.vs_disc, state.vs_dht);
|
||||
|
||||
@ -110,10 +108,7 @@ std::string textPeerConnectState(peerState &state)
|
||||
}
|
||||
|
||||
|
||||
p3PeerMgrIMPL::p3PeerMgrIMPL(const std::string& ssl_own_id,
|
||||
const std::string& gpg_own_id,
|
||||
const std::string& gpg_own_name,
|
||||
const std::string& ssl_own_location)
|
||||
p3PeerMgrIMPL::p3PeerMgrIMPL(const RsPeerId& ssl_own_id, const RsPgpId& gpg_own_id, const std::string& gpg_own_name, const std::string& ssl_own_location)
|
||||
:p3Config(CONFIG_TYPE_PEERS), mPeerMtx("p3PeerMgr"), mStatusChanged(false)
|
||||
{
|
||||
|
||||
@ -297,7 +292,7 @@ void p3PeerMgrIMPL::tick()
|
||||
*/
|
||||
|
||||
|
||||
const std::string p3PeerMgrIMPL::getOwnId()
|
||||
const RsPeerId& p3PeerMgrIMPL::getOwnId()
|
||||
{
|
||||
return AuthSSL::getAuthSSL()->OwnId();
|
||||
}
|
||||
@ -310,7 +305,7 @@ bool p3PeerMgrIMPL::getOwnNetStatus(peerState &state)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3PeerMgrIMPL::isFriend(const std::string &id)
|
||||
bool p3PeerMgrIMPL::isFriend(const RsPeerId& id)
|
||||
{
|
||||
#ifdef PEER_DEBUG_COMMON
|
||||
std::cerr << "p3PeerMgrIMPL::isFriend(" << id << ") called" << std::endl;
|
||||
@ -323,12 +318,12 @@ bool p3PeerMgrIMPL::isFriend(const std::string &id)
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool p3PeerMgrIMPL::getPeerName(const std::string &ssl_id, std::string &name)
|
||||
bool p3PeerMgrIMPL::getPeerName(const RsPeerId &ssl_id, std::string &name)
|
||||
{
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
/* check for existing */
|
||||
std::map<std::string, peerState>::iterator it;
|
||||
std::map<RsPeerId, peerState>::iterator it;
|
||||
it = mFriendList.find(ssl_id);
|
||||
if (it == mFriendList.end())
|
||||
{
|
||||
@ -339,12 +334,12 @@ bool p3PeerMgrIMPL::getPeerName(const std::string &ssl_id, std::string &name)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3PeerMgrIMPL::getGpgId(const std::string &ssl_id, std::string &gpgId)
|
||||
bool p3PeerMgrIMPL::getGpgId(const RsPeerId &ssl_id, RsPgpId &gpgId)
|
||||
{
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
/* check for existing */
|
||||
std::map<std::string, peerState>::iterator it;
|
||||
std::map<RsPeerId, peerState>::iterator it;
|
||||
it = mFriendList.find(ssl_id);
|
||||
if (it == mFriendList.end())
|
||||
{
|
||||
@ -364,12 +359,12 @@ bool p3PeerMgrIMPL::isHidden()
|
||||
}
|
||||
|
||||
|
||||
bool p3PeerMgrIMPL::isHiddenPeer(const std::string &ssl_id)
|
||||
bool p3PeerMgrIMPL::isHiddenPeer(const RsPeerId &ssl_id)
|
||||
{
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
/* check for existing */
|
||||
std::map<std::string, peerState>::iterator it;
|
||||
std::map<RsPeerId, peerState>::iterator it;
|
||||
it = mFriendList.find(ssl_id);
|
||||
if (it == mFriendList.end())
|
||||
{
|
||||
@ -384,7 +379,7 @@ bool p3PeerMgrIMPL::isHiddenPeer(const std::string &ssl_id)
|
||||
return (it->second).hiddenNode;
|
||||
}
|
||||
|
||||
bool p3PeerMgrIMPL::setHiddenDomainPort(const std::string &ssl_id, const std::string &domain_addr, const uint16_t domain_port)
|
||||
bool p3PeerMgrIMPL::setHiddenDomainPort(const RsPeerId &ssl_id, const std::string &domain_addr, const uint16_t domain_port)
|
||||
{
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
@ -417,7 +412,7 @@ bool p3PeerMgrIMPL::setHiddenDomainPort(const std::string &ssl_id, const std::st
|
||||
}
|
||||
|
||||
/* check for existing */
|
||||
std::map<std::string, peerState>::iterator it;
|
||||
std::map<RsPeerId, peerState>::iterator it;
|
||||
it = mFriendList.find(ssl_id);
|
||||
if (it == mFriendList.end())
|
||||
{
|
||||
@ -456,12 +451,12 @@ bool p3PeerMgrIMPL::getProxyServerAddress(struct sockaddr_storage &proxy_addr)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3PeerMgrIMPL::getProxyAddress(const std::string &ssl_id, struct sockaddr_storage &proxy_addr, std::string &domain_addr, uint16_t &domain_port)
|
||||
bool p3PeerMgrIMPL::getProxyAddress(const RsPeerId &ssl_id, struct sockaddr_storage &proxy_addr, std::string &domain_addr, uint16_t &domain_port)
|
||||
{
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
/* check for existing */
|
||||
std::map<std::string, peerState>::iterator it;
|
||||
std::map<RsPeerId, peerState>::iterator it;
|
||||
it = mFriendList.find(ssl_id);
|
||||
if (it == mFriendList.end())
|
||||
{
|
||||
@ -481,7 +476,7 @@ bool p3PeerMgrIMPL::getProxyAddress(const std::string &ssl_id, struct sockaddr_s
|
||||
}
|
||||
|
||||
// Placeholder until we implement this functionality.
|
||||
uint32_t p3PeerMgrIMPL::getConnectionType(const std::string &/*sslId*/)
|
||||
uint32_t p3PeerMgrIMPL::getConnectionType(const RsPeerId &/*sslId*/)
|
||||
{
|
||||
return RS_NET_CONN_TYPE_FRIEND;
|
||||
}
|
||||
@ -490,15 +485,15 @@ int p3PeerMgrIMPL::getFriendCount(bool ssl, bool online)
|
||||
{
|
||||
if (online) {
|
||||
// count only online id's
|
||||
std::list<std::string> onlineIds;
|
||||
std::list<RsPeerId> onlineIds;
|
||||
mLinkMgr->getOnlineList(onlineIds);
|
||||
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
std::set<std::string> gpgIds;
|
||||
std::set<RsPgpId> gpgIds;
|
||||
int count = 0;
|
||||
|
||||
std::map<std::string, peerState>::iterator it;
|
||||
std::map<RsPeerId, peerState>::iterator it;
|
||||
for(it = mFriendList.begin(); it != mFriendList.end(); ++it) {
|
||||
if (online && std::find(onlineIds.begin(), onlineIds.end(), it->first) == onlineIds.end()) {
|
||||
continue;
|
||||
@ -522,22 +517,22 @@ int p3PeerMgrIMPL::getFriendCount(bool ssl, bool online)
|
||||
}
|
||||
|
||||
// count all gpg id's
|
||||
std::list<std::string> gpgIds;
|
||||
std::list<RsPgpId> gpgIds;
|
||||
AuthGPG::getAuthGPG()->getGPGAcceptedList(gpgIds);
|
||||
|
||||
// add own gpg id, if we have more than one location
|
||||
std::list<std::string> ownSslIds;
|
||||
std::list<RsPeerId> ownSslIds;
|
||||
getAssociatedPeers(AuthGPG::getAuthGPG()->getGPGOwnId(), ownSslIds);
|
||||
|
||||
return gpgIds.size() + ((ownSslIds.size() > 0) ? 1 : 0);
|
||||
}
|
||||
|
||||
bool p3PeerMgrIMPL::getFriendNetStatus(const std::string &id, peerState &state)
|
||||
bool p3PeerMgrIMPL::getFriendNetStatus(const RsPeerId &id, peerState &state)
|
||||
{
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
/* check for existing */
|
||||
std::map<std::string, peerState>::iterator it;
|
||||
std::map<RsPeerId, peerState>::iterator it;
|
||||
it = mFriendList.find(id);
|
||||
if (it == mFriendList.end())
|
||||
{
|
||||
@ -549,12 +544,12 @@ bool p3PeerMgrIMPL::getFriendNetStatus(const std::string &id, peerState &state)
|
||||
}
|
||||
|
||||
|
||||
bool p3PeerMgrIMPL::getOthersNetStatus(const std::string &id, peerState &state)
|
||||
bool p3PeerMgrIMPL::getOthersNetStatus(const RsPeerId &id, peerState &state)
|
||||
{
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
/* check for existing */
|
||||
std::map<std::string, peerState>::iterator it;
|
||||
std::map<RsPeerId, peerState>::iterator it;
|
||||
it = mOthersList.find(id);
|
||||
if (it == mOthersList.end())
|
||||
{
|
||||
@ -565,41 +560,7 @@ bool p3PeerMgrIMPL::getOthersNetStatus(const std::string &id, peerState &state)
|
||||
return true;
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
void p3PeerMgrIMPL::getFriendList(std::list<std::string> &peers)
|
||||
{
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
/* check for existing */
|
||||
std::map<std::string, peerState>::iterator it;
|
||||
for(it = mFriendList.begin(); it != mFriendList.end(); it++)
|
||||
{
|
||||
peers.push_back(it->first);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
void p3PeerMgrIMPL::getOthersList(std::list<std::string> &peers)
|
||||
{
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
/* check for existing */
|
||||
std::map<std::string, peerState>::iterator it;
|
||||
for(it = mOthersList.begin(); it != mOthersList.end(); it++)
|
||||
{
|
||||
peers.push_back(it->first);
|
||||
}
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
int p3PeerMgrIMPL::getConnectAddresses(const std::string &id,
|
||||
int p3PeerMgrIMPL::getConnectAddresses(const RsPeerId &id,
|
||||
struct sockaddr_storage &lAddr, struct sockaddr_storage &eAddr,
|
||||
pqiIpAddrSet &histAddrs, std::string &dyndns)
|
||||
{
|
||||
@ -607,7 +568,7 @@ int p3PeerMgrIMPL::getConnectAddresses(const std::string &id,
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
/* check for existing */
|
||||
std::map<std::string, peerState>::iterator it;
|
||||
std::map<RsPeerId, peerState>::iterator it;
|
||||
it = mFriendList.find(id);
|
||||
if (it == mFriendList.end())
|
||||
{
|
||||
@ -632,7 +593,7 @@ bool p3PeerMgrIMPL::haveOnceConnected()
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
/* check for existing */
|
||||
std::map<std::string, peerState>::iterator it;
|
||||
std::map<RsPeerId, peerState>::iterator it;
|
||||
for(it = mFriendList.begin(); it != mFriendList.end(); it++)
|
||||
{
|
||||
if (it->second.lastcontact > 0)
|
||||
@ -660,23 +621,13 @@ bool p3PeerMgrIMPL::haveOnceConnected()
|
||||
/*******************************************************************/
|
||||
/*******************************************************************/
|
||||
|
||||
bool p3PeerMgrIMPL::addFriend(const std::string& input_id, const std::string& input_gpg_id, uint32_t netMode, uint16_t vs_disc, uint16_t vs_dht, time_t lastContact,ServicePermissionFlags service_flags)
|
||||
bool p3PeerMgrIMPL::addFriend(const RsPeerId& input_id, const RsPgpId& input_gpg_id, uint32_t netMode, uint16_t vs_disc, uint16_t vs_dht, time_t lastContact,ServicePermissionFlags service_flags)
|
||||
{
|
||||
bool notifyLinkMgr = false;
|
||||
std::string id = input_id ;
|
||||
std::string gpg_id = input_gpg_id ;
|
||||
RsPeerId id = input_id ;
|
||||
RsPgpId gpg_id = input_gpg_id ;
|
||||
|
||||
rslog(RSL_WARNING, p3peermgrzone, "p3PeerMgr::addFriend() id: " + id);
|
||||
|
||||
// For safety, make sure ssl_id is lower case and GPG id is upper case.
|
||||
//
|
||||
for(uint32_t i=0;i<id.length();++i)
|
||||
if(id[i] >= 'A' && id[i] <= 'F')
|
||||
id[i] += 'a' - 'A' ;
|
||||
|
||||
for(uint32_t i=0;i<gpg_id.length();++i)
|
||||
if(gpg_id[i] >= 'a' && gpg_id[i] <= 'f')
|
||||
gpg_id[i] += 'A' - 'a' ;
|
||||
rslog(RSL_WARNING, p3peermgrzone, "p3PeerMgr::addFriend() id: " + id.toStdString());
|
||||
|
||||
{
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
@ -700,7 +651,7 @@ bool p3PeerMgrIMPL::addFriend(const std::string& input_id, const std::string& in
|
||||
std::cerr << "p3PeerMgrIMPL::addFriend() " << id << "; gpg_id : " << gpg_id << std::endl;
|
||||
#endif
|
||||
|
||||
std::map<std::string, peerState>::iterator it;
|
||||
std::map<RsPeerId, peerState>::iterator it;
|
||||
if (mFriendList.end() != mFriendList.find(id))
|
||||
{
|
||||
#ifdef PEER_DEBUG
|
||||
@ -794,8 +745,79 @@ bool p3PeerMgrIMPL::addFriend(const std::string& input_id, const std::string& in
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3PeerMgrIMPL::removeFriend(const RsPgpId &id)
|
||||
{
|
||||
#ifdef PEER_DEBUG
|
||||
std::cerr << "p3PeerMgrIMPL::removeFriend() for id : " << id << std::endl;
|
||||
std::cerr << "p3PeerMgrIMPL::removeFriend() mFriendList.size() : " << mFriendList.size() << std::endl;
|
||||
#endif
|
||||
|
||||
bool p3PeerMgrIMPL::removeFriend(const std::string &id, bool removePgpId)
|
||||
rslog(RSL_WARNING, p3peermgrzone, "p3PeerMgr::removeFriend() id: " + id.toStdString());
|
||||
|
||||
std::list<RsPeerId> sslid_toRemove; // This is a list of SSLIds.
|
||||
rsPeers->getAssociatedSSLIds(id,sslid_toRemove) ;
|
||||
|
||||
{
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
/* move to othersList */
|
||||
bool success = false;
|
||||
std::map<RsPeerId, peerState>::iterator it;
|
||||
//remove ssl and gpg_ids
|
||||
for(it = mFriendList.begin(); it != mFriendList.end(); it++)
|
||||
{
|
||||
if (find(sslid_toRemove.begin(),sslid_toRemove.end(),it->second.id) != sslid_toRemove.end())
|
||||
{
|
||||
#ifdef PEER_DEBUG
|
||||
std::cerr << "p3PeerMgrIMPL::removeFriend() friend found in the list." << id << std::endl;
|
||||
#endif
|
||||
peerState peer = it->second;
|
||||
|
||||
sslid_toRemove.push_back(it->second.id);
|
||||
|
||||
mOthersList[it->second.id] = peer;
|
||||
mStatusChanged = true;
|
||||
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
|
||||
for(std::list<RsPeerId>::iterator rit = sslid_toRemove.begin(); rit != sslid_toRemove.end(); rit++)
|
||||
if (mFriendList.end() != (it = mFriendList.find(*rit)))
|
||||
mFriendList.erase(it);
|
||||
|
||||
std::map<RsPgpId,ServicePermissionFlags>::iterator it2 = mFriendsPermissionFlags.find(id) ;
|
||||
|
||||
if(it2 != mFriendsPermissionFlags.end())
|
||||
mFriendsPermissionFlags.erase(it2);
|
||||
|
||||
#ifdef PEER_DEBUG
|
||||
std::cerr << "p3PeerMgrIMPL::removeFriend() new mFriendList.size() : " << mFriendList.size() << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
std::list<RsPeerId>::iterator rit;
|
||||
for(rit = sslid_toRemove.begin(); rit != sslid_toRemove.end(); rit++)
|
||||
{
|
||||
mLinkMgr->removeFriend(*rit);
|
||||
}
|
||||
|
||||
/* remove id from all groups */
|
||||
|
||||
std::list<RsPgpId> ids ;
|
||||
ids.push_back(id) ;
|
||||
assignPeersToGroup("", ids, false);
|
||||
|
||||
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
||||
|
||||
#ifdef PEER_DEBUG
|
||||
printPeerLists(std::cerr);
|
||||
mLinkMgr->printPeerLists(std::cerr);
|
||||
#endif
|
||||
|
||||
return !sslid_toRemove.empty();
|
||||
}
|
||||
bool p3PeerMgrIMPL::removeFriend(const RsPeerId &id, bool removePgpId)
|
||||
{
|
||||
|
||||
#ifdef PEER_DEBUG
|
||||
@ -803,21 +825,22 @@ bool p3PeerMgrIMPL::removeFriend(const std::string &id, bool removePgpId)
|
||||
std::cerr << "p3PeerMgrIMPL::removeFriend() mFriendList.size() : " << mFriendList.size() << std::endl;
|
||||
#endif
|
||||
|
||||
rslog(RSL_WARNING, p3peermgrzone, "p3PeerMgr::removeFriend() id: " + id);
|
||||
rslog(RSL_WARNING, p3peermgrzone, "p3PeerMgr::removeFriend() id: " + id.toStdString());
|
||||
|
||||
std::list<std::string> sslid_toRemove; // This is a list of SSLIds.
|
||||
std::list<std::string> pgpid_toRemove; // This is a list of SSLIds.
|
||||
std::list<RsPeerId> sslid_toRemove; // This is a list of SSLIds.
|
||||
std::list<RsPgpId> pgpid_toRemove; // This is a list of SSLIds.
|
||||
|
||||
{
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
/* move to othersList */
|
||||
bool success = false;
|
||||
std::map<std::string, peerState>::iterator it;
|
||||
std::map<RsPeerId, peerState>::iterator it;
|
||||
//remove ssl and gpg_ids
|
||||
for(it = mFriendList.begin(); it != mFriendList.end(); it++)
|
||||
{
|
||||
if (it->second.id == id || it->second.gpg_id == id) {
|
||||
if (it->second.id == id)
|
||||
{
|
||||
#ifdef PEER_DEBUG
|
||||
std::cerr << "p3PeerMgrIMPL::removeFriend() friend found in the list." << id << std::endl;
|
||||
#endif
|
||||
@ -834,14 +857,13 @@ bool p3PeerMgrIMPL::removeFriend(const std::string &id, bool removePgpId)
|
||||
}
|
||||
}
|
||||
|
||||
std::list<std::string>::iterator rit;
|
||||
for(rit = sslid_toRemove.begin(); rit != sslid_toRemove.end(); rit++)
|
||||
for(std::list<RsPeerId>::iterator rit = sslid_toRemove.begin(); rit != sslid_toRemove.end(); rit++)
|
||||
if (mFriendList.end() != (it = mFriendList.find(*rit)))
|
||||
mFriendList.erase(it);
|
||||
|
||||
std::map<std::string,ServicePermissionFlags>::iterator it2 ;
|
||||
std::map<RsPgpId,ServicePermissionFlags>::iterator it2 ;
|
||||
|
||||
for(rit = pgpid_toRemove.begin(); rit != pgpid_toRemove.end(); rit++)
|
||||
for(std::list<RsPgpId>::iterator rit = pgpid_toRemove.begin(); rit != pgpid_toRemove.end(); rit++)
|
||||
if (mFriendsPermissionFlags.end() != (it2 = mFriendsPermissionFlags.find(*rit)))
|
||||
mFriendsPermissionFlags.erase(it2);
|
||||
|
||||
@ -850,17 +872,15 @@ bool p3PeerMgrIMPL::removeFriend(const std::string &id, bool removePgpId)
|
||||
#endif
|
||||
}
|
||||
|
||||
std::list<std::string>::iterator rit;
|
||||
std::list<RsPeerId>::iterator rit;
|
||||
for(rit = sslid_toRemove.begin(); rit != sslid_toRemove.end(); rit++)
|
||||
{
|
||||
mLinkMgr->removeFriend(*rit);
|
||||
}
|
||||
|
||||
/* remove id from all groups */
|
||||
std::list<std::string> peerIds;
|
||||
peerIds.push_back(id);
|
||||
|
||||
assignPeersToGroup("", peerIds, false);
|
||||
assignPeersToGroup("", pgpid_toRemove, false);
|
||||
|
||||
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
||||
|
||||
@ -882,7 +902,7 @@ void p3PeerMgrIMPL::printPeerLists(std::ostream &out)
|
||||
out << std::endl;
|
||||
|
||||
|
||||
std::map<std::string, peerState>::iterator it;
|
||||
std::map<RsPeerId, peerState>::iterator it;
|
||||
for(it = mFriendList.begin(); it != mFriendList.end(); it++)
|
||||
{
|
||||
out << "\t SSL ID: " << it->second.id;
|
||||
@ -905,69 +925,6 @@ void p3PeerMgrIMPL::printPeerLists(std::ostream &out)
|
||||
|
||||
|
||||
|
||||
#if 0
|
||||
bool p3PeerMgrIMPL::addNeighbour(std::string id)
|
||||
{
|
||||
|
||||
#ifdef PEER_DEBUG
|
||||
std::cerr << "p3PeerMgrIMPL::addNeighbour() not implemented anymore." << id << std::endl;
|
||||
#endif
|
||||
|
||||
/* so three possibilities
|
||||
* (1) already exists as friend -> do nothing.
|
||||
* (2) already in others list -> do nothing.
|
||||
* (3) is non-existant -> create new one.
|
||||
*/
|
||||
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
std::map<std::string, peerState>::iterator it;
|
||||
if (mFriendList.end() == mFriendList.find(id))
|
||||
{
|
||||
/* (1) already exists */
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mOthersList.end() == mOthersList.find(id))
|
||||
{
|
||||
/* (2) already exists */
|
||||
return true;
|
||||
}
|
||||
|
||||
/* check with the AuthMgr if its valid */
|
||||
if (!AuthSSL::getAuthSSL()->isAuthenticated(id))
|
||||
{
|
||||
/* no auth */
|
||||
return false;
|
||||
}
|
||||
|
||||
/* get details from AuthMgr */
|
||||
sslcert detail;
|
||||
if (!AuthSSL::getAuthSSL()->getCertDetails(id, detail))
|
||||
{
|
||||
/* no details */
|
||||
return false;
|
||||
}
|
||||
|
||||
/* create a new entry */
|
||||
peerState pstate;
|
||||
|
||||
pstate.id = id;
|
||||
pstate.name = detail.name;
|
||||
|
||||
pstate.state = 0;
|
||||
pstate.actions = 0; //RS_PEER_NEW;
|
||||
pstate.visState = RS_VIS_STATE_STD;
|
||||
pstate.netMode = RS_NET_MODE_UNKNOWN;
|
||||
|
||||
/* addr & timestamps -> auto cleared */
|
||||
mOthersList[id] = pstate;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*******************************************************************/
|
||||
/*******************************************************************/
|
||||
|
||||
@ -1058,7 +1015,7 @@ bool p3PeerMgrIMPL::UpdateOwnAddress(const struct sockaddr_storage &localAddr,
|
||||
|
||||
|
||||
|
||||
bool p3PeerMgrIMPL::setLocalAddress(const std::string &id, const struct sockaddr_storage &addr)
|
||||
bool p3PeerMgrIMPL::setLocalAddress(const RsPeerId &id, const struct sockaddr_storage &addr)
|
||||
{
|
||||
bool changed = false;
|
||||
|
||||
@ -1085,7 +1042,7 @@ bool p3PeerMgrIMPL::setLocalAddress(const std::string &id, const struct socka
|
||||
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
/* check if it is a friend */
|
||||
std::map<std::string, peerState>::iterator it;
|
||||
std::map<RsPeerId, peerState>::iterator it;
|
||||
if (mFriendList.end() == (it = mFriendList.find(id)))
|
||||
{
|
||||
if (mOthersList.end() == (it = mOthersList.find(id)))
|
||||
@ -1119,7 +1076,7 @@ bool p3PeerMgrIMPL::setLocalAddress(const std::string &id, const struct socka
|
||||
return changed;
|
||||
}
|
||||
|
||||
bool p3PeerMgrIMPL::setExtAddress(const std::string &id, const struct sockaddr_storage &addr)
|
||||
bool p3PeerMgrIMPL::setExtAddress(const RsPeerId &id, const struct sockaddr_storage &addr)
|
||||
{
|
||||
bool changed = false;
|
||||
|
||||
@ -1141,7 +1098,7 @@ bool p3PeerMgrIMPL::setExtAddress(const std::string &id, const struct sockadd
|
||||
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
/* check if it is a friend */
|
||||
std::map<std::string, peerState>::iterator it;
|
||||
std::map<RsPeerId, peerState>::iterator it;
|
||||
if (mFriendList.end() == (it = mFriendList.find(id)))
|
||||
{
|
||||
if (mOthersList.end() == (it = mOthersList.find(id)))
|
||||
@ -1176,7 +1133,7 @@ bool p3PeerMgrIMPL::setExtAddress(const std::string &id, const struct sockadd
|
||||
}
|
||||
|
||||
|
||||
bool p3PeerMgrIMPL::setDynDNS(const std::string &id, const std::string &dyndns)
|
||||
bool p3PeerMgrIMPL::setDynDNS(const RsPeerId &id, const std::string &dyndns)
|
||||
{
|
||||
bool changed = false;
|
||||
|
||||
@ -1194,7 +1151,7 @@ bool p3PeerMgrIMPL::setDynDNS(const std::string &id, const std::string &dyndns)
|
||||
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
/* check if it is a friend */
|
||||
std::map<std::string, peerState>::iterator it;
|
||||
std::map<RsPeerId, peerState>::iterator it;
|
||||
if (mFriendList.end() == (it = mFriendList.find(id)))
|
||||
{
|
||||
if (mOthersList.end() == (it = mOthersList.find(id)))
|
||||
@ -1216,7 +1173,7 @@ bool p3PeerMgrIMPL::setDynDNS(const std::string &id, const std::string &dyndns)
|
||||
return changed;
|
||||
}
|
||||
|
||||
bool p3PeerMgrIMPL::updateAddressList(const std::string& id, const pqiIpAddrSet &addrs)
|
||||
bool p3PeerMgrIMPL::updateAddressList(const RsPeerId& id, const pqiIpAddrSet &addrs)
|
||||
{
|
||||
#ifdef PEER_DEBUG
|
||||
std::cerr << "p3PeerMgrIMPL::setAddressList() called for id : " << id << std::endl;
|
||||
@ -1232,7 +1189,7 @@ bool p3PeerMgrIMPL::updateAddressList(const std::string& id, const pqiIpAddrS
|
||||
}
|
||||
|
||||
/* check if it is a friend */
|
||||
std::map<std::string, peerState>::iterator it;
|
||||
std::map<RsPeerId, peerState>::iterator it;
|
||||
if (mFriendList.end() == (it = mFriendList.find(id)))
|
||||
{
|
||||
if (mOthersList.end() == (it = mOthersList.find(id)))
|
||||
@ -1261,7 +1218,7 @@ bool p3PeerMgrIMPL::updateAddressList(const std::string& id, const pqiIpAddrS
|
||||
}
|
||||
|
||||
|
||||
bool p3PeerMgrIMPL::updateCurrentAddress(const std::string& id, const pqiIpAddress &addr)
|
||||
bool p3PeerMgrIMPL::updateCurrentAddress(const RsPeerId& id, const pqiIpAddress &addr)
|
||||
{
|
||||
#ifdef PEER_DEBUG
|
||||
std::cerr << "p3PeerMgrIMPL::updateCurrentAddress() called for id : " << id << std::endl;
|
||||
@ -1272,7 +1229,7 @@ bool p3PeerMgrIMPL::updateCurrentAddress(const std::string& id, const pqiIpAd
|
||||
/* cannot be own id */
|
||||
|
||||
/* check if it is a friend */
|
||||
std::map<std::string, peerState>::iterator it;
|
||||
std::map<RsPeerId, peerState>::iterator it;
|
||||
if (mFriendList.end() == (it = mFriendList.find(id)))
|
||||
{
|
||||
if (mOthersList.end() == (it = mOthersList.find(id)))
|
||||
@ -1308,7 +1265,7 @@ bool p3PeerMgrIMPL::updateCurrentAddress(const std::string& id, const pqiIpAd
|
||||
}
|
||||
|
||||
|
||||
bool p3PeerMgrIMPL::updateLastContact(const std::string& id)
|
||||
bool p3PeerMgrIMPL::updateLastContact(const RsPeerId& id)
|
||||
{
|
||||
#ifdef PEER_DEBUG
|
||||
std::cerr << "p3PeerMgrIMPL::updateLastContact() called for id : " << id << std::endl;
|
||||
@ -1319,7 +1276,7 @@ bool p3PeerMgrIMPL::updateLastContact(const std::string& id)
|
||||
/* cannot be own id */
|
||||
|
||||
/* check if it is a friend */
|
||||
std::map<std::string, peerState>::iterator it;
|
||||
std::map<RsPeerId, peerState>::iterator it;
|
||||
if (mFriendList.end() == (it = mFriendList.find(id)))
|
||||
{
|
||||
if (mOthersList.end() == (it = mOthersList.find(id)))
|
||||
@ -1336,7 +1293,7 @@ bool p3PeerMgrIMPL::updateLastContact(const std::string& id)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3PeerMgrIMPL::setNetworkMode(const std::string &id, uint32_t netMode)
|
||||
bool p3PeerMgrIMPL::setNetworkMode(const RsPeerId &id, uint32_t netMode)
|
||||
{
|
||||
if (id == AuthSSL::getAuthSSL()->OwnId())
|
||||
{
|
||||
@ -1345,7 +1302,7 @@ bool p3PeerMgrIMPL::setNetworkMode(const std::string &id, uint32_t netMode)
|
||||
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
/* check if it is a friend */
|
||||
std::map<std::string, peerState>::iterator it;
|
||||
std::map<RsPeerId, peerState>::iterator it;
|
||||
if (mFriendList.end() == (it = mFriendList.find(id)))
|
||||
{
|
||||
if (mOthersList.end() == (it = mOthersList.find(id)))
|
||||
@ -1367,7 +1324,7 @@ bool p3PeerMgrIMPL::setNetworkMode(const std::string &id, uint32_t netMode)
|
||||
return changed;
|
||||
}
|
||||
|
||||
bool p3PeerMgrIMPL::setLocation(const std::string &id, const std::string &location)
|
||||
bool p3PeerMgrIMPL::setLocation(const RsPeerId &id, const std::string &location)
|
||||
{
|
||||
bool changed = false;
|
||||
|
||||
@ -1386,7 +1343,7 @@ bool p3PeerMgrIMPL::setLocation(const std::string &id, const std::string &loc
|
||||
}
|
||||
|
||||
/* check if it is a friend */
|
||||
std::map<std::string, peerState>::iterator it;
|
||||
std::map<RsPeerId, peerState>::iterator it;
|
||||
if (mFriendList.end() != (it = mFriendList.find(id))) {
|
||||
if (it->second.location.compare(location) != 0) {
|
||||
it->second.location = location;
|
||||
@ -1396,11 +1353,11 @@ bool p3PeerMgrIMPL::setLocation(const std::string &id, const std::string &loc
|
||||
return changed;
|
||||
}
|
||||
|
||||
bool p3PeerMgrIMPL::setVisState(const std::string &id, uint16_t vs_disc, uint16_t vs_dht)
|
||||
bool p3PeerMgrIMPL::setVisState(const RsPeerId &id, uint16_t vs_disc, uint16_t vs_dht)
|
||||
{
|
||||
{
|
||||
std::string out;
|
||||
rs_sprintf(out, "p3PeerMgr::setVisState(%s, %u, %u)", id.c_str(), vs_disc, vs_dht);
|
||||
rs_sprintf(out, "p3PeerMgr::setVisState(%s, %u, %u)", id.toStdString().c_str(), vs_disc, vs_dht);
|
||||
rslog(RSL_WARNING, p3peermgrzone, out);
|
||||
}
|
||||
|
||||
@ -1415,7 +1372,7 @@ bool p3PeerMgrIMPL::setVisState(const std::string &id, uint16_t vs_disc, uint
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
/* check if it is a friend */
|
||||
std::map<std::string, peerState>::iterator it;
|
||||
std::map<RsPeerId, peerState>::iterator it;
|
||||
if (mFriendList.end() == (it = mFriendList.find(id)))
|
||||
{
|
||||
if (mOthersList.end() == (it = mOthersList.find(id)))
|
||||
@ -1518,9 +1475,9 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
|
||||
RsPeerNetItem *item = new RsPeerNetItem();
|
||||
item->clear();
|
||||
|
||||
item->pid = getOwnId();
|
||||
item->gpg_id = mOwnState.gpg_id;
|
||||
item->location = mOwnState.location;
|
||||
item->pid = getOwnId().toStdString();
|
||||
item->gpg_id = mOwnState.gpg_id.toStdString();
|
||||
item->location = mOwnState.location;
|
||||
#if 0
|
||||
if (mOwnState.netMode & RS_NET_MODE_TRY_EXT)
|
||||
{
|
||||
@ -1563,14 +1520,14 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
|
||||
saveCleanupList.push_back(item);
|
||||
|
||||
/* iterate through all friends and save */
|
||||
std::map<std::string, peerState>::iterator it;
|
||||
std::map<RsPeerId, peerState>::iterator it;
|
||||
for(it = mFriendList.begin(); it != mFriendList.end(); it++)
|
||||
{
|
||||
item = new RsPeerNetItem();
|
||||
item->clear();
|
||||
|
||||
item->pid = it->first;
|
||||
item->gpg_id = (it->second).gpg_id;
|
||||
item->pid = it->first.toStdString();
|
||||
item->gpg_id = (it->second).gpg_id.toStdString();
|
||||
item->location = (it->second).location;
|
||||
item->netMode = (it->second).netMode;
|
||||
item->vs_disc = (it->second).vs_disc;
|
||||
@ -1602,7 +1559,7 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
|
||||
|
||||
RsPeerServicePermissionItem *sitem = new RsPeerServicePermissionItem ;
|
||||
|
||||
for(std::map<std::string,ServicePermissionFlags>::const_iterator it(mFriendsPermissionFlags.begin());it!=mFriendsPermissionFlags.end();++it)
|
||||
for(std::map<RsPgpId,ServicePermissionFlags>::const_iterator it(mFriendsPermissionFlags.begin());it!=mFriendsPermissionFlags.end();++it)
|
||||
{
|
||||
sitem->pgp_ids.push_back(it->first) ;
|
||||
sitem->service_flags.push_back(it->second) ;
|
||||
@ -1677,7 +1634,7 @@ bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
|
||||
std::cerr << "p3PeerMgrIMPL::loadList() Item Count: " << load.size() << std::endl;
|
||||
#endif
|
||||
|
||||
std::string ownId = getOwnId();
|
||||
RsPeerId ownId = getOwnId();
|
||||
|
||||
/* load the list of peers */
|
||||
std::list<RsItem *>::iterator it;
|
||||
@ -1686,7 +1643,10 @@ bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
|
||||
RsPeerNetItem *pitem = dynamic_cast<RsPeerNetItem *>(*it);
|
||||
if (pitem)
|
||||
{
|
||||
if (pitem->pid == ownId)
|
||||
RsPeerId peer_id(pitem->pid) ;
|
||||
RsPgpId peer_pgp_id(pitem->gpg_id) ;
|
||||
|
||||
if (peer_id == ownId)
|
||||
{
|
||||
#ifdef PEER_DEBUG
|
||||
std::cerr << "p3PeerMgrIMPL::loadList() Own Config Item:" << std::endl;
|
||||
@ -1708,29 +1668,29 @@ bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
/* ************* */
|
||||
addFriend(pitem->pid, pitem->gpg_id, pitem->netMode, pitem->vs_disc, pitem->vs_dht, pitem->lastContact, RS_SERVICE_PERM_ALL);
|
||||
setLocation(pitem->pid, pitem->location);
|
||||
addFriend(peer_id, peer_pgp_id, pitem->netMode, pitem->vs_disc, pitem->vs_dht, pitem->lastContact, RS_SERVICE_PERM_ALL);
|
||||
setLocation(RsPeerId(pitem->pid), pitem->location);
|
||||
}
|
||||
|
||||
if (pitem->netMode == RS_NET_MODE_HIDDEN)
|
||||
{
|
||||
/* set only the hidden stuff & localAddress */
|
||||
setLocalAddress(pitem->pid, pitem->localAddrV4.addr);
|
||||
setHiddenDomainPort(pitem->pid, pitem->domain_addr, pitem->domain_port);
|
||||
setLocalAddress(peer_id, pitem->localAddrV4.addr);
|
||||
setHiddenDomainPort(peer_id, pitem->domain_addr, pitem->domain_port);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
setLocalAddress(pitem->pid, pitem->localAddrV4.addr);
|
||||
setExtAddress(pitem->pid, pitem->extAddrV4.addr);
|
||||
setDynDNS (pitem->pid, pitem->dyndns);
|
||||
setLocalAddress(peer_id, pitem->localAddrV4.addr);
|
||||
setExtAddress(peer_id, pitem->extAddrV4.addr);
|
||||
setDynDNS (peer_id, pitem->dyndns);
|
||||
|
||||
/* convert addresses */
|
||||
pqiIpAddrSet addrs;
|
||||
addrs.mLocal.extractFromTlv(pitem->localAddrList);
|
||||
addrs.mExt.extractFromTlv(pitem->extAddrList);
|
||||
|
||||
updateAddressList(pitem->pid, addrs);
|
||||
updateAddressList(peer_id, addrs);
|
||||
}
|
||||
|
||||
delete(*it);
|
||||
@ -2062,7 +2022,7 @@ bool p3PeerMgrIMPL::getGroupInfoList(std::list<RsGroupInfo> &groupInfoList)
|
||||
}
|
||||
|
||||
// groupId == "" && assign == false -> remove from all groups
|
||||
bool p3PeerMgrIMPL::assignPeersToGroup(const std::string &groupId, const std::list<std::string> &peerIds, bool assign)
|
||||
bool p3PeerMgrIMPL::assignPeersToGroup(const std::string &groupId, const std::list<RsPgpId> &peerIds, bool assign)
|
||||
{
|
||||
if (groupId.empty() && assign == true) {
|
||||
return false;
|
||||
@ -2082,9 +2042,9 @@ bool p3PeerMgrIMPL::assignPeersToGroup(const std::string &groupId, const std::li
|
||||
if (groupId.empty() || (*groupIt)->id == groupId) {
|
||||
RsPeerGroupItem *groupItem = *groupIt;
|
||||
|
||||
std::list<std::string>::const_iterator peerIt;
|
||||
std::list<RsPgpId>::const_iterator peerIt;
|
||||
for (peerIt = peerIds.begin(); peerIt != peerIds.end(); peerIt++) {
|
||||
std::list<std::string>::iterator peerIt1 = std::find(groupItem->peerIds.begin(), groupItem->peerIds.end(), *peerIt);
|
||||
std::list<RsPgpId>::iterator peerIt1 = std::find(groupItem->peerIds.begin(), groupItem->peerIds.end(), *peerIt);
|
||||
if (assign) {
|
||||
if (peerIt1 == groupItem->peerIds.end()) {
|
||||
groupItem->peerIds.push_back(*peerIt);
|
||||
@ -2121,19 +2081,14 @@ bool p3PeerMgrIMPL::assignPeersToGroup(const std::string &groupId, const std::li
|
||||
**********************************************************************
|
||||
**********************************************************************/
|
||||
|
||||
ServicePermissionFlags p3PeerMgrIMPL::servicePermissionFlags_sslid(const std::string& ssl_id)
|
||||
ServicePermissionFlags p3PeerMgrIMPL::servicePermissionFlags(const RsPeerId& ssl_id)
|
||||
{
|
||||
std::string gpg_id ;
|
||||
RsPgpId gpg_id ;
|
||||
|
||||
{
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
if(ssl_id.length() != 32)
|
||||
{
|
||||
std::cerr << "(EE) p3PeerMgrIMPL::servicePermissionFlags_sslid() called with inconsistent id " << ssl_id << std::endl;
|
||||
return RS_SERVICE_PERM_ALL ;
|
||||
}
|
||||
std::map<std::string, peerState>::const_iterator it = mFriendList.find(ssl_id);
|
||||
std::map<RsPeerId, peerState>::const_iterator it = mFriendList.find(ssl_id);
|
||||
|
||||
if(it == mFriendList.end())
|
||||
return RS_SERVICE_PERM_ALL ;
|
||||
@ -2145,19 +2100,12 @@ ServicePermissionFlags p3PeerMgrIMPL::servicePermissionFlags_sslid(const std::st
|
||||
}
|
||||
|
||||
|
||||
ServicePermissionFlags p3PeerMgrIMPL::servicePermissionFlags(const std::string& pgp_id)
|
||||
ServicePermissionFlags p3PeerMgrIMPL::servicePermissionFlags(const RsPgpId& pgp_id)
|
||||
{
|
||||
//
|
||||
if(pgp_id.length() != 16)
|
||||
{
|
||||
std::cerr << "(EE) p3PeerMgrIMPL::servicePermissionFlags() called with inconsistent id " << pgp_id << std::endl;
|
||||
return RS_SERVICE_PERM_ALL ;
|
||||
}
|
||||
|
||||
{
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
std::map<std::string,ServicePermissionFlags>::const_iterator it = mFriendsPermissionFlags.find( pgp_id ) ;
|
||||
std::map<RsPgpId,ServicePermissionFlags>::const_iterator it = mFriendsPermissionFlags.find( pgp_id ) ;
|
||||
|
||||
if(it == mFriendsPermissionFlags.end())
|
||||
return RS_SERVICE_PERM_ALL ;
|
||||
@ -2165,18 +2113,13 @@ ServicePermissionFlags p3PeerMgrIMPL::servicePermissionFlags(const std::string&
|
||||
return it->second ;
|
||||
}
|
||||
}
|
||||
void p3PeerMgrIMPL::setServicePermissionFlags(const std::string& pgp_id, const ServicePermissionFlags& flags)
|
||||
void p3PeerMgrIMPL::setServicePermissionFlags(const RsPgpId& pgp_id, const ServicePermissionFlags& flags)
|
||||
{
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
// Check that we have a PGP id. This should not be necessary, but because
|
||||
// we use std::string, anything can get passed down here.
|
||||
//
|
||||
if(pgp_id.length() != 16)
|
||||
{
|
||||
std::cerr << "Bad parameter passed to setServicePermissionFlags(): " << pgp_id << std::endl;
|
||||
return ;
|
||||
}
|
||||
|
||||
mFriendsPermissionFlags[pgp_id] = flags ;
|
||||
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
||||
@ -2188,15 +2131,15 @@ void p3PeerMgrIMPL::setServicePermissionFlags(const std::string& pgp_id, const S
|
||||
**********************************************************************
|
||||
**********************************************************************/
|
||||
|
||||
bool p3PeerMgrIMPL::removeAllFriendLocations(const std::string &gpgid)
|
||||
bool p3PeerMgrIMPL::removeAllFriendLocations(const RsPgpId &gpgid)
|
||||
{
|
||||
std::list<std::string> sslIds;
|
||||
std::list<RsPeerId> sslIds;
|
||||
if (!getAssociatedPeers(gpgid, sslIds))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::list<std::string>::iterator it;
|
||||
std::list<RsPeerId>::iterator it;
|
||||
for(it = sslIds.begin(); it != sslIds.end(); it++)
|
||||
{
|
||||
removeFriend(*it, true);
|
||||
@ -2206,7 +2149,7 @@ bool p3PeerMgrIMPL::removeAllFriendLocations(const std::string &gpgid)
|
||||
}
|
||||
|
||||
|
||||
bool p3PeerMgrIMPL::getAssociatedPeers(const std::string &gpg_id, std::list<std::string> &ids)
|
||||
bool p3PeerMgrIMPL::getAssociatedPeers(const RsPgpId &gpg_id, std::list<RsPeerId> &ids)
|
||||
{
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
@ -2215,7 +2158,7 @@ bool p3PeerMgrIMPL::getAssociatedPeers(const std::string &gpg_id, std::list<std:
|
||||
#endif
|
||||
|
||||
int count = 0;
|
||||
std::map<std::string, peerState>::iterator it;
|
||||
std::map<RsPeerId, peerState>::iterator it;
|
||||
for(it = mFriendList.begin(); it != mFriendList.end(); it++)
|
||||
{
|
||||
if (it->second.gpg_id == gpg_id)
|
||||
@ -2236,20 +2179,20 @@ bool p3PeerMgrIMPL::getAssociatedPeers(const std::string &gpg_id, std::list<std:
|
||||
|
||||
|
||||
|
||||
/* This only removes SSL certs, that are old... Can end up with no Certs per GPG Id
|
||||
* We are removing the concept of a "DummyId" - There is no need for it.
|
||||
*/
|
||||
|
||||
bool isDummyFriend(std::string id)
|
||||
{
|
||||
bool ret = (id.substr(0,5) == "dummy");
|
||||
return ret;
|
||||
}
|
||||
// /* This only removes SSL certs, that are old... Can end up with no Certs per GPG Id
|
||||
// * We are removing the concept of a "DummyId" - There is no need for it.
|
||||
// */
|
||||
//
|
||||
// bool isDummyFriend(RsPeerId id)
|
||||
// {
|
||||
// bool ret = (id.substr(0,5) == "dummy");
|
||||
// return ret;
|
||||
// }
|
||||
|
||||
|
||||
bool p3PeerMgrIMPL::removeUnusedLocations()
|
||||
{
|
||||
std::list<std::string> toRemove;
|
||||
std::list<RsPeerId> toRemove;
|
||||
|
||||
{
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
@ -2260,7 +2203,7 @@ bool p3PeerMgrIMPL::removeUnusedLocations()
|
||||
|
||||
time_t now = time(NULL);
|
||||
|
||||
std::map<std::string, peerState>::iterator it;
|
||||
std::map<RsPeerId, peerState>::iterator it;
|
||||
for(it = mFriendList.begin(); it != mFriendList.end(); it++)
|
||||
{
|
||||
if (now - it->second.lastcontact > VERY_OLD_PEER)
|
||||
@ -2273,19 +2216,19 @@ bool p3PeerMgrIMPL::removeUnusedLocations()
|
||||
|
||||
}
|
||||
|
||||
if (isDummyFriend(it->first))
|
||||
{
|
||||
toRemove.push_back(it->first);
|
||||
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3PeerMgr::removeUnusedLocations() removing Dummy Id: " << it->first << std::endl;
|
||||
#endif
|
||||
|
||||
}
|
||||
// if (isDummyFriend(it->first))
|
||||
// {
|
||||
// toRemove.push_back(it->first);
|
||||
//
|
||||
//#ifdef P3PEERS_DEBUG
|
||||
// std::cerr << "p3PeerMgr::removeUnusedLocations() removing Dummy Id: " << it->first << std::endl;
|
||||
//#endif
|
||||
//
|
||||
// }
|
||||
|
||||
}
|
||||
}
|
||||
std::list<std::string>::iterator it;
|
||||
std::list<RsPeerId>::iterator it;
|
||||
|
||||
for(it = toRemove.begin(); it != toRemove.end(); it++)
|
||||
{
|
||||
|
@ -70,8 +70,8 @@ class peerState
|
||||
public:
|
||||
peerState(); /* init */
|
||||
|
||||
std::string id;
|
||||
std::string gpg_id;
|
||||
RsPeerId id;
|
||||
RsPgpId gpg_id;
|
||||
|
||||
uint32_t netMode; /* EXT / UPNP / UDP / HIDDEN / INVALID */
|
||||
/* visState */
|
||||
@ -114,15 +114,15 @@ class p3PeerMgr
|
||||
p3PeerMgr() { return; }
|
||||
virtual ~p3PeerMgr() { return; }
|
||||
|
||||
virtual bool addFriend(const std::string &ssl_id, const std::string &gpg_id, uint32_t netMode = RS_NET_MODE_UDP,
|
||||
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_SERVICE_PERM_ALL)) = 0;
|
||||
virtual bool removeFriend(const std::string &ssl_id, bool removePgpId) = 0;
|
||||
virtual bool removeFriend(const RsPeerId &ssl_id, bool removePgpId) = 0;
|
||||
|
||||
virtual bool isFriend(const std::string &ssl_id) = 0;
|
||||
virtual bool isFriend(const RsPeerId& ssl_id) = 0;
|
||||
|
||||
virtual bool getAssociatedPeers(const std::string &gpg_id, std::list<std::string> &ids) = 0;
|
||||
virtual bool removeAllFriendLocations(const std::string &gpgid) = 0;
|
||||
virtual bool getAssociatedPeers(const RsPgpId &gpg_id, std::list<RsPeerId> &ids) = 0;
|
||||
virtual bool removeAllFriendLocations(const RsPgpId &gpgid) = 0;
|
||||
|
||||
|
||||
/******************** Groups **********************/
|
||||
@ -133,11 +133,11 @@ virtual bool editGroup(const std::string &groupId, RsGroupInfo &groupInfo) =
|
||||
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 assignPeersToGroup(const std::string &groupId, const std::list<std::string> &peerIds, bool assign) = 0;
|
||||
virtual bool assignPeersToGroup(const std::string &groupId, const std::list<RsPgpId> &peerIds, bool assign) = 0;
|
||||
|
||||
virtual ServicePermissionFlags servicePermissionFlags(const std::string& gpg_id) =0;
|
||||
virtual ServicePermissionFlags servicePermissionFlags_sslid(const std::string& ssl_id) =0;
|
||||
virtual void setServicePermissionFlags(const std::string& gpg_id,const ServicePermissionFlags& flags) =0;
|
||||
virtual ServicePermissionFlags servicePermissionFlags(const RsPgpId& gpg_id) =0;
|
||||
virtual ServicePermissionFlags servicePermissionFlags(const RsPeerId& ssl_id) =0;
|
||||
virtual void setServicePermissionFlags(const RsPgpId& gpg_id,const ServicePermissionFlags& flags) =0;
|
||||
|
||||
/**************** Set Net Info ****************/
|
||||
/*
|
||||
@ -147,19 +147,19 @@ virtual bool assignPeersToGroup(const std::string &groupId, const std::list<s
|
||||
* 3) p3disc - reasonable
|
||||
*/
|
||||
|
||||
virtual bool setLocalAddress(const std::string &id, const struct sockaddr_storage &addr) = 0;
|
||||
virtual bool setExtAddress(const std::string &id, const struct sockaddr_storage &addr) = 0;
|
||||
virtual bool setDynDNS(const std::string &id, const std::string &dyndns) = 0;
|
||||
virtual bool setLocalAddress(const RsPeerId &id, const struct sockaddr_storage &addr) = 0;
|
||||
virtual bool setExtAddress(const RsPeerId &id, const struct sockaddr_storage &addr) = 0;
|
||||
virtual bool setDynDNS(const RsPeerId &id, const std::string &dyndns) = 0;
|
||||
|
||||
virtual bool setNetworkMode(const std::string &id, uint32_t netMode) = 0;
|
||||
virtual bool setVisState(const std::string &id, uint16_t vs_disc, uint16_t vs_dht) = 0;
|
||||
virtual bool setNetworkMode(const RsPeerId &id, uint32_t netMode) = 0;
|
||||
virtual bool setVisState(const RsPeerId &id, uint16_t vs_disc, uint16_t vs_dht) = 0;
|
||||
|
||||
virtual bool setLocation(const std::string &pid, const std::string &location) = 0;
|
||||
virtual bool setHiddenDomainPort(const std::string &id, const std::string &domain_addr, const uint16_t domain_port) = 0;
|
||||
virtual bool setLocation(const RsPeerId &pid, const std::string &location) = 0;
|
||||
virtual bool setHiddenDomainPort(const RsPeerId &id, const std::string &domain_addr, const uint16_t domain_port) = 0;
|
||||
|
||||
virtual bool updateCurrentAddress(const std::string& id, const pqiIpAddress &addr) = 0;
|
||||
virtual bool updateLastContact(const std::string& id) = 0;
|
||||
virtual bool updateAddressList(const std::string& id, const pqiIpAddrSet &addrs) = 0;
|
||||
virtual bool updateCurrentAddress(const RsPeerId& id, const pqiIpAddress &addr) = 0;
|
||||
virtual bool updateLastContact(const RsPeerId& id) = 0;
|
||||
virtual bool updateAddressList(const RsPeerId& id, const pqiIpAddrSet &addrs) = 0;
|
||||
|
||||
|
||||
// THIS MUST ONLY BE CALLED BY NETMGR!!!!
|
||||
@ -175,18 +175,18 @@ virtual bool UpdateOwnAddress(const struct sockaddr_storage &local_addr, cons
|
||||
*/
|
||||
|
||||
virtual bool getOwnNetStatus(peerState &state) = 0;
|
||||
virtual bool getFriendNetStatus(const std::string &id, peerState &state) = 0;
|
||||
virtual bool getOthersNetStatus(const std::string &id, peerState &state) = 0;
|
||||
virtual bool getFriendNetStatus(const RsPeerId &id, peerState &state) = 0;
|
||||
virtual bool getOthersNetStatus(const RsPeerId &id, peerState &state) = 0;
|
||||
|
||||
virtual bool getPeerName(const std::string &ssl_id, std::string &name) = 0;
|
||||
virtual bool getGpgId(const std::string &sslId, std::string &gpgId) = 0;
|
||||
virtual uint32_t getConnectionType(const std::string &sslId) = 0;
|
||||
virtual bool getPeerName(const RsPeerId &ssl_id, std::string &name) = 0;
|
||||
virtual bool getGpgId(const RsPeerId &sslId, RsPgpId &gpgId) = 0;
|
||||
virtual uint32_t getConnectionType(const RsPeerId &sslId) = 0;
|
||||
|
||||
virtual bool setProxyServerAddress(const struct sockaddr_storage &proxy_addr) = 0;
|
||||
virtual bool getProxyServerAddress(struct sockaddr_storage &proxy_addr) = 0;
|
||||
virtual bool isHidden() = 0;
|
||||
virtual bool isHiddenPeer(const std::string &ssl_id) = 0;
|
||||
virtual bool getProxyAddress(const std::string &ssl_id, struct sockaddr_storage &proxy_addr, std::string &domain_addr, uint16_t &domain_port) = 0;
|
||||
virtual bool isHiddenPeer(const RsPeerId &ssl_id) = 0;
|
||||
virtual bool getProxyAddress(const RsPeerId &ssl_id, struct sockaddr_storage &proxy_addr, std::string &domain_addr, uint16_t &domain_port) = 0;
|
||||
|
||||
|
||||
virtual int getFriendCount(bool ssl, bool online) = 0;
|
||||
@ -214,15 +214,16 @@ class p3PeerMgrIMPL: public p3PeerMgr, public p3Config
|
||||
/* EXTERNAL INTERFACE */
|
||||
/************************************************************************************************/
|
||||
|
||||
virtual bool addFriend(const std::string &ssl_id, const std::string &gpg_id, uint32_t netMode = RS_NET_MODE_UDP,
|
||||
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_SERVICE_PERM_ALL));
|
||||
virtual bool removeFriend(const std::string &ssl_id, bool removePgpId);
|
||||
virtual bool removeFriend(const RsPeerId &ssl_id, bool removePgpId);
|
||||
virtual bool removeFriend(const RsPgpId &pgp_id);
|
||||
|
||||
virtual bool isFriend(const std::string &ssl_id);
|
||||
virtual bool isFriend(const RsPeerId &ssl_id);
|
||||
|
||||
virtual bool getAssociatedPeers(const std::string &gpg_id, std::list<std::string> &ids);
|
||||
virtual bool removeAllFriendLocations(const std::string &gpgid);
|
||||
virtual bool getAssociatedPeers(const RsPgpId &gpg_id, std::list<RsPeerId> &ids);
|
||||
virtual bool removeAllFriendLocations(const RsPgpId &gpgid);
|
||||
|
||||
|
||||
/******************** Groups **********************/
|
||||
@ -233,11 +234,11 @@ 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<std::string> &peerIds, bool assign);
|
||||
virtual bool assignPeersToGroup(const std::string &groupId, const std::list<RsPgpId> &peerIds, bool assign);
|
||||
|
||||
virtual ServicePermissionFlags servicePermissionFlags(const std::string& gpg_id) ;
|
||||
virtual ServicePermissionFlags servicePermissionFlags_sslid(const std::string& ssl_id) ;
|
||||
virtual void setServicePermissionFlags(const std::string& gpg_id,const ServicePermissionFlags& flags) ;
|
||||
virtual ServicePermissionFlags servicePermissionFlags(const RsPgpId& gpg_id) ;
|
||||
virtual ServicePermissionFlags servicePermissionFlags(const RsPeerId& ssl_id) ;
|
||||
virtual void setServicePermissionFlags(const RsPgpId& gpg_id,const ServicePermissionFlags& flags) ;
|
||||
|
||||
/**************** Set Net Info ****************/
|
||||
/*
|
||||
@ -247,19 +248,19 @@ virtual bool assignPeersToGroup(const std::string &groupId, const std::list<s
|
||||
* 3) p3disc - reasonable
|
||||
*/
|
||||
|
||||
virtual bool setLocalAddress(const std::string &id, const struct sockaddr_storage &addr);
|
||||
virtual bool setExtAddress(const std::string &id, const struct sockaddr_storage &addr);
|
||||
virtual bool setDynDNS(const std::string &id, const std::string &dyndns);
|
||||
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 setNetworkMode(const std::string &id, uint32_t netMode);
|
||||
virtual bool setVisState(const std::string &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 std::string &pid, const std::string &location);
|
||||
virtual bool setHiddenDomainPort(const std::string &id, const std::string &domain_addr, const uint16_t domain_port);
|
||||
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 std::string& id, const pqiIpAddress &addr);
|
||||
virtual bool updateLastContact(const std::string& id);
|
||||
virtual bool updateAddressList(const std::string& id, const pqiIpAddrSet &addrs);
|
||||
virtual bool updateCurrentAddress(const RsPeerId& id, const pqiIpAddress &addr);
|
||||
virtual bool updateLastContact(const RsPeerId& id);
|
||||
virtual bool updateAddressList(const RsPeerId& id, const pqiIpAddrSet &addrs);
|
||||
|
||||
|
||||
// THIS MUST ONLY BE CALLED BY NETMGR!!!!
|
||||
@ -274,18 +275,18 @@ virtual bool UpdateOwnAddress(const struct sockaddr_storage &local_addr, cons
|
||||
*/
|
||||
|
||||
virtual bool getOwnNetStatus(peerState &state);
|
||||
virtual bool getFriendNetStatus(const std::string &id, peerState &state);
|
||||
virtual bool getOthersNetStatus(const std::string &id, peerState &state);
|
||||
virtual bool getFriendNetStatus(const RsPeerId &id, peerState &state);
|
||||
virtual bool getOthersNetStatus(const RsPeerId &id, peerState &state);
|
||||
|
||||
virtual bool getPeerName(const std::string &ssl_id, std::string &name);
|
||||
virtual bool getGpgId(const std::string &sslId, std::string &gpgId);
|
||||
virtual uint32_t getConnectionType(const std::string &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 struct sockaddr_storage &proxy_addr);
|
||||
virtual bool getProxyServerAddress(struct sockaddr_storage &proxy_addr);
|
||||
virtual bool isHidden();
|
||||
virtual bool isHiddenPeer(const std::string &ssl_id);
|
||||
virtual bool getProxyAddress(const std::string &ssl_id, struct sockaddr_storage &proxy_addr, std::string &domain_addr, uint16_t &domain_port);
|
||||
virtual bool isHiddenPeer(const RsPeerId& ssl_id);
|
||||
virtual bool getProxyAddress(const RsPeerId& ssl_id, struct sockaddr_storage &proxy_addr, std::string &domain_addr, uint16_t &domain_port);
|
||||
|
||||
virtual int getFriendCount(bool ssl, bool online);
|
||||
|
||||
@ -299,8 +300,8 @@ virtual bool haveOnceConnected();
|
||||
/* Extra IMPL Functions (used by p3LinkMgr, p3NetMgr + Setup) */
|
||||
/************************************************************************************************/
|
||||
|
||||
p3PeerMgrIMPL( const std::string& ssl_own_id,
|
||||
const std::string& gpg_own_id,
|
||||
p3PeerMgrIMPL( const RsPeerId& ssl_own_id,
|
||||
const RsPgpId& gpg_own_id,
|
||||
const std::string& gpg_own_name,
|
||||
const std::string& ssl_own_location) ;
|
||||
|
||||
@ -311,11 +312,11 @@ bool setupHiddenNode(const std::string &hiddenAddress, const uint16_t hiddenPor
|
||||
|
||||
void tick();
|
||||
|
||||
const std::string getOwnId();
|
||||
const RsPeerId& getOwnId();
|
||||
bool setOwnNetworkMode(uint32_t netMode);
|
||||
bool setOwnVisState(uint16_t vs_disc, uint16_t vs_dht);
|
||||
|
||||
int getConnectAddresses(const std::string &id,
|
||||
int getConnectAddresses(const RsPeerId &id,
|
||||
struct sockaddr_storage &lAddr, struct sockaddr_storage &eAddr,
|
||||
pqiIpAddrSet &histAddrs, std::string &dyndns);
|
||||
|
||||
@ -352,15 +353,15 @@ private:
|
||||
|
||||
peerState mOwnState;
|
||||
|
||||
std::map<std::string, peerState> mFriendList; // <SSLid , peerState>
|
||||
std::map<std::string, peerState> mOthersList;
|
||||
std::map<RsPeerId, peerState> mFriendList; // <SSLid , peerState>
|
||||
std::map<RsPeerId, peerState> mOthersList;
|
||||
|
||||
std::list<RsPeerGroupItem *> groupList;
|
||||
uint32_t lastGroupId;
|
||||
|
||||
std::list<RsItem *> saveCleanupList; /* TEMPORARY LIST WHEN SAVING */
|
||||
|
||||
std::map<std::string, ServicePermissionFlags> mFriendsPermissionFlags ; // permission flags for each gpg key
|
||||
std::map<RsPgpId, ServicePermissionFlags> mFriendsPermissionFlags ; // permission flags for each gpg key
|
||||
|
||||
struct sockaddr_storage mProxyServerAddress;
|
||||
};
|
||||
|
@ -39,6 +39,7 @@
|
||||
|
||||
/*** Base DataTypes: ****/
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "retroshare/rstypes.h"
|
||||
|
||||
|
||||
#define PQI_MIN_PORT 10 // TO ALLOW USERS TO HAVE PORT 80! - was 1024
|
||||
@ -186,7 +187,7 @@ class NetInterface;
|
||||
class PQInterface: public RateInterface
|
||||
{
|
||||
public:
|
||||
PQInterface(const std::string &id) :peerId(id) { return; }
|
||||
PQInterface(const RsPeerId &id) :peerId(id) { return; }
|
||||
virtual ~PQInterface() { return; }
|
||||
|
||||
/*!
|
||||
@ -221,7 +222,7 @@ class PQInterface: public RateInterface
|
||||
*/
|
||||
virtual int tick() { return 0; }
|
||||
virtual int status() { return 0; }
|
||||
virtual std::string PeerId() { return peerId; }
|
||||
virtual const RsPeerId& PeerId() { return peerId; }
|
||||
|
||||
// the callback from NetInterface Connection Events.
|
||||
virtual int notifyEvent(NetInterface *ni, int event, const struct sockaddr_storage &remote_peer_address)
|
||||
@ -234,7 +235,7 @@ class PQInterface: public RateInterface
|
||||
|
||||
private:
|
||||
|
||||
std::string peerId;
|
||||
RsPeerId peerId;
|
||||
};
|
||||
|
||||
|
||||
@ -300,7 +301,7 @@ virtual int close() = 0;
|
||||
/**
|
||||
* If hashing data
|
||||
**/
|
||||
virtual std::string gethash() = 0;
|
||||
virtual RsFileHash gethash() = 0;
|
||||
|
||||
/**
|
||||
* Number of bytes read/sent
|
||||
@ -353,7 +354,7 @@ public:
|
||||
/**
|
||||
* @param p_in used to notify system of connect/disconnect events
|
||||
*/
|
||||
NetInterface(PQInterface *p_in, std::string id)
|
||||
NetInterface(PQInterface *p_in, const RsPeerId& id)
|
||||
:p(p_in), peerId(id) { return; }
|
||||
|
||||
virtual ~NetInterface()
|
||||
@ -364,7 +365,7 @@ virtual int listen() = 0;
|
||||
virtual int stoplistening() = 0;
|
||||
virtual int disconnect() = 0;
|
||||
virtual int reset() = 0;
|
||||
virtual std::string PeerId() { return peerId; }
|
||||
virtual const RsPeerId& PeerId() { return peerId; }
|
||||
virtual int getConnectAddress(struct sockaddr_storage &raddr) = 0;
|
||||
|
||||
virtual bool connect_parameter(uint32_t type, uint32_t value) = 0;
|
||||
@ -376,7 +377,7 @@ PQInterface *parent() { return p; }
|
||||
|
||||
private:
|
||||
PQInterface *p;
|
||||
std::string peerId;
|
||||
RsPeerId peerId;
|
||||
};
|
||||
|
||||
//! network binary interface (abstract)
|
||||
@ -390,7 +391,7 @@ private:
|
||||
class NetBinInterface: public NetInterface, public BinInterface
|
||||
{
|
||||
public:
|
||||
NetBinInterface(PQInterface *parent, std::string id)
|
||||
NetBinInterface(PQInterface *parent, const RsPeerId& id)
|
||||
:NetInterface(parent, id)
|
||||
{ return; }
|
||||
virtual ~NetBinInterface() { return; }
|
||||
|
@ -37,6 +37,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef SUSPENDED_UNUSED_CODE
|
||||
|
||||
#include "pqi/pqiarchive.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include <iostream>
|
||||
@ -415,6 +417,6 @@ std::string pqiarchive::gethash()
|
||||
{
|
||||
return bio->gethash();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -23,7 +23,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifdef SUSPENDED_UNUSED_CODE
|
||||
|
||||
#ifndef MRK_PQI_ARCHIVE_STREAMER_HEADER
|
||||
#define MRK_PQI_ARCHIVE_STREAMER_HEADER
|
||||
@ -79,3 +79,4 @@ int readPkt(RsItem **item_out, long *ts);
|
||||
|
||||
|
||||
#endif //MRK_PQI_ARCHIVE_STREAMER_HEADER
|
||||
#endif //SUSPENDED_UNUSED_CODE
|
||||
|
@ -29,6 +29,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include "retroshare/rstypes.h"
|
||||
#include "pqi/pqinetwork.h"
|
||||
#include "pqi/pqimonitor.h"
|
||||
|
||||
@ -109,7 +110,7 @@ class pqiNetAssistPeerShare
|
||||
public:
|
||||
|
||||
/* share Addresses for various reasons (bad peers, etc) */
|
||||
virtual void updatePeer(std::string id, const struct sockaddr_storage &addr, int type, int reason, int age) = 0;
|
||||
virtual void updatePeer(const RsPeerId& id, const struct sockaddr_storage &addr, int type, int reason, int age) = 0;
|
||||
|
||||
};
|
||||
|
||||
@ -149,7 +150,7 @@ class pqiNetAssistConnect: public pqiNetAssist
|
||||
/*
|
||||
*/
|
||||
public:
|
||||
pqiNetAssistConnect(std::string id, pqiConnectCb *cb)
|
||||
pqiNetAssistConnect(const RsPeerId& id, pqiConnectCb *cb)
|
||||
:mPeerId(id), mConnCb(cb) { return; }
|
||||
|
||||
/********** External DHT Interface ************************
|
||||
@ -159,17 +160,17 @@ class pqiNetAssistConnect: public pqiNetAssist
|
||||
|
||||
|
||||
/* add / remove peers */
|
||||
virtual bool findPeer(std::string id) = 0;
|
||||
virtual bool dropPeer(std::string id) = 0;
|
||||
virtual bool findPeer(const RsPeerId& id) = 0;
|
||||
virtual bool dropPeer(const RsPeerId& id) = 0;
|
||||
|
||||
/* add non-active peers (can still toggle active/non-active via above) */
|
||||
virtual int addBadPeer(const struct sockaddr_storage &addr, uint32_t reason, uint32_t flags, uint32_t age) = 0;
|
||||
virtual int addKnownPeer(const std::string &pid, const struct sockaddr_storage &addr, uint32_t flags) = 0;
|
||||
virtual int addKnownPeer(const RsPeerId &pid, const struct sockaddr_storage &addr, uint32_t flags) = 0;
|
||||
|
||||
virtual void ConnectionFeedback(std::string pid, int mode) = 0;
|
||||
virtual void ConnectionFeedback(const RsPeerId& pid, int mode) = 0;
|
||||
|
||||
/* extract current peer status */
|
||||
virtual bool getPeerStatus(std::string id,
|
||||
virtual bool getPeerStatus(const RsPeerId& id,
|
||||
struct sockaddr_storage &laddr, struct sockaddr_storage &raddr,
|
||||
uint32_t &type, uint32_t &mode) = 0; // DEPRECIATE.
|
||||
|
||||
@ -179,7 +180,7 @@ virtual bool setAttachMode(bool on) = 0; // FIXUP.
|
||||
virtual bool getNetworkStats(uint32_t &netsize, uint32_t &localnetsize) = 0; // DEPRECIATE.
|
||||
|
||||
protected:
|
||||
std::string mPeerId;
|
||||
RsPeerId mPeerId;
|
||||
pqiConnectCb *mConnCb;
|
||||
};
|
||||
|
||||
|
@ -150,9 +150,9 @@ int BinFileInterface::readdata(void *data, int len)
|
||||
return len;
|
||||
}
|
||||
|
||||
std::string BinFileInterface::gethash()
|
||||
RsFileHash BinFileInterface::gethash()
|
||||
{
|
||||
std::string hashstr;
|
||||
RsFileHash hashstr;
|
||||
if (bin_flags & BIN_FLAGS_HASH_DATA)
|
||||
{
|
||||
hash->Complete(hashstr);
|
||||
@ -410,9 +410,9 @@ int BinMemInterface::readdata(void *data, int len)
|
||||
|
||||
|
||||
|
||||
std::string BinMemInterface::gethash()
|
||||
RsFileHash BinMemInterface::gethash()
|
||||
{
|
||||
std::string hashstr;
|
||||
RsFileHash hashstr;
|
||||
if (bin_flags & BIN_FLAGS_HASH_DATA)
|
||||
{
|
||||
hash->Complete(hashstr);
|
||||
@ -493,7 +493,7 @@ bool BinMemInterface::readfromfile(const char *fname)
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
void printNetBinID(std::ostream &out, std::string id, uint32_t t)
|
||||
void printNetBinID(std::ostream &out, const RsPeerId& id, uint32_t t)
|
||||
{
|
||||
out << "NetBinId(" << id << ",";
|
||||
if (t == PQI_CONNECT_TCP)
|
||||
@ -520,9 +520,8 @@ void printNetBinID(std::ostream &out, std::string id, uint32_t t)
|
||||
|
||||
const uint32_t DEFAULT_DUMMY_DELTA = 5;
|
||||
|
||||
NetBinDummy::NetBinDummy(PQInterface *parent, std::string id, uint32_t t)
|
||||
:NetBinInterface(parent, id), type(t), dummyConnected(false),
|
||||
toConnect(false), connectDelta(DEFAULT_DUMMY_DELTA)
|
||||
NetBinDummy::NetBinDummy(PQInterface *parent, const RsPeerId& id, uint32_t t)
|
||||
:NetBinInterface(parent, id), type(t), dummyConnected(false), toConnect(false), connectDelta(DEFAULT_DUMMY_DELTA)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -717,12 +716,12 @@ int NetBinDummy::close()
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string NetBinDummy::gethash()
|
||||
RsFileHash NetBinDummy::gethash()
|
||||
{
|
||||
std::cerr << "NetBinDummy::gethash() ";
|
||||
printNetBinID(std::cerr, PeerId(), type);
|
||||
std::cerr << std::endl;
|
||||
|
||||
return std::string("");
|
||||
return RsFileHash();
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,7 @@ virtual bool cansend(uint32_t /* usec */)
|
||||
virtual bool bandwidthLimited() { return false; }
|
||||
|
||||
//! if HASHing is switched on
|
||||
virtual std::string gethash();
|
||||
virtual RsFileHash gethash();
|
||||
virtual uint64_t bytecount();
|
||||
|
||||
protected:
|
||||
@ -178,7 +178,7 @@ virtual bool cansend(uint32_t /* usec */)
|
||||
}
|
||||
virtual bool bandwidthLimited() { return false; }
|
||||
|
||||
virtual std::string gethash();
|
||||
virtual RsFileHash gethash();
|
||||
virtual uint64_t bytecount();
|
||||
|
||||
private:
|
||||
@ -195,7 +195,7 @@ virtual uint64_t bytecount();
|
||||
class NetBinDummy: public NetBinInterface
|
||||
{
|
||||
public:
|
||||
NetBinDummy(PQInterface *parent, std::string id, uint32_t t);
|
||||
NetBinDummy(PQInterface *parent, const RsPeerId& id, uint32_t t);
|
||||
virtual ~NetBinDummy() { return; }
|
||||
|
||||
// Net Interface
|
||||
@ -227,7 +227,7 @@ virtual bool moretoread(uint32_t usec);
|
||||
virtual bool cansend(uint32_t usec);
|
||||
virtual int close();
|
||||
|
||||
virtual std::string gethash();
|
||||
virtual RsFileHash gethash();
|
||||
|
||||
private:
|
||||
uint32_t type;
|
||||
|
@ -69,7 +69,7 @@ int pqihandler::tick()
|
||||
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
|
||||
|
||||
// tick all interfaces...
|
||||
std::map<std::string, SearchModule *>::iterator it;
|
||||
std::map<RsPeerId, SearchModule *>::iterator it;
|
||||
for(it = mods.begin(); it != mods.end(); it++)
|
||||
{
|
||||
if (0 < ((it -> second) -> pqi) -> tick())
|
||||
@ -113,7 +113,7 @@ bool pqihandler::queueOutRsItem(RsItem *item)
|
||||
|
||||
int pqihandler::status()
|
||||
{
|
||||
std::map<std::string, SearchModule *>::iterator it;
|
||||
std::map<RsPeerId, SearchModule *>::iterator it;
|
||||
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
|
||||
|
||||
{ // for output
|
||||
@ -122,7 +122,7 @@ int pqihandler::status()
|
||||
// display all interfaces...
|
||||
for(it = mods.begin(); it != mods.end(); it++)
|
||||
{
|
||||
rs_sprintf_append(out, "\tModule [%s] Pointer <%p>", it -> first.c_str(), (void *) ((it -> second) -> pqi));
|
||||
rs_sprintf_append(out, "\tModule [%s] Pointer <%p>", it -> first.toStdString().c_str(), (void *) ((it -> second) -> pqi));
|
||||
}
|
||||
|
||||
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone, out);
|
||||
@ -142,7 +142,7 @@ bool pqihandler::AddSearchModule(SearchModule *mod)
|
||||
{
|
||||
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
|
||||
// if peerid used -> error.
|
||||
std::map<std::string, SearchModule *>::iterator it;
|
||||
std::map<RsPeerId, SearchModule *>::iterator it;
|
||||
if (mod->peerid != mod->pqi->PeerId())
|
||||
{
|
||||
// ERROR!
|
||||
@ -150,7 +150,7 @@ bool pqihandler::AddSearchModule(SearchModule *mod)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mod->peerid == "")
|
||||
if (mod->peerid.isNull())
|
||||
{
|
||||
// ERROR!
|
||||
pqioutput(PQL_ALERT, pqihandlerzone, "ERROR peerid == NULL");
|
||||
@ -182,7 +182,7 @@ bool pqihandler::AddSearchModule(SearchModule *mod)
|
||||
bool pqihandler::RemoveSearchModule(SearchModule *mod)
|
||||
{
|
||||
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
|
||||
std::map<std::string, SearchModule *>::iterator it;
|
||||
std::map<RsPeerId, SearchModule *>::iterator it;
|
||||
for(it = mods.begin(); it != mods.end(); it++)
|
||||
{
|
||||
if (mod == it -> second)
|
||||
@ -208,7 +208,7 @@ int pqihandler::locked_checkOutgoingRsItem(RsItem * /*item*/, int /*global*/)
|
||||
int pqihandler::locked_HandleRsItem(RsItem *item, int allowglobal,uint32_t& computed_size)
|
||||
{
|
||||
computed_size = 0 ;
|
||||
std::map<std::string, SearchModule *>::iterator it;
|
||||
std::map<RsPeerId, SearchModule *>::iterator it;
|
||||
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone,
|
||||
"pqihandler::HandleRsItem()");
|
||||
|
||||
@ -261,7 +261,7 @@ int pqihandler::locked_HandleRsItem(RsItem *item, int allowglobal,uint32_t& comp
|
||||
// check security... is output allowed.
|
||||
if(0 < secpolicy_check((it -> second) -> sp, 0, PQI_OUTGOING))
|
||||
{
|
||||
std::string out = "pqihandler::HandleRsItem() sending to chan: " + it -> first;
|
||||
std::string out = "pqihandler::HandleRsItem() sending to chan: " + it -> first.toStdString();
|
||||
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone, out);
|
||||
#ifdef DEBUG_TICK
|
||||
std::cerr << out << std::endl;
|
||||
@ -302,7 +302,7 @@ int pqihandler::SendRsRawItem(RsRawItem *ns)
|
||||
|
||||
int pqihandler::locked_GetItems()
|
||||
{
|
||||
std::map<std::string, SearchModule *>::iterator it;
|
||||
std::map<RsPeerId, SearchModule *>::iterator it;
|
||||
|
||||
RsItem *item;
|
||||
int count = 0;
|
||||
@ -410,7 +410,7 @@ RsRawItem *pqihandler::GetRsRawItem()
|
||||
static const float MIN_RATE = 0.01; // 10 B/s
|
||||
|
||||
// NEW extern fn to extract rates.
|
||||
int pqihandler::ExtractRates(std::map<std::string, RsBwRates> &ratemap, RsBwRates &total)
|
||||
int pqihandler::ExtractRates(std::map<RsPeerId, RsBwRates> &ratemap, RsBwRates &total)
|
||||
{
|
||||
total.mMaxRateIn = getMaxRate(true);
|
||||
total.mMaxRateOut = getMaxRate(false);
|
||||
@ -422,7 +422,7 @@ int pqihandler::ExtractRates(std::map<std::string, RsBwRates> &ratemap, RsBw
|
||||
/* Lock once rates have been retrieved */
|
||||
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
|
||||
|
||||
std::map<std::string, SearchModule *>::iterator it;
|
||||
std::map<RsPeerId, SearchModule *>::iterator it;
|
||||
for(it = mods.begin(); it != mods.end(); it++)
|
||||
{
|
||||
SearchModule *mod = (it -> second);
|
||||
@ -447,7 +447,7 @@ int pqihandler::ExtractRates(std::map<std::string, RsBwRates> &ratemap, RsBw
|
||||
// internal fn to send updates
|
||||
int pqihandler::UpdateRates()
|
||||
{
|
||||
std::map<std::string, SearchModule *>::iterator it;
|
||||
std::map<RsPeerId, SearchModule *>::iterator it;
|
||||
int num_sm = mods.size();
|
||||
|
||||
float avail_in = getMaxRate(true);
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "pqi/pqiqos.h"
|
||||
|
||||
#include "util/rsthreads.h"
|
||||
#include "retroshare/rstypes.h"
|
||||
|
||||
#include <map>
|
||||
#include <list>
|
||||
@ -38,7 +39,7 @@
|
||||
class SearchModule
|
||||
{
|
||||
public:
|
||||
std::string peerid;
|
||||
RsPeerId peerid;
|
||||
PQInterface *pqi;
|
||||
SecurityPolicy *sp;
|
||||
};
|
||||
@ -75,7 +76,7 @@ class pqihandler: public P3Interface, public pqiPublisher
|
||||
void getCurrentRates(float &in, float &out);
|
||||
|
||||
// TESTING INTERFACE.
|
||||
int ExtractRates(std::map<std::string, RsBwRates> &ratemap, RsBwRates &totals);
|
||||
int ExtractRates(std::map<RsPeerId, RsBwRates> &ratemap, RsBwRates &totals);
|
||||
|
||||
protected:
|
||||
/* check to be overloaded by those that can
|
||||
@ -91,7 +92,7 @@ class pqihandler: public P3Interface, public pqiPublisher
|
||||
|
||||
RsMutex coreMtx; /* MUTEX */
|
||||
|
||||
std::map<std::string, SearchModule *> mods;
|
||||
std::map<RsPeerId, SearchModule *> mods;
|
||||
SecurityPolicy *globsec;
|
||||
|
||||
std::list<RsItem *> in_service;
|
||||
|
@ -26,7 +26,7 @@
|
||||
#ifndef PQI_HASH_
|
||||
#define PQI_HASH_
|
||||
|
||||
#include <util/rsid.h>
|
||||
#include <retroshare/rsids.h>
|
||||
#include <openssl/sha.h>
|
||||
#include <string>
|
||||
#include <iomanip>
|
||||
@ -63,7 +63,7 @@ void addData(const void *data, uint32_t len)
|
||||
}
|
||||
}
|
||||
|
||||
void Complete(std::string &hash)
|
||||
void Complete(RsFileHash &hash)
|
||||
{
|
||||
if (!doHash)
|
||||
{
|
||||
@ -74,8 +74,7 @@ void Complete(std::string &hash)
|
||||
SHA1_Final(sha_hash, sha_ctx);
|
||||
|
||||
endHash.clear();
|
||||
|
||||
endHash = hash = Sha1CheckSum(sha_hash).toStdString() ;
|
||||
endHash = hash = Sha1CheckSum(sha_hash);
|
||||
|
||||
// for(int i = 0; i < SHA_DIGEST_LENGTH; i++)
|
||||
// {
|
||||
@ -90,7 +89,7 @@ void Complete(std::string &hash)
|
||||
private:
|
||||
|
||||
bool doHash;
|
||||
std::string endHash;
|
||||
RsFileHash endHash;
|
||||
uint8_t *sha_hash;
|
||||
SHA_CTX *sha_ctx;
|
||||
};
|
||||
|
@ -30,7 +30,7 @@
|
||||
#define LOOPBACK_DEBUG 1
|
||||
***/
|
||||
|
||||
pqiloopback::pqiloopback(std::string id)
|
||||
pqiloopback::pqiloopback(const RsPeerId& id)
|
||||
:PQInterface(id)
|
||||
{
|
||||
setMaxRate(true, 0);
|
||||
|
@ -36,7 +36,7 @@
|
||||
class pqiloopback: public PQInterface
|
||||
{
|
||||
public:
|
||||
pqiloopback(std::string id);
|
||||
pqiloopback(const RsPeerId& id);
|
||||
virtual ~pqiloopback();
|
||||
|
||||
// search Interface.
|
||||
|
@ -44,7 +44,7 @@ pqiConnectCbDummy::~pqiConnectCbDummy()
|
||||
return;
|
||||
}
|
||||
|
||||
void pqiConnectCbDummy::peerStatus(std::string id, const pqiIpAddrSet &addrs,
|
||||
void pqiConnectCbDummy::peerStatus(const RsPeerId& id, const pqiIpAddrSet &addrs,
|
||||
uint32_t type, uint32_t mode, uint32_t source)
|
||||
{
|
||||
std::cerr << "pqiConnectCbDummy::peerStatus()";
|
||||
@ -61,7 +61,7 @@ void pqiConnectCbDummy::peerStatus(std::string id, const pqiIpAddrSet &addrs,
|
||||
std::cerr << out << std::endl;
|
||||
}
|
||||
|
||||
void pqiConnectCbDummy::peerConnectRequest(std::string id,
|
||||
void pqiConnectCbDummy::peerConnectRequest(const RsPeerId& id,
|
||||
const struct sockaddr_storage &raddr, uint32_t source)
|
||||
{
|
||||
std::cerr << "pqiConnectCbDummy::peerConnectRequest()";
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include "pqi/pqiipset.h"
|
||||
#include "retroshare/rstypes.h"
|
||||
|
||||
/************** Define Type/Mode/Source ***************/
|
||||
|
||||
@ -96,11 +97,11 @@ const uint32_t RS_STUN_FRIEND_OF_FRIEND = 0x0040;
|
||||
|
||||
class pqipeer
|
||||
{
|
||||
public:
|
||||
std::string id;
|
||||
std::string name;
|
||||
uint32_t state;
|
||||
uint32_t actions;
|
||||
public:
|
||||
RsPeerId id;
|
||||
std::string name;
|
||||
uint32_t state;
|
||||
uint32_t actions;
|
||||
};
|
||||
|
||||
class p3LinkMgr;
|
||||
@ -153,10 +154,10 @@ class pqiConnectCb
|
||||
{
|
||||
public:
|
||||
virtual ~pqiConnectCb() { return; }
|
||||
virtual void peerStatus(std::string id, const pqiIpAddrSet &addrs,
|
||||
virtual void peerStatus(const RsPeerId& id, const pqiIpAddrSet &addrs,
|
||||
uint32_t type, uint32_t flags, uint32_t source) = 0;
|
||||
|
||||
virtual void peerConnectRequest(std::string id, const struct sockaddr_storage &raddr,
|
||||
virtual void peerConnectRequest(const RsPeerId& id, const struct sockaddr_storage &raddr,
|
||||
const struct sockaddr_storage &proxyaddr, const struct sockaddr_storage &srcaddr,
|
||||
uint32_t source, uint32_t flags, uint32_t delay, uint32_t bandwidth) = 0;
|
||||
|
||||
@ -170,10 +171,10 @@ class pqiConnectCbDummy: public pqiConnectCb
|
||||
public:
|
||||
pqiConnectCbDummy();
|
||||
virtual ~pqiConnectCbDummy();
|
||||
virtual void peerStatus(std::string id, const pqiIpAddrSet &addrs,
|
||||
virtual void peerStatus(const RsPeerId& id, const pqiIpAddrSet &addrs,
|
||||
uint32_t type, uint32_t mode, uint32_t source);
|
||||
|
||||
virtual void peerConnectRequest(std::string id,
|
||||
virtual void peerConnectRequest(const RsPeerId& id,
|
||||
const struct sockaddr_storage &raddr, uint32_t source);
|
||||
|
||||
//virtual void stunStatus(std::string id, const struct sockaddr_storage &raddr, uint32_t type, uint32_t flags);
|
||||
|
@ -38,7 +38,7 @@ const int pqipersonzone = 82371;
|
||||
* #define PERSON_DEBUG 1
|
||||
****/
|
||||
|
||||
pqiperson::pqiperson(std::string id, pqipersongrp *pg)
|
||||
pqiperson::pqiperson(const RsPeerId& id, pqipersongrp *pg)
|
||||
:PQInterface(id), mNotifyMtx("pqiperson-notify"), mPersonMtx("pqiperson"),
|
||||
active(false), activepqi(NULL),
|
||||
inConnectAttempt(false), waittimes(0),
|
||||
@ -102,8 +102,10 @@ RsItem *pqiperson::GetItem()
|
||||
|
||||
bool pqiperson::RecvItem(RsItem *item)
|
||||
{
|
||||
#ifdef PERSON_DEBUG
|
||||
std::cerr << "pqiperson::RecvItem()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
return pqipg->recvItem((RsRawItem *) item);
|
||||
}
|
||||
@ -122,7 +124,7 @@ int pqiperson::receiveHeartbeat()
|
||||
{
|
||||
RsStackMutex stack(mPersonMtx); /**** LOCK MUTEX ****/
|
||||
|
||||
pqioutput(PQL_WARNING, pqipersonzone, "pqiperson::receiveHeartbeat() from peer : " + PeerId());
|
||||
pqioutput(PQL_WARNING, pqipersonzone, "pqiperson::receiveHeartbeat() from peer : " + PeerId().toStdString());
|
||||
lastHeartbeatReceived = time(NULL);
|
||||
|
||||
return true ;
|
||||
@ -140,7 +142,7 @@ int pqiperson::tick()
|
||||
(time(NULL) - lastHeartbeatReceived) > HEARTBEAT_REPEAT_TIME * 5)
|
||||
{
|
||||
int ageLastIncoming = time(NULL) - activepqi->getLastIncomingTS();
|
||||
std::string out = "pqiperson::tick() WARNING No heartbeat from: " + PeerId();
|
||||
std::string out = "pqiperson::tick() WARNING No heartbeat from: " + PeerId().toStdString();
|
||||
//out << " assume dead. calling pqissl::reset(), LastHeartbeat was: ";
|
||||
rs_sprintf_append(out, " LastHeartbeat was: %ld secs ago", time(NULL) - lastHeartbeatReceived);
|
||||
rs_sprintf_append(out, " LastIncoming was: %d secs ago", ageLastIncoming);
|
||||
@ -150,7 +152,7 @@ int pqiperson::tick()
|
||||
|
||||
if (ageLastIncoming > NO_PACKET_TIMEOUT)
|
||||
{
|
||||
out = "pqiperson::tick() " + PeerId();
|
||||
out = "pqiperson::tick() " + PeerId().toStdString();
|
||||
out += " No Heartbeat & No Packets -> assume dead. calling pqissl::reset()";
|
||||
pqioutput(PQL_WARNING, pqipersonzone, out);
|
||||
|
||||
@ -161,7 +163,7 @@ int pqiperson::tick()
|
||||
|
||||
|
||||
{
|
||||
std::string out = "pqiperson::tick() Id: " + PeerId() + " ";
|
||||
std::string out = "pqiperson::tick() Id: " + PeerId().toStdString() + " ";
|
||||
if (active)
|
||||
out += "***Active***";
|
||||
else
|
||||
@ -255,7 +257,7 @@ int pqiperson::handleNotifyEvent_locked(NetInterface *ni, int newState, const s
|
||||
{
|
||||
|
||||
{
|
||||
std::string out = "pqiperson::notifyEvent() Id: " + PeerId() + "\n";
|
||||
std::string out = "pqiperson::notifyEvent() Id: " + PeerId().toStdString() + "\n";
|
||||
rs_sprintf_append(out, "Message: %d from: %p\n", newState, ni);
|
||||
rs_sprintf_append(out, "Active pqi : %p", activepqi);
|
||||
|
||||
@ -303,7 +305,7 @@ int pqiperson::handleNotifyEvent_locked(NetInterface *ni, int newState, const s
|
||||
|
||||
if ((active) && (activepqi != pqi)) // already connected - trouble
|
||||
{
|
||||
pqioutput(PQL_WARNING, pqipersonzone, "pqiperson::notifyEvent() Id: " + PeerId() + " CONNECT_SUCCESS+active-> activing new connection, shutting others");
|
||||
pqioutput(PQL_WARNING, pqipersonzone, "pqiperson::notifyEvent() Id: " + PeerId().toStdString() + " CONNECT_SUCCESS+active-> activing new connection, shutting others");
|
||||
|
||||
// This is the RESET that's killing the connections.....
|
||||
//activepqi -> reset();
|
||||
@ -315,7 +317,7 @@ int pqiperson::handleNotifyEvent_locked(NetInterface *ni, int newState, const s
|
||||
/* now install a new one. */
|
||||
{
|
||||
|
||||
pqioutput(PQL_WARNING, pqipersonzone, "pqiperson::notifyEvent() Id: " + PeerId() + " CONNECT_SUCCESS->marking so! (resetting others)");
|
||||
pqioutput(PQL_WARNING, pqipersonzone, "pqiperson::notifyEvent() Id: " + PeerId().toStdString() + " CONNECT_SUCCESS->marking so! (resetting others)");
|
||||
|
||||
// mark as active.
|
||||
active = true;
|
||||
@ -350,7 +352,7 @@ int pqiperson::handleNotifyEvent_locked(NetInterface *ni, int newState, const s
|
||||
{
|
||||
if (activepqi == pqi)
|
||||
{
|
||||
pqioutput(PQL_WARNING, pqipersonzone, "pqiperson::notifyEvent() Id: " + PeerId() + " CONNECT_FAILED->marking so!");
|
||||
pqioutput(PQL_WARNING, pqipersonzone, "pqiperson::notifyEvent() Id: " + PeerId().toStdString() + " CONNECT_FAILED->marking so!");
|
||||
|
||||
activepqi->stop(); // STOP THREAD.
|
||||
active = false;
|
||||
@ -358,12 +360,12 @@ int pqiperson::handleNotifyEvent_locked(NetInterface *ni, int newState, const s
|
||||
}
|
||||
else
|
||||
{
|
||||
pqioutput(PQL_WARNING, pqipersonzone, "pqiperson::notifyEvent() Id: " + PeerId() + " CONNECT_FAILED-> from an unactive connection, don't flag the peer as not connected, just try next attempt !");
|
||||
pqioutput(PQL_WARNING, pqipersonzone, "pqiperson::notifyEvent() Id: " + PeerId().toStdString() + " CONNECT_FAILED-> from an unactive connection, don't flag the peer as not connected, just try next attempt !");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pqioutput(PQL_WARNING, pqipersonzone, "pqiperson::notifyEvent() Id: " + PeerId() + " CONNECT_FAILED+NOT active -> try connect again");
|
||||
pqioutput(PQL_WARNING, pqipersonzone, "pqiperson::notifyEvent() Id: " + PeerId().toStdString() + " CONNECT_FAILED+NOT active -> try connect again");
|
||||
}
|
||||
|
||||
/* notify up */
|
||||
@ -392,7 +394,7 @@ int pqiperson::reset()
|
||||
|
||||
int pqiperson::reset_locked()
|
||||
{
|
||||
pqioutput(PQL_WARNING, pqipersonzone, "pqiperson::reset() resetting all pqiconnect for Id: " + PeerId());
|
||||
pqioutput(PQL_WARNING, pqipersonzone, "pqiperson::reset() resetting all pqiconnect for Id: " + PeerId().toStdString());
|
||||
|
||||
std::map<uint32_t, pqiconnect *>::iterator it;
|
||||
for(it = kids.begin(); it != kids.end(); it++)
|
||||
@ -412,7 +414,7 @@ int pqiperson::fullstopthreads()
|
||||
{
|
||||
RsStackMutex stack(mPersonMtx); /**** LOCK MUTEX ****/
|
||||
|
||||
pqioutput(PQL_WARNING, pqipersonzone, "pqiperson::fullstopthreads() for Id: " + PeerId());
|
||||
pqioutput(PQL_WARNING, pqipersonzone, "pqiperson::fullstopthreads() for Id: " + PeerId().toStdString());
|
||||
|
||||
std::map<uint32_t, pqiconnect *>::iterator it;
|
||||
for(it = kids.begin(); it != kids.end(); it++)
|
||||
@ -433,7 +435,7 @@ int pqiperson::addChildInterface(uint32_t type, pqiconnect *pqi)
|
||||
|
||||
{
|
||||
std::string out;
|
||||
rs_sprintf(out, "pqiperson::addChildInterface() : Id %s %u", PeerId().c_str(), type);
|
||||
rs_sprintf(out, "pqiperson::addChildInterface() : Id %s %u", PeerId().toStdString().c_str(), type);
|
||||
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out);
|
||||
}
|
||||
|
||||
@ -449,7 +451,7 @@ int pqiperson::listen()
|
||||
{
|
||||
RsStackMutex stack(mPersonMtx); /**** LOCK MUTEX ****/
|
||||
|
||||
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, "pqiperson::listen() Id: " + PeerId());
|
||||
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, "pqiperson::listen() Id: " + PeerId().toStdString());
|
||||
|
||||
if (!active)
|
||||
{
|
||||
@ -468,7 +470,7 @@ int pqiperson::stoplistening()
|
||||
{
|
||||
RsStackMutex stack(mPersonMtx); /**** LOCK MUTEX ****/
|
||||
|
||||
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, "pqiperson::stoplistening() Id: " + PeerId());
|
||||
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, "pqiperson::stoplistening() Id: " + PeerId().toStdString());
|
||||
|
||||
std::map<uint32_t, pqiconnect *>::iterator it;
|
||||
for(it = kids.begin(); it != kids.end(); it++)
|
||||
@ -489,7 +491,7 @@ int pqiperson::connect(uint32_t type, const struct sockaddr_storage &raddr,
|
||||
#ifdef PERSON_DEBUG
|
||||
#endif
|
||||
{
|
||||
std::string out = "pqiperson::connect() Id: " + PeerId();
|
||||
std::string out = "pqiperson::connect() Id: " + PeerId().toStdString();
|
||||
rs_sprintf_append(out, " type: %u", type);
|
||||
out += " addr: ";
|
||||
out += sockaddr_storage_tostring(raddr);
|
||||
|
@ -82,7 +82,7 @@ virtual bool connect_additional_address(uint32_t type, const struct sockaddr_st
|
||||
virtual int getConnectAddress(struct sockaddr_storage &raddr){ return ni->getConnectAddress(raddr); }
|
||||
|
||||
// get the contact from the net side!
|
||||
virtual std::string PeerId()
|
||||
virtual const RsPeerId& PeerId()
|
||||
{
|
||||
if (ni)
|
||||
{
|
||||
@ -126,7 +126,7 @@ class NotifyData
|
||||
class pqiperson: public PQInterface
|
||||
{
|
||||
public:
|
||||
pqiperson(std::string id, pqipersongrp *ppg);
|
||||
pqiperson(const RsPeerId& id, pqipersongrp *ppg);
|
||||
virtual ~pqiperson(); // must clean up children.
|
||||
|
||||
// control of the connection.
|
||||
|
@ -36,7 +36,7 @@ const int pqipersongrpzone = 354;
|
||||
///////////////////////////////////////////////////////////
|
||||
// hack for too many connections
|
||||
#include "retroshare/rsinit.h"
|
||||
static std::list<std::string> waitingIds;
|
||||
static std::list<RsPeerId> waitingIds;
|
||||
#define MAX_CONNECT_COUNT 3
|
||||
///////////////////////////////////////////////////////////
|
||||
#endif
|
||||
@ -320,7 +320,7 @@ void pqipersongrp::statusChanged()
|
||||
|
||||
/* check for active connections and start waiting id's */
|
||||
long connect_count = 0;
|
||||
std::list<std::string> toConnect;
|
||||
std::list<RsPeerId> toConnect;
|
||||
|
||||
{
|
||||
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
|
||||
@ -331,11 +331,11 @@ void pqipersongrp::statusChanged()
|
||||
}
|
||||
|
||||
/* check for active connections and start waiting id's */
|
||||
std::list<std::string> peers;
|
||||
std::list<RsPeerId> peers;
|
||||
mLinkMgr->getFriendList(peers);
|
||||
|
||||
/* count connection attempts */
|
||||
std::list<std::string>::iterator peer;
|
||||
std::list<RsPeerId>::iterator peer;
|
||||
for (peer = peers.begin(); peer != peers.end(); peer++) {
|
||||
peerConnectState state;
|
||||
if (mLinkMgr->getFriendNetStatus(*peer, state) == false) {
|
||||
@ -367,7 +367,7 @@ void pqipersongrp::statusChanged()
|
||||
if (waitingIds.empty()) {
|
||||
break;
|
||||
}
|
||||
std::string waitingId = waitingIds.front();
|
||||
RsPeerId waitingId = waitingIds.front();
|
||||
waitingIds.pop_front();
|
||||
|
||||
#ifdef PGRP_DEBUG
|
||||
@ -379,7 +379,7 @@ void pqipersongrp::statusChanged()
|
||||
}
|
||||
} /* UNLOCKED */
|
||||
|
||||
std::list<std::string>::iterator cit;
|
||||
std::list<RsPeerId>::iterator cit;
|
||||
for(cit = toConnect.begin(); cit != toConnect.end(); cit++)
|
||||
{
|
||||
connectPeer(*cit, true);
|
||||
@ -388,11 +388,11 @@ void pqipersongrp::statusChanged()
|
||||
///////////////////////////////////////////////////////////
|
||||
#endif
|
||||
|
||||
bool pqipersongrp::getCryptoParams(const std::string& id,RsPeerCryptoParams& params)
|
||||
bool pqipersongrp::getCryptoParams(const RsPeerId& id,RsPeerCryptoParams& params)
|
||||
{
|
||||
RsStackMutex stack(coreMtx); /******* LOCKED MUTEX **********/
|
||||
|
||||
std::map<std::string, SearchModule *>::iterator it = mods.find(id) ;
|
||||
std::map<RsPeerId, SearchModule *>::iterator it = mods.find(id) ;
|
||||
|
||||
if(it == mods.end())
|
||||
return false ;
|
||||
@ -402,9 +402,9 @@ bool pqipersongrp::getCryptoParams(const std::string& id,RsPeerCryptoParams& par
|
||||
//return locked_getCryptoParams(id,params) ;
|
||||
}
|
||||
|
||||
int pqipersongrp::addPeer(std::string id)
|
||||
int pqipersongrp::addPeer(const RsPeerId& id)
|
||||
{
|
||||
pqioutput(PQL_DEBUG_BASIC, pqipersongrpzone, "pqipersongrp::addPeer() PeerId: " + id);
|
||||
pqioutput(PQL_DEBUG_BASIC, pqipersongrpzone, "pqipersongrp::addPeer() PeerId: " + id.toStdString());
|
||||
|
||||
std::cerr << "pqipersongrp::addPeer() id: " << id;
|
||||
std::cerr << std::endl;
|
||||
@ -435,9 +435,9 @@ int pqipersongrp::addPeer(std::string id)
|
||||
}
|
||||
|
||||
|
||||
int pqipersongrp::removePeer(std::string id)
|
||||
int pqipersongrp::removePeer(const RsPeerId& id)
|
||||
{
|
||||
std::map<std::string, SearchModule *>::iterator it;
|
||||
std::map<RsPeerId, SearchModule *>::iterator it;
|
||||
|
||||
#ifdef PGRP_DEBUG
|
||||
#endif
|
||||
@ -467,9 +467,9 @@ int pqipersongrp::removePeer(std::string id)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int pqipersongrp::tagHeartbeatRecvd(std::string id)
|
||||
int pqipersongrp::tagHeartbeatRecvd(const RsPeerId& id)
|
||||
{
|
||||
std::map<std::string, SearchModule *>::iterator it;
|
||||
std::map<RsPeerId, SearchModule *>::iterator it;
|
||||
|
||||
#ifdef PGRP_DEBUG
|
||||
std::cerr << " pqipersongrp::tagHeartbeatRecvd() id: " << id;
|
||||
@ -494,7 +494,7 @@ int pqipersongrp::tagHeartbeatRecvd(std::string id)
|
||||
|
||||
|
||||
|
||||
int pqipersongrp::connectPeer(std::string id
|
||||
int pqipersongrp::connectPeer(const RsPeerId& id
|
||||
#ifdef WINDOWS_SYS
|
||||
///////////////////////////////////////////////////////////
|
||||
// hack for too many connections
|
||||
@ -515,7 +515,7 @@ int pqipersongrp::connectPeer(std::string id
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
std::map<std::string, SearchModule *>::iterator it;
|
||||
std::map<RsPeerId, SearchModule *>::iterator it;
|
||||
it = mods.find(id);
|
||||
if (it == mods.end())
|
||||
{
|
||||
@ -662,7 +662,7 @@ int pqipersongrp::connectPeer(std::string id
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool pqipersongrp::notifyConnect(std::string id, uint32_t ptype, bool success, const struct sockaddr_storage &raddr)
|
||||
bool pqipersongrp::notifyConnect(const RsPeerId& id, uint32_t ptype, bool success, const struct sockaddr_storage &raddr)
|
||||
{
|
||||
uint32_t type = 0;
|
||||
if (ptype == PQI_CONNECT_TCP)
|
||||
@ -691,9 +691,9 @@ pqilistener * pqipersongrpDummy::locked_createListener(const struct sockaddr_sto
|
||||
}
|
||||
|
||||
|
||||
pqiperson * pqipersongrpDummy::locked_createPerson(std::string id, pqilistener * /*listener*/)
|
||||
pqiperson * pqipersongrpDummy::locked_createPerson(const RsPeerId& id, pqilistener * /*listener*/)
|
||||
{
|
||||
pqioutput(PQL_DEBUG_BASIC, pqipersongrpzone, "pqipersongrpDummy::createPerson() PeerId: " + id);
|
||||
pqioutput(PQL_DEBUG_BASIC, pqipersongrpzone, "pqipersongrpDummy::createPerson() PeerId: " + id.toStdString());
|
||||
|
||||
pqiperson *pqip = new pqiperson(id, this);
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user