From: Lakshminarayana Gurram <38289425+lakshminarayanagurram@users.noreply.github.com> Date: Tue, 23 Apr 2019 04:20:09 +0000 (+0530) Subject: Add meshlink_get_submesh API X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=1d7554c7b8c632adf86492be9dc7afecb49bca5d;p=meshlink Add meshlink_get_submesh API * Add meshlink_get_submesh API * Modify submesh test vector to test meshlink_get_submesh API --- diff --git a/src/meshlink++.h b/src/meshlink++.h index ac72f3cc..8f4a9b00 100644 --- a/src/meshlink++.h +++ b/src/meshlink++.h @@ -327,6 +327,18 @@ public: return (node *)meshlink_get_node(handle, name); } + /// Get a handle for a specific submesh. + /** This function returns a handle for the submesh with the given name. + * + * @param name The name of the submesh for which a handle is requested. + * + * @return A pointer to a meshlink::submesh which represents the requested submesh, + * or NULL if the requested submesh does not exist. + */ + submesh *get_submesh(const char *name) { + return (submesh *)meshlink_get_submesh(handle, name); + } + /// Get a handle for our own node. /** This function returns a handle for the local node. * diff --git a/src/meshlink.c b/src/meshlink.c index 8ec20784..cd23771a 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -1852,6 +1852,20 @@ meshlink_node_t *meshlink_get_node(meshlink_handle_t *mesh, const char *name) { return node; } +meshlink_submesh_t *meshlink_get_submesh(meshlink_handle_t *mesh, const char *name) { + if(!mesh || !name) { + meshlink_errno = MESHLINK_EINVAL; + return NULL; + } + + meshlink_submesh_t *submesh = NULL; + + pthread_mutex_lock(&(mesh->mesh_mutex)); + submesh = (meshlink_submesh_t *)lookup_submesh(mesh, name); + pthread_mutex_unlock(&(mesh->mesh_mutex)); + return submesh; +} + meshlink_node_t **meshlink_get_all_nodes(meshlink_handle_t *mesh, meshlink_node_t **nodes, size_t *nmemb) { if(!mesh || !nmemb || (*nmemb && !nodes)) { meshlink_errno = MESHLINK_EINVAL; diff --git a/src/meshlink.h b/src/meshlink.h index 43d269ce..a672118b 100644 --- a/src/meshlink.h +++ b/src/meshlink.h @@ -441,6 +441,19 @@ extern meshlink_node_t *meshlink_get_self(meshlink_handle_t *mesh); */ extern meshlink_node_t *meshlink_get_node(meshlink_handle_t *mesh, const char *name); +/// Get a handle for a specific submesh. +/** This function returns a handle for the submesh with the given name. + * + * @param mesh A handle which represents an instance of MeshLink. + * @param name The name of the submesh for which a handle is requested. + * After this function returns, the application is free to overwrite or free @a name @a. + * + * @return A pointer to a meshlink_submesh_t which represents the requested submesh, + * or NULL if the requested submesh does not exist. + * The pointer is guaranteed to be valid until meshlink_close() is called. + */ +extern meshlink_submesh_t *meshlink_get_submesh(meshlink_handle_t *mesh, const char *name); + /// Get the fingerprint of a node's public key. /** This function returns a fingerprint of the node's public key. * It should be treated as an opaque blob. diff --git a/test/blackbox/common/containers.h b/test/blackbox/common/containers.h index 8a54e6a3..c807bbff 100644 --- a/test/blackbox/common/containers.h +++ b/test/blackbox/common/containers.h @@ -49,6 +49,7 @@ extern void setup_containers(void **state); extern void destroy_containers(void); extern void restart_all_containers(void); extern char *invite_in_container(const char *inviter, const char *invitee); +extern char *submesh_invite_in_container(const char *inviter, const char *invitee, const char *submesh); extern void node_sim_in_container(const char *node, const char *device_class, const char *invite_url); extern void node_sim_in_container_event(const char *node, const char *device_class, const char *invite_url, const char *clientId, const char *import); diff --git a/test/blackbox/run_blackbox_tests/run_blackbox_tests.c b/test/blackbox/run_blackbox_tests/run_blackbox_tests.c index edf0f95d..29c662bb 100644 --- a/test/blackbox/run_blackbox_tests/run_blackbox_tests.c +++ b/test/blackbox/run_blackbox_tests/run_blackbox_tests.c @@ -134,13 +134,14 @@ int main(int argc, char *argv[]) { failed_tests += test_meshlink_channel_close(); failed_tests += test_meshlink_channel_conn(); + */ failed_tests += test_optimal_pmtu(); failed_tests += test_cases_submesh01(); failed_tests += test_cases_submesh02(); failed_tests += test_cases_submesh03(); failed_tests += test_cases_submesh04(); - */ + failed_tests += test_meshlink_autoconnect(); failed_tests += test_optimal_pmtu(); diff --git a/test/blackbox/run_blackbox_tests/test_cases_submesh01.c b/test/blackbox/run_blackbox_tests/test_cases_submesh01.c index 00f41525..c9854a12 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_submesh01.c +++ b/test/blackbox/run_blackbox_tests/test_cases_submesh01.c @@ -113,7 +113,7 @@ static bool event_cb(mesh_event_payload_t payload) { assert(change_state(&node_status[payload.client_id], payload.mesh_event)); if(payload.mesh_event == NODE_JOINED) { - signal_node_start(node_status, 1, 5, node_ids); + signal_node_start(node_status, 1, 5, (char **)node_ids); } if(check_nodes_finished(node_status, 6)) { @@ -188,4 +188,4 @@ int test_cases_submesh01(void) { total_tests += sizeof(blackbox_group0_tests) / sizeof(blackbox_group0_tests[0]); return cmocka_run_group_tests(blackbox_group0_tests, black_box_group0_setup, black_box_group0_teardown); -} \ No newline at end of file +} diff --git a/test/blackbox/run_blackbox_tests/test_cases_submesh02.c b/test/blackbox/run_blackbox_tests/test_cases_submesh02.c index 13c87d0d..da475749 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_submesh02.c +++ b/test/blackbox/run_blackbox_tests/test_cases_submesh02.c @@ -113,7 +113,7 @@ static bool event_cb(mesh_event_payload_t payload) { assert(change_state(&node_status[payload.client_id], payload.mesh_event)); if(payload.mesh_event == NODE_JOINED) { - signal_node_start(node_status, 1, 5, node_ids); + signal_node_start(node_status, 1, 5, (char **)node_ids); } if(check_nodes_finished(node_status, 6)) { @@ -191,4 +191,4 @@ int test_cases_submesh02(void) { total_tests += sizeof(blackbox_group0_tests) / sizeof(blackbox_group0_tests[0]); return cmocka_run_group_tests(blackbox_group0_tests, black_box_group0_setup, black_box_group0_teardown); -} \ No newline at end of file +} diff --git a/test/blackbox/run_blackbox_tests/test_cases_submesh03.c b/test/blackbox/run_blackbox_tests/test_cases_submesh03.c index 76b6ef9e..1f51479f 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_submesh03.c +++ b/test/blackbox/run_blackbox_tests/test_cases_submesh03.c @@ -113,7 +113,7 @@ static bool event_cb(mesh_event_payload_t payload) { assert(change_state(&node_status[payload.client_id], payload.mesh_event)); if(payload.mesh_event == NODE_JOINED) { - signal_node_start(node_status, 1, 2, node_ids); + signal_node_start(node_status, 1, 2, (char **)node_ids); } if(check_nodes_finished(node_status, 3)) { @@ -186,4 +186,4 @@ int test_cases_submesh03(void) { total_tests += sizeof(blackbox_group0_tests) / sizeof(blackbox_group0_tests[0]); return cmocka_run_group_tests(blackbox_group0_tests, black_box_group0_setup, black_box_group0_teardown); -} \ No newline at end of file +} diff --git a/test/blackbox/run_blackbox_tests/test_cases_submesh04.c b/test/blackbox/run_blackbox_tests/test_cases_submesh04.c index 96c117a5..1f37071b 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_submesh04.c +++ b/test/blackbox/run_blackbox_tests/test_cases_submesh04.c @@ -97,7 +97,7 @@ static bool event_cb(mesh_event_payload_t payload) { assert(change_state(&node_status[payload.client_id], payload.mesh_event)); if(payload.mesh_event == NODE_JOINED) { - signal_node_start(node_status, 1, 2, node_ids); + signal_node_start(node_status, 1, 2, (char **)node_ids); } if(check_nodes_finished(node_status, 3)) { @@ -165,4 +165,4 @@ int test_cases_submesh04(void) { total_tests += sizeof(blackbox_group0_tests) / sizeof(blackbox_group0_tests[0]); return cmocka_run_group_tests(blackbox_group0_tests, black_box_group0_setup, black_box_group0_teardown); -} \ No newline at end of file +} diff --git a/test/blackbox/test_cases_submesh02/node_sim_app1node2.c b/test/blackbox/test_cases_submesh02/node_sim_app1node2.c index 3656b299..77aa8b37 100644 --- a/test/blackbox/test_cases_submesh02/node_sim_app1node2.c +++ b/test/blackbox/test_cases_submesh02/node_sim_app1node2.c @@ -154,6 +154,7 @@ int main(int argc, char *argv[]) { meshlink_channel_t *channel = NULL; meshlink_node_t *core_node = NULL; meshlink_node_t **node_handles = NULL; + meshlink_submesh_t *submesh = NULL; fprintf(stderr, "\tMesh node 'app1node2' starting up........\n"); @@ -241,7 +242,7 @@ int main(int argc, char *argv[]) { meshlink_node_t *node = meshlink_get_self(mesh); assert(node); - meshlink_submesh_t *submesh = meshlink_get_node_submesh(mesh, node); + submesh = meshlink_get_node_submesh(mesh, node); assert(submesh); node_handles = meshlink_get_all_nodes_by_submesh(mesh, submesh, node_handles, &num_nodes); @@ -257,6 +258,20 @@ int main(int argc, char *argv[]) { } } + submesh = meshlink_get_submesh(mesh, "app1"); + + if(submesh == NULL) { + fprintf(stderr, "\tapp1node2 Got invalid submesh handle\n"); + send_event(ERR_NETWORK); + } + + submesh = meshlink_get_submesh(mesh, "app2"); + + if(submesh != NULL) { + fprintf(stderr, "\tapp1node2 Submesh handle should be NULL\n"); + send_event(ERR_NETWORK); + } + send_event(MESH_EVENT_COMPLETED); // All test steps executed - wait for signals to stop/start or close the mesh @@ -268,4 +283,4 @@ int main(int argc, char *argv[]) { meshlink_close(mesh); return EXIT_SUCCESS; -} \ No newline at end of file +} diff --git a/test/blackbox/test_cases_submesh02/node_sim_app2node2.c b/test/blackbox/test_cases_submesh02/node_sim_app2node2.c index b87a4848..b480f6a0 100644 --- a/test/blackbox/test_cases_submesh02/node_sim_app2node2.c +++ b/test/blackbox/test_cases_submesh02/node_sim_app2node2.c @@ -154,6 +154,7 @@ int main(int argc, char *argv[]) { meshlink_channel_t *channel = NULL; meshlink_node_t *core_node = NULL; meshlink_node_t **node_handles = NULL; + meshlink_submesh_t *submesh = NULL; fprintf(stderr, "\tMesh node 'app2node2' starting up........\n"); @@ -244,7 +245,7 @@ int main(int argc, char *argv[]) { meshlink_node_t *node = meshlink_get_self(mesh); assert(node); - meshlink_submesh_t *submesh = meshlink_get_node_submesh(mesh, node); + submesh = meshlink_get_node_submesh(mesh, node); assert(submesh); node_handles = meshlink_get_all_nodes_by_submesh(mesh, submesh, node_handles, &num_nodes); @@ -260,6 +261,20 @@ int main(int argc, char *argv[]) { } } + submesh = meshlink_get_submesh(mesh, "app2"); + + if(submesh == NULL) { + fprintf(stderr, "\tapp2node2 Got invalid submesh handle\n"); + send_event(ERR_NETWORK); + } + + submesh = meshlink_get_submesh(mesh, "app1"); + + if(submesh != NULL) { + fprintf(stderr, "\tapp2node2 Submesh handle should be NULL\n"); + send_event(ERR_NETWORK); + } + send_event(MESH_EVENT_COMPLETED); // All test steps executed - wait for signals to stop/start or close the mesh @@ -271,4 +286,4 @@ int main(int argc, char *argv[]) { meshlink_close(mesh); return EXIT_SUCCESS; -} \ No newline at end of file +}