]> git.meshlink.io Git - meshlink/blobdiff - src/net_setup.c
Add a #define for the maximum number of tracked recently seen addresses.
[meshlink] / src / net_setup.c
index 559f0496579ba38540c01635416160ca60c2d2a8..ec16b400873f15742ac2e998b287797771ad4c87 100644 (file)
@@ -100,7 +100,7 @@ bool node_read_public_key(meshlink_handle_t *mesh, node_t *n) {
        // Append any known addresses in the config file to the list we currently have
        uint32_t known_count = 0;
 
-       for(uint32_t i = 0; i < 5; i++) {
+       for(uint32_t i = 0; i < MAX_RECENT; i++) {
                if(n->recent[i].sa.sa_family) {
                        known_count++;
                }
@@ -108,12 +108,14 @@ bool node_read_public_key(meshlink_handle_t *mesh, node_t *n) {
 
        uint32_t count = packmsg_get_array(&in);
 
-       if(count > 5 - known_count) {
-               count = 5 - known_count;
+       for(uint32_t i = 0; i < count; i++) {
+               if(i < MAX_RECENT - known_count) {
+                       n->recent[i + known_count] = packmsg_get_sockaddr(&in);
+               } else {
+                       packmsg_skip_element(&in);
+               }
        }
 
-       for(uint32_t i = 0; i < count; i++) {
-               n->recent[i + known_count] = packmsg_get_sockaddr(&in);
        }
 
        config_free(&config);
@@ -182,12 +184,12 @@ bool node_read_from_config(meshlink_handle_t *mesh, node_t *n, const config_t *c
        n->canonical_address = packmsg_get_str_dup(&in);
        uint32_t count = packmsg_get_array(&in);
 
-       if(count > 5) {
-               count = 5;
-       }
-
        for(uint32_t i = 0; i < count; i++) {
-               n->recent[i] = packmsg_get_sockaddr(&in);
+               if(i < MAX_RECENT) {
+                       n->recent[i] = packmsg_get_sockaddr(&in);
+               } else {
+                       packmsg_skip_element(&in);
+               }
        }
 
        return packmsg_done(&in);
@@ -217,7 +219,7 @@ bool node_write_config(meshlink_handle_t *mesh, node_t *n) {
 
        uint32_t count = 0;
 
-       for(uint32_t i = 0; i < 5; i++) {
+       for(uint32_t i = 0; i < MAX_RECENT; i++) {
                if(n->recent[i].sa.sa_family) {
                        count++;
                } else {