// While we are at it, read known address information
if(!n->canonical_address) {
n->canonical_address = packmsg_get_str_dup(&in);
+
+ if(!*n->canonical_address) {
+ free(n->canonical_address);
+ n->canonical_address = NULL;
+ }
} else {
packmsg_skip_element(&in);
}
}
n->canonical_address = packmsg_get_str_dup(&in);
+
+ if(!*n->canonical_address) {
+ free(n->canonical_address);
+ n->canonical_address = NULL;
+ }
+
uint32_t count = packmsg_get_array(&in);
for(uint32_t i = 0; i < count; i++) {
return packmsg_done(&in);
}
-bool node_write_config(meshlink_handle_t *mesh, node_t *n) {
+bool node_write_config(meshlink_handle_t *mesh, node_t *n, bool new_key) {
if(!mesh->confbase) {
return true;
}
+ switch(mesh->storage_policy) {
+ case MESHLINK_STORAGE_KEYS_ONLY:
+ if(!new_key) {
+ return true;
+ }
+
+ break;
+
+ case MESHLINK_STORAGE_DISABLED:
+ return true;
+
+ default:
+ break;
+ }
+
uint8_t buf[4096];
packmsg_output_t out = {buf, sizeof(buf)};
return false;
}
+ n->status.dirty = false;
return true;
}
(void)priv;
if(!check_id(name)) {
+ // Check if this is a temporary file, if so remove it
+ const char *suffix = strstr(name, ".tmp");
+
+ if(suffix && !suffix[4]) {
+ char filename[PATH_MAX];
+ snprintf(filename, sizeof(filename), "%s" SLASH "current" SLASH "hosts", mesh->confbase);
+ unlink(filename);
+ }
+
return true;
}
fcntl(nfd, F_SETFD, FD_CLOEXEC);
#endif
+#ifdef O_NONBLOCK
+ int flags = fcntl(nfd, F_GETFL);
+
+ if(fcntl(nfd, F_SETFL, flags | O_NONBLOCK) < 0) {
+ closesocket(nfd);
+ logger(mesh, MESHLINK_ERROR, "System call `%s' failed: %s", "fcntl", strerror(errno));
+ return -1;
+ }
+
+#elif defined(WIN32)
+ unsigned long arg = 1;
+
+ if(ioctlsocket(nfd, FIONBIO, &arg) != 0) {
+ closesocket(nfd);
+ logger(mesh, MESHLINK_ERROR, "Call to `%s' failed: %s", "ioctlsocket", sockstrerror(sockerrno));
+ return -1;
+ }
+
+#endif
int option = 1;
setsockopt(nfd, SOL_SOCKET, SO_REUSEADDR, (void *)&option, sizeof(option));
.ai_family = AF_UNSPEC,
.ai_socktype = SOCK_STREAM,
.ai_protocol = IPPROTO_TCP,
- .ai_flags = AI_PASSIVE,
+ .ai_flags = AI_PASSIVE | AI_NUMERICSERV,
};
int err = getaddrinfo(NULL, mesh->myport, &hint, &ai);
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);
+ closesocket(mesh->listen_socket[i].tcp.fd);
+ closesocket(mesh->listen_socket[i].udp.fd);
}
mesh->listen_sockets = 0;
/*
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 */
-
+static bool setup_myself(meshlink_handle_t *mesh) {
mesh->self->nexthop = mesh->self;
node_add(mesh, mesh->self);
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);
+ closesocket(mesh->listen_socket[i].tcp.fd);
+ closesocket(mesh->listen_socket[i].udp.fd);
}
exit_requests(mesh);