../test_case_optimal_pmtu_01/node_sim_nut.c \
../test_case_optimal_pmtu_01/node_sim_relay.c \
../test_case_optimal_pmtu_01/node_sim_peer.c \
- test_optimal_pmtu.c
+ test_optimal_pmtu.c \
+ ../test_case_channel_blacklist_01/node_sim_nut_01.c \
+ ../test_case_channel_blacklist_01/node_sim_peer_01.c \
+ ../test_case_channel_blacklist_01/node_sim_relay_01.c \
+ test_cases_channel_blacklist.c
run_blackbox_tests_LDADD = ../../../src/libmeshlink.la $(LXC_LIBS) $(CMOCKA_LIBS)
run_blackbox_tests_CFLAGS = -D_GNU_SOURCE $(LXC_CFLAGS) $(CMOCKA_CFLAGS)
--- /dev/null
+/*
+ test_optimal_pmtu.c -- Execution of specific meshlink black box test cases
+ Copyright (C) 2019 Guus Sliepen <guus@meshlink.io>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+#include <stdlib.h>
+#include <stdarg.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include <assert.h>
+#include <pthread.h>
+#include "../common/containers.h"
+#include "../common/test_step.h"
+#include "../common/common_handlers.h"
+#include "../common/network_namespace_framework.h"
+#include "../../utils.h"
+#include "test_cases_channel_blacklist.h"
+#include "../test_case_channel_blacklist_01/node_sim_nut_01.h"
+
+typedef bool (*test_step_func_t)(void);
+extern int total_tests;
+
+static bool test_steps_channel_blacklist_01(void);
+static void test_case_channel_blacklist_01(void **state);
+
+static int setup_test(void **state);
+static int teardown_test(void **state);
+static void *gen_inv(void *arg);
+
+netns_state_t *test_channel_disconnection_state;
+
+static mesh_arg_t relay_arg = {.node_name = "relay", .confbase = "relay", .app_name = "relay", .dev_class = 0 };
+static mesh_arg_t peer_arg = {.node_name = "peer", .confbase = "peer", .app_name = "peer", .dev_class = 1 };
+static mesh_arg_t nut_arg = {.node_name = "nut", .confbase = "nut", .app_name = "nut", .dev_class = 1 };
+static mesh_invite_arg_t relay_nut_invite_arg = {.mesh_arg = &relay_arg, .invitee_name = "nut" };
+static mesh_invite_arg_t relay_peer_invite_arg = {.mesh_arg = &relay_arg, .invitee_name = "peer" };
+static mesh_invite_arg_t peer_nut_invite_arg = {.mesh_arg = &peer_arg, .invitee_name = "nut" };
+static netns_thread_t netns_relay_nut_invite = {.namespace_name = "relay", .netns_thread = gen_inv, .arg = &relay_nut_invite_arg};
+static netns_thread_t netns_relay_peer_invite = {.namespace_name = "relay", .netns_thread = gen_inv, .arg = &relay_peer_invite_arg};
+static netns_thread_t netns_peer_nut_invite = {.namespace_name = "peer", .netns_thread = gen_inv, .arg = &peer_nut_invite_arg};
+static netns_thread_t netns_relay_handle = {.namespace_name = "relay", .netns_thread = test_channel_blacklist_disonnection_relay_01, .arg = &relay_arg};
+static netns_thread_t netns_peer_handle = {.namespace_name = "peer", .netns_thread = test_channel_blacklist_disonnection_peer_01, .arg = &peer_arg};
+static netns_thread_t netns_nut_handle = {.namespace_name = "nut", .netns_thread = test_channel_blacklist_disonnection_nut_01, .arg = &nut_arg};
+
+struct sync_flag test_channel_discon_nut_close = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER};
+
+static int setup_test(void **state) {
+ netns_create_topology(test_channel_disconnection_state);
+ fprintf(stderr, "\nCreated topology\n");
+
+ meshlink_destroy("nut");
+ meshlink_destroy("peer");
+ meshlink_destroy("relay");
+ channel_discon_case_ping = false;
+ channel_discon_network_failure_01 = false;
+ channel_discon_network_failure_02 = false;
+ test_channel_restart_01 = false;
+ set_sync_flag(&test_channel_discon_nut_close, false);
+
+ return EXIT_SUCCESS;
+}
+
+static int teardown_test(void **state) {
+ meshlink_destroy("nut");
+ meshlink_destroy("peer");
+ meshlink_destroy("relay");
+ netns_destroy_topology(test_channel_disconnection_state);
+
+ return EXIT_SUCCESS;
+}
+
+static void execute_test(test_step_func_t step_func, void **state) {
+
+ fprintf(stderr, "\n\x1b[32mRunning Test\x1b[0m\n");
+ bool test_result = step_func();
+
+ if(!test_result) {
+ fail();
+ }
+}
+
+static void *gen_inv(void *arg) {
+ mesh_invite_arg_t *mesh_invite_arg = (mesh_invite_arg_t *)arg;
+ meshlink_handle_t *mesh;
+ mesh = meshlink_open(mesh_invite_arg->mesh_arg->node_name, mesh_invite_arg->mesh_arg->confbase, mesh_invite_arg->mesh_arg->app_name, mesh_invite_arg->mesh_arg->dev_class);
+ assert(mesh);
+
+ char *invitation = meshlink_invite(mesh, NULL, mesh_invite_arg->invitee_name);
+ assert(invitation);
+ mesh_invite_arg->invite_str = invitation;
+ meshlink_close(mesh);
+}
+
+static void launch_3_nodes(void) {
+ run_node_in_namespace_thread(&netns_relay_nut_invite);
+ sleep(1);
+ assert(relay_nut_invite_arg.invite_str);
+ nut_arg.join_invitation = relay_nut_invite_arg.invite_str;
+
+ run_node_in_namespace_thread(&netns_relay_peer_invite);
+ sleep(1);
+ assert(relay_peer_invite_arg.invite_str);
+ peer_arg.join_invitation = relay_peer_invite_arg.invite_str;
+
+ relay_arg.join_invitation = NULL;
+
+ run_node_in_namespace_thread(&netns_relay_handle);
+ sleep(1);
+
+ run_node_in_namespace_thread(&netns_peer_handle);
+ sleep(1);
+
+ run_node_in_namespace_thread(&netns_nut_handle);
+}
+
+static void test_case_channel_blacklist_01(void **state) {
+ execute_test(test_steps_channel_blacklist_01, state);
+ return;
+}
+
+static bool test_steps_channel_blacklist_01(void) {
+
+ launch_3_nodes();
+
+ wait_sync_flag(&test_channel_discon_nut_close, 240);
+
+ test_channel_blacklist_disonnection_peer_01_running = false;
+ test_channel_blacklist_disonnection_relay_01_running = false;
+ assert_int_equal(total_reachable_callbacks_01, 1);
+ assert_int_equal(total_unreachable_callbacks_01, 1);
+ assert_int_equal(total_channel_closure_callbacks_01, 2);
+
+ return true;
+}
+
+int test_meshlink_channel_blacklist(void) {
+
+ interface_t relay_ifs[] = { { .if_peer = "wan_bridge" } };
+ namespace_t relay = {
+ .name = "relay",
+ .type = HOST,
+ .interfaces = relay_ifs,
+ .interfaces_no = 1,
+ };
+
+ interface_t peer_ifs[] = { { .if_peer = "wan_bridge" } };
+ namespace_t peer = {
+ .name = "peer",
+ .type = HOST,
+ .interfaces = peer_ifs,
+ .interfaces_no = 1,
+ };
+
+ interface_t nut_ifs[] = { { .if_peer = "wan_bridge" } };
+ namespace_t nut = {
+ .name = "nut",
+ .type = HOST,
+ .interfaces = nut_ifs,
+ .interfaces_no = 1,
+ };
+
+ interface_t wan_ifs[] = { { .if_peer = "peer" }, { .if_peer = "nut" }, { .if_peer = "relay" } };
+ namespace_t wan_bridge = {
+ .name = "wan_bridge",
+ .type = BRIDGE,
+ .interfaces = wan_ifs,
+ .interfaces_no = 3,
+ };
+
+ namespace_t test_channel_nodes[] = { relay, wan_bridge, nut, peer };
+
+ netns_state_t test_channels_nodes = {
+ .test_case_name = "test_case_channel",
+ .namespaces = test_channel_nodes,
+ .num_namespaces = 4,
+ };
+ test_channel_disconnection_state = &test_channels_nodes;
+
+ const struct CMUnitTest blackbox_group0_tests[] = {
+ cmocka_unit_test_prestate_setup_teardown(test_case_channel_blacklist_01, setup_test, teardown_test,
+ (void *)NULL),
+ };
+ total_tests += sizeof(blackbox_group0_tests) / sizeof(blackbox_group0_tests[0]);
+
+ return cmocka_run_group_tests(blackbox_group0_tests, NULL, NULL);
+}
--- /dev/null
+#ifndef TEST_CASES_CHANNEL_CONN_H
+#define TEST_CASES_CHANNEL_CONN_H
+
+/*
+ test_cases_channel_blacklist.h -- Declarations for Individual Test Case implementation functions
+ Copyright (C) 2018 Guus Sliepen <guus@meshlink.io>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+
+#include <stdbool.h>
+
+extern int test_meshlink_channel_blacklist(void);
+
+extern void *test_channel_blacklist_disonnection_nut_01(void *arg);
+extern void *test_channel_blacklist_disonnection_peer_01(void *arg);
+extern void *test_channel_blacklist_disonnection_relay_01(void *arg);
+
+extern int total_reachable_callbacks_01;
+extern int total_unreachable_callbacks_01;
+extern int total_channel_closure_callbacks_01;
+extern bool channel_discon_case_ping;
+extern bool channel_discon_network_failure_01;
+extern bool channel_discon_network_failure_02;
+extern bool test_channel_blacklist_disonnection_peer_01_running;
+extern bool test_channel_blacklist_disonnection_relay_01_running;
+extern bool test_blacklist_whitelist_01;
+extern bool test_channel_restart_01;
+
+#endif // TEST_CASES_CHANNEL_CONN_H
--- /dev/null
+/*
+ node_sim_nut.c -- Implementation of Node Simulation for Meshlink Testing
+ for channel connections with respective to blacklisting their nodes
+ Copyright (C) 2019 Guus Sliepen <guus@meshlink.io>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <pthread.h>
+#include <assert.h>
+#include <signal.h>
+#include "../common/common_handlers.h"
+#include "../common/test_step.h"
+#include "../common/mesh_event_handler.h"
+#include "../common/network_namespace_framework.h"
+#include "../../utils.h"
+#include "node_sim_nut_01.h"
+
+#define CHANNEL_PORT 1234
+
+static bool blacklist_set;
+int total_reachable_callbacks_01;
+int total_unreachable_callbacks_01;
+int total_channel_closure_callbacks_01;
+bool channel_discon_case_ping;
+bool channel_discon_network_failure_01;
+bool channel_discon_network_failure_02;
+bool test_blacklist_whitelist_01;
+bool test_channel_restart_01;
+
+static struct sync_flag peer_reachable = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER};
+static struct sync_flag peer_unreachable = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER};
+static struct sync_flag channel_opened = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER};
+static struct sync_flag channels_closed = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER};
+
+static void node_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node,
+ bool reachable) {
+
+ fprintf(stderr, "Node %s %s\n", node->name, reachable ? "reachable" : "unreachable");
+
+ if(!strcmp(node->name, "peer")) {
+ if(reachable) {
+ set_sync_flag(&peer_reachable, true);
+
+ if(blacklist_set) {
+ ++total_reachable_callbacks_01;
+ }
+ } else {
+ set_sync_flag(&peer_unreachable, true);
+
+ if(blacklist_set) {
+ ++total_unreachable_callbacks_01;
+ }
+ }
+ }
+
+ return;
+}
+
+static void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) {
+ (void)len;
+ fprintf(stderr, "%s poll cb invoked\n", (char *)channel->priv);
+ meshlink_set_channel_poll_cb(mesh, channel, NULL);
+ assert(meshlink_channel_send(mesh, channel, "test", 5) >= 0);
+ return;
+}
+
+static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) {
+ if(len == 0) {
+ fprintf(stderr, "Closed channel with %s\n", (char *)channel->priv);
+
+ if(blacklist_set) {
+ ++total_channel_closure_callbacks_01;
+ }
+
+ if(total_channel_closure_callbacks_01 == 2) {
+ set_sync_flag(&channels_closed, true);
+ }
+ }
+
+ if(!strcmp(channel->node->name, "peer")) {
+ if(len == 5 && !memcmp(dat, "reply", 5)) {
+ fprintf(stderr, "Channel opened with %s\n", (char *)channel->priv);
+ set_sync_flag(&channel_opened, true);
+ }
+ }
+
+ return;
+}
+
+static void log_message(meshlink_handle_t *mesh, meshlink_log_level_t level, const char *text) {
+ (void)mesh;
+
+ fprintf(stderr, "\x1b[32m nut:\x1b[0m %s\n", text);
+}
+
+void *test_channel_blacklist_disonnection_nut_01(void *arg) {
+ mesh_arg_t *mesh_arg = (mesh_arg_t *)arg;
+ total_reachable_callbacks_01 = 0;
+ total_unreachable_callbacks_01 = 0;
+ total_channel_closure_callbacks_01 = 0;
+
+ set_sync_flag(&peer_reachable, false);
+ set_sync_flag(&peer_unreachable, false);
+ set_sync_flag(&channel_opened, false);
+ blacklist_set = false;
+
+ assert(!channel_discon_network_failure_01 || !channel_discon_network_failure_02);
+
+ // Run relay node instance
+
+ meshlink_handle_t *mesh;
+ mesh = meshlink_open(mesh_arg->node_name, mesh_arg->confbase, mesh_arg->app_name, mesh_arg->dev_class);
+ assert(mesh);
+ meshlink_set_log_cb(mesh, MESHLINK_DEBUG, log_message);
+ meshlink_set_node_status_cb(mesh, node_status_cb);
+
+ // Join relay node and if fails to join then try few more attempts
+
+ if(mesh_arg->join_invitation) {
+ assert(meshlink_join(mesh, mesh_arg->join_invitation));
+ }
+
+ assert(meshlink_start(mesh));
+
+ // Wait for peer node to join
+
+ assert(wait_sync_flag(&peer_reachable, 30));
+
+ meshlink_node_t *peer_node = meshlink_get_node(mesh, "peer");
+ assert(peer_node);
+ meshlink_channel_t *channel1 = meshlink_channel_open(mesh, peer_node, CHANNEL_PORT,
+ channel_receive_cb, NULL, 0);
+ channel1->priv = "channel1";
+ meshlink_set_channel_poll_cb(mesh, channel1, poll_cb);
+
+ assert(wait_sync_flag(&channel_opened, 15));
+
+ set_sync_flag(&channel_opened, false);
+
+ meshlink_channel_t *channel2 = meshlink_channel_open(mesh, peer_node, CHANNEL_PORT,
+ channel_receive_cb, NULL, 0);
+ channel2->priv = "channel2";
+ meshlink_set_channel_poll_cb(mesh, channel2, poll_cb);
+
+ assert(wait_sync_flag(&channel_opened, 15));
+
+ blacklist_set = true;
+
+ if(channel_discon_network_failure_01) {
+ fprintf(stderr, "Simulating network failure before blacklisting\n");
+ assert(system("iptables -A INPUT -m statistic --mode random --probability 0.9 -j DROP") == 0);
+ assert(system("iptables -A OUTPUT -m statistic --mode random --probability 0.9 -j DROP") == 0);
+ sleep(1);
+ }
+
+ fprintf(stderr, "Node blacklisted\n");
+ set_sync_flag(&channels_closed, false);
+ meshlink_blacklist(mesh, peer_node);
+
+ sleep(10);
+
+ if(channel_discon_network_failure_02) {
+ fprintf(stderr, "Simulating network failure after blacklisting\n");
+ assert(system("iptables -A INPUT -m statistic --mode random --probability 0.9 -j DROP") == 0);
+ assert(system("iptables -A OUTPUT -m statistic --mode random --probability 0.9 -j DROP") == 0);
+ sleep(1);
+ }
+
+ if(channel_discon_case_ping) {
+ fprintf(stderr, "Sending data through channels after blacklisting\n");
+ assert(meshlink_channel_send(mesh, channel1, "ping", 5) >= 0);
+ assert(meshlink_channel_send(mesh, channel2, "ping", 5) >= 0);
+ }
+
+ if(wait_sync_flag(&channels_closed, 120) == false) {
+ set_sync_flag(&test_channel_discon_nut_close, true);
+ return NULL;
+ }
+
+ if(channel_discon_network_failure_01 || channel_discon_network_failure_02) {
+ fprintf(stderr, "Simulating network failure after blacklisting\n");
+ assert(system("iptables -D INPUT -m statistic --mode random --probability 0.9 -j DROP") == 0);
+ assert(system("iptables -D OUTPUT -m statistic --mode random --probability 0.9 -j DROP") == 0);
+ }
+
+ set_sync_flag(&peer_reachable, false);
+
+ meshlink_whitelist(mesh, peer_node);
+ fprintf(stderr, "Node whitelisted\n");
+
+ wait_sync_flag(&peer_reachable, 70);
+
+ fprintf(stderr, "Closing NUT instance\n");
+ blacklist_set = false;
+
+ set_sync_flag(&test_channel_discon_nut_close, true);
+
+ meshlink_close(mesh);
+ return NULL;
+}
--- /dev/null
+#ifndef CHANNEL_BLACKLIST_NUT_01_H
+#define CHANNEL_BLACKLIST_NUT_01_H
+
+/*
+ test_case_channel_disconnection.h -- Implementation of Node Simulation for Meshlink Testing
+ Copyright (C) 2019 Guus Sliepen <guus@meshlink.io>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+extern void *test_channel_blacklist_disonnection_peer_01(void *arg);
+extern void *test_channel_blacklist_disonnection_nut_01(void *arg);
+extern void *test_channel_blacklist_disonnection_relay_01(void *arg);
+extern int total_blacklist_callbacks_01;
+extern int total_whitelist_callbacks_01;
+extern struct sync_flag test_channel_discon_nut_close;
+extern bool test_case_signal_peer_restart_01;
+
+#endif
--- /dev/null
+/*
+ node_sim_peer.c -- Implementation of Node Simulation for Meshlink Testing
+ for channel connections with respective to blacklisting their nodes
+ Copyright (C) 2019 Guus Sliepen <guus@meshlink.io>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <pthread.h>
+#include <assert.h>
+#include <signal.h>
+#include "../common/common_handlers.h"
+#include "../common/test_step.h"
+#include "../common/network_namespace_framework.h"
+#include "../../utils.h"
+
+#define CHANNEL_PORT 1234
+
+bool test_channel_blacklist_disonnection_peer_01_running;
+bool test_case_signal_peer_restart_01;
+
+static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len);
+static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len);
+
+static int client_id = -1;
+
+static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len) {
+ (void)dat;
+ (void)len;
+
+ assert(port == CHANNEL_PORT);
+
+ if(!strcmp(channel->node->name, "nut")) {
+ meshlink_set_channel_receive_cb(mesh, channel, channel_receive_cb);
+ return true;
+ }
+
+ return false;
+}
+
+/* channel receive callback */
+static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) {
+
+ if(len == 0) {
+ fprintf(stderr, "Channel closure\n");
+ }
+
+ if(!strcmp(channel->node->name, "nut")) {
+ if(!memcmp(dat, "test", 5)) {
+ assert(meshlink_channel_send(mesh, channel, "reply", 5) >= 0);
+ }
+ }
+
+ return;
+}
+
+void *test_channel_blacklist_disonnection_peer_01(void *arg) {
+ struct timeval main_loop_wait = { 2, 0 };
+ mesh_arg_t *mesh_arg = (mesh_arg_t *)arg;
+ test_channel_blacklist_disonnection_peer_01_running = true;
+
+ // Run relay node instance
+
+ meshlink_handle_t *mesh;
+ mesh = meshlink_open(mesh_arg->node_name, mesh_arg->confbase, mesh_arg->app_name, mesh_arg->dev_class);
+ assert(mesh);
+ meshlink_set_channel_accept_cb(mesh, channel_accept);
+
+ // Join relay node and if fails to join then try few more attempts
+
+ if(mesh_arg->join_invitation) {
+ assert(meshlink_join(mesh, mesh_arg->join_invitation));
+ }
+
+ assert(meshlink_start(mesh));
+
+ // All test steps executed - wait for signals to stop/start or close the mesh
+
+ while(test_channel_blacklist_disonnection_peer_01_running) {
+ select(1, NULL, NULL, NULL, &main_loop_wait);
+
+ if(test_case_signal_peer_restart_01) {
+ meshlink_stop(mesh);
+ assert(meshlink_start(mesh));
+ test_case_signal_peer_restart_01 = false;
+ }
+ }
+
+ meshlink_close(mesh);
+
+ return NULL;
+}
--- /dev/null
+/*
+ node_sim_relay.c -- Implementation of Node Simulation for Meshlink Testing
+ for channel connections with respective to blacklisting their nodes
+ Copyright (C) 2019 Guus Sliepen <guus@meshlink.io>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+#include <stdio.h>
+#include <stdlib.h>
+#include "../common/common_handlers.h"
+#include "../common/test_step.h"
+#include "../common/network_namespace_framework.h"
+
+bool test_channel_blacklist_disonnection_relay_01_running;
+
+void *test_channel_blacklist_disonnection_relay_01(void *arg) {
+ struct timeval main_loop_wait = { 2, 0 };
+ mesh_arg_t *mesh_arg = (mesh_arg_t *)arg;
+ test_channel_blacklist_disonnection_relay_01_running = true;
+
+ // Run relay node instance
+
+ meshlink_handle_t *mesh;
+ mesh = meshlink_open(mesh_arg->node_name, mesh_arg->confbase, mesh_arg->app_name, mesh_arg->dev_class);
+ assert(mesh);
+
+ meshlink_start(mesh);
+
+ /* All test steps executed - wait for signals to stop/start or close the mesh */
+ while(test_channel_blacklist_disonnection_relay_01_running) {
+ select(1, NULL, NULL, NULL, &main_loop_wait);
+ }
+
+ meshlink_close(mesh);
+
+ return NULL;
+}