From 9a2749dbe5c2041d3529ddd529a5eb078247ef3c Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 9 Nov 2020 22:42:28 +0100 Subject: [PATCH] added flags to invite system to unify the different variables and made sure the HomePage contains at least current IP (not fully tested) --- libretroshare/src/pqi/p3netmgr.cc | 18 ++- libretroshare/src/pqi/p3peermgr.cc | 6 +- libretroshare/src/retroshare/rsevents.h | 3 + libretroshare/src/retroshare/rspeers.h | 45 +++++- libretroshare/src/rsserver/p3peers.cc | 116 +++++++------- libretroshare/src/rsserver/p3peers.h | 144 ++++++++--------- retroshare-gui/src/gui/GetStartedDialog.cpp | 2 +- retroshare-gui/src/gui/HomePage.cpp | 151 +++++++++--------- retroshare-gui/src/gui/HomePage.h | 5 +- retroshare-gui/src/gui/HomePage.ui | 116 +++++--------- retroshare-gui/src/gui/RetroShareLink.cpp | 2 +- .../src/gui/common/NewFriendList.cpp | 3 +- .../src/gui/connect/ConfCertDialog.cpp | 11 +- .../gui/gxschannels/GxsChannelPostsModel.cpp | 10 +- .../src/gui/profile/ProfileWidget.cpp | 3 +- .../src/gui/settings/CryptoPage.cpp | 17 +- 16 files changed, 339 insertions(+), 313 deletions(-) diff --git a/libretroshare/src/pqi/p3netmgr.cc b/libretroshare/src/pqi/p3netmgr.cc index a215ff312..0583bfb72 100644 --- a/libretroshare/src/pqi/p3netmgr.cc +++ b/libretroshare/src/pqi/p3netmgr.cc @@ -1123,7 +1123,14 @@ bool p3NetMgrIMPL::setLocalAddress(const struct sockaddr_storage &addr) #ifdef NETMGR_DEBUG_RESET std::cerr << "p3NetMgrIMPL::setLocalAddress() Calling NetReset" << std::endl; #endif - rslog(RSL_WARNING, p3netmgrzone, "p3NetMgr::setLocalAddress() local address changed, resetting network"); + if(rsEvents) + { + auto ev = std::make_shared(); + ev->mNetworkEventCode = RsNetworkEventCode::LOCAL_IP_UPDATED; + ev->mIPAddress = sockaddr_storage_iptostring(addr); + rsEvents->postEvent(ev); + } + rslog(RSL_WARNING, p3netmgrzone, "p3NetMgr::setLocalAddress() local address changed, resetting network"); netReset(); } return true; @@ -1159,6 +1166,15 @@ bool p3NetMgrIMPL::setExtAddress(const struct sockaddr_storage &addr) #ifdef NETMGR_DEBUG_RESET std::cerr << "p3NetMgrIMPL::setExtAddress() Calling NetReset" << std::endl; #endif + + if(rsEvents) + { + auto ev = std::make_shared(); + ev->mNetworkEventCode = RsNetworkEventCode::EXTERNAL_IP_UPDATED; + ev->mIPAddress = sockaddr_storage_iptostring(addr); + rsEvents->postEvent(ev); + } + rslog(RSL_WARNING, p3netmgrzone, "p3NetMgr::setExtAddress() ext address changed, resetting network"); netReset(); } diff --git a/libretroshare/src/pqi/p3peermgr.cc b/libretroshare/src/pqi/p3peermgr.cc index 55b1eb041..ffcc96031 100644 --- a/libretroshare/src/pqi/p3peermgr.cc +++ b/libretroshare/src/pqi/p3peermgr.cc @@ -1471,7 +1471,7 @@ bool p3PeerMgrIMPL::UpdateOwnAddress( const sockaddr_storage& pLocalAddr, } sockaddr_storage_copy(localAddr, mOwnState.localaddr); - } + } { @@ -1646,7 +1646,7 @@ bool p3PeerMgrIMPL::setExtAddress( const RsPeerId &id, { mOwnState.serveraddr = addr; changed = true; - } + } } mNetMgr->setExtAddress(addr); @@ -1660,7 +1660,7 @@ bool p3PeerMgrIMPL::setExtAddress( const RsPeerId &id, if (mFriendList.end() == (it = mFriendList.find(id))) { #ifdef PEER_DEBUG - std::cerr << "p3PeerMgrIMPL::setLocalAddress() cannot add addres " << "info : peer id not found in friend list id: " << id << std::endl; + std::cerr << "p3PeerMgrIMPL::setExtAddress() cannot add addres " << "info : peer id not found in friend list id: " << id << std::endl; #endif return false; } diff --git a/libretroshare/src/retroshare/rsevents.h b/libretroshare/src/retroshare/rsevents.h index 2498a7712..ec2e7b97f 100644 --- a/libretroshare/src/retroshare/rsevents.h +++ b/libretroshare/src/retroshare/rsevents.h @@ -100,6 +100,9 @@ enum class RsEventType : uint32_t /// @see RsMsgs CHAT_MESSAGE = 15, + /// @see rspeers.h + NETWORK = 16, + __MAX /// Used internally, keep last }; diff --git a/libretroshare/src/retroshare/rspeers.h b/libretroshare/src/retroshare/rspeers.h index 124dba357..c7c9ffe9b 100644 --- a/libretroshare/src/retroshare/rspeers.h +++ b/libretroshare/src/retroshare/rspeers.h @@ -299,6 +299,32 @@ struct RsConnectionEvent : RsEvent ~RsConnectionEvent() override; }; +enum class RsNetworkEventCode: uint8_t { + UNKNOWN = 0x00, + LOCAL_IP_UPDATED = 0x01, + EXTERNAL_IP_UPDATED = 0x02, +}; + +struct RsNetworkEvent : RsEvent +{ + RsNetworkEvent() + : RsEvent(RsEventType::NETWORK), + mNetworkEventCode(RsNetworkEventCode::UNKNOWN){} + + RsNetworkEventCode mNetworkEventCode; + std::string mIPAddress; // local or external IP depending on the event type + + ///* @see RsEvent @see RsSerializable + void serial_process( + RsGenericSerializer::SerializeJob j, + RsGenericSerializer::SerializeContext& ctx ) override + { + RsEvent::serial_process(j, ctx); + RS_SERIAL_PROCESS(mNetworkEventCode); + RS_SERIAL_PROCESS(mIPAddress); + } +}; + //===================================================================================================// // Peer Details // //===================================================================================================// @@ -483,6 +509,16 @@ struct RsPeerStateChangedEvent : RsEvent } }; +enum class RetroshareInviteFlags:uint32_t { + NOTHING = 0x00, + CURRENT_IP = 0x01, + FULL_IP_HISTORY = 0x02, + DNS = 0x04, + RADIX_FORMAT = 0x08, + PGP_SIGNATURES = 0x10, +}; +RS_REGISTER_ENUM_FLAGS_TYPE(RetroshareInviteFlags) + /** The Main Interface Class - for information about your Peers * A peer is another RS instance, means associated with an SSL certificate * A same GPG person can have multiple peer running with different SSL certs @@ -492,6 +528,7 @@ struct RsPeerStateChangedEvent : RsEvent class RsPeers { public: + /** * @brief Get own SSL peer id * @return own peer id @@ -766,8 +803,7 @@ public: */ virtual std::string GetRetroshareInvite( const RsPeerId& sslId = RsPeerId(), - bool includeSignatures = false, - bool includeExtraLocators = true ) = 0; + RetroshareInviteFlags = RetroshareInviteFlags::DNS | RetroshareInviteFlags::CURRENT_IP ) = 0; /** * @brief Get RetroShare short invite of the given peer @@ -785,9 +821,8 @@ public: * "normal" looking web link. Used only if formatRadix is false. * @return false if error occurred, true otherwise */ - virtual bool getShortInvite( - std::string& invite, const RsPeerId& sslId = RsPeerId(), - bool formatRadix = false, bool bareBones = false, + virtual bool getShortInvite(std::string& invite, const RsPeerId& sslId = RsPeerId(), + RetroshareInviteFlags locator_flags = RetroshareInviteFlags::CURRENT_IP | RetroshareInviteFlags::DNS, const std::string& baseUrl = "https://retroshare.me/" ) = 0; /** diff --git a/libretroshare/src/rsserver/p3peers.cc b/libretroshare/src/rsserver/p3peers.cc index 0e2a04df4..eee3864d7 100644 --- a/libretroshare/src/rsserver/p3peers.cc +++ b/libretroshare/src/rsserver/p3peers.cc @@ -1189,9 +1189,7 @@ static void addPacketHeader(RsShortInviteFieldType ptag, size_t size, unsigned c offset += PGPKeyParser::write_125Size(&buf[offset],size) ; } -bool p3Peers::getShortInvite( - std::string& invite, const RsPeerId& _sslId, bool formatRadix, - bool bareBones, const std::string& baseUrl ) +bool p3Peers::getShortInvite(std::string& invite, const RsPeerId& _sslId, RetroshareInviteFlags invite_flags, const std::string& baseUrl ) { RsPeerId sslId = _sslId; if(sslId.isNull()) sslId = getOwnId(); @@ -1213,71 +1211,68 @@ bool p3Peers::getShortInvite( memcpy(&buf[offset],tDetails.name.c_str(),tDetails.name.size()); offset += tDetails.name.size(); - if(!bareBones) - { - /* If is hidden use hidden address and port as locator, else if we have - * a valid dyndns and extPort use that as locator, else if we have a - * valid extAddr and extPort use that as locator, otherwise use most - * recently known locator */ - sockaddr_storage tExt; - if(tDetails.isHiddenNode) - { - addPacketHeader(RsShortInviteFieldType::HIDDEN_LOCATOR,4 + 2 + tDetails.hiddenNodeAddress.size(),buf,offset,buf_size); + /* If it is a hidden node, always use hidden address and port as locator */ + sockaddr_storage tExt; + if(tDetails.isHiddenNode) + { + addPacketHeader(RsShortInviteFieldType::HIDDEN_LOCATOR,4 + 2 + tDetails.hiddenNodeAddress.size(),buf,offset,buf_size); - buf[offset+0] = (uint8_t)((tDetails.hiddenType >> 24) & 0xff); - buf[offset+1] = (uint8_t)((tDetails.hiddenType >> 16) & 0xff); - buf[offset+2] = (uint8_t)((tDetails.hiddenType >> 8) & 0xff); - buf[offset+3] = (uint8_t)((tDetails.hiddenType ) & 0xff); + buf[offset+0] = (uint8_t)((tDetails.hiddenType >> 24) & 0xff); + buf[offset+1] = (uint8_t)((tDetails.hiddenType >> 16) & 0xff); + buf[offset+2] = (uint8_t)((tDetails.hiddenType >> 8) & 0xff); + buf[offset+3] = (uint8_t)((tDetails.hiddenType ) & 0xff); - buf[offset+4] = (uint8_t)((tDetails.hiddenNodePort >> 8) & 0xff); - buf[offset+5] = (uint8_t)((tDetails.hiddenNodePort ) & 0xff); + buf[offset+4] = (uint8_t)((tDetails.hiddenNodePort >> 8) & 0xff); + buf[offset+5] = (uint8_t)((tDetails.hiddenNodePort ) & 0xff); - memcpy(&buf[offset+6],tDetails.hiddenNodeAddress.c_str(),tDetails.hiddenNodeAddress.size()); - offset += 4 + 2 + tDetails.hiddenNodeAddress.size(); - } - else if( !tDetails.dyndns.empty() && (tDetails.extPort || tDetails.localPort) ) - { - uint16_t tPort = tDetails.extPort ? tDetails.extPort : tDetails.localPort; + memcpy(&buf[offset+6],tDetails.hiddenNodeAddress.c_str(),tDetails.hiddenNodeAddress.size()); + offset += 4 + 2 + tDetails.hiddenNodeAddress.size(); + } - addPacketHeader(RsShortInviteFieldType::DNS_LOCATOR, 2 + tDetails.dyndns.size(),buf,offset,buf_size); + if( !!(invite_flags & RetroshareInviteFlags::DNS) && !tDetails.dyndns.empty() && (tDetails.extPort || tDetails.localPort)) + { + uint16_t tPort = tDetails.extPort ? tDetails.extPort : tDetails.localPort; - buf[offset+0] = (uint8_t)((tPort >> 8) & 0xff); - buf[offset+1] = (uint8_t)((tPort ) & 0xff); + addPacketHeader(RsShortInviteFieldType::DNS_LOCATOR, 2 + tDetails.dyndns.size(),buf,offset,buf_size); - memcpy(&buf[offset+2],tDetails.dyndns.c_str(),tDetails.dyndns.size()); - offset += 2 + tDetails.dyndns.size(); - } - else if( sockaddr_storage_inet_pton(tExt, tDetails.extAddr) && - sockaddr_storage_isValidNet(tExt) && - sockaddr_storage_ipv6_to_ipv4(tExt) && - tDetails.extPort ) - { - uint32_t t4Addr = reinterpret_cast(tExt).sin_addr.s_addr; + buf[offset+0] = (uint8_t)((tPort >> 8) & 0xff); + buf[offset+1] = (uint8_t)((tPort ) & 0xff); - addPacketHeader(RsShortInviteFieldType::EXT4_LOCATOR, 4 + 2,buf,offset,buf_size); + memcpy(&buf[offset+2],tDetails.dyndns.c_str(),tDetails.dyndns.size()); + offset += 2 + tDetails.dyndns.size(); + } - buf[offset+0] = (uint8_t)((t4Addr >> 24) & 0xff); - buf[offset+1] = (uint8_t)((t4Addr >> 16) & 0xff); - buf[offset+2] = (uint8_t)((t4Addr >> 8) & 0xff); - buf[offset+3] = (uint8_t)((t4Addr ) & 0xff); + if( !!(invite_flags & RetroshareInviteFlags::CURRENT_IP) && sockaddr_storage_inet_pton(tExt, tDetails.extAddr) + && sockaddr_storage_isValidNet(tExt) && sockaddr_storage_ipv6_to_ipv4(tExt) && tDetails.extPort ) + { + uint32_t t4Addr = reinterpret_cast(tExt).sin_addr.s_addr; - buf[offset+4] = (uint8_t)((tDetails.extPort >> 8) & 0xff); - buf[offset+5] = (uint8_t)((tDetails.extPort ) & 0xff); + addPacketHeader(RsShortInviteFieldType::EXT4_LOCATOR, 4 + 2,buf,offset,buf_size); - offset += 4+2; - } - else if(!tDetails.ipAddressList.empty()) - { - const std::string& tLc = tDetails.ipAddressList.front(); - std::string tLocator = tLc.substr(0, tLc.find_first_of(" ")-1); + buf[offset+0] = (uint8_t)((t4Addr >> 24) & 0xff); + buf[offset+1] = (uint8_t)((t4Addr >> 16) & 0xff); + buf[offset+2] = (uint8_t)((t4Addr >> 8) & 0xff); + buf[offset+3] = (uint8_t)((t4Addr ) & 0xff); - addPacketHeader(RsShortInviteFieldType::LOCATOR, tLocator.size(),buf,offset,buf_size); + buf[offset+4] = (uint8_t)((tDetails.extPort >> 8) & 0xff); + buf[offset+5] = (uint8_t)((tDetails.extPort ) & 0xff); + + offset += 4+2; + } + + if( !!(invite_flags & RetroshareInviteFlags::FULL_IP_HISTORY) && (!tDetails.ipAddressList.empty())) + for(auto& s: tDetails.ipAddressList) + { + const std::string& tLc = s; + std::string tLocator = tLc.substr(0, tLc.find_first_of(" ")-1); + + addPacketHeader(RsShortInviteFieldType::LOCATOR, tLocator.size(),buf,offset,buf_size); memcpy(&buf[offset],tLocator.c_str(),tLocator.size()); offset += tLocator.size(); - } - } - uint32_t computed_crc = PGPKeyManagement::compute24bitsCRC(buf,offset) ; + } + + uint32_t computed_crc = PGPKeyManagement::compute24bitsCRC(buf,offset) ; // handle endian issues. unsigned char mem[3] ; @@ -1291,7 +1286,7 @@ bool p3Peers::getShortInvite( Radix64::encode(buf, static_cast(offset), invite); - if(!formatRadix) + if(!(invite_flags & RetroshareInviteFlags::RADIX_FORMAT)) { RsUrl inviteUrl(baseUrl); inviteUrl.setQueryKV("rsInvite", invite); @@ -1523,9 +1518,7 @@ bool p3Peers::acceptInvite( const std::string& invite, return true; } -std::string p3Peers::GetRetroshareInvite( - const RsPeerId& sslId, bool include_signatures, - bool includeExtraLocators ) +std::string p3Peers::GetRetroshareInvite( const RsPeerId& sslId, RetroshareInviteFlags invite_flags) { #ifdef P3PEERS_DEBUG std::cerr << __PRETTY_FUNCTION__ << std::endl; @@ -1538,14 +1531,13 @@ std::string p3Peers::GetRetroshareInvite( if (getPeerDetails(ssl_id, detail)) { - if(!includeExtraLocators && !detail.isHiddenNode) detail.ipAddressList.clear(); + if(!(invite_flags & RetroshareInviteFlags::FULL_IP_HISTORY) || detail.isHiddenNode) + detail.ipAddressList.clear(); unsigned char *mem_block = nullptr; size_t mem_block_size = 0; - if(!AuthGPG::getAuthGPG()->exportPublicKey( - RsPgpId(detail.gpg_id), mem_block, mem_block_size, false, - include_signatures )) + if(!AuthGPG::getAuthGPG()->exportPublicKey( RsPgpId(detail.gpg_id), mem_block, mem_block_size, false, !!(invite_flags & RetroshareInviteFlags::PGP_SIGNATURES) )) { std::cerr << "Cannot output certificate for id \"" << detail.gpg_id << "\". Sorry." << std::endl; diff --git a/libretroshare/src/rsserver/p3peers.h b/libretroshare/src/rsserver/p3peers.h index e4ad390ed..cd4d0876e 100644 --- a/libretroshare/src/rsserver/p3peers.h +++ b/libretroshare/src/rsserver/p3peers.h @@ -52,54 +52,54 @@ public: virtual bool OthersChanged(); /* Peer Details (Net & Auth) */ - virtual const RsPeerId& getOwnId(); + virtual const RsPeerId& getOwnId() override; - virtual bool haveSecretKey(const RsPgpId& gpg_id) ; + virtual bool haveSecretKey(const RsPgpId& gpg_id) override; - virtual bool getOnlineList(std::list &ids); - virtual bool getFriendList(std::list &ids); + virtual bool getOnlineList(std::list &ids) override; + virtual bool getFriendList(std::list &ids) override; virtual bool getPeersCount( uint32_t& peersCount, uint32_t& onlinePeersCount, - bool countLocations ); + bool countLocations ) override; RS_DEPRECATED - virtual bool getPeerCount (unsigned int *friendCount, unsigned int *onlineCount, bool ssl); + virtual bool getPeerCount (unsigned int *friendCount, unsigned int *onlineCount, bool ssl) override; - virtual bool isOnline(const RsPeerId &id); - virtual bool isFriend(const RsPeerId &id); - virtual bool isPgpFriend(const RsPgpId& pgpId); + virtual bool isOnline(const RsPeerId &id) override; + virtual bool isFriend(const RsPeerId &id) override; + virtual bool isPgpFriend(const RsPgpId& pgpId) override; /// @see RsPeers bool isSslOnlyFriend(const RsPeerId& sslId) override; RS_DEPRECATED_FOR(isPgpFriend) - virtual bool isGPGAccepted(const RsPgpId &gpg_id_is_friend); + virtual bool isGPGAccepted(const RsPgpId &gpg_id_is_friend) override; - virtual std::string getGPGName(const RsPgpId &gpg_id); - virtual std::string getPeerName(const RsPeerId& ssl_or_gpg_id); - virtual bool getPeerDetails(const RsPeerId& ssl_or_gpg_id, RsPeerDetails &d); + virtual std::string getGPGName(const RsPgpId &gpg_id) override; + virtual std::string getPeerName(const RsPeerId& ssl_or_gpg_id) override; + virtual bool getPeerDetails(const RsPeerId& ssl_or_gpg_id, RsPeerDetails &d) override; /* Using PGP Ids */ - virtual const RsPgpId& getGPGOwnId(); - virtual RsPgpId getGPGId(const RsPeerId &ssl_id); - virtual bool isKeySupported(const RsPgpId& ids); + virtual const RsPgpId& getGPGOwnId() override; + virtual RsPgpId getGPGId(const RsPeerId &ssl_id) override; + virtual bool isKeySupported(const RsPgpId& ids) override; /// @see RsPeers bool getPgpFriendList(std::vector& pgpIds) override; RS_DEPRECATED_FOR(getPgpFriendList) - virtual bool getGPGAcceptedList(std::list &ids); - virtual bool getGPGSignedList(std::list &ids); - virtual bool getGPGValidList(std::list &ids); - virtual bool getGPGAllList(std::list &ids); - virtual bool getGPGDetails(const RsPgpId &id, RsPeerDetails &d); - virtual bool getAssociatedSSLIds(const RsPgpId& gpg_id, std::list &ids); - virtual bool gpgSignData(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen, std::string reason = "") ; + virtual bool getGPGAcceptedList(std::list &ids) override; + virtual bool getGPGSignedList(std::list &ids) override; + virtual bool getGPGValidList(std::list &ids) override; + virtual bool getGPGAllList(std::list &ids) override; + virtual bool getGPGDetails(const RsPgpId &id, RsPeerDetails &d) override; + virtual bool getAssociatedSSLIds(const RsPgpId& gpg_id, std::list &ids) override; + virtual bool gpgSignData(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen, std::string reason = "") override; virtual RsPgpId pgpIdFromFingerprint(const RsPgpFingerprint& fpr) override; /* Add/Remove Friends */ - virtual bool addFriend(const RsPeerId &ssl_id, const RsPgpId &gpg_id,ServicePermissionFlags flags = RS_NODE_PERM_DEFAULT); + virtual bool addFriend(const RsPeerId &ssl_id, const RsPgpId &gpg_id,ServicePermissionFlags flags = RS_NODE_PERM_DEFAULT) override; /// @see RsPeers bool addSslOnlyFriend( @@ -107,50 +107,48 @@ public: const RsPgpId& pgp_id, const RsPeerDetails& details = RsPeerDetails() ) override; - virtual bool removeFriend(const RsPgpId& gpgid); - virtual bool removeFriendLocation(const RsPeerId& sslId); + virtual bool removeFriend(const RsPgpId& gpgid) override; + virtual bool removeFriendLocation(const RsPeerId& sslId) override; /* keyring management */ - virtual bool removeKeysFromPGPKeyring(const std::set &pgp_ids,std::string& backup_file,uint32_t& error_code); + virtual bool removeKeysFromPGPKeyring(const std::set &pgp_ids,std::string& backup_file,uint32_t& error_code) override; /* Network Stuff */ - virtual bool connectAttempt(const RsPeerId &id); - virtual bool setLocation(const RsPeerId &ssl_id, const std::string &location);//location is shown in the gui to differentiate ssl certs - virtual bool setHiddenNode(const RsPeerId &id, const std::string &hidden_node_address); - virtual bool setHiddenNode(const RsPeerId &id, const std::string &address, uint16_t port); - virtual bool isHiddenNode(const RsPeerId &id); + virtual bool connectAttempt(const RsPeerId &id) override; + virtual bool setLocation(const RsPeerId &ssl_id, const std::string &location) override;//location is shown in the gui to differentiate ssl certs + virtual bool setHiddenNode(const RsPeerId &id, const std::string &hidden_node_address) override; + virtual bool setHiddenNode(const RsPeerId &id, const std::string &address, uint16_t port) override; + virtual bool isHiddenNode(const RsPeerId &id) override; - virtual bool addPeerLocator(const RsPeerId &ssl_id, const RsUrl& locator); - virtual bool setLocalAddress(const RsPeerId &id, const std::string &addr, uint16_t port); - virtual bool setExtAddress(const RsPeerId &id, const std::string &addr, uint16_t port); - virtual bool setDynDNS(const RsPeerId &id, const std::string &dyndns); - virtual bool setNetworkMode(const RsPeerId &id, uint32_t netMode); - virtual bool setVisState(const RsPeerId &id, uint16_t vs_disc, uint16_t vs_dht); + virtual bool addPeerLocator(const RsPeerId &ssl_id, const RsUrl& locator) override; + virtual bool setLocalAddress(const RsPeerId &id, const std::string &addr, uint16_t port) override; + virtual bool setExtAddress(const RsPeerId &id, const std::string &addr, uint16_t port) override; + virtual bool setDynDNS(const RsPeerId &id, const std::string &dyndns) override; + virtual bool setNetworkMode(const RsPeerId &id, uint32_t netMode) override; + virtual bool setVisState(const RsPeerId &id, uint16_t vs_disc, uint16_t vs_dht) override; - virtual bool getProxyServer(const uint32_t type, std::string &addr, uint16_t &port,uint32_t& status); - virtual bool setProxyServer(const uint32_t type, const std::string &addr, const uint16_t port); + virtual bool getProxyServer(const uint32_t type, std::string &addr, uint16_t &port,uint32_t& status) override; + virtual bool setProxyServer(const uint32_t type, const std::string &addr, const uint16_t port) override; virtual bool isProxyAddress(const uint32_t type, const sockaddr_storage &addr); - virtual void getIPServersList(std::list& ip_servers); - virtual void allowServerIPDetermination(bool); - virtual bool getAllowServerIPDetermination(); - virtual bool resetOwnExternalAddressList(); + virtual void getIPServersList(std::list& ip_servers) override; + virtual void allowServerIPDetermination(bool) override; + virtual bool getAllowServerIPDetermination() override; + virtual bool resetOwnExternalAddressList() override; /* Auth Stuff */ // Get the invitation (GPG cert + local/ext address + SSL id for the given peer) - virtual std::string GetRetroshareInvite( - const RsPeerId& ssl_id = RsPeerId(), - bool include_signatures = false, bool includeExtraLocators = true ); + virtual std::string GetRetroshareInvite(const RsPeerId& ssl_id = RsPeerId(), RetroshareInviteFlags invite_flags = RetroshareInviteFlags::DNS | RetroshareInviteFlags::CURRENT_IP ) override; + RS_DEPRECATED /// @see RsPeers std::string getPGPKey(const RsPgpId& pgp_id,bool include_signatures) override; virtual bool GetPGPBase64StringAndCheckSum(const RsPgpId& gpg_id,std::string& gpg_base64_string,std::string& gpg_base64_checksum); /// @see RsPeers - bool getShortInvite( - std::string& invite, const RsPeerId& sslId = RsPeerId(), - bool formatRadix = false, bool bareBones = false, - const std::string& baseUrl = "https://retroshare.me/" ) override; + bool getShortInvite(std::string& invite, const RsPeerId& sslId = RsPeerId(), + RetroshareInviteFlags invite_flags = RetroshareInviteFlags::CURRENT_IP | RetroshareInviteFlags::DNS, + const std::string& baseUrl = "https://retroshare.me/" ) override; /// @see RsPeers bool parseShortInvite(const std::string& invite, RsPeerDetails& details, uint32_t &err_code ) override; @@ -158,39 +156,39 @@ public: /// @see RsPeers::acceptInvite virtual bool acceptInvite( const std::string& invite, - ServicePermissionFlags flags = RS_NODE_PERM_DEFAULT ); + ServicePermissionFlags flags = RS_NODE_PERM_DEFAULT ) override; - virtual bool loadCertificateFromString(const std::string& cert, RsPeerId& ssl_id,RsPgpId& pgp_id, std::string& error_string); - virtual bool loadPgpKeyFromBinaryData( const unsigned char *bin_key_data,uint32_t bin_key_len, RsPgpId& gpg_id, std::string& error_string ); - virtual bool loadDetailsFromStringCert(const std::string &cert, RsPeerDetails &pd, uint32_t& error_code); + virtual bool loadCertificateFromString(const std::string& cert, RsPeerId& ssl_id,RsPgpId& pgp_id, std::string& error_string) override; + virtual bool loadPgpKeyFromBinaryData( const unsigned char *bin_key_data,uint32_t bin_key_len, RsPgpId& gpg_id, std::string& error_string ) override; + virtual bool loadDetailsFromStringCert(const std::string &cert, RsPeerDetails &pd, uint32_t& error_code) override; virtual bool cleanCertificate(const std::string &certstr, std::string &cleanCert, bool &is_short_format, uint32_t& error_code) override; - virtual std::string saveCertificateToString(const RsPeerId &id); + virtual std::string saveCertificateToString(const RsPeerId &id) override; - virtual bool signGPGCertificate(const RsPgpId &id); - virtual bool trustGPGCertificate(const RsPgpId &id, uint32_t trustlvl); + virtual bool signGPGCertificate(const RsPgpId &id) override; + virtual bool trustGPGCertificate(const RsPgpId &id, uint32_t trustlvl) override; /* Group Stuff */ - virtual bool addGroup(RsGroupInfo &groupInfo); - virtual bool editGroup(const RsNodeGroupId &groupId, RsGroupInfo &groupInfo); - virtual bool removeGroup(const RsNodeGroupId &groupId); - virtual bool getGroupInfo(const RsNodeGroupId &groupId, RsGroupInfo &groupInfo); - virtual bool getGroupInfoByName(const std::string& groupName, RsGroupInfo& groupInfo); - virtual bool getGroupInfoList(std::list &groupInfoList); - virtual bool assignPeerToGroup(const RsNodeGroupId &groupId, const RsPgpId &peerId, bool assign); - virtual bool assignPeersToGroup(const RsNodeGroupId &groupId, const std::list& peerIds, bool assign); + virtual bool addGroup(RsGroupInfo &groupInfo) override; + virtual bool editGroup(const RsNodeGroupId &groupId, RsGroupInfo &groupInfo) override; + virtual bool removeGroup(const RsNodeGroupId &groupId) override; + virtual bool getGroupInfo(const RsNodeGroupId &groupId, RsGroupInfo &groupInfo) override; + virtual bool getGroupInfoByName(const std::string& groupName, RsGroupInfo& groupInfo) override; + virtual bool getGroupInfoList(std::list &groupInfoList) override; + virtual bool assignPeerToGroup(const RsNodeGroupId &groupId, const RsPgpId &peerId, bool assign) override; + virtual bool assignPeersToGroup(const RsNodeGroupId &groupId, const std::list& peerIds, bool assign) override; - virtual FileSearchFlags computePeerPermissionFlags(const RsPeerId& peer_id, FileStorageFlags share_flags, const std::list &parent_groups); + virtual FileSearchFlags computePeerPermissionFlags(const RsPeerId& peer_id, FileStorageFlags share_flags, const std::list &parent_groups) override; // service permission stuff - virtual ServicePermissionFlags servicePermissionFlags(const RsPgpId& gpg_id); - virtual ServicePermissionFlags servicePermissionFlags(const RsPeerId & ssl_id); - virtual void setServicePermissionFlags(const RsPgpId& gpg_id,const ServicePermissionFlags& flags); + virtual ServicePermissionFlags servicePermissionFlags(const RsPgpId& gpg_id) override; + virtual ServicePermissionFlags servicePermissionFlags(const RsPeerId & ssl_id) override; + virtual void setServicePermissionFlags(const RsPgpId& gpg_id,const ServicePermissionFlags& flags) override; - virtual bool setPeerMaximumRates(const RsPgpId& pid,uint32_t maxUploadRate,uint32_t maxDownloadRate); - virtual bool getPeerMaximumRates(const RsPgpId& pid,uint32_t& maxUploadRate,uint32_t& maxDownloadRate); - virtual bool getPeerMaximumRates(const RsPeerId& pid,uint32_t& maxUploadRate,uint32_t& maxDownloadRate); + virtual bool setPeerMaximumRates(const RsPgpId& pid,uint32_t maxUploadRate,uint32_t maxDownloadRate) override; + virtual bool getPeerMaximumRates(const RsPgpId& pid,uint32_t& maxUploadRate,uint32_t& maxDownloadRate) override; + virtual bool getPeerMaximumRates(const RsPeerId& pid,uint32_t& maxUploadRate,uint32_t& maxDownloadRate) override; private: p3LinkMgr *mLinkMgr; diff --git a/retroshare-gui/src/gui/GetStartedDialog.cpp b/retroshare-gui/src/gui/GetStartedDialog.cpp index 7357ffb2f..d525808b6 100644 --- a/retroshare-gui/src/gui/GetStartedDialog.cpp +++ b/retroshare-gui/src/gui/GetStartedDialog.cpp @@ -235,7 +235,7 @@ void GetStartedDialog::inviteFriends() { RsAutoUpdatePage::lockAllEvents(); - cert = rsPeers->GetRetroshareInvite(RsPeerId(),false,false); + cert = rsPeers->GetRetroshareInvite(RsPeerId(),RetroshareInviteFlags::DNS | RetroshareInviteFlags::CURRENT_IP | RetroshareInviteFlags::FULL_IP_HISTORY); RsAutoUpdatePage::unlockAllEvents() ; } diff --git a/retroshare-gui/src/gui/HomePage.cpp b/retroshare-gui/src/gui/HomePage.cpp index 5ec132ef8..e1400af66 100644 --- a/retroshare-gui/src/gui/HomePage.cpp +++ b/retroshare-gui/src/gui/HomePage.cpp @@ -23,6 +23,8 @@ #include "retroshare/rsinit.h" +#include "util/qtthreadsutils.h" + #include "gui/notifyqt.h" #include "gui/msgs/MessageComposer.h" #include "gui/connect/ConnectFriendWizard.h" @@ -49,8 +51,7 @@ HomePage::HomePage(QWidget *parent) : MainPage(parent), ui(new Ui::HomePage), mIncludeAllIPs(false), - mUseShortFormat(false), - mUseBackwardCompatibleCert(false) + mUseShortFormat(true) { ui->setupUi(this); @@ -86,7 +87,7 @@ HomePage::HomePage(QWidget *parent) : useOldFormatAct->setToolTip(tr("Displays the certificate format used up to version 0.6.5\nOld Retroshare nodes will not understand the\nnew short format")); connect(useOldFormatAct, SIGNAL(triggered()), this, SLOT(toggleUseOldFormat())); useOldFormatAct->setCheckable(true); - useOldFormatAct->setChecked(mUseBackwardCompatibleCert); + useOldFormatAct->setChecked(!mUseShortFormat); menu->addAction(useOldFormatAct); menu->addSeparator(); @@ -96,27 +97,53 @@ HomePage::HomePage(QWidget *parent) : ui->shareButton->setMenu(menu); - QObject::connect(ui->userCertEdit,SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(certContextMenu(QPoint))); - connect(ui->openwebhelp,SIGNAL(clicked()), this,SLOT(openWebHelp())) ; - ui->userCertEdit->hide(); - int S = QFontMetricsF(font()).height(); - QString help_str = tr( - "

  Welcome to Retroshare!

\ -

You need to make friends! After you create a network of friends or join an existing network,\ - you'll be able to exchange files, chat, talk in forums, etc.

\ -
\ - \ -
\ -

To do so, copy your certificate on this page and send it to friends, and add your friends' certificate.

\ -

Another option is to search the internet for \"Retroshare chat servers\" (independently administrated). These servers allow you to exchange \ - certificates with a dedicated Retroshare node, through which\ - you will be able to anonymously meet other people.

").arg(QString::number(2*S)).arg(width()*0.5); - registerHelpButton(ui->helpButton,help_str,"HomePage") ; + QString help_str = tr( + "

  Welcome to Retroshare!

\ +

You need to make friends! After you create a network of friends or join an existing network,\ + you'll be able to exchange files, chat, talk in forums, etc.

\ +
\ + \ +
\ +

To do so, copy your certificate on this page and send it to friends, and add your friends' certificate.

\ +

Another option is to search the internet for \"Retroshare chat servers\" (independently administrated). These servers allow you to exchange \ + certificates with a dedicated Retroshare node, through which\ + you will be able to anonymously meet other people.

").arg(QString::number(2*S)).arg(width()*0.5); + registerHelpButton(ui->helpButton,help_str,"HomePage") ; + + // register a event handler to catch IP updates + + mEventHandlerId = 0; + rsEvents->registerEventsHandler( [this](std::shared_ptr event) { handleEvent(event); }, mEventHandlerId, RsEventType::NETWORK ); } +void HomePage::handleEvent(std::shared_ptr e) +{ + if(e->mType != RsEventType::NETWORK) + return; + + const RsNetworkEvent *ne = dynamic_cast(e.get()); + + if(ne) + return; + + // in any case we update the IPs + + switch(ne->mNetworkEventCode) + { + case RsNetworkEventCode::LOCAL_IP_UPDATED: // [fallthrough] + case RsNetworkEventCode::EXTERNAL_IP_UPDATED: // [fallthrough] + RsQThreadUtils::postToObject( [=]() + { + updateCertificate(); + },this); + break; + default: + break; + } +} void HomePage::certContextMenu(QPoint point) { QMenu menu(this) ; @@ -168,10 +195,7 @@ HomePage::~HomePage() void HomePage::updateCertificate() { - if(mUseBackwardCompatibleCert) - updateOwnCert(); - else - updateOwnId(); + updateOwnCert(); } void HomePage::updateOwnCert() @@ -186,54 +210,43 @@ void HomePage::updateOwnCert() return ; } - std::string invite ; + QString invite ; + RetroshareInviteFlags invite_flags = RetroshareInviteFlags::CURRENT_IP; + + if(mIncludeAllIPs) + invite_flags |= RetroshareInviteFlags::FULL_IP_HISTORY; if(mUseShortFormat) - rsPeers->getShortInvite(invite,rsPeers->getOwnId(),true,!mIncludeAllIPs); - else - invite = rsPeers->GetRetroshareInvite(detail.id,false,include_extra_locators); + { + std::string short_invite; + rsPeers->getShortInvite(short_invite,rsPeers->getOwnId(),invite_flags | RetroshareInviteFlags::RADIX_FORMAT); - ui->retroshareid->setText("\n"+QString::fromUtf8(invite.c_str())+"\n"); + QString S; + QString txt; + + for(uint32_t i=0;iGetRetroshareInvite(detail.id,invite_flags)); + + ui->retroshareid->setText("\n"+invite+"\n"); QString description = ConfCertDialog::getCertificateDescription(detail,false,mUseShortFormat,include_extra_locators); ui->retroshareid->setToolTip(description); } -void HomePage::updateOwnId() -{ - RsPeerDetails detail; - - if (!rsPeers->getPeerDetails(rsPeers->getOwnId(), detail)) - { - std::cerr << "(EE) Cannot retrieve information about own certificate. That is a real problem!!" << std::endl; - return ; - } - - bool include_extra_locators = mIncludeAllIPs || detail.isHiddenNode; - std::string invite ; - - rsPeers->getShortInvite(invite,rsPeers->getOwnId(),true,!include_extra_locators); - - QString S; - QString txt; - int i=0; - - for(uint32_t i=0;iretroshareid->setText("\n"+txt+"\n"); // the "\n" is here to make some space -//#endif -// ui->retroshareid->setText(QString::fromUtf8(invite.c_str())); -} static void sendMail(QString sAddress, QString sSubject, QString sBody) { #ifdef Q_OS_WIN @@ -335,18 +348,6 @@ void HomePage::openWebHelp() void HomePage::toggleUseOldFormat() { - mUseBackwardCompatibleCert = !mUseBackwardCompatibleCert; + mUseShortFormat = !mUseShortFormat; updateCertificate(); - - if (mUseBackwardCompatibleCert) - { - //ui->userCertEdit->show(); - //ui->expandButton->setToolTip(tr("Revert to normal Retroshare ID")); - } - else - { - //ui->userCertEdit->hide(); - //ui->expandButton->setToolTip(tr("Show full certificate (old format for backward compatibility)")); - } - } diff --git a/retroshare-gui/src/gui/HomePage.h b/retroshare-gui/src/gui/HomePage.h index 1edf6c037..2b9e28c18 100644 --- a/retroshare-gui/src/gui/HomePage.h +++ b/retroshare-gui/src/gui/HomePage.h @@ -50,7 +50,6 @@ private slots: void certContextMenu(QPoint); void updateOwnCert(); void updateCertificate(); - void updateOwnId(); void runEmailClient(); void copyCert(); void copyId(); @@ -69,8 +68,10 @@ private: bool mIncludeAllIPs; bool mUseShortFormat; - bool mUseBackwardCompatibleCert; + RsEventsHandlerId_t mEventHandlerId; + + void handleEvent(std::shared_ptr event); }; #endif // HomePage_H diff --git a/retroshare-gui/src/gui/HomePage.ui b/retroshare-gui/src/gui/HomePage.ui index 67d447037..16dd9080a 100644 --- a/retroshare-gui/src/gui/HomePage.ui +++ b/retroshare-gui/src/gui/HomePage.ui @@ -225,64 +225,7 @@ private and secure decentralized communication platform. 0 - - - - - 0 - 0 - - - - - Courier New - - - - Qt::CustomContextMenu - - - - - - - - - QPlainTextEdit::NoWrap - - - true - - - 80 - - - false - - - - - - - - 0 - 0 - - - - - 11 - - - - This is your Retroshare ID. Copy and share with your friends! - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - + @@ -312,24 +255,7 @@ private and secure decentralized communication platform. - - - - ... - - - - :/icons/help_64.png:/icons/help_64.png - - - true - - - true - - - - + @@ -361,6 +287,44 @@ private and secure decentralized communication platform. + + + + + 0 + 0 + + + + + 11 + + + + This is your Retroshare ID. Copy and share with your friends! + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + ... + + + + :/icons/help_64.png:/icons/help_64.png + + + true + + + true + + + diff --git a/retroshare-gui/src/gui/RetroShareLink.cpp b/retroshare-gui/src/gui/RetroShareLink.cpp index 72d6d7464..d34871104 100644 --- a/retroshare-gui/src/gui/RetroShareLink.cpp +++ b/retroshare-gui/src/gui/RetroShareLink.cpp @@ -566,7 +566,7 @@ RetroShareLink RetroShareLink::createCertificate(const RsPeerId& ssl_id) } else { link._type = TYPE_CERTIFICATE; - link._radix = QString::fromUtf8(rsPeers->GetRetroshareInvite(ssl_id,false,false).c_str()); + link._radix = QString::fromUtf8(rsPeers->GetRetroshareInvite(ssl_id).c_str()); link._name = QString::fromUtf8(detail.name.c_str()); link._location = QString::fromUtf8(detail.location.c_str()); link._radix.replace("\n",""); diff --git a/retroshare-gui/src/gui/common/NewFriendList.cpp b/retroshare-gui/src/gui/common/NewFriendList.cpp index 839145a16..ba0f94391 100644 --- a/retroshare-gui/src/gui/common/NewFriendList.cpp +++ b/retroshare-gui/src/gui/common/NewFriendList.cpp @@ -1255,7 +1255,8 @@ bool NewFriendList::exportFriendlist(QString &fileName) if (!rsPeers->getPeerDetails(*list_iter, detailSSL)) continue; - std::string certificate = rsPeers->GetRetroshareInvite(detailSSL.id, true,true); + std::string certificate = rsPeers->GetRetroshareInvite(detailSSL.id, RetroshareInviteFlags::CURRENT_IP | RetroshareInviteFlags::DNS | RetroshareInviteFlags::RADIX_FORMAT); + // remove \n from certificate certificate.erase(std::remove(certificate.begin(), certificate.end(), '\n'), certificate.end()); diff --git a/retroshare-gui/src/gui/connect/ConfCertDialog.cpp b/retroshare-gui/src/gui/connect/ConfCertDialog.cpp index 59871bde2..ed12ee192 100644 --- a/retroshare-gui/src/gui/connect/ConfCertDialog.cpp +++ b/retroshare-gui/src/gui/connect/ConfCertDialog.cpp @@ -275,15 +275,22 @@ void ConfCertDialog::loadInvitePage() // ui.userCertificateText_2->setText(QString::fromUtf8(pgp_key.c_str())); std::string invite ; + RetroshareInviteFlags flags = RetroshareInviteFlags::DNS | RetroshareInviteFlags::CURRENT_IP | RetroshareInviteFlags::RADIX_FORMAT; + + if(!detail.isHiddenNode && ui._includeIPHistory_CB->isChecked()) + flags |= RetroshareInviteFlags::FULL_IP_HISTORY; if(ui._shortFormat_CB->isChecked()) { - rsPeers->getShortInvite(invite,detail.id,true,!(ui._includeIPHistory_CB->isChecked()|| detail.isHiddenNode) ); + rsPeers->getShortInvite(invite,detail.id,flags); ui.stabWidget->setTabText(1, tr("Retroshare ID")); } else { - invite = rsPeers->GetRetroshareInvite(detail.id, ui._shouldAddSignatures_CB->isChecked(), ui._includeIPHistory_CB->isChecked() ) ; + if(ui._shouldAddSignatures_CB->isChecked()) + flags |= RetroshareInviteFlags::PGP_SIGNATURES; + + invite = rsPeers->GetRetroshareInvite(detail.id, flags ) ; ui.stabWidget->setTabText(1, tr("Retroshare Certificate")); } diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp index c4f804ecc..d7bbf344d 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp @@ -104,11 +104,12 @@ void RsGxsChannelPostsModel::handleEvent_main_thread(std::shared_ptr comments; std::vector votes; - std::cerr << "display of e 1: " << E << std::endl; - if(!rsGxsChannels->getChannelContent(E.mChannelGroupId,std::set{ E.mChannelMsgId }, posts,comments,votes)) { std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve channel message data for channel/msg " << E.mChannelGroupId << "/" << E.mChannelMsgId << std::endl; @@ -131,8 +130,6 @@ void RsGxsChannelPostsModel::handleEvent_main_thread(std::shared_ptrgetChannelComments(E.mChannelGroupId,std::set{ E.mChannelMsgId },comments)) { std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve message comment data for channel/msg " << E.mChannelGroupId << "/" << E.mChannelMsgId << std::endl; @@ -141,7 +138,6 @@ void RsGxsChannelPostsModel::handleEvent_main_thread(std::shared_ptrsetText(misc::fingerPrintStyleSplit(QString::fromStdString(detail.fpr.toStdString()))); std::string invite ; - rsPeers->getShortInvite(invite,rsPeers->getOwnId(),true,false); + rsPeers->getShortInvite(invite,rsPeers->getOwnId(),RetroshareInviteFlags::RADIX_FORMAT | RetroshareInviteFlags::DNS | RetroshareInviteFlags::CURRENT_IP); ui.retroshareid->setText(QString::fromUtf8(invite.c_str())); /* set retroshare version */ @@ -116,11 +116,22 @@ void CryptoPage::load() { std::string cert ; + RetroshareInviteFlags flags = RetroshareInviteFlags::DNS | RetroshareInviteFlags::CURRENT_IP; if(ui._shortFormat_CB->isChecked()) - rsPeers->getShortInvite(cert,rsPeers->getOwnId(), true, !ui._includeAllIPs_CB->isChecked()); + { + if(ui._includeAllIPs_CB->isChecked()) + flags |= RetroshareInviteFlags::FULL_IP_HISTORY; + + rsPeers->getShortInvite(cert,rsPeers->getOwnId(), RetroshareInviteFlags::RADIX_FORMAT | flags); + } else - cert = rsPeers->GetRetroshareInvite( rsPeers->getOwnId(), ui._includeSignatures_CB->isChecked(), ui._includeAllIPs_CB->isChecked() ); + { + if(ui._includeSignatures_CB->isChecked()) + flags |= RetroshareInviteFlags::PGP_SIGNATURES; + + cert = rsPeers->GetRetroshareInvite( rsPeers->getOwnId(), flags); + } ui.certplainTextEdit->setPlainText( QString::fromUtf8( cert.c_str() ) );