From f4a60901505f2ffab9591730e150d9d54bd01741 Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Mon, 26 Feb 2018 15:55:20 +0100 Subject: [PATCH] More ipv6_to_ipv4 conversions --- libretroshare/src/pqi/p3peermgr.cc | 30 +++++++++++---------------- libretroshare/src/pqi/p3peermgr.h | 6 +++--- libretroshare/src/rsserver/p3peers.cc | 7 +++++-- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/libretroshare/src/pqi/p3peermgr.cc b/libretroshare/src/pqi/p3peermgr.cc index f275170d6..bd1b40528 100644 --- a/libretroshare/src/pqi/p3peermgr.cc +++ b/libretroshare/src/pqi/p3peermgr.cc @@ -331,8 +331,8 @@ const RsPeerId& p3PeerMgrIMPL::getOwnId() bool p3PeerMgrIMPL::getOwnNetStatus(peerState &state) { - RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ - state = mOwnState; + RS_STACK_MUTEX(mPeerMtx); + state = mOwnState; return true; } @@ -817,15 +817,12 @@ int p3PeerMgrIMPL::getFriendCount(bool ssl, bool online) bool p3PeerMgrIMPL::getFriendNetStatus(const RsPeerId &id, peerState &state) { - RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ + RS_STACK_MUTEX(mPeerMtx); /* check for existing */ std::map::iterator it; it = mFriendList.find(id); - if (it == mFriendList.end()) - { - return false; - } + if (it == mFriendList.end()) return false; state = it->second; return true; @@ -834,27 +831,24 @@ bool p3PeerMgrIMPL::getFriendNetStatus(const RsPeerId &id, peerState &state) bool p3PeerMgrIMPL::getOthersNetStatus(const RsPeerId &id, peerState &state) { - RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ + RS_STACK_MUTEX(mPeerMtx); /* check for existing */ std::map::iterator it; it = mOthersList.find(id); - if (it == mOthersList.end()) - { - return false; - } + if (it == mOthersList.end()) return false; state = it->second; return true; } -int p3PeerMgrIMPL::getConnectAddresses(const RsPeerId &id, - struct sockaddr_storage &lAddr, struct sockaddr_storage &eAddr, - pqiIpAddrSet &histAddrs, std::string &dyndns) +int p3PeerMgrIMPL::getConnectAddresses( + const RsPeerId &id, sockaddr_storage &lAddr, sockaddr_storage &eAddr, + pqiIpAddrSet &histAddrs, std::string &dyndns ) { - RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ - + RS_STACK_MUTEX(mPeerMtx); + /* check for existing */ std::map::iterator it; it = mFriendList.find(id); @@ -865,7 +859,7 @@ int p3PeerMgrIMPL::getConnectAddresses(const RsPeerId &id, std::cerr << std::endl; return 0; } - + lAddr = it->second.localaddr; eAddr = it->second.serveraddr; histAddrs = it->second.ipAddrs; diff --git a/libretroshare/src/pqi/p3peermgr.h b/libretroshare/src/pqi/p3peermgr.h index 55d99b569..8a0ac5235 100644 --- a/libretroshare/src/pqi/p3peermgr.h +++ b/libretroshare/src/pqi/p3peermgr.h @@ -357,9 +357,9 @@ public: bool setOwnNetworkMode(uint32_t netMode); bool setOwnVisState(uint16_t vs_disc, uint16_t vs_dht); - int getConnectAddresses(const RsPeerId &id, - struct sockaddr_storage &lAddr, struct sockaddr_storage &eAddr, - pqiIpAddrSet &histAddrs, std::string &dyndns); + int getConnectAddresses( const RsPeerId &id, sockaddr_storage &lAddr, + sockaddr_storage &eAddr, pqiIpAddrSet &histAddrs, + std::string &dyndns ); protected: diff --git a/libretroshare/src/rsserver/p3peers.cc b/libretroshare/src/rsserver/p3peers.cc index c27943f62..9f0d7d73d 100644 --- a/libretroshare/src/rsserver/p3peers.cc +++ b/libretroshare/src/rsserver/p3peers.cc @@ -333,8 +333,9 @@ bool p3Peers::getPeerDetails(const RsPeerId& id, RsPeerDetails &d) d.hiddenNodePort = 0; d.hiddenType = RS_HIDDEN_TYPE_NONE; - if (sockaddr_storage_ipv6_to_ipv4(ps.localaddr)) + if(!sockaddr_storage_isnull(ps.localaddr)) { + sockaddr_storage_ipv6_to_ipv4(ps.localaddr); d.localAddr = sockaddr_storage_iptostring(ps.localaddr); d.localPort = sockaddr_storage_port(ps.localaddr); } @@ -344,8 +345,9 @@ bool p3Peers::getPeerDetails(const RsPeerId& id, RsPeerDetails &d) d.localPort = 0; } - if (sockaddr_storage_ipv6_to_ipv4(ps.serveraddr)) + if(!sockaddr_storage_isnull(ps.serveraddr)) { + sockaddr_storage_ipv6_to_ipv4(ps.serveraddr); d.extAddr = sockaddr_storage_iptostring(ps.serveraddr); d.extPort = sockaddr_storage_port(ps.serveraddr); } @@ -417,6 +419,7 @@ bool p3Peers::getPeerDetails(const RsPeerId& id, RsPeerDetails &d) if (pcs.state & RS_PEER_S_CONNECTED) { + sockaddr_storage_ipv6_to_ipv4(pcs.connectaddr); d.connectAddr = sockaddr_storage_iptostring(pcs.connectaddr); d.connectPort = sockaddr_storage_port(pcs.connectaddr); }