<commit_before>/*
 * Handler for control messages.
 *
 * author: <NAME> <<EMAIL>>
 */

#include "control-handler.h"
#include "control-server.h"
#include "udp-listener.h"
#include "udp-distribute.h"
#include "instance.h"

#include <daemon/log.h>

#include <glib.h>
#include <assert.h>
#include <arpa/inet.h>

static void
global_control_packet(enum beng_control_command command,
                      const void *payload, size_t payload_length,
                      void *ctx)
{
    struct instance *instance = ctx;

    (void)payload;
    (void)instance;

    daemon_log(5, "control command=%d payload_length=%zu\n",
               command, payload_length);
}

static const struct control_handler global_control_handler = {
    .packet = global_control_packet,
};

static struct udp_distribute *global_udp_distribute;

static void
global_control_udp_callback(const void *data, size_t length,
                            G_GNUC_UNUSED const struct sockaddr *addr,
                            G_GNUC_UNUSED size_t addrlen,
                            void *ctx)
{
    struct instance *instance = ctx;

    /* forward the packet to all worker processes */
    udp_distribute_packet(global_udp_distribute, data, length);

    /* handle the packet in this process */
    control_server_decode(data, length, &global_control_handler, instance);<commit_msg>control-handler: add switch(command), just NOP handled now<commit_after>/*
 * Handler for control messages.
 *
 * author: <NAME> <<EMAIL>>
 */

#include "control-handler.h"
#include "control-server.h"
#include "udp-listener.h"
#include "udp-distribute.h"
#include "instance.h"

#include <daemon/log.h>

#include <glib.h>
#include <assert.h>
#include <arpa/inet.h>

static void
global_control_packet(enum beng_control_command command,
                      const void *payload, size_t payload_length,
                      void *ctx)
{
    struct instance *instance = ctx;

    (void)payload;
    (void)instance;

    daemon_log(5, "control command=%d payload_length=%zu\n",
               command, payload_length);

    switch (command) {
    case BENG_CONTROL_NOP:
        /* duh! */
        break;
    }
}

static const struct control_handler global_control_handler = {
    .packet = global_control_packet,
};

static struct udp_distribute *global_udp_distribute;

static void
global_control_udp_callback(const void *data, size_t length,
                            G_GNUC_UNUSED const struct sockaddr *addr,
                            G_GNUC_UNUSED size_t addrlen,
                            void *ctx)
{
    struct instance *instance = ctx;

    /* forward the packet to all worker processes */
    udp_distribute_packet(global_udp_distribute, data, length);

    /* handle the packet in this process */
    control_server_decode(data, length, &global_control_handler, instance);
{'fraction_non_alphanumeric': 0.0995059985885674, 'fraction_numerical': 0.0007057163020465773, 'mean_word_length': 2.888888888888889, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3355603', 'n_tokens_mistral': 873, 'n_tokens_neox': 857, 'n_words': 215}