Undo Visual Studio mis-formatting

This commit is contained in:
Roxanne Skelly 2019-06-12 11:43:43 -07:00
parent 8704a36d07
commit 6e6bd18baa
2 changed files with 68 additions and 91 deletions

View file

@ -126,7 +126,7 @@ void DomainGatekeeper::processConnectRequestPacket(QSharedPointer<ReceivedMessag
<< "with MAC" << nodeConnection.hardwareAddress << "with MAC" << nodeConnection.hardwareAddress
<< "and machine fingerprint" << nodeConnection.machineFingerprint << "and machine fingerprint" << nodeConnection.machineFingerprint
<< "user" << username << "user" << username
<< "reason" << QString(nodeConnection.connectReason ? "Silent Domain Disconnect" : "Connect") << "reason" << QString(nodeConnection.connectReason ? "SilentDomainDisconnect" : "Connect")
<< "previous connection uptime" << nodeConnection.previousConnectionUpTime/USECS_PER_MSEC << "msec"; << "previous connection uptime" << nodeConnection.previousConnectionUpTime/USECS_PER_MSEC << "msec";
// signal that we just connected a node so the DomainServer can get it a list // signal that we just connected a node so the DomainServer can get it a list

View file

@ -20,7 +20,7 @@
#include <unordered_map> #include <unordered_map>
#ifndef _WIN32 #ifndef _WIN32
#include <unistd.h> // not on windows, not needed for mac or windows #include <unistd.h> // not on windows, not needed for mac or windows
#endif #endif
#include <QtCore/QElapsedTimer> #include <QtCore/QElapsedTimer>
@ -51,7 +51,7 @@ const int INVALID_PORT = -1;
const quint64 NODE_SILENCE_THRESHOLD_MSECS = 10 * 1000; const quint64 NODE_SILENCE_THRESHOLD_MSECS = 10 * 1000;
static const size_t DEFAULT_MAX_CONNECTION_RATE{ std::numeric_limits<size_t>::max() }; static const size_t DEFAULT_MAX_CONNECTION_RATE { std::numeric_limits<size_t>::max() };
const char DEFAULT_ASSIGNMENT_SERVER_HOSTNAME[] = "localhost"; const char DEFAULT_ASSIGNMENT_SERVER_HOSTNAME[] = "localhost";
@ -67,26 +67,26 @@ const QHostAddress DEFAULT_ASSIGNMENT_CLIENT_MONITOR_HOSTNAME = QHostAddress::Lo
const QString USERNAME_UUID_REPLACEMENT_STATS_KEY = "$username"; const QString USERNAME_UUID_REPLACEMENT_STATS_KEY = "$username";
using ConnectionID = int64_t; using ConnectionID = int64_t;
const ConnectionID NULL_CONNECTION_ID{ -1 }; const ConnectionID NULL_CONNECTION_ID { -1 };
const ConnectionID INITIAL_CONNECTION_ID{ 0 }; const ConnectionID INITIAL_CONNECTION_ID { 0 };
typedef std::pair<QUuid, SharedNodePointer> UUIDNodePair; typedef std::pair<QUuid, SharedNodePointer> UUIDNodePair;
typedef tbb::concurrent_unordered_map<QUuid, SharedNodePointer, UUIDHasher> NodeHash; typedef tbb::concurrent_unordered_map<QUuid, SharedNodePointer, UUIDHasher> NodeHash;
typedef quint8 PingType_t; typedef quint8 PingType_t;
namespace PingType { namespace PingType {
const PingType_t Agnostic = 0; const PingType_t Agnostic = 0;
const PingType_t Local = 1; const PingType_t Local = 1;
const PingType_t Public = 2; const PingType_t Public = 2;
const PingType_t Symmetric = 3; const PingType_t Symmetric = 3;
} // namespace PingType }
class LimitedNodeList : public QObject, public Dependency { class LimitedNodeList : public QObject, public Dependency {
Q_OBJECT Q_OBJECT
SINGLETON_DEPENDENCY SINGLETON_DEPENDENCY
public: public:
enum ConnectionStep
{ enum ConnectionStep {
LookupAddress = 1, LookupAddress = 1,
HandleAddress, HandleAddress,
SendSTUNRequest, SendSTUNRequest,
@ -109,8 +109,7 @@ public:
Q_ENUM(ConnectionStep); Q_ENUM(ConnectionStep);
enum ConnectReason : quint32 enum ConnectReason : quint32 {
{
Connect = 0, Connect = 0,
SilentDomainDisconnect SilentDomainDisconnect
}; };
@ -125,18 +124,12 @@ public:
bool isAllowedEditor() const { return _permissions.can(NodePermissions::Permission::canAdjustLocks); } bool isAllowedEditor() const { return _permissions.can(NodePermissions::Permission::canAdjustLocks); }
bool getThisNodeCanRez() const { return _permissions.can(NodePermissions::Permission::canRezPermanentEntities); } bool getThisNodeCanRez() const { return _permissions.can(NodePermissions::Permission::canRezPermanentEntities); }
bool getThisNodeCanRezTmp() const { return _permissions.can(NodePermissions::Permission::canRezTemporaryEntities); } bool getThisNodeCanRezTmp() const { return _permissions.can(NodePermissions::Permission::canRezTemporaryEntities); }
bool getThisNodeCanRezCertified() const { bool getThisNodeCanRezCertified() const { return _permissions.can(NodePermissions::Permission::canRezPermanentCertifiedEntities); }
return _permissions.can(NodePermissions::Permission::canRezPermanentCertifiedEntities); bool getThisNodeCanRezTmpCertified() const { return _permissions.can(NodePermissions::Permission::canRezTemporaryCertifiedEntities); }
}
bool getThisNodeCanRezTmpCertified() const {
return _permissions.can(NodePermissions::Permission::canRezTemporaryCertifiedEntities);
}
bool getThisNodeCanWriteAssets() const { return _permissions.can(NodePermissions::Permission::canWriteToAssetServer); } bool getThisNodeCanWriteAssets() const { return _permissions.can(NodePermissions::Permission::canWriteToAssetServer); }
bool getThisNodeCanKick() const { return _permissions.can(NodePermissions::Permission::canKick); } bool getThisNodeCanKick() const { return _permissions.can(NodePermissions::Permission::canKick); }
bool getThisNodeCanReplaceContent() const { return _permissions.can(NodePermissions::Permission::canReplaceDomainContent); } bool getThisNodeCanReplaceContent() const { return _permissions.can(NodePermissions::Permission::canReplaceDomainContent); }
bool getThisNodeCanGetAndSetPrivateUserData() const { bool getThisNodeCanGetAndSetPrivateUserData() const { return _permissions.can(NodePermissions::Permission::canGetAndSetPrivateUserData); }
return _permissions.can(NodePermissions::Permission::canGetAndSetPrivateUserData);
}
quint16 getSocketLocalPort() const { return _nodeSocket.localPort(); } quint16 getSocketLocalPort() const { return _nodeSocket.localPort(); }
Q_INVOKABLE void setSocketLocalPort(quint16 socketLocalPort); Q_INVOKABLE void setSocketLocalPort(quint16 socketLocalPort);
@ -146,18 +139,9 @@ public:
PacketReceiver& getPacketReceiver() { return *_packetReceiver; } PacketReceiver& getPacketReceiver() { return *_packetReceiver; }
virtual bool isDomainServer() const { return true; } virtual bool isDomainServer() const { return true; }
virtual QUuid getDomainUUID() const { virtual QUuid getDomainUUID() const { assert(false); return QUuid(); }
assert(false); virtual Node::LocalID getDomainLocalID() const { assert(false); return Node::NULL_LOCAL_ID; }
return QUuid(); virtual HifiSockAddr getDomainSockAddr() const { assert(false); return HifiSockAddr(); }
}
virtual Node::LocalID getDomainLocalID() const {
assert(false);
return Node::NULL_LOCAL_ID;
}
virtual HifiSockAddr getDomainSockAddr() const {
assert(false);
return HifiSockAddr();
}
// use sendUnreliablePacket to send an unreliable packet (that you do not need to move) // 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 // either to a node (via its active socket) or to a manual sockaddr
@ -171,9 +155,8 @@ public:
// use sendUnreliableUnorderedPacketList to unreliably send separate packets from the packet list // use sendUnreliableUnorderedPacketList to unreliably send separate packets from the packet list
// either to a node's active socket or to a manual sockaddr // either to a node's active socket or to a manual sockaddr
qint64 sendUnreliableUnorderedPacketList(NLPacketList& packetList, const Node& destinationNode); qint64 sendUnreliableUnorderedPacketList(NLPacketList& packetList, const Node& destinationNode);
qint64 sendUnreliableUnorderedPacketList(NLPacketList& packetList, qint64 sendUnreliableUnorderedPacketList(NLPacketList& packetList, const HifiSockAddr& sockAddr,
const HifiSockAddr& sockAddr, HMACAuth* hmacAuth = nullptr);
HMACAuth* hmacAuth = nullptr);
// use sendPacketList to send reliable packet lists (ordered or unordered) to a node's active socket // use sendPacketList to send reliable packet lists (ordered or unordered) to a node's active socket
// or to a manual sock addr // or to a manual sock addr
@ -182,22 +165,15 @@ public:
std::function<void(Node*)> linkedDataCreateCallback; std::function<void(Node*)> linkedDataCreateCallback;
size_t size() const { size_t size() const { QReadLocker readLock(&_nodeMutex); return _nodeHash.size(); }
QReadLocker readLock(&_nodeMutex);
return _nodeHash.size();
}
SharedNodePointer nodeWithUUID(const QUuid& nodeUUID); SharedNodePointer nodeWithUUID(const QUuid& nodeUUID);
SharedNodePointer nodeWithLocalID(Node::LocalID localID) const; SharedNodePointer nodeWithLocalID(Node::LocalID localID) const;
SharedNodePointer addOrUpdateNode(const QUuid& uuid, SharedNodePointer addOrUpdateNode(const QUuid& uuid, NodeType_t nodeType,
NodeType_t nodeType, const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket,
const HifiSockAddr& publicSocket, Node::LocalID localID = Node::NULL_LOCAL_ID, bool isReplicated = false,
const HifiSockAddr& localSocket, bool isUpstream = false, const QUuid& connectionSecret = QUuid(),
Node::LocalID localID = Node::NULL_LOCAL_ID,
bool isReplicated = false,
bool isUpstream = false,
const QUuid& connectionSecret = QUuid(),
const NodePermissions& permissions = DEFAULT_AGENT_PERMISSIONS); const NodePermissions& permissions = DEFAULT_AGENT_PERMISSIONS);
static bool parseSTUNResponse(udt::BasePacket* packet, QHostAddress& newPublicAddress, uint16_t& newPublicPort); static bool parseSTUNResponse(udt::BasePacket* packet, QHostAddress& newPublicAddress, uint16_t& newPublicPort);
@ -232,7 +208,7 @@ public:
// Use this for nested loops instead of taking nested read locks! // Use this for nested loops instead of taking nested read locks!
// This allows multiple threads (i.e. a thread pool) to share a lock // This allows multiple threads (i.e. a thread pool) to share a lock
// without deadlocking when a dying node attempts to acquire a write lock // without deadlocking when a dying node attempts to acquire a write lock
template <typename NestedNodeLambda> template<typename NestedNodeLambda>
void nestedEach(NestedNodeLambda functor, void nestedEach(NestedNodeLambda functor,
int* lockWaitOut = nullptr, int* lockWaitOut = nullptr,
int* nodeTransformOut = nullptr, int* nodeTransformOut = nullptr,
@ -252,8 +228,9 @@ public:
// so reserve enough memory for the current size // so reserve enough memory for the current size
// and then back insert all the nodes found // and then back insert all the nodes found
nodes.reserve(_nodeHash.size()); nodes.reserve(_nodeHash.size());
std::transform(_nodeHash.cbegin(), _nodeHash.cend(), std::back_inserter(nodes), std::transform(_nodeHash.cbegin(), _nodeHash.cend(), std::back_inserter(nodes), [&](const NodeHash::value_type& it) {
[&](const NodeHash::value_type& it) { return it.second; }); return it.second;
});
endTransform = usecTimestampNow(); endTransform = usecTimestampNow();
if (nodeTransformOut) { if (nodeTransformOut) {
@ -268,7 +245,7 @@ public:
} }
} }
template <typename NodeLambda> template<typename NodeLambda>
void eachNode(NodeLambda functor) { void eachNode(NodeLambda functor) {
QReadLocker readLock(&_nodeMutex); QReadLocker readLock(&_nodeMutex);
@ -277,7 +254,7 @@ public:
} }
} }
template <typename PredLambda, typename NodeLambda> template<typename PredLambda, typename NodeLambda>
void eachMatchingNode(PredLambda predicate, NodeLambda functor) { void eachMatchingNode(PredLambda predicate, NodeLambda functor) {
QReadLocker readLock(&_nodeMutex); QReadLocker readLock(&_nodeMutex);
@ -288,7 +265,7 @@ public:
} }
} }
template <typename BreakableNodeLambda> template<typename BreakableNodeLambda>
void eachNodeBreakable(BreakableNodeLambda functor) { void eachNodeBreakable(BreakableNodeLambda functor) {
QReadLocker readLock(&_nodeMutex); QReadLocker readLock(&_nodeMutex);
@ -299,7 +276,7 @@ public:
} }
} }
template <typename PredLambda> template<typename PredLambda>
SharedNodePointer nodeMatchingPredicate(const PredLambda predicate) { SharedNodePointer nodeMatchingPredicate(const PredLambda predicate) {
QReadLocker readLock(&_nodeMutex); QReadLocker readLock(&_nodeMutex);
@ -315,7 +292,7 @@ public:
// This is unsafe because it does not take a lock // This is unsafe because it does not take a lock
// Must only be called when you know that a read lock on the node mutex is held // Must only be called when you know that a read lock on the node mutex is held
// and will be held for the duration of your iteration // and will be held for the duration of your iteration
template <typename NodeLambda> template<typename NodeLambda>
void unsafeEachNode(NodeLambda functor) { void unsafeEachNode(NodeLambda functor) {
for (NodeHash::const_iterator it = _nodeHash.cbegin(); it != _nodeHash.cend(); ++it) { for (NodeHash::const_iterator it = _nodeHash.cbegin(); it != _nodeHash.cend(); ++it) {
functor(it->second); functor(it->second);
@ -325,19 +302,15 @@ public:
void putLocalPortIntoSharedMemory(const QString key, QObject* parent, quint16 localPort); void putLocalPortIntoSharedMemory(const QString key, QObject* parent, quint16 localPort);
bool getLocalServerPortFromSharedMemory(const QString key, quint16& localPort); bool getLocalServerPortFromSharedMemory(const QString key, quint16& localPort);
const QMap<quint64, ConnectionStep> getLastConnectionTimes() const { const QMap<quint64, ConnectionStep> getLastConnectionTimes() const
QReadLocker readLock(&_connectionTimeLock); { QReadLocker readLock(&_connectionTimeLock); return _lastConnectionTimes; }
return _lastConnectionTimes;
}
void flagTimeForConnectionStep(ConnectionStep connectionStep); void flagTimeForConnectionStep(ConnectionStep connectionStep);
udt::Socket::StatsVector sampleStatsForAllConnections() { return _nodeSocket.sampleStatsForAllConnections(); } udt::Socket::StatsVector sampleStatsForAllConnections() { return _nodeSocket.sampleStatsForAllConnections(); }
void setConnectionMaxBandwidth(int maxBandwidth) { _nodeSocket.setConnectionMaxBandwidth(maxBandwidth); } void setConnectionMaxBandwidth(int maxBandwidth) { _nodeSocket.setConnectionMaxBandwidth(maxBandwidth); }
void setPacketFilterOperator(udt::PacketFilterOperator filterOperator) { void setPacketFilterOperator(udt::PacketFilterOperator filterOperator) { _nodeSocket.setPacketFilterOperator(filterOperator); }
_nodeSocket.setPacketFilterOperator(filterOperator);
}
bool packetVersionMatch(const udt::Packet& packet); bool packetVersionMatch(const udt::Packet& packet);
bool isPacketVerifiedWithSource(const udt::Packet& packet, Node* sourceNode = nullptr); bool isPacketVerifiedWithSource(const udt::Packet& packet, Node* sourceNode = nullptr);
@ -362,9 +335,14 @@ public:
float getInboundKbps() const { return _inboundKbps; } float getInboundKbps() const { return _inboundKbps; }
float getOutboundKbps() const { return _outboundKbps; } float getOutboundKbps() const { return _outboundKbps; }
const std::set<NodeType_t> SOLO_NODE_TYPES = const std::set<NodeType_t> SOLO_NODE_TYPES = {
{ NodeType::AvatarMixer, NodeType::AudioMixer, NodeType::AssetServer, NodeType::AvatarMixer,
NodeType::EntityServer, NodeType::MessagesMixer, NodeType::EntityScriptServer }; NodeType::AudioMixer,
NodeType::AssetServer,
NodeType::EntityServer,
NodeType::MessagesMixer,
NodeType::EntityScriptServer
};
public slots: public slots:
void reset(); void reset();
@ -428,10 +406,11 @@ protected:
}; };
LimitedNodeList(int socketListenPort = INVALID_PORT, int dtlsListenPort = INVALID_PORT); LimitedNodeList(int socketListenPort = INVALID_PORT, int dtlsListenPort = INVALID_PORT);
LimitedNodeList(LimitedNodeList const&) = delete; // Don't implement, needed to avoid copies of singleton LimitedNodeList(LimitedNodeList const&) = delete; // Don't implement, needed to avoid copies of singleton
void operator=(LimitedNodeList const&) = delete; // Don't implement, needed to avoid copies of singleton void operator=(LimitedNodeList const&) = delete; // Don't implement, needed to avoid copies of singleton
qint64 sendPacket(std::unique_ptr<NLPacket> packet, const Node& destinationNode, const HifiSockAddr& overridenSockAddr); qint64 sendPacket(std::unique_ptr<NLPacket> packet, const Node& destinationNode,
const HifiSockAddr& overridenSockAddr);
void fillPacketHeader(const NLPacket& packet, HMACAuth* hmacAuth = nullptr); void fillPacketHeader(const NLPacket& packet, HMACAuth* hmacAuth = nullptr);
void setLocalSocket(const HifiSockAddr& sockAddr); void setLocalSocket(const HifiSockAddr& sockAddr);
@ -443,9 +422,7 @@ protected:
void stopInitialSTUNUpdate(bool success); void stopInitialSTUNUpdate(bool success);
void sendPacketToIceServer(PacketType packetType, void sendPacketToIceServer(PacketType packetType, const HifiSockAddr& iceServerSockAddr, const QUuid& clientID,
const HifiSockAddr& iceServerSockAddr,
const QUuid& clientID,
const QUuid& peerRequestID = QUuid()); const QUuid& peerRequestID = QUuid());
bool sockAddrBelongsToNode(const HifiSockAddr& sockAddr); bool sockAddrBelongsToNode(const HifiSockAddr& sockAddr);
@ -456,14 +433,14 @@ protected:
bool isDelayedNode(QUuid nodeUUID); bool isDelayedNode(QUuid nodeUUID);
NodeHash _nodeHash; NodeHash _nodeHash;
mutable QReadWriteLock _nodeMutex{ QReadWriteLock::Recursive }; mutable QReadWriteLock _nodeMutex { QReadWriteLock::Recursive };
udt::Socket _nodeSocket; udt::Socket _nodeSocket;
QUdpSocket* _dtlsSocket{ nullptr }; QUdpSocket* _dtlsSocket { nullptr };
HifiSockAddr _localSockAddr; HifiSockAddr _localSockAddr;
HifiSockAddr _publicSockAddr; HifiSockAddr _publicSockAddr;
HifiSockAddr _stunSockAddr{ STUN_SERVER_HOSTNAME, STUN_SERVER_PORT }; HifiSockAddr _stunSockAddr { STUN_SERVER_HOSTNAME, STUN_SERVER_PORT };
bool _hasTCPCheckedLocalSocket{ false }; bool _hasTCPCheckedLocalSocket { false };
bool _useAuthentication{ true }; bool _useAuthentication { true };
PacketReceiver* _packetReceiver; PacketReceiver* _packetReceiver;
@ -476,11 +453,11 @@ protected:
quint64 _firstSTUNTime = 0; quint64 _firstSTUNTime = 0;
quint64 _publicSocketUpdateTime = 0; quint64 _publicSocketUpdateTime = 0;
mutable QReadWriteLock _connectionTimeLock{}; mutable QReadWriteLock _connectionTimeLock { };
QMap<quint64, ConnectionStep> _lastConnectionTimes; QMap<quint64, ConnectionStep> _lastConnectionTimes;
bool _areConnectionTimesComplete = false; bool _areConnectionTimesComplete = false;
template <typename IteratorLambda> template<typename IteratorLambda>
void eachNodeHashIterator(IteratorLambda functor) { void eachNodeHashIterator(IteratorLambda functor) {
QWriteLocker writeLock(&_nodeMutex); QWriteLocker writeLock(&_nodeMutex);
NodeHash::iterator it = _nodeHash.begin(); NodeHash::iterator it = _nodeHash.begin();
@ -498,24 +475,24 @@ protected:
private slots: private slots:
void flagTimeForConnectionStep(ConnectionStep connectionStep, quint64 timestamp); void flagTimeForConnectionStep(ConnectionStep connectionStep, quint64 timestamp);
void possiblyTimeoutSTUNAddressLookup(); void possiblyTimeoutSTUNAddressLookup();
void addSTUNHandlerToUnfiltered(); // called once STUN socket known void addSTUNHandlerToUnfiltered(); // called once STUN socket known
private: private:
mutable QReadWriteLock _sessionUUIDLock; mutable QReadWriteLock _sessionUUIDLock;
QUuid _sessionUUID; QUuid _sessionUUID;
using LocalIDMapping = tbb::concurrent_unordered_map<Node::LocalID, SharedNodePointer>; using LocalIDMapping = tbb::concurrent_unordered_map<Node::LocalID, SharedNodePointer>;
LocalIDMapping _localIDMap; LocalIDMapping _localIDMap;
Node::LocalID _sessionLocalID{ 0 }; Node::LocalID _sessionLocalID { 0 };
bool _flagTimeForConnectionStep{ false }; // only keep track in interface bool _flagTimeForConnectionStep { false }; // only keep track in interface
size_t _maxConnectionRate{ DEFAULT_MAX_CONNECTION_RATE }; size_t _maxConnectionRate { DEFAULT_MAX_CONNECTION_RATE };
size_t _nodesAddedInCurrentTimeSlice{ 0 }; size_t _nodesAddedInCurrentTimeSlice { 0 };
std::vector<NewNodeInfo> _delayedNodeAdds; std::vector<NewNodeInfo> _delayedNodeAdds;
int _inboundPPS{ 0 }; int _inboundPPS { 0 };
int _outboundPPS{ 0 }; int _outboundPPS { 0 };
float _inboundKbps{ 0.0f }; float _inboundKbps { 0.0f };
float _outboundKbps{ 0.0f }; float _outboundKbps { 0.0f };
}; };
#endif // hifi_LimitedNodeList_h #endif // hifi_LimitedNodeList_h