mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-04-27 06:20:10 +00:00
Merge branch 'master' of github.com:servalproject/serval-dna
This commit is contained in:
commit
8a468e2a96
@ -51,6 +51,7 @@ SERVALD_SRC_FILES = \
|
||||
serval-dna/audio_reflector.c
|
||||
|
||||
SERVALD_LOCAL_CFLAGS = \
|
||||
-g \
|
||||
-DSHELL -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" \
|
||||
-DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" \
|
||||
-DHAVE_LIBC=1 -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 \
|
||||
|
@ -313,7 +313,7 @@ int rhizome_add_manifest(rhizome_manifest *m_in,int ttl)
|
||||
}
|
||||
|
||||
strbuf b = strbuf_local(ofilehash, sizeof ofilehash);
|
||||
sqlite_exec_strbuf(b, "SELECT fileid from filemanifests where manifestid='%s';", id);
|
||||
sqlite_exec_strbuf(b, "SELECT filehash from manifests where id='%s';", id);
|
||||
if (strbuf_overrun(b))
|
||||
return WHYF("fileid too long: '%s'", strbuf_str(b));
|
||||
} else {
|
||||
|
@ -274,6 +274,7 @@ int rhizome_bk_xor(const char *author,
|
||||
unsigned char bid[crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES],
|
||||
unsigned char bkin[crypto_sign_edwards25519sha512batch_SECRETKEYBYTES],
|
||||
unsigned char bkout[crypto_sign_edwards25519sha512batch_SECRETKEYBYTES]);
|
||||
unsigned char *rhizome_bundle_shared_secret(rhizome_manifest *m);
|
||||
int rhizome_extract_privatekey(rhizome_manifest *m,const char *authorHex);
|
||||
int rhizome_queue_ignore_manifest(rhizome_manifest *m,
|
||||
struct sockaddr_in *peerip,int timeout);
|
||||
|
@ -22,6 +22,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
|
||||
/* Work out the encrypt/decrypt key for the supplied manifest.
|
||||
If the manifest is not encrypted, then return NULL.
|
||||
*/
|
||||
unsigned char *rhizome_bundle_shared_secret(rhizome_manifest *m)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int rhizome_strn_is_manifest_id(const char *id)
|
||||
{
|
||||
int i;
|
||||
|
@ -139,37 +139,39 @@ int rhizome_opendb()
|
||||
}
|
||||
|
||||
/* Create tables if required */
|
||||
if (sqlite3_exec(rhizome_db,"PRAGMA auto_vacuum=2;",NULL,NULL,NULL)) {
|
||||
WARNF("SQLite could enable incremental vacuuming: %s", sqlite3_errmsg(rhizome_db));
|
||||
}
|
||||
if (sqlite3_exec(rhizome_db,"CREATE TABLE IF NOT EXISTS GROUPLIST(id text not null primary key, closed integer,ciphered integer,priority integer);",NULL,NULL,NULL))
|
||||
if (sqlite3_exec(rhizome_db,
|
||||
"PRAGMA auto_vacuum=2;"
|
||||
"CREATE TABLE IF NOT EXISTS GROUPLIST(id text not null primary key, closed integer,ciphered integer,priority integer);"
|
||||
|
||||
"CREATE TABLE IF NOT EXISTS MANIFESTS(id text not null primary key, manifest blob, version integer,inserttime integer, bar blob);"
|
||||
|
||||
"CREATE TABLE IF NOT EXISTS FILES(id text not null primary key, data blob, length integer, highestpriority integer, datavalid integer);"
|
||||
|
||||
"DROP TABLE IF EXISTS FILEMANIFESTS;"
|
||||
"CREATE TABLE IF NOT EXISTS GROUPMEMBERSHIPS(manifestid text not null, groupid text not null);"
|
||||
"CREATE TABLE IF NOT EXISTS VERIFICATIONS(sid text not null, did text, name text, starttime integer, endtime integer, signature blob);"
|
||||
|
||||
,NULL,NULL,NULL))
|
||||
{
|
||||
return WHYF("SQLite could not create GROUPLIST table: %s", sqlite3_errmsg(rhizome_db));
|
||||
}
|
||||
if (sqlite3_exec(rhizome_db,"CREATE TABLE IF NOT EXISTS MANIFESTS(id text not null primary key, manifest blob, version integer,inserttime integer, bar blob);",NULL,NULL,NULL))
|
||||
{
|
||||
return WHYF("SQLite could not create MANIFESTS table: %s", sqlite3_errmsg(rhizome_db));
|
||||
}
|
||||
if (sqlite3_exec(rhizome_db,"CREATE TABLE IF NOT EXISTS FILES(id text not null primary key, data blob, length integer, highestpriority integer, datavalid integer);",NULL,NULL,NULL))
|
||||
{
|
||||
return WHYF("SQLite could not create FILES table: %s", sqlite3_errmsg(rhizome_db));
|
||||
}
|
||||
if (sqlite3_exec(rhizome_db,"CREATE TABLE IF NOT EXISTS FILEMANIFESTS(fileid text not null, manifestid text not null);",NULL,NULL,NULL))
|
||||
{
|
||||
return WHYF("SQLite could not create FILEMANIFESTS table: %s", sqlite3_errmsg(rhizome_db));
|
||||
}
|
||||
if (sqlite3_exec(rhizome_db,"CREATE TABLE IF NOT EXISTS GROUPMEMBERSHIPS(manifestid text not null, groupid text not null);",NULL,NULL,NULL))
|
||||
{
|
||||
return WHYF("SQLite could not create GROUPMEMBERSHIPS table: %s", sqlite3_errmsg(rhizome_db));
|
||||
}
|
||||
if (sqlite3_exec(rhizome_db,"CREATE TABLE IF NOT EXISTS VERIFICATIONS(sid text not null, did text, name text, starttime integer, endtime integer, signature blob);",
|
||||
NULL,NULL,NULL))
|
||||
{
|
||||
return WHYF("SQLite could not create VERIFICATIONS table: %s", sqlite3_errmsg(rhizome_db));
|
||||
return WHYF("Failed to create required schema: %s", sqlite3_errmsg(rhizome_db));
|
||||
}
|
||||
// no easy way to tell if these columns already exist, should probably create some kind of schema version table
|
||||
// running this a second time will fail.
|
||||
sqlite3_exec(rhizome_db,
|
||||
"ALTER TABLE MANIFESTS ADD COLUMN filesize text;"
|
||||
"ALTER TABLE MANIFESTS ADD COLUMN filehash text;"
|
||||
"ALTER TABLE FILES ADD inserttime integer;"
|
||||
,NULL,NULL,NULL);
|
||||
|
||||
if (sqlite3_exec(rhizome_db,
|
||||
"CREATE INDEX IF NOT EXISTS IDX_MANIFESTS_HASH ON MANIFESTS(filehash);"
|
||||
"DELETE FROM MANIFESTS WHERE filehash IS NULL;"
|
||||
"DELETE FROM FILES WHERE NOT EXISTS( SELECT 1 FROM MANIFESTS WHERE MANIFESTS.filehash = FILES.id);"
|
||||
"DELETE FROM MANIFESTS WHERE NOT EXISTS( SELECT 1 FROM FILES WHERE MANIFESTS.filehash = FILES.id);"
|
||||
,NULL,NULL,NULL)){
|
||||
return WHYF("Failed to create required schema: %s", sqlite3_errmsg(rhizome_db));
|
||||
}
|
||||
|
||||
/* XXX Setup special groups, e.g., Serval Software and Serval Optional Data */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -378,7 +380,7 @@ int rhizome_drop_stored_file(const char *id,int maximum_priority)
|
||||
return -1;
|
||||
}
|
||||
|
||||
snprintf(sql,1024,"select manifests.id from manifests,filemanifests where manifests.id==filemanifests.manifestid and filemanifests.fileid='%s'",
|
||||
snprintf(sql,1024,"select id from manifests where filehash='%s'",
|
||||
id);
|
||||
if(sqlite3_prepare_v2(rhizome_db,sql, -1, &statement, NULL) != SQLITE_OK )
|
||||
{
|
||||
@ -408,9 +410,8 @@ int rhizome_drop_stored_file(const char *id,int maximum_priority)
|
||||
WHYF("Cannot drop due to manifest %s",id);
|
||||
cannot_drop=1;
|
||||
} else {
|
||||
printf("removing stale filemanifests, manifests, groupmemberships\n");
|
||||
sqlite_exec_void("delete from filemanifests where manifestid='%s';",manifestId);
|
||||
sqlite_exec_void("delete from manifests where manifestid='%s';",manifestId);
|
||||
printf("removing stale manifests, groupmemberships\n");
|
||||
sqlite_exec_void("delete from manifests where id='%s';",manifestId);
|
||||
sqlite_exec_void("delete from keypairs where public='%s';",manifestId);
|
||||
sqlite_exec_void("delete from groupmemberships where manifestid='%s';",manifestId);
|
||||
}
|
||||
@ -418,7 +419,6 @@ int rhizome_drop_stored_file(const char *id,int maximum_priority)
|
||||
sqlite3_finalize(statement);
|
||||
|
||||
if (!cannot_drop) {
|
||||
sqlite_exec_void("delete from filemanifests where fileid='%s';",id);
|
||||
sqlite_exec_void("delete from files where id='%s';",id);
|
||||
}
|
||||
return 0;
|
||||
@ -477,7 +477,7 @@ int sqlite3_step_retry(sqlite3_stmt *stmt){
|
||||
substitute bytes in the blog progressively.
|
||||
|
||||
We need to also need to create the appropriate row(s) in the MANIFESTS, FILES,
|
||||
FILEMANIFESTS and GROUPMEMBERSHIPS tables, and possibly GROUPLIST as well.
|
||||
and GROUPMEMBERSHIPS tables, and possibly GROUPLIST as well.
|
||||
*/
|
||||
int rhizome_store_bundle(rhizome_manifest *m)
|
||||
{
|
||||
@ -525,31 +525,23 @@ int rhizome_store_bundle(rhizome_manifest *m)
|
||||
if (!rhizome_db) rhizome_opendb();
|
||||
sql_ret = sqlite3_exec_retry(rhizome_db, "BEGIN TRANSACTION;", NULL, NULL, &err);
|
||||
|
||||
if (SQLITE_CODE_OK(sql_ret)) sql_ret = sqlite3_prepare_v2_retry(rhizome_db, "INSERT OR REPLACE INTO MANIFESTS(id,manifest,version,inserttime,bar) VALUES(?,?,?,?,?);", -1, &stmt, NULL);
|
||||
if (SQLITE_CODE_OK(sql_ret)) sql_ret = sqlite3_prepare_v2_retry(rhizome_db, "INSERT OR REPLACE INTO MANIFESTS(id,manifest,version,inserttime,bar,filesize,filehash) VALUES(?,?,?,?,?,?,?);", -1, &stmt, NULL);
|
||||
if (SQLITE_CODE_OK(sql_ret)) sql_ret = sqlite3_bind_text(stmt, 1, manifestid, -1, SQLITE_TRANSIENT);
|
||||
if (SQLITE_CODE_OK(sql_ret)) sql_ret = sqlite3_bind_blob(stmt, 2, m->manifestdata, m->manifest_bytes, SQLITE_TRANSIENT);
|
||||
if (SQLITE_CODE_OK(sql_ret)) sql_ret = sqlite3_bind_int64(stmt, 3, m->version);
|
||||
if (SQLITE_CODE_OK(sql_ret)) sql_ret = sqlite3_bind_int64(stmt, 4, gettime_ms());
|
||||
if (SQLITE_CODE_OK(sql_ret)) sql_ret = sqlite3_bind_blob(stmt, 5, bar, RHIZOME_BAR_BYTES, SQLITE_TRANSIENT);
|
||||
if (SQLITE_CODE_OK(sql_ret)) sql_ret = sqlite3_step_retry(stmt);
|
||||
if (SQLITE_CODE_OK(sql_ret)) sql_ret = sqlite3_finalize(stmt);
|
||||
|
||||
// delete all other file manifest records
|
||||
if (SQLITE_CODE_OK(sql_ret)) sql_ret = sqlite3_prepare_v2_retry(rhizome_db, "DELETE FROM FILEMANIFESTS WHERE manifestid=? AND fileid != ?;", -1, &stmt, NULL);
|
||||
if (SQLITE_CODE_OK(sql_ret)) sql_ret = sqlite3_bind_text(stmt, 1, manifestid, -1, SQLITE_TRANSIENT);
|
||||
if (SQLITE_CODE_OK(sql_ret)) sql_ret = sqlite3_bind_text(stmt, 2, filehash, -1, SQLITE_TRANSIENT);
|
||||
if (SQLITE_CODE_OK(sql_ret)) sql_ret = sqlite3_step_retry(stmt);
|
||||
if (SQLITE_CODE_OK(sql_ret)) sql_ret = sqlite3_finalize(stmt);
|
||||
|
||||
if (SQLITE_CODE_OK(sql_ret)) sql_ret = sqlite3_prepare_v2_retry(rhizome_db, "INSERT OR IGNORE INTO FILEMANIFESTS (manifestid, fileid) VALUES (?, ?);", -1, &stmt, NULL);
|
||||
if (SQLITE_CODE_OK(sql_ret)) sql_ret = sqlite3_bind_text(stmt, 1, manifestid, -1, SQLITE_TRANSIENT);
|
||||
if (SQLITE_CODE_OK(sql_ret)) sql_ret = sqlite3_bind_text(stmt, 2, filehash, -1, SQLITE_TRANSIENT);
|
||||
if (SQLITE_CODE_OK(sql_ret)) sql_ret = sqlite3_bind_int64(stmt, 6, m->fileLength);
|
||||
if (SQLITE_CODE_OK(sql_ret)) sql_ret = sqlite3_bind_text(stmt, 7, filehash, -1, SQLITE_TRANSIENT);
|
||||
if (SQLITE_CODE_OK(sql_ret)) sql_ret = sqlite3_step_retry(stmt);
|
||||
if (SQLITE_CODE_OK(sql_ret)) sql_ret = sqlite3_finalize(stmt);
|
||||
|
||||
// we might need to leave the old file around for a bit
|
||||
// clean out unreferenced files first
|
||||
if (SQLITE_CODE_OK(sql_ret)) sql_ret = sqlite3_exec_retry(rhizome_db, "DELETE FROM FILES WHERE NOT EXISTS( SELECT 1 FROM FILEMANIFESTS WHERE FILEMANIFESTS.fileid = FILES.id);", NULL, NULL, &err);
|
||||
if (SQLITE_CODE_OK(sql_ret)) sql_ret = sqlite3_prepare_v2_retry(rhizome_db, "DELETE FROM FILES WHERE inserttime < ? AND NOT EXISTS( SELECT 1 FROM MANIFESTS WHERE MANIFESTS.filehash = FILES.id);", -1, &stmt, NULL);
|
||||
if (SQLITE_CODE_OK(sql_ret)) sql_ret = sqlite3_bind_int64(stmt, 1, gettime_ms() - 60000);
|
||||
if (SQLITE_CODE_OK(sql_ret)) sql_ret = sqlite3_step_retry(stmt);
|
||||
if (SQLITE_CODE_OK(sql_ret)) sql_ret = sqlite3_finalize(stmt);
|
||||
|
||||
if (rhizome_manifest_get(m,"isagroup",NULL,0)!=NULL) {
|
||||
int closed=rhizome_manifest_get_ll(m,"closedgroup");
|
||||
@ -697,12 +689,13 @@ int rhizome_list_manifests(const char *service, const char *sender_sid, const ch
|
||||
long long blob_date = rhizome_manifest_get_ll(m, "date");
|
||||
const char *blob_filehash = rhizome_manifest_get(m, "filehash", NULL, 0);
|
||||
long long blob_filesize = rhizome_manifest_get_ll(m, "filesize");
|
||||
WHYF("Manifest payload size = %lld",blob_filesize);
|
||||
cli_puts(blob_service ? blob_service : ""); cli_delim(":");
|
||||
cli_puts(q_manifestid); cli_delim(":");
|
||||
cli_printf("%lld", blob_version); cli_delim(":");
|
||||
cli_printf("%lld", blob_date); cli_delim(":");
|
||||
cli_printf("%lld", q_inserttime); cli_delim(":");
|
||||
cli_printf("%u", blob_filesize); cli_delim(":");
|
||||
cli_printf("%lld", blob_filesize); cli_delim(":");
|
||||
cli_puts(blob_filehash ? blob_filehash : ""); cli_delim(":");
|
||||
cli_puts(blob_name ? blob_name : ""); cli_delim(":");
|
||||
cli_puts(blob_sender ? blob_sender : ""); cli_delim(":");
|
||||
@ -780,17 +773,14 @@ int rhizome_store_file(rhizome_manifest *m,const unsigned char *key)
|
||||
}
|
||||
close(fd);
|
||||
return 0;
|
||||
} else if (count>1) {
|
||||
/* This should never happen! */
|
||||
return WHY("Duplicate records for a file in the rhizome database. Database probably corrupt.");
|
||||
}
|
||||
|
||||
/* Okay, so there are no records that match, but we should delete any half-baked record (with datavalid=0) so that the insert below doesn't fail.
|
||||
Don't worry about the return result, since it might not delete any records. */
|
||||
sqlite3_exec(rhizome_db,"DELETE FROM FILES WHERE datavalid=0;",NULL,NULL,NULL);
|
||||
|
||||
snprintf(sqlcmd,1024,"INSERT INTO FILES(id,data,length,highestpriority,datavalid) VALUES('%s',?,%lld,%d,0);",
|
||||
hash,(long long)m->fileLength,priority);
|
||||
snprintf(sqlcmd,1024,"INSERT OR REPLACE INTO FILES(id,data,length,highestpriority,datavalid,inserttime) VALUES('%s',?,%lld,%d,0,%lld);",
|
||||
hash,(long long)m->fileLength,priority,gettime_ms());
|
||||
sqlite3_stmt *statement;
|
||||
if (sqlite3_prepare_v2(rhizome_db,sqlcmd,strlen(sqlcmd)+1,&statement,&cmdtail)
|
||||
!= SQLITE_OK)
|
||||
@ -920,19 +910,10 @@ void rhizome_bytes_to_hex_upper(unsigned const char *in, char *out, int byteCoun
|
||||
|
||||
int rhizome_update_file_priority(const char *fileid)
|
||||
{
|
||||
/* Drop if no references */
|
||||
int referrers=sqlite_exec_int64("SELECT COUNT(*) FROM FILEMANIFESTS WHERE fileid='%s';",fileid);
|
||||
WHYF("%d references point to %s",referrers,fileid);
|
||||
|
||||
if (referrers==0) {
|
||||
WHYF("About to drop file %s",fileid);
|
||||
rhizome_drop_stored_file(fileid,RHIZOME_PRIORITY_HIGHEST+1);
|
||||
} else if (referrers>0) {
|
||||
/* It has referrers, so workout the highest priority of any referrer */
|
||||
int highestPriority=sqlite_exec_int64("SELECT max(grouplist.priority) FROM MANIFESTS,FILEMANIFESTS,GROUPMEMBERSHIPS,GROUPLIST where manifests.id=filemanifests.manifestid AND groupmemberships.manifestid=manifests.id AND groupmemberships.groupid=grouplist.id AND filemanifests.fileid='%s';",fileid);
|
||||
if (highestPriority>=0)
|
||||
sqlite_exec_void("UPDATE files set highestPriority=%d WHERE id='%s';", highestPriority,fileid);
|
||||
}
|
||||
/* work out the highest priority of any referrer */
|
||||
int highestPriority=sqlite_exec_int64("SELECT max(grouplist.priority) FROM MANIFESTS,GROUPMEMBERSHIPS,GROUPLIST where manifests.filehash='%s' AND groupmemberships.manifestid=manifests.id AND groupmemberships.groupid=grouplist.id;",fileid);
|
||||
if (highestPriority>=0)
|
||||
sqlite_exec_void("UPDATE files set highestPriority=%d WHERE id='%s';", highestPriority,fileid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -966,11 +947,11 @@ int rhizome_find_duplicate(const rhizome_manifest *m, rhizome_manifest **found,
|
||||
char sqlcmd[1024];
|
||||
char *s = sqlcmd;
|
||||
s += snprintf(s, &sqlcmd[sizeof sqlcmd] - s,
|
||||
"SELECT manifests.id, manifests.manifest, manifests.version FROM filemanifests, manifests"
|
||||
" WHERE filemanifests.manifestid = manifests.id AND filemanifests.fileid = ?"
|
||||
"SELECT id, manifest, version FROM manifests"
|
||||
" WHERE filehash = ?"
|
||||
);
|
||||
if (checkVersionP && s < &sqlcmd[sizeof sqlcmd])
|
||||
s += snprintf(s, sqlcmd + sizeof(sqlcmd) - s, " AND manifests.version = ?");
|
||||
s += snprintf(s, sqlcmd + sizeof(sqlcmd) - s, " AND version = ?");
|
||||
if (s >= &sqlcmd[sizeof sqlcmd])
|
||||
return WHY("SQL command too long");
|
||||
int ret = 0;
|
||||
@ -1201,17 +1182,6 @@ int rhizome_retrieve_file(const char *fileid, const char *filepath,
|
||||
{
|
||||
sqlite3_blob *blob=NULL;
|
||||
rhizome_update_file_priority(fileid);
|
||||
long long count=sqlite_exec_int64("SELECT COUNT(*) FROM files WHERE id = '%s' AND datavalid != 0",fileid);
|
||||
if (count<1) {
|
||||
char id[9];
|
||||
int i;
|
||||
for(i=0;i<8;i++) id[i]=fileid[i];
|
||||
id[8]=0;
|
||||
WHYF("No such file ID %s* in the database",id);
|
||||
return 0; /* 0 files returned */
|
||||
} else if (count>1) {
|
||||
WARNF("There is more than one file in the database with ID=%s",fileid);
|
||||
}
|
||||
char sqlcmd[1024];
|
||||
int n = snprintf(sqlcmd, sizeof(sqlcmd), "SELECT id, rowid, length FROM files WHERE id = ? AND datavalid != 0");
|
||||
if (n >= sizeof(sqlcmd))
|
||||
@ -1229,7 +1199,7 @@ int rhizome_retrieve_file(const char *fileid, const char *filepath,
|
||||
sqlite3_bind_text(statement, 1, fileIdUpper, -1, SQLITE_STATIC);
|
||||
int stepcode = sqlite3_step(statement);
|
||||
if (stepcode != SQLITE_ROW) {
|
||||
WHY("Query for file yielded no results, even though it should have");
|
||||
WHY("File not found");
|
||||
ret = 0; /* no files returned */
|
||||
} else if (!( sqlite3_column_count(statement) == 3
|
||||
&& sqlite3_column_type(statement, 0) == SQLITE_TEXT
|
||||
|
@ -144,6 +144,15 @@ int rhizome_manifest_version_cache_lookup(rhizome_manifest *m)
|
||||
// dodgy manifest, we don't want to receive it
|
||||
return WHY("Ignoring bad manifest (no ID field)");
|
||||
str_toupper_inplace(id);
|
||||
m->version = rhizome_manifest_get_ll(m, "version");
|
||||
|
||||
// skip the cache for now
|
||||
long long dbVersion = sqlite_exec_int64("SELECT version FROM MANIFESTS WHERE id='%s';", id);
|
||||
if (dbVersion >= m->version){
|
||||
WHYF("We already have %s (%lld vs %lld)", id, dbVersion, m->version);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
||||
/* Work out bin number in cache */
|
||||
for(i=0;i<RHIZOME_VERSION_CACHE_NYBLS;i++)
|
||||
@ -166,19 +175,31 @@ int rhizome_manifest_version_cache_lookup(rhizome_manifest *m)
|
||||
}
|
||||
if (i==24) {
|
||||
/* Entries match -- so check version */
|
||||
unsigned long long rev = rhizome_manifest_get_ll(m,"version");
|
||||
if (0) WHYF("cached version same or newer (%lld)",entry->version);
|
||||
long long rev = rhizome_manifest_get_ll(m,"version");
|
||||
if (1) WHYF("cached version %lld vs manifest version %lld",
|
||||
entry->version,rev);
|
||||
if (rev>entry->version) {
|
||||
/* If we only have an old version, try refreshing the cache
|
||||
by querying the database */
|
||||
entry->version = sqlite_exec_int64("select version from manifests where id='%s'", id);
|
||||
WHYF("Refreshed stored version from database: entry->version=%lld",
|
||||
entry->version);
|
||||
}
|
||||
if (rev<entry->version) {
|
||||
/* the presented manifest is older than we have.
|
||||
This allows the caller to know that they can tell whoever gave them the
|
||||
manifest it's time to get with the times. May or not ever be
|
||||
implemented, but it would be nice. XXX */
|
||||
WHYF("cached version is NEWER than presented version (%lld is newer than %lld)",
|
||||
entry->version,rev);
|
||||
return -2;
|
||||
} else if (rev<=entry->version) {
|
||||
/* the presented manifest is already stored. */
|
||||
if (1) WHY("cached version is NEWER/SAME as presented version");
|
||||
return -1;
|
||||
} else {
|
||||
/* the presented manifest is newer than we have */
|
||||
WHY("cached version is older than presented version");
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
@ -362,6 +383,7 @@ int rhizome_suggest_queue_manifest_import(rhizome_manifest *m,
|
||||
|
||||
if (1) DEBUGF("Rhizome considering %s (size=%lld, priority=%d)",
|
||||
id,filesize,priority);
|
||||
m->version=rhizome_manifest_get_ll(m,"version");
|
||||
|
||||
if (rhizome_manifest_version_cache_lookup(m)) {
|
||||
/* We already have this version or newer */
|
||||
@ -378,8 +400,8 @@ int rhizome_suggest_queue_manifest_import(rhizome_manifest *m,
|
||||
long long stored_version
|
||||
=sqlite_exec_int64("select version from manifests where id='%s'",id);
|
||||
DEBUGF("manifest id=%s, version=%lld is new to us (we only have version %lld).",
|
||||
rhizome_manifest_get(m,"id",NULL,0),
|
||||
rhizome_manifest_get_ll(m,"version"),
|
||||
id,
|
||||
m->version,
|
||||
stored_version);
|
||||
}
|
||||
}
|
||||
|
@ -146,9 +146,9 @@ int overlay_rhizome_add_advertisements(int interface_number,overlay_buffer *e)
|
||||
bundle_offset[0]=0;
|
||||
if (bundles_available==-1||(bundle_offset[1]>=bundles_available))
|
||||
bundle_offset[1]=0;
|
||||
if(1)
|
||||
if(0)
|
||||
DEBUGF("%d bundles in database (%d %d), slots=%d.",bundles_available,
|
||||
bundle_offset[0],bundle_offset[1],slots);
|
||||
bundle_offset[0],bundle_offset[1],slots);
|
||||
|
||||
sqlite3_stmt *statement=NULL;
|
||||
sqlite3_blob *blob=NULL;
|
||||
|
Loading…
x
Reference in New Issue
Block a user