From 4b5e1798413a2f15408014dc14015575de91cd6a Mon Sep 17 00:00:00 2001 From: Andrew Bettison Date: Sat, 19 May 2012 14:09:50 +0930 Subject: [PATCH] Start support for MeshMS manifests --- commandline.c | 7 +++---- rhizome.c | 21 ++++++++++++++++----- rhizome_database.c | 6 ++++-- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/commandline.c b/commandline.c index 2245dea4..503a1f33 100644 --- a/commandline.c +++ b/commandline.c @@ -1084,18 +1084,17 @@ int app_rhizome_add_file(int argc, const char *const *argv, struct command_line_ cli_arg(argc, argv, o, "author_sid", &authorSid, cli_optional_sid, ""); cli_arg(argc, argv, o, "pin", &pin, NULL, ""); cli_arg(argc, argv, o, "manifestpath", &manifestpath, NULL, ""); - if (!keyring_open_with_pins(pin)) - return -1; - /* Ensure the Rhizome database exists and is open */ if (create_serval_instance_dir() == -1) return -1; + if (!keyring_open_with_pins(pin)) + return -1; if (rhizome_opendb() == -1) return -1; /* Create a new manifest that will represent the file. If a manifest file was supplied, then read * it, otherwise create a blank manifest. */ rhizome_manifest *m = NULL; int manifest_file_supplied = 0; - if (manifestpath[0] && access(manifestpath, R_OK) == 0) { + if (manifestpath[0] && access(manifestpath, R_OK) == 0) { m = rhizome_read_manifest_file(manifestpath, 0, 0); // no verify if (!m) return WHY("Manifest file could not be loaded -- not added to rhizome"); diff --git a/rhizome.c b/rhizome.c index a340d15e..7e52b001 100644 --- a/rhizome.c +++ b/rhizome.c @@ -150,11 +150,24 @@ int rhizome_add_manifest(rhizome_manifest *m_in, const char *service = rhizome_manifest_get(m_in, "service", NULL, 0); if (service == NULL || !service[0]) return WHY("Manifest missing 'service' field"); - const char *name = rhizome_manifest_get(m_in, "name", NULL, 0); - if (name == NULL || !name[0]) - return WHY("Manifest missing 'name' field"); if (rhizome_manifest_get_ll(m_in, "date") == -1) return WHY("Manifest missing 'date' field"); + if (strcasecmp(service, "file")) { + const char *name = rhizome_manifest_get(m_in, "name", NULL, 0); + if (name == NULL || !name[0]) + return WHY("Manifest missing 'name' field"); + } else if (strcasecmp(service, "MeshMS")) { + const char *sender = rhizome_manifest_get(m_in, "sender", NULL, 0); + const char *recipient = rhizome_manifest_get(m_in, "recipient", NULL, 0); + if (sender == NULL || sender[0]) + return WHY("Manifest missing 'sender' field"); + if (!validateSid(sender)) + return WHY("Manifest contains invalid 'sender' field"); + if (recipient == NULL || recipient[0]) + return WHY("Manifest missing 'recipient' field"); + if (!validateSid(recipient)) + return WHY("Manifest contains invalid 'recipient' field"); + } /* Keep payload file name handy for later */ m_in->dataFileName = strdup(filename); @@ -217,8 +230,6 @@ int rhizome_add_manifest(rhizome_manifest *m_in, if (rhizome_find_duplicate(m_in, &dupm) == -1) return WHY("Errors encountered searching for duplicate manifest"); if (dupm) { - if (debug & DEBUG_RHIZOME) - fprintf(stderr, "Found duplicate payload: name=\"%s\" version=%llu hexhash=%s -- not adding\n", name, dupm->version, dupm->fileHexHash); /* If the caller wants the duplicate manifest, it must be finalised, otherwise discarded. */ if (m_out) { if (rhizome_manifest_finalise(dupm, 0,NULL)) diff --git a/rhizome_database.c b/rhizome_database.c index 277ffdbb..723930d2 100644 --- a/rhizome_database.c +++ b/rhizome_database.c @@ -1,6 +1,6 @@ /* -Serval Distributed Numbering Architecture (DNA) -Copyright (C) 2010 Paul Gardner-Stephen +Serval Rhizome file sharing +Copyright (C) 2012 The Serval Project This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -899,6 +899,8 @@ int rhizome_find_duplicate(const rhizome_manifest *m, rhizome_manifest **found) blob_m->fileLength = m->fileLength; blob_m->version = q_version; *found = blob_m; + if (debug & DEBUG_RHIZOME) + DEBUGF("Found duplicate payload: name=\"%s\" version=%llu hexhash=%s -- not adding\n", blob_m, blob_m->version, blob_m->fileHexHash); ret = 1; if (debug & DEBUG_RHIZOME) DEBUG("found"); break;