* 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:
drbob 2008-08-23 21:28:08 +00:00
parent 7b7446c5b5
commit f243e5f6d3
4 changed files with 125 additions and 15 deletions

View File

@ -215,7 +215,7 @@ bool ftController::FileRequest(std::string fname, std::string hash,
/* add in new item for download */
std::string savepath = mDownloadPath + "/" + fname;
std::string chunker = "";
std::string chunker = "default";
ftFileCreator *fc = new ftFileCreator(savepath, size, hash, chunker);
ftTransferModule *tm = new ftTransferModule(fc, mDataplex);

View File

@ -40,6 +40,8 @@ const uint32_t DMULTIPLEX_MIN = 10; /* 1ms sleep */
const uint32_t DMULTIPLEX_MAX = 1000; /* 1 sec sleep */
const double DMULTIPLEX_RELAX = 0.5; /* ??? */
#define MPLEX_DEBUG 1
ftClient::ftClient(ftTransferModule *module, ftFileCreator *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,
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);
}
@ -152,6 +158,10 @@ bool ftDataMultiplex::sendData(std::string peerId,
std::string hash, uint64_t size,
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);
}
@ -163,6 +173,10 @@ bool ftDataMultiplex::recvData(std::string peerId,
std::string hash, uint64_t size,
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 */
RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/
mRequestQueue.push_back(
@ -177,6 +191,10 @@ bool ftDataMultiplex::recvDataRequest(std::string peerId,
std::string hash, uint64_t size,
uint64_t offset, uint32_t chunksize)
{
#ifdef MPLEX_DEBUG
std::cerr << "ftDataMultiplex::recvDataRequest() Server Recv";
std::cerr << std::endl;
#endif
/* Store in Queue */
RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/
mRequestQueue.push_back(

View File

@ -1,5 +1,7 @@
#include "ftfilecreator.h"
#define FILE_DEBUG 1
/***********************************************************
*
* ftFileCreator methods
@ -7,7 +9,7 @@
***********************************************************/
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?
@ -136,6 +138,10 @@ ftFileCreator::~ftFileCreator()
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);
}
@ -180,15 +186,32 @@ int ftFileChunker::splitFile(){
unsigned int index=0;
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++)
{
uint64_t offset = index * std_chunk_size;
time_t now = time(NULL);
max_chunk_size = file_size - (index * std_chunk_size);
ftChunk *f = new ftChunk(offset,max_chunk_size,now, ftChunk::AVAIL);
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
* 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_rem = 0;
#ifdef FILE_DEBUG
std::cerr << "ftFileChunker::getMissingChunk(???," << chunk << ")";
std::cerr << std::endl;
#endif
/*
* This signals file completion
* FIXME Does it need to be more explicit
*/
if(aggregate_status == num_chunks * ftChunk::RECEIVED)
{
#ifdef FILE_DEBUG
std::cerr << "completed ??";
std::cerr << std::endl;
#endif
return found;
}
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)
{
#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;
chunks_after = chunk/std_chunk_size; //10KB
/*
* FIXME Handling remaining chunk < 10KB
*/
//if (chunk <
chunks_rem = chunk % std_chunk_size;
chunk -= chunks_rem;
/*std::cout << "Found " << chunk << " at " << i << " "<< chunks_after << std::endl;*/
allocationTable.at(i)->max_chunk_size=0;
allocationTable.at(i)->timestamp = time(NULL);
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;
break;
}
@ -279,11 +350,17 @@ bool ftFileChunker::getMissingChunk(uint64_t &offset, uint32_t &chunk)
* Expensive? Can it be smarter FIXME
*/
/* drbob: Think this is wrong?
* disabling...
*
for(unsigned int j=0;j<i;j++)
{
if (allocationTable.at(j)->max_chunk_size >0)
allocationTable.at(j)->max_chunk_size -= chunk;
}
*
*/
for(unsigned int j=i;j<i+chunks_after;j++)
{

View File

@ -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_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 */
ftTransferModule::ftTransferModule(ftFileCreator *fc, ftDataMultiplex *dm)
@ -73,16 +73,24 @@ bool ftTransferModule::setPeerState(std::string peerId,uint32_t state,uint32_t m
it++;
}
if (!found) mFileSources.push_back(*it);
if (!found) mFileSources.push_back(peerId);
std::map<std::string,peerInfo>::iterator mit;
mit = mOnlinePeers.find(peerId);
if (mit == mOnlinePeers.end())
{
peerInfo pInfo;
/* Initialise it properly */
pInfo.peerId = peerId;
pInfo.state = state;
pInfo.offset = 0;
pInfo.chunkSize = TRANSFER_START_MIN;
pInfo.receivedSize = 0;
pInfo.lastTS = 0;
pInfo.actualRate = 0;
pInfo.desiredRate = maxRate;
mOnlinePeers[peerId] = pInfo;
}
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)
{
std::cerr << "ftTransferModule::getChunk()";
std::cerr << " offset: " << offset;
std::cerr << " Request: offset: " << offset;
std::cerr << " chunk_size: " << chunk_size;
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)