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;
-}
#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>
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;
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;
}
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.
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)
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;