Browse Source

config

nodeinfo-routing-update
jeka 1 month ago
parent
commit
b20bff32dd
  1. 6
      AGENTS.md
  2. 2
      doc/etcp_protocol.txt
  3. 28
      lib/debug_config.c
  4. 16
      lib/debug_config.h
  5. 1
      src/Makefile.am
  6. 4
      src/config_parser.c
  7. 7
      src/config_parser.h
  8. 16
      src/etcp.c
  9. 3
      tests/Makefile.am

6
AGENTS.md

@ -12,15 +12,15 @@ This file contains essential information for AI coding agents working in the uTu
## 🔧 Build Commands
### Full Build
win: powershell build.bat (без аргументов и дополнительных команд, текущий каталог не важен)
win: powershell build_full.bat (в точности как написано без дополнительных опций powershell, текущий каталог не важен)
```bash
./autogen.sh # Generate configure script (if needed)
./configure # Configure build
make # Build everything
make install # Install (requires sudo)
```
### Partial Builds
win: powershell build.bat (аналог make если не изменен makefile.am)
```bash
cd lib && make # Build only the library
cd src && make # Build only the main program
@ -28,7 +28,6 @@ cd tests && make # Build only tests
```
### Clean Build
win: powershell build_full.bat (без аргументов, текущий каталог не важен)
```bash
make clean # Clean object files
make distclean # Clean everything including configure files
@ -37,6 +36,7 @@ make distclean # Clean everything including configure files
## 🧪 Test Commands
### Run All Tests
win: powershell check.bat
```bash
make check # Run all tests via automake
```

2
doc/etcp_protocol.txt

@ -102,7 +102,7 @@ bandwidth по каждому линку адаптивно подстраива
**** Формат кодограмм для etcp_connections.c/h ****
Кодограммы с этими секциями обрабатываются в etcp_connections (в этих кодограммах всегда только одна секция). в обязательном заголовке ID не используется, при передаче для порядка =0: [СПОРНО: заголовок в etcp — только 2 байта TS; здесь подразумевается ID? Уточнить единый формат]
1) Init запрос - заголовок 0x02 (со сбросом etcp сессии) или 0x04 (без сброса):
[0x02/0x04] [my_node_id 64bit] [my mtu high] [my mtu low] [keepalive high] [keepalive low] [my link_id 1 байт] [my public key (64 байта, не шифруется)]
[0x02/0x04] [my_node_id 64bit] [my mtu high] [my mtu low] [keepalive high] [keepalive low] [recovery high] [recovery low] [my link_id 1 байт] [my public key (64 байта, не шифруется)]
- Инициирует новый connection для tcp instance. если tcp instance нет (первое подключение) - создаёт. Между нодами только одно подключение, но можно добавлять каналы.
- link_id: локальный идентификатор канала (0-255), назначается отправителем для идентификации канала
- Публичный ключ отправляется в конце пакета без шифрования, чтобы получатель мог установить его и расшифровать остальную часть пакета (т.к. инициатор соединения всегда имеет оригинальный peer public key в конфиге - по нему исключаем MITM)

28
lib/debug_config.c

@ -75,6 +75,7 @@ static debug_category_t get_category_by_name(const char* name) {
{"tun", DEBUG_CATEGORY_TUN},
{"routing", DEBUG_CATEGORY_ROUTING},
{"timers", DEBUG_CATEGORY_TIMERS},
{"dump", DEBUG_CATEGORY_DUMP},
{"all", DEBUG_CATEGORY_ALL},
{NULL, 0}
};
@ -92,8 +93,11 @@ debug_config_t g_debug_config;
/* Initialize debug system with default settings */
void debug_config_init(void) {
g_debug_config.level = DEBUG_LEVEL_TRACE; // Global level
g_debug_config.level = DEBUG_LEVEL_ERROR; // Global level: errors only by default
g_debug_config.categories = DEBUG_CATEGORY_ALL;
for (int i = 0; i < DEBUG_CATEGORY_COUNT; i++) {
g_debug_config.category_levels[i] = DEBUG_LEVEL_NONE; // 0 = disabled per category
}
g_debug_config.timestamp_enabled = 1;
g_debug_config.function_name_enabled = 1;
g_debug_config.file_line_enabled = 1;
@ -112,6 +116,18 @@ void debug_set_level(debug_level_t level) {
g_debug_config.console_level = level;
}
/* Set debug level for specific category (0 = disabled, otherwise uses that level) */
void debug_set_category_level(debug_category_t category, debug_level_t level) {
if (category == DEBUG_CATEGORY_NONE) return;
int idx = 0;
while (!(category & (1ULL << idx)) && idx < DEBUG_CATEGORY_COUNT) {
idx++;
}
if (idx < DEBUG_CATEGORY_COUNT) {
g_debug_config.category_levels[idx] = level;
}
}
/* Enable/disable specific categories */
void debug_enable_category(debug_category_t category) {
g_debug_config.categories |= category;
@ -200,8 +216,16 @@ int debug_should_output(debug_level_t level, debug_category_t category) {
return 0;
}
/* Determine effective level: max(global, category) */
int idx = 0;
while (!(category & (1ULL << idx)) && idx < DEBUG_CATEGORY_COUNT) {
idx++;
}
debug_level_t cat_level = (idx < DEBUG_CATEGORY_COUNT) ? g_debug_config.category_levels[idx] : DEBUG_LEVEL_NONE;
debug_level_t effective = (cat_level > g_debug_config.level) ? cat_level : g_debug_config.level;
/* Check if level is sufficient */
if (level > g_debug_config.level) {
if (level > effective) {
return 0;
}

16
lib/debug_config.h

@ -51,12 +51,15 @@ typedef uint64_t debug_category_t;
#define DEBUG_CATEGORY_BGP ((debug_category_t)1 << 12) // BGP route exchange
#define DEBUG_CATEGORY_SOCKET ((debug_category_t)1 << 13) // Socket operations
#define DEBUG_CATEGORY_CONTROL ((debug_category_t)1 << 14) // Control/monitoring server
#define DEBUG_CATEGORY_DUMP ((debug_category_t)1 << 15) // Packet dump/logging
#define DEBUG_CATEGORY_COUNT 16 // Total number of categories
#define DEBUG_CATEGORY_ALL ((debug_category_t)0xFFFFFFFFFFFFFFFFULL)
/* Debug configuration structure */
typedef struct {
debug_level_t level; // Global debug level
debug_level_t level; // Global debug level (default: ERROR)
debug_category_t categories; // Enabled categories (bitmask)
debug_level_t category_levels[DEBUG_CATEGORY_COUNT]; // Per-category levels (0 = disabled)
int timestamp_enabled; // Include timestamps in output
int function_name_enabled; // Include function names
int file_line_enabled; // Include file:line info
@ -75,10 +78,13 @@ extern debug_config_t g_debug_config;
/* Initialize debug system with default settings */
void debug_config_init(void);
/* Set debug level */
void debug_set_level(debug_level_t level);
/* Enable/disable specific categories */
/* Set debug level */
void debug_set_level(debug_level_t level);
/* Set debug level for specific category (0 = disabled, otherwise uses that level) */
void debug_set_category_level(debug_category_t category, debug_level_t level);
/* Enable/disable specific categories */
void debug_enable_category(debug_category_t category);
void debug_disable_category(debug_category_t category);
void debug_set_categories(debug_category_t categories);

1
src/Makefile.am

@ -14,6 +14,7 @@ utun_CORE_SOURCES = \
etcp.c \
etcp_connections.c \
etcp_loadbalancer.c \
etcp_debug.c \
secure_channel.c \
crc32.c \
pkt_normalizer.c \

4
src/config_parser.c

@ -27,7 +27,8 @@ typedef enum {
SECTION_GLOBAL,
SECTION_SERVER,
SECTION_CLIENT,
SECTION_ROUTING
SECTION_ROUTING,
SECTION_DEBUG
} section_type_t;
/* Forward declaration for new functions */
@ -426,6 +427,7 @@ static section_type_t parse_section_header(const char *line, char *name, size_t
if (strcasecmp(section, "global") == 0) return SECTION_GLOBAL;
if (strcasecmp(section, "routing") == 0) return SECTION_ROUTING;
if (strcasecmp(section, "debug") == 0) return SECTION_DEBUG;
char *colon = strchr(section, ':');
if (!colon) return SECTION_UNKNOWN;

7
src/config_parser.h

@ -76,6 +76,13 @@ struct global_config {
int enable_file_lines; // enable file:line in logs
int enable_colors; // enable ANSI colors in logs
// Per-category debug levels (loaded from [debug] section)
struct {
char category[16][16]; // category name
char level[16][16]; // level string
int count;
} debug_levels;
int tun_test_mode; // test mode: 1 = don't open real TUN, queues only
int keepalive_timeout; // keepalive timeout in ms (default: 2000)
int keepalive_interval; // keepalive interval in ms (default: 200)

16
src/etcp.c

@ -1,6 +1,7 @@
// etcp.c - ETCP Protocol Implementation (refactored and expanded based on etcp_protocol.txt)
#include "etcp.h"
#include "etcp_debug.h"
#include "etcp_loadbalancer.h"
#include "routing.h"
#include "route_bgp.h"
@ -642,10 +643,11 @@ struct ETCP_DGRAM* etcp_request_pkt(struct ETCP_CONN* etcp) {
DEBUG_DEBUG(DEBUG_CATEGORY_ETCP, "[%s] only ACK packet with %d bytes total", etcp->log_name, dgram->data_len);
}
dgram->data_len=ptr;
return dgram;
dgram->data_len=ptr;
etcp_dump_pkt_sections(dgram, link, 1);
return dgram;
}
// Callback for when a link is ready to send data
@ -801,8 +803,10 @@ void etcp_ack_recv(struct ETCP_CONN* etcp, uint32_t seq, uint16_t ts, uint16_t d
void etcp_conn_input(struct ETCP_DGRAM* pkt) {
DEBUG_TRACE(DEBUG_CATEGORY_ETCP, "");
if (!pkt || !pkt->data_len) return;
struct ETCP_CONN* etcp = pkt->link->etcp;
etcp_dump_pkt_sections(pkt, pkt->link, 0);
struct ETCP_CONN* etcp = pkt->link->etcp;
uint8_t* data = pkt->data;
uint16_t len = pkt->data_len;
uint16_t ts = pkt->timestamp; // Received timestamp

3
tests/Makefile.am

@ -55,7 +55,8 @@ ETCP_CORE_OBJS = \
$(top_builddir)/src/utun-etcp_connections.o \
$(top_builddir)/src/utun-etcp_loadbalancer.o \
$(top_builddir)/src/utun-pkt_normalizer.o \
$(top_builddir)/src/utun-etcp_api.o
$(top_builddir)/src/utun-etcp_api.o \
$(top_builddir)/src/utun-etcp_debug.o
# Platform-specific TUN objects
if OS_WINDOWS

Loading…
Cancel
Save