From dac827b81a8e29cb83fb17985ad5e83770cd833f Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Fri, 4 Jun 2021 01:12:24 +0200 Subject: Reconnect the analysis clients to servers when requested. --- src/analysis/db/analyst.c | 30 +++++++++++++++++++++++++++++- src/analysis/db/cdb.c | 4 ++-- src/analysis/db/client-int.h | 8 ++++++++ src/analysis/db/client.c | 15 +++++++++++---- src/analysis/db/server.c | 4 ++-- 5 files changed, 52 insertions(+), 9 deletions(-) diff --git a/src/analysis/db/analyst.c b/src/analysis/db/analyst.c index 87a60d3..dff073a 100644 --- a/src/analysis/db/analyst.c +++ b/src/analysis/db/analyst.c @@ -78,6 +78,9 @@ static void g_analyst_client_dispose(GAnalystClient *); /* Procède à la libération totale de la mémoire. */ static void g_analyst_client_finalize(GAnalystClient *); +/* Termine la constitution des données initiales à présenter. */ +static bool g_analyst_client_complete_hello(GAnalystClient *, packed_buffer_t *); + /* Assure l'accueil des nouvelles mises à jour. */ static void *g_analyst_client_update(GAnalystClient *); @@ -118,6 +121,7 @@ static void g_analyst_client_class_init(GAnalystClientClass *klass) client = G_HUB_CLIENT_CLASS(klass); client->role = CRL_ANALYST; + client->complete_hello = (complete_client_hello_fc)g_analyst_client_complete_hello; client->recv_func = (GThreadFunc)g_analyst_client_update; g_signal_new("snapshots-updated", @@ -243,7 +247,7 @@ GAnalystClient *g_analyst_client_new(const char *hash, GList *collections) { GAnalystClient *result; /* Adresse à retourner */ - result = g_object_new(G_TYPE_HUB_CLIENT, NULL); + result = g_object_new(G_TYPE_ANALYST_CLIENT, NULL); init_static_rle_string(&result->hash, hash); result->collections = collections; @@ -256,6 +260,30 @@ GAnalystClient *g_analyst_client_new(const char *hash, GList *collections) /****************************************************************************** * * * Paramètres : client = client pour les accès distants à manipuler. * +* pbuf = tampon d'émission initial à compléter. * +* * +* Description : Termine la constitution des données initiales à présenter. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool g_analyst_client_complete_hello(GAnalystClient *client, packed_buffer_t *pbuf) +{ + bool result; /* Bilan à retourner */ + + result = pack_rle_string(&client->hash, pbuf); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : client = client pour les accès distants à manipuler. * * * * Description : Assure l'accueil des nouvelles mises à jour. * * * diff --git a/src/analysis/db/cdb.c b/src/analysis/db/cdb.c index d2997c7..4da55fd 100644 --- a/src/analysis/db/cdb.c +++ b/src/analysis/db/cdb.c @@ -73,7 +73,7 @@ typedef struct _cdb_client /* Description d'une archive d'éléments utilisateur (instance) */ struct _GCdbArchive { - GObject parent; /* A laisser en premier */ + GServerBackend parent; /* A laisser en premier */ rle_string hash; /* Empreinte cryptographique */ @@ -95,7 +95,7 @@ struct _GCdbArchive /* Description d'une archive d'éléments utilisateur (classe) */ struct _GCdbArchiveClass { - GObjectClass parent; /* A laisser en premier */ + GServerBackendClass parent; /* A laisser en premier */ }; diff --git a/src/analysis/db/client-int.h b/src/analysis/db/client-int.h index 83c5039..3c140e9 100644 --- a/src/analysis/db/client-int.h +++ b/src/analysis/db/client-int.h @@ -28,6 +28,13 @@ #include "client.h" +#include "../../common/packed.h" + + + +/* Termine la constitution des données initiales à présenter. */ +typedef bool (* complete_client_hello_fc) (GHubClient *, packed_buffer_t *); + /* Description de client à l'écoute (instance) */ struct _GHubClient @@ -54,6 +61,7 @@ struct _GHubClientClass GObjectClass parent; /* A laisser en premier */ uint32_t role; /* Rôle associé aux clients */ + complete_client_hello_fc complete_hello;/* Finalisation de l'intro */ GThreadFunc recv_func; /* Réception de données */ }; diff --git a/src/analysis/db/client.c b/src/analysis/db/client.c index aa1407c..6ce33b0 100644 --- a/src/analysis/db/client.c +++ b/src/analysis/db/client.c @@ -99,6 +99,10 @@ static void g_hub_client_class_init(GHubClientClass *klass) object->dispose = (GObjectFinalizeFunc/* ! */)g_hub_client_dispose; object->finalize = (GObjectFinalizeFunc)g_hub_client_finalize; + klass->role = CRL_UNDEFINED; + klass->complete_hello = NULL; + klass->recv_func = NULL; + } @@ -485,7 +489,8 @@ static bool g_hub_client_start_common(GHubClient *client, char *desc) * On réalise l'envoi initial ; le premier paquet doit contenir : * - la commande 'DBC_HELO' ; * - le numéro de version du client ; - * - le rôle attendu de la connexion. + * - le rôle attendu de la connexion ; + * - des données complémentaires éventuelles. * * Tout ceci est à synchroniser avec la fonction g_db_server_listener(). */ @@ -501,9 +506,11 @@ static bool g_hub_client_start_common(GHubClient *client, char *desc) status = extend_packed_buffer(&out_pbuf, &class->role, sizeof(uint32_t), true); if (!status) goto setup_error; - - - + if (class->complete_hello != NULL) + { + status = class->complete_hello(client, &out_pbuf); + if (!status) goto setup_error; + } status = ssl_send_packed_buffer(&out_pbuf, client->tls_fd); if (!status) goto setup_error; diff --git a/src/analysis/db/server.c b/src/analysis/db/server.c index f324c74..b08962c 100644 --- a/src/analysis/db/server.c +++ b/src/analysis/db/server.c @@ -925,8 +925,8 @@ static void *g_hub_server_listener(GHubServer *server) break; default: - log_variadic_message(LMT_ERROR, _("Unknown client role requested by '%s'"), - peer_name); + log_variadic_message(LMT_ERROR, _("Unknown client role 0x%x requested by '%s'"), + role, peer_name); backend = NULL; error = DBE_BAD_EXCHANGE; new = false; -- cgit v0.11.2-87-g4458