diff --git a/assignment-client/src/AssignmentClient.cpp b/assignment-client/src/AssignmentClient.cpp index adc7f5e3c5..298eea00d0 100644 --- a/assignment-client/src/AssignmentClient.cpp +++ b/assignment-client/src/AssignmentClient.cpp @@ -4,6 +4,7 @@ // // Created by Stephen Birarda on 11/25/2013. // Copyright 2013 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -82,7 +83,7 @@ AssignmentClient::AssignmentClient(Assignment::Type requestAssignmentType, QStri _assignmentServerHostname = assignmentServerHostname; } - _assignmentServerSocket = HifiSockAddr(_assignmentServerHostname, assignmentServerPort, true); + _assignmentServerSocket = SockAddr(_assignmentServerHostname, assignmentServerPort, true); if (_assignmentServerSocket.isNull()) { qCCritical(assignment_client) << "PAGE: Couldn't resolve domain server address" << _assignmentServerHostname; } @@ -110,7 +111,7 @@ AssignmentClient::AssignmentClient(Assignment::Type requestAssignmentType, QStri // did we get an assignment-client monitor port? if (assignmentMonitorPort > 0) { - _assignmentClientMonitorSocket = HifiSockAddr(DEFAULT_ASSIGNMENT_CLIENT_MONITOR_HOSTNAME, assignmentMonitorPort); + _assignmentClientMonitorSocket = SockAddr(DEFAULT_ASSIGNMENT_CLIENT_MONITOR_HOSTNAME, assignmentMonitorPort); _assignmentClientMonitorSocket.setObjectName("AssignmentClientMonitor"); qCDebug(assignment_client) << "Assignment-client monitor socket is" << _assignmentClientMonitorSocket; @@ -269,7 +270,7 @@ void AssignmentClient::handleCreateAssignmentPacket(QSharedPointer message) { - const HifiSockAddr& senderSockAddr = message->getSenderSockAddr(); + const SockAddr& senderSockAddr = message->getSenderSockAddr(); if (senderSockAddr.getAddress() == QHostAddress::LocalHost || senderSockAddr.getAddress() == QHostAddress::LocalHostIPv6) { diff --git a/assignment-client/src/AssignmentClient.h b/assignment-client/src/AssignmentClient.h index 28464bc222..c70baf11fd 100644 --- a/assignment-client/src/AssignmentClient.h +++ b/assignment-client/src/AssignmentClient.h @@ -4,6 +4,7 @@ // // Created by Stephen Birarda on 11/25/2013. // Copyright 2013 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -49,13 +50,13 @@ private: QPointer _currentAssignment; bool _isAssigned { false }; QString _assignmentServerHostname; - HifiSockAddr _assignmentServerSocket; + SockAddr _assignmentServerSocket; QTimer _requestTimer; // timer for requesting and assignment QTimer _statsTimerACM; // timer for sending stats to assignment client monitor QUuid _childAssignmentUUID = QUuid::createUuid(); protected: - HifiSockAddr _assignmentClientMonitorSocket; + SockAddr _assignmentClientMonitorSocket; }; #endif // hifi_AssignmentClient_h diff --git a/assignment-client/src/AssignmentClientMonitor.cpp b/assignment-client/src/AssignmentClientMonitor.cpp index 68c0dfc9fd..221a922a4b 100644 --- a/assignment-client/src/AssignmentClientMonitor.cpp +++ b/assignment-client/src/AssignmentClientMonitor.cpp @@ -4,6 +4,7 @@ // // Created by Stephen Birarda on 1/10/2014. // Copyright 2014 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -331,7 +332,7 @@ void AssignmentClientMonitor::handleChildStatusPacket(QSharedPointer(); SharedNodePointer matchingNode = nodeList->nodeWithUUID(senderID); - const HifiSockAddr& senderSockAddr = message->getSenderSockAddr(); + const SockAddr& senderSockAddr = message->getSenderSockAddr(); AssignmentClientChildData* childData = nullptr; diff --git a/assignment-client/src/avatars/AvatarMixer.cpp b/assignment-client/src/avatars/AvatarMixer.cpp index 27b7d0d302..55decb90fb 100644 --- a/assignment-client/src/avatars/AvatarMixer.cpp +++ b/assignment-client/src/avatars/AvatarMixer.cpp @@ -4,6 +4,7 @@ // // Created by Stephen Birarda on 9/5/13. // Copyright 2013 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -113,7 +114,7 @@ AvatarMixer::AvatarMixer(ReceivedMessage& message) : }); } -SharedNodePointer addOrUpdateReplicatedNode(const QUuid& nodeID, const HifiSockAddr& senderSockAddr) { +SharedNodePointer addOrUpdateReplicatedNode(const QUuid& nodeID, const SockAddr& senderSockAddr) { auto replicatedNode = DependencyManager::get()->addOrUpdateNode(nodeID, NodeType::Agent, senderSockAddr, senderSockAddr, @@ -976,7 +977,7 @@ void AvatarMixer::domainSettingsRequestComplete() { start(); } -void AvatarMixer::handlePacketVersionMismatch(PacketType type, const HifiSockAddr& senderSockAddr, const QUuid& senderUUID) { +void AvatarMixer::handlePacketVersionMismatch(PacketType type, const SockAddr& senderSockAddr, const QUuid& senderUUID) { // if this client is using packet versions we don't expect. if ((type == PacketTypeEnum::Value::AvatarIdentity || type == PacketTypeEnum::Value::AvatarData) && !senderUUID.isNull()) { // Echo an empty AvatarData packet back to that client. diff --git a/assignment-client/src/avatars/AvatarMixer.h b/assignment-client/src/avatars/AvatarMixer.h index 10dff5e8a4..1a19a61bd2 100644 --- a/assignment-client/src/avatars/AvatarMixer.h +++ b/assignment-client/src/avatars/AvatarMixer.h @@ -4,6 +4,7 @@ // // Created by Stephen Birarda on 9/5/13. // Copyright 2013 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // The avatar mixer receives head, hand and positional data from all connected // nodes, and broadcasts that data back to them, every BROADCAST_INTERVAL ms. @@ -63,7 +64,7 @@ private slots: void handleReplicatedPacket(QSharedPointer message); void handleReplicatedBulkAvatarPacket(QSharedPointer message); void domainSettingsRequestComplete(); - void handlePacketVersionMismatch(PacketType type, const HifiSockAddr& senderSockAddr, const QUuid& senderUUID); + void handlePacketVersionMismatch(PacketType type, const SockAddr& senderSockAddr, const QUuid& senderUUID); void handleOctreePacket(QSharedPointer message, SharedNodePointer senderNode); void start(); diff --git a/domain-server/src/DomainGatekeeper.cpp b/domain-server/src/DomainGatekeeper.cpp index 035caaa328..d55a00dcf1 100644 --- a/domain-server/src/DomainGatekeeper.cpp +++ b/domain-server/src/DomainGatekeeper.cpp @@ -357,7 +357,7 @@ void DomainGatekeeper::updateNodePermissions() { } else { // at this point we don't have a sending socket for packets from this node - assume it is the active socket // or the public socket if we haven't activated a socket for the node yet - HifiSockAddr connectingAddr = node->getActiveSocket() ? *node->getActiveSocket() : node->getPublicSocket(); + SockAddr connectingAddr = node->getActiveSocket() ? *node->getActiveSocket() : node->getPublicSocket(); QString hardwareAddress; QUuid machineFingerprint; @@ -651,7 +651,7 @@ SharedNodePointer DomainGatekeeper::processAgentConnectRequest(const NodeConnect } SharedNodePointer DomainGatekeeper::addVerifiedNodeFromConnectRequest(const NodeConnectionData& nodeConnection) { - HifiSockAddr discoveredSocket = nodeConnection.senderSockAddr; + SockAddr discoveredSocket = nodeConnection.senderSockAddr; SharedNetworkPeer connectedPeer = _icePeers.value(nodeConnection.connectUUID); if (connectedPeer && connectedPeer->getActiveSocket()) { @@ -690,7 +690,7 @@ void DomainGatekeeper::cleanupICEPeerForNode(const QUuid& nodeID) { bool DomainGatekeeper::verifyUserSignature(const QString& username, const QByteArray& usernameSignature, - const HifiSockAddr& senderSockAddr) { + const SockAddr& senderSockAddr) { // it's possible this user can be allowed to connect, but we need to check their username signature auto lowerUsername = username.toLower(); KeyFlagPair publicKeyPair = _userPublicKeys.value(lowerUsername); @@ -773,7 +773,7 @@ bool DomainGatekeeper::needToVerifyDomainUserIdentity(const QString& username, c } bool DomainGatekeeper::verifyDomainUserIdentity(const QString& username, const QString& accessToken, - const QString& refreshToken, const HifiSockAddr& senderSockAddr) { + const QString& refreshToken, const SockAddr& senderSockAddr) { if (_verifiedDomainUserIdentities.contains(username) && _verifiedDomainUserIdentities.value(username) == QPair(accessToken, refreshToken)) { return true; @@ -871,7 +871,7 @@ void DomainGatekeeper::publicKeyJSONErrorCallback(QNetworkReply* requestReply) { _inFlightPublicKeyRequests.remove(username); } -void DomainGatekeeper::sendProtocolMismatchConnectionDenial(const HifiSockAddr& senderSockAddr) { +void DomainGatekeeper::sendProtocolMismatchConnectionDenial(const SockAddr& senderSockAddr) { QString protocolVersionError = "Protocol version mismatch - Domain version: " + QCoreApplication::applicationVersion(); qDebug() << "Protocol Version mismatch - denying connection."; @@ -880,7 +880,7 @@ void DomainGatekeeper::sendProtocolMismatchConnectionDenial(const HifiSockAddr& DomainHandler::ConnectionRefusedReason::ProtocolMismatch); } -void DomainGatekeeper::sendConnectionDeniedPacket(const QString& reason, const HifiSockAddr& senderSockAddr, +void DomainGatekeeper::sendConnectionDeniedPacket(const QString& reason, const SockAddr& senderSockAddr, DomainHandler::ConnectionRefusedReason reasonCode, QString extraInfo) { // this is an agent and we've decided we won't let them connect - send them a packet to deny connection @@ -910,7 +910,7 @@ void DomainGatekeeper::sendConnectionDeniedPacket(const QString& reason, const H DependencyManager::get()->sendPacket(std::move(connectionDeniedPacket), senderSockAddr); } -void DomainGatekeeper::sendConnectionTokenPacket(const QString& username, const HifiSockAddr& senderSockAddr) { +void DomainGatekeeper::sendConnectionTokenPacket(const QString& username, const SockAddr& senderSockAddr) { // get the existing connection token or create a new one QUuid& connectionToken = _connectionTokenHash[username.toLower()]; diff --git a/domain-server/src/DomainGatekeeper.h b/domain-server/src/DomainGatekeeper.h index cb42baa7e3..94f760d42e 100644 --- a/domain-server/src/DomainGatekeeper.h +++ b/domain-server/src/DomainGatekeeper.h @@ -47,7 +47,7 @@ public: Node::LocalID findOrCreateLocalID(const QUuid& uuid); - static void sendProtocolMismatchConnectionDenial(const HifiSockAddr& senderSockAddr); + static void sendProtocolMismatchConnectionDenial(const SockAddr& senderSockAddr); public slots: void processConnectRequestPacket(QSharedPointer message); void processICEPingPacket(QSharedPointer message); @@ -90,19 +90,19 @@ private: SharedNodePointer addVerifiedNodeFromConnectRequest(const NodeConnectionData& nodeConnection); bool verifyUserSignature(const QString& username, const QByteArray& usernameSignature, - const HifiSockAddr& senderSockAddr); + const SockAddr& senderSockAddr); bool needToVerifyDomainUserIdentity(const QString& username, const QString& accessToken, const QString& refreshToken); bool verifyDomainUserIdentity(const QString& username, const QString& accessToken, const QString& refreshToken, - const HifiSockAddr& senderSockAddr); + const SockAddr& senderSockAddr); bool isWithinMaxCapacity(); bool shouldAllowConnectionFromNode(const QString& username, const QByteArray& usernameSignature, - const HifiSockAddr& senderSockAddr); + const SockAddr& senderSockAddr); - void sendConnectionTokenPacket(const QString& username, const HifiSockAddr& senderSockAddr); - static void sendConnectionDeniedPacket(const QString& reason, const HifiSockAddr& senderSockAddr, + void sendConnectionTokenPacket(const QString& username, const SockAddr& senderSockAddr); + static void sendConnectionDeniedPacket(const QString& reason, const SockAddr& senderSockAddr, DomainHandler::ConnectionRefusedReason reasonCode = DomainHandler::ConnectionRefusedReason::Unknown, QString extraInfo = QString()); diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index 3acd17f6af..b221c88f6e 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -777,7 +777,7 @@ 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) { + [this](const SockAddr& localSockAddr) { DependencyManager::get()->putLocalPortIntoSharedMemory(DOMAIN_SERVER_LOCAL_PORT_SMEM_KEY, this, localSockAddr.getPort()); }); @@ -1225,7 +1225,7 @@ void DomainServer::handleConnectedNode(SharedNodePointer newNode, quint64 reques broadcastNewNode(newNode); } -void DomainServer::sendDomainListToNode(const SharedNodePointer& node, quint64 requestPacketReceiveTime, const HifiSockAddr &senderSockAddr, bool newConnection) { +void DomainServer::sendDomainListToNode(const SharedNodePointer& node, quint64 requestPacketReceiveTime, const SockAddr &senderSockAddr, bool newConnection) { const int NUM_DOMAIN_LIST_EXTENDED_HEADER_BYTES = NUM_BYTES_RFC4122_UUID + NLPacket::NUM_BYTES_LOCALID + NUM_BYTES_RFC4122_UUID + NLPacket::NUM_BYTES_LOCALID + 4; @@ -1501,7 +1501,7 @@ void DomainServer::transactionJSONCallback(const QJsonObject& data) { } } -QJsonObject jsonForDomainSocketUpdate(const HifiSockAddr& socket) { +QJsonObject jsonForDomainSocketUpdate(const SockAddr& socket) { const QString SOCKET_NETWORK_ADDRESS_KEY = "network_address"; const QString SOCKET_PORT_KEY = "port"; @@ -1512,7 +1512,7 @@ QJsonObject jsonForDomainSocketUpdate(const HifiSockAddr& socket) { return socketObject; } -void DomainServer::performIPAddressPortUpdate(const HifiSockAddr& newPublicSockAddr) { +void DomainServer::performIPAddressPortUpdate(const SockAddr& newPublicSockAddr) { const QString& DOMAIN_SERVER_SETTINGS_KEY = "domain_server"; const QString& publicSocketAddress = newPublicSockAddr.getAddress().toString(); const int publicSocketPort = newPublicSockAddr.getPort(); @@ -1770,7 +1770,7 @@ void DomainServer::sendHeartbeatToIceServer() { QDataStream heartbeatStream(_iceServerHeartbeatPacket.get()); QUuid senderUUID; - HifiSockAddr publicSocket, localSocket; + SockAddr publicSocket, localSocket; heartbeatStream >> senderUUID >> publicSocket >> localSocket; if (senderUUID != limitedNodeList->getSessionUUID() @@ -1928,7 +1928,7 @@ void DomainServer::processNodeJSONStatsPacket(QSharedPointer pa } } -QJsonObject DomainServer::jsonForSocket(const HifiSockAddr& socket) { +QJsonObject DomainServer::jsonForSocket(const SockAddr& socket) { QJsonObject socketJSON; socketJSON["ip"] = socket.getAddress().toString(); @@ -3017,7 +3017,7 @@ static const QString BROADCASTING_SETTINGS_KEY = "broadcasting"; struct ReplicationServerInfo { NodeType_t nodeType; - HifiSockAddr sockAddr; + SockAddr sockAddr; }; ReplicationServerInfo serverInformationFromSettings(QVariantMap serverMap, ReplicationServerDirection direction) { @@ -3038,7 +3038,7 @@ ReplicationServerInfo serverInformationFromSettings(QVariantMap serverMap, Repli serverInfo.nodeType = NodeType::downstreamType(nodeType); } - // read the address and port and construct a HifiSockAddr from them + // read the address and port and construct a SockAddr from them serverInfo.sockAddr = { serverMap[REPLICATION_SERVER_ADDRESS].toString(), (quint16) serverMap[REPLICATION_SERVER_PORT].toString().toInt() @@ -3047,7 +3047,7 @@ ReplicationServerInfo serverInformationFromSettings(QVariantMap serverMap, Repli return serverInfo; } - return { NodeType::Unassigned, HifiSockAddr() }; + return { NodeType::Unassigned, SockAddr() }; } void DomainServer::updateReplicationNodes(ReplicationServerDirection direction) { @@ -3056,7 +3056,7 @@ void DomainServer::updateReplicationNodes(ReplicationServerDirection direction) if (broadcastSettingsVariant.isValid()) { auto nodeList = DependencyManager::get(); - std::vector replicationNodesInSettings; + std::vector replicationNodesInSettings; auto replicationSettings = broadcastSettingsVariant.toMap(); @@ -3066,7 +3066,7 @@ void DomainServer::updateReplicationNodes(ReplicationServerDirection direction) if (replicationSettings.contains(serversKey)) { auto serversSettings = replicationSettings.value(serversKey).toList(); - std::vector knownReplicationNodes; + std::vector knownReplicationNodes; nodeList->eachNode([direction, &knownReplicationNodes](const SharedNodePointer& otherNode) { if ((direction == Upstream && NodeType::isUpstream(otherNode->getType())) || (direction == Downstream && NodeType::isDownstream(otherNode->getType()))) { @@ -3620,7 +3620,7 @@ void DomainServer::randomizeICEServerAddress(bool shouldTriggerHostLookup) { indexToTry = distribution(generator); } - _iceServerSocket = HifiSockAddr { candidateICEAddresses[indexToTry], ICE_SERVER_DEFAULT_PORT }; + _iceServerSocket = SockAddr { candidateICEAddresses[indexToTry], ICE_SERVER_DEFAULT_PORT }; qCInfo(domain_server_ice) << "Set candidate ice-server socket to" << _iceServerSocket; // clear our number of hearbeat denials, this should be re-set on ice-server change diff --git a/domain-server/src/DomainServer.h b/domain-server/src/DomainServer.h index 11d04cb255..deb204de1c 100644 --- a/domain-server/src/DomainServer.h +++ b/domain-server/src/DomainServer.h @@ -113,7 +113,7 @@ private slots: void setupPendingAssignmentCredits(); void sendPendingTransactionsToServer(); - void performIPAddressPortUpdate(const HifiSockAddr& newPublicSockAddr); + void performIPAddressPortUpdate(const SockAddr& newPublicSockAddr); void sendHeartbeatToMetaverse() { sendHeartbeatToMetaverse(QString(), int()); } void sendHeartbeatToIceServer(); void nodePingMonitor(); @@ -186,7 +186,7 @@ private: void handleKillNode(SharedNodePointer nodeToKill); void broadcastNodeDisconnect(const SharedNodePointer& disconnnectedNode); - void sendDomainListToNode(const SharedNodePointer& node, quint64 requestPacketReceiveTime, const HifiSockAddr& senderSockAddr, bool newConnection); + void sendDomainListToNode(const SharedNodePointer& node, quint64 requestPacketReceiveTime, const SockAddr& senderSockAddr, bool newConnection); bool isInInterestSet(const SharedNodePointer& nodeA, const SharedNodePointer& nodeB); @@ -212,7 +212,7 @@ private: QNetworkReply* profileRequestGivenTokenReply(QNetworkReply* tokenReply); Headers setupCookieHeadersFromProfileReply(QNetworkReply* profileReply); - QJsonObject jsonForSocket(const HifiSockAddr& socket); + QJsonObject jsonForSocket(const SockAddr& socket); QJsonObject jsonObjectForNode(const SharedNodePointer& node); bool shouldReplicateNode(const Node& node); @@ -270,7 +270,7 @@ private: DomainServerSettingsManager _settingsManager; - HifiSockAddr _iceServerSocket; + SockAddr _iceServerSocket; std::unique_ptr _iceServerHeartbeatPacket; // These will be parented to this, they are not dangling diff --git a/domain-server/src/DomainServerNodeData.h b/domain-server/src/DomainServerNodeData.h index 370886cbce..0a2e2775e2 100644 --- a/domain-server/src/DomainServerNodeData.h +++ b/domain-server/src/DomainServerNodeData.h @@ -4,6 +4,7 @@ // // Created by Stephen Birarda on 2/6/2014. // Copyright 2014 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -17,7 +18,7 @@ #include #include -#include +#include #include #include #include @@ -41,8 +42,8 @@ public: QElapsedTimer& getPaymentIntervalTimer() { return _paymentIntervalTimer; } - void setSendingSockAddr(const HifiSockAddr& sendingSockAddr) { _sendingSockAddr = sendingSockAddr; } - const HifiSockAddr& getSendingSockAddr() { return _sendingSockAddr; } + void setSendingSockAddr(const SockAddr& sendingSockAddr) { _sendingSockAddr = sendingSockAddr; } + const SockAddr& getSendingSockAddr() { return _sendingSockAddr; } void setIsAuthenticated(bool isAuthenticated) { _isAuthenticated = isAuthenticated; } bool isAuthenticated() const { return _isAuthenticated; } @@ -90,7 +91,7 @@ private: QJsonObject _statsJSONObject; static StringPairHash _overrideHash; - HifiSockAddr _sendingSockAddr; + SockAddr _sendingSockAddr; bool _isAuthenticated = true; NodeSet _nodeInterestSet; QString _nodeVersion; diff --git a/domain-server/src/NodeConnectionData.cpp b/domain-server/src/NodeConnectionData.cpp index 5419014622..1ef8ebf6a9 100644 --- a/domain-server/src/NodeConnectionData.cpp +++ b/domain-server/src/NodeConnectionData.cpp @@ -4,6 +4,7 @@ // // Created by Stephen Birarda on 2015-08-24. // Copyright 2015 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -13,7 +14,7 @@ #include -NodeConnectionData NodeConnectionData::fromDataStream(QDataStream& dataStream, const HifiSockAddr& senderSockAddr, +NodeConnectionData NodeConnectionData::fromDataStream(QDataStream& dataStream, const SockAddr& senderSockAddr, bool isConnectRequest) { NodeConnectionData newHeader; diff --git a/domain-server/src/NodeConnectionData.h b/domain-server/src/NodeConnectionData.h index 3833f5afd3..5976f07787 100644 --- a/domain-server/src/NodeConnectionData.h +++ b/domain-server/src/NodeConnectionData.h @@ -4,6 +4,7 @@ // // Created by Stephen Birarda on 2015-08-24. // Copyright 2015 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -18,15 +19,15 @@ class NodeConnectionData { public: - static NodeConnectionData fromDataStream(QDataStream& dataStream, const HifiSockAddr& senderSockAddr, + static NodeConnectionData fromDataStream(QDataStream& dataStream, const SockAddr& senderSockAddr, bool isConnectRequest = true); QUuid connectUUID; quint64 lastPingTimestamp{ 0 }; // client-side send time of last connect/domain list request NodeType_t nodeType; - HifiSockAddr publicSockAddr; - HifiSockAddr localSockAddr; - HifiSockAddr senderSockAddr; + SockAddr publicSockAddr; + SockAddr localSockAddr; + SockAddr senderSockAddr; QList interestList; QString placeName; QString hardwareAddress; diff --git a/ice-server/src/IceServer.cpp b/ice-server/src/IceServer.cpp index a8e50d31a9..d42c0a4e2a 100644 --- a/ice-server/src/IceServer.cpp +++ b/ice-server/src/IceServer.cpp @@ -4,6 +4,7 @@ // // Created by Stephen Birarda on 2014-10-01. // Copyright 2014 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -97,7 +98,7 @@ void IceServer::processPacket(std::unique_ptr packet) { heartbeatStream >> senderUUID; // pull the public and private sock addrs for this peer - HifiSockAddr publicSocket, localSocket; + SockAddr publicSocket, localSocket; heartbeatStream >> publicSocket >> localSocket; // check if this node also included a UUID that they would like to connect to @@ -129,7 +130,7 @@ SharedNetworkPeer IceServer::addOrUpdateHeartbeatingPeer(NLPacket& packet) { // pull the UUID, public and private sock addrs for this peer QUuid senderUUID; - HifiSockAddr publicSocket, localSocket; + SockAddr publicSocket, localSocket; QByteArray signature; QDataStream heartbeatStream(&packet); @@ -288,7 +289,7 @@ void IceServer::publicKeyReplyFinished(QNetworkReply* reply) { reply->deleteLater(); } -void IceServer::sendPeerInformationPacket(const NetworkPeer& peer, const HifiSockAddr* destinationSockAddr) { +void IceServer::sendPeerInformationPacket(const NetworkPeer& peer, const SockAddr* destinationSockAddr) { auto peerPacket = NLPacket::create(PacketType::ICEServerPeerInformation); // get the byte array for this peer diff --git a/ice-server/src/IceServer.h b/ice-server/src/IceServer.h index 2aa9a875a7..e68115f7ef 100644 --- a/ice-server/src/IceServer.h +++ b/ice-server/src/IceServer.h @@ -4,6 +4,7 @@ // // Created by Stephen Birarda on 2014-10-01. // Copyright 2014 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -40,7 +41,7 @@ private: void processPacket(std::unique_ptr packet); SharedNetworkPeer addOrUpdateHeartbeatingPeer(NLPacket& incomingPacket); - void sendPeerInformationPacket(const NetworkPeer& peer, const HifiSockAddr* destinationSockAddr); + void sendPeerInformationPacket(const NetworkPeer& peer, const SockAddr* destinationSockAddr); bool isVerifiedHeartbeat(const QUuid& domainID, const QByteArray& plaintext, const QByteArray& signature); void requestDomainPublicKey(const QUuid& domainID); diff --git a/libraries/audio-client/src/AudioClient.h b/libraries/audio-client/src/AudioClient.h index a5de9bd4ca..5e753fbef8 100644 --- a/libraries/audio-client/src/AudioClient.h +++ b/libraries/audio-client/src/AudioClient.h @@ -4,6 +4,7 @@ // // Created by Stephen Birarda on 1/22/13. // Copyright 2013 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -33,7 +34,7 @@ #include #include -#include +#include #include #include #include diff --git a/libraries/networking/src/DomainHandler.cpp b/libraries/networking/src/DomainHandler.cpp index 5a1d8fb4a0..4291c1eda7 100644 --- a/libraries/networking/src/DomainHandler.cpp +++ b/libraries/networking/src/DomainHandler.cpp @@ -26,7 +26,7 @@ #include "AddressManager.h" #include "Assignment.h" #include "DomainAccountManager.h" -#include "HifiSockAddr.h" +#include "SockAddr.h" #include "NodeList.h" #include "udt/Packet.h" #include "udt/PacketHeaders.h" @@ -37,7 +37,7 @@ DomainHandler::DomainHandler(QObject* parent) : QObject(parent), - _sockAddr(HifiSockAddr(QHostAddress::Null, DEFAULT_DOMAIN_SERVER_PORT)), + _sockAddr(SockAddr(QHostAddress::Null, DEFAULT_DOMAIN_SERVER_PORT)), _icePeer(this), _settingsTimer(this), _apiRefreshTimer(this) @@ -133,7 +133,7 @@ void DomainHandler::hardReset(QString reason) { qCDebug(networking) << "Hard reset in NodeList DomainHandler."; _pendingDomainID = QUuid(); - _iceServerSockAddr = HifiSockAddr(); + _iceServerSockAddr = SockAddr(); _sockAddr.clear(); _domainURL = QUrl(); @@ -170,7 +170,7 @@ void DomainHandler::setErrorDomainURL(const QUrl& url) { return; } -void DomainHandler::setSockAddr(const HifiSockAddr& sockAddr, const QString& hostname) { +void DomainHandler::setSockAddr(const SockAddr& sockAddr, const QString& hostname) { if (_sockAddr != sockAddr) { // we should reset on a sockAddr change hardReset("Changing domain sockAddr"); @@ -280,9 +280,9 @@ void DomainHandler::setIceServerHostnameAndID(const QString& iceServerHostname, _pendingDomainID = id; - HifiSockAddr* replaceableSockAddr = &_iceServerSockAddr; - replaceableSockAddr->~HifiSockAddr(); - replaceableSockAddr = new (replaceableSockAddr) HifiSockAddr(iceServerHostname, ICE_SERVER_DEFAULT_PORT); + SockAddr* replaceableSockAddr = &_iceServerSockAddr; + replaceableSockAddr->~SockAddr(); + replaceableSockAddr = new (replaceableSockAddr) SockAddr(iceServerHostname, ICE_SERVER_DEFAULT_PORT); _iceServerSockAddr.setObjectName("IceServer"); auto nodeList = DependencyManager::get(); @@ -291,7 +291,7 @@ void DomainHandler::setIceServerHostnameAndID(const QString& iceServerHostname, if (_iceServerSockAddr.getAddress().isNull()) { // connect to lookup completed for ice-server socket so we can request a heartbeat once hostname is looked up - connect(&_iceServerSockAddr, &HifiSockAddr::lookupCompleted, this, &DomainHandler::completedIceServerHostnameLookup); + connect(&_iceServerSockAddr, &SockAddr::lookupCompleted, this, &DomainHandler::completedIceServerHostnameLookup); } else { completedIceServerHostnameLookup(); } @@ -458,7 +458,7 @@ void DomainHandler::processSettingsPacketList(QSharedPointer pa } void DomainHandler::processICEPingReplyPacket(QSharedPointer message) { - const HifiSockAddr& senderSockAddr = message->getSenderSockAddr(); + const SockAddr& senderSockAddr = message->getSenderSockAddr(); qCDebug(networking_ice) << "Received reply from domain-server on" << senderSockAddr; if (getIP().isNull()) { diff --git a/libraries/networking/src/DomainHandler.h b/libraries/networking/src/DomainHandler.h index a56d3162bd..95bfb55894 100644 --- a/libraries/networking/src/DomainHandler.h +++ b/libraries/networking/src/DomainHandler.h @@ -25,7 +25,7 @@ #include #include -#include "HifiSockAddr.h" +#include "SockAddr.h" #include "NetworkPeer.h" #include "NLPacket.h" #include "NLPacketList.h" @@ -109,8 +109,8 @@ public: const QHostAddress& getIP() const { return _sockAddr.getAddress(); } void setIPToLocalhost() { _sockAddr.setAddress(QHostAddress(QHostAddress::LocalHost)); } - const HifiSockAddr& getSockAddr() const { return _sockAddr; } - void setSockAddr(const HifiSockAddr& sockAddr, const QString& hostname); + const SockAddr& getSockAddr() const { return _sockAddr; } + void setSockAddr(const SockAddr& sockAddr, const QString& hostname); unsigned short getPort() const { return _sockAddr.getPort(); } void setPort(quint16 port) { _sockAddr.setPort(port); } @@ -126,7 +126,7 @@ public: const QUuid& getICEClientID() const { return _iceClientID; } bool requiresICE() const { return !_iceServerSockAddr.isNull(); } - const HifiSockAddr& getICEServerSockAddr() const { return _iceServerSockAddr; } + const SockAddr& getICEServerSockAddr() const { return _iceServerSockAddr; } NetworkPeer& getICEPeer() { return _icePeer; } void activateICELocalSocket(); void activateICEPublicSocket(); @@ -288,12 +288,12 @@ private: Node::LocalID _localID; QUrl _domainURL; QUrl _errorDomainURL; - HifiSockAddr _sockAddr; + SockAddr _sockAddr; QUuid _assignmentUUID; QUuid _connectionToken; QUuid _pendingDomainID; // ID of domain being connected to, via ICE or direct connection QUuid _iceClientID; - HifiSockAddr _iceServerSockAddr; + SockAddr _iceServerSockAddr; NetworkPeer _icePeer; bool _isConnected { false }; bool _haveAskedConnectWithoutAvatarEntities { false }; diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index 653611ae8c..65e391d467 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -4,6 +4,7 @@ // // Created by Stephen Birarda on 2/15/13. // Copyright 2013 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -33,7 +34,7 @@ #include "AccountManager.h" #include "AssetClient.h" #include "Assignment.h" -#include "HifiSockAddr.h" +#include "SockAddr.h" #include "NetworkLogging.h" #include "udt/Packet.h" #include "HMACAuth.h" @@ -103,7 +104,7 @@ LimitedNodeList::LimitedNodeList(int socketListenPort, int dtlsListenPort) : _nodeSocket.setMessageHandler([this](std::unique_ptr packet) { _packetReceiver->handleVerifiedMessagePacket(std::move(packet)); }); - _nodeSocket.setMessageFailureHandler([this](HifiSockAddr from, + _nodeSocket.setMessageFailureHandler([this](SockAddr from, udt::Packet::MessageNumber messageNumber) { _packetReceiver->handleMessageFailure(from, messageNumber); }); @@ -120,7 +121,7 @@ LimitedNodeList::LimitedNodeList(int socketListenPort, int dtlsListenPort) : if (_stunSockAddr.getAddress().isNull()) { // we don't know the stun server socket yet, add it to unfiltered once known - connect(&_stunSockAddr, &HifiSockAddr::lookupCompleted, this, &LimitedNodeList::addSTUNHandlerToUnfiltered); + connect(&_stunSockAddr, &SockAddr::lookupCompleted, this, &LimitedNodeList::addSTUNHandlerToUnfiltered); } else { // we know the stun server socket, add it to unfiltered now addSTUNHandlerToUnfiltered(); @@ -248,11 +249,11 @@ bool LimitedNodeList::packetVersionMatch(const udt::Packet& packet) { if (headerVersion != versionForPacketType(headerType)) { static QMultiHash sourcedVersionDebugSuppressMap; - static QMultiHash versionDebugSuppressMap; + static QMultiHash versionDebugSuppressMap; bool hasBeenOutput = false; QString senderString; - const HifiSockAddr& senderSockAddr = packet.getSenderSockAddr(); + const SockAddr& senderSockAddr = packet.getSenderSockAddr(); QUuid sourceID; if (PacketTypeEnum::getNonSourcedPackets().contains(headerType)) { @@ -413,7 +414,7 @@ qint64 LimitedNodeList::sendUnreliablePacket(const NLPacket& packet, const Node& return sendUnreliablePacket(packet, *destinationNode.getActiveSocket(), destinationNode.getAuthenticateHash()); } -qint64 LimitedNodeList::sendUnreliablePacket(const NLPacket& packet, const HifiSockAddr& sockAddr, +qint64 LimitedNodeList::sendUnreliablePacket(const NLPacket& packet, const SockAddr& sockAddr, HMACAuth* hmacAuth) { Q_ASSERT(!packet.isPartOfMessage()); Q_ASSERT_X(!packet.isReliable(), "LimitedNodeList::sendUnreliablePacket", @@ -446,7 +447,7 @@ qint64 LimitedNodeList::sendPacket(std::unique_ptr packet, const Node& } } -qint64 LimitedNodeList::sendPacket(std::unique_ptr packet, const HifiSockAddr& sockAddr, +qint64 LimitedNodeList::sendPacket(std::unique_ptr packet, const SockAddr& sockAddr, HMACAuth* hmacAuth) { Q_ASSERT(!packet->isPartOfMessage()); if (packet->isReliable()) { @@ -497,7 +498,7 @@ qint64 LimitedNodeList::sendUnreliableUnorderedPacketList(NLPacketList& packetLi } } -qint64 LimitedNodeList::sendUnreliableUnorderedPacketList(NLPacketList& packetList, const HifiSockAddr& sockAddr, +qint64 LimitedNodeList::sendUnreliableUnorderedPacketList(NLPacketList& packetList, const SockAddr& sockAddr, HMACAuth* hmacAuth) { qint64 bytesSent = 0; @@ -511,7 +512,7 @@ qint64 LimitedNodeList::sendUnreliableUnorderedPacketList(NLPacketList& packetLi return bytesSent; } -qint64 LimitedNodeList::sendPacketList(std::unique_ptr packetList, const HifiSockAddr& sockAddr) { +qint64 LimitedNodeList::sendPacketList(std::unique_ptr packetList, const SockAddr& sockAddr) { // close the last packet in the list packetList->closeCurrentPacket(); @@ -543,7 +544,7 @@ qint64 LimitedNodeList::sendPacketList(std::unique_ptr packetList, } qint64 LimitedNodeList::sendPacket(std::unique_ptr packet, const Node& destinationNode, - const HifiSockAddr& overridenSockAddr) { + const SockAddr& overridenSockAddr) { if (overridenSockAddr.isNull() && !destinationNode.getActiveSocket()) { qCDebug(networking) << "LimitedNodeList::sendPacket called without active socket for node" << destinationNode.getUUID() << ". Not sending."; @@ -675,7 +676,7 @@ void LimitedNodeList::handleNodeKill(const SharedNodePointer& node, ConnectionID } SharedNodePointer LimitedNodeList::addOrUpdateNode(const QUuid& uuid, NodeType_t nodeType, - const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket, + const SockAddr& publicSocket, const SockAddr& localSocket, Node::LocalID localID, bool isReplicated, bool isUpstream, const QUuid& connectionSecret, const NodePermissions& permissions) { auto matchingNode = nodeWithUUID(uuid); @@ -1105,7 +1106,7 @@ void LimitedNodeList::processSTUNResponse(std::unique_ptr packe _publicSockAddr.getAddress().toString().toLocal8Bit().constData(), _publicSockAddr.getPort()); - _publicSockAddr = HifiSockAddr(newPublicAddress, newPublicPort); + _publicSockAddr = SockAddr(newPublicAddress, newPublicPort); if (!_hasCompletedInitialSTUN) { // if we're here we have definitely completed our initial STUN sequence @@ -1133,10 +1134,10 @@ void LimitedNodeList::startSTUNPublicSocketUpdate() { if (_stunSockAddr.getAddress().isNull()) { // if we fail to lookup the socket then timeout the STUN address lookup - connect(&_stunSockAddr, &HifiSockAddr::lookupFailed, this, &LimitedNodeList::possiblyTimeoutSTUNAddressLookup); + connect(&_stunSockAddr, &SockAddr::lookupFailed, this, &LimitedNodeList::possiblyTimeoutSTUNAddressLookup); // immediately send a STUN request once we know the socket - connect(&_stunSockAddr, &HifiSockAddr::lookupCompleted, this, &LimitedNodeList::sendSTUNRequest); + connect(&_stunSockAddr, &SockAddr::lookupCompleted, this, &LimitedNodeList::sendSTUNRequest); // start the initial STUN timer once we know the socket connect(&_stunSockAddr, SIGNAL(lookupCompleted()), _initialSTUNTimer, SLOT(start())); @@ -1186,7 +1187,7 @@ void LimitedNodeList::stopInitialSTUNUpdate(bool success) { qCDebug(networking) << "LimitedNodeList public socket will be set with local port and null QHostAddress."; // reset the public address and port to a null address - _publicSockAddr = HifiSockAddr(QHostAddress(), _nodeSocket.localPort()); + _publicSockAddr = SockAddr(QHostAddress(), _nodeSocket.localPort()); // we have changed the publicSockAddr, so emit our signal emit publicSockAddrChanged(_publicSockAddr); @@ -1213,7 +1214,7 @@ void LimitedNodeList::stopInitialSTUNUpdate(bool success) { void LimitedNodeList::updateLocalSocket() { // when update is called, if the local socket is empty then start with the guessed local socket if (_localSockAddr.isNull()) { - setLocalSocket(HifiSockAddr { getGuessedLocalAddress(), _nodeSocket.localPort() }); + setLocalSocket(SockAddr { getGuessedLocalAddress(), _nodeSocket.localPort() }); } // attempt to use Google's DNS to confirm that local IP @@ -1237,7 +1238,7 @@ void LimitedNodeList::connectedForLocalSocketTest() { auto localHostAddress = localIPTestSocket->localAddress(); if (localHostAddress.protocol() == QAbstractSocket::IPv4Protocol) { - setLocalSocket(HifiSockAddr { localHostAddress, _nodeSocket.localPort() }); + setLocalSocket(SockAddr { localHostAddress, _nodeSocket.localPort() }); _hasTCPCheckedLocalSocket = true; } @@ -1253,7 +1254,7 @@ void LimitedNodeList::errorTestingLocalSocket() { // error connecting to the test socket - if we've never set our local socket using this test socket // then use our possibly updated guessed local address as fallback if (!_hasTCPCheckedLocalSocket) { - setLocalSocket(HifiSockAddr { getGuessedLocalAddress(), _nodeSocket.localPort() }); + setLocalSocket(SockAddr { getGuessedLocalAddress(), _nodeSocket.localPort() }); qCCritical(networking) << "PAGE: Can't connect to Google DNS service via TCP, falling back to guessed local address" << getLocalSockAddr(); } @@ -1262,7 +1263,7 @@ void LimitedNodeList::errorTestingLocalSocket() { } } -void LimitedNodeList::setLocalSocket(const HifiSockAddr& sockAddr) { +void LimitedNodeList::setLocalSocket(const SockAddr& sockAddr) { if (sockAddr.getAddress() != _localSockAddr.getAddress()) { if (_localSockAddr.isNull()) { @@ -1283,12 +1284,12 @@ void LimitedNodeList::setLocalSocket(const HifiSockAddr& sockAddr) { } } -void LimitedNodeList::sendPeerQueryToIceServer(const HifiSockAddr& iceServerSockAddr, const QUuid& clientID, +void LimitedNodeList::sendPeerQueryToIceServer(const SockAddr& iceServerSockAddr, const QUuid& clientID, const QUuid& peerID) { sendPacketToIceServer(PacketType::ICEServerQuery, iceServerSockAddr, clientID, peerID); } -SharedNodePointer LimitedNodeList::findNodeWithAddr(const HifiSockAddr& addr) { +SharedNodePointer LimitedNodeList::findNodeWithAddr(const SockAddr& addr) { QReadLocker locker(&_nodeMutex); auto it = std::find_if(std::begin(_nodeHash), std::end(_nodeHash), [&addr](const UUIDNodePair& pair) { return pair.second->getPublicSocket() == addr @@ -1298,7 +1299,7 @@ SharedNodePointer LimitedNodeList::findNodeWithAddr(const HifiSockAddr& addr) { return (it != std::end(_nodeHash)) ? it->second : SharedNodePointer(); } -bool LimitedNodeList::sockAddrBelongsToNode(const HifiSockAddr& sockAddr) { +bool LimitedNodeList::sockAddrBelongsToNode(const SockAddr& sockAddr) { QReadLocker locker(&_nodeMutex); auto it = std::find_if(std::begin(_nodeHash), std::end(_nodeHash), [&sockAddr](const UUIDNodePair& pair) { return pair.second->getPublicSocket() == sockAddr @@ -1308,7 +1309,7 @@ bool LimitedNodeList::sockAddrBelongsToNode(const HifiSockAddr& sockAddr) { return it != std::end(_nodeHash); } -void LimitedNodeList::sendPacketToIceServer(PacketType packetType, const HifiSockAddr& iceServerSockAddr, +void LimitedNodeList::sendPacketToIceServer(PacketType packetType, const SockAddr& iceServerSockAddr, const QUuid& clientID, const QUuid& peerID) { auto icePacket = NLPacket::create(packetType); @@ -1400,7 +1401,7 @@ void LimitedNodeList::flagTimeForConnectionStep(ConnectionStep connectionStep, q } } -void LimitedNodeList::clientConnectionToSockAddrReset(const HifiSockAddr& sockAddr) { +void LimitedNodeList::clientConnectionToSockAddrReset(const SockAddr& sockAddr) { // for certain reliable channels higher level classes may need to know if the udt::Connection has been reset auto matchingNode = findNodeWithAddr(sockAddr); diff --git a/libraries/networking/src/LimitedNodeList.h b/libraries/networking/src/LimitedNodeList.h index 189f3e1b08..47b333220b 100644 --- a/libraries/networking/src/LimitedNodeList.h +++ b/libraries/networking/src/LimitedNodeList.h @@ -145,26 +145,26 @@ public: virtual bool isDomainServer() const { return true; } virtual QUuid getDomainUUID() const { assert(false); return QUuid(); } virtual Node::LocalID getDomainLocalID() const { assert(false); return Node::NULL_LOCAL_ID; } - virtual HifiSockAddr getDomainSockAddr() const { assert(false); return HifiSockAddr(); } + virtual SockAddr getDomainSockAddr() const { assert(false); return SockAddr(); } // use sendUnreliablePacket to send an unreliable packet (that you do not need to move) // either to a node (via its active socket) or to a manual sockaddr qint64 sendUnreliablePacket(const NLPacket& packet, const Node& destinationNode); - qint64 sendUnreliablePacket(const NLPacket& packet, const HifiSockAddr& sockAddr, HMACAuth* hmacAuth = nullptr); + qint64 sendUnreliablePacket(const NLPacket& packet, const SockAddr& sockAddr, HMACAuth* hmacAuth = nullptr); // use sendPacket to send a moved unreliable or reliable NL packet to a node's active socket or manual sockaddr qint64 sendPacket(std::unique_ptr packet, const Node& destinationNode); - qint64 sendPacket(std::unique_ptr packet, const HifiSockAddr& sockAddr, HMACAuth* hmacAuth = nullptr); + qint64 sendPacket(std::unique_ptr packet, const SockAddr& sockAddr, HMACAuth* hmacAuth = nullptr); // use sendUnreliableUnorderedPacketList to unreliably send separate packets from the packet list // either to a node's active socket or to a manual sockaddr qint64 sendUnreliableUnorderedPacketList(NLPacketList& packetList, const Node& destinationNode); - qint64 sendUnreliableUnorderedPacketList(NLPacketList& packetList, const HifiSockAddr& sockAddr, + qint64 sendUnreliableUnorderedPacketList(NLPacketList& packetList, const SockAddr& sockAddr, HMACAuth* hmacAuth = nullptr); // use sendPacketList to send reliable packet lists (ordered or unordered) to a node's active socket // or to a manual sock addr - qint64 sendPacketList(std::unique_ptr packetList, const HifiSockAddr& sockAddr); + qint64 sendPacketList(std::unique_ptr packetList, const SockAddr& sockAddr); qint64 sendPacketList(std::unique_ptr packetList, const Node& destinationNode); std::function linkedDataCreateCallback; @@ -175,7 +175,7 @@ public: SharedNodePointer nodeWithLocalID(Node::LocalID localID) const; SharedNodePointer addOrUpdateNode(const QUuid& uuid, NodeType_t nodeType, - const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket, + const SockAddr& publicSocket, const SockAddr& localSocket, Node::LocalID localID = Node::NULL_LOCAL_ID, bool isReplicated = false, bool isUpstream = false, const QUuid& connectionSecret = QUuid(), const NodePermissions& permissions = DEFAULT_AGENT_PERMISSIONS); @@ -183,9 +183,9 @@ public: static bool parseSTUNResponse(udt::BasePacket* packet, QHostAddress& newPublicAddress, uint16_t& newPublicPort); bool hasCompletedInitialSTUN() const { return _hasCompletedInitialSTUN; } - const HifiSockAddr& getLocalSockAddr() const { return _localSockAddr; } - const HifiSockAddr& getPublicSockAddr() const { return _publicSockAddr; } - const HifiSockAddr& getSTUNSockAddr() const { return _stunSockAddr; } + const SockAddr& getLocalSockAddr() const { return _localSockAddr; } + const SockAddr& getPublicSockAddr() const { return _publicSockAddr; } + const SockAddr& getSTUNSockAddr() const { return _stunSockAddr; } void processKillNode(ReceivedMessage& message); @@ -201,9 +201,9 @@ public: static std::unique_ptr constructICEPingPacket(PingType_t pingType, const QUuid& iceID); static std::unique_ptr constructICEPingReplyPacket(ReceivedMessage& message, const QUuid& iceID); - void sendPeerQueryToIceServer(const HifiSockAddr& iceServerSockAddr, const QUuid& clientID, const QUuid& peerID); + void sendPeerQueryToIceServer(const SockAddr& iceServerSockAddr, const QUuid& clientID, const QUuid& peerID); - SharedNodePointer findNodeWithAddr(const HifiSockAddr& addr); + SharedNodePointer findNodeWithAddr(const SockAddr& addr); using value_type = SharedNodePointer; using const_iterator = std::vector::const_iterator; @@ -369,7 +369,7 @@ private slots: signals: // QUuid might be zero for non-sourced packet types. - void packetVersionMismatch(PacketType type, const HifiSockAddr& senderSockAddr, const QUuid& senderUUID); + void packetVersionMismatch(PacketType type, const SockAddr& senderSockAddr, const QUuid& senderUUID); void uuidChanged(const QUuid& ownerUUID, const QUuid& oldUUID); void nodeAdded(SharedNodePointer); @@ -379,8 +379,8 @@ signals: void clientConnectionToNodeReset(SharedNodePointer); - void localSockAddrChanged(const HifiSockAddr& localSockAddr); - void publicSockAddrChanged(const HifiSockAddr& publicSockAddr); + void localSockAddrChanged(const SockAddr& localSockAddr); + void publicSockAddrChanged(const SockAddr& publicSockAddr); void isAllowedEditorChanged(bool isAllowedEditor); void canRezChanged(bool canRez); @@ -397,7 +397,7 @@ protected slots: void connectedForLocalSocketTest(); void errorTestingLocalSocket(); - void clientConnectionToSockAddrReset(const HifiSockAddr& sockAddr); + void clientConnectionToSockAddrReset(const SockAddr& sockAddr); void processDelayedAdds(); @@ -405,8 +405,8 @@ protected: struct NewNodeInfo { qint8 type; QUuid uuid; - HifiSockAddr publicSocket; - HifiSockAddr localSocket; + SockAddr publicSocket; + SockAddr localSocket; NodePermissions permissions; bool isReplicated; Node::LocalID sessionLocalID; @@ -418,10 +418,10 @@ protected: void operator=(LimitedNodeList const&) = delete; // Don't implement, needed to avoid copies of singleton qint64 sendPacket(std::unique_ptr packet, const Node& destinationNode, - const HifiSockAddr& overridenSockAddr); + const SockAddr& overridenSockAddr); void fillPacketHeader(const NLPacket& packet, HMACAuth* hmacAuth = nullptr); - void setLocalSocket(const HifiSockAddr& sockAddr); + void setLocalSocket(const SockAddr& sockAddr); bool packetSourceAndHashMatchAndTrackBandwidth(const udt::Packet& packet, Node* sourceNode = nullptr); void processSTUNResponse(std::unique_ptr packet); @@ -430,10 +430,10 @@ protected: void stopInitialSTUNUpdate(bool success); - void sendPacketToIceServer(PacketType packetType, const HifiSockAddr& iceServerSockAddr, const QUuid& clientID, + void sendPacketToIceServer(PacketType packetType, const SockAddr& iceServerSockAddr, const QUuid& clientID, const QUuid& peerRequestID = QUuid()); - bool sockAddrBelongsToNode(const HifiSockAddr& sockAddr); + bool sockAddrBelongsToNode(const SockAddr& sockAddr); void addNewNode(NewNodeInfo info); void delayNodeAdd(NewNodeInfo info); @@ -444,9 +444,9 @@ protected: mutable QReadWriteLock _nodeMutex { QReadWriteLock::Recursive }; udt::Socket _nodeSocket; QUdpSocket* _dtlsSocket { nullptr }; - HifiSockAddr _localSockAddr; - HifiSockAddr _publicSockAddr; - HifiSockAddr _stunSockAddr { STUN_SERVER_HOSTNAME, STUN_SERVER_PORT }; + SockAddr _localSockAddr; + SockAddr _publicSockAddr; + SockAddr _stunSockAddr { STUN_SERVER_HOSTNAME, STUN_SERVER_PORT }; bool _hasTCPCheckedLocalSocket { false }; bool _useAuthentication { true }; diff --git a/libraries/networking/src/NLPacket.cpp b/libraries/networking/src/NLPacket.cpp index 620e60945b..8463dab792 100644 --- a/libraries/networking/src/NLPacket.cpp +++ b/libraries/networking/src/NLPacket.cpp @@ -4,6 +4,7 @@ // // Created by Clement on 7/6/15. // Copyright 2015 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -35,7 +36,7 @@ std::unique_ptr NLPacket::create(PacketType type, qint64 size, bool is } std::unique_ptr NLPacket::fromReceivedPacket(std::unique_ptr data, qint64 size, - const HifiSockAddr& senderSockAddr) { + const SockAddr& senderSockAddr) { // Fail with null data Q_ASSERT(data); @@ -89,7 +90,7 @@ NLPacket::NLPacket(const NLPacket& other) : Packet(other) { _sourceID = other._sourceID; } -NLPacket::NLPacket(std::unique_ptr data, qint64 size, const HifiSockAddr& senderSockAddr) : +NLPacket::NLPacket(std::unique_ptr data, qint64 size, const SockAddr& senderSockAddr) : Packet(std::move(data), size, senderSockAddr) { // sanity check before we decrease the payloadSize with the payloadCapacity diff --git a/libraries/networking/src/NLPacket.h b/libraries/networking/src/NLPacket.h index 4103f2068e..b2a174a540 100644 --- a/libraries/networking/src/NLPacket.h +++ b/libraries/networking/src/NLPacket.h @@ -4,6 +4,7 @@ // // Created by Clement on 7/6/15. // Copyright 2015 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -52,7 +53,7 @@ public: bool isReliable = false, bool isPartOfMessage = false, PacketVersion version = 0); static std::unique_ptr fromReceivedPacket(std::unique_ptr data, qint64 size, - const HifiSockAddr& senderSockAddr); + const SockAddr& senderSockAddr); static std::unique_ptr fromBase(std::unique_ptr packet); @@ -87,7 +88,7 @@ public: protected: NLPacket(PacketType type, qint64 size = -1, bool forceReliable = false, bool isPartOfMessage = false, PacketVersion version = 0); - NLPacket(std::unique_ptr data, qint64 size, const HifiSockAddr& senderSockAddr); + NLPacket(std::unique_ptr data, qint64 size, const SockAddr& senderSockAddr); NLPacket(const NLPacket& other); NLPacket(NLPacket&& other); diff --git a/libraries/networking/src/NetworkPeer.cpp b/libraries/networking/src/NetworkPeer.cpp index b7807bc62d..e76b8c31a6 100644 --- a/libraries/networking/src/NetworkPeer.cpp +++ b/libraries/networking/src/NetworkPeer.cpp @@ -4,6 +4,7 @@ // // Created by Stephen Birarda on 2014-10-02. // Copyright 2014 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -37,7 +38,7 @@ NetworkPeer::NetworkPeer(QObject* parent) : _lastHeardMicrostamp = usecTimestampNow(); } -NetworkPeer::NetworkPeer(const QUuid& uuid, const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket, QObject* parent) : +NetworkPeer::NetworkPeer(const QUuid& uuid, const SockAddr& publicSocket, const SockAddr& localSocket, QObject* parent) : QObject(parent), _uuid(uuid), _publicSocket(publicSocket), @@ -50,7 +51,7 @@ NetworkPeer::NetworkPeer(const QUuid& uuid, const HifiSockAddr& publicSocket, co _lastHeardMicrostamp = usecTimestampNow(); } -void NetworkPeer::setPublicSocket(const HifiSockAddr& publicSocket) { +void NetworkPeer::setPublicSocket(const SockAddr& publicSocket) { if (publicSocket != _publicSocket) { if (_activeSocket == &_publicSocket) { // if the active socket was the public socket then reset it to NULL @@ -70,7 +71,7 @@ void NetworkPeer::setPublicSocket(const HifiSockAddr& publicSocket) { } } -void NetworkPeer::setLocalSocket(const HifiSockAddr& localSocket) { +void NetworkPeer::setLocalSocket(const SockAddr& localSocket) { if (localSocket != _localSocket) { if (_activeSocket == &_localSocket) { // if the active socket was the local socket then reset it to NULL @@ -90,7 +91,7 @@ void NetworkPeer::setLocalSocket(const HifiSockAddr& localSocket) { } } -void NetworkPeer::setSymmetricSocket(const HifiSockAddr& symmetricSocket) { +void NetworkPeer::setSymmetricSocket(const SockAddr& symmetricSocket) { if (symmetricSocket != _symmetricSocket) { if (_activeSocket == &_symmetricSocket) { // if the active socket was the symmetric socket then reset it to NULL @@ -110,7 +111,7 @@ void NetworkPeer::setSymmetricSocket(const HifiSockAddr& symmetricSocket) { } } -void NetworkPeer::setActiveSocket(HifiSockAddr* discoveredSocket) { +void NetworkPeer::setActiveSocket(SockAddr* discoveredSocket) { _activeSocket = discoveredSocket; // we have an active socket, stop our ping timer @@ -145,7 +146,7 @@ void NetworkPeer::activateSymmetricSocket() { } } -void NetworkPeer::activateMatchingOrNewSymmetricSocket(const HifiSockAddr& matchableSockAddr) { +void NetworkPeer::activateMatchingOrNewSymmetricSocket(const SockAddr& matchableSockAddr) { if (matchableSockAddr == _publicSocket) { activatePublicSocket(); } else if (matchableSockAddr == _localSocket) { diff --git a/libraries/networking/src/NetworkPeer.h b/libraries/networking/src/NetworkPeer.h index 4c08c97d3c..a3012087af 100644 --- a/libraries/networking/src/NetworkPeer.h +++ b/libraries/networking/src/NetworkPeer.h @@ -4,6 +4,7 @@ // // Created by Stephen Birarda on 2014-10-02. // Copyright 2014 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -18,7 +19,7 @@ #include #include -#include "HifiSockAddr.h" +#include "SockAddr.h" #include "UUID.h" const QString ICE_SERVER_HOSTNAME = "localhost"; @@ -32,7 +33,7 @@ class NetworkPeer : public QObject { Q_OBJECT public: NetworkPeer(QObject* parent = 0); - NetworkPeer(const QUuid& uuid, const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket, QObject* parent = 0); + NetworkPeer(const QUuid& uuid, const SockAddr& publicSocket, const SockAddr& localSocket, QObject* parent = 0); bool isNull() const { return _uuid.isNull(); } bool hasSockets() const { return !_localSocket.isNull() && !_publicSocket.isNull(); } @@ -49,21 +50,21 @@ public: void softReset(); void reset(); - const HifiSockAddr& getPublicSocket() const { return _publicSocket; } - const HifiSockAddr& getLocalSocket() const { return _localSocket; } - const HifiSockAddr& getSymmetricSocket() const { return _symmetricSocket; } + const SockAddr& getPublicSocket() const { return _publicSocket; } + const SockAddr& getLocalSocket() const { return _localSocket; } + const SockAddr& getSymmetricSocket() const { return _symmetricSocket; } - void setPublicSocket(const HifiSockAddr& publicSocket); - void setLocalSocket(const HifiSockAddr& localSocket); - void setSymmetricSocket(const HifiSockAddr& symmetricSocket); + void setPublicSocket(const SockAddr& publicSocket); + void setLocalSocket(const SockAddr& localSocket); + void setSymmetricSocket(const SockAddr& symmetricSocket); - const HifiSockAddr* getActiveSocket() const { return _activeSocket; } + const SockAddr* getActiveSocket() const { return _activeSocket; } void activatePublicSocket(); void activateLocalSocket(); void activateSymmetricSocket(); - void activateMatchingOrNewSymmetricSocket(const HifiSockAddr& matchableSockAddr); + void activateMatchingOrNewSymmetricSocket(const SockAddr& matchableSockAddr); quint64 getWakeTimestamp() const { return _wakeTimestamp; } void setWakeTimestamp(quint64 wakeTimestamp) { _wakeTimestamp = wakeTimestamp; } @@ -93,19 +94,19 @@ public slots: signals: void pingTimerTimeout(); - void socketActivated(const HifiSockAddr& sockAddr); - void socketUpdated(HifiSockAddr previousAddress, HifiSockAddr currentAddress); + void socketActivated(const SockAddr& sockAddr); + void socketUpdated(SockAddr previousAddress, SockAddr currentAddress); protected: - void setActiveSocket(HifiSockAddr* discoveredSocket); + void setActiveSocket(SockAddr* discoveredSocket); QUuid _uuid; LocalID _localID { 0 }; - HifiSockAddr _publicSocket; - HifiSockAddr _localSocket; - HifiSockAddr _symmetricSocket; - HifiSockAddr* _activeSocket; + SockAddr _publicSocket; + SockAddr _localSocket; + SockAddr _symmetricSocket; + SockAddr* _activeSocket; quint64 _wakeTimestamp; std::atomic_ullong _lastHeardMicrostamp; diff --git a/libraries/networking/src/Node.cpp b/libraries/networking/src/Node.cpp index a2bd60914a..aa13dd6565 100644 --- a/libraries/networking/src/Node.cpp +++ b/libraries/networking/src/Node.cpp @@ -4,6 +4,7 @@ // // Created by Stephen Birarda on 2/15/13. // Copyright 2013 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -85,8 +86,8 @@ NodeType_t NodeType::fromString(QString type) { } -Node::Node(const QUuid& uuid, NodeType_t type, const HifiSockAddr& publicSocket, - const HifiSockAddr& localSocket, QObject* parent) : +Node::Node(const QUuid& uuid, NodeType_t type, const SockAddr& publicSocket, + const SockAddr& localSocket, QObject* parent) : NetworkPeer(uuid, publicSocket, localSocket, parent), _type(type), _pingMs(-1), // "Uninitialized" diff --git a/libraries/networking/src/Node.h b/libraries/networking/src/Node.h index 7435ebaaf8..cf2f081da6 100644 --- a/libraries/networking/src/Node.h +++ b/libraries/networking/src/Node.h @@ -4,6 +4,7 @@ // // Created by Stephen Birarda on 2/15/13. // Copyright 2013 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -27,7 +28,7 @@ #include -#include "HifiSockAddr.h" +#include "SockAddr.h" #include "NetworkPeer.h" #include "NodeData.h" #include "NodeType.h" @@ -44,7 +45,7 @@ public: using Stats = udt::ConnectionStats::Stats; Node(const QUuid& uuid, NodeType_t type, - const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket, + const SockAddr& publicSocket, const SockAddr& localSocket, QObject* parent = nullptr); bool operator==(const Node& otherNode) const { return _uuid == otherNode._uuid; } diff --git a/libraries/networking/src/NodeList.cpp b/libraries/networking/src/NodeList.cpp index a975302699..ccbac287fa 100644 --- a/libraries/networking/src/NodeList.cpp +++ b/libraries/networking/src/NodeList.cpp @@ -35,7 +35,7 @@ #include "Assignment.h" #include "AudioHelpers.h" #include "DomainAccountManager.h" -#include "HifiSockAddr.h" +#include "SockAddr.h" #include "FingerprintUtils.h" #include "NetworkLogging.h" @@ -176,11 +176,11 @@ NodeList::NodeList(char newOwnerType, int socketListenPort, int dtlsListenPort) PacketReceiver::makeUnsourcedListenerReference(this, &NodeList::processUsernameFromIDReply)); } -qint64 NodeList::sendStats(QJsonObject statsObject, HifiSockAddr destination) { +qint64 NodeList::sendStats(QJsonObject statsObject, SockAddr destination) { if (thread() != QThread::currentThread()) { QMetaObject::invokeMethod(this, "sendStats", Qt::QueuedConnection, Q_ARG(QJsonObject, statsObject), - Q_ARG(HifiSockAddr, destination)); + Q_ARG(SockAddr, destination)); return 0; } @@ -245,7 +245,7 @@ void NodeList::timePingReply(ReceivedMessage& message, const SharedNodePointer& void NodeList::processPingPacket(QSharedPointer message, SharedNodePointer sendingNode) { // send back a reply auto replyPacket = constructPingReplyPacket(*message); - const HifiSockAddr& senderSockAddr = message->getSenderSockAddr(); + const SockAddr& senderSockAddr = message->getSenderSockAddr(); sendPacket(std::move(replyPacket), *sendingNode, senderSockAddr); // If we don't have a symmetric socket for this node and this socket doesn't match @@ -364,7 +364,7 @@ void NodeList::sendDomainServerCheckIn() { // let the domain handler know we are due to send a checkin packet } else if (!domainHandlerIp.isNull() && !_domainHandler.checkInPacketTimeout()) { bool domainIsConnected = _domainHandler.isConnected(); - HifiSockAddr domainSockAddr = _domainHandler.getSockAddr(); + SockAddr domainSockAddr = _domainHandler.getSockAddr(); PacketType domainPacketType = !domainIsConnected ? PacketType::DomainConnectRequest : PacketType::DomainListRequest; @@ -405,7 +405,7 @@ void NodeList::sendDomainServerCheckIn() { QDataStream packetStream(domainPacket.get()); - HifiSockAddr localSockAddr = _localSockAddr; + SockAddr localSockAddr = _localSockAddr; if (domainPacketType == PacketType::DomainConnectRequest) { #if (PR_BUILD || DEV_BUILD) @@ -1012,7 +1012,7 @@ void NodeList::sendKeepAlivePings() { }); } -bool NodeList::sockAddrBelongsToDomainOrNode(const HifiSockAddr& sockAddr) { +bool NodeList::sockAddrBelongsToDomainOrNode(const SockAddr& sockAddr) { return _domainHandler.getSockAddr() == sockAddr || LimitedNodeList::sockAddrBelongsToNode(sockAddr); } diff --git a/libraries/networking/src/NodeList.h b/libraries/networking/src/NodeList.h index 59b3815fba..72e37deb0f 100644 --- a/libraries/networking/src/NodeList.h +++ b/libraries/networking/src/NodeList.h @@ -4,6 +4,7 @@ // // Created by Stephen Birarda on 2/15/13. // Copyright 2013 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -57,7 +58,7 @@ public: NodeType_t getOwnerType() const { return _ownerType.load(); } void setOwnerType(NodeType_t ownerType) { _ownerType.store(ownerType); } - Q_INVOKABLE qint64 sendStats(QJsonObject statsObject, HifiSockAddr destination); + Q_INVOKABLE qint64 sendStats(QJsonObject statsObject, SockAddr destination); Q_INVOKABLE qint64 sendStatsToDomainServer(QJsonObject statsObject); DomainHandler& getDomainHandler() { return _domainHandler; } @@ -67,7 +68,7 @@ public: void addSetOfNodeTypesToNodeInterestSet(const NodeSet& setOfNodeTypes); void resetNodeInterestSet() { _nodeTypesOfInterest.clear(); } - void setAssignmentServerSocket(const HifiSockAddr& serverSocket) { _assignmentServerSocket = serverSocket; } + void setAssignmentServerSocket(const SockAddr& serverSocket) { _assignmentServerSocket = serverSocket; } void sendAssignment(Assignment& assignment); void setIsShuttingDown(bool isShuttingDown) { _isShuttingDown = isShuttingDown; } @@ -100,7 +101,7 @@ public: virtual bool isDomainServer() const override { return false; } virtual QUuid getDomainUUID() const override { return _domainHandler.getUUID(); } virtual Node::LocalID getDomainLocalID() const override { return _domainHandler.getLocalID(); } - virtual HifiSockAddr getDomainSockAddr() const override { return _domainHandler.getSockAddr(); } + virtual SockAddr getDomainSockAddr() const override { return _domainHandler.getSockAddr(); } public slots: void reset(QString reason, bool skipDomainHandlerReset = false); @@ -169,12 +170,12 @@ private: void pingPunchForInactiveNode(const SharedNodePointer& node); - bool sockAddrBelongsToDomainOrNode(const HifiSockAddr& sockAddr); + bool sockAddrBelongsToDomainOrNode(const SockAddr& sockAddr); std::atomic _ownerType; NodeSet _nodeTypesOfInterest; DomainHandler _domainHandler; - HifiSockAddr _assignmentServerSocket; + SockAddr _assignmentServerSocket; bool _isShuttingDown { false }; QTimer _keepAlivePingTimer; bool _requestsDomainListData { false }; diff --git a/libraries/networking/src/PacketReceiver.cpp b/libraries/networking/src/PacketReceiver.cpp index c13fb8566b..384355b53c 100644 --- a/libraries/networking/src/PacketReceiver.cpp +++ b/libraries/networking/src/PacketReceiver.cpp @@ -5,6 +5,7 @@ // Created by Stephen Birarda on 1/23/2014. // Update by Ryan Huffman on 7/8/2015. // Copyright 2014 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -152,7 +153,7 @@ void PacketReceiver::handleVerifiedPacket(std::unique_ptr packet) { void PacketReceiver::handleVerifiedMessagePacket(std::unique_ptr packet) { auto nlPacket = NLPacket::fromBase(std::move(packet)); - auto key = std::pair(nlPacket->getSenderSockAddr(), nlPacket->getMessageNumber()); + auto key = std::pair(nlPacket->getSenderSockAddr(), nlPacket->getMessageNumber()); auto it = _pendingMessages.find(key); QSharedPointer message; @@ -174,8 +175,8 @@ void PacketReceiver::handleVerifiedMessagePacket(std::unique_ptr pa } } -void PacketReceiver::handleMessageFailure(HifiSockAddr from, udt::Packet::MessageNumber messageNumber) { - auto key = std::pair(from, messageNumber); +void PacketReceiver::handleMessageFailure(SockAddr from, udt::Packet::MessageNumber messageNumber) { + auto key = std::pair(from, messageNumber); auto it = _pendingMessages.find(key); if (it != _pendingMessages.end()) { auto message = it->second; diff --git a/libraries/networking/src/PacketReceiver.h b/libraries/networking/src/PacketReceiver.h index 4d2f11360e..c354e98a37 100644 --- a/libraries/networking/src/PacketReceiver.h +++ b/libraries/networking/src/PacketReceiver.h @@ -5,6 +5,7 @@ // Created by Stephen Birarda on 1/23/2014. // Update by Ryan Huffman on 7/8/2015. // Copyright 2014 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -34,9 +35,9 @@ class OctreePacketProcessor; namespace std { template <> - struct hash> { - size_t operator()(const std::pair& pair) const { - return hash()(pair.first) ^ hash()(pair.second); + struct hash> { + size_t operator()(const std::pair& pair) const { + return hash()(pair.first) ^ hash()(pair.second); } }; } @@ -78,7 +79,7 @@ public: void handleVerifiedPacket(std::unique_ptr packet); void handleVerifiedMessagePacket(std::unique_ptr message); - void handleMessageFailure(HifiSockAddr from, udt::Packet::MessageNumber messageNumber); + void handleMessageFailure(SockAddr from, udt::Packet::MessageNumber messageNumber); private: template @@ -129,7 +130,7 @@ private: QMutex _directConnectSetMutex; QSet _directlyConnectedObjects; - std::unordered_map, QSharedPointer> _pendingMessages; + std::unordered_map, QSharedPointer> _pendingMessages; friend class EntityEditPacketSender; friend class OctreePacketProcessor; diff --git a/libraries/networking/src/ReceivedMessage.cpp b/libraries/networking/src/ReceivedMessage.cpp index 7ae408ef7a..684ad665ba 100644 --- a/libraries/networking/src/ReceivedMessage.cpp +++ b/libraries/networking/src/ReceivedMessage.cpp @@ -4,6 +4,7 @@ // // Created by Ryan Huffman on 2015/09/17 // Copyright 2015 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -49,7 +50,7 @@ ReceivedMessage::ReceivedMessage(NLPacket& packet) } ReceivedMessage::ReceivedMessage(QByteArray byteArray, PacketType packetType, PacketVersion packetVersion, - const HifiSockAddr& senderSockAddr, NLPacket::LocalID sourceID) : + const SockAddr& senderSockAddr, NLPacket::LocalID sourceID) : _data(byteArray), _headData(_data.mid(0, HEAD_DATA_SIZE)), _numPackets(1), diff --git a/libraries/networking/src/ReceivedMessage.h b/libraries/networking/src/ReceivedMessage.h index c864616635..f9c8245a10 100644 --- a/libraries/networking/src/ReceivedMessage.h +++ b/libraries/networking/src/ReceivedMessage.h @@ -4,6 +4,7 @@ // // Created by Ryan Huffman on 2015/09/15 // Copyright 2015 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -25,7 +26,7 @@ public: ReceivedMessage(const NLPacketList& packetList); ReceivedMessage(NLPacket& packet); ReceivedMessage(QByteArray byteArray, PacketType packetType, PacketVersion packetVersion, - const HifiSockAddr& senderSockAddr, NLPacket::LocalID sourceID = NLPacket::NULL_LOCAL_ID); + const SockAddr& senderSockAddr, NLPacket::LocalID sourceID = NLPacket::NULL_LOCAL_ID); QByteArray getMessage() const { return _data; } const char* getRawMessage() const { return _data.constData(); } @@ -41,7 +42,7 @@ public: bool isComplete() const { return _isComplete; } NLPacket::LocalID getSourceID() const { return _sourceID; } - const HifiSockAddr& getSenderSockAddr() { return _senderSockAddr; } + const SockAddr& getSenderSockAddr() { return _senderSockAddr; } qint64 getPosition() const { return _position; } @@ -99,7 +100,7 @@ private: NLPacket::LocalID _sourceID { NLPacket::NULL_LOCAL_ID }; PacketType _packetType; PacketVersion _packetVersion; - HifiSockAddr _senderSockAddr; + SockAddr _senderSockAddr; std::atomic _isComplete { true }; std::atomic _failed { false }; diff --git a/libraries/networking/src/HifiSockAddr.cpp b/libraries/networking/src/SockAddr.cpp similarity index 78% rename from libraries/networking/src/HifiSockAddr.cpp rename to libraries/networking/src/SockAddr.cpp index 086dd08489..e61ae5bccc 100644 --- a/libraries/networking/src/HifiSockAddr.cpp +++ b/libraries/networking/src/SockAddr.cpp @@ -1,15 +1,16 @@ // -// HifiSockAddr.cpp +// SockAddr.cpp // libraries/networking/src // // Created by Stephen Birarda on 11/26/2013. // Copyright 2013 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include "HifiSockAddr.h" +#include "SockAddr.h" #include #include @@ -24,23 +25,23 @@ #include #endif -int hifiSockAddrMetaTypeId = qRegisterMetaType(); +int sockAddrMetaTypeId = qRegisterMetaType(); -HifiSockAddr::HifiSockAddr() : +SockAddr::SockAddr() : _address(), _port(0) { } -HifiSockAddr::HifiSockAddr(const QHostAddress& address, quint16 port) : +SockAddr::SockAddr(const QHostAddress& address, quint16 port) : _address(address), _port(port) { } -HifiSockAddr::HifiSockAddr(const HifiSockAddr& otherSockAddr) : +SockAddr::SockAddr(const SockAddr& otherSockAddr) : QObject(), _address(otherSockAddr._address), _port(otherSockAddr._port) @@ -48,14 +49,14 @@ HifiSockAddr::HifiSockAddr(const HifiSockAddr& otherSockAddr) : setObjectName(otherSockAddr.objectName()); } -HifiSockAddr& HifiSockAddr::operator=(const HifiSockAddr& rhsSockAddr) { +SockAddr& SockAddr::operator=(const SockAddr& rhsSockAddr) { setObjectName(rhsSockAddr.objectName()); _address = rhsSockAddr._address; _port = rhsSockAddr._port; return *this; } -HifiSockAddr::HifiSockAddr(const QString& hostname, quint16 hostOrderPort, bool shouldBlockForLookup) : +SockAddr::SockAddr(const QString& hostname, quint16 hostOrderPort, bool shouldBlockForLookup) : _address(hostname), _port(hostOrderPort) { @@ -73,7 +74,7 @@ HifiSockAddr::HifiSockAddr(const QString& hostname, quint16 hostOrderPort, bool } } -HifiSockAddr::HifiSockAddr(const sockaddr* sockaddr) { +SockAddr::SockAddr(const sockaddr* sockaddr) { _address = QHostAddress(sockaddr); if (sockaddr->sa_family == AF_INET) { @@ -83,7 +84,7 @@ HifiSockAddr::HifiSockAddr(const sockaddr* sockaddr) { } } -void HifiSockAddr::swap(HifiSockAddr& otherSockAddr) { +void SockAddr::swap(SockAddr& otherSockAddr) { using std::swap; swap(_address, otherSockAddr._address); @@ -95,11 +96,11 @@ void HifiSockAddr::swap(HifiSockAddr& otherSockAddr) { setObjectName(temp); } -bool HifiSockAddr::operator==(const HifiSockAddr& rhsSockAddr) const { +bool SockAddr::operator==(const SockAddr& rhsSockAddr) const { return _address == rhsSockAddr._address && _port == rhsSockAddr._port; } -void HifiSockAddr::handleLookupResult(const QHostInfo& hostInfo) { +void SockAddr::handleLookupResult(const QHostInfo& hostInfo) { if (hostInfo.error() != QHostInfo::NoError) { qCDebug(networking) << "Lookup failed for" << hostInfo.lookupId() << ":" << hostInfo.errorString(); emit lookupFailed(); @@ -117,11 +118,11 @@ void HifiSockAddr::handleLookupResult(const QHostInfo& hostInfo) { } } -QString HifiSockAddr::toString() const { +QString SockAddr::toString() const { return _address.toString() + ":" + QString::number(_port); } -bool HifiSockAddr::hasPrivateAddress() const { +bool SockAddr::hasPrivateAddress() const { // an address is private if it is loopback or falls in any of the RFC1918 address spaces const QPair TWENTY_FOUR_BIT_BLOCK = { QHostAddress("10.0.0.0"), 8 }; const QPair TWENTY_BIT_BLOCK = { QHostAddress("172.16.0.0") , 12 }; @@ -133,22 +134,22 @@ bool HifiSockAddr::hasPrivateAddress() const { || _address.isInSubnet(SIXTEEN_BIT_BLOCK); } -QDebug operator<<(QDebug debug, const HifiSockAddr& sockAddr) { +QDebug operator<<(QDebug debug, const SockAddr& sockAddr) { debug.nospace() << sockAddr._address.toString().toLocal8Bit().constData() << ":" << sockAddr._port; return debug.space(); } -QDataStream& operator<<(QDataStream& dataStream, const HifiSockAddr& sockAddr) { +QDataStream& operator<<(QDataStream& dataStream, const SockAddr& sockAddr) { dataStream << sockAddr._address << sockAddr._port; return dataStream; } -QDataStream& operator>>(QDataStream& dataStream, HifiSockAddr& sockAddr) { +QDataStream& operator>>(QDataStream& dataStream, SockAddr& sockAddr) { dataStream >> sockAddr._address >> sockAddr._port; return dataStream; } -uint qHash(const HifiSockAddr& key, uint seed) { +uint qHash(const SockAddr& key, uint seed) { // use the existing QHostAddress and quint16 hash functions to get our hash return qHash(key.getAddress(), seed) ^ qHash(key.getPort(), seed); } diff --git a/libraries/networking/src/HifiSockAddr.h b/libraries/networking/src/SockAddr.h similarity index 64% rename from libraries/networking/src/HifiSockAddr.h rename to libraries/networking/src/SockAddr.h index dcf7f9a6a9..07b3e8c306 100644 --- a/libraries/networking/src/HifiSockAddr.h +++ b/libraries/networking/src/SockAddr.h @@ -1,16 +1,17 @@ // -// HifiSockAddr.h +// SockAddr.h // libraries/networking/src // // Created by Stephen Birarda on 11/26/2013. // Copyright 2013 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#ifndef hifi_HifiSockAddr_h -#define hifi_HifiSockAddr_h +#ifndef hifi_SockAddr_h +#define hifi_SockAddr_h #include #include @@ -19,23 +20,23 @@ struct sockaddr; #include -class HifiSockAddr : public QObject { +class SockAddr : public QObject { Q_OBJECT public: - HifiSockAddr(); - HifiSockAddr(const QHostAddress& address, quint16 port); - HifiSockAddr(const HifiSockAddr& otherSockAddr); - HifiSockAddr(const QString& hostname, quint16 hostOrderPort, bool shouldBlockForLookup = false); - HifiSockAddr(const sockaddr* sockaddr); + SockAddr(); + SockAddr(const QHostAddress& address, quint16 port); + SockAddr(const SockAddr& otherSockAddr); + SockAddr(const QString& hostname, quint16 hostOrderPort, bool shouldBlockForLookup = false); + SockAddr(const sockaddr* sockaddr); bool isNull() const { return _address.isNull() && _port == 0; } void clear() { _address.clear(); _port = 0;} - HifiSockAddr& operator=(const HifiSockAddr& rhsSockAddr); - void swap(HifiSockAddr& otherSockAddr); + SockAddr& operator=(const SockAddr& rhsSockAddr); + void swap(SockAddr& otherSockAddr); - bool operator==(const HifiSockAddr& rhsSockAddr) const; - bool operator!=(const HifiSockAddr& rhsSockAddr) const { return !(*this == rhsSockAddr); } + bool operator==(const SockAddr& rhsSockAddr) const; + bool operator!=(const SockAddr& rhsSockAddr) const { return !(*this == rhsSockAddr); } const QHostAddress& getAddress() const { return _address; } QHostAddress* getAddressPointer() { return &_address; } @@ -45,16 +46,16 @@ public: quint16* getPortPointer() { return &_port; } void setPort(quint16 port) { _port = port; } - static int packSockAddr(unsigned char* packetData, const HifiSockAddr& packSockAddr); - static int unpackSockAddr(const unsigned char* packetData, HifiSockAddr& unpackDestSockAddr); + static int packSockAddr(unsigned char* packetData, const SockAddr& packSockAddr); + static int unpackSockAddr(const unsigned char* packetData, SockAddr& unpackDestSockAddr); QString toString() const; bool hasPrivateAddress() const; // checks if the address behind this sock addr is private per RFC 1918 - friend QDebug operator<<(QDebug debug, const HifiSockAddr& sockAddr); - friend QDataStream& operator<<(QDataStream& dataStream, const HifiSockAddr& sockAddr); - friend QDataStream& operator>>(QDataStream& dataStream, HifiSockAddr& sockAddr); + friend QDebug operator<<(QDebug debug, const SockAddr& sockAddr); + friend QDataStream& operator<<(QDataStream& dataStream, const SockAddr& sockAddr); + friend QDataStream& operator>>(QDataStream& dataStream, SockAddr& sockAddr); private slots: void handleLookupResult(const QHostInfo& hostInfo); @@ -66,14 +67,14 @@ private: quint16 _port; }; -uint qHash(const HifiSockAddr& key, uint seed); +uint qHash(const SockAddr& key, uint seed); namespace std { template <> - struct hash { + struct hash { // NOTE: this hashing specifically ignores IPv6 addresses - if we begin to support those we will need // to conditionally hash the bytes that represent an IPv6 address - size_t operator()(const HifiSockAddr& sockAddr) const { + size_t operator()(const SockAddr& sockAddr) const { // use XOR of implemented std::hash templates for new hash // depending on the type of address we're looking at @@ -90,6 +91,6 @@ namespace std { }; } -Q_DECLARE_METATYPE(HifiSockAddr); +Q_DECLARE_METATYPE(SockAddr); -#endif // hifi_HifiSockAddr_h +#endif // hifi_SockAddr_h diff --git a/libraries/networking/src/udt/BasePacket.cpp b/libraries/networking/src/udt/BasePacket.cpp index 12a174b7d3..442ed8a2c8 100644 --- a/libraries/networking/src/udt/BasePacket.cpp +++ b/libraries/networking/src/udt/BasePacket.cpp @@ -4,6 +4,7 @@ // // Created by Stephen Birarda on 2015-07-23. // Copyright 2015 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -36,7 +37,7 @@ std::unique_ptr BasePacket::create(qint64 size) { } std::unique_ptr BasePacket::fromReceivedPacket(std::unique_ptr data, - qint64 size, const HifiSockAddr& senderSockAddr) { + qint64 size, const SockAddr& senderSockAddr) { // Fail with invalid size Q_ASSERT(size >= 0); @@ -66,7 +67,7 @@ BasePacket::BasePacket(qint64 size) { _payloadStart = _packet.get(); } -BasePacket::BasePacket(std::unique_ptr data, qint64 size, const HifiSockAddr& senderSockAddr) : +BasePacket::BasePacket(std::unique_ptr data, qint64 size, const SockAddr& senderSockAddr) : _packetSize(size), _packet(std::move(data)), _payloadStart(_packet.get()), diff --git a/libraries/networking/src/udt/BasePacket.h b/libraries/networking/src/udt/BasePacket.h index 4981cb4720..b196f5de24 100644 --- a/libraries/networking/src/udt/BasePacket.h +++ b/libraries/networking/src/udt/BasePacket.h @@ -4,6 +4,7 @@ // // Created by Stephen Birarda on 2015-07-23. // Copyright 2015 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -18,7 +19,7 @@ #include -#include "../HifiSockAddr.h" +#include "../SockAddr.h" #include "Constants.h" #include "../ExtendedIODevice.h" @@ -31,7 +32,7 @@ public: static std::unique_ptr create(qint64 size = -1); static std::unique_ptr fromReceivedPacket(std::unique_ptr data, qint64 size, - const HifiSockAddr& senderSockAddr); + const SockAddr& senderSockAddr); // Current level's header size static int localHeaderSize(); @@ -66,8 +67,8 @@ public: qint64 bytesLeftToRead() const { return _payloadSize - pos(); } qint64 bytesAvailableForWrite() const { return _payloadCapacity - pos(); } - HifiSockAddr& getSenderSockAddr() { return _senderSockAddr; } - const HifiSockAddr& getSenderSockAddr() const { return _senderSockAddr; } + SockAddr& getSenderSockAddr() { return _senderSockAddr; } + const SockAddr& getSenderSockAddr() const { return _senderSockAddr; } // QIODevice virtual functions // WARNING: Those methods all refer to the payload ONLY and NOT the entire packet @@ -87,7 +88,7 @@ public: protected: BasePacket(qint64 size); - BasePacket(std::unique_ptr data, qint64 size, const HifiSockAddr& senderSockAddr); + BasePacket(std::unique_ptr data, qint64 size, const SockAddr& senderSockAddr); BasePacket(const BasePacket& other) : ExtendedIODevice() { *this = other; } BasePacket& operator=(const BasePacket& other); BasePacket(BasePacket&& other); @@ -107,7 +108,7 @@ protected: qint64 _payloadSize = 0; // How much of the payload is actually used - HifiSockAddr _senderSockAddr; // sender address for packet (only used on receiving end) + SockAddr _senderSockAddr; // sender address for packet (only used on receiving end) p_high_resolution_clock::time_point _receiveTime; // captures the time the packet received (only used on receiving end) }; diff --git a/libraries/networking/src/udt/Connection.cpp b/libraries/networking/src/udt/Connection.cpp index 338b95163f..66bf3f6613 100644 --- a/libraries/networking/src/udt/Connection.cpp +++ b/libraries/networking/src/udt/Connection.cpp @@ -4,6 +4,7 @@ // // Created by Clement on 7/27/15. // Copyright 2015 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -17,7 +18,7 @@ #include -#include "../HifiSockAddr.h" +#include "../SockAddr.h" #include "../NetworkLogging.h" #include "CongestionControl.h" @@ -30,7 +31,7 @@ using namespace udt; using namespace std::chrono; -Connection::Connection(Socket* parentSocket, HifiSockAddr destination, std::unique_ptr congestionControl) : +Connection::Connection(Socket* parentSocket, SockAddr destination, std::unique_ptr congestionControl) : _parentSocket(parentSocket), _destination(destination), _congestionControl(move(congestionControl)) @@ -485,7 +486,7 @@ std::unique_ptr PendingReceivedMessage::removeNextPacket() { return std::unique_ptr(); } -void Connection::setDestinationAddress(const HifiSockAddr& destination) { +void Connection::setDestinationAddress(const SockAddr& destination) { if (_destination != destination) { _destination = destination; emit destinationAddressChange(destination); diff --git a/libraries/networking/src/udt/Connection.h b/libraries/networking/src/udt/Connection.h index 00d5beb5ab..2869b7f57d 100644 --- a/libraries/networking/src/udt/Connection.h +++ b/libraries/networking/src/udt/Connection.h @@ -4,6 +4,7 @@ // // Created by Clement on 7/27/15. // Copyright 2015 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -23,7 +24,7 @@ #include "Constants.h" #include "LossList.h" #include "SendQueue.h" -#include "../HifiSockAddr.h" +#include "../SockAddr.h" namespace udt { @@ -52,7 +53,7 @@ class Connection : public QObject { public: using ControlPacketPointer = std::unique_ptr; - Connection(Socket* parentSocket, HifiSockAddr destination, std::unique_ptr congestionControl); + Connection(Socket* parentSocket, SockAddr destination, std::unique_ptr congestionControl); virtual ~Connection(); void sendReliablePacket(std::unique_ptr packet); @@ -68,7 +69,7 @@ public: ConnectionStats::Stats sampleStats() { return _stats.sample(); } - HifiSockAddr getDestination() const { return _destination; } + SockAddr getDestination() const { return _destination; } void setMaxBandwidth(int maxBandwidth); @@ -77,12 +78,12 @@ public: void recordSentUnreliablePackets(int wireSize, int payloadSize); void recordReceivedUnreliablePackets(int wireSize, int payloadSize); - void setDestinationAddress(const HifiSockAddr& destination); + void setDestinationAddress(const SockAddr& destination); signals: void packetSent(); - void receiverHandshakeRequestComplete(const HifiSockAddr& sockAddr); - void destinationAddressChange(HifiSockAddr currentAddress); + void receiverHandshakeRequestComplete(const SockAddr& sockAddr); + void destinationAddressChange(SockAddr currentAddress); private slots: void recordSentPackets(int wireSize, int payloadSize, SequenceNumber seqNum, p_high_resolution_clock::time_point timePoint); @@ -124,7 +125,7 @@ private: SequenceNumber _lastReceivedACK; // The last ACK received Socket* _parentSocket { nullptr }; - HifiSockAddr _destination; + SockAddr _destination; std::unique_ptr _congestionControl; diff --git a/libraries/networking/src/udt/ControlPacket.cpp b/libraries/networking/src/udt/ControlPacket.cpp index 6fdefd36f6..b56f455030 100644 --- a/libraries/networking/src/udt/ControlPacket.cpp +++ b/libraries/networking/src/udt/ControlPacket.cpp @@ -4,6 +4,7 @@ // // Created by Stephen Birarda on 2015-07-24. // Copyright 2015 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -26,7 +27,7 @@ int ControlPacket::maxPayloadSize() { } std::unique_ptr ControlPacket::fromReceivedPacket(std::unique_ptr data, qint64 size, - const HifiSockAddr &senderSockAddr) { + const SockAddr &senderSockAddr) { // Fail with null data Q_ASSERT(data); @@ -56,7 +57,7 @@ ControlPacket::ControlPacket(Type type, qint64 size) : writeType(); } -ControlPacket::ControlPacket(std::unique_ptr data, qint64 size, const HifiSockAddr& senderSockAddr) : +ControlPacket::ControlPacket(std::unique_ptr data, qint64 size, const SockAddr& senderSockAddr) : BasePacket(std::move(data), size, senderSockAddr) { // sanity check before we decrease the payloadSize with the payloadCapacity diff --git a/libraries/networking/src/udt/ControlPacket.h b/libraries/networking/src/udt/ControlPacket.h index 46b9cdbd40..772df41455 100644 --- a/libraries/networking/src/udt/ControlPacket.h +++ b/libraries/networking/src/udt/ControlPacket.h @@ -4,6 +4,7 @@ // // Created by Stephen Birarda on 2015-07-24. // Copyright 2015 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -35,7 +36,7 @@ public: static std::unique_ptr create(Type type, qint64 size = -1); static std::unique_ptr fromReceivedPacket(std::unique_ptr data, qint64 size, - const HifiSockAddr& senderSockAddr); + const SockAddr& senderSockAddr); // Current level's header size static int localHeaderSize(); // Cumulated size of all the headers @@ -48,7 +49,7 @@ public: private: ControlPacket(Type type, qint64 size = -1); - ControlPacket(std::unique_ptr data, qint64 size, const HifiSockAddr& senderSockAddr); + ControlPacket(std::unique_ptr data, qint64 size, const SockAddr& senderSockAddr); ControlPacket(ControlPacket&& other); ControlPacket(const ControlPacket& other) = delete; diff --git a/libraries/networking/src/udt/Packet.cpp b/libraries/networking/src/udt/Packet.cpp index f8b74cea37..8c8f72457c 100644 --- a/libraries/networking/src/udt/Packet.cpp +++ b/libraries/networking/src/udt/Packet.cpp @@ -4,6 +4,7 @@ // // Created by Clement on 7/2/15. // Copyright 2015 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -61,7 +62,7 @@ std::unique_ptr Packet::create(qint64 size, bool isReliable, bool isPart return packet; } -std::unique_ptr Packet::fromReceivedPacket(std::unique_ptr data, qint64 size, const HifiSockAddr& senderSockAddr) { +std::unique_ptr Packet::fromReceivedPacket(std::unique_ptr data, qint64 size, const SockAddr& senderSockAddr) { // Fail with invalid size Q_ASSERT(size >= 0); @@ -87,7 +88,7 @@ Packet::Packet(qint64 size, bool isReliable, bool isPartOfMessage) : writeHeader(); } -Packet::Packet(std::unique_ptr data, qint64 size, const HifiSockAddr& senderSockAddr) : +Packet::Packet(std::unique_ptr data, qint64 size, const SockAddr& senderSockAddr) : BasePacket(std::move(data), size, senderSockAddr) { readHeader(); diff --git a/libraries/networking/src/udt/Packet.h b/libraries/networking/src/udt/Packet.h index 36098235f9..b852635d33 100644 --- a/libraries/networking/src/udt/Packet.h +++ b/libraries/networking/src/udt/Packet.h @@ -4,6 +4,7 @@ // // Created by Clement on 7/2/15. // Copyright 2015 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -69,7 +70,7 @@ public: }; static std::unique_ptr create(qint64 size = -1, bool isReliable = false, bool isPartOfMessage = false); - static std::unique_ptr fromReceivedPacket(std::unique_ptr data, qint64 size, const HifiSockAddr& senderSockAddr); + static std::unique_ptr fromReceivedPacket(std::unique_ptr data, qint64 size, const SockAddr& senderSockAddr); // Provided for convenience, try to limit use static std::unique_ptr createCopy(const Packet& other); @@ -97,7 +98,7 @@ public: protected: Packet(qint64 size, bool isReliable = false, bool isPartOfMessage = false); - Packet(std::unique_ptr data, qint64 size, const HifiSockAddr& senderSockAddr); + Packet(std::unique_ptr data, qint64 size, const SockAddr& senderSockAddr); Packet(const Packet& other); Packet(Packet&& other); diff --git a/libraries/networking/src/udt/PacketList.cpp b/libraries/networking/src/udt/PacketList.cpp index f6ea12242e..d29e79626b 100644 --- a/libraries/networking/src/udt/PacketList.cpp +++ b/libraries/networking/src/udt/PacketList.cpp @@ -4,6 +4,7 @@ // // Created by Clement on 7/13/15. // Copyright 2015 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -53,8 +54,8 @@ PacketList::PacketList(PacketList&& other) : { } -HifiSockAddr PacketList::getSenderSockAddr() const { - return _packets.size() > 0 ? _packets.front()->getSenderSockAddr() : HifiSockAddr(); +SockAddr PacketList::getSenderSockAddr() const { + return _packets.size() > 0 ? _packets.front()->getSenderSockAddr() : SockAddr(); } void PacketList::startSegment() { diff --git a/libraries/networking/src/udt/PacketList.h b/libraries/networking/src/udt/PacketList.h index 8d3ffb2783..af2adf1ddb 100644 --- a/libraries/networking/src/udt/PacketList.h +++ b/libraries/networking/src/udt/PacketList.h @@ -4,6 +4,7 @@ // // Created by Clement on 7/13/15. // Copyright 2015 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -50,7 +51,7 @@ public: virtual qint64 getMaxSegmentSize() const { return Packet::maxPayloadSize(_isOrdered); } - HifiSockAddr getSenderSockAddr() const; + SockAddr getSenderSockAddr() const; void closeCurrentPacket(bool shouldSendEmpty = false); diff --git a/libraries/networking/src/udt/SendQueue.cpp b/libraries/networking/src/udt/SendQueue.cpp index 63447f6e70..9bea47f89e 100644 --- a/libraries/networking/src/udt/SendQueue.cpp +++ b/libraries/networking/src/udt/SendQueue.cpp @@ -4,6 +4,7 @@ // // Created by Clement on 7/21/15. // Copyright 2015 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -65,7 +66,7 @@ private: const microseconds SendQueue::MAXIMUM_ESTIMATED_TIMEOUT = seconds(5); const microseconds SendQueue::MINIMUM_ESTIMATED_TIMEOUT = milliseconds(10); -std::unique_ptr SendQueue::create(Socket* socket, HifiSockAddr destination, SequenceNumber currentSequenceNumber, +std::unique_ptr SendQueue::create(Socket* socket, SockAddr destination, SequenceNumber currentSequenceNumber, MessageNumber currentMessageNumber, bool hasReceivedHandshakeACK) { Q_ASSERT_X(socket, "SendQueue::create", "Must be called with a valid Socket*"); @@ -91,7 +92,7 @@ std::unique_ptr SendQueue::create(Socket* socket, HifiSockAddr destin return queue; } -SendQueue::SendQueue(Socket* socket, HifiSockAddr dest, SequenceNumber currentSequenceNumber, +SendQueue::SendQueue(Socket* socket, SockAddr dest, SequenceNumber currentSequenceNumber, MessageNumber currentMessageNumber, bool hasReceivedHandshakeACK) : _packets(currentMessageNumber), _socket(socket), @@ -561,6 +562,6 @@ bool SendQueue::isFlowWindowFull() const { return seqlen(SequenceNumber { (uint32_t) _lastACKSequenceNumber }, _currentSequenceNumber) > _flowWindowSize; } -void SendQueue::updateDestinationAddress(HifiSockAddr newAddress) { +void SendQueue::updateDestinationAddress(SockAddr newAddress) { _destination = newAddress; } diff --git a/libraries/networking/src/udt/SendQueue.h b/libraries/networking/src/udt/SendQueue.h index 2153745250..ef3ad8bd16 100644 --- a/libraries/networking/src/udt/SendQueue.h +++ b/libraries/networking/src/udt/SendQueue.h @@ -4,6 +4,7 @@ // // Created by Clement on 7/21/15. // Copyright 2015 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -25,7 +26,7 @@ #include -#include "../HifiSockAddr.h" +#include "../SockAddr.h" #include "Constants.h" #include "PacketQueue.h" @@ -50,7 +51,7 @@ public: Stopped }; - static std::unique_ptr create(Socket* socket, HifiSockAddr destination, + static std::unique_ptr create(Socket* socket, SockAddr destination, SequenceNumber currentSequenceNumber, MessageNumber currentMessageNumber, bool hasReceivedHandshakeACK); @@ -75,7 +76,7 @@ public slots: void ack(SequenceNumber ack); void fastRetransmit(SequenceNumber ack); void handshakeACK(); - void updateDestinationAddress(HifiSockAddr newAddress); + void updateDestinationAddress(SockAddr newAddress); signals: void packetSent(int wireSize, int payloadSize, SequenceNumber seqNum, p_high_resolution_clock::time_point timePoint); @@ -89,7 +90,7 @@ private slots: void run(); private: - SendQueue(Socket* socket, HifiSockAddr dest, SequenceNumber currentSequenceNumber, + SendQueue(Socket* socket, SockAddr dest, SequenceNumber currentSequenceNumber, MessageNumber currentMessageNumber, bool hasReceivedHandshakeACK); SendQueue(SendQueue& other) = delete; SendQueue(SendQueue&& other) = delete; @@ -113,7 +114,7 @@ private: PacketQueue _packets; Socket* _socket { nullptr }; // Socket to send packet on - HifiSockAddr _destination; // Destination addr + SockAddr _destination; // Destination addr std::atomic _lastACKSequenceNumber { 0 }; // Last ACKed sequence number diff --git a/libraries/networking/src/udt/Socket.cpp b/libraries/networking/src/udt/Socket.cpp index 017855d628..241ca1db85 100644 --- a/libraries/networking/src/udt/Socket.cpp +++ b/libraries/networking/src/udt/Socket.cpp @@ -4,6 +4,7 @@ // // Created by Stephen Birarda on 2015-07-20. // Copyright 2015 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -123,7 +124,7 @@ void Socket::setSystemBufferSizes() { } } -qint64 Socket::writeBasePacket(const udt::BasePacket& packet, const HifiSockAddr &sockAddr) { +qint64 Socket::writeBasePacket(const udt::BasePacket& packet, const SockAddr &sockAddr) { // Since this is a base packet we have no way to know if this is reliable or not - we just fire it off // this should not be called with an instance of Packet @@ -133,7 +134,7 @@ qint64 Socket::writeBasePacket(const udt::BasePacket& packet, const HifiSockAddr return writeDatagram(packet.getData(), packet.getDataSize(), sockAddr); } -qint64 Socket::writePacket(const Packet& packet, const HifiSockAddr& sockAddr) { +qint64 Socket::writePacket(const Packet& packet, const SockAddr& sockAddr) { Q_ASSERT_X(!packet.isReliable(), "Socket::writePacket", "Cannot send a reliable packet unreliably"); SequenceNumber sequenceNumber; @@ -154,7 +155,7 @@ qint64 Socket::writePacket(const Packet& packet, const HifiSockAddr& sockAddr) { return writeDatagram(packet.getData(), packet.getDataSize(), sockAddr); } -qint64 Socket::writePacket(std::unique_ptr packet, const HifiSockAddr& sockAddr) { +qint64 Socket::writePacket(std::unique_ptr packet, const SockAddr& sockAddr) { if (packet->isReliable()) { // hand this packet off to writeReliablePacket @@ -163,7 +164,7 @@ qint64 Socket::writePacket(std::unique_ptr packet, const HifiSockAddr& s if (QThread::currentThread() != thread()) { QMetaObject::invokeMethod(this, "writeReliablePacket", Qt::QueuedConnection, Q_ARG(Packet*, packet.release()), - Q_ARG(HifiSockAddr, sockAddr)); + Q_ARG(SockAddr, sockAddr)); } else { writeReliablePacket(packet.release(), sockAddr); } @@ -174,7 +175,7 @@ qint64 Socket::writePacket(std::unique_ptr packet, const HifiSockAddr& s return writePacket(*packet, sockAddr); } -qint64 Socket::writePacketList(std::unique_ptr packetList, const HifiSockAddr& sockAddr) { +qint64 Socket::writePacketList(std::unique_ptr packetList, const SockAddr& sockAddr) { if (packetList->getNumPackets() == 0) { qCWarning(networking) << "Trying to send packet list with 0 packets, bailing."; @@ -189,7 +190,7 @@ qint64 Socket::writePacketList(std::unique_ptr packetList, const Hif auto ptr = packetList.release(); QMetaObject::invokeMethod(this, "writeReliablePacketList", Qt::AutoConnection, Q_ARG(PacketList*, ptr), - Q_ARG(HifiSockAddr, sockAddr)); + Q_ARG(SockAddr, sockAddr)); } else { writeReliablePacketList(packetList.release(), sockAddr); } @@ -205,7 +206,7 @@ qint64 Socket::writePacketList(std::unique_ptr packetList, const Hif return totalBytesSent; } -void Socket::writeReliablePacket(Packet* packet, const HifiSockAddr& sockAddr) { +void Socket::writeReliablePacket(Packet* packet, const SockAddr& sockAddr) { auto connection = findOrCreateConnection(sockAddr); if (connection) { connection->sendReliablePacket(std::unique_ptr(packet)); @@ -218,7 +219,7 @@ void Socket::writeReliablePacket(Packet* packet, const HifiSockAddr& sockAddr) { } -void Socket::writeReliablePacketList(PacketList* packetList, const HifiSockAddr& sockAddr) { +void Socket::writeReliablePacketList(PacketList* packetList, const SockAddr& sockAddr) { auto connection = findOrCreateConnection(sockAddr); if (connection) { connection->sendReliablePacketList(std::unique_ptr(packetList)); @@ -230,11 +231,11 @@ void Socket::writeReliablePacketList(PacketList* packetList, const HifiSockAddr& #endif } -qint64 Socket::writeDatagram(const char* data, qint64 size, const HifiSockAddr& sockAddr) { +qint64 Socket::writeDatagram(const char* data, qint64 size, const SockAddr& sockAddr) { return writeDatagram(QByteArray::fromRawData(data, size), sockAddr); } -qint64 Socket::writeDatagram(const QByteArray& datagram, const HifiSockAddr& sockAddr) { +qint64 Socket::writeDatagram(const QByteArray& datagram, const SockAddr& sockAddr) { // don't attempt to write the datagram if we're unbound. Just drop it. // _udpSocket.writeDatagram will return an error anyway, but there are @@ -270,7 +271,7 @@ qint64 Socket::writeDatagram(const QByteArray& datagram, const HifiSockAddr& soc return bytesWritten; } -Connection* Socket::findOrCreateConnection(const HifiSockAddr& sockAddr, bool filterCreate) { +Connection* Socket::findOrCreateConnection(const SockAddr& sockAddr, bool filterCreate) { Lock connectionsLock(_connectionsHashMutex); auto it = _connectionsHash.find(sockAddr); @@ -319,7 +320,7 @@ void Socket::clearConnections() { } } -void Socket::cleanupConnection(HifiSockAddr sockAddr) { +void Socket::cleanupConnection(SockAddr sockAddr) { Lock connectionsLock(_connectionsHashMutex); auto numErased = _connectionsHash.erase(sockAddr); @@ -390,8 +391,8 @@ void Socket::readPendingDatagrams() { // grab a time point we can mark as the receive time of this packet auto receiveTime = p_high_resolution_clock::now(); - // setup a HifiSockAddr to read into - HifiSockAddr senderSockAddr; + // setup a SockAddr to read into + SockAddr senderSockAddr; // setup a buffer to read the packet into auto buffer = std::unique_ptr(new char[packetSizeWithHeader]); @@ -413,7 +414,7 @@ void Socket::readPendingDatagrams() { auto it = _unfilteredHandlers.find(senderSockAddr); if (it != _unfilteredHandlers.end()) { - // we have a registered unfiltered handler for this HifiSockAddr - call that and return + // we have a registered unfiltered handler for this SockAddr - call that and return if (it->second) { auto basePacket = BasePacket::fromReceivedPacket(std::move(buffer), packetSizeWithHeader, senderSockAddr); basePacket->setReceiveTime(receiveTime); @@ -482,7 +483,7 @@ void Socket::readPendingDatagrams() { } } -void Socket::connectToSendSignal(const HifiSockAddr& destinationAddr, QObject* receiver, const char* slot) { +void Socket::connectToSendSignal(const SockAddr& destinationAddr, QObject* receiver, const char* slot) { Lock connectionsLock(_connectionsHashMutex); auto it = _connectionsHash.find(destinationAddr); if (it != _connectionsHash.end()) { @@ -507,7 +508,7 @@ void Socket::setConnectionMaxBandwidth(int maxBandwidth) { } } -ConnectionStats::Stats Socket::sampleStatsForConnection(const HifiSockAddr& destination) { +ConnectionStats::Stats Socket::sampleStatsForConnection(const SockAddr& destination) { auto it = _connectionsHash.find(destination); if (it != _connectionsHash.end()) { return it->second->sampleStats(); @@ -528,8 +529,8 @@ Socket::StatsVector Socket::sampleStatsForAllConnections() { } -std::vector Socket::getConnectionSockAddrs() { - std::vector addr; +std::vector Socket::getConnectionSockAddrs() { + std::vector addr; Lock connectionsLock(_connectionsHashMutex); addr.reserve(_connectionsHash.size()); @@ -569,7 +570,7 @@ void Socket::handleStateChanged(QAbstractSocket::SocketState socketState) { } } -void Socket::handleRemoteAddressChange(HifiSockAddr previousAddress, HifiSockAddr currentAddress) { +void Socket::handleRemoteAddressChange(SockAddr previousAddress, SockAddr currentAddress) { { Lock connectionsLock(_connectionsHashMutex); @@ -597,7 +598,7 @@ void Socket::handleRemoteAddressChange(HifiSockAddr previousAddress, HifiSockAdd #if (PR_BUILD || DEV_BUILD) -void Socket::sendFakedHandshakeRequest(const HifiSockAddr& sockAddr) { +void Socket::sendFakedHandshakeRequest(const SockAddr& sockAddr) { auto connection = findOrCreateConnection(sockAddr); if (connection) { connection->sendHandshakeRequest(); diff --git a/libraries/networking/src/udt/Socket.h b/libraries/networking/src/udt/Socket.h index 6cd2d25659..8c46a22335 100644 --- a/libraries/networking/src/udt/Socket.h +++ b/libraries/networking/src/udt/Socket.h @@ -4,6 +4,7 @@ // // Created by Stephen Birarda on 2015-07-20. // Copyright 2015 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -23,7 +24,7 @@ #include #include -#include "../HifiSockAddr.h" +#include "../SockAddr.h" #include "TCPVegasCC.h" #include "Connection.h" @@ -39,12 +40,12 @@ class PacketList; class SequenceNumber; using PacketFilterOperator = std::function; -using ConnectionCreationFilterOperator = std::function; +using ConnectionCreationFilterOperator = std::function; using BasePacketHandler = std::function)>; using PacketHandler = std::function)>; using MessageHandler = std::function)>; -using MessageFailureHandler = std::function; +using MessageFailureHandler = std::function; class Socket : public QObject { Q_OBJECT @@ -53,19 +54,19 @@ class Socket : public QObject { using Lock = std::unique_lock; public: - using StatsVector = std::vector>; + using StatsVector = std::vector>; Socket(QObject* object = 0, bool shouldChangeSocketOptions = true); quint16 localPort() const { return _udpSocket.localPort(); } // Simple functions writing to the socket with no processing - qint64 writeBasePacket(const BasePacket& packet, const HifiSockAddr& sockAddr); - qint64 writePacket(const Packet& packet, const HifiSockAddr& sockAddr); - qint64 writePacket(std::unique_ptr packet, const HifiSockAddr& sockAddr); - qint64 writePacketList(std::unique_ptr packetList, const HifiSockAddr& sockAddr); - qint64 writeDatagram(const char* data, qint64 size, const HifiSockAddr& sockAddr); - qint64 writeDatagram(const QByteArray& datagram, const HifiSockAddr& sockAddr); + qint64 writeBasePacket(const BasePacket& packet, const SockAddr& sockAddr); + qint64 writePacket(const Packet& packet, const SockAddr& sockAddr); + qint64 writePacket(std::unique_ptr packet, const SockAddr& sockAddr); + qint64 writePacketList(std::unique_ptr packetList, const SockAddr& sockAddr); + qint64 writeDatagram(const char* data, qint64 size, const SockAddr& sockAddr); + qint64 writeDatagram(const QByteArray& datagram, const SockAddr& sockAddr); void bind(const QHostAddress& address, quint16 port = 0); void rebind(quint16 port); @@ -78,7 +79,7 @@ public: void setConnectionCreationFilterOperator(ConnectionCreationFilterOperator filterOperator) { _connectionCreationFilterOperator = filterOperator; } - void addUnfilteredHandler(const HifiSockAddr& senderSockAddr, BasePacketHandler handler) + void addUnfilteredHandler(const SockAddr& senderSockAddr, BasePacketHandler handler) { _unfilteredHandlers[senderSockAddr] = handler; } void setCongestionControlFactory(std::unique_ptr ccFactory); @@ -90,16 +91,16 @@ public: StatsVector sampleStatsForAllConnections(); #if (PR_BUILD || DEV_BUILD) - void sendFakedHandshakeRequest(const HifiSockAddr& sockAddr); + void sendFakedHandshakeRequest(const SockAddr& sockAddr); #endif signals: - void clientHandshakeRequestComplete(const HifiSockAddr& sockAddr); + void clientHandshakeRequestComplete(const SockAddr& sockAddr); public slots: - void cleanupConnection(HifiSockAddr sockAddr); + void cleanupConnection(SockAddr sockAddr); void clearConnections(); - void handleRemoteAddressChange(HifiSockAddr previousAddress, HifiSockAddr currentAddress); + void handleRemoteAddressChange(SockAddr previousAddress, SockAddr currentAddress); private slots: void readPendingDatagrams(); @@ -110,16 +111,16 @@ private slots: private: void setSystemBufferSizes(); - Connection* findOrCreateConnection(const HifiSockAddr& sockAddr, bool filterCreation = false); + Connection* findOrCreateConnection(const SockAddr& sockAddr, bool filterCreation = false); // privatized methods used by UDTTest - they are private since they must be called on the Socket thread - ConnectionStats::Stats sampleStatsForConnection(const HifiSockAddr& destination); + ConnectionStats::Stats sampleStatsForConnection(const SockAddr& destination); - std::vector getConnectionSockAddrs(); - void connectToSendSignal(const HifiSockAddr& destinationAddr, QObject* receiver, const char* slot); + std::vector getConnectionSockAddrs(); + void connectToSendSignal(const SockAddr& destinationAddr, QObject* receiver, const char* slot); - Q_INVOKABLE void writeReliablePacket(Packet* packet, const HifiSockAddr& sockAddr); - Q_INVOKABLE void writeReliablePacketList(PacketList* packetList, const HifiSockAddr& sockAddr); + Q_INVOKABLE void writeReliablePacket(Packet* packet, const SockAddr& sockAddr); + Q_INVOKABLE void writeReliablePacketList(PacketList* packetList, const SockAddr& sockAddr); QUdpSocket _udpSocket { this }; PacketFilterOperator _packetFilterOperator; @@ -131,9 +132,9 @@ private: Mutex _unreliableSequenceNumbersMutex; Mutex _connectionsHashMutex; - std::unordered_map _unfilteredHandlers; - std::unordered_map _unreliableSequenceNumbers; - std::unordered_map> _connectionsHash; + std::unordered_map _unfilteredHandlers; + std::unordered_map _unreliableSequenceNumbers; + std::unordered_map> _connectionsHash; QTimer* _readyReadBackupTimer { nullptr }; @@ -145,7 +146,7 @@ private: int _lastPacketSizeRead { 0 }; SequenceNumber _lastReceivedSequenceNumber; - HifiSockAddr _lastPacketSockAddr; + SockAddr _lastPacketSockAddr; friend UDTTest; }; diff --git a/tests/networking/src/PacketTests.cpp b/tests/networking/src/PacketTests.cpp index 589c5f4302..1b13a38488 100644 --- a/tests/networking/src/PacketTests.cpp +++ b/tests/networking/src/PacketTests.cpp @@ -4,6 +4,7 @@ // // Created by Stephen Birarda on 07/14/15. // Copyright 2015 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -20,7 +21,7 @@ std::unique_ptr copyToReadPacket(std::unique_ptr& packet) { auto size = packet->getDataSize(); auto data = std::unique_ptr(new char[size]); memcpy(data.get(), packet->getData(), size); - return NLPacket::fromReceivedPacket(std::move(data), size, HifiSockAddr()); + return NLPacket::fromReceivedPacket(std::move(data), size, SockAddr()); } void PacketTests::emptyPacketTest() { diff --git a/tools/ice-client/src/ICEClientApp.cpp b/tools/ice-client/src/ICEClientApp.cpp index 0301fad6f4..1b342b2466 100644 --- a/tools/ice-client/src/ICEClientApp.cpp +++ b/tools/ice-client/src/ICEClientApp.cpp @@ -4,6 +4,7 @@ // // Created by Seth Alves on 3/5/15. // Copyright 2015 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -62,7 +63,7 @@ ICEClientApp::ICEClientApp(int argc, char* argv[]) : const_cast(&networking())->setEnabled(QtWarningMsg, false); } - _stunSockAddr = HifiSockAddr(STUN_SERVER_HOSTNAME, STUN_SERVER_PORT, true); + _stunSockAddr = SockAddr(STUN_SERVER_HOSTNAME, STUN_SERVER_PORT, true); _cacheSTUNResult = parser.isSet(cacheSTUNOption); @@ -79,7 +80,7 @@ ICEClientApp::ICEClientApp(int argc, char* argv[]) : } } - _iceServerAddr = HifiSockAddr("127.0.0.1", ICE_SERVER_DEFAULT_PORT); + _iceServerAddr = SockAddr("127.0.0.1", ICE_SERVER_DEFAULT_PORT); if (parser.isSet(iceServerAddressOption)) { // parse the IP and port combination for this target QString hostnamePortString = parser.value(iceServerAddressOption); @@ -96,7 +97,7 @@ ICEClientApp::ICEClientApp(int argc, char* argv[]) : QMetaObject::invokeMethod(this, "quit", Qt::QueuedConnection); } else { - _iceServerAddr = HifiSockAddr(address, port); + _iceServerAddr = SockAddr(address, port); } } @@ -142,8 +143,8 @@ void ICEClientApp::openSocket() { if (_verbose) { qDebug() << "local port is" << _socket->localPort(); } - _localSockAddr = HifiSockAddr("127.0.0.1", _socket->localPort()); - _publicSockAddr = HifiSockAddr("127.0.0.1", _socket->localPort()); + _localSockAddr = SockAddr("127.0.0.1", _socket->localPort()); + _publicSockAddr = SockAddr("127.0.0.1", _socket->localPort()); _domainPingCount = 0; } @@ -238,7 +239,7 @@ void ICEClientApp::stunResponseTimeout() { QCoreApplication::exit(stunFailureExitStatus); } -void ICEClientApp::sendPacketToIceServer(PacketType packetType, const HifiSockAddr& iceServerSockAddr, +void ICEClientApp::sendPacketToIceServer(PacketType packetType, const SockAddr& iceServerSockAddr, const QUuid& clientID, const QUuid& peerID) { std::unique_ptr icePacket = NLPacket::create(packetType); @@ -303,7 +304,7 @@ void ICEClientApp::processSTUNResponse(std::unique_ptr packet) uint16_t newPublicPort; QHostAddress newPublicAddress; if (LimitedNodeList::parseSTUNResponse(packet.get(), newPublicAddress, newPublicPort)) { - _publicSockAddr = HifiSockAddr(newPublicAddress, newPublicPort); + _publicSockAddr = SockAddr(newPublicAddress, newPublicPort); if (_verbose) { qDebug() << "My public address is" << _publicSockAddr; } @@ -326,7 +327,7 @@ void ICEClientApp::processPacket(std::unique_ptr packet) { } QSharedPointer message = QSharedPointer::create(*nlPacket); - const HifiSockAddr& senderAddr = message->getSenderSockAddr(); + const SockAddr& senderAddr = message->getSenderSockAddr(); if (nlPacket->getType() == PacketType::ICEServerPeerInformation) { // cancel the timeout timer diff --git a/tools/ice-client/src/ICEClientApp.h b/tools/ice-client/src/ICEClientApp.h index 642b9bc36b..c541c99d0b 100644 --- a/tools/ice-client/src/ICEClientApp.h +++ b/tools/ice-client/src/ICEClientApp.h @@ -4,6 +4,7 @@ // // Created by Seth Alves on 2016-9-16 // Copyright 2016 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -54,7 +55,7 @@ private: void setState(int newState); void doSomething(); - void sendPacketToIceServer(PacketType packetType, const HifiSockAddr& iceServerSockAddr, + void sendPacketToIceServer(PacketType packetType, const SockAddr& iceServerSockAddr, const QUuid& clientID, const QUuid& peerID); void icePingDomainServer(); void processSTUNResponse(std::unique_ptr packet); @@ -65,7 +66,7 @@ private: bool _cacheSTUNResult; // should we only talk to stun server once? bool _stunResultSet { false }; // have we already talked to stun server? - HifiSockAddr _stunSockAddr; + SockAddr _stunSockAddr; unsigned int _actionCount { 0 }; unsigned int _actionMax { 0 }; @@ -75,10 +76,10 @@ private: QTimer* _pingDomainTimer { nullptr }; - HifiSockAddr _iceServerAddr; + SockAddr _iceServerAddr; - HifiSockAddr _localSockAddr; - HifiSockAddr _publicSockAddr; + SockAddr _localSockAddr; + SockAddr _publicSockAddr; udt::Socket* _socket { nullptr }; bool _domainServerPeerSet { false }; diff --git a/tools/udt-test/src/UDTTest.cpp b/tools/udt-test/src/UDTTest.cpp index 65bf2c7ebd..a546b61b96 100644 --- a/tools/udt-test/src/UDTTest.cpp +++ b/tools/udt-test/src/UDTTest.cpp @@ -4,6 +4,7 @@ // // Created by Stephen Birarda on 2015-07-30. // Copyright 2015 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -90,7 +91,7 @@ UDTTest::UDTTest(int& argc, char** argv) : QMetaObject::invokeMethod(this, "quit", Qt::QueuedConnection); } else { - _target = HifiSockAddr(address, port); + _target = SockAddr(address, port); qDebug() << "Packets will be sent to" << _target; } } @@ -198,7 +199,7 @@ UDTTest::UDTTest(int& argc, char** argv) : }); } _socket.setMessageFailureHandler( - [this](HifiSockAddr from, udt::Packet::MessageNumber messageNumber) { + [this](SockAddr from, udt::Packet::MessageNumber messageNumber) { _pendingMessages.erase(messageNumber); } ); diff --git a/tools/udt-test/src/UDTTest.h b/tools/udt-test/src/UDTTest.h index 3a4b1b897d..0202d75b38 100644 --- a/tools/udt-test/src/UDTTest.h +++ b/tools/udt-test/src/UDTTest.h @@ -4,6 +4,7 @@ // // Created by Stephen Birarda on 2015-07-30. // Copyright 2015 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -49,7 +50,7 @@ private: QCommandLineParser _argumentParser; udt::Socket _socket; - HifiSockAddr _target; // the target for sent packets + SockAddr _target; // the target for sent packets int _minPacketSize { udt::MAX_PACKET_SIZE }; int _maxPacketSize { udt::MAX_PACKET_SIZE };