-/*
- Configure node_t mesh->self and set up the local sockets (listen only)
-*/
-bool setup_myself(meshlink_handle_t *mesh) {
- char *name;
- char *address = NULL;
-
- if(!(name = get_name(mesh))) {
- logger(mesh, MESHLINK_ERROR, "Name for MeshLink instance required!");
- return false;
- }
-
- mesh->self = new_node();
- mesh->self->connection = new_connection();
- mesh->self->name = name;
- mesh->self->devclass = mesh->devclass;
- mesh->self->connection->name = xstrdup(name);
- read_host_config(mesh, mesh->config, name);
-
- if(!get_config_string(lookup_config(mesh->config, "Port"), &mesh->myport)) {
- int port = check_port(mesh);
- if (port == 0)
- return false;
- xasprintf(&mesh->myport, "%d", port);
- }
-
- mesh->self->connection->options = 0;
- mesh->self->connection->protocol_major = PROT_MAJOR;
- mesh->self->connection->protocol_minor = PROT_MINOR;
-
- mesh->self->options |= PROT_MINOR << 24;
-
- if(!read_ecdsa_private_key(mesh)) {
- return false;
- }
-
- /* Ensure mesh->myport is numeric */
-
- if(!atoi(mesh->myport)) {
- struct addrinfo *ai = str2addrinfo("localhost", mesh->myport, SOCK_DGRAM);
- sockaddr_t sa;
-
- if(!ai || !ai->ai_addr) {
- return false;
+ if(!success) {
+ for(int i = 0; i < mesh->listen_sockets; i++) {
+ io_del(&mesh->loop, &mesh->listen_socket[i].tcp);
+ io_del(&mesh->loop, &mesh->listen_socket[i].udp);
+ close(mesh->listen_socket[i].tcp.fd);
+ close(mesh->listen_socket[i].udp.fd);