Correctly add/remove outgoing connections when reloading configuration.
This commit is contained in:
parent
f417271ea1
commit
c5325ffdd1
4 changed files with 76 additions and 32 deletions
46
src/net.c
46
src/net.c
|
@ -40,6 +40,7 @@
|
||||||
int contradicting_add_edge = 0;
|
int contradicting_add_edge = 0;
|
||||||
int contradicting_del_edge = 0;
|
int contradicting_del_edge = 0;
|
||||||
static int sleeptime = 10;
|
static int sleeptime = 10;
|
||||||
|
time_t last_config_check = 0;
|
||||||
|
|
||||||
/* Purge edges and subnets of unreachable nodes. Use carefully. */
|
/* Purge edges and subnets of unreachable nodes. Use carefully. */
|
||||||
|
|
||||||
|
@ -263,7 +264,6 @@ int reload_configuration(void) {
|
||||||
splay_node_t *node, *next;
|
splay_node_t *node, *next;
|
||||||
char *fname;
|
char *fname;
|
||||||
struct stat s;
|
struct stat s;
|
||||||
static time_t last_config_check = 0;
|
|
||||||
|
|
||||||
/* Reread our own configuration file */
|
/* Reread our own configuration file */
|
||||||
|
|
||||||
|
@ -286,31 +286,6 @@ int reload_configuration(void) {
|
||||||
|
|
||||||
setup_myself_reloadable();
|
setup_myself_reloadable();
|
||||||
|
|
||||||
/* Close connections to hosts that have a changed or deleted host config file */
|
|
||||||
|
|
||||||
for(node = connection_tree->head; node; node = next) {
|
|
||||||
c = node->data;
|
|
||||||
next = node->next;
|
|
||||||
|
|
||||||
if(c->status.control)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if(c->outgoing) {
|
|
||||||
free(c->outgoing->name);
|
|
||||||
if(c->outgoing->ai)
|
|
||||||
freeaddrinfo(c->outgoing->ai);
|
|
||||||
free(c->outgoing);
|
|
||||||
c->outgoing = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", confbase, c->name);
|
|
||||||
if(stat(fname, &s) || s.st_mtime > last_config_check)
|
|
||||||
terminate_connection(c, c->status.active);
|
|
||||||
free(fname);
|
|
||||||
}
|
|
||||||
|
|
||||||
last_config_check = time(NULL);
|
|
||||||
|
|
||||||
/* If StrictSubnet is set, expire deleted Subnets and read new ones in */
|
/* If StrictSubnet is set, expire deleted Subnets and read new ones in */
|
||||||
|
|
||||||
if(strictsubnets) {
|
if(strictsubnets) {
|
||||||
|
@ -387,6 +362,25 @@ int reload_configuration(void) {
|
||||||
|
|
||||||
try_outgoing_connections();
|
try_outgoing_connections();
|
||||||
|
|
||||||
|
/* Close connections to hosts that have a changed or deleted host config file */
|
||||||
|
|
||||||
|
for(node = connection_tree->head; node; node = next) {
|
||||||
|
c = node->data;
|
||||||
|
next = node->next;
|
||||||
|
|
||||||
|
if(c->status.control)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", confbase, c->name);
|
||||||
|
if(stat(fname, &s) || s.st_mtime > last_config_check) {
|
||||||
|
fprintf(stderr, "ZOMG %ld > %ld\n", s.st_mtime, last_config_check);
|
||||||
|
terminate_connection(c, c->status.active);
|
||||||
|
}
|
||||||
|
free(fname);
|
||||||
|
}
|
||||||
|
|
||||||
|
last_config_check = time(NULL);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -132,6 +132,7 @@ extern bool do_prune;
|
||||||
extern char *myport;
|
extern char *myport;
|
||||||
extern int contradicting_add_edge;
|
extern int contradicting_add_edge;
|
||||||
extern int contradicting_del_edge;
|
extern int contradicting_del_edge;
|
||||||
|
extern time_t last_config_check;
|
||||||
|
|
||||||
extern char *proxyhost;
|
extern char *proxyhost;
|
||||||
extern char *proxyport;
|
extern char *proxyport;
|
||||||
|
|
|
@ -916,6 +916,8 @@ static bool setup_myself(void) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
last_config_check = time(NULL);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -576,6 +576,9 @@ void handle_new_meta_connection(int sock, short events, void *data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void free_outgoing(outgoing_t *outgoing) {
|
static void free_outgoing(outgoing_t *outgoing) {
|
||||||
|
if(event_initialized(&outgoing->ev))
|
||||||
|
event_del(&outgoing->ev);
|
||||||
|
|
||||||
if(outgoing->ai)
|
if(outgoing->ai)
|
||||||
freeaddrinfo(outgoing->ai);
|
freeaddrinfo(outgoing->ai);
|
||||||
|
|
||||||
|
@ -590,8 +593,19 @@ void try_outgoing_connections(void) {
|
||||||
char *name;
|
char *name;
|
||||||
outgoing_t *outgoing;
|
outgoing_t *outgoing;
|
||||||
|
|
||||||
outgoing_list = list_alloc((list_action_t)free_outgoing);
|
/* If there is no outgoing list yet, create one. Otherwise, mark all outgoings as deleted. */
|
||||||
|
|
||||||
|
if(!outgoing_list) {
|
||||||
|
outgoing_list = list_alloc((list_action_t)free_outgoing);
|
||||||
|
} else {
|
||||||
|
for(list_node_t *i = outgoing_list->head; i; i = i->next) {
|
||||||
|
outgoing = i->data;
|
||||||
|
outgoing->timeout = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Make sure there is one outgoing_t in the list for each ConnectTo. */
|
||||||
|
|
||||||
for(cfg = lookup_config(config_tree, "ConnectTo"); cfg; cfg = lookup_config_next(config_tree, cfg)) {
|
for(cfg = lookup_config(config_tree, "ConnectTo"); cfg; cfg = lookup_config_next(config_tree, cfg)) {
|
||||||
get_config_string(cfg, &name);
|
get_config_string(cfg, &name);
|
||||||
|
|
||||||
|
@ -603,9 +617,42 @@ void try_outgoing_connections(void) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
outgoing = xmalloc_and_zero(sizeof *outgoing);
|
bool found = false;
|
||||||
outgoing->name = name;
|
|
||||||
list_insert_tail(outgoing_list, outgoing);
|
for(list_node_t *i = outgoing_list->head; i; i = i->next) {
|
||||||
setup_outgoing_connection(outgoing);
|
outgoing = i->data;
|
||||||
|
if(!strcmp(outgoing->name, name)) {
|
||||||
|
found = true;
|
||||||
|
outgoing->timeout = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!found) {
|
||||||
|
outgoing = xmalloc_and_zero(sizeof *outgoing);
|
||||||
|
outgoing->name = name;
|
||||||
|
list_insert_tail(outgoing_list, outgoing);
|
||||||
|
setup_outgoing_connection(outgoing);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Terminate any connections whose outgoing_t is to be deleted. */
|
||||||
|
|
||||||
|
for(splay_node_t *n = connection_tree->head, *next; n; n = next) {
|
||||||
|
next = n->next;
|
||||||
|
connection_t *c = n->data;
|
||||||
|
if(c->outgoing && c->outgoing->timeout == -1) {
|
||||||
|
c->outgoing = NULL;
|
||||||
|
terminate_connection(c, c->status.active);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Delete outgoing_ts for which there is no ConnectTo. */
|
||||||
|
|
||||||
|
for(list_node_t *i = outgoing_list->head, *next; i; i = next) {
|
||||||
|
next = i->next;
|
||||||
|
outgoing = i->data;
|
||||||
|
if(outgoing->timeout == -1)
|
||||||
|
list_delete_node(outgoing_list, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue