14static void cfg_u32(
const safecomm_config_t *c,
const char *key, uint32_t lo, uint32_t hi, uint32_t *out)
44 safecomm_config_t raw;
47 (void)memset(cfg, 0,
sizeof(*cfg));
48 (void)strcpy(cfg->west_host,
"127.0.0.1");
49 (void)strcpy(cfg->east_host,
"127.0.0.1");
50 (void)strcpy(cfg->listen_host,
"0.0.0.0");
51 cfg->west_port = 15010U;
52 cfg->east_port = 15110U;
53 cfg->listen_port = 16010U;
54 cfg->message_size = 96U;
55 cfg->connect_timeout_ms = 4000U;
58 if (safecomm_config_load(path, &raw) != SAFECOMM_STATUS_OK)
60 (void)fprintf(stderr,
"commserver: cannot load config '%s'\n", path);
64 cfg_host(&raw,
"rbc.west_host", cfg->west_host,
sizeof(cfg->west_host));
65 cfg_host(&raw,
"rbc.east_host", cfg->east_host,
sizeof(cfg->east_host));
66 cfg_host(&raw,
"train.listen_host", cfg->listen_host,
sizeof(cfg->listen_host));
68 u = cfg->west_port; cfg_u32(&raw,
"rbc.west_port", 1U, 65535U, &u); cfg->west_port = (uint16_t)u;
69 u = cfg->east_port; cfg_u32(&raw,
"rbc.east_port", 1U, 65535U, &u); cfg->east_port = (uint16_t)u;
70 u = cfg->listen_port; cfg_u32(&raw,
"train.listen_port", 1U, 65535U, &u); cfg->listen_port = (uint16_t)u;
71 u = cfg->message_size; cfg_u32(&raw,
"rbc.message_size", 1U, CS_MSG_MAX, &u); cfg->message_size = (uint16_t)u;
72 cfg_u32(&raw,
"rbc.connect_timeout_ms", 100U, 60000U, &cfg->connect_timeout_ms);
73 cfg_u32(&raw,
"poll.idle_ms", 0U, 1000U, &cfg->idle_ms);
79 if (safecomm_ale_from_config(&raw, &ale) == SAFECOMM_STATUS_OK)
81 (void)fprintf(stderr,
"commserver: ALE peer map loaded (%u peers)\n", ale.peer_count);
int load_cfg(const char *path, cs_cfg_t *cfg)
Loads path into cfg, defaults first then overridden by whatever the file actually sets (out-of-range ...