LCOV - code coverage report
Current view: top level - src/app - dc_config.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 11 11
Test Date: 2026-04-20 19:54:22 Functions: 100.0 % 1 1

            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           51 : const DcEndpoint *dc_lookup(int dc_id) {
      36           51 :     const char *host = getenv("TG_CLI_DC_HOST");
      37           51 :     const char *port = getenv("TG_CLI_DC_PORT");
      38           51 :     if (host && *host && port && *port) {
      39            5 :         g_override.id   = dc_id;
      40            5 :         g_override.host = host;
      41            5 :         g_override.port = atoi(port);
      42            5 :         return &g_override;
      43              :     }
      44          175 :     for (size_t i = 0; i < ENDPOINT_COUNT; i++) {
      45          168 :         if (ENDPOINTS[i].id == dc_id) return &ENDPOINTS[i];
      46              :     }
      47            7 :     return NULL;
      48              : }
        

Generated by: LCOV version 2.0-1