Skip to content

Commit

Permalink
the changes without b64 stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
n-hutton committed Jan 18, 2024
1 parent 4768752 commit 6d71194
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 2 deletions.
14 changes: 12 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# escape=\

# Common dependencies of the builder and runner stages.
FROM ubuntu:22.04 AS base
FROM --platform=linux/amd64 ubuntu:22.04 AS base

RUN apt-get update -y

# Format guideline: one package per line and keep them alphabetically sorted
RUN apt-get update -y \
&& apt-get install -y software-properties-common \
Expand Down Expand Up @@ -92,6 +95,9 @@ COPY scilla.opam .
COPY shell.nix .
COPY .ocamlformat .
COPY tests/ tests
COPY handle_connection.sh .
COPY run_scilla_tcp.sh .
COPY write_files.py .

# Make sure vcpkg installs brings in the dependencies
RUN --mount=type=cache,target=/root/.cache/vcpkg/ ${VCPKG_ROOT}/vcpkg install --triplet=x64-linux-dynamic
Expand All @@ -115,10 +121,14 @@ RUN mkdir -p ${VCPKG_INSTALL_LIB_DIR} \
&& rm -rf vcpkg_installed \
&& ln -s ${BUILD_DIR}/vcpkg_installed vcpkg_installed

FROM ubuntu:22.04
FROM --platform=linux/amd64 ubuntu:22.04

RUN apt-get update -y \
&& apt-get install -y build-essential \
netcat-openbsd \
vim \
socat \
python3 \
libgmp-dev

ARG SOURCE_DIR="/scilla/${MAJOR_VERSION}"
Expand Down
27 changes: 27 additions & 0 deletions handle_connection.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

echo "Starting server." 1>&2

# Start scilla-server in the background
rm -rf /tmp/scilla-socket/server.sock
/scilla/0/bin/scilla-server -socket /tmp/scilla-socket/server.sock 1>&2 &

# Get the PID of scilla-server
SERVER_PID=$!

echo "forwarding traffic." 1>&2

# Block until we see the scilla server has provided the socket
while [ ! -S /tmp/scilla-socket/server.sock ]; do sleep 1; done

echo "forwarding other traffic." 1>&2

# Forward traffic from stdin (provided by socat) to Unix socket.
# Note this means we ONLY use stderr when echoing within this script to avoid it going to the socket
socat - UNIX-CONNECT:/tmp/scilla-socket/server.sock

echo "connection closed - killing" 1>&2
echo "" 1>&2

# Kill the scilla-server process when done
kill $SERVER_PID
21 changes: 21 additions & 0 deletions run_scilla_tcp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

echo "Starting server." 1>&2

rm -rf myfifo 1>&2
mkfifo myfifo 1>&2

# Clear the directories we will be using the files for
mkdir -p /tmp/scilla_init/
mkdir -p /tmp/scilla_input/

rm -rf /tmp/scilla_init/*
rm -rf /tmp/scilla_input/*

# netcat listen to 12346 and forward it to/from a local socket (this is the state queries/updates)
nc -lkv 12346 <myfifo | nc -lkUD /tmp/scilla-server.sock > myfifo &


# socat - every connection on 12345, run the script handle_connection and pipe the input to it (this is the initial run/create/etc commands)
socat TCP-LISTEN:12347,reuseaddr,fork EXEC:"/scilla/0/write_files.py",nofork &
socat TCP-LISTEN:12345,reuseaddr,fork EXEC:"/scilla/0/handle_connection.sh",nofork
32 changes: 32 additions & 0 deletions write_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python3

import sys
import os

def main():
# Read the input as binary data from stdin
input_data = sys.stdin.buffer.read()

# Split the input into a path and data
try:
path, data = input_data.split(b' ', 1)
except ValueError:
print("Invalid input format. Please provide a valid absolute path and data.")
sys.exit(1)

# Ensure the path is absolute
if not os.path.isabs(path.decode()):
print("Please provide an absolute path.")
sys.exit(1)

# Write binary data to the specified file
try:
with open(path.decode(), 'wb') as file:
file.write(data)
print(f"Data written to {path.decode()}")
except Exception as e:
print(f"Error writing data to {path.decode()}: {str(e)}")
sys.exit(1)

if __name__ == "__main__":
main()

0 comments on commit 6d71194

Please sign in to comment.