]> git.meshlink.io Git - meshlink-tiny/blobdiff - src/net_setup.c
Use a key/value store with configurable storage callbacks.
[meshlink-tiny] / src / net_setup.c
index 7f8804b17be524cdfcc5d8d3abc9ad7cee20677b..8364e4f238090f94b8a10266919ee35698480e13 100644 (file)
@@ -33,7 +33,7 @@
 
 /// Helper function to start parsing a host config file
 static bool node_get_config(meshlink_handle_t *mesh, node_t *n, config_t *config, packmsg_input_t *in) {
-       if(!config_read(mesh, "current", n->name, config, mesh->config_key)) {
+       if(!config_load(mesh, n->name, config)) {
                return false;
        }
 
@@ -260,7 +260,7 @@ bool node_write_config(meshlink_handle_t *mesh, node_t *n, bool new_key) {
 
        config_t config = {buf, packmsg_output_size(&out, buf)};
 
-       if(!config_write(mesh, "current", n->name, &config, mesh->config_key)) {
+       if(!config_store(mesh, n->name, &config)) {
                call_error_cb(mesh, MESHLINK_ESTORAGE);
                return false;
        }
@@ -269,19 +269,11 @@ bool node_write_config(meshlink_handle_t *mesh, node_t *n, bool new_key) {
        return true;
 }
 
-static bool load_node(meshlink_handle_t *mesh, const char *name, void *priv) {
-       (void)priv;
+static bool load_node(meshlink_handle_t *mesh, const char *name, size_t len) {
+       (void)len;
 
        if(!check_id(name)) {
-               // Check if this is a temporary file, if so remove it
-               const char *suffix = strstr(name, ".tmp");
-
-               if(suffix && !suffix[4]) {
-                       char filename[PATH_MAX];
-                       snprintf(filename, sizeof(filename), "%s" SLASH "current" SLASH "hosts", mesh->confbase);
-                       unlink(filename);
-               }
-
+               // TODO: detect partial key rotation
                return true;
        }
 
@@ -324,7 +316,7 @@ static bool setup_myself(meshlink_handle_t *mesh) {
 
        node_add(mesh, mesh->self);
 
-       if(!config_scan_all(mesh, "current", "hosts", load_node, NULL)) {
+       if(!config_ls(mesh, load_node)) {
                logger(mesh, MESHLINK_WARNING, "Could not scan all host config files");
        }