+/*
+ Configure node_t mesh->self and set up the local sockets (listen only)
+*/
+bool setup_myself(meshlink_handle_t *mesh) {
+ /* Set some defaults */
+
+ mesh->maxtimeout = 900;
+
+ /* Done */
+
+ mesh->self->nexthop = mesh->self;
+ mesh->self->status.reachable = true;
+
+ node_add(mesh, mesh->self);
+
+ graph(mesh);
+
+ 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_address(mesh, NULL, NULL)) {
+ if(strcmp(mesh->myport, "0")) {
+ logger(mesh, MESHLINK_INFO, "Could not bind to port %s, asking OS to choose one for us", mesh->myport);
+ free(mesh->myport);
+ mesh->myport = strdup("0");
+
+ if(!mesh->myport) {
+ return false;
+ }
+
+ if(!add_listen_address(mesh, NULL, NULL)) {
+ return false;
+ }
+ } else {
+ return false;
+ }
+ }
+
+ if(!mesh->listen_sockets) {
+ logger(mesh, MESHLINK_ERROR, "Unable to create any listening socket!");