-bool setup_network_connections(void)
-{
- cp();
-
- now = time(NULL);
-
- init_connections();
- init_subnets();
- init_nodes();
- init_edges();
- init_events();
- init_requests();
-
- if(get_config_int(lookup_config(config_tree, "PingTimeout"), &pingtimeout)) {
- if(pingtimeout < 1) {
- pingtimeout = 86400;
+static bool setup_myself(meshlink_handle_t *mesh) {
+ mesh->self->nexthop = mesh->self;
+
+ node_add(mesh, mesh->self);
+
+ if(!config_scan_all(mesh, "current", "hosts", load_node, NULL)) {
+ logger(mesh, MESHLINK_WARNING, "Could not scan all host config files");
+ }
+
+ /* Open sockets */
+
+ mesh->listen_sockets = 0;
+
+ if(!add_listen_sockets(mesh)) {
+ if(strcmp(mesh->myport, "0")) {
+ logger(mesh, MESHLINK_WARNING, "Could not bind to port %s, trying to find an alternative port", mesh->myport);
+
+ if(!check_port(mesh)) {
+ logger(mesh, MESHLINK_WARNING, "Could not bind to any port, trying to bind to port 0");
+ free(mesh->myport);
+ mesh->myport = xstrdup("0");
+ }
+
+ if(!add_listen_sockets(mesh)) {
+ return false;
+ }
+ } else {
+ return false;