free(mesh->myport);
xasprintf(&mesh->myport, "%d", port);
- /* Write meshlink.conf with the updated port number */
- write_main_config_files(mesh);
-
/* Close down the network. This also deletes mesh->self. */
close_network_connections(mesh);
rval = true;
}
+ /* Rebuild our own list of recent addresses */
+ memset(mesh->self->recent, 0, sizeof(mesh->self->recent));
+ add_local_addresses(mesh);
+
+ /* Write meshlink.conf with the updated port number */
+ write_main_config_files(mesh);
+
+ if(!config_sync(mesh, "current")) {
+ return false;
+ }
+
done:
pthread_mutex_unlock(&(mesh->mesh_mutex));
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
+#include <assert.h>
#include "meshlink.h"
free(corge_url);
+ // Check that invitations work correctly after changing ports
+
+ meshlink_set_invitation_timeout(mesh1, 86400);
+ meshlink_stop(mesh1);
+ meshlink_stop(mesh3);
+
+ int oldport = meshlink_get_port(mesh1);
+ bool success;
+
+ for(int i = 0; i < 100; i++) {
+ success = meshlink_set_port(mesh1, 0x9000 + rand() % 0x1000);
+ }
+
+ assert(success);
+ int newport = meshlink_get_port(mesh1);
+ assert(oldport != newport);
+
+ assert(meshlink_start(mesh1));
+ quux_url = meshlink_invite(mesh1, NULL, "quux");
+ fprintf(stderr, "Invitation URL for quux: %s\n", quux_url);
+
+ // The old port should not be in the invitation URL
+
+ char portstr[10];
+ snprintf(portstr, sizeof(portstr), ":%d", oldport);
+ assert(!strstr(quux_url, portstr));
+
+ // The new port should be in the invitation URL
+
+ snprintf(portstr, sizeof(portstr), ":%d", newport);
+ assert(strstr(quux_url, portstr));
+
+ // The invitation should work
+
+ assert(meshlink_join(mesh3, quux_url));
+
// Clean up.
meshlink_close(mesh3);