}
add_local_addresses(mesh);
- node_write_config(mesh, mesh->self);
+
+ if(!node_write_config(mesh, mesh->self)) {
+ logger(NULL, MESHLINK_ERROR, "Cannot update configuration\n");
+ return NULL;
+ }
idle_set(&mesh->loop, idle, mesh);
exit_outgoings(mesh);
- // Write out any changed node config files
+ // Try to write out any changed node config files, ignore errors at this point.
if(mesh->nodes) {
for splay_each(node_t, n, mesh->nodes) {
if(n->status.dirty) {
- node_write_config(mesh, n);
- n->status.dirty = false;
+ n->status.dirty = !node_write_config(mesh, n);
}
}
}
node_t *n = (node_t *)node;
free(n->canonical_address);
n->canonical_address = canonical_address;
- node_write_config(mesh, n);
+
+ if(!node_write_config(mesh, n)) {
+ pthread_mutex_unlock(&mesh->mutex);
+ return false;
+ }
pthread_mutex_unlock(&mesh->mutex);
- return true;
+ return config_sync(mesh, "current");
}
bool meshlink_add_address(meshlink_handle_t *mesh, const char *address) {
break;
}
- config_write(mesh, "current", n->name, &config, mesh->config_key);
+ if(!config_write(mesh, "current", n->name, &config, mesh->config_key)) {
+ free_node(n);
+ return false;
+ }
+
node_add(mesh, n);
}
return true;
}
-void meshlink_blacklist(meshlink_handle_t *mesh, meshlink_node_t *node) {
+bool meshlink_blacklist(meshlink_handle_t *mesh, meshlink_node_t *node) {
if(!mesh || !node) {
meshlink_errno = MESHLINK_EINVAL;
- return;
+ return false;
}
pthread_mutex_lock(&mesh->mutex);
logger(mesh, MESHLINK_ERROR, "%s blacklisting itself?\n", node->name);
meshlink_errno = MESHLINK_EINVAL;
pthread_mutex_unlock(&mesh->mutex);
- return;
+ return false;
}
if(n->status.blacklisted) {
logger(mesh, MESHLINK_DEBUG, "Node %s already blacklisted\n", node->name);
pthread_mutex_unlock(&mesh->mutex);
- return;
+ return true;
}
n->status.blacklisted = true;
- node_write_config(mesh, n);
- config_sync(mesh, "current");
-
- logger(mesh, MESHLINK_DEBUG, "Blacklisted %s.\n", node->name);
/* 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.
n->mtuprobes = 0;
n->status.udp_confirmed = false;
+ if(!node_write_config(mesh, n)) {
+ pthread_mutex_unlock(&mesh->mutex);
+ return false;
+ }
+
+ logger(mesh, MESHLINK_DEBUG, "Blacklisted %s.\n", node->name);
+
pthread_mutex_unlock(&mesh->mutex);
+
+ return config_sync(mesh, "current");
}
-void meshlink_whitelist(meshlink_handle_t *mesh, meshlink_node_t *node) {
+bool meshlink_whitelist(meshlink_handle_t *mesh, meshlink_node_t *node) {
if(!mesh || !node) {
meshlink_errno = MESHLINK_EINVAL;
- return;
+ return false;
}
pthread_mutex_lock(&mesh->mutex);
logger(mesh, MESHLINK_ERROR, "%s whitelisting itself?\n", node->name);
meshlink_errno = MESHLINK_EINVAL;
pthread_mutex_unlock(&mesh->mutex);
- return;
+ return false;
}
if(!n->status.blacklisted) {
logger(mesh, MESHLINK_DEBUG, "Node %s was already whitelisted\n", node->name);
pthread_mutex_unlock(&mesh->mutex);
- return;
+ return true;
}
n->status.blacklisted = false;
- node_write_config(mesh, n);
- config_sync(mesh, "current");
if(n->status.reachable) {
update_node_status(mesh, n);
}
+ if(!node_write_config(mesh, n)) {
+ pthread_mutex_unlock(&mesh->mutex);
+ return false;
+ }
+
logger(mesh, MESHLINK_DEBUG, "Whitelisted %s.\n", node->name);
pthread_mutex_unlock(&mesh->mutex);
- return;
+
+ return config_sync(mesh, "current");
}
void meshlink_set_default_blacklist(meshlink_handle_t *mesh, bool blacklist) {
node_t *n = (node_t *)node;
memmove(n->recent + 1, n->recent, 4 * sizeof(*n->recent));
memcpy(n->recent, addr, SALEN(*addr));
- node_write_config(mesh, n);
+
+ if(!node_write_config(mesh, n)) {
+ logger(mesh, MESHLINK_DEBUG, "Could not update %s\n", n->name);
+ }
pthread_mutex_unlock(&mesh->mutex);
// @TODO do we want to fire off a connection attempt right away?