samples: net: Modify mqtt_publisher to use set proxy
Modify mqtt_publisher sample to use mqtt_client_set_proxy(). Removed CONFIG_MQTT_LIB_SOCKS based setup. Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
This commit is contained in:
parent
8e70bd6f48
commit
fa7a5db12e
3 changed files with 13 additions and 11 deletions
|
@ -1 +1 @@
|
||||||
CONFIG_MQTT_LIB_SOCKS=y
|
CONFIG_SOCKS=y
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CONFIG_MQTT_LIB_SOCKS)
|
#if defined(CONFIG_SOCKS)
|
||||||
#define SOCKS5_PROXY_ADDR SERVER_ADDR
|
#define SOCKS5_PROXY_ADDR SERVER_ADDR
|
||||||
#define SOCKS5_PROXY_PORT 1080
|
#define SOCKS5_PROXY_PORT 1080
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -26,8 +26,9 @@ static struct mqtt_client client_ctx;
|
||||||
|
|
||||||
/* MQTT Broker details. */
|
/* MQTT Broker details. */
|
||||||
static struct sockaddr_storage broker;
|
static struct sockaddr_storage broker;
|
||||||
#if defined(CONFIG_MQTT_LIB_SOCKS)
|
|
||||||
static struct sockaddr_storage socks5_proxy;
|
#if defined(CONFIG_SOCKS)
|
||||||
|
static struct sockaddr socks5_proxy;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static struct pollfd fds[1];
|
static struct pollfd fds[1];
|
||||||
|
@ -246,7 +247,7 @@ static void broker_init(void)
|
||||||
broker6->sin6_port = htons(SERVER_PORT);
|
broker6->sin6_port = htons(SERVER_PORT);
|
||||||
inet_pton(AF_INET6, SERVER_ADDR, &broker6->sin6_addr);
|
inet_pton(AF_INET6, SERVER_ADDR, &broker6->sin6_addr);
|
||||||
|
|
||||||
#if defined(CONFIG_MQTT_LIB_SOCKS)
|
#if defined(CONFIG_SOCKS)
|
||||||
struct sockaddr_in6 *proxy6 = (struct sockaddr_in6 *)&socks5_proxy;
|
struct sockaddr_in6 *proxy6 = (struct sockaddr_in6 *)&socks5_proxy;
|
||||||
|
|
||||||
proxy6->sin6_family = AF_INET6;
|
proxy6->sin6_family = AF_INET6;
|
||||||
|
@ -259,8 +260,7 @@ static void broker_init(void)
|
||||||
broker4->sin_family = AF_INET;
|
broker4->sin_family = AF_INET;
|
||||||
broker4->sin_port = htons(SERVER_PORT);
|
broker4->sin_port = htons(SERVER_PORT);
|
||||||
inet_pton(AF_INET, SERVER_ADDR, &broker4->sin_addr);
|
inet_pton(AF_INET, SERVER_ADDR, &broker4->sin_addr);
|
||||||
|
#if defined(CONFIG_SOCKS)
|
||||||
#if defined(CONFIG_MQTT_LIB_SOCKS)
|
|
||||||
struct sockaddr_in *proxy4 = (struct sockaddr_in *)&socks5_proxy;
|
struct sockaddr_in *proxy4 = (struct sockaddr_in *)&socks5_proxy;
|
||||||
|
|
||||||
proxy4->sin_family = AF_INET;
|
proxy4->sin_family = AF_INET;
|
||||||
|
@ -307,13 +307,15 @@ static void client_init(struct mqtt_client *client)
|
||||||
tls_config->hostname = NULL;
|
tls_config->hostname = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#else
|
|
||||||
#if defined(CONFIG_MQTT_LIB_SOCKS)
|
|
||||||
client->transport.type = MQTT_TRANSPORT_SOCKS;
|
|
||||||
client->transport.socks5.proxy = &socks5_proxy;
|
|
||||||
#else
|
#else
|
||||||
client->transport.type = MQTT_TRANSPORT_NON_SECURE;
|
client->transport.type = MQTT_TRANSPORT_NON_SECURE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(CONFIG_SOCKS)
|
||||||
|
mqtt_client_set_proxy(client, &socks5_proxy,
|
||||||
|
socks5_proxy.sa_family == AF_INET ?
|
||||||
|
sizeof(struct sockaddr_in) :
|
||||||
|
sizeof(struct sockaddr_in6));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue