X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=examples%2Fmanynodes.c;h=d9fb0a41fee1f826458a4a18af3a0d20f24e95d9;hb=fe5563f92021618b4a8b41e412c73d8364fcaf6e;hp=2cfe818033e371bc673b37a35920d5f880674a5c;hpb=668664d0ea90dc81670cccd7b7d56b36b8360eaa;p=meshlink diff --git a/examples/manynodes.c b/examples/manynodes.c index 2cfe8180..d9fb0a41 100644 --- a/examples/manynodes.c +++ b/examples/manynodes.c @@ -53,7 +53,7 @@ static void testmesh() { } else { printf("%zu known nodes:\n", nnodes); - for(int i = 0; i < nnodes; i++) { + for(size_t i = 0; i < nnodes; i++) { //printf(" %s\n", nodes[i]->name); if(!meshlink_send(mesh[nindex], nodes[i], "magic", strlen("magic") + 1)) { fprintf(stderr, "Could not send message to '%s': %s\n", nodes[i]->name, meshlink_strerror(meshlink_errno)); @@ -71,8 +71,11 @@ static void linkmesh() { for(int j = i + 1; j < n; j++) { char *dataj = meshlink_export(mesh[j]); - meshlink_import(mesh[i], dataj); - meshlink_import(mesh[j], datai); + + if(!meshlink_import(mesh[i], dataj) || !meshlink_import(mesh[j], datai)) { + fprintf(stderr, "Could not exchange keys between %s and %s: %s\n", mesh[i]->name, mesh[j]->name, meshlink_strerror(meshlink_errno)); + } + free(dataj); } @@ -115,6 +118,8 @@ static bool exportmeshgraph(const char *path) { void exportmeshgraph_timer(int signum) { + (void)signum; + struct timeval ts; gettimeofday(&ts, NULL); @@ -127,12 +132,12 @@ void exportmeshgraph_timer(int signum) { #ifndef _WIN32 static bool exportmeshgraph_started = false; -static bool exportmeshgraph_end(const char *none) { +static bool exportmeshgraph_end(void) { if(!exportmeshgraph_started) { return false; } - struct itimerval zero_timer = { 0 }; + struct itimerval zero_timer; setitimer(ITIMER_REAL, &zero_timer, NULL); @@ -147,7 +152,7 @@ static bool exportmeshgraph_begin(const char *timeout_str) { } if(exportmeshgraph_started) { - if(!exportmeshgraph_end(NULL)) { + if(!exportmeshgraph_end()) { return false; } } @@ -182,7 +187,7 @@ static bool exportmeshgraph_begin(const char *timeout_str) { return true; } #else -static bool exportmeshgraph_end(const char *none) { +static bool exportmeshgraph_end(void) { return false; } @@ -206,7 +211,7 @@ static void parse_command(char *buf) { return; } - invitation = meshlink_invite(mesh[nodeindex], arg); + invitation = meshlink_invite(mesh[nodeindex], NULL, arg); if(!invitation) { fprintf(stderr, "Could not invite '%s': %s\n", arg, meshlink_strerror(meshlink_errno)); @@ -246,9 +251,31 @@ static void parse_command(char *buf) { return; } - meshlink_blacklist(mesh[nodeindex], node); + if(!meshlink_blacklist(mesh[nodeindex], node)) { + fprintf(stderr, "Error blacklising '%s': %s", arg, meshlink_strerror(meshlink_errno)); + return; + } printf("Node '%s' blacklisted.\n", arg); + } else if(!strcasecmp(buf, "whitelist")) { + if(!arg) { + fprintf(stderr, "/whitelist requires an argument!\n"); + return; + } + + meshlink_node_t *node = meshlink_get_node(mesh[nodeindex], arg); + + if(!node) { + fprintf(stderr, "Error looking up '%s': %s\n", arg, meshlink_strerror(meshlink_errno)); + return; + } + + if(!meshlink_whitelist(mesh[nodeindex], node)) { + fprintf(stderr, "Error whitelising '%s': %s", arg, meshlink_strerror(meshlink_errno)); + return; + } + + printf("Node '%s' whitelisted.\n", arg); } else if(!strcasecmp(buf, "who")) { if(!arg) { nodes = meshlink_get_all_nodes(mesh[nodeindex], nodes, &nnodes); @@ -258,7 +285,7 @@ static void parse_command(char *buf) { } else { printf("%zu known nodes:", nnodes); - for(int i = 0; i < nnodes; i++) { + for(size_t i = 0; i < nnodes; i++) { printf(" %s", nodes[i]->name); } @@ -270,7 +297,7 @@ static void parse_command(char *buf) { if(!node) { fprintf(stderr, "Unknown node '%s'\n", arg); } else { - printf("Node %s found, pmtu %zd\n", arg, meshlink_get_pmtu(mesh[nodeindex], node)); + printf("Node %s found, pmtu %ld\n", arg, (long int)meshlink_get_pmtu(mesh[nodeindex], node)); } } } else if(!strcasecmp(buf, "link")) { @@ -280,7 +307,7 @@ static void parse_command(char *buf) { } else if(!strcasecmp(buf, "egb")) { exportmeshgraph_begin(arg); } else if(!strcasecmp(buf, "ege")) { - exportmeshgraph_end(NULL); + exportmeshgraph_end(); } else if(!strcasecmp(buf, "test")) { testmesh(); } else if(!strcasecmp(buf, "select")) { @@ -345,7 +372,8 @@ static void parse_input(char *buf) { // Commands start with '/' if(*buf == '/') { - return parse_command(buf + 1); + parse_command(buf + 1); + return; } // Lines in the form "name: message..." set the destination node. @@ -465,7 +493,7 @@ int main(int argc, char *argv[]) { parse_input(buf); } - exportmeshgraph_end(NULL); + exportmeshgraph_end(); printf("Nodes stopping.\n");