mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-08-03 11:54:30 -04:00
Squeleton code for the global routing matrix. Most functions are left unimplemented, but
the basic structure is here. Functions have been added to serialise both SHA1 and floats. The router is not yet enabled since protocol is likely to change again. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6886 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
261d9102d4
commit
e0863194a3
18 changed files with 1241 additions and 4 deletions
202
libretroshare/src/grouter/p3grouter.h
Normal file
202
libretroshare/src/grouter/p3grouter.h
Normal file
|
@ -0,0 +1,202 @@
|
|||
/*
|
||||
* libretroshare/src/services: p3grouter.h
|
||||
*
|
||||
* Services for RetroShare.
|
||||
*
|
||||
* Copyright 2013 by Cyril Soler
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "csoler@users.sourceforge.net".
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <queue>
|
||||
|
||||
#include "rsgrouter.h"
|
||||
#include "services/p3service.h"
|
||||
#include "pqi/p3cfgmgr.h"
|
||||
#include "util/rsid.h"
|
||||
|
||||
#include "groutertypes.h"
|
||||
#include "groutermatrix.h"
|
||||
#include "groutercache.h"
|
||||
#include "grouteritems.h"
|
||||
|
||||
// To be put in pqi/p3cfgmgr.h
|
||||
//
|
||||
static const uint32_t CONFIG_TYPE_GROUTER = 0x0016 ;
|
||||
|
||||
class p3LinkMgr ;
|
||||
|
||||
class GRouterPublishedKeyInfo
|
||||
{
|
||||
public:
|
||||
GRouterServiceId service_id ;
|
||||
std::string description_string ;
|
||||
time_t last_published_time ;
|
||||
time_t validity_time ;
|
||||
};
|
||||
|
||||
class p3GRouter: public RsGRouter, public p3Service, public p3Config
|
||||
{
|
||||
public:
|
||||
p3GRouter(p3LinkMgr *lm) ;
|
||||
|
||||
//===================================================//
|
||||
// Router clients business //
|
||||
//===================================================//
|
||||
|
||||
// This method allows to associate client ids (that are saved to disk) to client objects deriving
|
||||
// from GRouterClientService. The various services are responsible for regstering themselves to the
|
||||
// global router, with consistent ids. The services are stored in a map, and arriving objects are
|
||||
// passed on the correct service depending on the client id of the key they are reaching.
|
||||
//
|
||||
bool registerClientService(const GRouterServiceId& id,GRouterClientService *service) ;
|
||||
|
||||
// Use this method to register a new key that the global router will
|
||||
// forward in the network, so that is can be a possible destination for
|
||||
// global messages.
|
||||
//
|
||||
// key : the key that is published
|
||||
// client_id: id of the client service to send the traffic to.
|
||||
// To obtain a client id, the service must register using the previous method.
|
||||
//
|
||||
bool registerKey(const GRouterKeyId& key,const GRouterServiceId& client_id,const std::string& description_string) ;
|
||||
|
||||
//===================================================//
|
||||
// Client/server request services //
|
||||
//===================================================//
|
||||
|
||||
// Sends an item to the given destination. The router takes ownership of
|
||||
// the memory. That means item_data will be erase on return.
|
||||
//
|
||||
void sendData(const GRouterKeyId& destination, void *& item_data,uint32_t item_size) ;
|
||||
|
||||
//===================================================//
|
||||
// Interface with RsGRouter //
|
||||
//===================================================//
|
||||
|
||||
// debug info from routing matrix
|
||||
// - list of known key ids
|
||||
// - list of clues/time_stamp for each key.
|
||||
// - real time routing probabilities
|
||||
//
|
||||
virtual bool getRoutingMatrixInfo(RoutingMatrixInfo& info) { return false ;}
|
||||
|
||||
// debug info from routing cache
|
||||
// - Cache Items
|
||||
// * which message ids
|
||||
// * directions
|
||||
// * timestamp
|
||||
// * message type
|
||||
// - Cache state (memory size, etc)
|
||||
//
|
||||
virtual bool getRoutingCacheInfo(RoutingCacheInfo& info) { return false ;}
|
||||
|
||||
private:
|
||||
//===================================================//
|
||||
// Routing method handling //
|
||||
//===================================================//
|
||||
|
||||
// Calls
|
||||
// - autoWash()
|
||||
// - packet handling methods
|
||||
// - matrix updates
|
||||
//
|
||||
virtual int tick() ;
|
||||
|
||||
void autoWash() ;
|
||||
void routeObjects() ;
|
||||
void handleIncoming() ;
|
||||
void publishKeys() ;
|
||||
|
||||
//===================================================//
|
||||
// p3Config methods //
|
||||
//===================================================//
|
||||
|
||||
// Load/save the routing info, the pending items in transit, and the config variables.
|
||||
//
|
||||
virtual bool loadList(std::list<RsItem*>& items) ;
|
||||
virtual bool saveList(bool&,std::list<RsItem*>& items) ;
|
||||
|
||||
virtual RsSerialiser *setupSerialiser() ;
|
||||
|
||||
//===================================================//
|
||||
// Debug methods //
|
||||
//===================================================//
|
||||
|
||||
// Prints the internal state of the router, for debug purpose.
|
||||
//
|
||||
void debug_dump() ;
|
||||
|
||||
// Stores the routing info
|
||||
// - list of known key ids
|
||||
// - list of clues/time_stamp for each key.
|
||||
// - real time routing probabilities
|
||||
//
|
||||
GRouterMatrix _routing_matrix ;
|
||||
|
||||
// Stores the routing events.
|
||||
// - pending items
|
||||
// - ongoing requests, waiting for return ACK
|
||||
//
|
||||
GRouterCache _routing_cache ;
|
||||
|
||||
// Stores the keys which identify the router's node. For each key, a structure holds:
|
||||
// - the client service
|
||||
// - flags
|
||||
// - usage time stamps
|
||||
//
|
||||
std::map<GRouterKeyId, GRouterPublishedKeyInfo> _owned_key_ids ;
|
||||
|
||||
// Key publish cache and buffers
|
||||
// Handles key publish items routes and forwarding info.
|
||||
//
|
||||
// 1 - timestamps of diffused keys received stored by diffusion id.
|
||||
std::map<GRouterKeyPropagationId,time_t> _key_diffusion_time_stamps ;
|
||||
|
||||
// 2 - list of key diffusion items to be routed. These are stored in a priority structure
|
||||
// where the priority is based on key distance, so that:
|
||||
// - long distance keys get propagated less easily
|
||||
// - when the list exceeds the maximum allowed size, items with the largest distance get dropped.
|
||||
//
|
||||
std::priority_queue<RsGRouterPublishKeyItem *> _key_diffusion_items ;
|
||||
|
||||
// Registered services. These are known to the different peers with a common id,
|
||||
// so it's important to keep consistency here. This map is volatile, and re-created at each startup of
|
||||
// the software, when newly created services register themselves.
|
||||
|
||||
std::map<GRouterServiceId,GRouterClientService *> _registered_services ;
|
||||
|
||||
// Data handling ethods
|
||||
//
|
||||
void handleRecvPublishKeyItem(RsGRouterPublishKeyItem *item) ;
|
||||
void handleRecvDataItem(RsGRouterGenericDataItem *item);
|
||||
void handleRecvACKItem(RsGRouterACKItem *item);
|
||||
|
||||
// Pointers to other RS objects
|
||||
//
|
||||
p3LinkMgr *mLinkMgr ;
|
||||
|
||||
// Multi-thread protection mutex.
|
||||
//
|
||||
RsMutex grMtx ;
|
||||
};
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue