allows using LWS without SOCKS5 (#9973)
* allows using LWS without SOCKS5
Timotej S committed
Sep 24, 2020 at 11:54 UTC
b2ac03cf4bf6bf19783ff726585dc5b62bb55520
3 files changed
+45
-2
aclk/aclk_common.c
+23
-2
@@ -2,6 +2,10 @@
2
3
#include "../daemon/common.h"
4
5
+#ifdef ENABLE_ACLK
6
+#include <libwebsockets.h>
7
+#endif
8
+
9
netdata_mutex_t aclk_shared_state_mutex = NETDATA_MUTEX_INITIALIZER;
10
11
int aclk_disable_runtime = 0;
@@ -144,14 +148,31 @@ const char *aclk_lws_wss_get_proxy_setting(ACLK_PROXY_TYPE *type)
148
return proxy;
149
150
if (strcmp(proxy, ACLK_PROXY_ENV) == 0) {
147
- if (check_socks_enviroment(&proxy) == 0)
151
+ if (check_socks_enviroment(&proxy) == 0) {
152
+#ifdef LWS_WITH_SOCKS5
153
*type = PROXY_TYPE_SOCKS5;
149
- else if (check_http_enviroment(&proxy) == 0)
154
+ return proxy;
155
+#else
156
+ safe_log_proxy_error("socks_proxy environment variable set to use SOCKS5 proxy "
157
+ "but Libwebsockets used doesn't have SOCKS5 support built in. "
158
+ "Ignoring and checking for other options.",
159
+ proxy);
160
+#endif
161
+ }
162
+ if (check_http_enviroment(&proxy) == 0)
163
*type = PROXY_TYPE_HTTP;
164
return proxy;
165
}
166
167
*type = aclk_verify_proxy(proxy);
168
+#ifndef LWS_WITH_SOCKS5
169
+ if (*type == PROXY_TYPE_SOCKS5) {
170
+ safe_log_proxy_error(
171
+ "Config var \"" ACLK_PROXY_CONFIG_VAR
172
+ "\" set to use SOCKS5 proxy but Libwebsockets used is built without support for SOCKS proxy. ACLK will be disabled.",
173
+ proxy);
174
+ }
175
+#endif
176
if (*type == PROXY_TYPE_UNKNOWN) {
177
*type = PROXY_DISABLED;
178
safe_log_proxy_error(
aclk/aclk_lws_wss_client.c
+8
@@ -209,6 +209,7 @@ void aclk_lws_wss_client_destroy()
209
#endif
210
}
211
212
+#ifdef LWS_WITH_SOCKS5
213
static int aclk_wss_set_socks(struct lws_vhost *vhost, const char *socks)
214
{
215
char *proxy = strstr(socks, ACLK_PROXY_PROTO_ADDR_SEPARATOR);
@@ -223,6 +224,7 @@ static int aclk_wss_set_socks(struct lws_vhost *vhost, const char *socks)
224
225
return lws_set_socks(vhost, proxy);
226
}
227
+#endif
228
229
void aclk_wss_set_proxy(struct lws_vhost *vhost)
230
{
@@ -232,7 +234,9 @@ void aclk_wss_set_proxy(struct lws_vhost *vhost)
234
235
proxy = aclk_get_proxy(&proxy_type);
236
237
+#ifdef LWS_WITH_SOCKS5
238
lws_set_socks(vhost, ":");
239
+#endif
240
lws_set_proxy(vhost, ":");
241
242
if (proxy_type == PROXY_TYPE_UNKNOWN) {
@@ -247,9 +251,13 @@ void aclk_wss_set_proxy(struct lws_vhost *vhost)
251
freez(log);
252
}
253
if (proxy_type == PROXY_TYPE_SOCKS5) {
254
+#ifdef LWS_WITH_SOCKS5
255
if (aclk_wss_set_socks(vhost, proxy))
256
error("LWS failed to accept socks proxy.");
257
return;
258
+#else
259
+ fatal("We have no SOCKS5 support but we made it here. Programming error!");
260
+#endif
261
}
262
if (proxy_type == PROXY_TYPE_HTTP) {
263
if (lws_set_proxy(vhost, proxy))
aclk/agent_cloud_link.c
+14
@@ -7,6 +7,10 @@
7
#include "aclk_common.h"
8
#include "aclk_stats.h"
9
10
+#ifdef ENABLE_ACLK
11
+#include <libwebsockets.h>
12
+#endif
13
+
14
int aclk_shutting_down = 0;
15
16
// Other global state
@@ -886,6 +890,16 @@ void *aclk_main(void *ptr)
890
return NULL;
891
#endif
892
893
+#ifndef LWS_WITH_SOCKS5
894
+ ACLK_PROXY_TYPE proxy_type;
895
+ aclk_get_proxy(&proxy_type);
896
+ if(proxy_type == PROXY_TYPE_SOCKS5) {
897
+ error("Disabling ACLK due to requested SOCKS5 proxy.");
898
+ static_thread->enabled = NETDATA_MAIN_THREAD_EXITED;
899
+ return NULL;
900
+ }
901
+#endif
902
+
903
info("Waiting for netdata to be ready");
904
while (!netdata_ready) {
905
sleep_usec(USEC_PER_MS * 300);