From 154ef63474c03005c25582092df8740a992cb579 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 15 Feb 2010 20:44:37 +0000 Subject: [PATCH] removed potentially harmful code. Warning: needs make clean in libretroshare git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2335 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/ft/ftdatamultiplex.cc | 41 ++++++++++++++++--------- libretroshare/src/ft/ftdatamultiplex.h | 2 +- libretroshare/src/ft/ftfileprovider.h | 2 +- libretroshare/src/ft/ftserver.cc | 27 ++-------------- 4 files changed, 32 insertions(+), 40 deletions(-) diff --git a/libretroshare/src/ft/ftdatamultiplex.cc b/libretroshare/src/ft/ftdatamultiplex.cc index 2146a338b..690f3909f 100644 --- a/libretroshare/src/ft/ftdatamultiplex.cc +++ b/libretroshare/src/ft/ftdatamultiplex.cc @@ -563,6 +563,11 @@ bool ftDataMultiplex::locked_handleServerRequest(ftFileProvider *provider, std::string peerId, std::string hash, uint64_t size, uint64_t offset, uint32_t chunksize) { + if(chunksize > std::min(size,uint64_t(10*1024*1024))) + { + std::cerr << "Warning: peer " << peerId << " is asking a large chunk (s=" << chunksize << ") for hash " << hash << ", filesize=" << size << ". This is unexpected." << std::endl ; + return false ; + } void *data = malloc(chunksize); if(data == NULL) @@ -600,7 +605,7 @@ bool ftDataMultiplex::locked_handleServerRequest(ftFileProvider *provider, bool ftDataMultiplex::getClientChunkMap(const std::string& upload_hash,const std::string& peerId,CompressedChunkMap& cmap) { - bool too_old ; + bool too_old = false; { RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/ @@ -625,24 +630,32 @@ bool ftDataMultiplex::sendChunkMapRequest(const std::string& peer_id,const std:: return mDataSend->sendChunkMapRequest(peer_id,hash); } -void ftDataMultiplex::deleteServers(const std::list& serv) +void ftDataMultiplex::deleteUnusedServers() { RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/ - for(std::list::const_iterator it=serv.begin();it != serv.end(); it++) - { - std::map::iterator sit = mServers.find(*it); + //scan the uploads list in ftdatamultiplex and delete the items which time out + time_t now = time(NULL); + + for(std::map::iterator sit(mServers.begin());sit != mServers.end();) + if ((now - sit->second->lastTS) > 10) + { +#ifdef SERVER_DEBUG + std::cout << "info.lastTS = " << info.lastTS << ", now=" << now << std::endl ; +#endif + // We don't delete servers that are clients at the same time ! + if(dynamic_cast(sit->second) == NULL) + delete sit->second; - if(mServers.end() != sit) - { - // Only delete servers that are not also file creators! - // - if(dynamic_cast(sit->second) == NULL) - delete sit->second; + std::map::iterator tmp(sit); + ++tmp ; - mServers.erase(sit); - } - } + mServers.erase(sit); + + sit = tmp ; + } + else + ++sit ; } bool ftDataMultiplex::handleSearchRequest(const std::string& peerId, const std::string& hash) diff --git a/libretroshare/src/ft/ftdatamultiplex.h b/libretroshare/src/ft/ftdatamultiplex.h index b00d5b7cc..43de26e76 100644 --- a/libretroshare/src/ft/ftdatamultiplex.h +++ b/libretroshare/src/ft/ftdatamultiplex.h @@ -96,7 +96,7 @@ class ftDataMultiplex: public ftDataRecv, public RsQueueThread bool FileDownloads(std::list &hashs); bool FileDetails(std::string hash, uint32_t hintsflag, FileInfo &info); - void deleteServers(const std::list& serv_hash) ; + void deleteUnusedServers() ; /*************** SEND INTERFACE (calls ftDataSend) *******************/ diff --git a/libretroshare/src/ft/ftfileprovider.h b/libretroshare/src/ft/ftfileprovider.h index e51718499..616abc0d5 100644 --- a/libretroshare/src/ft/ftfileprovider.h +++ b/libretroshare/src/ft/ftfileprovider.h @@ -59,6 +59,7 @@ class ftFileProvider void getClientMap(const std::string& peer_id,CompressedChunkMap& cmap,bool& map_is_too_old) ; void setClientMap(const std::string& peer_id,const CompressedChunkMap& cmap) ; + time_t lastTS; // used for checking if it's alive protected: virtual int initializeFileAttrs(); /* does for both */ @@ -74,7 +75,6 @@ class ftFileProvider std::string lastRequestor; uint64_t req_loc; uint32_t req_size; - time_t lastTS; // used for checking if it's alive time_t lastTS_t; // used for estimating transfer rate. // these two are used for speed estimation diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index 71951961a..967b41052 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -206,32 +206,11 @@ void ftServer::run() { while(1) { - //scan the uploads list in ftdatamultiplex and delete the items which time out - time_t now = time(NULL); - FileInfo info; - std::list toDels; - std::map::iterator sit; - for(sit = mFtDataplex->mServers.begin(); sit != mFtDataplex->mServers.end(); sit++) - { - if (FileDetails(sit->first,RS_FILE_HINTS_UPLOAD,info)) - { - if ((now - info.lastTS) > 10) - { -#ifdef SERVER_DEBUG - std::cout << "info.lastTS = " << info.lastTS << ", now=" << now << std::endl ; -#endif - toDels.push_back(sit->first); - } - } - } - - if(!toDels.empty()) - mFtDataplex->deleteServers(toDels) ; - + mFtDataplex->deleteUnusedServers() ; #ifdef WIN32 - Sleep(1000); + Sleep(5000); #else - sleep(1); + sleep(5); #endif } }