Refactor of do_outgoing_connection - make it use config_address2addrinfo
This means: setup_outgoing_connection() has to prepare fake Address = "ip port" config based on the actuall configuration file Prefer the addresses discovered via SLDP while making outgoing connections
This commit is contained in:
parent
69bb848f59
commit
3327feb025
1 changed files with 29 additions and 19 deletions
|
@ -442,7 +442,7 @@ static void handle_meta_io(void *data, int flags) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool do_outgoing_connection(outgoing_t *outgoing) {
|
bool do_outgoing_connection(outgoing_t *outgoing) {
|
||||||
char *address, *port, *space;
|
char *address;
|
||||||
struct addrinfo *proxyai = NULL;
|
struct addrinfo *proxyai = NULL;
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
|
@ -454,21 +454,12 @@ begin:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
get_config_string(outgoing->cfg, &address);
|
if (!get_config_string(outgoing->cfg, &address)) {
|
||||||
|
logger(DEBUG_CONNECTIONS, LOG_ERR, "Could not set up a meta connection to %s - address not found", outgoing->name);
|
||||||
space = strchr(address, ' ');
|
return false;
|
||||||
if(space) {
|
|
||||||
port = xstrdup(space + 1);
|
|
||||||
*space = 0;
|
|
||||||
} else {
|
|
||||||
if(!get_config_string(lookup_config(outgoing->config_tree, "Port"), &port))
|
|
||||||
port = xstrdup("655");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
outgoing->ai = str2addrinfo(address, port, SOCK_STREAM);
|
outgoing->ai = config_address2addrinfo(address, SOCK_STREAM);
|
||||||
free(address);
|
|
||||||
free(port);
|
|
||||||
|
|
||||||
outgoing->aip = outgoing->ai;
|
outgoing->aip = outgoing->ai;
|
||||||
outgoing->cfg = lookup_config_next(outgoing->config_tree, outgoing->cfg);
|
outgoing->cfg = lookup_config_next(outgoing->config_tree, outgoing->cfg);
|
||||||
}
|
}
|
||||||
|
@ -613,14 +604,33 @@ void setup_outgoing_connection(outgoing_t *outgoing) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!outgoing->config_tree) {
|
// Prefer the address discovered via SLPD
|
||||||
|
if (slpdinterval && n->slpd_address)
|
||||||
|
outgoing->cfg = n->slpd_address;
|
||||||
|
else if (!outgoing->config_tree) {
|
||||||
init_configuration(&outgoing->config_tree);
|
init_configuration(&outgoing->config_tree);
|
||||||
read_host_config(outgoing->config_tree, outgoing->name);
|
read_host_config(outgoing->config_tree, outgoing->name);
|
||||||
outgoing->cfg = lookup_config(outgoing->config_tree, "Address");
|
char *address, *port;
|
||||||
}
|
|
||||||
|
|
||||||
if (slpdinterval && !outgoing->cfg && n->slpd_address)
|
if(!get_config_string(lookup_config(outgoing->config_tree, "Port"), &port))
|
||||||
outgoing->cfg = n->slpd_address;
|
port = xstrdup("655");
|
||||||
|
|
||||||
|
if(get_config_string(lookup_config(outgoing->config_tree, "Address"), &address)) {
|
||||||
|
char fullhost[MAXSIZE] = { 0 };
|
||||||
|
config_t *cfg = new_config();
|
||||||
|
|
||||||
|
if (!strchr(address, ' ')) {
|
||||||
|
snprintf(fullhost, MAXSIZE-1, "%s %s", address, port);
|
||||||
|
cfg->value = xstrdup(fullhost);
|
||||||
|
} else
|
||||||
|
cfg->value = xstrdup(address);
|
||||||
|
|
||||||
|
cfg->variable = xstrdup("Address");
|
||||||
|
cfg->file = NULL;
|
||||||
|
cfg->line = -1;
|
||||||
|
outgoing->cfg = cfg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(!outgoing->cfg) {
|
if(!outgoing->cfg) {
|
||||||
if(n)
|
if(n)
|
||||||
|
|
Loading…
Reference in a new issue