stephb9959
2022-07-24 12:28:40 -07:00
parent d1c13ad2dd
commit 0a6ee4ea47
4 changed files with 48 additions and 35 deletions

View File

@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.13) cmake_minimum_required(VERSION 3.13)
project(owsec VERSION 2.6.0) project(owsec VERSION 2.7.0)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)

2
build
View File

@@ -1 +1 @@
60 2

View File

@@ -29,7 +29,8 @@
namespace OpenWifi { namespace OpenWifi {
Poco::Net::HTTPRequestHandler * RESTAPI_ExtRouter(const std::string &Path, RESTAPIHandler::BindingMap &Bindings, Poco::Net::HTTPRequestHandler * RESTAPI_ExtRouter(const std::string &Path, RESTAPIHandler::BindingMap &Bindings,
Poco::Logger & L, RESTAPI_GenericServer & S, uint64_t TransactionId) { Poco::Logger & L, RESTAPI_GenericServer & S,
uint64_t TransactionId) {
return RESTAPI_Router< return RESTAPI_Router<
RESTAPI_oauth2_handler, RESTAPI_oauth2_handler,
RESTAPI_user_handler, RESTAPI_user_handler,

View File

@@ -1399,13 +1399,14 @@ namespace OpenWifi {
[[nodiscard]] inline const std::string &Address() const { return address_; }; [[nodiscard]] inline const std::string &Address() const { return address_; };
[[nodiscard]] inline uint32_t Port() const { return port_; }; [[nodiscard]] inline uint32_t Port() const { return port_; };
[[nodiscard]] inline const std::string &KeyFile() const { return key_file_; }; [[nodiscard]] inline auto KeyFile() const { return key_file_; };
[[nodiscard]] inline const std::string &CertFile() const { return cert_file_; }; [[nodiscard]] inline auto CertFile() const { return cert_file_; };
[[nodiscard]] inline const std::string &RootCA() const { return root_ca_; }; [[nodiscard]] inline auto RootCA() const { return root_ca_; };
[[nodiscard]] inline const std::string &KeyFilePassword() const { return key_file_password_; }; [[nodiscard]] inline auto KeyFilePassword() const { return key_file_password_; };
[[nodiscard]] inline const std::string &IssuerCertFile() const { return issuer_cert_file_; }; [[nodiscard]] inline auto IssuerCertFile() const { return issuer_cert_file_; };
[[nodiscard]] inline const std::string &Name() const { return name_; }; [[nodiscard]] inline auto Name() const { return name_; };
[[nodiscard]] inline int Backlog() const { return backlog_; } [[nodiscard]] inline int Backlog() const { return backlog_; }
[[nodiscard]] inline auto Cas() const { return cas_; }
[[nodiscard]] inline Poco::Net::SecureServerSocket CreateSecureSocket(Poco::Logger &L) const { [[nodiscard]] inline Poco::Net::SecureServerSocket CreateSecureSocket(Poco::Logger &L) const {
Poco::Net::Context::Params P; Poco::Net::Context::Params P;
@@ -1885,8 +1886,8 @@ namespace OpenWifi {
Request = &RequestIn; Request = &RequestIn;
Response = &ResponseIn; Response = &ResponseIn;
std::string th_name = "restsvr_" + std::to_string(TransactionId_); // std::string th_name = "restsvr_" + std::to_string(TransactionId_);
Utils::SetThreadName(th_name.c_str()); // Utils::SetThreadName(th_name.c_str());
if(Request->getContentLength()>0) { if(Request->getContentLength()>0) {
if(Request->getContentType().find("application/json")!=std::string::npos) { if(Request->getContentType().find("application/json")!=std::string::npos) {
@@ -2712,7 +2713,7 @@ namespace OpenWifi {
inline void run() override { inline void run() override {
Poco::AutoPtr<Poco::Notification> Note(Queue_.waitDequeueNotification()); Poco::AutoPtr<Poco::Notification> Note(Queue_.waitDequeueNotification());
Utils::SetThreadName("kafka-dispatch"); Utils::SetThreadName("kafka:dispatch");
while(Note && Running_) { while(Note && Running_) {
auto Msg = dynamic_cast<KafkaMessage*>(Note.get()); auto Msg = dynamic_cast<KafkaMessage*>(Note.get());
if(Msg!= nullptr) { if(Msg!= nullptr) {
@@ -3034,18 +3035,17 @@ namespace OpenWifi {
inline Poco::Net::HTTPRequestHandler *CallServer(const std::string &Path, uint64_t Id) { inline Poco::Net::HTTPRequestHandler *CallServer(const std::string &Path, uint64_t Id) {
RESTAPIHandler::BindingMap Bindings; RESTAPIHandler::BindingMap Bindings;
Utils::SetThreadName(fmt::format("rest_ext_{}",Id).c_str()); Utils::SetThreadName(fmt::format("x-rest:{}",Id).c_str());
return RESTAPI_ExtRouter(Path, Bindings, Logger(), Server_, Id); return RESTAPI_ExtRouter(Path, Bindings, Logger(), Server_, Id);
} }
private: private:
std::vector<std::unique_ptr<Poco::Net::HTTPServer>> RESTServers_; std::vector<std::unique_ptr<Poco::Net::HTTPServer>> RESTServers_;
Poco::ThreadPool Pool_; Poco::ThreadPool Pool_{"x-rest",2,32};
RESTAPI_GenericServer Server_; RESTAPI_GenericServer Server_;
RESTAPI_ExtServer() noexcept: RESTAPI_ExtServer() noexcept:
SubSystemServer("RESTAPI_ExtServer", "RESTAPIServer", "openwifi.restapi"), SubSystemServer("RESTAPI_ExtServer", "RESTAPIServer", "openwifi.restapi")
Pool_("RESTAPI_ExtServer",4,50,120)
{ {
} }
}; };
@@ -3058,7 +3058,7 @@ namespace OpenWifi {
inline Poco::Net::HTTPRequestHandler *createRequestHandler(const Poco::Net::HTTPServerRequest &Request) override { inline Poco::Net::HTTPRequestHandler *createRequestHandler(const Poco::Net::HTTPServerRequest &Request) override {
try { try {
Poco::URI uri(Request.getURI()); Poco::URI uri(Request.getURI());
Utils::SetThreadName(fmt::format("rest_ext_{}",TransactionId_).c_str()); Utils::SetThreadName(fmt::format("x-rest:{}",TransactionId_).c_str());
return RESTAPI_ExtServer()->CallServer(uri.getPath(), TransactionId_++); return RESTAPI_ExtServer()->CallServer(uri.getPath(), TransactionId_++);
} catch (...) { } catch (...) {
@@ -3167,17 +3167,16 @@ namespace OpenWifi {
inline Poco::Net::HTTPRequestHandler *CallServer(const std::string &Path, uint64_t Id) { inline Poco::Net::HTTPRequestHandler *CallServer(const std::string &Path, uint64_t Id) {
RESTAPIHandler::BindingMap Bindings; RESTAPIHandler::BindingMap Bindings;
Utils::SetThreadName(fmt::format("rest_int_{}",Id).c_str()); Utils::SetThreadName(fmt::format("i-rest:{}",Id).c_str());
return RESTAPI_IntRouter(Path, Bindings, Logger(), Server_, Id); return RESTAPI_IntRouter(Path, Bindings, Logger(), Server_, Id);
} }
private: private:
std::vector<std::unique_ptr<Poco::Net::HTTPServer>> RESTServers_; std::vector<std::unique_ptr<Poco::Net::HTTPServer>> RESTServers_;
Poco::ThreadPool Pool_; Poco::ThreadPool Pool_{"i-rest",2,16};
RESTAPI_GenericServer Server_; RESTAPI_GenericServer Server_;
RESTAPI_IntServer() noexcept: RESTAPI_IntServer() noexcept:
SubSystemServer("RESTAPI_IntServer", "REST-ISRV", "openwifi.internal.restapi"), SubSystemServer("RESTAPI_IntServer", "REST-ISRV", "openwifi.internal.restapi")
Pool_("RESTAPI_IntServer",4,50,120)
{ {
} }
}; };
@@ -3188,6 +3187,7 @@ namespace OpenWifi {
public: public:
inline IntRequestHandlerFactory() = default; inline IntRequestHandlerFactory() = default;
inline Poco::Net::HTTPRequestHandler *createRequestHandler(const Poco::Net::HTTPServerRequest &Request) override { inline Poco::Net::HTTPRequestHandler *createRequestHandler(const Poco::Net::HTTPServerRequest &Request) override {
Utils::SetThreadName(fmt::format("i-rest:{}",TransactionId_).c_str());
Poco::URI uri(Request.getURI()); Poco::URI uri(Request.getURI());
return RESTAPI_IntServer()->CallServer(uri.getPath(), TransactionId_); return RESTAPI_IntServer()->CallServer(uri.getPath(), TransactionId_);
} }
@@ -3231,7 +3231,6 @@ namespace OpenWifi {
} }
[[nodiscard]] std::string Version() { return Version_; } [[nodiscard]] std::string Version() { return Version_; }
// [[nodiscard]] const Poco::SharedPtr<Poco::Crypto::RSAKey> & Key() { return AppKey_; }
[[nodiscard]] inline const std::string & DataDir() { return DataDir_; } [[nodiscard]] inline const std::string & DataDir() { return DataDir_; }
[[nodiscard]] inline const std::string & WWWAssetsDir() { return WWWAssetsDir_; } [[nodiscard]] inline const std::string & WWWAssetsDir() { return WWWAssetsDir_; }
[[nodiscard]] bool Debug() const { return DebugMode_; } [[nodiscard]] bool Debug() const { return DebugMode_; }
@@ -3264,7 +3263,12 @@ namespace OpenWifi {
return Poco::Logger::get(Name); return Poco::Logger::get(Name);
} }
static inline void Exit(int Reason); virtual void GetExtraConfiguration(Poco::JSON::Object & Cfg) {
Cfg.set("additionalConfiguration",false);
}
static inline void Exit(int Reason);
inline void BusMessageReceived(const std::string &Key, const std::string & Payload); inline void BusMessageReceived(const std::string &Key, const std::string & Payload);
inline MicroServiceMetaVec GetServices(const std::string & Type); inline MicroServiceMetaVec GetServices(const std::string & Type);
inline MicroServiceMetaVec GetServices(); inline MicroServiceMetaVec GetServices();
@@ -3330,6 +3334,9 @@ namespace OpenWifi {
return Signer_.sign(T,Algo); return Signer_.sign(T,Algo);
} }
} }
inline Poco::ThreadPool & TimerPool() { return TimerPool_; }
private: private:
static MicroService * instance_; static MicroService * instance_;
bool HelpRequested_ = false; bool HelpRequested_ = false;
@@ -3364,6 +3371,7 @@ namespace OpenWifi {
bool NoBuiltInCrypto_=false; bool NoBuiltInCrypto_=false;
Poco::JWT::Signer Signer_; Poco::JWT::Signer Signer_;
Poco::Logger &Logger_; Poco::Logger &Logger_;
Poco::ThreadPool TimerPool_{"timer:pool",2,16};
}; };
inline void MicroService::Exit(int Reason) { inline void MicroService::Exit(int Reason) {
@@ -3576,8 +3584,6 @@ namespace OpenWifi {
void DaemonPostInitialization(Poco::Util::Application &self); void DaemonPostInitialization(Poco::Util::Application &self);
inline void MicroService::initialize(Poco::Util::Application &self) { inline void MicroService::initialize(Poco::Util::Application &self) {
// Utils::SetThreadName("microservice");
// add the default services // add the default services
LoadConfigurationFile(); LoadConfigurationFile();
InitializeLoggingSystem(); InitializeLoggingSystem();
@@ -3919,6 +3925,7 @@ namespace OpenWifi {
Params->setMaxThreads(50); Params->setMaxThreads(50);
Params->setMaxQueued(200); Params->setMaxQueued(200);
Params->setKeepAlive(true); Params->setKeepAlive(true);
Params->setName("ws:xrest");
std::unique_ptr<Poco::Net::HTTPServer> NewServer; std::unique_ptr<Poco::Net::HTTPServer> NewServer;
if(MicroService::instance().NoAPISecurity()) { if(MicroService::instance().NoAPISecurity()) {
@@ -3955,6 +3962,7 @@ namespace OpenWifi {
Params->setMaxThreads(50); Params->setMaxThreads(50);
Params->setMaxQueued(200); Params->setMaxQueued(200);
Params->setKeepAlive(true); Params->setKeepAlive(true);
Params->setName("ws:irest");
std::unique_ptr<Poco::Net::HTTPServer> NewServer; std::unique_ptr<Poco::Net::HTTPServer> NewServer;
if(MicroService::instance().NoAPISecurity()) { if(MicroService::instance().NoAPISecurity()) {
@@ -3972,8 +3980,6 @@ namespace OpenWifi {
} }
inline int MicroService::main([[maybe_unused]] const ArgVec &args) { inline int MicroService::main([[maybe_unused]] const ArgVec &args) {
// Utils::SetThreadName("main");
MyErrorHandler ErrorHandler(*this); MyErrorHandler ErrorHandler(*this);
Poco::ErrorHandler::set(&ErrorHandler); Poco::ErrorHandler::set(&ErrorHandler);
@@ -4080,6 +4086,7 @@ namespace OpenWifi {
Port_ = (int)MicroService::instance().ConfigGetInt("alb.port",15015); Port_ = (int)MicroService::instance().ConfigGetInt("alb.port",15015);
Socket_ = std::make_unique<Poco::Net::ServerSocket>(Port_); Socket_ = std::make_unique<Poco::Net::ServerSocket>(Port_);
auto Params = new Poco::Net::HTTPServerParams; auto Params = new Poco::Net::HTTPServerParams;
Params->setName("ws:alb");
Server_ = std::make_unique<Poco::Net::HTTPServer>(new ALBRequestHandlerFactory(Logger()), *Socket_, Params); Server_ = std::make_unique<Poco::Net::HTTPServer>(new ALBRequestHandlerFactory(Logger()), *Socket_, Params);
Server_->start(); Server_->start();
} }
@@ -4089,7 +4096,7 @@ namespace OpenWifi {
inline void BusEventManager::run() { inline void BusEventManager::run() {
Running_ = true; Running_ = true;
Utils::SetThreadName("BusEventManager"); Utils::SetThreadName("fmwk:EventMgr");
auto Msg = MicroService::instance().MakeSystemEventMessage(KafkaTopics::ServiceEvents::EVENT_JOIN); auto Msg = MicroService::instance().MakeSystemEventMessage(KafkaTopics::ServiceEvents::EVENT_JOIN);
KafkaManager()->PostMessage(KafkaTopics::SERVICE_EVENTS,MicroService::instance().PrivateEndPoint(),Msg, false); KafkaManager()->PostMessage(KafkaTopics::SERVICE_EVENTS,MicroService::instance().PrivateEndPoint(),Msg, false);
while(Running_) { while(Running_) {
@@ -4176,7 +4183,7 @@ namespace OpenWifi {
inline void KafkaProducer::run() { inline void KafkaProducer::run() {
Utils::SetThreadName("KafkaProducer"); Utils::SetThreadName("Kafka:Prod");
cppkafka::Configuration Config({ cppkafka::Configuration Config({
{ "client.id", MicroService::instance().ConfigGetString("openwifi.kafka.client.id") }, { "client.id", MicroService::instance().ConfigGetString("openwifi.kafka.client.id") },
{ "metadata.broker.list", MicroService::instance().ConfigGetString("openwifi.kafka.brokerlist") } { "metadata.broker.list", MicroService::instance().ConfigGetString("openwifi.kafka.brokerlist") }
@@ -4215,7 +4222,7 @@ namespace OpenWifi {
} }
inline void KafkaConsumer::run() { inline void KafkaConsumer::run() {
Utils::SetThreadName("KafkaConsumer"); Utils::SetThreadName("Kafka:Cons");
cppkafka::Configuration Config({ cppkafka::Configuration Config({
{ "client.id", MicroService::instance().ConfigGetString("openwifi.kafka.client.id") }, { "client.id", MicroService::instance().ConfigGetString("openwifi.kafka.client.id") },
@@ -4355,6 +4362,11 @@ namespace OpenWifi {
Answer.set("certificates", Certificates); Answer.set("certificates", Certificates);
return ReturnObject(Answer); return ReturnObject(Answer);
} }
if(GetBoolParameter("extraConfiguration")) {
Poco::JSON::Object Answer;
MicroService::instance().GetExtraConfiguration(Answer);
return ReturnObject(Answer);
}
BadRequest(RESTAPI::Errors::InvalidCommand); BadRequest(RESTAPI::Errors::InvalidCommand);
} }
@@ -4876,7 +4888,7 @@ namespace OpenWifi {
void SendToAll(const std::string &Payload); void SendToAll(const std::string &Payload);
private: private:
mutable std::atomic_bool Running_ = false; mutable std::atomic_bool Running_ = false;
Poco::Thread Thr_; Poco::Thread Thr_;
// std::unique_ptr<MyParallelSocketReactor> ReactorPool_; // std::unique_ptr<MyParallelSocketReactor> ReactorPool_;
Poco::Net::SocketReactor Reactor_; Poco::Net::SocketReactor Reactor_;
Poco::Thread ReactorThread_; Poco::Thread ReactorThread_;
@@ -4966,13 +4978,13 @@ namespace OpenWifi {
[[nodiscard]] inline bool SendToUser(const std::string &userName, const std::string &Payload); [[nodiscard]] inline bool SendToUser(const std::string &userName, const std::string &Payload);
inline WebSocketClientServer::WebSocketClientServer() noexcept: inline WebSocketClientServer::WebSocketClientServer() noexcept:
SubSystemServer("WebSocketClientServer", "WSCLNT-SVR", "websocketclients") SubSystemServer("WebSocketClientServer", "UI-WSCLNT-SVR", "websocketclients")
{ {
} }
inline void WebSocketClientServer::run() { inline void WebSocketClientServer::run() {
Running_ = true ; Running_ = true ;
Utils::SetThreadName("ws:clnt-svr"); Utils::SetThreadName("ws:uiclnt-svr");
while(Running_) { while(Running_) {
Poco::Thread::trySleep(2000); Poco::Thread::trySleep(2000);
@@ -5065,7 +5077,7 @@ namespace OpenWifi {
case Poco::Net::WebSocket::FRAME_OP_PONG: { case Poco::Net::WebSocket::FRAME_OP_PONG: {
} break; } break;
case Poco::Net::WebSocket::FRAME_OP_CLOSE: { case Poco::Net::WebSocket::FRAME_OP_CLOSE: {
Logger().warning(Poco::format("CLOSE(%s): Client is closing its connection.", Id_)); Logger().warning(Poco::format("CLOSE(%s): UI Client is closing its connection.", Id_));
Done = true; Done = true;
} break; } break;
case Poco::Net::WebSocket::FRAME_OP_TEXT: { case Poco::Net::WebSocket::FRAME_OP_TEXT: {
@@ -5204,7 +5216,7 @@ namespace OpenWifi {
try try
{ {
Poco::Net::WebSocket WS(*Request, *Response); Poco::Net::WebSocket WS(*Request, *Response);
Logger().information("WebSocket connection established."); Logger().information("UI-WebSocket connection established.");
auto Id = MicroService::CreateUUID(); auto Id = MicroService::CreateUUID();
WebSocketClientServer()->NewClient(WS,Id); WebSocketClientServer()->NewClient(WS,Id);
} }