]> git.ipfire.org Git - pakfire.git/commitdiff
daemon: Remove the buildservice
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 15 Sep 2024 03:15:34 +0000 (03:15 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 15 Sep 2024 03:15:34 +0000 (03:15 +0000)
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 <michael.tremer@ipfire.org>
src/libpakfire/buildservice.c
src/libpakfire/daemon.c
src/libpakfire/include/pakfire/buildservice.h

index 966551160722940729bab4098472726efa474ccf..e976060b62784087729485fd11014c1650944145 100644 (file)
@@ -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;
-}
index 9ceac6f9afbaddca4594795b98ebcbb1ff2e3529..c0b730cb201d169233f96cf4df847d2a445fda79 100644 (file)
@@ -24,9 +24,9 @@
 #include <systemd/sd-daemon.h>
 #include <systemd/sd-event.h>
 
-#include <pakfire/buildservice.h>
 #include <pakfire/ctx.h>
 #include <pakfire/daemon.h>
+#include <pakfire/httpclient.h>
 #include <pakfire/util.h>
 #include <pakfire/worker.h>
 
@@ -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;
 
index 313991043a6957091f8efa5d4fd32dc3ddeec302..fa05cf5e05caa7d1a05f133aaea2a97619039c0c 100644 (file)
@@ -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 <pakfire/xfer.h>
-
-// 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 */