]> git.meshlink.io Git - meshlink/blobdiff - examples/manynodes.c
Merge branch 'discovery' of chicago.everbase.net:meshlink/meshlink into everbase
[meshlink] / examples / manynodes.c
index 991d5ba65868622a36b68900f15c0bb20f1d74fb..fa583f606a960b3ec71eb149b19c56ef9095b68c 100644 (file)
@@ -8,12 +8,33 @@
 
 #include "../src/meshlink.h"
 
-static int n = 100;
+static int n = 10;
 static meshlink_handle_t **mesh;
 
 static meshlink_node_t **nodes;
 static size_t nnodes;
 
+//Test mesh sending data
+static void testmesh () {
+
+       for(int nindex = 0; nindex < n; nindex++) {
+
+                       nodes = meshlink_get_all_nodes(mesh[nindex], nodes, &nnodes);
+                       if(!nodes) {
+                               fprintf(stderr, "Could not get list of nodes: %s\n", meshlink_strerror(meshlink_errno));
+                       } else {
+                               printf("%zu known nodes:", nnodes);
+                               for(int i = 0; i < nnodes; i++) {
+                                       printf(" %s", 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));
+       }
+       }
+
+                       }
+
+       }
+}
 // Make all nodes know about each other by importing each others public keys and addresses.
 static void linkmesh() {
        for(int i = 0; i < n; i++) {
@@ -94,11 +115,13 @@ static void parse_command(char *buf) {
                        if(!node) {
                                fprintf(stderr, "Unknown node '%s'\n", arg);
                        } else {
-                               printf("Node %s found\n", arg);
+                               printf("Node %s found, pmtu %zd\n", arg, meshlink_get_pmtu(mesh[0], node));
                        }
                }
        } else if(!strcasecmp(buf, "link")) {
                linkmesh();
+       } else if(!strcasecmp(buf, "test")) {
+               testmesh();
        } else if(!strcasecmp(buf, "quit")) {
                printf("Bye!\n");
                fclose(stdin);
@@ -111,6 +134,7 @@ static void parse_command(char *buf) {
                        "/kick <name>          Blacklist the given node.\n"
                        "/who [<name>]         List all nodes or show information about the given node.\n"
                        "/link                 Link all nodes together.\n"
+                       "/test                 Test functionality sending some data to all nodes\n"
                        "/quit                 Exit this program.\n"
                        );
        } else {