// if result is smaller than edges, we have to dealloc all the excess devtool_edge_t
if((size_t)result_size > *nmemb) {
- result = realloc(edges, result_size * sizeof(*result));
+ result = xrealloc(edges, result_size * sizeof(*result));
} else {
result = edges;
}
}
// shrink result to the actual amount of memory used
- result = realloc(result, n * sizeof(*result));
+ result = xrealloc(result, n * sizeof(*result));
*nmemb = n;
} else {
*nmemb = 0;
pthread_mutex_lock(&(mesh->mesh_mutex));
node_name += 1;
- node_fp += 1;
meshlink_node_t *node = meshlink_get_node(mesh, node_name);
// Get our local address(es) by simulating connecting to an Internet host.
static void add_local_addresses(meshlink_handle_t *mesh) {
struct sockaddr_storage sn;
+ sn.ss_family = AF_UNKNOWN;
socklen_t sl = sizeof(sn);
// IPv4 example.org
if(!name || !*name) {
logger(NULL, MESHLINK_ERROR, "No name given!\n");
- //return NULL;
- } else { //check name only if there is a name != NULL
- if(!check_id(name)) {
- logger(NULL, MESHLINK_ERROR, "Invalid name given!\n");
- meshlink_errno = MESHLINK_EINVAL;
- return NULL;
- }
+ meshlink_errno = MESHLINK_EINVAL;
+ return NULL;
+ };
+
+ if(!check_id(name)) {
+ logger(NULL, MESHLINK_ERROR, "Invalid name given!\n");
+ meshlink_errno = MESHLINK_EINVAL;
+ return NULL;
}
if(devclass < 0 || devclass >= DEV_CLASS_COUNT) {
meshlink_errno = MESHLINK_ESTORAGE;
free_node(mesh->self);
mesh->self = NULL;
+ goto done;
} else if(!setup_network(mesh)) {
meshlink_errno = MESHLINK_ENETWORK;
- } else {
- rval = true;
+ goto done;
}
/* Rebuild our own list of recent addresses */
/* Write meshlink.conf with the updated port number */
write_main_config_files(mesh);
- if(!config_sync(mesh, "current")) {
- return false;
- }
+ rval = config_sync(mesh, "current");
done:
pthread_mutex_unlock(&(mesh->mesh_mutex));
#endif
static const int default_timeout = 5;
+static const int default_interval = 60;
/*
Terminate a connection:
for list_each(connection_t, c, mesh->connections) {
int pingtimeout = c->node ? mesh->dev_class_traits[c->node->devclass].pingtimeout : default_timeout;
+ int pinginterval = c->node ? mesh->dev_class_traits[c->node->devclass].pinginterval : default_interval;
// Also make sure that if outstanding key requests for the UDP counterpart of a connection has timed out, we restart it.
if(c->node) {
if(c->status.active) {
if(c->status.pinged) {
logger(mesh, MESHLINK_INFO, "%s didn't respond to PING in %ld seconds", c->name, (long)mesh->loop.now.tv_sec - c->last_ping_time);
- } else if(c->last_ping_time + mesh->dev_class_traits[c->node->devclass].pinginterval <= mesh->loop.now.tv_sec) {
+ } else if(c->last_ping_time + pinginterval <= mesh->loop.now.tv_sec) {
send_ping(mesh, c);
continue;
} else {
const char *name;
uint32_t len = packmsg_get_str_raw(in, &name);
- if(len != strlen(n->name) || strncmp(name, n->name, len)) {
+ if(len != strlen(n->name) || !name || strncmp(name, n->name, len)) {
config_free(config);
return false;
}