summaryrefslogtreecommitdiffstats
path: root/aclk
diff options
context:
space:
mode:
authorAndrew Moss <1043609+amoss@users.noreply.github.com>2020-03-17 13:57:15 +0100
committerGitHub <noreply@github.com>2020-03-17 13:57:15 +0100
commit9e32f03a474cd37da288d43cf4df051d22e2e3d0 (patch)
treea586ee01d86aa2bd9edb7f42f66ed0b93d73d041 /aclk
parent449f09bdf64a95a238cc43a110beb49c38930049 (diff)
Fix outstanding problems in claiming and add SOCKS5 support. (#8406)
This commit fixes the known problems in claiming: incorrect reports of success, better treatment of error code and improved visibility of what the script is doing. There has been extensive testing against both environments to check that it works. The socks5 proxy support has been integrated and works for both methods of calling the claiming script. Co-authored-by: Timotej Šiškovič <timotej@netdata.cloud>
Diffstat (limited to 'aclk')
-rw-r--r--aclk/aclk_common.c42
-rw-r--r--aclk/agent_cloud_link.c45
-rw-r--r--aclk/tests/paho-inspection.py2
3 files changed, 46 insertions, 43 deletions
diff --git a/aclk/aclk_common.c b/aclk/aclk_common.c
index fe113478f5..027d97e54c 100644
--- a/aclk/aclk_common.c
+++ b/aclk/aclk_common.c
@@ -105,3 +105,45 @@ const char *aclk_lws_wss_get_proxy_setting(ACLK_PROXY_TYPE *type) {
return proxy;
}
+
+int aclk_decode_base_url(char *url, char **aclk_hostname, char **aclk_port)
+{
+int pos = 0;
+ if (!strncmp("https://", url, 8))
+ {
+ pos = 8;
+ }
+ else if (!strncmp("http://", url, 7))
+ {
+ error("Cannot connect ACLK over %s -> unencrypted link is not supported", url);
+ return 1;
+ }
+int host_end = pos;
+ while( url[host_end] != 0 && url[host_end] != '/' && url[host_end] != ':' )
+ host_end++;
+ if (url[host_end] == 0)
+ {
+ *aclk_hostname = strdupz(url+pos);
+ *aclk_port = strdupz("443");
+ info("Setting ACLK target host=%s port=%s from %s", *aclk_hostname, *aclk_port, url);
+ return 0;
+ }
+ if (url[host_end] == ':')
+ {
+ *aclk_hostname = callocz(host_end - pos + 1, 1);
+ strncpy(*aclk_hostname, url+pos, host_end - pos);
+ int port_end = host_end + 1;
+ while (url[port_end] >= '0' && url[port_end] <= '9')
+ port_end++;
+ if (port_end - host_end > 6)
+ {
+ error("Port specified in %s is invalid", url);
+ return 0;
+ }
+ *aclk_port = callocz(port_end - host_end + 1, 1);
+ for(int i=host_end + 1; i < port_end; i++)
+ (*aclk_port)[i - host_end - 1] = url[i];
+ }
+ info("Setting ACLK target host=%s port=%s from %s", *aclk_hostname, *aclk_port, url);
+ return 0;
+}
diff --git a/aclk/agent_cloud_link.c b/aclk/agent_cloud_link.c
index ab1b85bae1..5196c689b5 100644
--- a/aclk/agent_cloud_link.c
+++ b/aclk/agent_cloud_link.c
@@ -3,6 +3,7 @@
#include "libnetdata/libnetdata.h"
#include "agent_cloud_link.h"
#include "aclk_lws_https_client.h"
+#include "aclk_common.h"
// State-machine for the on-connect metadata transmission.
// TODO: The AGENT_STATE should be centralized as it would be useful to control error-logging during the initial
@@ -1129,48 +1130,6 @@ unsigned int line_len=0;
return NULL;
}
-static int decode_base_url(char *url, char **aclk_hostname, char **aclk_port)
-{
-int pos = 0;
- if (!strncmp("https://", url, 8))
- {
- pos = 8;
- }
- else if (!strncmp("http://", url, 7))
- {
- error("Cannot connect ACLK over %s -> unencrypted link is not supported", url);
- return 1;
- }
-int host_end = pos;
- while( url[host_end] != 0 && url[host_end] != '/' && url[host_end] != ':' )
- host_end++;
- if (url[host_end] == 0)
- {
- *aclk_hostname = strdupz(url+pos);
- *aclk_port = strdupz("443");
- info("Setting ACLK target host=%s port=%s from %s", *aclk_hostname, *aclk_port, url);
- return 0;
- }
- if (url[host_end] == ':')
- {
- *aclk_hostname = callocz(host_end - pos + 1, 1);
- strncpy(*aclk_hostname, url+pos, host_end - pos);
- int port_end = host_end + 1;
- while (url[port_end] >= '0' && url[port_end] <= '9')
- port_end++;
- if (port_end - host_end > 6)
- {
- error("Port specified in %s is invalid", url);
- return 0;
- }
- *aclk_port = callocz(port_end - host_end + 1, 1);
- for(int i=host_end + 1; i < port_end; i++)
- (*aclk_port)[i - host_end - 1] = url[i];
- }
- info("Setting ACLK target host=%s port=%s from %s", *aclk_hostname, *aclk_port, url);
- return 0;
-}
-
void aclk_get_challenge(char *aclk_hostname, char *aclk_port)
{
char *data_buffer = mallocz(NETDATA_WEB_RESPONSE_INITIAL_SIZE);
@@ -1304,7 +1263,7 @@ void *aclk_main(void *ptr)
char *aclk_port = NULL;
uint32_t port_num = 0;
char *cloud_base_url = config_get(CONFIG_SECTION_CLOUD, "cloud base url", "https://netdata.cloud");
- if( decode_base_url(cloud_base_url, &aclk_hostname, &aclk_port))
+ if( aclk_decode_base_url(cloud_base_url, &aclk_hostname, &aclk_port))
{
error("Configuration error - cannot use agent cloud link");
return NULL;
diff --git a/aclk/tests/paho-inspection.py b/aclk/tests/paho-inspection.py
index b12b62da8c..20ab523d4e 100644
--- a/aclk/tests/paho-inspection.py
+++ b/aclk/tests/paho-inspection.py
@@ -27,6 +27,8 @@ def on_message(mqttc, obj, msg):
print(f"Message {mtype} time={ts} size {len(api_msg)}", flush=True)
now = time.time()
print(f"Current {now} -> Delay {now-ts}", flush=True)
+ if mtype=="disconnect":
+ print(f"Message dump: {api_msg}", flush=True)
def on_publish(mqttc, obj, mid):
print("mid: "+str(mid), flush=True)