From 6760b35ae682ba7270cad28cb1f7ea342cf4aaea Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 6 Apr 2013 13:16:54 +0000 Subject: [PATCH] fixed a few bugs related to previous commit git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-GenericTunneling@6294 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/ft/ftserver.cc | 10 +++++----- libretroshare/src/turtle/p3turtle.cc | 27 +++++++++++++++++---------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index 2a13705f2..3d3bf6fa6 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -1109,17 +1109,17 @@ bool ftServer::sendData(const std::string& peerId, const std::string& hash, uint { RsTurtleFileDataItem *item = new RsTurtleFileDataItem ; - item->chunk_offset = offset ; - item->chunk_size = chunksize ; - item->chunk_data = malloc(chunksize) ; + item->chunk_offset = offset+baseoffset ; + item->chunk_size = chunk; + item->chunk_data = malloc(chunk) ; if(item->chunk_data == NULL) { - std::cerr << "p3turtle: Warning: failed malloc of " << chunksize << " bytes for sending data packet." << std::endl ; + std::cerr << "p3turtle: Warning: failed malloc of " << chunk << " bytes for sending data packet." << std::endl ; delete item; return false; } - memcpy(item->chunk_data,(void*)((uint8_t*)data),chunksize) ; + memcpy(item->chunk_data,&(((uint8_t *) data)[offset]),chunk) ; mTurtleRouter->sendTurtleData(peerId,item) ; } diff --git a/libretroshare/src/turtle/p3turtle.cc b/libretroshare/src/turtle/p3turtle.cc index 8f0239161..4a8aba985 100644 --- a/libretroshare/src/turtle/p3turtle.cc +++ b/libretroshare/src/turtle/p3turtle.cc @@ -877,11 +877,6 @@ void p3turtle::handleSearchRequest(RsTurtleSearchRequestItem *item) res_item = NULL ; } } - -#ifdef P3TURTLE_DEBUG - else - std::cerr << " Rejecting local search because strategy is FRIENDS_ONLY and item depth=" << item->depth << std::endl ; -#endif } // If search depth not too large, also forward this search request to all other peers. @@ -1135,17 +1130,29 @@ void p3turtle::sendTurtleData(const std::string& virtual_peer_id,RsTurtleGeneric if(it == _virtual_peers.end()) { #ifdef P3TURTLE_DEBUG - std::cerr << "p3turtle::senddataRequest: cannot find virtual peer " << peerId << " in VP list." << std::endl ; + std::cerr << "p3turtle::senddataRequest: cannot find virtual peer " << virtual_peer_id << " in VP list." << std::endl ; #endif + delete item ; return ; } TurtleTunnelId tunnel_id = it->second ; - TurtleTunnel& tunnel(_local_tunnels[tunnel_id]) ; + std::map::iterator it2( _local_tunnels.find(tunnel_id) ) ; + + if(it2 == _local_tunnels.end()) + { + std::cerr << "p3turtle::client asked to send a packet through tunnel that has previously been deleted. Not a big issue unless it happens in masses." << std::endl; + delete item ; + return ; + } + TurtleTunnel& tunnel(it2->second) ; item->tunnel_id = tunnel_id ; // we should randomly select a tunnel, or something more clever. std::string ownid = mLinkMgr->getOwnId() ; + if(item->shouldStampTunnel()) + tunnel.time_stamp = time(NULL) ; + if(tunnel.local_src == ownid) { item->setTravelingDirection(RsTurtleGenericTunnelItem::DIRECTION_SERVER) ; @@ -2031,14 +2038,14 @@ void p3turtle::dumpState() std::cerr << " Active incoming file hashes: " << _incoming_file_hashes.size() << std::endl ; for(std::map::const_iterator it(_incoming_file_hashes.begin());it!=_incoming_file_hashes.end();++it) { - std::cerr << " hash=0x" << it->first << ", name=" << it->second.name << ", size=" << it->second.size << ", tunnel ids =" ; + std::cerr << " hash=0x" << it->first << ", tunnel ids =" ; for(std::vector::const_iterator it2(it->second.tunnels.begin());it2!=it->second.tunnels.end();++it2) std::cerr << " " << (void*)*it2 ; //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 ; - for(std::map::const_iterator it(_outgoing_file_hashes.begin());it!=_outgoing_file_hashes.end();++it) - std::cerr << " hash=0x" << it->first << ", name=" << it->second.fname << ", size=" << it->second.size << std::endl ; + for(std::map::const_iterator it(_outgoing_file_hashes.begin());it!=_outgoing_file_hashes.end();++it) + std::cerr << " hash=0x" << it->first << std::endl ; std::cerr << " Local tunnels:" << std::endl ; for(std::map::const_iterator it(_local_tunnels.begin());it!=_local_tunnels.end();++it)