From aa904a35281269e43ce9d4015ba322340bf3a37e Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 4 Jan 2022 19:28:58 +0100 Subject: [PATCH] fixed bug caused by RsNxsPullItem not deriving from RsNxsItem and uniformized the code --- libretroshare/src/gxs/rsgxsnetservice.cc | 24 +++++++----------------- libretroshare/src/gxs/rsgxsnetservice.h | 6 +++++- libretroshare/src/pqi/pqisslproxy.cc | 4 ++-- libretroshare/src/rsitems/rsnxsitems.cc | 7 +------ libretroshare/src/rsitems/rsnxsitems.h | 18 ++++++------------ 5 files changed, 21 insertions(+), 38 deletions(-) diff --git a/libretroshare/src/gxs/rsgxsnetservice.cc b/libretroshare/src/gxs/rsgxsnetservice.cc index d51fdceef..163bd4ef9 100644 --- a/libretroshare/src/gxs/rsgxsnetservice.cc +++ b/libretroshare/src/gxs/rsgxsnetservice.cc @@ -1730,15 +1730,6 @@ void RsGxsNetService::recvNxsItemQueue() #endif /* Handle pull request and other new items here to not mess with all the * old nested code and items hell */ - switch(static_cast(item->PacketSubType())) - { - case RsNxsSubtype::PULL_REQUEST: - std::unique_ptr pullItem( - static_cast(item) ); - handlePullRequest(std::move(pullItem)); - continue; - } - // RsNxsItem needs dynamic_cast, since they have derived siblings. // RsNxsItem *ni = dynamic_cast(item) ; @@ -1781,10 +1772,11 @@ void RsGxsNetService::recvNxsItemQueue() switch(ni->PacketSubType()) { - case RS_PKT_SUBTYPE_NXS_SYNC_GRP_STATS_ITEM: handleRecvSyncGrpStatistics (dynamic_cast(ni)) ; break ; - case RS_PKT_SUBTYPE_NXS_SYNC_GRP_REQ_ITEM: handleRecvSyncGroup (dynamic_cast(ni)) ; break ; - case RS_PKT_SUBTYPE_NXS_SYNC_MSG_REQ_ITEM: handleRecvSyncMessage (dynamic_cast(ni),item_was_encrypted) ; break ; - case RS_PKT_SUBTYPE_NXS_GRP_PUBLISH_KEY_ITEM:handleRecvPublishKeys (dynamic_cast(ni)) ; break ; + case RS_PKT_SUBTYPE_NXS_SYNC_GRP_STATS_ITEM: handleRecvSyncGrpStatistics (dynamic_cast(ni)) ; break ; + case RS_PKT_SUBTYPE_NXS_SYNC_GRP_REQ_ITEM: handleRecvSyncGroup (dynamic_cast(ni)) ; break ; + case RS_PKT_SUBTYPE_NXS_SYNC_MSG_REQ_ITEM: handleRecvSyncMessage (dynamic_cast(ni),item_was_encrypted) ; break ; + case RS_PKT_SUBTYPE_NXS_GRP_PUBLISH_KEY_ITEM: handleRecvPublishKeys (dynamic_cast(ni)) ; break ; + case RS_PKT_SUBTYPE_NXS_SYNC_PULL_REQUEST_ITEM: handlePullRequest (dynamic_cast(ni)) ; break ; default: if(ni->PacketSubType() != RS_PKT_SUBTYPE_NXS_ENCRYPTED_DATA_ITEM) @@ -5119,8 +5111,7 @@ std::error_condition RsGxsNetService::requestPull(std::set peers) for(auto& peerId: std::as_const(peers)) { - auto item = new RsNxsPullRequestItem( - static_cast(mServType) ); + auto item = new RsNxsPullRequestItem(mServType); item->PeerId(peerId); generic_sendItem(item); } @@ -5128,8 +5119,7 @@ std::error_condition RsGxsNetService::requestPull(std::set peers) return std::error_condition(); } -void RsGxsNetService::handlePullRequest( - std::unique_ptr item ) +void RsGxsNetService::handlePullRequest(RsNxsPullRequestItem *item) { checkUpdatesFromPeers(std::set{item->PeerId()}); } diff --git a/libretroshare/src/gxs/rsgxsnetservice.h b/libretroshare/src/gxs/rsgxsnetservice.h index 0baee2a2f..015d01301 100644 --- a/libretroshare/src/gxs/rsgxsnetservice.h +++ b/libretroshare/src/gxs/rsgxsnetservice.h @@ -432,7 +432,11 @@ private: */ void handleRecvPublishKeys(RsNxsGroupPublishKeyItem*) ; - void handlePullRequest(std::unique_ptr item); + /*! + * Handles a nxs pull request item from a given friend/tunnel + * @param item contaims keys/grp info + */ + void handlePullRequest(RsNxsPullRequestItem *item); /** E: item handlers **/ diff --git a/libretroshare/src/pqi/pqisslproxy.cc b/libretroshare/src/pqi/pqisslproxy.cc index 1c61bef78..0f6c4ae11 100644 --- a/libretroshare/src/pqi/pqisslproxy.cc +++ b/libretroshare/src/pqi/pqisslproxy.cc @@ -586,9 +586,9 @@ bool pqisslproxy::connect_parameter(uint32_t type, const std::string &value) if (type == NET_PARAM_CONNECT_DOMAIN_ADDRESS) { - std::string out; - rs_sprintf(out, "pqisslproxy::connect_parameter() Peer: %s DOMAIN_ADDRESS: %s", PeerId().toStdString().c_str(), value.c_str()); #ifdef PROXY_DEBUG_LOG + std::string out; + rs_sprintf(out, "pqisslproxy::connect_parameter() Peer: %s DOMAIN_ADDRESS: %s", PeerId().toStdString().c_str(), value.c_str()); rslog(RSL_WARNING, pqisslproxyzone, out); #endif mDomainAddress = value; diff --git a/libretroshare/src/rsitems/rsnxsitems.cc b/libretroshare/src/rsitems/rsnxsitems.cc index 94409bc19..dbed0d967 100644 --- a/libretroshare/src/rsitems/rsnxsitems.cc +++ b/libretroshare/src/rsitems/rsnxsitems.cc @@ -64,12 +64,6 @@ RsItem *RsNxsSerialiser::create_item(uint16_t service_id,uint8_t item_subtype) c if(service_id != SERVICE_TYPE) return NULL ; - switch(static_cast(item_subtype)) - { - case RsNxsSubtype::PULL_REQUEST: - return new RsNxsPullRequestItem(static_cast(service_id)); - } - switch(item_subtype) { case RS_PKT_SUBTYPE_NXS_SYNC_GRP_REQ_ITEM: return new RsNxsSyncGrpReqItem(SERVICE_TYPE) ; @@ -82,6 +76,7 @@ RsItem *RsNxsSerialiser::create_item(uint16_t service_id,uint8_t item_subtype) c case RS_PKT_SUBTYPE_NXS_GRP_PUBLISH_KEY_ITEM:return new RsNxsGroupPublishKeyItem(SERVICE_TYPE) ; case RS_PKT_SUBTYPE_NXS_ENCRYPTED_DATA_ITEM: return new RsNxsEncryptedDataItem(SERVICE_TYPE) ; case RS_PKT_SUBTYPE_NXS_SYNC_GRP_STATS_ITEM: return new RsNxsSyncGrpStatsItem(SERVICE_TYPE) ; + case RS_PKT_SUBTYPE_NXS_SYNC_PULL_REQUEST_ITEM: return new RsNxsPullRequestItem(SERVICE_TYPE) ; default: return NULL; diff --git a/libretroshare/src/rsitems/rsnxsitems.h b/libretroshare/src/rsitems/rsnxsitems.h index c7b6c58e3..3cd941bdc 100644 --- a/libretroshare/src/rsitems/rsnxsitems.h +++ b/libretroshare/src/rsitems/rsnxsitems.h @@ -35,11 +35,6 @@ #include "serialiser/rstlvkeys.h" #include "gxs/rsgxsdata.h" -enum class RsNxsSubtype : uint8_t -{ - PULL_REQUEST = 0x90 /// @see RsNxsPullRequestItem -}; - // These items have "flag type" numbers, but this is not used. // TODO: refactor as C++11 enum class const uint8_t RS_PKT_SUBTYPE_NXS_SYNC_GRP_REQ_ITEM = 0x01; @@ -53,6 +48,7 @@ const uint8_t RS_PKT_SUBTYPE_NXS_SYNC_MSG_REQ_ITEM = 0x10; const uint8_t RS_PKT_SUBTYPE_NXS_MSG_ITEM = 0x20; const uint8_t RS_PKT_SUBTYPE_NXS_TRANSAC_ITEM = 0x40; const uint8_t RS_PKT_SUBTYPE_NXS_GRP_PUBLISH_KEY_ITEM = 0x80; +const uint8_t RS_PKT_SUBTYPE_NXS_SYNC_PULL_REQUEST_ITEM = 0x90; #ifdef RS_DEAD_CODE @@ -370,13 +366,10 @@ public: /*! * Used to request to a peer pull updates from us ASAP without waiting GXS sync * timer */ -struct RsNxsPullRequestItem: RsItem +class RsNxsPullRequestItem: public RsNxsItem { - explicit RsNxsPullRequestItem(RsServiceType servtype): - RsItem( RS_PKT_VERSION_SERVICE, - servtype, - static_cast(RsNxsSubtype::PULL_REQUEST), - QOS_PRIORITY_RS_GXS_NET ) {} +public: + explicit RsNxsPullRequestItem(uint16_t servtype): RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_SYNC_PULL_REQUEST_ITEM) {} /// @see RsSerializable void serial_process( RsGenericSerializer::SerializeJob, @@ -388,8 +381,9 @@ struct RsNxsPullRequestItem: RsItem * Used to respond to a RsGrpMsgsReq * with message items satisfying request */ -struct RsNxsMsg : RsNxsItem +class RsNxsMsg : public RsNxsItem { +public: explicit RsNxsMsg(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_MSG_ITEM) , pos(0), count(0), meta(servtype), msg(servtype), metaData(NULL)