From d79c07e2a49567d8293e860507a31c1e36d137f0 Mon Sep 17 00:00:00 2001 From: ading2210 Date: Mon, 26 Feb 2024 22:52:06 -0500 Subject: [PATCH 1/4] limit max connections to 50 --- client/build.sh | 2 +- client/javascript/main.js | 6 +----- client/libcurl/main.c | 2 ++ client/package.json | 2 +- server/wisp_server | 2 +- 5 files changed, 6 insertions(+), 8 deletions(-) diff --git a/client/build.sh b/client/build.sh index be013ab..1ef82b5 100755 --- a/client/build.sh +++ b/client/build.sh @@ -28,7 +28,7 @@ EXPORTED_FUNCS="${EXPORTED_FUNCS:1}" #compile options RUNTIME_METHODS="addFunction,removeFunction,allocate,ALLOC_NORMAL" COMPILER_OPTIONS="-o $MODULE_FILE -lcurl -lssl -lcrypto -lcjson -lz -lbrotlidec -lbrotlicommon -lnghttp2 -I $INCLUDE_DIR -L $LIB_DIR" -EMSCRIPTEN_OPTIONS="-lwebsocket.js -sASSERTIONS=1 -sLLD_REPORT_UNDEFINED -sALLOW_TABLE_GROWTH -sALLOW_MEMORY_GROWTH -sEXPORTED_FUNCTIONS=$EXPORTED_FUNCS -sEXPORTED_RUNTIME_METHODS=$RUNTIME_METHODS" +EMSCRIPTEN_OPTIONS="-lwebsocket.js -sENVIRONMENT=worker,web -sASSERTIONS=1 -sLLD_REPORT_UNDEFINED -sALLOW_TABLE_GROWTH -sALLOW_MEMORY_GROWTH -sEXPORTED_FUNCTIONS=$EXPORTED_FUNCS -sEXPORTED_RUNTIME_METHODS=$RUNTIME_METHODS" #clean output dir rm -rf $OUT_DIR diff --git a/client/javascript/main.js b/client/javascript/main.js index f42596b..fc8b6f8 100644 --- a/client/javascript/main.js +++ b/client/javascript/main.js @@ -16,12 +16,8 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ -if (typeof window === "undefined") { - throw new Error("NodeJS is not supported. This only works inside the browser."); -} - //everything is wrapped in a function to prevent emscripten from polluting the global scope -window.libcurl = (function() { +const libcurl = (function() { //emscripten compiled code is inserted here /* __emscripten_output__ */ diff --git a/client/libcurl/main.c b/client/libcurl/main.c index f085d7a..249cd24 100644 --- a/client/libcurl/main.c +++ b/client/libcurl/main.c @@ -192,6 +192,8 @@ void finish_request(CURLMsg *curl_msg) { void init_curl() { curl_global_init(CURL_GLOBAL_DEFAULT); multi_handle = curl_multi_init(); + curl_multi_setopt(multi_handle, CURLMOPT_MAX_TOTAL_CONNECTIONS, 50L); + curl_multi_setopt(multi_handle, CURLMOPT_MAXCONNECTS, 40L); FILE* file = fopen("/cacert.pem", "wb"); fwrite(_cacert_pem, 1, _cacert_pem_len, file); diff --git a/client/package.json b/client/package.json index 47caa58..d14d66f 100644 --- a/client/package.json +++ b/client/package.json @@ -1,6 +1,6 @@ { "name": "libcurl.js", - "version": "0.3.3", + "version": "0.3.4", "description": "An experimental port of libcurl to WebAssembly for use in the browser.", "main": "libcurl.mjs", "scripts": { diff --git a/server/wisp_server b/server/wisp_server index 65d3124..3b0d432 160000 --- a/server/wisp_server +++ b/server/wisp_server @@ -1 +1 @@ -Subproject commit 65d312414aa896d8f9e18f48e8fe37b72d75ee5c +Subproject commit 3b0d432e89cff7eaa850ba8605b180189e237f1b From b0314bf8cb1eaa9d4ada4fa3b17f35950c3c7b60 Mon Sep 17 00:00:00 2001 From: ading2210 Date: Mon, 26 Feb 2024 23:03:23 -0500 Subject: [PATCH 2/4] fix es6 module not getting built properly --- client/build.sh | 2 +- client/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/build.sh b/client/build.sh index 1ef82b5..1dcd95c 100755 --- a/client/build.sh +++ b/client/build.sh @@ -91,4 +91,4 @@ python3 tools/patch_js.py $FRAGMENTS_DIR $OUT_FILE #generate es6 module cp $OUT_FILE $ES6_FILE -sed -i 's/window.libcurl/export const libcurl/' $ES6_FILE \ No newline at end of file +sed -i 's/const libcurl/export const libcurl/' $ES6_FILE \ No newline at end of file diff --git a/client/package.json b/client/package.json index d14d66f..73f8b3b 100644 --- a/client/package.json +++ b/client/package.json @@ -1,6 +1,6 @@ { "name": "libcurl.js", - "version": "0.3.4", + "version": "0.3.5", "description": "An experimental port of libcurl to WebAssembly for use in the browser.", "main": "libcurl.mjs", "scripts": { From cc4009a4afef56e3f9005b75386d24ff1e582b68 Mon Sep 17 00:00:00 2001 From: ading2210 Date: Mon, 26 Feb 2024 23:13:55 -0500 Subject: [PATCH 3/4] fix sed expression again --- client/build.sh | 2 +- client/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/build.sh b/client/build.sh index 1dcd95c..3effa33 100755 --- a/client/build.sh +++ b/client/build.sh @@ -91,4 +91,4 @@ python3 tools/patch_js.py $FRAGMENTS_DIR $OUT_FILE #generate es6 module cp $OUT_FILE $ES6_FILE -sed -i 's/const libcurl/export const libcurl/' $ES6_FILE \ No newline at end of file +sed -i 's/const libcurl = /export const libcurl = /' $ES6_FILE \ No newline at end of file diff --git a/client/package.json b/client/package.json index 73f8b3b..80bfb0c 100644 --- a/client/package.json +++ b/client/package.json @@ -1,6 +1,6 @@ { "name": "libcurl.js", - "version": "0.3.5", + "version": "0.3.6", "description": "An experimental port of libcurl to WebAssembly for use in the browser.", "main": "libcurl.mjs", "scripts": { From b5aff5b0857f2fa1c3501d5649dd01f4f0f5c82e Mon Sep 17 00:00:00 2001 From: ading2210 Date: Tue, 27 Feb 2024 11:38:00 -0800 Subject: [PATCH 4/4] pin library versions, load cacert from blob --- client/index.html | 2 +- client/libcurl/main.c | 14 +++++++------- client/package.json | 2 +- client/tools/brotli.sh | 2 +- client/tools/cjson.sh | 2 +- client/tools/curl.sh | 2 +- client/tools/nghttp2.sh | 2 +- client/tools/openssl.sh | 2 +- client/tools/zlib.sh | 2 +- 9 files changed, 15 insertions(+), 15 deletions(-) diff --git a/client/index.html b/client/index.html index 9760e4c..8555276 100644 --- a/client/index.html +++ b/client/index.html @@ -6,7 +6,7 @@ diff --git a/client/libcurl/main.c b/client/libcurl/main.c index 249cd24..4f5578a 100644 --- a/client/libcurl/main.c +++ b/client/libcurl/main.c @@ -19,9 +19,10 @@ void finish_request(CURLMsg *curl_msg); CURLM *multi_handle; int request_active = 0; +struct curl_blob cacert_blob; -int write_function(void *data, size_t size, size_t nmemb, DataCallback data_callback) { - long real_size = size * nmemb; +size_t write_function(void *data, size_t size, size_t nmemb, DataCallback data_callback) { + size_t real_size = size * nmemb; char* chunk = malloc(real_size); memcpy(chunk, data, real_size); data_callback(chunk, real_size); @@ -53,8 +54,7 @@ CURL* start_request(const char* url, const char* json_params, DataCallback data_ int prevent_cleanup = 0; curl_easy_setopt(http_handle, CURLOPT_URL, url); - curl_easy_setopt(http_handle, CURLOPT_CAINFO, "/cacert.pem"); - curl_easy_setopt(http_handle, CURLOPT_CAPATH, "/cacert.pem"); + curl_easy_setopt(http_handle, CURLOPT_CAINFO_BLOB , cacert_blob); //callbacks to pass the response data back to js curl_easy_setopt(http_handle, CURLOPT_WRITEFUNCTION, &write_function); @@ -195,7 +195,7 @@ void init_curl() { curl_multi_setopt(multi_handle, CURLMOPT_MAX_TOTAL_CONNECTIONS, 50L); curl_multi_setopt(multi_handle, CURLMOPT_MAXCONNECTS, 40L); - FILE* file = fopen("/cacert.pem", "wb"); - fwrite(_cacert_pem, 1, _cacert_pem_len, file); - fclose(file); + cacert_blob.data = _cacert_pem; + cacert_blob.len = _cacert_pem_len; + cacert_blob.flags = CURL_BLOB_NOCOPY; } \ No newline at end of file diff --git a/client/package.json b/client/package.json index 80bfb0c..d85ef44 100644 --- a/client/package.json +++ b/client/package.json @@ -1,6 +1,6 @@ { "name": "libcurl.js", - "version": "0.3.6", + "version": "0.3.7", "description": "An experimental port of libcurl to WebAssembly for use in the browser.", "main": "libcurl.mjs", "scripts": { diff --git a/client/tools/brotli.sh b/client/tools/brotli.sh index 1210f4b..c9cba4a 100755 --- a/client/tools/brotli.sh +++ b/client/tools/brotli.sh @@ -10,7 +10,7 @@ PREFIX=$(realpath build/brotli-wasm) cd build rm -rf brotli -git clone -b master --depth=1 https://github.com/google/brotli +git clone -b v1.1.0 --depth=1 https://github.com/google/brotli cd brotli emcmake cmake . -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=./installed diff --git a/client/tools/cjson.sh b/client/tools/cjson.sh index acf7290..5cdfc1e 100755 --- a/client/tools/cjson.sh +++ b/client/tools/cjson.sh @@ -11,7 +11,7 @@ mkdir -p $PREFIX cd build rm -rf cjson -git clone -b master --depth=1 https://github.com/DaveGamble/cJSON cjson +git clone -b v1.7.17 --depth=1 https://github.com/DaveGamble/cJSON cjson cd cjson sed -i 's/-fstack-protector-strong//' Makefile diff --git a/client/tools/curl.sh b/client/tools/curl.sh index 7f4afa0..cf286a5 100755 --- a/client/tools/curl.sh +++ b/client/tools/curl.sh @@ -14,7 +14,7 @@ NGHTTP2_PREFIX=$(realpath build/nghttp2-wasm) cd build rm -rf curl -git clone -b master --depth=1 https://github.com/curl/curl +git clone -b curl-8_6_0 --depth=1 https://github.com/curl/curl cd curl autoreconf -fi diff --git a/client/tools/nghttp2.sh b/client/tools/nghttp2.sh index e9c86eb..58a5aba 100755 --- a/client/tools/nghttp2.sh +++ b/client/tools/nghttp2.sh @@ -10,7 +10,7 @@ PREFIX=$(realpath build/nghttp2-wasm) cd build rm -rf nghttp2 -git clone -b master --depth=1 https://github.com/nghttp2/nghttp2 +git clone -b v1.59.0 --depth=1 https://github.com/nghttp2/nghttp2 cd nghttp2 rm -rf $PREFIX diff --git a/client/tools/openssl.sh b/client/tools/openssl.sh index dc8a041..014f5c3 100755 --- a/client/tools/openssl.sh +++ b/client/tools/openssl.sh @@ -11,7 +11,7 @@ mkdir -p $PREFIX cd build rm -rf openssl -git clone -b master --depth=1 https://github.com/openssl/openssl +git clone -b openssl-3.2.1 --depth=1 https://github.com/openssl/openssl cd openssl export CFLAGS="-Wall -Oz" diff --git a/client/tools/zlib.sh b/client/tools/zlib.sh index 624246e..10c7bd1 100755 --- a/client/tools/zlib.sh +++ b/client/tools/zlib.sh @@ -10,7 +10,7 @@ PREFIX=$(realpath build/zlib-wasm) cd build rm -rf zlib -git clone -b master --depth=1 https://github.com/madler/zlib +git clone -b v1.3.1 --depth=1 https://github.com/madler/zlib cd zlib emconfigure ./configure --static