mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-27 07:47:03 -05:00
made GxsNetTunnelService a parent class of GxsNetService and renamed public methods appropriately.
This commit is contained in:
parent
38b39caf13
commit
1a9a7622a2
@ -361,7 +361,7 @@ RsGxsNetService::RsGxsNetService(uint16_t servType, RsGeneralDataService *gds,
|
||||
RsNxsNetMgr *netMgr, RsNxsObserver *nxsObs,
|
||||
const RsServiceInfo serviceInfo,
|
||||
RsGixsReputation* reputations, RsGcxs* circles, RsGixs *gixs,
|
||||
PgpAuxUtils *pgpUtils, RsGxsNetTunnelService *mGxsNT,
|
||||
PgpAuxUtils *pgpUtils,
|
||||
bool grpAutoSync, bool msgAutoSync, bool distSync, uint32_t default_store_period, uint32_t default_sync_period)
|
||||
: p3ThreadedService(), p3Config(), mTransactionN(0),
|
||||
mObserver(nxsObs), mDataStore(gds),
|
||||
@ -370,7 +370,7 @@ RsGxsNetService::RsGxsNetService(uint16_t servType, RsGeneralDataService *gds,
|
||||
mSyncTs(0), mLastKeyPublishTs(0),
|
||||
mLastCleanRejectedMessages(0), mSYNC_PERIOD(SYNC_PERIOD),
|
||||
mCircles(circles), mGixs(gixs),
|
||||
mReputations(reputations), mPgpUtils(pgpUtils),mGxsNetTunnel(mGxsNT),
|
||||
mReputations(reputations), mPgpUtils(pgpUtils),
|
||||
mGrpAutoSync(grpAutoSync), mAllowMsgSync(msgAutoSync),mAllowDistSync(distSync),
|
||||
mServiceInfo(serviceInfo), mDefaultMsgStorePeriod(default_store_period),
|
||||
mDefaultMsgSyncPeriod(default_sync_period)
|
||||
@ -569,12 +569,12 @@ void RsGxsNetService::syncWithPeers()
|
||||
std::set<RsPeerId> peers;
|
||||
mNetMgr->getOnlineList(mServiceInfo.mServiceType, peers);
|
||||
|
||||
if(mAllowDistSync && mGxsNetTunnel != NULL)
|
||||
if(mAllowDistSync)
|
||||
{
|
||||
// Grab all online virtual peers of distant tunnels for the current service.
|
||||
|
||||
std::list<RsGxsNetTunnelVirtualPeerId> vpids ;
|
||||
mGxsNetTunnel->getVirtualPeers(mServType,vpids);
|
||||
getVirtualPeers(mServType,vpids);
|
||||
|
||||
for(auto it(vpids.begin());it!=vpids.end();++it)
|
||||
peers.insert(RsPeerId(*it)) ;
|
||||
@ -668,6 +668,7 @@ void RsGxsNetService::syncWithPeers()
|
||||
const RsGxsGroupId& grpId = mmit->first;
|
||||
RsGxsCircleId encrypt_to_this_circle_id ;
|
||||
|
||||
#warning we should use this call in order to determine wether the peer can be sent group information about a specific group, otherwise we leak which group we are subscribed to
|
||||
if(!checkCanRecvMsgFromPeer(peerId, *meta,encrypt_to_this_circle_id))
|
||||
continue;
|
||||
|
||||
@ -725,7 +726,7 @@ void RsGxsNetService::syncWithPeers()
|
||||
#ifdef NXS_NET_DEBUG_7
|
||||
GXSNETDEBUG_PG(*sit,grpId) << " Service " << std::hex << ((mServiceInfo.mServiceType >> 8)& 0xffff) << std::dec << " sending message TS of peer id: " << *sit << " ts=" << nice_time_stamp(time(NULL),updateTS) << " (secs ago) for group " << grpId << " to himself - in clear " << std::endl;
|
||||
#endif
|
||||
generic_sendItem(msg);
|
||||
generic_sendItem(msg);
|
||||
|
||||
#ifdef NXS_NET_DEBUG_5
|
||||
GXSNETDEBUG_PG(*sit,grpId) << "Service "<< std::hex << ((mServiceInfo.mServiceType >> 8)& 0xffff) << std::dec << " sending global message TS of peer id: " << *sit << " ts=" << nice_time_stamp(time(NULL),updateTS) << " (secs ago) for group " << grpId << " to himself" << std::endl;
|
||||
@ -740,7 +741,7 @@ void RsGxsNetService::generic_sendItem(RsNxsItem *si)
|
||||
{
|
||||
// check if the item is to be sent to a distant peer or not
|
||||
|
||||
if(mAllowDistSync && mGxsNetTunnel != NULL && mGxsNetTunnel->isDistantPeer( static_cast<RsGxsNetTunnelVirtualPeerId>(si->PeerId())))
|
||||
if(mAllowDistSync && isDistantPeer( static_cast<RsGxsNetTunnelVirtualPeerId>(si->PeerId())))
|
||||
{
|
||||
RsNxsSerialiser ser(mServType);
|
||||
|
||||
@ -756,7 +757,7 @@ void RsGxsNetService::generic_sendItem(RsNxsItem *si)
|
||||
#endif
|
||||
ser.serialise(si,mem,&size) ;
|
||||
|
||||
mGxsNetTunnel->sendData(mem,size,static_cast<RsGxsNetTunnelVirtualPeerId>(si->PeerId()));
|
||||
sendTunnelData(mem,size,static_cast<RsGxsNetTunnelVirtualPeerId>(si->PeerId()));
|
||||
}
|
||||
else
|
||||
sendItem(si) ;
|
||||
@ -764,7 +765,7 @@ void RsGxsNetService::generic_sendItem(RsNxsItem *si)
|
||||
|
||||
void RsGxsNetService::checkDistantSyncState()
|
||||
{
|
||||
if(!mAllowDistSync || mGxsNetTunnel==NULL)
|
||||
if(!mAllowDistSync)
|
||||
return ;
|
||||
|
||||
RsGxsGrpMetaTemporaryMap grpMeta;
|
||||
@ -804,14 +805,14 @@ void RsGxsNetService::checkDistantSyncState()
|
||||
|
||||
if(at_least_one_friend_is_supplier)
|
||||
{
|
||||
mGxsNetTunnel->releasePeers(mServType,grpId);
|
||||
releaseDistantPeers(mServType,grpId);
|
||||
#ifdef NXS_NET_DEBUG_8
|
||||
GXSNETDEBUG___<< " Group " << grpId << ": suppliers among friends. Releasing peers." << std::endl;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
mGxsNetTunnel->requestPeers(mServType,grpId);
|
||||
requestDistantPeers(mServType,grpId);
|
||||
#ifdef NXS_NET_DEBUG_8
|
||||
GXSNETDEBUG___<< " Group " << grpId << ": no suppliers among friends. Requesting peers." << std::endl;
|
||||
#endif
|
||||
@ -1676,7 +1677,7 @@ RsItem *RsGxsNetService::generic_recvItem()
|
||||
uint32_t size = 0 ;
|
||||
RsGxsNetTunnelVirtualPeerId virtual_peer_id ;
|
||||
|
||||
while(mAllowDistSync && mGxsNetTunnel != NULL && mGxsNetTunnel->receiveData(mServType,data,size,virtual_peer_id))
|
||||
while(mAllowDistSync && receiveTunnelData(mServType,data,size,virtual_peer_id))
|
||||
{
|
||||
RsNxsItem *item = dynamic_cast<RsNxsItem*>(RsNxsSerialiser(mServType).deserialise(data,&size)) ;
|
||||
item->PeerId(virtual_peer_id) ;
|
||||
@ -1995,6 +1996,10 @@ void RsGxsNetService::data_tick()
|
||||
runVetting();
|
||||
|
||||
processExplicitGroupRequests();
|
||||
|
||||
// also tick distant traffic
|
||||
|
||||
RsGxsNetTunnelService::data_tick();
|
||||
}
|
||||
|
||||
void RsGxsNetService::debugDump()
|
||||
|
@ -72,7 +72,7 @@ class RsGroupNetworkStatsRecord
|
||||
* Incoming transaction are in 3 different states
|
||||
* 1. START 2. RECEIVING 3. END
|
||||
*/
|
||||
class RsGxsNetService : public RsNetworkExchangeService, public p3ThreadedService, public p3Config
|
||||
class RsGxsNetService : public RsNetworkExchangeService, public RsGxsNetTunnelService, public p3ThreadedService, public p3Config
|
||||
{
|
||||
public:
|
||||
|
||||
@ -90,7 +90,7 @@ public:
|
||||
RsNxsObserver *nxsObs, // used to be = NULL.
|
||||
const RsServiceInfo serviceInfo,
|
||||
RsGixsReputation* reputations = NULL, RsGcxs* circles = NULL, RsGixs *gixs=NULL,
|
||||
PgpAuxUtils *pgpUtils = NULL, RsGxsNetTunnelService *mGxsNT = NULL,
|
||||
PgpAuxUtils *pgpUtils = NULL,
|
||||
bool grpAutoSync = true, bool msgAutoSync = true,bool distSync=false,
|
||||
uint32_t default_store_period = RS_GXS_DEFAULT_MSG_STORE_PERIOD,
|
||||
uint32_t default_sync_period = RS_GXS_DEFAULT_MSG_REQ_PERIOD);
|
||||
@ -546,7 +546,6 @@ private:
|
||||
RsGixs *mGixs;
|
||||
RsGixsReputation* mReputations;
|
||||
PgpAuxUtils *mPgpUtils;
|
||||
RsGxsNetTunnelService *mGxsNetTunnel;
|
||||
|
||||
bool mGrpAutoSync;
|
||||
bool mAllowMsgSync;
|
||||
|
@ -38,7 +38,7 @@
|
||||
|
||||
RsGxsNetTunnelService::RsGxsNetTunnelService(): mGxsNetTunnelMtx("GxsNetTunnel")
|
||||
{
|
||||
#warning this is for testing only. In the final version this needs to be initialized with some random content.
|
||||
#warning this is for testing only. In the final version this needs to be initialized with some random content, saved and re-used for a while (e.g. 1 month)
|
||||
memset(mRandomBias,0,RS_GXS_TUNNEL_CONST_RANDOM_BIAS_SIZE) ;
|
||||
}
|
||||
|
||||
@ -148,7 +148,7 @@ bool RsGxsNetTunnelService::isDistantPeer(const RsGxsNetTunnelVirtualPeerId& vir
|
||||
return mVirtualPeers.find(virtual_peer) != mVirtualPeers.end();
|
||||
}
|
||||
|
||||
bool RsGxsNetTunnelService::receiveData(uint16_t service_id,unsigned char *& data,uint32_t& data_len,RsGxsNetTunnelVirtualPeerId& virtual_peer)
|
||||
bool RsGxsNetTunnelService::receiveTunnelData(uint16_t service_id,unsigned char *& data,uint32_t& data_len,RsGxsNetTunnelVirtualPeerId& virtual_peer)
|
||||
{
|
||||
RS_STACK_MUTEX(mGxsNetTunnelMtx);
|
||||
|
||||
@ -174,7 +174,7 @@ bool RsGxsNetTunnelService::receiveData(uint16_t service_id,unsigned char *& dat
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RsGxsNetTunnelService::sendData(unsigned char *& data,uint32_t data_len,const RsGxsNetTunnelVirtualPeerId& virtual_peer)
|
||||
bool RsGxsNetTunnelService::sendTunnelData(unsigned char *& data,uint32_t data_len,const RsGxsNetTunnelVirtualPeerId& virtual_peer)
|
||||
{
|
||||
RS_STACK_MUTEX(mGxsNetTunnelMtx);
|
||||
// The item is serialized and encrypted using chacha20+SHA256, using the generic turtle encryption, and then sent to the turtle router.
|
||||
@ -233,7 +233,7 @@ bool RsGxsNetTunnelService::getVirtualPeers(uint16_t service_id, std::list<RsGxs
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool RsGxsNetTunnelService::requestPeers(uint16_t service_id,const RsGxsGroupId& group_id)
|
||||
bool RsGxsNetTunnelService::requestDistantPeers(uint16_t service_id,const RsGxsGroupId& group_id)
|
||||
{
|
||||
RS_STACK_MUTEX(mGxsNetTunnelMtx);
|
||||
|
||||
@ -255,7 +255,7 @@ bool RsGxsNetTunnelService::requestPeers(uint16_t service_id,const RsGxsGroupId&
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RsGxsNetTunnelService::releasePeers(uint16_t service_id, const RsGxsGroupId& group_id)
|
||||
bool RsGxsNetTunnelService::releaseDistantPeers(uint16_t service_id, const RsGxsGroupId& group_id)
|
||||
{
|
||||
RS_STACK_MUTEX(mGxsNetTunnelMtx);
|
||||
|
||||
@ -606,8 +606,6 @@ void RsGxsNetTunnelService::data_tick()
|
||||
mPendingTurtleItems.pop_front();
|
||||
}
|
||||
|
||||
rstime::rs_usleep(1*1000*1000); // 1 sec
|
||||
|
||||
time_t now = time(NULL);
|
||||
|
||||
// cleanup
|
||||
|
@ -88,11 +88,12 @@
|
||||
//
|
||||
// * virtual peers are also shared among services. This reduces the required amount of tunnels and tunnel requests to send.
|
||||
//
|
||||
//
|
||||
// How do we know that a group needs distant sync?
|
||||
// * look into GrpConfigMap for suppliers. Suppliers is cleared at load.
|
||||
// * last_update_TS in GrpConfigMap is randomised so it cannot be used
|
||||
// * we need a way to know that there's no suppliers for good reasons (not that we just started)
|
||||
//
|
||||
// Security
|
||||
// *
|
||||
|
||||
typedef RsPeerId RsGxsNetTunnelVirtualPeerId ;
|
||||
@ -150,7 +151,7 @@ struct RsGxsNetTunnelGroupInfo
|
||||
std::set<TurtleVirtualPeerId> virtual_peers ; // list of which virtual peers provide this group. Can me more than 1.
|
||||
};
|
||||
|
||||
class RsGxsNetTunnelService: public RsTurtleClientService, public RsTickingThread
|
||||
class RsGxsNetTunnelService: public RsTurtleClientService
|
||||
{
|
||||
public:
|
||||
RsGxsNetTunnelService() ;
|
||||
@ -160,13 +161,13 @@ public:
|
||||
* \brief Manage tunnels for this group
|
||||
* @param group_id group for which tunnels should be released
|
||||
*/
|
||||
bool requestPeers(uint16_t service_id, const RsGxsGroupId&group_id) ;
|
||||
bool requestDistantPeers(uint16_t service_id, const RsGxsGroupId&group_id) ;
|
||||
|
||||
/*!
|
||||
* \brief Stop managing tunnels for this group
|
||||
* @param group_id group for which tunnels should be released
|
||||
*/
|
||||
bool releasePeers(uint16_t service_id,const RsGxsGroupId&group_id) ;
|
||||
bool releaseDistantPeers(uint16_t service_id,const RsGxsGroupId&group_id) ;
|
||||
|
||||
/*!
|
||||
* \brief Get the list of active virtual peers for a given group. This implies that a tunnel is up and
|
||||
@ -182,7 +183,7 @@ public:
|
||||
* \return
|
||||
* true if succeeded.
|
||||
*/
|
||||
bool sendData(unsigned char *& data, uint32_t data_len, const RsGxsNetTunnelVirtualPeerId& virtual_peer) ;
|
||||
bool sendTunnelData(unsigned char *& data, uint32_t data_len, const RsGxsNetTunnelVirtualPeerId& virtual_peer) ;
|
||||
|
||||
/*!
|
||||
* \brief receiveData
|
||||
@ -194,7 +195,7 @@ public:
|
||||
* \return
|
||||
* true if something is returned. If not, data is set to NULL, data_len to 0.
|
||||
*/
|
||||
bool receiveData(uint16_t service_id,unsigned char *& data,uint32_t& data_len,RsGxsNetTunnelVirtualPeerId& virtual_peer) ;
|
||||
bool receiveTunnelData(uint16_t service_id,unsigned char *& data,uint32_t& data_len,RsGxsNetTunnelVirtualPeerId& virtual_peer) ;
|
||||
|
||||
/*!
|
||||
* \brief isDistantPeer
|
||||
|
@ -1358,14 +1358,6 @@ int RsServer::StartupRetroShare()
|
||||
mWiki->setNetworkExchangeService(wiki_ns) ;
|
||||
#endif
|
||||
|
||||
/**** GXS Dist sync service ****/
|
||||
#ifdef RS_USE_GXS_DISTANT_SYNC
|
||||
RsGxsNetTunnelService *mGxsNetTunnel = new RsGxsNetTunnelService ;
|
||||
#else
|
||||
RsGxsNetTunnelService *mGxsNetTunnel = NULL;
|
||||
#endif
|
||||
|
||||
|
||||
/**** Forum GXS service ****/
|
||||
|
||||
RsGeneralDataService* gxsforums_ds = new RsDataService(currGxsDir + "/", "gxsforums_db",
|
||||
@ -1379,7 +1371,7 @@ int RsServer::StartupRetroShare()
|
||||
RS_SERVICE_GXS_TYPE_FORUMS, gxsforums_ds, nxsMgr,
|
||||
mGxsForums, mGxsForums->getServiceInfo(),
|
||||
mReputations, mGxsCircles,mGxsIdService,
|
||||
pgpAuxUtils); //,mGxsNetTunnel,true,true,true);
|
||||
pgpAuxUtils);
|
||||
|
||||
mGxsForums->setNetworkExchangeService(gxsforums_ns) ;
|
||||
|
||||
@ -1395,7 +1387,7 @@ int RsServer::StartupRetroShare()
|
||||
RS_SERVICE_GXS_TYPE_CHANNELS, gxschannels_ds, nxsMgr,
|
||||
mGxsChannels, mGxsChannels->getServiceInfo(),
|
||||
mReputations, mGxsCircles,mGxsIdService,
|
||||
pgpAuxUtils,mGxsNetTunnel,true,true,true);
|
||||
pgpAuxUtils,true,true,true);
|
||||
|
||||
mGxsChannels->setNetworkExchangeService(gxschannels_ns) ;
|
||||
|
||||
@ -1450,7 +1442,7 @@ int RsServer::StartupRetroShare()
|
||||
RsGxsNetService* gxstrans_ns = new RsGxsNetService(
|
||||
RS_SERVICE_TYPE_GXS_TRANS, gxstrans_ds, nxsMgr, mGxsTrans,
|
||||
mGxsTrans->getServiceInfo(), mReputations, mGxsCircles,
|
||||
mGxsIdService, pgpAuxUtils,NULL,true,true,false,p3GxsTrans::GXS_STORAGE_PERIOD,p3GxsTrans::GXS_SYNC_PERIOD);
|
||||
mGxsIdService, pgpAuxUtils,true,true,false,p3GxsTrans::GXS_STORAGE_PERIOD,p3GxsTrans::GXS_SYNC_PERIOD);
|
||||
|
||||
mGxsTrans->setNetworkExchangeService(gxstrans_ns);
|
||||
pqih->addService(gxstrans_ns, true);
|
||||
@ -1492,7 +1484,7 @@ int RsServer::StartupRetroShare()
|
||||
|
||||
// connect components to turtle router.
|
||||
|
||||
mGxsNetTunnel->connectToTurtleRouter(tr) ;
|
||||
gxschannels_ns->connectToTurtleRouter(tr) ;
|
||||
ftserver->connectToTurtleRouter(tr) ;
|
||||
ftserver->connectToFileDatabase(fdb) ;
|
||||
chatSrv->connectToGxsTunnelService(mGxsTunnels) ;
|
||||
@ -1831,7 +1823,6 @@ int RsServer::StartupRetroShare()
|
||||
//rsWire = mWire;
|
||||
|
||||
/*** start up GXS core runner ***/
|
||||
startServiceThread(mGxsNetTunnel, "gxs net tunnel");
|
||||
|
||||
startServiceThread(mGxsIdService, "gxs id");
|
||||
startServiceThread(mGxsCircles, "gxs circle");
|
||||
|
Loading…
x
Reference in New Issue
Block a user