Fork @iov/socket (#250)
* socket: Fork @iov/socket * socket: Remove nonces * socket: Update package.json * socket: Update README * socket: Remove tslint * socket: Fix lint warnings * scripts: Fork socketserver from IOV Core * root: Update NOTICE for socket * tendermint-rpc: Replace @iov/socket dependency with @cosmjs/socket * root: Update CI config for tendermint/socket * scripts: Add wait to tendermint start script * socket: Add coverage
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
FROM python:3.7-alpine
|
||||
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
COPY echo.py ./
|
||||
RUN pip install websockets
|
||||
|
||||
ENTRYPOINT ["python", "./echo.py"]
|
||||
Executable
+50
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env python3
|
||||
#pylint:disable=missing-docstring,invalid-name
|
||||
|
||||
import argparse
|
||||
import asyncio
|
||||
import websockets
|
||||
import sys
|
||||
import time
|
||||
|
||||
HOST = "0.0.0.0"
|
||||
|
||||
def log(data):
|
||||
print(data, flush=True)
|
||||
|
||||
@asyncio.coroutine
|
||||
def connection_handler(connection, path):
|
||||
connection_id = hex(id(connection))
|
||||
log("{} opened connection via {}".format(connection_id, path))
|
||||
try:
|
||||
while True:
|
||||
incoming_message = yield from connection.recv()
|
||||
log("< {}".format(incoming_message))
|
||||
outgoing_message = incoming_message
|
||||
yield from connection.send(outgoing_message)
|
||||
log("> {}".format(outgoing_message))
|
||||
except websockets.exceptions.ConnectionClosed:
|
||||
log("{} closed connection".format(connection_id))
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--port",
|
||||
help="Port to listen on",
|
||||
type=int,
|
||||
default=4000)
|
||||
parser.add_argument("--delay",
|
||||
help="Time in seconds that a connection will be delayed before establishing it",
|
||||
type=int,
|
||||
default=0)
|
||||
args = parser.parse_args()
|
||||
|
||||
def delaying_process_request(path, request_headers):
|
||||
time.sleep(args.delay)
|
||||
return None
|
||||
|
||||
log("Starting server at {}:{}".format(HOST, args.port))
|
||||
server = websockets.serve(connection_handler, HOST, args.port, process_request=delaying_process_request)
|
||||
log("Running now.")
|
||||
|
||||
asyncio.get_event_loop().run_until_complete(server)
|
||||
asyncio.get_event_loop().run_forever()
|
||||
Executable
+37
@@ -0,0 +1,37 @@
|
||||
#!/bin/bash
|
||||
set -o errexit -o nounset -o pipefail
|
||||
command -v shellcheck > /dev/null && shellcheck "$0"
|
||||
|
||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
SOCKETSERVER_DIR=$(mktemp -d "${TMPDIR:-/tmp}/socketserver.XXXXXXXXX")
|
||||
export SOCKETSERVER_DIR
|
||||
echo "SOCKETSERVER_DIR = $SOCKETSERVER_DIR"
|
||||
|
||||
NAME_DEFAULT="socketserver-default"
|
||||
NAME_SLOW="socketserver-slow"
|
||||
|
||||
LOGFILE_DEFAULT="${SOCKETSERVER_DIR}/socketserver_4444.log"
|
||||
LOGFILE_SLOW="${SOCKETSERVER_DIR}/socketserver_4445.log"
|
||||
|
||||
docker build -t "socketserver:local" "$SCRIPT_DIR"
|
||||
|
||||
docker run --rm \
|
||||
--user="$UID" \
|
||||
--name "$NAME_DEFAULT" \
|
||||
-p "4444:4000" \
|
||||
socketserver:local \
|
||||
--delay 0 \
|
||||
> "$LOGFILE_DEFAULT" &
|
||||
docker run --rm \
|
||||
--user="$UID" \
|
||||
--name "$NAME_SLOW" \
|
||||
-p "4445:4000" \
|
||||
socketserver:local \
|
||||
--delay 5 \
|
||||
> "$LOGFILE_SLOW" &
|
||||
|
||||
# Debug start
|
||||
sleep 3
|
||||
cat "$LOGFILE_DEFAULT"
|
||||
cat "$LOGFILE_SLOW"
|
||||
Executable
+6
@@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
set -o errexit -o nounset -o pipefail
|
||||
command -v shellcheck > /dev/null && shellcheck "$0"
|
||||
|
||||
echo "Killing socketserver containers ..."
|
||||
docker container kill "socketserver-default" "socketserver-slow"
|
||||
Reference in New Issue
Block a user