From 4cdd3da77f99e5bdeb1529beb38586ea8b4ae407 Mon Sep 17 00:00:00 2001 From: Jeremy Lakeman Date: Tue, 5 Mar 2013 10:55:18 +1030 Subject: [PATCH] Add config option to disable fetching via rhizome --- conf_schema.h | 1 + rhizome_fetch.c | 4 ++++ rhizome_packetformats.c | 6 ++++-- tests/rhizomeprotocol | 24 ++++++++++++++++++++++++ 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/conf_schema.h b/conf_schema.h index 65c02023..2b157fa4 100644 --- a/conf_schema.h +++ b/conf_schema.h @@ -320,6 +320,7 @@ END_STRUCT STRUCT(rhizome) ATOM(int, enable, 1, int_boolean,, "If true, server opens Rhizome database when starting") +ATOM(char, fetch, 1, char_boolean,, "If false, no new bundles will be fetched from peers") ATOM(int, clean_on_open, 1, int_boolean,, "If true, Rhizome database is cleaned at start of every command") STRING(256, datastore_path, "", absolute_path,, "Path of rhizome storage directory, absolute or relative to instance directory") ATOM(uint64_t, database_size, 1000000, uint64_scaled,, "Size of database in bytes") diff --git a/rhizome_fetch.c b/rhizome_fetch.c index be4cd5ba..b96f041f 100644 --- a/rhizome_fetch.c +++ b/rhizome_fetch.c @@ -896,6 +896,10 @@ struct profile_total rfmsc_stats={.name="rhizome_fetch_mdp_slot_callback"}; int rhizome_suggest_queue_manifest_import(rhizome_manifest *m, const struct sockaddr_in *peerip,const unsigned char peersid[SID_SIZE]) { IN(); + + if (!config.rhizome.fetch) + RETURN(0); + const char *bid = alloca_tohex_bid(m->cryptoSignPublic); int priority=100; /* normal priority */ diff --git a/rhizome_packetformats.c b/rhizome_packetformats.c index f9de6968..86ab7d20 100644 --- a/rhizome_packetformats.c +++ b/rhizome_packetformats.c @@ -257,9 +257,11 @@ error: int overlay_rhizome_saw_advertisements(int i, struct overlay_frame *f, long long now) { IN(); - if (!f) { RETURN(-1); } + if (!f) + RETURN(-1); - if (!rhizome_db) { RETURN(0); } + if (!(rhizome_db && config.rhizome.fetch)) + RETURN(0); int ad_frame_type=ob_get(f->payload); struct sockaddr_in httpaddr = f->recvaddr; diff --git a/tests/rhizomeprotocol b/tests/rhizomeprotocol index aa2c5af6..b6669969 100755 --- a/tests/rhizomeprotocol +++ b/tests/rhizomeprotocol @@ -109,6 +109,30 @@ test_EncryptedTransfer() { assert diff file1 file1x } +doc_NoFetch="Disabling fetching still allows pushing bundles" +setup_NoFetch() { + setup_common + set_instance +A + rhizome_add_file file1 + BID1=$BID + VERSION1=$VERSION + set_instance +B + rhizome_add_file file2 + BID2=$BID + VERSION2=$VERSION + executeOk_servald config set rhizome.fetch 0 + start_servald_instances +A +B +} +test_NoFetch() { + wait_until bundle_received_by $BID2:$VERSION2 +A + set_instance +A + executeOk_servald rhizome list + assert_rhizome_list --fromhere=1 file1 --fromhere=0 file2 + set_instance +B + executeOk_servald rhizome list + assert_rhizome_list --fromhere=1 file2 +} + doc_DisablingHTTPServer="Disabling HTTP rhizome transports works" setup_DisablingHTTPServer() { setup_common