- outgoing = xmalloc_and_zero(sizeof(*outgoing));
- outgoing->name = name;
- list_insert_tail(outgoing_list, outgoing);
- setup_outgoing_connection(outgoing);
+ bool found = false;
+
+ for(list_node_t *i = outgoing_list->head; i; i = i->next) {
+ 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(list_node_t *node = connection_list->head, *next; node; node = next) {
+ next = node->next;
+ connection_t *c = node->data;
+ if(c->outgoing && c->outgoing->timeout == -1) {
+ c->outgoing = NULL;
+ logger(DEBUG_CONNECTIONS, LOG_INFO, "No more outgoing connection to %s", c->name);
+ terminate_connection(c, c->status.active);
+ }
+ }
+
+ /* Delete outgoing_ts for which there is no ConnectTo. */
+
+ for(list_node_t *node = outgoing_list->head, *next; node; node = next) {
+ next = node->next;
+ outgoing = node->data;
+ if(outgoing->timeout == -1)
+ list_delete_node(outgoing_list, node);