upleb.uk

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

summaryrefslogtreecommitdiff
path: root/main/tollgate_main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main/tollgate_main.c')
-rw-r--r--main/tollgate_main.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/main/tollgate_main.c b/main/tollgate_main.c
index ad5211a..4741765 100644
--- a/main/tollgate_main.c
+++ b/main/tollgate_main.c
@@ -24,6 +24,9 @@
24#include "lightning_payout.h" 24#include "lightning_payout.h"
25#include "cvm_server.h" 25#include "cvm_server.h"
26#include "display.h" 26#include "display.h"
27#include "local_relay.h"
28#include "relay_selector.h"
29#include "sync_manager.h"
27 30
28#define MAX_STA_RETRY 5 31#define MAX_STA_RETRY 5
29static const char *TAG = "tollgate_main"; 32static const char *TAG = "tollgate_main";
@@ -38,6 +41,9 @@ static bool s_services_running = false;
38static SemaphoreHandle_t s_services_mutex = NULL; 41static SemaphoreHandle_t s_services_mutex = NULL;
39static char s_ap_ip_str[16] = "10.0.0.1"; 42static char s_ap_ip_str[16] = "10.0.0.1";
40 43
44static relay_selector_t s_relay_selector;
45static sync_manager_t s_sync_manager;
46
41static void start_services(void); 47static void start_services(void);
42static void stop_services(void); 48static void stop_services(void);
43 49
@@ -159,6 +165,12 @@ static void start_services(void)
159 captive_portal_start(cfg->ap_ip_str); 165 captive_portal_start(cfg->ap_ip_str);
160 tollgate_api_start(); 166 tollgate_api_start();
161 167
168 relay_selector_init(&s_relay_selector);
169 relay_selector_seed_from_config(&s_relay_selector);
170
171 sync_manager_init(&s_sync_manager, &s_relay_selector);
172 sync_manager_start(&s_sync_manager);
173
162 xTaskCreate(publish_wifistr_task, "wifistr_init", 16384, NULL, 3, NULL); 174 xTaskCreate(publish_wifistr_task, "wifistr_init", 16384, NULL, 3, NULL);
163 175
164 const tollgate_config_t *cfg2 = tollgate_config_get(); 176 const tollgate_config_t *cfg2 = tollgate_config_get();
@@ -189,6 +201,9 @@ static void stop_services(void)
189 tollgate_api_stop(); 201 tollgate_api_stop();
190 dns_server_stop(); 202 dns_server_stop();
191 cvm_server_stop(); 203 cvm_server_stop();
204 sync_manager_stop(&s_sync_manager);
205 local_relay_stop();
206 relay_selector_destroy(&s_relay_selector);
192 firewall_revoke_all(); 207 firewall_revoke_all();
193 s_services_running = false; 208 s_services_running = false;
194 if (s_services_mutex) xSemaphoreGive(s_services_mutex); 209 if (s_services_mutex) xSemaphoreGive(s_services_mutex);
@@ -311,6 +326,9 @@ void app_main(void)
311 326
312 ESP_ERROR_CHECK(esp_wifi_start()); 327 ESP_ERROR_CHECK(esp_wifi_start());
313 328
329 local_relay_init();
330 local_relay_start();
331
314 ESP_LOGI(TAG, "WiFi AP+STA started, waiting for connection..."); 332 ESP_LOGI(TAG, "WiFi AP+STA started, waiting for connection...");
315 333
316 if (tollgate_config_get_wifi(&(wifi_config_t){0}) != ESP_OK) { 334 if (tollgate_config_get_wifi(&(wifi_config_t){0}) != ESP_OK) {