[MESHLINK_EPEER] = "Error communicating with peer",
[MESHLINK_ENOTSUP] = "Operation not supported",
[MESHLINK_EBUSY] = "MeshLink instance already in use",
+ [MESHLINK_EBLACKLISTED] = "Node is blacklisted",
};
const char *meshlink_strerror(meshlink_errno_t err) {
mesh->self->name = xstrdup(mesh->name);
mesh->self->devclass = mesh->devclass;
mesh->self->ecdsa = ecdsa_set_public_key(ecdsa_get_public_key(mesh->private_key));
+ mesh->self->session_id = mesh->session_id;
if(!write_main_config_files(mesh)) {
logger(mesh, MESHLINK_ERROR, "Could not write main config files into %s/current: %s\n", mesh->confbase, strerror(errno));
mesh->self = new_node();
mesh->self->name = xstrdup(name);
mesh->self->devclass = mesh->devclass;
+ mesh->self->session_id = mesh->session_id;
if(!node_read_public_key(mesh, mesh->self)) {
logger(NULL, MESHLINK_ERROR, "Could not read our host configuration file!");
randomize(&mesh->prng_state, sizeof(mesh->prng_state));
+ do {
+ randomize(&mesh->session_id, sizeof(mesh->session_id));
+ } while(mesh->session_id == 0);
+
memcpy(mesh->dev_class_traits, default_class_traits, sizeof(default_class_traits));
if(usingname) {
if(n->status.blacklisted) {
logger(mesh, MESHLINK_ERROR, "Node %s blacklisted, dropping packet\n", n->name);
+ meshlink_errno = MESHLINK_EBLACKLISTED;
return false;
}
mesh->self = new_node();
mesh->self->name = xstrdup(mesh->name);
mesh->self->devclass = mesh->devclass;
+ mesh->self->session_id = mesh->session_id;
xasprintf(&mesh->myport, "%d", port);
if(!node_read_public_key(mesh, mesh->self)) {
logger(mesh, MESHLINK_DEBUG, "Blacklisted %s.\n", node->name);
- //Immediately terminate any connections we have with the blacklisted node
+ /* Immediately shut down any connections we have with the blacklisted node.
+ * We can't call terminate_connection(), because we might be called from a callback function.
+ */
for list_each(connection_t, c, mesh->connections) {
if(c->node == n) {
- terminate_connection(mesh, c, c->status.active);
+ shutdown(c->socket, SHUT_RDWR);
}
}
n->mtuprobes = 0;
n->status.udp_confirmed = false;
- if(n->status.reachable) {
- update_node_status(mesh, n);
- }
-
pthread_mutex_unlock(&mesh->mutex);
}
node_t *n = (node_t *)node;
+ if(n == mesh->self) {
+ logger(mesh, MESHLINK_ERROR, "%s whitelisting itself?\n", node->name);
+ meshlink_errno = MESHLINK_EINVAL;
+ pthread_mutex_unlock(&mesh->mutex);
+ return;
+ }
+
if(!n->status.blacklisted) {
logger(mesh, MESHLINK_DEBUG, "Node %s was already whitelisted\n", node->name);
- meshlink_errno = MESHLINK_EINVAL;
pthread_mutex_unlock(&mesh->mutex);
return;
}
update_node_status(mesh, n);
}
+ logger(mesh, MESHLINK_DEBUG, "Whitelisted %s.\n", node->name);
+
pthread_mutex_unlock(&mesh->mutex);
return;
}
if(n->status.blacklisted) {
logger(mesh, MESHLINK_ERROR, "Cannot open a channel with blacklisted node\n");
+ meshlink_errno = MESHLINK_EBLACKLISTED;
pthread_mutex_unlock(&mesh->mutex);
return NULL;
}