Start support for MeshMS manifests

This commit is contained in:
Andrew Bettison 2012-05-19 14:09:50 +09:30
parent 96916c053c
commit 4b5e179841
3 changed files with 23 additions and 11 deletions

View File

@ -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");

View File

@ -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))

View File

@ -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;