From be263dacde44ed752ba345e16f35839564cb722f Mon Sep 17 00:00:00 2001 From: Yury Popov Date: Sun, 4 Sep 2016 23:45:46 +0300 Subject: [PATCH] Set espconn's secure buffer size once at initialization (#1466) Fixes #1457 --- app/http/httpclient.c | 1 - app/include/user_config.h | 4 ++++ app/modules/mqtt.c | 3 --- app/modules/net.c | 1 - app/user/user_main.c | 5 +++++ app/websocket/websocketclient.c | 3 --- 6 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/http/httpclient.c b/app/http/httpclient.c index 19ce015f..5e0fe555 100644 --- a/app/http/httpclient.c +++ b/app/http/httpclient.c @@ -477,7 +477,6 @@ static void ICACHE_FLASH_ATTR http_dns_callback( const char * hostname, ip_addr_ if ( req->secure ) { - espconn_secure_set_size( ESPCONN_CLIENT, 5120 ); /* set SSL buffer size */ espconn_secure_connect( conn ); } else diff --git a/app/include/user_config.h b/app/include/user_config.h index be3332ef..3d865fea 100644 --- a/app/include/user_config.h +++ b/app/include/user_config.h @@ -60,6 +60,10 @@ extern void luaL_assertfail(const char *file, int line, const char *message); #define NO_INTR_CODE inline #endif +// SSL buffer size used only for espconn-layer secure connections. +// See https://github.com/nodemcu/nodemcu-firmware/issues/1457 for conversation details. +#define SSL_BUFFER_SIZE 5120 + //#define CLIENT_SSL_ENABLE //#define MD2_ENABLE #define SHA2_ENABLE diff --git a/app/modules/mqtt.c b/app/modules/mqtt.c index 6439541b..ef604ac7 100644 --- a/app/modules/mqtt.c +++ b/app/modules/mqtt.c @@ -1618,9 +1618,6 @@ static const LUA_REG_TYPE mqtt_map[] = { int luaopen_mqtt( lua_State *L ) { luaL_rometatable(L, "mqtt.socket", (void *)mqtt_socket_map); // create metatable for mqtt.socket -#ifdef CLIENT_SSL_ENABLE - espconn_secure_set_size(ESPCONN_CLIENT, 4096); -#endif return 0; } diff --git a/app/modules/net.c b/app/modules/net.c index b9549487..744a4122 100644 --- a/app/modules/net.c +++ b/app/modules/net.c @@ -577,7 +577,6 @@ static void socket_connect(struct espconn *pesp_conn) { #ifdef CLIENT_SSL_ENABLE if(nud->secure){ - espconn_secure_set_size(ESPCONN_CLIENT, 5120); /* set SSL buffer size */ espconn_secure_connect(pesp_conn); } else diff --git a/app/user/user_main.c b/app/user/user_main.c index 581619e8..69115171 100644 --- a/app/user/user_main.c +++ b/app/user/user_main.c @@ -22,6 +22,7 @@ #include "driver/uart.h" #include "task/task.h" #include "mem.h" +#include "espconn.h" #ifdef LUA_USE_MODULES_RTCTIME #include "rtc/rtctime.h" @@ -98,6 +99,10 @@ void nodemcu_init(void) } #endif // defined(FLASH_SAFE_API) +#if defined ( CLIENT_SSL_ENABLE ) && defined ( SSL_BUFFER_SIZE ) + espconn_secure_set_size(ESPCONN_CLIENT, SSL_BUFFER_SIZE); +#endif + #if defined ( BUILD_SPIFFS ) if (!fs_mount()) { // Failed to mount -- try reformat diff --git a/app/websocket/websocketclient.c b/app/websocket/websocketclient.c index bc0f7209..d9fa29ce 100644 --- a/app/websocket/websocketclient.c +++ b/app/websocket/websocketclient.c @@ -47,8 +47,6 @@ #define PORT_INSECURE 80 #define PORT_MAX_VALUE 65535 -#define SSL_BUFFER_SIZE 5120 - // TODO: user agent configurable #define WS_INIT_HEADERS "GET %s HTTP/1.1\r\n"\ "Host: %s:%d\r\n"\ @@ -656,7 +654,6 @@ static void dns_callback(const char *hostname, ip_addr_t *addr, void *arg) { if (ws->isSecure) { NODE_DBG("secure connecting \n"); - espconn_secure_set_size(ESPCONN_CLIENT, SSL_BUFFER_SIZE); espconn_secure_connect(conn); } else {