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
This commit is contained in:
csoler 2010-02-15 20:44:37 +00:00
parent 9303035d7f
commit 154ef63474
4 changed files with 32 additions and 40 deletions

View File

@ -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<std::string>& serv)
void ftDataMultiplex::deleteUnusedServers()
{
RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/
for(std::list<std::string>::const_iterator it=serv.begin();it != serv.end(); it++)
{
std::map<std::string,ftFileProvider *>::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<std::string, ftFileProvider *>::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<ftFileCreator*>(sit->second) == NULL)
delete sit->second;
if(mServers.end() != sit)
{
// Only delete servers that are not also file creators!
//
if(dynamic_cast<ftFileCreator*>(sit->second) == NULL)
delete sit->second;
std::map<std::string, ftFileProvider *>::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)

View File

@ -96,7 +96,7 @@ class ftDataMultiplex: public ftDataRecv, public RsQueueThread
bool FileDownloads(std::list<std::string> &hashs);
bool FileDetails(std::string hash, uint32_t hintsflag, FileInfo &info);
void deleteServers(const std::list<std::string>& serv_hash) ;
void deleteUnusedServers() ;
/*************** SEND INTERFACE (calls ftDataSend) *******************/

View File

@ -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

View File

@ -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<std::string> toDels;
std::map<std::string, ftFileProvider *>::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
}
}