From 6951d730a571297adb638e3fa4c44aabc473a61c Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 28 Nov 2015 18:02:57 -0500 Subject: [PATCH] debugging of GxsTunnel service - fixed transport layer --- libretroshare/src/gxstunnel/p3gxstunnel.cc | 77 ++++++++++++++++++- libretroshare/src/gxstunnel/p3gxstunnel.h | 10 ++- .../src/gxstunnel/rsgxstunnelitems.cc | 4 +- libretroshare/src/retroshare/rsplugin.h | 2 + libretroshare/src/rsserver/rsinit.cc | 4 + 5 files changed, 91 insertions(+), 6 deletions(-) diff --git a/libretroshare/src/gxstunnel/p3gxstunnel.cc b/libretroshare/src/gxstunnel/p3gxstunnel.cc index 007cf4c6d..043869800 100644 --- a/libretroshare/src/gxstunnel/p3gxstunnel.cc +++ b/libretroshare/src/gxstunnel/p3gxstunnel.cc @@ -58,6 +58,15 @@ static const uint32_t RS_GXS_TUNNEL_DELAY_BETWEEN_RESEND = 10 ; // re-send ever static const uint32_t GXS_TUNNEL_ENCRYPTION_HMAC_SIZE = SHA_DIGEST_LENGTH ; static const uint32_t GXS_TUNNEL_ENCRYPTION_IV_SIZE = 8 ; +static const uint32_t INTERVAL_BETWEEN_DEBUG_DUMP = 10 ; + +static std::string GXS_TUNNEL_APP_NAME = "GxsTunnels" ; + +static const uint8_t GXS_TUNNEL_APP_MAJOR_VERSION = 0x01 ; +static const uint8_t GXS_TUNNEL_APP_MINOR_VERSION = 0x00 ; +static const uint8_t GXS_TUNNEL_MIN_MAJOR_VERSION = 0x01 ; +static const uint8_t GXS_TUNNEL_MIN_MINOR_VERSION = 0x00 ; + RsGxsTunnelService *rsGxsTunnel = NULL ; p3GxsTunnelService::p3GxsTunnelService(RsGixs *pids) @@ -91,6 +100,31 @@ bool p3GxsTunnelService::registerClientService(uint32_t service_id,RsGxsTunnelSe return true ; } +int p3GxsTunnelService::tick() +{ + static time_t last_dump = 0 ; + std::cerr << "p3GxsTunnelService::tick()" << std::endl; + time_t now = time(NULL); + + if(now > last_dump + INTERVAL_BETWEEN_DEBUG_DUMP ) + { + last_dump = now ; + debug_dump() ; + } + + flush() ; +} + +RsServiceInfo p3GxsTunnelService::getServiceInfo() +{ + return RsServiceInfo(RS_SERVICE_TYPE_GXS_TUNNEL, + GXS_TUNNEL_APP_NAME, + GXS_TUNNEL_APP_MAJOR_VERSION, + GXS_TUNNEL_APP_MINOR_VERSION, + GXS_TUNNEL_MIN_MAJOR_VERSION, + GXS_TUNNEL_MIN_MINOR_VERSION); +} + void p3GxsTunnelService::flush() { // Flush pending DH items. This is a higher priority, so we deal with them first. @@ -342,7 +376,7 @@ void p3GxsTunnelService::addVirtualPeer(const TurtleFileHash& hash,const TurtleV } else // client side { - std::map::const_iterator it ; + std::map::const_iterator it = _gxs_tunnel_contacts.begin(); while(it != _gxs_tunnel_contacts.end() && it->second.hash != hash) ++it ; @@ -495,7 +529,8 @@ void p3GxsTunnelService::receiveTurtleData(RsTurtleGenericTunnelItem *gitem,cons // Now try deserialise the decrypted data to make an RsItem out of it. // - RsItem *citem = RsGxsTunnelSerialiser().deserialise(&((uint8_t*)item->data_bytes)[8],&item->data_size-8) ; + uint32_t pktsize = item->data_size-8; + RsItem *citem = RsGxsTunnelSerialiser().deserialise(&((uint8_t*)item->data_bytes)[8],&pktsize) ; if(citem == NULL) { @@ -1340,3 +1375,41 @@ void p3GxsTunnelService::markGxsTunnelAsClosed(const RsGxsTunnelId& tunnel_id) } } +void p3GxsTunnelService::debug_dump() +{ + RS_STACK_MUTEX(mGxsTunnelMtx); /********** STACK LOCKED MTX ******/ + + time_t now = time(NULL) ; + + std::cerr << "p3GxsTunnelService::debug_dump()" << std::endl; + std::cerr << " Registered client services: " << std::endl; + + for(std::map::const_iterator it=mRegisteredServices.begin();it!=mRegisteredServices.end();++it) + std::cerr << std::hex << " " << it->first << " - " << (void*)it->second << std::dec << std::endl; + + std::cerr << " Active tunnels" << std::endl; + + for(std::map::const_iterator it=_gxs_tunnel_contacts.begin();it!=_gxs_tunnel_contacts.end();++it) + std::cerr << " tunnel_id=" << it->first << " vpid=" << it->second.virtual_peer_id << " status=" << it->second.status << " direction=" << it->second.direction << " last_contact=" << (now-it->second.last_contact) <<" secs ago. Last_keep_alive_sent:" << (now - it->second.last_keep_alive_sent) << " secs ago." << std::endl; + + std::cerr << " Virtual peers:" << std::endl; + + for(std::map::const_iterator it=_gxs_tunnel_virtual_peer_ids.begin();it!=_gxs_tunnel_virtual_peer_ids.end();++it) + std::cerr << " vpid=" << it->first << " to=" << it->second.gxs_id << " from=" << it->second.own_gxs_id << " tunnel_id=" << it->second.tunnel_id << " status=" << it->second.status << " direction=" << it->second.direction << " hash=" << it->second.hash << std::endl; +} + + + + + + + + + + + + + + + + diff --git a/libretroshare/src/gxstunnel/p3gxstunnel.h b/libretroshare/src/gxstunnel/p3gxstunnel.h index 16a1d2e8b..9138f9f86 100644 --- a/libretroshare/src/gxstunnel/p3gxstunnel.h +++ b/libretroshare/src/gxstunnel/p3gxstunnel.h @@ -107,13 +107,14 @@ #include #include +#include #include class RsGixs ; static const uint32_t GXS_TUNNEL_AES_KEY_SIZE = 16 ; -class p3GxsTunnelService: public RsGxsTunnelService, public RsTurtleClientService +class p3GxsTunnelService: public RsGxsTunnelService, public RsTurtleClientService, public p3Service { public: p3GxsTunnelService(RsGixs *pids) ; @@ -131,6 +132,11 @@ public: virtual bool registerClientService(uint32_t service_id,RsGxsTunnelClientService *service) ; + // derived from p3service + + virtual int tick(); + virtual RsServiceInfo getServiceInfo(); + private: void flush() ; virtual void handleIncomingItem(const RsGxsTunnelId &tunnel_id, RsGxsTunnelItem *) ; @@ -237,5 +243,7 @@ private: uint64_t global_item_counter ; std::map mRegisteredServices ; + + void debug_dump(); }; diff --git a/libretroshare/src/gxstunnel/rsgxstunnelitems.cc b/libretroshare/src/gxstunnel/rsgxstunnelitems.cc index ed8a7c472..055fb4ba0 100644 --- a/libretroshare/src/gxstunnel/rsgxstunnelitems.cc +++ b/libretroshare/src/gxstunnel/rsgxstunnelitems.cc @@ -32,7 +32,7 @@ #include "gxstunnel/rsgxstunnelitems.h" -//#define GXS_TUNNEL_ITEM_DEBUG 1 +#define GXS_TUNNEL_ITEM_DEBUG 1 std::ostream& RsGxsTunnelDHPublicKeyItem::print(std::ostream &out, uint16_t indent) { @@ -105,9 +105,7 @@ RsItem *RsGxsTunnelSerialiser::deserialise(void *data, uint32_t *pktsize) // look what we have... if (*pktsize < rssize) /* check size */ { -#ifdef GXS_TUNNEL_ITEM_DEBUG std::cerr << "GxsTunnel deserialisation: not enough size: pktsize=" << *pktsize << ", rssize=" << rssize << std::endl ; -#endif return NULL; /* not enough data */ } diff --git a/libretroshare/src/retroshare/rsplugin.h b/libretroshare/src/retroshare/rsplugin.h index e8cb91714..bb882c8dd 100644 --- a/libretroshare/src/retroshare/rsplugin.h +++ b/libretroshare/src/retroshare/rsplugin.h @@ -41,6 +41,7 @@ extern RsPluginHandler *rsPlugins ; class p3Service ; class RsServiceControl ; class RsTurtle ; +class RsGxsTunnelService ; class RsDht ; class RsDisc ; class RsMsgs ; @@ -116,6 +117,7 @@ public: RsUtil::inited_ptr mPgpAuxUtils; RsUtil::inited_ptr mGxsForums; RsUtil::inited_ptr mGxsChannels; + RsUtil::inited_ptr mGxsTunnels; }; class RsPlugin diff --git a/libretroshare/src/rsserver/rsinit.cc b/libretroshare/src/rsserver/rsinit.cc index f2f775649..684f08998 100644 --- a/libretroshare/src/rsserver/rsinit.cc +++ b/libretroshare/src/rsserver/rsinit.cc @@ -1475,6 +1475,7 @@ int RsServer::StartupRetroShare() pqih -> addService(ftserver,true); mGxsTunnels = new p3GxsTunnelService(mGxsIdService) ; + mGxsTunnels->connectToTurtleRouter(tr) ; rsGxsTunnel = mGxsTunnels; rsDisc = mDisc; @@ -1495,6 +1496,7 @@ int RsServer::StartupRetroShare() pqih -> addService(msgSrv,true); pqih -> addService(chatSrv,true); pqih -> addService(mStatusSrv,true); + pqih -> addService(mGxsTunnels,true); // set interfaces for plugins // @@ -1515,6 +1517,8 @@ int RsServer::StartupRetroShare() interfaces.mPgpAuxUtils = pgpAuxUtils; interfaces.mGxsForums = mGxsForums; interfaces.mGxsChannels = mGxsChannels; + interfaces.mGxsTunnels = mGxsTunnels; + mPluginsManager->setInterfaces(interfaces); // now add plugin objects inside the loop: