- fixed bug (added missing call to addSerialType())

- removed unused RsFileTransferCacheRequestItem and all related functions
- fixed bug in turtle router calling members of a deleted item
- removed some debug info
 


git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.6-initdev@6789 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2013-10-02 19:56:01 +00:00
parent a455bcc5d2
commit 3a82fffd0e
9 changed files with 81 additions and 156 deletions

View File

@ -53,8 +53,8 @@ const int ftserverzone = 29539;
#include "serialiser/rsserviceids.h" #include "serialiser/rsserviceids.h"
/*** /***
* #define SERVER_DEBUG 1 * #define SERVER_DEBUG 1
* #define DEBUG_TICK 1 * #define SERVER_DEBUG_CACHE 1
***/ ***/
static const time_t FILE_TRANSFER_LOW_PRIORITY_TASKS_PERIOD = 5 ; // low priority tasks handling every 5 seconds static const time_t FILE_TRANSFER_LOW_PRIORITY_TASKS_PERIOD = 5 ; // low priority tasks handling every 5 seconds
@ -70,6 +70,8 @@ ftServer::ftServer(p3PeerMgr *pm, p3LinkMgr *lm)
mFtDataplex(NULL), mFtSearch(NULL), srvMutex("ftServer") mFtDataplex(NULL), mFtSearch(NULL), srvMutex("ftServer")
{ {
mCacheStrapper = new ftCacheStrapper(lm); mCacheStrapper = new ftCacheStrapper(lm);
addSerialType(new RsFileTransferSerialiser()) ;
} }
void ftServer::setConfigDirectory(std::string path) void ftServer::setConfigDirectory(std::string path)
@ -446,15 +448,11 @@ RsTurtleGenericTunnelItem *ftServer::deserialiseItem(void *data,uint32_t size) c
#ifdef SERVER_DEBUG #ifdef SERVER_DEBUG
std::cerr << "p3turtle: deserialising packet: " << std::endl ; std::cerr << "p3turtle: deserialising packet: " << std::endl ;
#endif #endif
#ifdef SERVER_DEBUG
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_TURTLE != getRsItemService(rstype))) if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_TURTLE != getRsItemService(rstype)))
{ {
#ifdef SERVER_DEBUG
std::cerr << " Wrong type !!" << std::endl ; std::cerr << " Wrong type !!" << std::endl ;
#endif
return NULL; /* wrong type */ return NULL; /* wrong type */
} }
#endif
switch(getRsItemSubType(rstype)) switch(getRsItemSubType(rstype))
{ {
@ -838,10 +836,15 @@ bool ftServer::shareDownloadDirectory(bool share)
/**************** Config Interface *****************************/ /**************** Config Interface *****************************/
/***************************************************************/ /***************************************************************/
/* Key Functions to be overloaded for Full Configuration */ /* Key Functions to be overloaded for Full Configuration */
RsSerialiser *ftServer::setupSerialiser() 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*/) bool ftServer::saveList(bool &/*cleanup*/, std::list<RsItem *>& /*list*/)
@ -868,6 +871,9 @@ bool ftServer::loadConfigMap(std::map<std::string, std::string> &/*configMap*/)
/* Client Send */ /* Client Send */
bool ftServer::sendDataRequest(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize) 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)) if(mTurtleRouter->isTurtlePeer(peerId))
{ {
RsTurtleFileRequestItem *item = new RsTurtleFileRequestItem ; RsTurtleFileRequestItem *item = new RsTurtleFileRequestItem ;
@ -879,6 +885,7 @@ bool ftServer::sendDataRequest(const std::string& peerId, const std::string& has
} }
else else
{ {
std::cerr << "ftServer::sendDataRequest() " <<std::endl;
/* create a packet */ /* create a packet */
/* push to networking part */ /* push to networking part */
RsFileTransferDataRequestItem *rfi = new RsFileTransferDataRequestItem(); RsFileTransferDataRequestItem *rfi = new RsFileTransferDataRequestItem();
@ -902,6 +909,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) 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)) if(mTurtleRouter->isTurtlePeer(peerId))
{ {
RsTurtleFileMapRequestItem *item = new RsTurtleFileMapRequestItem ; RsTurtleFileMapRequestItem *item = new RsTurtleFileMapRequestItem ;
@ -928,6 +938,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) 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)) if(mTurtleRouter->isTurtlePeer(peerId))
{ {
RsTurtleFileMapItem *item = new RsTurtleFileMapItem ; RsTurtleFileMapItem *item = new RsTurtleFileMapItem ;
@ -956,6 +969,9 @@ bool ftServer::sendChunkMap(const std::string& peerId,const std::string& hash,co
bool ftServer::sendSingleChunkCRCRequest(const std::string& peerId,const std::string& hash,uint32_t chunk_number) 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)) if(mTurtleRouter->isTurtlePeer(peerId))
{ {
RsTurtleChunkCrcRequestItem *item = new RsTurtleChunkCrcRequestItem; RsTurtleChunkCrcRequestItem *item = new RsTurtleChunkCrcRequestItem;
@ -984,6 +1000,9 @@ bool ftServer::sendSingleChunkCRCRequest(const std::string& peerId,const std::st
bool ftServer::sendSingleChunkCRC(const std::string& peerId,const std::string& hash,uint32_t chunk_number,const Sha1CheckSum& crc) 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)) if(mTurtleRouter->isTurtlePeer(peerId))
{ {
RsTurtleChunkCrcItem *item = new RsTurtleChunkCrcItem; RsTurtleChunkCrcItem *item = new RsTurtleChunkCrcItem;
@ -1119,6 +1138,9 @@ void ftServer::receiveTurtleData(RsTurtleGenericTunnelItem *i,
case RS_TURTLE_SUBTYPE_FILE_REQUEST: case RS_TURTLE_SUBTYPE_FILE_REQUEST:
{ {
RsTurtleFileRequestItem *item = dynamic_cast<RsTurtleFileRequestItem *>(i) ; 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) ; getMultiplexer()->recvDataRequest(virtual_peer_id,hash,0,item->chunk_offset,item->chunk_size) ;
} }
break ; break ;
@ -1126,6 +1148,9 @@ void ftServer::receiveTurtleData(RsTurtleGenericTunnelItem *i,
case RS_TURTLE_SUBTYPE_FILE_DATA : case RS_TURTLE_SUBTYPE_FILE_DATA :
{ {
RsTurtleFileDataItem *item = dynamic_cast<RsTurtleFileDataItem *>(i) ; 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) ; 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 item->chunk_data = NULL ; // this prevents deletion in the destructor of RsFileDataItem, because data will be deleted
@ -1137,6 +1162,9 @@ void ftServer::receiveTurtleData(RsTurtleGenericTunnelItem *i,
case RS_TURTLE_SUBTYPE_FILE_MAP : case RS_TURTLE_SUBTYPE_FILE_MAP :
{ {
RsTurtleFileMapItem *item = dynamic_cast<RsTurtleFileMapItem *>(i) ; 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) ; getMultiplexer()->recvChunkMap(virtual_peer_id,hash,item->compressed_map,direction == RsTurtleGenericTunnelItem::DIRECTION_CLIENT) ;
} }
break ; break ;
@ -1144,6 +1172,9 @@ void ftServer::receiveTurtleData(RsTurtleGenericTunnelItem *i,
case RS_TURTLE_SUBTYPE_FILE_MAP_REQUEST: 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) ; getMultiplexer()->recvChunkMapRequest(virtual_peer_id,hash,direction == RsTurtleGenericTunnelItem::DIRECTION_CLIENT) ;
} }
break ; break ;
@ -1151,6 +1182,9 @@ void ftServer::receiveTurtleData(RsTurtleGenericTunnelItem *i,
case RS_TURTLE_SUBTYPE_CHUNK_CRC : case RS_TURTLE_SUBTYPE_CHUNK_CRC :
{ {
RsTurtleChunkCrcItem *item = dynamic_cast<RsTurtleChunkCrcItem *>(i) ; 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) ; getMultiplexer()->recvSingleChunkCRC(virtual_peer_id,hash,item->chunk_number,item->check_sum) ;
} }
break ; break ;
@ -1158,6 +1192,9 @@ void ftServer::receiveTurtleData(RsTurtleGenericTunnelItem *i,
case RS_TURTLE_SUBTYPE_CHUNK_CRC_REQUEST: case RS_TURTLE_SUBTYPE_CHUNK_CRC_REQUEST:
{ {
RsTurtleChunkCrcRequestItem *item = dynamic_cast<RsTurtleChunkCrcRequestItem *>(i) ; 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) ; getMultiplexer()->recvSingleChunkCRCRequest(virtual_peer_id,hash,item->chunk_number) ;
} }
break ; break ;
@ -1174,8 +1211,11 @@ int ftServer::tick()
{ {
bool moreToTick = false ; bool moreToTick = false ;
moreToTick = handleIncoming() || moreToTick ; // order is important!! if(handleIncoming())
moreToTick = handleCacheData() || moreToTick ; moreToTick = true;
if(handleCacheData())
moreToTick = true;
static time_t last_law_priority_tasks_handling_time = 0 ; static time_t last_law_priority_tasks_handling_time = 0 ;
time_t now = time(NULL) ; time_t now = time(NULL) ;
@ -1198,6 +1238,9 @@ bool ftServer::handleCacheData()
std::list<std::pair<RsPeerId, CacheData> >::iterator it; std::list<std::pair<RsPeerId, CacheData> >::iterator it;
int i=0 ; int i=0 ;
#ifdef SERVER_DEBUG_CACHE
std::cerr << "handleCacheData() " << std::endl;
#endif
mCacheStrapper->getCacheUpdates(cacheUpdates); mCacheStrapper->getCacheUpdates(cacheUpdates);
for(it = cacheUpdates.begin(); it != cacheUpdates.end(); it++) for(it = cacheUpdates.begin(); it != cacheUpdates.end(); it++)
{ {
@ -1214,7 +1257,7 @@ bool ftServer::handleCacheData()
ci -> cacheType = (it->second).cid.type; ci -> cacheType = (it->second).cid.type;
ci -> cacheSubId = (it->second).cid.subid; ci -> cacheSubId = (it->second).cid.subid;
#ifdef SERVER_DEBUG #ifdef SERVER_DEBUG_CACHE
std::string out2 = "Outgoing CacheStrapper Update -> RsCacheItem:\n"; std::string out2 = "Outgoing CacheStrapper Update -> RsCacheItem:\n";
ci -> print_string(out2); ci -> print_string(out2);
std::cerr << out2 << std::endl; std::cerr << out2 << std::endl;
@ -1234,6 +1277,9 @@ int ftServer::handleIncoming()
int nhandled = 0 ; int nhandled = 0 ;
RsItem *item = NULL ; RsItem *item = NULL ;
#ifdef SERVER_DEBUG
std::cerr << "ftServer::handleIncoming() " << std::endl;
#endif
while(NULL != (item = recvItem())) while(NULL != (item = recvItem()))
{ {
@ -1279,7 +1325,7 @@ int ftServer::handleIncoming()
{ {
RsFileTransferChunkMapItem *f = dynamic_cast<RsFileTransferChunkMapItem*>(item) ; RsFileTransferChunkMapItem *f = dynamic_cast<RsFileTransferChunkMapItem*>(item) ;
#ifdef SERVER_DEBUG #ifdef SERVER_DEBUG
std::cerr << "ftServer::handleIncoming: received chunkmap for hash " << f->hash << ", client=" << f->is_client << ", map=" << f->compressed_map << std::endl; std::cerr << "ftServer::handleIncoming: received chunkmap for hash " << f->hash << ", client=" << f->is_client << /*", map=" << f->compressed_map <<*/ std::endl;
#endif #endif
mFtDataplex->recvChunkMap(f->PeerId(), f->hash,f->compressed_map,f->is_client) ; mFtDataplex->recvChunkMap(f->PeerId(), f->hash,f->compressed_map,f->is_client) ;
} }
@ -1308,8 +1354,8 @@ int ftServer::handleIncoming()
case RS_PKT_SUBTYPE_FT_CACHE_ITEM: case RS_PKT_SUBTYPE_FT_CACHE_ITEM:
{ {
RsFileTransferCacheItem *ci = dynamic_cast<RsFileTransferCacheItem*>(item) ; RsFileTransferCacheItem *ci = dynamic_cast<RsFileTransferCacheItem*>(item) ;
#ifdef SERVER_DEBUG #ifdef SERVER_DEBUG_CACHE
std::cerr << "ftServer::handleIncoming: received cache item hash=" << ci->file.hash << ". from peer " << ci->PeerId() << std::ednl; std::cerr << "ftServer::handleIncoming: received cache item hash=" << ci->file.hash << ". from peer " << ci->PeerId() << std::endl;
#endif #endif
/* these go to the CacheStrapper! */ /* these go to the CacheStrapper! */
CacheData data; CacheData data;
@ -1325,15 +1371,15 @@ int ftServer::handleIncoming()
} }
break ; break ;
case RS_PKT_SUBTYPE_FT_CACHE_REQUEST: // case RS_PKT_SUBTYPE_FT_CACHE_REQUEST:
{ // {
// do nothing // // do nothing
RsFileTransferCacheRequestItem *cr = dynamic_cast<RsFileTransferCacheRequestItem*>(item) ; // RsFileTransferCacheRequestItem *cr = dynamic_cast<RsFileTransferCacheRequestItem*>(item) ;
#ifdef SERVER_DEBUG //#ifdef SERVER_DEBUG_CACHE
std::cerr << "ftServer::handleIncoming: received cache request from peer " << cr->PeerId() << std::ednl; // std::cerr << "ftServer::handleIncoming: received cache request from peer " << cr->PeerId() << std::endl;
#endif //#endif
} // }
break ; // break ;
} }
delete item ; delete item ;

View File

@ -74,7 +74,6 @@ const uint32_t MIN_TIME_BETWEEN_NET_RESET = 5;
* #define NETMGR_DEBUG_STATEBOX 1 * #define NETMGR_DEBUG_STATEBOX 1
***/ ***/
pqiNetStatus::pqiNetStatus() pqiNetStatus::pqiNetStatus()
:mLocalAddrOk(false), mExtAddrOk(false), mExtAddrStableOk(false), :mLocalAddrOk(false), mExtAddrOk(false), mExtAddrStableOk(false),
mUpnpOk(false), mDhtOk(false), mResetReq(false) mUpnpOk(false), mDhtOk(false), mResetReq(false)

View File

@ -70,6 +70,7 @@ int p3ServiceServer::addService(pqiService *ts)
it = services.find(ts -> getType()); it = services.find(ts -> getType());
if (it != services.end()) if (it != services.end())
{ {
std::cerr << "p3ServiceServer::addService(): Service already added with id " << ts->getType() << "!" << std::endl;
// it exists already! // it exists already!
return -1; return -1;
} }

View File

@ -45,7 +45,6 @@ const int PQISTREAM_ABS_MAX = 100000000; /* 100 MB/sec (actually per loop) */
#define DEBUG_PQISTREAMER 1 #define DEBUG_PQISTREAMER 1
***/ ***/
#ifdef DEBUG_TRANSFERS #ifdef DEBUG_TRANSFERS
#include "util/rsprint.h" #include "util/rsprint.h"
#endif #endif

View File

@ -70,6 +70,8 @@ class Sha1CheckSum
std::string toStdString() const ; std::string toStdString() const ;
bool operator==(const Sha1CheckSum& s) const ; bool operator==(const Sha1CheckSum& s) const ;
friend std::ostream& operator<<(std::ostream& out,const Sha1CheckSum& sum) { return out << sum.toStdString() ; }
// private: // private:
uint32_t fourbytes[5] ; uint32_t fourbytes[5] ;
}; };

View File

@ -56,7 +56,6 @@ RsFileTransferItem *RsFileTransferSerialiser::deserialise(void *data, uint32_t *
switch(getRsItemSubType(rstype)) switch(getRsItemSubType(rstype))
{ {
case RS_PKT_SUBTYPE_FT_CACHE_REQUEST: return deserialise_RsFileTransferCacheRequestItem(data, *pktsize);
case RS_PKT_SUBTYPE_FT_CACHE_ITEM: return deserialise_RsFileTransferCacheItem(data, *pktsize); case RS_PKT_SUBTYPE_FT_CACHE_ITEM: return deserialise_RsFileTransferCacheItem(data, *pktsize);
case RS_PKT_SUBTYPE_FT_DATA_REQUEST: return deserialise_RsFileTransferDataRequestItem(data, *pktsize); case RS_PKT_SUBTYPE_FT_DATA_REQUEST: return deserialise_RsFileTransferDataRequestItem(data, *pktsize);
case RS_PKT_SUBTYPE_FT_DATA: return deserialise_RsFileTransferDataItem(data, *pktsize); case RS_PKT_SUBTYPE_FT_DATA: return deserialise_RsFileTransferDataItem(data, *pktsize);
@ -65,6 +64,7 @@ RsFileTransferItem *RsFileTransferSerialiser::deserialise(void *data, uint32_t *
case RS_PKT_SUBTYPE_FT_CHUNK_CRC_REQUEST: return deserialise_RsFileTransferSingleChunkCrcRequestItem(data,*pktsize) ; case RS_PKT_SUBTYPE_FT_CHUNK_CRC_REQUEST: return deserialise_RsFileTransferSingleChunkCrcRequestItem(data,*pktsize) ;
case RS_PKT_SUBTYPE_FT_CHUNK_CRC: return deserialise_RsFileTransferSingleChunkCrcItem(data,*pktsize) ; case RS_PKT_SUBTYPE_FT_CHUNK_CRC: return deserialise_RsFileTransferSingleChunkCrcItem(data,*pktsize) ;
default: default:
std::cerr << "RsFileTransferSerialiser::deserialise(): Could not de-serialise item. SubPacket id = " << std::hex << getRsItemSubType(rstype) << " id = " << rstype << std::dec << std::endl;
return NULL; return NULL;
} }
return NULL; return NULL;
@ -74,17 +74,6 @@ RsFileTransferItem *RsFileTransferSerialiser::deserialise(void *data, uint32_t *
/* OUTPUTS */ /* OUTPUTS */
/**********************************************************************************************/ /**********************************************************************************************/
std::ostream& RsFileTransferCacheRequestItem::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsFileTransferCacheRequestItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "CacheId: " << cacheType << "/" << cacheSubId << std::endl;
file.print(out, int_Indent);
printRsItemEnd(out, "RsFileTransferCacheRequestItem", indent);
return out;
}
std::ostream& RsFileTransferCacheItem::print(std::ostream &out, uint16_t indent) std::ostream& RsFileTransferCacheItem::print(std::ostream &out, uint16_t indent)
{ {
printRsItemBase(out, "RsFileTransferCacheItem", indent); printRsItemBase(out, "RsFileTransferCacheItem", indent);
@ -183,14 +172,6 @@ uint32_t RsFileTransferDataItem::serial_size()
return s; return s;
} }
uint32_t RsFileTransferCacheRequestItem::serial_size()
{
uint32_t s = 8; /* header */
s += 4; /* type/subid */
s += file.TlvSize();
return s;
}
uint32_t RsFileTransferChunkMapRequestItem::serial_size() uint32_t RsFileTransferChunkMapRequestItem::serial_size()
{ {
uint32_t s = 8; /* header */ uint32_t s = 8; /* header */
@ -245,13 +226,7 @@ void RsFileTransferDataItem::clear()
{ {
fd.TlvClear(); fd.TlvClear();
} }
void RsFileTransferCacheRequestItem::clear()
{
cacheType = 0;
cacheSubId = 0;
file.TlvClear();
}
/**********************************************************************************************/ /**********************************************************************************************/
/* SERIALISATION */ /* SERIALISATION */
/**********************************************************************************************/ /**********************************************************************************************/
@ -372,29 +347,6 @@ bool RsFileTransferChunkMapItem::serialise(void *data, uint32_t& pktsize)
return ok; return ok;
} }
/* serialise the data to the buffer */
bool RsFileTransferCacheRequestItem::serialise(void *data, uint32_t& pktsize)
{
uint32_t tlvsize,offset=0;
bool ok = true;
if(!serialise_header(data,pktsize,tlvsize,offset))
return false ;
/* add mandatory parts first */
ok &= setRawUInt16(data, tlvsize, &offset, cacheType);
ok &= setRawUInt16(data, tlvsize, &offset, cacheSubId);
ok &= file.SetTlv(data, tlvsize, &offset);
if (offset != tlvsize)
{
ok = false;
std::cerr << "RsFileItemSerialiser::serialiseReq() Size Error! " << std::endl;
}
return ok;
}
/* serialise the data to the buffer */ /* serialise the data to the buffer */
bool RsFileTransferDataItem::serialise(void *data, uint32_t& pktsize) bool RsFileTransferDataItem::serialise(void *data, uint32_t& pktsize)
{ {
@ -482,58 +434,6 @@ bool RsFileTransferCacheItem::serialise(void *data, uint32_t& pktsize)
/* DESERIALISATION */ /* DESERIALISATION */
/**********************************************************************************************/ /**********************************************************************************************/
RsFileTransferItem *RsFileTransferSerialiser::deserialise_RsFileTransferCacheRequestItem(void *data, uint32_t pktsize)
{
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if(RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype) || RS_SERVICE_TYPE_FILE_TRANSFER != getRsItemType(rstype) || RS_PKT_SUBTYPE_FT_CACHE_REQUEST != getRsItemSubType(rstype))
{
std::cerr << "RsFileTransferSerialiser::deserialise_RsFileTransferCacheRequest(): wong subtype!" << std::endl;
return NULL; /* wrong type */
}
if (pktsize < rssize) /* check size */
{
std::cerr << "RsFileTransferSerialiser::deserialise_RsFileTransferCacheRequest(): size inconsistency!" << std::endl;
return NULL; /* not enough data */
}
bool ok = true;
/* ready to load */
RsFileTransferCacheRequestItem *item = new RsFileTransferCacheRequestItem();
item->clear();
/* skip the header */
offset += 8;
/* get mandatory parts first */
ok &= getRawUInt16(data, rssize, &offset, &(item->cacheType));
ok &= getRawUInt16(data, rssize, &offset, &(item->cacheSubId));
ok &= item->file.GetTlv(data, rssize, &offset);
if (offset != rssize)
{
/* error */
delete item;
return NULL;
}
if (!ok)
{
delete item;
return NULL;
}
return item;
}
RsFileTransferItem *RsFileTransferSerialiser::deserialise_RsFileTransferCacheItem(void *data, uint32_t pktsize) RsFileTransferItem *RsFileTransferSerialiser::deserialise_RsFileTransferCacheItem(void *data, uint32_t pktsize)
{ {
/* get the type and size */ /* get the type and size */

View File

@ -194,26 +194,6 @@ class RsFileTransferSingleChunkCrcItem: public RsFileTransferItem
Sha1CheckSum check_sum ; // CRC32 map of the file. Sha1CheckSum check_sum ; // CRC32 map of the file.
}; };
class RsFileTransferCacheRequestItem: public RsFileTransferItem
{
public:
RsFileTransferCacheRequestItem() :RsFileTransferItem(RS_PKT_SUBTYPE_FT_CACHE_REQUEST)
{
setPriorityLevel(QOS_PRIORITY_RS_CACHE_REQUEST);
}
virtual ~RsFileTransferCacheRequestItem() {}
virtual bool serialise(void *data,uint32_t& size) ;
virtual uint32_t serial_size() ;
virtual void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
// private part
//
uint16_t cacheType;
uint16_t cacheSubId;
RsTlvFileItem file; /* file information */
};
class RsFileTransferCacheItem: public RsFileTransferItem class RsFileTransferCacheItem: public RsFileTransferItem
{ {
public: public:
@ -256,7 +236,6 @@ class RsFileTransferSerialiser: public RsSerialType
virtual RsFileTransferItem *deserialise(void *data, uint32_t *size); virtual RsFileTransferItem *deserialise(void *data, uint32_t *size);
private: private:
RsFileTransferItem *deserialise_RsFileTransferCacheRequestItem(void *data, uint32_t pktsize);
RsFileTransferItem *deserialise_RsFileTransferCacheItem(void *data, uint32_t pktsize); RsFileTransferItem *deserialise_RsFileTransferCacheItem(void *data, uint32_t pktsize);
RsFileTransferItem *deserialise_RsFileTransferChunkMapRequestItem(void *data, uint32_t pktsize); RsFileTransferItem *deserialise_RsFileTransferChunkMapRequestItem(void *data, uint32_t pktsize);
RsFileTransferItem *deserialise_RsFileTransferChunkMapItem(void *data, uint32_t pktsize); RsFileTransferItem *deserialise_RsFileTransferChunkMapItem(void *data, uint32_t pktsize);

View File

@ -36,7 +36,6 @@ RsDisc *rsDisc = NULL;
* #define P3DISC_DEBUG 1 * #define P3DISC_DEBUG 1
****/ ****/
bool populateContactInfo(const peerState &detail, RsDiscContactItem *pkt) bool populateContactInfo(const peerState &detail, RsDiscContactItem *pkt)
{ {
pkt->clear(); pkt->clear();

View File

@ -23,8 +23,6 @@
* *
*/ */
//#define P3TURTLE_DEBUG
#include <unistd.h> #include <unistd.h>
#include <stdexcept> #include <stdexcept>
#include <stdlib.h> #include <stdlib.h>
@ -1103,7 +1101,7 @@ bool p3turtle::getTunnelServiceInfo(TurtleTunnelId tunnel_id,std::string& vpid,s
if(it2 == _local_tunnels.end()) if(it2 == _local_tunnels.end())
{ {
#ifdef P3TURTLE_DEBUG #ifdef P3TURTLE_DEBUG
std::cerr << "p3turtle: unknown tunnel id " << (void*)item->tunnelId() << std::endl ; std::cerr << "p3turtle: unknown tunnel id " << (void*)tunnel_id << std::endl ;
#endif #endif
return false; return false;
} }
@ -1450,6 +1448,8 @@ void p3turtle::handleTunnelRequest(RsTurtleOpenTunnelItem *item)
res_item->tunnel_id = item->partial_tunnel_id ^ generatePersonalFilePrint(item->file_hash,false) ; res_item->tunnel_id = item->partial_tunnel_id ^ generatePersonalFilePrint(item->file_hash,false) ;
res_item->PeerId(item->PeerId()) ; res_item->PeerId(item->PeerId()) ;
TurtleTunnelId t_id = res_item->tunnel_id ;
sendItem(res_item) ; sendItem(res_item) ;
// Note in the tunnels list that we have an ending tunnel here. // Note in the tunnels list that we have an ending tunnel here.
@ -1461,11 +1461,11 @@ void p3turtle::handleTunnelRequest(RsTurtleOpenTunnelItem *item)
tt.transfered_bytes = 0 ; tt.transfered_bytes = 0 ;
tt.speed_Bps = 0.0f ; tt.speed_Bps = 0.0f ;
_local_tunnels[res_item->tunnel_id] = tt ; _local_tunnels[t_id] = tt ;
// We add a virtual peer for that tunnel+hash combination. // We add a virtual peer for that tunnel+hash combination.
// //
locked_addDistantPeer(item->file_hash,res_item->tunnel_id) ; locked_addDistantPeer(item->file_hash,t_id) ;
// Store some info string about the tunnel. // Store some info string about the tunnel.
// //
@ -1473,7 +1473,7 @@ void p3turtle::handleTunnelRequest(RsTurtleOpenTunnelItem *item)
// Notify the client service that there's a new virtual peer id available as a client. // Notify the client service that there's a new virtual peer id available as a client.
// //
service->addVirtualPeer(item->file_hash,_local_tunnels[res_item->tunnel_id].vpid,RsTurtleGenericTunnelItem::DIRECTION_CLIENT) ; service->addVirtualPeer(item->file_hash,_local_tunnels[t_id].vpid,RsTurtleGenericTunnelItem::DIRECTION_CLIENT) ;
// We return straight, because when something is found, there's no need to digg a tunnel further. // We return straight, because when something is found, there's no need to digg a tunnel further.
// //
@ -2093,7 +2093,7 @@ void p3turtle::dumpState()
//std::cerr << ", last_req=" << (void*)it->second.last_request << ", time_stamp = " << it->second.time_stamp << "(" << now-it->second.time_stamp << " secs ago)" << std::endl ; //std::cerr << ", last_req=" << (void*)it->second.last_request << ", time_stamp = " << it->second.time_stamp << "(" << now-it->second.time_stamp << " secs ago)" << std::endl ;
} }
std::cerr << " Active outgoing file hashes: " << _outgoing_file_hashes.size() << std::endl ; std::cerr << " Active outgoing file hashes: " << _outgoing_file_hashes.size() << std::endl ;
for(std::map<TurtleFileHash,std::string>::const_iterator it(_outgoing_file_hashes.begin());it!=_outgoing_file_hashes.end();++it) for(std::map<TurtleFileHash,RsTurtleClientService*>::const_iterator it(_outgoing_file_hashes.begin());it!=_outgoing_file_hashes.end();++it)
std::cerr << " hash=0x" << it->first << std::endl ; std::cerr << " hash=0x" << it->first << std::endl ;
std::cerr << " Local tunnels:" << std::endl ; std::cerr << " Local tunnels:" << std::endl ;