mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
* Added lots of debugging.
* Partial bug fix for allocate algorithms. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@706 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
7b7446c5b5
commit
f243e5f6d3
@ -215,7 +215,7 @@ bool ftController::FileRequest(std::string fname, std::string hash,
|
|||||||
|
|
||||||
/* add in new item for download */
|
/* add in new item for download */
|
||||||
std::string savepath = mDownloadPath + "/" + fname;
|
std::string savepath = mDownloadPath + "/" + fname;
|
||||||
std::string chunker = "";
|
std::string chunker = "default";
|
||||||
ftFileCreator *fc = new ftFileCreator(savepath, size, hash, chunker);
|
ftFileCreator *fc = new ftFileCreator(savepath, size, hash, chunker);
|
||||||
ftTransferModule *tm = new ftTransferModule(fc, mDataplex);
|
ftTransferModule *tm = new ftTransferModule(fc, mDataplex);
|
||||||
|
|
||||||
|
@ -40,6 +40,8 @@ const uint32_t DMULTIPLEX_MIN = 10; /* 1ms sleep */
|
|||||||
const uint32_t DMULTIPLEX_MAX = 1000; /* 1 sec sleep */
|
const uint32_t DMULTIPLEX_MAX = 1000; /* 1 sec sleep */
|
||||||
const double DMULTIPLEX_RELAX = 0.5; /* ??? */
|
const double DMULTIPLEX_RELAX = 0.5; /* ??? */
|
||||||
|
|
||||||
|
#define MPLEX_DEBUG 1
|
||||||
|
|
||||||
ftClient::ftClient(ftTransferModule *module, ftFileCreator *creator)
|
ftClient::ftClient(ftTransferModule *module, ftFileCreator *creator)
|
||||||
:mModule(module), mCreator(creator)
|
:mModule(module), mCreator(creator)
|
||||||
{
|
{
|
||||||
@ -144,6 +146,10 @@ bool ftDataMultiplex::FileDetails(std::string hash, uint32_t hintsflag, FileI
|
|||||||
bool ftDataMultiplex::sendDataRequest(std::string peerId,
|
bool ftDataMultiplex::sendDataRequest(std::string peerId,
|
||||||
std::string hash, uint64_t size, uint64_t offset, uint32_t chunksize)
|
std::string hash, uint64_t size, uint64_t offset, uint32_t chunksize)
|
||||||
{
|
{
|
||||||
|
#ifdef MPLEX_DEBUG
|
||||||
|
std::cerr << "ftDataMultiplex::sendDataRequest() Client Send";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
return mDataSend->sendDataRequest(peerId,hash,size,offset,chunksize);
|
return mDataSend->sendDataRequest(peerId,hash,size,offset,chunksize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,6 +158,10 @@ bool ftDataMultiplex::sendData(std::string peerId,
|
|||||||
std::string hash, uint64_t size,
|
std::string hash, uint64_t size,
|
||||||
uint64_t offset, uint32_t chunksize, void *data)
|
uint64_t offset, uint32_t chunksize, void *data)
|
||||||
{
|
{
|
||||||
|
#ifdef MPLEX_DEBUG
|
||||||
|
std::cerr << "ftDataMultiplex::sendData() Server Send";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
return mDataSend->sendData(peerId,hash,size,offset,chunksize,data);
|
return mDataSend->sendData(peerId,hash,size,offset,chunksize,data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,6 +173,10 @@ bool ftDataMultiplex::recvData(std::string peerId,
|
|||||||
std::string hash, uint64_t size,
|
std::string hash, uint64_t size,
|
||||||
uint64_t offset, uint32_t chunksize, void *data)
|
uint64_t offset, uint32_t chunksize, void *data)
|
||||||
{
|
{
|
||||||
|
#ifdef MPLEX_DEBUG
|
||||||
|
std::cerr << "ftDataMultiplex::recvData() Client Recv";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
/* Store in Queue */
|
/* Store in Queue */
|
||||||
RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/
|
RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/
|
||||||
mRequestQueue.push_back(
|
mRequestQueue.push_back(
|
||||||
@ -177,6 +191,10 @@ bool ftDataMultiplex::recvDataRequest(std::string peerId,
|
|||||||
std::string hash, uint64_t size,
|
std::string hash, uint64_t size,
|
||||||
uint64_t offset, uint32_t chunksize)
|
uint64_t offset, uint32_t chunksize)
|
||||||
{
|
{
|
||||||
|
#ifdef MPLEX_DEBUG
|
||||||
|
std::cerr << "ftDataMultiplex::recvDataRequest() Server Recv";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
/* Store in Queue */
|
/* Store in Queue */
|
||||||
RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/
|
RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/
|
||||||
mRequestQueue.push_back(
|
mRequestQueue.push_back(
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#include "ftfilecreator.h"
|
#include "ftfilecreator.h"
|
||||||
|
|
||||||
|
#define FILE_DEBUG 1
|
||||||
|
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
*
|
*
|
||||||
* ftFileCreator methods
|
* ftFileCreator methods
|
||||||
@ -7,7 +9,7 @@
|
|||||||
***********************************************************/
|
***********************************************************/
|
||||||
|
|
||||||
ftFileCreator::ftFileCreator(std::string path, uint64_t size, std::string
|
ftFileCreator::ftFileCreator(std::string path, uint64_t size, std::string
|
||||||
hash, std::string chunker="default"): ftFileProvider(path,size,hash)
|
hash, std::string chunker): ftFileProvider(path,size,hash)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* FIXME any inits to do?
|
* FIXME any inits to do?
|
||||||
@ -136,6 +138,10 @@ ftFileCreator::~ftFileCreator()
|
|||||||
|
|
||||||
bool ftFileCreator::getMissingChunk(uint64_t &offset, uint32_t &chunk)
|
bool ftFileCreator::getMissingChunk(uint64_t &offset, uint32_t &chunk)
|
||||||
{
|
{
|
||||||
|
#ifdef FILE_DEBUG
|
||||||
|
std::cerr << "ftFileCreator::getMissingChunk(???," << chunk << ")";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
return fileChunker->getMissingChunk(offset, chunk);
|
return fileChunker->getMissingChunk(offset, chunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,15 +186,32 @@ int ftFileChunker::splitFile(){
|
|||||||
unsigned int index=0;
|
unsigned int index=0;
|
||||||
uint64_t max_chunk_size = file_size - (index * std_chunk_size);
|
uint64_t max_chunk_size = file_size - (index * std_chunk_size);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef FILE_DEBUG
|
||||||
|
std::cerr << "ftFileChunker::splitFile()";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
std::cerr << "\tnum_chunks: " << num_chunks;
|
||||||
|
std::cerr << std::endl;
|
||||||
|
std::cerr << "\trem: " << rem;
|
||||||
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
time_t now = time(NULL);
|
||||||
for(index=0;index<num_chunks;index++)
|
for(index=0;index<num_chunks;index++)
|
||||||
{
|
{
|
||||||
uint64_t offset = index * std_chunk_size;
|
uint64_t offset = index * std_chunk_size;
|
||||||
time_t now = time(NULL);
|
|
||||||
max_chunk_size = file_size - (index * std_chunk_size);
|
max_chunk_size = file_size - (index * std_chunk_size);
|
||||||
ftChunk *f = new ftChunk(offset,max_chunk_size,now, ftChunk::AVAIL);
|
ftChunk *f = new ftChunk(offset,max_chunk_size,now, ftChunk::AVAIL);
|
||||||
allocationTable.push_back(f);
|
allocationTable.push_back(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (rem != 0)
|
||||||
|
{
|
||||||
|
ftChunk *f = new ftChunk(file_size-rem,rem,now, ftChunk::AVAIL);
|
||||||
|
allocationTable.push_back(f);
|
||||||
|
num_chunks++;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* DEBUGGER
|
* DEBUGGER
|
||||||
* for(int j=0;j<allocationTable.size();j++)
|
* for(int j=0;j<allocationTable.size();j++)
|
||||||
@ -212,29 +235,77 @@ bool ftFileChunker::getMissingChunk(uint64_t &offset, uint32_t &chunk)
|
|||||||
int chunks_after = 0;
|
int chunks_after = 0;
|
||||||
int chunks_rem = 0;
|
int chunks_rem = 0;
|
||||||
|
|
||||||
|
#ifdef FILE_DEBUG
|
||||||
|
std::cerr << "ftFileChunker::getMissingChunk(???," << chunk << ")";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This signals file completion
|
* This signals file completion
|
||||||
* FIXME Does it need to be more explicit
|
* FIXME Does it need to be more explicit
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if(aggregate_status == num_chunks * ftChunk::RECEIVED)
|
if(aggregate_status == num_chunks * ftChunk::RECEIVED)
|
||||||
|
{
|
||||||
|
#ifdef FILE_DEBUG
|
||||||
|
std::cerr << "completed ??";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
return found;
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
while(i<allocationTable.size())
|
while(i<allocationTable.size())
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#ifdef FILE_DEBUG
|
||||||
|
std::cerr << "ftFileChunker checking allocTable(" << i << ")";
|
||||||
|
std::cerr << " of " << allocationTable.size();
|
||||||
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
if(allocationTable.at(i)->max_chunk_size >=chunk)
|
if(allocationTable.at(i)->max_chunk_size >=chunk)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#ifdef FILE_DEBUG
|
||||||
|
std::cerr << "ftFileChunker pre alloc(" << i << ")";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
std::cerr << "\toffset: " << allocationTable.at(i)->offset;
|
||||||
|
std::cerr << std::endl;
|
||||||
|
std::cerr << "\tmax_chunk: " << allocationTable.at(i)->max_chunk_size;
|
||||||
|
std::cerr << std::endl;
|
||||||
|
std::cerr << "\treq_chunk: " << chunk;
|
||||||
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
offset = allocationTable.at(i)->offset;
|
offset = allocationTable.at(i)->offset;
|
||||||
chunks_after = chunk/std_chunk_size; //10KB
|
chunks_after = chunk/std_chunk_size; //10KB
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* FIXME Handling remaining chunk < 10KB
|
* FIXME Handling remaining chunk < 10KB
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
//if (chunk <
|
||||||
chunks_rem = chunk % std_chunk_size;
|
chunks_rem = chunk % std_chunk_size;
|
||||||
chunk -= chunks_rem;
|
chunk -= chunks_rem;
|
||||||
/*std::cout << "Found " << chunk << " at " << i << " "<< chunks_after << std::endl;*/
|
/*std::cout << "Found " << chunk << " at " << i << " "<< chunks_after << std::endl;*/
|
||||||
allocationTable.at(i)->max_chunk_size=0;
|
allocationTable.at(i)->max_chunk_size=0;
|
||||||
allocationTable.at(i)->timestamp = time(NULL);
|
allocationTable.at(i)->timestamp = time(NULL);
|
||||||
allocationTable.at(i)->chunk_status = ftChunk::ALLOCATED;
|
allocationTable.at(i)->chunk_status = ftChunk::ALLOCATED;
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef FILE_DEBUG
|
||||||
|
std::cerr << "ftFileChunker postalloc(" << i << ")";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
std::cerr << "\tchunks_after: " << chunks_after;
|
||||||
|
std::cerr << std::endl;
|
||||||
|
std::cerr << "\tchunks_rem: " << chunks_after;
|
||||||
|
std::cerr << std::endl;
|
||||||
|
std::cerr << "\tchunk: " << chunks_after;
|
||||||
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -279,11 +350,17 @@ bool ftFileChunker::getMissingChunk(uint64_t &offset, uint32_t &chunk)
|
|||||||
* Expensive? Can it be smarter FIXME
|
* Expensive? Can it be smarter FIXME
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* drbob: Think this is wrong?
|
||||||
|
* disabling...
|
||||||
|
*
|
||||||
for(unsigned int j=0;j<i;j++)
|
for(unsigned int j=0;j<i;j++)
|
||||||
{
|
{
|
||||||
if (allocationTable.at(j)->max_chunk_size >0)
|
if (allocationTable.at(j)->max_chunk_size >0)
|
||||||
allocationTable.at(j)->max_chunk_size -= chunk;
|
allocationTable.at(j)->max_chunk_size -= chunk;
|
||||||
}
|
}
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
for(unsigned int j=i;j<i+chunks_after;j++)
|
for(unsigned int j=i;j<i+chunks_after;j++)
|
||||||
{
|
{
|
||||||
|
@ -32,7 +32,7 @@ const uint32_t PQIPEER_DOWNLOAD_TOO_FAST = 8; /* 8 secs */
|
|||||||
const uint32_t PQIPEER_DOWNLOAD_TOO_SLOW = 12; /* 12 secs */
|
const uint32_t PQIPEER_DOWNLOAD_TOO_SLOW = 12; /* 12 secs */
|
||||||
const uint32_t PQIPEER_DOWNLOAD_MIN_DELTA = 5; /* 5 secs */
|
const uint32_t PQIPEER_DOWNLOAD_MIN_DELTA = 5; /* 5 secs */
|
||||||
|
|
||||||
const uint32_t TRANSFER_START_MIN = 500; /* 500 byte min limit */
|
const uint32_t TRANSFER_START_MIN = 10000; /* 10000 byte min limit */
|
||||||
const uint32_t TRANSFER_START_MAX = 10000; /* 10000 byte max limit */
|
const uint32_t TRANSFER_START_MAX = 10000; /* 10000 byte max limit */
|
||||||
|
|
||||||
ftTransferModule::ftTransferModule(ftFileCreator *fc, ftDataMultiplex *dm)
|
ftTransferModule::ftTransferModule(ftFileCreator *fc, ftDataMultiplex *dm)
|
||||||
@ -73,16 +73,24 @@ bool ftTransferModule::setPeerState(std::string peerId,uint32_t state,uint32_t m
|
|||||||
it++;
|
it++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!found) mFileSources.push_back(*it);
|
if (!found) mFileSources.push_back(peerId);
|
||||||
|
|
||||||
std::map<std::string,peerInfo>::iterator mit;
|
std::map<std::string,peerInfo>::iterator mit;
|
||||||
mit = mOnlinePeers.find(peerId);
|
mit = mOnlinePeers.find(peerId);
|
||||||
if (mit == mOnlinePeers.end())
|
if (mit == mOnlinePeers.end())
|
||||||
{
|
{
|
||||||
peerInfo pInfo;
|
peerInfo pInfo;
|
||||||
|
/* Initialise it properly */
|
||||||
|
pInfo.peerId = peerId;
|
||||||
pInfo.state = state;
|
pInfo.state = state;
|
||||||
|
pInfo.offset = 0;
|
||||||
|
pInfo.chunkSize = TRANSFER_START_MIN;
|
||||||
|
pInfo.receivedSize = 0;
|
||||||
|
pInfo.lastTS = 0;
|
||||||
|
pInfo.actualRate = 0;
|
||||||
pInfo.desiredRate = maxRate;
|
pInfo.desiredRate = maxRate;
|
||||||
mOnlinePeers[peerId] = pInfo;
|
mOnlinePeers[peerId] = pInfo;
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -143,11 +151,18 @@ void ftTransferModule::requestData(std::string peerId, uint64_t offset, uint32_t
|
|||||||
bool ftTransferModule::getChunk(uint64_t &offset, uint32_t &chunk_size)
|
bool ftTransferModule::getChunk(uint64_t &offset, uint32_t &chunk_size)
|
||||||
{
|
{
|
||||||
std::cerr << "ftTransferModule::getChunk()";
|
std::cerr << "ftTransferModule::getChunk()";
|
||||||
std::cerr << " offset: " << offset;
|
std::cerr << " Request: offset: " << offset;
|
||||||
std::cerr << " chunk_size: " << chunk_size;
|
std::cerr << " chunk_size: " << chunk_size;
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
|
|
||||||
return mFileCreator->getMissingChunk(offset, chunk_size);
|
bool val = mFileCreator->getMissingChunk(offset, chunk_size);
|
||||||
|
|
||||||
|
std::cerr << "ftTransferModule::getChunk()";
|
||||||
|
std::cerr << " Answer: offset: " << offset;
|
||||||
|
std::cerr << " chunk_size: " << chunk_size;
|
||||||
|
std::cerr << std::endl;
|
||||||
|
|
||||||
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ftTransferModule::storeData(uint64_t offset, uint32_t chunk_size,void *data)
|
bool ftTransferModule::storeData(uint64_t offset, uint32_t chunk_size,void *data)
|
||||||
|
Loading…
Reference in New Issue
Block a user