mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-25 01:10:19 -05:00
- added debug ifdef to GRouter code
- switched turtle router and grouter to use service control git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7216 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
600639db51
commit
d340440998
@ -191,10 +191,14 @@
|
||||
#include "groutertypes.h"
|
||||
#include "grouterclientservice.h"
|
||||
|
||||
/**********************/
|
||||
//#define GROUTER_DEBUG
|
||||
/**********************/
|
||||
|
||||
const std::string p3GRouter::SERVICE_INFO_APP_NAME = "Global Router" ;
|
||||
|
||||
p3GRouter::p3GRouter(p3LinkMgr *lm)
|
||||
: p3Service(), p3Config(), mLinkMgr(lm), grMtx("GRouter")
|
||||
p3GRouter::p3GRouter(p3ServiceControl *sc,p3LinkMgr *lm)
|
||||
: p3Service(), p3Config(), mServiceControl(sc), mLinkMgr(lm), grMtx("GRouter")
|
||||
{
|
||||
addSerialType(new RsGRouterSerialiser()) ;
|
||||
|
||||
@ -234,6 +238,7 @@ int p3GRouter::tick()
|
||||
_routing_matrix.updateRoutingProbabilities() ;
|
||||
}
|
||||
|
||||
#ifdef GROUTER_DEBUG
|
||||
// Debug dump everything
|
||||
//
|
||||
if(now > last_debug_output_time + RS_GROUTER_DEBUG_OUTPUT_PERIOD)
|
||||
@ -241,13 +246,16 @@ int p3GRouter::tick()
|
||||
last_debug_output_time = now ;
|
||||
debugDump() ;
|
||||
}
|
||||
#endif
|
||||
|
||||
// If content has changed, save config, at most every RS_GROUTER_MIN_CONFIG_SAVE_PERIOD seconds appart
|
||||
// Otherwise, always save at least every RS_GROUTER_MAX_CONFIG_SAVE_PERIOD seconds
|
||||
//
|
||||
if(_changed && now > last_config_changed + RS_GROUTER_MIN_CONFIG_SAVE_PERIOD)
|
||||
{
|
||||
#ifdef GROUTER_DEBUG
|
||||
std::cerr << "p3GRouter::tick(): triggering config save." << std::endl;
|
||||
#endif
|
||||
|
||||
_changed = false ;
|
||||
last_config_changed = now ;
|
||||
@ -271,7 +279,9 @@ void p3GRouter::autoWash()
|
||||
{
|
||||
RsStackMutex mtx(grMtx) ;
|
||||
|
||||
#ifdef GROUTER_DEBUG
|
||||
std::cerr << "p3GRouter::autoWash(): cleaning old entried." << std::endl;
|
||||
#endif
|
||||
|
||||
// cleanup cache
|
||||
|
||||
@ -280,7 +290,9 @@ void p3GRouter::autoWash()
|
||||
for(std::map<GRouterKeyPropagationId,time_t>::iterator it(_key_diffusion_time_stamps.begin());it!=_key_diffusion_time_stamps.end();)
|
||||
if(it->second + RS_GROUTER_KEY_DIFFUSION_MAX_KEEP < now)
|
||||
{
|
||||
#ifdef GROUTER_DEBUG
|
||||
std::cerr << " Removing key diffusion time stamp " << it->second << " for diffusion id " << std::hex << it->first << std::dec << std::endl;
|
||||
#endif
|
||||
std::map<GRouterKeyPropagationId,time_t>::iterator tmp(it) ;
|
||||
++tmp ;
|
||||
_key_diffusion_time_stamps.erase(it) ;
|
||||
@ -291,8 +303,10 @@ void p3GRouter::autoWash()
|
||||
|
||||
// look into pending items.
|
||||
|
||||
#ifdef GROUTER_DEBUG
|
||||
std::cerr << " Pending key diffusion items: " << _key_diffusion_items.size() << std::endl;
|
||||
std::cerr << " Pending messages to route : " << _pending_messages.size() << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
void p3GRouter::routePendingObjects()
|
||||
@ -301,20 +315,23 @@ void p3GRouter::routePendingObjects()
|
||||
|
||||
time_t now = time(NULL) ;
|
||||
|
||||
#ifdef GROUTER_DEBUG
|
||||
std::cerr << "p3GRouter::routeObjects() triage phase:" << std::endl;
|
||||
std::cerr << "Cached Items : " << _pending_messages.size() << std::endl;
|
||||
#endif
|
||||
|
||||
std::list<RsPeerId> lst ;
|
||||
mLinkMgr->getOnlineList(lst) ;
|
||||
RsPeerId own_id( mLinkMgr->getOwnId() );
|
||||
std::set<RsPeerId> lst ;
|
||||
mServiceControl->getPeersConnected(RS_SERVICE_TYPE_GROUTER,lst) ;
|
||||
RsPeerId own_id( mServiceControl->getOwnId() );
|
||||
|
||||
std::vector<RsPeerId> pids ;
|
||||
for(std::list<RsPeerId>::const_iterator it(lst.begin());it!=lst.end();++it)
|
||||
for(std::set<RsPeerId>::const_iterator it(lst.begin());it!=lst.end();++it)
|
||||
pids.push_back(*it) ;
|
||||
|
||||
for(std::map<GRouterMsgPropagationId, GRouterRoutingInfo>::iterator it(_pending_messages.begin());it!=_pending_messages.end();)
|
||||
if((it->second.status_flags == RS_GROUTER_ROUTING_STATE_PEND) || (it->second.status_flags == RS_GROUTER_ROUTING_STATE_SENT && it->second.tried_friends.front().time_stamp+RS_GROUTER_ROUTING_WAITING_TIME < now))
|
||||
{
|
||||
#ifdef GROUTER_DEBUG
|
||||
std::cerr << " Msg id: " << std::hex << it->first << std::dec << std::endl;
|
||||
std::cerr << " Origin: " << it->second.origin.toStdString() << std::endl;
|
||||
std::cerr << " Last : " << it->second.tried_friends.front().friend_id.toStdString() << std::endl;
|
||||
@ -322,6 +339,7 @@ void p3GRouter::routePendingObjects()
|
||||
std::cerr << " Flags : " << it->second.status_flags << std::endl;
|
||||
std::cerr << " Dist : " << it->second.data_item->randomized_distance<< std::endl;
|
||||
std::cerr << " Probabilities: " << std::endl;
|
||||
#endif
|
||||
|
||||
std::vector<float> probas ; // friends probabilities for online friend list.
|
||||
RsPeerId routed_friend ; // friend chosen for the next hop
|
||||
@ -339,13 +357,17 @@ void p3GRouter::routePendingObjects()
|
||||
|
||||
std::set<uint32_t> routing_friend_indices = computeRoutingFriends(pids,probas,N) ;
|
||||
|
||||
#ifdef GROUTER_DEBUG
|
||||
std::cerr << " Routing statistics: " << std::endl;
|
||||
#endif
|
||||
|
||||
// Actually send the item.
|
||||
|
||||
for(std::set<uint32_t>::const_iterator its(routing_friend_indices.begin());its!=routing_friend_indices.end();++its)
|
||||
{
|
||||
#ifdef GROUTER_DEBUG
|
||||
std::cerr << " Friend : " << (*its) << std::endl;
|
||||
#endif
|
||||
|
||||
// make a deep copy of the item
|
||||
RsGRouterGenericDataItem *new_item = it->second.data_item->duplicate() ;
|
||||
@ -360,8 +382,10 @@ void p3GRouter::routePendingObjects()
|
||||
it->second.tried_friends.push_front(ftr) ;
|
||||
it->second.status_flags = RS_GROUTER_ROUTING_STATE_SENT ;
|
||||
|
||||
#ifdef GROUTER_DEBUG
|
||||
std::cerr << " Routing probability: " << ftr.probability << std::endl;
|
||||
std::cerr << " Sending..." << std::endl;
|
||||
#endif
|
||||
|
||||
// send
|
||||
new_item->PeerId(pids[*its]) ;
|
||||
@ -375,7 +399,9 @@ void p3GRouter::routePendingObjects()
|
||||
{
|
||||
// We remove from the map. That means the RsItem* has been transfered to somewhere else.
|
||||
//
|
||||
#ifdef GROUTER_DEBUG
|
||||
std::cerr << " Removing item from pending items" << std::endl;
|
||||
#endif
|
||||
|
||||
std::map<GRouterMsgPropagationId, GRouterRoutingInfo>::iterator tmp(it) ;
|
||||
delete it->second.data_item ;
|
||||
@ -388,7 +414,9 @@ void p3GRouter::routePendingObjects()
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef GROUTER_DEBUG
|
||||
std::cerr << "Skipping " << std::hex << it->first << std::dec << ", dest=" << it->second.data_item->destination_key.toStdString() << ", state = " << it->second.status_flags << ", stamp=" << it->second.tried_friends.front().time_stamp << " - " << it->second.tried_friends.front().friend_id.toStdString() << std::endl;
|
||||
#endif
|
||||
++it ;
|
||||
}
|
||||
}
|
||||
@ -452,10 +480,12 @@ void p3GRouter::publishKeys()
|
||||
{
|
||||
// publish this key
|
||||
|
||||
#ifdef GROUTER_DEBUG
|
||||
std::cerr << "Publishing this key: " << std::endl;
|
||||
std::cerr << " Key id : " << it->first.toStdString() << std::endl;
|
||||
std::cerr << " Service id : " << std::hex << info.service_id << std::dec << std::endl;
|
||||
std::cerr << " Description : " << info.description_string << std::endl;
|
||||
#endif
|
||||
|
||||
RsGRouterPublishKeyItem item ;
|
||||
item.diffusion_id = RSRandom::random_u32() ;
|
||||
@ -477,17 +507,21 @@ void p3GRouter::publishKeys()
|
||||
|
||||
void p3GRouter::locked_forwardKey(const RsGRouterPublishKeyItem& item)
|
||||
{
|
||||
std::list<RsPeerId> connected_peers ;
|
||||
mLinkMgr->getOnlineList(connected_peers) ;
|
||||
std::set<RsPeerId> connected_peers ;
|
||||
mServiceControl->getPeersConnected(RS_SERVICE_TYPE_GROUTER,connected_peers) ;
|
||||
|
||||
#ifdef GROUTER_DEBUG
|
||||
std::cerr << " Forwarding key item to all available friends..." << std::endl;
|
||||
#endif
|
||||
|
||||
// get list of connected friends, and broadcast to all of them
|
||||
//
|
||||
for(std::list<RsPeerId>::const_iterator it(connected_peers.begin());it!=connected_peers.end();++it)
|
||||
for(std::set<RsPeerId>::const_iterator it(connected_peers.begin());it!=connected_peers.end();++it)
|
||||
if(item.PeerId() != *it)
|
||||
{
|
||||
#ifdef GROUTER_DEBUG
|
||||
std::cerr << " sending to " << (*it) << std::endl;
|
||||
#endif
|
||||
|
||||
RsGRouterPublishKeyItem *itm = new RsGRouterPublishKeyItem(item) ;
|
||||
itm->PeerId(*it) ;
|
||||
@ -496,8 +530,10 @@ void p3GRouter::locked_forwardKey(const RsGRouterPublishKeyItem& item)
|
||||
|
||||
sendItem(itm) ;
|
||||
}
|
||||
#ifdef GROUTER_DEBUG
|
||||
else
|
||||
std::cerr << " Not forwarding to source id " << item.PeerId() << std::endl;
|
||||
#endif
|
||||
}
|
||||
bool p3GRouter::registerKey(const GRouterKeyId& key,const GRouterServiceId& client_id,const std::string& description)
|
||||
{
|
||||
@ -515,11 +551,12 @@ bool p3GRouter::registerKey(const GRouterKeyId& key,const GRouterServiceId& clie
|
||||
//info.last_published_time = 0 ; // means never published, se it will be re-published soon.
|
||||
|
||||
_owned_key_ids[key] = info ;
|
||||
|
||||
#ifdef GROUTER_DEBUG
|
||||
std::cerr << "Registered the following key: " << std::endl;
|
||||
std::cerr << " Key id : " << key.toStdString() << std::endl;
|
||||
std::cerr << " Client id : " << std::hex << client_id << std::dec << std::endl;
|
||||
std::cerr << " Description : " << info.description_string << std::endl;
|
||||
#endif
|
||||
|
||||
return true ;
|
||||
}
|
||||
@ -535,10 +572,12 @@ bool p3GRouter::unregisterKey(const GRouterKeyId& key)
|
||||
return false ;
|
||||
}
|
||||
|
||||
#ifdef GROUTER_DEBUG
|
||||
std::cerr << "p3GRouter::unregistered the following key: " << std::endl;
|
||||
std::cerr << " Key id : " << key.toStdString() << std::endl;
|
||||
std::cerr << " Client id : " << std::hex << it->second.service_id << std::dec << std::endl;
|
||||
std::cerr << " Description : " << it->second.description_string << std::endl;
|
||||
#endif
|
||||
|
||||
_owned_key_ids.erase(it) ;
|
||||
|
||||
@ -572,12 +611,14 @@ void p3GRouter::handleRecvPublishKeyItem(RsGRouterPublishKeyItem *item)
|
||||
{
|
||||
RsStackMutex mtx(grMtx) ;
|
||||
|
||||
#ifdef GROUTER_DEBUG
|
||||
std::cerr << "Received key publish item for key :" << std::endl ;
|
||||
std::cerr << " diffusion = " << std::hex << item->diffusion_id << std::dec << std::endl ;
|
||||
std::cerr << " key id = " << item->published_key.toStdString() << std::endl ;
|
||||
std::cerr << " service id = " << std::hex << item->service_id << std::dec << std::endl;
|
||||
std::cerr << " distance = " << item->randomized_distance << std::endl;
|
||||
std::cerr << " description= " << item->description_string << std::endl;
|
||||
#endif
|
||||
|
||||
// update the route matrix
|
||||
|
||||
@ -593,7 +634,9 @@ void p3GRouter::handleRecvPublishKeyItem(RsGRouterPublishKeyItem *item)
|
||||
|
||||
if(found)
|
||||
{
|
||||
#ifdef GROUTER_DEBUG
|
||||
std::cerr << " Key diffusion item already in cache. Not forwardign further." << std::endl;
|
||||
#endif
|
||||
return ;
|
||||
}
|
||||
|
||||
@ -608,7 +651,9 @@ void p3GRouter::handleRecvPublishKeyItem(RsGRouterPublishKeyItem *item)
|
||||
void p3GRouter::handleRecvACKItem(RsGRouterACKItem *item)
|
||||
{
|
||||
RsStackMutex mtx(grMtx) ;
|
||||
#ifdef GROUTER_DEBUG
|
||||
std::cerr << "Received ACK item, mid=" << std::hex << item->mid << std::dec << ", ACK type = "<< item->state << std::endl;
|
||||
#endif
|
||||
|
||||
// find the item in the pendign list,
|
||||
// - if not found, drop.
|
||||
@ -624,7 +669,9 @@ void p3GRouter::handleRecvACKItem(RsGRouterACKItem *item)
|
||||
|
||||
if(it == _pending_messages.end())
|
||||
{
|
||||
#ifdef GROUTER_DEBUG
|
||||
std::cerr << "p3GRouter::handleRecvACKItem(): cannot find entry for message id " << std::hex << item->mid << std::dec << ". Dropping it." << std::endl;
|
||||
#endif
|
||||
return ;
|
||||
}
|
||||
switch(item->state)
|
||||
@ -633,7 +680,9 @@ void p3GRouter::handleRecvACKItem(RsGRouterACKItem *item)
|
||||
case RS_GROUTER_ACK_STATE_RECEIVED:
|
||||
// Notify the origin. This is the main route and it was successful.
|
||||
|
||||
#ifdef GROUTER_DEBUG
|
||||
std::cerr << " updating routing matrix." << std::endl;
|
||||
#endif
|
||||
|
||||
it->second.status_flags = RS_GROUTER_ROUTING_STATE_ARVD ;
|
||||
|
||||
@ -643,7 +692,9 @@ void p3GRouter::handleRecvACKItem(RsGRouterACKItem *item)
|
||||
// Now compute the weight for that particular item. See with what probabilities it was chosen.
|
||||
//
|
||||
float weight = (item->state == RS_GROUTER_ACK_STATE_RECEIVED)?1.0f : 0.5;
|
||||
#ifdef GROUTER_DEBUG
|
||||
std::cerr << " weight = " << weight << std::endl;
|
||||
#endif
|
||||
|
||||
|
||||
_routing_matrix.addRoutingClue(it->second.data_item->destination_key,item->PeerId(),weight) ;
|
||||
@ -651,7 +702,9 @@ void p3GRouter::handleRecvACKItem(RsGRouterACKItem *item)
|
||||
|
||||
if(it->second.origin != mLinkMgr->getOwnId())
|
||||
{
|
||||
#ifdef GROUTER_DEBUG
|
||||
std::cerr << " forwarding ACK to origin: " << it->second.origin.toStdString() << std::endl;
|
||||
#endif
|
||||
sendACK(it->second.origin,item->mid,item->state) ;
|
||||
}
|
||||
break ;
|
||||
@ -663,7 +716,9 @@ void p3GRouter::handleRecvACKItem(RsGRouterACKItem *item)
|
||||
if(it->second.origin == mLinkMgr->getOwnId())
|
||||
{
|
||||
// find the client service and notify it.
|
||||
#ifdef GROUTER_DEBUG
|
||||
std::cerr << " We're owner: should notify client id" << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Just decrement the list of tried friends
|
||||
@ -671,7 +726,9 @@ void p3GRouter::handleRecvACKItem(RsGRouterACKItem *item)
|
||||
for(std::list<FriendTrialRecord>::iterator it2(it->second.tried_friends.begin());it2!=it->second.tried_friends.end();++it2)
|
||||
if( (*it2).friend_id == item->PeerId())
|
||||
{
|
||||
#ifdef GROUTER_DEBUG
|
||||
std::cerr << " Removing friend try for peer " << item->PeerId() << ". " << it->second.tried_friends.size() << " tries left." << std::endl;
|
||||
#endif
|
||||
it->second.tried_friends.erase(it2) ;
|
||||
break ;
|
||||
}
|
||||
@ -681,20 +738,26 @@ void p3GRouter::handleRecvACKItem(RsGRouterACKItem *item)
|
||||
delete it->second.data_item ;
|
||||
_pending_messages.erase(it) ;
|
||||
|
||||
#ifdef GROUTER_DEBUG
|
||||
std::cerr << " No tries left. Removing item from pending list." << std::endl;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void p3GRouter::handleRecvDataItem(RsGRouterGenericDataItem *item)
|
||||
{
|
||||
RsStackMutex mtx(grMtx) ;
|
||||
#ifdef GROUTER_DEBUG
|
||||
std::cerr << "Received data item for key " << item->destination_key << ", distance = " << item->randomized_distance << std::endl;
|
||||
#endif
|
||||
|
||||
// check the item depth. If too large, send a ACK back.
|
||||
|
||||
if(item->randomized_distance > GROUTER_ITEM_MAX_TRAVEL_DISTANCE)
|
||||
{
|
||||
#ifdef GROUTER_DEBUG
|
||||
std::cerr << " Distance is too large: " << item->randomized_distance << " units. Item is dropped." << std::endl;
|
||||
#endif
|
||||
sendACK(item->PeerId(),item->routing_id,RS_GROUTER_ACK_STATE_TOO_FAR) ;
|
||||
return ;
|
||||
}
|
||||
@ -709,13 +772,17 @@ void p3GRouter::handleRecvDataItem(RsGRouterGenericDataItem *item)
|
||||
|
||||
if(itr != _pending_messages.end())
|
||||
{
|
||||
#ifdef GROUTER_DEBUG
|
||||
std::cerr << " Item is already there. Nothing to do. Should we update the cache?" << std::endl;
|
||||
#endif
|
||||
|
||||
item_copy = itr->second.data_item ;
|
||||
}
|
||||
else // item is not known. Store it into pending msgs. We make a copy, since the item will be deleted otherwise.
|
||||
{
|
||||
#ifdef GROUTER_DEBUG
|
||||
std::cerr << " Item is new. Storing in cache as pending messages." << std::endl;
|
||||
#endif
|
||||
|
||||
GRouterRoutingInfo info ;
|
||||
|
||||
@ -744,16 +811,22 @@ void p3GRouter::handleRecvDataItem(RsGRouterGenericDataItem *item)
|
||||
|
||||
if(its != _registered_services.end())
|
||||
{
|
||||
#ifdef GROUTER_DEBUG
|
||||
std::cerr << " Key is owned by us. Notifying service for this item." << std::endl;
|
||||
#endif
|
||||
its->second->receiveGRouterData(it->first,item_copy) ;
|
||||
}
|
||||
#ifdef GROUTER_DEBUG
|
||||
else
|
||||
std::cerr << " (EE) weird situation. No service registered for a key that we own. Key id = " << item->destination_key.toStdString() << ", service id = " << it->second.service_id << std::endl;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef GROUTER_DEBUG
|
||||
std::cerr << " item is not for us. Storing in pending mode." << std::endl;
|
||||
#endif
|
||||
itr->second.status_flags = RS_GROUTER_ROUTING_STATE_PEND ;
|
||||
}
|
||||
|
||||
@ -787,6 +860,7 @@ void p3GRouter::sendData(const GRouterKeyId& destination, RsGRouterGenericDataIt
|
||||
item->destination_key = destination ;
|
||||
item->routing_id = propagation_id ;
|
||||
|
||||
#ifdef GROUTER_DEBUG
|
||||
std::cerr << "p3GRouter::sendGRouterData(): pushing the followign item in the msg pending list:" << std::endl;
|
||||
std::cerr << " data_item.size = " << info.data_item->data_size << std::endl;
|
||||
std::cerr << " data_item.byte = " << info.data_item->data_bytes << std::endl;
|
||||
@ -795,6 +869,7 @@ void p3GRouter::sendData(const GRouterKeyId& destination, RsGRouterGenericDataIt
|
||||
std::cerr << " distance = " << info.data_item->randomized_distance << std::endl;
|
||||
std::cerr << " origin = " << info.origin.toStdString() << std::endl;
|
||||
std::cerr << " Recv time = " << info.received_time << std::endl;
|
||||
#endif
|
||||
|
||||
_pending_messages[propagation_id] = info ;
|
||||
}
|
||||
@ -814,13 +889,17 @@ bool p3GRouter::loadList(std::list<RsItem*>& items)
|
||||
{
|
||||
RsStackMutex mtx(grMtx) ;
|
||||
|
||||
#ifdef GROUTER_DEBUG
|
||||
std::cerr << "p3GRouter::loadList() : " << std::endl;
|
||||
#endif
|
||||
|
||||
_routing_matrix.loadList(items) ;
|
||||
|
||||
#ifdef GROUTER_DEBUG
|
||||
// remove all existing objects.
|
||||
//
|
||||
std::cerr << " removing all existing items (" << _pending_messages.size() << " items to delete)." << std::endl;
|
||||
#endif
|
||||
|
||||
for(std::map<GRouterMsgPropagationId,GRouterRoutingInfo>::iterator it(_pending_messages.begin());it!=_pending_messages.end();++it)
|
||||
delete it->second.data_item ;
|
||||
@ -850,12 +929,16 @@ bool p3GRouter::saveList(bool& cleanup,std::list<RsItem*>& items)
|
||||
|
||||
cleanup = true ; // the client should delete the items.
|
||||
|
||||
#ifdef GROUTER_DEBUG
|
||||
std::cerr << "p3GRouter::saveList()..." << std::endl;
|
||||
std::cerr << " saving routing clues." << std::endl;
|
||||
#endif
|
||||
|
||||
_routing_matrix.saveList(items) ;
|
||||
|
||||
#ifdef GROUTER_DEBUG
|
||||
std::cerr << " saving pending items." << std::endl;
|
||||
#endif
|
||||
|
||||
for(std::map<GRouterMsgPropagationId,GRouterRoutingInfo>::const_iterator it(_pending_messages.begin());it!=_pending_messages.end();++it)
|
||||
{
|
||||
@ -877,14 +960,14 @@ bool p3GRouter::getRoutingMatrixInfo(RsGRouter::GRouterRoutingMatrixInfo& info)
|
||||
info.friend_ids.clear() ;
|
||||
info.published_keys.clear() ;
|
||||
|
||||
std::list<RsPeerId> ids ;
|
||||
mLinkMgr->getOnlineList(ids) ;
|
||||
std::set<RsPeerId> ids ;
|
||||
mServiceControl->getPeersConnected(RS_SERVICE_TYPE_GROUTER,ids) ;
|
||||
|
||||
RsStackMutex mtx(grMtx) ;
|
||||
|
||||
info.published_keys = _owned_key_ids ;
|
||||
|
||||
for(std::list<RsPeerId>::const_iterator it(ids.begin());it!=ids.end();++it)
|
||||
for(std::set<RsPeerId>::const_iterator it(ids.begin());it!=ids.end();++it)
|
||||
info.friend_ids.push_back(*it) ;
|
||||
|
||||
std::vector<GRouterKeyId> known_keys ;
|
||||
|
@ -50,7 +50,7 @@ class RsGRouterACKItem ;
|
||||
class p3GRouter: public RsGRouter, public p3Service, public p3Config
|
||||
{
|
||||
public:
|
||||
p3GRouter(p3LinkMgr *lm) ;
|
||||
p3GRouter(p3ServiceControl *sc,p3LinkMgr *lm) ;
|
||||
|
||||
//===================================================//
|
||||
// Router clients business //
|
||||
@ -226,6 +226,7 @@ class p3GRouter: public RsGRouter, public p3Service, public p3Config
|
||||
|
||||
// Pointers to other RS objects
|
||||
//
|
||||
p3ServiceControl *mServiceControl ;
|
||||
p3LinkMgr *mLinkMgr ;
|
||||
|
||||
// Multi-thread protection mutex.
|
||||
|
@ -1455,12 +1455,12 @@ int RsServer::StartupRetroShare()
|
||||
mStatusSrv = new p3StatusService(serviceCtrl);
|
||||
|
||||
#ifdef ENABLE_GROUTER
|
||||
p3GRouter *gr = new p3GRouter(mLinkMgr) ;
|
||||
p3GRouter *gr = new p3GRouter(serviceCtrl,mLinkMgr) ;
|
||||
rsGRouter = gr ;
|
||||
pqih->addService(gr,true) ;
|
||||
#endif
|
||||
|
||||
p3turtle *tr = new p3turtle(mLinkMgr) ;
|
||||
p3turtle *tr = new p3turtle(serviceCtrl,mLinkMgr) ;
|
||||
rsTurtle = tr ;
|
||||
pqih -> addService(tr,true);
|
||||
pqih -> addService(ftserver,true);
|
||||
|
@ -98,11 +98,18 @@ static const int MAX_TR_FORWARD_PER_SEC_UPPER_LIMIT = 30 ;
|
||||
static const int MAX_TR_FORWARD_PER_SEC_LOWER_LIMIT = 10 ;
|
||||
static const int DISTANCE_SQUEEZING_POWER = 8 ;
|
||||
|
||||
p3turtle::p3turtle(p3LinkMgr *lm)
|
||||
:p3Service(), p3Config(), mLinkMgr(lm), mTurtleMtx("p3turtle")
|
||||
p3turtle::p3turtle(p3ServiceControl *sc,p3LinkMgr *lm)
|
||||
:p3Service(), p3Config(), mServiceControl(sc), mLinkMgr(lm), mTurtleMtx("p3turtle")
|
||||
{
|
||||
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
_own_id = sc->getOwnId() ;
|
||||
|
||||
if(_own_id.isNull())
|
||||
{
|
||||
std::cerr << "OwnId is null, as returned by the p3ServiceControl object in turtle router. Can't go on!" << std::endl;
|
||||
exit(-1) ;
|
||||
}
|
||||
_turtle_routing_enabled = true ;
|
||||
_turtle_routing_session_enabled = true;
|
||||
|
||||
@ -550,7 +557,7 @@ void p3turtle::locked_closeTunnel(TurtleTunnelId tid,std::vector<std::pair<RsTur
|
||||
std::cerr << "p3turtle: Closing tunnel " << (void*)tid << std::endl ;
|
||||
#endif
|
||||
|
||||
if(it->second.local_src == mLinkMgr->getOwnId()) // this is a starting tunnel. We thus remove
|
||||
if(it->second.local_src == _own_id) // this is a starting tunnel. We thus remove
|
||||
// - the virtual peer from the vpid list
|
||||
// - the tunnel id from the file hash
|
||||
// - the virtual peer from the file sources in the file transfer controller.
|
||||
@ -594,7 +601,7 @@ void p3turtle::locked_closeTunnel(TurtleTunnelId tid,std::vector<std::pair<RsTur
|
||||
sources_to_remove.push_back(std::pair<RsTurtleClientService*,std::pair<TurtleFileHash,TurtleVirtualPeerId> >(it->second.service,hash_vpid)) ;
|
||||
}
|
||||
}
|
||||
else if(it->second.local_dst == mLinkMgr->getOwnId()) // This is a ending tunnel. We also remove the virtual peer id
|
||||
else if(it->second.local_dst == _own_id) // This is a ending tunnel. We also remove the virtual peer id
|
||||
{
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << " Tunnel is a ending point. Also removing associated outgoing hash." ;
|
||||
@ -739,7 +746,7 @@ uint32_t p3turtle::generatePersonalFilePrint(const TurtleFileHash& hash,uint32_t
|
||||
// The only important thing is that the saem couple (hash,SSL id) produces the same tunnel
|
||||
// id. The result uses a boolean to allow generating non symmetric tunnel ids.
|
||||
|
||||
std::string buff(hash.toStdString() + mLinkMgr->getOwnId().toStdString()) ;
|
||||
std::string buff(hash.toStdString() + _own_id.toStdString()) ;
|
||||
uint32_t res = seed ;
|
||||
uint32_t decal = 0 ;
|
||||
|
||||
@ -853,7 +860,7 @@ void p3turtle::handleSearchRequest(RsTurtleSearchRequestItem *item)
|
||||
|
||||
// If it's not for us, perform a local search. If something found, forward the search result back.
|
||||
|
||||
if(item->PeerId() != mLinkMgr->getOwnId())
|
||||
if(item->PeerId() != _own_id)
|
||||
{
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << " Request not from us. Performing local search" << std::endl ;
|
||||
@ -911,13 +918,13 @@ void p3turtle::handleSearchRequest(RsTurtleSearchRequestItem *item)
|
||||
|
||||
if(item->depth < TURTLE_MAX_SEARCH_DEPTH || random_bypass)
|
||||
{
|
||||
std::list<RsPeerId> onlineIds ;
|
||||
mLinkMgr->getOnlineList(onlineIds);
|
||||
std::set<RsPeerId> onlineIds ;
|
||||
mServiceControl->getPeersConnected(RS_SERVICE_TYPE_TURTLE, onlineIds);
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << " Looking for online peers" << std::endl ;
|
||||
#endif
|
||||
|
||||
for(std::list<RsPeerId>::const_iterator it(onlineIds.begin());it!=onlineIds.end();++it)
|
||||
for(std::set<RsPeerId>::const_iterator it(onlineIds.begin());it!=onlineIds.end();++it)
|
||||
{
|
||||
if(!(RS_SERVICE_PERM_TURTLE & rsPeers->servicePermissionFlags(*it)))
|
||||
continue ;
|
||||
@ -979,7 +986,7 @@ void p3turtle::handleSearchResult(RsTurtleSearchResultItem *item)
|
||||
|
||||
++(item->depth) ; // increase depth
|
||||
|
||||
if(it->second.origin == mLinkMgr->getOwnId())
|
||||
if(it->second.origin == _own_id)
|
||||
returnSearchResult(item) ; // Yes, so send upward.
|
||||
else
|
||||
{ // Nope, so forward it back.
|
||||
@ -1057,7 +1064,7 @@ void p3turtle::routeGenericTunnelItem(RsTurtleGenericTunnelItem *item)
|
||||
|
||||
// Let's figure out whether this packet is for us or not.
|
||||
|
||||
if(item->PeerId() == tunnel.local_dst && tunnel.local_src != mLinkMgr->getOwnId()) //direction == RsTurtleGenericTunnelItem::DIRECTION_CLIENT &&
|
||||
if(item->PeerId() == tunnel.local_dst && tunnel.local_src != _own_id) //direction == RsTurtleGenericTunnelItem::DIRECTION_CLIENT &&
|
||||
{
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << " Forwarding generic item to peer " << tunnel.local_src << std::endl ;
|
||||
@ -1075,7 +1082,7 @@ void p3turtle::routeGenericTunnelItem(RsTurtleGenericTunnelItem *item)
|
||||
return ;
|
||||
}
|
||||
|
||||
if(item->PeerId() == tunnel.local_src && tunnel.local_dst != mLinkMgr->getOwnId()) //direction == RsTurtleGenericTunnelItem::DIRECTION_SERVER &&
|
||||
if(item->PeerId() == tunnel.local_src && tunnel.local_dst != _own_id) //direction == RsTurtleGenericTunnelItem::DIRECTION_SERVER &&
|
||||
{
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << " Forwarding generic item to peer " << tunnel.local_dst << std::endl ;
|
||||
@ -1144,9 +1151,7 @@ bool p3turtle::getTunnelServiceInfo(TurtleTunnelId tunnel_id,RsPeerId& vpid,RsFi
|
||||
|
||||
// Now sort out the case of client vs. server side items.
|
||||
//
|
||||
RsPeerId ownid = mLinkMgr->getOwnId() ;
|
||||
|
||||
if(tunnel.local_src == ownid)
|
||||
if(tunnel.local_src == _own_id)
|
||||
{
|
||||
std::map<TurtleFileHash,TurtleHashInfo>::const_iterator it = _incoming_file_hashes.find(hash) ;
|
||||
|
||||
@ -1158,7 +1163,7 @@ bool p3turtle::getTunnelServiceInfo(TurtleTunnelId tunnel_id,RsPeerId& vpid,RsFi
|
||||
|
||||
service = it->second.service ;
|
||||
}
|
||||
else if(tunnel.local_dst == ownid)
|
||||
else if(tunnel.local_dst == _own_id)
|
||||
{
|
||||
std::map<TurtleFileHash,RsTurtleClientService*>::const_iterator it = _outgoing_file_hashes.find(hash) ;
|
||||
|
||||
@ -1208,7 +1213,6 @@ void p3turtle::sendTurtleData(const RsPeerId& virtual_peer_id,RsTurtleGenericTun
|
||||
|
||||
item->tunnel_id = tunnel_id ; // we should randomly select a tunnel, or something more clever.
|
||||
|
||||
RsPeerId ownid = mLinkMgr->getOwnId() ;
|
||||
uint32_t ss = item->serial_size() ;
|
||||
|
||||
if(item->shouldStampTunnel())
|
||||
@ -1216,13 +1220,13 @@ void p3turtle::sendTurtleData(const RsPeerId& virtual_peer_id,RsTurtleGenericTun
|
||||
|
||||
tunnel.transfered_bytes += ss ;
|
||||
|
||||
if(tunnel.local_src == ownid)
|
||||
if(tunnel.local_src == _own_id)
|
||||
{
|
||||
item->setTravelingDirection(RsTurtleGenericTunnelItem::DIRECTION_SERVER) ;
|
||||
item->PeerId(tunnel.local_dst) ;
|
||||
_traffic_info_buffer.data_dn_Bps += ss ;
|
||||
}
|
||||
else if(tunnel.local_dst == ownid)
|
||||
else if(tunnel.local_dst == _own_id)
|
||||
{
|
||||
item->setTravelingDirection(RsTurtleGenericTunnelItem::DIRECTION_CLIENT) ;
|
||||
item->PeerId(tunnel.local_src) ;
|
||||
@ -1280,18 +1284,8 @@ bool p3turtle::isOnline(const RsPeerId& peer_id) const
|
||||
TurtleRequestId p3turtle::diggTunnel(const TurtleFileHash& hash)
|
||||
{
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << "DiggTunnel: performing tunnel request. OwnId = " << mLinkMgr->getOwnId() << " for hash=" << hash << std::endl ;
|
||||
std::cerr << "DiggTunnel: performing tunnel request. OwnId = " << _own_id << " for hash=" << hash << std::endl ;
|
||||
#endif
|
||||
while(mLinkMgr->getOwnId().isNull())
|
||||
{
|
||||
std::cerr << "... waiting for connect manager to form own id." << std::endl ;
|
||||
#ifdef WIN32
|
||||
Sleep(1000) ;
|
||||
#else
|
||||
sleep(1) ;
|
||||
#endif
|
||||
}
|
||||
|
||||
TurtleRequestId id = generateRandomRequestId() ;
|
||||
|
||||
{
|
||||
@ -1306,7 +1300,7 @@ TurtleRequestId p3turtle::diggTunnel(const TurtleFileHash& hash)
|
||||
//
|
||||
RsTurtleOpenTunnelItem *item = new RsTurtleOpenTunnelItem ;
|
||||
|
||||
item->PeerId(mLinkMgr->getOwnId()) ;
|
||||
item->PeerId(_own_id) ;
|
||||
item->file_hash = hash ;
|
||||
item->request_id = id ;
|
||||
item->partial_tunnel_id = generatePersonalFilePrint(hash,_random_bias,true) ;
|
||||
@ -1404,7 +1398,7 @@ void p3turtle::handleTunnelRequest(RsTurtleOpenTunnelItem *item)
|
||||
std::string info ;
|
||||
RsTurtleClientService *service = NULL ;
|
||||
|
||||
if(item->PeerId() != mLinkMgr->getOwnId())
|
||||
if(item->PeerId() != _own_id)
|
||||
{
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << " Request not from us. Performing local search" << std::endl ;
|
||||
@ -1436,7 +1430,7 @@ void p3turtle::handleTunnelRequest(RsTurtleOpenTunnelItem *item)
|
||||
TurtleTunnel tt ;
|
||||
tt.local_src = item->PeerId() ;
|
||||
tt.hash = item->file_hash ;
|
||||
tt.local_dst = mLinkMgr->getOwnId() ; // this means us
|
||||
tt.local_dst = _own_id ; // this means us
|
||||
tt.time_stamp = time(NULL) ;
|
||||
tt.transfered_bytes = 0 ;
|
||||
tt.speed_Bps = 0.0f ;
|
||||
@ -1487,13 +1481,13 @@ void p3turtle::handleTunnelRequest(RsTurtleOpenTunnelItem *item)
|
||||
|
||||
if(item->depth < TURTLE_MAX_SEARCH_DEPTH || random_bypass)
|
||||
{
|
||||
std::list<RsPeerId> onlineIds ;
|
||||
mLinkMgr->getOnlineList(onlineIds);
|
||||
std::set<RsPeerId> onlineIds ;
|
||||
mServiceControl->getPeersConnected(RS_SERVICE_TYPE_TURTLE, onlineIds);
|
||||
|
||||
for(std::list<RsPeerId>::iterator it(onlineIds.begin());it!=onlineIds.end();)
|
||||
for(std::set<RsPeerId>::iterator it(onlineIds.begin());it!=onlineIds.end();)
|
||||
if(!(RS_SERVICE_PERM_TURTLE & rsPeers->servicePermissionFlags(*it)))
|
||||
{
|
||||
std::list<RsPeerId>::iterator tmp = it++ ;
|
||||
std::set<RsPeerId>::iterator tmp = it++ ;
|
||||
onlineIds.erase(tmp) ;
|
||||
}
|
||||
else
|
||||
@ -1517,7 +1511,7 @@ void p3turtle::handleTunnelRequest(RsTurtleOpenTunnelItem *item)
|
||||
std::cerr << " Forwarding tunnel request: Looking for online peers" << std::endl ;
|
||||
#endif
|
||||
|
||||
for(std::list<RsPeerId>::const_iterator it(onlineIds.begin());it!=onlineIds.end();++it)
|
||||
for(std::set<RsPeerId>::const_iterator it(onlineIds.begin());it!=onlineIds.end();++it)
|
||||
{
|
||||
uint32_t linkType = mLinkMgr->getLinkType(*it);
|
||||
|
||||
@ -1621,7 +1615,7 @@ void p3turtle::handleTunnelResult(RsTurtleTunnelOkItem *item)
|
||||
|
||||
// Is this result's target actually ours ?
|
||||
|
||||
if(it->second.origin == mLinkMgr->getOwnId())
|
||||
if(it->second.origin == _own_id)
|
||||
{
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << " Tunnel starting point. Storing id=" << (void*)item->tunnel_id << " for hash (unknown) and tunnel request id " << it->second.origin << std::endl;
|
||||
@ -1775,19 +1769,10 @@ TurtleRequestId p3turtle::turtleSearch(const std::string& string_to_match)
|
||||
RsTurtleStringSearchRequestItem *item = new RsTurtleStringSearchRequestItem ;
|
||||
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << "performing search. OwnId = " << mLinkMgr->getOwnId() << std::endl ;
|
||||
std::cerr << "performing search. OwnId = " << _own_id << std::endl ;
|
||||
#endif
|
||||
while(mLinkMgr->getOwnId().isNull())
|
||||
{
|
||||
std::cerr << "... waitting for connect manager to form own id." << std::endl ;
|
||||
#ifdef WIN32
|
||||
Sleep(1000) ;
|
||||
#else
|
||||
sleep(1) ;
|
||||
#endif
|
||||
}
|
||||
|
||||
item->PeerId(mLinkMgr->getOwnId()) ;
|
||||
item->PeerId(_own_id) ;
|
||||
item->match_string = string_to_match ;
|
||||
item->request_id = id ;
|
||||
item->depth = 0 ;
|
||||
@ -1811,19 +1796,10 @@ TurtleRequestId p3turtle::turtleSearch(const LinearizedExpression& expr)
|
||||
RsTurtleRegExpSearchRequestItem *item = new RsTurtleRegExpSearchRequestItem ;
|
||||
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << "performing search. OwnId = " << mLinkMgr->getOwnId() << std::endl ;
|
||||
std::cerr << "performing search. OwnId = " << _own_id << std::endl ;
|
||||
#endif
|
||||
while(mLinkMgr->getOwnId().isNull())
|
||||
{
|
||||
std::cerr << "... waitting for connect manager to form own id." << std::endl ;
|
||||
#ifdef WIN32
|
||||
Sleep(1000) ;
|
||||
#else
|
||||
sleep(1) ;
|
||||
#endif
|
||||
}
|
||||
|
||||
item->PeerId(mLinkMgr->getOwnId()) ;
|
||||
item->PeerId(_own_id) ;
|
||||
item->expr = expr ;
|
||||
item->request_id = id ;
|
||||
item->depth = 0 ;
|
||||
@ -1971,8 +1947,8 @@ void p3turtle::getTrafficStatistics(TurtleTrafficStatisticsInfo& info) const
|
||||
float distance_to_maximum = std::min(100.0f,info.tr_up_Bps/(float)(TUNNEL_REQUEST_PACKET_SIZE*_max_tr_up_rate)) ;
|
||||
info.forward_probabilities.clear() ;
|
||||
|
||||
std::list<RsPeerId> onlineIds ;
|
||||
mLinkMgr->getOnlineList(onlineIds);
|
||||
std::set<RsPeerId> onlineIds ;
|
||||
mServiceControl->getPeersConnected(RS_SERVICE_TYPE_TURTLE, onlineIds);
|
||||
|
||||
int nb_online_ids = onlineIds.size() ;
|
||||
|
||||
|
@ -216,7 +216,7 @@ class TurtleHashInfo
|
||||
class p3turtle: public p3Service, public RsTurtle, public p3Config
|
||||
{
|
||||
public:
|
||||
p3turtle(p3LinkMgr *lm) ;
|
||||
p3turtle(p3ServiceControl *sc,p3LinkMgr *lm) ;
|
||||
virtual RsServiceInfo getServiceInfo();
|
||||
|
||||
// Enables/disable the service. Still ticks, but does nothing. Default is true.
|
||||
@ -375,8 +375,10 @@ class p3turtle: public p3Service, public RsTurtle, public p3Config
|
||||
//--------------------------- Local variables --------------------------------//
|
||||
|
||||
/* data */
|
||||
p3ServiceControl *mServiceControl;
|
||||
p3LinkMgr *mLinkMgr;
|
||||
RsTurtleSerialiser *_serialiser ;
|
||||
RsPeerId _own_id ;
|
||||
|
||||
mutable RsMutex mTurtleMtx;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user