saving intermediate work for id cleaning

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.6-IdCleaning@7087 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2014-02-03 20:38:24 +00:00
parent 08d64be2e5
commit 33ab4ee3b5
61 changed files with 1016 additions and 1005 deletions

View file

@ -92,7 +92,7 @@ bool CacheSource::loadLocalCache(const RsCacheData &data)
} }
/* control Caches available */ /* 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<SSLIdType>& destination_peers)
{ {
bool ret = false; 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 */ if (mStrapper) /* allow testing without full feedback */
{ {
std::set<std::string> allowed_dest_peers ; std::set<SSLIdType> allowed_dest_peers ;
for(std::set<std::string>::const_iterator it(destination_peers.begin());it!=destination_peers.end();++it) for(std::set<SSLIdType>::const_iterator it(destination_peers.begin());it!=destination_peers.end();++it)
if(isPeerAcceptedAsCacheReceiver(*it)) if(isPeerAcceptedAsCacheReceiver(*it))
allowed_dest_peers.insert(*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. // Strip down destination peers to eliminate peers that are not allowed to receive cache items.
std::list<std::string> ids; std::list<SSLIdType> ids;
rsPeers->getOnlineList(ids); rsPeers->getOnlineList(ids);
if (mStrapper) /* allow testing without full feedback */ if (mStrapper) /* allow testing without full feedback */
{ {
std::set<std::string> allowed_dest_peers ; std::set<SSLIdType> allowed_dest_peers ;
for(std::list<std::string>::const_iterator it(ids.begin());it!=ids.end();++it) for(std::list<SSLIdType>::const_iterator it(ids.begin());it!=ids.end();++it)
if(isPeerAcceptedAsCacheReceiver(*it)) if(isPeerAcceptedAsCacheReceiver(*it))
allowed_dest_peers.insert(*it) ; allowed_dest_peers.insert(*it) ;
@ -232,7 +232,7 @@ bool CacheSource::clearCache(CacheId id)
return ret; return ret;
} }
bool CacheSource::cachesAvailable(RsPeerId pid, std::map<CacheId, RsCacheData> &ids) bool CacheSource::cachesAvailable(const SSLIdType& pid, std::map<CacheId, RsCacheData> &ids)
{ {
if(!isPeerAcceptedAsCacheReceiver(pid)) if(!isPeerAcceptedAsCacheReceiver(pid))
return false ; return false ;
@ -336,7 +336,7 @@ void CacheStore::listCaches(std::ostream &out)
lockData(); /* LOCK MUTEX */ lockData(); /* LOCK MUTEX */
/* can overwrite for more control! */ /* can overwrite for more control! */
std::map<RsPeerId, CacheSet>::iterator pit; std::map<SSLIdType, CacheSet>::iterator pit;
out << "CacheStore::listCaches() [" << getCacheType(); out << "CacheStore::listCaches() [" << getCacheType();
out << "] Total People: " << caches.size(); out << "] Total People: " << caches.size();
out << std::endl; out << std::endl;
@ -377,7 +377,7 @@ bool CacheStore::locked_getStoredCache(RsCacheData &data)
return false; return false;
} }
std::map<RsPeerId, CacheSet>::iterator pit; std::map<SSLIdType, CacheSet>::iterator pit;
if (caches.end() == (pit = caches.find(data.pid))) if (caches.end() == (pit = caches.find(data.pid)))
{ {
return false; return false;
@ -414,7 +414,7 @@ bool CacheStore::getAllStoredCaches(std::list<RsCacheData> &data)
{ {
lockData(); /* LOCK MUTEX */ lockData(); /* LOCK MUTEX */
std::map<RsPeerId, CacheSet>::iterator pit; std::map<SSLIdType, CacheSet>::iterator pit;
for(pit = caches.begin(); pit != caches.end(); pit++) for(pit = caches.begin(); pit != caches.end(); pit++)
{ {
CacheSet::iterator cit; CacheSet::iterator cit;
@ -585,7 +585,7 @@ int CacheStore::loadCache(const RsCacheData &data)
void CacheStore::locked_storeCacheEntry(const RsCacheData &data) void CacheStore::locked_storeCacheEntry(const RsCacheData &data)
{ {
/* store what we loaded - overwriting if necessary */ /* store what we loaded - overwriting if necessary */
std::map<RsPeerId, CacheSet>::iterator pit; std::map<SSLIdType, CacheSet>::iterator pit;
if (caches.end() == (pit = caches.find(data.pid))) if (caches.end() == (pit = caches.find(data.pid)))
{ {
/* add in a new CacheSet */ /* add in a new CacheSet */
@ -658,7 +658,7 @@ void CacheStrapper::statusChange(const std::list<pqipeer> &plist)
/**************** from pqimonclient ********************/ /**************** from pqimonclient ********************/
void CacheStrapper::refreshCache(const RsCacheData &data,const std::set<std::string>& destination_peers) void CacheStrapper::refreshCache(const RsCacheData &data,const std::set<SSLIdType>& destination_peers)
{ {
/* we've received an update /* we've received an update
* send to all online peers + self intersected with online peers. * 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 #ifdef CS_DEBUG
std::cerr << "CacheStrapper::refreshCache() : " << data << std::endl; std::cerr << "CacheStrapper::refreshCache() : " << data << std::endl;
#endif #endif
std::string ownid = mLinkMgr->getOwnId() ; const SSLIdType& ownid = mLinkMgr->getOwnId() ;
std::list<std::string> ids; std::list<SSLIdType> ids;
mLinkMgr->getOnlineList(ids); mLinkMgr->getOnlineList(ids);
ids.push_back(ownid) ; ids.push_back(ownid) ;
RsStackMutex stack(csMtx); /******* LOCK STACK MUTEX *********/ RsStackMutex stack(csMtx); /******* LOCK STACK MUTEX *********/
for(std::list<std::string>::const_iterator it = ids.begin(); it != ids.end(); ++it) for(std::list<SSLIdType>::const_iterator it = ids.begin(); it != ids.end(); ++it)
if(destination_peers.find(*it) != destination_peers.end()) if(destination_peers.find(*it) != destination_peers.end())
{ {
#ifdef CS_DEBUG #ifdef CS_DEBUG
@ -714,7 +714,7 @@ void CacheStrapper::refreshCacheStore(const RsCacheData & /* data */ )
} }
bool CacheStrapper::getCacheUpdates(std::list<std::pair<RsPeerId, RsCacheData> > &updates) bool CacheStrapper::getCacheUpdates(std::list<std::pair<SSLIdType, RsCacheData> > &updates)
{ {
RsStackMutex stack(csMtx); /******* LOCK STACK MUTEX *********/ RsStackMutex stack(csMtx); /******* LOCK STACK MUTEX *********/
updates = mCacheUpdates; updates = mCacheUpdates;
@ -741,28 +741,7 @@ void CacheStrapper::recvCacheResponse(RsCacheData &data, time_t /* ts */)
} }
void CacheStrapper::handleCacheQuery(const SSLIdType& id, std::map<CacheId,RsCacheData> &hashs)
/* 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)
{ {
/* basic version just iterates through .... /* basic version just iterates through ....
* more complex could decide who gets what! * more complex could decide who gets what!
@ -875,7 +854,7 @@ bool CacheStrapper::saveList(bool &cleanup, std::list<RsItem *>& saveData)
std::list<RsCacheData>::iterator cit; std::list<RsCacheData>::iterator cit;
std::list<RsCacheData> ownCaches; std::list<RsCacheData> ownCaches;
std::list<RsCacheData> remoteCaches; std::list<RsCacheData> remoteCaches;
std::string ownId = mLinkMgr->getOwnId(); const SSLIdType& ownId = mLinkMgr->getOwnId();
std::map<uint16_t, CachePair>::iterator it; std::map<uint16_t, CachePair>::iterator it;
for(it = caches.begin(); it != caches.end(); 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... // Fixup lazy behaviour in clients...
// This ensures correct loading later. // This ensures correct loading later.
// (used to be: rscc->pid = cit->pid;) // (used to be: rscc->pid = cit->pid;)
rscc->pid = ownId; rscc->pid = ownId.toStdString();
//rscc->pname = cit->pname; //rscc->pname = cit->pname;
rscc->cachetypeid = cit->cid.type; rscc->cachetypeid = cit->cid.type;
@ -926,7 +905,7 @@ bool CacheStrapper::saveList(bool &cleanup, std::list<RsItem *>& saveData)
RsCacheConfig *rscc = new RsCacheConfig(); RsCacheConfig *rscc = new RsCacheConfig();
rscc->pid = cit->pid; rscc->pid = cit->pid.toStdString();
//rscc->pname = cit->pname; //rscc->pname = cit->pname;
rscc->cachetypeid = cit->cid.type; rscc->cachetypeid = cit->cid.type;
rscc->cachesubid = cit->cid.subid; rscc->cachesubid = cit->cid.subid;
@ -955,7 +934,7 @@ bool CacheStrapper::loadList(std::list<RsItem *>& load)
#endif #endif
std::list<RsCacheData> ownCaches; std::list<RsCacheData> ownCaches;
std::list<RsCacheData> remoteCaches; std::list<RsCacheData> remoteCaches;
std::string ownId = mLinkMgr->getOwnId(); const SSLIdType& ownId = mLinkMgr->getOwnId();
//peerConnectState ownState; //peerConnectState ownState;
//mPeerMgr->getOwnNetStatus(ownState); //mPeerMgr->getOwnNetStatus(ownState);
@ -977,7 +956,7 @@ bool CacheStrapper::loadList(std::list<RsItem *>& load)
#endif #endif
RsCacheData cd; RsCacheData cd;
cd.pid = rscc->pid; cd.pid = SSLIdType(rscc->pid) ;
#if 0 #if 0
if(cd.pid == ownId) if(cd.pid == ownId)
@ -1114,6 +1093,7 @@ bool CacheStrapper::loadList(std::list<RsItem *>& load)
std::cerr << "CacheStrapper::loadList() Cleaning cache dir: <" << *dit << ">" << std::endl; std::cerr << "CacheStrapper::loadList() Cleaning cache dir: <" << *dit << ">" << std::endl;
#endif #endif
sit = saveFiles.find(RsDirUtil::convertPathToUnix(*dit)); sit = saveFiles.find(RsDirUtil::convertPathToUnix(*dit));
if (sit != saveFiles.end()) if (sit != saveFiles.end())
{ {
#ifdef CS_DEBUG #ifdef CS_DEBUG
@ -1219,7 +1199,7 @@ bool CacheTransfer::RequestCache(RsCacheData &data, CacheStore *cbStore)
/* to be overloaded */ /* to be overloaded */
bool CacheTransfer::RequestCacheFile(RsPeerId id, std::string path, std::string hash, uint64_t size) bool CacheTransfer::RequestCacheFile(const SSLIdType& id, std::string path, std::string hash, uint64_t size)
{ {
(void) id; (void) id;
(void) path; (void) path;
@ -1238,7 +1218,7 @@ bool CacheTransfer::RequestCacheFile(RsPeerId id, std::string path, std::string
} }
/* to be overloaded */ /* to be overloaded */
bool CacheTransfer::CancelCacheFile(RsPeerId id, std::string path, std::string hash, uint64_t size) bool CacheTransfer::CancelCacheFile(const SSLIdType& id, std::string path, std::string hash, uint64_t size)
{ {
(void) id; (void) id;
(void) path; (void) path;

View file

@ -60,11 +60,6 @@ class CacheSource; /* Interface for local File Index/Monitor */
class CacheStore; /* Interface for the actual Cache */ class CacheStore; /* Interface for the actual Cache */
class CacheStrapper; /* Controlling Class */ class CacheStrapper; /* Controlling Class */
/****
typedef uint32_t RsPeerId;
*****/
typedef std::string RsPeerId;
/******************************** CacheId ********************************/ /******************************** CacheId ********************************/
/*! /*!
@ -91,7 +86,7 @@ class RsCacheData
{ {
public: public:
RsPeerId pid; /// peer id SSLIdType pid; /// peer id
/// REMOVED as a WASTE to look it up everywhere! std::string pname; /// peer name (can be used by cachestore) /// REMOVED as a WASTE to look it up everywhere! std::string pname; /// peer name (can be used by cachestore)
CacheId cid; /// cache id CacheId cid; /// cache id
std::string path; /// file system path where physical cache data is located std::string path; /// file system path where physical cache data is located
@ -132,8 +127,8 @@ class CacheTransfer
/*! /*!
* to be overloaded * to be overloaded
*/ */
virtual bool RequestCacheFile(RsPeerId id, std::string path, std::string hash, uint64_t size); virtual bool RequestCacheFile(const SSLIdType& 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 CancelCacheFile(const SSLIdType& id, std::string path, std::string hash, uint64_t size);
bool CompletedCache(std::string hash); /* internal completion -> does cb */ bool CompletedCache(std::string hash); /* internal completion -> does cb */
bool FailedCache(std::string hash); /* internal completion -> does cb */ bool FailedCache(std::string hash); /* internal completion -> does cb */
@ -172,7 +167,7 @@ class CacheSource
* called to determine available cache for peer - * called to determine available cache for peer -
* default acceptable (returns all) * default acceptable (returns all)
*/ */
virtual bool cachesAvailable(RsPeerId pid, std::map<CacheId, RsCacheData> &ids); virtual bool cachesAvailable(const SSLIdType& pid, std::map<CacheId, RsCacheData> &ids);
/*! /*!
* function called at startup to load from * function called at startup to load from
@ -182,12 +177,12 @@ class CacheSource
virtual bool loadLocalCache(const RsCacheData &data); virtual bool loadLocalCache(const RsCacheData &data);
/* control Caches available */ /* control Caches available */
bool refreshCache(const RsCacheData &data,const std::set<std::string>& destination_peers); bool refreshCache(const RsCacheData &data,const std::set<SSLIdType>& destination_peers);
bool refreshCache(const RsCacheData &data); bool refreshCache(const RsCacheData &data);
bool clearCache(CacheId id); bool clearCache(CacheId id);
/* controls if peer is an accepted receiver for cache items. Default is yes. To be overloaded. */ /* 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 SSLIdType& /*peer_id*/) { return true ; }
/* get private data */ /* get private data */
std::string getCacheDir() { return cacheDir; } std::string getCacheDir() { return cacheDir; }
@ -276,7 +271,7 @@ class CacheStore
/* virtual functions overloaded by cache implementor */ /* virtual functions overloaded by cache implementor */
/* controls if peer is an accepted provider for cache items. Default is yes. To be overloaded. */ /* 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 SSLIdType& /*peer_id*/) { return true ; }
/*! /*!
* @param data cache data is stored here * @param data cache data is stored here
@ -334,7 +329,7 @@ class CacheStore
std::string cacheDir; std::string cacheDir;
mutable RsMutex cMutex; mutable RsMutex cMutex;
std::map<RsPeerId, CacheSet> caches; std::map<SSLIdType, CacheSet> caches;
}; };
@ -407,7 +402,7 @@ virtual void statusChange(const std::list<pqipeer> &plist);
* *
*/ */
void refreshCache(const RsCacheData &data); 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<SSLIdType>& destination_peers); // specify a particular list of destination peers (self not added!)
/*! /*!
* forces config savelist * forces config savelist
@ -419,7 +414,7 @@ void refreshCacheStore(const RsCacheData &data);
/*! /*!
* list of Caches to send out * list of Caches to send out
*/ */
bool getCacheUpdates(std::list<std::pair<RsPeerId, RsCacheData> > &updates); bool getCacheUpdates(std::list<std::pair<SSLIdType, RsCacheData> > &updates);
/*! /*!
* add to strapper's cachepair set so a related service's store and source can be maintained * add to strapper's cachepair set so a related service's store and source can be maintained
@ -429,7 +424,7 @@ void addCachePair(CachePair pair);
/*** I/O (2) ***/ /*** I/O (2) ***/
void recvCacheResponse(RsCacheData &data, time_t ts); void recvCacheResponse(RsCacheData &data, time_t ts);
void handleCacheQuery(RsPeerId id, std::map<CacheId, RsCacheData> &data); void handleCacheQuery(const SSLIdType& id, std::map<CacheId, RsCacheData> &data);
/*! /*!
@ -472,7 +467,7 @@ virtual bool loadList(std::list<RsItem *>& load);
RsMutex csMtx; /* protect below */ RsMutex csMtx; /* protect below */
std::list<std::pair<RsPeerId, RsCacheData> > mCacheUpdates; std::list<std::pair<SSLIdType, RsCacheData> > mCacheUpdates;
}; };

View file

@ -52,7 +52,7 @@
//#define FIM_DEBUG 1 //#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 SSLIdType& pid,const std::string& config_dir)
:CacheSource(RS_SERVICE_TYPE_FILE_INDEX, false, cs, cachedir), fiMutex("FileIndexMonitor"), fi(pid), :CacheSource(RS_SERVICE_TYPE_FILE_INDEX, false, cs, cachedir), fiMutex("FileIndexMonitor"), fi(pid),
pendingDirs(false), pendingForceCacheWrite(false), pendingDirs(false), pendingForceCacheWrite(false),
mForceCheck(false), mInCheck(false), hashCache(config_dir+"/" + "file_cache.lst"),useHashCache(true) mForceCheck(false), mInCheck(false), hashCache(config_dir+"/" + "file_cache.lst"),useHashCache(true)
@ -271,7 +271,7 @@ FileIndexMonitor::~FileIndexMonitor()
/* Data cleanup - TODO */ /* 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 SSLIdType& peer_id)
{ {
results.clear(); results.clear();
std::list<FileEntry *> firesults; std::list<FileEntry *> firesults;
@ -284,7 +284,7 @@ int FileIndexMonitor::SearchKeywords(std::list<std::string> keywords, std::list<
return filterResults(firesults,results,flags,peer_id) ; 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 SSLIdType& peer_id) const
{ {
results.clear(); results.clear();
std::list<FileEntry *> firesults; std::list<FileEntry *> firesults;
@ -297,7 +297,7 @@ int FileIndexMonitor::SearchBoolExp(Expression *exp, std::list<DirDetails>& resu
return filterResults(firesults,results,flags,peer_id) ; 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 SSLIdType& peer_id) const
{ {
#ifdef DEBUG #ifdef DEBUG
if((flags & ~RS_FILE_HINTS_PERMISSION_MASK) > 0) if((flags & ~RS_FILE_HINTS_PERMISSION_MASK) > 0)
@ -313,13 +313,13 @@ int FileIndexMonitor::filterResults(std::list<FileEntry*>& firesults,std::list<D
std::cerr << "Filtering candidate " << (*rit)->name << ", flags=" << cdetails.flags << ", peer=" << peer_id ; std::cerr << "Filtering candidate " << (*rit)->name << ", flags=" << cdetails.flags << ", peer=" << peer_id ;
#endif #endif
if(!peer_id.empty()) if(!peer_id.isNull())
{ {
FileSearchFlags permission_flags = rsPeers->computePeerPermissionFlags(peer_id,cdetails.flags,cdetails.parent_groups) ; FileSearchFlags permission_flags = rsPeers->computePeerPermissionFlags(peer_id,cdetails.flags,cdetails.parent_groups) ;
if (cdetails.type == DIR_TYPE_FILE && ( permission_flags & flags )) if (cdetails.type == DIR_TYPE_FILE && ( permission_flags & flags ))
{ {
cdetails.id = "Local"; cdetails.id.clear() ;
results.push_back(cdetails); results.push_back(cdetails);
#ifdef FIM_DEBUG #ifdef FIM_DEBUG
std::cerr << ": kept" << std::endl ; std::cerr << ": kept" << std::endl ;
@ -337,7 +337,7 @@ int FileIndexMonitor::filterResults(std::list<FileEntry*>& firesults,std::list<D
return !results.empty() ; 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(std::string hash,FileSearchFlags hint_flags, const SSLIdType& peer_id,std::string &fullpath, uint64_t &size,FileStorageFlags& storage_flags,std::list<std::string>& parent_groups) const
{ {
std::list<FileEntry *> results; std::list<FileEntry *> results;
bool ok = false; bool ok = false;
@ -361,12 +361,12 @@ bool FileIndexMonitor::findLocalFile(std::string hash,FileSearchFlags hint_flags
// turn share flags into 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 #ifdef FIM_DEBUG
std::cerr << "FileIndexMonitor::findLocalFile: Filtering candidate " << fe->name << ", flags=" << storage_flags << ", hint_flags=" << hint_flags << ", peer_id = " << peer_id << std::endl ; std::cerr << "FileIndexMonitor::findLocalFile: Filtering candidate " << fe->name << ", flags=" << storage_flags << ", hint_flags=" << hint_flags << ", peer_id = " << peer_id << std::endl ;
#endif #endif
if(peer_id.empty() || (shflh & hint_flags)) if(peer_id.isNull() || (shflh & hint_flags))
{ {
#ifdef FIM_DEBUG #ifdef FIM_DEBUG
std::cerr << "FileIndexMonitor::findLocalFile() Found Name: " << fe->name << std::endl; std::cerr << "FileIndexMonitor::findLocalFile() Found Name: " << fe->name << std::endl;
@ -458,7 +458,7 @@ bool FileIndexMonitor::loadLocalCache(const RsCacheData &data) /* called with s
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
fi.root->row = 0; 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 ; std::string fname_browsable = data.path + '/' + name ;
struct stat64 buf; struct stat64 buf;
@ -516,7 +516,7 @@ bool FileIndexMonitor::loadLocalCache(const RsCacheData &data) /* called with s
return false; 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<SSLIdType>& destination_peers) /* we call this one */
{ {
return refreshCache(data,destination_peers); return refreshCache(data,destination_peers);
} }
@ -1107,7 +1107,7 @@ 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. // 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. // 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<SSLIdType> all_friend_ids ;
rsPeers->getFriendList(all_friend_ids); rsPeers->getFriendList(all_friend_ids);
#ifdef FIM_DEBUG #ifdef FIM_DEBUG
@ -1116,9 +1116,9 @@ time_t FileIndexMonitor::locked_saveFileIndexes(bool update_cache)
std::cerr << " " << *it << std::endl; std::cerr << " " << *it << std::endl;
#endif #endif
std::map<std::set<std::string>, std::set<std::string> > peers_per_directory_combination ; std::map<std::set<std::string>, std::set<SSLIdType> > 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<SSLIdType>::const_iterator it(all_friend_ids.begin());it!=all_friend_ids.end();++it)
{ {
#ifdef FIM_DEBUG #ifdef FIM_DEBUG
std::cerr << "About to save, with the following restrictions:" << std::endl ; std::cerr << "About to save, with the following restrictions:" << std::endl ;
@ -1153,14 +1153,14 @@ time_t FileIndexMonitor::locked_saveFileIndexes(bool update_cache)
peers_per_directory_combination[forbidden_dirs].insert(*it) ; peers_per_directory_combination[forbidden_dirs].insert(*it) ;
} }
std::string ownId = rsPeers->getOwnId() ; SSLIdType ownId = rsPeers->getOwnId() ;
peers_per_directory_combination[std::set<std::string>()].insert(ownId) ; // add full configuration to self, i.e. no forbidden directories. peers_per_directory_combination[std::set<std::string>()].insert(ownId) ; // add full configuration to self, i.e. no forbidden directories.
int n=0 ; int n=0 ;
time_t now = time(NULL) ; time_t now = time(NULL) ;
time_t mod_time = 0 ; 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<SSLIdType> >::const_iterator it(peers_per_directory_combination.begin());
it!=peers_per_directory_combination.end();++it,++n) it!=peers_per_directory_combination.end();++it,++n)
{ {
std::string tmpname_browsable; std::string tmpname_browsable;
@ -1210,7 +1210,7 @@ time_t FileIndexMonitor::locked_saveFileIndexes(bool update_cache)
data.size = size; data.size = size;
data.recvd = time(NULL); data.recvd = time(NULL);
for(std::set<std::string>::const_iterator ff(it->second.begin());ff!=it->second.end();++ff) for(std::set<SSLIdType>::const_iterator ff(it->second.begin());ff!=it->second.end();++ff)
_cache_items_per_peer[*ff] = data ; _cache_items_per_peer[*ff] = data ;
data.cid.subid = 0; data.cid.subid = 0;
@ -1261,7 +1261,7 @@ bool FileIndexMonitor::cachesAvailable(RsPeerId pid,std::map<CacheId, RsCacheDat
// //
ids.clear() ; ids.clear() ;
std::map<RsPeerId,RsCacheData>::const_iterator it(_cache_items_per_peer.find(pid)) ; std::map<RsPeerId,RsCacheData>::const_iterator it(_cache_items_per_peer.find(pid)) ;
std::string ownId = rsPeers->getOwnId() ; SSLIdType ownId = rsPeers->getOwnId();
if(it != _cache_items_per_peer.end()) if(it != _cache_items_per_peer.end())
{ {

View file

@ -106,16 +106,16 @@ class HashCache
class FileIndexMonitor: public CacheSource, public RsThread class FileIndexMonitor: public CacheSource, public RsThread
{ {
public: public:
FileIndexMonitor(CacheStrapper *cs, std::string cachedir, std::string pid, const std::string& config_dir); FileIndexMonitor(CacheStrapper *cs, std::string cachedir, const SSLIdType& pid, const std::string& config_dir);
virtual ~FileIndexMonitor(); virtual ~FileIndexMonitor();
/* external interface for filetransfer */ /* 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(std::string hash,FileSearchFlags flags,const SSLIdType& 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 SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags,const SSLIdType& peer_id) ;
int SearchBoolExp(Expression *exp, std::list<DirDetails> &results,FileSearchFlags flags,const std::string& peer_id) const ; int SearchBoolExp(Expression *exp, std::list<DirDetails> &results,FileSearchFlags flags,const SSLIdType& 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 SSLIdType& peer_id) const ;
/* external interface for local access to files */ /* external interface for local access to files */
@ -125,7 +125,7 @@ class FileIndexMonitor: public CacheSource, public RsThread
/* Interacting with CacheSource */ /* Interacting with CacheSource */
/* overloaded from CacheSource */ /* overloaded from CacheSource */
virtual bool loadLocalCache(const RsCacheData &data); /* called with stored data */ 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<SSLIdType>& dest_peers); /* we call when we have a new cache for others */
/* the FileIndexMonitor inner workings */ /* the FileIndexMonitor inner workings */

View file

@ -524,7 +524,7 @@ int DirEntry::print(std::string &out)
return 1; return 1;
} }
FileIndex::FileIndex(const std::string& pid) FileIndex::FileIndex(const SSLIdType& pid)
{ {
root = new PersonEntry(pid); root = new PersonEntry(pid);
registerEntry(root) ; registerEntry(root) ;
@ -857,7 +857,7 @@ int FileIndex::loadIndex(const std::string& filename, const std::string& expecte
/* finished parse, last dir is root */ /* finished parse, last dir is root */
case 1: case 1:
{ {
std::string pid = root -> id; SSLIdType pid = root -> id;
FileIndex::unregisterEntry((void*)root) ; FileIndex::unregisterEntry((void*)root) ;
delete root; /* to clean up old entries */ delete root; /* to clean up old entries */
root = new PersonEntry(pid); root = new PersonEntry(pid);

View file

@ -174,7 +174,7 @@ class PersonEntry: public DirEntry
{ {
public: public:
/* cleanup */ /* cleanup */
PersonEntry(const std::string& pid) : id(pid) { return; } PersonEntry(const SSLIdType& pid) : id(pid) { return; }
virtual ~PersonEntry() { return; } virtual ~PersonEntry() { return; }
DirEntry &operator=(DirEntry &src) DirEntry &operator=(DirEntry &src)
@ -186,7 +186,7 @@ DirEntry &operator=(DirEntry &src)
virtual uint32_t type() const { return DIR_TYPE_PERSON ; } virtual uint32_t type() const { return DIR_TYPE_PERSON ; }
/* Data */ /* Data */
std::string id; SSLIdType id;
/* Inherited members from FileEntry: /* Inherited members from FileEntry:
int size - count for dirs int size - count for dirs
@ -209,7 +209,7 @@ class Expression;
class FileIndex class FileIndex
{ {
public: public:
FileIndex(const std::string& pid); FileIndex(const SSLIdType& pid);
~FileIndex(); ~FileIndex();
/* control root entries */ /* control root entries */

View file

@ -106,7 +106,7 @@ int FileIndexStore::loadCache(const RsCacheData &data)
* *
* peername should not be used in dbase. * peername should not be used in dbase.
*/ */
finew->root->name = data.pid; finew->root->name = data.pid.toStdString();
if (local) if (local)
{ {
@ -168,7 +168,7 @@ int FileIndexStore::loadCache(const RsCacheData &data)
/* Search Interface - For Directory Access */ /* Search Interface - For Directory Access */
int FileIndexStore::RequestDirDetails(const std::string& uid, const std::string& path, DirDetails& details) const int FileIndexStore::RequestDirDetails(const SSLIdType& uid, const std::string& path, DirDetails& details) const
{ {
lockData(); lockData();
@ -382,7 +382,7 @@ int FileIndexStore::SearchKeywords(std::list<std::string> keywords, std::list<Di
if(!FileIndex::extractData(*rit, dd)) if(!FileIndex::extractData(*rit, dd))
continue ; continue ;
dd.id = "Local"; dd.id.clear() ;
results.push_back(dd); results.push_back(dd);
} }
@ -431,7 +431,7 @@ int FileIndexStore::searchBoolExp(Expression * exp, std::list<DirDetails> &resul
{ {
DirDetails dd; DirDetails dd;
FileIndex::extractData(*rit, dd); FileIndex::extractData(*rit, dd);
dd.id = "Local"; dd.id.clear() ;
results.push_back(dd); results.push_back(dd);
} }

View file

@ -83,7 +83,7 @@ virtual int loadCache(const RsCacheData &data); /* actual load, once data avai
/* Search Interface - For Directory Access */ /* Search Interface - For Directory Access */
int RequestDirDetails(const std::string& uid, const std::string& path, DirDetails &details) const; int RequestDirDetails(const SSLIdType& uid, const std::string& path, DirDetails &details) const;
int RequestDirDetails(void *ref, DirDetails &details, FileSearchFlags flags) const; int RequestDirDetails(void *ref, DirDetails &details, FileSearchFlags flags) const;
uint32_t getType(void *ref) const ; uint32_t getType(void *ref) const ;

View file

@ -267,15 +267,15 @@ void ChunkMap::setChunkCheckingResult(uint32_t chunk_number,bool check_succeeded
// - chunks pushed when new chunks are needed // - chunks pushed when new chunks are needed
// - chunks removed when completely downloaded // - 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 #ifdef DEBUG_FTCHUNK
std::cerr << "*** ChunkMap::getDataChunk: size_hint = " << size_hint << std::endl ; std::cerr << "*** ChunkMap::getDataChunk: size_hint = " << size_hint << std::endl ;
#endif #endif
// 1 - find if this peer already has an active chunk. // 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<RsPeerId,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 falsafe_it = _active_chunks_feed.end() ;
if(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 // 0 - Look into other pending chunks and slice from here. We only consider chunks with size smaller than
// the requested size, // 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 ; 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. // 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)) 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 ; ++it3 ;
_active_chunks_feed.erase(tmp3) ; _active_chunks_feed.erase(tmp3) ;
} }
@ -428,7 +428,7 @@ bool ChunkMap::isChunkAvailable(uint64_t offset, uint32_t chunk_size) const
return true ; 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 #ifdef DEBUG_FTCHUNK
std::cout << "ChunkMap::Receiving new availability map for peer " << peer_id << std::endl ; 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 ; 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 ? // Do we have a chunk map for this file source ?
// - if yes, we use it // - if yes, we use it
@ -508,16 +508,16 @@ SourceChunksInfo *ChunkMap::getSourceChunksInfo(const std::string& peer_id)
return &(it->second) ; 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() ; 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]) if(it->second.cmap[chunk_number])
sources.push_back(it->first) ; 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. // 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() ; 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 ; 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()) if(it == _peers_chunks_availability.end())
return ; return ;

View file

@ -43,7 +43,7 @@ class ftChunk
ChunkId id ; // id of the chunk. Equal to the starting offset of the chunk ChunkId id ; // id of the chunk. Equal to the starting offset of the chunk
time_t ts; // time of last data received time_t ts; // time of last data received
int *ref_cnt; // shared counter of number of sub-blocks. Used when a slice gets split. 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, // This class handles a single fixed-sized chunk. Although each chunk is requested at once,
@ -118,7 +118,7 @@ class ChunkMap
/// On return: /// On return:
/// - source_chunk_map_needed = true if the source map should be asked /// - 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 /// Notify received a slice of data. This needs to
/// - carve in the map of chunks what is received, what is not. /// - carve in the map of chunks what is received, what is not.
@ -145,7 +145,7 @@ class ChunkMap
void setAvailabilityMap(const CompressedChunkMap& cmap) ; void setAvailabilityMap(const CompressedChunkMap& cmap) ;
/// Removes the source availability map. The map /// 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 /// 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 /// 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 /// 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 /// Returns a pointer to the availability chunk map of the given source, and possibly
/// allocates it if necessary. /// 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. /// Returns the total size of downloaded data in the file.
uint64_t getTotalReceived() const { return _total_downloaded ; } uint64_t getTotalReceived() const { return _total_downloaded ; }
@ -188,7 +188,7 @@ class ChunkMap
void getChunksToCheck(std::vector<uint32_t>& chunks_to_ask) ; void getChunksToCheck(std::vector<uint32_t>& chunks_to_ask) ;
/// Get all available sources for this chunk /// 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 /// sets all chunks to checking state
void forceCheck() ; void forceCheck() ;
@ -203,16 +203,16 @@ class ChunkMap
/// Returns a chunk available for this peer_id, depending on the chunk strategy. /// 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: private:
uint64_t _file_size ; //! total size of the file in bytes. uint64_t _file_size ; //! total size of the file in bytes.
uint32_t _chunk_size ; //! Size of chunks. Common to all chunks. uint32_t _chunk_size ; //! Size of chunks. Common to all chunks.
FileChunksInfo::ChunkStrategy _strategy ; //! how do we allocate new 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::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::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 uint64_t _total_downloaded ; //! completion for the file
bool _file_is_complete ; //! set to true when the file is complete. bool _file_is_complete ; //! set to true when the file is complete.
bool _assume_availability ; //! true if all sources always have the complete file. bool _assume_availability ; //! true if all sources always have the complete file.

View file

@ -161,7 +161,7 @@ bool ftController::getFileDownloadChunksDetails(const std::string& hash,FileChun
return false ; return false ;
} }
void ftController::addFileSource(const std::string& hash,const std::string& peer_id) void ftController::addFileSource(const std::string& hash,const SSLIdType& peer_id)
{ {
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/ RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
@ -184,7 +184,7 @@ void ftController::addFileSource(const std::string& hash,const std::string& peer
std::cerr << "... not added: hash not found." << std::endl ; std::cerr << "... not added: hash not found." << std::endl ;
#endif #endif
} }
void ftController::removeFileSource(const std::string& hash,const std::string& peer_id) void ftController::removeFileSource(const std::string& hash,const SSLIdType& peer_id)
{ {
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/ RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
@ -293,7 +293,7 @@ void ftController::searchForDirectSources()
if(mSearch->search(it->first, RS_FILE_HINTS_REMOTE | RS_FILE_HINTS_SPEC_ONLY, info)) 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++) 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 */ 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 )); setPeerState(it->second->mTransfer, pit->peerId, FT_CNTRL_STANDARD_RATE, mLinkMgr->isOnline( pit->peerId ));
} }
@ -1070,9 +1070,9 @@ bool ftController::alreadyHaveFile(const std::string& hash, FileInfo &info)
bool ftController::FileRequest(const std::string& fname, const std::string& hash, bool ftController::FileRequest(const std::string& fname, const std::string& hash,
uint64_t size, const std::string& dest, TransferRequestFlags flags, uint64_t size, const std::string& dest, TransferRequestFlags flags,
const std::list<std::string> &_srcIds, uint16_t state) const std::list<SSLIdType> &_srcIds, uint16_t state)
{ {
std::list<std::string> srcIds(_srcIds) ; std::list<SSLIdType> srcIds(_srcIds) ;
/* check if we have the file */ /* 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. // 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)) if(!(flags & RS_FILE_REQ_CACHE))
for(std::list<std::string>::iterator it = srcIds.begin(); it != srcIds.end(); ) for(std::list<SSLIdType>::iterator it = srcIds.begin(); it != srcIds.end(); )
if(!(rsPeers->servicePermissionFlags_sslid(*it) & RS_SERVICE_PERM_DIRECT_DL)) if(!(rsPeers->servicePermissionFlags(*it) & RS_SERVICE_PERM_DIRECT_DL))
{ {
std::list<std::string>::iterator tmp(it) ; std::list<SSLIdType>::iterator tmp(it) ;
++tmp ; ++tmp ;
srcIds.erase(it) ; srcIds.erase(it) ;
it = tmp ; it = tmp ;
@ -1145,7 +1145,7 @@ bool ftController::FileRequest(const std::string& fname, const std::string& has
else else
++it ; ++it ;
std::list<std::string>::const_iterator it; std::list<SSLIdType>::const_iterator it;
std::list<TransferInfo>::const_iterator pit; std::list<TransferInfo>::const_iterator pit;
#ifdef CONTROL_DEBUG #ifdef CONTROL_DEBUG
@ -1191,7 +1191,7 @@ bool ftController::FileRequest(const std::string& fname, const std::string& has
*/ */
for(it = srcIds.begin(); it != srcIds.end(); it++) 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; uint32_t i, j;
if ((dit->second)->mTransfer->getPeerState(*it, 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 #endif
// Because this is auto-add, we only add sources that we allow to DL from using direct transfers. // 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); srcIds.push_back(pit->peerId);
@ -1331,7 +1331,7 @@ bool ftController::FileRequest(const std::string& fname, const std::string& has
return true; return true;
} }
bool ftController::setPeerState(ftTransferModule *tm, std::string id, uint32_t maxrate, bool online) bool ftController::setPeerState(ftTransferModule *tm, const SSLIdType& id, uint32_t maxrate, bool online)
{ {
if (id == mLinkMgr->getOwnId()) if (id == mLinkMgr->getOwnId())
{ {
@ -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. info.storage_permission_flags |= DIR_FLAGS_NETWORK_WIDE_OTHERS ; // file being downloaded anonymously are always anonymously available.
/* get list of sources from transferModule */ /* get list of sources from transferModule */
std::list<std::string> peerIds; std::list<SSLIdType> peerIds;
std::list<std::string>::iterator pit; std::list<SSLIdType>::iterator pit;
if (!completed) if (!completed)
{ {
@ -1922,7 +1922,7 @@ bool ftController::RequestCacheFile(RsPeerId id, std::string path, std::string h
#endif #endif
/* Request File */ /* Request File */
std::list<std::string> ids; std::list<SSLIdType> ids;
ids.push_back(id); ids.push_back(id);
FileInfo info ; FileInfo info ;

View file

@ -96,7 +96,7 @@ class ftPendingRequest
public: public:
ftPendingRequest(const std::string& fname, const std::string& hash, ftPendingRequest(const std::string& fname, const std::string& hash,
uint64_t size, const std::string& dest, TransferRequestFlags flags, uint64_t size, const std::string& dest, TransferRequestFlags flags,
const std::list<std::string> &srcIds, uint16_t state) const std::list<SSLIdType> &srcIds, uint16_t state)
: mName(fname), mHash(hash), mSize(size), : mName(fname), mHash(hash), mSize(size),
mDest(dest), mFlags(flags), mSrcIds(srcIds), mState(state) { return; } mDest(dest), mFlags(flags), mSrcIds(srcIds), mState(state) { return; }
@ -107,7 +107,7 @@ class ftPendingRequest
uint64_t mSize; uint64_t mSize;
std::string mDest; std::string mDest;
TransferRequestFlags mFlags; TransferRequestFlags mFlags;
std::list<std::string> mSrcIds; std::list<SSLIdType> mSrcIds;
uint16_t mState; uint16_t mState;
}; };
@ -133,7 +133,7 @@ class ftController: public CacheTransfer, public RsThread, public pqiMonitor, pu
bool FileRequest(const std::string& fname, const std::string& hash, bool FileRequest(const std::string& fname, const std::string& hash,
uint64_t size, const std::string& dest, TransferRequestFlags flags, uint64_t size, const std::string& dest, TransferRequestFlags flags,
const std::list<std::string> &sourceIds, uint16_t state = ftFileControl::DOWNLOADING); const std::list<SSLIdType> &sourceIds, uint16_t state = ftFileControl::DOWNLOADING);
/// Do we already have this file, either in download or in file lists ? /// Do we already have this file, either in download or in file lists ?
bool alreadyHaveFile(const std::string& hash, FileInfo &info); bool alreadyHaveFile(const std::string& hash, FileInfo &info);
@ -184,12 +184,12 @@ class ftController: public CacheTransfer, public RsThread, public pqiMonitor, pu
/// Returns true is full source availability can be assumed for this peer. /// Returns true is full source availability can be assumed for this peer.
/// ///
bool assumeAvailability(const std::string& peer_id) const ; bool assumeAvailability(const SSLIdType& peer_id) const ;
/* pqiMonitor callback (also provided mConnMgr pointer!) */ /* pqiMonitor callback (also provided mConnMgr pointer!) */
virtual void statusChange(const std::list<pqipeer> &plist); virtual void statusChange(const std::list<pqipeer> &plist);
void addFileSource(const std::string& hash,const std::string& peer_id) ; void addFileSource(const std::string& hash,const SSLIdType& peer_id) ;
void removeFileSource(const std::string& hash,const std::string& peer_id) ; void removeFileSource(const std::string& hash,const SSLIdType& peer_id) ;
protected: protected:
@ -226,7 +226,7 @@ class ftController: public CacheTransfer, public RsThread, public pqiMonitor, pu
bool completeFile(std::string hash); bool completeFile(std::string hash);
bool handleAPendingRequest(); bool handleAPendingRequest();
bool setPeerState(ftTransferModule *tm, std::string id, bool setPeerState(ftTransferModule *tm, const SSLIdType& id,
uint32_t maxrate, bool online); uint32_t maxrate, bool online);
time_t last_save_time ; time_t last_save_time ;

View file

@ -38,7 +38,6 @@
#include <string> #include <string>
#include <inttypes.h> #include <inttypes.h>
#include <util/rsid.h>
#include <retroshare/rstypes.h> #include <retroshare/rstypes.h>
/*************** SEND INTERFACE *******************/ /*************** SEND INTERFACE *******************/
@ -51,23 +50,23 @@ class ftDataSend
virtual ~ftDataSend() { return; } virtual ~ftDataSend() { return; }
/* Client Send */ /* 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 std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize) = 0;
/* Server Send */ /* 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 std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data) = 0;
/// Send a chunkmap[request]. Because requests/chunkmaps can go both /// Send a chunkmap[request]. Because requests/chunkmaps can go both
//directions, but for different usages, we have this "is_client" flags, //directions, but for different usages, we have this "is_client" flags,
//that gives the ultimate goal of the data. "is_client==true" means that //that gives the ultimate goal of the data. "is_client==true" means that
//the message is for a client (download) instead of a server. //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 sendChunkMapRequest(const RsPeerId& 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 sendChunkMap(const RsPeerId& peer_id,const std::string& hash,const CompressedChunkMap& cmap,bool is_client) = 0;
/// Send a request for a chunk crc map /// 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 std::string& hash,uint32_t chunk_number) = 0;
/// Send a chunk crc map /// 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 std::string& hash,uint32_t chunk_number,const Sha1CheckSum& crc) = 0;
}; };
@ -80,19 +79,19 @@ class ftDataRecv
virtual ~ftDataRecv() { return; } virtual ~ftDataRecv() { return; }
/* Client Recv */ /* 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 std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data) = 0;
/* Server Recv */ /* 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 std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize) = 0;
/// Send a request for a chunk map /// 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 std::string& hash,bool is_client) = 0;
/// Send a chunk map /// 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 std::string& 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 recvSingleChunkCRCRequest(const RsPeerId& 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 recvSingleChunkCRC(const RsPeerId& peer_id,const std::string& hash,uint32_t chunk_id,const Sha1CheckSum& sum) = 0;
}; };

View file

@ -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_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 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 std::string& hash, uint64_t size, uint64_t offset, uint32_t chunk, void *data)
:mType(type), mPeerId(peerId), mHash(hash), mSize(size), :mType(type), mPeerId(peerId), mHash(hash), mSize(size),
mOffset(offset), mChunk(chunk), mData(data) mOffset(offset), mChunk(chunk), mData(data)
{ {
return; 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"), :RsQueueThread(DMULTIPLEX_MIN, DMULTIPLEX_MAX, DMULTIPLEX_RELAX), dataMtx("ftDataMultiplex"),
mDataSend(server), mSearch(search), mOwnId(ownId) mDataSend(server), mSearch(search), mOwnId(ownId)
{ {
@ -204,7 +204,7 @@ bool ftDataMultiplex::FileDetails(const std::string &hash, FileSearchFlags hi
/*************** SEND INTERFACE (calls ftDataSend) *******************/ /*************** SEND INTERFACE (calls ftDataSend) *******************/
/* Client Send */ /* 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 std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize)
{ {
#ifdef MPLEX_DEBUG #ifdef MPLEX_DEBUG
std::cerr << "ftDataMultiplex::sendDataRequest() Client Send"; std::cerr << "ftDataMultiplex::sendDataRequest() Client Send";
@ -214,7 +214,7 @@ bool ftDataMultiplex::sendDataRequest(const std::string& peerId, const std::stri
} }
/* Server Send */ /* 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 std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data)
{ {
#ifdef MPLEX_DEBUG #ifdef MPLEX_DEBUG
std::cerr << "ftDataMultiplex::sendData() Server Send"; 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) ****************/ /*************** RECV INTERFACE (provides ftDataRecv) ****************/
/* Client Recv */ /* 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 std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data)
{ {
#ifdef MPLEX_DEBUG #ifdef MPLEX_DEBUG
std::cerr << "ftDataMultiplex::recvData() Client Recv"; std::cerr << "ftDataMultiplex::recvData() Client Recv";
@ -242,7 +242,7 @@ bool ftDataMultiplex::recvData(const std::string& peerId, const std::string& has
/* Server Recv */ /* 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 std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize)
{ {
#ifdef MPLEX_DEBUG #ifdef MPLEX_DEBUG
std::cerr << "ftDataMultiplex::recvDataRequest() Server Recv"; std::cerr << "ftDataMultiplex::recvDataRequest() Server Recv";
@ -256,7 +256,7 @@ bool ftDataMultiplex::recvDataRequest(const std::string& peerId, const std::stri
return true; return true;
} }
bool ftDataMultiplex::recvChunkMapRequest(const std::string& peerId, const std::string& hash,bool is_client) bool ftDataMultiplex::recvChunkMapRequest(const RsPeerId& peerId, const std::string& hash,bool is_client)
{ {
#ifdef MPLEX_DEBUG #ifdef MPLEX_DEBUG
std::cerr << "ftDataMultiplex::recvChunkMapRequest() Server Recv"; std::cerr << "ftDataMultiplex::recvChunkMapRequest() Server Recv";
@ -273,7 +273,7 @@ bool ftDataMultiplex::recvChunkMapRequest(const std::string& peerId, const std::
return true; return true;
} }
bool ftDataMultiplex::recvSingleChunkCRCRequest(const std::string& peerId, const std::string& hash,uint32_t chunk_number) bool ftDataMultiplex::recvSingleChunkCRCRequest(const RsPeerId& peerId, const std::string& hash,uint32_t chunk_number)
{ {
#ifdef MPLEX_DEBUG #ifdef MPLEX_DEBUG
std::cerr << "ftDataMultiplex::recvChunkMapRequest() Server Recv"; std::cerr << "ftDataMultiplex::recvChunkMapRequest() Server Recv";
@ -406,7 +406,7 @@ bool ftDataMultiplex::doWork()
return true; 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 std::string& hash,uint32_t chunk_number,const Sha1CheckSum& crc)
{ {
RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/ RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/
@ -503,7 +503,7 @@ bool ftDataMultiplex::dispatchReceivedChunkCheckSum()
// - an uploader has sent his chunk map, so we need to store it in the corresponding ftFileProvider // - 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. // - 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 std::string& hash,const CompressedChunkMap& compressed_map,bool client)
{ {
RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/ RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/
@ -549,7 +549,7 @@ bool ftDataMultiplex::recvChunkMap(const std::string& peerId, const std::string&
return false; return false;
} }
bool ftDataMultiplex::handleRecvClientChunkMapRequest(const std::string& peerId, const std::string& hash) bool ftDataMultiplex::handleRecvClientChunkMapRequest(const RsPeerId& peerId, const std::string& hash)
{ {
CompressedChunkMap cmap ; CompressedChunkMap cmap ;
@ -581,7 +581,7 @@ bool ftDataMultiplex::handleRecvClientChunkMapRequest(const std::string& peerId,
return true ; return true ;
} }
bool ftDataMultiplex::handleRecvChunkCrcRequest(const std::string& peerId, const std::string& hash, uint32_t chunk_number) bool ftDataMultiplex::handleRecvChunkCrcRequest(const RsPeerId& peerId, const std::string& hash, uint32_t chunk_number)
{ {
// look into the sha1sum cache // look into the sha1sum cache
@ -705,7 +705,7 @@ bool ftDataMultiplex::handleRecvChunkCrcRequest(const std::string& peerId, const
return true ; return true ;
} }
bool ftDataMultiplex::handleRecvServerChunkMapRequest(const std::string& peerId, const std::string& hash) bool ftDataMultiplex::handleRecvServerChunkMapRequest(const RsPeerId& peerId, const std::string& hash)
{ {
CompressedChunkMap cmap ; CompressedChunkMap cmap ;
std::map<std::string, ftFileProvider *>::iterator it ; std::map<std::string, ftFileProvider *>::iterator it ;
@ -754,9 +754,7 @@ bool ftDataMultiplex::handleRecvServerChunkMapRequest(const std::string& peerId,
return true; return true;
} }
bool ftDataMultiplex::handleRecvData(const std::string& peerId, bool ftDataMultiplex::handleRecvData(const RsPeerId& peerId, const std::string& hash, uint64_t /*size*/, uint64_t offset, uint32_t chunksize, void *data)
const std::string& hash, uint64_t /*size*/,
uint64_t offset, uint32_t chunksize, void *data)
{ {
ftTransferModule *transfer_module = NULL ; ftTransferModule *transfer_module = NULL ;
@ -787,7 +785,7 @@ bool ftDataMultiplex::handleRecvData(const std::string& peerId,
/* called by ftTransferModule */ /* 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 std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize)
{ {
/**** Find Files *****/ /**** Find Files *****/
@ -833,8 +831,7 @@ bool ftDataMultiplex::handleRecvDataRequest(const std::string& peerId, const std
return true; return true;
} }
bool ftDataMultiplex::locked_handleServerRequest(ftFileProvider *provider, bool ftDataMultiplex::locked_handleServerRequest(ftFileProvider *provider, const RsPeerId& peerId, const std::string& hash, uint64_t size,
std::string peerId, std::string hash, uint64_t size,
uint64_t offset, uint32_t chunksize) uint64_t offset, uint32_t chunksize)
{ {
if(chunksize > uint32_t(10*1024*1024)) if(chunksize > uint32_t(10*1024*1024))
@ -875,7 +872,7 @@ bool ftDataMultiplex::locked_handleServerRequest(ftFileProvider *provider,
return false; return false;
} }
bool ftDataMultiplex::getClientChunkMap(const std::string& upload_hash,const std::string& peerId,CompressedChunkMap& cmap) bool ftDataMultiplex::getClientChunkMap(const std::string& upload_hash,const RsPeerId& peerId,CompressedChunkMap& cmap)
{ {
bool too_old = false; bool too_old = false;
{ {
@ -897,7 +894,7 @@ bool ftDataMultiplex::getClientChunkMap(const std::string& upload_hash,const std
return true ; 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 std::string& hash,bool is_client)
{ {
return mDataSend->sendChunkMapRequest(peer_id,hash,is_client); return mDataSend->sendChunkMapRequest(peer_id,hash,is_client);
} }
@ -947,13 +944,13 @@ void ftDataMultiplex::handlePendingCrcRequests()
if(it4 == mClients.end()) if(it4 == mClients.end())
continue ; continue ;
std::vector<std::string> sources ; std::vector<RsPeerId> sources ;
it4->second.mCreator->getSourcesList(it2->first,sources) ; it4->second.mCreator->getSourcesList(it2->first,sources) ;
// 1 - go through all sources. Take the oldest one. // 1 - go through all sources. Take the oldest one.
// //
std::string best_source ; RsPeerId best_source ;
time_t oldest_timestamp = now ; time_t oldest_timestamp = now ;
for(uint32_t i=0;i<sources.size();++i) for(uint32_t i=0;i<sources.size();++i)
@ -961,7 +958,7 @@ void ftDataMultiplex::handlePendingCrcRequests()
#ifdef MPLEX_DEBUG #ifdef MPLEX_DEBUG
std::cerr << "ftDataMultiplex::handlePendingCrcRequests(): Examining source " << sources[i] << std::endl; std::cerr << "ftDataMultiplex::handlePendingCrcRequests(): Examining source " << sources[i] << std::endl;
#endif #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. 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; std::cerr << "ftDataMultiplex::handlePendingCrcRequests(): Source too recently used! So using it directly." << std::endl;
#endif #endif
} }
if(best_source != "") if(!best_source.isNull())
{ {
#ifdef MPLEX_DEBUG #ifdef MPLEX_DEBUG
std::cerr << "ftDataMultiplex::handlePendingCrcRequests(): Asking crc of chunk " << it2->first << " to peer " << best_source << " for hash " << it->first << std::endl; std::cerr << "ftDataMultiplex::handlePendingCrcRequests(): Asking crc of chunk " << it2->first << " to peer " << best_source << " for hash " << it->first << std::endl;
@ -1044,7 +1041,7 @@ void ftDataMultiplex::deleteUnusedServers()
++sit ; ++sit ;
} }
bool ftDataMultiplex::handleSearchRequest(const std::string& peerId, const std::string& hash) bool ftDataMultiplex::handleSearchRequest(const RsPeerId& peerId, const std::string& hash)
{ {
#ifdef MPLEX_DEBUG #ifdef MPLEX_DEBUG
std::cerr << "ftDataMultiplex::handleSearchRequest("; std::cerr << "ftDataMultiplex::handleSearchRequest(";

View file

@ -63,13 +63,13 @@ class ftRequest
{ {
public: 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 SSLIdType& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunk, void *data);
ftRequest() ftRequest()
:mType(0), mSize(0), mOffset(0), mChunk(0), mData(NULL) { return; } :mType(0), mSize(0), mOffset(0), mChunk(0), mData(NULL) { return; }
uint32_t mType; uint32_t mType;
std::string mPeerId; SSLIdType mPeerId;
std::string mHash; std::string mHash;
uint64_t mSize; uint64_t mSize;
uint64_t mOffset; uint64_t mOffset;
@ -77,7 +77,7 @@ class ftRequest
void *mData; void *mData;
}; };
typedef std::map<std::string,time_t> ChunkCheckSumSourceList ; typedef std::map<RsPeerId,time_t> ChunkCheckSumSourceList ;
class Sha1CacheEntry class Sha1CacheEntry
{ {
@ -93,7 +93,7 @@ class ftDataMultiplex: public ftDataRecv, public RsQueueThread
public: public:
ftDataMultiplex(std::string ownId, ftDataSend *server, ftSearch *search); ftDataMultiplex(const SSLIdType& ownId, ftDataSend *server, ftSearch *search);
/* ftController Interface */ /* ftController Interface */
bool addTransferModule(ftTransferModule *mod, ftFileCreator *f); bool addTransferModule(ftTransferModule *mod, ftFileCreator *f);
@ -112,13 +112,13 @@ class ftDataMultiplex: public ftDataRecv, public RsQueueThread
/*************** SEND INTERFACE (calls ftDataSend) *******************/ /*************** SEND INTERFACE (calls ftDataSend) *******************/
/* Client Send */ /* Client Send */
bool sendDataRequest(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize); bool sendDataRequest(const SSLIdType& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize);
/* Server Send */ /* 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 SSLIdType& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data);
/* Server/client Send */ /* Server/client Send */
bool sendChunkMapRequest(const std::string& peerId, const std::string& hash,bool is_client) ; bool sendChunkMapRequest(const SSLIdType& peerId, const std::string& hash,bool is_client) ;
/* called from a separate thread */ /* called from a separate thread */
@ -129,22 +129,22 @@ class ftDataMultiplex: public ftDataRecv, public RsQueueThread
/*************** RECV INTERFACE (provides ftDataRecv) ****************/ /*************** RECV INTERFACE (provides ftDataRecv) ****************/
/* Client Recv */ /* 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 SSLIdType& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data);
/* Server Recv */ /* 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 SSLIdType& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize);
/// Receive a request for a chunk map /// 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 SSLIdType& peer_id,const std::string& hash,bool is_client) ;
/// Receive a chunk map /// 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 SSLIdType& peer_id,const std::string& 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 recvSingleChunkCRCRequest(const SSLIdType& 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 recvSingleChunkCRC(const SSLIdType& peer_id,const std::string& 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 // 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. // 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 std::string& upload_hash,const SSLIdType& peer_id,CompressedChunkMap& map) ;
protected: protected:
@ -155,15 +155,15 @@ class ftDataMultiplex: public ftDataRecv, public RsQueueThread
private: private:
/* Handling Job Queues */ /* 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 handleRecvData(const SSLIdType& 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 handleRecvDataRequest(const SSLIdType& 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 handleSearchRequest(const SSLIdType& peerId, const std::string& hash);
bool handleRecvClientChunkMapRequest(const std::string& peerId, const std::string& hash) ; bool handleRecvClientChunkMapRequest(const SSLIdType& peerId, const std::string& hash) ;
bool handleRecvServerChunkMapRequest(const std::string& peerId, const std::string& hash) ; bool handleRecvServerChunkMapRequest(const SSLIdType& peerId, const std::string& hash) ;
bool handleRecvChunkCrcRequest(const std::string& peerId, const std::string& hash,uint32_t chunk_id) ; bool handleRecvChunkCrcRequest(const SSLIdType& peerId, const std::string& hash,uint32_t chunk_id) ;
/* We end up doing the actual server job here */ /* 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 SSLIdType& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize);
RsMutex dataMtx; RsMutex dataMtx;
@ -178,7 +178,7 @@ class ftDataMultiplex: public ftDataRecv, public RsQueueThread
ftDataSend *mDataSend; ftDataSend *mDataSend;
ftSearch *mSearch; ftSearch *mSearch;
std::string mOwnId; RsPeerId mOwnId;
friend class ftServer; friend class ftServer;
}; };

View file

@ -122,7 +122,7 @@ 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) :FileIndexMonitor(cs,cachedir, pid,config_dir), p3Config(CONFIG_TYPE_FT_SHARED)
{ {
return; return;
@ -130,9 +130,9 @@ ftFiMonitor::ftFiMonitor(CacheStrapper *cs,std::string cachedir, std::string pid
bool ftFiMonitor::search(const std::string &hash, FileSearchFlags hintflags, FileInfo &info) const bool ftFiMonitor::search(const std::string &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 std::string &hash, FileSearchFlags hintflags, const RsPeerId& peer_id,FileInfo &info) const
{ {
#ifdef DB_DEBUG #ifdef DB_DEBUG
std::cerr << "ftFiMonitor::search(" << hash << "," << hintflags; std::cerr << "ftFiMonitor::search(" << hash << "," << hintflags;

View file

@ -58,11 +58,11 @@ virtual bool search(const std::string &hash, FileSearchFlags hintflags, FileInfo
class ftFiMonitor: public FileIndexMonitor, public ftSearch, public p3Config class ftFiMonitor: public FileIndexMonitor, public ftSearch, public p3Config
{ {
public: 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 */ /* overloaded search function */
virtual bool search(const std::string &hash, FileSearchFlags hintflags, FileInfo &info) const; 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 std::string &hash, FileSearchFlags hintflags, const RsPeerId& peer_id, FileInfo &info) const;
/* overloaded set dirs enables config indication */ /* overloaded set dirs enables config indication */
virtual void setSharedDirectories(const std::list<SharedDirInfo>& dirList); virtual void setSharedDirectories(const std::list<SharedDirInfo>& dirList);

View file

@ -65,7 +65,7 @@ ftFileCreator::ftFileCreator(const std::string& path, uint64_t size, const std::
#endif #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. // Only send the data if we actually have it.
// //
@ -243,7 +243,7 @@ void ftFileCreator::removeInactiveChunks()
#endif #endif
} }
void ftFileCreator::removeFileSource(const std::string& peer_id) void ftFileCreator::removeFileSource(const RsPeerId& peer_id)
{ {
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/ RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
#ifdef FILE_DEBUG #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. * 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 ******/ RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
#ifdef FILE_DEBUG #ifdef FILE_DEBUG
@ -559,7 +559,7 @@ bool ftFileCreator::locked_printChunkMap()
std::cerr << " " << it->second << std::endl ; std::cerr << " " << it->second << std::endl ;
std::cerr << "Active chunks per peer:" << 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; std::cerr << " " << it->first << "\t: " << it->second.cnt << std::endl;
return true; return true;
@ -586,14 +586,14 @@ void ftFileCreator::getAvailabilityMap(CompressedChunkMap& map)
chunkMap.getAvailabilityMap(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 ******/ RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
return chunkMap.getSourceChunksInfo(peer_id)->is_full ; 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 ******/ RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
@ -646,7 +646,7 @@ void ftFileCreator::forceCheck()
chunkMap.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 ******/ RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/

View file

@ -52,7 +52,7 @@ class ftFileCreator: public ftFileProvider
~ftFileCreator(); ~ftFileCreator();
/* overloaded from FileProvider */ /* overloaded from FileProvider */
virtual bool getFileData(const std::string& peer_id,uint64_t offset, uint32_t &chunk_size, void *data); virtual bool getFileData(const SSLIdType& peer_id,uint64_t offset, uint32_t &chunk_size, void *data);
bool finished() ; bool finished() ;
uint64_t getRecvd(); uint64_t getRecvd();
@ -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. // - 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. // - 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 SSLIdType& 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 // Takes care of purging any inactive chunks. This should be called regularly, because some peers may disconnect
// and let inactive chunks not finished. // and let inactive chunks not finished.
@ -99,11 +99,11 @@ class ftFileCreator: public ftFileProvider
void removeInactiveChunks() ; void removeInactiveChunks() ;
// removes the designated file source from the chunkmap. // removes the designated file source from the chunkmap.
void removeFileSource(const std::string& peer_id) ; void removeFileSource(const SSLIdType& peer_id) ;
// Get all available sources for this chunk // 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<SSLIdType>& sources) ;
// Returns resets the time stamp of the last data receive. // Returns resets the time stamp of the last data receive.
time_t lastRecvTimeStamp() ; 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. // 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 SSLIdType& peer_id,const CompressedChunkMap& map) ;
// Returns true id the given file source is complete. // Returns true id the given file source is complete.
// //
bool sourceIsComplete(const std::string& peer_id) ; bool sourceIsComplete(const SSLIdType& peer_id) ;
protected: protected:
@ -146,7 +146,7 @@ class ftFileCreator: public ftFileProvider
uint64_t mEnd; uint64_t mEnd;
std::map<uint64_t, ftChunk> mChunks; std::map<uint64_t, ftChunk> mChunks;
std::map<std::string,ZeroInitCounter> mChunksPerPeer ; std::map<SSLIdType,ZeroInitCounter> mChunksPerPeer ;
ChunkMap chunkMap ; ChunkMap chunkMap ;

View file

@ -80,7 +80,7 @@ bool ftFileProvider::FileDetails(FileInfo &info)
info.peers.clear() ; info.peers.clear() ;
float total_transfer_rate = 0.0f ; 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<SSLIdType,PeerUploadInfo>::const_iterator it(uploading_peers.begin());it!=uploading_peers.end();++it)
{ {
TransferInfo inf ; TransferInfo inf ;
inf.peerId = it->first ; 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 ; std::cerr << "ftFileProvider::purgeOldPeers(): " << (void*)this << ": examining peers." << std::endl ;
#endif #endif
bool ret = true ; bool ret = true ;
for(std::map<std::string,PeerUploadInfo>::iterator it(uploading_peers.begin());it!=uploading_peers.end();) for(std::map<SSLIdType,PeerUploadInfo>::iterator it(uploading_peers.begin());it!=uploading_peers.end();)
if( (*it).second.lastTS+max_duration < (uint32_t)now) if( (*it).second.lastTS+max_duration < (uint32_t)now)
{ {
#ifdef DEBUG_FT_FILE_PROVIDER #ifdef DEBUG_FT_FILE_PROVIDER
std::cerr << "ftFileProvider::purgeOldPeers(): " << (void*)this << ": peer " << it->first << " is too old. Removing." << std::endl ; std::cerr << "ftFileProvider::purgeOldPeers(): " << (void*)this << ": peer " << it->first << " is too old. Removing." << std::endl ;
#endif #endif
std::map<std::string,PeerUploadInfo>::iterator tmp = it ; std::map<SSLIdType,PeerUploadInfo>::iterator tmp = it ;
++tmp ; ++tmp ;
uploading_peers.erase(it) ; uploading_peers.erase(it) ;
it=tmp ; 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 SSLIdType& peer_id,uint64_t offset, uint32_t &chunk_size, void *data)
{ {
/* dodgey checking outside of mutex... /* dodgey checking outside of mutex...
* much check again inside FileAttrs(). * much check again inside FileAttrs().
@ -250,7 +250,7 @@ void ftFileProvider::PeerUploadInfo::updateStatus(uint64_t offset,uint32_t data_
total_size += req_size ; total_size += req_size ;
} }
void ftFileProvider::setClientMap(const std::string& peer_id,const CompressedChunkMap& cmap) void ftFileProvider::setClientMap(const SSLIdType& peer_id,const CompressedChunkMap& cmap)
{ {
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/ 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) ; 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 SSLIdType& peer_id,CompressedChunkMap& cmap,bool& map_is_too_old)
{ {
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/ RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/

View file

@ -41,7 +41,7 @@ class ftFileProvider
ftFileProvider(const std::string& path, uint64_t size, const std::string& hash); ftFileProvider(const std::string& path, uint64_t size, const std::string& hash);
virtual ~ftFileProvider(); virtual ~ftFileProvider();
virtual bool getFileData(const std::string& peer_id,uint64_t offset, uint32_t &chunk_size, void *data); virtual bool getFileData(const SSLIdType& peer_id,uint64_t offset, uint32_t &chunk_size, void *data);
virtual bool FileDetails(FileInfo &info); virtual bool FileDetails(FileInfo &info);
std::string getHash(); std::string getHash();
uint64_t getFileSize(); uint64_t getFileSize();
@ -54,8 +54,8 @@ class ftFileProvider
virtual void getAvailabilityMap(CompressedChunkMap& cmap) ; 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. // 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 getClientMap(const RsPeerId& peer_id,CompressedChunkMap& cmap,bool& map_is_too_old) ;
void setClientMap(const std::string& peer_id,const CompressedChunkMap& cmap) ; void setClientMap(const RsPeerId& peer_id,const CompressedChunkMap& cmap) ;
// Removes inactive peers from the client list. Returns true if all peers have been removed. // Removes inactive peers from the client list. Returns true if all peers have been removed.
// //
@ -100,7 +100,7 @@ class ftFileProvider
// Contains statistics (speed, peer name, etc.) of all uploading peers for that file. // 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 * Mutex Required for stuff below

View file

@ -102,12 +102,14 @@ void ftServer::addConfigComponents(p3ConfigMgr */*mgr*/)
/* NOT SURE ABOUT THIS ONE */ /* NOT SURE ABOUT THIS ONE */
} }
std::string ftServer::OwnId() const RsPeerId& ftServer::OwnId()
{ {
std::string ownId; static RsPeerId null_id ;
if (mLinkMgr) if (mLinkMgr)
ownId = mLinkMgr->getOwnId(); return mLinkMgr->getOwnId();
return ownId; else
return null_id ;
} }
/* Final Setup (once everything is assigned) */ /* Final Setup (once everything is assigned) */
@ -117,7 +119,7 @@ void ftServer::SetupFtServer()
/* setup FiStore/Monitor */ /* setup FiStore/Monitor */
std::string localcachedir = mConfigPath + "/cache/local"; std::string localcachedir = mConfigPath + "/cache/local";
std::string remotecachedir = mConfigPath + "/cache/remote"; std::string remotecachedir = mConfigPath + "/cache/remote";
std::string ownId = mLinkMgr->getOwnId(); RsPeerId ownId = mLinkMgr->getOwnId();
/* search/extras List */ /* search/extras List */
mFtExtra = new ftExtraList(); mFtExtra = new ftExtraList();
@ -264,7 +266,7 @@ bool ftServer::alreadyHaveFile(const std::string& hash, FileInfo &info)
return mFtController->alreadyHaveFile(hash, 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 std::string& hash, uint64_t size, const std::string& dest, TransferRequestFlags flags, const std::list<RsPeerId>& srcIds)
{ {
std::string error_string ; std::string error_string ;
@ -407,7 +409,7 @@ bool ftServer::FileDownloads(std::list<std::string> &hashs)
//return mFtDataplex->FileDownloads(hashs); //return mFtDataplex->FileDownloads(hashs);
} }
bool ftServer::FileUploadChunksDetails(const std::string& hash,const std::string& peer_id,CompressedChunkMap& cmap) bool ftServer::FileUploadChunksDetails(const std::string& hash,const RsPeerId& peer_id,CompressedChunkMap& cmap)
{ {
return mFtDataplex->getClientChunkMap(hash,peer_id,cmap); return mFtDataplex->getClientChunkMap(hash,peer_id,cmap);
} }
@ -481,7 +483,7 @@ void ftServer::removeVirtualPeer(const TurtleFileHash& hash,const TurtleVirtualP
mFtController->removeFileSource(hash,virtual_peer_id) ; mFtController->removeFileSource(hash,virtual_peer_id) ;
} }
bool ftServer::handleTunnelRequest(const std::string& hash,const std::string& peer_id) bool ftServer::handleTunnelRequest(const std::string& hash,const RsPeerId& peer_id)
{ {
FileInfo info ; 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); 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);
@ -545,7 +547,7 @@ bool ftServer::ExtraFileMove(std::string fname, std::string hash, uint64_t size,
/******************** Directory Listing ************************/ /******************** 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 #ifdef SERVER_DEBUG
std::cerr << "ftServer::RequestDirDetails(uid:" << uid; std::cerr << "ftServer::RequestDirDetails(uid:" << uid;
@ -610,12 +612,12 @@ uint32_t ftServer::getType(void *ref, FileSearchFlags flags)
int ftServer::SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags) int ftServer::SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags)
{ {
if(flags & RS_FILE_HINTS_LOCAL) if(flags & RS_FILE_HINTS_LOCAL)
return mFiMon->SearchKeywords(keywords, results,flags,""); return mFiMon->SearchKeywords(keywords, results,flags,RsPeerId());
else else
return mFiStore->SearchKeywords(keywords, results,flags); return mFiStore->SearchKeywords(keywords, results,flags);
return 0 ; 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 #ifdef SERVER_DEBUG
std::cerr << "ftServer::SearchKeywords()"; std::cerr << "ftServer::SearchKeywords()";
@ -637,12 +639,12 @@ int ftServer::SearchKeywords(std::list<std::string> keywords, std::list<DirDetai
int ftServer::SearchBoolExp(Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags) int ftServer::SearchBoolExp(Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags)
{ {
if(flags & RS_FILE_HINTS_LOCAL) if(flags & RS_FILE_HINTS_LOCAL)
return mFiMon->SearchBoolExp(exp,results,flags,"") ; return mFiMon->SearchBoolExp(exp,results,flags,RsPeerId()) ;
else else
return mFiStore->searchBoolExp(exp, results); return mFiStore->searchBoolExp(exp, results);
return 0 ; 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) if(flags & RS_FILE_HINTS_LOCAL)
return mFiMon->SearchBoolExp(exp,results,flags,peer_id) ; return mFiMon->SearchBoolExp(exp,results,flags,peer_id) ;
@ -870,7 +872,7 @@ bool ftServer::loadConfigMap(std::map<std::string, std::string> &/*configMap*/)
/***************************************************************/ /***************************************************************/
/* Client Send */ /* 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 std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize)
{ {
#ifdef SERVER_DEBUG #ifdef SERVER_DEBUG
std::cerr << "ftServer::sendDataRequest() to peer " << peerId << " for hash " << hash << ", offset=" << offset << ", chunk size="<< chunksize << std::endl; std::cerr << "ftServer::sendDataRequest() to peer " << peerId << " for hash " << hash << ", offset=" << offset << ", chunk size="<< chunksize << std::endl;
@ -908,7 +910,7 @@ bool ftServer::sendDataRequest(const std::string& peerId, const std::string& has
return true; return true;
} }
bool ftServer::sendChunkMapRequest(const std::string& peerId,const std::string& hash,bool is_client) bool ftServer::sendChunkMapRequest(const RsPeerId& peerId,const std::string& hash,bool is_client)
{ {
#ifdef SERVER_DEBUG #ifdef SERVER_DEBUG
std::cerr << "ftServer::sendChunkMapRequest() to peer " << peerId << " for hash " << hash << std::endl; std::cerr << "ftServer::sendChunkMapRequest() to peer " << peerId << " for hash " << hash << std::endl;
@ -937,7 +939,7 @@ bool ftServer::sendChunkMapRequest(const std::string& peerId,const std::string&
return true ; 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 std::string& hash,const CompressedChunkMap& map,bool is_client)
{ {
#ifdef SERVER_DEBUG #ifdef SERVER_DEBUG
std::cerr << "ftServer::sendChunkMap() to peer " << peerId << " for hash " << hash << std::endl; std::cerr << "ftServer::sendChunkMap() to peer " << peerId << " for hash " << hash << std::endl;
@ -968,7 +970,7 @@ bool ftServer::sendChunkMap(const std::string& peerId,const std::string& hash,co
return true ; return true ;
} }
bool ftServer::sendSingleChunkCRCRequest(const std::string& peerId,const std::string& hash,uint32_t chunk_number) bool ftServer::sendSingleChunkCRCRequest(const RsPeerId& peerId,const std::string& hash,uint32_t chunk_number)
{ {
#ifdef SERVER_DEBUG #ifdef SERVER_DEBUG
std::cerr << "ftServer::sendSingleCRCRequest() to peer " << peerId << " for hash " << hash << ", chunk number=" << chunk_number << std::endl; std::cerr << "ftServer::sendSingleCRCRequest() to peer " << peerId << " for hash " << hash << ", chunk number=" << chunk_number << std::endl;
@ -999,7 +1001,7 @@ bool ftServer::sendSingleChunkCRCRequest(const std::string& peerId,const std::st
return true ; 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 std::string& hash,uint32_t chunk_number,const Sha1CheckSum& crc)
{ {
#ifdef SERVER_DEBUG #ifdef SERVER_DEBUG
std::cerr << "ftServer::sendSingleCRC() to peer " << peerId << " for hash " << hash << ", chunk number=" << chunk_number << std::endl; std::cerr << "ftServer::sendSingleCRC() to peer " << peerId << " for hash " << hash << ", chunk number=" << chunk_number << std::endl;
@ -1033,7 +1035,7 @@ bool ftServer::sendSingleChunkCRC(const std::string& peerId,const std::string& h
} }
/* Server Send */ /* 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 std::string& hash, uint64_t size, uint64_t baseoffset, uint32_t chunksize, void *data)
{ {
/* create a packet */ /* create a packet */
/* push to networking part */ /* push to networking part */
@ -1131,7 +1133,7 @@ bool ftServer::sendData(const std::string& peerId, const std::string& hash, uint
// //
void ftServer::receiveTurtleData(RsTurtleGenericTunnelItem *i, void ftServer::receiveTurtleData(RsTurtleGenericTunnelItem *i,
const std::string& hash, const std::string& hash,
const std::string& virtual_peer_id, const RsPeerId& virtual_peer_id,
RsTurtleGenericTunnelItem::Direction direction) RsTurtleGenericTunnelItem::Direction direction)
{ {
switch(i->PacketSubType()) switch(i->PacketSubType())

View file

@ -94,7 +94,7 @@ class ftServer: public p3Service, public RsFiles, public ftDataSend, public RsTu
virtual CacheStrapper *getCacheStrapper(); virtual CacheStrapper *getCacheStrapper();
virtual CacheTransfer *getCacheTransfer(); virtual CacheTransfer *getCacheTransfer();
std::string OwnId(); const RsPeerId& OwnId();
/* Final Setup (once everything is assigned) */ /* Final Setup (once everything is assigned) */
void SetupFtServer() ; void SetupFtServer() ;
@ -106,8 +106,8 @@ class ftServer: public p3Service, public RsFiles, public ftDataSend, public RsTu
// Implements RsTurtleClientService // Implements RsTurtleClientService
// //
virtual bool handleTunnelRequest(const std::string& hash,const std::string& peer_id) ; virtual bool handleTunnelRequest(const std::string& hash,const RsPeerId& peer_id) ;
virtual void receiveTurtleData(RsTurtleGenericTunnelItem *item,const std::string& hash,const std::string& virtual_peer_id,RsTurtleGenericTunnelItem::Direction direction) ; virtual void receiveTurtleData(RsTurtleGenericTunnelItem *item,const std::string& hash,const RsPeerId& virtual_peer_id,RsTurtleGenericTunnelItem::Direction direction) ;
virtual RsTurtleGenericTunnelItem *deserialiseItem(void *data,uint32_t size) const ; virtual RsTurtleGenericTunnelItem *deserialiseItem(void *data,uint32_t size) const ;
void addVirtualPeer(const TurtleFileHash&, const TurtleVirtualPeerId&,RsTurtleGenericTunnelItem::Direction dir) ; void addVirtualPeer(const TurtleFileHash&, const TurtleVirtualPeerId&,RsTurtleGenericTunnelItem::Direction dir) ;
@ -130,7 +130,7 @@ class ftServer: public p3Service, public RsFiles, public ftDataSend, public RsTu
* Control of Downloads * Control of Downloads
***/ ***/
virtual bool alreadyHaveFile(const std::string& hash, FileInfo &info); 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 FileRequest(const std::string& fname, const std::string& hash, uint64_t size, const std::string& dest, TransferRequestFlags flags, const std::list<RsPeerId>& srcIds);
virtual bool FileCancel(const std::string& hash); virtual bool FileCancel(const std::string& hash);
virtual bool FileControl(const std::string& hash, uint32_t flags); virtual bool FileControl(const std::string& hash, uint32_t flags);
virtual bool FileClearCompleted(); virtual bool FileClearCompleted();
@ -163,7 +163,7 @@ class ftServer: public p3Service, public RsFiles, public ftDataSend, public RsTu
virtual bool FileUploads(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 FileDetails(const std::string &hash, FileSearchFlags hintflags, FileInfo &info);
virtual bool FileDownloadChunksDetails(const std::string& hash,FileChunksInfo& 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 FileUploadChunksDetails(const std::string& hash,const RsPeerId& peer_id,CompressedChunkMap& map) ;
/*** /***
@ -179,14 +179,14 @@ class ftServer: public p3Service, public RsFiles, public ftDataSend, public RsTu
/*** /***
* Directory Listing / Search Interface * 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 int RequestDirDetails(void *ref, DirDetails &details, FileSearchFlags flags);
virtual uint32_t getType(void *ref,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);
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);
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 * Utility Functions
@ -230,12 +230,12 @@ class ftServer: public p3Service, public RsFiles, public ftDataSend, public RsTu
/*************** Data Transfer Interface ***********************/ /*************** Data Transfer Interface ***********************/
/***************************************************************/ /***************************************************************/
public: 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 sendData(const RsPeerId& 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 sendDataRequest(const RsPeerId& 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 sendChunkMapRequest(const RsPeerId& 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 sendChunkMap(const RsPeerId& 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 sendSingleChunkCRCRequest(const RsPeerId& 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 sendSingleChunkCRC(const RsPeerId& peer_id,const std::string& hash,uint32_t chunk_number,const Sha1CheckSum& crc) ;
/*************** Internal Transfer Fns *************************/ /*************** Internal Transfer Fns *************************/
virtual int tick(); virtual int tick();

View file

@ -103,7 +103,7 @@ ftTransferModule::~ftTransferModule()
} }
bool ftTransferModule::setFileSources(const std::list<std::string>& peerIds) bool ftTransferModule::setFileSources(const std::list<SSLIdType>& peerIds)
{ {
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/ RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
@ -114,7 +114,7 @@ bool ftTransferModule::setFileSources(const std::list<std::string>& peerIds)
std::cerr << " List of peers: " ; std::cerr << " List of peers: " ;
#endif #endif
std::list<std::string>::const_iterator it; std::list<SSLIdType>::const_iterator it;
for(it = peerIds.begin(); it != peerIds.end(); it++) for(it = peerIds.begin(); it != peerIds.end(); it++)
{ {
@ -123,7 +123,7 @@ bool ftTransferModule::setFileSources(const std::list<std::string>& peerIds)
#endif #endif
peerInfo pInfo(*it); peerInfo pInfo(*it);
mFileSources.insert(std::pair<std::string,peerInfo>(*it,pInfo)); mFileSources.insert(std::pair<SSLIdType,peerInfo>(*it,pInfo));
} }
#ifdef FT_DEBUG #ifdef FT_DEBUG
@ -133,10 +133,10 @@ bool ftTransferModule::setFileSources(const std::list<std::string>& peerIds)
return true; return true;
} }
bool ftTransferModule::getFileSources(std::list<std::string> &peerIds) bool ftTransferModule::getFileSources(std::list<SSLIdType> &peerIds)
{ {
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/ RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
std::map<std::string,peerInfo>::iterator it; std::map<SSLIdType,peerInfo>::iterator it;
for(it = mFileSources.begin(); it != mFileSources.end(); it++) for(it = mFileSources.begin(); it != mFileSources.end(); it++)
{ {
peerIds.push_back(it->first); peerIds.push_back(it->first);
@ -144,17 +144,17 @@ bool ftTransferModule::getFileSources(std::list<std::string> &peerIds)
return true; return true;
} }
bool ftTransferModule::addFileSource(const std::string& peerId) bool ftTransferModule::addFileSource(const SSLIdType& peerId)
{ {
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/ RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
std::map<std::string,peerInfo>::iterator mit; std::map<SSLIdType,peerInfo>::iterator mit;
mit = mFileSources.find(peerId); mit = mFileSources.find(peerId);
if (mit == mFileSources.end()) if (mit == mFileSources.end())
{ {
/* add in new source */ /* add in new source */
peerInfo pInfo(peerId); peerInfo pInfo(peerId);
mFileSources.insert(std::pair<std::string,peerInfo>(peerId,pInfo)); mFileSources.insert(std::pair<SSLIdType,peerInfo>(peerId,pInfo));
mit = mFileSources.find(peerId); mit = mFileSources.find(peerId);
mMultiplexor->sendChunkMapRequest(peerId, mHash,false) ; 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 SSLIdType& peerId)
{ {
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/ RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
std::map<std::string,peerInfo>::iterator mit; std::map<SSLIdType,peerInfo>::iterator mit;
mit = mFileSources.find(peerId); mit = mFileSources.find(peerId);
if (mit != mFileSources.end()) if (mit != mFileSources.end())
@ -199,7 +199,7 @@ bool ftTransferModule::removeFileSource(const std::string& peerId)
return true; return true;
} }
bool ftTransferModule::setPeerState(const std::string& peerId,uint32_t state,uint32_t maxRate) bool ftTransferModule::setPeerState(const SSLIdType& peerId,uint32_t state,uint32_t maxRate)
{ {
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/ RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
#ifdef FT_DEBUG #ifdef FT_DEBUG
@ -209,7 +209,7 @@ bool ftTransferModule::setPeerState(const std::string& peerId,uint32_t state,uin
std::cerr << " maxRate: " << maxRate << std::endl; std::cerr << " maxRate: " << maxRate << std::endl;
#endif #endif
std::map<std::string,peerInfo>::iterator mit; std::map<SSLIdType,peerInfo>::iterator mit;
mit = mFileSources.find(peerId); mit = mFileSources.find(peerId);
if (mit == mFileSources.end()) if (mit == mFileSources.end())
@ -229,7 +229,7 @@ bool ftTransferModule::setPeerState(const std::string& peerId,uint32_t state,uin
// Start it off at zero.... // Start it off at zero....
// (mit->second).actualRate=maxRate; /* should give big kick in right direction */ // (mit->second).actualRate=maxRate; /* should give big kick in right direction */
std::list<std::string>::iterator it; std::list<SSLIdType>::iterator it;
it = std::find(mOnlinePeers.begin(), mOnlinePeers.end(), peerId); it = std::find(mOnlinePeers.begin(), mOnlinePeers.end(), peerId);
if (state!=PQIPEER_NOT_ONLINE) 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 SSLIdType& peerId,uint32_t &state,uint32_t &tfRate)
{ {
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/ RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
std::map<std::string,peerInfo>::iterator mit; std::map<SSLIdType,peerInfo>::iterator mit;
mit = mFileSources.find(peerId); mit = mFileSources.find(peerId);
if (mit == mFileSources.end()) return false; if (mit == mFileSources.end()) return false;
@ -267,10 +267,10 @@ bool ftTransferModule::getPeerState(const std::string& peerId,uint32_t &state,ui
return true; return true;
} }
uint32_t ftTransferModule::getDataRate(const std::string& peerId) uint32_t ftTransferModule::getDataRate(const SSLIdType& peerId)
{ {
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/ RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
std::map<std::string,peerInfo>::iterator mit; std::map<SSLIdType,peerInfo>::iterator mit;
mit = mFileSources.find(peerId); mit = mFileSources.find(peerId);
if (mit == mFileSources.end()) if (mit == mFileSources.end())
{ {
@ -296,7 +296,7 @@ time_t ftTransferModule::lastActvTimeStamp()
} }
//interface to client module //interface to client module
bool ftTransferModule::recvFileData(const std::string& peerId, uint64_t offset, uint32_t chunk_size, void *data) bool ftTransferModule::recvFileData(const SSLIdType& peerId, uint64_t offset, uint32_t chunk_size, void *data)
{ {
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/ RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
#ifdef FT_DEBUG #ifdef FT_DEBUG
@ -310,7 +310,7 @@ bool ftTransferModule::recvFileData(const std::string& peerId, uint64_t offset,
bool ok = false; bool ok = false;
std::map<std::string,peerInfo>::iterator mit; std::map<SSLIdType,peerInfo>::iterator mit;
mit = mFileSources.find(peerId); mit = mFileSources.find(peerId);
if (mit == mFileSources.end()) if (mit == mFileSources.end())
@ -332,7 +332,7 @@ bool ftTransferModule::recvFileData(const std::string& peerId, uint64_t offset,
return ok; return ok;
} }
void ftTransferModule::locked_requestData(const std::string& peerId, uint64_t offset, uint32_t chunk_size) void ftTransferModule::locked_requestData(const SSLIdType& peerId, uint64_t offset, uint32_t chunk_size)
{ {
#ifdef FT_DEBUG #ifdef FT_DEBUG
std::cerr << "ftTransferModule::requestData()"; 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); 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 SSLIdType& peer_id,uint32_t size_hint,uint64_t &offset, uint32_t &chunk_size)
{ {
#ifdef FT_DEBUG #ifdef FT_DEBUG
std::cerr << "ftTransferModule::locked_getChunk()"; std::cerr << "ftTransferModule::locked_getChunk()";
@ -427,7 +427,7 @@ bool ftTransferModule::queryInactive()
if (mFileStatus.stat == ftFileStatus::PQIFILE_CHECKING) if (mFileStatus.stat == ftFileStatus::PQIFILE_CHECKING)
return false ; return false ;
std::map<std::string,peerInfo>::iterator mit; std::map<SSLIdType,peerInfo>::iterator mit;
for(mit = mFileSources.begin(); mit != mFileSources.end(); mit++) for(mit = mFileSources.begin(); mit != mFileSources.end(); mit++)
{ {
locked_tickPeerTransfer(mit->second); locked_tickPeerTransfer(mit->second);
@ -496,7 +496,7 @@ int ftTransferModule::tick()
std::cerr << std::endl; std::cerr << std::endl;
std::cerr << "Peers: "; std::cerr << "Peers: ";
std::map<std::string,peerInfo>::iterator it; std::map<SSLIdType,peerInfo>::iterator it;
for(it = mFileSources.begin(); it != mFileSources.end(); it++) for(it = mFileSources.begin(); it != mFileSources.end(); it++)
{ {
std::cerr << " " << it->first; std::cerr << " " << it->first;
@ -645,7 +645,7 @@ void ftTransferModule::adjustSpeed()
{ {
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/ RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
std::map<std::string,peerInfo>::iterator mit; std::map<SSLIdType,peerInfo>::iterator mit;
actualRate = 0; actualRate = 0;

View file

@ -56,7 +56,7 @@ class HashThread ;
class peerInfo class peerInfo
{ {
public: public:
peerInfo(std::string peerId_in):peerId(peerId_in),state(PQIPEER_NOT_ONLINE),desiredRate(0),actualRate(0), peerInfo(const SSLIdType& peerId_in):peerId(peerId_in),state(PQIPEER_NOT_ONLINE),desiredRate(0),actualRate(0),
lastTS(0), lastTS(0),
recvTS(0), lastTransfers(0), nResets(0), recvTS(0), lastTransfers(0), nResets(0),
rtt(0), rttActive(false), rttStart(0), rttOffset(0), rtt(0), rttActive(false), rttStart(0), rttOffset(0),
@ -64,7 +64,7 @@ public:
{ {
return; return;
} }
peerInfo(std::string peerId_in,uint32_t state_in,uint32_t maxRate_in): peerInfo(const SSLIdType& peerId_in,uint32_t state_in,uint32_t maxRate_in):
peerId(peerId_in),state(state_in),desiredRate(maxRate_in),actualRate(0), peerId(peerId_in),state(state_in),desiredRate(maxRate_in),actualRate(0),
lastTS(0), lastTS(0),
recvTS(0), lastTransfers(0), nResets(0), recvTS(0), lastTransfers(0), nResets(0),
@ -73,7 +73,7 @@ public:
{ {
return; return;
} }
std::string peerId; SSLIdType peerId;
uint32_t state; uint32_t state;
double desiredRate; double desiredRate;
double actualRate; double actualRate;
@ -124,13 +124,13 @@ public:
~ftTransferModule(); ~ftTransferModule();
//interface to download controller //interface to download controller
bool setFileSources(const std::list<std::string>& peerIds); bool setFileSources(const std::list<SSLIdType>& peerIds);
bool addFileSource(const std::string& peerId); bool addFileSource(const SSLIdType& peerId);
bool removeFileSource(const std::string& peerId); bool removeFileSource(const SSLIdType& peerId);
bool setPeerState(const std::string& peerId,uint32_t state,uint32_t maxRate); //state = ONLINE/OFFLINE bool setPeerState(const SSLIdType& peerId,uint32_t state,uint32_t maxRate); //state = ONLINE/OFFLINE
bool getFileSources(std::list<std::string> &peerIds); bool getFileSources(std::list<SSLIdType> &peerIds);
bool getPeerState(const std::string& peerId,uint32_t &state,uint32_t &tfRate); bool getPeerState(const SSLIdType& peerId,uint32_t &state,uint32_t &tfRate);
uint32_t getDataRate(const std::string& peerId); uint32_t getDataRate(const SSLIdType& peerId);
bool cancelTransfer(); bool cancelTransfer();
bool cancelFileTransferUpward(); bool cancelFileTransferUpward();
bool completeFileTransfer(); bool completeFileTransfer();
@ -138,11 +138,11 @@ public:
void forceCheck() ; void forceCheck() ;
//interface to multiplex module //interface to multiplex module
bool recvFileData(const std::string& peerId, uint64_t offset, uint32_t chunk_size, void *data); bool recvFileData(const SSLIdType& peerId, uint64_t offset, uint32_t chunk_size, void *data);
void locked_requestData(const std::string& peerId, uint64_t offset, uint32_t chunk_size); void locked_requestData(const SSLIdType& peerId, uint64_t offset, uint32_t chunk_size);
//interface to file creator //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 SSLIdType& 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); bool locked_storeData(uint64_t offset, uint32_t chunk_size, void *data);
int tick(); int tick();
@ -180,8 +180,8 @@ private:
RsMutex tfMtx; /* below is mutex protected */ RsMutex tfMtx; /* below is mutex protected */
std::list<std::string> mOnlinePeers; std::list<SSLIdType> mOnlinePeers;
std::map<std::string,peerInfo> mFileSources; std::map<SSLIdType,peerInfo> mFileSources;
uint16_t mFlag; //2:file canceled, 1:transfer complete, 0: not complete, 3: checking hash, 4: checking chunks uint16_t mFlag; //2:file canceled, 1:transfer complete, 0: not complete, 3: checking hash, 4: checking chunks
double desiredRate; double desiredRate;

View file

@ -113,6 +113,7 @@ PUBLIC_HEADERS = retroshare/rsdisc.h \
retroshare/rsmsgs.h \ retroshare/rsmsgs.h \
retroshare/rsnotify.h \ retroshare/rsnotify.h \
retroshare/rspeers.h \ retroshare/rspeers.h \
retroshare/rsids.h \
retroshare/rsrank.h \ retroshare/rsrank.h \
retroshare/rsstatus.h \ retroshare/rsstatus.h \
retroshare/rsturtle.h \ retroshare/rsturtle.h \
@ -357,7 +358,7 @@ HEADERS += pqi/authssl.h \
pqi/pqiqos.h \ pqi/pqiqos.h \
pqi/pqi.h \ pqi/pqi.h \
pqi/pqi_base.h \ pqi/pqi_base.h \
pqi/pqiarchive.h \ # pqi/pqiarchive.h \
pqi/pqiassist.h \ pqi/pqiassist.h \
pqi/pqibin.h \ pqi/pqibin.h \
pqi/pqihandler.h \ pqi/pqihandler.h \
@ -485,7 +486,7 @@ SOURCES += pqi/authgpg.cc \
pqi/p3netmgr.cc \ pqi/p3netmgr.cc \
pqi/p3notify.cc \ pqi/p3notify.cc \
pqi/pqiqos.cc \ pqi/pqiqos.cc \
pqi/pqiarchive.cc \ # pqi/pqiarchive.cc \
pqi/pqibin.cc \ pqi/pqibin.cc \
pqi/pqihandler.cc \ pqi/pqihandler.cc \
pqi/p3historymgr.cc \ pqi/p3historymgr.cc \

View file

@ -126,7 +126,7 @@ PGPHandler::PGPHandler(const std::string& pubring, const std::string& secring,co
int i=0 ; int i=0 ;
while( (keydata = ops_keyring_get_key_by_index(_pubring,i)) != NULL ) 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[ PGPIdType(keydata->key_id) ]) ;
// Init all certificates. // Init all certificates.
@ -152,7 +152,7 @@ PGPHandler::PGPHandler(const std::string& pubring, const std::string& secring,co
i=0 ; i=0 ;
while( (keydata = ops_keyring_get_key_by_index(_secring,i)) != NULL ) 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[ PGPIdType(keydata->key_id) ],keydata,i) ;
++i ; ++i ;
} }
_secring_last_update_time = time(NULL) ; _secring_last_update_time = time(NULL) ;
@ -246,11 +246,11 @@ bool PGPHandler::validateAndUpdateSignatures(PGPCertificateInfo& cert,const ops_
if(result != NULL) if(result != NULL)
for(size_t i=0;i<result->valid_count;++i) for(size_t i=0;i<result->valid_count;++i)
{ {
std::string signer_str = PGPIdType(result->valid_sigs[i].signer_id).toStdString() ; PGPIdType 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 ; 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; std::cerr << "Printing details of all " << std::dec << _public_keyring_map.size() << " keys: " << std::endl;
#endif #endif
for(std::map<std::string,PGPCertificateInfo>::const_iterator it(_public_keyring_map.begin()); it != _public_keyring_map.end(); it++) for(std::map<PGPIdType,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 << "\tName : " << it->second._name << std::endl;
std::cerr << "\tEmail : " << it->second._email << 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 << "\tfingerprint : " << it->second._fpr.toStdString() << std::endl;
std::cerr << "\tSigners : " << it->second.signers.size() << std::endl; std::cerr << "\tSigners : " << it->second.signers.size() << std::endl;
std::set<std::string>::const_iterator sit; std::set<PGPIdType>::const_iterator sit;
for(sit = it->second.signers.begin(); sit != it->second.signers.end(); sit++) for(sit = it->second.signers.begin(); sit != it->second.signers.end(); sit++)
{ {
std::cerr << "\t\tSigner ID:" << *sit << ", Name: " ; std::cerr << "\t\tSigner ID:" << (*sit).toStdString() << ", Name: " ;
const PGPCertificateInfo *info = PGPHandler::getCertificateInfo(PGPIdType(*sit)) ; const PGPCertificateInfo *info = PGPHandler::getCertificateInfo(*sit) ;
if(info != NULL) if(info != NULL)
std::cerr << info->_name ; std::cerr << info->_name ;
@ -325,7 +325,7 @@ const PGPCertificateInfo *PGPHandler::getCertificateInfo(const PGPIdType& id) co
{ {
RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP memory structures. 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<PGPIdType,PGPCertificateInfo>::const_iterator it( _public_keyring_map.find(id) ) ;
if(it != _public_keyring_map.end()) if(it != _public_keyring_map.end())
return &it->second; return &it->second;
@ -432,7 +432,7 @@ bool PGPHandler::GeneratePGPCertificate(const std::string& name, const std::stri
pgpId = PGPIdType(tmp_secring->keys[0].key_id) ; pgpId = PGPIdType(tmp_secring->keys[0].key_id) ;
addNewKeyToOPSKeyring(_secring,tmp_secring->keys[0]) ; 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 #ifdef DEBUG_PGPHANDLER
std::cerr << "Added new secret key with id " << pgpId.toStdString() << " to secret keyring." << std::endl; std::cerr << "Added new secret key with id " << pgpId.toStdString() << " to secret keyring." << std::endl;
@ -548,7 +548,7 @@ std::string PGPHandler::makeRadixEncodedPGPKey(const ops_keydata_t *key,bool inc
const ops_keydata_t *PGPHandler::locked_getSecretKey(const PGPIdType& id) const const ops_keydata_t *PGPHandler::locked_getSecretKey(const PGPIdType& id) const
{ {
std::map<std::string,PGPCertificateInfo>::const_iterator res = _secret_keyring_map.find(id.toStdString()) ; std::map<PGPIdType,PGPCertificateInfo>::const_iterator res = _secret_keyring_map.find(id) ;
if(res == _secret_keyring_map.end()) if(res == _secret_keyring_map.end())
return NULL ; return NULL ;
@ -557,7 +557,7 @@ const ops_keydata_t *PGPHandler::locked_getSecretKey(const PGPIdType& id) const
} }
const ops_keydata_t *PGPHandler::locked_getPublicKey(const PGPIdType& id,bool stamp_the_key) const const ops_keydata_t *PGPHandler::locked_getPublicKey(const PGPIdType& id,bool stamp_the_key) const
{ {
std::map<std::string,PGPCertificateInfo>::const_iterator res = _public_keyring_map.find(id.toStdString()) ; std::map<PGPIdType,PGPCertificateInfo>::const_iterator res = _public_keyring_map.find(id) ;
if(res == _public_keyring_map.end()) if(res == _public_keyring_map.end())
return NULL ; return NULL ;
@ -667,7 +667,7 @@ bool PGPHandler::exportGPGKeyPair(const std::string& filename,const PGPIdType& e
return true ; 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,PGPIdType& key_id, std::string& name, std::list<PGPIdType>& signers) const
{ {
ops_keyring_t *tmp_keyring = allocateOPSKeyring(); ops_keyring_t *tmp_keyring = allocateOPSKeyring();
ops_memory_t *mem = ops_memory_new() ; ops_memory_t *mem = ops_memory_new() ;
@ -699,7 +699,7 @@ bool PGPHandler::getGPGDetailsFromBinaryBlock(const unsigned char *mem_block,siz
return false ; return false ;
} }
key_id = PGPIdType(tmp_keyring->keys[0].key_id).toStdString() ; key_id = PGPIdType(tmp_keyring->keys[0].key_id) ;
name = std::string((char *)tmp_keyring->keys[0].uids[0].user_id) ; name = std::string((char *)tmp_keyring->keys[0].uids[0].user_id) ;
// now parse signatures. // now parse signatures.
@ -725,14 +725,11 @@ bool PGPHandler::getGPGDetailsFromBinaryBlock(const unsigned char *mem_block,siz
// Parse signers. // Parse signers.
// //
std::set<std::string> signers_set ; // Use a set to remove duplicates. std::set<PGPIdType> signers_set ; // Use a set to remove duplicates.
if(result != NULL) if(result != NULL)
for(size_t i=0;i<result->valid_count;++i) for(size_t i=0;i<result->valid_count;++i)
{ signers_set.insert(PGPIdType(result->valid_sigs[i].signer_id)) ;
std::string signer_str = PGPIdType(result->valid_sigs[i].signer_id).toStdString() ;
signers_set.insert(signer_str) ;
}
ops_validate_result_free(result) ; ops_validate_result_free(result) ;
@ -743,7 +740,7 @@ bool PGPHandler::getGPGDetailsFromBinaryBlock(const unsigned char *mem_block,siz
signers.clear() ; signers.clear() ;
for(std::set<std::string>::const_iterator it(signers_set.begin());it!=signers_set.end();++it) for(std::set<PGPIdType>::const_iterator it(signers_set.begin());it!=signers_set.end();++it)
signers.push_back(*it) ; signers.push_back(*it) ;
return true ; return true ;
@ -900,7 +897,7 @@ bool PGPHandler::importGPGKeyPair(const std::string& filename,PGPIdType& importe
} }
addNewKeyToOPSKeyring(_secring,*seckey) ; 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 else
import_error = "Private key already exists! Not importing it again." ; import_error = "Private key already exists! Not importing it again." ;
@ -1037,7 +1034,7 @@ bool PGPHandler::LoadCertificateFromString(const std::string& pgp_cert,PGPIdType
return true ; 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<PGPIdType,PGPCertificateInfo>& kmap,const ops_keydata_t *keydata)
{ {
bool ret = false ; bool ret = false ;
PGPIdType id(keydata->key_id) ; PGPIdType id(keydata->key_id) ;
@ -1049,7 +1046,7 @@ bool PGPHandler::locked_addOrMergeKey(ops_keyring_t *keyring,std::map<std::strin
// See if the key is already in the keyring // See if the key is already in the keyring
const ops_keydata_t *existing_key = NULL; const ops_keydata_t *existing_key = NULL;
std::map<std::string,PGPCertificateInfo>::const_iterator res = kmap.find(id.toStdString()) ; std::map<PGPIdType,PGPCertificateInfo>::const_iterator res = kmap.find(id) ;
// Checks that // Checks that
// - the key is referenced by keyid // - the key is referenced by keyid
@ -1062,7 +1059,7 @@ bool PGPHandler::locked_addOrMergeKey(ops_keyring_t *keyring,std::map<std::strin
std::cerr << " Key is new. Adding it to keyring" << std::endl; std::cerr << " Key is new. Adding it to keyring" << std::endl;
#endif #endif
addNewKeyToOPSKeyring(keyring,*keydata) ; // the key is new. 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]) ; existing_key = &(keyring->keys[keyring->nkeys-1]) ;
ret = true ; ret = true ;
} }
@ -1080,13 +1077,13 @@ bool PGPHandler::locked_addOrMergeKey(ops_keyring_t *keyring,std::map<std::strin
ret = mergeKeySignatures(const_cast<ops_keydata_t*>(existing_key),keydata) ; ret = mergeKeySignatures(const_cast<ops_keydata_t*>(existing_key),keydata) ;
if(ret) if(ret)
initCertificateInfo(kmap[id.toStdString()],existing_key,res->second._key_index) ; initCertificateInfo(kmap[id],existing_key,res->second._key_index) ;
} }
if(ret) if(ret)
{ {
validateAndUpdateSignatures(kmap[id.toStdString()],existing_key) ; validateAndUpdateSignatures(kmap[id],existing_key) ;
kmap[id.toStdString()]._time_stamp = time(NULL) ; kmap[id]._time_stamp = time(NULL) ;
} }
return ret ; return ret ;
@ -1413,7 +1410,7 @@ bool PGPHandler::privateSignCertificate(const PGPIdType& ownId,const PGPIdType&
// 4 - update signatures. // 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) ; validateAndUpdateSignatures(cert,key_to_sign) ;
cert._flags |= PGPCertificateInfo::PGP_CERTIFICATE_FLAG_HAS_OWN_SIGNATURE ; cert._flags |= PGPCertificateInfo::PGP_CERTIFICATE_FLAG_HAS_OWN_SIGNATURE ;
@ -1424,25 +1421,23 @@ void PGPHandler::updateOwnSignatureFlag(const PGPIdType& own_id)
{ {
RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP memory structures. RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP memory structures.
std::string own_id_str = own_id.toStdString(); if(_public_keyring_map.find(own_id)==_public_keyring_map.end())
if(_public_keyring_map.find(own_id_str)==_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 now, because the following operation would add an entry to _public_keyring_map
return; 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) for(std::map<PGPIdType,PGPCertificateInfo>::iterator it=_public_keyring_map.begin();it!=_public_keyring_map.end();++it)
locked_updateOwnSignatureFlag(it->second,it->first,own_cert,own_id_str) ; 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 PGPIdType& cert_id,const PGPIdType& own_id)
{ {
RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP memory structures. 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<PGPIdType,PGPCertificateInfo>::iterator it( _public_keyring_map.find(cert_id) ) ;
if(it == _public_keyring_map.end()) if(it == _public_keyring_map.end())
{ {
@ -1452,19 +1447,18 @@ void PGPHandler::updateOwnSignatureFlag(const PGPIdType& cert_id,const PGPIdType
PGPCertificateInfo& cert( it->second ); PGPCertificateInfo& cert( it->second );
std::string own_id_str = own_id.toStdString(); PGPCertificateInfo& own_cert(_public_keyring_map[ own_id ]) ;
PGPCertificateInfo& own_cert(_public_keyring_map[ own_id_str ]) ;
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 PGPIdType& cert_id,PGPCertificateInfo& own_cert,const PGPIdType& own_id_str)
{ {
if(cert.signers.find(own_id_str) != cert.signers.end()) if(cert.signers.find(own_id_str) != cert.signers.end())
cert._flags |= PGPCertificateInfo::PGP_CERTIFICATE_FLAG_HAS_OWN_SIGNATURE ; cert._flags |= PGPCertificateInfo::PGP_CERTIFICATE_FLAG_HAS_OWN_SIGNATURE ;
else else
cert._flags &= ~PGPCertificateInfo::PGP_CERTIFICATE_FLAG_HAS_OWN_SIGNATURE ; 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 ; cert._flags |= PGPCertificateInfo::PGP_CERTIFICATE_FLAG_HAS_SIGNED_ME ;
else else
cert._flags &= ~PGPCertificateInfo::PGP_CERTIFICATE_FLAG_HAS_SIGNED_ME ; cert._flags &= ~PGPCertificateInfo::PGP_CERTIFICATE_FLAG_HAS_SIGNED_ME ;
@ -1528,7 +1522,7 @@ void PGPHandler::setAcceptConnexion(const PGPIdType& id,bool b)
{ {
RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP memory structures. RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP memory structures.
std::map<std::string,PGPCertificateInfo>::iterator res = _public_keyring_map.find(id.toStdString()) ; std::map<PGPIdType,PGPCertificateInfo>::iterator res = _public_keyring_map.find(id) ;
if(res != _public_keyring_map.end()) if(res != _public_keyring_map.end())
{ {
@ -1544,27 +1538,27 @@ bool PGPHandler::getGPGFilteredList(std::list<PGPIdType>& list,bool (*filter)(co
RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP directory. RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP directory.
list.clear() ; list.clear() ;
for(std::map<std::string,PGPCertificateInfo>::const_iterator it(_public_keyring_map.begin());it!=_public_keyring_map.end();++it) for(std::map<PGPIdType,PGPCertificateInfo>::const_iterator it(_public_keyring_map.begin());it!=_public_keyring_map.end();++it)
if( filter == NULL || (*filter)(it->second) ) if( filter == NULL || (*filter)(it->second) )
list.push_back(PGPIdType(it->first)) ; list.push_back(PGPIdType(it->first)) ;
return true ; return true ;
} }
bool PGPHandler::isGPGId(const std::string &id) //bool PGPHandler::isGPGId(const std::string &id)
{ //{
return _public_keyring_map.find(id) != _public_keyring_map.end() ; // return _public_keyring_map.find(id) != _public_keyring_map.end() ;
} //}
bool PGPHandler::isGPGSigned(const std::string &id) bool PGPHandler::isGPGSigned(const PGPIdType &id)
{ {
std::map<std::string,PGPCertificateInfo>::const_iterator res = _public_keyring_map.find(id) ; std::map<PGPIdType,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) ; 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 PGPIdType &id)
{ {
std::map<std::string,PGPCertificateInfo>::const_iterator res = _public_keyring_map.find(id) ; std::map<PGPIdType,PGPCertificateInfo>::const_iterator res = _public_keyring_map.find(id) ;
return (res != _public_keyring_map.end()) && (res->second._flags & PGPCertificateInfo::PGP_CERTIFICATE_FLAG_ACCEPT_CONNEXION) ; return (res != _public_keyring_map.end()) && (res->second._flags & PGPCertificateInfo::PGP_CERTIFICATE_FLAG_ACCEPT_CONNEXION) ;
} }
@ -1635,7 +1629,7 @@ bool PGPHandler::privateTrustCertificate(const PGPIdType& id,int trustlvl)
return false ; return false ;
} }
std::map<std::string,PGPCertificateInfo>::iterator it = _public_keyring_map.find(id.toStdString()); std::map<PGPIdType,PGPCertificateInfo>::iterator it = _public_keyring_map.find(id);
if(it == _public_keyring_map.end()) if(it == _public_keyring_map.end())
{ {
@ -1670,13 +1664,13 @@ void PGPHandler::locked_readPrivateTrustDatabase()
std::cerr << " private trust database not found. No trust info loaded." << std::endl ; std::cerr << " private trust database not found. No trust info loaded." << std::endl ;
return ; return ;
} }
std::map<std::string,PGPCertificateInfo>::iterator it ; std::map<PGPIdType,PGPCertificateInfo>::iterator it ;
PrivateTrustPacket trustpacket; PrivateTrustPacket trustpacket;
int n_packets = 0 ; int n_packets = 0 ;
while(fread((void*)&trustpacket,sizeof(PrivateTrustPacket),1,fdb) == 1) while(fread((void*)&trustpacket,sizeof(PrivateTrustPacket),1,fdb) == 1)
{ {
it = _public_keyring_map.find(PGPIdType(trustpacket.user_id).toStdString()) ; it = _public_keyring_map.find(PGPIdType(trustpacket.user_id)) ;
if(it == _public_keyring_map.end()) if(it == _public_keyring_map.end())
{ {
@ -1715,7 +1709,7 @@ bool PGPHandler::locked_writePrivateTrustDatabase()
} }
PrivateTrustPacket trustpacket ; PrivateTrustPacket trustpacket ;
for(std::map<std::string,PGPCertificateInfo>::iterator it = _public_keyring_map.begin();it!=_public_keyring_map.end() ;++it) for(std::map<PGPIdType,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,PGPIdType(it->first).toByteArray(),PGP_KEY_ID_SIZE) ;
trustpacket.trust_level = it->second._trustLvl ; trustpacket.trust_level = it->second._trustLvl ;
@ -1843,7 +1837,7 @@ bool PGPHandler::locked_syncTrustDatabase()
return true ; return true ;
} }
void PGPHandler::locked_mergeKeyringFromDisk( ops_keyring_t *keyring, void PGPHandler::locked_mergeKeyringFromDisk( ops_keyring_t *keyring,
std::map<std::string,PGPCertificateInfo>& kmap, std::map<PGPIdType,PGPCertificateInfo>& kmap,
const std::string& keyring_file) const std::string& keyring_file)
{ {
#ifdef DEBUG_PGPHANDLER #ifdef DEBUG_PGPHANDLER
@ -1922,7 +1916,7 @@ bool PGPHandler::removeKeysFromPGPKeyring(const std::list<PGPIdType>& keys_to_re
continue ; continue ;
} }
std::map<std::string,PGPCertificateInfo>::iterator res = _public_keyring_map.find((*it).toStdString()) ; std::map<PGPIdType,PGPCertificateInfo>::iterator res = _public_keyring_map.find(*it) ;
if(res == _public_keyring_map.end()) if(res == _public_keyring_map.end())
{ {
@ -1952,7 +1946,7 @@ bool PGPHandler::removeKeysFromPGPKeyring(const std::list<PGPIdType>& keys_to_re
const ops_keydata_t *keydata ; const ops_keydata_t *keydata ;
while( (keydata = ops_keyring_get_key_by_index(_pubring,i)) != NULL ) 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[ PGPIdType(keydata->key_id) ]) ;
cert._key_index = i ; cert._key_index = i ;
++i ; ++i ;
} }

View file

@ -8,7 +8,7 @@
#include <map> #include <map>
#include <set> #include <set>
#include <util/rsthreads.h> #include <util/rsthreads.h>
#include <util/rsid.h> #include <retroshare/rsids.h>
extern "C" { extern "C" {
#include <openpgpsdk/types.h> #include <openpgpsdk/types.h>
@ -27,7 +27,7 @@ class PGPCertificateInfo
std::string _email; std::string _email;
std::string _comment; std::string _comment;
std::set<std::string> signers; std::set<PGPIdType> signers;
uint32_t _trustLvl; uint32_t _trustLvl;
uint32_t _validLvl; uint32_t _validLvl;
@ -104,7 +104,7 @@ class PGPHandler
void updateOwnSignatureFlag(const PGPIdType& ownId) ; void updateOwnSignatureFlag(const PGPIdType& ownId) ;
void updateOwnSignatureFlag(const PGPIdType& pgp_id,const PGPIdType& ownId) ; void updateOwnSignatureFlag(const PGPIdType& pgp_id,const PGPIdType& ownId) ;
void locked_updateOwnSignatureFlag(PGPCertificateInfo&, const std::string&, PGPCertificateInfo&, const std::string&) ; void locked_updateOwnSignatureFlag(PGPCertificateInfo&, const PGPIdType&, PGPCertificateInfo&, const PGPIdType&) ;
// Removes the given keys from the keyring. Also backup the keyring to a file which name is automatically generated // 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. // and given pack for proper display.
@ -123,15 +123,15 @@ class PGPHandler
const PGPCertificateInfo *getCertificateInfo(const PGPIdType& id) const ; const PGPCertificateInfo *getCertificateInfo(const PGPIdType& id) const ;
bool isGPGId(const std::string &id); bool isGPGId(const std::string &id);
bool isGPGSigned(const std::string &id); bool isGPGSigned(const PGPIdType &id);
bool isGPGAccepted(const std::string &id); bool isGPGAccepted(const PGPIdType &id);
static void setPassphraseCallback(PassphraseCallback cb) ; static void setPassphraseCallback(PassphraseCallback cb) ;
static PassphraseCallback passphraseCallback() { return _passphrase_callback ; } static PassphraseCallback passphraseCallback() { return _passphrase_callback ; }
// Gets info about the key. Who are the signers, what's the owner's name, etc. // 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,PGPIdType& key_id, std::string& name, std::list<PGPIdType>& signers) const ;
// Debug stuff. // Debug stuff.
virtual bool printKeys() const ; virtual bool printKeys() const ;
@ -161,8 +161,8 @@ class PGPHandler
bool locked_syncPublicKeyring() ; bool locked_syncPublicKeyring() ;
bool locked_syncTrustDatabase() ; bool locked_syncTrustDatabase() ;
void locked_mergeKeyringFromDisk(ops_keyring_t *keyring, std::map<std::string,PGPCertificateInfo>& kmap, const std::string& keyring_file) ; void locked_mergeKeyringFromDisk(ops_keyring_t *keyring, std::map<PGPIdType,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) ; bool locked_addOrMergeKey(ops_keyring_t *keyring,std::map<PGPIdType,PGPCertificateInfo>& kmap,const ops_keydata_t *keydata) ;
// Members. // Members.
// //
@ -171,8 +171,8 @@ class PGPHandler
ops_keyring_t *_pubring ; ops_keyring_t *_pubring ;
ops_keyring_t *_secring ; 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<PGPIdType,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<PGPIdType,PGPCertificateInfo> _secret_keyring_map ;
const std::string _pubring_path ; const std::string _pubring_path ;
const std::string _secring_path ; const std::string _secring_path ;

View file

@ -1,7 +1,7 @@
#pragma once #pragma once
#include <string> #include <string>
#include <util/rsid.h> #include <retroshare/rsids.h>
class RsPeerDetails ; class RsPeerDetails ;

View file

@ -159,9 +159,9 @@ bool AuthGPG::availableGPGCertificatesWithPrivateKeys(std::list<std::string> &id
* This function must be called successfully (return == 1) * This function must be called successfully (return == 1)
* before anything else can be done. (except above fn). * before anything else can be done. (except above fn).
*/ */
int AuthGPG::GPGInit(const std::string &ownId) int AuthGPG::GPGInit(const PGPIdType &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 = PGPIdType(ownId);
@ -312,21 +312,9 @@ bool AuthGPG::DoOwnSignature(const void *data, unsigned int datalen, void *buf_s
/* import to GnuPG and other Certificates */ /* 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) return PGPHandler::VerifySignBin((unsigned char*)data,datalen,(unsigned char*)sig,siglen,withfingerprint) ;
{
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)) ;
} }
bool AuthGPG::exportProfile(const std::string& fname,const std::string& exported_id) bool AuthGPG::exportProfile(const std::string& fname,const std::string& exported_id)
@ -417,10 +405,10 @@ std::string AuthGPG::getGPGEmail(const std::string &id,bool *success)
/**** GPG versions ***/ /**** GPG versions ***/
std::string AuthGPG::getGPGOwnId() PGPIdType AuthGPG::getGPGOwnId()
{ {
RsStackMutex stack(gpgMtxData); /******* LOCKED ******/ RsStackMutex stack(gpgMtxData); /******* LOCKED ******/
return mOwnGpgId.toStdString(); return mOwnGpgId ;
} }
std::string AuthGPG::getGPGOwnName() std::string AuthGPG::getGPGOwnName()
@ -466,31 +454,19 @@ bool AuthGPG::isKeySupported(const std::string& id) const
return !(pc->_flags & PGPCertificateInfo::PGP_CERTIFICATE_FLAG_UNSUPPORTED_ALGORITHM) ; return !(pc->_flags & PGPCertificateInfo::PGP_CERTIFICATE_FLAG_UNSUPPORTED_ALGORITHM) ;
} }
bool AuthGPG::getGPGDetails(const std::string& id, RsPeerDetails &d) bool AuthGPG::getGPGDetails(const PGPIdType& pgp_id, RsPeerDetails &d)
{ {
RsStackMutex stack(gpgMtxData); /******* LOCKED ******/ RsStackMutex stack(gpgMtxData); /******* LOCKED ******/
if(id.length() != 16) const PGPCertificateInfo *pc = PGPHandler::getCertificateInfo(pgp_id) ;
{
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) ;
if(pc == NULL) if(pc == NULL)
return false ; return false ;
const PGPCertificateInfo& cert(*pc) ; const PGPCertificateInfo& cert(*pc) ;
d.id = id ; d.id.clear() ;
d.gpg_id = id ; d.gpg_id = pgp_id ;
d.name = cert._name; d.name = cert._name;
d.lastUsed = cert._time_stamp; d.lastUsed = cert._time_stamp;
d.email = cert._email; d.email = cert._email;
@ -499,10 +475,10 @@ bool AuthGPG::getGPGDetails(const std::string& id, RsPeerDetails &d)
d.ownsign = cert._flags & PGPCertificateInfo::PGP_CERTIFICATE_FLAG_HAS_OWN_SIGNATURE; d.ownsign = cert._flags & PGPCertificateInfo::PGP_CERTIFICATE_FLAG_HAS_OWN_SIGNATURE;
d.gpgSigners.clear() ; d.gpgSigners.clear() ;
for(std::set<std::string>::const_iterator it(cert.signers.begin());it!=cert.signers.end();++it) for(std::set<PGPIdType>::const_iterator it(cert.signers.begin());it!=cert.signers.end();++it)
d.gpgSigners.push_back( *it ) ; d.gpgSigners.push_back( *it ) ;
d.fpr = cert._fpr.toStdString(); d.fpr = cert._fpr ;
d.accept_connection = cert._flags & PGPCertificateInfo::PGP_CERTIFICATE_FLAG_ACCEPT_CONNEXION; d.accept_connection = cert._flags & PGPCertificateInfo::PGP_CERTIFICATE_FLAG_ACCEPT_CONNEXION;
d.hasSignedMe = cert._flags & PGPCertificateInfo::PGP_CERTIFICATE_FLAG_HAS_SIGNED_ME; d.hasSignedMe = cert._flags & PGPCertificateInfo::PGP_CERTIFICATE_FLAG_HAS_SIGNED_ME;
@ -661,7 +637,7 @@ bool AuthGPG::RevokeCertificate(const std::string &id)
return false; return false;
} }
bool AuthGPG::TrustCertificate(const std::string &id, int trustlvl) bool AuthGPG::TrustCertificate(const PGPIdType& id, int trustlvl)
{ {
#ifdef GPG_DEBUG #ifdef GPG_DEBUG
std::cerr << "AuthGPG::TrustCertificate(" << id << ", " << trustlvl << ")" << std::endl; std::cerr << "AuthGPG::TrustCertificate(" << id << ", " << trustlvl << ")" << std::endl;
@ -683,7 +659,7 @@ bool AuthGPG::SignDataBin(const void *data, unsigned int datalen, unsigned char
return DoOwnSignature(data, datalen, sign, signlen); 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); return VerifySignature(data, datalen, sign, signlen, withfingerprint);
} }
@ -707,7 +683,7 @@ int AuthGPG::privateRevokeCertificate(const std::string &/*id*/)
return 0; return 0;
} }
int AuthGPG::privateTrustCertificate(const std::string &id, int trustlvl) int AuthGPG::privateTrustCertificate(const PGPIdType& id, int trustlvl)
{ {
RsStackMutex stack(gpgMtxData); /******* LOCKED ******/ RsStackMutex stack(gpgMtxData); /******* LOCKED ******/

View file

@ -68,7 +68,7 @@ public:
class AuthGPGOperationLoadOrSave : public AuthGPGOperation class AuthGPGOperationLoadOrSave : public AuthGPGOperation
{ {
public: public:
AuthGPGOperationLoadOrSave(bool load, const std::string &gpgId, const std::string &gpgCert, void *userdata) AuthGPGOperationLoadOrSave(bool load, const PGPIdType &gpgId, const PGPIdType &gpgCert, void *userdata)
: AuthGPGOperation(userdata) : AuthGPGOperation(userdata)
{ {
m_load = load; m_load = load;
@ -82,8 +82,8 @@ public:
public: public:
bool m_load; bool m_load;
std::string m_certGpgId; // set for save & load. PGPIdType m_certGpgId; // set for save & load.
std::string m_certGpg; // set for load PGPIdType m_certGpg; // set for load
}; };
class AuthGPGService 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) * @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<PGPIdType> &ids);
/*********************************************************************************/ /*********************************************************************************/
/************************* STAGE 1 ***********************************************/ /************************* 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 */ /* Init by generating new Own PGP Cert, or selecting existing PGP Cert */
virtual int GPGInit(const std::string &ownId); virtual int GPGInit(const PGPIdType &ownId);
virtual bool GeneratePGPCertificate(const std::string& name, const std::string& email, const std::string& passwd, std::string &pgpId, std::string &errString); virtual bool GeneratePGPCertificate(const std::string& name, const std::string& email, const std::string& passwd, PGPIdType &pgpId, std::string &errString);
/*********************************************************************************/ /*********************************************************************************/
/************************* STAGE 3 ***********************************************/ /************************* STAGE 3 ***********************************************/
@ -148,25 +148,25 @@ class AuthGPG: public p3Config, public RsThread, public PGPHandler
* provide access to details in cache list. * provide access to details in cache list.
* *
****/ ****/
virtual std::string getGPGName(const std::string &pgp_id,bool *success = NULL); virtual std::string getGPGName(const PGPIdType &pgp_id,bool *success = NULL);
virtual std::string getGPGEmail(const std::string &pgp_id,bool *success = NULL); virtual std::string getGPGEmail(const PGPIdType &pgp_id,bool *success = NULL);
/* PGP web of trust management */ /* PGP web of trust management */
virtual std::string getGPGOwnId(); virtual PGPIdType getGPGOwnId();
virtual std::string getGPGOwnName(); virtual std::string getGPGOwnName();
//virtual std::string getGPGOwnEmail(); //virtual std::string getGPGOwnEmail();
virtual bool isKeySupported(const std::string &id) const ; virtual bool isKeySupported(const PGPIdType &id) const ;
virtual bool haveSecretKey(const std::string &id) const ; virtual bool haveSecretKey(const PGPIdType &id) const ;
virtual bool getGPGDetails(const std::string &id, RsPeerDetails &d); virtual bool getGPGDetails(const PGPIdType& id, RsPeerDetails &d);
virtual bool getGPGAllList(std::list<std::string> &ids); virtual bool getGPGAllList(std::list<PGPIdType> &ids);
virtual bool getGPGValidList(std::list<std::string> &ids); virtual bool getGPGValidList(std::list<PGPIdType> &ids);
virtual bool getGPGAcceptedList(std::list<std::string> &ids); virtual bool getGPGAcceptedList(std::list<PGPIdType> &ids);
virtual bool getGPGSignedList(std::list<std::string> &ids); virtual bool getGPGSignedList(std::list<PGPIdType> &ids);
virtual bool importProfile(const std::string& filename,std::string& gpg_id,std::string& import_error) ; virtual bool importProfile(const std::string& filename,PGPIdType& gpg_id,std::string& import_error) ;
virtual bool exportProfile(const std::string& filename,const std::string& gpg_id) ; virtual bool exportProfile(const std::string& filename,const PGPIdType& 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<PGPIdType>& pgp_ids,std::string& backup_file,uint32_t& error_code) ;
/*********************************************************************************/ /*********************************************************************************/
/************************* STAGE 4 ***********************************************/ /************************* STAGE 4 ***********************************************/
@ -176,7 +176,7 @@ class AuthGPG: public p3Config, public RsThread, public PGPHandler
* *
****/ ****/
virtual bool LoadCertificateFromString(const std::string &pem, PGPIdType& gpg_id,std::string& error_string); 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 std::string SaveCertificateToString(const RsPeerId &id,bool include_signatures) ;
// Cached certificates. // Cached certificates.
bool getCachedGPGCertificate(const std::string &id, std::string &certificate); bool getCachedGPGCertificate(const std::string &id, std::string &certificate);
@ -191,12 +191,12 @@ class AuthGPG: public p3Config, public RsThread, public PGPHandler
* done in gpgroot already. * done in gpgroot already.
* *
****/ ****/
virtual bool AllowConnection(const std::string &gpg_id, bool accept); virtual bool AllowConnection(const PGPIdType &gpg_id, bool accept);
virtual bool SignCertificateLevel0(const std::string &id); virtual bool SignCertificateLevel0(const PGPIdType &id);
virtual bool RevokeCertificate(const std::string &id); /* Particularly hard - leave for later */ virtual bool RevokeCertificate(const PGPIdType &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 PGPIdType& id, int trustlvl); //trustlvl is 2 for none, 3 for marginal and 4 for full trust
/*********************************************************************************/ /*********************************************************************************/
/************************* STAGE 7 ***********************************************/ /************************* 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 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 PGPIdType& 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 decryptDataBin(const void *data, const uint32_t len, unsigned char *decr, unsigned int *decrlen);
virtual bool decryptTextFromFile( std::string& text,const std::string& filename); 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 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); // 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<PGPIdType>& list,bool (*filter)(const PGPCertificateInfo&) = NULL) ;
//END of PGP public functions //END of PGP public functions
@ -253,12 +253,12 @@ class AuthGPG: public p3Config, public RsThread, public PGPHandler
/* Internal functions */ /* Internal functions */
bool DoOwnSignature(const void *, unsigned int, void *, unsigned int *); 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 */ /* Sign/Trust stuff */
int privateSignCertificate(const std::string &id); int privateSignCertificate(const PGPIdType &id);
int privateRevokeCertificate(const std::string &id); /* revoke the signature on Certificate */ int privateRevokeCertificate(const PGPIdType &id); /* revoke the signature on Certificate */
int privateTrustCertificate(const std::string &id, int trustlvl); int privateTrustCertificate(const PGPIdType& id, int trustlvl);
// store all keys in map mKeyList to avoid calling gpgme exe repeatedly // store all keys in map mKeyList to avoid calling gpgme exe repeatedly
//bool storeAllKeys(); //bool storeAllKeys();

View file

@ -42,6 +42,7 @@
#include "util/rsstring.h" #include "util/rsstring.h"
#include "retroshare/rspeers.h" // for RsPeerDetails structure #include "retroshare/rspeers.h" // for RsPeerDetails structure
#include "retroshare/rsids.h" // for RsPeerDetails structure
#include "rsserver/p3face.h" #include "rsserver/p3face.h"
/******************** notify of new Cert **************************/ /******************** notify of new Cert **************************/
@ -240,7 +241,7 @@ AuthSSL::AuthSSL()
static int verify_x509_callback(int preverify_ok, X509_STORE_CTX *ctx); static int verify_x509_callback(int preverify_ok, X509_STORE_CTX *ctx);
sslcert::sslcert(X509 *x509, std::string pid) sslcert::sslcert(X509 *x509, const SSLIdType& pid)
{ {
certificate = x509; certificate = x509;
id = pid; id = pid;
@ -249,7 +250,7 @@ sslcert::sslcert(X509 *x509, std::string pid)
location = getX509LocString(x509->cert_info->subject); location = getX509LocString(x509->cert_info->subject);
email = ""; email = "";
issuer = getX509CNString(x509->cert_info->issuer); issuer = PGPIdType(std::string(getX509CNString(x509->cert_info->issuer)));
authed = false; authed = false;
} }
@ -426,7 +427,9 @@ static int initLib = 0;
return -1; return -1;
} }
if (!getX509id(x509, mOwnId)) std::string mownidstr ;
if (!getX509id(x509, mownidstr))
{ {
std::cerr << "AuthSSLimpl::InitAuth() getX509id() Failed"; std::cerr << "AuthSSLimpl::InitAuth() getX509id() Failed";
std::cerr << std::endl; std::cerr << std::endl;
@ -435,6 +438,10 @@ static int initLib = 0;
CloseAuth(); CloseAuth();
return -1; return -1;
} }
mOwnId = SSLIdType(mownidstr) ;
assert(!mOwnId.isNull()) ;
/* Check that Certificate is Ok ( virtual function ) /* Check that Certificate is Ok ( virtual function )
* for gpg/pgp or CA verification * for gpg/pgp or CA verification
*/ */
@ -522,7 +529,7 @@ SSL_CTX *AuthSSLimpl::getCTX()
return sslctx; return sslctx;
} }
std::string AuthSSLimpl::OwnId() const SSLIdType& AuthSSLimpl::OwnId()
{ {
#ifdef AUTHSSL_DEBUG #ifdef AUTHSSL_DEBUG
// std::cerr << "AuthSSLimpl::OwnId()" << std::endl; // 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, 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 SSLIdType& sslId)
{ {
/* find certificate. /* find certificate.
* if we don't have - fail. * if we don't have - fail.
@ -677,7 +684,7 @@ X509 *AuthSSLimpl::SignX509ReqWithGPG(X509_REQ *req, long days)
unsigned long chtype = MBSTRING_ASC; unsigned long chtype = MBSTRING_ASC;
X509_NAME *issuer_name = X509_NAME_new(); X509_NAME *issuer_name = X509_NAME_new();
X509_NAME_add_entry_by_txt(issuer_name, "CN", chtype, 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, X509_NAME_add_entry_by_NID(issuer_name, 48, 0,
(unsigned char *) "email@email.com", -1, -1, 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); (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(); BIGNUM *btmp = BN_new();
if (!BN_pseudo_rand(btmp, SERIAL_RAND_BITS, 0, 0)) 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 */ /* extract CN for peer Id */
std::string issuer = getX509CNString(x509->cert_info->issuer); PGPIdType issuer(std::string(getX509CNString(x509->cert_info->issuer)));
RsPeerDetails pd; RsPeerDetails pd;
#ifdef AUTHSSL_DEBUG #ifdef AUTHSSL_DEBUG
std::cerr << "Checking GPG issuer : " << issuer << std::endl ; std::cerr << "Checking GPG issuer : " << issuer.toStdString() << std::endl ;
#endif #endif
if (!AuthGPG::getAuthGPG()->getGPGDetails(issuer, pd)) { if (!AuthGPG::getAuthGPG()->getGPGDetails(issuer, pd)) {
std::cerr << "AuthSSLimpl::AuthX509() X509 NOT authenticated : AuthGPG::getAuthGPG()->getGPGDetails() returned false." << std::endl; std::cerr << "AuthSSLimpl::AuthX509() X509 NOT authenticated : AuthGPG::getAuthGPG()->getGPGDetails() returned false." << std::endl;
@ -1009,7 +1016,7 @@ err:
/* validate + get id */ /* validate + get id */
bool AuthSSLimpl::ValidateCertificate(X509 *x509, std::string &peerId) bool AuthSSLimpl::ValidateCertificate(X509 *x509, SSLIdType &peerId)
{ {
uint32_t auth_diagnostic ; uint32_t auth_diagnostic ;
@ -1022,7 +1029,9 @@ bool AuthSSLimpl::ValidateCertificate(X509 *x509, std::string &peerId)
#endif #endif
return false; return false;
} }
if(!getX509id(x509, peerId)) std::string peerIdstr ;
if(!getX509id(x509, peerIdstr))
{ {
#ifdef AUTHSSL_DEBUG #ifdef AUTHSSL_DEBUG
std::cerr << "AuthSSLimpl::ValidateCertificate() Cannot retrieve peer id from certificate.."; std::cerr << "AuthSSLimpl::ValidateCertificate() Cannot retrieve peer id from certificate..";
@ -1030,6 +1039,7 @@ bool AuthSSLimpl::ValidateCertificate(X509 *x509, std::string &peerId)
#endif #endif
return false; return false;
} }
peerId = SSLIdType(peerIdstr) ;
#ifdef AUTHSSL_DEBUG #ifdef AUTHSSL_DEBUG
std::cerr << "AuthSSLimpl::ValidateCertificate() good certificate."; std::cerr << "AuthSSLimpl::ValidateCertificate() good certificate.";
@ -1058,10 +1068,25 @@ static int verify_x509_callback(int preverify_ok, X509_STORE_CTX *ctx)
if(x509 != NULL) if(x509 != NULL)
{ {
std::string gpgid = getX509CNString(x509->cert_info->issuer); PGPIdType 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 sslcn = getX509CNString(x509->cert_info->subject);
std::string sslid ; std::string sslidstr ;
getX509id(x509,sslid);
getX509id(x509,sslidstr);
SSLIdType sslid(sslidstr) ;
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) ; AuthSSL::getAuthSSL()->setCurrentConnectionAttemptInfo(gpgid,sslid,sslcn) ;
} }
@ -1130,7 +1155,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; std::cerr << "(WW) Certificate was rejected because authentication failed. Diagnostic = " << auth_diagnostic << std::endl;
return false; return false;
} }
std::string pgpid = getX509CNString(X509_STORE_CTX_get_current_cert(ctx)->cert_info->issuer); PGPIdType pgpid = PGPIdType(std::string(getX509CNString(X509_STORE_CTX_get_current_cert(ctx)->cert_info->issuer)));
if (pgpid != AuthGPG::getAuthGPG()->getGPGOwnId() && !AuthGPG::getAuthGPG()->isGPGAccepted(pgpid)) if (pgpid != AuthGPG::getAuthGPG()->getGPGOwnId() && !AuthGPG::getAuthGPG()->isGPGAccepted(pgpid))
{ {
@ -1181,7 +1206,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 SSLIdType& peerId)
{ {
RsStackMutex stack(sslMtx); /******* LOCKED ******/ RsStackMutex stack(sslMtx); /******* LOCKED ******/
@ -1377,7 +1402,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 PGPIdType& gpg_id,const SSLIdType& ssl_id,const std::string& ssl_cn)
{ {
#ifdef AUTHSSL_DEBUG #ifdef AUTHSSL_DEBUG
std::cerr << "AuthSSL: registering connection attempt from:" << std::endl; std::cerr << "AuthSSL: registering connection attempt from:" << std::endl;
@ -1389,7 +1414,7 @@ void AuthSSLimpl::setCurrentConnectionAttemptInfo(const std::string& gpg_id,cons
_last_sslid_to_connect = ssl_id ; _last_sslid_to_connect = ssl_id ;
_last_sslcn_to_connect = ssl_cn ; _last_sslcn_to_connect = ssl_cn ;
} }
void AuthSSLimpl::getCurrentConnectionAttemptInfo(std::string& gpg_id,std::string& ssl_id,std::string& ssl_cn) void AuthSSLimpl::getCurrentConnectionAttemptInfo(PGPIdType& gpg_id,SSLIdType& ssl_id,std::string& ssl_cn)
{ {
gpg_id = _last_gpgid_to_connect ; gpg_id = _last_gpgid_to_connect ;
ssl_id = _last_sslid_to_connect ; ssl_id = _last_sslid_to_connect ;
@ -1397,8 +1422,8 @@ void AuthSSLimpl::getCurrentConnectionAttemptInfo(std::string& gpg_id,std::strin
} }
/* store for discovery */ /* store for discovery */
bool AuthSSLimpl::FailedCertificate(X509 *x509, const std::string& gpgid, bool AuthSSLimpl::FailedCertificate(X509 *x509, const PGPIdType& gpgid,
const std::string& sslid, const SSLIdType& sslid,
const std::string& sslcn, const std::string& sslcn,
const struct sockaddr_storage& addr, const struct sockaddr_storage& addr,
bool incoming) bool incoming)
@ -1424,24 +1449,24 @@ bool AuthSSLimpl::FailedCertificate(X509 *x509, const std::string& gpgid,
#endif #endif
if (incoming) 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) 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 ; 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 ; 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 ; 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 ; 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 ; break ;
case RS_SSL_HANDSHAKE_DIAGNOSTIC_OK: case RS_SSL_HANDSHAKE_DIAGNOSTIC_OK:
case RS_SSL_HANDSHAKE_DIAGNOSTIC_UNKNOWN: case RS_SSL_HANDSHAKE_DIAGNOSTIC_UNKNOWN:
default: 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 #ifdef AUTHSSL_DEBUG
@ -1451,9 +1476,9 @@ bool AuthSSLimpl::FailedCertificate(X509 *x509, const std::string& gpgid,
else else
{ {
if(authed) 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 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 #ifdef AUTHSSL_DEBUG
std::cerr << " Outgoing to: "; std::cerr << " Outgoing to: ";
@ -1468,7 +1493,7 @@ bool AuthSSLimpl::FailedCertificate(X509 *x509, const std::string& gpgid,
return false; return false;
} }
bool AuthSSLimpl::CheckCertificate(std::string id, X509 *x509) bool AuthSSLimpl::CheckCertificate(const SSLIdType& id, X509 *x509)
{ {
(void) id; /* remove unused parameter warning */ (void) id; /* remove unused parameter warning */
@ -1485,9 +1510,9 @@ bool AuthSSLimpl::CheckCertificate(std::string id, X509 *x509)
/* Locked search -> internal help function */ /* Locked search -> internal help function */
bool AuthSSLimpl::locked_FindCert(std::string id, sslcert **cert) bool AuthSSLimpl::locked_FindCert(const SSLIdType& id, sslcert **cert)
{ {
std::map<std::string, sslcert *>::iterator it; std::map<SSLIdType, sslcert *>::iterator it;
if (mCerts.end() != (it = mCerts.find(id))) if (mCerts.end() != (it = mCerts.find(id)))
{ {
@ -1500,9 +1525,9 @@ bool AuthSSLimpl::locked_FindCert(std::string id, sslcert **cert)
/* Remove Certificate */ /* Remove Certificate */
bool AuthSSLimpl::RemoveX509(std::string id) bool AuthSSLimpl::RemoveX509(SSLIdType id)
{ {
std::map<std::string, sslcert *>::iterator it; std::map<SSLIdType, sslcert *>::iterator it;
RsStackMutex stack(sslMtx); /******* LOCKED ******/ RsStackMutex stack(sslMtx); /******* LOCKED ******/
@ -1526,14 +1551,21 @@ bool AuthSSLimpl::RemoveX509(std::string id)
bool AuthSSLimpl::LocalStoreCert(X509* x509) bool AuthSSLimpl::LocalStoreCert(X509* x509)
{ {
//store the certificate in the local cert list //store the certificate in the local cert list
std::string peerId; std::string peerIdstr ;
if(!getX509id(x509, peerId)) if(!getX509id(x509, peerIdstr))
{ {
std::cerr << "AuthSSLimpl::LocalStoreCert() Cannot retrieve peer id from certificate." << std::endl; std::cerr << "AuthSSLimpl::LocalStoreCert() Cannot retrieve peer id from certificate." << std::endl;
#ifdef AUTHSSL_DEBUG #ifdef AUTHSSL_DEBUG
#endif #endif
return false; return false;
} }
SSLIdType peerId(peerIdstr);
if(peerId.isNull())
{
std::cerr << "AuthSSLimpl::LocalStoreCert(): invalid peer id \"" << peerIdstr << "\"" << std::endl;
return false ;
}
RsStackMutex stack(sslMtx); /******* LOCKED ******/ RsStackMutex stack(sslMtx); /******* LOCKED ******/
@ -1547,7 +1579,7 @@ bool AuthSSLimpl::LocalStoreCert(X509* x509)
} }
/* do a search */ /* do a search */
std::map<std::string, sslcert *>::iterator it; std::map<SSLIdType, sslcert *>::iterator it;
if (mCerts.end() != (it = mCerts.find(peerId))) if (mCerts.end() != (it = mCerts.find(peerId)))
{ {
@ -1603,13 +1635,13 @@ bool AuthSSLimpl::saveList(bool& cleanup, std::list<RsItem*>& lst)
// Now save config for network digging strategies // Now save config for network digging strategies
RsConfigKeyValueSet *vitem = new RsConfigKeyValueSet ; RsConfigKeyValueSet *vitem = new RsConfigKeyValueSet ;
std::map<std::string, sslcert*>::iterator mapIt; std::map<SSLIdType, sslcert*>::iterator mapIt;
for (mapIt = mCerts.begin(); mapIt != mCerts.end(); mapIt++) { for (mapIt = mCerts.begin(); mapIt != mCerts.end(); mapIt++) {
if (mapIt->first == mOwnId) { if (mapIt->first == mOwnId) {
continue; continue;
} }
RsTlvKeyValue kv; RsTlvKeyValue kv;
kv.key = mapIt->first; kv.key = mapIt->first.toStdString();
#ifdef AUTHSSL_DEBUG #ifdef AUTHSSL_DEBUG
std::cerr << "AuthSSLimpl::saveList() called (mapIt->first) : " << (mapIt->first) << std::endl ; std::cerr << "AuthSSLimpl::saveList() called (mapIt->first) : " << (mapIt->first) << std::endl ;
#endif #endif
@ -1641,7 +1673,7 @@ bool AuthSSLimpl::loadList(std::list<RsItem*>& load)
std::list<RsTlvKeyValue>::iterator kit; std::list<RsTlvKeyValue>::iterator kit;
for(kit = vitem->tlvkvs.pairs.begin(); kit != vitem->tlvkvs.pairs.end(); kit++) { for(kit = vitem->tlvkvs.pairs.begin(); kit != vitem->tlvkvs.pairs.end(); kit++) {
if (kit->key == mOwnId) { if (SSLIdType(kit->key) == mOwnId) {
continue; continue;
} }

View file

@ -51,8 +51,6 @@
#include "pqi/pqinetwork.h" #include "pqi/pqinetwork.h"
#include "pqi/p3cfgmgr.h" #include "pqi/p3cfgmgr.h"
typedef std::string SSL_id;
/* This #define removes Connection Manager references in AuthSSL. /* This #define removes Connection Manager references in AuthSSL.
* They should not be here. What about Objects and orthogonality? * They should not be here. What about Objects and orthogonality?
* This code is also stopping immediate reconnections from working. * This code is also stopping immediate reconnections from working.
@ -63,20 +61,18 @@ class AuthSSL;
class sslcert class sslcert
{ {
public: public:
sslcert(X509* x509, std::string id); sslcert(X509* x509, const SSLIdType& id);
sslcert(); sslcert();
/* certificate parameters */ /* certificate parameters */
std::string id; SSLIdType id;
std::string name; std::string name;
std::string location; std::string location;
std::string org; std::string org;
std::string email; std::string email;
std::string issuer; PGPIdType issuer;
PGPFingerprintType fpr;
std::string fpr;
//std::list<std::string> signers;
/* Auth settings */ /* Auth settings */
bool authed; bool authed;
@ -106,19 +102,8 @@ virtual bool CloseAuth() = 0;
/*********** Overloaded Functions from p3AuthMgr **********/ /*********** Overloaded Functions from p3AuthMgr **********/
/* get Certificate Id */ /* get Certificate Id */
virtual std::string OwnId() = 0; virtual const SSLIdType& OwnId() = 0;
virtual std::string getOwnLocation() = 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 */ /* Load/Save certificates */
virtual std::string SaveOwnCertificateToString() = 0; 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 SignDataBin(const void*, uint32_t, unsigned char*, unsigned int*) = 0;
virtual bool VerifyOwnSignBin(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, 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 SSLIdType& sslId) = 0;
// return : false if encrypt failed // 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 SSLIdType& peerId) = 0;
// return : false if decrypt fails // return : false if decrypt fails
virtual bool decrypt(void *&out, int &outlen, const void *in, int inlen) = 0; 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 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, SSLIdType& peerId) = 0; /* validate + get id */
public: /* SSL specific functions used in pqissl/pqissllistener */ public: /* SSL specific functions used in pqissl/pqissllistener */
virtual SSL_CTX *getCTX() = 0; virtual SSL_CTX *getCTX() = 0;
/* Restored these functions: */ /* Restored these functions: */
virtual void setCurrentConnectionAttemptInfo(const std::string& gpg_id,const std::string& ssl_id,const std::string& ssl_cn) = 0 ; virtual void setCurrentConnectionAttemptInfo(const PGPIdType& gpg_id,const SSLIdType& 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 getCurrentConnectionAttemptInfo( PGPIdType& gpg_id, SSLIdType& 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 FailedCertificate(X509 *x509, const PGPIdType& gpgid,const SSLIdType& 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 CheckCertificate(const SSLIdType& 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 void setAuthSSL_debug(AuthSSL*) ; // used for debug only. The real function is InitSSL()
static AuthSSL *instance_ssl ; static AuthSSL *instance_ssl ;
@ -177,19 +162,8 @@ virtual bool CloseAuth();
/*********** Overloaded Functions from p3AuthMgr **********/ /*********** Overloaded Functions from p3AuthMgr **********/
/* get Certificate Id */ /* get Certificate Id */
virtual std::string OwnId(); virtual const SSLIdType& OwnId();
virtual std::string getOwnLocation(); 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 */ /* Load/Save certificates */
virtual std::string SaveOwnCertificateToString(); 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 SignDataBin(const void*, uint32_t, unsigned char*, unsigned int*);
virtual bool VerifyOwnSignBin(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, 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 SSLIdType& sslId);
// return : false if encrypt failed // 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 SSLIdType& peerId);
// return : false if decrypt fails // return : false if decrypt fails
virtual bool decrypt(void *&out, int &outlen, const void *in, int inlen); 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 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, SSLIdType& peerId); /* validate + get id */
/*****************************************************************/ /*****************************************************************/
@ -230,24 +204,24 @@ virtual bool ValidateCertificate(X509 *x509, std::string &peerId); /* validate
virtual SSL_CTX *getCTX(); virtual SSL_CTX *getCTX();
/* Restored these functions: */ /* Restored these functions: */
virtual void setCurrentConnectionAttemptInfo(const std::string& gpg_id,const std::string& ssl_id,const std::string& ssl_cn) ; virtual void setCurrentConnectionAttemptInfo(const PGPIdType& gpg_id,const SSLIdType& ssl_id,const std::string& ssl_cn) ;
virtual void getCurrentConnectionAttemptInfo( std::string& gpg_id, std::string& ssl_id, std::string& ssl_cn) ; virtual void getCurrentConnectionAttemptInfo( PGPIdType& gpg_id, SSLIdType& 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 FailedCertificate(X509 *x509, const PGPIdType& gpgid,const SSLIdType& 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 bool CheckCertificate(const SSLIdType& peerId, X509 *x509); /* check that they are exact match */
private: private:
bool LocalStoreCert(X509* x509); bool LocalStoreCert(X509* x509);
bool RemoveX509(std::string id); bool RemoveX509(const SSLIdType id);
/*********** LOCKED Functions ******/ /*********** LOCKED Functions ******/
bool locked_FindCert(std::string id, sslcert **cert); bool locked_FindCert(const SSLIdType& id, sslcert **cert);
/* Data */ /* Data */
/* these variables are constants -> don't need to protect */ /* these variables are constants -> don't need to protect */
SSL_CTX *sslctx; SSL_CTX *sslctx;
std::string mOwnId; SSLIdType mOwnId;
sslcert *mOwnCert; sslcert *mOwnCert;
RsMutex sslMtx; /* protects all below */ RsMutex sslMtx; /* protects all below */
@ -258,11 +232,11 @@ bool locked_FindCert(std::string id, sslcert **cert);
int init; int init;
std::map<std::string, sslcert *> mCerts; std::map<SSLIdType, sslcert *> mCerts;
std::string _last_gpgid_to_connect ; PGPIdType _last_gpgid_to_connect ;
std::string _last_sslcn_to_connect ; std::string _last_sslcn_to_connect ;
std::string _last_sslid_to_connect ; SSLIdType _last_sslid_to_connect ;
}; };
#endif // MRK_AUTH_SSL_HEADER #endif // MRK_AUTH_SSL_HEADER

View file

@ -100,7 +100,7 @@ void p3HistoryMgr::addMessage(bool incoming, const std::string &chatPeerId, cons
item->chatPeerId = chatPeerId; item->chatPeerId = chatPeerId;
item->incoming = incoming; item->incoming = incoming;
item->peerId = peerId; 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->sendTime = chatItem->sendTime;
item->recvTime = chatItem->recvTime; item->recvTime = chatItem->recvTime;

View file

@ -94,7 +94,7 @@ class peerConnectState
public: public:
peerConnectState(); /* init */ peerConnectState(); /* init */
std::string id; SSLIdType id;
/***** Below here not stored permanently *****/ /***** Below here not stored permanently *****/
@ -155,26 +155,26 @@ class p3LinkMgr: public pqiConnectCb
virtual ~p3LinkMgr() { return; } virtual ~p3LinkMgr() { return; }
virtual const std::string getOwnId() = 0; virtual const SSLIdType& getOwnId() = 0;
virtual bool isOnline(const std::string &ssl_id) = 0; virtual bool isOnline(const SSLIdType &ssl_id) = 0;
virtual void getOnlineList(std::list<std::string> &ssl_peers) = 0; virtual void getOnlineList(std::list<SSLIdType> &ssl_peers) = 0;
virtual bool getPeerName(const std::string &ssl_id, std::string &name) = 0; virtual bool getPeerName(const SSLIdType &ssl_id, std::string &name) = 0;
virtual uint32_t getLinkType(const std::string &ssl_id) = 0; virtual uint32_t getLinkType(const SSLIdType &ssl_id) = 0;
/**************** handle monitors *****************/ /**************** handle monitors *****************/
virtual void addMonitor(pqiMonitor *mon) = 0; virtual void addMonitor(pqiMonitor *mon) = 0;
virtual void removeMonitor(pqiMonitor *mon) = 0; virtual void removeMonitor(pqiMonitor *mon) = 0;
/****************** Connections *******************/ /****************** Connections *******************/
virtual bool connectAttempt(const std::string &id, struct sockaddr_storage &raddr, virtual bool connectAttempt(const SSLIdType &id, struct sockaddr_storage &raddr,
struct sockaddr_storage &proxyaddr, struct sockaddr_storage &srcaddr, struct sockaddr_storage &proxyaddr, struct sockaddr_storage &srcaddr,
uint32_t &delay, uint32_t &period, uint32_t &type, uint32_t &flags, uint32_t &bandwidth, uint32_t &delay, uint32_t &period, uint32_t &type, uint32_t &flags, uint32_t &bandwidth,
std::string &domain_addr, uint16_t &domain_port) = 0; 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 connectResult(const SSLIdType &id, bool success, uint32_t flags, const struct sockaddr_storage &remote_peer_address) = 0;
virtual bool retryConnect(const std::string &id) = 0; virtual bool retryConnect(const SSLIdType &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 PGPIdType& gpgid,const SSLIdType& sslid,const std::string& sslcn,const struct sockaddr_storage &addr, bool incoming) = 0;
/* Network Addresses */ /* Network Addresses */
virtual bool setLocalAddress(const struct sockaddr_storage &addr) = 0; 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) ********/ /************* DEPRECIATED FUNCTIONS (TO REMOVE) ********/
virtual void getFriendList(std::list<std::string> &ssl_peers) = 0; // ONLY used by p3peers.cc USE p3PeerMgr instead. virtual void getFriendList(std::list<SSLIdType> &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 bool getFriendNetStatus(const SSLIdType &id, peerConnectState &state) = 0; // ONLY used by p3peers.cc
/************* DEPRECIATED FUNCTIONS (TO REMOVE) ********/ /************* DEPRECIATED FUNCTIONS (TO REMOVE) ********/
virtual int addFriend(const std::string &ssl_id, bool isVisible) = 0; virtual int addFriend(const SSLIdType &ssl_id, bool isVisible) = 0;
/******* overloaded from pqiConnectCb *************/ /******* overloaded from pqiConnectCb *************/
// THESE MUSTn't BE specfied HERE - as overloaded from pqiConnectCb. // THESE MUSTn't BE specfied HERE - as overloaded from pqiConnectCb.
//virtual void peerStatus(std::string id, const pqiIpAddrSet &addrs, //virtual void peerStatus(std::string id, const pqiIpAddrSet &addrs,
@ -212,11 +212,11 @@ class p3LinkMgrIMPL: public p3LinkMgr
/* EXTERNAL INTERFACE */ /* EXTERNAL INTERFACE */
/************************************************************************************************/ /************************************************************************************************/
virtual const std::string getOwnId(); virtual const SSLIdType& getOwnId();
virtual bool isOnline(const std::string &ssl_id); virtual bool isOnline(const SSLIdType &ssl_id);
virtual void getOnlineList(std::list<std::string> &ssl_peers); virtual void getOnlineList(std::list<SSLIdType> &ssl_peers);
virtual bool getPeerName(const std::string &ssl_id, std::string &name); virtual bool getPeerName(const SSLIdType &ssl_id, std::string &name);
virtual uint32_t getLinkType(const std::string &ssl_id); virtual uint32_t getLinkType(const SSLIdType &ssl_id);
/**************** handle monitors *****************/ /**************** handle monitors *****************/
@ -224,32 +224,32 @@ virtual void addMonitor(pqiMonitor *mon);
virtual void removeMonitor(pqiMonitor *mon); virtual void removeMonitor(pqiMonitor *mon);
/****************** Connections *******************/ /****************** Connections *******************/
virtual bool connectAttempt(const std::string &id, struct sockaddr_storage &raddr, virtual bool connectAttempt(const SSLIdType &id, struct sockaddr_storage &raddr,
struct sockaddr_storage &proxyaddr, struct sockaddr_storage &srcaddr, struct sockaddr_storage &proxyaddr, struct sockaddr_storage &srcaddr,
uint32_t &delay, uint32_t &period, uint32_t &type, uint32_t &flags, uint32_t &bandwidth, uint32_t &delay, uint32_t &period, uint32_t &type, uint32_t &flags, uint32_t &bandwidth,
std::string &domain_addr, uint16_t &domain_port); 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 connectResult(const SSLIdType &id, bool success, uint32_t flags, const struct sockaddr_storage &remote_peer_address);
virtual bool retryConnect(const std::string &id); virtual bool retryConnect(const SSLIdType &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 PGPIdType& gpgid,const SSLIdType& sslid,const std::string& sslcn,const struct sockaddr_storage &addr, bool incoming);
/* Network Addresses */ /* Network Addresses */
virtual bool setLocalAddress(const struct sockaddr_storage &addr); virtual bool setLocalAddress(const struct sockaddr_storage &addr);
virtual bool getLocalAddress(struct sockaddr_storage &addr); virtual bool getLocalAddress(struct sockaddr_storage &addr);
/******* overloaded from pqiConnectCb *************/ /******* overloaded from pqiConnectCb *************/
virtual void peerStatus(std::string id, const pqiIpAddrSet &addrs, virtual void peerStatus(const SSLIdType& id, const pqiIpAddrSet &addrs,
uint32_t type, uint32_t flags, uint32_t source); uint32_t type, uint32_t flags, uint32_t source);
virtual void peerConnectRequest(std::string id, const struct sockaddr_storage &raddr, virtual void peerConnectRequest(const SSLIdType& id, const struct sockaddr_storage &raddr,
const struct sockaddr_storage &proxyaddr, const struct sockaddr_storage &srcaddr, const struct sockaddr_storage &proxyaddr, const struct sockaddr_storage &srcaddr,
uint32_t source, uint32_t flags, uint32_t delay, uint32_t bandwidth); uint32_t source, uint32_t flags, uint32_t delay, uint32_t bandwidth);
/************* DEPRECIATED FUNCTIONS (TO REMOVE) ********/ /************* DEPRECIATED FUNCTIONS (TO REMOVE) ********/
virtual void getFriendList(std::list<std::string> &ssl_peers); // ONLY used by p3peers.cc USE p3PeerMgr instead. virtual void getFriendList(std::list<SSLIdType> &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 bool getFriendNetStatus(const SSLIdType &id, peerConnectState &state); // ONLY used by p3peers.cc
/************************************************************************************************/ /************************************************************************************************/
/* Extra IMPL Functions (used by p3PeerMgr, p3NetMgr + Setup) */ /* Extra IMPL Functions (used by p3PeerMgr, p3NetMgr + Setup) */
@ -260,11 +260,11 @@ virtual bool getFriendNetStatus(const std::string &id, peerConnectState &state);
void tick(); void tick();
/* THIS COULD BE ADDED TO INTERFACE */ /* THIS COULD BE ADDED TO INTERFACE */
void setFriendVisibility(const std::string &id, bool isVisible); void setFriendVisibility(const SSLIdType &id, bool isVisible);
/* add/remove friends */ /* add/remove friends */
virtual int addFriend(const std::string &ssl_id, bool isVisible); virtual int addFriend(const SSLIdType &ssl_id, bool isVisible);
int removeFriend(const std::string &ssl_id); int removeFriend(const SSLIdType &ssl_id);
void printPeerLists(std::ostream &out); void printPeerLists(std::ostream &out);
@ -284,12 +284,12 @@ void statusTick();
void tickMonitors(); void tickMonitors();
/* connect attempts UDP */ /* connect attempts UDP */
bool tryConnectUDP(const std::string &id, const struct sockaddr_storage &rUdpAddr, bool tryConnectUDP(const SSLIdType &id, const struct sockaddr_storage &rUdpAddr,
const struct sockaddr_storage &proxyaddr, const struct sockaddr_storage &srcaddr, const struct sockaddr_storage &proxyaddr, const struct sockaddr_storage &srcaddr,
uint32_t flags, uint32_t delay, uint32_t bandwidth); uint32_t flags, uint32_t delay, uint32_t bandwidth);
/* connect attempts TCP */ /* connect attempts TCP */
bool retryConnectTCP(const std::string &id); bool retryConnectTCP(const SSLIdType &id);
void locked_ConnectAttempt_SpecificAddress(peerConnectState *peer, const struct sockaddr_storage &remoteAddr); 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); void locked_ConnectAttempt_CurrentAddresses(peerConnectState *peer, const struct sockaddr_storage &localAddr, const struct sockaddr_storage &serverAddr);
@ -330,8 +330,8 @@ private:
//peerConnectState mOwnState; //peerConnectState mOwnState;
std::map<std::string, peerConnectState> mFriendList; std::map<SSLIdType, peerConnectState> mFriendList;
std::map<std::string, peerConnectState> mOthersList; std::map<SSLIdType, peerConnectState> mOthersList;
std::list<RsPeerGroupItem *> groupList; std::list<RsPeerGroupItem *> groupList;
uint32_t lastGroupId; uint32_t lastGroupId;

View file

@ -96,7 +96,7 @@ peerState::peerState()
std::string textPeerConnectState(peerState &state) 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, "NetMode: %lu\n", state.netMode);
rs_sprintf_append(out, "VisState: Disc: %u Dht: %u\n", state.vs_disc, state.vs_dht); rs_sprintf_append(out, "VisState: Disc: %u Dht: %u\n", state.vs_disc, state.vs_dht);
@ -110,10 +110,7 @@ std::string textPeerConnectState(peerState &state)
} }
p3PeerMgrIMPL::p3PeerMgrIMPL(const std::string& ssl_own_id, p3PeerMgrIMPL::p3PeerMgrIMPL(const SSLIdType& ssl_own_id, const PGPIdType& gpg_own_id, const PGPIdType& gpg_own_name, const RsPeerId& ssl_own_location)
const std::string& gpg_own_id,
const std::string& gpg_own_name,
const std::string& ssl_own_location)
:p3Config(CONFIG_TYPE_PEERS), mPeerMtx("p3PeerMgr"), mStatusChanged(false) :p3Config(CONFIG_TYPE_PEERS), mPeerMtx("p3PeerMgr"), mStatusChanged(false)
{ {
@ -297,7 +294,7 @@ void p3PeerMgrIMPL::tick()
*/ */
const std::string p3PeerMgrIMPL::getOwnId() const SSLIdType& p3PeerMgrIMPL::getOwnId()
{ {
return AuthSSL::getAuthSSL()->OwnId(); return AuthSSL::getAuthSSL()->OwnId();
} }
@ -310,7 +307,7 @@ bool p3PeerMgrIMPL::getOwnNetStatus(peerState &state)
return true; return true;
} }
bool p3PeerMgrIMPL::isFriend(const std::string &id) bool p3PeerMgrIMPL::isFriend(const SSLIdType& id)
{ {
#ifdef PEER_DEBUG_COMMON #ifdef PEER_DEBUG_COMMON
std::cerr << "p3PeerMgrIMPL::isFriend(" << id << ") called" << std::endl; std::cerr << "p3PeerMgrIMPL::isFriend(" << id << ") called" << std::endl;
@ -323,12 +320,12 @@ bool p3PeerMgrIMPL::isFriend(const std::string &id)
return ret; return ret;
} }
bool p3PeerMgrIMPL::getPeerName(const std::string &ssl_id, std::string &name) bool p3PeerMgrIMPL::getPeerName(const SSLIdType &ssl_id, std::string &name)
{ {
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
/* check for existing */ /* check for existing */
std::map<std::string, peerState>::iterator it; std::map<SSLIdType, peerState>::iterator it;
it = mFriendList.find(ssl_id); it = mFriendList.find(ssl_id);
if (it == mFriendList.end()) if (it == mFriendList.end())
{ {
@ -339,12 +336,12 @@ bool p3PeerMgrIMPL::getPeerName(const std::string &ssl_id, std::string &name)
return true; return true;
} }
bool p3PeerMgrIMPL::getGpgId(const std::string &ssl_id, std::string &gpgId) bool p3PeerMgrIMPL::getGpgId(const SSLIdType &ssl_id, PGPIdType &gpgId)
{ {
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
/* check for existing */ /* check for existing */
std::map<std::string, peerState>::iterator it; std::map<SSLIdType, peerState>::iterator it;
it = mFriendList.find(ssl_id); it = mFriendList.find(ssl_id);
if (it == mFriendList.end()) if (it == mFriendList.end())
{ {
@ -364,12 +361,12 @@ bool p3PeerMgrIMPL::isHidden()
} }
bool p3PeerMgrIMPL::isHiddenPeer(const std::string &ssl_id) bool p3PeerMgrIMPL::isHiddenPeer(const SSLIdType &ssl_id)
{ {
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
/* check for existing */ /* check for existing */
std::map<std::string, peerState>::iterator it; std::map<SSLIdType, peerState>::iterator it;
it = mFriendList.find(ssl_id); it = mFriendList.find(ssl_id);
if (it == mFriendList.end()) if (it == mFriendList.end())
{ {
@ -384,7 +381,7 @@ bool p3PeerMgrIMPL::isHiddenPeer(const std::string &ssl_id)
return (it->second).hiddenNode; 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 SSLIdType &ssl_id, const std::string &domain_addr, const uint16_t domain_port)
{ {
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
@ -417,7 +414,7 @@ bool p3PeerMgrIMPL::setHiddenDomainPort(const std::string &ssl_id, const std::st
} }
/* check for existing */ /* check for existing */
std::map<std::string, peerState>::iterator it; std::map<SSLIdType, peerState>::iterator it;
it = mFriendList.find(ssl_id); it = mFriendList.find(ssl_id);
if (it == mFriendList.end()) if (it == mFriendList.end())
{ {
@ -456,12 +453,12 @@ bool p3PeerMgrIMPL::getProxyServerAddress(struct sockaddr_storage &proxy_addr)
return true; 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 SSLIdType &ssl_id, struct sockaddr_storage &proxy_addr, std::string &domain_addr, uint16_t &domain_port)
{ {
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
/* check for existing */ /* check for existing */
std::map<std::string, peerState>::iterator it; std::map<SSLIdType, peerState>::iterator it;
it = mFriendList.find(ssl_id); it = mFriendList.find(ssl_id);
if (it == mFriendList.end()) if (it == mFriendList.end())
{ {
@ -481,7 +478,7 @@ bool p3PeerMgrIMPL::getProxyAddress(const std::string &ssl_id, struct sockaddr_s
} }
// Placeholder until we implement this functionality. // Placeholder until we implement this functionality.
uint32_t p3PeerMgrIMPL::getConnectionType(const std::string &/*sslId*/) uint32_t p3PeerMgrIMPL::getConnectionType(const SSLIdType &/*sslId*/)
{ {
return RS_NET_CONN_TYPE_FRIEND; return RS_NET_CONN_TYPE_FRIEND;
} }
@ -490,15 +487,15 @@ int p3PeerMgrIMPL::getFriendCount(bool ssl, bool online)
{ {
if (online) { if (online) {
// count only online id's // count only online id's
std::list<std::string> onlineIds; std::list<SSLIdType> onlineIds;
mLinkMgr->getOnlineList(onlineIds); mLinkMgr->getOnlineList(onlineIds);
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
std::set<std::string> gpgIds; std::set<PGPIdType> gpgIds;
int count = 0; int count = 0;
std::map<std::string, peerState>::iterator it; std::map<SSLIdType, peerState>::iterator it;
for(it = mFriendList.begin(); it != mFriendList.end(); ++it) { for(it = mFriendList.begin(); it != mFriendList.end(); ++it) {
if (online && std::find(onlineIds.begin(), onlineIds.end(), it->first) == onlineIds.end()) { if (online && std::find(onlineIds.begin(), onlineIds.end(), it->first) == onlineIds.end()) {
continue; continue;
@ -522,22 +519,22 @@ int p3PeerMgrIMPL::getFriendCount(bool ssl, bool online)
} }
// count all gpg id's // count all gpg id's
std::list<std::string> gpgIds; std::list<PGPIdType> gpgIds;
AuthGPG::getAuthGPG()->getGPGAcceptedList(gpgIds); AuthGPG::getAuthGPG()->getGPGAcceptedList(gpgIds);
// add own gpg id, if we have more than one location // add own gpg id, if we have more than one location
std::list<std::string> ownSslIds; std::list<SSLIdType> ownSslIds;
getAssociatedPeers(AuthGPG::getAuthGPG()->getGPGOwnId(), ownSslIds); getAssociatedPeers(AuthGPG::getAuthGPG()->getGPGOwnId(), ownSslIds);
return gpgIds.size() + ((ownSslIds.size() > 0) ? 1 : 0); return gpgIds.size() + ((ownSslIds.size() > 0) ? 1 : 0);
} }
bool p3PeerMgrIMPL::getFriendNetStatus(const std::string &id, peerState &state) bool p3PeerMgrIMPL::getFriendNetStatus(const SSLIdType &id, peerState &state)
{ {
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
/* check for existing */ /* check for existing */
std::map<std::string, peerState>::iterator it; std::map<SSLIdType, peerState>::iterator it;
it = mFriendList.find(id); it = mFriendList.find(id);
if (it == mFriendList.end()) if (it == mFriendList.end())
{ {
@ -549,12 +546,12 @@ bool p3PeerMgrIMPL::getFriendNetStatus(const std::string &id, peerState &state)
} }
bool p3PeerMgrIMPL::getOthersNetStatus(const std::string &id, peerState &state) bool p3PeerMgrIMPL::getOthersNetStatus(const SSLIdType &id, peerState &state)
{ {
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
/* check for existing */ /* check for existing */
std::map<std::string, peerState>::iterator it; std::map<SSLIdType, peerState>::iterator it;
it = mOthersList.find(id); it = mOthersList.find(id);
if (it == mOthersList.end()) if (it == mOthersList.end())
{ {
@ -565,41 +562,7 @@ bool p3PeerMgrIMPL::getOthersNetStatus(const std::string &id, peerState &state)
return true; return true;
} }
#if 0 int p3PeerMgrIMPL::getConnectAddresses(const SSLIdType &id,
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,
struct sockaddr_storage &lAddr, struct sockaddr_storage &eAddr, struct sockaddr_storage &lAddr, struct sockaddr_storage &eAddr,
pqiIpAddrSet &histAddrs, std::string &dyndns) pqiIpAddrSet &histAddrs, std::string &dyndns)
{ {
@ -607,7 +570,7 @@ int p3PeerMgrIMPL::getConnectAddresses(const std::string &id,
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
/* check for existing */ /* check for existing */
std::map<std::string, peerState>::iterator it; std::map<SSLIdType, peerState>::iterator it;
it = mFriendList.find(id); it = mFriendList.find(id);
if (it == mFriendList.end()) if (it == mFriendList.end())
{ {
@ -632,7 +595,7 @@ bool p3PeerMgrIMPL::haveOnceConnected()
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
/* check for existing */ /* check for existing */
std::map<std::string, peerState>::iterator it; std::map<SSLIdType, peerState>::iterator it;
for(it = mFriendList.begin(); it != mFriendList.end(); it++) for(it = mFriendList.begin(); it != mFriendList.end(); it++)
{ {
if (it->second.lastcontact > 0) if (it->second.lastcontact > 0)
@ -660,23 +623,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 SSLIdType& input_id, const PGPIdType& input_gpg_id, uint32_t netMode, uint16_t vs_disc, uint16_t vs_dht, time_t lastContact,ServicePermissionFlags service_flags)
{ {
bool notifyLinkMgr = false; bool notifyLinkMgr = false;
std::string id = input_id ; SSLIdType id = input_id ;
std::string gpg_id = input_gpg_id ; PGPIdType gpg_id = input_gpg_id ;
rslog(RSL_WARNING, p3peermgrzone, "p3PeerMgr::addFriend() id: " + id); rslog(RSL_WARNING, p3peermgrzone, "p3PeerMgr::addFriend() id: " + id.toStdString());
// 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' ;
{ {
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
@ -700,7 +653,7 @@ bool p3PeerMgrIMPL::addFriend(const std::string& input_id, const std::string& in
std::cerr << "p3PeerMgrIMPL::addFriend() " << id << "; gpg_id : " << gpg_id << std::endl; std::cerr << "p3PeerMgrIMPL::addFriend() " << id << "; gpg_id : " << gpg_id << std::endl;
#endif #endif
std::map<std::string, peerState>::iterator it; std::map<SSLIdType, peerState>::iterator it;
if (mFriendList.end() != mFriendList.find(id)) if (mFriendList.end() != mFriendList.find(id))
{ {
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
@ -795,7 +748,7 @@ bool p3PeerMgrIMPL::addFriend(const std::string& input_id, const std::string& in
} }
bool p3PeerMgrIMPL::removeFriend(const std::string &id, bool removePgpId) bool p3PeerMgrIMPL::removeFriend(const SSLIdType &id, bool removePgpId)
{ {
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
@ -805,15 +758,15 @@ bool p3PeerMgrIMPL::removeFriend(const std::string &id, bool removePgpId)
rslog(RSL_WARNING, p3peermgrzone, "p3PeerMgr::removeFriend() id: " + id); rslog(RSL_WARNING, p3peermgrzone, "p3PeerMgr::removeFriend() id: " + id);
std::list<std::string> sslid_toRemove; // This is a list of SSLIds. std::list<SSLIdType> sslid_toRemove; // This is a list of SSLIds.
std::list<std::string> pgpid_toRemove; // This is a list of SSLIds. std::list<PGPIdType> pgpid_toRemove; // This is a list of SSLIds.
{ {
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
/* move to othersList */ /* move to othersList */
bool success = false; bool success = false;
std::map<std::string, peerState>::iterator it; std::map<SSLIdType, peerState>::iterator it;
//remove ssl and gpg_ids //remove ssl and gpg_ids
for(it = mFriendList.begin(); it != mFriendList.end(); it++) for(it = mFriendList.begin(); it != mFriendList.end(); it++)
{ {
@ -834,12 +787,12 @@ bool p3PeerMgrIMPL::removeFriend(const std::string &id, bool removePgpId)
} }
} }
std::list<std::string>::iterator rit; std::list<SSLIdType>::iterator rit;
for(rit = sslid_toRemove.begin(); rit != sslid_toRemove.end(); rit++) for(rit = sslid_toRemove.begin(); rit != sslid_toRemove.end(); rit++)
if (mFriendList.end() != (it = mFriendList.find(*rit))) if (mFriendList.end() != (it = mFriendList.find(*rit)))
mFriendList.erase(it); mFriendList.erase(it);
std::map<std::string,ServicePermissionFlags>::iterator it2 ; std::map<PGPIdType,ServicePermissionFlags>::iterator it2 ;
for(rit = pgpid_toRemove.begin(); rit != pgpid_toRemove.end(); rit++) for(rit = pgpid_toRemove.begin(); rit != pgpid_toRemove.end(); rit++)
if (mFriendsPermissionFlags.end() != (it2 = mFriendsPermissionFlags.find(*rit))) if (mFriendsPermissionFlags.end() != (it2 = mFriendsPermissionFlags.find(*rit)))
@ -850,14 +803,14 @@ bool p3PeerMgrIMPL::removeFriend(const std::string &id, bool removePgpId)
#endif #endif
} }
std::list<std::string>::iterator rit; std::list<SSLIdType>::iterator rit;
for(rit = sslid_toRemove.begin(); rit != sslid_toRemove.end(); rit++) for(rit = sslid_toRemove.begin(); rit != sslid_toRemove.end(); rit++)
{ {
mLinkMgr->removeFriend(*rit); mLinkMgr->removeFriend(*rit);
} }
/* remove id from all groups */ /* remove id from all groups */
std::list<std::string> peerIds; std::list<SSLIdType> peerIds;
peerIds.push_back(id); peerIds.push_back(id);
assignPeersToGroup("", peerIds, false); assignPeersToGroup("", peerIds, false);
@ -882,7 +835,7 @@ void p3PeerMgrIMPL::printPeerLists(std::ostream &out)
out << std::endl; out << std::endl;
std::map<std::string, peerState>::iterator it; std::map<SSLIdType, peerState>::iterator it;
for(it = mFriendList.begin(); it != mFriendList.end(); it++) for(it = mFriendList.begin(); it != mFriendList.end(); it++)
{ {
out << "\t SSL ID: " << it->second.id; out << "\t SSL ID: " << it->second.id;
@ -905,69 +858,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 +948,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 SSLIdType &id, const struct sockaddr_storage &addr)
{ {
bool changed = false; bool changed = false;
@ -1085,7 +975,7 @@ bool p3PeerMgrIMPL::setLocalAddress(const std::string &id, const struct socka
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
/* check if it is a friend */ /* check if it is a friend */
std::map<std::string, peerState>::iterator it; std::map<SSLIdType, peerState>::iterator it;
if (mFriendList.end() == (it = mFriendList.find(id))) if (mFriendList.end() == (it = mFriendList.find(id)))
{ {
if (mOthersList.end() == (it = mOthersList.find(id))) if (mOthersList.end() == (it = mOthersList.find(id)))
@ -1119,7 +1009,7 @@ bool p3PeerMgrIMPL::setLocalAddress(const std::string &id, const struct socka
return changed; return changed;
} }
bool p3PeerMgrIMPL::setExtAddress(const std::string &id, const struct sockaddr_storage &addr) bool p3PeerMgrIMPL::setExtAddress(const SSLIdType &id, const struct sockaddr_storage &addr)
{ {
bool changed = false; bool changed = false;
@ -1141,7 +1031,7 @@ bool p3PeerMgrIMPL::setExtAddress(const std::string &id, const struct sockadd
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
/* check if it is a friend */ /* check if it is a friend */
std::map<std::string, peerState>::iterator it; std::map<SSLIdType, peerState>::iterator it;
if (mFriendList.end() == (it = mFriendList.find(id))) if (mFriendList.end() == (it = mFriendList.find(id)))
{ {
if (mOthersList.end() == (it = mOthersList.find(id))) if (mOthersList.end() == (it = mOthersList.find(id)))
@ -1176,7 +1066,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 SSLIdType &id, const std::string &dyndns)
{ {
bool changed = false; bool changed = false;
@ -1194,7 +1084,7 @@ bool p3PeerMgrIMPL::setDynDNS(const std::string &id, const std::string &dyndns)
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
/* check if it is a friend */ /* check if it is a friend */
std::map<std::string, peerState>::iterator it; std::map<SSLIdType, peerState>::iterator it;
if (mFriendList.end() == (it = mFriendList.find(id))) if (mFriendList.end() == (it = mFriendList.find(id)))
{ {
if (mOthersList.end() == (it = mOthersList.find(id))) if (mOthersList.end() == (it = mOthersList.find(id)))
@ -1216,7 +1106,7 @@ bool p3PeerMgrIMPL::setDynDNS(const std::string &id, const std::string &dyndns)
return changed; return changed;
} }
bool p3PeerMgrIMPL::updateAddressList(const std::string& id, const pqiIpAddrSet &addrs) bool p3PeerMgrIMPL::updateAddressList(const SSLIdType& id, const pqiIpAddrSet &addrs)
{ {
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
std::cerr << "p3PeerMgrIMPL::setAddressList() called for id : " << id << std::endl; std::cerr << "p3PeerMgrIMPL::setAddressList() called for id : " << id << std::endl;
@ -1232,7 +1122,7 @@ bool p3PeerMgrIMPL::updateAddressList(const std::string& id, const pqiIpAddrS
} }
/* check if it is a friend */ /* check if it is a friend */
std::map<std::string, peerState>::iterator it; std::map<SSLIdType, peerState>::iterator it;
if (mFriendList.end() == (it = mFriendList.find(id))) if (mFriendList.end() == (it = mFriendList.find(id)))
{ {
if (mOthersList.end() == (it = mOthersList.find(id))) if (mOthersList.end() == (it = mOthersList.find(id)))
@ -1261,7 +1151,7 @@ bool p3PeerMgrIMPL::updateAddressList(const std::string& id, const pqiIpAddrS
} }
bool p3PeerMgrIMPL::updateCurrentAddress(const std::string& id, const pqiIpAddress &addr) bool p3PeerMgrIMPL::updateCurrentAddress(const SSLIdType& id, const pqiIpAddress &addr)
{ {
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
std::cerr << "p3PeerMgrIMPL::updateCurrentAddress() called for id : " << id << std::endl; std::cerr << "p3PeerMgrIMPL::updateCurrentAddress() called for id : " << id << std::endl;
@ -1272,7 +1162,7 @@ bool p3PeerMgrIMPL::updateCurrentAddress(const std::string& id, const pqiIpAd
/* cannot be own id */ /* cannot be own id */
/* check if it is a friend */ /* check if it is a friend */
std::map<std::string, peerState>::iterator it; std::map<SSLIdType, peerState>::iterator it;
if (mFriendList.end() == (it = mFriendList.find(id))) if (mFriendList.end() == (it = mFriendList.find(id)))
{ {
if (mOthersList.end() == (it = mOthersList.find(id))) if (mOthersList.end() == (it = mOthersList.find(id)))
@ -1308,7 +1198,7 @@ bool p3PeerMgrIMPL::updateCurrentAddress(const std::string& id, const pqiIpAd
} }
bool p3PeerMgrIMPL::updateLastContact(const std::string& id) bool p3PeerMgrIMPL::updateLastContact(const SSLIdType& id)
{ {
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
std::cerr << "p3PeerMgrIMPL::updateLastContact() called for id : " << id << std::endl; std::cerr << "p3PeerMgrIMPL::updateLastContact() called for id : " << id << std::endl;
@ -1319,7 +1209,7 @@ bool p3PeerMgrIMPL::updateLastContact(const std::string& id)
/* cannot be own id */ /* cannot be own id */
/* check if it is a friend */ /* check if it is a friend */
std::map<std::string, peerState>::iterator it; std::map<SSLIdType, peerState>::iterator it;
if (mFriendList.end() == (it = mFriendList.find(id))) if (mFriendList.end() == (it = mFriendList.find(id)))
{ {
if (mOthersList.end() == (it = mOthersList.find(id))) if (mOthersList.end() == (it = mOthersList.find(id)))
@ -1336,7 +1226,7 @@ bool p3PeerMgrIMPL::updateLastContact(const std::string& id)
return true; return true;
} }
bool p3PeerMgrIMPL::setNetworkMode(const std::string &id, uint32_t netMode) bool p3PeerMgrIMPL::setNetworkMode(const SSLIdType &id, uint32_t netMode)
{ {
if (id == AuthSSL::getAuthSSL()->OwnId()) if (id == AuthSSL::getAuthSSL()->OwnId())
{ {
@ -1345,7 +1235,7 @@ bool p3PeerMgrIMPL::setNetworkMode(const std::string &id, uint32_t netMode)
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
/* check if it is a friend */ /* check if it is a friend */
std::map<std::string, peerState>::iterator it; std::map<SSLIdType, peerState>::iterator it;
if (mFriendList.end() == (it = mFriendList.find(id))) if (mFriendList.end() == (it = mFriendList.find(id)))
{ {
if (mOthersList.end() == (it = mOthersList.find(id))) if (mOthersList.end() == (it = mOthersList.find(id)))
@ -1367,7 +1257,7 @@ bool p3PeerMgrIMPL::setNetworkMode(const std::string &id, uint32_t netMode)
return changed; return changed;
} }
bool p3PeerMgrIMPL::setLocation(const std::string &id, const std::string &location) bool p3PeerMgrIMPL::setLocation(const SSLIdType &id, const std::string &location)
{ {
bool changed = false; bool changed = false;
@ -1386,7 +1276,7 @@ bool p3PeerMgrIMPL::setLocation(const std::string &id, const std::string &loc
} }
/* check if it is a friend */ /* check if it is a friend */
std::map<std::string, peerState>::iterator it; std::map<SSLIdType, peerState>::iterator it;
if (mFriendList.end() != (it = mFriendList.find(id))) { if (mFriendList.end() != (it = mFriendList.find(id))) {
if (it->second.location.compare(location) != 0) { if (it->second.location.compare(location) != 0) {
it->second.location = location; it->second.location = location;
@ -1396,7 +1286,7 @@ bool p3PeerMgrIMPL::setLocation(const std::string &id, const std::string &loc
return changed; return changed;
} }
bool p3PeerMgrIMPL::setVisState(const std::string &id, uint16_t vs_disc, uint16_t vs_dht) bool p3PeerMgrIMPL::setVisState(const SSLIdType &id, uint16_t vs_disc, uint16_t vs_dht)
{ {
{ {
std::string out; std::string out;
@ -1415,7 +1305,7 @@ bool p3PeerMgrIMPL::setVisState(const std::string &id, uint16_t vs_disc, uint
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
/* check if it is a friend */ /* check if it is a friend */
std::map<std::string, peerState>::iterator it; std::map<SSLIdType, peerState>::iterator it;
if (mFriendList.end() == (it = mFriendList.find(id))) if (mFriendList.end() == (it = mFriendList.find(id)))
{ {
if (mOthersList.end() == (it = mOthersList.find(id))) if (mOthersList.end() == (it = mOthersList.find(id)))
@ -1563,7 +1453,7 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
saveCleanupList.push_back(item); saveCleanupList.push_back(item);
/* iterate through all friends and save */ /* iterate through all friends and save */
std::map<std::string, peerState>::iterator it; std::map<SSLIdType, peerState>::iterator it;
for(it = mFriendList.begin(); it != mFriendList.end(); it++) for(it = mFriendList.begin(); it != mFriendList.end(); it++)
{ {
item = new RsPeerNetItem(); item = new RsPeerNetItem();
@ -1602,7 +1492,7 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
RsPeerServicePermissionItem *sitem = new RsPeerServicePermissionItem ; RsPeerServicePermissionItem *sitem = new RsPeerServicePermissionItem ;
for(std::map<std::string,ServicePermissionFlags>::const_iterator it(mFriendsPermissionFlags.begin());it!=mFriendsPermissionFlags.end();++it) for(std::map<PGPIdType,ServicePermissionFlags>::const_iterator it(mFriendsPermissionFlags.begin());it!=mFriendsPermissionFlags.end();++it)
{ {
sitem->pgp_ids.push_back(it->first) ; sitem->pgp_ids.push_back(it->first) ;
sitem->service_flags.push_back(it->second) ; sitem->service_flags.push_back(it->second) ;
@ -1677,7 +1567,7 @@ bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
std::cerr << "p3PeerMgrIMPL::loadList() Item Count: " << load.size() << std::endl; std::cerr << "p3PeerMgrIMPL::loadList() Item Count: " << load.size() << std::endl;
#endif #endif
std::string ownId = getOwnId(); SSLIdType ownId = getOwnId();
/* load the list of peers */ /* load the list of peers */
std::list<RsItem *>::iterator it; std::list<RsItem *>::iterator it;
@ -2062,7 +1952,7 @@ bool p3PeerMgrIMPL::getGroupInfoList(std::list<RsGroupInfo> &groupInfoList)
} }
// groupId == "" && assign == false -> remove from all groups // 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<SSLIdType> &peerIds, bool assign)
{ {
if (groupId.empty() && assign == true) { if (groupId.empty() && assign == true) {
return false; return false;
@ -2121,9 +2011,9 @@ bool p3PeerMgrIMPL::assignPeersToGroup(const std::string &groupId, const std::li
********************************************************************** **********************************************************************
**********************************************************************/ **********************************************************************/
ServicePermissionFlags p3PeerMgrIMPL::servicePermissionFlags_sslid(const std::string& ssl_id) ServicePermissionFlags p3PeerMgrIMPL::servicePermissionFlags_sslid(const SSLIdType& ssl_id)
{ {
std::string gpg_id ; PGPIdType gpg_id ;
{ {
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
@ -2133,7 +2023,7 @@ ServicePermissionFlags p3PeerMgrIMPL::servicePermissionFlags_sslid(const std::st
std::cerr << "(EE) p3PeerMgrIMPL::servicePermissionFlags_sslid() called with inconsistent id " << ssl_id << std::endl; std::cerr << "(EE) p3PeerMgrIMPL::servicePermissionFlags_sslid() called with inconsistent id " << ssl_id << std::endl;
return RS_SERVICE_PERM_ALL ; return RS_SERVICE_PERM_ALL ;
} }
std::map<std::string, peerState>::const_iterator it = mFriendList.find(ssl_id); std::map<SSLIdType, peerState>::const_iterator it = mFriendList.find(ssl_id);
if(it == mFriendList.end()) if(it == mFriendList.end())
return RS_SERVICE_PERM_ALL ; return RS_SERVICE_PERM_ALL ;
@ -2145,7 +2035,7 @@ ServicePermissionFlags p3PeerMgrIMPL::servicePermissionFlags_sslid(const std::st
} }
ServicePermissionFlags p3PeerMgrIMPL::servicePermissionFlags(const std::string& pgp_id) ServicePermissionFlags p3PeerMgrIMPL::servicePermissionFlags(const PGPIdType& pgp_id)
{ {
// //
if(pgp_id.length() != 16) if(pgp_id.length() != 16)
@ -2157,7 +2047,7 @@ ServicePermissionFlags p3PeerMgrIMPL::servicePermissionFlags(const std::string&
{ {
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
std::map<std::string,ServicePermissionFlags>::const_iterator it = mFriendsPermissionFlags.find( pgp_id ) ; std::map<PGPIdType,ServicePermissionFlags>::const_iterator it = mFriendsPermissionFlags.find( pgp_id ) ;
if(it == mFriendsPermissionFlags.end()) if(it == mFriendsPermissionFlags.end())
return RS_SERVICE_PERM_ALL ; return RS_SERVICE_PERM_ALL ;
@ -2165,7 +2055,7 @@ ServicePermissionFlags p3PeerMgrIMPL::servicePermissionFlags(const std::string&
return it->second ; return it->second ;
} }
} }
void p3PeerMgrIMPL::setServicePermissionFlags(const std::string& pgp_id, const ServicePermissionFlags& flags) void p3PeerMgrIMPL::setServicePermissionFlags(const PGPIdType& pgp_id, const ServicePermissionFlags& flags)
{ {
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
@ -2188,15 +2078,15 @@ void p3PeerMgrIMPL::setServicePermissionFlags(const std::string& pgp_id, const S
********************************************************************** **********************************************************************
**********************************************************************/ **********************************************************************/
bool p3PeerMgrIMPL::removeAllFriendLocations(const std::string &gpgid) bool p3PeerMgrIMPL::removeAllFriendLocations(const PGPIdType &gpgid)
{ {
std::list<std::string> sslIds; std::list<SSLIdType> sslIds;
if (!getAssociatedPeers(gpgid, sslIds)) if (!getAssociatedPeers(gpgid, sslIds))
{ {
return false; return false;
} }
std::list<std::string>::iterator it; std::list<SSLIdType>::iterator it;
for(it = sslIds.begin(); it != sslIds.end(); it++) for(it = sslIds.begin(); it != sslIds.end(); it++)
{ {
removeFriend(*it, true); removeFriend(*it, true);
@ -2206,7 +2096,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 PGPIdType &gpg_id, std::list<SSLIdType> &ids)
{ {
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
@ -2215,7 +2105,7 @@ bool p3PeerMgrIMPL::getAssociatedPeers(const std::string &gpg_id, std::list<std:
#endif #endif
int count = 0; int count = 0;
std::map<std::string, peerState>::iterator it; std::map<SSLIdType, peerState>::iterator it;
for(it = mFriendList.begin(); it != mFriendList.end(); it++) for(it = mFriendList.begin(); it != mFriendList.end(); it++)
{ {
if (it->second.gpg_id == gpg_id) if (it->second.gpg_id == gpg_id)
@ -2240,7 +2130,7 @@ bool p3PeerMgrIMPL::getAssociatedPeers(const std::string &gpg_id, std::list<std:
* We are removing the concept of a "DummyId" - There is no need for it. * We are removing the concept of a "DummyId" - There is no need for it.
*/ */
bool isDummyFriend(std::string id) bool isDummyFriend(SSLIdType id)
{ {
bool ret = (id.substr(0,5) == "dummy"); bool ret = (id.substr(0,5) == "dummy");
return ret; return ret;
@ -2249,7 +2139,7 @@ bool isDummyFriend(std::string id)
bool p3PeerMgrIMPL::removeUnusedLocations() bool p3PeerMgrIMPL::removeUnusedLocations()
{ {
std::list<std::string> toRemove; std::list<SSLIdType> toRemove;
{ {
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
@ -2260,7 +2150,7 @@ bool p3PeerMgrIMPL::removeUnusedLocations()
time_t now = time(NULL); time_t now = time(NULL);
std::map<std::string, peerState>::iterator it; std::map<SSLIdType, peerState>::iterator it;
for(it = mFriendList.begin(); it != mFriendList.end(); it++) for(it = mFriendList.begin(); it != mFriendList.end(); it++)
{ {
if (now - it->second.lastcontact > VERY_OLD_PEER) if (now - it->second.lastcontact > VERY_OLD_PEER)
@ -2285,7 +2175,7 @@ bool p3PeerMgrIMPL::removeUnusedLocations()
} }
} }
std::list<std::string>::iterator it; std::list<SSLIdType>::iterator it;
for(it = toRemove.begin(); it != toRemove.end(); it++) for(it = toRemove.begin(); it != toRemove.end(); it++)
{ {

View file

@ -70,8 +70,8 @@ class peerState
public: public:
peerState(); /* init */ peerState(); /* init */
std::string id; SSLIdType id;
std::string gpg_id; PGPIdType gpg_id;
uint32_t netMode; /* EXT / UPNP / UDP / HIDDEN / INVALID */ uint32_t netMode; /* EXT / UPNP / UDP / HIDDEN / INVALID */
/* visState */ /* visState */
@ -114,15 +114,15 @@ class p3PeerMgr
p3PeerMgr() { return; } p3PeerMgr() { return; }
virtual ~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 SSLIdType &ssl_id, const PGPIdType &gpg_id, uint32_t netMode = RS_NET_MODE_UDP,
uint16_t vsDisc = RS_VS_DISC_FULL, uint16_t vsDht = RS_VS_DHT_FULL, 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; 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 SSLIdType &ssl_id, bool removePgpId) = 0;
virtual bool isFriend(const std::string &ssl_id) = 0; virtual bool isFriend(const SSLIdType& ssl_id) = 0;
virtual bool getAssociatedPeers(const std::string &gpg_id, std::list<std::string> &ids) = 0; virtual bool getAssociatedPeers(const PGPIdType &gpg_id, std::list<SSLIdType> &ids) = 0;
virtual bool removeAllFriendLocations(const std::string &gpgid) = 0; virtual bool removeAllFriendLocations(const PGPIdType &gpgid) = 0;
/******************** Groups **********************/ /******************** Groups **********************/
@ -133,11 +133,11 @@ virtual bool editGroup(const std::string &groupId, RsGroupInfo &groupInfo) =
virtual bool removeGroup(const std::string &groupId) = 0; virtual bool removeGroup(const std::string &groupId) = 0;
virtual bool getGroupInfo(const std::string &groupId, RsGroupInfo &groupInfo) = 0; virtual bool getGroupInfo(const std::string &groupId, RsGroupInfo &groupInfo) = 0;
virtual bool getGroupInfoList(std::list<RsGroupInfo> &groupInfoList) = 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<SSLIdType> &peerIds, bool assign) = 0;
virtual ServicePermissionFlags servicePermissionFlags(const std::string& gpg_id) =0; virtual ServicePermissionFlags servicePermissionFlags(const PGPIdType& gpg_id) =0;
virtual ServicePermissionFlags servicePermissionFlags_sslid(const std::string& ssl_id) =0; virtual ServicePermissionFlags servicePermissionFlags(const SSLIdType& ssl_id) =0;
virtual void setServicePermissionFlags(const std::string& gpg_id,const ServicePermissionFlags& flags) =0; virtual void setServicePermissionFlags(const PGPIdType& gpg_id,const ServicePermissionFlags& flags) =0;
/**************** Set Net Info ****************/ /**************** Set Net Info ****************/
/* /*
@ -147,19 +147,19 @@ virtual bool assignPeersToGroup(const std::string &groupId, const std::list<s
* 3) p3disc - reasonable * 3) p3disc - reasonable
*/ */
virtual bool setLocalAddress(const std::string &id, const struct sockaddr_storage &addr) = 0; virtual bool setLocalAddress(const SSLIdType &id, const struct sockaddr_storage &addr) = 0;
virtual bool setExtAddress(const std::string &id, const struct sockaddr_storage &addr) = 0; virtual bool setExtAddress(const SSLIdType &id, const struct sockaddr_storage &addr) = 0;
virtual bool setDynDNS(const std::string &id, const std::string &dyndns) = 0; virtual bool setDynDNS(const SSLIdType &id, const std::string &dyndns) = 0;
virtual bool setNetworkMode(const std::string &id, uint32_t netMode) = 0; virtual bool setNetworkMode(const SSLIdType &id, uint32_t netMode) = 0;
virtual bool setVisState(const std::string &id, uint16_t vs_disc, uint16_t vs_dht) = 0; virtual bool setVisState(const SSLIdType &id, uint16_t vs_disc, uint16_t vs_dht) = 0;
virtual bool setLocation(const std::string &pid, const std::string &location) = 0; virtual bool setLocation(const SSLIdType &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 setHiddenDomainPort(const SSLIdType &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 updateCurrentAddress(const SSLIdType& id, const pqiIpAddress &addr) = 0;
virtual bool updateLastContact(const std::string& id) = 0; virtual bool updateLastContact(const SSLIdType& id) = 0;
virtual bool updateAddressList(const std::string& id, const pqiIpAddrSet &addrs) = 0; virtual bool updateAddressList(const SSLIdType& id, const pqiIpAddrSet &addrs) = 0;
// THIS MUST ONLY BE CALLED BY NETMGR!!!! // 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 getOwnNetStatus(peerState &state) = 0;
virtual bool getFriendNetStatus(const std::string &id, peerState &state) = 0; virtual bool getFriendNetStatus(const SSLIdType &id, peerState &state) = 0;
virtual bool getOthersNetStatus(const std::string &id, peerState &state) = 0; virtual bool getOthersNetStatus(const SSLIdType &id, peerState &state) = 0;
virtual bool getPeerName(const std::string &ssl_id, std::string &name) = 0; virtual bool getPeerName(const SSLIdType &ssl_id, std::string &name) = 0;
virtual bool getGpgId(const std::string &sslId, std::string &gpgId) = 0; virtual bool getGpgId(const SSLIdType &sslId, PGPIdType &gpgId) = 0;
virtual uint32_t getConnectionType(const std::string &sslId) = 0; virtual uint32_t getConnectionType(const SSLIdType &sslId) = 0;
virtual bool setProxyServerAddress(const struct sockaddr_storage &proxy_addr) = 0; virtual bool setProxyServerAddress(const struct sockaddr_storage &proxy_addr) = 0;
virtual bool getProxyServerAddress(struct sockaddr_storage &proxy_addr) = 0; virtual bool getProxyServerAddress(struct sockaddr_storage &proxy_addr) = 0;
virtual bool isHidden() = 0; virtual bool isHidden() = 0;
virtual bool isHiddenPeer(const std::string &ssl_id) = 0; virtual bool isHiddenPeer(const SSLIdType &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 getProxyAddress(const SSLIdType &ssl_id, struct sockaddr_storage &proxy_addr, std::string &domain_addr, uint16_t &domain_port) = 0;
virtual int getFriendCount(bool ssl, bool online) = 0; virtual int getFriendCount(bool ssl, bool online) = 0;
@ -214,15 +214,15 @@ class p3PeerMgrIMPL: public p3PeerMgr, public p3Config
/* EXTERNAL INTERFACE */ /* 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 SSLIdType&ssl_id, const PGPIdType&gpg_id, uint32_t netMode = RS_NET_MODE_UDP,
uint16_t vsDisc = RS_VS_DISC_FULL, uint16_t vsDht = RS_VS_DHT_FULL, uint16_t vsDisc = RS_VS_DISC_FULL, uint16_t vsDht = RS_VS_DHT_FULL,
time_t lastContact = 0,ServicePermissionFlags = ServicePermissionFlags(RS_SERVICE_PERM_ALL)); time_t lastContact = 0,ServicePermissionFlags = ServicePermissionFlags(RS_SERVICE_PERM_ALL));
virtual bool removeFriend(const std::string &ssl_id, bool removePgpId); virtual bool removeFriend(const SSLIdType &ssl_id, bool removePgpId);
virtual bool isFriend(const std::string &ssl_id); virtual bool isFriend(const SSLIdType &ssl_id);
virtual bool getAssociatedPeers(const std::string &gpg_id, std::list<std::string> &ids); virtual bool getAssociatedPeers(const PGPIdType &gpg_id, std::list<SSLIdType> &ids);
virtual bool removeAllFriendLocations(const std::string &gpgid); virtual bool removeAllFriendLocations(const PGPIdType &gpgid);
/******************** Groups **********************/ /******************** Groups **********************/
@ -247,19 +247,19 @@ virtual bool assignPeersToGroup(const std::string &groupId, const std::list<s
* 3) p3disc - reasonable * 3) p3disc - reasonable
*/ */
virtual bool setLocalAddress(const std::string &id, const struct sockaddr_storage &addr); virtual bool setLocalAddress(const SSLIdType &id, const struct sockaddr_storage &addr);
virtual bool setExtAddress(const std::string &id, const struct sockaddr_storage &addr); virtual bool setExtAddress(const SSLIdType &id, const struct sockaddr_storage &addr);
virtual bool setDynDNS(const std::string &id, const std::string &dyndns); virtual bool setDynDNS(const SSLIdType &id, const std::string &dyndns);
virtual bool setNetworkMode(const std::string &id, uint32_t netMode); virtual bool setNetworkMode(const SSLIdType &id, uint32_t netMode);
virtual bool setVisState(const std::string &id, uint16_t vs_disc, uint16_t vs_dht); virtual bool setVisState(const SSLIdType &id, uint16_t vs_disc, uint16_t vs_dht);
virtual bool setLocation(const std::string &pid, const std::string &location); virtual bool setLocation(const SSLIdType &pid, const std::string &location);
virtual bool setHiddenDomainPort(const std::string &id, const std::string &domain_addr, const uint16_t domain_port); virtual bool setHiddenDomainPort(const SSLIdType &id, const std::string &domain_addr, const uint16_t domain_port);
virtual bool updateCurrentAddress(const std::string& id, const pqiIpAddress &addr); virtual bool updateCurrentAddress(const SSLIdType& id, const pqiIpAddress &addr);
virtual bool updateLastContact(const std::string& id); virtual bool updateLastContact(const SSLIdType& id);
virtual bool updateAddressList(const std::string& id, const pqiIpAddrSet &addrs); virtual bool updateAddressList(const SSLIdType& id, const pqiIpAddrSet &addrs);
// THIS MUST ONLY BE CALLED BY NETMGR!!!! // THIS MUST ONLY BE CALLED BY NETMGR!!!!
@ -274,18 +274,18 @@ virtual bool UpdateOwnAddress(const struct sockaddr_storage &local_addr, cons
*/ */
virtual bool getOwnNetStatus(peerState &state); virtual bool getOwnNetStatus(peerState &state);
virtual bool getFriendNetStatus(const std::string &id, peerState &state); virtual bool getFriendNetStatus(const SSLIdType &id, peerState &state);
virtual bool getOthersNetStatus(const std::string &id, peerState &state); virtual bool getOthersNetStatus(const SSLIdType &id, peerState &state);
virtual bool getPeerName(const std::string &ssl_id, std::string &name); virtual bool getPeerName(const SSLIdType& ssl_id, std::string& name);
virtual bool getGpgId(const std::string &sslId, std::string &gpgId); virtual bool getGpgId(const SSLIdType& sslId, PGPIdType& gpgId);
virtual uint32_t getConnectionType(const std::string &sslId); virtual uint32_t getConnectionType(const SSLIdType& sslId);
virtual bool setProxyServerAddress(const struct sockaddr_storage &proxy_addr); virtual bool setProxyServerAddress(const struct sockaddr_storage &proxy_addr);
virtual bool getProxyServerAddress(struct sockaddr_storage &proxy_addr); virtual bool getProxyServerAddress(struct sockaddr_storage &proxy_addr);
virtual bool isHidden(); virtual bool isHidden();
virtual bool isHiddenPeer(const std::string &ssl_id); virtual bool isHiddenPeer(const SSLIdType& 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 getProxyAddress(const SSLIdType& ssl_id, struct sockaddr_storage &proxy_addr, std::string &domain_addr, uint16_t &domain_port);
virtual int getFriendCount(bool ssl, bool online); virtual int getFriendCount(bool ssl, bool online);
@ -299,8 +299,8 @@ virtual bool haveOnceConnected();
/* Extra IMPL Functions (used by p3LinkMgr, p3NetMgr + Setup) */ /* Extra IMPL Functions (used by p3LinkMgr, p3NetMgr + Setup) */
/************************************************************************************************/ /************************************************************************************************/
p3PeerMgrIMPL( const std::string& ssl_own_id, p3PeerMgrIMPL( const SSLIdType& ssl_own_id,
const std::string& gpg_own_id, const PGPIdType& gpg_own_id,
const std::string& gpg_own_name, const std::string& gpg_own_name,
const std::string& ssl_own_location) ; const std::string& ssl_own_location) ;
@ -311,11 +311,11 @@ bool setupHiddenNode(const std::string &hiddenAddress, const uint16_t hiddenPor
void tick(); void tick();
const std::string getOwnId(); const SSLIdType& getOwnId();
bool setOwnNetworkMode(uint32_t netMode); bool setOwnNetworkMode(uint32_t netMode);
bool setOwnVisState(uint16_t vs_disc, uint16_t vs_dht); bool setOwnVisState(uint16_t vs_disc, uint16_t vs_dht);
int getConnectAddresses(const std::string &id, int getConnectAddresses(const SSLIdType &id,
struct sockaddr_storage &lAddr, struct sockaddr_storage &eAddr, struct sockaddr_storage &lAddr, struct sockaddr_storage &eAddr,
pqiIpAddrSet &histAddrs, std::string &dyndns); pqiIpAddrSet &histAddrs, std::string &dyndns);
@ -352,15 +352,15 @@ private:
peerState mOwnState; peerState mOwnState;
std::map<std::string, peerState> mFriendList; // <SSLid , peerState> std::map<SSLIdType, peerState> mFriendList; // <SSLid , peerState>
std::map<std::string, peerState> mOthersList; std::map<SSLIdType, peerState> mOthersList;
std::list<RsPeerGroupItem *> groupList; std::list<RsPeerGroupItem *> groupList;
uint32_t lastGroupId; uint32_t lastGroupId;
std::list<RsItem *> saveCleanupList; /* TEMPORARY LIST WHEN SAVING */ std::list<RsItem *> saveCleanupList; /* TEMPORARY LIST WHEN SAVING */
std::map<std::string, ServicePermissionFlags> mFriendsPermissionFlags ; // permission flags for each gpg key std::map<PGPIdType, ServicePermissionFlags> mFriendsPermissionFlags ; // permission flags for each gpg key
struct sockaddr_storage mProxyServerAddress; struct sockaddr_storage mProxyServerAddress;
}; };

View file

@ -37,6 +37,8 @@
* *
*/ */
#ifdef SUSPENDED_UNUSED_CODE
#include "pqi/pqiarchive.h" #include "pqi/pqiarchive.h"
#include "serialiser/rsserial.h" #include "serialiser/rsserial.h"
#include <iostream> #include <iostream>
@ -415,6 +417,6 @@ std::string pqiarchive::gethash()
{ {
return bio->gethash(); return bio->gethash();
} }
#endif

View file

@ -23,7 +23,7 @@
* *
*/ */
#ifdef SUSPENDED_UNUSED_CODE
#ifndef MRK_PQI_ARCHIVE_STREAMER_HEADER #ifndef MRK_PQI_ARCHIVE_STREAMER_HEADER
#define 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 //MRK_PQI_ARCHIVE_STREAMER_HEADER
#endif //SUSPENDED_UNUSED_CODE

View file

@ -69,7 +69,7 @@ int pqihandler::tick()
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/ RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
// tick all interfaces... // tick all interfaces...
std::map<std::string, SearchModule *>::iterator it; std::map<RsPeerId, SearchModule *>::iterator it;
for(it = mods.begin(); it != mods.end(); it++) for(it = mods.begin(); it != mods.end(); it++)
{ {
if (0 < ((it -> second) -> pqi) -> tick()) if (0 < ((it -> second) -> pqi) -> tick())
@ -113,7 +113,7 @@ bool pqihandler::queueOutRsItem(RsItem *item)
int pqihandler::status() int pqihandler::status()
{ {
std::map<std::string, SearchModule *>::iterator it; std::map<RsPeerId, SearchModule *>::iterator it;
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/ RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
{ // for output { // for output
@ -142,7 +142,7 @@ bool pqihandler::AddSearchModule(SearchModule *mod)
{ {
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/ RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
// if peerid used -> error. // if peerid used -> error.
std::map<std::string, SearchModule *>::iterator it; std::map<RsPeerId, SearchModule *>::iterator it;
if (mod->peerid != mod->pqi->PeerId()) if (mod->peerid != mod->pqi->PeerId())
{ {
// ERROR! // ERROR!
@ -182,7 +182,7 @@ bool pqihandler::AddSearchModule(SearchModule *mod)
bool pqihandler::RemoveSearchModule(SearchModule *mod) bool pqihandler::RemoveSearchModule(SearchModule *mod)
{ {
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/ 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++) for(it = mods.begin(); it != mods.end(); it++)
{ {
if (mod == it -> second) 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) int pqihandler::locked_HandleRsItem(RsItem *item, int allowglobal,uint32_t& computed_size)
{ {
computed_size = 0 ; computed_size = 0 ;
std::map<std::string, SearchModule *>::iterator it; std::map<RsPeerId, SearchModule *>::iterator it;
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone, pqioutput(PQL_DEBUG_BASIC, pqihandlerzone,
"pqihandler::HandleRsItem()"); "pqihandler::HandleRsItem()");
@ -302,7 +302,7 @@ int pqihandler::SendRsRawItem(RsRawItem *ns)
int pqihandler::locked_GetItems() int pqihandler::locked_GetItems()
{ {
std::map<std::string, SearchModule *>::iterator it; std::map<RsPeerId, SearchModule *>::iterator it;
RsItem *item; RsItem *item;
int count = 0; int count = 0;
@ -410,7 +410,7 @@ RsRawItem *pqihandler::GetRsRawItem()
static const float MIN_RATE = 0.01; // 10 B/s static const float MIN_RATE = 0.01; // 10 B/s
// NEW extern fn to extract rates. // 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.mMaxRateIn = getMaxRate(true);
total.mMaxRateOut = getMaxRate(false); total.mMaxRateOut = getMaxRate(false);
@ -422,7 +422,7 @@ int pqihandler::ExtractRates(std::map<std::string, RsBwRates> &ratemap, RsBw
/* Lock once rates have been retrieved */ /* Lock once rates have been retrieved */
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/ 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++) for(it = mods.begin(); it != mods.end(); it++)
{ {
SearchModule *mod = (it -> second); SearchModule *mod = (it -> second);
@ -447,7 +447,7 @@ int pqihandler::ExtractRates(std::map<std::string, RsBwRates> &ratemap, RsBw
// internal fn to send updates // internal fn to send updates
int pqihandler::UpdateRates() int pqihandler::UpdateRates()
{ {
std::map<std::string, SearchModule *>::iterator it; std::map<RsPeerId, SearchModule *>::iterator it;
int num_sm = mods.size(); int num_sm = mods.size();
float avail_in = getMaxRate(true); float avail_in = getMaxRate(true);

View file

@ -31,6 +31,7 @@
#include "pqi/pqiqos.h" #include "pqi/pqiqos.h"
#include "util/rsthreads.h" #include "util/rsthreads.h"
#include "retroshare/rstypes.h"
#include <map> #include <map>
#include <list> #include <list>
@ -38,7 +39,7 @@
class SearchModule class SearchModule
{ {
public: public:
std::string peerid; RsPeerId peerid;
PQInterface *pqi; PQInterface *pqi;
SecurityPolicy *sp; SecurityPolicy *sp;
}; };
@ -75,7 +76,7 @@ class pqihandler: public P3Interface, public pqiPublisher
void getCurrentRates(float &in, float &out); void getCurrentRates(float &in, float &out);
// TESTING INTERFACE. // TESTING INTERFACE.
int ExtractRates(std::map<std::string, RsBwRates> &ratemap, RsBwRates &totals); int ExtractRates(std::map<RsPeerId, RsBwRates> &ratemap, RsBwRates &totals);
protected: protected:
/* check to be overloaded by those that can /* check to be overloaded by those that can
@ -91,7 +92,7 @@ class pqihandler: public P3Interface, public pqiPublisher
RsMutex coreMtx; /* MUTEX */ RsMutex coreMtx; /* MUTEX */
std::map<std::string, SearchModule *> mods; std::map<RsPeerId, SearchModule *> mods;
SecurityPolicy *globsec; SecurityPolicy *globsec;
std::list<RsItem *> in_service; std::list<RsItem *> in_service;

View file

@ -26,7 +26,7 @@
#ifndef PQI_HASH_ #ifndef PQI_HASH_
#define PQI_HASH_ #define PQI_HASH_
#include <util/rsid.h> #include <retroshare/rsids.h>
#include <openssl/sha.h> #include <openssl/sha.h>
#include <string> #include <string>
#include <iomanip> #include <iomanip>

View file

@ -35,6 +35,7 @@
#include <string> #include <string>
#include <list> #include <list>
#include "pqi/pqiipset.h" #include "pqi/pqiipset.h"
#include "retroshare/rsids.h"
/************** Define Type/Mode/Source ***************/ /************** Define Type/Mode/Source ***************/
@ -97,10 +98,10 @@ const uint32_t RS_STUN_FRIEND_OF_FRIEND = 0x0040;
class pqipeer class pqipeer
{ {
public: public:
std::string id; SSLIdType id;
std::string name; std::string name;
uint32_t state; uint32_t state;
uint32_t actions; uint32_t actions;
}; };
class p3LinkMgr; class p3LinkMgr;

View file

@ -367,8 +367,8 @@ int pqissllistenbase::acceptconnection()
incoming_connexion_info.ssl = SSL_new(AuthSSL::getAuthSSL() -> getCTX()); incoming_connexion_info.ssl = SSL_new(AuthSSL::getAuthSSL() -> getCTX());
incoming_connexion_info.addr = remote_addr ; incoming_connexion_info.addr = remote_addr ;
incoming_connexion_info.gpgid = "" ; incoming_connexion_info.gpgid.clear() ;
incoming_connexion_info.sslid = "" ; incoming_connexion_info.sslid.clear() ;
incoming_connexion_info.sslcn = "" ; incoming_connexion_info.sslcn = "" ;
SSL_set_fd(incoming_connexion_info.ssl, fd); SSL_set_fd(incoming_connexion_info.ssl, fd);
@ -383,7 +383,7 @@ int pqissllistenbase::continueSSL(IncomingSSLInfo& incoming_connexion_info, bool
// clear the connection info that will be filled in by the callback. // clear the connection info that will be filled in by the callback.
// //
AuthSSL::getAuthSSL()->setCurrentConnectionAttemptInfo(std::string(),std::string(),std::string()) ; AuthSSL::getAuthSSL()->setCurrentConnectionAttemptInfo(PGPIdType(),RsPeerId(),std::string()) ;
int err = SSL_accept(incoming_connexion_info.ssl); int err = SSL_accept(incoming_connexion_info.ssl);
@ -690,14 +690,14 @@ pqissllistener::~pqissllistener()
return; return;
} }
int pqissllistener::addlistenaddr(std::string id, pqissl *acc) int pqissllistener::addlistenaddr(const RsPeerId& id, pqissl *acc)
{ {
std::map<std::string, pqissl *>::iterator it; std::map<RsPeerId, pqissl *>::iterator it;
std::string out = "Adding to Cert Listening Addresses Id: " + id + "\nCurrent Certs:\n"; std::string out = "Adding to Cert Listening Addresses Id: " + id.toStdString() + "\nCurrent Certs:\n";
for(it = listenaddr.begin(); it != listenaddr.end(); it++) for(it = listenaddr.begin(); it != listenaddr.end(); it++)
{ {
out += id + "\n"; out += id.toStdString() + "\n";
if (it -> first == id) if (it -> first == id)
{ {
out += "pqissllistener::addlistenaddr() Already listening for Certificate!\n"; out += "pqissllistener::addlistenaddr() Already listening for Certificate!\n";
@ -715,13 +715,13 @@ int pqissllistener::addlistenaddr(std::string id, pqissl *acc)
return 1; return 1;
} }
int pqissllistener::removeListenPort(std::string id) int pqissllistener::removeListenPort(const RsPeerId& id)
{ {
// check where the connection is coming from. // check where the connection is coming from.
// if in list of acceptable addresses, // if in list of acceptable addresses,
// //
// check if in list. // check if in list.
std::map<std::string, pqissl *>::iterator it; std::map<RsPeerId, pqissl *>::iterator it;
for(it = listenaddr.begin();it!=listenaddr.end();it++) for(it = listenaddr.begin();it!=listenaddr.end();it++)
{ {
if (it->first == id) if (it->first == id)
@ -745,14 +745,14 @@ int pqissllistener::status()
{ {
pqissllistenbase::status(); pqissllistenbase::status();
// print certificates we are listening for. // print certificates we are listening for.
std::map<std::string, pqissl *>::iterator it; std::map<RsPeerId, pqissl *>::iterator it;
std::string out = "pqissllistener::status(): Listening ("; std::string out = "pqissllistener::status(): Listening (";
out += sockaddr_storage_tostring(laddr); out += sockaddr_storage_tostring(laddr);
out += ") for Certs:"; out += ") for Certs:";
for(it = listenaddr.begin(); it != listenaddr.end(); it++) for(it = listenaddr.begin(); it != listenaddr.end(); it++)
{ {
out += "\n" + it -> first ; out += "\n" + it -> first.toStdString() ;
} }
pqioutput(PQL_DEBUG_ALL, pqissllistenzone, out); pqioutput(PQL_DEBUG_ALL, pqissllistenzone, out);
@ -776,7 +776,7 @@ int pqissllistener::completeConnection(int fd, IncomingSSLInfo& info)
} }
// Check cert. // Check cert.
std::string newPeerId; RsPeerId newPeerId;
/**** /****
@ -787,7 +787,7 @@ int pqissllistener::completeConnection(int fd, IncomingSSLInfo& info)
bool certOk = AuthSSL::getAuthSSL()->ValidateCertificate(peercert, newPeerId); bool certOk = AuthSSL::getAuthSSL()->ValidateCertificate(peercert, newPeerId);
bool found = false; bool found = false;
std::map<std::string, pqissl *>::iterator it; std::map<RsPeerId, pqissl *>::iterator it;
// Let connected one through as well! if ((npc == NULL) || (npc -> Connected())) // Let connected one through as well! if ((npc == NULL) || (npc -> Connected()))
if (!certOk) if (!certOk)
@ -803,11 +803,11 @@ int pqissllistener::completeConnection(int fd, IncomingSSLInfo& info)
} }
else else
{ {
std::string out = "pqissllistener::continueSSL()\nchecking: " + newPeerId + "\n"; std::string out = "pqissllistener::continueSSL()\nchecking: " + newPeerId.toStdString() + "\n";
// check if cert is in our list..... // check if cert is in our list.....
for(it = listenaddr.begin();(found!=true) && (it!=listenaddr.end());) for(it = listenaddr.begin();(found!=true) && (it!=listenaddr.end());)
{ {
out + "\tagainst: " + it->first + "\n"; out + "\tagainst: " + it->first.toStdString() + "\n";
if (it -> first == newPeerId) if (it -> first == newPeerId)
{ {
// accept even if already connected. // accept even if already connected.
@ -836,7 +836,7 @@ int pqissllistener::completeConnection(int fd, IncomingSSLInfo& info)
AuthSSL::getAuthSSL()->CheckCertificate(newPeerId, peercert); AuthSSL::getAuthSSL()->CheckCertificate(newPeerId, peercert);
/* now need to get GPG id too */ /* now need to get GPG id too */
std::string pgpid = getX509CNString(peercert->cert_info->issuer); PGPIdType pgpid(std::string(getX509CNString(peercert->cert_info->issuer)));
mPeerMgr->addFriend(newPeerId, pgpid); mPeerMgr->addFriend(newPeerId, pgpid);
X509_free(peercert); X509_free(peercert);
@ -856,7 +856,7 @@ int pqissllistener::completeConnection(int fd, IncomingSSLInfo& info)
accepted_ssl.push_back(as); accepted_ssl.push_back(as);
std::string out = "pqissllistener::completeConnection() Successful Connection with: " + newPeerId; std::string out = "pqissllistener::completeConnection() Successful Connection with: " + newPeerId.toStdString();
out += " for Connection:"; out += " for Connection:";
out += sockaddr_storage_tostring(info.addr); out += sockaddr_storage_tostring(info.addr);
out += " Adding to WAIT-ACCEPT Queue"; out += " Adding to WAIT-ACCEPT Queue";
@ -865,12 +865,12 @@ int pqissllistener::completeConnection(int fd, IncomingSSLInfo& info)
return 1; return 1;
} }
int pqissllistener::finaliseConnection(int fd, SSL *ssl, std::string peerId, const struct sockaddr_storage &remote_addr) int pqissllistener::finaliseConnection(int fd, SSL *ssl, const RsPeerId& peerId, const struct sockaddr_storage &remote_addr)
{ {
std::map<std::string, pqissl *>::iterator it; std::map<RsPeerId, pqissl *>::iterator it;
std::string out = "pqissllistener::finaliseConnection()\n"; std::string out = "pqissllistener::finaliseConnection()\n";
out += "checking: " + peerId + "\n"; out += "checking: " + peerId.toStdString() + "\n";
// check if cert is in the list..... // check if cert is in the list.....
it = listenaddr.find(peerId); it = listenaddr.find(peerId);

View file

@ -53,7 +53,7 @@ class AcceptedSSL
int mFd; int mFd;
SSL *mSSL; SSL *mSSL;
std::string mPeerId; RsPeerId mPeerId;
struct sockaddr_storage mAddr; struct sockaddr_storage mAddr;
time_t mAcceptTS; time_t mAcceptTS;
@ -89,8 +89,8 @@ int finaliseAccepts();
{ {
SSL *ssl ; SSL *ssl ;
sockaddr_storage addr ; sockaddr_storage addr ;
std::string gpgid ; PGPIdType gpgid ;
std::string sslid ; SSLIdType sslid ;
std::string sslcn ; std::string sslcn ;
}; };
@ -100,7 +100,7 @@ int closeConnection(int fd, SSL *ssl);
int isSSLActive(int fd, SSL *ssl); int isSSLActive(int fd, SSL *ssl);
virtual int completeConnection(int sockfd, IncomingSSLInfo&) = 0; virtual int completeConnection(int sockfd, IncomingSSLInfo&) = 0;
virtual int finaliseConnection(int fd, SSL *ssl, std::string peerId, const struct sockaddr_storage &raddr) = 0; virtual int finaliseConnection(int fd, SSL *ssl, const RsPeerId& peerId, const struct sockaddr_storage &raddr) = 0;
protected: protected:
struct sockaddr_storage laddr; struct sockaddr_storage laddr;
@ -129,18 +129,18 @@ class pqissllistener: public pqissllistenbase
pqissllistener(const struct sockaddr_storage &addr, p3PeerMgr *pm); pqissllistener(const struct sockaddr_storage &addr, p3PeerMgr *pm);
virtual ~pqissllistener(); virtual ~pqissllistener();
int addlistenaddr(std::string id, pqissl *acc); int addlistenaddr(const RsPeerId& id, pqissl *acc);
int removeListenPort(std::string id); int removeListenPort(const RsPeerId& id);
//virtual int tick(); //virtual int tick();
virtual int status(); virtual int status();
virtual int completeConnection(int sockfd, IncomingSSLInfo&); virtual int completeConnection(int sockfd, IncomingSSLInfo&);
virtual int finaliseConnection(int fd, SSL *ssl, std::string peerId, const struct sockaddr_storage &raddr); virtual int finaliseConnection(int fd, SSL *ssl, const RsPeerId& peerId, const struct sockaddr_storage &raddr);
private: private:
std::map<std::string, pqissl *> listenaddr; std::map<RsPeerId, pqissl *> listenaddr;
}; };

View file

@ -51,7 +51,7 @@ const int PQISTREAM_ABS_MAX = 100000000; /* 100 MB/sec (actually per loop) */
#endif #endif
pqistreamer::pqistreamer(RsSerialiser *rss, std::string id, BinInterface *bio_in, int bio_flags_in) pqistreamer::pqistreamer(RsSerialiser *rss, const RsPeerId& id, BinInterface *bio_in, int bio_flags_in)
:PQInterface(id), mStreamerMtx("pqistreamer"), :PQInterface(id), mStreamerMtx("pqistreamer"),
mBio(bio_in), mBio_flags(bio_flags_in), mRsSerialiser(rss), mBio(bio_in), mBio_flags(bio_flags_in), mRsSerialiser(rss),
mPkt_wpending(NULL), mPkt_wpending(NULL),

View file

@ -30,6 +30,7 @@
// Only dependent on the base stuff. // Only dependent on the base stuff.
#include "pqi/pqi_base.h" #include "pqi/pqi_base.h"
#include "util/rsthreads.h" #include "util/rsthreads.h"
#include "retroshare/rstypes.h"
#include <list> #include <list>
@ -42,7 +43,7 @@
class pqistreamer: public PQInterface class pqistreamer: public PQInterface
{ {
public: public:
pqistreamer(RsSerialiser *rss, std::string peerid, BinInterface *bio_in, int bio_flagsin); pqistreamer(RsSerialiser *rss, const RsPeerId& peerid, BinInterface *bio_in, int bio_flagsin);
virtual ~pqistreamer(); virtual ~pqistreamer();
// PQInterface // PQInterface

View file

@ -119,7 +119,7 @@ class RsFiles
virtual bool alreadyHaveFile(const std::string& hash, FileInfo &info) = 0; virtual bool alreadyHaveFile(const std::string& hash, FileInfo &info) = 0;
/// Returns false is we already have the file. Otherwise, initiates the dl and returns true. /// Returns false is we already have the file. Otherwise, initiates the dl and returns true.
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) = 0; virtual bool FileRequest(const std::string& fname, const std::string& hash, uint64_t size, const std::string& dest, TransferRequestFlags flags, const std::list<SSLIdType>& srcIds) = 0;
virtual bool FileCancel(const std::string& hash) = 0; virtual bool FileCancel(const std::string& hash) = 0;
virtual bool setDestinationDirectory(const std::string& hash,const std::string& new_path) = 0; virtual bool setDestinationDirectory(const std::string& hash,const std::string& new_path) = 0;
virtual bool setDestinationName(const std::string& hash,const std::string& new_name) = 0; virtual bool setDestinationName(const std::string& hash,const std::string& new_name) = 0;
@ -155,7 +155,7 @@ class RsFiles
virtual bool FileDownloadChunksDetails(const std::string& hash,FileChunksInfo& info) = 0 ; virtual bool FileDownloadChunksDetails(const std::string& hash,FileChunksInfo& info) = 0 ;
/// details about the upload with given hash /// details about the upload with given hash
virtual bool FileUploadChunksDetails(const std::string& hash,const std::string& peer_id,CompressedChunkMap& map) = 0 ; virtual bool FileUploadChunksDetails(const std::string& hash,const SSLIdType& peer_id,CompressedChunkMap& map) = 0 ;
/*** /***
* Extra List Access * Extra List Access
@ -172,14 +172,14 @@ class RsFiles
/*** /***
* Directory Listing / Search Interface * Directory Listing / Search Interface
*/ */
virtual int RequestDirDetails(const std::string& uid, const std::string& path, DirDetails &details) = 0; virtual int RequestDirDetails(const SSLIdType& uid, const std::string& path, DirDetails &details) = 0;
virtual int RequestDirDetails(void *ref, DirDetails &details, FileSearchFlags flags) = 0; virtual int RequestDirDetails(void *ref, DirDetails &details, FileSearchFlags flags) = 0;
virtual uint32_t getType(void *ref,FileSearchFlags flags) = 0; virtual uint32_t getType(void *ref,FileSearchFlags flags) = 0;
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags) = 0; virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags) = 0;
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags,const std::string& peer_id) = 0; virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags,const SSLIdType& peer_id) = 0;
virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags) = 0; virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags) = 0;
virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags,const std::string& peer_id) = 0; virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags,const SSLIdType& peer_id) = 0;
/*** /***
* Utility Functions. * Utility Functions.

View file

@ -43,7 +43,6 @@ extern RsGxsCircles *rsGxsCircles;
typedef std::string RsGxsCircleId; typedef std::string RsGxsCircleId;
typedef std::string RsPeerId; // SSL ID.
typedef std::string RsPgpId; typedef std::string RsPgpId;
typedef std::string RsCircleInternalId; typedef std::string RsCircleInternalId;

View file

@ -0,0 +1,173 @@
// This class aims at defining a generic ID type that is a list of bytes. It
// can be converted into a hexadecial string for printing, mainly) or for
// compatibility with old methods.
//
// To use this class, derive your own ID type from it. Examples include:
//
// class PGPIdType: public t_RsGenericIdType<8>
// {
// [..]
// };
//
// class PGPFingerprintType: public t_RsGenericIdType<20>
// {
// [..]
// };
//
// With this, there is no implicit conversion between subtypes, and therefore ID mixup
// is impossible.
//
// A simpler way to make ID types is to
// typedef t_RsGenericIdType<MySize> MyType ;
//
// ID Types with different lengths will be incompatible on compilation.
//
// Warning: never store references to a t_RsGenericIdType accross threads, since the
// cached string convertion is not thread safe.
//
#pragma once
#include <stdexcept>
#include <string>
#include <iostream>
#include <ostream>
#include <string.h>
#include <stdint.h>
#include <util/rsrandom.h>
template<uint32_t ID_SIZE_IN_BYTES,uint32_t UNIQUE_IDENTIFIER> class t_RsGenericIdType
{
public:
t_RsGenericIdType()
{
memset(bytes,0,ID_SIZE_IN_BYTES) ; // by default, ids are set to null()
}
virtual ~t_RsGenericIdType() {}
// Explicit constructor from a hexadecimal string
//
explicit t_RsGenericIdType(const std::string& hex_string) ;
// Explicit constructor from a byte array. The array should have size at least ID_SIZE_IN_BYTES
//
explicit t_RsGenericIdType(const unsigned char bytes[]) ;
// Random initialization. Can be useful for testing.
//
static t_RsGenericIdType<ID_SIZE_IN_BYTES,UNIQUE_IDENTIFIER> random()
{
t_RsGenericIdType<ID_SIZE_IN_BYTES,UNIQUE_IDENTIFIER> id ;
for(uint32_t i=0;i<ID_SIZE_IN_BYTES;++i)
id.bytes[i] = RSRandom::random_u32() & 0xff ;
return id ;
}
inline void clear() { bzero(bytes,SIZE_IN_BYTES) ; }
// Converts to a std::string using cached value.
//
std::string toStdString(bool upper_case = true) const ;
const unsigned char *toByteArray() const { return &bytes[0] ; }
static const uint32_t SIZE_IN_BYTES = ID_SIZE_IN_BYTES ;
inline bool operator==(const t_RsGenericIdType<ID_SIZE_IN_BYTES,UNIQUE_IDENTIFIER>& fp) const { return !memcmp(bytes,fp.bytes,ID_SIZE_IN_BYTES) ; }
inline bool operator!=(const t_RsGenericIdType<ID_SIZE_IN_BYTES,UNIQUE_IDENTIFIER>& fp) const { return !!memcmp(bytes,fp.bytes,ID_SIZE_IN_BYTES); }
inline bool operator< (const t_RsGenericIdType<ID_SIZE_IN_BYTES,UNIQUE_IDENTIFIER>& fp) const { return (memcmp(bytes,fp.bytes,ID_SIZE_IN_BYTES) < 0) ; }
inline bool isNull() const
{
for(int i=0;i<SIZE_IN_BYTES;++i)
if(bytes[i] != 0)
return false ;
return true ;
}
friend std::ostream& operator<<(std::ostream& out,const t_RsGenericIdType<ID_SIZE_IN_BYTES,UNIQUE_IDENTIFIER>& id)
{
return out << id.toStdString() ;
}
private:
unsigned char bytes[ID_SIZE_IN_BYTES] ;
};
template<uint32_t ID_SIZE_IN_BYTES,uint32_t UNIQUE_IDENTIFIER> std::string t_RsGenericIdType<ID_SIZE_IN_BYTES,UNIQUE_IDENTIFIER>::toStdString(bool upper_case) const
{
static const char outh[16] = { '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' } ;
static const char outl[16] = { '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f' } ;
std::string res(ID_SIZE_IN_BYTES*2,' ') ;
for(uint32_t j = 0; j < ID_SIZE_IN_BYTES; j++)
if(upper_case)
{
res[2*j ] = outh[ (bytes[j]>>4) ] ;
res[2*j+1] = outh[ bytes[j] & 0xf ] ;
}
else
{
res[2*j ] = outl[ (bytes[j]>>4) ] ;
res[2*j+1] = outl[ bytes[j] & 0xf ] ;
}
return res ;
}
template<uint32_t ID_SIZE_IN_BYTES,uint32_t UNIQUE_IDENTIFIER> t_RsGenericIdType<ID_SIZE_IN_BYTES,UNIQUE_IDENTIFIER>::t_RsGenericIdType(const std::string& s)
{
try
{
int n=0;
if(s.length() != ID_SIZE_IN_BYTES*2)
throw std::runtime_error("t_RsGenericIdType<>::t_RsGenericIdType(std::string&): supplied string in constructor has wrong size.") ;
for(uint32_t i = 0; i < ID_SIZE_IN_BYTES; ++i)
{
bytes[i] = 0 ;
for(int k=0;k<2;++k)
{
char b = s[n++] ;
if(b >= 'A' && b <= 'F')
bytes[i] += (b-'A'+10) << 4*(1-k) ;
else if(b >= 'a' && b <= 'f')
bytes[i] += (b-'a'+10) << 4*(1-k) ;
else if(b >= '0' && b <= '9')
bytes[i] += (b-'0') << 4*(1-k) ;
else
throw std::runtime_error("t_RsGenericIdType<>::t_RsGenericIdType(std::string&): supplied string is not purely hexadecimal") ;
}
}
}
catch(std::exception& e)
{
std::cerr << e.what() << std::endl;
clear() ;
}
}
template<uint32_t ID_SIZE_IN_BYTES,uint32_t UNIQUE_IDENTIFIER> t_RsGenericIdType<ID_SIZE_IN_BYTES,UNIQUE_IDENTIFIER>::t_RsGenericIdType(const unsigned char *mem)
{
memcpy(bytes,mem,ID_SIZE_IN_BYTES) ;
}
static const int SSL_ID_SIZE = 16 ;
static const int PGP_KEY_ID_SIZE = 8 ;
static const int PGP_KEY_FINGERPRINT_SIZE = 20 ;
static const int SHA1_SIZE = 20 ;
// These constants are random, but should be different, in order to make the various IDs incompatible with each other.
//
static const uint32_t RS_GENERIC_ID_SSL_ID_TYPE = 0x038439ff ;
static const uint32_t RS_GENERIC_ID_PGP_ID_TYPE = 0x80339f4f ;
static const uint32_t RS_GENERIC_ID_SHA1_ID_TYPE = 0x9540284e ;
static const uint32_t RS_GENERIC_ID_PGP_FINGERPRINT_TYPE = 0x102943e3 ;
typedef t_RsGenericIdType< SSL_ID_SIZE , RS_GENERIC_ID_SSL_ID_TYPE> SSLIdType ;
typedef t_RsGenericIdType< PGP_KEY_ID_SIZE , RS_GENERIC_ID_PGP_ID_TYPE> PGPIdType;
typedef t_RsGenericIdType< SHA1_SIZE , RS_GENERIC_ID_SHA1_ID_TYPE> Sha1CheckSum ;
typedef t_RsGenericIdType< PGP_KEY_FINGERPRINT_SIZE, RS_GENERIC_ID_PGP_FINGERPRINT_TYPE> PGPFingerprintType ;

View file

@ -32,6 +32,7 @@
#include <retroshare/rstypes.h> #include <retroshare/rstypes.h>
#include <retroshare/rsfiles.h> #include <retroshare/rsfiles.h>
#include <retroshare/rsids.h>
/* The Main Interface Class - for information about your Peers /* The Main Interface Class - for information about your Peers
* A peer is another RS instance, means associated with an SSL certificate * A peer is another RS instance, means associated with an SSL certificate
@ -186,18 +187,19 @@ class RsPeerDetails
/* Auth details */ /* Auth details */
bool isOnlyGPGdetail; bool isOnlyGPGdetail;
std::string id; SSLIdType id;
std::string gpg_id; PGPIdType gpg_id;
std::string name; std::string name;
std::string email; std::string email;
std::string location; std::string location;
std::string org; std::string org;
std::string issuer; PGPIdType issuer;
std::string fpr; /* pgp fingerprint */ PGPFingerprintType fpr; /* pgp fingerprint */
std::string authcode; //std::string authcode; // (cyril) what is this used for ?????
std::list<std::string> gpgSigners; std::list<PGPIdType> gpgSigners;
uint32_t trustLvl; uint32_t trustLvl;
uint32_t validLvl; uint32_t validLvl;
@ -272,7 +274,7 @@ public:
std::string name; std::string name;
uint32_t flag; uint32_t flag;
std::list<std::string> peerIds; std::list<SSLIdType> peerIds;
}; };
std::ostream &operator<<(std::ostream &out, const RsPeerDetails &detail); std::ostream &operator<<(std::ostream &out, const RsPeerDetails &detail);
@ -289,54 +291,55 @@ class RsPeers
virtual bool OthersChanged() = 0; virtual bool OthersChanged() = 0;
/* Peer Details (Net & Auth) */ /* Peer Details (Net & Auth) */
virtual std::string getOwnId() = 0; virtual SSLIdType getOwnId() = 0;
virtual bool haveSecretKey(const std::string& gpg_id) = 0 ; virtual bool haveSecretKey(const PGPIdType& gpg_id) = 0 ;
virtual bool getOnlineList(std::list<std::string> &ssl_ids) = 0; virtual bool getOnlineList(std::list<SSLIdType> &ssl_ids) = 0;
virtual bool getFriendList(std::list<std::string> &ssl_ids) = 0; virtual bool getFriendList(std::list<SSLIdType> &ssl_ids) = 0;
//virtual bool getOthersList(std::list<std::string> &ssl_ids) = 0;
virtual bool getPeerCount (unsigned int *pnFriendCount, unsigned int *pnnOnlineCount, bool ssl) = 0; virtual bool getPeerCount (unsigned int *pnFriendCount, unsigned int *pnnOnlineCount, bool ssl) = 0;
virtual bool isOnline(const std::string &ssl_id) = 0; virtual bool isOnline(const SSLIdType &ssl_id) = 0;
virtual bool isFriend(const std::string &ssl_id) = 0; virtual bool isFriend(const SSLIdType &ssl_id) = 0;
virtual bool isGPGAccepted(const std::string &gpg_id_is_friend) = 0; // virtual bool isGPGAccepted(const PGPIdType &gpg_id_is_friend) = 0; //
virtual std::string getPeerName(const std::string &ssl_or_gpg_id) = 0; virtual std::string getPeerName(const SSLIdType &ssl_id) = 0;
virtual std::string getGPGName(const std::string &gpg_id) = 0; virtual std::string getGPGName(const PGPIdType& gpg_id) = 0;
virtual bool getPeerDetails(const std::string &ssl_or_gpg_id, RsPeerDetails &d) = 0; //get Peer detail accept SSL and PGP certs virtual bool getPeerDetails(const SSLIdType& ssl_id, RsPeerDetails &d) = 0;
virtual bool getGPGDetails(const PGPIdType& gpg_id, RsPeerDetails &d) = 0;
/* Using PGP Ids */ /* Using PGP Ids */
virtual std::string getGPGOwnId() = 0; virtual PGPIdType getGPGOwnId() = 0;
virtual std::string getGPGId(const std::string &sslid_or_gpgid) = 0; //return the gpg id of the given gpg or ssl id virtual PGPIdType getGPGId(const SSLIdType& sslid) = 0; //return the gpg id of the given ssl id
virtual bool isKeySupported(const std::string& gpg_ids) = 0; virtual bool isKeySupported(const PGPIdType& gpg_ids) = 0;
virtual bool getGPGAcceptedList(std::list<std::string> &gpg_ids) = 0; virtual bool getGPGAcceptedList(std::list<PGPIdType> &gpg_ids) = 0;
virtual bool getGPGSignedList(std::list<std::string> &gpg_ids) = 0;//friends that we accpet to connect with but we don't want to sign their gpg key virtual bool getGPGSignedList(std::list<PGPIdType> &gpg_ids) = 0;//friends that we accpet to connect with but we don't want to sign their gpg key
virtual bool getGPGValidList(std::list<std::string> &gpg_ids) = 0; virtual bool getGPGValidList(std::list<PGPIdType> &gpg_ids) = 0;
virtual bool getGPGAllList(std::list<std::string> &gpg_ids) = 0; virtual bool getGPGAllList(std::list<PGPIdType> &gpg_ids) = 0;
virtual bool getGPGDetails(const std::string &gpg_id, RsPeerDetails &d) = 0; virtual bool getAssociatedSSLIds(const PGPIdType& gpg_id, std::list<SSLIdType>& ids) = 0;
virtual bool getAssociatedSSLIds(const std::string &gpg_id, std::list<std::string> &ids) = 0;
virtual bool gpgSignData(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen) = 0; virtual bool gpgSignData(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen) = 0;
/* Add/Remove Friends */ /* Add/Remove Friends */
virtual bool addFriend(const std::string &ssl_id, const std::string &gpg_id,ServicePermissionFlags flags = RS_SERVICE_PERM_ALL) = 0; virtual bool addFriend(const SSLIdType &ssl_id, const PGPIdType &gpg_id,ServicePermissionFlags flags = RS_SERVICE_PERM_ALL) = 0;
virtual bool removeFriend(const std::string &ssl_or_gpg_id) = 0; virtual bool removeFriend(const PGPIdType& pgp_id) = 0;
virtual bool removeFriendLocation(const std::string &sslId) = 0; virtual bool removeFriend(const SSLIdType& ssl_id) = 0;
virtual bool removeFriendLocation(const SSLIdType& sslId) = 0;
/* keyring management */ /* keyring management */
virtual bool removeKeysFromPGPKeyring(const std::list<std::string>& pgp_ids,std::string& backup_file,uint32_t& error_code)=0 ; virtual bool removeKeysFromPGPKeyring(const std::list<PGPIdType>& pgp_ids,std::string& backup_file,uint32_t& error_code)=0 ;
/* Network Stuff */ /* Network Stuff */
virtual bool connectAttempt(const std::string &ssl_id) = 0; virtual bool connectAttempt(const SSLIdType& ssl_id) = 0;
virtual bool setLocation(const std::string &ssl_id, const std::string &location) = 0;//location is shown in the gui to differentiate ssl certs virtual bool setLocation(const SSLIdType &ssl_id, const std::string &location) = 0;//location is shown in the gui to differentiate ssl certs
virtual bool setHiddenNode(const std::string &id, const std::string &hidden_node_address) = 0; virtual bool setHiddenNode(const SSLIdType &id, const std::string &hidden_node_address) = 0;
virtual bool setHiddenNode(const std::string &id, const std::string &address, uint16_t port) = 0; virtual bool setHiddenNode(const SSLIdType &id, const std::string &address, uint16_t port) = 0;
virtual bool setLocalAddress(const std::string &ssl_id, const std::string &addr, uint16_t port) = 0; virtual bool setLocalAddress(const SSLIdType &ssl_id, const std::string &addr, uint16_t port) = 0;
virtual bool setExtAddress( const std::string &ssl_id, const std::string &addr, uint16_t port) = 0; virtual bool setExtAddress( const SSLIdType &ssl_id, const std::string &addr, uint16_t port) = 0;
virtual bool setDynDNS(const std::string &id, const std::string &addr) = 0; virtual bool setDynDNS(const SSLIdType &id, const std::string &addr) = 0;
virtual bool setNetworkMode(const std::string &ssl_id, uint32_t netMode) = 0; virtual bool setNetworkMode(const SSLIdType &ssl_id, uint32_t netMode) = 0;
virtual bool setVisState(const std::string &ssl_id, uint16_t vs_disc, uint16_t vs_dht) = 0; virtual bool setVisState(const SSLIdType &ssl_id, uint16_t vs_disc, uint16_t vs_dht) = 0;
virtual bool getProxyServer(std::string &addr, uint16_t &port) = 0; virtual bool getProxyServer(std::string &addr, uint16_t &port) = 0;
virtual bool setProxyServer(const std::string &addr, const uint16_t port) = 0; virtual bool setProxyServer(const std::string &addr, const uint16_t port) = 0;
@ -346,24 +349,24 @@ class RsPeers
virtual bool getAllowServerIPDetermination() = 0 ; virtual bool getAllowServerIPDetermination() = 0 ;
/* Auth Stuff */ /* Auth Stuff */
virtual std::string GetRetroshareInvite(const std::string& ssl_id,bool include_signatures) = 0; virtual std::string GetRetroshareInvite(const SSLIdType& ssl_id,bool include_signatures) = 0;
virtual bool GetPGPBase64StringAndCheckSum(const std::string& gpg_id,std::string& gpg_base64_string,std::string& gpg_base64_checksum) = 0 ; virtual bool GetPGPBase64StringAndCheckSum(const PGPIdType& gpg_id,std::string& gpg_base64_string,std::string& gpg_base64_checksum) = 0 ;
virtual std::string GetRetroshareInvite(bool include_signatures) = 0; virtual std::string GetRetroshareInvite(bool include_signatures) = 0;
virtual bool hasExportMinimal() = 0 ; virtual bool hasExportMinimal() = 0 ;
// Add keys to the keyring // Add keys to the keyring
virtual bool loadCertificateFromString(const std::string& cert, std::string& ssl_id,std::string& pgp_id, std::string& error_string) = 0; virtual bool loadCertificateFromString(const std::string& cert, SSLIdType& ssl_id,PGPIdType& pgp_id, std::string& error_string) = 0;
// Gets the GPG details, but does not add the key to the keyring. // Gets the GPG details, but does not add the key to the keyring.
virtual bool loadDetailsFromStringCert(const std::string& certGPG, RsPeerDetails &pd,uint32_t& error_code) = 0; virtual bool loadDetailsFromStringCert(const std::string& certGPG, RsPeerDetails &pd,uint32_t& error_code) = 0;
// Certificate utils // Certificate utils
virtual bool cleanCertificate(const std::string &certstr, std::string &cleanCert,int& error_code) = 0; virtual bool cleanCertificate(const std::string &certstr, std::string &cleanCert,int& error_code) = 0;
virtual bool saveCertificateToFile(const std::string& id, const std::string &fname) = 0; virtual bool saveCertificateToFile(const SSLIdType& id, const std::string &fname) = 0;
virtual std::string saveCertificateToString(const std::string &id) = 0; virtual std::string saveCertificateToString(const SSLIdType &id) = 0;
virtual bool signGPGCertificate(const std::string &gpg_id) = 0; virtual bool signGPGCertificate(const PGPIdType &gpg_id) = 0;
virtual bool trustGPGCertificate(const std::string &gpg_id, uint32_t trustlvl) = 0; virtual bool trustGPGCertificate(const PGPIdType &gpg_id, uint32_t trustlvl) = 0;
/* Group Stuff */ /* Group Stuff */
virtual bool addGroup(RsGroupInfo &groupInfo) = 0; virtual bool addGroup(RsGroupInfo &groupInfo) = 0;
@ -372,8 +375,8 @@ class RsPeers
virtual bool getGroupInfo(const std::string &groupId, RsGroupInfo &groupInfo) = 0; virtual bool getGroupInfo(const std::string &groupId, RsGroupInfo &groupInfo) = 0;
virtual bool getGroupInfoList(std::list<RsGroupInfo> &groupInfoList) = 0; virtual bool getGroupInfoList(std::list<RsGroupInfo> &groupInfoList) = 0;
// groupId == "" && assign == false -> remove from all groups // groupId == "" && assign == false -> remove from all groups
virtual bool assignPeerToGroup(const std::string &groupId, const std::string &peerId, bool assign) = 0; virtual bool assignPeerToGroup(const std::string &groupId, const SSLIdType& peerId, bool assign) = 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<SSLIdType> &peerIds, bool assign) = 0;
/* Group sharing permission */ /* Group sharing permission */
@ -386,13 +389,13 @@ class RsPeers
// ... computes the sharing file permission hint flags set for this peer, that is a combination of // ... computes the sharing file permission hint flags set for this peer, that is a combination of
// RS_FILE_HINTS_NETWORK_WIDE and RS_FILE_HINTS_BROWSABLE. // RS_FILE_HINTS_NETWORK_WIDE and RS_FILE_HINTS_BROWSABLE.
// //
virtual FileSearchFlags computePeerPermissionFlags(const std::string& peer_id,FileStorageFlags file_sharing_flags,const std::list<std::string>& file_parent_groups) = 0; virtual FileSearchFlags computePeerPermissionFlags(const SSLIdType& peer_id,FileStorageFlags file_sharing_flags,const std::list<std::string>& file_parent_groups) = 0;
/* Service permission flags */ /* Service permission flags */
virtual ServicePermissionFlags servicePermissionFlags(const std::string& gpg_id) = 0; virtual ServicePermissionFlags servicePermissionFlags(const PGPIdType& gpg_id) = 0;
virtual ServicePermissionFlags servicePermissionFlags_sslid(const std::string& ssl_id) = 0; virtual ServicePermissionFlags servicePermissionFlags(const SSLIdType& ssl_id) = 0;
virtual void setServicePermissionFlags(const std::string& gpg_id,const ServicePermissionFlags& flags) = 0; virtual void setServicePermissionFlags(const PGPIdType& gpg_id,const ServicePermissionFlags& flags) = 0;
}; };
#endif #endif

View file

@ -33,6 +33,8 @@
#include <list> #include <list>
#include <vector> #include <vector>
#include "retroshare/rsids.h"
class LinearizedExpression ; class LinearizedExpression ;
class RsTurtleClientService ; class RsTurtleClientService ;
@ -54,7 +56,7 @@ struct TurtleFileInfo
struct TurtleRequestDisplayInfo struct TurtleRequestDisplayInfo
{ {
uint32_t request_id ; // Id of the request uint32_t request_id ; // Id of the request
std::string source_peer_id ; // Peer that relayed the request SSLIdType source_peer_id ; // Peer that relayed the request
uint32_t age ; // Age in seconds uint32_t age ; // Age in seconds
uint32_t depth ; // Depth of the request. Might be altered. uint32_t depth ; // Depth of the request. Might be altered.
}; };
@ -134,7 +136,7 @@ class RsTurtle
virtual void getTrafficStatistics(TurtleTrafficStatisticsInfo& info) const = 0; virtual void getTrafficStatistics(TurtleTrafficStatisticsInfo& info) const = 0;
// Convenience function. // Convenience function.
virtual bool isTurtlePeer(const std::string& peer_id) const = 0 ; virtual bool isTurtlePeer(const SSLIdType& peer_id) const = 0 ;
// Hardcore handles // Hardcore handles
virtual void setMaxTRForwardRate(int max_tr_up_rate) = 0 ; virtual void setMaxTRForwardRate(int max_tr_up_rate) = 0 ;

View file

@ -33,8 +33,8 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <stdint.h> #include <stdint.h>
#include <util/rsid.h>
#include <retroshare/rsids.h>
#include <retroshare/rsflags.h> #include <retroshare/rsflags.h>
#define USE_NEW_CHUNK_CHECKING_CODE #define USE_NEW_CHUNK_CHECKING_CODE
@ -43,6 +43,7 @@ typedef std::string RsCertId;
typedef std::string RsChanId; typedef std::string RsChanId;
typedef std::string RsMsgId; typedef std::string RsMsgId;
typedef std::string RsAuthId; typedef std::string RsAuthId;
typedef SSLIdType RsPeerId ;
const uint32_t FT_STATE_FAILED = 0x0000 ; const uint32_t FT_STATE_FAILED = 0x0000 ;
const uint32_t FT_STATE_OKAY = 0x0001 ; const uint32_t FT_STATE_OKAY = 0x0001 ;
@ -84,7 +85,7 @@ class TransferInfo
{ {
public: public:
/**** Need Some of these Fields ****/ /**** Need Some of these Fields ****/
std::string peerId; SSLIdType peerId;
std::string name; /* if has alternative name? */ std::string name; /* if has alternative name? */
double tfRate; /* kbytes */ double tfRate; /* kbytes */
int status; /* FT_STATE_... */ int status; /* FT_STATE_... */
@ -235,7 +236,7 @@ class DirDetails
void *ref; void *ref;
uint8_t type; uint8_t type;
std::string id; SSLIdType id;
std::string name; std::string name;
std::string hash; std::string hash;
std::string path; std::string path;
@ -251,7 +252,7 @@ class DirDetails
class FileDetail class FileDetail
{ {
public: public:
std::string id; SSLIdType id;
std::string name; std::string name;
std::string hash; std::string hash;
std::string path; std::string path;
@ -272,7 +273,7 @@ class FileChunksInfo
{ {
uint32_t start ; uint32_t start ;
uint32_t size ; uint32_t size ;
std::string peer_id ; RsPeerId peer_id ;
}; };
uint64_t file_size ; // real size of the file uint64_t file_size ; // real size of the file
@ -283,7 +284,7 @@ class FileChunksInfo
std::vector<ChunkState> chunks ; std::vector<ChunkState> chunks ;
// For each source peer, gives the compressed bit map of have/don't have sate // For each source peer, gives the compressed bit map of have/don't have sate
std::map<std::string, CompressedChunkMap> compressed_peer_availability_maps ; std::map<RsPeerId, CompressedChunkMap> compressed_peer_availability_maps ;
// For each chunk (by chunk number), gives the completion of the chunk. // For each chunk (by chunk number), gives the completion of the chunk.
// //

View file

@ -29,7 +29,7 @@
#include <string> #include <string>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h> #include <stdint.h>
#include <util/rsid.h> #include <retroshare/rsids.h>
/******************************************************************* /*******************************************************************
* This is at the lowlevel packing routines. They are usually * This is at the lowlevel packing routines. They are usually

View file

@ -112,7 +112,7 @@ void RsFileTransfer::clear()
file.TlvClear(); file.TlvClear();
allPeerIds.TlvClear(); allPeerIds.TlvClear();
cPeerId = ""; cPeerId.clear() ;
state = 0; state = 0;
in = false; in = false;
transferred = 0; transferred = 0;
@ -197,7 +197,7 @@ uint32_t RsFileConfigSerialiser::sizeTransfer(RsFileTransfer *item)
uint32_t s = 8; /* header */ uint32_t s = 8; /* header */
s += item->file.TlvSize(); s += item->file.TlvSize();
s += item->allPeerIds.TlvSize(); s += item->allPeerIds.TlvSize();
s += GetTlvStringSize(item->cPeerId); s += SSLIdType::SIZE_IN_BYTES;
s += 2; /* state */ s += 2; /* state */
s += 2; /* in/out */ s += 2; /* in/out */
s += 8; /* transferred */ s += 8; /* transferred */
@ -239,7 +239,7 @@ bool RsFileConfigSerialiser::serialiseTransfer(RsFileTransfer *item, void *d
ok &= item->file.SetTlv(data, tlvsize, &offset); ok &= item->file.SetTlv(data, tlvsize, &offset);
ok &= item->allPeerIds.SetTlv(data, tlvsize, &offset); ok &= item->allPeerIds.SetTlv(data, tlvsize, &offset);
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_PEERID, item->cPeerId); ok &= setRawSSLId(data, tlvsize, &offset, item->cPeerId);
ok &= setRawUInt16(data, tlvsize, &offset, item->state); ok &= setRawUInt16(data, tlvsize, &offset, item->state);
ok &= setRawUInt16(data, tlvsize, &offset, item->in); ok &= setRawUInt16(data, tlvsize, &offset, item->in);
@ -305,8 +305,7 @@ RsFileTransfer *RsFileConfigSerialiser::deserialiseTransfer(void *data, uint32_t
ok &= item->file.GetTlv(data, rssize, &offset); ok &= item->file.GetTlv(data, rssize, &offset);
ok &= item->allPeerIds.GetTlv(data, rssize, &offset); ok &= item->allPeerIds.GetTlv(data, rssize, &offset);
/* string */ ok &= getRawSSLId(data, rssize, &offset, item->cPeerId);
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_PEERID, item->cPeerId);
/* data */ /* data */
ok &= getRawUInt16(data, rssize, &offset, &(item->state)); ok &= getRawUInt16(data, rssize, &offset, &(item->state));

View file

@ -254,7 +254,7 @@ class RsFileTransfer: public RsItem
RsTlvFileItem file; RsTlvFileItem file;
RsTlvPeerIdSet allPeerIds; RsTlvPeerIdSet allPeerIds;
std::string cPeerId; SSLIdType cPeerId;
uint16_t state; uint16_t state;
uint16_t in; uint16_t in;

View file

@ -34,6 +34,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h> #include <stdint.h>
#include "retroshare/rsids.h"
/******************************************************************* /*******************************************************************
* This is the Top-Level serialiser/deserialise, * This is the Top-Level serialiser/deserialise,
* *
@ -84,8 +86,8 @@ class RsItem: public RsMemoryManagement::SmallObject
void print_string(std::string &out, uint16_t indent = 0); void print_string(std::string &out, uint16_t indent = 0);
/* source / destination id */ /* source / destination id */
const std::string& PeerId() const { return peerId; } const SSLIdType& PeerId() const { return peerId; }
void PeerId(const std::string& id) { peerId = id; } void PeerId(const SSLIdType& id) { peerId = id; }
/* complete id */ /* complete id */
uint32_t PacketId() const; uint32_t PacketId() const;
@ -104,7 +106,7 @@ class RsItem: public RsMemoryManagement::SmallObject
inline void setPriorityLevel(uint8_t l) { _priority_level = l ;} inline void setPriorityLevel(uint8_t l) { _priority_level = l ;}
private: private:
uint32_t type; uint32_t type;
std::string peerId; SSLIdType peerId;
uint8_t _priority_level ; uint8_t _priority_level ;
}; };

View file

@ -261,14 +261,16 @@ int p3turtle::tick()
// //
void p3turtle::locked_addDistantPeer(const TurtleFileHash&,TurtleTunnelId tid) void p3turtle::locked_addDistantPeer(const TurtleFileHash&,TurtleTunnelId tid)
{ {
char buff[400] ; unsigned char tmp[SSLIdType::SIZE_IN_BYTES] ;
sprintf(buff,"Anonymous F2F tunnel %08x",tid) ;
_virtual_peers[TurtleVirtualPeerId(buff)] = tid ; ((uint32_t*)tmp)[0] = tid ;
SSLIdType virtual_peer_id(tmp) ;
_virtual_peers[virtual_peer_id] = tid ;
#ifdef P3TURTLE_DEBUG #ifdef P3TURTLE_DEBUG
assert(_local_tunnels.find(tid)!=_local_tunnels.end()) ; assert(_local_tunnels.find(tid)!=_local_tunnels.end()) ;
#endif #endif
_local_tunnels[tid].vpid = TurtleVirtualPeerId(buff) ; _local_tunnels[tid].vpid = virtual_peer_id ;
} }
void p3turtle::getSourceVirtualPeersList(const TurtleFileHash& hash,std::list<pqipeer>& list) void p3turtle::getSourceVirtualPeersList(const TurtleFileHash& hash,std::list<pqipeer>& list)
@ -719,7 +721,7 @@ uint32_t p3turtle::generatePersonalFilePrint(const TurtleFileHash& hash,uint32_t
// The only important thing is that the saem couple (hash,SSL id) produces the same tunnel // The only important thing is that the saem couple (hash,SSL id) produces the same tunnel
// id. The result uses a boolean to allow generating non symmetric tunnel ids. // id. The result uses a boolean to allow generating non symmetric tunnel ids.
std::string buff(hash + mLinkMgr->getOwnId()) ; std::string buff(hash + mLinkMgr->getOwnId().toStdString()) ;
uint32_t res = seed ; uint32_t res = seed ;
uint32_t decal = 0 ; uint32_t decal = 0 ;
@ -750,7 +752,7 @@ int p3turtle::handleIncoming()
{ {
nhandled++; nhandled++;
if( (!(_turtle_routing_enabled && _turtle_routing_session_enabled)) || !(RS_SERVICE_PERM_TURTLE & rsPeers->servicePermissionFlags_sslid(item->PeerId()))) if( (!(_turtle_routing_enabled && _turtle_routing_session_enabled)) || !(RS_SERVICE_PERM_TURTLE & rsPeers->servicePermissionFlags(item->PeerId())))
delete item ; delete item ;
else else
{ {
@ -891,15 +893,15 @@ void p3turtle::handleSearchRequest(RsTurtleSearchRequestItem *item)
if(item->depth < TURTLE_MAX_SEARCH_DEPTH || random_bypass) if(item->depth < TURTLE_MAX_SEARCH_DEPTH || random_bypass)
{ {
std::list<std::string> onlineIds ; std::list<SSLIdType> onlineIds ;
mLinkMgr->getOnlineList(onlineIds); mLinkMgr->getOnlineList(onlineIds);
#ifdef P3TURTLE_DEBUG #ifdef P3TURTLE_DEBUG
std::cerr << " Looking for online peers" << std::endl ; std::cerr << " Looking for online peers" << std::endl ;
#endif #endif
for(std::list<std::string>::const_iterator it(onlineIds.begin());it!=onlineIds.end();++it) for(std::list<SSLIdType>::const_iterator it(onlineIds.begin());it!=onlineIds.end();++it)
{ {
if(!(RS_SERVICE_PERM_TURTLE & rsPeers->servicePermissionFlags_sslid(*it))) if(!(RS_SERVICE_PERM_TURTLE & rsPeers->servicePermissionFlags(*it)))
continue ; continue ;
uint32_t linkType = mLinkMgr->getLinkType(*it); uint32_t linkType = mLinkMgr->getLinkType(*it);
@ -1085,7 +1087,7 @@ void p3turtle::handleRecvGenericTunnelItem(RsTurtleGenericTunnelItem *item)
item->print(std::cerr,1) ; item->print(std::cerr,1) ;
#endif #endif
std::string hash ; std::string hash ;
std::string vpid ; SSLIdType vpid ;
RsTurtleClientService *service ; RsTurtleClientService *service ;
if(!getTunnelServiceInfo(item->tunnelId(),vpid,hash,service)) if(!getTunnelServiceInfo(item->tunnelId(),vpid,hash,service))
@ -1094,23 +1096,7 @@ void p3turtle::handleRecvGenericTunnelItem(RsTurtleGenericTunnelItem *item)
service->receiveTurtleData(item,hash,vpid,item->travelingDirection()) ; service->receiveTurtleData(item,hash,vpid,item->travelingDirection()) ;
} }
//void p3turtle::handleRecvGenericDataItem(RsTurtleGenericDataItem *item) bool p3turtle::getTunnelServiceInfo(TurtleTunnelId tunnel_id,SSLIdType& vpid,std::string& hash,RsTurtleClientService *& service)
//{
//#ifdef P3TURTLE_DEBUG
// std::cerr << "p3Turtle: received Generic Data item:" << std::endl ;
// item->print(std::cerr,1) ;
//#endif
// std::string virtual_peer_id ;
// std::string hash ;
// RsTurtleClientService *service ;
//
// if(!getTunnelServiceInfo(item->tunnelId(),virtual_peer_id,hash,service))
// return ;
//
// service->receiveTurtleData(item->data_bytes,item->data_size,hash,virtual_peer_id,item->travelingDirection()) ;
//}
bool p3turtle::getTunnelServiceInfo(TurtleTunnelId tunnel_id,std::string& vpid,std::string& hash,RsTurtleClientService *& service)
{ {
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/ RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
@ -1140,7 +1126,7 @@ bool p3turtle::getTunnelServiceInfo(TurtleTunnelId tunnel_id,std::string& vpid,s
// Now sort out the case of client vs. server side items. // Now sort out the case of client vs. server side items.
// //
std::string ownid = mLinkMgr->getOwnId() ; SSLIdType ownid = mLinkMgr->getOwnId() ;
if(tunnel.local_src == ownid) if(tunnel.local_src == ownid)
{ {
@ -1176,7 +1162,7 @@ bool p3turtle::getTunnelServiceInfo(TurtleTunnelId tunnel_id,std::string& vpid,s
} }
// Send a data request into the correct tunnel for the given file hash // Send a data request into the correct tunnel for the given file hash
// //
void p3turtle::sendTurtleData(const std::string& virtual_peer_id,RsTurtleGenericTunnelItem *item) void p3turtle::sendTurtleData(const SSLIdType& virtual_peer_id,RsTurtleGenericTunnelItem *item)
{ {
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/ RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
@ -1204,7 +1190,7 @@ void p3turtle::sendTurtleData(const std::string& virtual_peer_id,RsTurtleGeneric
item->tunnel_id = tunnel_id ; // we should randomly select a tunnel, or something more clever. item->tunnel_id = tunnel_id ; // we should randomly select a tunnel, or something more clever.
std::string ownid = mLinkMgr->getOwnId() ; SSLIdType ownid = mLinkMgr->getOwnId() ;
uint32_t ss = item->serial_size() ; uint32_t ss = item->serial_size() ;
if(item->shouldStampTunnel()) if(item->shouldStampTunnel())
@ -1237,14 +1223,14 @@ void p3turtle::sendTurtleData(const std::string& virtual_peer_id,RsTurtleGeneric
sendItem(item) ; sendItem(item) ;
} }
bool p3turtle::isTurtlePeer(const std::string& peer_id) const bool p3turtle::isTurtlePeer(const SSLIdType& peer_id) const
{ {
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/ RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
return _virtual_peers.find(peer_id) != _virtual_peers.end() ; return _virtual_peers.find(peer_id) != _virtual_peers.end() ;
} }
std::string p3turtle::getTurtlePeerId(TurtleTunnelId tid) const SSLIdType p3turtle::getTurtlePeerId(TurtleTunnelId tid) const
{ {
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/ RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
@ -1258,7 +1244,7 @@ std::string p3turtle::getTurtlePeerId(TurtleTunnelId tid) const
return it->second.vpid ; return it->second.vpid ;
} }
bool p3turtle::isOnline(const std::string& peer_id) const bool p3turtle::isOnline(const SSLIdType& peer_id) const
{ {
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/ RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
@ -1278,7 +1264,7 @@ TurtleRequestId p3turtle::diggTunnel(const TurtleFileHash& hash)
#ifdef P3TURTLE_DEBUG #ifdef P3TURTLE_DEBUG
std::cerr << "DiggTunnel: performing tunnel request. OwnId = " << mLinkMgr->getOwnId() << " for hash=" << hash << std::endl ; std::cerr << "DiggTunnel: performing tunnel request. OwnId = " << mLinkMgr->getOwnId() << " for hash=" << hash << std::endl ;
#endif #endif
while(mLinkMgr->getOwnId() == "") while(mLinkMgr->getOwnId().isNull())
{ {
std::cerr << "... waiting for connect manager to form own id." << std::endl ; std::cerr << "... waiting for connect manager to form own id." << std::endl ;
#ifdef WIN32 #ifdef WIN32
@ -1483,13 +1469,13 @@ void p3turtle::handleTunnelRequest(RsTurtleOpenTunnelItem *item)
if(item->depth < TURTLE_MAX_SEARCH_DEPTH || random_bypass) if(item->depth < TURTLE_MAX_SEARCH_DEPTH || random_bypass)
{ {
std::list<std::string> onlineIds ; std::list<SSLIdType> onlineIds ;
mLinkMgr->getOnlineList(onlineIds); mLinkMgr->getOnlineList(onlineIds);
for(std::list<std::string>::iterator it(onlineIds.begin());it!=onlineIds.end();) for(std::list<SSLIdType>::iterator it(onlineIds.begin());it!=onlineIds.end();)
if(!(RS_SERVICE_PERM_TURTLE & rsPeers->servicePermissionFlags_sslid(*it))) if(!(RS_SERVICE_PERM_TURTLE & rsPeers->servicePermissionFlags(*it)))
{ {
std::list<std::string>::iterator tmp = it++ ; std::list<SSLIdType>::iterator tmp = it++ ;
onlineIds.erase(tmp) ; onlineIds.erase(tmp) ;
} }
else else
@ -1513,7 +1499,7 @@ void p3turtle::handleTunnelRequest(RsTurtleOpenTunnelItem *item)
std::cerr << " Forwarding tunnel request: Looking for online peers" << std::endl ; std::cerr << " Forwarding tunnel request: Looking for online peers" << std::endl ;
#endif #endif
for(std::list<std::string>::const_iterator it(onlineIds.begin());it!=onlineIds.end();++it) for(std::list<SSLIdType>::const_iterator it(onlineIds.begin());it!=onlineIds.end();++it)
{ {
uint32_t linkType = mLinkMgr->getLinkType(*it); uint32_t linkType = mLinkMgr->getLinkType(*it);
@ -1558,7 +1544,7 @@ void p3turtle::handleTunnelResult(RsTurtleTunnelOkItem *item)
{ {
bool new_tunnel = false ; bool new_tunnel = false ;
TurtleFileHash new_hash ; TurtleFileHash new_hash ;
std::string new_vpid ; SSLIdType new_vpid ;
RsTurtleClientService *service = NULL ; RsTurtleClientService *service = NULL ;
{ {
@ -1773,7 +1759,7 @@ TurtleRequestId p3turtle::turtleSearch(const std::string& string_to_match)
#ifdef P3TURTLE_DEBUG #ifdef P3TURTLE_DEBUG
std::cerr << "performing search. OwnId = " << mLinkMgr->getOwnId() << std::endl ; std::cerr << "performing search. OwnId = " << mLinkMgr->getOwnId() << std::endl ;
#endif #endif
while(mLinkMgr->getOwnId() == "") while(mLinkMgr->getOwnId().isNull())
{ {
std::cerr << "... waitting for connect manager to form own id." << std::endl ; std::cerr << "... waitting for connect manager to form own id." << std::endl ;
#ifdef WIN32 #ifdef WIN32
@ -1809,7 +1795,7 @@ TurtleRequestId p3turtle::turtleSearch(const LinearizedExpression& expr)
#ifdef P3TURTLE_DEBUG #ifdef P3TURTLE_DEBUG
std::cerr << "performing search. OwnId = " << mLinkMgr->getOwnId() << std::endl ; std::cerr << "performing search. OwnId = " << mLinkMgr->getOwnId() << std::endl ;
#endif #endif
while(mLinkMgr->getOwnId() == "") while(mLinkMgr->getOwnId().isNull())
{ {
std::cerr << "... waitting for connect manager to form own id." << std::endl ; std::cerr << "... waitting for connect manager to form own id." << std::endl ;
#ifdef WIN32 #ifdef WIN32
@ -1889,7 +1875,7 @@ void p3turtle::returnSearchResult(RsTurtleSearchResultItem *item)
/// Warning: this function should never be called while the turtle mutex is locked. /// Warning: this function should never be called while the turtle mutex is locked.
/// Otherwize this is a possible source of cross-lock with the File mutex. /// Otherwize this is a possible source of cross-lock with the File mutex.
// //
bool p3turtle::performLocalHashSearch(const TurtleFileHash& hash,const std::string& peer_id,RsTurtleClientService *& service) bool p3turtle::performLocalHashSearch(const TurtleFileHash& hash,const SSLIdType& peer_id,RsTurtleClientService *& service)
{ {
if(_registered_services.empty()) if(_registered_services.empty())
std::cerr << "Turtle router has no services registered. Tunnel requests cannot be handled." << std::endl; std::cerr << "Turtle router has no services registered. Tunnel requests cannot be handled." << std::endl;
@ -1967,7 +1953,7 @@ void p3turtle::getTrafficStatistics(TurtleTrafficStatisticsInfo& info) const
float distance_to_maximum = std::min(100.0f,info.tr_up_Bps/(float)(TUNNEL_REQUEST_PACKET_SIZE*_max_tr_up_rate)) ; float distance_to_maximum = std::min(100.0f,info.tr_up_Bps/(float)(TUNNEL_REQUEST_PACKET_SIZE*_max_tr_up_rate)) ;
info.forward_probabilities.clear() ; info.forward_probabilities.clear() ;
std::list<std::string> onlineIds ; std::list<SSLIdType> onlineIds ;
mLinkMgr->getOnlineList(onlineIds); mLinkMgr->getOnlineList(onlineIds);
int nb_online_ids = onlineIds.size() ; int nb_online_ids = onlineIds.size() ;
@ -2026,12 +2012,12 @@ void p3turtle::getInfo( std::vector<std::vector<std::string> >& hashes_info,
if(mLinkMgr->getPeerName(it->second.local_src,name)) if(mLinkMgr->getPeerName(it->second.local_src,name))
tunnel.push_back(name) ; tunnel.push_back(name) ;
else else
tunnel.push_back(it->second.local_src) ; tunnel.push_back(it->second.local_src.toStdString()) ;
if(mLinkMgr->getPeerName(it->second.local_dst,name)) if(mLinkMgr->getPeerName(it->second.local_dst,name))
tunnel.push_back(name) ; tunnel.push_back(name) ;
else else
tunnel.push_back(it->second.local_dst); tunnel.push_back(it->second.local_dst.toStdString());
tunnel.push_back(it->second.hash) ; tunnel.push_back(it->second.hash) ;
tunnel.push_back(printNumber(now-it->second.time_stamp) + " secs ago") ; tunnel.push_back(printNumber(now-it->second.time_stamp) + " secs ago") ;

View file

@ -292,23 +292,23 @@ class p3turtle: public p3Service, public RsTurtle, public p3Config
/************* Communication with clients *******************/ /************* Communication with clients *******************/
/// Does the turtle router manages tunnels to this peer ? (this is not a /// Does the turtle router manages tunnels to this peer ? (this is not a
/// real id, but a fake one, that the turtle router is capable of connecting with a tunnel id). /// real id, but a fake one, that the turtle router is capable of connecting with a tunnel id).
virtual bool isTurtlePeer(const std::string& peer_id) const ; virtual bool isTurtlePeer(const SSLIdType& peer_id) const ;
/// sets/gets the max number of forwarded tunnel requests per second. /// sets/gets the max number of forwarded tunnel requests per second.
virtual void setMaxTRForwardRate(int max_tr_up_rate) ; virtual void setMaxTRForwardRate(int max_tr_up_rate) ;
virtual int getMaxTRForwardRate() const ; virtual int getMaxTRForwardRate() const ;
/// Examines the peer id, finds the turtle tunnel in it, and respond yes if the tunnel is ok and operational. /// Examines the peer id, finds the turtle tunnel in it, and respond yes if the tunnel is ok and operational.
bool isOnline(const std::string& peer_id) const ; bool isOnline(const SSLIdType& peer_id) const ;
/// Returns a unique peer id, corresponding to the given tunnel. /// Returns a unique peer id, corresponding to the given tunnel.
std::string getTurtlePeerId(TurtleTunnelId tid) const ; SSLIdType getTurtlePeerId(TurtleTunnelId tid) const ;
/// returns the list of virtual peers for all tunnels. /// returns the list of virtual peers for all tunnels.
void getSourceVirtualPeersList(const TurtleFileHash& hash,std::list<pqipeer>& list) ; void getSourceVirtualPeersList(const TurtleFileHash& hash,std::list<pqipeer>& list) ;
/// Send a data request into the correct tunnel for the given file hash /// Send a data request into the correct tunnel for the given file hash
void sendTurtleData(const std::string& virtual_peer_id, RsTurtleGenericTunnelItem *item) ; void sendTurtleData(const SSLIdType& virtual_peer_id, RsTurtleGenericTunnelItem *item) ;
private: private:
//--------------------------- Admin/Helper functions -------------------------// //--------------------------- Admin/Helper functions -------------------------//
@ -352,7 +352,7 @@ class p3turtle: public p3Service, public RsTurtle, public p3Config
/// specific routing functions for handling particular packets. /// specific routing functions for handling particular packets.
void handleRecvGenericTunnelItem(RsTurtleGenericTunnelItem *item); void handleRecvGenericTunnelItem(RsTurtleGenericTunnelItem *item);
bool getTunnelServiceInfo(TurtleTunnelId, std::string& virtual_peer_id, std::string& hash, RsTurtleClientService*&) ; bool getTunnelServiceInfo(TurtleTunnelId, SSLIdType& virtual_peer_id, std::string& hash, RsTurtleClientService*&) ;
// following functions should go to ftServer // following functions should go to ftServer
void handleSearchRequest(RsTurtleSearchRequestItem *item); void handleSearchRequest(RsTurtleSearchRequestItem *item);
@ -369,7 +369,7 @@ class p3turtle: public p3Service, public RsTurtle, public p3Config
void returnSearchResult(RsTurtleSearchResultItem *item) ; void returnSearchResult(RsTurtleSearchResultItem *item) ;
/// Returns true if the file with given hash is hosted locally, and accessible in anonymous mode the supplied peer. /// Returns true if the file with given hash is hosted locally, and accessible in anonymous mode the supplied peer.
virtual bool performLocalHashSearch(const TurtleFileHash& hash,const std::string& client_peer_id,RsTurtleClientService *& service); virtual bool performLocalHashSearch(const TurtleFileHash& hash,const SSLIdType& client_peer_id,RsTurtleClientService *& service);
//--------------------------- Local variables --------------------------------// //--------------------------- Local variables --------------------------------//

View file

@ -46,7 +46,7 @@ class RsTurtleClientService
// The output info_string is used by the turtle router to display info about tunnels it manages. It is // The output info_string is used by the turtle router to display info about tunnels it manages. It is
// not passed to the tunnel. // not passed to the tunnel.
virtual bool handleTunnelRequest(const std::string& /*hash*/,const std::string& /*peer_id*/) { return false ; } virtual bool handleTunnelRequest(const std::string& /*hash*/,const SSLIdType& /*peer_id*/) { return false ; }
// This method is called by the turtle router to send data that comes out of a turtle tunnel. // 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 // The turtle router stays responsible for the memory management of data. Most of the time the
@ -66,7 +66,7 @@ class RsTurtleClientService
// By default (if not overloaded), the method will just free the data, as any subclass should do as well. // By default (if not overloaded), the method will just free the data, as any subclass should do as well.
// Note: p3turtle stays owner of the item, so the client should not delete it! // Note: p3turtle stays owner of the item, so the client should not delete it!
// //
virtual void receiveTurtleData(RsTurtleGenericTunnelItem */*item*/,const std::string& /*hash*/,const std::string& /*virtual_peer_id*/,RsTurtleGenericTunnelItem::Direction /*direction*/) virtual void receiveTurtleData(RsTurtleGenericTunnelItem */*item*/,const std::string& /*hash*/,const SSLIdType& /*virtual_peer_id*/,RsTurtleGenericTunnelItem::Direction /*direction*/)
{ {
std::cerr << "!!!!!! Received Data from turtle router, but the client service is not handling it !!!!!!!!!!" << std::endl ; std::cerr << "!!!!!! Received Data from turtle router, but the client service is not handling it !!!!!!!!!!" << std::endl ;
} }

View file

@ -2,8 +2,8 @@
#include "retroshare/rsturtle.h" #include "retroshare/rsturtle.h"
typedef std::string TurtlePeerId ; typedef SSLIdType TurtlePeerId ;
typedef std::string TurtleVirtualPeerId ; typedef SSLIdType TurtleVirtualPeerId ;
typedef std::string TurtleFileHash ; typedef std::string TurtleFileHash ;
typedef std::string TurtleFileName ; typedef std::string TurtleFileName ;