diff --git a/libretroshare/src/dbase/cachestrapper.cc b/libretroshare/src/dbase/cachestrapper.cc index de6729003..9d5ae4a8c 100644 --- a/libretroshare/src/dbase/cachestrapper.cc +++ b/libretroshare/src/dbase/cachestrapper.cc @@ -92,7 +92,7 @@ bool CacheSource::loadLocalCache(const RsCacheData &data) } /* control Caches available */ -bool CacheSource::refreshCache(const RsCacheData &data,const std::set& destination_peers) +bool CacheSource::refreshCache(const RsCacheData &data,const std::set& destination_peers) { bool ret = false; { @@ -122,9 +122,9 @@ bool CacheSource::refreshCache(const RsCacheData &data,const std::set allowed_dest_peers ; + std::set allowed_dest_peers ; - for(std::set::const_iterator it(destination_peers.begin());it!=destination_peers.end();++it) + for(std::set::const_iterator it(destination_peers.begin());it!=destination_peers.end();++it) if(isPeerAcceptedAsCacheReceiver(*it)) allowed_dest_peers.insert(*it) ; @@ -161,14 +161,14 @@ bool CacheSource::refreshCache(const RsCacheData &data) } // Strip down destination peers to eliminate peers that are not allowed to receive cache items. - std::list ids; + std::list ids; rsPeers->getOnlineList(ids); if (mStrapper) /* allow testing without full feedback */ { - std::set allowed_dest_peers ; + std::set allowed_dest_peers ; - for(std::list::const_iterator it(ids.begin());it!=ids.end();++it) + for(std::list::const_iterator it(ids.begin());it!=ids.end();++it) if(isPeerAcceptedAsCacheReceiver(*it)) allowed_dest_peers.insert(*it) ; @@ -232,7 +232,7 @@ bool CacheSource::clearCache(CacheId id) return ret; } -bool CacheSource::cachesAvailable(RsPeerId pid, std::map &ids) +bool CacheSource::cachesAvailable(const SSLIdType& pid, std::map &ids) { if(!isPeerAcceptedAsCacheReceiver(pid)) return false ; @@ -336,7 +336,7 @@ void CacheStore::listCaches(std::ostream &out) lockData(); /* LOCK MUTEX */ /* can overwrite for more control! */ - std::map::iterator pit; + std::map::iterator pit; out << "CacheStore::listCaches() [" << getCacheType(); out << "] Total People: " << caches.size(); out << std::endl; @@ -377,7 +377,7 @@ bool CacheStore::locked_getStoredCache(RsCacheData &data) return false; } - std::map::iterator pit; + std::map::iterator pit; if (caches.end() == (pit = caches.find(data.pid))) { return false; @@ -414,7 +414,7 @@ bool CacheStore::getAllStoredCaches(std::list &data) { lockData(); /* LOCK MUTEX */ - std::map::iterator pit; + std::map::iterator pit; for(pit = caches.begin(); pit != caches.end(); pit++) { CacheSet::iterator cit; @@ -585,7 +585,7 @@ int CacheStore::loadCache(const RsCacheData &data) void CacheStore::locked_storeCacheEntry(const RsCacheData &data) { /* store what we loaded - overwriting if necessary */ - std::map::iterator pit; + std::map::iterator pit; if (caches.end() == (pit = caches.find(data.pid))) { /* add in a new CacheSet */ @@ -658,7 +658,7 @@ void CacheStrapper::statusChange(const std::list &plist) /**************** from pqimonclient ********************/ -void CacheStrapper::refreshCache(const RsCacheData &data,const std::set& destination_peers) +void CacheStrapper::refreshCache(const RsCacheData &data,const std::set& destination_peers) { /* we've received an update * send to all online peers + self intersected with online peers. @@ -666,13 +666,13 @@ void CacheStrapper::refreshCache(const RsCacheData &data,const std::setgetOwnId() ; - std::list ids; + const SSLIdType& ownid = mLinkMgr->getOwnId() ; + std::list ids; mLinkMgr->getOnlineList(ids); ids.push_back(ownid) ; RsStackMutex stack(csMtx); /******* LOCK STACK MUTEX *********/ - for(std::list::const_iterator it = ids.begin(); it != ids.end(); ++it) + for(std::list::const_iterator it = ids.begin(); it != ids.end(); ++it) if(destination_peers.find(*it) != destination_peers.end()) { #ifdef CS_DEBUG @@ -714,7 +714,7 @@ void CacheStrapper::refreshCacheStore(const RsCacheData & /* data */ ) } -bool CacheStrapper::getCacheUpdates(std::list > &updates) +bool CacheStrapper::getCacheUpdates(std::list > &updates) { RsStackMutex stack(csMtx); /******* LOCK STACK MUTEX *********/ updates = mCacheUpdates; @@ -741,28 +741,7 @@ void CacheStrapper::recvCacheResponse(RsCacheData &data, time_t /* ts */) } - - /* generate periodically or at a change */ -#if 0 -bool CacheStrapper::sendCacheQuery(std::list &id, time_t ts) -{ - /* iterate through peers, and see who we haven't got an answer from recently */ - std::map::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 &hashs) +void CacheStrapper::handleCacheQuery(const SSLIdType& id, std::map &hashs) { /* basic version just iterates through .... * more complex could decide who gets what! @@ -875,7 +854,7 @@ bool CacheStrapper::saveList(bool &cleanup, std::list& saveData) std::list::iterator cit; std::list ownCaches; std::list remoteCaches; - std::string ownId = mLinkMgr->getOwnId(); + const SSLIdType& ownId = mLinkMgr->getOwnId(); std::map::iterator it; for(it = caches.begin(); it != caches.end(); it++) @@ -899,7 +878,7 @@ bool CacheStrapper::saveList(bool &cleanup, std::list& saveData) // Fixup lazy behaviour in clients... // This ensures correct loading later. // (used to be: rscc->pid = cit->pid;) - rscc->pid = ownId; + rscc->pid = ownId.toStdString(); //rscc->pname = cit->pname; rscc->cachetypeid = cit->cid.type; @@ -926,7 +905,7 @@ bool CacheStrapper::saveList(bool &cleanup, std::list& saveData) RsCacheConfig *rscc = new RsCacheConfig(); - rscc->pid = cit->pid; + rscc->pid = cit->pid.toStdString(); //rscc->pname = cit->pname; rscc->cachetypeid = cit->cid.type; rscc->cachesubid = cit->cid.subid; @@ -955,7 +934,7 @@ bool CacheStrapper::loadList(std::list& load) #endif std::list ownCaches; std::list remoteCaches; - std::string ownId = mLinkMgr->getOwnId(); + const SSLIdType& ownId = mLinkMgr->getOwnId(); //peerConnectState ownState; //mPeerMgr->getOwnNetStatus(ownState); @@ -977,7 +956,7 @@ bool CacheStrapper::loadList(std::list& load) #endif RsCacheData cd; - cd.pid = rscc->pid; + cd.pid = SSLIdType(rscc->pid) ; #if 0 if(cd.pid == ownId) @@ -1113,7 +1092,8 @@ bool CacheStrapper::loadList(std::list& load) #ifdef CS_DEBUG std::cerr << "CacheStrapper::loadList() Cleaning cache dir: <" << *dit << ">" << std::endl; #endif - sit = saveFiles.find(RsDirUtil::convertPathToUnix(*dit)); + sit = saveFiles.find(RsDirUtil::convertPathToUnix(*dit)); + if (sit != saveFiles.end()) { #ifdef CS_DEBUG @@ -1219,7 +1199,7 @@ bool CacheTransfer::RequestCache(RsCacheData &data, CacheStore *cbStore) /* to be overloaded */ -bool CacheTransfer::RequestCacheFile(RsPeerId id, std::string path, std::string hash, uint64_t size) +bool CacheTransfer::RequestCacheFile(const SSLIdType& id, std::string path, std::string hash, uint64_t size) { (void) id; (void) path; @@ -1238,7 +1218,7 @@ bool CacheTransfer::RequestCacheFile(RsPeerId id, std::string path, std::string } /* 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) path; diff --git a/libretroshare/src/dbase/cachestrapper.h b/libretroshare/src/dbase/cachestrapper.h index 83ddac11b..59c705297 100644 --- a/libretroshare/src/dbase/cachestrapper.h +++ b/libretroshare/src/dbase/cachestrapper.h @@ -60,11 +60,6 @@ class CacheSource; /* Interface for local File Index/Monitor */ class CacheStore; /* Interface for the actual Cache */ class CacheStrapper; /* Controlling Class */ -/**** -typedef uint32_t RsPeerId; -*****/ -typedef std::string RsPeerId; - /******************************** CacheId ********************************/ /*! @@ -91,7 +86,7 @@ class RsCacheData { 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) CacheId cid; /// cache id std::string path; /// file system path where physical cache data is located @@ -132,8 +127,8 @@ class CacheTransfer /*! * to be overloaded */ - virtual bool RequestCacheFile(RsPeerId id, std::string path, std::string hash, uint64_t size); - virtual bool CancelCacheFile(RsPeerId id, std::string path, std::string hash, uint64_t size); + virtual bool RequestCacheFile(const SSLIdType& 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 FailedCache(std::string hash); /* internal completion -> does cb */ @@ -172,7 +167,7 @@ class CacheSource * called to determine available cache for peer - * default acceptable (returns all) */ - virtual bool cachesAvailable(RsPeerId pid, std::map &ids); + virtual bool cachesAvailable(const SSLIdType& pid, std::map &ids); /*! * function called at startup to load from @@ -182,12 +177,12 @@ class CacheSource virtual bool loadLocalCache(const RsCacheData &data); /* control Caches available */ - bool refreshCache(const RsCacheData &data,const std::set& destination_peers); + bool refreshCache(const RsCacheData &data,const std::set& destination_peers); bool refreshCache(const RsCacheData &data); bool clearCache(CacheId id); /* controls if peer is an accepted receiver for cache items. Default is yes. To be overloaded. */ - virtual bool isPeerAcceptedAsCacheReceiver(const std::string& /*peer_id*/) { return true ; } + virtual bool isPeerAcceptedAsCacheReceiver(const SSLIdType& /*peer_id*/) { return true ; } /* get private data */ std::string getCacheDir() { return cacheDir; } @@ -276,7 +271,7 @@ class CacheStore /* virtual functions overloaded by cache implementor */ /* controls if peer is an accepted provider for cache items. Default is yes. To be overloaded. */ - virtual bool isPeerAcceptedAsCacheProvider(const std::string& /*peer_id*/) { return true ; } + virtual bool isPeerAcceptedAsCacheProvider(const SSLIdType& /*peer_id*/) { return true ; } /*! * @param data cache data is stored here @@ -334,7 +329,7 @@ class CacheStore std::string cacheDir; mutable RsMutex cMutex; - std::map caches; + std::map caches; }; @@ -407,7 +402,7 @@ virtual void statusChange(const std::list &plist); * */ void refreshCache(const RsCacheData &data); -void refreshCache(const RsCacheData &data,const std::set& destination_peers); // specify a particular list of destination peers (self not added!) +void refreshCache(const RsCacheData &data,const std::set& destination_peers); // specify a particular list of destination peers (self not added!) /*! * forces config savelist @@ -419,7 +414,7 @@ void refreshCacheStore(const RsCacheData &data); /*! * list of Caches to send out */ -bool getCacheUpdates(std::list > &updates); +bool getCacheUpdates(std::list > &updates); /*! * 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) ***/ void recvCacheResponse(RsCacheData &data, time_t ts); -void handleCacheQuery(RsPeerId id, std::map &data); +void handleCacheQuery(const SSLIdType& id, std::map &data); /*! @@ -472,7 +467,7 @@ virtual bool loadList(std::list& load); RsMutex csMtx; /* protect below */ - std::list > mCacheUpdates; + std::list > mCacheUpdates; }; diff --git a/libretroshare/src/dbase/fimonitor.cc b/libretroshare/src/dbase/fimonitor.cc index f36656a78..1f35f3673 100644 --- a/libretroshare/src/dbase/fimonitor.cc +++ b/libretroshare/src/dbase/fimonitor.cc @@ -52,7 +52,7 @@ //#define FIM_DEBUG 1 // ***********/ -FileIndexMonitor::FileIndexMonitor(CacheStrapper *cs, std::string cachedir, std::string pid,const std::string& config_dir) +FileIndexMonitor::FileIndexMonitor(CacheStrapper *cs, std::string cachedir, const SSLIdType& pid,const std::string& config_dir) :CacheSource(RS_SERVICE_TYPE_FILE_INDEX, false, cs, cachedir), fiMutex("FileIndexMonitor"), fi(pid), pendingDirs(false), pendingForceCacheWrite(false), mForceCheck(false), mInCheck(false), hashCache(config_dir+"/" + "file_cache.lst"),useHashCache(true) @@ -271,7 +271,7 @@ FileIndexMonitor::~FileIndexMonitor() /* Data cleanup - TODO */ } -int FileIndexMonitor::SearchKeywords(std::list keywords, std::list &results,FileSearchFlags flags,const std::string& peer_id) +int FileIndexMonitor::SearchKeywords(std::list keywords, std::list &results,FileSearchFlags flags,const SSLIdType& peer_id) { results.clear(); std::list firesults; @@ -284,7 +284,7 @@ int FileIndexMonitor::SearchKeywords(std::list keywords, std::list< return filterResults(firesults,results,flags,peer_id) ; } -int FileIndexMonitor::SearchBoolExp(Expression *exp, std::list& results,FileSearchFlags flags,const std::string& peer_id) const +int FileIndexMonitor::SearchBoolExp(Expression *exp, std::list& results,FileSearchFlags flags,const SSLIdType& peer_id) const { results.clear(); std::list firesults; @@ -297,7 +297,7 @@ int FileIndexMonitor::SearchBoolExp(Expression *exp, std::list& resu return filterResults(firesults,results,flags,peer_id) ; } -int FileIndexMonitor::filterResults(std::list& firesults,std::list& results,FileSearchFlags flags,const std::string& peer_id) const +int FileIndexMonitor::filterResults(std::list& firesults,std::list& results,FileSearchFlags flags,const SSLIdType& peer_id) const { #ifdef DEBUG if((flags & ~RS_FILE_HINTS_PERMISSION_MASK) > 0) @@ -313,13 +313,13 @@ int FileIndexMonitor::filterResults(std::list& firesults,std::listname << ", flags=" << cdetails.flags << ", peer=" << peer_id ; #endif - if(!peer_id.empty()) + if(!peer_id.isNull()) { FileSearchFlags permission_flags = rsPeers->computePeerPermissionFlags(peer_id,cdetails.flags,cdetails.parent_groups) ; if (cdetails.type == DIR_TYPE_FILE && ( permission_flags & flags )) { - cdetails.id = "Local"; + cdetails.id.clear() ; results.push_back(cdetails); #ifdef FIM_DEBUG std::cerr << ": kept" << std::endl ; @@ -337,7 +337,7 @@ int FileIndexMonitor::filterResults(std::list& firesults,std::list& 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& parent_groups) const { std::list results; bool ok = false; @@ -361,12 +361,12 @@ bool FileIndexMonitor::findLocalFile(std::string hash,FileSearchFlags hint_flags // turn share flags into hint flags - FileSearchFlags shflh = peer_id.empty()?(RS_FILE_HINTS_BROWSABLE|RS_FILE_HINTS_NETWORK_WIDE):rsPeers->computePeerPermissionFlags(peer_id,storage_flags,parent_groups) ; + FileSearchFlags shflh = peer_id.isNull()?(RS_FILE_HINTS_BROWSABLE|RS_FILE_HINTS_NETWORK_WIDE):rsPeers->computePeerPermissionFlags(peer_id,storage_flags,parent_groups) ; #ifdef FIM_DEBUG std::cerr << "FileIndexMonitor::findLocalFile: Filtering candidate " << fe->name << ", flags=" << storage_flags << ", hint_flags=" << hint_flags << ", peer_id = " << peer_id << std::endl ; #endif - if(peer_id.empty() || (shflh & hint_flags)) + if(peer_id.isNull() || (shflh & hint_flags)) { #ifdef FIM_DEBUG std::cerr << "FileIndexMonitor::findLocalFile() Found Name: " << fe->name << std::endl; @@ -458,7 +458,7 @@ bool FileIndexMonitor::loadLocalCache(const RsCacheData &data) /* called with s std::cerr << std::endl; #endif fi.root->row = 0; - fi.root->name = data.pid; // XXX Hack here - TODO + fi.root->name = data.pid.toStdString(); // XXX Hack here - TODO std::string fname_browsable = data.path + '/' + name ; struct stat64 buf; @@ -516,7 +516,7 @@ bool FileIndexMonitor::loadLocalCache(const RsCacheData &data) /* called with s return false; } -bool FileIndexMonitor::updateCache(const RsCacheData &data,const std::set& destination_peers) /* we call this one */ +bool FileIndexMonitor::updateCache(const RsCacheData &data,const std::set& destination_peers) /* we call this one */ { 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. // This is probably a bit costly, but we can't suppose that the number of shared directories is bounded. // - std::list all_friend_ids ; + std::list all_friend_ids ; rsPeers->getFriendList(all_friend_ids); #ifdef FIM_DEBUG @@ -1116,9 +1116,9 @@ time_t FileIndexMonitor::locked_saveFileIndexes(bool update_cache) std::cerr << " " << *it << std::endl; #endif - std::map, std::set > peers_per_directory_combination ; + std::map, std::set > peers_per_directory_combination ; - for(std::list::const_iterator it(all_friend_ids.begin());it!=all_friend_ids.end();++it) + for(std::list::const_iterator it(all_friend_ids.begin());it!=all_friend_ids.end();++it) { #ifdef FIM_DEBUG std::cerr << "About to save, with the following restrictions:" << std::endl ; @@ -1153,14 +1153,14 @@ time_t FileIndexMonitor::locked_saveFileIndexes(bool update_cache) peers_per_directory_combination[forbidden_dirs].insert(*it) ; } - std::string ownId = rsPeers->getOwnId() ; + SSLIdType ownId = rsPeers->getOwnId() ; peers_per_directory_combination[std::set()].insert(ownId) ; // add full configuration to self, i.e. no forbidden directories. int n=0 ; time_t now = time(NULL) ; time_t mod_time = 0 ; - for(std::map, std::set >::const_iterator it(peers_per_directory_combination.begin()); + for(std::map, std::set >::const_iterator it(peers_per_directory_combination.begin()); it!=peers_per_directory_combination.end();++it,++n) { std::string tmpname_browsable; @@ -1210,7 +1210,7 @@ time_t FileIndexMonitor::locked_saveFileIndexes(bool update_cache) data.size = size; data.recvd = time(NULL); - for(std::set::const_iterator ff(it->second.begin());ff!=it->second.end();++ff) + for(std::set::const_iterator ff(it->second.begin());ff!=it->second.end();++ff) _cache_items_per_peer[*ff] = data ; data.cid.subid = 0; @@ -1261,7 +1261,7 @@ bool FileIndexMonitor::cachesAvailable(RsPeerId pid,std::map::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()) { diff --git a/libretroshare/src/dbase/fimonitor.h b/libretroshare/src/dbase/fimonitor.h index 9603aa313..396dc7825 100644 --- a/libretroshare/src/dbase/fimonitor.h +++ b/libretroshare/src/dbase/fimonitor.h @@ -106,16 +106,16 @@ class HashCache class FileIndexMonitor: public CacheSource, public RsThread { public: - FileIndexMonitor(CacheStrapper *cs, std::string cachedir, std::string pid, const std::string& config_dir); + FileIndexMonitor(CacheStrapper *cs, std::string cachedir, const SSLIdType& pid, const std::string& config_dir); virtual ~FileIndexMonitor(); /* external interface for filetransfer */ - bool findLocalFile(std::string hash,FileSearchFlags flags,const std::string& peer_id, std::string &fullpath, uint64_t &size,FileStorageFlags& storage_flags,std::list& 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& parent_groups) const; - int SearchKeywords(std::list keywords, std::list &results,FileSearchFlags flags,const std::string& peer_id) ; - int SearchBoolExp(Expression *exp, std::list &results,FileSearchFlags flags,const std::string& peer_id) const ; + int SearchKeywords(std::list keywords, std::list &results,FileSearchFlags flags,const SSLIdType& peer_id) ; + int SearchBoolExp(Expression *exp, std::list &results,FileSearchFlags flags,const SSLIdType& peer_id) const ; - int filterResults(std::list& firesults,std::list& results,FileSearchFlags flags,const std::string& peer_id) const ; + int filterResults(std::list& firesults,std::list& results,FileSearchFlags flags,const SSLIdType& peer_id) const ; /* external interface for local access to files */ @@ -125,7 +125,7 @@ class FileIndexMonitor: public CacheSource, public RsThread /* Interacting with CacheSource */ /* overloaded from CacheSource */ virtual bool loadLocalCache(const RsCacheData &data); /* called with stored data */ - bool updateCache(const RsCacheData &data,const std::set& dest_peers); /* we call when we have a new cache for others */ + bool updateCache(const RsCacheData &data,const std::set& dest_peers); /* we call when we have a new cache for others */ /* the FileIndexMonitor inner workings */ diff --git a/libretroshare/src/dbase/findex.cc b/libretroshare/src/dbase/findex.cc index f067f56af..d97aadce0 100644 --- a/libretroshare/src/dbase/findex.cc +++ b/libretroshare/src/dbase/findex.cc @@ -524,7 +524,7 @@ int DirEntry::print(std::string &out) return 1; } -FileIndex::FileIndex(const std::string& pid) +FileIndex::FileIndex(const SSLIdType& pid) { root = new PersonEntry(pid); registerEntry(root) ; @@ -857,7 +857,7 @@ int FileIndex::loadIndex(const std::string& filename, const std::string& expecte /* finished parse, last dir is root */ case 1: { - std::string pid = root -> id; + SSLIdType pid = root -> id; FileIndex::unregisterEntry((void*)root) ; delete root; /* to clean up old entries */ root = new PersonEntry(pid); diff --git a/libretroshare/src/dbase/findex.h b/libretroshare/src/dbase/findex.h index 32cfb66ea..ecf985bf9 100644 --- a/libretroshare/src/dbase/findex.h +++ b/libretroshare/src/dbase/findex.h @@ -174,7 +174,7 @@ class PersonEntry: public DirEntry { public: /* cleanup */ - PersonEntry(const std::string& pid) : id(pid) { return; } + PersonEntry(const SSLIdType& pid) : id(pid) { return; } virtual ~PersonEntry() { return; } DirEntry &operator=(DirEntry &src) @@ -186,7 +186,7 @@ DirEntry &operator=(DirEntry &src) virtual uint32_t type() const { return DIR_TYPE_PERSON ; } /* Data */ - std::string id; + SSLIdType id; /* Inherited members from FileEntry: int size - count for dirs @@ -209,7 +209,7 @@ class Expression; class FileIndex { public: - FileIndex(const std::string& pid); + FileIndex(const SSLIdType& pid); ~FileIndex(); /* control root entries */ diff --git a/libretroshare/src/dbase/fistore.cc b/libretroshare/src/dbase/fistore.cc index 629a977ed..abe957377 100644 --- a/libretroshare/src/dbase/fistore.cc +++ b/libretroshare/src/dbase/fistore.cc @@ -106,7 +106,7 @@ int FileIndexStore::loadCache(const RsCacheData &data) * * peername should not be used in dbase. */ - finew->root->name = data.pid; + finew->root->name = data.pid.toStdString(); if (local) { @@ -168,7 +168,7 @@ int FileIndexStore::loadCache(const RsCacheData &data) /* Search Interface - For Directory Access */ -int FileIndexStore::RequestDirDetails(const std::string& uid, const std::string& path, DirDetails& details) const +int FileIndexStore::RequestDirDetails(const SSLIdType& uid, const std::string& path, DirDetails& details) const { lockData(); @@ -382,7 +382,7 @@ int FileIndexStore::SearchKeywords(std::list keywords, std::list &resul { DirDetails dd; FileIndex::extractData(*rit, dd); - dd.id = "Local"; + dd.id.clear() ; results.push_back(dd); } diff --git a/libretroshare/src/dbase/fistore.h b/libretroshare/src/dbase/fistore.h index 7a6339c68..7766f0ba6 100644 --- a/libretroshare/src/dbase/fistore.h +++ b/libretroshare/src/dbase/fistore.h @@ -83,7 +83,7 @@ virtual int loadCache(const RsCacheData &data); /* actual load, once data avai /* Search Interface - For Directory Access */ - int RequestDirDetails(const std::string& uid, const std::string& path, DirDetails &details) const; + int RequestDirDetails(const SSLIdType& uid, const std::string& path, DirDetails &details) const; int RequestDirDetails(void *ref, DirDetails &details, FileSearchFlags flags) const; uint32_t getType(void *ref) const ; diff --git a/libretroshare/src/ft/ftchunkmap.cc b/libretroshare/src/ft/ftchunkmap.cc index 9a89119b1..1fff8a3b7 100644 --- a/libretroshare/src/ft/ftchunkmap.cc +++ b/libretroshare/src/ft/ftchunkmap.cc @@ -267,15 +267,15 @@ void ChunkMap::setChunkCheckingResult(uint32_t chunk_number,bool check_succeeded // - chunks pushed when new chunks are needed // - chunks removed when completely downloaded // -bool ChunkMap::getDataChunk(const std::string& peer_id,uint32_t size_hint,ftChunk& chunk,bool& source_chunk_map_needed) +bool ChunkMap::getDataChunk(const RsPeerId& peer_id,uint32_t size_hint,ftChunk& chunk,bool& source_chunk_map_needed) { #ifdef DEBUG_FTCHUNK std::cerr << "*** ChunkMap::getDataChunk: size_hint = " << size_hint << std::endl ; #endif // 1 - find if this peer already has an active chunk. // - std::map::iterator it = _active_chunks_feed.find(peer_id) ; - std::map::iterator falsafe_it = _active_chunks_feed.end() ; + std::map::iterator it = _active_chunks_feed.find(peer_id) ; + std::map::iterator falsafe_it = _active_chunks_feed.end() ; if(it == _active_chunks_feed.end()) { @@ -284,7 +284,7 @@ bool ChunkMap::getDataChunk(const std::string& peer_id,uint32_t size_hint,ftChun // 0 - Look into other pending chunks and slice from here. We only consider chunks with size smaller than // the requested size, // - for(std::map::iterator pit(_active_chunks_feed.begin());pit!=_active_chunks_feed.end();++pit) + for(std::map::iterator pit(_active_chunks_feed.begin());pit!=_active_chunks_feed.end();++pit) { uint32_t c = pit->second._start / _chunk_size ; @@ -385,10 +385,10 @@ void ChunkMap::removeInactiveChunks(std::vector& to_remove) // Also remove the chunk from the chunk feed, to free the associated peer. // - for(std::map::iterator it3=_active_chunks_feed.begin();it3!=_active_chunks_feed.end();) + for(std::map::iterator it3=_active_chunks_feed.begin();it3!=_active_chunks_feed.end();) if(it3->second._start == _chunk_size*uint64_t(it->first)) { - std::map::iterator tmp3 = it3 ; + std::map::iterator tmp3 = it3 ; ++it3 ; _active_chunks_feed.erase(tmp3) ; } @@ -428,7 +428,7 @@ bool ChunkMap::isChunkAvailable(uint64_t offset, uint32_t chunk_size) const return true ; } -void ChunkMap::setPeerAvailabilityMap(const std::string& peer_id,const CompressedChunkMap& cmap) +void ChunkMap::setPeerAvailabilityMap(const RsPeerId& peer_id,const CompressedChunkMap& cmap) { #ifdef DEBUG_FTCHUNK std::cout << "ChunkMap::Receiving new availability map for peer " << peer_id << std::endl ; @@ -469,9 +469,9 @@ uint32_t ChunkMap::sizeOfChunk(uint32_t cid) const return _chunk_size ; } -SourceChunksInfo *ChunkMap::getSourceChunksInfo(const std::string& peer_id) +SourceChunksInfo *ChunkMap::getSourceChunksInfo(const RsPeerId& peer_id) { - std::map::iterator it(_peers_chunks_availability.find(peer_id)) ; + std::map::iterator it(_peers_chunks_availability.find(peer_id)) ; // Do we have a chunk map for this file source ? // - if yes, we use it @@ -508,16 +508,16 @@ SourceChunksInfo *ChunkMap::getSourceChunksInfo(const std::string& peer_id) return &(it->second) ; } -void ChunkMap::getSourcesList(uint32_t chunk_number,std::vector& sources) +void ChunkMap::getSourcesList(uint32_t chunk_number,std::vector& sources) { sources.clear() ; - for(std::map::const_iterator it(_peers_chunks_availability.begin());it!=_peers_chunks_availability.end();++it) + for(std::map::const_iterator it(_peers_chunks_availability.begin());it!=_peers_chunks_availability.end();++it) if(it->second.cmap[chunk_number]) sources.push_back(it->first) ; } -uint32_t ChunkMap::getAvailableChunk(const std::string& peer_id,bool& map_is_too_old) +uint32_t ChunkMap::getAvailableChunk(const RsPeerId& peer_id,bool& map_is_too_old) { // Quite simple strategy: Check for 1st availabe chunk for this peer starting from the given start location. // @@ -601,13 +601,13 @@ void ChunkMap::getChunksInfo(FileChunksInfo& info) const info.compressed_peer_availability_maps.clear() ; - for(std::map::const_iterator it(_peers_chunks_availability.begin());it!=_peers_chunks_availability.end();++it) + for(std::map::const_iterator it(_peers_chunks_availability.begin());it!=_peers_chunks_availability.end();++it) info.compressed_peer_availability_maps[it->first] = it->second.cmap ; } -void ChunkMap::removeFileSource(const std::string& peer_id) +void ChunkMap::removeFileSource(const RsPeerId& peer_id) { - std::map::iterator it(_peers_chunks_availability.find(peer_id)) ; + std::map::iterator it(_peers_chunks_availability.find(peer_id)) ; if(it == _peers_chunks_availability.end()) return ; diff --git a/libretroshare/src/ft/ftchunkmap.h b/libretroshare/src/ft/ftchunkmap.h index e5ddd6789..84174f87a 100644 --- a/libretroshare/src/ft/ftchunkmap.h +++ b/libretroshare/src/ft/ftchunkmap.h @@ -43,7 +43,7 @@ class ftChunk ChunkId id ; // id of the chunk. Equal to the starting offset of the chunk time_t ts; // time of last data received int *ref_cnt; // shared counter of number of sub-blocks. Used when a slice gets split. - std::string peer_id ; + RsPeerId peer_id ; }; // This class handles a single fixed-sized chunk. Although each chunk is requested at once, @@ -118,7 +118,7 @@ class ChunkMap /// On return: /// - source_chunk_map_needed = true if the source map should be asked - virtual bool getDataChunk(const std::string& peer_id,uint32_t size_hint,ftChunk& chunk,bool& source_chunk_map_needed) ; + virtual bool getDataChunk(const RsPeerId& peer_id,uint32_t size_hint,ftChunk& chunk,bool& source_chunk_map_needed) ; /// Notify received a slice of data. This needs to /// - carve in the map of chunks what is received, what is not. @@ -145,7 +145,7 @@ class ChunkMap void setAvailabilityMap(const CompressedChunkMap& cmap) ; /// Removes the source availability map. The map - void removeFileSource(const std::string& peer_id) ; + void removeFileSource(const RsPeerId& peer_id) ; /// This function fills in a plain map for a file of the given size. This /// is used to ensure that the chunk size will be consistent with the rest @@ -165,12 +165,12 @@ class ChunkMap /// Updates the peer's availablility map // - void setPeerAvailabilityMap(const std::string& peer_id,const CompressedChunkMap& peer_map) ; + void setPeerAvailabilityMap(const RsPeerId& peer_id,const CompressedChunkMap& peer_map) ; /// Returns a pointer to the availability chunk map of the given source, and possibly /// allocates it if necessary. // - SourceChunksInfo *getSourceChunksInfo(const std::string& peer_id) ; + SourceChunksInfo *getSourceChunksInfo(const RsPeerId& peer_id) ; /// Returns the total size of downloaded data in the file. uint64_t getTotalReceived() const { return _total_downloaded ; } @@ -188,7 +188,7 @@ class ChunkMap void getChunksToCheck(std::vector& chunks_to_ask) ; /// Get all available sources for this chunk - void getSourcesList(uint32_t chunk_number,std::vector& sources) ; + void getSourcesList(uint32_t chunk_number,std::vector& sources) ; /// sets all chunks to checking state void forceCheck() ; @@ -203,16 +203,16 @@ class ChunkMap /// Returns a chunk available for this peer_id, depending on the chunk strategy. // - uint32_t getAvailableChunk(const std::string& peer_id,bool& chunk_map_too_old) ; + uint32_t getAvailableChunk(const RsPeerId& peer_id,bool& chunk_map_too_old) ; private: uint64_t _file_size ; //! total size of the file in bytes. uint32_t _chunk_size ; //! Size of chunks. Common to all chunks. FileChunksInfo::ChunkStrategy _strategy ; //! how do we allocate new chunks - std::map _active_chunks_feed ; //! vector of chunks being downloaded. Exactly 1 chunk per peer. + std::map _active_chunks_feed ; //! vector of chunks being downloaded. Exactly 1 chunk per peer. std::map _slices_to_download ; //! list of (slice id,slice size) std::vector _map ; //! vector of chunk state over the whole file - std::map _peers_chunks_availability ; //! what does each source peer have + std::map _peers_chunks_availability ; //! what does each source peer have uint64_t _total_downloaded ; //! completion for the file bool _file_is_complete ; //! set to true when the file is complete. bool _assume_availability ; //! true if all sources always have the complete file. diff --git a/libretroshare/src/ft/ftcontroller.cc b/libretroshare/src/ft/ftcontroller.cc index d8f3d174c..3ac172594 100644 --- a/libretroshare/src/ft/ftcontroller.cc +++ b/libretroshare/src/ft/ftcontroller.cc @@ -161,7 +161,7 @@ bool ftController::getFileDownloadChunksDetails(const std::string& hash,FileChun return false ; } -void ftController::addFileSource(const std::string& hash,const std::string& peer_id) +void ftController::addFileSource(const std::string& hash,const SSLIdType& peer_id) { 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 ; #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 ********/ @@ -293,7 +293,7 @@ void ftController::searchForDirectSources() if(mSearch->search(it->first, RS_FILE_HINTS_REMOTE | RS_FILE_HINTS_SPEC_ONLY, info)) for(std::list::const_iterator pit = info.peers.begin(); pit != info.peers.end(); pit++) - if(rsPeers->servicePermissionFlags_sslid(pit->peerId) & RS_SERVICE_PERM_DIRECT_DL) + if(rsPeers->servicePermissionFlags(pit->peerId) & RS_SERVICE_PERM_DIRECT_DL) if(it->second->mTransfer->addFileSource(pit->peerId)) /* if the sources don't exist already - add in */ setPeerState(it->second->mTransfer, pit->peerId, FT_CNTRL_STANDARD_RATE, mLinkMgr->isOnline( pit->peerId )); } @@ -1070,9 +1070,9 @@ bool ftController::alreadyHaveFile(const std::string& hash, FileInfo &info) bool ftController::FileRequest(const std::string& fname, const std::string& hash, uint64_t size, const std::string& dest, TransferRequestFlags flags, - const std::list &_srcIds, uint16_t state) + const std::list &_srcIds, uint16_t state) { - std::list srcIds(_srcIds) ; + std::list srcIds(_srcIds) ; /* check if we have the file */ @@ -1134,10 +1134,10 @@ bool ftController::FileRequest(const std::string& fname, const std::string& has // remove the sources from the list, if they don't have clearance for direct transfer. This happens only for non cache files. // if(!(flags & RS_FILE_REQ_CACHE)) - for(std::list::iterator it = srcIds.begin(); it != srcIds.end(); ) - if(!(rsPeers->servicePermissionFlags_sslid(*it) & RS_SERVICE_PERM_DIRECT_DL)) + for(std::list::iterator it = srcIds.begin(); it != srcIds.end(); ) + if(!(rsPeers->servicePermissionFlags(*it) & RS_SERVICE_PERM_DIRECT_DL)) { - std::list::iterator tmp(it) ; + std::list::iterator tmp(it) ; ++tmp ; srcIds.erase(it) ; it = tmp ; @@ -1145,7 +1145,7 @@ bool ftController::FileRequest(const std::string& fname, const std::string& has else ++it ; - std::list::const_iterator it; + std::list::const_iterator it; std::list::const_iterator pit; #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++) - if(rsPeers->servicePermissionFlags_sslid(*it) & RS_SERVICE_PERM_DIRECT_DL) + if(rsPeers->servicePermissionFlags(*it) & RS_SERVICE_PERM_DIRECT_DL) { uint32_t i, j; if ((dit->second)->mTransfer->getPeerState(*it, i, j)) @@ -1248,7 +1248,7 @@ bool ftController::FileRequest(const std::string& fname, const std::string& has #endif // Because this is auto-add, we only add sources that we allow to DL from using direct transfers. - if ((srcIds.end() == std::find( srcIds.begin(), srcIds.end(), pit->peerId)) && (RS_SERVICE_PERM_DIRECT_DL & rsPeers->servicePermissionFlags_sslid(pit->peerId))) + if ((srcIds.end() == std::find( srcIds.begin(), srcIds.end(), pit->peerId)) && (RS_SERVICE_PERM_DIRECT_DL & rsPeers->servicePermissionFlags(pit->peerId))) { srcIds.push_back(pit->peerId); @@ -1331,7 +1331,7 @@ bool ftController::FileRequest(const std::string& fname, const std::string& has return true; } -bool ftController::setPeerState(ftTransferModule *tm, std::string id, uint32_t maxrate, bool online) +bool ftController::setPeerState(ftTransferModule *tm, const SSLIdType& id, uint32_t maxrate, bool online) { 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. /* get list of sources from transferModule */ - std::list peerIds; - std::list::iterator pit; + std::list peerIds; + std::list::iterator pit; if (!completed) { @@ -1922,7 +1922,7 @@ bool ftController::RequestCacheFile(RsPeerId id, std::string path, std::string h #endif /* Request File */ - std::list ids; + std::list ids; ids.push_back(id); FileInfo info ; diff --git a/libretroshare/src/ft/ftcontroller.h b/libretroshare/src/ft/ftcontroller.h index 4d0580e27..8db5f6ed4 100644 --- a/libretroshare/src/ft/ftcontroller.h +++ b/libretroshare/src/ft/ftcontroller.h @@ -96,7 +96,7 @@ class ftPendingRequest public: ftPendingRequest(const std::string& fname, const std::string& hash, uint64_t size, const std::string& dest, TransferRequestFlags flags, - const std::list &srcIds, uint16_t state) + const std::list &srcIds, uint16_t state) : mName(fname), mHash(hash), mSize(size), mDest(dest), mFlags(flags), mSrcIds(srcIds), mState(state) { return; } @@ -107,7 +107,7 @@ class ftPendingRequest uint64_t mSize; std::string mDest; TransferRequestFlags mFlags; - std::list mSrcIds; + std::list mSrcIds; 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, uint64_t size, const std::string& dest, TransferRequestFlags flags, - const std::list &sourceIds, uint16_t state = ftFileControl::DOWNLOADING); + const std::list &sourceIds, uint16_t state = ftFileControl::DOWNLOADING); /// Do we already have this file, either in download or in file lists ? bool alreadyHaveFile(const std::string& hash, FileInfo &info); @@ -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. /// - bool assumeAvailability(const std::string& peer_id) const ; + bool assumeAvailability(const SSLIdType& peer_id) const ; /* pqiMonitor callback (also provided mConnMgr pointer!) */ virtual void statusChange(const std::list &plist); - void addFileSource(const std::string& hash,const std::string& peer_id) ; - void removeFileSource(const std::string& hash,const std::string& peer_id) ; + void addFileSource(const std::string& hash,const SSLIdType& peer_id) ; + void removeFileSource(const std::string& hash,const SSLIdType& peer_id) ; protected: @@ -226,7 +226,7 @@ class ftController: public CacheTransfer, public RsThread, public pqiMonitor, pu bool completeFile(std::string hash); bool handleAPendingRequest(); - bool setPeerState(ftTransferModule *tm, std::string id, + bool setPeerState(ftTransferModule *tm, const SSLIdType& id, uint32_t maxrate, bool online); time_t last_save_time ; diff --git a/libretroshare/src/ft/ftdata.h b/libretroshare/src/ft/ftdata.h index 9b8cbeaff..bf50c0d3f 100644 --- a/libretroshare/src/ft/ftdata.h +++ b/libretroshare/src/ft/ftdata.h @@ -38,7 +38,6 @@ #include #include -#include #include /*************** SEND INTERFACE *******************/ @@ -51,23 +50,23 @@ class ftDataSend virtual ~ftDataSend() { return; } /* Client Send */ - virtual bool sendDataRequest(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize) = 0; + virtual bool sendDataRequest(const RsPeerId& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize) = 0; /* Server Send */ - virtual bool sendData(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data) = 0; + virtual bool sendData(const RsPeerId& peerId, const 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 //directions, but for different usages, we have this "is_client" flags, //that gives the ultimate goal of the data. "is_client==true" means that //the message is for a client (download) instead of a server. // - virtual bool sendChunkMapRequest(const std::string& peer_id,const std::string& hash,bool is_client) = 0; - virtual bool sendChunkMap(const std::string& peer_id,const std::string& hash,const CompressedChunkMap& cmap,bool is_client) = 0; + virtual bool sendChunkMapRequest(const RsPeerId& peer_id,const std::string& hash,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 - 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 - 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; } /* 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 */ - 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 - 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 - 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 recvSingleChunkCRC(const std::string& peer_id,const std::string& hash,uint32_t chunk_id,const Sha1CheckSum& sum) = 0; + virtual bool recvSingleChunkCRCRequest(const RsPeerId& peer_id,const std::string& hash,uint32_t chunk_id) = 0; + virtual bool recvSingleChunkCRC(const RsPeerId& peer_id,const std::string& hash,uint32_t chunk_id,const Sha1CheckSum& sum) = 0; }; diff --git a/libretroshare/src/ft/ftdatamultiplex.cc b/libretroshare/src/ft/ftdatamultiplex.cc index c7480d181..399f34987 100644 --- a/libretroshare/src/ft/ftdatamultiplex.cc +++ b/libretroshare/src/ft/ftdatamultiplex.cc @@ -63,14 +63,14 @@ const uint32_t FT_SERVER_CHUNK_MAP_REQ = 0x0004; // chunk map request to be tre //const uint32_t FT_CRC32MAP_REQ = 0x0005; // crc32 map request to be treated by server const uint32_t FT_CLIENT_CHUNK_CRC_REQ = 0x0006; // chunk sha1 crc request to be treated -ftRequest::ftRequest(uint32_t type, std::string peerId, std::string hash, uint64_t size, uint64_t offset, uint32_t chunk, void *data) +ftRequest::ftRequest(uint32_t type, const RsPeerId& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunk, void *data) :mType(type), mPeerId(peerId), mHash(hash), mSize(size), mOffset(offset), mChunk(chunk), mData(data) { return; } -ftDataMultiplex::ftDataMultiplex(std::string ownId, ftDataSend *server, ftSearch *search) +ftDataMultiplex::ftDataMultiplex(const RsPeerId& ownId, ftDataSend *server, ftSearch *search) :RsQueueThread(DMULTIPLEX_MIN, DMULTIPLEX_MAX, DMULTIPLEX_RELAX), dataMtx("ftDataMultiplex"), mDataSend(server), mSearch(search), mOwnId(ownId) { @@ -204,7 +204,7 @@ bool ftDataMultiplex::FileDetails(const std::string &hash, FileSearchFlags hi /*************** SEND INTERFACE (calls ftDataSend) *******************/ /* Client Send */ -bool ftDataMultiplex::sendDataRequest(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize) +bool ftDataMultiplex::sendDataRequest(const RsPeerId& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize) { #ifdef MPLEX_DEBUG std::cerr << "ftDataMultiplex::sendDataRequest() Client Send"; @@ -214,7 +214,7 @@ bool ftDataMultiplex::sendDataRequest(const std::string& peerId, const std::stri } /* Server Send */ -bool ftDataMultiplex::sendData(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data) +bool ftDataMultiplex::sendData(const RsPeerId& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data) { #ifdef MPLEX_DEBUG std::cerr << "ftDataMultiplex::sendData() Server Send"; @@ -227,7 +227,7 @@ bool ftDataMultiplex::sendData(const std::string& peerId, const std::string& has /*************** RECV INTERFACE (provides ftDataRecv) ****************/ /* Client Recv */ -bool ftDataMultiplex::recvData(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data) +bool ftDataMultiplex::recvData(const RsPeerId& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data) { #ifdef MPLEX_DEBUG std::cerr << "ftDataMultiplex::recvData() Client Recv"; @@ -242,7 +242,7 @@ bool ftDataMultiplex::recvData(const std::string& peerId, const std::string& has /* Server Recv */ -bool ftDataMultiplex::recvDataRequest(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize) +bool ftDataMultiplex::recvDataRequest(const RsPeerId& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize) { #ifdef MPLEX_DEBUG std::cerr << "ftDataMultiplex::recvDataRequest() Server Recv"; @@ -256,7 +256,7 @@ bool ftDataMultiplex::recvDataRequest(const std::string& peerId, const std::stri return true; } -bool ftDataMultiplex::recvChunkMapRequest(const std::string& peerId, const std::string& hash,bool is_client) +bool ftDataMultiplex::recvChunkMapRequest(const RsPeerId& peerId, const std::string& hash,bool is_client) { #ifdef MPLEX_DEBUG std::cerr << "ftDataMultiplex::recvChunkMapRequest() Server Recv"; @@ -273,7 +273,7 @@ bool ftDataMultiplex::recvChunkMapRequest(const std::string& peerId, const std:: return true; } -bool ftDataMultiplex::recvSingleChunkCRCRequest(const std::string& peerId, const std::string& hash,uint32_t chunk_number) +bool ftDataMultiplex::recvSingleChunkCRCRequest(const RsPeerId& peerId, const std::string& hash,uint32_t chunk_number) { #ifdef MPLEX_DEBUG std::cerr << "ftDataMultiplex::recvChunkMapRequest() Server Recv"; @@ -406,7 +406,7 @@ bool ftDataMultiplex::doWork() return true; } -bool ftDataMultiplex::recvSingleChunkCRC(const std::string& peerId, const std::string& hash,uint32_t chunk_number,const Sha1CheckSum& crc) +bool ftDataMultiplex::recvSingleChunkCRC(const RsPeerId& peerId, const std::string& hash,uint32_t chunk_number,const Sha1CheckSum& crc) { 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 // - 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 ******/ @@ -549,7 +549,7 @@ bool ftDataMultiplex::recvChunkMap(const std::string& peerId, const std::string& return false; } -bool ftDataMultiplex::handleRecvClientChunkMapRequest(const std::string& peerId, const std::string& hash) +bool ftDataMultiplex::handleRecvClientChunkMapRequest(const RsPeerId& peerId, const std::string& hash) { CompressedChunkMap cmap ; @@ -581,7 +581,7 @@ bool ftDataMultiplex::handleRecvClientChunkMapRequest(const std::string& peerId, return true ; } -bool ftDataMultiplex::handleRecvChunkCrcRequest(const std::string& peerId, const std::string& hash, uint32_t chunk_number) +bool ftDataMultiplex::handleRecvChunkCrcRequest(const RsPeerId& peerId, const std::string& hash, uint32_t chunk_number) { // look into the sha1sum cache @@ -705,7 +705,7 @@ bool ftDataMultiplex::handleRecvChunkCrcRequest(const std::string& peerId, const return true ; } -bool ftDataMultiplex::handleRecvServerChunkMapRequest(const std::string& peerId, const std::string& hash) +bool ftDataMultiplex::handleRecvServerChunkMapRequest(const RsPeerId& peerId, const std::string& hash) { CompressedChunkMap cmap ; std::map::iterator it ; @@ -754,9 +754,7 @@ bool ftDataMultiplex::handleRecvServerChunkMapRequest(const std::string& peerId, return true; } -bool ftDataMultiplex::handleRecvData(const std::string& peerId, - const std::string& hash, uint64_t /*size*/, - uint64_t offset, uint32_t chunksize, void *data) +bool ftDataMultiplex::handleRecvData(const RsPeerId& peerId, const std::string& hash, uint64_t /*size*/, uint64_t offset, uint32_t chunksize, void *data) { ftTransferModule *transfer_module = NULL ; @@ -787,7 +785,7 @@ bool ftDataMultiplex::handleRecvData(const std::string& peerId, /* called by ftTransferModule */ -bool ftDataMultiplex::handleRecvDataRequest(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize) +bool ftDataMultiplex::handleRecvDataRequest(const RsPeerId& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize) { /**** Find Files *****/ @@ -833,8 +831,7 @@ bool ftDataMultiplex::handleRecvDataRequest(const std::string& peerId, const std return true; } -bool ftDataMultiplex::locked_handleServerRequest(ftFileProvider *provider, - std::string peerId, std::string hash, uint64_t size, +bool ftDataMultiplex::locked_handleServerRequest(ftFileProvider *provider, const RsPeerId& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize) { if(chunksize > uint32_t(10*1024*1024)) @@ -875,7 +872,7 @@ bool ftDataMultiplex::locked_handleServerRequest(ftFileProvider *provider, return false; } -bool ftDataMultiplex::getClientChunkMap(const std::string& upload_hash,const std::string& peerId,CompressedChunkMap& cmap) +bool ftDataMultiplex::getClientChunkMap(const std::string& upload_hash,const RsPeerId& peerId,CompressedChunkMap& cmap) { bool too_old = false; { @@ -897,7 +894,7 @@ bool ftDataMultiplex::getClientChunkMap(const std::string& upload_hash,const std return true ; } -bool ftDataMultiplex::sendChunkMapRequest(const std::string& peer_id,const std::string& hash,bool is_client) +bool ftDataMultiplex::sendChunkMapRequest(const RsPeerId& peer_id,const std::string& hash,bool is_client) { return mDataSend->sendChunkMapRequest(peer_id,hash,is_client); } @@ -947,13 +944,13 @@ void ftDataMultiplex::handlePendingCrcRequests() if(it4 == mClients.end()) continue ; - std::vector sources ; + std::vector sources ; it4->second.mCreator->getSourcesList(it2->first,sources) ; // 1 - go through all sources. Take the oldest one. // - std::string best_source ; + RsPeerId best_source ; time_t oldest_timestamp = now ; for(uint32_t i=0;i::const_iterator it3(it2->second.second.find(sources[i])) ; + std::map::const_iterator it3(it2->second.second.find(sources[i])) ; if(it3 == it2->second.second.end()) // source not found. So this one is surely the oldest one to have been requested. { @@ -984,7 +981,7 @@ void ftDataMultiplex::handlePendingCrcRequests() std::cerr << "ftDataMultiplex::handlePendingCrcRequests(): Source too recently used! So using it directly." << std::endl; #endif } - if(best_source != "") + if(!best_source.isNull()) { #ifdef MPLEX_DEBUG std::cerr << "ftDataMultiplex::handlePendingCrcRequests(): Asking crc of chunk " << it2->first << " to peer " << best_source << " for hash " << it->first << std::endl; @@ -1044,7 +1041,7 @@ void ftDataMultiplex::deleteUnusedServers() ++sit ; } -bool ftDataMultiplex::handleSearchRequest(const std::string& peerId, const std::string& hash) +bool ftDataMultiplex::handleSearchRequest(const RsPeerId& peerId, const std::string& hash) { #ifdef MPLEX_DEBUG std::cerr << "ftDataMultiplex::handleSearchRequest("; diff --git a/libretroshare/src/ft/ftdatamultiplex.h b/libretroshare/src/ft/ftdatamultiplex.h index 23bac4cf8..a8130fd3d 100644 --- a/libretroshare/src/ft/ftdatamultiplex.h +++ b/libretroshare/src/ft/ftdatamultiplex.h @@ -63,13 +63,13 @@ class ftRequest { public: - ftRequest(uint32_t type, std::string peerId, std::string hash, uint64_t size, uint64_t offset, uint32_t chunk, void *data); + ftRequest(uint32_t type, const SSLIdType& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunk, void *data); ftRequest() :mType(0), mSize(0), mOffset(0), mChunk(0), mData(NULL) { return; } uint32_t mType; - std::string mPeerId; + SSLIdType mPeerId; std::string mHash; uint64_t mSize; uint64_t mOffset; @@ -77,7 +77,7 @@ class ftRequest void *mData; }; -typedef std::map ChunkCheckSumSourceList ; +typedef std::map ChunkCheckSumSourceList ; class Sha1CacheEntry { @@ -93,7 +93,7 @@ class ftDataMultiplex: public ftDataRecv, public RsQueueThread public: - ftDataMultiplex(std::string ownId, ftDataSend *server, ftSearch *search); + ftDataMultiplex(const SSLIdType& ownId, ftDataSend *server, ftSearch *search); /* ftController Interface */ bool addTransferModule(ftTransferModule *mod, ftFileCreator *f); @@ -112,13 +112,13 @@ class ftDataMultiplex: public ftDataRecv, public RsQueueThread /*************** SEND INTERFACE (calls ftDataSend) *******************/ /* Client Send */ - bool sendDataRequest(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize); + bool sendDataRequest(const SSLIdType& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize); /* Server Send */ - bool sendData(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data); + bool sendData(const SSLIdType& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data); /* Server/client Send */ - bool sendChunkMapRequest(const std::string& peerId, const std::string& hash,bool is_client) ; + bool sendChunkMapRequest(const SSLIdType& peerId, const std::string& hash,bool is_client) ; /* called from a separate thread */ @@ -129,22 +129,22 @@ class ftDataMultiplex: public ftDataRecv, public RsQueueThread /*************** RECV INTERFACE (provides ftDataRecv) ****************/ /* Client Recv */ - virtual bool recvData(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data); + virtual bool recvData(const SSLIdType& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data); /* Server Recv */ - virtual bool recvDataRequest(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize); + virtual bool recvDataRequest(const SSLIdType& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize); /// Receive a request for a chunk map - virtual bool recvChunkMapRequest(const std::string& peer_id,const std::string& hash,bool is_client) ; + virtual bool recvChunkMapRequest(const SSLIdType& peer_id,const std::string& hash,bool is_client) ; /// Receive a chunk map - virtual bool recvChunkMap(const std::string& peer_id,const std::string& hash,const CompressedChunkMap& cmap,bool is_client) ; + virtual bool recvChunkMap(const 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 recvSingleChunkCRC(const std::string& peer_id,const std::string& hash,uint32_t chunk_id,const Sha1CheckSum& sum) ; + virtual bool recvSingleChunkCRCRequest(const SSLIdType& peer_id,const std::string& hash,uint32_t chunk_id) ; + 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 // 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: @@ -155,15 +155,15 @@ class ftDataMultiplex: public ftDataRecv, public RsQueueThread private: /* Handling Job Queues */ - bool handleRecvData(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data); - bool handleRecvDataRequest(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize); - bool handleSearchRequest(const std::string& peerId, const std::string& hash); - bool handleRecvClientChunkMapRequest(const std::string& peerId, const std::string& hash) ; - bool handleRecvServerChunkMapRequest(const std::string& peerId, const std::string& hash) ; - bool handleRecvChunkCrcRequest(const std::string& peerId, const std::string& hash,uint32_t chunk_id) ; + bool handleRecvData(const SSLIdType& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data); + bool handleRecvDataRequest(const SSLIdType& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize); + bool handleSearchRequest(const SSLIdType& peerId, const std::string& hash); + bool handleRecvClientChunkMapRequest(const SSLIdType& peerId, const std::string& hash) ; + bool handleRecvServerChunkMapRequest(const SSLIdType& peerId, const std::string& hash) ; + bool handleRecvChunkCrcRequest(const SSLIdType& peerId, const std::string& hash,uint32_t chunk_id) ; /* We end up doing the actual server job here */ - bool locked_handleServerRequest(ftFileProvider *provider, std::string peerId, std::string hash, uint64_t size, uint64_t offset, uint32_t chunksize); + bool locked_handleServerRequest(ftFileProvider *provider, const SSLIdType& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize); RsMutex dataMtx; @@ -178,7 +178,7 @@ class ftDataMultiplex: public ftDataRecv, public RsQueueThread ftDataSend *mDataSend; ftSearch *mSearch; - std::string mOwnId; + RsPeerId mOwnId; friend class ftServer; }; diff --git a/libretroshare/src/ft/ftdbase.cc b/libretroshare/src/ft/ftdbase.cc index e7948427f..6ea5ae963 100644 --- a/libretroshare/src/ft/ftdbase.cc +++ b/libretroshare/src/ft/ftdbase.cc @@ -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) { 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 { - 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 std::cerr << "ftFiMonitor::search(" << hash << "," << hintflags; diff --git a/libretroshare/src/ft/ftdbase.h b/libretroshare/src/ft/ftdbase.h index 108e37fc2..2280540a3 100644 --- a/libretroshare/src/ft/ftdbase.h +++ b/libretroshare/src/ft/ftdbase.h @@ -58,11 +58,11 @@ virtual bool search(const std::string &hash, FileSearchFlags hintflags, FileInfo class ftFiMonitor: public FileIndexMonitor, public ftSearch, public p3Config { public: - ftFiMonitor(CacheStrapper *cs,std::string cachedir, std::string pid,const std::string& config_dir); + ftFiMonitor(CacheStrapper *cs,std::string cachedir, const RsPeerId& pid,const std::string& config_dir); /* overloaded search function */ virtual bool search(const std::string &hash, FileSearchFlags hintflags, FileInfo &info) const; - virtual bool search(const std::string &hash, FileSearchFlags hintflags, const std::string& peer_id, FileInfo &info) const; + virtual bool search(const std::string &hash, FileSearchFlags hintflags, const RsPeerId& peer_id, FileInfo &info) const; /* overloaded set dirs enables config indication */ virtual void setSharedDirectories(const std::list& dirList); diff --git a/libretroshare/src/ft/ftfilecreator.cc b/libretroshare/src/ft/ftfilecreator.cc index 0611ef182..06c40ea85 100644 --- a/libretroshare/src/ft/ftfilecreator.cc +++ b/libretroshare/src/ft/ftfilecreator.cc @@ -65,7 +65,7 @@ ftFileCreator::ftFileCreator(const std::string& path, uint64_t size, const std:: #endif } -bool ftFileCreator::getFileData(const std::string& peer_id,uint64_t offset, uint32_t &chunk_size, void *data) +bool ftFileCreator::getFileData(const RsPeerId& peer_id,uint64_t offset, uint32_t &chunk_size, void *data) { // Only send the data if we actually have it. // @@ -243,7 +243,7 @@ void ftFileCreator::removeInactiveChunks() #endif } -void ftFileCreator::removeFileSource(const std::string& peer_id) +void ftFileCreator::removeFileSource(const RsPeerId& peer_id) { RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/ #ifdef FILE_DEBUG @@ -456,7 +456,7 @@ void ftFileCreator::setChunkStrategy(FileChunksInfo::ChunkStrategy s) * But can return size = 0, if we are still waiting for the data. */ -bool ftFileCreator::getMissingChunk(const std::string& peer_id,uint32_t size_hint,uint64_t &offset, uint32_t& size,bool& source_chunk_map_needed) +bool ftFileCreator::getMissingChunk(const RsPeerId& peer_id,uint32_t size_hint,uint64_t &offset, uint32_t& size,bool& source_chunk_map_needed) { RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/ #ifdef FILE_DEBUG @@ -559,7 +559,7 @@ bool ftFileCreator::locked_printChunkMap() std::cerr << " " << it->second << std::endl ; std::cerr << "Active chunks per peer:" << std::endl ; - for(std::map::const_iterator it(mChunksPerPeer.begin());it!=mChunksPerPeer.end();++it) + for(std::map::const_iterator it(mChunksPerPeer.begin());it!=mChunksPerPeer.end();++it) std::cerr << " " << it->first << "\t: " << it->second.cnt << std::endl; return true; @@ -586,14 +586,14 @@ void ftFileCreator::getAvailabilityMap(CompressedChunkMap& map) chunkMap.getAvailabilityMap(map) ; } -bool ftFileCreator::sourceIsComplete(const std::string& peer_id) +bool ftFileCreator::sourceIsComplete(const RsPeerId& peer_id) { RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/ return chunkMap.getSourceChunksInfo(peer_id)->is_full ; } -void ftFileCreator::setSourceMap(const std::string& peer_id,const CompressedChunkMap& compressed_map) +void ftFileCreator::setSourceMap(const RsPeerId& peer_id,const CompressedChunkMap& compressed_map) { RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/ @@ -646,7 +646,7 @@ void ftFileCreator::forceCheck() chunkMap.forceCheck(); } -void ftFileCreator::getSourcesList(uint32_t chunk_num,std::vector& sources) +void ftFileCreator::getSourcesList(uint32_t chunk_num,std::vector& sources) { RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/ diff --git a/libretroshare/src/ft/ftfilecreator.h b/libretroshare/src/ft/ftfilecreator.h index c5612e2b9..5ffb4d88b 100644 --- a/libretroshare/src/ft/ftfilecreator.h +++ b/libretroshare/src/ft/ftfilecreator.h @@ -52,7 +52,7 @@ class ftFileCreator: public ftFileProvider ~ftFileCreator(); /* overloaded from FileProvider */ - virtual bool getFileData(const std::string& peer_id,uint64_t offset, uint32_t &chunk_size, void *data); + virtual bool getFileData(const SSLIdType& peer_id,uint64_t offset, uint32_t &chunk_size, void *data); bool finished() ; 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. // - 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 // and let inactive chunks not finished. @@ -99,11 +99,11 @@ class ftFileCreator: public ftFileProvider void removeInactiveChunks() ; // removes the designated file source from the chunkmap. - void removeFileSource(const std::string& peer_id) ; + void removeFileSource(const SSLIdType& peer_id) ; // Get all available sources for this chunk // - void getSourcesList(uint32_t chunk_number,std::vector& sources) ; + void getSourcesList(uint32_t chunk_number,std::vector& sources) ; // Returns resets the time stamp of the last data receive. time_t lastRecvTimeStamp() ; @@ -124,11 +124,11 @@ class ftFileCreator: public ftFileProvider // This is called when receiving the availability map from a source peer, for the file being handled. // - void setSourceMap(const std::string& peer_id,const CompressedChunkMap& map) ; + void setSourceMap(const SSLIdType& peer_id,const CompressedChunkMap& map) ; // Returns true id the given file source is complete. // - bool sourceIsComplete(const std::string& peer_id) ; + bool sourceIsComplete(const SSLIdType& peer_id) ; protected: @@ -146,7 +146,7 @@ class ftFileCreator: public ftFileProvider uint64_t mEnd; std::map mChunks; - std::map mChunksPerPeer ; + std::map mChunksPerPeer ; ChunkMap chunkMap ; diff --git a/libretroshare/src/ft/ftfileprovider.cc b/libretroshare/src/ft/ftfileprovider.cc index c396abb9d..e8de630bf 100644 --- a/libretroshare/src/ft/ftfileprovider.cc +++ b/libretroshare/src/ft/ftfileprovider.cc @@ -80,7 +80,7 @@ bool ftFileProvider::FileDetails(FileInfo &info) info.peers.clear() ; float total_transfer_rate = 0.0f ; - for(std::map::const_iterator it(uploading_peers.begin());it!=uploading_peers.end();++it) + for(std::map::const_iterator it(uploading_peers.begin());it!=uploading_peers.end();++it) { TransferInfo inf ; inf.peerId = it->first ; @@ -109,13 +109,13 @@ bool ftFileProvider::purgeOldPeers(time_t now,uint32_t max_duration) std::cerr << "ftFileProvider::purgeOldPeers(): " << (void*)this << ": examining peers." << std::endl ; #endif bool ret = true ; - for(std::map::iterator it(uploading_peers.begin());it!=uploading_peers.end();) + for(std::map::iterator it(uploading_peers.begin());it!=uploading_peers.end();) if( (*it).second.lastTS+max_duration < (uint32_t)now) { #ifdef DEBUG_FT_FILE_PROVIDER std::cerr << "ftFileProvider::purgeOldPeers(): " << (void*)this << ": peer " << it->first << " is too old. Removing." << std::endl ; #endif - std::map::iterator tmp = it ; + std::map::iterator tmp = it ; ++tmp ; uploading_peers.erase(it) ; it=tmp ; @@ -139,7 +139,7 @@ void ftFileProvider::getAvailabilityMap(CompressedChunkMap& cmap) } -bool ftFileProvider::getFileData(const std::string& peer_id,uint64_t offset, uint32_t &chunk_size, void *data) +bool ftFileProvider::getFileData(const SSLIdType& peer_id,uint64_t offset, uint32_t &chunk_size, void *data) { /* dodgey checking outside of mutex... * much check again inside FileAttrs(). @@ -250,7 +250,7 @@ void ftFileProvider::PeerUploadInfo::updateStatus(uint64_t offset,uint32_t data_ total_size += req_size ; } -void ftFileProvider::setClientMap(const std::string& peer_id,const CompressedChunkMap& cmap) +void ftFileProvider::setClientMap(const SSLIdType& peer_id,const CompressedChunkMap& cmap) { RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/ @@ -259,7 +259,7 @@ void ftFileProvider::setClientMap(const std::string& peer_id,const CompressedChu uploading_peers[peer_id].client_chunk_map_stamp = time(NULL) ; } -void ftFileProvider::getClientMap(const std::string& peer_id,CompressedChunkMap& cmap,bool& map_is_too_old) +void ftFileProvider::getClientMap(const SSLIdType& peer_id,CompressedChunkMap& cmap,bool& map_is_too_old) { RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/ diff --git a/libretroshare/src/ft/ftfileprovider.h b/libretroshare/src/ft/ftfileprovider.h index 07789b870..d086f107c 100644 --- a/libretroshare/src/ft/ftfileprovider.h +++ b/libretroshare/src/ft/ftfileprovider.h @@ -41,7 +41,7 @@ class ftFileProvider ftFileProvider(const std::string& path, uint64_t size, const std::string& hash); 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); std::string getHash(); uint64_t getFileSize(); @@ -54,8 +54,8 @@ class ftFileProvider virtual void getAvailabilityMap(CompressedChunkMap& cmap) ; // a ftFileProvider feeds a distant peer. To display what the peers already has, we need to store/read this info. - void getClientMap(const std::string& peer_id,CompressedChunkMap& cmap,bool& map_is_too_old) ; - void setClientMap(const std::string& peer_id,const CompressedChunkMap& cmap) ; + void getClientMap(const RsPeerId& peer_id,CompressedChunkMap& cmap,bool& map_is_too_old) ; + void setClientMap(const RsPeerId& peer_id,const CompressedChunkMap& cmap) ; // Removes inactive peers from the client list. Returns true if all peers have been removed. // @@ -100,7 +100,7 @@ class ftFileProvider // Contains statistics (speed, peer name, etc.) of all uploading peers for that file. // - std::map uploading_peers ; + std::map uploading_peers ; /* * Mutex Required for stuff below diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index 134254a15..a1e8286d2 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -102,12 +102,14 @@ void ftServer::addConfigComponents(p3ConfigMgr */*mgr*/) /* NOT SURE ABOUT THIS ONE */ } -std::string ftServer::OwnId() +const RsPeerId& ftServer::OwnId() { - std::string ownId; + static RsPeerId null_id ; + if (mLinkMgr) - ownId = mLinkMgr->getOwnId(); - return ownId; + return mLinkMgr->getOwnId(); + else + return null_id ; } /* Final Setup (once everything is assigned) */ @@ -117,7 +119,7 @@ void ftServer::SetupFtServer() /* setup FiStore/Monitor */ std::string localcachedir = mConfigPath + "/cache/local"; std::string remotecachedir = mConfigPath + "/cache/remote"; - std::string ownId = mLinkMgr->getOwnId(); + RsPeerId ownId = mLinkMgr->getOwnId(); /* search/extras List */ mFtExtra = new ftExtraList(); @@ -264,7 +266,7 @@ bool ftServer::alreadyHaveFile(const std::string& hash, FileInfo &info) return mFtController->alreadyHaveFile(hash, info); } -bool ftServer::FileRequest(const std::string& fname, const std::string& hash, uint64_t size, const std::string& dest, TransferRequestFlags flags, const std::list& srcIds) +bool ftServer::FileRequest(const std::string& fname, const std::string& hash, uint64_t size, const std::string& dest, TransferRequestFlags flags, const std::list& srcIds) { std::string error_string ; @@ -407,7 +409,7 @@ bool ftServer::FileDownloads(std::list &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); } @@ -481,7 +483,7 @@ void ftServer::removeVirtualPeer(const TurtleFileHash& hash,const TurtleVirtualP mFtController->removeFileSource(hash,virtual_peer_id) ; } -bool ftServer::handleTunnelRequest(const std::string& hash,const std::string& peer_id) +bool ftServer::handleTunnelRequest(const std::string& hash,const RsPeerId& peer_id) { FileInfo info ; bool res = FileDetails(hash, RS_FILE_HINTS_NETWORK_WIDE | RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_SPEC_ONLY | RS_FILE_HINTS_DOWNLOAD, info); @@ -545,7 +547,7 @@ bool ftServer::ExtraFileMove(std::string fname, std::string hash, uint64_t size, /******************** Directory Listing ************************/ /***************************************************************/ -int ftServer::RequestDirDetails(const std::string& uid, const std::string& path, DirDetails &details) +int ftServer::RequestDirDetails(const RsPeerId& uid, const std::string& path, DirDetails &details) { #ifdef SERVER_DEBUG std::cerr << "ftServer::RequestDirDetails(uid:" << uid; @@ -610,12 +612,12 @@ uint32_t ftServer::getType(void *ref, FileSearchFlags flags) int ftServer::SearchKeywords(std::list keywords, std::list &results,FileSearchFlags flags) { if(flags & RS_FILE_HINTS_LOCAL) - return mFiMon->SearchKeywords(keywords, results,flags,""); + return mFiMon->SearchKeywords(keywords, results,flags,RsPeerId()); else return mFiStore->SearchKeywords(keywords, results,flags); return 0 ; } -int ftServer::SearchKeywords(std::list keywords, std::list &results,FileSearchFlags flags,const std::string& peer_id) +int ftServer::SearchKeywords(std::list keywords, std::list &results,FileSearchFlags flags,const RsPeerId& peer_id) { #ifdef SERVER_DEBUG std::cerr << "ftServer::SearchKeywords()"; @@ -637,12 +639,12 @@ int ftServer::SearchKeywords(std::list keywords, std::list &results,FileSearchFlags flags) { if(flags & RS_FILE_HINTS_LOCAL) - return mFiMon->SearchBoolExp(exp,results,flags,"") ; + return mFiMon->SearchBoolExp(exp,results,flags,RsPeerId()) ; else return mFiStore->searchBoolExp(exp, results); return 0 ; } -int ftServer::SearchBoolExp(Expression * exp, std::list &results,FileSearchFlags flags,const std::string& peer_id) +int ftServer::SearchBoolExp(Expression * exp, std::list &results,FileSearchFlags flags,const RsPeerId& peer_id) { if(flags & RS_FILE_HINTS_LOCAL) return mFiMon->SearchBoolExp(exp,results,flags,peer_id) ; @@ -870,7 +872,7 @@ bool ftServer::loadConfigMap(std::map &/*configMap*/) /***************************************************************/ /* Client Send */ -bool ftServer::sendDataRequest(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize) +bool ftServer::sendDataRequest(const RsPeerId& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize) { #ifdef SERVER_DEBUG std::cerr << "ftServer::sendDataRequest() to peer " << peerId << " for hash " << hash << ", offset=" << offset << ", chunk size="<< chunksize << std::endl; @@ -908,7 +910,7 @@ bool ftServer::sendDataRequest(const std::string& peerId, const std::string& has return true; } -bool ftServer::sendChunkMapRequest(const std::string& peerId,const std::string& hash,bool is_client) +bool ftServer::sendChunkMapRequest(const RsPeerId& peerId,const std::string& hash,bool is_client) { #ifdef SERVER_DEBUG 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 ; } -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 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 ; } -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 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 ; } -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 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 */ -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 */ /* 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, const std::string& hash, - const std::string& virtual_peer_id, + const RsPeerId& virtual_peer_id, RsTurtleGenericTunnelItem::Direction direction) { switch(i->PacketSubType()) diff --git a/libretroshare/src/ft/ftserver.h b/libretroshare/src/ft/ftserver.h index 5edddb4ca..03ec31520 100644 --- a/libretroshare/src/ft/ftserver.h +++ b/libretroshare/src/ft/ftserver.h @@ -94,7 +94,7 @@ class ftServer: public p3Service, public RsFiles, public ftDataSend, public RsTu virtual CacheStrapper *getCacheStrapper(); virtual CacheTransfer *getCacheTransfer(); - std::string OwnId(); + const RsPeerId& OwnId(); /* Final Setup (once everything is assigned) */ void SetupFtServer() ; @@ -106,8 +106,8 @@ class ftServer: public p3Service, public RsFiles, public ftDataSend, public RsTu // Implements RsTurtleClientService // - virtual bool handleTunnelRequest(const std::string& hash,const std::string& peer_id) ; - virtual void receiveTurtleData(RsTurtleGenericTunnelItem *item,const std::string& hash,const std::string& virtual_peer_id,RsTurtleGenericTunnelItem::Direction direction) ; + virtual bool handleTunnelRequest(const std::string& hash,const RsPeerId& peer_id) ; + 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 ; 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 ***/ 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& srcIds); + virtual bool FileRequest(const std::string& fname, const std::string& hash, uint64_t size, const std::string& dest, TransferRequestFlags flags, const std::list& srcIds); virtual bool FileCancel(const std::string& hash); virtual bool FileControl(const std::string& hash, uint32_t flags); virtual bool FileClearCompleted(); @@ -163,7 +163,7 @@ class ftServer: public p3Service, public RsFiles, public ftDataSend, public RsTu virtual bool FileUploads(std::list &hashs); virtual bool FileDetails(const std::string &hash, FileSearchFlags hintflags, FileInfo &info); virtual bool FileDownloadChunksDetails(const std::string& hash,FileChunksInfo& info) ; - virtual bool FileUploadChunksDetails(const std::string& hash,const std::string& peer_id,CompressedChunkMap& map) ; + virtual bool 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 ***/ - virtual int RequestDirDetails(const std::string& uid, const std::string& path, DirDetails &details); + virtual int RequestDirDetails(const RsPeerId& uid, const std::string& path, DirDetails &details); virtual int RequestDirDetails(void *ref, DirDetails &details, FileSearchFlags flags); virtual uint32_t getType(void *ref,FileSearchFlags flags) ; virtual int SearchKeywords(std::list keywords, std::list &results,FileSearchFlags flags); - virtual int SearchKeywords(std::list keywords, std::list &results,FileSearchFlags flags,const std::string& peer_id); + virtual int SearchKeywords(std::list keywords, std::list &results,FileSearchFlags flags,const RsPeerId& peer_id); virtual int SearchBoolExp(Expression * exp, std::list &results,FileSearchFlags flags); - virtual int SearchBoolExp(Expression * exp, std::list &results,FileSearchFlags flags,const std::string& peer_id); + virtual int SearchBoolExp(Expression * exp, std::list &results,FileSearchFlags flags,const RsPeerId& peer_id); /*** * Utility Functions @@ -230,12 +230,12 @@ class ftServer: public p3Service, public RsFiles, public ftDataSend, public RsTu /*************** Data Transfer Interface ***********************/ /***************************************************************/ public: - virtual bool sendData(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data); - virtual bool sendDataRequest(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize); - virtual bool sendChunkMapRequest(const std::string& peer_id,const std::string& hash,bool is_client) ; - virtual bool sendChunkMap(const std::string& peer_id,const std::string& hash,const CompressedChunkMap& cmap,bool is_client) ; - virtual bool sendSingleChunkCRCRequest(const std::string& peer_id,const std::string& hash,uint32_t chunk_number) ; - virtual bool sendSingleChunkCRC(const std::string& peer_id,const std::string& hash,uint32_t chunk_number,const Sha1CheckSum& crc) ; + virtual bool sendData(const RsPeerId& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data); + virtual bool sendDataRequest(const RsPeerId& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize); + virtual bool sendChunkMapRequest(const RsPeerId& peer_id,const std::string& hash,bool is_client) ; + virtual bool sendChunkMap(const RsPeerId& peer_id,const std::string& hash,const CompressedChunkMap& cmap,bool is_client) ; + virtual bool sendSingleChunkCRCRequest(const RsPeerId& peer_id,const std::string& hash,uint32_t chunk_number) ; + virtual bool sendSingleChunkCRC(const RsPeerId& peer_id,const std::string& hash,uint32_t chunk_number,const Sha1CheckSum& crc) ; /*************** Internal Transfer Fns *************************/ virtual int tick(); diff --git a/libretroshare/src/ft/fttransfermodule.cc b/libretroshare/src/ft/fttransfermodule.cc index f7da162d9..38ae9dd81 100644 --- a/libretroshare/src/ft/fttransfermodule.cc +++ b/libretroshare/src/ft/fttransfermodule.cc @@ -103,7 +103,7 @@ ftTransferModule::~ftTransferModule() } -bool ftTransferModule::setFileSources(const std::list& peerIds) +bool ftTransferModule::setFileSources(const std::list& peerIds) { RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/ @@ -114,7 +114,7 @@ bool ftTransferModule::setFileSources(const std::list& peerIds) std::cerr << " List of peers: " ; #endif - std::list::const_iterator it; + std::list::const_iterator it; for(it = peerIds.begin(); it != peerIds.end(); it++) { @@ -123,7 +123,7 @@ bool ftTransferModule::setFileSources(const std::list& peerIds) #endif peerInfo pInfo(*it); - mFileSources.insert(std::pair(*it,pInfo)); + mFileSources.insert(std::pair(*it,pInfo)); } #ifdef FT_DEBUG @@ -133,10 +133,10 @@ bool ftTransferModule::setFileSources(const std::list& peerIds) return true; } -bool ftTransferModule::getFileSources(std::list &peerIds) +bool ftTransferModule::getFileSources(std::list &peerIds) { RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/ - std::map::iterator it; + std::map::iterator it; for(it = mFileSources.begin(); it != mFileSources.end(); it++) { peerIds.push_back(it->first); @@ -144,17 +144,17 @@ bool ftTransferModule::getFileSources(std::list &peerIds) return true; } -bool ftTransferModule::addFileSource(const std::string& peerId) +bool ftTransferModule::addFileSource(const SSLIdType& peerId) { RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/ - std::map::iterator mit; + std::map::iterator mit; mit = mFileSources.find(peerId); if (mit == mFileSources.end()) { /* add in new source */ peerInfo pInfo(peerId); - mFileSources.insert(std::pair(peerId,pInfo)); + mFileSources.insert(std::pair(peerId,pInfo)); mit = mFileSources.find(peerId); mMultiplexor->sendChunkMapRequest(peerId, mHash,false) ; @@ -177,10 +177,10 @@ bool ftTransferModule::addFileSource(const std::string& peerId) } } -bool ftTransferModule::removeFileSource(const std::string& peerId) +bool ftTransferModule::removeFileSource(const SSLIdType& peerId) { RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/ - std::map::iterator mit; + std::map::iterator mit; mit = mFileSources.find(peerId); if (mit != mFileSources.end()) @@ -199,7 +199,7 @@ bool ftTransferModule::removeFileSource(const std::string& peerId) return true; } -bool ftTransferModule::setPeerState(const std::string& peerId,uint32_t state,uint32_t maxRate) +bool ftTransferModule::setPeerState(const SSLIdType& peerId,uint32_t state,uint32_t maxRate) { RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/ #ifdef FT_DEBUG @@ -209,7 +209,7 @@ bool ftTransferModule::setPeerState(const std::string& peerId,uint32_t state,uin std::cerr << " maxRate: " << maxRate << std::endl; #endif - std::map::iterator mit; + std::map::iterator mit; mit = mFileSources.find(peerId); if (mit == mFileSources.end()) @@ -229,7 +229,7 @@ bool ftTransferModule::setPeerState(const std::string& peerId,uint32_t state,uin // Start it off at zero.... // (mit->second).actualRate=maxRate; /* should give big kick in right direction */ - std::list::iterator it; + std::list::iterator it; it = std::find(mOnlinePeers.begin(), mOnlinePeers.end(), peerId); if (state!=PQIPEER_NOT_ONLINE) @@ -247,10 +247,10 @@ bool ftTransferModule::setPeerState(const std::string& peerId,uint32_t state,uin } -bool ftTransferModule::getPeerState(const std::string& peerId,uint32_t &state,uint32_t &tfRate) +bool ftTransferModule::getPeerState(const SSLIdType& peerId,uint32_t &state,uint32_t &tfRate) { RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/ - std::map::iterator mit; + std::map::iterator mit; mit = mFileSources.find(peerId); if (mit == mFileSources.end()) return false; @@ -267,10 +267,10 @@ bool ftTransferModule::getPeerState(const std::string& peerId,uint32_t &state,ui return true; } -uint32_t ftTransferModule::getDataRate(const std::string& peerId) +uint32_t ftTransferModule::getDataRate(const SSLIdType& peerId) { RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/ - std::map::iterator mit; + std::map::iterator mit; mit = mFileSources.find(peerId); if (mit == mFileSources.end()) { @@ -296,7 +296,7 @@ time_t ftTransferModule::lastActvTimeStamp() } //interface to client module -bool ftTransferModule::recvFileData(const std::string& peerId, uint64_t offset, uint32_t chunk_size, void *data) +bool ftTransferModule::recvFileData(const SSLIdType& peerId, uint64_t offset, uint32_t chunk_size, void *data) { RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/ #ifdef FT_DEBUG @@ -310,7 +310,7 @@ bool ftTransferModule::recvFileData(const std::string& peerId, uint64_t offset, bool ok = false; - std::map::iterator mit; + std::map::iterator mit; mit = mFileSources.find(peerId); if (mit == mFileSources.end()) @@ -332,7 +332,7 @@ bool ftTransferModule::recvFileData(const std::string& peerId, uint64_t offset, return ok; } -void ftTransferModule::locked_requestData(const std::string& peerId, uint64_t offset, uint32_t chunk_size) +void ftTransferModule::locked_requestData(const SSLIdType& peerId, uint64_t offset, uint32_t chunk_size) { #ifdef FT_DEBUG std::cerr << "ftTransferModule::requestData()"; @@ -347,7 +347,7 @@ void ftTransferModule::locked_requestData(const std::string& peerId, uint64_t of mMultiplexor->sendDataRequest(peerId, mHash, mSize, offset,chunk_size); } -bool ftTransferModule::locked_getChunk(const std::string& peer_id,uint32_t size_hint,uint64_t &offset, uint32_t &chunk_size) +bool ftTransferModule::locked_getChunk(const SSLIdType& peer_id,uint32_t size_hint,uint64_t &offset, uint32_t &chunk_size) { #ifdef FT_DEBUG std::cerr << "ftTransferModule::locked_getChunk()"; @@ -427,7 +427,7 @@ bool ftTransferModule::queryInactive() if (mFileStatus.stat == ftFileStatus::PQIFILE_CHECKING) return false ; - std::map::iterator mit; + std::map::iterator mit; for(mit = mFileSources.begin(); mit != mFileSources.end(); mit++) { locked_tickPeerTransfer(mit->second); @@ -496,7 +496,7 @@ int ftTransferModule::tick() std::cerr << std::endl; std::cerr << "Peers: "; - std::map::iterator it; + std::map::iterator it; for(it = mFileSources.begin(); it != mFileSources.end(); it++) { std::cerr << " " << it->first; @@ -645,7 +645,7 @@ void ftTransferModule::adjustSpeed() { RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/ - std::map::iterator mit; + std::map::iterator mit; actualRate = 0; diff --git a/libretroshare/src/ft/fttransfermodule.h b/libretroshare/src/ft/fttransfermodule.h index f64845526..6e95094a1 100644 --- a/libretroshare/src/ft/fttransfermodule.h +++ b/libretroshare/src/ft/fttransfermodule.h @@ -56,7 +56,7 @@ class HashThread ; class peerInfo { public: - peerInfo(std::string peerId_in):peerId(peerId_in),state(PQIPEER_NOT_ONLINE),desiredRate(0),actualRate(0), + peerInfo(const SSLIdType& peerId_in):peerId(peerId_in),state(PQIPEER_NOT_ONLINE),desiredRate(0),actualRate(0), lastTS(0), recvTS(0), lastTransfers(0), nResets(0), rtt(0), rttActive(false), rttStart(0), rttOffset(0), @@ -64,7 +64,7 @@ public: { return; } - peerInfo(std::string peerId_in,uint32_t state_in,uint32_t maxRate_in): + peerInfo(const SSLIdType& peerId_in,uint32_t state_in,uint32_t maxRate_in): peerId(peerId_in),state(state_in),desiredRate(maxRate_in),actualRate(0), lastTS(0), recvTS(0), lastTransfers(0), nResets(0), @@ -73,7 +73,7 @@ public: { return; } - std::string peerId; + SSLIdType peerId; uint32_t state; double desiredRate; double actualRate; @@ -124,13 +124,13 @@ public: ~ftTransferModule(); //interface to download controller - bool setFileSources(const std::list& peerIds); - bool addFileSource(const std::string& peerId); - bool removeFileSource(const std::string& peerId); - bool setPeerState(const std::string& peerId,uint32_t state,uint32_t maxRate); //state = ONLINE/OFFLINE - bool getFileSources(std::list &peerIds); - bool getPeerState(const std::string& peerId,uint32_t &state,uint32_t &tfRate); - uint32_t getDataRate(const std::string& peerId); + bool setFileSources(const std::list& peerIds); + bool addFileSource(const SSLIdType& peerId); + bool removeFileSource(const SSLIdType& peerId); + bool setPeerState(const SSLIdType& peerId,uint32_t state,uint32_t maxRate); //state = ONLINE/OFFLINE + bool getFileSources(std::list &peerIds); + bool getPeerState(const SSLIdType& peerId,uint32_t &state,uint32_t &tfRate); + uint32_t getDataRate(const SSLIdType& peerId); bool cancelTransfer(); bool cancelFileTransferUpward(); bool completeFileTransfer(); @@ -138,11 +138,11 @@ public: void forceCheck() ; //interface to multiplex module - bool recvFileData(const std::string& peerId, uint64_t offset, uint32_t chunk_size, void *data); - void locked_requestData(const std::string& peerId, uint64_t offset, uint32_t chunk_size); + bool recvFileData(const SSLIdType& peerId, uint64_t offset, uint32_t chunk_size, void *data); + void locked_requestData(const SSLIdType& peerId, uint64_t offset, uint32_t chunk_size); //interface to file creator - bool locked_getChunk(const std::string& peer_id,uint32_t size_hint,uint64_t &offset, uint32_t &chunk_size); + bool locked_getChunk(const 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); int tick(); @@ -180,8 +180,8 @@ private: RsMutex tfMtx; /* below is mutex protected */ - std::list mOnlinePeers; - std::map mFileSources; + std::list mOnlinePeers; + std::map mFileSources; uint16_t mFlag; //2:file canceled, 1:transfer complete, 0: not complete, 3: checking hash, 4: checking chunks double desiredRate; diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index 6185eca0e..d63fcc04f 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -113,6 +113,7 @@ PUBLIC_HEADERS = retroshare/rsdisc.h \ retroshare/rsmsgs.h \ retroshare/rsnotify.h \ retroshare/rspeers.h \ + retroshare/rsids.h \ retroshare/rsrank.h \ retroshare/rsstatus.h \ retroshare/rsturtle.h \ @@ -357,7 +358,7 @@ HEADERS += pqi/authssl.h \ pqi/pqiqos.h \ pqi/pqi.h \ pqi/pqi_base.h \ - pqi/pqiarchive.h \ +# pqi/pqiarchive.h \ pqi/pqiassist.h \ pqi/pqibin.h \ pqi/pqihandler.h \ @@ -485,7 +486,7 @@ SOURCES += pqi/authgpg.cc \ pqi/p3netmgr.cc \ pqi/p3notify.cc \ pqi/pqiqos.cc \ - pqi/pqiarchive.cc \ +# pqi/pqiarchive.cc \ pqi/pqibin.cc \ pqi/pqihandler.cc \ pqi/p3historymgr.cc \ diff --git a/libretroshare/src/pgp/pgphandler.cc b/libretroshare/src/pgp/pgphandler.cc index cf9e16ec2..9eec1bc6d 100644 --- a/libretroshare/src/pgp/pgphandler.cc +++ b/libretroshare/src/pgp/pgphandler.cc @@ -126,7 +126,7 @@ PGPHandler::PGPHandler(const std::string& pubring, const std::string& secring,co int i=0 ; while( (keydata = ops_keyring_get_key_by_index(_pubring,i)) != NULL ) { - PGPCertificateInfo& cert(_public_keyring_map[ PGPIdType(keydata->key_id).toStdString() ]) ; + PGPCertificateInfo& cert(_public_keyring_map[ PGPIdType(keydata->key_id) ]) ; // Init all certificates. @@ -152,7 +152,7 @@ PGPHandler::PGPHandler(const std::string& pubring, const std::string& secring,co i=0 ; while( (keydata = ops_keyring_get_key_by_index(_secring,i)) != NULL ) { - initCertificateInfo(_secret_keyring_map[ PGPIdType(keydata->key_id).toStdString() ],keydata,i) ; + initCertificateInfo(_secret_keyring_map[ PGPIdType(keydata->key_id) ],keydata,i) ; ++i ; } _secring_last_update_time = time(NULL) ; @@ -246,11 +246,11 @@ bool PGPHandler::validateAndUpdateSignatures(PGPCertificateInfo& cert,const ops_ if(result != NULL) for(size_t i=0;ivalid_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 ; } } @@ -282,9 +282,9 @@ bool PGPHandler::printKeys() const std::cerr << "Printing details of all " << std::dec << _public_keyring_map.size() << " keys: " << std::endl; #endif - for(std::map::const_iterator it(_public_keyring_map.begin()); it != _public_keyring_map.end(); it++) + for(std::map::const_iterator it(_public_keyring_map.begin()); it != _public_keyring_map.end(); it++) { - std::cerr << "PGP Key: " << it->first << std::endl; + std::cerr << "PGP Key: " << it->first.toStdString() << std::endl; std::cerr << "\tName : " << it->second._name << std::endl; std::cerr << "\tEmail : " << it->second._email << std::endl; @@ -296,11 +296,11 @@ bool PGPHandler::printKeys() const std::cerr << "\tfingerprint : " << it->second._fpr.toStdString() << std::endl; std::cerr << "\tSigners : " << it->second.signers.size() << std::endl; - std::set::const_iterator sit; + std::set::const_iterator sit; for(sit = it->second.signers.begin(); sit != it->second.signers.end(); sit++) { - std::cerr << "\t\tSigner ID:" << *sit << ", Name: " ; - const PGPCertificateInfo *info = PGPHandler::getCertificateInfo(PGPIdType(*sit)) ; + std::cerr << "\t\tSigner ID:" << (*sit).toStdString() << ", Name: " ; + const PGPCertificateInfo *info = PGPHandler::getCertificateInfo(*sit) ; if(info != NULL) std::cerr << info->_name ; @@ -325,7 +325,7 @@ const PGPCertificateInfo *PGPHandler::getCertificateInfo(const PGPIdType& id) co { RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP memory structures. - std::map::const_iterator it( _public_keyring_map.find(id.toStdString()) ) ; + std::map::const_iterator it( _public_keyring_map.find(id) ) ; if(it != _public_keyring_map.end()) 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) ; addNewKeyToOPSKeyring(_secring,tmp_secring->keys[0]) ; - initCertificateInfo(_secret_keyring_map[ pgpId.toStdString() ],&tmp_secring->keys[0],_secring->nkeys-1) ; + initCertificateInfo(_secret_keyring_map[ pgpId ],&tmp_secring->keys[0],_secring->nkeys-1) ; #ifdef DEBUG_PGPHANDLER std::cerr << "Added new secret key with id " << pgpId.toStdString() << " to secret keyring." << std::endl; @@ -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 { - std::map::const_iterator res = _secret_keyring_map.find(id.toStdString()) ; + std::map::const_iterator res = _secret_keyring_map.find(id) ; if(res == _secret_keyring_map.end()) 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 { - std::map::const_iterator res = _public_keyring_map.find(id.toStdString()) ; + std::map::const_iterator res = _public_keyring_map.find(id) ; if(res == _public_keyring_map.end()) return NULL ; @@ -667,7 +667,7 @@ bool PGPHandler::exportGPGKeyPair(const std::string& filename,const PGPIdType& e return true ; } -bool PGPHandler::getGPGDetailsFromBinaryBlock(const unsigned char *mem_block,size_t mem_size,std::string& key_id, std::string& name, std::list& signers) const +bool PGPHandler::getGPGDetailsFromBinaryBlock(const unsigned char *mem_block,size_t mem_size,PGPIdType& key_id, std::string& name, std::list& signers) const { ops_keyring_t *tmp_keyring = allocateOPSKeyring(); ops_memory_t *mem = ops_memory_new() ; @@ -699,7 +699,7 @@ bool PGPHandler::getGPGDetailsFromBinaryBlock(const unsigned char *mem_block,siz 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) ; // now parse signatures. @@ -725,14 +725,11 @@ bool PGPHandler::getGPGDetailsFromBinaryBlock(const unsigned char *mem_block,siz // Parse signers. // - std::set signers_set ; // Use a set to remove duplicates. + std::set signers_set ; // Use a set to remove duplicates. if(result != NULL) for(size_t i=0;ivalid_count;++i) - { - std::string signer_str = PGPIdType(result->valid_sigs[i].signer_id).toStdString() ; - signers_set.insert(signer_str) ; - } + signers_set.insert(PGPIdType(result->valid_sigs[i].signer_id)) ; ops_validate_result_free(result) ; @@ -743,7 +740,7 @@ bool PGPHandler::getGPGDetailsFromBinaryBlock(const unsigned char *mem_block,siz signers.clear() ; - for(std::set::const_iterator it(signers_set.begin());it!=signers_set.end();++it) + for(std::set::const_iterator it(signers_set.begin());it!=signers_set.end();++it) signers.push_back(*it) ; return true ; @@ -900,7 +897,7 @@ bool PGPHandler::importGPGKeyPair(const std::string& filename,PGPIdType& importe } addNewKeyToOPSKeyring(_secring,*seckey) ; - initCertificateInfo(_secret_keyring_map[ imported_key_id.toStdString() ],seckey,_secring->nkeys-1) ; + initCertificateInfo(_secret_keyring_map[ imported_key_id ],seckey,_secring->nkeys-1) ; } else import_error = "Private key already exists! Not importing it again." ; @@ -1037,7 +1034,7 @@ bool PGPHandler::LoadCertificateFromString(const std::string& pgp_cert,PGPIdType return true ; } -bool PGPHandler::locked_addOrMergeKey(ops_keyring_t *keyring,std::map& kmap,const ops_keydata_t *keydata) +bool PGPHandler::locked_addOrMergeKey(ops_keyring_t *keyring,std::map& kmap,const ops_keydata_t *keydata) { bool ret = false ; PGPIdType id(keydata->key_id) ; @@ -1049,7 +1046,7 @@ bool PGPHandler::locked_addOrMergeKey(ops_keyring_t *keyring,std::map::const_iterator res = kmap.find(id.toStdString()) ; + std::map::const_iterator res = kmap.find(id) ; // Checks that // - the key is referenced by keyid @@ -1062,7 +1059,7 @@ bool PGPHandler::locked_addOrMergeKey(ops_keyring_t *keyring,std::mapnkeys-1) ; + initCertificateInfo(kmap[id],keydata,keyring->nkeys-1) ; existing_key = &(keyring->keys[keyring->nkeys-1]) ; ret = true ; } @@ -1080,13 +1077,13 @@ bool PGPHandler::locked_addOrMergeKey(ops_keyring_t *keyring,std::map(existing_key),keydata) ; if(ret) - initCertificateInfo(kmap[id.toStdString()],existing_key,res->second._key_index) ; + initCertificateInfo(kmap[id],existing_key,res->second._key_index) ; } if(ret) { - validateAndUpdateSignatures(kmap[id.toStdString()],existing_key) ; - kmap[id.toStdString()]._time_stamp = time(NULL) ; + validateAndUpdateSignatures(kmap[id],existing_key) ; + kmap[id]._time_stamp = time(NULL) ; } return ret ; @@ -1413,7 +1410,7 @@ bool PGPHandler::privateSignCertificate(const PGPIdType& ownId,const PGPIdType& // 4 - update signatures. // - PGPCertificateInfo& cert(_public_keyring_map[ id_of_key_to_sign.toStdString() ]) ; + PGPCertificateInfo& cert(_public_keyring_map[ id_of_key_to_sign ]) ; validateAndUpdateSignatures(cert,key_to_sign) ; cert._flags |= PGPCertificateInfo::PGP_CERTIFICATE_FLAG_HAS_OWN_SIGNATURE ; @@ -1424,25 +1421,23 @@ void PGPHandler::updateOwnSignatureFlag(const PGPIdType& own_id) { RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP memory structures. - std::string own_id_str = own_id.toStdString(); - - if(_public_keyring_map.find(own_id_str)==_public_keyring_map.end()) + if(_public_keyring_map.find(own_id)==_public_keyring_map.end()) { - std::cerr << __func__ << ": key with id=" << own_id_str << " not in keyring." << std::endl; + std::cerr << __func__ << ": key with id=" << own_id.toStdString() << " not in keyring." << std::endl; // return now, because the following operation would add an entry to _public_keyring_map return; } - PGPCertificateInfo& own_cert(_public_keyring_map[ own_id_str ]) ; + PGPCertificateInfo& own_cert(_public_keyring_map[ own_id ]) ; - for(std::map::iterator it=_public_keyring_map.begin();it!=_public_keyring_map.end();++it) - locked_updateOwnSignatureFlag(it->second,it->first,own_cert,own_id_str) ; + for(std::map::iterator it=_public_keyring_map.begin();it!=_public_keyring_map.end();++it) + locked_updateOwnSignatureFlag(it->second,it->first,own_cert,own_id) ; } void PGPHandler::updateOwnSignatureFlag(const PGPIdType& cert_id,const PGPIdType& own_id) { RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP memory structures. - std::map::iterator it( _public_keyring_map.find(cert_id.toStdString()) ) ; + std::map::iterator it( _public_keyring_map.find(cert_id) ) ; if(it == _public_keyring_map.end()) { @@ -1452,19 +1447,18 @@ void PGPHandler::updateOwnSignatureFlag(const PGPIdType& cert_id,const PGPIdType PGPCertificateInfo& cert( it->second ); - std::string own_id_str = own_id.toStdString(); - PGPCertificateInfo& own_cert(_public_keyring_map[ own_id_str ]) ; + PGPCertificateInfo& own_cert(_public_keyring_map[ own_id ]) ; - locked_updateOwnSignatureFlag(cert,cert_id.toStdString(),own_cert,own_id_str) ; + locked_updateOwnSignatureFlag(cert,cert_id,own_cert,own_id) ; } -void PGPHandler::locked_updateOwnSignatureFlag(PGPCertificateInfo& cert,const std::string& cert_id_str,PGPCertificateInfo& own_cert,const std::string& own_id_str) +void PGPHandler::locked_updateOwnSignatureFlag(PGPCertificateInfo& cert,const PGPIdType& cert_id,PGPCertificateInfo& own_cert,const PGPIdType& own_id_str) { if(cert.signers.find(own_id_str) != cert.signers.end()) cert._flags |= PGPCertificateInfo::PGP_CERTIFICATE_FLAG_HAS_OWN_SIGNATURE ; else cert._flags &= ~PGPCertificateInfo::PGP_CERTIFICATE_FLAG_HAS_OWN_SIGNATURE ; - if(own_cert.signers.find( cert_id_str ) != own_cert.signers.end()) + if(own_cert.signers.find( cert_id ) != own_cert.signers.end()) cert._flags |= PGPCertificateInfo::PGP_CERTIFICATE_FLAG_HAS_SIGNED_ME ; else cert._flags &= ~PGPCertificateInfo::PGP_CERTIFICATE_FLAG_HAS_SIGNED_ME ; @@ -1528,7 +1522,7 @@ void PGPHandler::setAcceptConnexion(const PGPIdType& id,bool b) { RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP memory structures. - std::map::iterator res = _public_keyring_map.find(id.toStdString()) ; + std::map::iterator res = _public_keyring_map.find(id) ; if(res != _public_keyring_map.end()) { @@ -1544,27 +1538,27 @@ bool PGPHandler::getGPGFilteredList(std::list& list,bool (*filter)(co RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP directory. list.clear() ; - for(std::map::const_iterator it(_public_keyring_map.begin());it!=_public_keyring_map.end();++it) + for(std::map::const_iterator it(_public_keyring_map.begin());it!=_public_keyring_map.end();++it) if( filter == NULL || (*filter)(it->second) ) list.push_back(PGPIdType(it->first)) ; return true ; } -bool PGPHandler::isGPGId(const std::string &id) -{ - return _public_keyring_map.find(id) != _public_keyring_map.end() ; -} +//bool PGPHandler::isGPGId(const std::string &id) +//{ +// 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::const_iterator res = _public_keyring_map.find(id) ; + std::map::const_iterator res = _public_keyring_map.find(id) ; return res != _public_keyring_map.end() && (res->second._flags & PGPCertificateInfo::PGP_CERTIFICATE_FLAG_HAS_OWN_SIGNATURE) ; } -bool PGPHandler::isGPGAccepted(const std::string &id) +bool PGPHandler::isGPGAccepted(const PGPIdType &id) { - std::map::const_iterator res = _public_keyring_map.find(id) ; + std::map::const_iterator res = _public_keyring_map.find(id) ; 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 ; } - std::map::iterator it = _public_keyring_map.find(id.toStdString()); + std::map::iterator it = _public_keyring_map.find(id); 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 ; return ; } - std::map::iterator it ; + std::map::iterator it ; PrivateTrustPacket trustpacket; int n_packets = 0 ; while(fread((void*)&trustpacket,sizeof(PrivateTrustPacket),1,fdb) == 1) { - it = _public_keyring_map.find(PGPIdType(trustpacket.user_id).toStdString()) ; + it = _public_keyring_map.find(PGPIdType(trustpacket.user_id)) ; if(it == _public_keyring_map.end()) { @@ -1715,7 +1709,7 @@ bool PGPHandler::locked_writePrivateTrustDatabase() } PrivateTrustPacket trustpacket ; - for(std::map::iterator it = _public_keyring_map.begin();it!=_public_keyring_map.end() ;++it) + for(std::map::iterator it = _public_keyring_map.begin();it!=_public_keyring_map.end() ;++it) { memcpy(trustpacket.user_id,PGPIdType(it->first).toByteArray(),PGP_KEY_ID_SIZE) ; trustpacket.trust_level = it->second._trustLvl ; @@ -1843,7 +1837,7 @@ bool PGPHandler::locked_syncTrustDatabase() return true ; } void PGPHandler::locked_mergeKeyringFromDisk( ops_keyring_t *keyring, - std::map& kmap, + std::map& kmap, const std::string& keyring_file) { #ifdef DEBUG_PGPHANDLER @@ -1922,7 +1916,7 @@ bool PGPHandler::removeKeysFromPGPKeyring(const std::list& keys_to_re continue ; } - std::map::iterator res = _public_keyring_map.find((*it).toStdString()) ; + std::map::iterator res = _public_keyring_map.find(*it) ; if(res == _public_keyring_map.end()) { @@ -1952,7 +1946,7 @@ bool PGPHandler::removeKeysFromPGPKeyring(const std::list& keys_to_re const ops_keydata_t *keydata ; while( (keydata = ops_keyring_get_key_by_index(_pubring,i)) != NULL ) { - PGPCertificateInfo& cert(_public_keyring_map[ PGPIdType(keydata->key_id).toStdString() ]) ; + PGPCertificateInfo& cert(_public_keyring_map[ PGPIdType(keydata->key_id) ]) ; cert._key_index = i ; ++i ; } diff --git a/libretroshare/src/pgp/pgphandler.h b/libretroshare/src/pgp/pgphandler.h index c76417f17..58c63a0ac 100644 --- a/libretroshare/src/pgp/pgphandler.h +++ b/libretroshare/src/pgp/pgphandler.h @@ -8,7 +8,7 @@ #include #include #include -#include +#include extern "C" { #include @@ -27,7 +27,7 @@ class PGPCertificateInfo std::string _email; std::string _comment; - std::set signers; + std::set signers; uint32_t _trustLvl; uint32_t _validLvl; @@ -104,7 +104,7 @@ class PGPHandler void updateOwnSignatureFlag(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 // and given pack for proper display. @@ -123,15 +123,15 @@ class PGPHandler const PGPCertificateInfo *getCertificateInfo(const PGPIdType& id) const ; bool isGPGId(const std::string &id); - bool isGPGSigned(const std::string &id); - bool isGPGAccepted(const std::string &id); + bool isGPGSigned(const PGPIdType &id); + bool isGPGAccepted(const PGPIdType &id); static void setPassphraseCallback(PassphraseCallback cb) ; static PassphraseCallback passphraseCallback() { return _passphrase_callback ; } // Gets info about the key. Who are the signers, what's the owner's name, etc. // - bool getGPGDetailsFromBinaryBlock(const unsigned char *mem,size_t mem_size,std::string& key_id, std::string& name, std::list& signers) const ; + bool getGPGDetailsFromBinaryBlock(const unsigned char *mem,size_t mem_size,PGPIdType& key_id, std::string& name, std::list& signers) const ; // Debug stuff. virtual bool printKeys() const ; @@ -161,8 +161,8 @@ class PGPHandler bool locked_syncPublicKeyring() ; bool locked_syncTrustDatabase() ; - void locked_mergeKeyringFromDisk(ops_keyring_t *keyring, std::map& kmap, const std::string& keyring_file) ; - bool locked_addOrMergeKey(ops_keyring_t *keyring,std::map& kmap,const ops_keydata_t *keydata) ; + void locked_mergeKeyringFromDisk(ops_keyring_t *keyring, std::map& kmap, const std::string& keyring_file) ; + bool locked_addOrMergeKey(ops_keyring_t *keyring,std::map& kmap,const ops_keydata_t *keydata) ; // Members. // @@ -171,8 +171,8 @@ class PGPHandler ops_keyring_t *_pubring ; ops_keyring_t *_secring ; - std::map _public_keyring_map ; // used for fast access to keys. Gives the index in the keyring. - std::map _secret_keyring_map ; + std::map _public_keyring_map ; // used for fast access to keys. Gives the index in the keyring. + std::map _secret_keyring_map ; const std::string _pubring_path ; const std::string _secring_path ; diff --git a/libretroshare/src/pgp/rscertificate.h b/libretroshare/src/pgp/rscertificate.h index 22c77a240..1ab40f3e4 100644 --- a/libretroshare/src/pgp/rscertificate.h +++ b/libretroshare/src/pgp/rscertificate.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include class RsPeerDetails ; diff --git a/libretroshare/src/pqi/authgpg.cc b/libretroshare/src/pqi/authgpg.cc index e1594d391..b3dbbf893 100644 --- a/libretroshare/src/pqi/authgpg.cc +++ b/libretroshare/src/pqi/authgpg.cc @@ -159,9 +159,9 @@ bool AuthGPG::availableGPGCertificatesWithPrivateKeys(std::list &id * This function must be called successfully (return == 1) * before anything else can be done. (except above fn). */ -int AuthGPG::GPGInit(const std::string &ownId) +int AuthGPG::GPGInit(const 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); @@ -312,21 +312,9 @@ bool AuthGPG::DoOwnSignature(const void *data, unsigned int datalen, void *buf_s /* import to GnuPG and other Certificates */ -bool AuthGPG::VerifySignature(const void *data, int datalen, const void *sig, unsigned int siglen, const std::string &withfingerprint) +bool AuthGPG::VerifySignature(const void *data, int datalen, const void *sig, unsigned int siglen, const PGPFingerprintType& withfingerprint) { - if(withfingerprint.length() != 40) - { - static bool already_reported = false ; - - if( !already_reported) - { - std::cerr << "AuthGPG::VerifySignature(): no (or dammaged) fingerprint. Nor verifying signature. This is likely to be an unknown peer. fingerprint=\"" << withfingerprint << "\". Not reporting other errors." << std::endl; - already_reported = true ; - } - return false ; - } - - return PGPHandler::VerifySignBin((unsigned char*)data,datalen,(unsigned char*)sig,siglen,PGPFingerprintType(withfingerprint)) ; + return PGPHandler::VerifySignBin((unsigned char*)data,datalen,(unsigned char*)sig,siglen,withfingerprint) ; } bool AuthGPG::exportProfile(const std::string& fname,const std::string& exported_id) @@ -417,10 +405,10 @@ std::string AuthGPG::getGPGEmail(const std::string &id,bool *success) /**** GPG versions ***/ -std::string AuthGPG::getGPGOwnId() +PGPIdType AuthGPG::getGPGOwnId() { RsStackMutex stack(gpgMtxData); /******* LOCKED ******/ - return mOwnGpgId.toStdString(); + return mOwnGpgId ; } 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) ; } -bool AuthGPG::getGPGDetails(const std::string& id, RsPeerDetails &d) +bool AuthGPG::getGPGDetails(const PGPIdType& pgp_id, RsPeerDetails &d) { RsStackMutex stack(gpgMtxData); /******* LOCKED ******/ - if(id.length() != 16) - { - static int already = 0 ; - - if(already < 10) - { - std::cerr << "Wrong string passed to getGPGDetails: \"" << id << "\"" << std::endl; - ++already ; - } - return false ; - } - - const PGPCertificateInfo *pc = getCertInfoFromStdString(id) ; + const PGPCertificateInfo *pc = PGPHandler::getCertificateInfo(pgp_id) ; if(pc == NULL) return false ; const PGPCertificateInfo& cert(*pc) ; - d.id = id ; - d.gpg_id = id ; + d.id.clear() ; + d.gpg_id = pgp_id ; d.name = cert._name; d.lastUsed = cert._time_stamp; d.email = cert._email; @@ -499,12 +475,12 @@ bool AuthGPG::getGPGDetails(const std::string& id, RsPeerDetails &d) d.ownsign = cert._flags & PGPCertificateInfo::PGP_CERTIFICATE_FLAG_HAS_OWN_SIGNATURE; d.gpgSigners.clear() ; - for(std::set::const_iterator it(cert.signers.begin());it!=cert.signers.end();++it) + for(std::set::const_iterator it(cert.signers.begin());it!=cert.signers.end();++it) d.gpgSigners.push_back( *it ) ; - d.fpr = cert._fpr.toStdString(); - d.accept_connection = cert._flags & PGPCertificateInfo::PGP_CERTIFICATE_FLAG_ACCEPT_CONNEXION; - d.hasSignedMe = cert._flags & PGPCertificateInfo::PGP_CERTIFICATE_FLAG_HAS_SIGNED_ME; + d.fpr = cert._fpr ; + d.accept_connection = cert._flags & PGPCertificateInfo::PGP_CERTIFICATE_FLAG_ACCEPT_CONNEXION; + d.hasSignedMe = cert._flags & PGPCertificateInfo::PGP_CERTIFICATE_FLAG_HAS_SIGNED_ME; return true; } @@ -661,7 +637,7 @@ bool AuthGPG::RevokeCertificate(const std::string &id) return false; } -bool AuthGPG::TrustCertificate(const std::string &id, int trustlvl) +bool AuthGPG::TrustCertificate(const PGPIdType& id, int trustlvl) { #ifdef GPG_DEBUG 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); } -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); } @@ -707,7 +683,7 @@ int AuthGPG::privateRevokeCertificate(const std::string &/*id*/) return 0; } -int AuthGPG::privateTrustCertificate(const std::string &id, int trustlvl) +int AuthGPG::privateTrustCertificate(const PGPIdType& id, int trustlvl) { RsStackMutex stack(gpgMtxData); /******* LOCKED ******/ diff --git a/libretroshare/src/pqi/authgpg.h b/libretroshare/src/pqi/authgpg.h index 0dee278f5..69882ef41 100644 --- a/libretroshare/src/pqi/authgpg.h +++ b/libretroshare/src/pqi/authgpg.h @@ -68,7 +68,7 @@ public: class AuthGPGOperationLoadOrSave : public AuthGPGOperation { public: - AuthGPGOperationLoadOrSave(bool load, const std::string &gpgId, const std::string &gpgCert, void *userdata) + AuthGPGOperationLoadOrSave(bool load, const PGPIdType &gpgId, const PGPIdType &gpgCert, void *userdata) : AuthGPGOperation(userdata) { m_load = load; @@ -82,8 +82,8 @@ public: public: bool m_load; - std::string m_certGpgId; // set for save & load. - std::string m_certGpg; // set for load + PGPIdType m_certGpgId; // set for save & load. + PGPIdType m_certGpg; // set for load }; class AuthGPGService @@ -111,7 +111,7 @@ class AuthGPG: public p3Config, public RsThread, public PGPHandler /** * @param ids list of gpg certificate ids (note, not the actual certificates) */ - virtual bool availableGPGCertificatesWithPrivateKeys(std::list &ids); + virtual bool availableGPGCertificatesWithPrivateKeys(std::list &ids); /*********************************************************************************/ /************************* STAGE 1 ***********************************************/ @@ -134,8 +134,8 @@ class AuthGPG: public p3Config, public RsThread, public PGPHandler /* Init by generating new Own PGP Cert, or selecting existing PGP Cert */ - virtual int GPGInit(const std::string &ownId); - virtual bool GeneratePGPCertificate(const std::string& name, const std::string& email, const std::string& passwd, std::string &pgpId, std::string &errString); + virtual int GPGInit(const PGPIdType &ownId); + virtual bool GeneratePGPCertificate(const std::string& name, const std::string& email, const std::string& passwd, PGPIdType &pgpId, std::string &errString); /*********************************************************************************/ /************************* STAGE 3 ***********************************************/ @@ -148,25 +148,25 @@ class AuthGPG: public p3Config, public RsThread, public PGPHandler * provide access to details in cache list. * ****/ - virtual std::string getGPGName(const std::string &pgp_id,bool *success = NULL); - virtual std::string getGPGEmail(const std::string &pgp_id,bool *success = NULL); + virtual std::string getGPGName(const PGPIdType &pgp_id,bool *success = NULL); + virtual std::string getGPGEmail(const PGPIdType &pgp_id,bool *success = NULL); /* PGP web of trust management */ - virtual std::string getGPGOwnId(); + virtual PGPIdType getGPGOwnId(); virtual std::string getGPGOwnName(); //virtual std::string getGPGOwnEmail(); - virtual bool isKeySupported(const std::string &id) const ; - virtual bool haveSecretKey(const std::string &id) const ; - virtual bool getGPGDetails(const std::string &id, RsPeerDetails &d); - virtual bool getGPGAllList(std::list &ids); - virtual bool getGPGValidList(std::list &ids); - virtual bool getGPGAcceptedList(std::list &ids); - virtual bool getGPGSignedList(std::list &ids); - virtual bool importProfile(const std::string& filename,std::string& gpg_id,std::string& import_error) ; - virtual bool exportProfile(const std::string& filename,const std::string& gpg_id) ; + virtual bool isKeySupported(const PGPIdType &id) const ; + virtual bool haveSecretKey(const PGPIdType &id) const ; + virtual bool getGPGDetails(const PGPIdType& id, RsPeerDetails &d); + virtual bool getGPGAllList(std::list &ids); + virtual bool getGPGValidList(std::list &ids); + virtual bool getGPGAcceptedList(std::list &ids); + virtual bool getGPGSignedList(std::list &ids); + virtual bool importProfile(const std::string& filename,PGPIdType& gpg_id,std::string& import_error) ; + virtual bool exportProfile(const std::string& filename,const PGPIdType& gpg_id) ; - virtual bool removeKeysFromPGPKeyring(const std::list& pgp_ids,std::string& backup_file,uint32_t& error_code) ; + virtual bool removeKeysFromPGPKeyring(const std::list& pgp_ids,std::string& backup_file,uint32_t& error_code) ; /*********************************************************************************/ /************************* 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 std::string SaveCertificateToString(const std::string &id,bool include_signatures) ; + virtual std::string SaveCertificateToString(const RsPeerId &id,bool include_signatures) ; // Cached certificates. 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. * ****/ - 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 RevokeCertificate(const std::string &id); /* Particularly hard - leave for later */ + virtual bool SignCertificateLevel0(const PGPIdType &id); + 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 ***********************************************/ @@ -208,9 +208,9 @@ class AuthGPG: public p3Config, public RsThread, public PGPHandler * ****/ virtual bool SignDataBin(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen); - virtual bool VerifySignBin(const void*, uint32_t, unsigned char*, unsigned int, const std::string &withfingerprint); + virtual bool VerifySignBin(const void*, uint32_t, unsigned char*, unsigned int, const PGPFingerprintType& withfingerprint); - virtual bool encryptDataBin(const std::string& pgp_id,const void *data, const uint32_t len, unsigned char *encr, unsigned int *encrlen); + virtual bool encryptDataBin(const 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 decryptTextFromFile( std::string& text,const std::string& filename); @@ -219,7 +219,7 @@ class AuthGPG: public p3Config, public RsThread, public PGPHandler // virtual bool decryptTextFromString( std::string& encrypted_text,std::string& clear_string); // virtual bool encryptTextToString (const std::string& pgp_id,const std::string& clear_text,std::string& encrypted_string); - bool getGPGFilteredList(std::list& list,bool (*filter)(const PGPCertificateInfo&) = NULL) ; + bool getGPGFilteredList(std::list& list,bool (*filter)(const PGPCertificateInfo&) = NULL) ; //END of PGP public functions @@ -253,12 +253,12 @@ class AuthGPG: public p3Config, public RsThread, public PGPHandler /* Internal functions */ bool DoOwnSignature(const void *, unsigned int, void *, unsigned int *); - bool VerifySignature(const void *data, int datalen, const void *sig, unsigned int siglen, const std::string &withfingerprint); + bool VerifySignature(const void *data, int datalen, const void *sig, unsigned int siglen, const PGPFingerprintType& withfingerprint); /* Sign/Trust stuff */ - int privateSignCertificate(const std::string &id); - int privateRevokeCertificate(const std::string &id); /* revoke the signature on Certificate */ - int privateTrustCertificate(const std::string &id, int trustlvl); + int privateSignCertificate(const PGPIdType &id); + int privateRevokeCertificate(const PGPIdType &id); /* revoke the signature on Certificate */ + int privateTrustCertificate(const PGPIdType& id, int trustlvl); // store all keys in map mKeyList to avoid calling gpgme exe repeatedly //bool storeAllKeys(); diff --git a/libretroshare/src/pqi/authssl.cc b/libretroshare/src/pqi/authssl.cc index 47e97072a..f9d9dc904 100644 --- a/libretroshare/src/pqi/authssl.cc +++ b/libretroshare/src/pqi/authssl.cc @@ -42,6 +42,7 @@ #include "util/rsstring.h" #include "retroshare/rspeers.h" // for RsPeerDetails structure +#include "retroshare/rsids.h" // for RsPeerDetails structure #include "rsserver/p3face.h" /******************** notify of new Cert **************************/ @@ -240,7 +241,7 @@ AuthSSL::AuthSSL() static int verify_x509_callback(int preverify_ok, X509_STORE_CTX *ctx); -sslcert::sslcert(X509 *x509, std::string pid) +sslcert::sslcert(X509 *x509, const SSLIdType& pid) { certificate = x509; id = pid; @@ -249,7 +250,7 @@ sslcert::sslcert(X509 *x509, std::string pid) location = getX509LocString(x509->cert_info->subject); email = ""; - issuer = getX509CNString(x509->cert_info->issuer); + issuer = PGPIdType(std::string(getX509CNString(x509->cert_info->issuer))); authed = false; } @@ -426,7 +427,9 @@ static int initLib = 0; return -1; } - if (!getX509id(x509, mOwnId)) + std::string mownidstr ; + + if (!getX509id(x509, mownidstr)) { std::cerr << "AuthSSLimpl::InitAuth() getX509id() Failed"; std::cerr << std::endl; @@ -435,6 +438,10 @@ static int initLib = 0; CloseAuth(); return -1; } + mOwnId = SSLIdType(mownidstr) ; + + assert(!mOwnId.isNull()) ; + /* Check that Certificate is Ok ( virtual function ) * for gpg/pgp or CA verification */ @@ -522,7 +529,7 @@ SSL_CTX *AuthSSLimpl::getCTX() return sslctx; } -std::string AuthSSLimpl::OwnId() +const SSLIdType& AuthSSLimpl::OwnId() { #ifdef AUTHSSL_DEBUG // std::cerr << "AuthSSLimpl::OwnId()" << std::endl; @@ -615,7 +622,7 @@ bool AuthSSLimpl::SignDataBin(const void *data, const uint32_t len, bool AuthSSLimpl::VerifySignBin(const void *data, const uint32_t len, - unsigned char *sign, unsigned int signlen, SSL_id sslId) + unsigned char *sign, unsigned int signlen, const SSLIdType& sslId) { /* find certificate. * if we don't have - fail. @@ -677,7 +684,7 @@ X509 *AuthSSLimpl::SignX509ReqWithGPG(X509_REQ *req, long days) unsigned long chtype = MBSTRING_ASC; X509_NAME *issuer_name = X509_NAME_new(); X509_NAME_add_entry_by_txt(issuer_name, "CN", chtype, - (unsigned char *) AuthGPG::getAuthGPG()->getGPGOwnId().c_str(), -1, -1, 0); + (unsigned char *) AuthGPG::getAuthGPG()->getGPGOwnId().toStdString().c_str(), -1, -1, 0); /**** X509_NAME_add_entry_by_NID(issuer_name, 48, 0, (unsigned char *) "email@email.com", -1, -1, 0); @@ -687,7 +694,7 @@ X509 *AuthSSLimpl::SignX509ReqWithGPG(X509_REQ *req, long days) (unsigned char *) "loc", -1, -1, 0); ****/ - std::cerr << "AuthSSLimpl::SignX509Req() Issuer name: " << AuthGPG::getAuthGPG()->getGPGOwnId() << std::endl; + std::cerr << "AuthSSLimpl::SignX509Req() Issuer name: " << AuthGPG::getAuthGPG()->getGPGOwnId().toStdString() << std::endl; BIGNUM *btmp = BN_new(); if (!BN_pseudo_rand(btmp, SERIAL_RAND_BITS, 0, 0)) @@ -888,10 +895,10 @@ bool AuthSSLimpl::AuthX509WithGPG(X509 *x509,uint32_t& diagnostic) } /* extract CN for peer Id */ - std::string issuer = getX509CNString(x509->cert_info->issuer); + PGPIdType issuer(std::string(getX509CNString(x509->cert_info->issuer))); RsPeerDetails pd; #ifdef AUTHSSL_DEBUG - std::cerr << "Checking GPG issuer : " << issuer << std::endl ; + std::cerr << "Checking GPG issuer : " << issuer.toStdString() << std::endl ; #endif if (!AuthGPG::getAuthGPG()->getGPGDetails(issuer, pd)) { std::cerr << "AuthSSLimpl::AuthX509() X509 NOT authenticated : AuthGPG::getAuthGPG()->getGPGDetails() returned false." << std::endl; @@ -1009,7 +1016,7 @@ err: /* validate + get id */ -bool AuthSSLimpl::ValidateCertificate(X509 *x509, std::string &peerId) +bool AuthSSLimpl::ValidateCertificate(X509 *x509, SSLIdType &peerId) { uint32_t auth_diagnostic ; @@ -1022,7 +1029,9 @@ bool AuthSSLimpl::ValidateCertificate(X509 *x509, std::string &peerId) #endif return false; } - if(!getX509id(x509, peerId)) + std::string peerIdstr ; + + if(!getX509id(x509, peerIdstr)) { #ifdef AUTHSSL_DEBUG std::cerr << "AuthSSLimpl::ValidateCertificate() Cannot retrieve peer id from certificate.."; @@ -1030,6 +1039,7 @@ bool AuthSSLimpl::ValidateCertificate(X509 *x509, std::string &peerId) #endif return false; } + peerId = SSLIdType(peerIdstr) ; #ifdef AUTHSSL_DEBUG 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) { - 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 sslid ; - getX509id(x509,sslid); + std::string sslidstr ; + + 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) ; } @@ -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; 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)) { @@ -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 ******/ @@ -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 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_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 ; ssl_id = _last_sslid_to_connect ; @@ -1397,8 +1422,8 @@ void AuthSSLimpl::getCurrentConnectionAttemptInfo(std::string& gpg_id,std::strin } /* store for discovery */ -bool AuthSSLimpl::FailedCertificate(X509 *x509, const std::string& gpgid, - const std::string& sslid, +bool AuthSSLimpl::FailedCertificate(X509 *x509, const PGPIdType& gpgid, + const SSLIdType& sslid, const std::string& sslcn, const struct sockaddr_storage& addr, bool incoming) @@ -1424,24 +1449,24 @@ bool AuthSSLimpl::FailedCertificate(X509 *x509, const std::string& gpgid, #endif if (incoming) { - RsServer::notify()->AddPopupMessage(RS_POPUP_CONNECT_ATTEMPT, gpgid, sslcn, sslid); + RsServer::notify()->AddPopupMessage(RS_POPUP_CONNECT_ATTEMPT, gpgid.toStdString(), sslcn, sslid.toStdString()); switch(auth_diagnostic) { - case RS_SSL_HANDSHAKE_DIAGNOSTIC_CERTIFICATE_MISSING: RsServer::notify()->AddFeedItem(RS_FEED_ITEM_SEC_MISSING_CERTIFICATE, gpgid, sslid, sslcn, ip_address); + case RS_SSL_HANDSHAKE_DIAGNOSTIC_CERTIFICATE_MISSING: RsServer::notify()->AddFeedItem(RS_FEED_ITEM_SEC_MISSING_CERTIFICATE, gpgid.toStdString(), sslid.toStdString(), sslcn, ip_address); break ; - case RS_SSL_HANDSHAKE_DIAGNOSTIC_CERTIFICATE_NOT_VALID: RsServer::notify()->AddFeedItem(RS_FEED_ITEM_SEC_BAD_CERTIFICATE, gpgid, sslid, sslcn, ip_address); + case RS_SSL_HANDSHAKE_DIAGNOSTIC_CERTIFICATE_NOT_VALID: RsServer::notify()->AddFeedItem(RS_FEED_ITEM_SEC_BAD_CERTIFICATE, gpgid.toStdString(), sslid.toStdString(), sslcn, ip_address); break ; - case RS_SSL_HANDSHAKE_DIAGNOSTIC_ISSUER_UNKNOWN: RsServer::notify()->AddFeedItem(RS_FEED_ITEM_SEC_UNKNOWN_IN , gpgid, sslid, sslcn, ip_address); + case RS_SSL_HANDSHAKE_DIAGNOSTIC_ISSUER_UNKNOWN: RsServer::notify()->AddFeedItem(RS_FEED_ITEM_SEC_UNKNOWN_IN , gpgid.toStdString(), sslid.toStdString(), sslcn, ip_address); break ; - case RS_SSL_HANDSHAKE_DIAGNOSTIC_MALLOC_ERROR: RsServer::notify()->AddFeedItem(RS_FEED_ITEM_SEC_INTERNAL_ERROR , gpgid, sslid, sslcn, ip_address); + case RS_SSL_HANDSHAKE_DIAGNOSTIC_MALLOC_ERROR: RsServer::notify()->AddFeedItem(RS_FEED_ITEM_SEC_INTERNAL_ERROR , gpgid.toStdString(), sslid.toStdString(), sslcn, ip_address); break ; - case RS_SSL_HANDSHAKE_DIAGNOSTIC_WRONG_SIGNATURE: RsServer::notify()->AddFeedItem(RS_FEED_ITEM_SEC_WRONG_SIGNATURE, gpgid, sslid, sslcn, ip_address); + case RS_SSL_HANDSHAKE_DIAGNOSTIC_WRONG_SIGNATURE: RsServer::notify()->AddFeedItem(RS_FEED_ITEM_SEC_WRONG_SIGNATURE, gpgid.toStdString(), sslid.toStdString(), sslcn, ip_address); break ; case RS_SSL_HANDSHAKE_DIAGNOSTIC_OK: case RS_SSL_HANDSHAKE_DIAGNOSTIC_UNKNOWN: default: - RsServer::notify()->AddFeedItem(RS_FEED_ITEM_SEC_CONNECT_ATTEMPT, gpgid, sslid, sslcn, ip_address); + RsServer::notify()->AddFeedItem(RS_FEED_ITEM_SEC_CONNECT_ATTEMPT, gpgid.toStdString(), sslid.toStdString(), sslcn, ip_address); } #ifdef AUTHSSL_DEBUG @@ -1451,9 +1476,9 @@ bool AuthSSLimpl::FailedCertificate(X509 *x509, const std::string& gpgid, else { if(authed) - RsServer::notify()->AddFeedItem(RS_FEED_ITEM_SEC_AUTH_DENIED, gpgid, sslid, sslcn, ip_address); + RsServer::notify()->AddFeedItem(RS_FEED_ITEM_SEC_AUTH_DENIED, gpgid.toStdString(), sslid.toStdString(), sslcn, ip_address); else - RsServer::notify()->AddFeedItem(RS_FEED_ITEM_SEC_UNKNOWN_OUT, gpgid, sslid, sslcn, ip_address); + RsServer::notify()->AddFeedItem(RS_FEED_ITEM_SEC_UNKNOWN_OUT, gpgid.toStdString(), sslid.toStdString(), sslcn, ip_address); #ifdef AUTHSSL_DEBUG std::cerr << " Outgoing to: "; @@ -1468,7 +1493,7 @@ bool AuthSSLimpl::FailedCertificate(X509 *x509, const std::string& gpgid, return false; } -bool AuthSSLimpl::CheckCertificate(std::string id, X509 *x509) +bool AuthSSLimpl::CheckCertificate(const SSLIdType& id, X509 *x509) { (void) id; /* remove unused parameter warning */ @@ -1485,9 +1510,9 @@ bool AuthSSLimpl::CheckCertificate(std::string id, X509 *x509) /* Locked search -> internal help function */ -bool AuthSSLimpl::locked_FindCert(std::string id, sslcert **cert) +bool AuthSSLimpl::locked_FindCert(const SSLIdType& id, sslcert **cert) { - std::map::iterator it; + std::map::iterator it; if (mCerts.end() != (it = mCerts.find(id))) { @@ -1500,9 +1525,9 @@ bool AuthSSLimpl::locked_FindCert(std::string id, sslcert **cert) /* Remove Certificate */ -bool AuthSSLimpl::RemoveX509(std::string id) +bool AuthSSLimpl::RemoveX509(SSLIdType id) { - std::map::iterator it; + std::map::iterator it; RsStackMutex stack(sslMtx); /******* LOCKED ******/ @@ -1526,14 +1551,21 @@ bool AuthSSLimpl::RemoveX509(std::string id) bool AuthSSLimpl::LocalStoreCert(X509* x509) { //store the certificate in the local cert list - std::string peerId; - if(!getX509id(x509, peerId)) + std::string peerIdstr ; + if(!getX509id(x509, peerIdstr)) { std::cerr << "AuthSSLimpl::LocalStoreCert() Cannot retrieve peer id from certificate." << std::endl; #ifdef AUTHSSL_DEBUG #endif return false; } + SSLIdType peerId(peerIdstr); + + if(peerId.isNull()) + { + std::cerr << "AuthSSLimpl::LocalStoreCert(): invalid peer id \"" << peerIdstr << "\"" << std::endl; + return false ; + } RsStackMutex stack(sslMtx); /******* LOCKED ******/ @@ -1547,7 +1579,7 @@ bool AuthSSLimpl::LocalStoreCert(X509* x509) } /* do a search */ - std::map::iterator it; + std::map::iterator it; if (mCerts.end() != (it = mCerts.find(peerId))) { @@ -1603,13 +1635,13 @@ bool AuthSSLimpl::saveList(bool& cleanup, std::list& lst) // Now save config for network digging strategies RsConfigKeyValueSet *vitem = new RsConfigKeyValueSet ; - std::map::iterator mapIt; + std::map::iterator mapIt; for (mapIt = mCerts.begin(); mapIt != mCerts.end(); mapIt++) { if (mapIt->first == mOwnId) { continue; } RsTlvKeyValue kv; - kv.key = mapIt->first; + kv.key = mapIt->first.toStdString(); #ifdef AUTHSSL_DEBUG std::cerr << "AuthSSLimpl::saveList() called (mapIt->first) : " << (mapIt->first) << std::endl ; #endif @@ -1641,7 +1673,7 @@ bool AuthSSLimpl::loadList(std::list& load) std::list::iterator kit; for(kit = vitem->tlvkvs.pairs.begin(); kit != vitem->tlvkvs.pairs.end(); kit++) { - if (kit->key == mOwnId) { + if (SSLIdType(kit->key) == mOwnId) { continue; } diff --git a/libretroshare/src/pqi/authssl.h b/libretroshare/src/pqi/authssl.h index 02a56b1fd..6a566743e 100644 --- a/libretroshare/src/pqi/authssl.h +++ b/libretroshare/src/pqi/authssl.h @@ -51,8 +51,6 @@ #include "pqi/pqinetwork.h" #include "pqi/p3cfgmgr.h" -typedef std::string SSL_id; - /* This #define removes Connection Manager references in AuthSSL. * They should not be here. What about Objects and orthogonality? * This code is also stopping immediate reconnections from working. @@ -63,20 +61,18 @@ class AuthSSL; class sslcert { public: - sslcert(X509* x509, std::string id); + sslcert(X509* x509, const SSLIdType& id); sslcert(); /* certificate parameters */ - std::string id; + SSLIdType id; std::string name; std::string location; std::string org; std::string email; - std::string issuer; - - std::string fpr; - //std::list signers; + PGPIdType issuer; + PGPFingerprintType fpr; /* Auth settings */ bool authed; @@ -106,19 +102,8 @@ virtual bool CloseAuth() = 0; /*********** Overloaded Functions from p3AuthMgr **********/ /* get Certificate Id */ -virtual std::string OwnId() = 0; +virtual const SSLIdType& OwnId() = 0; virtual std::string getOwnLocation() = 0; -//virtual bool getAllList(std::list &ids); -//virtual bool getAuthenticatedList(std::list &ids); -//virtual bool getUnknownList(std::list &ids); -//virtual bool getSSLChildListOfGPGId(std::string gpg_id, std::list &ids); - - /* get Details from the Certificates */ -//virtual bool isAuthenticated(std::string id); -//virtual std::string getName(std::string id); -//virtual std::string getIssuerName(std::string id); -//virtual std::string getGPGId(SSL_id id); -//virtual bool getCertDetails(std::string id, sslcert &cert); /* Load/Save certificates */ virtual std::string SaveOwnCertificateToString() = 0; @@ -131,10 +116,10 @@ virtual bool SignDataBin(std::string, unsigned char*, unsigned int*) = 0; virtual bool SignDataBin(const void*, uint32_t, unsigned char*, unsigned int*) = 0; virtual bool VerifyOwnSignBin(const void*, uint32_t, unsigned char*, unsigned int) = 0; virtual bool VerifySignBin(const void *data, const uint32_t len, - unsigned char *sign, unsigned int signlen, SSL_id sslId) = 0; + unsigned char *sign, unsigned int signlen, const SSLIdType& sslId) = 0; // return : false if encrypt failed -virtual bool encrypt(void *&out, int &outlen, const void *in, int inlen, std::string peerId) = 0; +virtual bool encrypt(void *&out, int &outlen, const void *in, int inlen, const SSLIdType& peerId) = 0; // return : false if decrypt fails virtual bool decrypt(void *&out, int &outlen, const void *in, int inlen) = 0; @@ -144,17 +129,17 @@ virtual bool AuthX509WithGPG(X509 *x509,uint32_t& auth_diagnostic)=0; virtual int VerifyX509Callback(int preverify_ok, X509_STORE_CTX *ctx) = 0; -virtual bool ValidateCertificate(X509 *x509, std::string &peerId) = 0; /* validate + get id */ +virtual bool ValidateCertificate(X509 *x509, SSLIdType& peerId) = 0; /* validate + get id */ public: /* SSL specific functions used in pqissl/pqissllistener */ virtual SSL_CTX *getCTX() = 0; /* Restored these functions: */ -virtual void setCurrentConnectionAttemptInfo(const std::string& gpg_id,const std::string& ssl_id,const std::string& ssl_cn) = 0 ; -virtual void getCurrentConnectionAttemptInfo( std::string& gpg_id, std::string& ssl_id, std::string& ssl_cn) = 0 ; +virtual void setCurrentConnectionAttemptInfo(const PGPIdType& gpg_id,const SSLIdType& ssl_id,const 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 CheckCertificate(std::string peerId, X509 *x509) = 0; /* check that they are exact match */ +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(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 AuthSSL *instance_ssl ; @@ -177,19 +162,8 @@ virtual bool CloseAuth(); /*********** Overloaded Functions from p3AuthMgr **********/ /* get Certificate Id */ -virtual std::string OwnId(); +virtual const SSLIdType& OwnId(); virtual std::string getOwnLocation(); -//virtual bool getAllList(std::list &ids); -//virtual bool getAuthenticatedList(std::list &ids); -//virtual bool getUnknownList(std::list &ids); -//virtual bool getSSLChildListOfGPGId(std::string gpg_id, std::list &ids); - - /* get Details from the Certificates */ -//virtual bool isAuthenticated(std::string id); -//virtual std::string getName(std::string id); -//virtual std::string getIssuerName(std::string id); -//virtual std::string getGPGId(SSL_id id); -//virtual bool getCertDetails(std::string id, sslcert &cert); /* Load/Save certificates */ virtual std::string SaveOwnCertificateToString(); @@ -202,10 +176,10 @@ virtual bool SignDataBin(std::string, unsigned char*, unsigned int*); virtual bool SignDataBin(const void*, uint32_t, unsigned char*, unsigned int*); virtual bool VerifyOwnSignBin(const void*, uint32_t, unsigned char*, unsigned int); virtual bool VerifySignBin(const void *data, const uint32_t len, - unsigned char *sign, unsigned int signlen, SSL_id sslId); + unsigned char *sign, unsigned int signlen, const SSLIdType& sslId); // return : false if encrypt failed -virtual bool encrypt(void *&out, int &outlen, const void *in, int inlen, std::string peerId); +virtual bool encrypt(void *&out, int &outlen, const void *in, int inlen, const SSLIdType& peerId); // return : false if decrypt fails virtual bool decrypt(void *&out, int &outlen, const void *in, int inlen); @@ -215,7 +189,7 @@ virtual bool AuthX509WithGPG(X509 *x509,uint32_t& auth_diagnostic); virtual int VerifyX509Callback(int preverify_ok, X509_STORE_CTX *ctx); -virtual bool ValidateCertificate(X509 *x509, std::string &peerId); /* validate + get id */ +virtual bool ValidateCertificate(X509 *x509, SSLIdType& peerId); /* validate + get id */ /*****************************************************************/ @@ -230,24 +204,24 @@ virtual bool ValidateCertificate(X509 *x509, std::string &peerId); /* validate virtual SSL_CTX *getCTX(); /* Restored these functions: */ -virtual void setCurrentConnectionAttemptInfo(const std::string& gpg_id,const std::string& ssl_id,const std::string& ssl_cn) ; -virtual void getCurrentConnectionAttemptInfo( std::string& gpg_id, std::string& ssl_id, std::string& ssl_cn) ; -virtual bool FailedCertificate(X509 *x509, const std::string& gpgid,const std::string& sslid,const std::string& sslcn,const struct sockaddr_storage &addr, bool incoming); /* store for discovery */ -virtual bool CheckCertificate(std::string peerId, X509 *x509); /* check that they are exact match */ +virtual void setCurrentConnectionAttemptInfo(const PGPIdType& gpg_id,const SSLIdType& ssl_id,const std::string& ssl_cn) ; +virtual void getCurrentConnectionAttemptInfo( PGPIdType& gpg_id, SSLIdType& ssl_id, std::string& ssl_cn) ; +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(const SSLIdType& peerId, X509 *x509); /* check that they are exact match */ private: bool LocalStoreCert(X509* x509); -bool RemoveX509(std::string id); +bool RemoveX509(const SSLIdType id); /*********** LOCKED Functions ******/ -bool locked_FindCert(std::string id, sslcert **cert); +bool locked_FindCert(const SSLIdType& id, sslcert **cert); /* Data */ /* these variables are constants -> don't need to protect */ SSL_CTX *sslctx; - std::string mOwnId; + SSLIdType mOwnId; sslcert *mOwnCert; RsMutex sslMtx; /* protects all below */ @@ -258,11 +232,11 @@ bool locked_FindCert(std::string id, sslcert **cert); int init; - std::map mCerts; + std::map mCerts; - std::string _last_gpgid_to_connect ; + PGPIdType _last_gpgid_to_connect ; std::string _last_sslcn_to_connect ; - std::string _last_sslid_to_connect ; + SSLIdType _last_sslid_to_connect ; }; #endif // MRK_AUTH_SSL_HEADER diff --git a/libretroshare/src/pqi/p3historymgr.cc b/libretroshare/src/pqi/p3historymgr.cc index 16a30c800..2566dee4f 100644 --- a/libretroshare/src/pqi/p3historymgr.cc +++ b/libretroshare/src/pqi/p3historymgr.cc @@ -100,7 +100,7 @@ void p3HistoryMgr::addMessage(bool incoming, const std::string &chatPeerId, cons item->chatPeerId = chatPeerId; item->incoming = incoming; item->peerId = peerId; - item->peerName = cli ? cli->nick : rsPeers->getPeerName(item->peerId); + item->peerName = cli ? cli->nick : rsPeers->getPeerName(RsPeerId(item->peerId)); item->sendTime = chatItem->sendTime; item->recvTime = chatItem->recvTime; diff --git a/libretroshare/src/pqi/p3linkmgr.h b/libretroshare/src/pqi/p3linkmgr.h index 36659d656..df1f96a40 100644 --- a/libretroshare/src/pqi/p3linkmgr.h +++ b/libretroshare/src/pqi/p3linkmgr.h @@ -94,7 +94,7 @@ class peerConnectState public: peerConnectState(); /* init */ - std::string id; + SSLIdType id; /***** Below here not stored permanently *****/ @@ -155,26 +155,26 @@ class p3LinkMgr: public pqiConnectCb virtual ~p3LinkMgr() { return; } -virtual const std::string getOwnId() = 0; -virtual bool isOnline(const std::string &ssl_id) = 0; -virtual void getOnlineList(std::list &ssl_peers) = 0; -virtual bool getPeerName(const std::string &ssl_id, std::string &name) = 0; -virtual uint32_t getLinkType(const std::string &ssl_id) = 0; +virtual const SSLIdType& getOwnId() = 0; +virtual bool isOnline(const SSLIdType &ssl_id) = 0; +virtual void getOnlineList(std::list &ssl_peers) = 0; +virtual bool getPeerName(const SSLIdType &ssl_id, std::string &name) = 0; +virtual uint32_t getLinkType(const SSLIdType &ssl_id) = 0; /**************** handle monitors *****************/ virtual void addMonitor(pqiMonitor *mon) = 0; virtual void removeMonitor(pqiMonitor *mon) = 0; /****************** Connections *******************/ -virtual bool connectAttempt(const std::string &id, struct sockaddr_storage &raddr, +virtual bool connectAttempt(const SSLIdType &id, struct sockaddr_storage &raddr, struct sockaddr_storage &proxyaddr, struct sockaddr_storage &srcaddr, uint32_t &delay, uint32_t &period, uint32_t &type, uint32_t &flags, uint32_t &bandwidth, std::string &domain_addr, uint16_t &domain_port) = 0; -virtual bool connectResult(const std::string &id, bool success, uint32_t flags, const struct sockaddr_storage &remote_peer_address) = 0; -virtual bool retryConnect(const std::string &id) = 0; +virtual bool connectResult(const SSLIdType &id, bool success, uint32_t flags, const struct sockaddr_storage &remote_peer_address) = 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 */ virtual bool setLocalAddress(const struct sockaddr_storage &addr) = 0; @@ -182,12 +182,12 @@ virtual bool getLocalAddress(struct sockaddr_storage &addr) = 0; /************* DEPRECIATED FUNCTIONS (TO REMOVE) ********/ -virtual void getFriendList(std::list &ssl_peers) = 0; // ONLY used by p3peers.cc USE p3PeerMgr instead. -virtual bool getFriendNetStatus(const std::string &id, peerConnectState &state) = 0; // ONLY used by p3peers.cc +virtual void getFriendList(std::list &ssl_peers) = 0; // ONLY used by p3peers.cc USE p3PeerMgr instead. +virtual bool getFriendNetStatus(const SSLIdType &id, peerConnectState &state) = 0; // ONLY used by p3peers.cc /************* DEPRECIATED FUNCTIONS (TO REMOVE) ********/ -virtual int addFriend(const std::string &ssl_id, bool isVisible) = 0; +virtual int addFriend(const SSLIdType &ssl_id, bool isVisible) = 0; /******* overloaded from pqiConnectCb *************/ // THESE MUSTn't BE specfied HERE - as overloaded from pqiConnectCb. //virtual void peerStatus(std::string id, const pqiIpAddrSet &addrs, @@ -212,11 +212,11 @@ class p3LinkMgrIMPL: public p3LinkMgr /* EXTERNAL INTERFACE */ /************************************************************************************************/ -virtual const std::string getOwnId(); -virtual bool isOnline(const std::string &ssl_id); -virtual void getOnlineList(std::list &ssl_peers); -virtual bool getPeerName(const std::string &ssl_id, std::string &name); -virtual uint32_t getLinkType(const std::string &ssl_id); +virtual const SSLIdType& getOwnId(); +virtual bool isOnline(const SSLIdType &ssl_id); +virtual void getOnlineList(std::list &ssl_peers); +virtual bool getPeerName(const SSLIdType &ssl_id, std::string &name); +virtual uint32_t getLinkType(const SSLIdType &ssl_id); /**************** handle monitors *****************/ @@ -224,32 +224,32 @@ virtual void addMonitor(pqiMonitor *mon); virtual void removeMonitor(pqiMonitor *mon); /****************** Connections *******************/ -virtual bool connectAttempt(const std::string &id, struct sockaddr_storage &raddr, +virtual bool connectAttempt(const SSLIdType &id, struct sockaddr_storage &raddr, struct sockaddr_storage &proxyaddr, struct sockaddr_storage &srcaddr, uint32_t &delay, uint32_t &period, uint32_t &type, uint32_t &flags, uint32_t &bandwidth, std::string &domain_addr, uint16_t &domain_port); -virtual bool connectResult(const std::string &id, bool success, uint32_t flags, const struct sockaddr_storage &remote_peer_address); -virtual bool retryConnect(const std::string &id); +virtual bool connectResult(const SSLIdType &id, bool success, uint32_t flags, const struct sockaddr_storage &remote_peer_address); +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 */ virtual bool setLocalAddress(const struct sockaddr_storage &addr); virtual bool getLocalAddress(struct sockaddr_storage &addr); /******* overloaded from pqiConnectCb *************/ -virtual void peerStatus(std::string id, const pqiIpAddrSet &addrs, +virtual void peerStatus(const SSLIdType& id, const pqiIpAddrSet &addrs, uint32_t type, uint32_t flags, uint32_t source); -virtual void peerConnectRequest(std::string id, const struct sockaddr_storage &raddr, +virtual void peerConnectRequest(const SSLIdType& id, const struct sockaddr_storage &raddr, const struct sockaddr_storage &proxyaddr, const struct sockaddr_storage &srcaddr, uint32_t source, uint32_t flags, uint32_t delay, uint32_t bandwidth); /************* DEPRECIATED FUNCTIONS (TO REMOVE) ********/ -virtual void getFriendList(std::list &ssl_peers); // ONLY used by p3peers.cc USE p3PeerMgr instead. -virtual bool getFriendNetStatus(const std::string &id, peerConnectState &state); // ONLY used by p3peers.cc +virtual void getFriendList(std::list &ssl_peers); // ONLY used by p3peers.cc USE p3PeerMgr instead. +virtual bool getFriendNetStatus(const SSLIdType &id, peerConnectState &state); // ONLY used by p3peers.cc /************************************************************************************************/ /* Extra IMPL Functions (used by p3PeerMgr, p3NetMgr + Setup) */ @@ -260,11 +260,11 @@ virtual bool getFriendNetStatus(const std::string &id, peerConnectState &state); void tick(); /* THIS COULD BE ADDED TO INTERFACE */ -void setFriendVisibility(const std::string &id, bool isVisible); +void setFriendVisibility(const SSLIdType &id, bool isVisible); /* add/remove friends */ -virtual int addFriend(const std::string &ssl_id, bool isVisible); -int removeFriend(const std::string &ssl_id); +virtual int addFriend(const SSLIdType &ssl_id, bool isVisible); +int removeFriend(const SSLIdType &ssl_id); void printPeerLists(std::ostream &out); @@ -284,12 +284,12 @@ void statusTick(); void tickMonitors(); /* connect attempts UDP */ -bool tryConnectUDP(const std::string &id, const struct sockaddr_storage &rUdpAddr, +bool tryConnectUDP(const SSLIdType &id, const struct sockaddr_storage &rUdpAddr, const struct sockaddr_storage &proxyaddr, const struct sockaddr_storage &srcaddr, uint32_t flags, uint32_t delay, uint32_t bandwidth); /* connect attempts TCP */ -bool retryConnectTCP(const std::string &id); +bool retryConnectTCP(const SSLIdType &id); void locked_ConnectAttempt_SpecificAddress(peerConnectState *peer, const struct sockaddr_storage &remoteAddr); void locked_ConnectAttempt_CurrentAddresses(peerConnectState *peer, const struct sockaddr_storage &localAddr, const struct sockaddr_storage &serverAddr); @@ -330,8 +330,8 @@ private: //peerConnectState mOwnState; - std::map mFriendList; - std::map mOthersList; + std::map mFriendList; + std::map mOthersList; std::list groupList; uint32_t lastGroupId; diff --git a/libretroshare/src/pqi/p3peermgr.cc b/libretroshare/src/pqi/p3peermgr.cc index 29e0658ea..2e16b0ecc 100644 --- a/libretroshare/src/pqi/p3peermgr.cc +++ b/libretroshare/src/pqi/p3peermgr.cc @@ -96,7 +96,7 @@ peerState::peerState() std::string textPeerConnectState(peerState &state) { - std::string out = "Id: " + state.id + "\n"; + std::string out = "Id: " + state.id.toStdString() + "\n"; rs_sprintf_append(out, "NetMode: %lu\n", state.netMode); rs_sprintf_append(out, "VisState: Disc: %u Dht: %u\n", state.vs_disc, state.vs_dht); @@ -110,10 +110,7 @@ std::string textPeerConnectState(peerState &state) } -p3PeerMgrIMPL::p3PeerMgrIMPL(const std::string& ssl_own_id, - const std::string& gpg_own_id, - const std::string& gpg_own_name, - const std::string& ssl_own_location) +p3PeerMgrIMPL::p3PeerMgrIMPL(const SSLIdType& ssl_own_id, const PGPIdType& gpg_own_id, const PGPIdType& gpg_own_name, const RsPeerId& ssl_own_location) :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(); } @@ -310,7 +307,7 @@ bool p3PeerMgrIMPL::getOwnNetStatus(peerState &state) return true; } -bool p3PeerMgrIMPL::isFriend(const std::string &id) +bool p3PeerMgrIMPL::isFriend(const SSLIdType& id) { #ifdef PEER_DEBUG_COMMON std::cerr << "p3PeerMgrIMPL::isFriend(" << id << ") called" << std::endl; @@ -323,12 +320,12 @@ bool p3PeerMgrIMPL::isFriend(const std::string &id) return ret; } -bool p3PeerMgrIMPL::getPeerName(const std::string &ssl_id, std::string &name) +bool p3PeerMgrIMPL::getPeerName(const SSLIdType &ssl_id, std::string &name) { RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ /* check for existing */ - std::map::iterator it; + std::map::iterator it; it = mFriendList.find(ssl_id); if (it == mFriendList.end()) { @@ -339,12 +336,12 @@ bool p3PeerMgrIMPL::getPeerName(const std::string &ssl_id, std::string &name) return true; } -bool p3PeerMgrIMPL::getGpgId(const std::string &ssl_id, std::string &gpgId) +bool p3PeerMgrIMPL::getGpgId(const SSLIdType &ssl_id, PGPIdType &gpgId) { RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ /* check for existing */ - std::map::iterator it; + std::map::iterator it; it = mFriendList.find(ssl_id); 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 *******/ /* check for existing */ - std::map::iterator it; + std::map::iterator it; it = mFriendList.find(ssl_id); if (it == mFriendList.end()) { @@ -384,7 +381,7 @@ bool p3PeerMgrIMPL::isHiddenPeer(const std::string &ssl_id) return (it->second).hiddenNode; } -bool p3PeerMgrIMPL::setHiddenDomainPort(const std::string &ssl_id, const std::string &domain_addr, const uint16_t domain_port) +bool p3PeerMgrIMPL::setHiddenDomainPort(const SSLIdType &ssl_id, const std::string &domain_addr, const uint16_t domain_port) { RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ @@ -417,7 +414,7 @@ bool p3PeerMgrIMPL::setHiddenDomainPort(const std::string &ssl_id, const std::st } /* check for existing */ - std::map::iterator it; + std::map::iterator it; it = mFriendList.find(ssl_id); if (it == mFriendList.end()) { @@ -456,12 +453,12 @@ bool p3PeerMgrIMPL::getProxyServerAddress(struct sockaddr_storage &proxy_addr) return true; } -bool p3PeerMgrIMPL::getProxyAddress(const std::string &ssl_id, struct sockaddr_storage &proxy_addr, std::string &domain_addr, uint16_t &domain_port) +bool p3PeerMgrIMPL::getProxyAddress(const SSLIdType &ssl_id, struct sockaddr_storage &proxy_addr, std::string &domain_addr, uint16_t &domain_port) { RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ /* check for existing */ - std::map::iterator it; + std::map::iterator it; it = mFriendList.find(ssl_id); 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. -uint32_t p3PeerMgrIMPL::getConnectionType(const std::string &/*sslId*/) +uint32_t p3PeerMgrIMPL::getConnectionType(const SSLIdType &/*sslId*/) { return RS_NET_CONN_TYPE_FRIEND; } @@ -490,15 +487,15 @@ int p3PeerMgrIMPL::getFriendCount(bool ssl, bool online) { if (online) { // count only online id's - std::list onlineIds; + std::list onlineIds; mLinkMgr->getOnlineList(onlineIds); RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ - std::set gpgIds; + std::set gpgIds; int count = 0; - std::map::iterator it; + std::map::iterator it; for(it = mFriendList.begin(); it != mFriendList.end(); ++it) { if (online && std::find(onlineIds.begin(), onlineIds.end(), it->first) == onlineIds.end()) { continue; @@ -522,22 +519,22 @@ int p3PeerMgrIMPL::getFriendCount(bool ssl, bool online) } // count all gpg id's - std::list gpgIds; + std::list gpgIds; AuthGPG::getAuthGPG()->getGPGAcceptedList(gpgIds); // add own gpg id, if we have more than one location - std::list ownSslIds; + std::list ownSslIds; getAssociatedPeers(AuthGPG::getAuthGPG()->getGPGOwnId(), ownSslIds); return gpgIds.size() + ((ownSslIds.size() > 0) ? 1 : 0); } -bool p3PeerMgrIMPL::getFriendNetStatus(const std::string &id, peerState &state) +bool p3PeerMgrIMPL::getFriendNetStatus(const SSLIdType &id, peerState &state) { RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ /* check for existing */ - std::map::iterator it; + std::map::iterator it; it = mFriendList.find(id); 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 *******/ /* check for existing */ - std::map::iterator it; + std::map::iterator it; it = mOthersList.find(id); if (it == mOthersList.end()) { @@ -565,41 +562,7 @@ bool p3PeerMgrIMPL::getOthersNetStatus(const std::string &id, peerState &state) return true; } -#if 0 - -void p3PeerMgrIMPL::getFriendList(std::list &peers) -{ - RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ - - /* check for existing */ - std::map::iterator it; - for(it = mFriendList.begin(); it != mFriendList.end(); it++) - { - peers.push_back(it->first); - } - return; -} - -#endif - -#if 0 -void p3PeerMgrIMPL::getOthersList(std::list &peers) -{ - RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ - - /* check for existing */ - std::map::iterator it; - for(it = mOthersList.begin(); it != mOthersList.end(); it++) - { - peers.push_back(it->first); - } - return; -} -#endif - - - -int p3PeerMgrIMPL::getConnectAddresses(const std::string &id, +int p3PeerMgrIMPL::getConnectAddresses(const SSLIdType &id, struct sockaddr_storage &lAddr, struct sockaddr_storage &eAddr, pqiIpAddrSet &histAddrs, std::string &dyndns) { @@ -607,7 +570,7 @@ int p3PeerMgrIMPL::getConnectAddresses(const std::string &id, RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ /* check for existing */ - std::map::iterator it; + std::map::iterator it; it = mFriendList.find(id); if (it == mFriendList.end()) { @@ -632,7 +595,7 @@ bool p3PeerMgrIMPL::haveOnceConnected() RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ /* check for existing */ - std::map::iterator it; + std::map::iterator it; for(it = mFriendList.begin(); it != mFriendList.end(); it++) { 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; - std::string id = input_id ; - std::string gpg_id = input_gpg_id ; + SSLIdType id = input_id ; + PGPIdType gpg_id = input_gpg_id ; - rslog(RSL_WARNING, p3peermgrzone, "p3PeerMgr::addFriend() id: " + id); - - // For safety, make sure ssl_id is lower case and GPG id is upper case. - // - for(uint32_t i=0;i= 'A' && id[i] <= 'F') - id[i] += 'a' - 'A' ; - - for(uint32_t i=0;i= 'a' && gpg_id[i] <= 'f') - gpg_id[i] += 'A' - 'a' ; + rslog(RSL_WARNING, p3peermgrzone, "p3PeerMgr::addFriend() id: " + id.toStdString()); { RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ @@ -700,7 +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; #endif - std::map::iterator it; + std::map::iterator it; if (mFriendList.end() != mFriendList.find(id)) { #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 @@ -805,15 +758,15 @@ bool p3PeerMgrIMPL::removeFriend(const std::string &id, bool removePgpId) rslog(RSL_WARNING, p3peermgrzone, "p3PeerMgr::removeFriend() id: " + id); - std::list sslid_toRemove; // This is a list of SSLIds. - std::list pgpid_toRemove; // This is a list of SSLIds. + std::list sslid_toRemove; // This is a list of SSLIds. + std::list pgpid_toRemove; // This is a list of SSLIds. { RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ /* move to othersList */ bool success = false; - std::map::iterator it; + std::map::iterator it; //remove ssl and gpg_ids for(it = mFriendList.begin(); it != mFriendList.end(); it++) { @@ -834,12 +787,12 @@ bool p3PeerMgrIMPL::removeFriend(const std::string &id, bool removePgpId) } } - std::list::iterator rit; + std::list::iterator rit; for(rit = sslid_toRemove.begin(); rit != sslid_toRemove.end(); rit++) if (mFriendList.end() != (it = mFriendList.find(*rit))) mFriendList.erase(it); - std::map::iterator it2 ; + std::map::iterator it2 ; for(rit = pgpid_toRemove.begin(); rit != pgpid_toRemove.end(); rit++) if (mFriendsPermissionFlags.end() != (it2 = mFriendsPermissionFlags.find(*rit))) @@ -850,14 +803,14 @@ bool p3PeerMgrIMPL::removeFriend(const std::string &id, bool removePgpId) #endif } - std::list::iterator rit; + std::list::iterator rit; for(rit = sslid_toRemove.begin(); rit != sslid_toRemove.end(); rit++) { mLinkMgr->removeFriend(*rit); } /* remove id from all groups */ - std::list peerIds; + std::list peerIds; peerIds.push_back(id); assignPeersToGroup("", peerIds, false); @@ -882,7 +835,7 @@ void p3PeerMgrIMPL::printPeerLists(std::ostream &out) out << std::endl; - std::map::iterator it; + std::map::iterator it; for(it = mFriendList.begin(); it != mFriendList.end(); it++) { 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::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; @@ -1085,7 +975,7 @@ bool p3PeerMgrIMPL::setLocalAddress(const std::string &id, const struct socka RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ /* check if it is a friend */ - std::map::iterator it; + std::map::iterator it; if (mFriendList.end() == (it = mFriendList.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; } -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; @@ -1141,7 +1031,7 @@ bool p3PeerMgrIMPL::setExtAddress(const std::string &id, const struct sockadd RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ /* check if it is a friend */ - std::map::iterator it; + std::map::iterator it; if (mFriendList.end() == (it = mFriendList.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; @@ -1194,7 +1084,7 @@ bool p3PeerMgrIMPL::setDynDNS(const std::string &id, const std::string &dyndns) RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ /* check if it is a friend */ - std::map::iterator it; + std::map::iterator it; if (mFriendList.end() == (it = mFriendList.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; } -bool p3PeerMgrIMPL::updateAddressList(const std::string& id, const pqiIpAddrSet &addrs) +bool p3PeerMgrIMPL::updateAddressList(const SSLIdType& id, const pqiIpAddrSet &addrs) { #ifdef PEER_DEBUG 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 */ - std::map::iterator it; + std::map::iterator it; if (mFriendList.end() == (it = mFriendList.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 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 */ /* check if it is a friend */ - std::map::iterator it; + std::map::iterator it; if (mFriendList.end() == (it = mFriendList.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 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 */ /* check if it is a friend */ - std::map::iterator it; + std::map::iterator it; if (mFriendList.end() == (it = mFriendList.find(id))) { if (mOthersList.end() == (it = mOthersList.find(id))) @@ -1336,7 +1226,7 @@ bool p3PeerMgrIMPL::updateLastContact(const std::string& id) 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()) { @@ -1345,7 +1235,7 @@ bool p3PeerMgrIMPL::setNetworkMode(const std::string &id, uint32_t netMode) RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ /* check if it is a friend */ - std::map::iterator it; + std::map::iterator it; if (mFriendList.end() == (it = mFriendList.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; } -bool p3PeerMgrIMPL::setLocation(const std::string &id, const std::string &location) +bool p3PeerMgrIMPL::setLocation(const SSLIdType &id, const std::string &location) { bool changed = false; @@ -1386,7 +1276,7 @@ bool p3PeerMgrIMPL::setLocation(const std::string &id, const std::string &loc } /* check if it is a friend */ - std::map::iterator it; + std::map::iterator it; if (mFriendList.end() != (it = mFriendList.find(id))) { if (it->second.location.compare(location) != 0) { it->second.location = location; @@ -1396,7 +1286,7 @@ bool p3PeerMgrIMPL::setLocation(const std::string &id, const std::string &loc return changed; } -bool p3PeerMgrIMPL::setVisState(const std::string &id, uint16_t vs_disc, uint16_t vs_dht) +bool p3PeerMgrIMPL::setVisState(const SSLIdType &id, uint16_t vs_disc, uint16_t vs_dht) { { 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 *******/ /* check if it is a friend */ - std::map::iterator it; + std::map::iterator it; if (mFriendList.end() == (it = mFriendList.find(id))) { if (mOthersList.end() == (it = mOthersList.find(id))) @@ -1563,7 +1453,7 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list& saveData) saveCleanupList.push_back(item); /* iterate through all friends and save */ - std::map::iterator it; + std::map::iterator it; for(it = mFriendList.begin(); it != mFriendList.end(); it++) { item = new RsPeerNetItem(); @@ -1602,7 +1492,7 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list& saveData) RsPeerServicePermissionItem *sitem = new RsPeerServicePermissionItem ; - for(std::map::const_iterator it(mFriendsPermissionFlags.begin());it!=mFriendsPermissionFlags.end();++it) + for(std::map::const_iterator it(mFriendsPermissionFlags.begin());it!=mFriendsPermissionFlags.end();++it) { sitem->pgp_ids.push_back(it->first) ; sitem->service_flags.push_back(it->second) ; @@ -1677,7 +1567,7 @@ bool p3PeerMgrIMPL::loadList(std::list& load) std::cerr << "p3PeerMgrIMPL::loadList() Item Count: " << load.size() << std::endl; #endif - std::string ownId = getOwnId(); + SSLIdType ownId = getOwnId(); /* load the list of peers */ std::list::iterator it; @@ -2062,7 +1952,7 @@ bool p3PeerMgrIMPL::getGroupInfoList(std::list &groupInfoList) } // groupId == "" && assign == false -> remove from all groups -bool p3PeerMgrIMPL::assignPeersToGroup(const std::string &groupId, const std::list &peerIds, bool assign) +bool p3PeerMgrIMPL::assignPeersToGroup(const std::string &groupId, const std::list &peerIds, bool assign) { if (groupId.empty() && assign == true) { 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 *******/ @@ -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; return RS_SERVICE_PERM_ALL ; } - std::map::const_iterator it = mFriendList.find(ssl_id); + std::map::const_iterator it = mFriendList.find(ssl_id); if(it == mFriendList.end()) 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) @@ -2157,7 +2047,7 @@ ServicePermissionFlags p3PeerMgrIMPL::servicePermissionFlags(const std::string& { RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ - std::map::const_iterator it = mFriendsPermissionFlags.find( pgp_id ) ; + std::map::const_iterator it = mFriendsPermissionFlags.find( pgp_id ) ; if(it == mFriendsPermissionFlags.end()) return RS_SERVICE_PERM_ALL ; @@ -2165,7 +2055,7 @@ ServicePermissionFlags p3PeerMgrIMPL::servicePermissionFlags(const std::string& 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 *******/ @@ -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 sslIds; + std::list sslIds; if (!getAssociatedPeers(gpgid, sslIds)) { return false; } - std::list::iterator it; + std::list::iterator it; for(it = sslIds.begin(); it != sslIds.end(); it++) { removeFriend(*it, true); @@ -2206,7 +2096,7 @@ bool p3PeerMgrIMPL::removeAllFriendLocations(const std::string &gpgid) } -bool p3PeerMgrIMPL::getAssociatedPeers(const std::string &gpg_id, std::list &ids) +bool p3PeerMgrIMPL::getAssociatedPeers(const PGPIdType &gpg_id, std::list &ids) { RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ @@ -2215,7 +2105,7 @@ bool p3PeerMgrIMPL::getAssociatedPeers(const std::string &gpg_id, std::list::iterator it; + std::map::iterator it; for(it = mFriendList.begin(); it != mFriendList.end(); it++) { if (it->second.gpg_id == gpg_id) @@ -2240,7 +2130,7 @@ bool p3PeerMgrIMPL::getAssociatedPeers(const std::string &gpg_id, std::list toRemove; + std::list toRemove; { RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ @@ -2260,7 +2150,7 @@ bool p3PeerMgrIMPL::removeUnusedLocations() time_t now = time(NULL); - std::map::iterator it; + std::map::iterator it; for(it = mFriendList.begin(); it != mFriendList.end(); it++) { if (now - it->second.lastcontact > VERY_OLD_PEER) @@ -2285,7 +2175,7 @@ bool p3PeerMgrIMPL::removeUnusedLocations() } } - std::list::iterator it; + std::list::iterator it; for(it = toRemove.begin(); it != toRemove.end(); it++) { diff --git a/libretroshare/src/pqi/p3peermgr.h b/libretroshare/src/pqi/p3peermgr.h index 1ee263496..07e696694 100644 --- a/libretroshare/src/pqi/p3peermgr.h +++ b/libretroshare/src/pqi/p3peermgr.h @@ -70,8 +70,8 @@ class peerState public: peerState(); /* init */ - std::string id; - std::string gpg_id; + SSLIdType id; + PGPIdType gpg_id; uint32_t netMode; /* EXT / UPNP / UDP / HIDDEN / INVALID */ /* visState */ @@ -114,15 +114,15 @@ class p3PeerMgr p3PeerMgr() { return; } virtual ~p3PeerMgr() { return; } -virtual bool addFriend(const std::string &ssl_id, const std::string &gpg_id, uint32_t netMode = RS_NET_MODE_UDP, +virtual bool addFriend(const 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, 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 &ids) = 0; -virtual bool removeAllFriendLocations(const std::string &gpgid) = 0; +virtual bool getAssociatedPeers(const PGPIdType &gpg_id, std::list &ids) = 0; +virtual bool removeAllFriendLocations(const PGPIdType &gpgid) = 0; /******************** Groups **********************/ @@ -133,11 +133,11 @@ virtual bool editGroup(const std::string &groupId, RsGroupInfo &groupInfo) = virtual bool removeGroup(const std::string &groupId) = 0; virtual bool getGroupInfo(const std::string &groupId, RsGroupInfo &groupInfo) = 0; virtual bool getGroupInfoList(std::list &groupInfoList) = 0; -virtual bool assignPeersToGroup(const std::string &groupId, const std::list &peerIds, bool assign) = 0; +virtual bool assignPeersToGroup(const std::string &groupId, const std::list &peerIds, bool assign) = 0; - virtual ServicePermissionFlags servicePermissionFlags(const std::string& gpg_id) =0; - virtual ServicePermissionFlags servicePermissionFlags_sslid(const std::string& ssl_id) =0; - virtual void setServicePermissionFlags(const std::string& gpg_id,const ServicePermissionFlags& flags) =0; + virtual ServicePermissionFlags servicePermissionFlags(const PGPIdType& gpg_id) =0; + virtual ServicePermissionFlags servicePermissionFlags(const SSLIdType& ssl_id) =0; + virtual void setServicePermissionFlags(const PGPIdType& gpg_id,const ServicePermissionFlags& flags) =0; /**************** Set Net Info ****************/ /* @@ -147,19 +147,19 @@ virtual bool assignPeersToGroup(const std::string &groupId, const std::list &ids); -virtual bool removeAllFriendLocations(const std::string &gpgid); +virtual bool getAssociatedPeers(const PGPIdType &gpg_id, std::list &ids); +virtual bool removeAllFriendLocations(const PGPIdType &gpgid); /******************** Groups **********************/ @@ -247,19 +247,19 @@ virtual bool assignPeersToGroup(const std::string &groupId, const std::list mFriendList; // - std::map mOthersList; + std::map mFriendList; // + std::map mOthersList; std::list groupList; uint32_t lastGroupId; std::list saveCleanupList; /* TEMPORARY LIST WHEN SAVING */ - std::map mFriendsPermissionFlags ; // permission flags for each gpg key + std::map mFriendsPermissionFlags ; // permission flags for each gpg key struct sockaddr_storage mProxyServerAddress; }; diff --git a/libretroshare/src/pqi/pqiarchive.cc b/libretroshare/src/pqi/pqiarchive.cc index 34865c6a9..e6d3d65e1 100644 --- a/libretroshare/src/pqi/pqiarchive.cc +++ b/libretroshare/src/pqi/pqiarchive.cc @@ -37,6 +37,8 @@ * */ +#ifdef SUSPENDED_UNUSED_CODE + #include "pqi/pqiarchive.h" #include "serialiser/rsserial.h" #include @@ -415,6 +417,6 @@ std::string pqiarchive::gethash() { return bio->gethash(); } - +#endif diff --git a/libretroshare/src/pqi/pqiarchive.h b/libretroshare/src/pqi/pqiarchive.h index 1c329bd33..e80d634b0 100644 --- a/libretroshare/src/pqi/pqiarchive.h +++ b/libretroshare/src/pqi/pqiarchive.h @@ -23,7 +23,7 @@ * */ - +#ifdef SUSPENDED_UNUSED_CODE #ifndef MRK_PQI_ARCHIVE_STREAMER_HEADER #define MRK_PQI_ARCHIVE_STREAMER_HEADER @@ -79,3 +79,4 @@ int readPkt(RsItem **item_out, long *ts); #endif //MRK_PQI_ARCHIVE_STREAMER_HEADER +#endif //SUSPENDED_UNUSED_CODE diff --git a/libretroshare/src/pqi/pqihandler.cc b/libretroshare/src/pqi/pqihandler.cc index 71e07d2cf..da0096ffa 100644 --- a/libretroshare/src/pqi/pqihandler.cc +++ b/libretroshare/src/pqi/pqihandler.cc @@ -69,7 +69,7 @@ int pqihandler::tick() RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/ // tick all interfaces... - std::map::iterator it; + std::map::iterator it; for(it = mods.begin(); it != mods.end(); it++) { if (0 < ((it -> second) -> pqi) -> tick()) @@ -113,7 +113,7 @@ bool pqihandler::queueOutRsItem(RsItem *item) int pqihandler::status() { - std::map::iterator it; + std::map::iterator it; RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/ { // for output @@ -142,7 +142,7 @@ bool pqihandler::AddSearchModule(SearchModule *mod) { RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/ // if peerid used -> error. - std::map::iterator it; + std::map::iterator it; if (mod->peerid != mod->pqi->PeerId()) { // ERROR! @@ -182,7 +182,7 @@ bool pqihandler::AddSearchModule(SearchModule *mod) bool pqihandler::RemoveSearchModule(SearchModule *mod) { RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/ - std::map::iterator it; + std::map::iterator it; for(it = mods.begin(); it != mods.end(); it++) { if (mod == it -> second) @@ -208,7 +208,7 @@ int pqihandler::locked_checkOutgoingRsItem(RsItem * /*item*/, int /*global*/) int pqihandler::locked_HandleRsItem(RsItem *item, int allowglobal,uint32_t& computed_size) { computed_size = 0 ; - std::map::iterator it; + std::map::iterator it; pqioutput(PQL_DEBUG_BASIC, pqihandlerzone, "pqihandler::HandleRsItem()"); @@ -302,7 +302,7 @@ int pqihandler::SendRsRawItem(RsRawItem *ns) int pqihandler::locked_GetItems() { - std::map::iterator it; + std::map::iterator it; RsItem *item; int count = 0; @@ -410,7 +410,7 @@ RsRawItem *pqihandler::GetRsRawItem() static const float MIN_RATE = 0.01; // 10 B/s // NEW extern fn to extract rates. -int pqihandler::ExtractRates(std::map &ratemap, RsBwRates &total) +int pqihandler::ExtractRates(std::map &ratemap, RsBwRates &total) { total.mMaxRateIn = getMaxRate(true); total.mMaxRateOut = getMaxRate(false); @@ -422,7 +422,7 @@ int pqihandler::ExtractRates(std::map &ratemap, RsBw /* Lock once rates have been retrieved */ RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/ - std::map::iterator it; + std::map::iterator it; for(it = mods.begin(); it != mods.end(); it++) { SearchModule *mod = (it -> second); @@ -447,7 +447,7 @@ int pqihandler::ExtractRates(std::map &ratemap, RsBw // internal fn to send updates int pqihandler::UpdateRates() { - std::map::iterator it; + std::map::iterator it; int num_sm = mods.size(); float avail_in = getMaxRate(true); diff --git a/libretroshare/src/pqi/pqihandler.h b/libretroshare/src/pqi/pqihandler.h index 3cafa62e7..bc5043738 100644 --- a/libretroshare/src/pqi/pqihandler.h +++ b/libretroshare/src/pqi/pqihandler.h @@ -31,6 +31,7 @@ #include "pqi/pqiqos.h" #include "util/rsthreads.h" +#include "retroshare/rstypes.h" #include #include @@ -38,7 +39,7 @@ class SearchModule { public: - std::string peerid; + RsPeerId peerid; PQInterface *pqi; SecurityPolicy *sp; }; @@ -75,7 +76,7 @@ class pqihandler: public P3Interface, public pqiPublisher void getCurrentRates(float &in, float &out); // TESTING INTERFACE. - int ExtractRates(std::map &ratemap, RsBwRates &totals); + int ExtractRates(std::map &ratemap, RsBwRates &totals); protected: /* check to be overloaded by those that can @@ -91,7 +92,7 @@ class pqihandler: public P3Interface, public pqiPublisher RsMutex coreMtx; /* MUTEX */ - std::map mods; + std::map mods; SecurityPolicy *globsec; std::list in_service; diff --git a/libretroshare/src/pqi/pqihash.h b/libretroshare/src/pqi/pqihash.h index b47f3da3a..267f8df54 100644 --- a/libretroshare/src/pqi/pqihash.h +++ b/libretroshare/src/pqi/pqihash.h @@ -26,7 +26,7 @@ #ifndef PQI_HASH_ #define PQI_HASH_ -#include +#include #include #include #include diff --git a/libretroshare/src/pqi/pqimonitor.h b/libretroshare/src/pqi/pqimonitor.h index 3016308db..550af6e9c 100644 --- a/libretroshare/src/pqi/pqimonitor.h +++ b/libretroshare/src/pqi/pqimonitor.h @@ -35,6 +35,7 @@ #include #include #include "pqi/pqiipset.h" +#include "retroshare/rsids.h" /************** Define Type/Mode/Source ***************/ @@ -96,11 +97,11 @@ const uint32_t RS_STUN_FRIEND_OF_FRIEND = 0x0040; class pqipeer { - public: -std::string id; -std::string name; -uint32_t state; -uint32_t actions; + public: + SSLIdType id; + std::string name; + uint32_t state; + uint32_t actions; }; class p3LinkMgr; diff --git a/libretroshare/src/pqi/pqissllistener.cc b/libretroshare/src/pqi/pqissllistener.cc index a9bbc9492..ae86a1a4e 100644 --- a/libretroshare/src/pqi/pqissllistener.cc +++ b/libretroshare/src/pqi/pqissllistener.cc @@ -367,8 +367,8 @@ int pqissllistenbase::acceptconnection() incoming_connexion_info.ssl = SSL_new(AuthSSL::getAuthSSL() -> getCTX()); incoming_connexion_info.addr = remote_addr ; - incoming_connexion_info.gpgid = "" ; - incoming_connexion_info.sslid = "" ; + incoming_connexion_info.gpgid.clear() ; + incoming_connexion_info.sslid.clear() ; incoming_connexion_info.sslcn = "" ; 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. // - AuthSSL::getAuthSSL()->setCurrentConnectionAttemptInfo(std::string(),std::string(),std::string()) ; + AuthSSL::getAuthSSL()->setCurrentConnectionAttemptInfo(PGPIdType(),RsPeerId(),std::string()) ; int err = SSL_accept(incoming_connexion_info.ssl); @@ -690,14 +690,14 @@ pqissllistener::~pqissllistener() return; } -int pqissllistener::addlistenaddr(std::string id, pqissl *acc) +int pqissllistener::addlistenaddr(const RsPeerId& id, pqissl *acc) { - std::map::iterator it; + std::map::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++) { - out += id + "\n"; + out += id.toStdString() + "\n"; if (it -> first == id) { out += "pqissllistener::addlistenaddr() Already listening for Certificate!\n"; @@ -715,13 +715,13 @@ int pqissllistener::addlistenaddr(std::string id, pqissl *acc) return 1; } -int pqissllistener::removeListenPort(std::string id) +int pqissllistener::removeListenPort(const RsPeerId& id) { // check where the connection is coming from. // if in list of acceptable addresses, // // check if in list. - std::map::iterator it; + std::map::iterator it; for(it = listenaddr.begin();it!=listenaddr.end();it++) { if (it->first == id) @@ -745,14 +745,14 @@ int pqissllistener::status() { pqissllistenbase::status(); // print certificates we are listening for. - std::map::iterator it; + std::map::iterator it; std::string out = "pqissllistener::status(): Listening ("; out += sockaddr_storage_tostring(laddr); out += ") for Certs:"; for(it = listenaddr.begin(); it != listenaddr.end(); it++) { - out += "\n" + it -> first ; + out += "\n" + it -> first.toStdString() ; } pqioutput(PQL_DEBUG_ALL, pqissllistenzone, out); @@ -776,7 +776,7 @@ int pqissllistener::completeConnection(int fd, IncomingSSLInfo& info) } // 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 found = false; - std::map::iterator it; + std::map::iterator it; // Let connected one through as well! if ((npc == NULL) || (npc -> Connected())) if (!certOk) @@ -803,11 +803,11 @@ int pqissllistener::completeConnection(int fd, IncomingSSLInfo& info) } 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..... for(it = listenaddr.begin();(found!=true) && (it!=listenaddr.end());) { - out + "\tagainst: " + it->first + "\n"; + out + "\tagainst: " + it->first.toStdString() + "\n"; if (it -> first == newPeerId) { // accept even if already connected. @@ -836,7 +836,7 @@ int pqissllistener::completeConnection(int fd, IncomingSSLInfo& info) AuthSSL::getAuthSSL()->CheckCertificate(newPeerId, peercert); /* 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); X509_free(peercert); @@ -856,7 +856,7 @@ int pqissllistener::completeConnection(int fd, IncomingSSLInfo& info) 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 += sockaddr_storage_tostring(info.addr); out += " Adding to WAIT-ACCEPT Queue"; @@ -865,12 +865,12 @@ int pqissllistener::completeConnection(int fd, IncomingSSLInfo& info) 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::iterator it; + std::map::iterator it; std::string out = "pqissllistener::finaliseConnection()\n"; - out += "checking: " + peerId + "\n"; + out += "checking: " + peerId.toStdString() + "\n"; // check if cert is in the list..... it = listenaddr.find(peerId); diff --git a/libretroshare/src/pqi/pqissllistener.h b/libretroshare/src/pqi/pqissllistener.h index 74260e6e2..2a595f7b0 100644 --- a/libretroshare/src/pqi/pqissllistener.h +++ b/libretroshare/src/pqi/pqissllistener.h @@ -53,7 +53,7 @@ class AcceptedSSL int mFd; SSL *mSSL; - std::string mPeerId; + RsPeerId mPeerId; struct sockaddr_storage mAddr; time_t mAcceptTS; @@ -89,8 +89,8 @@ int finaliseAccepts(); { SSL *ssl ; sockaddr_storage addr ; - std::string gpgid ; - std::string sslid ; + PGPIdType gpgid ; + SSLIdType sslid ; std::string sslcn ; }; @@ -100,7 +100,7 @@ int closeConnection(int fd, SSL *ssl); int isSSLActive(int fd, SSL *ssl); 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: struct sockaddr_storage laddr; @@ -129,18 +129,18 @@ class pqissllistener: public pqissllistenbase pqissllistener(const struct sockaddr_storage &addr, p3PeerMgr *pm); virtual ~pqissllistener(); -int addlistenaddr(std::string id, pqissl *acc); -int removeListenPort(std::string id); +int addlistenaddr(const RsPeerId& id, pqissl *acc); +int removeListenPort(const RsPeerId& id); //virtual int tick(); virtual int status(); 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: - std::map listenaddr; + std::map listenaddr; }; diff --git a/libretroshare/src/pqi/pqistreamer.cc b/libretroshare/src/pqi/pqistreamer.cc index b365ab260..dc1d438a7 100644 --- a/libretroshare/src/pqi/pqistreamer.cc +++ b/libretroshare/src/pqi/pqistreamer.cc @@ -51,7 +51,7 @@ const int PQISTREAM_ABS_MAX = 100000000; /* 100 MB/sec (actually per loop) */ #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"), mBio(bio_in), mBio_flags(bio_flags_in), mRsSerialiser(rss), mPkt_wpending(NULL), diff --git a/libretroshare/src/pqi/pqistreamer.h b/libretroshare/src/pqi/pqistreamer.h index ce6555532..b957f7de4 100644 --- a/libretroshare/src/pqi/pqistreamer.h +++ b/libretroshare/src/pqi/pqistreamer.h @@ -30,6 +30,7 @@ // Only dependent on the base stuff. #include "pqi/pqi_base.h" #include "util/rsthreads.h" +#include "retroshare/rstypes.h" #include @@ -42,7 +43,7 @@ class pqistreamer: public PQInterface { 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(); // PQInterface diff --git a/libretroshare/src/retroshare/rsfiles.h b/libretroshare/src/retroshare/rsfiles.h index fbde51b61..93e9110d2 100644 --- a/libretroshare/src/retroshare/rsfiles.h +++ b/libretroshare/src/retroshare/rsfiles.h @@ -119,7 +119,7 @@ class RsFiles 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. - virtual bool FileRequest(const std::string& fname, const std::string& hash, uint64_t size, const std::string& dest, TransferRequestFlags flags, const std::list& 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& srcIds) = 0; virtual bool FileCancel(const std::string& hash) = 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; @@ -155,7 +155,7 @@ class RsFiles virtual bool FileDownloadChunksDetails(const std::string& hash,FileChunksInfo& info) = 0 ; /// 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 @@ -172,14 +172,14 @@ class RsFiles /*** * 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 uint32_t getType(void *ref,FileSearchFlags flags) = 0; virtual int SearchKeywords(std::list keywords, std::list &results,FileSearchFlags flags) = 0; - virtual int SearchKeywords(std::list keywords, std::list &results,FileSearchFlags flags,const std::string& peer_id) = 0; + virtual int SearchKeywords(std::list keywords, std::list &results,FileSearchFlags flags,const SSLIdType& peer_id) = 0; virtual int SearchBoolExp(Expression * exp, std::list &results,FileSearchFlags flags) = 0; - virtual int SearchBoolExp(Expression * exp, std::list &results,FileSearchFlags flags,const std::string& peer_id) = 0; + virtual int SearchBoolExp(Expression * exp, std::list &results,FileSearchFlags flags,const SSLIdType& peer_id) = 0; /*** * Utility Functions. diff --git a/libretroshare/src/retroshare/rsgxscircles.h b/libretroshare/src/retroshare/rsgxscircles.h index 9168f5876..eb89145cc 100644 --- a/libretroshare/src/retroshare/rsgxscircles.h +++ b/libretroshare/src/retroshare/rsgxscircles.h @@ -43,7 +43,6 @@ extern RsGxsCircles *rsGxsCircles; typedef std::string RsGxsCircleId; -typedef std::string RsPeerId; // SSL ID. typedef std::string RsPgpId; typedef std::string RsCircleInternalId; diff --git a/libretroshare/src/retroshare/rsids.h b/libretroshare/src/retroshare/rsids.h new file mode 100644 index 000000000..1ccd59334 --- /dev/null +++ b/libretroshare/src/retroshare/rsids.h @@ -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 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 +#include +#include +#include +#include +#include +#include + +template 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 random() + { + t_RsGenericIdType id ; + + for(uint32_t i=0;i& fp) const { return !memcmp(bytes,fp.bytes,ID_SIZE_IN_BYTES) ; } + inline bool operator!=(const t_RsGenericIdType& fp) const { return !!memcmp(bytes,fp.bytes,ID_SIZE_IN_BYTES); } + inline bool operator< (const t_RsGenericIdType& fp) const { return (memcmp(bytes,fp.bytes,ID_SIZE_IN_BYTES) < 0) ; } + + inline bool isNull() const + { + for(int i=0;i& id) + { + return out << id.toStdString() ; + } + private: + unsigned char bytes[ID_SIZE_IN_BYTES] ; +}; + +template std::string t_RsGenericIdType::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 t_RsGenericIdType::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 t_RsGenericIdType::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 ; + diff --git a/libretroshare/src/retroshare/rspeers.h b/libretroshare/src/retroshare/rspeers.h index f1533fa89..cf267d79a 100644 --- a/libretroshare/src/retroshare/rspeers.h +++ b/libretroshare/src/retroshare/rspeers.h @@ -32,6 +32,7 @@ #include #include +#include /* The Main Interface Class - for information about your Peers * A peer is another RS instance, means associated with an SSL certificate @@ -186,18 +187,19 @@ class RsPeerDetails /* Auth details */ bool isOnlyGPGdetail; - std::string id; - std::string gpg_id; + SSLIdType id; + PGPIdType gpg_id; + std::string name; std::string email; std::string location; std::string org; - std::string issuer; + PGPIdType issuer; - std::string fpr; /* pgp fingerprint */ - std::string authcode; - std::list gpgSigners; + PGPFingerprintType fpr; /* pgp fingerprint */ + //std::string authcode; // (cyril) what is this used for ????? + std::list gpgSigners; uint32_t trustLvl; uint32_t validLvl; @@ -272,7 +274,7 @@ public: std::string name; uint32_t flag; - std::list peerIds; + std::list peerIds; }; std::ostream &operator<<(std::ostream &out, const RsPeerDetails &detail); @@ -289,54 +291,55 @@ class RsPeers virtual bool OthersChanged() = 0; /* 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 &ssl_ids) = 0; - virtual bool getFriendList(std::list &ssl_ids) = 0; - //virtual bool getOthersList(std::list &ssl_ids) = 0; + virtual bool getOnlineList(std::list &ssl_ids) = 0; + virtual bool getFriendList(std::list &ssl_ids) = 0; virtual bool getPeerCount (unsigned int *pnFriendCount, unsigned int *pnnOnlineCount, bool ssl) = 0; - virtual bool isOnline(const std::string &ssl_id) = 0; - virtual bool isFriend(const std::string &ssl_id) = 0; - virtual bool isGPGAccepted(const std::string &gpg_id_is_friend) = 0; // - virtual std::string getPeerName(const std::string &ssl_or_gpg_id) = 0; - virtual std::string getGPGName(const std::string &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 isOnline(const SSLIdType &ssl_id) = 0; + virtual bool isFriend(const SSLIdType &ssl_id) = 0; + virtual bool isGPGAccepted(const PGPIdType &gpg_id_is_friend) = 0; // + virtual std::string getPeerName(const SSLIdType &ssl_id) = 0; + virtual std::string getGPGName(const PGPIdType& gpg_id) = 0; + virtual bool getPeerDetails(const SSLIdType& ssl_id, RsPeerDetails &d) = 0; + virtual bool getGPGDetails(const PGPIdType& gpg_id, RsPeerDetails &d) = 0; /* Using PGP Ids */ - virtual std::string 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 bool isKeySupported(const std::string& gpg_ids) = 0; - virtual bool getGPGAcceptedList(std::list &gpg_ids) = 0; - virtual bool getGPGSignedList(std::list &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 &gpg_ids) = 0; - virtual bool getGPGAllList(std::list &gpg_ids) = 0; - virtual bool getGPGDetails(const std::string &gpg_id, RsPeerDetails &d) = 0; - virtual bool getAssociatedSSLIds(const std::string &gpg_id, std::list &ids) = 0; + virtual PGPIdType getGPGOwnId() = 0; + virtual PGPIdType getGPGId(const SSLIdType& sslid) = 0; //return the gpg id of the given ssl id + virtual bool isKeySupported(const PGPIdType& gpg_ids) = 0; + virtual bool getGPGAcceptedList(std::list &gpg_ids) = 0; + virtual bool getGPGSignedList(std::list &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 &gpg_ids) = 0; + virtual bool getGPGAllList(std::list &gpg_ids) = 0; + virtual bool getAssociatedSSLIds(const PGPIdType& gpg_id, std::list& ids) = 0; virtual bool gpgSignData(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen) = 0; /* 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 removeFriend(const std::string &ssl_or_gpg_id) = 0; - virtual bool removeFriendLocation(const std::string &sslId) = 0; + virtual bool addFriend(const SSLIdType &ssl_id, const PGPIdType &gpg_id,ServicePermissionFlags flags = RS_SERVICE_PERM_ALL) = 0; + virtual bool removeFriend(const PGPIdType& pgp_id) = 0; + virtual bool removeFriend(const SSLIdType& ssl_id) = 0; + + virtual bool removeFriendLocation(const SSLIdType& sslId) = 0; /* keyring management */ - virtual bool removeKeysFromPGPKeyring(const std::list& pgp_ids,std::string& backup_file,uint32_t& error_code)=0 ; + virtual bool removeKeysFromPGPKeyring(const std::list& pgp_ids,std::string& backup_file,uint32_t& error_code)=0 ; /* Network Stuff */ - virtual bool connectAttempt(const std::string &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 connectAttempt(const SSLIdType& ssl_id) = 0; + 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 std::string &id, const std::string &address, uint16_t port) = 0; + virtual bool setHiddenNode(const SSLIdType &id, const std::string &hidden_node_address) = 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 setExtAddress( const std::string &ssl_id, const std::string &addr, uint16_t port) = 0; - virtual bool setDynDNS(const std::string &id, const std::string &addr) = 0; - virtual bool setNetworkMode(const std::string &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 setLocalAddress(const SSLIdType &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 SSLIdType &id, const std::string &addr) = 0; + virtual bool setNetworkMode(const SSLIdType &ssl_id, uint32_t netMode) = 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 setProxyServer(const std::string &addr, const uint16_t port) = 0; @@ -346,24 +349,24 @@ class RsPeers virtual bool getAllowServerIPDetermination() = 0 ; /* Auth Stuff */ - virtual std::string GetRetroshareInvite(const std::string& 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 std::string GetRetroshareInvite(const SSLIdType& ssl_id,bool include_signatures) = 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 bool hasExportMinimal() = 0 ; // 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. virtual bool loadDetailsFromStringCert(const std::string& certGPG, RsPeerDetails &pd,uint32_t& error_code) = 0; // Certificate utils 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 std::string saveCertificateToString(const std::string &id) = 0; + virtual bool saveCertificateToFile(const SSLIdType& id, const std::string &fname) = 0; + virtual std::string saveCertificateToString(const SSLIdType &id) = 0; - virtual bool signGPGCertificate(const std::string &gpg_id) = 0; - virtual bool trustGPGCertificate(const std::string &gpg_id, uint32_t trustlvl) = 0; + virtual bool signGPGCertificate(const PGPIdType &gpg_id) = 0; + virtual bool trustGPGCertificate(const PGPIdType &gpg_id, uint32_t trustlvl) = 0; /* Group Stuff */ virtual bool addGroup(RsGroupInfo &groupInfo) = 0; @@ -372,8 +375,8 @@ class RsPeers virtual bool getGroupInfo(const std::string &groupId, RsGroupInfo &groupInfo) = 0; virtual bool getGroupInfoList(std::list &groupInfoList) = 0; // groupId == "" && assign == false -> remove from all groups - virtual bool assignPeerToGroup(const std::string &groupId, const std::string &peerId, bool assign) = 0; - virtual bool assignPeersToGroup(const std::string &groupId, const std::list &peerIds, 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 &peerIds, bool assign) = 0; /* 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 // 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& file_parent_groups) = 0; + virtual FileSearchFlags computePeerPermissionFlags(const SSLIdType& peer_id,FileStorageFlags file_sharing_flags,const std::list& file_parent_groups) = 0; /* Service permission flags */ - virtual ServicePermissionFlags servicePermissionFlags(const std::string& gpg_id) = 0; - virtual ServicePermissionFlags servicePermissionFlags_sslid(const std::string& ssl_id) = 0; - virtual void setServicePermissionFlags(const std::string& gpg_id,const ServicePermissionFlags& flags) = 0; + virtual ServicePermissionFlags servicePermissionFlags(const PGPIdType& gpg_id) = 0; + virtual ServicePermissionFlags servicePermissionFlags(const SSLIdType& ssl_id) = 0; + virtual void setServicePermissionFlags(const PGPIdType& gpg_id,const ServicePermissionFlags& flags) = 0; }; #endif diff --git a/libretroshare/src/retroshare/rsturtle.h b/libretroshare/src/retroshare/rsturtle.h index e66ab7367..b0725551c 100644 --- a/libretroshare/src/retroshare/rsturtle.h +++ b/libretroshare/src/retroshare/rsturtle.h @@ -33,6 +33,8 @@ #include #include +#include "retroshare/rsids.h" + class LinearizedExpression ; class RsTurtleClientService ; @@ -54,7 +56,7 @@ struct TurtleFileInfo struct TurtleRequestDisplayInfo { 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 depth ; // Depth of the request. Might be altered. }; @@ -134,7 +136,7 @@ class RsTurtle virtual void getTrafficStatistics(TurtleTrafficStatisticsInfo& info) const = 0; // Convenience function. - virtual bool isTurtlePeer(const std::string& peer_id) const = 0 ; + virtual bool isTurtlePeer(const SSLIdType& peer_id) const = 0 ; // Hardcore handles virtual void setMaxTRForwardRate(int max_tr_up_rate) = 0 ; diff --git a/libretroshare/src/retroshare/rstypes.h b/libretroshare/src/retroshare/rstypes.h index 9ffaf6637..cdb028a18 100644 --- a/libretroshare/src/retroshare/rstypes.h +++ b/libretroshare/src/retroshare/rstypes.h @@ -33,8 +33,8 @@ #include #include #include -#include +#include #include #define USE_NEW_CHUNK_CHECKING_CODE @@ -43,6 +43,7 @@ typedef std::string RsCertId; typedef std::string RsChanId; typedef std::string RsMsgId; typedef std::string RsAuthId; +typedef SSLIdType RsPeerId ; const uint32_t FT_STATE_FAILED = 0x0000 ; const uint32_t FT_STATE_OKAY = 0x0001 ; @@ -84,7 +85,7 @@ class TransferInfo { public: /**** Need Some of these Fields ****/ - std::string peerId; + SSLIdType peerId; std::string name; /* if has alternative name? */ double tfRate; /* kbytes */ int status; /* FT_STATE_... */ @@ -235,7 +236,7 @@ class DirDetails void *ref; uint8_t type; - std::string id; + SSLIdType id; std::string name; std::string hash; std::string path; @@ -251,7 +252,7 @@ class DirDetails class FileDetail { public: - std::string id; + SSLIdType id; std::string name; std::string hash; std::string path; @@ -272,7 +273,7 @@ class FileChunksInfo { uint32_t start ; uint32_t size ; - std::string peer_id ; + RsPeerId peer_id ; }; uint64_t file_size ; // real size of the file @@ -283,7 +284,7 @@ class FileChunksInfo std::vector chunks ; // For each source peer, gives the compressed bit map of have/don't have sate - std::map compressed_peer_availability_maps ; + std::map compressed_peer_availability_maps ; // For each chunk (by chunk number), gives the completion of the chunk. // diff --git a/libretroshare/src/serialiser/rsbaseserial.h b/libretroshare/src/serialiser/rsbaseserial.h index 51a4eee3c..7263ad480 100644 --- a/libretroshare/src/serialiser/rsbaseserial.h +++ b/libretroshare/src/serialiser/rsbaseserial.h @@ -29,7 +29,7 @@ #include #include #include -#include +#include /******************************************************************* * This is at the lowlevel packing routines. They are usually diff --git a/libretroshare/src/serialiser/rsconfigitems.cc b/libretroshare/src/serialiser/rsconfigitems.cc index c67cdab92..2b1bb7f1f 100644 --- a/libretroshare/src/serialiser/rsconfigitems.cc +++ b/libretroshare/src/serialiser/rsconfigitems.cc @@ -112,7 +112,7 @@ void RsFileTransfer::clear() file.TlvClear(); allPeerIds.TlvClear(); - cPeerId = ""; + cPeerId.clear() ; state = 0; in = false; transferred = 0; @@ -197,7 +197,7 @@ uint32_t RsFileConfigSerialiser::sizeTransfer(RsFileTransfer *item) uint32_t s = 8; /* header */ s += item->file.TlvSize(); s += item->allPeerIds.TlvSize(); - s += GetTlvStringSize(item->cPeerId); + s += SSLIdType::SIZE_IN_BYTES; s += 2; /* state */ s += 2; /* in/out */ s += 8; /* transferred */ @@ -239,7 +239,7 @@ bool RsFileConfigSerialiser::serialiseTransfer(RsFileTransfer *item, void *d ok &= item->file.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->in); @@ -305,8 +305,7 @@ RsFileTransfer *RsFileConfigSerialiser::deserialiseTransfer(void *data, uint32_t ok &= item->file.GetTlv(data, rssize, &offset); ok &= item->allPeerIds.GetTlv(data, rssize, &offset); - /* string */ - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_PEERID, item->cPeerId); + ok &= getRawSSLId(data, rssize, &offset, item->cPeerId); /* data */ ok &= getRawUInt16(data, rssize, &offset, &(item->state)); diff --git a/libretroshare/src/serialiser/rsconfigitems.h b/libretroshare/src/serialiser/rsconfigitems.h index b06c92370..7e1e1cb29 100644 --- a/libretroshare/src/serialiser/rsconfigitems.h +++ b/libretroshare/src/serialiser/rsconfigitems.h @@ -254,7 +254,7 @@ class RsFileTransfer: public RsItem RsTlvFileItem file; RsTlvPeerIdSet allPeerIds; - std::string cPeerId; + SSLIdType cPeerId; uint16_t state; uint16_t in; diff --git a/libretroshare/src/serialiser/rsserial.h b/libretroshare/src/serialiser/rsserial.h index 563e96446..70255c529 100644 --- a/libretroshare/src/serialiser/rsserial.h +++ b/libretroshare/src/serialiser/rsserial.h @@ -34,6 +34,8 @@ #include #include +#include "retroshare/rsids.h" + /******************************************************************* * 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); /* source / destination id */ - const std::string& PeerId() const { return peerId; } - void PeerId(const std::string& id) { peerId = id; } + const SSLIdType& PeerId() const { return peerId; } + void PeerId(const SSLIdType& id) { peerId = id; } /* complete id */ uint32_t PacketId() const; @@ -104,7 +106,7 @@ class RsItem: public RsMemoryManagement::SmallObject inline void setPriorityLevel(uint8_t l) { _priority_level = l ;} private: uint32_t type; - std::string peerId; + SSLIdType peerId; uint8_t _priority_level ; }; diff --git a/libretroshare/src/turtle/p3turtle.cc b/libretroshare/src/turtle/p3turtle.cc index a1140f316..d9f80280a 100644 --- a/libretroshare/src/turtle/p3turtle.cc +++ b/libretroshare/src/turtle/p3turtle.cc @@ -261,14 +261,16 @@ int p3turtle::tick() // void p3turtle::locked_addDistantPeer(const TurtleFileHash&,TurtleTunnelId tid) { - char buff[400] ; - sprintf(buff,"Anonymous F2F tunnel %08x",tid) ; + unsigned char tmp[SSLIdType::SIZE_IN_BYTES] ; - _virtual_peers[TurtleVirtualPeerId(buff)] = tid ; + ((uint32_t*)tmp)[0] = tid ; + SSLIdType virtual_peer_id(tmp) ; + + _virtual_peers[virtual_peer_id] = tid ; #ifdef P3TURTLE_DEBUG assert(_local_tunnels.find(tid)!=_local_tunnels.end()) ; #endif - _local_tunnels[tid].vpid = TurtleVirtualPeerId(buff) ; + _local_tunnels[tid].vpid = virtual_peer_id ; } void p3turtle::getSourceVirtualPeersList(const TurtleFileHash& hash,std::list& 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 // 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 decal = 0 ; @@ -750,7 +752,7 @@ int p3turtle::handleIncoming() { 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 ; else { @@ -891,15 +893,15 @@ void p3turtle::handleSearchRequest(RsTurtleSearchRequestItem *item) if(item->depth < TURTLE_MAX_SEARCH_DEPTH || random_bypass) { - std::list onlineIds ; + std::list onlineIds ; mLinkMgr->getOnlineList(onlineIds); #ifdef P3TURTLE_DEBUG std::cerr << " Looking for online peers" << std::endl ; #endif - for(std::list::const_iterator it(onlineIds.begin());it!=onlineIds.end();++it) + for(std::list::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 ; uint32_t linkType = mLinkMgr->getLinkType(*it); @@ -1085,7 +1087,7 @@ void p3turtle::handleRecvGenericTunnelItem(RsTurtleGenericTunnelItem *item) item->print(std::cerr,1) ; #endif std::string hash ; - std::string vpid ; + SSLIdType vpid ; RsTurtleClientService *service ; if(!getTunnelServiceInfo(item->tunnelId(),vpid,hash,service)) @@ -1094,23 +1096,7 @@ void p3turtle::handleRecvGenericTunnelItem(RsTurtleGenericTunnelItem *item) service->receiveTurtleData(item,hash,vpid,item->travelingDirection()) ; } -//void p3turtle::handleRecvGenericDataItem(RsTurtleGenericDataItem *item) -//{ -//#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) +bool p3turtle::getTunnelServiceInfo(TurtleTunnelId tunnel_id,SSLIdType& vpid,std::string& hash,RsTurtleClientService *& service) { 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. // - std::string ownid = mLinkMgr->getOwnId() ; + SSLIdType ownid = mLinkMgr->getOwnId() ; 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 // -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 ******/ @@ -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. - std::string ownid = mLinkMgr->getOwnId() ; + SSLIdType ownid = mLinkMgr->getOwnId() ; uint32_t ss = item->serial_size() ; if(item->shouldStampTunnel()) @@ -1237,14 +1223,14 @@ void p3turtle::sendTurtleData(const std::string& virtual_peer_id,RsTurtleGeneric 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 ******/ 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 ******/ @@ -1258,7 +1244,7 @@ std::string p3turtle::getTurtlePeerId(TurtleTunnelId tid) const 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 ******/ @@ -1278,7 +1264,7 @@ TurtleRequestId p3turtle::diggTunnel(const TurtleFileHash& hash) #ifdef P3TURTLE_DEBUG std::cerr << "DiggTunnel: performing tunnel request. OwnId = " << mLinkMgr->getOwnId() << " for hash=" << hash << std::endl ; #endif - while(mLinkMgr->getOwnId() == "") + while(mLinkMgr->getOwnId().isNull()) { std::cerr << "... waiting for connect manager to form own id." << std::endl ; #ifdef WIN32 @@ -1483,13 +1469,13 @@ void p3turtle::handleTunnelRequest(RsTurtleOpenTunnelItem *item) if(item->depth < TURTLE_MAX_SEARCH_DEPTH || random_bypass) { - std::list onlineIds ; + std::list onlineIds ; mLinkMgr->getOnlineList(onlineIds); - for(std::list::iterator it(onlineIds.begin());it!=onlineIds.end();) - if(!(RS_SERVICE_PERM_TURTLE & rsPeers->servicePermissionFlags_sslid(*it))) + for(std::list::iterator it(onlineIds.begin());it!=onlineIds.end();) + if(!(RS_SERVICE_PERM_TURTLE & rsPeers->servicePermissionFlags(*it))) { - std::list::iterator tmp = it++ ; + std::list::iterator tmp = it++ ; onlineIds.erase(tmp) ; } else @@ -1513,7 +1499,7 @@ void p3turtle::handleTunnelRequest(RsTurtleOpenTunnelItem *item) std::cerr << " Forwarding tunnel request: Looking for online peers" << std::endl ; #endif - for(std::list::const_iterator it(onlineIds.begin());it!=onlineIds.end();++it) + for(std::list::const_iterator it(onlineIds.begin());it!=onlineIds.end();++it) { uint32_t linkType = mLinkMgr->getLinkType(*it); @@ -1558,7 +1544,7 @@ void p3turtle::handleTunnelResult(RsTurtleTunnelOkItem *item) { bool new_tunnel = false ; TurtleFileHash new_hash ; - std::string new_vpid ; + SSLIdType new_vpid ; RsTurtleClientService *service = NULL ; { @@ -1773,7 +1759,7 @@ TurtleRequestId p3turtle::turtleSearch(const std::string& string_to_match) #ifdef P3TURTLE_DEBUG std::cerr << "performing search. OwnId = " << mLinkMgr->getOwnId() << std::endl ; #endif - while(mLinkMgr->getOwnId() == "") + while(mLinkMgr->getOwnId().isNull()) { std::cerr << "... waitting for connect manager to form own id." << std::endl ; #ifdef WIN32 @@ -1809,7 +1795,7 @@ TurtleRequestId p3turtle::turtleSearch(const LinearizedExpression& expr) #ifdef P3TURTLE_DEBUG std::cerr << "performing search. OwnId = " << mLinkMgr->getOwnId() << std::endl ; #endif - while(mLinkMgr->getOwnId() == "") + while(mLinkMgr->getOwnId().isNull()) { std::cerr << "... waitting for connect manager to form own id." << std::endl ; #ifdef WIN32 @@ -1889,7 +1875,7 @@ void p3turtle::returnSearchResult(RsTurtleSearchResultItem *item) /// 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. // -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()) 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)) ; info.forward_probabilities.clear() ; - std::list onlineIds ; + std::list onlineIds ; mLinkMgr->getOnlineList(onlineIds); int nb_online_ids = onlineIds.size() ; @@ -2026,12 +2012,12 @@ void p3turtle::getInfo( std::vector >& hashes_info, if(mLinkMgr->getPeerName(it->second.local_src,name)) tunnel.push_back(name) ; else - tunnel.push_back(it->second.local_src) ; + tunnel.push_back(it->second.local_src.toStdString()) ; if(mLinkMgr->getPeerName(it->second.local_dst,name)) tunnel.push_back(name) ; 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(printNumber(now-it->second.time_stamp) + " secs ago") ; diff --git a/libretroshare/src/turtle/p3turtle.h b/libretroshare/src/turtle/p3turtle.h index 7a7cc57aa..26f89e037 100644 --- a/libretroshare/src/turtle/p3turtle.h +++ b/libretroshare/src/turtle/p3turtle.h @@ -292,23 +292,23 @@ class p3turtle: public p3Service, public RsTurtle, public p3Config /************* Communication with clients *******************/ /// 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). - 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. virtual void setMaxTRForwardRate(int max_tr_up_rate) ; virtual int getMaxTRForwardRate() const ; /// 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. - std::string getTurtlePeerId(TurtleTunnelId tid) const ; + SSLIdType getTurtlePeerId(TurtleTunnelId tid) const ; /// returns the list of virtual peers for all tunnels. void getSourceVirtualPeersList(const TurtleFileHash& hash,std::list& list) ; /// 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: //--------------------------- Admin/Helper functions -------------------------// @@ -352,7 +352,7 @@ class p3turtle: public p3Service, public RsTurtle, public p3Config /// specific routing functions for handling particular packets. 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 void handleSearchRequest(RsTurtleSearchRequestItem *item); @@ -369,7 +369,7 @@ class p3turtle: public p3Service, public RsTurtle, public p3Config void returnSearchResult(RsTurtleSearchResultItem *item) ; /// 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 --------------------------------// diff --git a/libretroshare/src/turtle/turtleclientservice.h b/libretroshare/src/turtle/turtleclientservice.h index 887f3730a..59e1d17d2 100644 --- a/libretroshare/src/turtle/turtleclientservice.h +++ b/libretroshare/src/turtle/turtleclientservice.h @@ -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 // 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. // 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. // 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 ; } diff --git a/libretroshare/src/turtle/turtletypes.h b/libretroshare/src/turtle/turtletypes.h index e1dc80e12..94ca66426 100644 --- a/libretroshare/src/turtle/turtletypes.h +++ b/libretroshare/src/turtle/turtletypes.h @@ -2,8 +2,8 @@ #include "retroshare/rsturtle.h" -typedef std::string TurtlePeerId ; -typedef std::string TurtleVirtualPeerId ; +typedef SSLIdType TurtlePeerId ; +typedef SSLIdType TurtleVirtualPeerId ; typedef std::string TurtleFileHash ; typedef std::string TurtleFileName ;