upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/main/tls_worker.c
blob: 1c3a7ef35cb2fc7fd6e8a669cd99c17d9500f92c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "tls_worker.h"
#include "nucula_wallet.h"
#include "esp_log.h"
#include <string.h>
#include <stdlib.h>

static const char *TAG = "tls_worker";
static QueueHandle_t s_wallet_queue = NULL;

void tls_worker_set_queue(QueueHandle_t q)
{
    s_wallet_queue = q;
}

void tls_worker_submit(const char *token)
{
    if (!s_wallet_queue) {
        ESP_LOGW(TAG, "No wallet queue, receiving synchronously");
        nucula_wallet_receive(token);
        return;
    }

    char *copy = strdup(token);
    if (!copy) return;

    if (xQueueSend(s_wallet_queue, &copy, pdMS_TO_TICKS(1000)) != pdTRUE) {
        ESP_LOGW(TAG, "Wallet queue full, receiving synchronously");
        nucula_wallet_receive(copy);
        free(copy);
    }
}