From 53af9905e023c89c9d7c30c22eb25f2b0105026c Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Fri, 13 Dec 2019 14:44:22 +0000 Subject: [peerdist] Allow PeerDist to be globally enabled or disabled Allow the use of PeerDist content encoding to be enabled or disabled via the ${peerdist} setting, e.g.: # Disable PeerDist set peerdist 0 Signed-off-by: Michael Brown --- src/net/peerdist.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/net/peerdist.c b/src/net/peerdist.c index 48933f95..3210ac0e 100644 --- a/src/net/peerdist.c +++ b/src/net/peerdist.c @@ -25,6 +25,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include #include +#include #include /** @file @@ -35,6 +36,9 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); * misfortune to encounter, and I've encountered multicast TFTP. */ +/** PeerDist is globally enabled */ +static long peerdist_enabled = 1; + /** * Check whether or not to support PeerDist encoding for this request * @@ -43,6 +47,10 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); */ static int http_peerdist_supported ( struct http_transaction *http ) { + /* Allow PeerDist to be globally enabled/disabled */ + if ( ! peerdist_enabled ) + return 0; + /* Support PeerDist encoding only if we can directly access an * underlying data transfer buffer. Direct access is required * in order to support decryption of data received via the @@ -143,3 +151,33 @@ struct http_content_encoding peerdist_encoding __http_content_encoding = { .supported = http_peerdist_supported, .init = http_peerdist_init, }; + +/** PeerDist enabled setting */ +const struct setting peerdist_setting __setting ( SETTING_MISC, peerdist ) = { + .name = "peerdist", + .description = "PeerDist enabled", + .type = &setting_type_int8, +}; + +/** + * Apply PeerDist settings + * + * @ret rc Return status code + */ +static int apply_peerdist_settings ( void ) { + + /* Fetch global PeerDist enabled setting */ + if ( fetch_int_setting ( NULL, &peerdist_setting, + &peerdist_enabled ) < 0 ) { + peerdist_enabled = 1; + } + DBGC ( &peerdist_enabled, "PEERDIST is %s\n", + ( peerdist_enabled ? "enabled" : "disabled" ) ); + + return 0; +} + +/** PeerDist settings applicator */ +struct settings_applicator peerdist_applicator __settings_applicator = { + .apply = apply_peerdist_settings, +}; -- cgit v1.2.3-55-g7522