fixed bugs with rhizome streaming direct to database.

that now works, but rhizome direct pull now fails.
This commit is contained in:
gardners 2012-12-03 20:51:14 +10:30
parent e108fe0822
commit de7a4ce2e3
3 changed files with 19 additions and 13 deletions

View File

@ -110,8 +110,6 @@ int rhizome_bundle_import(rhizome_manifest *m, int ttl)
if (debug & DEBUG_RHIZOME)
DEBUGF("(m=%p, ttl=%d)", m, ttl);
/* Add the manifest and its payload to the Rhizome database. */
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");
int ret = rhizome_manifest_check_duplicate(m, NULL);

View File

@ -966,6 +966,10 @@ int64_t rhizome_database_create_blob_for(const char *hashhex,int64_t fileLength,
sqlite3_stmt *statement = sqlite_prepare(&retry, "INSERT OR REPLACE INTO FILES(id,data,length,highestpriority,datavalid,inserttime) VALUES('%s',?,%lld,%d,0,%lld);",
hashhex, (long long)fileLength, priority, (long long)gettime_ms()
);
DEBUGF("INSERT OR REPLACE INTO FILES(id,data,length,highestpriority,datavalid,inserttime) VALUES('%s',?,%lld,%d,0,%lld);",
hashhex, (long long)fileLength, priority, (long long)gettime_ms()
);
if (!statement)
goto insert_row_fail;
/* Bind appropriate sized zero-filled blob to data field */

View File

@ -505,7 +505,8 @@ static int schedule_fetch(struct rhizome_fetch_slot *slot)
if (create_rhizome_import_dir() == -1)
goto bail;
slot->file_len=slot->manifest->fileLength;
slot->rowid=rhizome_database_create_blob_for(alloca_tohex_sid(slot->bid),
slot->rowid=
rhizome_database_create_blob_for(slot->manifest->fileHexHash,
slot->file_len,
RHIZOME_PRIORITY_DEFAULT);
if (slot->rowid<0) {
@ -1155,6 +1156,7 @@ static int rhizome_fetch_switch_to_mdp(struct rhizome_fetch_slot *slot)
which is the block size we will use. 200bytes allows for several blocks
to fit into a packet, and probably fit at least one any any outgoing packet
that is not otherwise full. */
slot->file_len=slot->manifest->fileLength;
slot->mdpIdleTimeout=5000; // give up if nothing received for 5 seconds
slot->mdpRXBitmap=0x00000000; // no blocks received yet
slot->mdpRXBlockLength=200; // 200;
@ -1218,6 +1220,8 @@ int rhizome_write_content(struct rhizome_fetch_slot *slot, char *buffer, int byt
if (ret!=SQLITE_OK) return -1;
ret=sqlite3_blob_write(blob, buffer, bytes, slot->file_ofs);
if (ret!=SQLITE_OK) {
WHYF("sqlite3_blob_write(,,%d,%d) failed, %s",
bytes,slot->file_ofs,sqlite3_errmsg(rhizome_db));
if (debug & DEBUG_RHIZOME_RX)
DEBUGF("Failed to write %d bytes to file @ offset %d", bytes, slot->file_ofs);
rhizome_fetch_close(slot);
@ -1241,21 +1245,21 @@ int rhizome_write_content(struct rhizome_fetch_slot *slot, char *buffer, int byt
char hash_out[SHA512_DIGEST_STRING_LENGTH+1];
SHA512_End(&slot->sha512_context, (char *)hash_out);
DEBUGF("Hash of received file = %s",hash_out);
DEBUGF("Hash I was looking for = %s",slot->manifest->fileHexHash);
sqlite_retry_state retry = SQLITE_RETRY_STATE_DEFAULT;
if (strcasecmp(hash_out,slot->manifest->fileHexHash)) {
if (debug & DEBUG_RHIZOME_RX)
DEBUGF("Hash mismatch -- dropping row from table.");
sqlite_exec_void_retry(&retry,
"DROP FROM FILES WHERE rowid=%lld",slot->rowid);
rhizome_fetch_close(slot);
return -1;
} else {
sqlite_exec_void_retry(&retry,
int ret=sqlite_exec_void_retry(&retry,
"UPDATE FILES SET datavalid=1 WHERE rowid=%lld",
slot->rowid);
DEBUGF("Marked row valid");
if (ret!=SQLITE_OK)
if (debug & DEBUG_RHIZOME_RX)
DEBUGF("error marking row valid: %s",sqlite3_errmsg(rhizome_db));
}
if (!rhizome_import_received_bundle(slot->manifest)){