From 2aade543f32d4160088e57f74efa2847323726ba Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Wed, 25 Sep 2019 16:33:13 +0200 Subject: [PATCH 1/3] Send PGP full fingerprint in broadcast discovery --- .../src/retroshare/rsbroadcastdiscovery.h | 4 +++- libretroshare/src/rsserver/rsinit.cc | 8 ++++---- .../src/services/broadcastdiscoveryservice.cc | 14 +++++++++----- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/libretroshare/src/retroshare/rsbroadcastdiscovery.h b/libretroshare/src/retroshare/rsbroadcastdiscovery.h index 36ffd4ff2..a712c60af 100644 --- a/libretroshare/src/retroshare/rsbroadcastdiscovery.h +++ b/libretroshare/src/retroshare/rsbroadcastdiscovery.h @@ -41,11 +41,12 @@ class RsBroadcastDiscovery; * TODO: this should become std::weak_ptr once we have a reasonable services * management. */ -extern std::shared_ptr rsBroadcastDiscovery; +extern RsBroadcastDiscovery* rsBroadcastDiscovery; struct RsBroadcastDiscoveryResult : RsSerializable { + RsPgpFingerprint mPgpFingerprint; RsPeerId mSslId; std::string mProfileName; RsUrl mLocator; @@ -54,6 +55,7 @@ struct RsBroadcastDiscoveryResult : RsSerializable void serial_process( RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext& ctx) override { + RS_SERIAL_PROCESS(mPgpFingerprint); RS_SERIAL_PROCESS(mSslId); RS_SERIAL_PROCESS(mProfileName); RS_SERIAL_PROCESS(mLocator); diff --git a/libretroshare/src/rsserver/rsinit.cc b/libretroshare/src/rsserver/rsinit.cc index e8e2b518f..4e6c0a6e2 100644 --- a/libretroshare/src/rsserver/rsinit.cc +++ b/libretroshare/src/rsserver/rsinit.cc @@ -1429,9 +1429,9 @@ int RsServer::StartupRetroShare() mStatusSrv = new p3StatusService(serviceCtrl); #ifdef RS_BROADCAST_DISCOVERY - rsBroadcastDiscovery.reset(new BroadcastDiscoveryService(*rsPeers)); - BroadcastDiscoveryService& tBroadcastDiscoveryService = - static_cast(*rsBroadcastDiscovery); + BroadcastDiscoveryService* broadcastDiscoveryService = + new BroadcastDiscoveryService(*rsPeers); + rsBroadcastDiscovery = broadcastDiscoveryService; #endif // def RS_BROADCAST_DISCOVERY #ifdef ENABLE_GROUTER @@ -1828,7 +1828,7 @@ int RsServer::StartupRetroShare() #endif // RS_ENABLE_GXS #ifdef RS_BROADCAST_DISCOVERY - startServiceThread(&tBroadcastDiscoveryService, "Broadcast Discovery"); + startServiceThread(broadcastDiscoveryService, "Broadcast Discovery"); #endif // def RS_BROADCAST_DISCOVERY ftserver->StartupThreads(); diff --git a/libretroshare/src/services/broadcastdiscoveryservice.cc b/libretroshare/src/services/broadcastdiscoveryservice.cc index bbcaa307d..526610ced 100644 --- a/libretroshare/src/services/broadcastdiscoveryservice.cc +++ b/libretroshare/src/services/broadcastdiscoveryservice.cc @@ -31,15 +31,13 @@ #include "serialiser/rsserializer.h" #include "retroshare/rsevents.h" -/*extern*/ std::shared_ptr rsBroadcastDiscovery(nullptr); -RsBroadcastDiscovery::~RsBroadcastDiscovery() { /* Beware of Rs prefix! */ } -RsBroadcastDiscoveryResult::~RsBroadcastDiscoveryResult() {} -RsBroadcastDiscoveryPeerFoundEvent::~RsBroadcastDiscoveryPeerFoundEvent() {} +/*extern*/ RsBroadcastDiscovery* rsBroadcastDiscovery = nullptr; struct BroadcastDiscoveryPack : RsSerializable { BroadcastDiscoveryPack() : mLocalPort(0) {} + RsPgpFingerprint mPgpFingerprint; RsPeerId mSslId; uint16_t mLocalPort; std::string mProfileName; @@ -47,6 +45,7 @@ struct BroadcastDiscoveryPack : RsSerializable void serial_process( RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext& ctx ) override { + RS_SERIAL_PROCESS(mPgpFingerprint); RS_SERIAL_PROCESS(mSslId); RS_SERIAL_PROCESS(mLocalPort); RS_SERIAL_PROCESS(mProfileName); @@ -55,6 +54,7 @@ struct BroadcastDiscoveryPack : RsSerializable static BroadcastDiscoveryPack fromPeerDetails(const RsPeerDetails& pd) { BroadcastDiscoveryPack bdp; + bdp.mPgpFingerprint = pd.fpr; bdp.mSslId = pd.id; bdp.mLocalPort = pd.localPort; bdp.mProfileName = pd.name; @@ -86,7 +86,6 @@ struct BroadcastDiscoveryPack : RsSerializable ~BroadcastDiscoveryPack() override; }; -BroadcastDiscoveryPack::~BroadcastDiscoveryPack() {}; BroadcastDiscoveryService::BroadcastDiscoveryService( RsPeers& pRsPeers ) : @@ -202,3 +201,8 @@ RsBroadcastDiscoveryResult BroadcastDiscoveryService::createResult( return rbdr; } + +RsBroadcastDiscovery::~RsBroadcastDiscovery() = default; +RsBroadcastDiscoveryResult::~RsBroadcastDiscoveryResult() = default; +RsBroadcastDiscoveryPeerFoundEvent::~RsBroadcastDiscoveryPeerFoundEvent() = default; +BroadcastDiscoveryPack::~BroadcastDiscoveryPack() = default; From 86957c98433e5feb7b6b10e881704b69aaed36e7 Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Fri, 27 Sep 2019 16:57:07 +0200 Subject: [PATCH 2/3] Fail gracefully when requesting membership on an unknown circle --- libretroshare/src/services/p3gxscircles.cc | 54 +++++++++++++--------- libretroshare/src/services/p3gxscircles.h | 5 +- 2 files changed, 36 insertions(+), 23 deletions(-) diff --git a/libretroshare/src/services/p3gxscircles.cc b/libretroshare/src/services/p3gxscircles.cc index ca599d85b..eed23313d 100644 --- a/libretroshare/src/services/p3gxscircles.cc +++ b/libretroshare/src/services/p3gxscircles.cc @@ -2061,29 +2061,41 @@ void p3GxsCircles::handle_event(uint32_t event_type, const std::string &elabel) // | | Grp Subscribed: NO | Grp Subscribed: NO | // +-------------+------------------------------+-----------------------------+ -bool p3GxsCircles::pushCircleMembershipRequest(const RsGxsId& own_gxsid,const RsGxsCircleId& circle_id,uint32_t request_type) +bool p3GxsCircles::pushCircleMembershipRequest( + const RsGxsId& own_gxsid, const RsGxsCircleId& circle_id, + uint32_t request_type ) { -#ifdef DEBUG_CIRCLES - std::cerr << "Circle membership request: own_gxsid = " << own_gxsid << ", circle=" << circle_id << ", req type=" << request_type << std::endl; -#endif - - // check for some consistency - - if(request_type != RsGxsCircleSubscriptionRequestItem::SUBSCRIPTION_REQUEST_SUBSCRIBE && request_type != RsGxsCircleSubscriptionRequestItem::SUBSCRIPTION_REQUEST_UNSUBSCRIBE) - return false ; - - std::list own_ids ; - if(!rsIdentity->getOwnIds(own_ids)) - return false ; - - bool found = false ; - for(std::list::const_iterator it(own_ids.begin());it!=own_ids.end() && !found;++it) - found = ( (*it) == own_gxsid) ; + Dbg3() << __PRETTY_FUNCTION__ << "own_gxsid = " << own_gxsid + << ", circle=" << circle_id << ", req type=" << request_type + << std::endl; - if(!found) - return false ; - - // Create a subscribe item + if( request_type != + RsGxsCircleSubscriptionRequestItem::SUBSCRIPTION_REQUEST_SUBSCRIBE && + request_type != + RsGxsCircleSubscriptionRequestItem::SUBSCRIPTION_REQUEST_UNSUBSCRIBE ) + { + RsErr() << __PRETTY_FUNCTION__ << " Unknown request type: " + << request_type << std::endl; + return false; + } + + if(!rsIdentity->isOwnId(own_gxsid)) + { + RsErr() << __PRETTY_FUNCTION__ << " Cannot generate membership request " + << "from not-own id: " << own_gxsid << std::endl; + return false; + } + + if(!getCirclesInfo( + std::list{static_cast(circle_id)}, + RS_DEFAULT_STORAGE_PARAM(std::vector) )) + { + RsErr() << __PRETTY_FUNCTION__ << " Cannot generate membership request " + << "from unknown circle: " << circle_id << std::endl; + return false; + } + + // Create a subscribe item RsGxsCircleSubscriptionRequestItem *s = new RsGxsCircleSubscriptionRequestItem ; diff --git a/libretroshare/src/services/p3gxscircles.h b/libretroshare/src/services/p3gxscircles.h index 48129a9ba..9eb6c15bb 100644 --- a/libretroshare/src/services/p3gxscircles.h +++ b/libretroshare/src/services/p3gxscircles.h @@ -26,12 +26,11 @@ #include "retroshare/rsgxscircles.h" // External Interfaces. #include "gxs/rsgenexchange.h" // GXS service. #include "gxs/rsgixs.h" // Internal Interfaces. - #include "services/p3idservice.h" // For constructing Caches - #include "gxs/gxstokenqueue.h" #include "util/rstickevent.h" #include "util/rsmemcache.h" +#include "util/rsdebug.h" #include #include @@ -321,4 +320,6 @@ virtual RsServiceInfo getServiceInfo(); uint32_t mDummyIdToken; std::list mDummyPgpLinkedIds; std::list mDummyOwnIds; + + RS_SET_CONTEXT_DEBUG_LEVEL(2) }; From a169250e1c462a80aa4ef8b0f0ea768bc3e15ad7 Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Sat, 28 Sep 2019 13:54:16 +0200 Subject: [PATCH 3/3] Add support to build with miniupnpc on Android Necessary to workaroud issues: https://github.com/RetroShare/RetroShare/issues/1649 https://github.com/mrjimenez/pupnp/issues/119 --- .../Android/prepare-toolchain-clang.sh | 31 +++++++++++++++++++ libretroshare/src/libretroshare.pro | 2 +- .../src/rs_upnp/{upnputil.c => upnputil.cc} | 0 3 files changed, 32 insertions(+), 1 deletion(-) rename libretroshare/src/rs_upnp/{upnputil.c => upnputil.cc} (100%) diff --git a/build_scripts/Android/prepare-toolchain-clang.sh b/build_scripts/Android/prepare-toolchain-clang.sh index dcea8b2e2..b943ee5e3 100755 --- a/build_scripts/Android/prepare-toolchain-clang.sh +++ b/build_scripts/Android/prepare-toolchain-clang.sh @@ -49,6 +49,9 @@ define_default_value XAPIAN_SOURCE_SHA256 13f08a0b649c7afa804fa0e85678d693fd6069 define_default_value RAPIDJSON_SOURCE_VERSION "1.1.0" define_default_value RAPIDJSON_SOURCE_SHA256 bf7ced29704a1e696fbccf2a2b4ea068e7774fa37f6d7dd4039d0787f8bed98e +define_default_value MINIUPNPC_SOURCE_VERSION "2.1.20190625" +define_default_value MINIUPNPC_SOURCE_SHA256 8723f5d7fd7970de23635547700878cd29a5c2bb708b5e5475b2d1d2510317fb + ## $1 filename, $2 sha256 hash function check_sha256() @@ -482,6 +485,33 @@ build_xapian() make install } +build_miniupnpc() +{ + echo "build_miniupnpc() +################################################################################ +################################################################################ +################################################################################ +" + S_dir="miniupnpc-${MINIUPNPC_SOURCE_VERSION}" + B_dir="miniupnpc-${MINIUPNPC_SOURCE_VERSION}-build" + D_file="$S_dir.tar.gz" + verified_download $D_file $MINIUPNPC_SOURCE_SHA256 \ + http://miniupnp.free.fr/files/${D_file} + rm -rf $S_dir $B_dir + tar -xf $D_file + mkdir $B_dir + cd $B_dir + cmake \ + -DUPNPC_BUILD_STATIC=TRUE \ + -DUPNPC_BUILD_SHARED=FALSE \ + -DUPNPC_BUILD_TESTS=FALSE \ + -DUPNPC_BUILD_SAMPLE=FALSE \ + -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ + -DCMAKE_INSTALL_PREFIX="${PREFIX}" -B. -S../$S_dir + make -j${HOST_NUM_CPU} + make install +} + build_toolchain [ "${INSTALL_QT_ANDROID}X" != "trueX" ] || install_qt_android build_bzlib @@ -493,6 +523,7 @@ build_rapidjson build_restbed build_udp-discovery-cpp build_xapian +build_miniupnpc delete_copied_includes echo NATIVE_LIBS_TOOLCHAIN_PATH=${NATIVE_LIBS_TOOLCHAIN_PATH} diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index 248ff5563..574311bb8 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -648,7 +648,7 @@ SOURCES += util/folderiterator.cc \ equals(RS_UPNP_LIB, miniupnpc) { HEADERS += rs_upnp/upnputil.h rs_upnp/upnphandler_miniupnp.h - SOURCES += rs_upnp/upnputil.c rs_upnp/upnphandler_miniupnp.cc + SOURCES += rs_upnp/upnputil.cc rs_upnp/upnphandler_miniupnp.cc } contains(RS_UPNP_LIB, upnp) { diff --git a/libretroshare/src/rs_upnp/upnputil.c b/libretroshare/src/rs_upnp/upnputil.cc similarity index 100% rename from libretroshare/src/rs_upnp/upnputil.c rename to libretroshare/src/rs_upnp/upnputil.cc