Browse Source

[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 <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 5 years ago
parent
commit
53af9905e0
1 changed files with 38 additions and 0 deletions
  1. 38
    0
      src/net/peerdist.c

+ 38
- 0
src/net/peerdist.c View File

25
 
25
 
26
 #include <stdio.h>
26
 #include <stdio.h>
27
 #include <ipxe/http.h>
27
 #include <ipxe/http.h>
28
+#include <ipxe/settings.h>
28
 #include <ipxe/peermux.h>
29
 #include <ipxe/peermux.h>
29
 
30
 
30
 /** @file
31
 /** @file
35
  * misfortune to encounter, and I've encountered multicast TFTP.
36
  * misfortune to encounter, and I've encountered multicast TFTP.
36
  */
37
  */
37
 
38
 
39
+/** PeerDist is globally enabled */
40
+static long peerdist_enabled = 1;
41
+
38
 /**
42
 /**
39
  * Check whether or not to support PeerDist encoding for this request
43
  * Check whether or not to support PeerDist encoding for this request
40
  *
44
  *
43
  */
47
  */
44
 static int http_peerdist_supported ( struct http_transaction *http ) {
48
 static int http_peerdist_supported ( struct http_transaction *http ) {
45
 
49
 
50
+	/* Allow PeerDist to be globally enabled/disabled */
51
+	if ( ! peerdist_enabled )
52
+		return 0;
53
+
46
 	/* Support PeerDist encoding only if we can directly access an
54
 	/* Support PeerDist encoding only if we can directly access an
47
 	 * underlying data transfer buffer.  Direct access is required
55
 	 * underlying data transfer buffer.  Direct access is required
48
 	 * in order to support decryption of data received via the
56
 	 * in order to support decryption of data received via the
143
 	.supported = http_peerdist_supported,
151
 	.supported = http_peerdist_supported,
144
 	.init = http_peerdist_init,
152
 	.init = http_peerdist_init,
145
 };
153
 };
154
+
155
+/** PeerDist enabled setting */
156
+const struct setting peerdist_setting __setting ( SETTING_MISC, peerdist ) = {
157
+	.name = "peerdist",
158
+	.description = "PeerDist enabled",
159
+	.type = &setting_type_int8,
160
+};
161
+
162
+/**
163
+ * Apply PeerDist settings
164
+ *
165
+ * @ret rc		Return status code
166
+ */
167
+static int apply_peerdist_settings ( void ) {
168
+
169
+	/* Fetch global PeerDist enabled setting */
170
+	if ( fetch_int_setting ( NULL, &peerdist_setting,
171
+				 &peerdist_enabled ) < 0 ) {
172
+		peerdist_enabled = 1;
173
+	}
174
+	DBGC ( &peerdist_enabled, "PEERDIST is %s\n",
175
+	       ( peerdist_enabled ? "enabled" : "disabled" ) );
176
+
177
+	return 0;
178
+}
179
+
180
+/** PeerDist settings applicator */
181
+struct settings_applicator peerdist_applicator __settings_applicator = {
182
+	.apply = apply_peerdist_settings,
183
+};

Loading…
Cancel
Save