From f243e5f6d31f2c3aab68c4bb05b5eee8a942f603 Mon Sep 17 00:00:00 2001 From: drbob Date: Sat, 23 Aug 2008 21:28:08 +0000 Subject: [PATCH] * 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 --- libretroshare/src/ft/ftcontroller.cc | 2 +- libretroshare/src/ft/ftdatamultiplex.cc | 18 +++++ libretroshare/src/ft/ftfilecreator.cc | 83 +++++++++++++++++++++++- libretroshare/src/ft/fttransfermodule.cc | 37 +++++++---- 4 files changed, 125 insertions(+), 15 deletions(-) diff --git a/libretroshare/src/ft/ftcontroller.cc b/libretroshare/src/ft/ftcontroller.cc index ff1267304..762073625 100644 --- a/libretroshare/src/ft/ftcontroller.cc +++ b/libretroshare/src/ft/ftcontroller.cc @@ -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); diff --git a/libretroshare/src/ft/ftdatamultiplex.cc b/libretroshare/src/ft/ftdatamultiplex.cc index 97b4c3b18..f1ff8bad9 100644 --- a/libretroshare/src/ft/ftdatamultiplex.cc +++ b/libretroshare/src/ft/ftdatamultiplex.cc @@ -39,6 +39,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( diff --git a/libretroshare/src/ft/ftfilecreator.cc b/libretroshare/src/ft/ftfilecreator.cc index 2e659a690..1f6a27ea4 100644 --- a/libretroshare/src/ft/ftfilecreator.cc +++ b/libretroshare/src/ft/ftfilecreator.cc @@ -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); } @@ -179,16 +185,33 @@ int ftFileChunker::splitFile(){ uint64_t rem = file_size % std_chunk_size; 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;indexmax_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; } @@ -278,12 +349,18 @@ bool ftFileChunker::getMissingChunk(uint64_t &offset, uint32_t &chunk) * update all previous chunks max available size * Expensive? Can it be smarter FIXME */ - + + /* drbob: Think this is wrong? + * disabling... + * for(unsigned int j=0;jmax_chunk_size >0) allocationTable.at(j)->max_chunk_size -= chunk; } + * + */ + for(unsigned int j=i;j::iterator mit; - mit = mOnlinePeers.find(peerId); - if (mit == mOnlinePeers.end()) - { - peerInfo pInfo; - pInfo.state = state; - pInfo.desiredRate = maxRate; - mOnlinePeers[peerId] = pInfo; + 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)