From 8161709c4e9357b7146cd6465fd03e82bba80388 Mon Sep 17 00:00:00 2001 From: gardners Date: Sat, 26 May 2012 08:32:17 +0930 Subject: [PATCH] work on fixing handling of duplicate rhizome bundle debouncing. (seems to work from command line, but not from the test framework). --- rhizome.c | 5 ++++- rhizome.h | 3 ++- rhizome_database.c | 12 +++++++----- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/rhizome.c b/rhizome.c index d7a44a34..076f9199 100644 --- a/rhizome.c +++ b/rhizome.c @@ -236,9 +236,10 @@ int rhizome_manifest_check_file(rhizome_manifest *m_in) (Debounce!) */ int rhizome_manifest_check_duplicate(rhizome_manifest *m_in,rhizome_manifest **m_out) { + WHY("Checking for duplicate"); if (m_out) *m_out = NULL; rhizome_manifest *dupm = NULL; - if (rhizome_find_duplicate(m_in, &dupm) == -1) + if (rhizome_find_duplicate(m_in, &dupm,0 /* version doesn't matter */) == -1) return WHY("Errors encountered searching for duplicate manifest"); if (dupm) { /* If the caller wants the duplicate manifest, it must be finalised, otherwise discarded. */ @@ -247,8 +248,10 @@ int rhizome_manifest_check_duplicate(rhizome_manifest *m_in,rhizome_manifest **m } else rhizome_manifest_free(dupm); + WHY("Found a duplicate"); return 2; } + WHY("No duplicate found"); return 0; } diff --git a/rhizome.h b/rhizome.h index 4e7c0913..5b4e4c9e 100644 --- a/rhizome.h +++ b/rhizome.h @@ -248,7 +248,8 @@ double rhizome_manifest_get_double(rhizome_manifest *m,char *var,double default_ int chartonybl(int c); int rhizome_manifest_extract_signature(rhizome_manifest *m,int *ofs); int rhizome_update_file_priority(char *fileid); -int rhizome_find_duplicate(const rhizome_manifest *m, rhizome_manifest **found); +int rhizome_find_duplicate(const rhizome_manifest *m, rhizome_manifest **found, + int checkVersionP); int rhizome_manifest_to_bar(rhizome_manifest *m,unsigned char *bar); char nybltochar_upper(int n); int rhizome_queue_manifest_import(rhizome_manifest *m, struct sockaddr_in *peerip, int *manifest_kept); diff --git a/rhizome_database.c b/rhizome_database.c index 505b4e1b..86ba6ab4 100644 --- a/rhizome_database.c +++ b/rhizome_database.c @@ -890,7 +890,8 @@ int rhizome_update_file_priority(char *fileid) @author Andrew Bettison */ -int rhizome_find_duplicate(const rhizome_manifest *m, rhizome_manifest **found) +int rhizome_find_duplicate(const rhizome_manifest *m, rhizome_manifest **found, + int checkVersionP) { if (!m->fileHashedP) return WHY("Manifest payload is not hashed"); @@ -917,13 +918,14 @@ int rhizome_find_duplicate(const rhizome_manifest *m, rhizome_manifest **found) "SELECT manifests.id, manifests.manifest, manifests.version FROM filemanifests, manifests" " WHERE filemanifests.manifestid = manifests.id AND filemanifests.fileid = ?" ); - if (m->version != -1 && s < &sqlcmd[sizeof sqlcmd]) + if (checkVersionP && s < &sqlcmd[sizeof sqlcmd]) s += snprintf(s, sqlcmd + sizeof(sqlcmd) - s, " AND manifests.version = ?"); if (s >= &sqlcmd[sizeof sqlcmd]) return WHY("SQL command too long"); int ret = 0; sqlite3_stmt *statement; const char *cmdtail; + if (debug&DEBUG_RHIZOME) WHYF("sql query: %s",sqlcmd); if (sqlite3_prepare_v2(rhizome_db, sqlcmd, strlen(sqlcmd) + 1, &statement, &cmdtail) != SQLITE_OK) { ret = WHY(sqlite3_errmsg(rhizome_db)); } else { @@ -932,7 +934,7 @@ int rhizome_find_duplicate(const rhizome_manifest *m, rhizome_manifest **found) str_toupper_inplace(filehash); if (debug & DEBUG_RHIZOME) DEBUGF("filehash=\"%s\"", filehash); sqlite3_bind_text(statement, 1, filehash, -1, SQLITE_STATIC); - if (m->version != -1) + if (checkVersionP) sqlite3_bind_int64(statement, 2, m->version); size_t rows = 0; while (sqlite3_step(statement) == SQLITE_ROW) { @@ -976,7 +978,7 @@ int rhizome_find_duplicate(const rhizome_manifest *m, rhizome_manifest **found) WARNF("MANIFESTS row id=%s has inconsistent blob with id=%s -- skipped", q_manifestid, blob_id); ++inconsistent; } - if (blob_version != -1 && blob_version != q_version) { + if (checkVersionP && blob_version != q_version) { WARNF("MANIFESTS row id=%s has inconsistent blob: manifests.version=%lld, blob.version=%lld -- skipped", q_manifestid, q_version, blob_version); ++inconsistent; @@ -991,7 +993,7 @@ int rhizome_find_duplicate(const rhizome_manifest *m, rhizome_manifest **found) q_manifestid, m->fileLength, blob_filesize); ++inconsistent; } - if (m->version != -1 && q_version != m->version) { + if (checkVersionP && q_version != m->version) { WARNF("SELECT query with version=%lld returned incorrect row: manifests.version=%lld -- skipped", m->version, q_version); ++inconsistent; }