Skip to content

Commit

Permalink
feat(gateway): improve build and test (#7)
Browse files Browse the repository at this point in the history
* refactor: remove coordinator debug log
* hack: add symlinks cmd/xtrellis/{groups,servers}.json -> ../coordinator/{groups,servers}.json
* chore(xtrellis): gitignore exclude {groups,servers}.json
* chore: gitignore cmd/coordinator/res.json{,.csv}
* feat(bin): test-gateway-io.sh: gateway host/port as params
* feat(bin): add run-coordinator-gateway
* feat(docker): install netcat for gateway test scripts
* feat(docker-compose): add xtrellis-test-gateway service in test profile
* chore(docker): sync dockerignore with gitignore
* refactor(gateway): log message data stats (but not actual data) to terminal
* docs(xtrellis): update README with prereqs, build, test
* docs(bin): test-gateway-io.sh: update comments
* feat(utils): add DebugCaller option with flag
* refactor(gateway): improve and conform log messages
* feat(bin): test-gateway-io.sh: exit with status
* feat(xtrellis): change default MessageSize
* refactor: remove xtrellis/bin/run-coordinator-gateway.sh
* docs(xtrellis): more detailed build and run gateway
* chore(go): update pb version
* ci(test): replace test of `./...` with `./xtrellis/...`
* ci(test): add `--profile test-gateway` to docker-compose
* feat(bin): add test-gateway-ci.sh
* feat(docker-compose): replace multi-line command with `./bin/test-gateway-ci.sh`
  • Loading branch information
xendarboh committed Oct 11, 2023
1 parent 5741da8 commit 506ea31
Show file tree
Hide file tree
Showing 17 changed files with 201 additions and 53 deletions.
26 changes: 26 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
.env
.git
cmd/*/*.log
cmd/*/*.pprof
cmd/certificates/*.key
cmd/certificates/*.pem
cmd/client/client
cmd/coordinator/clients.json
cmd/coordinator/coordinator
cmd/coordinator/groups.json
cmd/coordinator/keys.json
cmd/coordinator/messages.json
cmd/coordinator/res.json
cmd/coordinator/res.json.csv
cmd/coordinator/servers.json
cmd/experiments/*.list
cmd/server/server
cmd/simulation/simulation
cmd/testnet2/testnet2
cmd/xtrellis/clients.json
cmd/xtrellis/keys.json
cmd/xtrellis/messages.json
cmd/xtrellis/res.json
cmd/xtrellis/res.json.csv
cmd/xtrellis/xtrellis
coordinator/*.pprof
coordinator/*.prof
docker-compose.yml
errors/*.log
pb/gen
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ jobs:
run: docker build -t trellis-test .

- name: Run Go Tests
run: docker run trellis-test go test ./...
run: docker run trellis-test go test ./xtrellis/...

- name: Docker Compose Test
- name: Docker Compose Test Gateway
run: |
docker-compose -f docker-compose.yml up --build --abort-on-container-exit
docker-compose -f docker-compose.yml --profile test-gateway up --build --abort-on-container-exit
# Add other jobs here if needed
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ cmd/coordinator/groups.json
cmd/coordinator/clients.json
cmd/coordinator/keys.json
cmd/coordinator/messages.json
cmd/coordinator/res.json
cmd/coordinator/res.json.csv
cmd/certificates/*.pem
cmd/certificates/*.key
coordinator/*.pprof
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ RUN apt update \
git \
libgmp-dev \
libssl-dev \
netcat \
sudo \
unzip \
wget \
Expand Down
3 changes: 3 additions & 0 deletions cmd/xtrellis/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
*.json
!groups.json
!servers.json

xtrellis
86 changes: 86 additions & 0 deletions cmd/xtrellis/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,89 @@
# 0KN

## xtrellis

A single executable to launch mix-net components including coordinator, servers, clients, and gateway.

## Prerequisites

Install the following:

- latest stable version of [go](https://go.dev/doc/install) (`>= 1.21.1`)
- [Protocol Buffer Compiler](https://grpc.io/docs/protoc-installation/)
- [Buf](https://buf.build/docs/installation)
- [Trellis dependencies](/README.md#dependencies)
- except for "_go files_", which we'll build after `pb/` (see below)

Utilities used by test scripts:

- netcat
- wget

## Build

Generate code from protocol buffers:

```sh
cd pb && go mod download && go mod verify
buf generate
cd ..
```

Build trellis `server`, `client`, `coordinator`:

```sh
go mod download && go mod verify
cd cmd/server && go install && go build
cd ../client && go install && go build
cd ../coordinator && go install && go build
```

Build `xtrellis`:

```sh
cd ../xtrellis
go install && go build
```

## Test Gateway

From the xtrellis directory `cmd/xtrellis/`,

Run a coordinated local mix-net with gateway enabled, for example:

```sh
./xtrellis coordinator --gatewayenable --debug
```

Then, in a separate terminal:

Send `100KB` random data through the mix-net and compare data in to data out:

```sh
./bin/test-gateway-io.sh 102400
```

Pipe generic data through the mix-net:

```sh
cat in.png | ./bin/test-gateway-pipe.sh > out.png
```

### With Docker Compose

From project root:

```sh
# build container
docker compose --profile test-gateway build

# run gateway test
docker compose --profile test-gateway up

# remove container
docker compose --profile test-gateway down
```

## Network Data Flow

The Gateway:
Expand Down
19 changes: 19 additions & 0 deletions cmd/xtrellis/bin/test-gateway-ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

set -ex

./xtrellis \
coordinator \
--gatewayenable \
--debug \
&

xtrellis_pid=$!

sleep 10s

./bin/test-gateway-io.sh 102400

kill -s SIGTERM ${xtrellis_pid}

exit 0
14 changes: 9 additions & 5 deletions cmd/xtrellis/bin/test-gateway-io.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#!/bin/bash

# Test transmission of data streams through mix-net by means of gateway proxy i/o

# Example coordinated local mix-net invocation before running this:
# ./xtrellis coordinator --messagesize 120 --numlayers 5 --numusers 3 --roundinterval 1 --gatewayenable --debug
# First start a coordinated local mix-net with gateway enabled. See README.

set -e

# bytes of data to send through the mix-net (default 10K)
DATA_SIZE=${1:-10240}

GATEWAY_HOST=${2:-localhost}
GATEWAY_PORT_IN=${3:-9000}
GATEWAY_PORT_OUT=${4:-9900}

cd /tmp
rm -f data.{in,out}

Expand All @@ -18,14 +20,16 @@ cat /dev/urandom | head -c ${DATA_SIZE} > data.in
# dd if=/dev/urandom of=data.in bs=1024 count=10 &>/dev/null

# file -> gateway -> [mix-net]
cat data.in | nc -q 1 localhost 9000
cat data.in | nc -q 1 ${GATEWAY_HOST} ${GATEWAY_PORT_IN}

# [mix-net] -> gateway -> file
wget -O data.out -q http://localhost:9900 || echo "not found"
wget -O data.out -q http://${GATEWAY_HOST}:${GATEWAY_PORT_OUT} || echo "not found"

# compare data input to output
if diff -q data.in data.out &>/dev/null; then
echo "Success!"
exit 0
else
echo "Fail!"
exit 1
fi
1 change: 1 addition & 0 deletions cmd/xtrellis/groups.json
1 change: 1 addition & 0 deletions cmd/xtrellis/servers.json
8 changes: 5 additions & 3 deletions cmd/xtrellis/xtrellis.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ import (
)

type Args struct {
Mode string `arg:"positional,required" help:"execution mode: coordinator, server, or client"`
Debug bool `default:"False" help:"enable debug log output"`
Mode string `arg:"positional,required" help:"execution mode: coordinator, server, or client"`
Debug bool `default:"False" help:"enable debug log output"`
DebugCaller bool `default:"False" help:"with debug enabled, print calling function's info"`

////////////////////////////////////
// files
Expand Down Expand Up @@ -50,7 +51,7 @@ type Args struct {
RunType int `default:"1"`
NumUsers int `default:"100" help:"also NumMessages"`
NumServers int `default:"10"`
MessageSize int `default:"1024"`
MessageSize int `default:"128"` // TODO: default 1024 after dynamic gateway packet header

NumGroups int `default:"3"`
GroupSize int `default:"3"`
Expand Down Expand Up @@ -432,6 +433,7 @@ func main() {
p := arg.MustParse(&args)

utils.SetDebugLogEnabled(args.Debug)
utils.SetDebugLogCallerEnabled(args.DebugCaller)

switch args.Mode {
case "coordinator":
Expand Down
4 changes: 0 additions & 4 deletions coordinator/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/31333337/trellis/errors"
"github.com/31333337/trellis/server/prepareMessages"
"github.com/31333337/trellis/xtrellis/gateway"
"github.com/31333337/trellis/xtrellis/utils"
)

// The coordinator simulates the glocal clock time when the round begins, the time when receipts should have been received by, etc.
Expand Down Expand Up @@ -147,7 +146,6 @@ func (c *Coordinator) DoAction(exp *Experiment) error {
return err
}
}
utils.DebugLog("exp.Info. PathEstablishment=%t; ReceiptLayer=%d; Round=%d", exp.Info.PathEstablishment, exp.Info.ReceiptLayer, exp.Info.Round)
if exp.Info.PathEstablishment {
if exp.Info.ReceiptLayer == 0 && exp.Info.Round != 0 {
err := c.Net.CheckClientReceipt(exp.Info, exp.NumMessages)
Expand Down Expand Up @@ -185,9 +183,7 @@ func (c *Coordinator) DoAction(exp *Experiment) error {
}

if gateway.Enable {
// give final messages to gateway and check them
exp.Passed = gateway.CheckFinalMessages(messages, exp.NumMessages)
utils.DebugLog("exp.Passed = gateway.CheckFinalMessages = %t", exp.Passed)
} else {
exp.Passed = c.Check(messages, exp.NumMessages)
}
Expand Down
17 changes: 7 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,16 @@ services:
profiles: ["build"]
image: ${IMG_REPO}/${IMG_NAME}:${IMG_TAG}
init: true
restart: unless-stopped
build:
context: ./

server-0:
profiles: ["run"]
xtrellis-test-gateway:
profiles: ["test-gateway"]
extends:
service: base
container_name: server-0
container_name: xtrellis-test-gateway
expose:
- 8000
command: >
./cmd/server/server
./cmd/coordinator/servers.json
./cmd/coordinator/groups.json
localhost:8000
- 9000
- 9900
working_dir: /opt/trellis/cmd/xtrellis
command: ./bin/test-gateway-ci.sh
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
filippo.io/edwards25519 v1.0.0
github.com/alexflint/go-arg v1.4.3
github.com/gonum/stat v0.0.0-20181125101827-41a0da705a5b
github.com/31333337/trellis/pb v0.0.0-20231007205846-8bd30e009506
github.com/31333337/trellis/pb v0.0.0-20231011004659-5741da8a64a2
github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a
go.dedis.ch/kyber/v3 v3.1.0
golang.org/x/crypto v0.14.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/31333337/trellis/pb v0.0.0-20231007205846-8bd30e009506 h1:8JNZVPaPAaODJNENDTDLQ3Lo9dt28g6G1W6cFuVJxDc=
github.com/31333337/trellis/pb v0.0.0-20231007205846-8bd30e009506/go.mod h1:t9N2TWH9o5oHOqZNB7MI62nHUKKtwJ2qaxHg0daxEmo=
github.com/31333337/trellis/pb v0.0.0-20231011004659-5741da8a64a2 h1:149++5damqHKj3xK2qcZPsEGSggiimCwDraz0eOceHU=
github.com/31333337/trellis/pb v0.0.0-20231011004659-5741da8a64a2/go.mod h1:mzEZvbGzQ3XZWpzFVAoKTlA0TY/EAfR5+X2ifhm634M=
github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a h1:dlRvE5fWabOchtH7znfiFCcOvmIYgOeAS5ifBXBlh9Q=
github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a/go.mod h1:hVoHR2EVESiICEMbg137etN/Lx+lSrHPTD39Z/uE+2s=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
Loading

0 comments on commit 506ea31

Please sign in to comment.