UDP API port is now stored in and read from global config

This commit is contained in:
Thulinma 2023-05-01 02:09:21 +02:00
parent 40df03439c
commit 0af85de22d
13 changed files with 61 additions and 39 deletions

View file

@ -441,12 +441,22 @@ int Controller::handleAPIConnection(Socket::Connection &conn){
void Controller::handleUDPAPI(void *np){
Socket::UDPConnection uSock(true);
if (!uSock.bind(UDP_API_PORT, UDP_API_HOST)){
uint16_t boundPort = uSock.bind(UDP_API_PORT, UDP_API_HOST);
if (!boundPort){
FAIL_MSG("Could not open local API UDP socket - not all functionality will be available");
return;
}
HTTP::URL boundAddr;
boundAddr.protocol = "udp";
boundAddr.setPort(boundPort);
boundAddr.host = uSock.getBoundAddress();
{
tthread::lock_guard<tthread::mutex> guard(configMutex);
udpApiBindAddr = boundAddr.getUrl();
Controller::writeConfig();
}
Util::Procs::socketList.insert(uSock.getSock());
uSock.SetDestination(UDP_API_HOST, UDP_API_PORT);
uSock.allocateDestination();
while (Controller::conf.is_active){
if (uSock.Receive()){
MEDIUM_MSG("UDP API: %s", (const char*)uSock.data);

View file

@ -16,6 +16,7 @@ namespace Controller{
std::string instanceId; /// instanceId (previously uniqId) is set in controller.cpp
std::string prometheus;
std::string accesslog;
std::string udpApiBindAddr;
Util::Config conf;
JSON::Value Storage; ///< Global storage of data.
tthread::mutex configMutex;
@ -444,7 +445,9 @@ namespace Controller{
|| !globAccX.getFieldAccX("sessionOutputMode")
|| !globAccX.getFieldAccX("sessionUnspecifiedMode")
|| !globAccX.getFieldAccX("sessionStreamInfoMode")
|| !globAccX.getFieldAccX("tknMode")){
|| !globAccX.getFieldAccX("tknMode")
|| !globAccX.getFieldAccX("udpApi")
){
globAccX.setReload();
globCfg.master = true;
globCfg.close();
@ -461,6 +464,7 @@ namespace Controller{
globAccX.addField("sessionUnspecifiedMode", RAX_64UINT);
globAccX.addField("sessionStreamInfoMode", RAX_64UINT);
globAccX.addField("tknMode", RAX_64UINT);
globAccX.addField("udpApi", RAX_128STRING);
globAccX.setRCount(1);
globAccX.setEndPos(1);
globAccX.setReady();
@ -472,6 +476,7 @@ namespace Controller{
globAccX.setInt("sessionUnspecifiedMode", Storage["config"]["sessionUnspecifiedMode"].asInt());
globAccX.setInt("sessionStreamInfoMode", Storage["config"]["sessionStreamInfoMode"].asInt());
globAccX.setInt("tknMode", Storage["config"]["tknMode"].asInt());
globAccX.setString("udpApi", udpApiBindAddr);
globAccX.setInt("systemBoot", systemBoot);
globCfg.master = false; // leave the page after closing
}

View file

@ -8,6 +8,7 @@ namespace Controller{
extern std::string instanceId; ///< global storage of instanceId (previously uniqID) is set in controller.cpp
extern std::string prometheus; ///< Prometheus access string
extern std::string accesslog; ///< Where to write the access log
extern std::string udpApiBindAddr; ///< Bound address where the UDP API listens
extern Util::Config conf; ///< Global storage of configuration.
extern JSON::Value Storage; ///< Global storage of data.
extern tthread::mutex logMutex; ///< Mutex for log thread.