Moved rhizome direct imports to be in-process instead of

out-of-process. rhizomeprotocol push test still fails.
Investigating. #9
This commit is contained in:
gardners 2012-10-02 20:23:44 +09:30
parent 4fd832f4ba
commit 92a5423b17
4 changed files with 69 additions and 60 deletions

View File

@ -1200,66 +1200,7 @@ int app_rhizome_import_bundle(int argc, const char *const *argv, struct command_
cli_arg(argc, argv, o, "manifestpath", &manifestpath, NULL, "");
if (rhizome_opendb() == -1)
return -1;
rhizome_manifest *m = rhizome_new_manifest();
if (!m)
return WHY("Out of manifests.");
int status = -1;
if (rhizome_read_manifest_file(m, manifestpath, 0) == -1) {
status = WHY("could not read manifest file");
} else if (rhizome_manifest_verify(m) == -1) {
status = WHY("Could not verify manifest file.");
} else {
/* Add the manifest and its associated file to the Rhizome database. */
m->dataFileName = strdup(filepath);
if (rhizome_manifest_check_file(m))
status = WHY("file does not belong to manifest");
else {
int ret = rhizome_manifest_check_duplicate(m, NULL);
if (ret == -1)
status = WHY("rhizome_manifest_check_duplicate() failed");
else if (ret) {
INFO("Duplicate found in store");
status = 1;
} else if (rhizome_add_manifest(m, 1) == -1) { // ttl = 1
status = WHY("rhizome_add_manifest() failed");
} else {
status = 0;
}
if (status != -1) {
const char *service = rhizome_manifest_get(m, "service", NULL, 0);
if (service) {
cli_puts("service");
cli_delim(":");
cli_puts(service);
cli_delim("\n");
}
{
cli_puts("manifestid");
cli_delim(":");
cli_puts(alloca_tohex(m->cryptoSignPublic, RHIZOME_MANIFEST_ID_BYTES));
cli_delim("\n");
}
cli_puts("filesize");
cli_delim(":");
cli_printf("%lld", m->fileLength);
cli_delim("\n");
if (m->fileLength != 0) {
cli_puts("filehash");
cli_delim(":");
cli_puts(m->fileHexHash);
cli_delim("\n");
}
const char *name = rhizome_manifest_get(m, "name", NULL, 0);
if (name) {
cli_puts("name");
cli_delim(":");
cli_puts(name);
cli_delim("\n");
}
}
}
}
rhizome_manifest_free(m);
int status=rhizome_import_from_files(manifestpath,filepath);
return status;
}

View File

@ -509,3 +509,5 @@ void rhizome_direct_http_dispatch(rhizome_direct_sync_request *);
extern unsigned char favicon_bytes[];
extern int favicon_len;
int rhizome_import_from_files(const char *manifestpath,const char *filepath);

View File

@ -1437,3 +1437,68 @@ int rhizome_retrieve_file(const char *fileid, const char *filepath, const unsign
sqlite3_finalize(statement);
return ret;
}
int rhizome_import_from_files(const char *manifestpath,const char *filepath)
{
rhizome_manifest *m = rhizome_new_manifest();
if (!m)
return WHY("Out of manifests.");
int status = -1;
if (rhizome_read_manifest_file(m, manifestpath, 0) == -1) {
status = WHY("could not read manifest file");
} else if (rhizome_manifest_verify(m) == -1) {
status = WHY("Could not verify manifest file.");
} else {
/* Add the manifest and its associated file to the Rhizome database. */
m->dataFileName = strdup(filepath);
if (rhizome_manifest_check_file(m))
status = WHY("file does not belong to manifest");
else {
int ret = rhizome_manifest_check_duplicate(m, NULL);
if (ret == -1)
status = WHY("rhizome_manifest_check_duplicate() failed");
else if (ret) {
INFO("Duplicate found in store");
status = 1;
} else if (rhizome_add_manifest(m, 1) == -1) { // ttl = 1
status = WHY("rhizome_add_manifest() failed");
} else {
status = 0;
}
if (status != -1) {
const char *service = rhizome_manifest_get(m, "service", NULL, 0);
if (service) {
cli_puts("service");
cli_delim(":");
cli_puts(service);
cli_delim("\n");
}
{
cli_puts("manifestid");
cli_delim(":");
cli_puts(alloca_tohex(m->cryptoSignPublic, RHIZOME_MANIFEST_ID_BYTES));
cli_delim("\n");
}
cli_puts("filesize");
cli_delim(":");
cli_printf("%lld", m->fileLength);
cli_delim("\n");
if (m->fileLength != 0) {
cli_puts("filehash");
cli_delim(":");
cli_puts(m->fileHexHash);
cli_delim("\n");
}
const char *name = rhizome_manifest_get(m, "name", NULL, 0);
if (name) {
cli_puts("name");
cli_delim(":");
cli_puts(name);
cli_delim("\n");
}
}
}
}
rhizome_manifest_free(m);
return status;
}

View File

@ -51,6 +51,7 @@ int rhizome_direct_form_received(rhizome_http_request *r)
strbuf_sprintf(manifest_path, "rhizomedirect.%d.manifest", r->alarm.poll.fd);
strbuf_sprintf(payload_path, "rhizomedirect.%d.data", r->alarm.poll.fd);
int ret = rhizome_bundle_import_files(strbuf_str(manifest_path), strbuf_str(payload_path), 1); // ttl = 1
rhizome_direct_clear_temporary_files(r);
/* report back to caller.
200 = ok, which is probably appropriate for when we already had the bundle.