Commit 36d7fbd7 authored by jan.koester's avatar jan.koester
Browse files

test

parent 860e4278
Loading
Loading
Loading
Loading
+10 −5
Changes for src/api/JsonApiServer.cpp: 10 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -355,8 +355,10 @@ JsonApiController::JsonApiController(std::vector<netplus::socket *> serverSocket
                                      auth::IAuthService &authService,
                                      lb::LoadBalancer &loadBalancer,
                                      cluster::ClusterManager *clusterManager,
                                      tls::CertificateManager &certManager)
    : libhttppp::HttpEvent(std::move(serverSockets))
                                      tls::CertificateManager &certManager,
                                      int idleTimeoutSeconds)
    : libhttppp::HttpEvent(std::move(serverSockets), /*timeout=*/1000, /*h2OffloadThreads=*/0,
                            idleTimeoutSeconds)
    , _cfg(std::move(cfg))
    , _staticDir(std::move(staticDir))
    , _configStore(configStore)
@@ -1059,7 +1061,8 @@ JsonApiServer::JsonApiServer(config::AppConfig cfg, std::string staticDir, std::
                              std::string keyPath, store::ConfigStore &configStore,
                              auth::IAuthService &authService, lb::LoadBalancer &loadBalancer,
                              cluster::ClusterManager *clusterManager,
                              tls::CertificateManager &certManager)
                              tls::CertificateManager &certManager,
                              int idleTimeoutSeconds)
    : _cfg(cfg)
    , _staticDir(std::move(staticDir))
    , _httpd(std::make_unique<libhttppp::HttpD>(cfg.adminListen, cfg.adminPort, 256, certPath,
@@ -1068,7 +1071,8 @@ JsonApiServer::JsonApiServer(config::AppConfig cfg, std::string staticDir, std::
    , _authService(authService)
    , _loadBalancer(loadBalancer)
    , _clusterManager(clusterManager)
    , _certManager(certManager) {
    , _certManager(certManager)
    , _idleTimeoutSeconds(idleTimeoutSeconds) {
    // See HttpProxyServer::HttpProxyServer -- same lazy-bind hazard applies to the admin
    // listener's socket.
    for (auto *sock : _httpd->getServerSockets()) {
@@ -1079,7 +1083,8 @@ JsonApiServer::JsonApiServer(config::AppConfig cfg, std::string staticDir, std::

void JsonApiServer::run() {
    JsonApiController controller(_httpd->getServerSockets(), _cfg, _staticDir, _configStore,
                                  _authService, _loadBalancer, _clusterManager, _certManager);
                                  _authService, _loadBalancer, _clusterManager, _certManager,
                                  _idleTimeoutSeconds);
    controller.runEventloop();
}

+10 −2
Changes for src/api/JsonApiServer.h: 10 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -23,6 +23,9 @@ namespace proxyplus::api {
//   api.route("POST", "/api/v1/smtp/relays", requirePermission("smtp.domains.write"), ...);
class JsonApiController : public libhttppp::HttpEvent {
public:
    // idleTimeoutSeconds is forwarded straight to the libhttppp::HttpEvent base (see its own
    // doc comment in httpd.h) -- default 0 keeps today's behavior for any caller that doesn't
    // pass it explicitly; main.cpp's real call site passes AppConfig::idleConnectionTimeoutSeconds.
    JsonApiController(std::vector<netplus::socket *> serverSockets,
                       config::AppConfig cfg,
                       std::string staticDir,
@@ -30,7 +33,8 @@ public:
                       auth::IAuthService &authService,
                       lb::LoadBalancer &loadBalancer,
                       cluster::ClusterManager *clusterManager, // nullptr in single-node mode
                       tls::CertificateManager &certManager);
                       tls::CertificateManager &certManager,
                       int idleTimeoutSeconds = 0);

    void RequestEvent(libhttppp::HttpRequest &curreq, const int tid, ULONG_PTR args) override;

@@ -71,10 +75,13 @@ private:
// Binds at construction time, same rationale as HttpProxyServer/SmtpProxyServer.
class JsonApiServer {
public:
    // idleTimeoutSeconds: see JsonApiController's own doc comment above -- threaded down into
    // the controller it constructs internally in run().
    JsonApiServer(config::AppConfig cfg, std::string staticDir, std::string certPath,
                   std::string keyPath, store::ConfigStore &configStore,
                   auth::IAuthService &authService, lb::LoadBalancer &loadBalancer,
                   cluster::ClusterManager *clusterManager, tls::CertificateManager &certManager);
                   cluster::ClusterManager *clusterManager, tls::CertificateManager &certManager,
                   int idleTimeoutSeconds = 0);
    void run();

    bool reloadCertificates(const std::string &certPath, const std::string &keyPath) {
@@ -90,6 +97,7 @@ private:
    lb::LoadBalancer &_loadBalancer;
    cluster::ClusterManager *_clusterManager;
    tls::CertificateManager &_certManager;
    int _idleTimeoutSeconds;
};

} // namespace proxyplus::api
+9 −5
Changes for src/http/HttpProxyServer.cpp: 9 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -565,7 +565,8 @@ HttpProxyServer::HttpProxyServer(config::ListenerConfig listener, std::string ce
                                  auth::IAuthService &authService,
                                  plugin::PluginManager &pluginManager,
                                  lb::LoadBalancer &loadBalancer,
                                  tls::AcmeChallengeStore *acmeChallenges)
                                  tls::AcmeChallengeStore *acmeChallenges,
                                  int idleTimeoutSeconds)
    : _listener(listener)
    , _tlsActive(!listener.tlsProfile.empty())
    , _httpd(std::make_unique<libhttppp::HttpD>(listener.address, listener.port, 512, certPath,
@@ -574,7 +575,8 @@ HttpProxyServer::HttpProxyServer(config::ListenerConfig listener, std::string ce
    , _authService(authService)
    , _pluginManager(pluginManager)
    , _loadBalancer(loadBalancer)
    , _acmeChallenges(acmeChallenges) {
    , _acmeChallenges(acmeChallenges)
    , _idleTimeoutSeconds(idleTimeoutSeconds) {
    bindAndListen();
}

@@ -582,7 +584,8 @@ HttpProxyServer::HttpProxyServer(config::ListenerConfig listener,
                                  const std::map<std::string, netplus::ssl::CertificateBundle> &certsByHostname,
                                  store::ConfigStore &configStore, auth::IAuthService &authService,
                                  plugin::PluginManager &pluginManager, lb::LoadBalancer &loadBalancer,
                                  tls::AcmeChallengeStore *acmeChallenges)
                                  tls::AcmeChallengeStore *acmeChallenges,
                                  int idleTimeoutSeconds)
    : _listener(listener)
    , _tlsActive(true)
    , _httpd(std::make_unique<libhttppp::HttpD>(listener.address, listener.port, 512, certsByHostname))
@@ -590,7 +593,8 @@ HttpProxyServer::HttpProxyServer(config::ListenerConfig listener,
    , _authService(authService)
    , _pluginManager(pluginManager)
    , _loadBalancer(loadBalancer)
    , _acmeChallenges(acmeChallenges) {
    , _acmeChallenges(acmeChallenges)
    , _idleTimeoutSeconds(idleTimeoutSeconds) {
    bindAndListen();
}

@@ -609,7 +613,7 @@ void HttpProxyServer::run() {
    HttpProxyController controller(_httpd->getServerSockets(),
                                    _listener.address + ":" + std::to_string(_listener.port),
                                    _tlsActive, _configStore, _authService, _pluginManager,
                                    _loadBalancer, _acmeChallenges);
                                    _loadBalancer, _acmeChallenges, _idleTimeoutSeconds);
    controller.runEventloop();
}

+3 −2
Changes for src/main.cpp: 3 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -331,7 +331,7 @@ int main(int argc, char **argv) {
                    auto sniCerts = loadSniCertMap(cfg, configStore, tlsProfiles);
                    httpServers.push_back(std::make_unique<proxyplus::httpproxy::HttpProxyServer>(
                        listener, sniCerts, configStore, authService, pluginManager, loadBalancer,
                        &acmeChallenges));
                        &acmeChallenges, cfg.idleConnectionTimeoutSeconds));
                    auto *server = httpServers.back().get();
                    auto allProfiles = configStore.listTlsProfiles();
                    for (const auto &profileName : tlsProfiles) {
@@ -351,7 +351,8 @@ int main(int argc, char **argv) {
                std::string profile = tlsProfiles.empty() ? "" : tlsProfiles.front();
                httpServers.push_back(std::make_unique<proxyplus::httpproxy::HttpProxyServer>(
                    listener, certPathFor(cfg, profile), keyPathFor(cfg, profile), configStore,
                    authService, pluginManager, loadBalancer, &acmeChallenges));
                    authService, pluginManager, loadBalancer, &acmeChallenges,
                    cfg.idleConnectionTimeoutSeconds));
                if (!profile.empty()) {
                    auto *server = httpServers.back().get();
                    certManager.registerReloadCallback(profile, [server, &cfg, profile] {