From: Michael Tremer Date: Sun, 15 Sep 2024 03:15:34 +0000 (+0000) Subject: daemon: Remove the buildservice X-Git-Tag: 0.9.30~1196 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=20f66267c1f5d0a0658d48a795f2e70991c76e59;p=pakfire.git daemon: Remove the buildservice It is becoming too complicated to make the buildservice event-driven when it does not need to be. It can live as a single request abstraction model. Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/buildservice.c b/src/libpakfire/buildservice.c index 966551160..e976060b6 100644 --- a/src/libpakfire/buildservice.c +++ b/src/libpakfire/buildservice.c @@ -995,40 +995,3 @@ ERROR: return r; } - -/* - Called before the daemon's -*/ -int pakfire_buildservice_daemon(struct pakfire_buildservice* service, pakfire_xfer_recv_callback recv, - pakfire_xfer_send_callback send, pakfire_xfer_close_callback close, void* data) { - struct pakfire_xfer* xfer = NULL; - int r; - - // Create a new xfer - r = pakfire_httpclient_create_xfer(&xfer, service->httpclient, "/api/v1/builders/control"); - if (r) - goto ERROR; - - // Enable authentication - r = pakfire_xfer_auth(xfer); - if (r) - goto ERROR; - - // Make this a WebSocket connection - r = pakfire_xfer_socket(xfer, recv, send, close, data); - if (r) - goto ERROR; - - // Enqueue the transfer - r = pakfire_httpclient_enqueue_xfer(service->httpclient, xfer); - if (r) - goto ERROR; - - return 0; - -ERROR: - if (xfer) - pakfire_xfer_unref(xfer); - - return r; -} diff --git a/src/libpakfire/daemon.c b/src/libpakfire/daemon.c index 9ceac6f9a..c0b730cb2 100644 --- a/src/libpakfire/daemon.c +++ b/src/libpakfire/daemon.c @@ -24,9 +24,9 @@ #include #include -#include #include #include +#include #include #include @@ -36,12 +36,15 @@ struct pakfire_daemon { struct pakfire_ctx* ctx; int nrefs; - // Pakfire Build Service - struct pakfire_buildservice* service; + // HTTP Client + struct pakfire_httpclient* client; // Event Loop sd_event* loop; + // The control connection + struct pakfire_xfer* control; + // Connection Timer and Holdoff Time sd_event_source* connect_timer; unsigned int reconnect_holdoff; @@ -188,15 +191,43 @@ static int pakfire_daemon_close(struct pakfire_xfer* xfer, int code, void* data) static int pakfire_daemon_connect(sd_event_source* s, uint64_t usec, void* data) { struct pakfire_daemon* daemon = data; + struct pakfire_xfer* xfer = NULL; int r; CTX_INFO(daemon->ctx, "Connecting...\n"); - // Connect to the build service - r = pakfire_buildservice_daemon(daemon->service, - pakfire_daemon_recv, NULL, pakfire_daemon_close, daemon); + // Drop any previous control connections + if (daemon->control) { + pakfire_xfer_unref(daemon->control); + daemon->control = NULL; + } + + // Create a new xfer + r = pakfire_httpclient_create_xfer(&xfer, daemon->client, "/api/v1/builders/control"); + if (r) + goto ERROR; + + // Enable authentication + r = pakfire_xfer_auth(xfer); + if (r) + goto ERROR; + + // Make this a WebSocket connection + r = pakfire_xfer_socket(xfer, pakfire_daemon_recv, NULL, pakfire_daemon_close, daemon); if (r) - CTX_ERROR(daemon->ctx, "Connection attempt failed\n"); + goto ERROR; + + // Enqueue the transfer + r = pakfire_httpclient_enqueue_xfer(daemon->client, xfer); + if (r) + goto ERROR; + + // If everything was successful up to here, we make this our new control connection + daemon->control = pakfire_xfer_ref(xfer); + +ERROR: + if (xfer) + pakfire_xfer_unref(xfer); return r; } @@ -205,10 +236,12 @@ static int pakfire_daemon_submit_stats(sd_event_source* s, uint64_t usec, void* struct pakfire_daemon* daemon = data; int r; +#if 0 // XXX TEMPORARILY DISABLED // Submit stats r = pakfire_buildservice_submit_stats(daemon->service); if (r < 0) CTX_ERROR(daemon->ctx, "Could not submit stats: %s\n", strerror(-r)); +#endif // If we have any workers running, we will submit our stats // every five seconds, otherwise 30 seconds is enough. @@ -283,13 +316,49 @@ static int pakfire_daemon_setup_loop(struct pakfire_daemon* daemon) { return 0; } +static int pakfire_daemon_setup_httpclient(struct pakfire_daemon* daemon) { + struct pakfire_config* config = NULL; + int r; + + // Fetch the configuration + config = pakfire_ctx_get_config(daemon->ctx); + if (!config) { + CTX_ERROR(daemon->ctx, "Could not fetch configuration: %m\n"); + r = -errno; + goto ERROR; + } + + // Fetch the URL + const char* url = pakfire_config_get(config, "daemon", "url", "https://pakfire.ipfire.org"); + + // Create the HTTP client + r = pakfire_httpclient_create(&daemon->client, daemon->ctx, daemon->loop); + if (r) + goto ERROR; + + // Configure the base URL + r = pakfire_httpclient_set_baseurl(daemon->client, url); + if (r) { + CTX_ERROR(daemon->ctx, "Could not configure the URL\n"); + goto ERROR; + } + +ERROR: + if (config) + pakfire_config_unref(config); + + return r; +} + static void pakfire_daemon_free(struct pakfire_daemon* daemon) { if (daemon->connect_timer) sd_event_source_unref(daemon->connect_timer); if (daemon->stat_timer) sd_event_source_unref(daemon->stat_timer); - if (daemon->service) - pakfire_buildservice_unref(daemon->service); + if (daemon->client) + pakfire_httpclient_unref(daemon->client); + if (daemon->control) + pakfire_xfer_unref(daemon->control); if (daemon->loop) sd_event_unref(daemon->loop); if (daemon->ctx) @@ -317,8 +386,8 @@ int pakfire_daemon_create(struct pakfire_daemon** daemon, struct pakfire_ctx* ct if (r) goto ERROR; - // Connect to the buildservice - r = pakfire_buildservice_create(&d->service, d->ctx, d->loop); + // Setup the HTTP client + r = pakfire_daemon_setup_httpclient(d); if (r) goto ERROR; diff --git a/src/libpakfire/include/pakfire/buildservice.h b/src/libpakfire/include/pakfire/buildservice.h index 313991043..fa05cf5e0 100644 --- a/src/libpakfire/include/pakfire/buildservice.h +++ b/src/libpakfire/include/pakfire/buildservice.h @@ -75,15 +75,4 @@ int pakfire_buildservice_submit_stats(struct pakfire_buildservice* service); int pakfire_buildservice_job_finished(struct pakfire_buildservice* service, const char* uuid, int success, const char* logfile, const char** packages); -#ifdef PAKFIRE_PRIVATE - -#include - -// Daemon - -int pakfire_buildservice_daemon(struct pakfire_buildservice* service, pakfire_xfer_recv_callback recv, - pakfire_xfer_send_callback send, pakfire_xfer_close_callback close, void* data); - -#endif /* PAKFIRE_PRIVATE */ - #endif /* PAKFIRE_BUILDSERVICE_H */