mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-27 10:21:40 -05:00
added code to add/remove virtual peers in RsGxsNetTunnel
This commit is contained in:
parent
076309133b
commit
3407604a54
@ -23,6 +23,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "util/rsdir.h"
|
||||||
#include "rsgxsnettunnel.h"
|
#include "rsgxsnettunnel.h"
|
||||||
|
|
||||||
#define DEBUG_RSGXSNETTUNNEL 1
|
#define DEBUG_RSGXSNETTUNNEL 1
|
||||||
@ -31,6 +32,10 @@
|
|||||||
|
|
||||||
RsGxsNetTunnelService::RsGxsNetTunnelService(): mGxsNetTunnelMtx("GxsNetTunnel") {}
|
RsGxsNetTunnelService::RsGxsNetTunnelService(): mGxsNetTunnelMtx("GxsNetTunnel") {}
|
||||||
|
|
||||||
|
//===========================================================================================================================================//
|
||||||
|
// Interface with rest of the software //
|
||||||
|
//===========================================================================================================================================//
|
||||||
|
|
||||||
bool RsGxsNetTunnelService::manage(const RsGxsGroupId& group_id)
|
bool RsGxsNetTunnelService::manage(const RsGxsGroupId& group_id)
|
||||||
{
|
{
|
||||||
RsFileHash hash = calculateGroupHash(group_id) ;
|
RsFileHash hash = calculateGroupHash(group_id) ;
|
||||||
@ -48,6 +53,8 @@ bool RsGxsNetTunnelService::manage(const RsGxsGroupId& group_id)
|
|||||||
info.last_contact = now ;
|
info.last_contact = now ;
|
||||||
info.group_status = RsGxsNetTunnelGroupInfo::RS_GXS_NET_TUNNEL_GRP_STATUS_TUNNELS_REQUESTED;
|
info.group_status = RsGxsNetTunnelGroupInfo::RS_GXS_NET_TUNNEL_GRP_STATUS_TUNNELS_REQUESTED;
|
||||||
|
|
||||||
|
mHandledHashes[hash] = group_id ;
|
||||||
|
|
||||||
#ifdef DEBUG_GXS_TUNNEL
|
#ifdef DEBUG_GXS_TUNNEL
|
||||||
std::cerr << "Starting distant chat to " << to_gxs_id << ", hash = " << hash << ", from " << from_gxs_id << std::endl;
|
std::cerr << "Starting distant chat to " << to_gxs_id << ", hash = " << hash << ", from " << from_gxs_id << std::endl;
|
||||||
std::cerr << "Asking turtle router to monitor tunnels for hash " << hash << std::endl;
|
std::cerr << "Asking turtle router to monitor tunnels for hash " << hash << std::endl;
|
||||||
@ -75,6 +82,10 @@ bool RsGxsNetTunnelService::release(const RsGxsGroupId& group_id)
|
|||||||
}
|
}
|
||||||
|
|
||||||
mClientGroups.erase(it) ;
|
mClientGroups.erase(it) ;
|
||||||
|
|
||||||
|
RsFileHash hash = calculateGroupHash(group_id) ;
|
||||||
|
|
||||||
|
mHandledHashes.erase(hash) ;
|
||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +104,7 @@ bool RsGxsNetTunnelService::getVirtualPeers(const RsGxsGroupId&, std::list<RsPee
|
|||||||
return false ;
|
return false ;
|
||||||
}
|
}
|
||||||
|
|
||||||
RsGxsNetTunnelVirtualPeerInfo RsGxsNetTunnelService::makeVirtualPeerIdForGroup(const RsGxsGroupId&) const
|
RsGxsNetTunnelVirtualPeerInfo RsGxsNetTunnelService::makeVirtualPeerIdForGroup(const RsGxsGroupId& group_id) const
|
||||||
{
|
{
|
||||||
NOT_IMPLEMENTED();
|
NOT_IMPLEMENTED();
|
||||||
return RsGxsNetTunnelVirtualPeerInfo();
|
return RsGxsNetTunnelVirtualPeerInfo();
|
||||||
@ -116,25 +127,66 @@ void RsGxsNetTunnelService::connectToTurtleRouter(p3turtle *tr)
|
|||||||
bool RsGxsNetTunnelService::handleTunnelRequest(const RsFileHash &hash,const RsPeerId& peer_id)
|
bool RsGxsNetTunnelService::handleTunnelRequest(const RsFileHash &hash,const RsPeerId& peer_id)
|
||||||
{
|
{
|
||||||
NOT_IMPLEMENTED();
|
NOT_IMPLEMENTED();
|
||||||
return false ;
|
|
||||||
|
// at this point we need to talk to the client services
|
||||||
|
// There's 2 ways to do that:
|
||||||
|
// 1 - client services "register" and we ask them one by one.
|
||||||
|
// 2 - client service derives from RsGxsNetTunnelService and the client is interrogated using an overloaded virtual method
|
||||||
|
|
||||||
|
return true ;
|
||||||
}
|
}
|
||||||
void RsGxsNetTunnelService::receiveTurtleData(RsTurtleGenericTunnelItem *item,const RsFileHash& hash,const RsPeerId& virtual_peer_id,RsTurtleGenericTunnelItem::Direction direction)
|
void RsGxsNetTunnelService::receiveTurtleData(RsTurtleGenericTunnelItem *item,const RsFileHash& hash,const RsPeerId& virtual_peer_id,RsTurtleGenericTunnelItem::Direction direction)
|
||||||
{
|
{
|
||||||
NOT_IMPLEMENTED();
|
NOT_IMPLEMENTED();
|
||||||
}
|
}
|
||||||
void RsGxsNetTunnelService::addVirtualPeer(const TurtleFileHash&, const TurtleVirtualPeerId&,RsTurtleGenericTunnelItem::Direction dir)
|
void RsGxsNetTunnelService::addVirtualPeer(const TurtleFileHash& hash, const TurtleVirtualPeerId& vpid,RsTurtleGenericTunnelItem::Direction dir)
|
||||||
{
|
{
|
||||||
NOT_IMPLEMENTED();
|
auto it = mHandledHashes.find(hash) ;
|
||||||
}
|
|
||||||
void RsGxsNetTunnelService::removeVirtualPeer(const TurtleFileHash&, const TurtleVirtualPeerId&)
|
if(it == mHandledHashes.end())
|
||||||
{
|
{
|
||||||
NOT_IMPLEMENTED();
|
std::cerr << "RsGxsNetTunnelService::addVirtualPeer(): error! hash " << hash << " is not handled. Cannot add vpid " << vpid << " in direction " << dir << std::endl;
|
||||||
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
RsFileHash RsGxsNetTunnelService::calculateGroupHash(const RsGxsGroupId&) const
|
const RsGxsGroupId group_id(it->second) ;
|
||||||
|
|
||||||
|
RsGxsNetTunnelGroupInfo& ginfo( mClientGroups[group_id] ) ;
|
||||||
|
ginfo.group_status = RsGxsNetTunnelGroupInfo::RS_GXS_NET_TUNNEL_GRP_STATUS_VPIDS_AVAILABLE ;
|
||||||
|
|
||||||
|
RsGxsNetTunnelVirtualPeerInfo& vpinfo( ginfo.virtual_peers[vpid] ) ;
|
||||||
|
|
||||||
|
vpinfo.vpid_status = RsGxsNetTunnelVirtualPeerInfo::RS_GXS_NET_TUNNEL_VP_STATUS_TUNNEL_OK ;
|
||||||
|
vpinfo.net_service_virtual_peer.clear();
|
||||||
|
vpinfo.side = dir ;
|
||||||
|
vpinfo.last_contact = time(NULL) ;
|
||||||
|
|
||||||
|
generateEncryptionKey(group_id,vpid,vpinfo.encryption_key );
|
||||||
|
}
|
||||||
|
|
||||||
|
void RsGxsNetTunnelService::removeVirtualPeer(const TurtleFileHash& hash, const TurtleVirtualPeerId& vpid)
|
||||||
{
|
{
|
||||||
NOT_IMPLEMENTED();
|
auto it = mHandledHashes.find(hash) ;
|
||||||
return RsFileHash() ;
|
|
||||||
|
if(it == mHandledHashes.end())
|
||||||
|
{
|
||||||
|
std::cerr << "RsGxsNetTunnelService::removeVirtualPeer(): error! hash " << hash << " is not handled. Cannot remove vpid " << vpid << std::endl;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
const RsGxsGroupId group_id(it->second) ;
|
||||||
|
|
||||||
|
RsGxsNetTunnelGroupInfo& ginfo( mClientGroups[group_id] ) ;
|
||||||
|
|
||||||
|
ginfo.virtual_peers.erase(vpid);
|
||||||
|
|
||||||
|
if(ginfo.virtual_peers.empty())
|
||||||
|
ginfo.group_status = RsGxsNetTunnelGroupInfo::RS_GXS_NET_TUNNEL_GRP_STATUS_TUNNELS_REQUESTED ;
|
||||||
|
}
|
||||||
|
|
||||||
|
RsFileHash RsGxsNetTunnelService::calculateGroupHash(const RsGxsGroupId& group_id) const
|
||||||
|
{
|
||||||
|
return RsDirUtil::sha1sum(group_id.toByteArray(),RsGxsGroupId::SIZE_IN_BYTES) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
//===========================================================================================================================================//
|
//===========================================================================================================================================//
|
||||||
|
@ -150,21 +150,24 @@ private:
|
|||||||
std::map<RsGxsGroupId,RsGxsNetTunnelGroupInfo> mClientGroups ; // groups on the client side
|
std::map<RsGxsGroupId,RsGxsNetTunnelGroupInfo> mClientGroups ; // groups on the client side
|
||||||
std::map<RsGxsGroupId,RsGxsNetTunnelGroupInfo> mServerGroups ; // groups on the server side
|
std::map<RsGxsGroupId,RsGxsNetTunnelGroupInfo> mServerGroups ; // groups on the server side
|
||||||
|
|
||||||
std::map<RsGxsNetTunnelVirtualPeerId, std::pair<RsGxsGroupId,TurtleVirtualPeerId> > mVirtualPeers ;
|
std::map<RsGxsNetTunnelVirtualPeerId, std::pair<RsGxsGroupId,TurtleVirtualPeerId> > mVirtualPeers ; // current virtual peers, with the (group,turtle vpid) they are for
|
||||||
|
std::map<RsFileHash, RsGxsGroupId> mHandledHashes ; // hashes asked to turtle
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Generates the hash to request tunnels for this group. This hash is only used by turtle, and is used to
|
* \brief Generates the hash to request tunnels for this group. This hash is only used by turtle, and is used to
|
||||||
* hide the real group id.
|
* hide the real group id.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
RsFileHash calculateGroupHash(const RsGxsGroupId&) const ;
|
RsFileHash calculateGroupHash(const RsGxsGroupId&group_id) const ;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief makeVirtualPeerIdForGroup creates a virtual peer id that can be used and that will be constant accross time, whatever the
|
* \brief makeVirtualPeerIdForGroup creates a virtual peer id that can be used and that will be constant accross time, whatever the
|
||||||
* tunnel ID and turtle virtual peer id. This allows RsGxsNetService to keep sync-ing the data consistently.
|
* tunnel ID and turtle virtual peer id. This allows RsGxsNetService to keep sync-ing the data consistently.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
RsGxsNetTunnelVirtualPeerInfo makeVirtualPeerIdForGroup(const RsGxsGroupId&) const ;
|
RsGxsNetTunnelVirtualPeerInfo makeVirtualPeerIdForGroup(const RsGxsGroupId&group_id) const ;
|
||||||
|
|
||||||
|
void generateEncryptionKey(const RsGxsGroupId& group_id,const TurtleVirtualPeerId& vpid) const ;
|
||||||
|
|
||||||
uint8_t mRandomBias[16] ; // constant accross reboots. Allows to disguise the real SSL id while providing a consistent value accross time.
|
uint8_t mRandomBias[16] ; // constant accross reboots. Allows to disguise the real SSL id while providing a consistent value accross time.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user