From c1d727418933bb899472aafd604e7e2508826dc6 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Fri, 30 Jul 2021 01:32:03 +0200 Subject: [PATCH] Update the test suite for Meshlink-tiny. It depends on the full Meshlink library being available as well, which must be installed or its location should be added to LD_LIBRARY_PATH in order to be able to run the tests. It is being loaded using dlopen() with the RTLD_LOCAL and RTLD_DEEPBIND flags to ensure the symbols from the tiny and full version don't collide. --- src/protocol_edge.c | 2 - test/.gitignore | 1 + test/Makefile.am | 137 ++++---------------------- test/duplicate.c | 76 --------------- test/full.c | 217 ++++++++++++++++++++++++++++++++++++++++++ test/full.h | 134 ++++++++++++++++++++++++++ test/import-export.c | 48 ---------- test/invite-join.c | 188 ++++++++++++++---------------------- test/storage-policy.c | 93 ++++++------------ test/utils.c | 27 ++++++ test/utils.h | 3 + 11 files changed, 501 insertions(+), 425 deletions(-) delete mode 100644 test/duplicate.c create mode 100644 test/full.c create mode 100644 test/full.h diff --git a/src/protocol_edge.c b/src/protocol_edge.c index 744ae38..c229940 100644 --- a/src/protocol_edge.c +++ b/src/protocol_edge.c @@ -54,7 +54,6 @@ bool add_edge_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { (void)c; (void)request; - /* TODO: Check if this is an edge we would own. */ return true; } @@ -66,6 +65,5 @@ bool del_edge_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { (void)c; (void)request; - /* TODO: Check if this is an edge we would own. */ return true; } diff --git a/test/.gitignore b/test/.gitignore index b1dd28e..cf349a8 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -12,6 +12,7 @@ /import-export /invite-join /sign-verify +/storage-policy /trio /*.[0123456789] /channels_aio_fd.in diff --git a/test/Makefile.am b/test/Makefile.am index 57d7eb8..3090ae9 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,33 +1,11 @@ TESTS = \ basic \ - basicpp \ - channels \ - channels-aio \ - channels-aio-abort \ - channels-aio-cornercases \ - channels-aio-fd \ - channels-buffer-storage \ - channels-cornercases \ - channels-failure \ - channels-fork \ - channels-no-partial \ - channels-udp \ - channels-udp-cornercases \ - duplicate \ encrypted \ ephemeral \ - get-all-nodes \ import-export \ - meta-connections \ + invite-join \ sign-verify \ - storage-policy \ - trio \ - trio2 \ - utcp-benchmark \ - utcp-benchmark-stream - -TESTS += \ - api_set_node_status_cb + storage-policy dist_check_SCRIPTS = $(TESTS) @@ -35,112 +13,29 @@ AM_CPPFLAGS = $(PTHREAD_CFLAGS) -I${top_srcdir}/src -iquote. -Wall AM_LDFLAGS = $(PTHREAD_LIBS) check_PROGRAMS = \ - api_set_node_status_cb \ basic \ - basicpp \ - channels \ - channels-aio \ - channels-aio-abort \ - channels-aio-cornercases \ - channels-aio-fd \ - channels-buffer-storage \ - channels-cornercases \ - channels-failure \ - channels-fork \ - channels-no-partial \ - channels-udp \ - channels-udp-cornercases \ - duplicate \ - echo-fork \ encrypted \ ephemeral \ - get-all-nodes \ import-export \ - meta-connections \ + invite-join \ sign-verify \ - storage-policy \ - stream \ - trio \ - trio2 + storage-policy if INSTALL_TESTS bin_PROGRAMS = $(check_PROGRAMS) endif -api_set_node_status_cb_SOURCES = api_set_node_status_cb.c utils.c utils.h -api_set_node_status_cb_LDADD = $(top_builddir)/src/libmeshlink-tiny.la - -basic_SOURCES = basic.c utils.c utils.h -basic_LDADD = $(top_builddir)/src/libmeshlink-tiny.la - -basicpp_SOURCES = basicpp.cpp utils.c utils.h -basicpp_LDADD = $(top_builddir)/src/libmeshlink-tiny.la - -channels_SOURCES = channels.c utils.c utils.h -channels_LDADD = $(top_builddir)/src/libmeshlink-tiny.la - -channels_aio_SOURCES = channels-aio.c utils.c utils.h -channels_aio_LDADD = $(top_builddir)/src/libmeshlink-tiny.la - -channels_aio_abort_SOURCES = channels-aio-abort.c utils.c utils.h -channels_aio_abort_LDADD = $(top_builddir)/src/libmeshlink-tiny.la - -channels_aio_cornercases_SOURCES = channels-aio-cornercases.c utils.c utils.h -channels_aio_cornercases_LDADD = $(top_builddir)/src/libmeshlink-tiny.la - -channels_aio_fd_SOURCES = channels-aio-fd.c utils.c utils.h -channels_aio_fd_LDADD = $(top_builddir)/src/libmeshlink-tiny.la - -channels_buffer_storage_SOURCES = channels-buffer-storage.c utils.c utils.h -channels_buffer_storage_LDADD = $(top_builddir)/src/libmeshlink-tiny.la - -channels_no_partial_SOURCES = channels-no-partial.c utils.c utils.h -channels_no_partial_LDADD = $(top_builddir)/src/libmeshlink-tiny.la - -channels_failure_SOURCES = channels-failure.c utils.c utils.h -channels_failure_LDADD = $(top_builddir)/src/libmeshlink-tiny.la - -channels_fork_SOURCES = channels-fork.c utils.c utils.h -channels_fork_LDADD = $(top_builddir)/src/libmeshlink-tiny.la - -channels_cornercases_SOURCES = channels-cornercases.c utils.c utils.h -channels_cornercases_LDADD = $(top_builddir)/src/libmeshlink-tiny.la - -channels_udp_SOURCES = channels-udp.c utils.c utils.h -channels_udp_LDADD = $(top_builddir)/src/libmeshlink-tiny.la - -channels_udp_cornercases_SOURCES = channels-udp-cornercases.c utils.c utils.h -channels_udp_cornercases_LDADD = $(top_builddir)/src/libmeshlink-tiny.la - -duplicate_SOURCES = duplicate.c utils.c utils.h -duplicate_LDADD = $(top_builddir)/src/libmeshlink-tiny.la - -echo_fork_SOURCES = echo-fork.c utils.c utils.h -echo_fork_LDADD = $(top_builddir)/src/libmeshlink-tiny.la - -encrypted_SOURCES = encrypted.c utils.c utils.h -encrypted_LDADD = $(top_builddir)/src/libmeshlink-tiny.la - -ephemeral_SOURCES = ephemeral.c utils.c utils.h -ephemeral_LDADD = $(top_builddir)/src/libmeshlink-tiny.la - -get_all_nodes_SOURCES = get-all-nodes.c utils.c utils.h -get_all_nodes_LDADD = $(top_builddir)/src/libmeshlink-tiny.la - -import_export_SOURCES = import-export.c utils.c utils.h -import_export_LDADD = $(top_builddir)/src/libmeshlink-tiny.la - -meta_connections_SOURCES = meta-connections.c netns_utils.c netns_utils.h utils.c utils.h -meta_connections_LDADD = $(top_builddir)/src/libmeshlink-tiny.la - -sign_verify_SOURCES = sign-verify.c utils.c utils.h -sign_verify_LDADD = $(top_builddir)/src/libmeshlink-tiny.la - -storage_policy_SOURCES = storage-policy.c utils.c utils.h -storage_policy_LDADD = $(top_builddir)/src/libmeshlink-tiny.la +default_SOURCES = \ + full.c full.h \ + utils.c utils.h -trio_SOURCES = trio.c utils.c utils.h -trio_LDADD = $(top_builddir)/src/libmeshlink-tiny.la +LDADD = $(top_builddir)/src/libmeshlink-tiny.la -ldl -trio2_SOURCES = trio2.c utils.c utils.h -trio2_LDADD = $(top_builddir)/src/libmeshlink-tiny.la +basic_SOURCES = basic.c $(default_SOURCES) +encrypted_SOURCES = encrypted.c $(default_SOURCES) +ephemeral_SOURCES = ephemeral.c $(default_SOURCES) +get_all_nodes_SOURCES = get-all-nodes.c $(default_SOURCES) +import_export_SOURCES = import-export.c $(default_SOURCES) +invite_join_SOURCES = invite-join.c $(default_SOURCES) +sign_verify_SOURCES = sign-verify.c $(default_SOURCES) +storage_policy_SOURCES = storage-policy.c $(default_SOURCES) diff --git a/test/duplicate.c b/test/duplicate.c deleted file mode 100644 index 0dba67f..0000000 --- a/test/duplicate.c +++ /dev/null @@ -1,76 +0,0 @@ -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include - -#include "meshlink-tiny.h" -#include "utils.h" - -static struct sync_flag duplicate_detected; - -static void handle_duplicate(meshlink_handle_t *mesh, meshlink_node_t *node) { - set_sync_flag(&duplicate_detected, true); -} - -int main(void) { - init_sync_flag(&duplicate_detected); - - meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); - - // Open meshlink instances - - static const char *name[4] = {"foo", "bar", "baz", "foo"}; - meshlink_handle_t *mesh[4]; - - for(int i = 0; i < 4; i++) { - char dirname[100]; - snprintf(dirname, sizeof dirname, "duplicate_conf.%d", i); - - assert(meshlink_destroy(dirname)); - mesh[i] = meshlink_open(dirname, name[i], "duplicate", DEV_CLASS_BACKBONE); - assert(mesh[i]); - - assert(meshlink_set_canonical_address(mesh[i], meshlink_get_self(mesh[i]), "localhost", NULL)); - - meshlink_set_node_duplicate_cb(mesh[i], handle_duplicate); - } - - // Link them in a chain - - char *data[4]; - - for(int i = 0; i < 4; i++) { - data[i] = meshlink_export(mesh[i]); - assert(data[i]); - } - - for(int i = 0; i < 3; i++) { - assert(meshlink_import(mesh[i], data[i + 1])); - assert(meshlink_import(mesh[i + 1], data[i])); - } - - for(int i = 0; i < 4; i++) { - free(data[i]); - } - - // Start the meshes - - for(int i = 0; i < 4; i++) { - assert(meshlink_start(mesh[i])); - } - - // Wait for the duplicate node to be detected - - assert(wait_sync_flag(&duplicate_detected, 20)); - - // Clean up - - for(int i = 0; i < 4; i++) { - meshlink_close(mesh[i]); - } -} diff --git a/test/full.c b/test/full.c new file mode 100644 index 0000000..97d5d41 --- /dev/null +++ b/test/full.c @@ -0,0 +1,217 @@ +#include +#include + +#include "full.h" + +meshlink_errno_t *full_meshlink_errno; +const char *(*full_meshlink_strerror)(meshlink_errno_t err) __attribute__((__warn_unused_result__)); +meshlink_open_params_t *(*full_meshlink_open_params_init)(const char *confbase, const char *name, const char *appname, dev_class_t devclass) __attribute__((__warn_unused_result__)); +void (*full_meshlink_open_params_free)(meshlink_open_params_t *params); +bool (*full_meshlink_open_params_set_netns)(meshlink_open_params_t *params, int netns) __attribute__((__warn_unused_result__)); +bool (*full_meshlink_open_params_set_storage_key)(meshlink_open_params_t *params, const void *key, size_t keylen) __attribute__((__warn_unused_result__)); +bool (*full_meshlink_open_params_set_storage_policy)(meshlink_open_params_t *params, meshlink_storage_policy_t policy) __attribute__((__warn_unused_result__)); +bool (*full_meshlink_open_params_set_lock_filename)(meshlink_open_params_t *params, const char *filename) __attribute__((__warn_unused_result__)); +struct meshlink_handle *(*full_meshlink_open_ex)(const meshlink_open_params_t *params) __attribute__((__warn_unused_result__)); +struct meshlink_handle *(*full_meshlink_open)(const char *confbase, const char *name, const char *appname, dev_class_t devclass) __attribute__((__warn_unused_result__)); +struct meshlink_handle *(*full_meshlink_open_encrypted)(const char *confbase, const char *name, const char *appname, dev_class_t devclass, const void *key, size_t keylen) __attribute__((__warn_unused_result__)); +struct meshlink_handle *(*full_meshlink_open_ephemeral)(const char *name, const char *appname, dev_class_t devclass) __attribute__((__warn_unused_result__)); +struct meshlink_submesh *(*full_meshlink_submesh_open)(struct meshlink_handle *mesh, const char *submesh) __attribute__((__warn_unused_result__)); +bool (*full_meshlink_start)(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__)); +void (*full_meshlink_stop)(struct meshlink_handle *mesh); +void (*full_meshlink_close)(struct meshlink_handle *mesh); +bool (*full_meshlink_destroy)(const char *confbase) __attribute__((__warn_unused_result__)); +bool (*full_meshlink_destroy_ex)(const meshlink_open_params_t *params) __attribute__((__warn_unused_result__)); +void (*full_meshlink_set_receive_cb)(struct meshlink_handle *mesh, meshlink_receive_cb_t cb); +void (*full_meshlink_set_connection_try_cb)(struct meshlink_handle *mesh, meshlink_connection_try_cb_t cb); +void (*full_meshlink_set_node_status_cb)(struct meshlink_handle *mesh, meshlink_node_status_cb_t cb); +void (*full_meshlink_set_node_pmtu_cb)(struct meshlink_handle *mesh, meshlink_node_pmtu_cb_t cb); +void (*full_meshlink_set_node_duplicate_cb)(struct meshlink_handle *mesh, meshlink_node_duplicate_cb_t cb); +void (*full_meshlink_set_log_cb)(struct meshlink_handle *mesh, meshlink_log_level_t level, meshlink_log_cb_t cb); +void (*full_meshlink_set_error_cb)(struct meshlink_handle *mesh, meshlink_error_cb_t cb); +void (*full_meshlink_set_blacklisted_cb)(struct meshlink_handle *mesh, meshlink_blacklisted_cb_t cb); +bool (*full_meshlink_send)(struct meshlink_handle *mesh, struct meshlink_node *destination, const void *data, size_t len) __attribute__((__warn_unused_result__)); +ssize_t (*full_meshlink_get_pmtu)(struct meshlink_handle *mesh, struct meshlink_node *destination) __attribute__((__warn_unused_result__)); +struct meshlink_node *(*full_meshlink_get_self)(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__)); +struct meshlink_node *(*full_meshlink_get_node)(struct meshlink_handle *mesh, const char *name) __attribute__((__warn_unused_result__)); +struct meshlink_submesh *(*full_meshlink_get_submesh)(struct meshlink_handle *mesh, const char *name) __attribute__((__warn_unused_result__)); +char *(*full_meshlink_get_fingerprint)(struct meshlink_handle *mesh, struct meshlink_node *node) __attribute__((__warn_unused_result__)); +struct meshlink_node **(*full_meshlink_get_all_nodes)(struct meshlink_handle *mesh, struct meshlink_node **nodes, size_t *nmemb) __attribute__((__warn_unused_result__)); +bool (*full_meshlink_sign)(struct meshlink_handle *mesh, const void *data, size_t len, void *signature, size_t *siglen) __attribute__((__warn_unused_result__)); +struct meshlink_node **(*full_meshlink_get_all_nodes_by_dev_class)(struct meshlink_handle *mesh, dev_class_t devclass, struct meshlink_node **nodes, size_t *nmemb) __attribute__((__warn_unused_result__)); +struct meshlink_node **(*full_meshlink_get_all_nodes_by_submesh)(struct meshlink_handle *mesh, struct meshlink_submesh *submesh, struct meshlink_node **nodes, size_t *nmemb) __attribute__((__warn_unused_result__)); +struct meshlink_node **(*full_meshlink_get_all_nodes_by_last_reachable)(struct meshlink_handle *mesh, time_t start, time_t end, struct meshlink_node **nodes, size_t *nmemb) __attribute__((__warn_unused_result__)); +struct meshlink_node **(*full_meshlink_get_all_nodes_by_blacklisted)(struct meshlink_handle *mesh, bool blacklisted, struct meshlink_node **nodes, size_t *nmemb) __attribute__((__warn_unused_result__)); +dev_class_t (*full_meshlink_get_node_dev_class)(struct meshlink_handle *mesh, struct meshlink_node *node) __attribute__((__warn_unused_result__)); +bool (*full_meshlink_get_node_blacklisted)(struct meshlink_handle *mesh, struct meshlink_node *node) __attribute__((__warn_unused_result__)); +struct meshlink_submesh *(*full_meshlink_get_node_submesh)(struct meshlink_handle *mesh, struct meshlink_node *node) __attribute__((__warn_unused_result__)); +bool (*full_meshlink_get_node_reachability)(struct meshlink_handle *mesh, struct meshlink_node *node, time_t *last_reachable, time_t *last_unreachable); +bool (*full_meshlink_verify)(struct meshlink_handle *mesh, struct meshlink_node *source, const void *data, size_t len, const void *signature, size_t siglen) __attribute__((__warn_unused_result__)); +bool (*full_meshlink_set_canonical_address)(struct meshlink_handle *mesh, struct meshlink_node *node, const char *address, const char *port) __attribute__((__warn_unused_result__)); +bool (*full_meshlink_clear_canonical_address)(struct meshlink_handle *mesh, struct meshlink_node *node) __attribute__((__warn_unused_result__)); +bool (*full_meshlink_add_invitation_address)(struct meshlink_handle *mesh, const char *address, const char *port) __attribute__((__warn_unused_result__)); +void (*full_meshlink_clear_invitation_addresses)(struct meshlink_handle *mesh); +char *(*full_meshlink_get_external_address)(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__)); +char *(*full_meshlink_get_external_address_for_family)(struct meshlink_handle *mesh, int address_family) __attribute__((__warn_unused_result__)); +char *(*full_meshlink_get_local_address_for_family)(struct meshlink_handle *mesh, int address_family) __attribute__((__warn_unused_result__)); +bool (*full_meshlink_add_external_address)(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__)); +int (*full_meshlink_get_port)(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__)); +bool (*full_meshlink_set_port)(struct meshlink_handle *mesh, int port) __attribute__((__warn_unused_result__)); +void (*full_meshlink_set_invitation_timeout)(struct meshlink_handle *mesh, int timeout); +char *(*full_meshlink_invite_ex)(struct meshlink_handle *mesh, struct meshlink_submesh *submesh, const char *name, uint32_t flags) __attribute__((__warn_unused_result__)); +char *(*full_meshlink_invite)(struct meshlink_handle *mesh, struct meshlink_submesh *submesh, const char *name) __attribute__((__warn_unused_result__)); +bool (*full_meshlink_join)(struct meshlink_handle *mesh, const char *invitation) __attribute__((__warn_unused_result__)); +char *(*full_meshlink_export)(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__)); +bool (*full_meshlink_import)(struct meshlink_handle *mesh, const char *data) __attribute__((__warn_unused_result__)); +bool (*full_meshlink_forget_node)(struct meshlink_handle *mesh, struct meshlink_node *node); +bool (*full_meshlink_blacklist)(struct meshlink_handle *mesh, struct meshlink_node *node) __attribute__((__warn_unused_result__)); +bool (*full_meshlink_blacklist_by_name)(struct meshlink_handle *mesh, const char *name) __attribute__((__warn_unused_result__)); +bool (*full_meshlink_whitelist)(struct meshlink_handle *mesh, struct meshlink_node *node) __attribute__((__warn_unused_result__)); +bool (*full_meshlink_whitelist_by_name)(struct meshlink_handle *mesh, const char *name) __attribute__((__warn_unused_result__)); +void (*full_meshlink_set_default_blacklist)(struct meshlink_handle *mesh, bool blacklist); +void (*full_meshlink_set_channel_listen_cb)(struct meshlink_handle *mesh, meshlink_channel_listen_cb_t cb); +void (*full_meshlink_set_channel_accept_cb)(struct meshlink_handle *mesh, meshlink_channel_accept_cb_t cb); +void (*full_meshlink_set_channel_receive_cb)(struct meshlink_handle *mesh, struct meshlink_channel *channel, meshlink_channel_receive_cb_t cb); +void (*full_meshlink_set_channel_poll_cb)(struct meshlink_handle *mesh, struct meshlink_channel *channel, meshlink_channel_poll_cb_t cb); +void (*full_meshlink_set_channel_sndbuf)(struct meshlink_handle *mesh, struct meshlink_channel *channel, size_t size); +void (*full_meshlink_set_channel_rcvbuf)(struct meshlink_handle *mesh, struct meshlink_channel *channel, size_t size); +void (*full_meshlink_set_channel_sndbuf_storage)(struct meshlink_handle *mesh, struct meshlink_channel *channel, void *buf, size_t size); +void (*full_meshlink_set_channel_rcvbuf_storage)(struct meshlink_handle *mesh, struct meshlink_channel *channel, void *buf, size_t size); +void (*full_meshlink_set_channel_flags)(struct meshlink_handle *mesh, struct meshlink_channel *channel, uint32_t flags); +struct meshlink_channel *(*full_meshlink_channel_open_ex)(struct meshlink_handle *mesh, struct meshlink_node *node, uint16_t port, meshlink_channel_receive_cb_t cb, const void *data, size_t len, uint32_t flags) __attribute__((__warn_unused_result__)); +struct meshlink_channel *(*full_meshlink_channel_open)(struct meshlink_handle *mesh, struct meshlink_node *node, uint16_t port, meshlink_channel_receive_cb_t cb, const void *data, size_t len) __attribute__((__warn_unused_result__)); +void (*full_meshlink_channel_shutdown)(struct meshlink_handle *mesh, struct meshlink_channel *channel, int direction); +void (*full_meshlink_channel_close)(struct meshlink_handle *mesh, struct meshlink_channel *channel); +void (*full_meshlink_channel_abort)(struct meshlink_handle *mesh, struct meshlink_channel *channel); +ssize_t (*full_meshlink_channel_send)(struct meshlink_handle *mesh, struct meshlink_channel *channel, const void *data, size_t len) __attribute__((__warn_unused_result__)); +bool (*full_meshlink_channel_aio_send)(struct meshlink_handle *mesh, struct meshlink_channel *channel, const void *data, size_t len, meshlink_aio_cb_t cb, void *priv) __attribute__((__warn_unused_result__)); +bool (*full_meshlink_channel_aio_fd_send)(struct meshlink_handle *mesh, struct meshlink_channel *channel, int fd, size_t len, meshlink_aio_fd_cb_t cb, void *priv) __attribute__((__warn_unused_result__)); +bool (*full_meshlink_channel_aio_receive)(struct meshlink_handle *mesh, struct meshlink_channel *channel, const void *data, size_t len, meshlink_aio_cb_t cb, void *priv) __attribute__((__warn_unused_result__)); +bool (*full_meshlink_channel_aio_fd_receive)(struct meshlink_handle *mesh, struct meshlink_channel *channel, int fd, size_t len, meshlink_aio_fd_cb_t cb, void *priv) __attribute__((__warn_unused_result__)); +uint32_t (*full_meshlink_channel_get_flags)(struct meshlink_handle *mesh, struct meshlink_channel *channel) __attribute__((__warn_unused_result__)); +size_t (*full_meshlink_channel_get_sendq)(struct meshlink_handle *mesh, struct meshlink_channel *channel) __attribute__((__warn_unused_result__)); +size_t (*full_meshlink_channel_get_recvq)(struct meshlink_handle *mesh, struct meshlink_channel *channel) __attribute__((__warn_unused_result__)); +size_t (*full_meshlink_channel_get_mss)(struct meshlink_handle *mesh, struct meshlink_channel *channel) __attribute__((__warn_unused_result__)); +void (*full_meshlink_set_node_channel_timeout)(struct meshlink_handle *mesh, struct meshlink_node *node, int timeout); +void (*full_meshlink_hint_address)(struct meshlink_handle *mesh, struct meshlink_node *node, const struct sockaddr *addr); +void (*full_meshlink_enable_discovery)(struct meshlink_handle *mesh, bool enable); +void (*full_meshlink_hint_network_change)(struct meshlink_handle *mesh); +bool (*full_meshlink_encrypted_key_rotate)(struct meshlink_handle *mesh, const void *key, size_t keylen) __attribute__((__warn_unused_result__)); +void (*full_meshlink_set_dev_class_timeouts)(struct meshlink_handle *mesh, dev_class_t devclass, int pinginterval, int pingtimeout); +void (*full_meshlink_set_dev_class_fast_retry_period)(struct meshlink_handle *mesh, dev_class_t devclass, int fast_retry_period); +void (*full_meshlink_set_dev_class_maxtimeout)(struct meshlink_handle *mesh, dev_class_t devclass, int maxtimeout); +void (*full_meshlink_reset_timers)(struct meshlink_handle *mesh); +void (*full_meshlink_set_inviter_commits_first)(struct meshlink_handle *mesh, bool inviter_commits_first); +void (*full_meshlink_set_external_address_discovery_url)(struct meshlink_handle *mesh, const char *url); +void (*full_meshlink_set_scheduling_granularity)(struct meshlink_handle *mesh, long granularity); +void (*full_meshlink_set_storage_policy)(struct meshlink_handle *mesh, meshlink_storage_policy_t policy); + +full_devtool_set_inviter_commits_first_t *full_devtool_set_inviter_commits_first; + +void init_full(void) { + void *handle = dlopen("libmeshlink.so", RTLD_LAZY | RTLD_LOCAL | RTLD_DEEPBIND); + assert(handle); + + full_meshlink_errno = dlsym(handle, "meshlink_errno"); + full_meshlink_strerror = dlsym(handle, "meshlink_strerror"); + full_meshlink_open_params_init = dlsym(handle, "meshlink_open_params_init"); + full_meshlink_open_params_free = dlsym(handle, "meshlink_open_params_free"); + full_meshlink_open_params_set_netns = dlsym(handle, "meshlink_open_params_set_netns"); + full_meshlink_open_params_set_storage_key = dlsym(handle, "meshlink_open_params_set_storage_key"); + full_meshlink_open_params_set_storage_policy = dlsym(handle, "meshlink_open_params_set_storage_policy"); + full_meshlink_open_params_set_lock_filename = dlsym(handle, "meshlink_open_params_set_lock_filename"); + full_meshlink_open_ex = dlsym(handle, "meshlink_open_ex"); + full_meshlink_open = dlsym(handle, "meshlink_open"); + full_meshlink_open_encrypted = dlsym(handle, "meshlink_open_encrypted"); + full_meshlink_open_ephemeral = dlsym(handle, "meshlink_open_ephemeral"); + full_meshlink_submesh_open = dlsym(handle, "meshlink_submesh_open"); + full_meshlink_start = dlsym(handle, "meshlink_start"); + full_meshlink_stop = dlsym(handle, "meshlink_stop"); + full_meshlink_close = dlsym(handle, "meshlink_close"); + full_meshlink_destroy = dlsym(handle, "meshlink_destroy"); + full_meshlink_destroy_ex = dlsym(handle, "meshlink_destroy_ex"); + full_meshlink_set_receive_cb = dlsym(handle, "meshlink_set_receive_cb"); + full_meshlink_set_connection_try_cb = dlsym(handle, "meshlink_set_connection_try_cb"); + full_meshlink_set_node_status_cb = dlsym(handle, "meshlink_set_node_status_cb"); + full_meshlink_set_node_pmtu_cb = dlsym(handle, "meshlink_set_node_pmtu_cb"); + full_meshlink_set_node_duplicate_cb = dlsym(handle, "meshlink_set_node_duplicate_cb"); + full_meshlink_set_log_cb = dlsym(handle, "meshlink_set_log_cb"); + full_meshlink_set_error_cb = dlsym(handle, "meshlink_set_error_cb"); + full_meshlink_set_blacklisted_cb = dlsym(handle, "meshlink_set_blacklisted_cb"); + full_meshlink_send = dlsym(handle, "meshlink_send"); + full_meshlink_get_pmtu = dlsym(handle, "meshlink_get_pmtu"); + full_meshlink_get_self = dlsym(handle, "meshlink_get_self"); + full_meshlink_get_node = dlsym(handle, "meshlink_get_node"); + full_meshlink_get_submesh = dlsym(handle, "meshlink_get_submesh"); + full_meshlink_get_fingerprint = dlsym(handle, "meshlink_get_fingerprint"); + full_meshlink_get_all_nodes = dlsym(handle, "meshlink_get_all_nodes"); + full_meshlink_sign = dlsym(handle, "meshlink_sign"); + full_meshlink_get_all_nodes_by_dev_class = dlsym(handle, "meshlink_get_all_nodes_by_dev_class"); + full_meshlink_get_all_nodes_by_submesh = dlsym(handle, "meshlink_get_all_nodes_by_submesh"); + full_meshlink_get_all_nodes_by_last_reachable = dlsym(handle, "meshlink_get_all_nodes_by_last_reachable"); + full_meshlink_get_all_nodes_by_blacklisted = dlsym(handle, "meshlink_get_all_nodes_by_blacklisted"); + full_meshlink_get_node_dev_class = dlsym(handle, "meshlink_get_node_dev_class"); + full_meshlink_get_node_blacklisted = dlsym(handle, "meshlink_get_node_blacklisted"); + full_meshlink_get_node_submesh = dlsym(handle, "meshlink_get_node_submesh"); + full_meshlink_get_node_reachability = dlsym(handle, "meshlink_get_node_reachability"); + full_meshlink_verify = dlsym(handle, "meshlink_verify"); + full_meshlink_set_canonical_address = dlsym(handle, "meshlink_set_canonical_address"); + full_meshlink_clear_canonical_address = dlsym(handle, "meshlink_clear_canonical_address"); + full_meshlink_add_invitation_address = dlsym(handle, "meshlink_add_invitation_address"); + full_meshlink_clear_invitation_addresses = dlsym(handle, "meshlink_clear_invitation_addresses"); + full_meshlink_get_external_address = dlsym(handle, "meshlink_get_external_address"); + full_meshlink_get_external_address_for_family = dlsym(handle, "meshlink_get_external_address_for_family"); + full_meshlink_get_local_address_for_family = dlsym(handle, "meshlink_get_local_address_for_family"); + full_meshlink_add_external_address = dlsym(handle, "meshlink_add_external_address"); + full_meshlink_get_port = dlsym(handle, "meshlink_get_port"); + full_meshlink_set_port = dlsym(handle, "meshlink_set_port"); + full_meshlink_set_invitation_timeout = dlsym(handle, "meshlink_set_invitation_timeout"); + full_meshlink_invite_ex = dlsym(handle, "meshlink_invite_ex"); + full_meshlink_invite = dlsym(handle, "meshlink_invite"); + full_meshlink_join = dlsym(handle, "meshlink_join"); + full_meshlink_export = dlsym(handle, "meshlink_export"); + full_meshlink_import = dlsym(handle, "meshlink_import"); + full_meshlink_forget_node = dlsym(handle, "meshlink_forget_node"); + full_meshlink_blacklist = dlsym(handle, "meshlink_blacklist"); + full_meshlink_blacklist_by_name = dlsym(handle, "meshlink_blacklist_by_name"); + full_meshlink_whitelist = dlsym(handle, "meshlink_whitelist"); + full_meshlink_whitelist_by_name = dlsym(handle, "meshlink_whitelist_by_name"); + full_meshlink_set_default_blacklist = dlsym(handle, "meshlink_set_default_blacklist"); + full_meshlink_set_channel_listen_cb = dlsym(handle, "meshlink_set_channel_listen_cb"); + full_meshlink_set_channel_accept_cb = dlsym(handle, "meshlink_set_channel_accept_cb"); + full_meshlink_set_channel_receive_cb = dlsym(handle, "meshlink_set_channel_receive_cb"); + full_meshlink_set_channel_poll_cb = dlsym(handle, "meshlink_set_channel_poll_cb"); + full_meshlink_set_channel_sndbuf = dlsym(handle, "meshlink_set_channel_sndbuf"); + full_meshlink_set_channel_rcvbuf = dlsym(handle, "meshlink_set_channel_rcvbuf"); + full_meshlink_set_channel_sndbuf_storage = dlsym(handle, "meshlink_set_channel_sndbuf_storage"); + full_meshlink_set_channel_rcvbuf_storage = dlsym(handle, "meshlink_set_channel_rcvbuf_storage"); + full_meshlink_set_channel_flags = dlsym(handle, "meshlink_set_channel_flags"); + full_meshlink_channel_open_ex = dlsym(handle, "meshlink_channel_open_ex"); + full_meshlink_channel_open = dlsym(handle, "meshlink_channel_open"); + full_meshlink_channel_shutdown = dlsym(handle, "meshlink_channel_shutdown"); + full_meshlink_channel_close = dlsym(handle, "meshlink_channel_close"); + full_meshlink_channel_abort = dlsym(handle, "meshlink_channel_abort"); + full_meshlink_channel_send = dlsym(handle, "meshlink_channel_send"); + full_meshlink_channel_aio_send = dlsym(handle, "meshlink_channel_aio_send"); + full_meshlink_channel_aio_fd_send = dlsym(handle, "meshlink_channel_aio_fd_send"); + full_meshlink_channel_aio_receive = dlsym(handle, "meshlink_channel_aio_receive"); + full_meshlink_channel_aio_fd_receive = dlsym(handle, "meshlink_channel_aio_fd_receive"); + full_meshlink_channel_get_flags = dlsym(handle, "meshlink_channel_get_flags"); + full_meshlink_channel_get_sendq = dlsym(handle, "meshlink_channel_get_sendq"); + full_meshlink_channel_get_recvq = dlsym(handle, "meshlink_channel_get_recvq"); + full_meshlink_channel_get_mss = dlsym(handle, "meshlink_channel_get_mss"); + full_meshlink_set_node_channel_timeout = dlsym(handle, "meshlink_set_node_channel_timeout"); + full_meshlink_hint_address = dlsym(handle, "meshlink_hint_address"); + full_meshlink_enable_discovery = dlsym(handle, "meshlink_enable_discovery"); + full_meshlink_hint_network_change = dlsym(handle, "meshlink_hint_network_change"); + full_meshlink_encrypted_key_rotate = dlsym(handle, "meshlink_encrypted_key_rotate"); + full_meshlink_set_dev_class_timeouts = dlsym(handle, "meshlink_set_dev_class_timeouts"); + full_meshlink_set_dev_class_fast_retry_period = dlsym(handle, "meshlink_set_dev_class_fast_retry_period"); + full_meshlink_set_dev_class_maxtimeout = dlsym(handle, "meshlink_set_dev_class_maxtimeout"); + full_meshlink_reset_timers = dlsym(handle, "meshlink_reset_timers"); + full_meshlink_set_inviter_commits_first = dlsym(handle, "meshlink_set_inviter_commits_first"); + full_meshlink_set_external_address_discovery_url = dlsym(handle, "meshlink_set_external_address_discovery_url"); + full_meshlink_set_scheduling_granularity = dlsym(handle, "meshlink_set_scheduling_granularity"); + full_meshlink_set_storage_policy = dlsym(handle, "meshlink_set_storage_policy"); + + full_devtool_set_inviter_commits_first = dlsym(handle, "devtool_set_inviter_commits_first"); +} diff --git a/test/full.h b/test/full.h new file mode 100644 index 0000000..93f5a1d --- /dev/null +++ b/test/full.h @@ -0,0 +1,134 @@ +#ifndef FULL_H +#define FULL_H + +#include "meshlink-tiny.h" + +typedef struct meshlink_channel meshlink_channel_t; +typedef struct meshlink_submesh meshlink_submesh_t; + +struct meshlink_channel { + struct meshlink_node *const node; ///< Pointer to the peer of this channel. + void *priv; ///< Private pointer which may be set freely by the application, and is never used or modified by MeshLink. +}; + +struct meshlink_submesh { + const char *const name; ///< Textual name of this Sub-Mesh. It is stored in a nul-terminated C string, which is allocated by MeshLink. + void *priv; ///< Private pointer which may be set freely by the application, and is never used or modified by MeshLink. +}; + +typedef void (*meshlink_node_pmtu_cb_t)(struct meshlink_handle *mesh, struct meshlink_node *node, uint16_t pmtu); +typedef void (*meshlink_blacklisted_cb_t)(struct meshlink_handle *mesh, struct meshlink_node *node); +typedef bool (*meshlink_channel_listen_cb_t)(struct meshlink_handle *mesh, struct meshlink_node *node, uint16_t port); +typedef bool (*meshlink_channel_accept_cb_t)(struct meshlink_handle *mesh, struct meshlink_channel *channel, uint16_t port, const void *data, size_t len); +typedef void (*meshlink_channel_receive_cb_t)(struct meshlink_handle *mesh, struct meshlink_channel *channel, const void *data, size_t len); +typedef void (*meshlink_channel_poll_cb_t)(struct meshlink_handle *mesh, struct meshlink_channel *channel, size_t len); +typedef void (*meshlink_aio_cb_t)(struct meshlink_handle *mesh, struct meshlink_channel *channel, const void *data, size_t len, void *priv); +typedef void (*meshlink_aio_fd_cb_t)(struct meshlink_handle *mesh, struct meshlink_channel *channel, int fd, size_t len, void *priv); + +extern meshlink_errno_t *full_meshlink_errno; +extern const char *(*full_meshlink_strerror)(meshlink_errno_t err) __attribute__((__warn_unused_result__)); +extern meshlink_open_params_t *(*full_meshlink_open_params_init)(const char *confbase, const char *name, const char *appname, dev_class_t devclass) __attribute__((__warn_unused_result__)); +extern void (*full_meshlink_open_params_free)(meshlink_open_params_t *params); +extern bool (*full_meshlink_open_params_set_netns)(meshlink_open_params_t *params, int netns) __attribute__((__warn_unused_result__)); +extern bool (*full_meshlink_open_params_set_storage_key)(meshlink_open_params_t *params, const void *key, size_t keylen) __attribute__((__warn_unused_result__)); +extern bool (*full_meshlink_open_params_set_storage_policy)(meshlink_open_params_t *params, meshlink_storage_policy_t policy) __attribute__((__warn_unused_result__)); +extern bool (*full_meshlink_open_params_set_lock_filename)(meshlink_open_params_t *params, const char *filename) __attribute__((__warn_unused_result__)); +extern struct meshlink_handle *(*full_meshlink_open_ex)(const meshlink_open_params_t *params) __attribute__((__warn_unused_result__)); +extern struct meshlink_handle *(*full_meshlink_open)(const char *confbase, const char *name, const char *appname, dev_class_t devclass) __attribute__((__warn_unused_result__)); +extern struct meshlink_handle *(*full_meshlink_open_encrypted)(const char *confbase, const char *name, const char *appname, dev_class_t devclass, const void *key, size_t keylen) __attribute__((__warn_unused_result__)); +extern struct meshlink_handle *(*full_meshlink_open_ephemeral)(const char *name, const char *appname, dev_class_t devclass) __attribute__((__warn_unused_result__)); +extern struct meshlink_submesh *(*full_meshlink_submesh_open)(struct meshlink_handle *mesh, const char *submesh) __attribute__((__warn_unused_result__)); +extern bool (*full_meshlink_start)(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__)); +extern void (*full_meshlink_stop)(struct meshlink_handle *mesh); +extern void (*full_meshlink_close)(struct meshlink_handle *mesh); +extern bool (*full_meshlink_destroy)(const char *confbase) __attribute__((__warn_unused_result__)); +extern bool (*full_meshlink_destroy_ex)(const meshlink_open_params_t *params) __attribute__((__warn_unused_result__)); +extern void (*full_meshlink_set_receive_cb)(struct meshlink_handle *mesh, meshlink_receive_cb_t cb); +extern void (*full_meshlink_set_connection_try_cb)(struct meshlink_handle *mesh, meshlink_connection_try_cb_t cb); +extern void (*full_meshlink_set_node_status_cb)(struct meshlink_handle *mesh, meshlink_node_status_cb_t cb); +extern void (*full_meshlink_set_node_pmtu_cb)(struct meshlink_handle *mesh, meshlink_node_pmtu_cb_t cb); +extern void (*full_meshlink_set_node_duplicate_cb)(struct meshlink_handle *mesh, meshlink_node_duplicate_cb_t cb); +extern void (*full_meshlink_set_log_cb)(struct meshlink_handle *mesh, meshlink_log_level_t level, meshlink_log_cb_t cb); +extern void (*full_meshlink_set_error_cb)(struct meshlink_handle *mesh, meshlink_error_cb_t cb); +extern void (*full_meshlink_set_blacklisted_cb)(struct meshlink_handle *mesh, meshlink_blacklisted_cb_t cb); +extern bool (*full_meshlink_send)(struct meshlink_handle *mesh, struct meshlink_node *destination, const void *data, size_t len) __attribute__((__warn_unused_result__)); +extern ssize_t (*full_meshlink_get_pmtu)(struct meshlink_handle *mesh, struct meshlink_node *destination) __attribute__((__warn_unused_result__)); +extern struct meshlink_node *(*full_meshlink_get_self)(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__)); +extern struct meshlink_node *(*full_meshlink_get_node)(struct meshlink_handle *mesh, const char *name) __attribute__((__warn_unused_result__)); +extern struct meshlink_submesh *(*full_meshlink_get_submesh)(struct meshlink_handle *mesh, const char *name) __attribute__((__warn_unused_result__)); +extern char *(*full_meshlink_get_fingerprint)(struct meshlink_handle *mesh, struct meshlink_node *node) __attribute__((__warn_unused_result__)); +extern struct meshlink_node **(*full_meshlink_get_all_nodes)(struct meshlink_handle *mesh, struct meshlink_node **nodes, size_t *nmemb) __attribute__((__warn_unused_result__)); +extern bool (*full_meshlink_sign)(struct meshlink_handle *mesh, const void *data, size_t len, void *signature, size_t *siglen) __attribute__((__warn_unused_result__)); +extern struct meshlink_node **(*full_meshlink_get_all_nodes_by_dev_class)(struct meshlink_handle *mesh, dev_class_t devclass, struct meshlink_node **nodes, size_t *nmemb) __attribute__((__warn_unused_result__)); +extern struct meshlink_node **(*full_meshlink_get_all_nodes_by_submesh)(struct meshlink_handle *mesh, struct meshlink_submesh *submesh, struct meshlink_node **nodes, size_t *nmemb) __attribute__((__warn_unused_result__)); +extern struct meshlink_node **(*full_meshlink_get_all_nodes_by_last_reachable)(struct meshlink_handle *mesh, time_t start, time_t end, struct meshlink_node **nodes, size_t *nmemb) __attribute__((__warn_unused_result__)); +extern struct meshlink_node **(*full_meshlink_get_all_nodes_by_blacklisted)(struct meshlink_handle *mesh, bool blacklisted, struct meshlink_node **nodes, size_t *nmemb) __attribute__((__warn_unused_result__)); +extern dev_class_t (*full_meshlink_get_node_dev_class)(struct meshlink_handle *mesh, struct meshlink_node *node) __attribute__((__warn_unused_result__)); +extern bool (*full_meshlink_get_node_blacklisted)(struct meshlink_handle *mesh, struct meshlink_node *node) __attribute__((__warn_unused_result__)); +extern struct meshlink_submesh *(*full_meshlink_get_node_submesh)(struct meshlink_handle *mesh, struct meshlink_node *node) __attribute__((__warn_unused_result__)); +extern bool (*full_meshlink_get_node_reachability)(struct meshlink_handle *mesh, struct meshlink_node *node, time_t *last_reachable, time_t *last_unreachable); +extern bool (*full_meshlink_verify)(struct meshlink_handle *mesh, struct meshlink_node *source, const void *data, size_t len, const void *signature, size_t siglen) __attribute__((__warn_unused_result__)); +extern bool (*full_meshlink_set_canonical_address)(struct meshlink_handle *mesh, struct meshlink_node *node, const char *address, const char *port) __attribute__((__warn_unused_result__)); +extern bool (*full_meshlink_clear_canonical_address)(struct meshlink_handle *mesh, struct meshlink_node *node) __attribute__((__warn_unused_result__)); +extern bool (*full_meshlink_add_invitation_address)(struct meshlink_handle *mesh, const char *address, const char *port) __attribute__((__warn_unused_result__)); +extern void (*full_meshlink_clear_invitation_addresses)(struct meshlink_handle *mesh); +extern char *(*full_meshlink_get_external_address)(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__)); +extern char *(*full_meshlink_get_external_address_for_family)(struct meshlink_handle *mesh, int address_family) __attribute__((__warn_unused_result__)); +extern char *(*full_meshlink_get_local_address_for_family)(struct meshlink_handle *mesh, int address_family) __attribute__((__warn_unused_result__)); +extern bool (*full_meshlink_add_external_address)(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__)); +extern int (*full_meshlink_get_port)(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__)); +extern bool (*full_meshlink_set_port)(struct meshlink_handle *mesh, int port) __attribute__((__warn_unused_result__)); +extern void (*full_meshlink_set_invitation_timeout)(struct meshlink_handle *mesh, int timeout); +extern char *(*full_meshlink_invite_ex)(struct meshlink_handle *mesh, struct meshlink_submesh *submesh, const char *name, uint32_t flags) __attribute__((__warn_unused_result__)); +extern char *(*full_meshlink_invite)(struct meshlink_handle *mesh, struct meshlink_submesh *submesh, const char *name) __attribute__((__warn_unused_result__)); +extern bool (*full_meshlink_join)(struct meshlink_handle *mesh, const char *invitation) __attribute__((__warn_unused_result__)); +extern char *(*full_meshlink_export)(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__)); +extern bool (*full_meshlink_import)(struct meshlink_handle *mesh, const char *data) __attribute__((__warn_unused_result__)); +extern bool (*full_meshlink_forget_node)(struct meshlink_handle *mesh, struct meshlink_node *node); +extern bool (*full_meshlink_blacklist)(struct meshlink_handle *mesh, struct meshlink_node *node) __attribute__((__warn_unused_result__)); +extern bool (*full_meshlink_blacklist_by_name)(struct meshlink_handle *mesh, const char *name) __attribute__((__warn_unused_result__)); +extern bool (*full_meshlink_whitelist)(struct meshlink_handle *mesh, struct meshlink_node *node) __attribute__((__warn_unused_result__)); +extern bool (*full_meshlink_whitelist_by_name)(struct meshlink_handle *mesh, const char *name) __attribute__((__warn_unused_result__)); +extern void (*full_meshlink_set_default_blacklist)(struct meshlink_handle *mesh, bool blacklist); +extern void (*full_meshlink_set_channel_listen_cb)(struct meshlink_handle *mesh, meshlink_channel_listen_cb_t cb); +extern void (*full_meshlink_set_channel_accept_cb)(struct meshlink_handle *mesh, meshlink_channel_accept_cb_t cb); +extern void (*full_meshlink_set_channel_receive_cb)(struct meshlink_handle *mesh, struct meshlink_channel *channel, meshlink_channel_receive_cb_t cb); +extern void (*full_meshlink_set_channel_poll_cb)(struct meshlink_handle *mesh, struct meshlink_channel *channel, meshlink_channel_poll_cb_t cb); +extern void (*full_meshlink_set_channel_sndbuf)(struct meshlink_handle *mesh, struct meshlink_channel *channel, size_t size); +extern void (*full_meshlink_set_channel_rcvbuf)(struct meshlink_handle *mesh, struct meshlink_channel *channel, size_t size); +extern void (*full_meshlink_set_channel_sndbuf_storage)(struct meshlink_handle *mesh, struct meshlink_channel *channel, void *buf, size_t size); +extern void (*full_meshlink_set_channel_rcvbuf_storage)(struct meshlink_handle *mesh, struct meshlink_channel *channel, void *buf, size_t size); +extern void (*full_meshlink_set_channel_flags)(struct meshlink_handle *mesh, struct meshlink_channel *channel, uint32_t flags); +extern struct meshlink_channel *(*full_meshlink_channel_open_ex)(struct meshlink_handle *mesh, struct meshlink_node *node, uint16_t port, meshlink_channel_receive_cb_t cb, const void *data, size_t len, uint32_t flags) __attribute__((__warn_unused_result__)); +extern struct meshlink_channel *(*full_meshlink_channel_open)(struct meshlink_handle *mesh, struct meshlink_node *node, uint16_t port, meshlink_channel_receive_cb_t cb, const void *data, size_t len) __attribute__((__warn_unused_result__)); +extern void (*full_meshlink_channel_shutdown)(struct meshlink_handle *mesh, struct meshlink_channel *channel, int direction); +extern void (*full_meshlink_channel_close)(struct meshlink_handle *mesh, struct meshlink_channel *channel); +extern void (*full_meshlink_channel_abort)(struct meshlink_handle *mesh, struct meshlink_channel *channel); +extern ssize_t (*full_meshlink_channel_send)(struct meshlink_handle *mesh, struct meshlink_channel *channel, const void *data, size_t len) __attribute__((__warn_unused_result__)); +extern bool (*full_meshlink_channel_aio_send)(struct meshlink_handle *mesh, struct meshlink_channel *channel, const void *data, size_t len, meshlink_aio_cb_t cb, void *priv) __attribute__((__warn_unused_result__)); +extern bool (*full_meshlink_channel_aio_fd_send)(struct meshlink_handle *mesh, struct meshlink_channel *channel, int fd, size_t len, meshlink_aio_fd_cb_t cb, void *priv) __attribute__((__warn_unused_result__)); +extern bool (*full_meshlink_channel_aio_receive)(struct meshlink_handle *mesh, struct meshlink_channel *channel, const void *data, size_t len, meshlink_aio_cb_t cb, void *priv) __attribute__((__warn_unused_result__)); +extern bool (*full_meshlink_channel_aio_fd_receive)(struct meshlink_handle *mesh, struct meshlink_channel *channel, int fd, size_t len, meshlink_aio_fd_cb_t cb, void *priv) __attribute__((__warn_unused_result__)); +extern uint32_t (*full_meshlink_channel_get_flags)(struct meshlink_handle *mesh, struct meshlink_channel *channel) __attribute__((__warn_unused_result__)); +extern size_t (*full_meshlink_channel_get_sendq)(struct meshlink_handle *mesh, struct meshlink_channel *channel) __attribute__((__warn_unused_result__)); +extern size_t (*full_meshlink_channel_get_recvq)(struct meshlink_handle *mesh, struct meshlink_channel *channel) __attribute__((__warn_unused_result__)); +extern size_t (*full_meshlink_channel_get_mss)(struct meshlink_handle *mesh, struct meshlink_channel *channel) __attribute__((__warn_unused_result__)); +extern void (*full_meshlink_set_node_channel_timeout)(struct meshlink_handle *mesh, struct meshlink_node *node, int timeout); +extern void (*full_meshlink_hint_address)(struct meshlink_handle *mesh, struct meshlink_node *node, const struct sockaddr *addr); +extern void (*full_meshlink_enable_discovery)(struct meshlink_handle *mesh, bool enable); +extern void (*full_meshlink_hint_network_change)(struct meshlink_handle *mesh); +extern bool (*full_meshlink_encrypted_key_rotate)(struct meshlink_handle *mesh, const void *key, size_t keylen) __attribute__((__warn_unused_result__)); +extern void (*full_meshlink_set_dev_class_timeouts)(struct meshlink_handle *mesh, dev_class_t devclass, int pinginterval, int pingtimeout); +extern void (*full_meshlink_set_dev_class_fast_retry_period)(struct meshlink_handle *mesh, dev_class_t devclass, int fast_retry_period); +extern void (*full_meshlink_set_dev_class_maxtimeout)(struct meshlink_handle *mesh, dev_class_t devclass, int maxtimeout); +extern void (*full_meshlink_reset_timers)(struct meshlink_handle *mesh); +extern void (*full_meshlink_set_inviter_commits_first)(struct meshlink_handle *mesh, bool inviter_commits_first); +extern void (*full_meshlink_set_external_address_discovery_url)(struct meshlink_handle *mesh, const char *url); +extern void (*full_meshlink_set_scheduling_granularity)(struct meshlink_handle *mesh, long granularity); +extern void (*full_meshlink_set_storage_policy)(struct meshlink_handle *mesh, meshlink_storage_policy_t policy); + +typedef void (*full_devtool_set_inviter_commits_first_t)(bool inviter_commited_first); +extern full_devtool_set_inviter_commits_first_t *full_devtool_set_inviter_commits_first; + +void init_full(void); +#endif diff --git a/test/import-export.c b/test/import-export.c index 3382fee..dfad386 100644 --- a/test/import-export.c +++ b/test/import-export.c @@ -13,7 +13,6 @@ #include "utils.h" static struct sync_flag bar_reachable; -static struct sync_flag pmtu_flag; static void status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { (void)mesh; @@ -23,17 +22,8 @@ static void status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reach } } -static void pmtu_cb(meshlink_handle_t *mesh, meshlink_node_t *node, uint16_t pmtu) { - (void)mesh; - - if(pmtu && !strcmp(node->name, "bar")) { - set_sync_flag(&pmtu_flag, true); - } -} - int main(void) { init_sync_flag(&bar_reachable); - init_sync_flag(&pmtu_flag); meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); @@ -73,46 +63,8 @@ int main(void) { // Check that foo knows bar, but that it is not reachable. - time_t last_reachable; - time_t last_unreachable; meshlink_node_t *bar = meshlink_get_node(mesh1, "bar"); assert(bar); - assert(!meshlink_get_node_reachability(mesh1, bar, &last_reachable, &last_unreachable)); - assert(!last_reachable); - assert(!last_unreachable); - - // Start both instances - - meshlink_set_node_status_cb(mesh1, status_cb); - meshlink_set_node_pmtu_cb(mesh1, pmtu_cb); - - assert(meshlink_start(mesh1)); - assert(meshlink_start(mesh2)); - - // Wait for the two to connect. - - assert(wait_sync_flag(&bar_reachable, 10)); - - // Wait for UDP communication to become possible. - - assert(wait_sync_flag(&pmtu_flag, 10)); - - // Check that we now have reachability information - - assert(meshlink_get_node_reachability(mesh1, bar, &last_reachable, &last_unreachable)); - assert(last_reachable); - - // Stop the meshes. - - meshlink_stop(mesh1); - meshlink_stop(mesh2); - - // Check that bar is no longer reachable - - assert(!meshlink_get_node_reachability(mesh1, bar, &last_reachable, &last_unreachable)); - assert(last_reachable); - assert(last_unreachable); - assert(last_reachable <= last_unreachable); // Clean up. diff --git a/test/invite-join.c b/test/invite-join.c index e84ddd8..c025304 100644 --- a/test/invite-join.c +++ b/test/invite-join.c @@ -14,6 +14,8 @@ #include "devtools.h" #include "utils.h" +#include "full.h" + static struct sync_flag baz_reachable; static struct sync_flag seven_reachable; static struct sync_flag commits_first_flag; @@ -45,6 +47,8 @@ static void inviter_commits_first_cb(bool inviter_first) { } int main(void) { + init_full(); + init_sync_flag(&baz_reachable); init_sync_flag(&seven_reachable); init_sync_flag(&commits_first_flag); @@ -63,7 +67,7 @@ int main(void) { // Open thee new meshlink instance. - meshlink_handle_t *mesh1 = meshlink_open("invite_join_conf.1", "foo", "invite-join", DEV_CLASS_BACKBONE); + meshlink_handle_t *mesh1 = full_meshlink_open("invite_join_conf.1", "foo", "invite-join", DEV_CLASS_BACKBONE); assert(mesh1); meshlink_handle_t *mesh2 = meshlink_open("invite_join_conf.2", "bar", "invite-join", DEV_CLASS_BACKBONE); @@ -74,19 +78,19 @@ int main(void) { // Have the first instance generate invitations. - meshlink_set_node_status_cb(mesh1, status_cb); + full_meshlink_set_node_status_cb(mesh1, status_cb); - assert(meshlink_set_canonical_address(mesh1, meshlink_get_self(mesh1), "localhost", NULL)); + assert(full_meshlink_set_canonical_address(mesh1, full_meshlink_get_self(mesh1), "localhost", NULL)); - char *baz_url = meshlink_invite(mesh1, NULL, "baz"); + char *baz_url = full_meshlink_invite(mesh1, NULL, "baz"); assert(baz_url); - char *quux_url = meshlink_invite(mesh1, NULL, "quux"); + char *quux_url = full_meshlink_invite(mesh1, NULL, "quux"); assert(quux_url); // Check that the second instances cannot join if it is already started - assert(meshlink_start(mesh1)); + assert(full_meshlink_start(mesh1)); assert(meshlink_start(mesh2)); meshlink_errno = MESHLINK_OK; assert(!meshlink_join(mesh2, baz_url)); @@ -104,11 +108,11 @@ int main(void) { // Wait for UDP communication to become possible. - int pmtu = meshlink_get_pmtu(mesh1, meshlink_get_node(mesh1, "baz")); + int pmtu = full_meshlink_get_pmtu(mesh1, meshlink_get_node(mesh1, "baz")); for(int i = 0; i < 10 && !pmtu; i++) { sleep(1); - pmtu = meshlink_get_pmtu(mesh1, meshlink_get_node(mesh1, "baz")); + pmtu = full_meshlink_get_pmtu(mesh1, meshlink_get_node(mesh1, "baz")); } assert(pmtu); @@ -120,18 +124,16 @@ int main(void) { // Check that nodes cannot join with expired invitations - meshlink_set_invitation_timeout(mesh1, 0); + full_meshlink_set_invitation_timeout(mesh1, 0); assert(!meshlink_join(mesh3, quux_url)); free(quux_url); // Check that existing nodes cannot join another mesh - char *corge_url = meshlink_invite(mesh3, NULL, "corge"); + char *corge_url = full_meshlink_invite(mesh1, NULL, "corge"); assert(corge_url); - assert(meshlink_start(mesh3)); - meshlink_stop(mesh2); assert(!meshlink_join(mesh2, corge_url)); @@ -139,25 +141,25 @@ int main(void) { // Check that invitations work correctly after changing ports - meshlink_set_invitation_timeout(mesh1, 86400); - meshlink_stop(mesh1); + full_meshlink_set_invitation_timeout(mesh1, 86400); + full_meshlink_stop(mesh1); meshlink_stop(mesh3); - int oldport = meshlink_get_port(mesh1); + int oldport = full_meshlink_get_port(mesh1); bool success = false; for(int i = 0; !success && i < 100; i++) { - success = meshlink_set_port(mesh1, 0x9000 + rand() % 0x1000); + success = full_meshlink_set_port(mesh1, 0x9000 + rand() % 0x1000); } assert(success); - int newport = meshlink_get_port(mesh1); + int newport = full_meshlink_get_port(mesh1); assert(oldport != newport); - assert(meshlink_set_canonical_address(mesh1, meshlink_get_self(mesh1), "localhost", NULL)); + assert(full_meshlink_set_canonical_address(mesh1, meshlink_get_self(mesh1), "localhost", NULL)); - assert(meshlink_start(mesh1)); - quux_url = meshlink_invite(mesh1, NULL, "quux"); + assert(full_meshlink_start(mesh1)); + quux_url = full_meshlink_invite(mesh1, NULL, "quux"); assert(quux_url); // The old port should not be in the invitation URL @@ -178,8 +180,8 @@ int main(void) { // Check that adding duplicate addresses get removed correctly - assert(meshlink_add_invitation_address(mesh1, "localhost", portstr + 1)); - corge_url = meshlink_invite(mesh1, NULL, "corge"); + assert(full_meshlink_add_invitation_address(mesh1, "localhost", portstr + 1)); + corge_url = full_meshlink_invite(mesh1, NULL, "corge"); assert(corge_url); char *localhost = strstr(corge_url, "localhost"); assert(localhost); @@ -188,13 +190,13 @@ int main(void) { // Check that resetting and adding multiple, different invitation address works - meshlink_clear_invitation_addresses(mesh1); - assert(meshlink_add_invitation_address(mesh1, "1.invalid.", "12345")); - assert(meshlink_add_invitation_address(mesh1, "2.invalid.", NULL)); - assert(meshlink_add_invitation_address(mesh1, "3.invalid.", NULL)); - assert(meshlink_add_invitation_address(mesh1, "4.invalid.", NULL)); - assert(meshlink_add_invitation_address(mesh1, "5.invalid.", NULL)); - char *grault_url = meshlink_invite(mesh1, NULL, "grault"); + full_meshlink_clear_invitation_addresses(mesh1); + assert(full_meshlink_add_invitation_address(mesh1, "1.invalid.", "12345")); + assert(full_meshlink_add_invitation_address(mesh1, "2.invalid.", NULL)); + assert(full_meshlink_add_invitation_address(mesh1, "3.invalid.", NULL)); + assert(full_meshlink_add_invitation_address(mesh1, "4.invalid.", NULL)); + assert(full_meshlink_add_invitation_address(mesh1, "5.invalid.", NULL)); + char *grault_url = full_meshlink_invite(mesh1, NULL, "grault"); assert(grault_url); localhost = strstr(grault_url, "localhost"); assert(localhost); @@ -211,7 +213,7 @@ int main(void) { // Check inviting nodes into a submesh - assert(!meshlink_get_node_submesh(mesh1, meshlink_get_self(mesh1))); + assert(!full_meshlink_get_node_submesh(mesh1, meshlink_get_self(mesh1))); meshlink_handle_t *mesh4 = meshlink_open("invite_join_conf.4", "four", "invite-join", DEV_CLASS_BACKBONE); meshlink_handle_t *mesh5 = meshlink_open("invite_join_conf.5", "five", "invite-join", DEV_CLASS_BACKBONE); @@ -220,18 +222,14 @@ int main(void) { assert(mesh5); assert(mesh6); - meshlink_enable_discovery(mesh4, false); - meshlink_enable_discovery(mesh5, false); - meshlink_enable_discovery(mesh6, false); - - meshlink_submesh_t *submesh1 = meshlink_submesh_open(mesh1, "submesh1"); - meshlink_submesh_t *submesh2 = meshlink_submesh_open(mesh1, "submesh2"); + meshlink_submesh_t *submesh1 = full_meshlink_submesh_open(mesh1, "submesh1"); + meshlink_submesh_t *submesh2 = full_meshlink_submesh_open(mesh1, "submesh2"); assert(submesh1); assert(submesh2); - char *four_url = meshlink_invite(mesh1, submesh1, mesh4->name); - char *five_url = meshlink_invite(mesh1, submesh1, mesh5->name); - char *six_url = meshlink_invite(mesh1, submesh2, mesh6->name); + char *four_url = full_meshlink_invite(mesh1, submesh1, mesh4->name); + char *five_url = full_meshlink_invite(mesh1, submesh1, mesh5->name); + char *six_url = full_meshlink_invite(mesh1, submesh2, mesh6->name); assert(four_url); assert(five_url); assert(six_url); @@ -249,88 +247,51 @@ int main(void) { assert(meshlink_start(mesh5)); assert(meshlink_start(mesh6)); - // Check that each node knows in which submesh it is - - meshlink_submesh_t *mesh4_submesh = meshlink_get_node_submesh(mesh4, meshlink_get_self(mesh4)); - meshlink_submesh_t *mesh5_submesh = meshlink_get_node_submesh(mesh4, meshlink_get_self(mesh5)); - meshlink_submesh_t *mesh6_submesh = meshlink_get_node_submesh(mesh6, meshlink_get_self(mesh6)); - assert(mesh4_submesh); - assert(mesh5_submesh); - assert(mesh6_submesh); - assert(!strcmp(mesh4_submesh->name, "submesh1")); - assert(!strcmp(mesh5_submesh->name, "submesh1")); - assert(!strcmp(mesh6_submesh->name, "submesh2")); - // Wait for nodes to connect, and check that foo sees the right submeshes sleep(2); - meshlink_node_t *mesh1_four = meshlink_get_node(mesh1, mesh4->name); - meshlink_node_t *mesh1_six = meshlink_get_node(mesh1, mesh6->name); - assert(meshlink_get_node_submesh(mesh1, meshlink_get_self(mesh1)) == NULL); - assert(meshlink_get_node_submesh(mesh1, mesh1_four) == submesh1); - assert(meshlink_get_node_submesh(mesh1, mesh1_six) == submesh2); - - // Check that the new invitees still have the right submesh information + meshlink_node_t *mesh1_four = full_meshlink_get_node(mesh1, mesh4->name); + meshlink_node_t *mesh1_six = full_meshlink_get_node(mesh1, mesh6->name); + assert(full_meshlink_get_node_submesh(mesh1, meshlink_get_self(mesh1)) == NULL); + assert(full_meshlink_get_node_submesh(mesh1, mesh1_four) == submesh1); + assert(full_meshlink_get_node_submesh(mesh1, mesh1_six) == submesh2); - meshlink_node_t *mesh4_four = meshlink_get_node(mesh4, mesh4->name); - meshlink_node_t *mesh4_five = meshlink_get_node(mesh4, mesh5->name); - meshlink_node_t *mesh6_six = meshlink_get_node(mesh6, mesh6->name); - assert(meshlink_get_node_submesh(mesh4, mesh4_four) == mesh4_submesh); - assert(meshlink_get_node_submesh(mesh4, mesh4_five) == mesh4_submesh); - assert(meshlink_get_node_submesh(mesh6, mesh6_six) == mesh6_submesh); + // Check that none of the tiny nodes can see each other, regardless of which submesh they are in - // Check that bar can see all the nodes in submeshes and vice versa + assert(!meshlink_get_node(mesh2, mesh4->name)); + assert(!meshlink_get_node(mesh2, mesh5->name)); + assert(!meshlink_get_node(mesh2, mesh6->name)); + assert(!meshlink_get_node(mesh4, mesh2->name)); + assert(!meshlink_get_node(mesh5, mesh2->name)); + assert(!meshlink_get_node(mesh6, mesh2->name)); - assert(meshlink_get_node(mesh2, mesh4->name)); - assert(meshlink_get_node(mesh2, mesh5->name)); - assert(meshlink_get_node(mesh2, mesh6->name)); - assert(meshlink_get_node(mesh4, mesh2->name)); - assert(meshlink_get_node(mesh5, mesh2->name)); - assert(meshlink_get_node(mesh6, mesh2->name)); + assert(!meshlink_get_node(mesh4, mesh5->name)); + assert(!meshlink_get_node(mesh5, mesh4->name)); - // Check that four and five can see each other - - assert(meshlink_get_node(mesh4, mesh5->name)); - assert(meshlink_get_node(mesh5, mesh4->name)); - - // Check that the nodes in different submeshes cannot see each other assert(!meshlink_get_node(mesh4, mesh6->name)); assert(!meshlink_get_node(mesh5, mesh6->name)); assert(!meshlink_get_node(mesh6, mesh4->name)); assert(!meshlink_get_node(mesh6, mesh5->name)); - // Check that bar sees the right submesh information for the nodes in submeshes - - meshlink_submesh_t *mesh2_four_submesh = meshlink_get_node_submesh(mesh2, meshlink_get_node(mesh2, mesh4->name)); - meshlink_submesh_t *mesh2_five_submesh = meshlink_get_node_submesh(mesh2, meshlink_get_node(mesh2, mesh5->name)); - meshlink_submesh_t *mesh2_six_submesh = meshlink_get_node_submesh(mesh2, meshlink_get_node(mesh2, mesh6->name)); - assert(mesh2_four_submesh); - assert(mesh2_five_submesh); - assert(mesh2_six_submesh); - assert(!strcmp(mesh2_four_submesh->name, "submesh1")); - assert(!strcmp(mesh2_five_submesh->name, "submesh1")); - assert(!strcmp(mesh2_six_submesh->name, "submesh2")); - // Test case #2: check invalid parameters meshlink_handle_t *mesh7 = meshlink_open("invite_join_conf.7", "seven", "invite-join", DEV_CLASS_BACKBONE); assert(mesh7); - meshlink_enable_discovery(mesh7, false); - char *seven_url = meshlink_invite(mesh1, NULL, "seven"); + char *seven_url = full_meshlink_invite(mesh1, NULL, "seven"); assert(seven_url); meshlink_errno = MESHLINK_OK; - assert(!meshlink_invite(NULL, NULL, "seven")); - assert(meshlink_errno == MESHLINK_EINVAL); + assert(!full_meshlink_invite(NULL, NULL, "seven")); + assert(*full_meshlink_errno == MESHLINK_EINVAL); meshlink_errno = MESHLINK_OK; - assert(!meshlink_invite(mesh1, NULL, NULL)); - assert(meshlink_errno == MESHLINK_EINVAL); + assert(!full_meshlink_invite(mesh1, NULL, NULL)); + assert(*full_meshlink_errno == MESHLINK_EINVAL); meshlink_errno = MESHLINK_OK; - assert(!meshlink_invite(mesh1, NULL, "")); - assert(meshlink_errno == MESHLINK_EINVAL); + assert(!full_meshlink_invite(mesh1, NULL, "")); + assert(*full_meshlink_errno == MESHLINK_EINVAL); meshlink_errno = MESHLINK_OK; assert(!meshlink_join(NULL, seven_url)); @@ -348,21 +309,20 @@ int main(void) { assert(meshlink_join(mesh7, seven_url)); free(seven_url); - meshlink_close(mesh1); + full_meshlink_close(mesh1); meshlink_stop(mesh2); meshlink_stop(mesh3); meshlink_stop(mesh4); meshlink_stop(mesh5); meshlink_stop(mesh6); meshlink_close(mesh7); - mesh1 = meshlink_open("invite_join_conf.1", "foo", "invite-join", DEV_CLASS_BACKBONE); + mesh1 = full_meshlink_open("invite_join_conf.1", "foo", "invite-join", DEV_CLASS_BACKBONE); mesh7 = meshlink_open("invite_join_conf.7", "seven", "invite-join", DEV_CLASS_BACKBONE); assert(mesh1); assert(mesh7); - meshlink_enable_discovery(mesh1, false); - meshlink_enable_discovery(mesh7, false); - meshlink_set_node_status_cb(mesh1, status_cb); - assert(meshlink_start(mesh1)); + full_meshlink_enable_discovery(mesh1, false); + full_meshlink_set_node_status_cb(mesh1, status_cb); + assert(full_meshlink_start(mesh1)); assert(meshlink_start(mesh7)); assert(wait_sync_flag(&seven_reachable, 5)); meshlink_stop(mesh7); @@ -371,24 +331,23 @@ int main(void) { meshlink_handle_t *mesh8 = meshlink_open("invite_join_conf.8", "eight", "invite-join", DEV_CLASS_BACKBONE); assert(mesh8); - meshlink_enable_discovery(mesh8, false); - char *eight_url = meshlink_invite(mesh1, NULL, "eight"); + char *eight_url = full_meshlink_invite(mesh1, NULL, "eight"); assert(eight_url); - meshlink_set_inviter_commits_first(mesh1, true); + full_meshlink_set_inviter_commits_first(mesh1, true); meshlink_set_inviter_commits_first(mesh8, false); assert(!meshlink_join(mesh8, eight_url)); free(eight_url); - eight_url = meshlink_invite(mesh1, NULL, "eight"); - meshlink_set_inviter_commits_first(mesh1, false); + eight_url = full_meshlink_invite(mesh1, NULL, "eight"); + full_meshlink_set_inviter_commits_first(mesh1, false); meshlink_set_inviter_commits_first(mesh8, true); assert(!meshlink_join(mesh8, eight_url)); free(eight_url); // Test case #5: test invitee committing first scenario - eight_url = meshlink_invite(mesh1, NULL, "eight"); - meshlink_set_inviter_commits_first(mesh1, false); + eight_url = full_meshlink_invite(mesh1, NULL, "eight"); + full_meshlink_set_inviter_commits_first(mesh1, false); meshlink_set_inviter_commits_first(mesh8, false); devtool_set_inviter_commits_first = invitee_commits_first_cb; assert(meshlink_join(mesh8, eight_url)); @@ -399,11 +358,10 @@ int main(void) { meshlink_handle_t *mesh9 = meshlink_open("invite_join_conf.9", "nine", "invite-join", DEV_CLASS_BACKBONE); assert(mesh9); - meshlink_enable_discovery(mesh9, false); - char *nine_url = meshlink_invite(mesh1, NULL, "nine"); - meshlink_set_inviter_commits_first(mesh1, true); + char *nine_url = full_meshlink_invite(mesh1, NULL, "nine"); + full_meshlink_set_inviter_commits_first(mesh1, true); meshlink_set_inviter_commits_first(mesh9, true); - devtool_set_inviter_commits_first = inviter_commits_first_cb; + *full_devtool_set_inviter_commits_first = inviter_commits_first_cb; reset_sync_flag(&commits_first_flag); assert(meshlink_join(mesh9, nine_url)); free(nine_url); @@ -419,5 +377,5 @@ int main(void) { meshlink_close(mesh4); meshlink_close(mesh3); meshlink_close(mesh2); - meshlink_close(mesh1); + full_meshlink_close(mesh1); } diff --git a/test/storage-policy.c b/test/storage-policy.c index 6885406..6db52da 100644 --- a/test/storage-policy.c +++ b/test/storage-policy.c @@ -7,10 +7,14 @@ #include #include +#include "full.h" #include "meshlink-tiny.h" #include "utils.h" int main(void) { + init_full(); + + full_meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); meshlink_handle_t *mesh1; @@ -18,53 +22,53 @@ int main(void) { // Open two instances - assert(meshlink_destroy("storage-policy_conf.1")); + assert(full_meshlink_destroy("storage-policy_conf.1")); assert(meshlink_destroy("storage-policy_conf.2")); - mesh1 = meshlink_open("storage-policy_conf.1", "foo", "storage-policy", DEV_CLASS_BACKBONE); + mesh1 = full_meshlink_open("storage-policy_conf.1", "foo", "storage-policy", DEV_CLASS_BACKBONE); mesh2 = meshlink_open("storage-policy_conf.2", "bar", "storage-policy", DEV_CLASS_BACKBONE); assert(mesh1); assert(mesh2); - meshlink_set_storage_policy(mesh1, MESHLINK_STORAGE_DISABLED); + full_meshlink_set_storage_policy(mesh1, MESHLINK_STORAGE_DISABLED); meshlink_set_storage_policy(mesh2, MESHLINK_STORAGE_DISABLED); // Exchange data - char *export1 = meshlink_export(mesh1); + char *export1 = full_meshlink_export(mesh1); char *export2 = meshlink_export(mesh2); assert(export1); assert(export2); - assert(meshlink_import(mesh1, export2)); + assert(full_meshlink_import(mesh1, export2)); assert(meshlink_import(mesh2, export1)); // Check that they know each other - assert(meshlink_get_node(mesh1, "bar")); + assert(full_meshlink_get_node(mesh1, "bar")); assert(meshlink_get_node(mesh2, "foo")); - start_meshlink_pair(mesh1, mesh2); + start_full_tiny_pair(mesh1, mesh2); // Close the instances and reopen them. - close_meshlink_pair(mesh1, mesh2); + close_full_tiny_pair(mesh1, mesh2); - mesh1 = meshlink_open("storage-policy_conf.1", "foo", "storage-policy", DEV_CLASS_BACKBONE); + mesh1 = full_meshlink_open("storage-policy_conf.1", "foo", "storage-policy", DEV_CLASS_BACKBONE); mesh2 = meshlink_open("storage-policy_conf.2", "bar", "storage-policy", DEV_CLASS_BACKBONE); assert(mesh1); assert(mesh2); - meshlink_set_storage_policy(mesh1, MESHLINK_STORAGE_KEYS_ONLY); + full_meshlink_set_storage_policy(mesh1, MESHLINK_STORAGE_KEYS_ONLY); meshlink_set_storage_policy(mesh2, MESHLINK_STORAGE_KEYS_ONLY); // Check that the nodes no longer know each other - assert(!meshlink_get_node(mesh1, "bar")); + assert(!full_meshlink_get_node(mesh1, "bar")); assert(!meshlink_get_node(mesh2, "foo")); // Exchange data again - assert(meshlink_import(mesh1, export2)); + assert(full_meshlink_import(mesh1, export2)); assert(meshlink_import(mesh2, export1)); free(export1); @@ -72,89 +76,52 @@ int main(void) { // Close the instances and reopen them. - close_meshlink_pair(mesh1, mesh2); + close_full_tiny_pair(mesh1, mesh2); - mesh1 = meshlink_open("storage-policy_conf.1", "foo", "storage-policy", DEV_CLASS_BACKBONE); + mesh1 = full_meshlink_open("storage-policy_conf.1", "foo", "storage-policy", DEV_CLASS_BACKBONE); mesh2 = meshlink_open("storage-policy_conf.2", "bar", "storage-policy", DEV_CLASS_BACKBONE); assert(mesh1); assert(mesh2); - meshlink_set_storage_policy(mesh1, MESHLINK_STORAGE_KEYS_ONLY); + full_meshlink_set_storage_policy(mesh1, MESHLINK_STORAGE_KEYS_ONLY); meshlink_set_storage_policy(mesh2, MESHLINK_STORAGE_KEYS_ONLY); // Check that the nodes know each other - assert(meshlink_get_node(mesh1, "bar")); - assert(meshlink_get_node(mesh2, "foo")); - - // Check that we update reachability - - time_t last_reachable; - time_t last_unreachable; - assert(!meshlink_get_node_reachability(mesh1, meshlink_get_node(mesh1, "bar"), &last_reachable, &last_unreachable)); - assert(!last_reachable); - assert(!last_unreachable); - - start_meshlink_pair(mesh1, mesh2); - stop_meshlink_pair(mesh1, mesh2); - - assert(!meshlink_get_node_reachability(mesh1, meshlink_get_node(mesh1, "bar"), &last_reachable, &last_unreachable)); - assert(last_reachable); - assert(last_unreachable); - - // But have not stored it - - close_meshlink_pair(mesh1, mesh2); - - mesh1 = meshlink_open("storage-policy_conf.1", "foo", "storage-policy", DEV_CLASS_BACKBONE); - mesh2 = meshlink_open("storage-policy_conf.2", "bar", "storage-policy", DEV_CLASS_BACKBONE); - assert(mesh1); - assert(mesh2); - meshlink_set_storage_policy(mesh1, MESHLINK_STORAGE_KEYS_ONLY); - meshlink_set_storage_policy(mesh2, MESHLINK_STORAGE_KEYS_ONLY); - - assert(meshlink_get_node(mesh1, "bar")); + assert(full_meshlink_get_node(mesh1, "bar")); assert(meshlink_get_node(mesh2, "foo")); - assert(!meshlink_get_node_reachability(mesh1, meshlink_get_node(mesh1, "bar"), &last_reachable, &last_unreachable)); - assert(!last_reachable); - assert(!last_unreachable); - // Check that if we change back to STORAGE_ENABLED right before closing, pending changes are still saved - start_meshlink_pair(mesh1, mesh2); - stop_meshlink_pair(mesh1, mesh2); + start_full_tiny_pair(mesh1, mesh2); + stop_full_tiny_pair(mesh1, mesh2); - meshlink_set_storage_policy(mesh1, MESHLINK_STORAGE_ENABLED); + full_meshlink_set_storage_policy(mesh1, MESHLINK_STORAGE_ENABLED); meshlink_set_storage_policy(mesh2, MESHLINK_STORAGE_ENABLED); - close_meshlink_pair(mesh1, mesh2); + close_full_tiny_pair(mesh1, mesh2); - mesh1 = meshlink_open("storage-policy_conf.1", "foo", "storage-policy", DEV_CLASS_BACKBONE); + mesh1 = full_meshlink_open("storage-policy_conf.1", "foo", "storage-policy", DEV_CLASS_BACKBONE); mesh2 = meshlink_open("storage-policy_conf.2", "bar", "storage-policy", DEV_CLASS_BACKBONE); assert(mesh1); assert(mesh2); - assert(!meshlink_get_node_reachability(mesh1, meshlink_get_node(mesh1, "bar"), &last_reachable, &last_unreachable)); - assert(last_reachable); - assert(last_unreachable); - // Close the instances and reopen them. - close_meshlink_pair(mesh1, mesh2); + close_full_tiny_pair(mesh1, mesh2); - mesh1 = meshlink_open("storage-policy_conf.1", "foo", "storage-policy", DEV_CLASS_BACKBONE); + mesh1 = full_meshlink_open("storage-policy_conf.1", "foo", "storage-policy", DEV_CLASS_BACKBONE); mesh2 = meshlink_open("storage-policy_conf.2", "bar", "storage-policy", DEV_CLASS_BACKBONE); assert(mesh1); assert(mesh2); - meshlink_set_storage_policy(mesh1, MESHLINK_STORAGE_KEYS_ONLY); + full_meshlink_set_storage_policy(mesh1, MESHLINK_STORAGE_KEYS_ONLY); meshlink_set_storage_policy(mesh2, MESHLINK_STORAGE_KEYS_ONLY); // Check that the nodes know each other - assert(meshlink_get_node(mesh1, "bar")); + assert(full_meshlink_get_node(mesh1, "bar")); assert(meshlink_get_node(mesh2, "foo")); // Done. - close_meshlink_pair(mesh1, mesh2); + close_full_tiny_pair(mesh1, mesh2); } diff --git a/test/utils.c b/test/utils.c index 27582ad..322aa87 100644 --- a/test/utils.c +++ b/test/utils.c @@ -11,6 +11,7 @@ #include #include +#include "full.h" #include "utils.h" void init_sync_flag(struct sync_flag *s) { @@ -148,16 +149,42 @@ void start_meshlink_pair(meshlink_handle_t *a, meshlink_handle_t *b) { a->priv = NULL; } +void start_full_tiny_pair(meshlink_handle_t *a, meshlink_handle_t *b) { + struct sync_flag pair_status = {.flag = false}; + init_sync_flag(&pair_status); + + a->priv = &pair_status; + full_meshlink_set_node_status_cb(a, pair_status_cb); + + assert(full_meshlink_start(a)); + assert(meshlink_start(b)); + + assert(wait_sync_flag(&pair_status, 5)); + + full_meshlink_set_node_status_cb(a, NULL); + a->priv = NULL; +} + void stop_meshlink_pair(meshlink_handle_t *a, meshlink_handle_t *b) { meshlink_stop(a); meshlink_stop(b); } +void stop_full_tiny_pair(meshlink_handle_t *a, meshlink_handle_t *b) { + full_meshlink_stop(a); + meshlink_stop(b); +} + void close_meshlink_pair(meshlink_handle_t *a, meshlink_handle_t *b) { meshlink_close(a); meshlink_close(b); } +void close_full_tiny_pair(meshlink_handle_t *a, meshlink_handle_t *b) { + full_meshlink_close(a); + meshlink_close(b); +} + void log_cb(meshlink_handle_t *mesh, meshlink_log_level_t level, const char *text) { static const char *levelstr[] = { [MESHLINK_DEBUG] = "DEBUG", diff --git a/test/utils.h b/test/utils.h index ecc1f2a..d893ee4 100644 --- a/test/utils.h +++ b/test/utils.h @@ -26,12 +26,15 @@ extern void open_meshlink_pair_ephemeral(meshlink_handle_t **a, meshlink_handle_ /// Start a pair of meshlink instances and wait for them to connect together. extern void start_meshlink_pair(meshlink_handle_t *a, meshlink_handle_t *b); +extern void start_full_tiny_pair(meshlink_handle_t *a, meshlink_handle_t *b); /// Stop a pair of meshlink instances. extern void stop_meshlink_pair(meshlink_handle_t *a, meshlink_handle_t *b); +extern void stop_full_tiny_pair(meshlink_handle_t *a, meshlink_handle_t *b); /// Stop and cleanup a pair of meshlink instances. extern void close_meshlink_pair(meshlink_handle_t *a, meshlink_handle_t *b); +extern void close_full_tiny_pair(meshlink_handle_t *a, meshlink_handle_t *b); /// Link two meshlink instances. extern void link_meshlink_pair(meshlink_handle_t *a, meshlink_handle_t *b); -- 2.39.5