+ meshlink_errno = MESHLINK_ESTORAGE;
+ }
+ }
+
+ return mesh->invitation_key;
+}
+
+bool meshlink_add_address(meshlink_handle_t *mesh, const char *address) {
+ if(!mesh || !address) {
+ meshlink_errno = MESHLINK_EINVAL;
+ return false;
+ }
+
+ for(const char *p = address; *p; p++) {
+ if(isalnum(*p) || *p == '-' || *p == '.' || *p == ':')
+ continue;
+ fprintf(stderr, "Invalid character in address: %s\n", address);
+ meshlink_errno = MESHLINK_EINVAL;
+ return false;
+ }
+
+ return append_config_file(mesh, mesh->self->name, "Address", address);
+}
+
+char *meshlink_invite(meshlink_handle_t *mesh, const char *name) {
+ if(!mesh) {
+ meshlink_errno = MESHLINK_EINVAL;
+ return NULL;
+ }
+
+ // Check validity of the new node's name
+ if(!check_id(name)) {
+ fprintf(stderr, "Invalid name for node.\n");
+ meshlink_errno = MESHLINK_EINVAL;
+ return NULL;
+ }
+
+ // Ensure no host configuration file with that name exists
+ char filename[PATH_MAX];
+ snprintf(filename, sizeof filename, "%s" SLASH "hosts" SLASH "%s", mesh->confbase, name);
+ if(!access(filename, F_OK)) {
+ fprintf(stderr, "A host config file for %s already exists!\n", name);
+ meshlink_errno = MESHLINK_EEXIST;
+ return NULL;
+ }
+
+ // Ensure no other nodes know about this name
+ if(meshlink_get_node(mesh, name)) {
+ fprintf(stderr, "A node with name %s is already known!\n", name);
+ meshlink_errno = MESHLINK_EEXIST;
+ return NULL;
+ }
+
+ // Get the local address
+ char *address = get_my_hostname(mesh);
+ if(!address) {
+ fprintf(stderr, "No Address known for ourselves!\n");
+ meshlink_errno = MESHLINK_ERESOLV;
+ return NULL;
+ }
+
+ if(!refresh_invitation_key(mesh)) {
+ meshlink_errno = MESHLINK_EINTERNAL;
+ return NULL;