various fixes to rhizome re-fetch logic after a failed partial fetch

(which seems to be what is tripping things up)
This commit is contained in:
gardners 2012-05-27 17:29:50 +02:00
parent 60057681b7
commit 07fc646fed
2 changed files with 24 additions and 15 deletions

View File

@ -202,6 +202,13 @@ int rhizome_manifest_bind_file(rhizome_manifest *m_in,const char *filename,int e
int rhizome_manifest_check_file(rhizome_manifest *m_in) int rhizome_manifest_check_file(rhizome_manifest *m_in)
{ {
int gotfile= sqlite_exec_int64("SELECT COUNT(*) FROM FILES WHERE ID='%s' and datavalid=1;",
m_in->fileHexHash);
if (gotfile==1) {
WHYF("Skipping file checks for bundle, as file is already in the database");
return 0;
}
/* Find out whether the payload is expected to be encrypted or not */ /* Find out whether the payload is expected to be encrypted or not */
m_in->payloadEncryption=rhizome_manifest_get_ll(m_in, "crypt"); m_in->payloadEncryption=rhizome_manifest_get_ll(m_in, "crypt");
@ -302,7 +309,7 @@ int rhizome_add_manifest(rhizome_manifest *m_in,int ttl)
return WHY("Newer version exists"); return WHY("Newer version exists");
} }
if (m_in->version == storedversion) { if (m_in->version == storedversion) {
return WHY("Same version exists"); return WHY("Same version of manifest exists, not adding");
} }
strbuf b = strbuf_local(ofilehash, sizeof ofilehash); strbuf b = strbuf_local(ofilehash, sizeof ofilehash);

View File

@ -502,7 +502,7 @@ int rhizome_queue_manifest_import(rhizome_manifest *m, struct sockaddr_in *peeri
if (rhizome_manifest_version_cache_lookup(m)) { if (rhizome_manifest_version_cache_lookup(m)) {
/* We already have this version or newer */ /* We already have this version or newer */
if (debug&DEBUG_RHIZOMESYNC) { if (1||debug&DEBUG_RHIZOMESYNC) {
DEBUGF("manifest id=%s, version=%lld", DEBUGF("manifest id=%s, version=%lld",
rhizome_manifest_get(m,"id",NULL,0), rhizome_manifest_get(m,"id",NULL,0),
rhizome_manifest_get_ll(m,"version")); rhizome_manifest_get_ll(m,"version"));
@ -510,7 +510,7 @@ int rhizome_queue_manifest_import(rhizome_manifest *m, struct sockaddr_in *peeri
} }
return -1; return -1;
} else { } else {
if (debug&DEBUG_RHIZOMESYNC) { if (1||debug&DEBUG_RHIZOMESYNC) {
DEBUGF("manifest id=%s, version=%lld is new to us.", DEBUGF("manifest id=%s, version=%lld is new to us.",
rhizome_manifest_get(m,"id",NULL,0), rhizome_manifest_get(m,"id",NULL,0),
rhizome_manifest_get_ll(m,"version")); rhizome_manifest_get_ll(m,"version"));
@ -519,7 +519,7 @@ int rhizome_queue_manifest_import(rhizome_manifest *m, struct sockaddr_in *peeri
/* Don't queue if queue slots already full */ /* Don't queue if queue slots already full */
if (rhizome_file_fetch_queue_count>=MAX_QUEUED_FILES) { if (rhizome_file_fetch_queue_count>=MAX_QUEUED_FILES) {
if (debug&DEBUG_RHIZOME) DEBUG("Already busy fetching files"); if (1||debug&DEBUG_RHIZOME) DEBUG("Already busy fetching files");
return -1; return -1;
} }
/* Don't queue if already queued */ /* Don't queue if already queued */
@ -530,7 +530,7 @@ int rhizome_queue_manifest_import(rhizome_manifest *m, struct sockaddr_in *peeri
rhizome_file_fetch_record rhizome_file_fetch_record
*q=&file_fetch_queue[i]; *q=&file_fetch_queue[i];
if (!strcasecmp(id,rhizome_manifest_get(q->manifest,"id",NULL,0))) { if (!strcasecmp(id,rhizome_manifest_get(q->manifest,"id",NULL,0))) {
if (debug&DEBUG_RHIZOMESYNC) if (1||debug&DEBUG_RHIZOMESYNC)
DEBUGF("Already have %s in the queue.",id); DEBUGF("Already have %s in the queue.",id);
return -1; return -1;
} }
@ -545,12 +545,14 @@ int rhizome_queue_manifest_import(rhizome_manifest *m, struct sockaddr_in *peeri
long long filesize = rhizome_manifest_get_ll(m, "filesize"); long long filesize = rhizome_manifest_get_ll(m, "filesize");
if (debug&DEBUG_RHIZOMESYNC) if (1||debug&DEBUG_RHIZOMESYNC)
DEBUGF("Getting ready to fetch file %s for manifest %s", m->fileHexHash, id); DEBUGF("Getting ready to fetch file %s for manifest %s", m->fileHexHash, id);
if (filesize > 0 && m->fileHexHash[0]) if (filesize > 0 && m->fileHexHash[0])
{ {
int gotfile= sqlite_exec_int64("SELECT COUNT(*) FROM FILES WHERE ID='%s';", m->fileHexHash); int gotfile= sqlite_exec_int64("SELECT COUNT(*) FROM FILES WHERE ID='%s' and datavalid=1;", m->fileHexHash);
WHYF("SELECT COUNT(*) FROM FILES WHERE ID='%s' and datavalid=1; returned %d", m->fileHexHash,
gotfile);
if (gotfile!=1) { if (gotfile!=1) {
/* We need to get the file */ /* We need to get the file */
/* Discard request if the same manifest is already queued for reception. /* Discard request if the same manifest is already queued for reception.
@ -564,7 +566,7 @@ int rhizome_queue_manifest_import(rhizome_manifest *m, struct sockaddr_in *peeri
if (j==crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES) if (j==crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES)
{ {
/* We are already fetching this manifest */ /* We are already fetching this manifest */
if (debug&DEBUG_RHIZOME) DEBUGF("Already fetching manifest"); if (1||debug&DEBUG_RHIZOME) DEBUGF("Already fetching manifest");
return -1; return -1;
} }
for(j=0;j<=RHIZOME_FILEHASH_STRLEN;j++) for(j=0;j<=RHIZOME_FILEHASH_STRLEN;j++)
@ -572,7 +574,7 @@ int rhizome_queue_manifest_import(rhizome_manifest *m, struct sockaddr_in *peeri
if (j==RHIZOME_FILEHASH_STRLEN + 1) if (j==RHIZOME_FILEHASH_STRLEN + 1)
{ {
/* We are already fetching this file */ /* We are already fetching this file */
if (debug&DEBUG_RHIZOME) DEBUGF("Already fetching file %s", m->fileHexHash); if (1||debug&DEBUG_RHIZOME) DEBUGF("Already fetching file %s", m->fileHexHash);
return -1; return -1;
} }
} }
@ -627,13 +629,13 @@ int rhizome_queue_manifest_import(rhizome_manifest *m, struct sockaddr_in *peeri
q->file=fopen(q->manifest->dataFileName,"w"); q->file=fopen(q->manifest->dataFileName,"w");
if (!q->file) { if (!q->file) {
WHY_perror("fopen"); WHY_perror("fopen");
if (debug&DEBUG_RHIZOME) if (1||debug&DEBUG_RHIZOME)
DEBUGF("Could not open '%s' to write received file.", q->manifest->dataFileName); DEBUGF("Could not open '%s' to write received file.", q->manifest->dataFileName);
close(sock); close(sock);
return -1; return -1;
} }
rhizome_file_fetch_queue_count++; rhizome_file_fetch_queue_count++;
if (debug&DEBUG_RHIZOME) DEBUGF("Queued file for fetching into %s (%d in queue)", if (1||debug&DEBUG_RHIZOME) DEBUGF("Queued file for fetching into %s (%d in queue)",
q->manifest->dataFileName, rhizome_file_fetch_queue_count); q->manifest->dataFileName, rhizome_file_fetch_queue_count);
return 0; return 0;
} }
@ -645,7 +647,7 @@ int rhizome_queue_manifest_import(rhizome_manifest *m, struct sockaddr_in *peeri
} }
else else
{ {
if (debug&DEBUG_RHIZOMESYNC) if (1||debug&DEBUG_RHIZOMESYNC)
DEBUGF("We already have the file for this manifest; importing from manifest alone."); DEBUGF("We already have the file for this manifest; importing from manifest alone.");
if (create_rhizome_import_dir() == -1) if (create_rhizome_import_dir() == -1)
return -1; return -1;
@ -727,8 +729,8 @@ int rhizome_fetch_poll()
switch(q->state) switch(q->state)
{ {
case RHIZOME_FETCH_SENDINGHTTPREQUEST: case RHIZOME_FETCH_SENDINGHTTPREQUEST:
DEBUGF("sending http request (%d of %d bytes sent)", DEBUGF("sending http request (%d of %d bytes sent): %s",
q->request_ofs,q->request_len); q->request_ofs,q->request_len,q->request);
bytes=write(q->socket,&q->request[q->request_ofs], bytes=write(q->socket,&q->request[q->request_ofs],
q->request_len-q->request_ofs); q->request_len-q->request_ofs);
if (bytes>0) { if (bytes>0) {