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) {
QReadLocker locker(&_nodeMutex);
auto it = std::find_if(std::begin(_nodeHash), std::end(_nodeHash), [&](const UUIDNodePair& pair) {
return pair.second->getActiveSocket() ? (*pair.second->getActiveSocket() == addr) : false;
auto it = std::find_if(std::begin(_nodeHash), std::end(_nodeHash), [&addr](const UUIDNodePair& pair) {
return pair.second->getPublicSocket() == addr
|| pair.second->getLocalSocket() == addr
|| pair.second->getSymmetricSocket() == addr;
});
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,
const QUuid& clientID, const QUuid& peerID) {
auto icePacket = NLPacket::create(packetType);

View file

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

View file

@ -228,13 +228,13 @@ qint64 Socket::writeDatagram(const QByteArray& datagram, const HifiSockAddr& soc
return bytesWritten;
}
Connection* Socket::findOrCreateConnection(const HifiSockAddr& sockAddr) {
Connection* Socket::findOrCreateConnection(const HifiSockAddr& sockAddr, bool filterCreate) {
auto it = _connectionsHash.find(sockAddr);
if (it == _connectionsHash.end()) {
// 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
#ifdef UDT_CONNECTION_DEBUG
qCDebug(networking) << "Socket::findOrCreateConnection refusing to create connection for" << sockAddr
@ -376,7 +376,7 @@ void Socket::readPendingDatagrams() {
controlPacket->setReceiveTime(receiveTime);
// move this control packet to the matching connection, if there is one
auto connection = findOrCreateConnection(senderSockAddr);
auto connection = findOrCreateConnection(senderSockAddr, true);
if (connection) {
connection->processControl(move(controlPacket));
@ -394,7 +394,7 @@ void Socket::readPendingDatagrams() {
if (!_packetFilterOperator || _packetFilterOperator(*packet)) {
if (packet->isReliable()) {
// 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(),
packet->getDataSize(),
@ -409,7 +409,7 @@ void Socket::readPendingDatagrams() {
}
if (packet->isPartOfMessage()) {
auto connection = findOrCreateConnection(senderSockAddr);
auto connection = findOrCreateConnection(senderSockAddr, true);
if (connection) {
connection->queueReceivedMessagePacket(std::move(packet));
}

View file

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