Merge pull request #14051 from birarda/feat/improve-sock-addr-belongs

consider all node sockets in sockAddrBelongsToNode
This commit is contained in:
Stephen Birarda 2018-10-23 14:21:42 -07:00 committed by GitHub
commit 061f86e550
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 9 deletions

View file

@ -1187,12 +1187,24 @@ void LimitedNodeList::sendPeerQueryToIceServer(const HifiSockAddr& iceServerSock
SharedNodePointer LimitedNodeList::findNodeWithAddr(const HifiSockAddr& addr) { SharedNodePointer LimitedNodeList::findNodeWithAddr(const HifiSockAddr& addr) {
QReadLocker locker(&_nodeMutex); QReadLocker locker(&_nodeMutex);
auto it = std::find_if(std::begin(_nodeHash), std::end(_nodeHash), [&](const UUIDNodePair& pair) { auto it = std::find_if(std::begin(_nodeHash), std::end(_nodeHash), [&addr](const UUIDNodePair& pair) {
return pair.second->getActiveSocket() ? (*pair.second->getActiveSocket() == addr) : false; return pair.second->getPublicSocket() == addr
|| pair.second->getLocalSocket() == addr
|| pair.second->getSymmetricSocket() == addr;
}); });
return (it != std::end(_nodeHash)) ? it->second : SharedNodePointer(); return (it != std::end(_nodeHash)) ? it->second : SharedNodePointer();
} }
bool LimitedNodeList::sockAddrBelongsToNode(const HifiSockAddr& sockAddr) {
QReadLocker locker(&_nodeMutex);
auto it = std::find_if(std::begin(_nodeHash), std::end(_nodeHash), [&sockAddr](const UUIDNodePair& pair) {
return pair.second->getPublicSocket() == sockAddr
|| pair.second->getLocalSocket() == sockAddr
|| pair.second->getSymmetricSocket() == sockAddr;
});
return it != std::end(_nodeHash);
}
void LimitedNodeList::sendPacketToIceServer(PacketType packetType, const HifiSockAddr& iceServerSockAddr, void LimitedNodeList::sendPacketToIceServer(PacketType packetType, const HifiSockAddr& iceServerSockAddr,
const QUuid& clientID, const QUuid& peerID) { const QUuid& clientID, const QUuid& peerID) {
auto icePacket = NLPacket::create(packetType); auto icePacket = NLPacket::create(packetType);

View file

@ -386,7 +386,7 @@ protected:
void sendPacketToIceServer(PacketType packetType, const HifiSockAddr& iceServerSockAddr, const QUuid& clientID, void sendPacketToIceServer(PacketType packetType, const HifiSockAddr& iceServerSockAddr, const QUuid& clientID,
const QUuid& peerRequestID = QUuid()); const QUuid& peerRequestID = QUuid());
bool sockAddrBelongsToNode(const HifiSockAddr& sockAddr) { return findNodeWithAddr(sockAddr) != SharedNodePointer(); } bool sockAddrBelongsToNode(const HifiSockAddr& sockAddr);
NodeHash _nodeHash; NodeHash _nodeHash;
mutable QReadWriteLock _nodeMutex { QReadWriteLock::Recursive }; mutable QReadWriteLock _nodeMutex { QReadWriteLock::Recursive };

View file

@ -228,13 +228,13 @@ qint64 Socket::writeDatagram(const QByteArray& datagram, const HifiSockAddr& soc
return bytesWritten; return bytesWritten;
} }
Connection* Socket::findOrCreateConnection(const HifiSockAddr& sockAddr) { Connection* Socket::findOrCreateConnection(const HifiSockAddr& sockAddr, bool filterCreate) {
auto it = _connectionsHash.find(sockAddr); auto it = _connectionsHash.find(sockAddr);
if (it == _connectionsHash.end()) { if (it == _connectionsHash.end()) {
// we did not have a matching connection, time to see if we should make one // we did not have a matching connection, time to see if we should make one
if (_connectionCreationFilterOperator && !_connectionCreationFilterOperator(sockAddr)) { if (filterCreate && _connectionCreationFilterOperator && !_connectionCreationFilterOperator(sockAddr)) {
// the connection creation filter did not allow us to create a new connection // the connection creation filter did not allow us to create a new connection
#ifdef UDT_CONNECTION_DEBUG #ifdef UDT_CONNECTION_DEBUG
qCDebug(networking) << "Socket::findOrCreateConnection refusing to create connection for" << sockAddr qCDebug(networking) << "Socket::findOrCreateConnection refusing to create connection for" << sockAddr
@ -376,7 +376,7 @@ void Socket::readPendingDatagrams() {
controlPacket->setReceiveTime(receiveTime); controlPacket->setReceiveTime(receiveTime);
// move this control packet to the matching connection, if there is one // move this control packet to the matching connection, if there is one
auto connection = findOrCreateConnection(senderSockAddr); auto connection = findOrCreateConnection(senderSockAddr, true);
if (connection) { if (connection) {
connection->processControl(move(controlPacket)); connection->processControl(move(controlPacket));
@ -394,7 +394,7 @@ void Socket::readPendingDatagrams() {
if (!_packetFilterOperator || _packetFilterOperator(*packet)) { if (!_packetFilterOperator || _packetFilterOperator(*packet)) {
if (packet->isReliable()) { if (packet->isReliable()) {
// if this was a reliable packet then signal the matching connection with the sequence number // if this was a reliable packet then signal the matching connection with the sequence number
auto connection = findOrCreateConnection(senderSockAddr); auto connection = findOrCreateConnection(senderSockAddr, true);
if (!connection || !connection->processReceivedSequenceNumber(packet->getSequenceNumber(), if (!connection || !connection->processReceivedSequenceNumber(packet->getSequenceNumber(),
packet->getDataSize(), packet->getDataSize(),
@ -409,7 +409,7 @@ void Socket::readPendingDatagrams() {
} }
if (packet->isPartOfMessage()) { if (packet->isPartOfMessage()) {
auto connection = findOrCreateConnection(senderSockAddr); auto connection = findOrCreateConnection(senderSockAddr, true);
if (connection) { if (connection) {
connection->queueReceivedMessagePacket(std::move(packet)); connection->queueReceivedMessagePacket(std::move(packet));
} }

View file

@ -109,7 +109,7 @@ private slots:
private: private:
void setSystemBufferSizes(); void setSystemBufferSizes();
Connection* findOrCreateConnection(const HifiSockAddr& sockAddr); Connection* findOrCreateConnection(const HifiSockAddr& sockAddr, bool filterCreation = false);
bool socketMatchesNodeOrDomain(const HifiSockAddr& sockAddr); bool socketMatchesNodeOrDomain(const HifiSockAddr& sockAddr);
// privatized methods used by UDTTest - they are private since they must be called on the Socket thread // privatized methods used by UDTTest - they are private since they must be called on the Socket thread