diff --git a/libretroshare/src/pqi/p3netmgr.cc b/libretroshare/src/pqi/p3netmgr.cc index 7ca1713f7..3381705cd 100644 --- a/libretroshare/src/pqi/p3netmgr.cc +++ b/libretroshare/src/pqi/p3netmgr.cc @@ -987,8 +987,8 @@ bool p3NetMgrIMPL::checkNetAddress() bool addrChanged = false; bool validAddr = false; - struct sockaddr_storage prefAddr; - struct sockaddr_storage oldAddr; + sockaddr_storage prefAddr; + sockaddr_storage oldAddr; if (mNetMode & RS_NET_MODE_TRY_LOOPBACK) { @@ -996,7 +996,7 @@ bool p3NetMgrIMPL::checkNetAddress() std::cerr << "p3NetMgrIMPL::checkNetAddress() LOOPBACK ... forcing to 127.0.0.1"; std::cerr << std::endl; #endif - sockaddr_storage_ipv4_aton(prefAddr, "127.0.0.1"); + sockaddr_storage_ipv4_aton(prefAddr, "127.0.0.1"); validAddr = true; } else @@ -1012,7 +1012,7 @@ bool p3NetMgrIMPL::checkNetAddress() std::vector addrs; if (getLocalAddresses(addrs)) { - for (auto it = addrs.begin(); it!=addrs.end(); ++it) + for (auto it = addrs.begin(); it != addrs.end(); ++it) { sockaddr_storage& addr(*it); if( sockaddr_storage_isValidNet(addr) && @@ -1060,8 +1060,8 @@ bool p3NetMgrIMPL::checkNetAddress() { RS_STACK_MUTEX(mNetMtx); - - oldAddr = mLocalAddr; + + sockaddr_storage_copy(mLocalAddr, oldAddr); addrChanged = !sockaddr_storage_sameip(prefAddr, mLocalAddr); #ifdef NETMGR_DEBUG_TICK @@ -1087,7 +1087,7 @@ bool p3NetMgrIMPL::checkNetAddress() // update address. sockaddr_storage_copyip(mLocalAddr, prefAddr); - mNetFlags.mLocalAddr = mLocalAddr; + sockaddr_storage_copy(mLocalAddr, mNetFlags.mLocalAddr); if(sockaddr_storage_isLoopbackNet(mLocalAddr)) { @@ -1137,6 +1137,7 @@ bool p3NetMgrIMPL::checkNetAddress() if (sockaddr_storage_sameip(mLocalAddr, mExtAddr)) { sockaddr_storage_setport(mExtAddr, sockaddr_storage_port(mLocalAddr)); + addrChanged = true; } // ensure that address family is set, otherwise windows Barfs. diff --git a/libretroshare/src/pqi/p3peermgr.cc b/libretroshare/src/pqi/p3peermgr.cc index ba3ecbf84..d1e9e4e97 100644 --- a/libretroshare/src/pqi/p3peermgr.cc +++ b/libretroshare/src/pqi/p3peermgr.cc @@ -1239,11 +1239,11 @@ bool p3PeerMgrIMPL::UpdateOwnAddress( const sockaddr_storage& pLocalAddr, sockaddr_storage_copy(pExtAddr, extAddr); sockaddr_storage_ipv6_to_ipv4(extAddr); -#ifdef PEER_DEBUG +//#ifdef PEER_DEBUG std::cerr << "p3PeerMgrIMPL::UpdateOwnAddress(" << sockaddr_storage_tostring(localAddr) << ", " << sockaddr_storage_tostring(extAddr) << ")" << std::endl; -#endif +//#endif if( rsBanList && !rsBanList->isAddressAccepted(localAddr, @@ -1428,21 +1428,25 @@ bool p3PeerMgrIMPL::setLocalAddress(const RsPeerId &id, const struct sockaddr return changed; } -bool p3PeerMgrIMPL::setExtAddress(const RsPeerId &id, const struct sockaddr_storage &addr) +bool p3PeerMgrIMPL::setExtAddress( const RsPeerId &id, + const sockaddr_storage &addr ) { - bool changed = false; - uint32_t check_res = 0 ; + bool changed = false; + uint32_t check_res = 0; - if(rsBanList!=NULL && !rsBanList->isAddressAccepted(addr,RSBANLIST_CHECKING_FLAGS_BLACKLIST,&check_res)) - { - std::cerr << "(SS) trying to set external contact address for peer " << id << " to a banned address " << sockaddr_storage_iptostring(addr )<< std::endl; - return false ; - } + if( rsBanList!=NULL && !rsBanList->isAddressAccepted( + addr, RSBANLIST_CHECKING_FLAGS_BLACKLIST, &check_res) ) + { + std::cerr << "(SS) trying to set external contact address for peer " + << id << " to a banned address " + << sockaddr_storage_iptostring(addr) << std::endl; + return false; + } if (id == AuthSSL::getAuthSSL()->OwnId()) { { - RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ + RS_STACK_MUTEX(mPeerMtx); if (!sockaddr_storage_same(mOwnState.serveraddr, addr)) { mOwnState.serveraddr = addr; @@ -1455,7 +1459,7 @@ bool p3PeerMgrIMPL::setExtAddress(const RsPeerId &id, const struct sockaddr_s return changed; } - RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ + RS_STACK_MUTEX(mPeerMtx); /* check if it is a friend */ std::map::iterator it; if (mFriendList.end() == (it = mFriendList.find(id))) @@ -1463,7 +1467,9 @@ bool p3PeerMgrIMPL::setExtAddress(const RsPeerId &id, const struct sockaddr_s if (mOthersList.end() == (it = mOthersList.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::setLocalAddress() cannot add addres " + << "info : peer id not found in friend list id: " << id + << std::endl; #endif return false; } diff --git a/libretroshare/src/pqi/pqissludp.cc b/libretroshare/src/pqi/pqissludp.cc index 8d7e45fd1..dbde145df 100644 --- a/libretroshare/src/pqi/pqissludp.cc +++ b/libretroshare/src/pqi/pqissludp.cc @@ -227,6 +227,15 @@ int pqissludp::Initiate_Connection() return -1; } + if(!sockaddr_storage_ipv6_to_ipv4(remote_addr)) + { + std::cerr << __PRETTY_FUNCTION__ << "Error: remote_addr is not " + << "valid IPv4!" << std::endl; + sockaddr_storage_dump(remote_addr); + print_stacktrace(); + return -EINVAL; + } + mTimeoutTS = time(NULL) + mConnectTimeout; //std::cerr << "Setting Connect Timeout " << mConnectTimeout << " Seconds into Future " << std::endl; //std::cerr << " Connect Period is:" << mConnectPeriod << std::endl; @@ -254,32 +263,22 @@ int pqissludp::Initiate_Connection() struct sockaddr_in proxyaddr; struct sockaddr_in remoteaddr; - bool nonIpV4 = false; - if(!sockaddr_storage_ipv6_to_ipv4(remote_addr)) - { - nonIpV4 = true; - std::cerr << __PRETTY_FUNCTION__ << "Error: remote_addr is not " - << "valid IPv4!" << std::endl; - sockaddr_storage_dump(remote_addr); - } if(!sockaddr_storage_ipv6_to_ipv4(mConnectSrcAddr)) { - nonIpV4 = true; std::cerr << __PRETTY_FUNCTION__ << "Error: mConnectSrcAddr is " << "not valid IPv4!" << std::endl; sockaddr_storage_dump(mConnectSrcAddr); + print_stacktrace(); + return -EINVAL; } if(!sockaddr_storage_ipv6_to_ipv4(mConnectProxyAddr)) { - nonIpV4 = true; std::cerr << __PRETTY_FUNCTION__ << "Error: mConnectProxyAddr " << "is not valid IPv4!" << std::endl; sockaddr_storage_dump(mConnectProxyAddr); - } - if(!nonIpV4) - { print_stacktrace(); return -EINVAL; + } struct sockaddr_in *rap = (struct sockaddr_in *) &remote_addr; @@ -301,7 +300,6 @@ int pqissludp::Initiate_Connection() err = tou_connect_via_relay(sockfd, &srcaddr, &proxyaddr, &remoteaddr); } - /*** It seems that the UDP Layer sees x 1.2 the traffic of the SSL layer. * We need to compensate somewhere... we drop the maximum traffic to 75% of limit diff --git a/libretroshare/src/rsserver/p3peers.cc b/libretroshare/src/rsserver/p3peers.cc index 52f6c3dba..c6d686469 100644 --- a/libretroshare/src/rsserver/p3peers.cc +++ b/libretroshare/src/rsserver/p3peers.cc @@ -336,8 +336,8 @@ bool p3Peers::getPeerDetails(const RsPeerId& id, RsPeerDetails &d) 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); + d.localAddr = sockaddr_storage_iptostring(ps.localaddr); + d.localPort = sockaddr_storage_port(ps.localaddr); } else { diff --git a/retroshare-gui/src/gui/settings/ServerPage.cpp b/retroshare-gui/src/gui/settings/ServerPage.cpp index 042a379cb..dcfe29426 100755 --- a/retroshare-gui/src/gui/settings/ServerPage.cpp +++ b/retroshare-gui/src/gui/settings/ServerPage.cpp @@ -846,10 +846,15 @@ void ServerPage::updateStatus() return; } - /* load up configuration from rsPeers */ - RsPeerDetails detail; - if (!rsPeers->getPeerDetails(rsPeers->getOwnId(), detail)) - return; + /* load up configuration from rsPeers */ + RsPeerDetails detail; + if (!rsPeers->getPeerDetails(rsPeers->getOwnId(), detail)) + { + std::cerr << __PRETTY_FUNCTION__ << " getPeerDetails(...) failed!" + << " This is unexpected report to developers please." + << std::endl; + return; + } /* only update if can't edit */ if (!ui.localPort->isEnabled())