1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

refactor(bootstrap): Rename UDP port from port to udpPort

This commit is contained in:
Anthony Bilinski 2022-02-15 14:21:16 -08:00
parent 2f92a5f2f0
commit 3d36cf47e8
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
4 changed files with 12 additions and 13 deletions

View File

@ -828,7 +828,6 @@ void Core::bootstrapDht()
// i think the more we bootstrap, the more we jitter because the more we overwrite nodes
while (i < 2) {
const DhtServer& dhtServer = bootstrapNodesList[j % listSize];
QString port = QString::number(dhtServer.port);
qDebug("Connecting to bootstrap node %d", j % listSize);
QByteArray address;
@ -843,11 +842,11 @@ void Core::bootstrapDht()
Tox_Err_Bootstrap error;
if (dhtServer.statusUdp) {
tox_bootstrap(tox.get(), address.constData(), dhtServer.port, pkPtr, &error);
tox_bootstrap(tox.get(), address.constData(), dhtServer.udpPort, pkPtr, &error);
PARSE_ERR(error);
}
if (dhtServer.statusTcp) {
tox_add_tcp_relay(tox.get(), address.constData(), dhtServer.port, pkPtr, &error);
tox_add_tcp_relay(tox.get(), address.constData(), dhtServer.udpPort, pkPtr, &error);
PARSE_ERR(error);
}

View File

@ -33,7 +33,7 @@ bool DhtServer::operator==(const DhtServer& other) const
&& ipv6 == other.ipv6
&& maintainer == other.maintainer
&& userId == other.userId
&& port == other.port);
&& udpPort == other.udpPort);
}
/**

View File

@ -29,7 +29,7 @@ struct DhtServer
QString ipv6;
QString maintainer;
QString userId;
quint16 port;
quint16 udpPort;
bool operator==(const DhtServer& other) const;
bool operator!=(const DhtServer& other) const;

View File

@ -36,11 +36,11 @@ const QLatin1String status_tcp{"status_tcp"};
const QLatin1String ipv4{"ipv4"};
const QLatin1String ipv6{"ipv6"};
const QLatin1String public_key{"public_key"};
const QLatin1String port{"port"};
const QLatin1String udp_port{"port"};
const QLatin1String maintainer{"maintainer"};
// TODO(sudden6): make use of this field once we differentiate between TCP nodes, and bootstrap nodes
const QLatin1String tcp_ports{"tcp_ports"};
const QStringList neededFields{status_udp, status_tcp, ipv4, ipv6, public_key, port, maintainer};
const QStringList neededFields{status_udp, status_tcp, ipv4, ipv6, public_key, udp_port, maintainer};
} // namespace NodeFields
namespace {
@ -69,7 +69,7 @@ void jsonNodeToDhtServer(const QJsonObject& node, QList<DhtServer>& outList)
}
const QString public_key = node[NodeFields::public_key].toString({});
const int port = node[NodeFields::port].toInt(-1);
const auto udp_port = node[NodeFields::udp_port].toInt(-1);
// nodes.tox.chat doesn't use empty strings for empty addresses
QString ipv6_address = node[NodeFields::ipv6].toString({});
@ -88,11 +88,11 @@ void jsonNodeToDhtServer(const QJsonObject& node, QList<DhtServer>& outList)
const QString maintainer = node[NodeFields::maintainer].toString({});
if (port < 1 || port > std::numeric_limits<uint16_t>::max()) {
qDebug() << "Invalid port in nodes list:" << port;
if (udp_port < 1 || udp_port > std::numeric_limits<uint16_t>::max()) {
qDebug() << "Invalid port in nodes list:" << udp_port;
return;
}
const quint16 port_u16 = static_cast<quint16>(port);
const quint16 udp_port_u16 = static_cast<quint16>(udp_port);
if (!public_key.contains(ToxPkRegEx)) {
qDebug() << "Invalid public key in nodes list" << public_key;
@ -103,7 +103,7 @@ void jsonNodeToDhtServer(const QJsonObject& node, QList<DhtServer>& outList)
server.statusUdp = true;
server.statusTcp = node[NodeFields::status_udp].toBool(false);
server.userId = public_key;
server.port = port_u16;
server.udpPort = udp_port_u16;
server.maintainer = maintainer;
server.ipv4 = ipv4_address;
server.ipv6 = ipv6_address;
@ -165,7 +165,7 @@ QByteArray serialize(QList<DhtServer> nodes)
nodeJson.insert(NodeFields::ipv4, node.ipv4);
nodeJson.insert(NodeFields::ipv6, node.ipv6);
nodeJson.insert(NodeFields::public_key, node.userId);
nodeJson.insert(NodeFields::port, node.port);
nodeJson.insert(NodeFields::udp_port, node.udpPort);
nodeJson.insert(NodeFields::maintainer, node.maintainer);
jsonNodes.append(nodeJson);
}