#include "ed25519/sha512.h"
#include "discovery.h"
#include "devtools.h"
+#include "graph.h"
#ifndef MSG_NOSIGNAL
#define MSG_NOSIGNAL 0
pthread_cond_wait(&mesh->cond, &mesh->mutex);
mesh->threadstarted = true;
- mesh->self->last_reachable = time(NULL);
- mesh->self->status.dirty = true;
+
+ // Ensure we are considered reachable
+ graph(mesh);
pthread_mutex_unlock(&mesh->mutex);
return true;
pthread_mutex_lock(&mesh->mutex);
logger(mesh, MESHLINK_DEBUG, "meshlink_stop called\n");
- if(mesh->self) {
- mesh->self->last_unreachable = time(NULL);
- mesh->self->status.dirty = true;
- }
-
// Shut down the main thread
event_loop_stop(&mesh->loop);
exit_outgoings(mesh);
+ // Ensure we are considered unreachable
+ if(mesh->nodes) {
+ graph(mesh);
+ }
+
// 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) {
/* Done */
mesh->self->nexthop = mesh->self;
- mesh->self->status.reachable = true;
node_add(mesh, mesh->self);
- graph(mesh);
-
if(!config_scan_all(mesh, "current", "hosts", load_node, NULL)) {
logger(mesh, MESHLINK_WARNING, "Could not scan all host config files");
}
assert(self);
assert(!strcmp(self->name, "foo"));
- // Check that we are reachable.
+ // Check that we are not reachable.
- assert(meshlink_get_node_reachability(mesh, self, NULL, NULL));
+ time_t last_reachable;
+ time_t last_unreachable;
+ assert(!meshlink_get_node_reachability(mesh, self, &last_reachable, &last_unreachable));
+ assert(!last_reachable);
+ assert(!last_unreachable);
// Start and stop the mesh.
assert(meshlink_start(mesh));
+
+ // Check that we are now reachable
+
+ assert(meshlink_get_node_reachability(mesh, self, &last_reachable, &last_unreachable));
+ assert(last_reachable);
+ assert(!last_unreachable);
+
meshlink_stop(mesh);
- // Check that we are still reachable.
+ // Check that we are no longer reachable.
- assert(meshlink_get_node_reachability(mesh, self, NULL, NULL));
+ assert(!meshlink_get_node_reachability(mesh, self, &last_reachable, &last_unreachable));
+ assert(last_reachable);
+ assert(last_unreachable);
// Make sure we can start and stop the mesh again.
mesh = meshlink_open("basic_conf", "bar", "basic", DEV_CLASS_BACKBONE);
assert(mesh);
+ self = meshlink_get_self(mesh);
+ assert(self);
+
+ // Check that we remembered we were reachable
+
+ assert(!meshlink_get_node_reachability(mesh, self, &last_reachable, &last_unreachable));
+ assert(last_reachable);
+ assert(last_unreachable);
+
// Check that the name is ignored now, and that we still are "foo".
assert(!meshlink_get_node(mesh, "bar"));