+bool node_write_config(meshlink_handle_t *mesh, node_t *n) {
+ uint8_t buf[4096];
+ packmsg_output_t out = {buf, sizeof(buf)};
+
+ packmsg_add_uint32(&out, MESHLINK_CONFIG_VERSION);
+ packmsg_add_str(&out, n->name);
+ packmsg_add_str(&out, n->submesh ? n->submesh->name : CORE_MESH);
+ packmsg_add_int32(&out, n->devclass);
+ assert(n->devclass != 3);
+ packmsg_add_bool(&out, n->status.blacklisted);
+
+ if(ecdsa_active(n->ecdsa)) {
+ packmsg_add_bin(&out, ecdsa_get_public_key(n->ecdsa), 32);
+ } else {
+ packmsg_add_bin(&out, "", 0);
+ }
+
+ packmsg_add_str(&out, n->canonical_address ? n->canonical_address : "");
+
+ uint32_t count = 0;
+
+ for(uint32_t i = 0; i < 5; i++) {
+ if(n->recent[i].sa.sa_family) {
+ count++;
+ } else {
+ break;
+ }
+ }
+
+ packmsg_add_array(&out, count);
+
+ for(uint32_t i = 0; i < count; i++) {
+ packmsg_add_sockaddr(&out, &n->recent[i]);
+ }
+
+ if(!packmsg_output_ok(&out)) {
+ return false;
+ }
+
+ config_t config = {buf, packmsg_output_size(&out, buf)};
+ return config_write(mesh, n->name, &config);