From 6722d31a12ee9ff88e413261d02b924403e11587 Mon Sep 17 00:00:00 2001 From: OfficialR3ido101 Date: Tue, 14 Nov 2023 19:50:55 +0000 Subject: [PATCH 1/2] Added command line and setting address and port --- ice-server/src/IceServer.cpp | 43 +++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/ice-server/src/IceServer.cpp b/ice-server/src/IceServer.cpp index ee610edce4..9a47a483f9 100644 --- a/ice-server/src/IceServer.cpp +++ b/ice-server/src/IceServer.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -39,9 +40,45 @@ IceServer::IceServer(int argc, char* argv[]) : _serverSocket(0, false), _activePeers() { - // start the ice-server socket - qDebug() << "ice-server socket is listening on" << ICE_SERVER_DEFAULT_PORT; - _serverSocket.bind(SocketType::UDP, QHostAddress::AnyIPv4, ICE_SERVER_DEFAULT_PORT); + // parse command-line + QCommandLineParser parser; + + const QCommandLineOption helpOption = parser.addHelpOption(); + + const QCommandLineOption addressOption("address", "Ice listen address.", "address"); + parser.addOption(addressOption); + + const QCommandLineOption portOption("port", "Port for the ICE server to listen on", "port"); + parser.addOption(portOption); + + if (!parser.parse(QCoreApplication::arguments())) { + qCritical() << parser.errorText() << Qt::endl; + parser.showHelp(); + Q_UNREACHABLE(); + } + + if (parser.isSet(helpOption)) { + parser.showHelp(); + Q_UNREACHABLE(); + } + + QHostAddress address = QHostAddress::AnyIPv4; + if (parser.isSet(addressOption)) { + if (parser.value(addressOption) == "0.0.0.0") { + QHostAddress address = QHostAddress::AnyIPv4; + } else { + address.setAddress(parser.value(addressOption)); + } + } + + // set the port + quint16 port = ICE_SERVER_DEFAULT_PORT; + if (parser.isSet(portOption)) { + port = parser.value(portOption).toInt(); + } + + _serverSocket.bind(SocketType::UDP, address, port); + qDebug() << "ice-server socket is listening on address: " << address.toString() << ":" << port; // set processPacket as the verified packet callback for the udt::Socket _serverSocket.setPacketHandler([this](std::unique_ptr packet) { processPacket(std::move(packet)); }); From 955f4dbc3ec66ca961d9c7579cda69707d434dbd Mon Sep 17 00:00:00 2001 From: OfficialR3ido101 Date: Tue, 14 Nov 2023 20:52:27 +0000 Subject: [PATCH 2/2] Added logging to ice server and ice testing script. --- ice-server/src/IceServer.cpp | 15 +++++++++++++++ tools/ice-client/src/ICEClientApp.cpp | 14 ++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/ice-server/src/IceServer.cpp b/ice-server/src/IceServer.cpp index 9a47a483f9..800592073f 100644 --- a/ice-server/src/IceServer.cpp +++ b/ice-server/src/IceServer.cpp @@ -30,6 +30,7 @@ #include #include #include "WarningsSuppression.h" +#include const int CLEAR_INACTIVE_PEERS_INTERVAL_MSECS = 1 * 1000; const int PEER_SILENCE_THRESHOLD_MSECS = 5 * 1000; @@ -51,6 +52,9 @@ IceServer::IceServer(int argc, char* argv[]) : const QCommandLineOption portOption("port", "Port for the ICE server to listen on", "port"); parser.addOption(portOption); + const QCommandLineOption logOption("logOptions", "Logging options, comma separated: ", "color,nocolor,process_id,thread_id,milliseconds,keep_repeats,journald,nojournald", "options"); + parser.addOption(logOption); + if (!parser.parse(QCoreApplication::arguments())) { qCritical() << parser.errorText() << Qt::endl; parser.showHelp(); @@ -77,6 +81,17 @@ IceServer::IceServer(int argc, char* argv[]) : port = parser.value(portOption).toInt(); } + // We want to configure the logging system as early as possible + auto& logHandler = LogHandler::getInstance(); + if (parser.isSet(logOption)) { + if (!logHandler.parseOptions(parser.value(logOption).toUtf8(), logOption.names().first())) { + QCoreApplication mockApp(argc, const_cast(argv)); // required for call to showHelp() + parser.showHelp(); + Q_UNREACHABLE(); + } + } + + _serverSocket.bind(SocketType::UDP, address, port); qDebug() << "ice-server socket is listening on address: " << address.toString() << ":" << port; diff --git a/tools/ice-client/src/ICEClientApp.cpp b/tools/ice-client/src/ICEClientApp.cpp index b10ef46b62..b73030e5c0 100644 --- a/tools/ice-client/src/ICEClientApp.cpp +++ b/tools/ice-client/src/ICEClientApp.cpp @@ -20,6 +20,7 @@ #include #include #include +#include ICEClientApp::ICEClientApp(int argc, char* argv[]) : QCoreApplication(argc, argv) @@ -46,6 +47,9 @@ ICEClientApp::ICEClientApp(int argc, char* argv[]) : const QCommandLineOption cacheSTUNOption("s", "cache stun-server response"); parser.addOption(cacheSTUNOption); + const QCommandLineOption logOption("logOptions", "Logging options, comma separated: ", "color,nocolor,process_id,thread_id,milliseconds,keep_repeats,journald,nojournald", "options"); + parser.addOption(logOption); + if (!parser.parse(QCoreApplication::arguments())) { qCritical() << parser.errorText() << Qt::endl; parser.showHelp(); @@ -81,6 +85,16 @@ ICEClientApp::ICEClientApp(int argc, char* argv[]) : } } + // We want to configure the logging system as early as possible + auto& logHandler = LogHandler::getInstance(); + if (parser.isSet(logOption)) { + if (!logHandler.parseOptions(parser.value(logOption).toUtf8(), logOption.names().first())) { + QCoreApplication mockApp(argc, const_cast(argv)); // required for call to showHelp() + parser.showHelp(); + Q_UNREACHABLE(); + } + } + _iceServerAddr = SockAddr(SocketType::UDP, "127.0.0.1", ICE_SERVER_DEFAULT_PORT); if (parser.isSet(iceServerAddressOption)) { // parse the IP and port combination for this target