From a61b4f18a1f9dcb78dba4bcde48a9318b04a45ec Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 23 Jul 2019 17:21:29 +0200 Subject: [SERVER] Add pretendClient config option This makes the server not set the FLAGS8_SERVER flag when establishing an uplink connection. Useful mostly for running a proxy on localhost for local caching. --- src/server/globals.c | 2 ++ src/server/globals.h | 7 +++++++ src/shared/protocol.h | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/server/globals.c b/src/server/globals.c index c9b9411..010274d 100644 --- a/src/server/globals.c +++ b/src/server/globals.c @@ -32,6 +32,7 @@ atomic_int _maxClients = SERVER_MAX_CLIENTS; atomic_int _maxImages = SERVER_MAX_IMAGES; atomic_int _maxPayload = 9000000; // 9MB atomic_uint_fast64_t _maxReplicationSize = (uint64_t)100000000000LL; +atomic_bool _pretendClient = false; /** * True when loading config the first time. Consecutive loads will @@ -80,6 +81,7 @@ static int ini_handler(void *custom UNUSED, const char* section, const char* key SAVE_TO_VAR_UINT( dnbd3, clientTimeout ); SAVE_TO_VAR_UINT( limits, maxPayload ); SAVE_TO_VAR_UINT64( limits, maxReplicationSize ); + SAVE_TO_VAR_BOOL( dnbd3, pretendClient ); if ( strcmp( section, "dnbd3" ) == 0 && strcmp( key, "backgroundReplication" ) == 0 ) { if ( strcmp( value, "hashblock" ) == 0 ) { _backgroundReplication = BGR_HASHBLOCK; diff --git a/src/server/globals.h b/src/server/globals.h index 9b10ee4..031f565 100644 --- a/src/server/globals.h +++ b/src/server/globals.h @@ -265,6 +265,13 @@ extern atomic_int _maxPayload; */ extern atomic_uint_fast64_t _maxReplicationSize; +/** + * Pretend to be a client when talking to others servers, + * effectively not setting the server bit during connection + * setup. Useful for local caching. + */ +extern atomic_bool _pretendClient; + /** * Load the server configuration. */ diff --git a/src/shared/protocol.h b/src/shared/protocol.h index d87bbd8..92dbe11 100644 --- a/src/shared/protocol.h +++ b/src/shared/protocol.h @@ -20,7 +20,7 @@ #define COND_HOPCOUNT(vers,hopcount) ( (vers) >= 3 ? (hopcount) : 0 ) // 2017-11-02: Macro to set flags in select image message properly if we're a server, as BG_REP depends on global var -#define SI_SERVER_FLAGS ( FLAGS8_SERVER | (_backgroundReplication == BGR_FULL ? FLAGS8_BG_REP : 0) ) +#define SI_SERVER_FLAGS ( (_pretendClient ? 0 : FLAGS8_SERVER) | (_backgroundReplication == BGR_FULL ? FLAGS8_BG_REP : 0) ) #define REPLY_OK (0) #define REPLY_ERRNO (-1) -- cgit v1.2.3-55-g7522