9 void log_cb(meshlink_handle_t *mesh, meshlink_log_level_t level, const char *text) {
10 static struct timeval tv0;
14 gettimeofday(&tv0, NULL);
17 gettimeofday(&tv, NULL);
18 fprintf(stderr, "%u.%.03u ", (unsigned int)(tv.tv_sec - tv0.tv_sec), (unsigned int)tv.tv_usec / 1000);
21 fprintf(stderr, "(%s) ", mesh->name);
24 fprintf(stderr, "[%d] %s\n", level, text);
28 meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb);
30 // Open a new meshlink instance.
32 meshlink_handle_t *mesh = meshlink_open_encrypted("encrypted_conf", "foo", "encrypted", DEV_CLASS_BACKBONE, "right", 5);
35 fprintf(stderr, "Could not initialize configuration for foo\n");
39 // Close the mesh and open it again, now with a different key.
43 mesh = meshlink_open_encrypted("encrypted_conf", "foo", "encrypted", DEV_CLASS_BACKBONE, "wrong", 5);
46 fprintf(stderr, "Could open mesh with the wrong key\n");
50 // Open it again, now with the right key.
52 mesh = meshlink_open_encrypted("encrypted_conf", "foo", "encrypted", DEV_CLASS_BACKBONE, "right", 5);
55 fprintf(stderr, "Could not open mesh with the right key\n");
65 if(!meshlink_destroy("encrypted_conf")) {
66 fprintf(stderr, "Could not destroy configuration\n");
70 if(!access("encrypted_conf", F_OK) || errno != ENOENT) {
71 fprintf(stderr, "Configuration not fully destroyed\n");