2022-05-10 10:06:48 +00:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
#include "connectionmanager.h"
|
|
|
|
|
|
|
|
#include <QByteArray>
|
|
|
|
#include <QDateTime>
|
|
|
|
|
|
|
|
static const int MaxConnections = 250;
|
|
|
|
|
|
|
|
Q_GLOBAL_STATIC(ConnectionManager, connectionManager)
|
|
|
|
|
|
|
|
ConnectionManager *ConnectionManager::instance()
|
|
|
|
{
|
|
|
|
return connectionManager();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ConnectionManager::canAddConnection() const
|
|
|
|
{
|
|
|
|
return (connections.size() < MaxConnections);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectionManager::addConnection(PeerWireClient *client)
|
|
|
|
{
|
|
|
|
connections << client;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectionManager::removeConnection(PeerWireClient *client)
|
|
|
|
{
|
|
|
|
connections.remove(client);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ConnectionManager::maxConnections() const
|
|
|
|
{
|
|
|
|
return MaxConnections;
|
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray ConnectionManager::clientId() const
|
|
|
|
{
|
|
|
|
if (id.isEmpty()) {
|
|
|
|
// Generate peer id
|
2016-06-21 21:27:48 +00:00
|
|
|
qint64 startupTime = QDateTime::currentSecsSinceEpoch();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2016-07-02 00:49:26 +00:00
|
|
|
id += QString::asprintf("-QT%04x-", QT_VERSION >> 8).toLatin1();
|
2011-04-27 10:05:43 +00:00
|
|
|
id += QByteArray::number(startupTime, 10);
|
|
|
|
id += QByteArray(20 - id.size(), '-');
|
|
|
|
}
|
|
|
|
return id;
|
|
|
|
}
|