Line data Source code
1 : /* SPDX-License-Identifier: GPL-3.0-or-later */
2 : /* Copyright 2026 Peter Csaszar */
3 :
4 : /**
5 : * @file app/dc_config.c
6 : * @brief Hardcoded fallback DC endpoint table.
7 : */
8 :
9 : #include "app/dc_config.h"
10 :
11 : #include <stddef.h>
12 : #include <stdlib.h>
13 :
14 : static const DcEndpoint ENDPOINTS[] = {
15 : { 1, "149.154.175.50", 443 },
16 : { 2, "149.154.167.50", 443 },
17 : { 3, "149.154.175.100", 443 },
18 : { 4, "149.154.167.91", 443 },
19 : { 5, "91.108.56.130", 443 },
20 : };
21 :
22 : #define ENDPOINT_COUNT (sizeof(ENDPOINTS) / sizeof(ENDPOINTS[0]))
23 :
24 : /**
25 : * @brief Per-process redirect used by tests.
26 : *
27 : * When TG_CLI_DC_HOST and TG_CLI_DC_PORT are set in the environment every
28 : * dc_lookup() call returns a synthetic endpoint pointing at those
29 : * coordinates. This lets the PTY-based functional tests redirect the
30 : * production binary to a local stub server without modifying the binary or
31 : * the DC table.
32 : */
33 : static DcEndpoint g_override;
34 :
35 16 : const DcEndpoint *dc_lookup(int dc_id) {
36 16 : const char *host = getenv("TG_CLI_DC_HOST");
37 16 : const char *port = getenv("TG_CLI_DC_PORT");
38 16 : if (host && *host && port && *port) {
39 0 : g_override.id = dc_id;
40 0 : g_override.host = host;
41 0 : g_override.port = atoi(port);
42 0 : return &g_override;
43 : }
44 61 : for (size_t i = 0; i < ENDPOINT_COUNT; i++) {
45 60 : if (ENDPOINTS[i].id == dc_id) return &ENDPOINTS[i];
46 : }
47 1 : return NULL;
48 : }
|