test-local.sh raw
1 #!/bin/sh
2 # Local end-to-end test: relay + smesh3 + bridge + mailpit
3 # Usage: ./test-local.sh [--latency MS] [--jitter MS]
4 # Then open: http://127.0.0.1:8090 (smesh) and http://127.0.0.1:8025 (mailpit)
5 set -e
6 cd "$(dirname "$0")"
7
8 DATADIR=/tmp/orly-test
9 BRIDGEDIR="$HOME/.config/orly-bridge-test"
10 mkdir -p "$DATADIR" "$BRIDGEDIR"
11
12 # Parse --latency and --jitter
13 LATENCY=0
14 JITTER=0
15 while [ $# -gt 0 ]; do
16 case "$1" in
17 --latency) LATENCY="$2"; shift 2 ;;
18 --jitter) JITTER="$2"; shift 2 ;;
19 *) shift ;;
20 esac
21 done
22
23 PID_PROXY=""
24 cleanup() {
25 echo "shutting down..."
26 kill $PID_ORLY $PID_BRIDGE $PID_MAILPIT $PID_PROXY 2>/dev/null
27 wait 2>/dev/null
28 }
29 trap cleanup EXIT INT TERM
30
31 # 1. mailpit — catches all outbound email (web UI on :8025, SMTP on :25)
32 echo "starting mailpit on :25 (SMTP) and :8025 (web UI)..."
33 sudo "$HOME/.local/bin/mailpit" --smtp 127.0.0.1:25 --listen 127.0.0.1:8025 &
34 PID_MAILPIT=$!
35 sleep 1
36
37 # 2. orly — relay on :3334, smesh3 on :8090
38 echo "starting orly (relay :3334, smesh3 :8090)..."
39 ORLY_DATA_DIR="$DATADIR" \
40 ORLY_LISTEN=127.0.0.1 \
41 ORLY_SMESH3_DIR="$PWD/app/smesh3" \
42 ORLY_SMESH3_PORT=8090 \
43 ORLY_LOG_LEVEL=info \
44 /tmp/orly-local &
45 PID_ORLY=$!
46 sleep 2
47
48 # 2b. latency proxy (optional)
49 BRIDGE_RELAY_PORT=3334
50 if [ "$LATENCY" -gt 0 ] 2>/dev/null; then
51 echo "starting latency proxy on :3335 -> :3334 (${LATENCY}ms +${JITTER}ms jitter)..."
52 python3 test/latency_proxy.py --listen 127.0.0.1:3335 --target 127.0.0.1:3334 \
53 --latency "$LATENCY" --jitter "$JITTER" &
54 PID_PROXY=$!
55 sleep 1
56 BRIDGE_RELAY_PORT=3335
57 fi
58
59 # 3. bridge — standalone, connects to local relay (or proxy)
60 echo "starting bridge (relay ws://127.0.0.1:$BRIDGE_RELAY_PORT, domain bridge.test)..."
61 ORLY_BRIDGE_DOMAIN=bridge.test \
62 ORLY_BRIDGE_RELAY_URL=ws://127.0.0.1:$BRIDGE_RELAY_PORT \
63 ORLY_BRIDGE_PUBLIC_RELAY_URL=ws://127.0.0.1:$BRIDGE_RELAY_PORT \
64 ORLY_BRIDGE_SMTP_PORT=2525 \
65 ORLY_BRIDGE_SMTP_HOST=127.0.0.1 \
66 ORLY_BRIDGE_SMTP_RELAY_HOST=127.0.0.1 \
67 ORLY_BRIDGE_SMTP_RELAY_PORT=2525 \
68 ORLY_BRIDGE_DATA_DIR="$BRIDGEDIR" \
69 ORLY_LOG_LEVEL=debug \
70 /tmp/orly-local bridge &
71 PID_BRIDGE=$!
72 sleep 2
73
74 # Print bridge identity
75 if [ -f "$BRIDGEDIR/bridge.nsec" ]; then
76 echo ""
77 echo "=== bridge identity ==="
78 cat "$BRIDGEDIR/bridge.nsec"
79 echo ""
80 fi
81
82 echo ""
83 echo "=== ready ==="
84 echo "smesh: http://127.0.0.1:8090"
85 echo "mailpit: http://127.0.0.1:8025"
86 echo "relay: ws://127.0.0.1:3334"
87 if [ "$LATENCY" -gt 0 ] 2>/dev/null; then
88 echo "proxy: ws://127.0.0.1:3335 (${LATENCY}ms +${JITTER}ms)"
89 fi
90 echo "bridge: npub14jr5zjp8ahx8jqsxcuh6xym256gaqy4gvljzlsa9fzpsnyhsftaq0dt3gd"
91 echo ""
92 echo "DM the bridge npub above. Send 'status' or 'subscribe' to start."
93 echo "Press Ctrl+C to stop all services."
94 wait
95