From e2d492ac3f471507e574ca2cd33d98b3a52b24bf Mon Sep 17 00:00:00 2001 From: Thad House Date: Tue, 16 Dec 2025 22:26:56 -0800 Subject: [PATCH] [ntcore] Add ability to announce mDNS for server (#8373) We can use this as a new way of resolving addresses. --- .../native/cpp/NetworkTablesSettings.cpp | 2 +- ntcore/src/dev/native/cpp/main.cpp | 8 +++---- .../main/java/NetworkTableInstance.java.jinja | 24 +++++++++++++++---- .../main/java/NetworkTablesJNI.java.jinja | 3 ++- .../networktables/NetworkTableInstance.java | 24 +++++++++++++++---- .../networktables/NetworkTablesJNI.java | 3 ++- ntcore/src/main/native/cpp/InstanceImpl.cpp | 8 +++++-- ntcore/src/main/native/cpp/InstanceImpl.hpp | 3 ++- ntcore/src/main/native/cpp/NetworkServer.cpp | 22 ++++++++++++++--- ntcore/src/main/native/cpp/NetworkServer.hpp | 13 ++++++---- .../main/native/cpp/jni/NetworkTablesJNI.cpp | 11 ++++++--- ntcore/src/main/native/cpp/ntcore_c.cpp | 5 ++-- ntcore/src/main/native/cpp/ntcore_cpp.cpp | 5 ++-- .../include/wpi/nt/NetworkTableInstance.hpp | 9 +++++-- .../src/main/native/include/wpi/nt/ntcore_c.h | 7 +++++- .../main/native/include/wpi/nt/ntcore_cpp.hpp | 6 ++++- .../python/semiwrap/NetworkTableInstance.yml | 8 +++---- .../networktables/ConnectionListenerTest.java | 4 ++-- .../wpilib/networktables/TimeSyncTest.java | 2 +- .../networktables/TopicListenerTest.java | 2 +- .../native/cpp/ConnectionListenerTest.cpp | 2 +- ntcore/src/test/native/cpp/TimeSyncTest.cpp | 2 +- .../src/test/native/cpp/TopicListenerTest.cpp | 2 +- wpilibc/src/main/native/cppcs/RobotBase.cpp | 4 ++-- wpilibc/src/main/python/wpilib/_impl/start.py | 4 ++-- .../java/org/wpilib/framework/RobotBase.java | 4 ++-- .../java/org/wpilib/util/PreferencesTest.java | 2 +- 27 files changed, 133 insertions(+), 56 deletions(-) diff --git a/glass/src/libnt/native/cpp/NetworkTablesSettings.cpp b/glass/src/libnt/native/cpp/NetworkTablesSettings.cpp index 9ac653eae2..b0d594877d 100644 --- a/glass/src/libnt/native/cpp/NetworkTablesSettings.cpp +++ b/glass/src/libnt/native/cpp/NetworkTablesSettings.cpp @@ -80,7 +80,7 @@ void NetworkTablesSettings::Thread::Main() { } } else if (m_mode == 3) { wpi::nt::StartServer(m_inst, m_iniName.c_str(), m_listenAddress.c_str(), - m_port); + "", m_port); } } } diff --git a/ntcore/src/dev/native/cpp/main.cpp b/ntcore/src/dev/native/cpp/main.cpp index 922318af88..536cfdd01a 100644 --- a/ntcore/src/dev/native/cpp/main.cpp +++ b/ntcore/src/dev/native/cpp/main.cpp @@ -87,7 +87,7 @@ void bench() { auto server = wpi::nt::CreateInstance(); // connect client and server - wpi::nt::StartServer(server, "bench.json", "127.0.0.1", 10000); + wpi::nt::StartServer(server, "bench.json", "127.0.0.1", "", 10000); wpi::nt::StartClient(client, "client"); wpi::nt::SetServer(client, "127.0.0.1", 10000); @@ -150,7 +150,7 @@ void bench2() { auto server = wpi::nt::CreateInstance(); // connect client and server - wpi::nt::StartServer(server, "bench2.json", "127.0.0.1", 10000); + wpi::nt::StartServer(server, "bench2.json", "127.0.0.1", "", 10000); wpi::nt::StartClient(client1, "client1"); wpi::nt::StartClient(client2, "client2"); wpi::nt::SetServer(client1, "127.0.0.1", 10000); @@ -223,7 +223,7 @@ static std::uniform_real_distribution dist; void stress() { auto server = wpi::nt::CreateInstance(); - wpi::nt::StartServer(server, "stress.json", "127.0.0.1", 10000); + wpi::nt::StartServer(server, "stress.json", "127.0.0.1", "", 10000); wpi::nt::SubscribeMultiple(server, {{std::string_view{}}}); using namespace std::chrono_literals; @@ -344,7 +344,7 @@ void latency() { auto server = wpi::nt::CreateInstance(); // connect client and server - wpi::nt::StartServer(server, "latency.json", "127.0.0.1", 10000); + wpi::nt::StartServer(server, "latency.json", "127.0.0.1", "", 10000); wpi::nt::StartClient(client1, "client1"); wpi::nt::SetServer(client1, "127.0.0.1", 10000); wpi::nt::StartClient(client2, "client2"); diff --git a/ntcore/src/generate/main/java/NetworkTableInstance.java.jinja b/ntcore/src/generate/main/java/NetworkTableInstance.java.jinja index 8b83ee6796..0650022bfe 100644 --- a/ntcore/src/generate/main/java/NetworkTableInstance.java.jinja +++ b/ntcore/src/generate/main/java/NetworkTableInstance.java.jinja @@ -891,7 +891,7 @@ public final class NetworkTableInstance implements AutoCloseable { * @param persistFilename the name of the persist file to use */ public void startServer(String persistFilename) { - startServer(persistFilename, ""); + startServer(persistFilename, "", ""); } /** @@ -901,18 +901,32 @@ public final class NetworkTableInstance implements AutoCloseable { * @param listenAddress the address to listen on, or empty to listen on any address */ public void startServer(String persistFilename, String listenAddress) { - startServer(persistFilename, listenAddress, kDefaultPort); + startServer(persistFilename, listenAddress, ""); } /** - * Starts a server using the specified filename, listening address, and port. + * Starts a server using the specified filename, listening address, and mdns service, + * using the default port. * * @param persistFilename the name of the persist file to use * @param listenAddress the address to listen on, or empty to listen on any address + * @param mdnsService the mDNS service name to advertise, or empty to not advertise + */ + public void startServer(String persistFilename, String listenAddress, String mdnsService) { + startServer(persistFilename, listenAddress, mdnsService, kDefaultPort); + } + + /** + * Starts a server using the specified filename, listening address, mdns service and port. + * + * @param persistFilename the name of the persist file to use + * @param listenAddress the address to listen on, or empty to listen on any address + * @param mdnsService the mDNS service name to advertise, or empty to not advertise * @param port port to communicate over */ - public void startServer(String persistFilename, String listenAddress, int port) { - NetworkTablesJNI.startServer(m_handle, persistFilename, listenAddress, port); + public void startServer(String persistFilename, String listenAddress, String mdnsService, + int port) { + NetworkTablesJNI.startServer(m_handle, persistFilename, listenAddress, mdnsService, port); } /** Stops the server if it is running. */ diff --git a/ntcore/src/generate/main/java/NetworkTablesJNI.java.jinja b/ntcore/src/generate/main/java/NetworkTablesJNI.java.jinja index 5b3e132c4b..b1d0d6a36c 100644 --- a/ntcore/src/generate/main/java/NetworkTablesJNI.java.jinja +++ b/ntcore/src/generate/main/java/NetworkTablesJNI.java.jinja @@ -864,10 +864,11 @@ public final class NetworkTablesJNI { * @param inst NT instance handle. * @param persistFilename the name of the persist file to use * @param listenAddress the address to listen on, or empty to listen on any address + * @param mdnsService the mDNS service name to advertise, or empty to not advertise * @param port port to communicate over */ public static native void startServer( - int inst, String persistFilename, String listenAddress, int port); + int inst, String persistFilename, String listenAddress, String mdnsService, int port); /** * Stops the server if it is running. diff --git a/ntcore/src/generated/main/java/org/wpilib/networktables/NetworkTableInstance.java b/ntcore/src/generated/main/java/org/wpilib/networktables/NetworkTableInstance.java index f997e01145..bfa2060afc 100644 --- a/ntcore/src/generated/main/java/org/wpilib/networktables/NetworkTableInstance.java +++ b/ntcore/src/generated/main/java/org/wpilib/networktables/NetworkTableInstance.java @@ -1171,7 +1171,7 @@ public final class NetworkTableInstance implements AutoCloseable { * @param persistFilename the name of the persist file to use */ public void startServer(String persistFilename) { - startServer(persistFilename, ""); + startServer(persistFilename, "", ""); } /** @@ -1181,18 +1181,32 @@ public final class NetworkTableInstance implements AutoCloseable { * @param listenAddress the address to listen on, or empty to listen on any address */ public void startServer(String persistFilename, String listenAddress) { - startServer(persistFilename, listenAddress, kDefaultPort); + startServer(persistFilename, listenAddress, ""); } /** - * Starts a server using the specified filename, listening address, and port. + * Starts a server using the specified filename, listening address, and mdns service, + * using the default port. * * @param persistFilename the name of the persist file to use * @param listenAddress the address to listen on, or empty to listen on any address + * @param mdnsService the mDNS service name to advertise, or empty to not advertise + */ + public void startServer(String persistFilename, String listenAddress, String mdnsService) { + startServer(persistFilename, listenAddress, mdnsService, kDefaultPort); + } + + /** + * Starts a server using the specified filename, listening address, mdns service and port. + * + * @param persistFilename the name of the persist file to use + * @param listenAddress the address to listen on, or empty to listen on any address + * @param mdnsService the mDNS service name to advertise, or empty to not advertise * @param port port to communicate over */ - public void startServer(String persistFilename, String listenAddress, int port) { - NetworkTablesJNI.startServer(m_handle, persistFilename, listenAddress, port); + public void startServer(String persistFilename, String listenAddress, String mdnsService, + int port) { + NetworkTablesJNI.startServer(m_handle, persistFilename, listenAddress, mdnsService, port); } /** Stops the server if it is running. */ diff --git a/ntcore/src/generated/main/java/org/wpilib/networktables/NetworkTablesJNI.java b/ntcore/src/generated/main/java/org/wpilib/networktables/NetworkTablesJNI.java index 6f72b821bc..c4b1e5c22c 100644 --- a/ntcore/src/generated/main/java/org/wpilib/networktables/NetworkTablesJNI.java +++ b/ntcore/src/generated/main/java/org/wpilib/networktables/NetworkTablesJNI.java @@ -1404,10 +1404,11 @@ public final class NetworkTablesJNI { * @param inst NT instance handle. * @param persistFilename the name of the persist file to use * @param listenAddress the address to listen on, or empty to listen on any address + * @param mdnsService the mDNS service name to advertise, or empty to not advertise * @param port port to communicate over */ public static native void startServer( - int inst, String persistFilename, String listenAddress, int port); + int inst, String persistFilename, String listenAddress, String mdnsService, int port); /** * Stops the server if it is running. diff --git a/ntcore/src/main/native/cpp/InstanceImpl.cpp b/ntcore/src/main/native/cpp/InstanceImpl.cpp index 7c217954a7..e2071e2e73 100644 --- a/ntcore/src/main/native/cpp/InstanceImpl.cpp +++ b/ntcore/src/main/native/cpp/InstanceImpl.cpp @@ -103,16 +103,20 @@ void InstanceImpl::StopLocal() { void InstanceImpl::StartServer(std::string_view persistFilename, std::string_view listenAddress, + std::string_view mdnsService, unsigned int port) { std::scoped_lock lock{m_mutex}; if (networkMode != NT_NET_MODE_NONE) { return; } m_networkServer = std::make_shared( - persistFilename, listenAddress, port, localStorage, connectionList, - logger, [this] { + persistFilename, listenAddress, mdnsService, port, localStorage, + connectionList, logger, [this](bool announcingmDNS) { std::scoped_lock lock{m_mutex}; networkMode &= ~NT_NET_MODE_STARTING; + if (announcingmDNS) { + networkMode |= NT_NET_MODE_MDNS_ANNOUNCING; + } }); networkMode = NT_NET_MODE_SERVER | NT_NET_MODE_STARTING; listenerStorage.NotifyTimeSync({}, NT_EVENT_TIMESYNC, 0, 0, true); diff --git a/ntcore/src/main/native/cpp/InstanceImpl.hpp b/ntcore/src/main/native/cpp/InstanceImpl.hpp index 61ae8731b1..bd8d9e7057 100644 --- a/ntcore/src/main/native/cpp/InstanceImpl.hpp +++ b/ntcore/src/main/native/cpp/InstanceImpl.hpp @@ -44,7 +44,8 @@ class InstanceImpl { void StartLocal(); void StopLocal(); void StartServer(std::string_view persistFilename, - std::string_view listenAddress, unsigned int port); + std::string_view listenAddress, std::string_view mdnsService, + unsigned int port); void StopServer(); void StartClient(std::string_view identity); void StopClient(); diff --git a/ntcore/src/main/native/cpp/NetworkServer.cpp b/ntcore/src/main/native/cpp/NetworkServer.cpp index ff26afd4e9..4880473cac 100644 --- a/ntcore/src/main/native/cpp/NetworkServer.cpp +++ b/ntcore/src/main/native/cpp/NetworkServer.cpp @@ -253,17 +253,19 @@ void NetworkServer::ServerConnection4::ProcessWsUpgrade() { } NetworkServer::NetworkServer(std::string_view persistentFilename, - std::string_view listenAddress, unsigned int port, + std::string_view listenAddress, + std::string_view mdnsService, unsigned int port, net::ILocalStorage& localStorage, IConnectionList& connList, wpi::util::Logger& logger, - std::function initDone) + std::function initDone) : m_localStorage{localStorage}, m_connList{connList}, m_logger{logger}, m_initDone{std::move(initDone)}, m_persistentFilename{persistentFilename}, m_listenAddress{wpi::util::trim(listenAddress)}, + m_mdnsService{wpi::util::trim(mdnsService)}, m_port{port}, m_serverImpl{logger}, m_localQueue{logger}, @@ -462,9 +464,23 @@ void NetworkServer::Init() { tcp4->Listen(); } + bool announcingmDNS = false; + if (!m_mdnsService.empty()) { + m_mdnsAnnouncer.emplace(m_mdnsService, "_networktables._tcp", m_port); + if (!m_mdnsAnnouncer->HasImplementation()) { + WARN("mDNS service announcer not available; cannot announce '{}'", + m_mdnsService); + m_mdnsAnnouncer.reset(); + } else { + m_mdnsAnnouncer->Start(); + announcingmDNS = true; + INFO("mDNS announcing as service '{}' on port {}", m_mdnsService, m_port); + } + } + if (m_initDone) { DEBUG4("NetworkServer initDone()"); - m_initDone(); + m_initDone(announcingmDNS); m_initDone = nullptr; } } diff --git a/ntcore/src/main/native/cpp/NetworkServer.hpp b/ntcore/src/main/native/cpp/NetworkServer.hpp index f1ce4eae29..d7f78f3435 100644 --- a/ntcore/src/main/native/cpp/NetworkServer.hpp +++ b/ntcore/src/main/native/cpp/NetworkServer.hpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -15,6 +16,7 @@ #include "net/Message.hpp" #include "server/ServerImpl.hpp" #include "wpi/net/EventLoopRunner.hpp" +#include "wpi/net/MulticastServiceAnnouncer.h" #include "wpi/net/uv/Async.hpp" #include "wpi/net/uv/Idle.hpp" #include "wpi/net/uv/Timer.hpp" @@ -35,9 +37,10 @@ class IConnectionList; class NetworkServer { public: NetworkServer(std::string_view persistentFilename, - std::string_view listenAddress, unsigned int port, - net::ILocalStorage& localStorage, IConnectionList& connList, - wpi::util::Logger& logger, std::function initDone); + std::string_view listenAddress, std::string_view mdnsService, + unsigned int port, net::ILocalStorage& localStorage, + IConnectionList& connList, wpi::util::Logger& logger, + std::function initDone); ~NetworkServer(); void FlushLocal(); @@ -57,13 +60,15 @@ class NetworkServer { net::ILocalStorage& m_localStorage; IConnectionList& m_connList; wpi::util::Logger& m_logger; - std::function m_initDone; + std::function m_initDone; std::string m_persistentData; std::string m_persistentFilename; std::string m_listenAddress; + std::string m_mdnsService; unsigned int m_port; // used only from loop + std::optional m_mdnsAnnouncer; std::shared_ptr m_readLocalTimer; std::shared_ptr m_savePersistentTimer; std::shared_ptr> m_flushLocal; diff --git a/ntcore/src/main/native/cpp/jni/NetworkTablesJNI.cpp b/ntcore/src/main/native/cpp/jni/NetworkTablesJNI.cpp index f49db39c07..6996cd1769 100644 --- a/ntcore/src/main/native/cpp/jni/NetworkTablesJNI.cpp +++ b/ntcore/src/main/native/cpp/jni/NetworkTablesJNI.cpp @@ -1178,12 +1178,12 @@ Java_org_wpilib_networktables_NetworkTablesJNI_stopLocal /* * Class: org_wpilib_networktables_NetworkTablesJNI * Method: startServer - * Signature: (ILjava/lang/String;Ljava/lang/String;I)V + * Signature: (ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;I)V */ JNIEXPORT void JNICALL Java_org_wpilib_networktables_NetworkTablesJNI_startServer (JNIEnv* env, jclass, jint inst, jstring persistFilename, - jstring listenAddress, jint port) + jstring listenAddress, jstring mdnsService, jint port) { if (!persistFilename) { nullPointerEx.Throw(env, "persistFilename cannot be null"); @@ -1193,8 +1193,13 @@ Java_org_wpilib_networktables_NetworkTablesJNI_startServer nullPointerEx.Throw(env, "listenAddress cannot be null"); return; } + if (!mdnsService) { + nullPointerEx.Throw(env, "mdnsService cannot be null"); + return; + } wpi::nt::StartServer(inst, JStringRef{env, persistFilename}.str(), - JStringRef{env, listenAddress}.c_str(), port); + JStringRef{env, listenAddress}.c_str(), + JStringRef{env, mdnsService}.c_str(), port); } /* diff --git a/ntcore/src/main/native/cpp/ntcore_c.cpp b/ntcore/src/main/native/cpp/ntcore_c.cpp index f746acf17c..920b244555 100644 --- a/ntcore/src/main/native/cpp/ntcore_c.cpp +++ b/ntcore/src/main/native/cpp/ntcore_c.cpp @@ -532,9 +532,10 @@ void NT_StopLocal(NT_Inst inst) { void NT_StartServer(NT_Inst inst, const struct WPI_String* persist_filename, const struct WPI_String* listen_address, - unsigned int port) { + const struct WPI_String* mdns_service, unsigned int port) { wpi::nt::StartServer(inst, wpi::util::to_string_view(persist_filename), - wpi::util::to_string_view(listen_address), port); + wpi::util::to_string_view(listen_address), + wpi::util::to_string_view(mdns_service), port); } void NT_StopServer(NT_Inst inst) { diff --git a/ntcore/src/main/native/cpp/ntcore_cpp.cpp b/ntcore/src/main/native/cpp/ntcore_cpp.cpp index baba9e5748..45e4bcb3d5 100644 --- a/ntcore/src/main/native/cpp/ntcore_cpp.cpp +++ b/ntcore/src/main/native/cpp/ntcore_cpp.cpp @@ -633,9 +633,10 @@ void StopLocal(NT_Inst inst) { } void StartServer(NT_Inst inst, std::string_view persist_filename, - std::string_view listen_address, unsigned int port) { + std::string_view listen_address, std::string_view mdns_service, + unsigned int port) { if (auto ii = InstanceImpl::GetTyped(inst, Handle::kInstance)) { - ii->StartServer(persist_filename, listen_address, port); + ii->StartServer(persist_filename, listen_address, mdns_service, port); } } diff --git a/ntcore/src/main/native/include/wpi/nt/NetworkTableInstance.hpp b/ntcore/src/main/native/include/wpi/nt/NetworkTableInstance.hpp index 6469f7038c..766ea6d98f 100644 --- a/ntcore/src/main/native/include/wpi/nt/NetworkTableInstance.hpp +++ b/ntcore/src/main/native/include/wpi/nt/NetworkTableInstance.hpp @@ -607,12 +607,17 @@ class NetworkTableInstance final { * @param listen_address the address to listen on, or an empty string to * listen on any address. (UTF-8 string, null * terminated) + * @param mdns_service the mDNS service name to announce, or an empty + * string to not announce via mDNS (UTF-8 string, + * null terminated) * @param port port to communicate over */ void StartServer(std::string_view persist_filename = "networktables.json", - const char* listen_address = "", + std::string_view listen_address = "", + std::string_view mdns_service = "", unsigned int port = kDefaultPort) { - ::wpi::nt::StartServer(m_handle, persist_filename, listen_address, port); + ::wpi::nt::StartServer(m_handle, persist_filename, listen_address, + mdns_service, port); } /** diff --git a/ntcore/src/main/native/include/wpi/nt/ntcore_c.h b/ntcore/src/main/native/include/wpi/nt/ntcore_c.h index 75794081bd..842f327fb8 100644 --- a/ntcore/src/main/native/include/wpi/nt/ntcore_c.h +++ b/ntcore/src/main/native/include/wpi/nt/ntcore_c.h @@ -90,6 +90,7 @@ enum NT_NetworkMode { NT_NET_MODE_CLIENT = 0x04, /* running in client mode */ NT_NET_MODE_STARTING = 0x08, /* flag for starting (either client or server) */ NT_NET_MODE_LOCAL = 0x10, /* running in local-only mode */ + NT_NET_MODE_MDNS_ANNOUNCING = 0x20 /* mDNS is enabled and announcing */ }; /** Event notification flags. */ @@ -1116,10 +1117,14 @@ void NT_StopLocal(NT_Inst inst); * @param listen_address the address to listen on, or an empty string to * listen on any address. (UTF-8 string, null * terminated) + * @param mdns_service the mDNS service name to advertise, or an empty + * string to not advertise via mDNS. (UTF-8 string, + * null terminated) * @param port port to communicate over */ void NT_StartServer(NT_Inst inst, const struct WPI_String* persist_filename, - const struct WPI_String* listen_address, unsigned int port); + const struct WPI_String* listen_address, + const struct WPI_String* mdns_service, unsigned int port); /** * Stops the server if it is running. diff --git a/ntcore/src/main/native/include/wpi/nt/ntcore_cpp.hpp b/ntcore/src/main/native/include/wpi/nt/ntcore_cpp.hpp index be28f7965b..0726d70c7e 100644 --- a/ntcore/src/main/native/include/wpi/nt/ntcore_cpp.hpp +++ b/ntcore/src/main/native/include/wpi/nt/ntcore_cpp.hpp @@ -1057,10 +1057,14 @@ void StopLocal(NT_Inst inst); * @param listen_address the address to listen on, or an empty string to * listen on any address. (UTF-8 string, null * terminated) + * @param mdns_service the mDNS service name to advertise, or an empty + * string to not advertise via mDNS. (UTF-8 string, + * null terminated) * @param port port to communicate over */ void StartServer(NT_Inst inst, std::string_view persist_filename, - std::string_view listen_address, unsigned int port); + std::string_view listen_address, std::string_view mdns_service, + unsigned int port); /** * Stops the server if it is running. diff --git a/ntcore/src/main/python/semiwrap/NetworkTableInstance.yml b/ntcore/src/main/python/semiwrap/NetworkTableInstance.yml index 2bf33daa1b..2a1a1cf963 100644 --- a/ntcore/src/main/python/semiwrap/NetworkTableInstance.yml +++ b/ntcore/src/main/python/semiwrap/NetworkTableInstance.yml @@ -117,11 +117,11 @@ classes: StopLocal: StartServer: cpp_code: | - [](NetworkTableInstance * self, std::string_view persist_filename, const char* listen_address, - unsigned int port) { + [](NetworkTableInstance * self, std::string_view persist_filename, std::string_view listen_address, + std::string_view mdns_service, unsigned int port) { pyntcore::onInstanceStart(self); py::gil_scoped_release release; - self->StartServer(persist_filename, listen_address, port); + self->StartServer(persist_filename, listen_address, mdns_service, port); } StopServer: StopClient: @@ -156,7 +156,7 @@ classes: operator==: StartClient: inline_code: | - .def("configPythonLogging", [](NetworkTableInstance * self, + .def("configPythonLogging", [](NetworkTableInstance * self, NetworkTableInstance::LogLevel minLevel, NetworkTableInstance::LogLevel maxLevel, py::str logName) { py::module::import("ntcore._logutil").attr("_config_logging")(self, minLevel, maxLevel, logName); }, py::kw_only(), diff --git a/ntcore/src/test/java/org/wpilib/networktables/ConnectionListenerTest.java b/ntcore/src/test/java/org/wpilib/networktables/ConnectionListenerTest.java index 464a1f0cab..8582dd8dcc 100644 --- a/ntcore/src/test/java/org/wpilib/networktables/ConnectionListenerTest.java +++ b/ntcore/src/test/java/org/wpilib/networktables/ConnectionListenerTest.java @@ -39,7 +39,7 @@ class ConnectionListenerTest { /** Connect to the server. */ private void connect(int port) { - m_serverInst.startServer("connectionlistenertest.json", "127.0.0.1", port); + m_serverInst.startServer("connectionlistenertest.json", "127.0.0.1", "", port); m_clientInst.startClient("client"); m_clientInst.setServer("127.0.0.1", port); @@ -113,7 +113,7 @@ class ConnectionListenerTest { @ParameterizedTest @ValueSource(strings = {"127.0.0.1", "127.0.0.1 ", " 127.0.0.1 "}) void testThreaded(String address) { - m_serverInst.startServer("connectionlistenertest.json", address, threadedPort); + m_serverInst.startServer("connectionlistenertest.json", address, "", threadedPort); List events = new ArrayList<>(); final int handle = m_serverInst.addConnectionListener( diff --git a/ntcore/src/test/java/org/wpilib/networktables/TimeSyncTest.java b/ntcore/src/test/java/org/wpilib/networktables/TimeSyncTest.java index f0d97cbd0d..42cb9ef82d 100644 --- a/ntcore/src/test/java/org/wpilib/networktables/TimeSyncTest.java +++ b/ntcore/src/test/java/org/wpilib/networktables/TimeSyncTest.java @@ -37,7 +37,7 @@ class TimeSyncTest { try (var poller = new NetworkTableListenerPoller(m_inst)) { poller.addTimeSyncListener(false); - m_inst.startServer("timesynctest.json", "127.0.0.1", 10030); + m_inst.startServer("timesynctest.json", "127.0.0.1", "", 10030); var offset = m_inst.getServerTimeOffset(); assertTrue(offset.isPresent()); assertEquals(0L, offset.getAsLong()); diff --git a/ntcore/src/test/java/org/wpilib/networktables/TopicListenerTest.java b/ntcore/src/test/java/org/wpilib/networktables/TopicListenerTest.java index 02b5448ae5..8af23cc2bb 100644 --- a/ntcore/src/test/java/org/wpilib/networktables/TopicListenerTest.java +++ b/ntcore/src/test/java/org/wpilib/networktables/TopicListenerTest.java @@ -33,7 +33,7 @@ class TopicListenerTest { } private void connect() { - m_serverInst.startServer("topiclistenertest.json", "127.0.0.1", 10010); + m_serverInst.startServer("topiclistenertest.json", "127.0.0.1", "", 10010); m_clientInst.startClient("client"); m_clientInst.setServer("127.0.0.1", 10010); diff --git a/ntcore/src/test/native/cpp/ConnectionListenerTest.cpp b/ntcore/src/test/native/cpp/ConnectionListenerTest.cpp index 31b9515573..56fa7da290 100644 --- a/ntcore/src/test/native/cpp/ConnectionListenerTest.cpp +++ b/ntcore/src/test/native/cpp/ConnectionListenerTest.cpp @@ -32,7 +32,7 @@ class ConnectionListenerTest : public ::testing::Test { }; void ConnectionListenerTest::Connect(const char* address, unsigned int port4) { - wpi::nt::StartServer(server_inst, "connectionlistenertest.ini", address, + wpi::nt::StartServer(server_inst, "connectionlistenertest.ini", address, "", port4); wpi::nt::StartClient(client_inst, "client"); wpi::nt::SetServer(client_inst, address, port4); diff --git a/ntcore/src/test/native/cpp/TimeSyncTest.cpp b/ntcore/src/test/native/cpp/TimeSyncTest.cpp index 72d2b832b4..eac1c85dab 100644 --- a/ntcore/src/test/native/cpp/TimeSyncTest.cpp +++ b/ntcore/src/test/native/cpp/TimeSyncTest.cpp @@ -26,7 +26,7 @@ TEST_F(TimeSyncTest, TestServer) { wpi::nt::NetworkTableListenerPoller poller{m_inst}; poller.AddTimeSyncListener(false); - m_inst.StartServer("timesynctest.json", "127.0.0.1", 10030); + m_inst.StartServer("timesynctest.json", "127.0.0.1", "", 10030); auto offset = m_inst.GetServerTimeOffset(); ASSERT_TRUE(offset); ASSERT_EQ(0, *offset); diff --git a/ntcore/src/test/native/cpp/TopicListenerTest.cpp b/ntcore/src/test/native/cpp/TopicListenerTest.cpp index 6d209bfc25..bfeb332d34 100644 --- a/ntcore/src/test/native/cpp/TopicListenerTest.cpp +++ b/ntcore/src/test/native/cpp/TopicListenerTest.cpp @@ -52,7 +52,7 @@ class TopicListenerTest : public ::testing::Test { }; void TopicListenerTest::Connect(unsigned int port) { - wpi::nt::StartServer(m_serverInst, "topiclistenertest.json", "127.0.0.1", + wpi::nt::StartServer(m_serverInst, "topiclistenertest.json", "127.0.0.1", "", port); wpi::nt::StartClient(m_clientInst, "client"); wpi::nt::SetServer(m_clientInst, "127.0.0.1", port); diff --git a/wpilibc/src/main/native/cppcs/RobotBase.cpp b/wpilibc/src/main/native/cppcs/RobotBase.cpp index 006d63ebd1..80b5a8eca0 100644 --- a/wpilibc/src/main/native/cppcs/RobotBase.cpp +++ b/wpilibc/src/main/native/cppcs/RobotBase.cpp @@ -200,9 +200,9 @@ RobotBase::RobotBase() { // subscribe to "" to force persistent values to propagate to local wpi::nt::SubscribeMultiple(inst.GetHandle(), {{std::string_view{}}}); if constexpr (!IsSimulation()) { - inst.StartServer("/home/systemcore/networktables.json"); + inst.StartServer("/home/systemcore/networktables.json", "", "robot"); } else { - inst.StartServer(); + inst.StartServer("networktables.json", "", "robot"); } // wait for the NT server to actually start diff --git a/wpilibc/src/main/python/wpilib/_impl/start.py b/wpilibc/src/main/python/wpilib/_impl/start.py index 7cb442b1f6..6c87d074e0 100644 --- a/wpilibc/src/main/python/wpilib/_impl/start.py +++ b/wpilibc/src/main/python/wpilib/_impl/start.py @@ -186,9 +186,9 @@ class RobotStarter: msub = ntcore.MultiSubscriber(inst, [""]) if not isSimulation: - inst.startServer("/home/systemcore/networktables.ini") + inst.startServer("/home/systemcore/networktables.json", "", "robot") else: - inst.startServer() + inst.startServer("networktables.json", "", "robot") # wait for the NT server to actually start for i in range(100): diff --git a/wpilibj/src/main/java/org/wpilib/framework/RobotBase.java b/wpilibj/src/main/java/org/wpilib/framework/RobotBase.java index 1982a910cd..08969b89a3 100644 --- a/wpilibj/src/main/java/org/wpilib/framework/RobotBase.java +++ b/wpilibj/src/main/java/org/wpilib/framework/RobotBase.java @@ -103,9 +103,9 @@ public abstract class RobotBase implements AutoCloseable { // subscribe to "" to force persistent values to propagate to local m_suball = new MultiSubscriber(inst, new String[] {""}); if (!isSimulation()) { - inst.startServer("/home/systemcore/networktables.json"); + inst.startServer("/home/systemcore/networktables.json", "", "robot"); } else { - inst.startServer(); + inst.startServer("networktables.json", "", "robot"); } // wait for the NT server to actually start diff --git a/wpilibj/src/test/java/org/wpilib/util/PreferencesTest.java b/wpilibj/src/test/java/org/wpilib/util/PreferencesTest.java index 0e849b6a12..28d6487816 100644 --- a/wpilibj/src/test/java/org/wpilib/util/PreferencesTest.java +++ b/wpilibj/src/test/java/org/wpilib/util/PreferencesTest.java @@ -52,7 +52,7 @@ class PreferencesTest { fail(ex); } - m_inst.startServer(filepath.toString(), "", 0); + m_inst.startServer(filepath.toString(), "", "", 0); try { int count = 0; while (m_inst.getNetworkMode().contains(NetworkTableInstance.NetworkMode.kStarting)) {