#include "address_cache.h"
#include "conf.h"
#include "connection.h"
+#include "crypto.h"
#include "list.h"
#include "logger.h"
#include "names.h"
#ifndef HAVE_MINGW
io_t unix_socket;
#endif
-list_t *outgoing_list = NULL;
+
+static void free_outgoing(outgoing_t *outgoing) {
+ timeout_del(&outgoing->ev);
+ free(outgoing);
+}
+
+list_t outgoing_list = {
+ .head = NULL,
+ .tail = NULL,
+ .count = 0,
+ .delete = (list_action_t)free_outgoing,
+};
/* Setup sockets */
int status;
#endif /* defined(SOL_SOCKET) && defined(SO_BINDTODEVICE) */
- if(!get_config_string(lookup_config(config_tree, "BindToInterface"), &iface)) {
+ if(!get_config_string(lookup_config(&config_tree, "BindToInterface"), &iface)) {
return true;
}
#endif
if(get_config_string
- (lookup_config(config_tree, "BindToInterface"), &iface)) {
+ (lookup_config(&config_tree, "BindToInterface"), &iface)) {
#if defined(SOL_SOCKET) && defined(SO_BINDTODEVICE)
struct ifreq ifr;
}
timeout_add(&outgoing->ev, retry_outgoing_handler, outgoing, &(struct timeval) {
- outgoing->timeout, rand() % 100000
+ outgoing->timeout, jitter()
});
logger(DEBUG_CONNECTIONS, LOG_NOTICE, "Trying to re-establish outgoing connection in %d seconds", outgoing->timeout);
return;
remove:
- list_delete(outgoing_list, outgoing);
+ list_delete(&outgoing_list, outgoing);
}
/*
}
#endif
-static void free_outgoing(outgoing_t *outgoing) {
- timeout_del(&outgoing->ev);
- free(outgoing);
-}
-
void try_outgoing_connections(void) {
/* 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_each(outgoing_t, outgoing, outgoing_list) {
- outgoing->timeout = -1;
- }
+ for list_each(outgoing_t, outgoing, &outgoing_list) {
+ outgoing->timeout = -1;
}
/* Make sure there is one outgoing_t in the list for each ConnectTo. */
- for(config_t *cfg = lookup_config(config_tree, "ConnectTo"); cfg; cfg = lookup_config_next(config_tree, cfg)) {
+ for(config_t *cfg = lookup_config(&config_tree, "ConnectTo"); cfg; cfg = lookup_config_next(&config_tree, cfg)) {
char *name;
get_config_string(cfg, &name);
bool found = false;
- for list_each(outgoing_t, outgoing, outgoing_list) {
+ for list_each(outgoing_t, outgoing, &outgoing_list) {
if(!strcmp(outgoing->node->name, name)) {
found = true;
outgoing->timeout = 0;
free(name);
outgoing->node = n;
- list_insert_tail(outgoing_list, outgoing);
+ list_insert_tail(&outgoing_list, outgoing);
setup_outgoing_connection(outgoing, true);
}
}
/* Terminate any connections whose outgoing_t is to be deleted. */
- for list_each(connection_t, c, connection_list) {
+ for list_each(connection_t, c, &connection_list) {
if(c->outgoing && c->outgoing->timeout == -1) {
c->outgoing = NULL;
logger(DEBUG_CONNECTIONS, LOG_INFO, "No more outgoing connection to %s", c->name);
/* Delete outgoing_ts for which there is no ConnectTo. */
- for list_each(outgoing_t, outgoing, outgoing_list)
+ for list_each(outgoing_t, outgoing, &outgoing_list)
if(outgoing->timeout == -1) {
- list_delete_node(outgoing_list, node);
+ list_delete_node(&outgoing_list, node);
}
}