mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-03 22:55:04 -04:00
p3NetMgrIMPL::checkNetAddress() notify if port change
Plus cleanups and proper sockaddr_storage copy
This commit is contained in:
parent
0bf02e2bc3
commit
1ad1fdc7be
4 changed files with 38 additions and 26 deletions
|
@ -987,8 +987,8 @@ bool p3NetMgrIMPL::checkNetAddress()
|
||||||
bool addrChanged = false;
|
bool addrChanged = false;
|
||||||
bool validAddr = false;
|
bool validAddr = false;
|
||||||
|
|
||||||
struct sockaddr_storage prefAddr;
|
sockaddr_storage prefAddr;
|
||||||
struct sockaddr_storage oldAddr;
|
sockaddr_storage oldAddr;
|
||||||
|
|
||||||
if (mNetMode & RS_NET_MODE_TRY_LOOPBACK)
|
if (mNetMode & RS_NET_MODE_TRY_LOOPBACK)
|
||||||
{
|
{
|
||||||
|
@ -1012,7 +1012,7 @@ bool p3NetMgrIMPL::checkNetAddress()
|
||||||
std::vector<sockaddr_storage> addrs;
|
std::vector<sockaddr_storage> addrs;
|
||||||
if (getLocalAddresses(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);
|
sockaddr_storage& addr(*it);
|
||||||
if( sockaddr_storage_isValidNet(addr) &&
|
if( sockaddr_storage_isValidNet(addr) &&
|
||||||
|
@ -1061,7 +1061,7 @@ bool p3NetMgrIMPL::checkNetAddress()
|
||||||
{
|
{
|
||||||
RS_STACK_MUTEX(mNetMtx);
|
RS_STACK_MUTEX(mNetMtx);
|
||||||
|
|
||||||
oldAddr = mLocalAddr;
|
sockaddr_storage_copy(mLocalAddr, oldAddr);
|
||||||
addrChanged = !sockaddr_storage_sameip(prefAddr, mLocalAddr);
|
addrChanged = !sockaddr_storage_sameip(prefAddr, mLocalAddr);
|
||||||
|
|
||||||
#ifdef NETMGR_DEBUG_TICK
|
#ifdef NETMGR_DEBUG_TICK
|
||||||
|
@ -1087,7 +1087,7 @@ bool p3NetMgrIMPL::checkNetAddress()
|
||||||
|
|
||||||
// update address.
|
// update address.
|
||||||
sockaddr_storage_copyip(mLocalAddr, prefAddr);
|
sockaddr_storage_copyip(mLocalAddr, prefAddr);
|
||||||
mNetFlags.mLocalAddr = mLocalAddr;
|
sockaddr_storage_copy(mLocalAddr, mNetFlags.mLocalAddr);
|
||||||
|
|
||||||
if(sockaddr_storage_isLoopbackNet(mLocalAddr))
|
if(sockaddr_storage_isLoopbackNet(mLocalAddr))
|
||||||
{
|
{
|
||||||
|
@ -1137,6 +1137,7 @@ bool p3NetMgrIMPL::checkNetAddress()
|
||||||
if (sockaddr_storage_sameip(mLocalAddr, mExtAddr))
|
if (sockaddr_storage_sameip(mLocalAddr, mExtAddr))
|
||||||
{
|
{
|
||||||
sockaddr_storage_setport(mExtAddr, sockaddr_storage_port(mLocalAddr));
|
sockaddr_storage_setport(mExtAddr, sockaddr_storage_port(mLocalAddr));
|
||||||
|
addrChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensure that address family is set, otherwise windows Barfs.
|
// ensure that address family is set, otherwise windows Barfs.
|
||||||
|
|
|
@ -1239,11 +1239,11 @@ bool p3PeerMgrIMPL::UpdateOwnAddress( const sockaddr_storage& pLocalAddr,
|
||||||
sockaddr_storage_copy(pExtAddr, extAddr);
|
sockaddr_storage_copy(pExtAddr, extAddr);
|
||||||
sockaddr_storage_ipv6_to_ipv4(extAddr);
|
sockaddr_storage_ipv6_to_ipv4(extAddr);
|
||||||
|
|
||||||
#ifdef PEER_DEBUG
|
//#ifdef PEER_DEBUG
|
||||||
std::cerr << "p3PeerMgrIMPL::UpdateOwnAddress("
|
std::cerr << "p3PeerMgrIMPL::UpdateOwnAddress("
|
||||||
<< sockaddr_storage_tostring(localAddr) << ", "
|
<< sockaddr_storage_tostring(localAddr) << ", "
|
||||||
<< sockaddr_storage_tostring(extAddr) << ")" << std::endl;
|
<< sockaddr_storage_tostring(extAddr) << ")" << std::endl;
|
||||||
#endif
|
//#endif
|
||||||
|
|
||||||
if( rsBanList &&
|
if( rsBanList &&
|
||||||
!rsBanList->isAddressAccepted(localAddr,
|
!rsBanList->isAddressAccepted(localAddr,
|
||||||
|
@ -1428,21 +1428,25 @@ bool p3PeerMgrIMPL::setLocalAddress(const RsPeerId &id, const struct sockaddr
|
||||||
return changed;
|
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;
|
bool changed = false;
|
||||||
uint32_t check_res = 0 ;
|
uint32_t check_res = 0;
|
||||||
|
|
||||||
if(rsBanList!=NULL && !rsBanList->isAddressAccepted(addr,RSBANLIST_CHECKING_FLAGS_BLACKLIST,&check_res))
|
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;
|
std::cerr << "(SS) trying to set external contact address for peer "
|
||||||
return false ;
|
<< id << " to a banned address "
|
||||||
|
<< sockaddr_storage_iptostring(addr) << std::endl;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id == AuthSSL::getAuthSSL()->OwnId())
|
if (id == AuthSSL::getAuthSSL()->OwnId())
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
RS_STACK_MUTEX(mPeerMtx);
|
||||||
if (!sockaddr_storage_same(mOwnState.serveraddr, addr))
|
if (!sockaddr_storage_same(mOwnState.serveraddr, addr))
|
||||||
{
|
{
|
||||||
mOwnState.serveraddr = addr;
|
mOwnState.serveraddr = addr;
|
||||||
|
@ -1455,7 +1459,7 @@ bool p3PeerMgrIMPL::setExtAddress(const RsPeerId &id, const struct sockaddr_s
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
RS_STACK_MUTEX(mPeerMtx);
|
||||||
/* check if it is a friend */
|
/* check if it is a friend */
|
||||||
std::map<RsPeerId, peerState>::iterator it;
|
std::map<RsPeerId, peerState>::iterator it;
|
||||||
if (mFriendList.end() == (it = mFriendList.find(id)))
|
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)))
|
if (mOthersList.end() == (it = mOthersList.find(id)))
|
||||||
{
|
{
|
||||||
#ifdef PEER_DEBUG
|
#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
|
#endif
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -849,7 +849,12 @@ void ServerPage::updateStatus()
|
||||||
/* load up configuration from rsPeers */
|
/* load up configuration from rsPeers */
|
||||||
RsPeerDetails detail;
|
RsPeerDetails detail;
|
||||||
if (!rsPeers->getPeerDetails(rsPeers->getOwnId(), detail))
|
if (!rsPeers->getPeerDetails(rsPeers->getOwnId(), detail))
|
||||||
|
{
|
||||||
|
std::cerr << __PRETTY_FUNCTION__ << " getPeerDetails(...) failed!"
|
||||||
|
<< " This is unexpected report to developers please."
|
||||||
|
<< std::endl;
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* only update if can't edit */
|
/* only update if can't edit */
|
||||||
if (!ui.localPort->isEnabled())
|
if (!ui.localPort->isEnabled())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue