diff --git a/makefile b/makefile index 4f94d59b..dd259f52 100644 --- a/makefile +++ b/makefile @@ -20,6 +20,9 @@ ws_openssl: ws_mbedtls: mkdir -p build && (cd build ; cmake -DCMAKE_BUILD_TYPE=Debug -DUSE_TLS=1 -DUSE_WS=1 -DUSE_MBED_TLS=1 .. ; make -j 4) +ws_no_ssl: + mkdir -p build && (cd build ; cmake -DCMAKE_BUILD_TYPE=Debug -DUSE_WS=1 .. ; make -j 4) + uninstall: xargs rm -fv < build/install_manifest.txt diff --git a/ws/test_ws.sh b/ws/test_ws.sh index f5ff5543..a8d4f44e 100644 --- a/ws/test_ws.sh +++ b/ws/test_ws.sh @@ -1,21 +1,43 @@ -#!/bin/sh +#!/bin/bash # Handle Ctrl-C by killing all sub-processing AND exiting -trap cleanup INT +trap cleanup_and_exit INT -cleanup() { - kill `cat /tmp/ws_test/pidfile.transfer` - kill `cat /tmp/ws_test/pidfile.receive` - kill `cat /tmp/ws_test/pidfile.send` - exit 1 +function cleanup_and_exit { + local exit_code=${1:-1} + echo "cleaning up..." + echo + kill `cat /tmp/ws_test/pidfile.transfer` &>/dev/null + kill `cat /tmp/ws_test/pidfile.receive` &>/dev/null + kill `cat /tmp/ws_test/pidfile.send` &>/dev/null + exit ${exit_code} } +WITH_TLS=${WITH_TLS:-0} + rm -rf /tmp/ws_test mkdir -p /tmp/ws_test +client_tls='' +server_tls='' +protocol='ws://' +delay='--delay 10' +if [ "$WITH_TLS" == "1" ]; then + certs="/tmp/ws_test/certs" + ./generate_certs.sh "${certs}" + client_tls="--cert-file ${certs}/trusted-client-crt.pem" + client_tls="${client_tls} --key-file ${certs}/trusted-client-key.pem" + client_tls="${client_tls} --ca-file ${certs}/trusted-ca-crt.pem" + server_tls="--cert-file ${certs}/trusted-server-crt.pem" + server_tls="${server_tls} --key-file ${certs}/trusted-server-key.pem" + server_tls="${server_tls} --ca-file ${certs}/trusted-ca-crt.pem" + server_tls="${server_tls} --tls" + protocol='wss://' + delay='' +fi # Start a transport server cd /tmp/ws_test -ws transfer --port 8090 --pidfile /tmp/ws_test/pidfile.transfer & +ws transfer --port 8090 ${server_tls} --pidfile /tmp/ws_test/pidfile.transfer & # Wait until the transfer server is up while true @@ -31,14 +53,14 @@ done # Start a receiver mkdir -p /tmp/ws_test/receive cd /tmp/ws_test/receive -ws receive --delay 10 ws://127.0.0.1:8090 --pidfile /tmp/ws_test/pidfile.receive & +ws receive "${protocol}127.0.0.1:8090" ${delay} --pidfile /tmp/ws_test/pidfile.receive ${server_tls} & -mkdir /tmp/ws_test/send +mkdir -p /tmp/ws_test/send cd /tmp/ws_test/send -dd if=/dev/urandom of=20M_file count=20000 bs=1024 +dd if=/dev/urandom of=/tmp/ws_test/send/20M_file count=20000 bs=1024 # Start the sender job -ws send --pidfile /tmp/ws_test/pidfile.send ws://127.0.0.1:8090 20M_file +ws send ${client_tls} --pidfile /tmp/ws_test/pidfile.send "${protocol}127.0.0.1:8090" /tmp/ws_test/send/20M_file # Wait until the file has been written to disk while true @@ -58,7 +80,4 @@ cksum /tmp/ws_test/receive/20M_file sleep 2 # Cleanup -kill `cat /tmp/ws_test/pidfile.transfer` -kill `cat /tmp/ws_test/pidfile.receive` -kill `cat /tmp/ws_test/pidfile.send` -exit 0 +cleanup_and_exit 0