22 #define OB_OPTIONS_MAGIC 0x631DE7EA
25 #define VAR(varname, conftype, member, initvalue) \
26 CONFIG_VAR_ETYPE(ob_options_t, varname, conftype, member, 0, initvalue)
27 #define V(member,conftype,initvalue) \
28 VAR(#member, conftype, member, initvalue)
32 DUMMY_TYPECHECK_INSTANCE(ob_options_t);
36 V(MasterOnionAddress, LINELIST, NULL),
46 .offset = offsetof(ob_options_t, ExtraLines),
51 .
size =
sizeof(ob_options_t),
55 offsetof(ob_options_t, magic_),
58 .extra = &config_extra_vars,
66 get_config_options_mgr(
void)
68 if (PREDICT_UNLIKELY(config_options_mgr == NULL)) {
72 return config_options_mgr;
75 #define ob_option_free(val) \
76 FREE_AND_NULL(ob_options_t, ob_option_free_, (val))
85 config_free(get_config_options_mgr(), opts);
92 ob_options_t *opts =
config_new(get_config_options_mgr());
125 strlcpy(address, value, strlen(value) -
sizeof(
".onion") + 2);
148 for (line = opts->MasterOnionAddress; line; line = line->next) {
156 log_warn(
LD_REND,
"OnionBalance: MasterOnionAddress %s is invalid",
162 log_notice(
LD_REND,
"OnionBalance: MasterOnionAddress %s registered",
203 if (BUG(service == NULL)) {
223 static const char *fname =
"ob_config";
225 char *content = NULL, *errmsg = NULL, *config_file_path = NULL;
226 ob_options_t *options = NULL;
233 content = read_file_to_str(config_file_path, 0, NULL);
235 log_warn(
LD_FS,
"OnionBalance: Unable to read config file %s",
246 config_assign(get_config_options_mgr(), options, lines, 0, &errmsg);
248 log_warn(
LD_REND,
"OnionBalance: Unable to parse config file: %s",
258 config_free_lines(lines);
259 ob_option_free(options);
281 unsigned int num_pkeys, idx = 0;
283 const int steps[3] = {0, -1, 1};
296 *subcredentials_out = NULL;
331 for (
unsigned int i = 0; i < num_steps; i++) {
336 } SMARTLIST_FOREACH_END(pkey);
346 log_info(
LD_REND,
"Refreshing %u onionbalance keys (TP #%d).",
349 *subcredentials_out = subcreds;
391 if (BUG(!num_subcreds)) {
396 if (service->
state.ob_subcreds) {
400 service->
state.ob_subcreds = ob_subcreds;
401 service->
state.n_ob_subcreds = num_subcreds;
408 config_mgr_free(config_options_mgr);