Issue #9, fix old 'rhizomeprotocol' test failures

Now only the five new Rhizome Direct tests fail.
This commit is contained in:
Andrew Bettison 2012-10-02 16:32:48 +09:30
parent 4daaa8f164
commit cc9cb8d827
5 changed files with 24 additions and 18 deletions

View File

@ -76,7 +76,7 @@ int rhizome_bundle_import(rhizome_manifest *m_in, rhizome_manifest **m_out,
}
}
/* Add the manifest and its payload to the Rhizome database. */
if (!(m->dataFileName && m->dataFileName[0]))
if (m->fileLength > 0 && !(m->dataFileName && m->dataFileName[0]))
return WHY("Missing data file name");
if (rhizome_manifest_check_file(m))
return WHY("File does not belong to manifest");
@ -232,7 +232,7 @@ int rhizome_manifest_check_file(rhizome_manifest *m_in)
the file size stored in the manifest */
long long mfilesize = rhizome_manifest_get_ll(m_in, "filesize");
m_in->fileLength = 0;
if (m_in->dataFileName[0]) {
if (m_in->dataFileName && m_in->dataFileName[0]) {
struct stat stat;
if (lstat(m_in->dataFileName,&stat) == -1) {
if (errno != ENOENT || mfilesize != 0)
@ -242,7 +242,7 @@ int rhizome_manifest_check_file(rhizome_manifest *m_in)
}
}
if (debug & DEBUG_RHIZOME)
DEBUGF("filename=%s, fileLength=%lld", m_in->dataFileName, m_in->fileLength);
DEBUGF("filename=%s, fileLength=%lld", m_in->dataFileName ? alloca_str_toprint(m_in->dataFileName) : NULL, m_in->fileLength);
if (mfilesize != -1 && mfilesize != m_in->fileLength) {
WHYF("Manifest.filesize (%lld) != actual file size (%lld)", mfilesize, m_in->fileLength);
return -1;
@ -315,7 +315,7 @@ int rhizome_add_manifest(rhizome_manifest *m_in,int ttl)
/* Get manifest version number. */
m_in->version = rhizome_manifest_get_ll(m_in, "version");
if (m_in->version==-1)
if (m_in->version==-1)
return WHY("Manifest must have a version number");
/* Supply manifest version number if missing, so we can do the version check below */

View File

@ -352,7 +352,7 @@ long long rhizome_manifest_get_ll(rhizome_manifest *m, const char *var)
if (!m)
return -1;
int i;
for (i = 0;i != m->var_count; ++i)
for (i = 0; i < m->var_count; ++i)
if (!strcmp(m->vars[i], var)) {
char *vp = m->values[i];
char *ep = vp;

View File

@ -296,7 +296,10 @@ int rhizome_manifest_lookup_signature_validity(unsigned char *hash,unsigned char
int rhizome_manifest_extract_signature(rhizome_manifest *m,int *ofs)
{
IN();
if (!m) { RETURN(WHY("NULL pointer passed in as manifest")); }
if (!m)
RETURN(WHY("NULL pointer passed in as manifest"));
if (debug&DEBUG_RHIZOME)
DEBUGF("m->manifest_all_bytes=%d m->manifest_bytes=%d *ofs=%d", m->manifest_all_bytes, m->manifest_bytes, *ofs);
if ((*ofs)>=m->manifest_all_bytes) { RETURN(0); }

View File

@ -382,6 +382,8 @@ int rhizome_position_candidate(int position)
void rhizome_import_received_bundle(struct rhizome_manifest *m)
{
m->finalised = 1;
m->manifest_bytes = m->manifest_all_bytes; // store the signatures too
if (debug & DEBUG_RHIZOME_RX) {
DEBUGF("manifest len=%d has %d signatories", m->manifest_bytes, m->sig_count);
dump("manifest", m->manifestdata, m->manifest_all_bytes);
@ -702,13 +704,11 @@ int rhizome_queue_manifest_import(rhizome_manifest *m, struct sockaddr_in *peeri
/* TODO: fetch via overlay */
return WHY("Rhizome fetching via overlay not implemented");
}
} else {
if (debug & DEBUG_RHIZOME_RX)
DEBUGF("We already have the file for this manifest; importing from manifest alone.");
rhizome_bundle_import(m, NULL, NULL, m->ttl-1);
}
else
{
if (debug & DEBUG_RHIZOME_RX)
DEBUGF("We already have the file for this manifest; importing from manifest alone.");
rhizome_bundle_import(m, NULL, NULL, m->ttl-1);
}
}
return 0;

View File

@ -428,7 +428,7 @@ int overlay_rhizome_saw_advertisements(int i,overlay_frame *f, long long now)
/* Ignoring manifest that has caused us problems recently */
if (1) WARNF("Ignoring manifest with errors: %s*", manifest_id_prefix);
}
else if (m&&(!m->errors))
else if (m->errors == 0)
{
/* Manifest is okay, so see if it is worth storing */
if (rhizome_manifest_version_cache_lookup(m)) {
@ -447,8 +447,10 @@ int overlay_rhizome_saw_advertisements(int i,overlay_frame *f, long long now)
a minute. */
rhizome_queue_ignore_manifest(m, &httpaddr, 60000);
}
if (m) rhizome_manifest_free(m);
m=NULL;
if (m) {
rhizome_manifest_free(m);
m = NULL;
}
if (importManifest) {
/* Okay, so the manifest looks like it is potentially interesting to us,
i.e., we don't already have it or a later version of it.
@ -466,15 +468,16 @@ int overlay_rhizome_saw_advertisements(int i,overlay_frame *f, long long now)
rhizome_suggest_queue_manifest_import(), where it only gets called
after checking that it is worth adding to the queue. */
} else if (m->errors) {
if (debug&DEBUG_RHIZOME) DEBUGF("Verifying manifest %s* revealed errors -- not storing.", manifest_id_prefix);
if (debug&DEBUG_RHIZOME)
DEBUGF("Verifying manifest %s* revealed errors -- not storing.", manifest_id_prefix);
rhizome_queue_ignore_manifest(m, &httpaddr, 60000);
rhizome_manifest_free(m);
m = NULL;
} else {
if (debug&DEBUG_RHIZOME) DEBUGF("Verifying manifest %s* revealed no errors -- will try to store.", manifest_id_prefix);
if (debug&DEBUG_RHIZOME)
DEBUGF("Verifying manifest %s* revealed no errors -- will try to store.", manifest_id_prefix);
/* Add manifest to import queue. We need to know originating IPv4 address
so that we can transfer by HTTP. */
if (0) DEBUG("Suggesting fetching of a bundle");
rhizome_suggest_queue_manifest_import(m, &httpaddr);
}
}