mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-23 16:21:29 -04:00
Merging branches/v0.6-initdev into trunk.
These split at 6672 -> 7075, so quite a bit merge. libretroshare compiles - but untested. retroshare-gui needs GenCertDialog.ui and IdEditDialog.ui to be properly merged. (compile errors). some plugins will be broken. retroshare-nogui is untested. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7078 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
commit
c0738eec7f
407 changed files with 23716 additions and 50779 deletions
|
@ -52,23 +52,29 @@ const int ftserverzone = 29539;
|
|||
#include "pqi/pqi.h"
|
||||
#include "pqi/p3linkmgr.h"
|
||||
|
||||
#include "serialiser/rsfiletransferitems.h"
|
||||
#include "serialiser/rsserviceids.h"
|
||||
|
||||
/***
|
||||
* #define SERVER_DEBUG 1
|
||||
* #define DEBUG_TICK 1
|
||||
* #define SERVER_DEBUG 1
|
||||
* #define SERVER_DEBUG_CACHE 1
|
||||
***/
|
||||
|
||||
static const time_t FILE_TRANSFER_LOW_PRIORITY_TASKS_PERIOD = 5 ; // low priority tasks handling every 5 seconds
|
||||
|
||||
/* Setup */
|
||||
ftServer::ftServer(p3PeerMgr *pm, p3LinkMgr *lm)
|
||||
: mP3iface(NULL), mPeerMgr(pm),
|
||||
: p3Service(RS_SERVICE_TYPE_FILE_TRANSFER),
|
||||
mPeerMgr(pm),
|
||||
mLinkMgr(lm),
|
||||
mCacheStrapper(NULL),
|
||||
mFiStore(NULL), mFiMon(NULL),
|
||||
mFtController(NULL), mFtExtra(NULL),
|
||||
mFtDataplex(NULL), mFtSearch(NULL), srvMutex("ftServer")
|
||||
{
|
||||
mCacheStrapper = new ftCacheStrapper(lm);
|
||||
mCacheStrapper = new ftCacheStrapper(lm);
|
||||
|
||||
addSerialType(new RsFileTransferSerialiser()) ;
|
||||
}
|
||||
|
||||
void ftServer::setConfigDirectory(std::string path)
|
||||
|
@ -88,11 +94,6 @@ void ftServer::setConfigDirectory(std::string path)
|
|||
RsDirUtil::checkCreateDirectory(remotecachedir) ;
|
||||
}
|
||||
|
||||
void ftServer::setP3Interface(P3Interface *pqi)
|
||||
{
|
||||
mP3iface = pqi;
|
||||
}
|
||||
|
||||
/* Control Interface */
|
||||
|
||||
/* add Config Items (Extra, Controller) */
|
||||
|
@ -182,16 +183,10 @@ void ftServer::StartupThreads()
|
|||
|
||||
/* Dataplex */
|
||||
mFtDataplex->start();
|
||||
|
||||
/* start own thread */
|
||||
start();
|
||||
}
|
||||
|
||||
void ftServer::StopThreads()
|
||||
{
|
||||
/* stop own thread */
|
||||
join();
|
||||
|
||||
/* stop Dataplex */
|
||||
mFtDataplex->join();
|
||||
|
||||
|
@ -228,31 +223,22 @@ CacheTransfer *ftServer::getCacheTransfer()
|
|||
return mFtController;
|
||||
}
|
||||
|
||||
void ftServer::run()
|
||||
|
||||
/***************************************************************/
|
||||
/********************** RsFiles Interface **********************/
|
||||
/***************************************************************/
|
||||
|
||||
/***************************************************************/
|
||||
/********************** Controller Access **********************/
|
||||
/***************************************************************/
|
||||
|
||||
bool ftServer::ResumeTransfers()
|
||||
{
|
||||
while(isRunning())
|
||||
{
|
||||
mFtDataplex->deleteUnusedServers() ;
|
||||
mFtDataplex->handlePendingCrcRequests() ;
|
||||
mFtDataplex->dispatchReceivedChunkCheckSum() ;
|
||||
#ifdef WIN32
|
||||
Sleep(5000);
|
||||
#else
|
||||
sleep(5);
|
||||
#endif
|
||||
}
|
||||
mFtController->activate();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************/
|
||||
/********************** RsFiles Interface **********************/
|
||||
/***************************************************************/
|
||||
|
||||
|
||||
/***************************************************************/
|
||||
/********************** Controller Access **********************/
|
||||
/***************************************************************/
|
||||
|
||||
bool ftServer::checkHash(const std::string& hash,std::string& error_string)
|
||||
{
|
||||
static const uint32_t HASH_LENGTH = 40 ;
|
||||
|
@ -465,15 +451,11 @@ RsTurtleGenericTunnelItem *ftServer::deserialiseItem(void *data,uint32_t size) c
|
|||
#ifdef SERVER_DEBUG
|
||||
std::cerr << "p3turtle: deserialising packet: " << std::endl ;
|
||||
#endif
|
||||
#ifdef SERVER_DEBUG
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_TURTLE != getRsItemService(rstype)))
|
||||
{
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << " Wrong type !!" << std::endl ;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
#endif
|
||||
|
||||
switch(getRsItemSubType(rstype))
|
||||
{
|
||||
|
@ -857,10 +839,15 @@ bool ftServer::shareDownloadDirectory(bool share)
|
|||
/**************** Config Interface *****************************/
|
||||
/***************************************************************/
|
||||
|
||||
/* Key Functions to be overloaded for Full Configuration */
|
||||
/* Key Functions to be overloaded for Full Configuration */
|
||||
RsSerialiser *ftServer::setupSerialiser()
|
||||
{
|
||||
return NULL;
|
||||
RsSerialiser *rss = new RsSerialiser ;
|
||||
rss->addSerialType(new RsFileTransferSerialiser) ;
|
||||
|
||||
//rss->addSerialType(new RsGeneralConfigSerialiser());
|
||||
|
||||
return rss ;
|
||||
}
|
||||
|
||||
bool ftServer::saveList(bool &/*cleanup*/, std::list<RsItem *>& /*list*/)
|
||||
|
@ -887,6 +874,9 @@ bool ftServer::loadConfigMap(std::map<std::string, std::string> &/*configMap*/)
|
|||
/* Client Send */
|
||||
bool ftServer::sendDataRequest(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize)
|
||||
{
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << "ftServer::sendDataRequest() to peer " << peerId << " for hash " << hash << ", offset=" << offset << ", chunk size="<< chunksize << std::endl;
|
||||
#endif
|
||||
if(mTurtleRouter->isTurtlePeer(peerId))
|
||||
{
|
||||
RsTurtleFileRequestItem *item = new RsTurtleFileRequestItem ;
|
||||
|
@ -898,9 +888,10 @@ bool ftServer::sendDataRequest(const std::string& peerId, const std::string& has
|
|||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "ftServer::sendDataRequest() " <<std::endl;
|
||||
/* create a packet */
|
||||
/* push to networking part */
|
||||
RsFileRequest *rfi = new RsFileRequest();
|
||||
RsFileTransferDataRequestItem *rfi = new RsFileTransferDataRequestItem();
|
||||
|
||||
/* id */
|
||||
rfi->PeerId(peerId);
|
||||
|
@ -913,7 +904,7 @@ bool ftServer::sendDataRequest(const std::string& peerId, const std::string& has
|
|||
rfi->fileoffset = offset; /* ftr->offset; */
|
||||
rfi->chunksize = chunksize; /* ftr->chunk; */
|
||||
|
||||
mP3iface->SendFileRequest(rfi);
|
||||
sendItem(rfi);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -921,6 +912,9 @@ bool ftServer::sendDataRequest(const std::string& peerId, const std::string& has
|
|||
|
||||
bool ftServer::sendChunkMapRequest(const std::string& peerId,const std::string& hash,bool is_client)
|
||||
{
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << "ftServer::sendChunkMapRequest() to peer " << peerId << " for hash " << hash << std::endl;
|
||||
#endif
|
||||
if(mTurtleRouter->isTurtlePeer(peerId))
|
||||
{
|
||||
RsTurtleFileMapRequestItem *item = new RsTurtleFileMapRequestItem ;
|
||||
|
@ -930,7 +924,7 @@ bool ftServer::sendChunkMapRequest(const std::string& peerId,const std::string&
|
|||
{
|
||||
/* create a packet */
|
||||
/* push to networking part */
|
||||
RsFileChunkMapRequest *rfi = new RsFileChunkMapRequest();
|
||||
RsFileTransferChunkMapRequestItem *rfi = new RsFileTransferChunkMapRequestItem();
|
||||
|
||||
/* id */
|
||||
rfi->PeerId(peerId);
|
||||
|
@ -939,7 +933,7 @@ bool ftServer::sendChunkMapRequest(const std::string& peerId,const std::string&
|
|||
rfi->hash = hash; /* ftr->hash; */
|
||||
rfi->is_client = is_client ;
|
||||
|
||||
mP3iface->SendFileChunkMapRequest(rfi);
|
||||
sendItem(rfi);
|
||||
}
|
||||
|
||||
return true ;
|
||||
|
@ -947,6 +941,9 @@ bool ftServer::sendChunkMapRequest(const std::string& peerId,const std::string&
|
|||
|
||||
bool ftServer::sendChunkMap(const std::string& peerId,const std::string& hash,const CompressedChunkMap& map,bool is_client)
|
||||
{
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << "ftServer::sendChunkMap() to peer " << peerId << " for hash " << hash << std::endl;
|
||||
#endif
|
||||
if(mTurtleRouter->isTurtlePeer(peerId))
|
||||
{
|
||||
RsTurtleFileMapItem *item = new RsTurtleFileMapItem ;
|
||||
|
@ -957,7 +954,7 @@ bool ftServer::sendChunkMap(const std::string& peerId,const std::string& hash,co
|
|||
{
|
||||
/* create a packet */
|
||||
/* push to networking part */
|
||||
RsFileChunkMap *rfi = new RsFileChunkMap();
|
||||
RsFileTransferChunkMapItem *rfi = new RsFileTransferChunkMapItem();
|
||||
|
||||
/* id */
|
||||
rfi->PeerId(peerId);
|
||||
|
@ -967,38 +964,17 @@ bool ftServer::sendChunkMap(const std::string& peerId,const std::string& hash,co
|
|||
rfi->is_client = is_client; /* ftr->hash; */
|
||||
rfi->compressed_map = map; /* ftr->hash; */
|
||||
|
||||
mP3iface->SendFileChunkMap(rfi);
|
||||
sendItem(rfi);
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
bool ftServer::sendCRC32MapRequest(const std::string& peerId,const std::string& hash)
|
||||
{
|
||||
if(mTurtleRouter->isTurtlePeer(peerId))
|
||||
{
|
||||
RsTurtleFileCrcRequestItem *item = new RsTurtleFileCrcRequestItem;
|
||||
|
||||
mTurtleRouter->sendTurtleData(peerId,item) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* create a packet */
|
||||
/* push to networking part */
|
||||
RsFileCRC32MapRequest *rfi = new RsFileCRC32MapRequest();
|
||||
|
||||
/* id */
|
||||
rfi->PeerId(peerId);
|
||||
|
||||
/* file info */
|
||||
rfi->hash = hash; /* ftr->hash; */
|
||||
|
||||
mP3iface->SendFileCRC32MapRequest(rfi);
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
bool ftServer::sendSingleChunkCRCRequest(const std::string& peerId,const std::string& hash,uint32_t chunk_number)
|
||||
{
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << "ftServer::sendSingleCRCRequest() to peer " << peerId << " for hash " << hash << ", chunk number=" << chunk_number << std::endl;
|
||||
#endif
|
||||
if(mTurtleRouter->isTurtlePeer(peerId))
|
||||
{
|
||||
RsTurtleChunkCrcRequestItem *item = new RsTurtleChunkCrcRequestItem;
|
||||
|
@ -1010,7 +986,7 @@ bool ftServer::sendSingleChunkCRCRequest(const std::string& peerId,const std::st
|
|||
{
|
||||
/* create a packet */
|
||||
/* push to networking part */
|
||||
RsFileSingleChunkCrcRequest *rfi = new RsFileSingleChunkCrcRequest();
|
||||
RsFileTransferSingleChunkCrcRequestItem *rfi = new RsFileTransferSingleChunkCrcRequestItem();
|
||||
|
||||
/* id */
|
||||
rfi->PeerId(peerId);
|
||||
|
@ -1019,41 +995,17 @@ bool ftServer::sendSingleChunkCRCRequest(const std::string& peerId,const std::st
|
|||
rfi->hash = hash; /* ftr->hash; */
|
||||
rfi->chunk_number = chunk_number ;
|
||||
|
||||
mP3iface->SendFileSingleChunkCrcRequest(rfi);
|
||||
sendItem(rfi);
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool ftServer::sendCRC32Map(const std::string& peerId,const std::string& hash,const CRC32Map& crcmap)
|
||||
{
|
||||
if(mTurtleRouter->isTurtlePeer(peerId))
|
||||
{
|
||||
RsTurtleFileCrcItem *item = new RsTurtleFileCrcItem ;
|
||||
item->crc_map = crcmap ;
|
||||
|
||||
mTurtleRouter->sendTurtleData(peerId,item) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* create a packet */
|
||||
/* push to networking part */
|
||||
RsFileCRC32Map *rfi = new RsFileCRC32Map();
|
||||
|
||||
/* id */
|
||||
rfi->PeerId(peerId);
|
||||
|
||||
/* file info */
|
||||
rfi->hash = hash; /* ftr->hash; */
|
||||
rfi->crc_map = crcmap; /* ftr->hash; */
|
||||
|
||||
mP3iface->SendFileCRC32Map(rfi);
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
bool ftServer::sendSingleChunkCRC(const std::string& peerId,const std::string& hash,uint32_t chunk_number,const Sha1CheckSum& crc)
|
||||
{
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << "ftServer::sendSingleCRC() to peer " << peerId << " for hash " << hash << ", chunk number=" << chunk_number << std::endl;
|
||||
#endif
|
||||
if(mTurtleRouter->isTurtlePeer(peerId))
|
||||
{
|
||||
RsTurtleChunkCrcItem *item = new RsTurtleChunkCrcItem;
|
||||
|
@ -1066,7 +1018,7 @@ bool ftServer::sendSingleChunkCRC(const std::string& peerId,const std::string& h
|
|||
{
|
||||
/* create a packet */
|
||||
/* push to networking part */
|
||||
RsFileSingleChunkCrc *rfi = new RsFileSingleChunkCrc();
|
||||
RsFileTransferSingleChunkCrcItem *rfi = new RsFileTransferSingleChunkCrcItem();
|
||||
|
||||
/* id */
|
||||
rfi->PeerId(peerId);
|
||||
|
@ -1076,16 +1028,12 @@ bool ftServer::sendSingleChunkCRC(const std::string& peerId,const std::string& h
|
|||
rfi->check_sum = crc;
|
||||
rfi->chunk_number = chunk_number;
|
||||
|
||||
mP3iface->SendFileSingleChunkCrc(rfi);
|
||||
sendItem(rfi);
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
//const uint32_t MAX_FT_CHUNK = 32 * 1024; /* 32K */
|
||||
//const uint32_t MAX_FT_CHUNK = 16 * 1024; /* 16K */
|
||||
const uint32_t MAX_FT_CHUNK = 8 * 1024; /* 16K */
|
||||
|
||||
/* Server Send */
|
||||
bool ftServer::sendData(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t baseoffset, uint32_t chunksize, void *data)
|
||||
{
|
||||
|
@ -1106,6 +1054,11 @@ bool ftServer::sendData(const std::string& peerId, const std::string& hash, uint
|
|||
|
||||
while(tosend > 0)
|
||||
{
|
||||
//static const uint32_t MAX_FT_CHUNK = 32 * 1024; /* 32K */
|
||||
//static const uint32_t MAX_FT_CHUNK = 16 * 1024; /* 16K */
|
||||
//
|
||||
static const uint32_t MAX_FT_CHUNK = 8 * 1024; /* 16K */
|
||||
|
||||
/* workout size */
|
||||
chunk = MAX_FT_CHUNK;
|
||||
if (chunk > tosend)
|
||||
|
@ -1135,7 +1088,7 @@ bool ftServer::sendData(const std::string& peerId, const std::string& hash, uint
|
|||
}
|
||||
else
|
||||
{
|
||||
RsFileData *rfd = new RsFileData();
|
||||
RsFileTransferDataItem *rfd = new RsFileTransferDataItem();
|
||||
|
||||
/* set id */
|
||||
rfd->PeerId(peerId);
|
||||
|
@ -1153,7 +1106,7 @@ bool ftServer::sendData(const std::string& peerId, const std::string& hash, uint
|
|||
/* file data */
|
||||
rfd->fd.binData.setBinData( &(((uint8_t *) data)[offset]), chunk);
|
||||
|
||||
mP3iface->SendFileData(rfd);
|
||||
sendItem(rfd);
|
||||
|
||||
/* print the data pointer */
|
||||
#ifdef SERVER_DEBUG
|
||||
|
@ -1176,6 +1129,8 @@ bool ftServer::sendData(const std::string& peerId, const std::string& hash, uint
|
|||
return true;
|
||||
}
|
||||
|
||||
// Dont delete the item. The client (p3turtle) is doing it after calling this.
|
||||
//
|
||||
void ftServer::receiveTurtleData(RsTurtleGenericTunnelItem *i,
|
||||
const std::string& hash,
|
||||
const std::string& virtual_peer_id,
|
||||
|
@ -1186,6 +1141,9 @@ void ftServer::receiveTurtleData(RsTurtleGenericTunnelItem *i,
|
|||
case RS_TURTLE_SUBTYPE_FILE_REQUEST:
|
||||
{
|
||||
RsTurtleFileRequestItem *item = dynamic_cast<RsTurtleFileRequestItem *>(i) ;
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << "ftServer::receiveTurtleData(): received file data request for " << hash << " from peer " << virtual_peer_id << std::endl;
|
||||
#endif
|
||||
getMultiplexer()->recvDataRequest(virtual_peer_id,hash,0,item->chunk_offset,item->chunk_size) ;
|
||||
}
|
||||
break ;
|
||||
|
@ -1193,6 +1151,9 @@ void ftServer::receiveTurtleData(RsTurtleGenericTunnelItem *i,
|
|||
case RS_TURTLE_SUBTYPE_FILE_DATA :
|
||||
{
|
||||
RsTurtleFileDataItem *item = dynamic_cast<RsTurtleFileDataItem *>(i) ;
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << "ftServer::receiveTurtleData(): received file data for " << hash << " from peer " << virtual_peer_id << std::endl;
|
||||
#endif
|
||||
getMultiplexer()->recvData(virtual_peer_id,hash,0,item->chunk_offset,item->chunk_size,item->chunk_data) ;
|
||||
|
||||
item->chunk_data = NULL ; // this prevents deletion in the destructor of RsFileDataItem, because data will be deleted
|
||||
|
@ -1204,33 +1165,29 @@ void ftServer::receiveTurtleData(RsTurtleGenericTunnelItem *i,
|
|||
case RS_TURTLE_SUBTYPE_FILE_MAP :
|
||||
{
|
||||
RsTurtleFileMapItem *item = dynamic_cast<RsTurtleFileMapItem *>(i) ;
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << "ftServer::receiveTurtleData(): received chunk map for hash " << hash << " from peer " << virtual_peer_id << std::endl;
|
||||
#endif
|
||||
getMultiplexer()->recvChunkMap(virtual_peer_id,hash,item->compressed_map,direction == RsTurtleGenericTunnelItem::DIRECTION_CLIENT) ;
|
||||
}
|
||||
break ;
|
||||
|
||||
case RS_TURTLE_SUBTYPE_FILE_MAP_REQUEST:
|
||||
{
|
||||
RsTurtleFileMapRequestItem *item = dynamic_cast<RsTurtleFileMapRequestItem *>(i) ;
|
||||
//RsTurtleFileMapRequestItem *item = dynamic_cast<RsTurtleFileMapRequestItem *>(i) ;
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << "ftServer::receiveTurtleData(): received chunkmap request for hash " << hash << " from peer " << virtual_peer_id << std::endl;
|
||||
#endif
|
||||
getMultiplexer()->recvChunkMapRequest(virtual_peer_id,hash,direction == RsTurtleGenericTunnelItem::DIRECTION_CLIENT) ;
|
||||
}
|
||||
break ;
|
||||
|
||||
case RS_TURTLE_SUBTYPE_FILE_CRC :
|
||||
{
|
||||
RsTurtleFileCrcItem *item = dynamic_cast<RsTurtleFileCrcItem *>(i) ;
|
||||
getMultiplexer()->recvCRC32Map(virtual_peer_id,hash,item->crc_map) ;
|
||||
}
|
||||
break ;
|
||||
|
||||
case RS_TURTLE_SUBTYPE_FILE_CRC_REQUEST:
|
||||
{
|
||||
getMultiplexer()->recvCRC32MapRequest(virtual_peer_id,hash) ;
|
||||
}
|
||||
break ;
|
||||
|
||||
case RS_TURTLE_SUBTYPE_CHUNK_CRC :
|
||||
{
|
||||
RsTurtleChunkCrcItem *item = dynamic_cast<RsTurtleChunkCrcItem *>(i) ;
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << "ftServer::receiveTurtleData(): received single chunk CRC for hash " << hash << " from peer " << virtual_peer_id << std::endl;
|
||||
#endif
|
||||
getMultiplexer()->recvSingleChunkCRC(virtual_peer_id,hash,item->chunk_number,item->check_sum) ;
|
||||
}
|
||||
break ;
|
||||
|
@ -1238,6 +1195,9 @@ void ftServer::receiveTurtleData(RsTurtleGenericTunnelItem *i,
|
|||
case RS_TURTLE_SUBTYPE_CHUNK_CRC_REQUEST:
|
||||
{
|
||||
RsTurtleChunkCrcRequestItem *item = dynamic_cast<RsTurtleChunkCrcRequestItem *>(i) ;
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << "ftServer::receiveTurtleData(): received single chunk CRC request for hash " << hash << " from peer " << virtual_peer_id << std::endl;
|
||||
#endif
|
||||
getMultiplexer()->recvSingleChunkCRCRequest(virtual_peer_id,hash,item->chunk_number) ;
|
||||
}
|
||||
break ;
|
||||
|
@ -1246,358 +1206,189 @@ void ftServer::receiveTurtleData(RsTurtleGenericTunnelItem *i,
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/* NB: The rsCore lock must be activated before calling this.
|
||||
* This Lock should be moved lower into the system...
|
||||
* most likely destination is in ftServer.
|
||||
*/
|
||||
int ftServer::tick()
|
||||
{
|
||||
rslog(RSL_DEBUG_BASIC, ftserverzone,
|
||||
"filedexserver::tick()");
|
||||
bool moreToTick = false ;
|
||||
|
||||
if (mP3iface == NULL)
|
||||
if(handleIncoming())
|
||||
moreToTick = true;
|
||||
|
||||
if(handleCacheData())
|
||||
moreToTick = true;
|
||||
|
||||
static time_t last_law_priority_tasks_handling_time = 0 ;
|
||||
time_t now = time(NULL) ;
|
||||
|
||||
if(last_law_priority_tasks_handling_time + FILE_TRANSFER_LOW_PRIORITY_TASKS_PERIOD < now)
|
||||
{
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << "ftServer::tick() ERROR: mP3iface == NULL";
|
||||
#endif
|
||||
last_law_priority_tasks_handling_time = now ;
|
||||
|
||||
rslog(RSL_DEBUG_BASIC, ftserverzone,
|
||||
"filedexserver::tick() Invalid Interface()");
|
||||
|
||||
return 1;
|
||||
mFtDataplex->deleteUnusedServers() ;
|
||||
mFtDataplex->handlePendingCrcRequests() ;
|
||||
mFtDataplex->dispatchReceivedChunkCheckSum() ;
|
||||
}
|
||||
|
||||
int moreToTick = 0;
|
||||
|
||||
if (0 < mP3iface -> tick())
|
||||
{
|
||||
moreToTick = 1;
|
||||
#ifdef DEBUG_TICK
|
||||
std::cerr << "filedexserver::tick() moreToTick from mP3iface" << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (0 < handleInputQueues())
|
||||
{
|
||||
moreToTick = 1;
|
||||
#ifdef DEBUG_TICK
|
||||
std::cerr << "filedexserver::tick() moreToTick from InputQueues" << std::endl;
|
||||
#endif
|
||||
}
|
||||
return moreToTick;
|
||||
}
|
||||
|
||||
|
||||
// This function needs to be divided up.
|
||||
bool ftServer::handleInputQueues()
|
||||
{
|
||||
bool moreToTick = false;
|
||||
|
||||
if (handleCacheData())
|
||||
moreToTick = true;
|
||||
|
||||
if (handleFileData())
|
||||
moreToTick = true;
|
||||
|
||||
return moreToTick;
|
||||
}
|
||||
|
||||
bool ftServer::handleCacheData()
|
||||
bool ftServer::handleCacheData()
|
||||
{
|
||||
// get all the incoming results.. and print to the screen.
|
||||
RsCacheRequest *cr;
|
||||
RsCacheItem *ci;
|
||||
std::list<std::pair<RsPeerId, RsCacheData> > cacheUpdates;
|
||||
std::list<std::pair<RsPeerId, RsCacheData> >::iterator it;
|
||||
int i=0 ;
|
||||
|
||||
// Loop through Search Results.
|
||||
int i = 0;
|
||||
int i_init = 0;
|
||||
|
||||
#ifdef SERVER_DEBUG
|
||||
//std::cerr << "ftServer::handleCacheData()" << std::endl;
|
||||
#ifdef SERVER_DEBUG_CACHE
|
||||
std::cerr << "handleCacheData() " << std::endl;
|
||||
#endif
|
||||
while((ci = mP3iface -> GetSearchResult()) != NULL)
|
||||
mCacheStrapper->getCacheUpdates(cacheUpdates);
|
||||
for(it = cacheUpdates.begin(); it != cacheUpdates.end(); it++)
|
||||
{
|
||||
/* construct reply */
|
||||
RsFileTransferCacheItem *ci = new RsFileTransferCacheItem();
|
||||
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << "ftServer::handleCacheData() Recvd SearchResult (CacheResponse!)" << std::endl;
|
||||
std::string out;
|
||||
if (i++ == i_init)
|
||||
{
|
||||
out += "Recieved Search Results:\n";
|
||||
}
|
||||
ci -> print_string(out);
|
||||
rslog(RSL_DEBUG_BASIC, ftserverzone, out);
|
||||
/* id from incoming */
|
||||
ci -> PeerId(it->first);
|
||||
|
||||
ci -> file.hash = (it->second).hash;
|
||||
ci -> file.name = (it->second).name;
|
||||
ci -> file.path = ""; // (it->second).path;
|
||||
ci -> file.filesize = (it->second).size;
|
||||
ci -> cacheType = (it->second).cid.type;
|
||||
ci -> cacheSubId = (it->second).cid.subid;
|
||||
|
||||
#ifdef SERVER_DEBUG_CACHE
|
||||
std::string out2 = "Outgoing CacheStrapper Update -> RsCacheItem:\n";
|
||||
ci -> print_string(out2);
|
||||
std::cerr << out2 << std::endl;
|
||||
#endif
|
||||
|
||||
/* these go to the CacheStrapper! */
|
||||
RsCacheData data;
|
||||
data.pid = ci->PeerId();
|
||||
data.cid = CacheId(ci->cacheType, ci->cacheSubId);
|
||||
data.path = ci->file.path;
|
||||
data.name = ci->file.name;
|
||||
data.hash = ci->file.hash;
|
||||
data.size = ci->file.filesize;
|
||||
data.recvd = time(NULL) ;
|
||||
sendItem(ci);
|
||||
|
||||
mCacheStrapper->recvCacheResponse(data, time(NULL));
|
||||
|
||||
delete ci;
|
||||
i++;
|
||||
}
|
||||
|
||||
// now requested Searches.
|
||||
i_init = i;
|
||||
while((cr = mP3iface -> RequestedSearch()) != NULL)
|
||||
{
|
||||
#ifdef SERVER_DEBUG
|
||||
/* just delete these */
|
||||
std::string out = "Requested Search:\n";
|
||||
cr -> print_string(out);
|
||||
rslog(RSL_DEBUG_BASIC, ftserverzone, out);
|
||||
#endif
|
||||
delete cr;
|
||||
}
|
||||
|
||||
|
||||
// Now handle it replacement (pushed cache results)
|
||||
{
|
||||
std::list<std::pair<RsPeerId, RsCacheData> > cacheUpdates;
|
||||
std::list<std::pair<RsPeerId, RsCacheData> >::iterator it;
|
||||
|
||||
mCacheStrapper->getCacheUpdates(cacheUpdates);
|
||||
for(it = cacheUpdates.begin(); it != cacheUpdates.end(); it++)
|
||||
{
|
||||
/* construct reply */
|
||||
RsCacheItem *ci = new RsCacheItem();
|
||||
|
||||
/* id from incoming */
|
||||
ci -> PeerId(it->first);
|
||||
|
||||
ci -> file.hash = (it->second).hash;
|
||||
ci -> file.name = (it->second).name;
|
||||
ci -> file.path = ""; // (it->second).path;
|
||||
ci -> file.filesize = (it->second).size;
|
||||
ci -> cacheType = (it->second).cid.type;
|
||||
ci -> cacheSubId = (it->second).cid.subid;
|
||||
|
||||
#ifdef SERVER_DEBUG
|
||||
std::string out2 = "Outgoing CacheStrapper Update -> RsCacheItem:\n";
|
||||
ci -> print_string(out2);
|
||||
std::cerr << out2 << std::endl;
|
||||
#endif
|
||||
|
||||
//rslog(RSL_DEBUG_BASIC, ftserverzone, out2.str());
|
||||
mP3iface -> SendSearchResult(ci);
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return (i > 0);
|
||||
return i>0 ;
|
||||
}
|
||||
|
||||
|
||||
bool ftServer::handleFileData()
|
||||
int ftServer::handleIncoming()
|
||||
{
|
||||
// now File Input.
|
||||
RsFileRequest *fr;
|
||||
RsFileData *fd;
|
||||
RsFileChunkMapRequest *fcmr;
|
||||
RsFileChunkMap *fcm;
|
||||
RsFileCRC32MapRequest *fccrcmr;
|
||||
RsFileCRC32Map *fccrcm;
|
||||
RsFileSingleChunkCrcRequest *fscrcr;
|
||||
RsFileSingleChunkCrc *fscrc;
|
||||
int nhandled = 0 ;
|
||||
|
||||
int i_init = 0;
|
||||
int i = 0;
|
||||
|
||||
i_init = i;
|
||||
while((fr = mP3iface -> GetFileRequest()) != NULL )
|
||||
{
|
||||
RsItem *item = NULL ;
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << "ftServer::handleFileData() Recvd ftFiler Request" << std::endl;
|
||||
std::string out;
|
||||
if (i == i_init)
|
||||
{
|
||||
out += "Incoming(Net) File Item:\n";
|
||||
}
|
||||
fr -> print_string(out);
|
||||
rslog(RSL_DEBUG_BASIC, ftserverzone, out);
|
||||
std::cerr << "ftServer::handleIncoming() " << std::endl;
|
||||
#endif
|
||||
|
||||
i++; /* count */
|
||||
mFtDataplex->recvDataRequest(fr->PeerId(),
|
||||
fr->file.hash, fr->file.filesize,
|
||||
fr->fileoffset, fr->chunksize);
|
||||
|
||||
FileInfo(ffr);
|
||||
delete fr;
|
||||
}
|
||||
|
||||
// now File Data.
|
||||
i_init = i;
|
||||
while((fd = mP3iface -> GetFileData()) != NULL )
|
||||
while(NULL != (item = recvItem()))
|
||||
{
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << "ftServer::handleFileData() Recvd ftFiler Data" << std::endl;
|
||||
std::cerr << "hash: " << fd->fd.file.hash;
|
||||
std::cerr << " length: " << fd->fd.binData.bin_len;
|
||||
std::cerr << " data: " << fd->fd.binData.bin_data;
|
||||
std::cerr << std::endl;
|
||||
nhandled++ ;
|
||||
|
||||
std::string out;
|
||||
if (i == i_init)
|
||||
switch(item->PacketSubType())
|
||||
{
|
||||
out += "Incoming(Net) File Data:\n";
|
||||
}
|
||||
fd -> print_string(out);
|
||||
rslog(RSL_DEBUG_BASIC, ftserverzone, out);
|
||||
#endif
|
||||
i++; /* count */
|
||||
|
||||
/* incoming data */
|
||||
mFtDataplex->recvData(fd->PeerId(),
|
||||
fd->fd.file.hash, fd->fd.file.filesize,
|
||||
fd->fd.file_offset,
|
||||
fd->fd.binData.bin_len,
|
||||
fd->fd.binData.bin_data);
|
||||
|
||||
/* we've stolen the data part -> so blank before delete
|
||||
*/
|
||||
fd->fd.binData.TlvShallowClear();
|
||||
delete fd;
|
||||
}
|
||||
// now file chunkmap requests
|
||||
i_init = i;
|
||||
while((fcmr = mP3iface -> GetFileChunkMapRequest()) != NULL )
|
||||
{
|
||||
case RS_PKT_SUBTYPE_FT_DATA_REQUEST:
|
||||
{
|
||||
RsFileTransferDataRequestItem *f = dynamic_cast<RsFileTransferDataRequestItem*>(item) ;
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << "ftServer::handleFileData() Recvd ChunkMap request" << std::endl;
|
||||
std::string out;
|
||||
if (i == i_init)
|
||||
{
|
||||
out += "Incoming(Net) File Data:\n";
|
||||
}
|
||||
fcmr -> print_string(out);
|
||||
rslog(RSL_DEBUG_BASIC, ftserverzone, out);
|
||||
std::cerr << "ftServer::handleIncoming: received data request for hash " << f->file.hash << ", offset=" << f->fileoffset << ", chunk size=" << f->chunksize << std::endl;
|
||||
#endif
|
||||
i++; /* count */
|
||||
mFtDataplex->recvDataRequest(f->PeerId(), f->file.hash, f->file.filesize, f->fileoffset, f->chunksize);
|
||||
}
|
||||
break ;
|
||||
|
||||
/* incoming data */
|
||||
mFtDataplex->recvChunkMapRequest(fcmr->PeerId(), fcmr->hash,fcmr->is_client) ;
|
||||
|
||||
delete fcmr;
|
||||
}
|
||||
// now file chunkmaps
|
||||
i_init = i;
|
||||
while((fcm = mP3iface -> GetFileChunkMap()) != NULL )
|
||||
{
|
||||
case RS_PKT_SUBTYPE_FT_DATA:
|
||||
{
|
||||
RsFileTransferDataItem *f = dynamic_cast<RsFileTransferDataItem*>(item) ;
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << "ftServer::handleFileData() Recvd ChunkMap request" << std::endl;
|
||||
std::string out;
|
||||
if (i == i_init)
|
||||
{
|
||||
out += "Incoming(Net) File Data:\n";
|
||||
}
|
||||
fcm -> print_string(out);
|
||||
rslog(RSL_DEBUG_BASIC, ftserverzone, out);
|
||||
std::cerr << "ftServer::handleIncoming: received data for hash " << f->fd.file.hash << ", offset=" << f->fd.file_offset << ", chunk size=" << f->fd.binData.bin_len << std::endl;
|
||||
#endif
|
||||
i++; /* count */
|
||||
mFtDataplex->recvData(f->PeerId(), f->fd.file.hash, f->fd.file.filesize, f->fd.file_offset, f->fd.binData.bin_len, f->fd.binData.bin_data);
|
||||
|
||||
/* incoming data */
|
||||
mFtDataplex->recvChunkMap(fcm->PeerId(), fcm->hash,fcm->compressed_map,fcm->is_client) ;
|
||||
/* we've stolen the data part -> so blank before delete
|
||||
*/
|
||||
f->fd.binData.TlvShallowClear();
|
||||
}
|
||||
break ;
|
||||
|
||||
delete fcm;
|
||||
}
|
||||
// now file chunkmap requests
|
||||
i_init = i;
|
||||
while((fccrcmr = mP3iface -> GetFileCRC32MapRequest()) != NULL )
|
||||
{
|
||||
case RS_PKT_SUBTYPE_FT_CHUNK_MAP_REQUEST:
|
||||
{
|
||||
RsFileTransferChunkMapRequestItem *f = dynamic_cast<RsFileTransferChunkMapRequestItem*>(item) ;
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << "ftServer::handleFileData() Recvd ChunkMap request" << std::endl;
|
||||
std::string out;
|
||||
if (i == i_init)
|
||||
{
|
||||
out += "Incoming(Net) File Data:\n";
|
||||
}
|
||||
fccrcmr -> print_string(out);
|
||||
rslog(RSL_DEBUG_BASIC, ftserverzone, out);
|
||||
std::cerr << "ftServer::handleIncoming: received chunkmap request for hash " << f->hash << ", client=" << f->is_client << std::endl;
|
||||
#endif
|
||||
i++; /* count */
|
||||
mFtDataplex->recvChunkMapRequest(f->PeerId(), f->hash,f->is_client) ;
|
||||
}
|
||||
break ;
|
||||
|
||||
/* incoming data */
|
||||
mFtDataplex->recvCRC32MapRequest(fccrcmr->PeerId(), fccrcmr->hash) ;
|
||||
|
||||
delete fccrcmr;
|
||||
}
|
||||
// now file chunkmaps
|
||||
i_init = i;
|
||||
while((fccrcm = mP3iface -> GetFileCRC32Map()) != NULL )
|
||||
{
|
||||
case RS_PKT_SUBTYPE_FT_CHUNK_MAP:
|
||||
{
|
||||
RsFileTransferChunkMapItem *f = dynamic_cast<RsFileTransferChunkMapItem*>(item) ;
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << "ftServer::handleFileData() Recvd ChunkMap request" << std::endl;
|
||||
std::string out;
|
||||
if (i == i_init)
|
||||
{
|
||||
out += "Incoming(Net) File Data:\n";
|
||||
}
|
||||
fccrcm -> print_string(out);
|
||||
rslog(RSL_DEBUG_BASIC, ftserverzone, out);
|
||||
std::cerr << "ftServer::handleIncoming: received chunkmap for hash " << f->hash << ", client=" << f->is_client << /*", map=" << f->compressed_map <<*/ std::endl;
|
||||
#endif
|
||||
i++; /* count */
|
||||
mFtDataplex->recvChunkMap(f->PeerId(), f->hash,f->compressed_map,f->is_client) ;
|
||||
}
|
||||
break ;
|
||||
|
||||
/* incoming data */
|
||||
mFtDataplex->recvCRC32Map(fccrcm->PeerId(), fccrcm->hash,fccrcm->crc_map);
|
||||
|
||||
delete fccrcm;
|
||||
}
|
||||
// now file chunk crc requests
|
||||
i_init = i;
|
||||
while((fscrcr = mP3iface -> GetFileSingleChunkCrcRequest()) != NULL )
|
||||
{
|
||||
case RS_PKT_SUBTYPE_FT_CHUNK_CRC_REQUEST:
|
||||
{
|
||||
RsFileTransferSingleChunkCrcRequestItem *f = dynamic_cast<RsFileTransferSingleChunkCrcRequestItem*>(item) ;
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << "ftServer::handleFileData() Recvd ChunkMap request" << std::endl;
|
||||
std::string out;
|
||||
if (i == i_init)
|
||||
{
|
||||
out += "Incoming(Net) File CRC Request:\n";
|
||||
}
|
||||
fscrcr -> print_string(out);
|
||||
rslog(RSL_DEBUG_BASIC, ftserverzone, out);
|
||||
std::cerr << "ftServer::handleIncoming: received single chunk crc req for hash " << f->hash << ", chunk number=" << f->chunk_number << std::endl;
|
||||
#endif
|
||||
i++; /* count */
|
||||
mFtDataplex->recvSingleChunkCRCRequest(f->PeerId(), f->hash,f->chunk_number) ;
|
||||
}
|
||||
break ;
|
||||
|
||||
/* incoming data */
|
||||
mFtDataplex->recvSingleChunkCRCRequest(fscrcr->PeerId(), fscrcr->hash,fscrcr->chunk_number) ;
|
||||
|
||||
delete fscrcr;
|
||||
}
|
||||
// now file chunkmaps
|
||||
i_init = i;
|
||||
while((fscrc = mP3iface -> GetFileSingleChunkCrc()) != NULL )
|
||||
{
|
||||
case RS_PKT_SUBTYPE_FT_CHUNK_CRC:
|
||||
{
|
||||
RsFileTransferSingleChunkCrcItem *f = dynamic_cast<RsFileTransferSingleChunkCrcItem *>(item) ;
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << "ftServer::handleFileData() Recvd ChunkMap request" << std::endl;
|
||||
std::string out;
|
||||
if (i == i_init)
|
||||
{
|
||||
out += "Incoming(Net) File Data:\n";
|
||||
}
|
||||
fscrc -> print_string(out);
|
||||
rslog(RSL_DEBUG_BASIC, ftserverzone, out);
|
||||
std::cerr << "ftServer::handleIncoming: received single chunk crc req for hash " << f->hash << ", chunk number=" << f->chunk_number << ", checksum = " << f->check_sum << std::endl;
|
||||
#endif
|
||||
i++; /* count */
|
||||
mFtDataplex->recvSingleChunkCRC(f->PeerId(), f->hash,f->chunk_number,f->check_sum);
|
||||
}
|
||||
break ;
|
||||
|
||||
/* incoming data */
|
||||
mFtDataplex->recvSingleChunkCRC(fscrc->PeerId(), fscrc->hash,fscrc->chunk_number,fscrc->check_sum);
|
||||
case RS_PKT_SUBTYPE_FT_CACHE_ITEM:
|
||||
{
|
||||
RsFileTransferCacheItem *ci = dynamic_cast<RsFileTransferCacheItem*>(item) ;
|
||||
#ifdef SERVER_DEBUG_CACHE
|
||||
std::cerr << "ftServer::handleIncoming: received cache item hash=" << ci->file.hash << ". from peer " << ci->PeerId() << std::endl;
|
||||
#endif
|
||||
/* these go to the CacheStrapper! */
|
||||
RsCacheData data;
|
||||
data.pid = ci->PeerId();
|
||||
data.cid = CacheId(ci->cacheType, ci->cacheSubId);
|
||||
data.path = ci->file.path;
|
||||
data.name = ci->file.name;
|
||||
data.hash = ci->file.hash;
|
||||
data.size = ci->file.filesize;
|
||||
data.recvd = time(NULL) ;
|
||||
|
||||
delete fscrcr;
|
||||
mCacheStrapper->recvCacheResponse(data, time(NULL));
|
||||
}
|
||||
break ;
|
||||
|
||||
// case RS_PKT_SUBTYPE_FT_CACHE_REQUEST:
|
||||
// {
|
||||
// // do nothing
|
||||
// RsFileTransferCacheRequestItem *cr = dynamic_cast<RsFileTransferCacheRequestItem*>(item) ;
|
||||
//#ifdef SERVER_DEBUG_CACHE
|
||||
// std::cerr << "ftServer::handleIncoming: received cache request from peer " << cr->PeerId() << std::endl;
|
||||
//#endif
|
||||
// }
|
||||
// break ;
|
||||
}
|
||||
|
||||
delete item ;
|
||||
}
|
||||
if (i > 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
||||
return nhandled;
|
||||
}
|
||||
|
||||
/**********************************
|
||||
|
@ -1617,10 +1408,3 @@ bool ftServer::addConfiguration(p3ConfigMgr *cfgmgr)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ftServer::ResumeTransfers()
|
||||
{
|
||||
mFtController->activate();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue