Handle local address changes for servers

This commit is contained in:
Simon Walton 2019-06-14 16:51:59 -07:00
parent 0804ffe5eb
commit cfcea359b2
2 changed files with 7 additions and 1 deletions

View file

@ -739,6 +739,10 @@ void DomainServer::setupNodeListAndAssignments() {
connect(nodeList.data(), &LimitedNodeList::nodeAdded, this, &DomainServer::nodeAdded);
connect(nodeList.data(), &LimitedNodeList::nodeKilled, this, &DomainServer::nodeKilled);
connect(nodeList.data(), &LimitedNodeList::localSockAddrChanged, this,
[this](const HifiSockAddr& localSockAddr) {
DependencyManager::get<LimitedNodeList>()->putLocalPortIntoSharedMemory(DOMAIN_SERVER_LOCAL_PORT_SMEM_KEY, this, localSockAddr.getPort());
});
// register as the packet receiver for the types we want
PacketReceiver& packetReceiver = nodeList->getPacketReceiver();

View file

@ -1237,16 +1237,18 @@ void LimitedNodeList::setLocalSocket(const HifiSockAddr& sockAddr) {
if (_localSockAddr.isNull()) {
qCInfo(networking) << "Local socket is" << sockAddr;
_localSockAddr = sockAddr;
} else {
qCInfo(networking) << "Local socket has changed from" << _localSockAddr << "to" << sockAddr;
_localSockAddr = sockAddr;
if (_hasTCPCheckedLocalSocket) { // Force a port change for NAT:
reset();
_nodeSocket.rebind(0);
_localSockAddr.setPort(_nodeSocket.localPort());
qCInfo(networking) << "Local port changed to" << _localSockAddr.getPort();
}
}
_localSockAddr = sockAddr;
emit localSockAddrChanged(_localSockAddr);
}
}