-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathquickstart.sh
More file actions
executable file
·171 lines (138 loc) · 4.91 KB
/
quickstart.sh
File metadata and controls
executable file
·171 lines (138 loc) · 4.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/usr/bin/env bash
SESSION_NAME="unbounded-sandbox"
FREDDIE_DEFAULT=http://localhost:9000
EGRESS_DEFAULT=http://localhost:8000
NETSTATE_DEFAULT=http://localhost:8080/exec
PROXYPORT_DEFAULT=1080
usage () {
echo "Usage: $0 run_type [peers]"
echo " options:"
echo " run_type: local | ui | derek | egress"
echo " peers: number of peers (only for derek), default is 2"
echo " example:"
echo " $0 local"
echo " $0 ui"
echo " $0 derek 5"
exit 1
}
if [ $# -ne 1 ]; then
usage;
fi
create_tmux_session() {
local session_name=$1
shift
local commands=("$@")
tmux new-session -d -s "$session_name"
# make panes for each command, and set the layout
for i in "${!commands[@]}"; do
tmux split-window
tmux select-layout tiled
done
# Send commands to each pane
for i in "${!commands[@]}"; do
tmux select-pane -t $(( i + 1 ))
tmux send-keys "${commands[$i]}" C-m
done
tmux select-pane -t 0
chmod +x quickstop.sh
tmux send-keys "./quickstop.sh" C-m
# Attach to the tmux session
tmux attach-session -t "$session_name"
}
declare peers
default_peers=2
if [ "$1" == "derek" ]; then
if [ -z "$2" ]; then
echo "no number of peers specified, using default $default_peers"
peers=$default_peers
else
peers=$2
echo "Using $peers peers"
fi
fi
#build binaries then return to the right directory
cd cmd
./build.sh desktop
./build.sh widget
cd ..
# Default commands that are used in many options
# start freddie for matchmaking
freddie_start="PORT=9000 go run ./freddie/cmd/main.go"
# Start egress server
egress_start="PORT=8000 go run ./egress/cmd/egress.go"
# Start desktop proxy for outgoing connections with websocket
desktop_start="TAG=bob NETSTATED=$NETSTATE_DEFAULT FREDDIE=$FREDDIE_DEFAULT EGRESS=$EGRESS_DEFAULT PORT=$PROXYPORT_DEFAULT ./cmd/dist/bin/desktop"
# build and start native binary widget
widget_start="TAG=alice NETSTATED=$NETSTATE_DEFAULT FREDDIE=$FREDDIE_DEFAULT EGRESS=$EGRESS_DEFAULT ./cmd/dist/bin/widget"
# start netstate
netstate_start="cd netstate/d && UNSAFE=1 go run ."
# different sequences of commands for different run options
# 'derek' option starts a specified number of censored peers
derek_commands=(
"$netstate_start"
"$freddie_start"
"$egress_start"
"$widget_start"
# build and start up a number of censored peers
"cd cmd && ./build.sh desktop && TAG=bob NETSTATED=$NETSTATE_DEFAULT FREDDIE=$FREDDIE_DEFAULT EGRESS=$EGRESS_DEFAULT ./derek.sh $peers"
)
# Starts all the pieces of unbounded locally with websockets, which can be used by
# setting firefoxy to use '127.0.0.1:1080' for http and https
local_commands=(
"$netstate_start"
"$freddie_start"
"$egress_start"
"$desktop_start"
"$widget_start"
)
# Starts the UI
ui_commands=(
"$netstate_start"
"$freddie_start"
"$egress_start"
# Build web widget and start ui
"cd cmd && ./build_web.sh && cd ../ui && yarn && cp .env.development.example .env.development && yarn dev:web"
)
# start everything except egress, useful for testing egress server without restarting the other components
# to use run an egress server separately at localhost:8000
custom_egress_commands=(
"$netstate_start"
"$freddie_start"
"$desktop_start"
"$widget_start"
)
# Start everything for webtransports
wt_commands=(
# start netstate
"$netstate_start"
# start freddie for matchmaking
"$freddie_start"
#start egress server pointed to keys created below
"TLS_CERT=localhost.crt TLS_KEY=localhost.key PORT=8000 go run ./egress/cmd/egress.go"
# Start desktop proxy with webtransports enabled, and pointed to the correct certs
"WEBTRANSPORT=1 CA=localhost.crt SERVER_NAME=localhost EGRESS=https://localhost:8001 TAG=bob NETSTATED=$NETSTATE_DEFAULT FREDDIE=$FREDDIE_DEFAULT PORT=$PROXYPORT_DEFAULT ./cmd/dist/bin/desktop"
# build and start native binary widget with webtransports enabled
"WEBTRANSPORT=1 CA=localhost.crt EGRESS=https://localhost:8001 TAG=alice NETSTATED=$NETSTATE_DEFAULT FREDDIE=$FREDDIE_DEFAULT ./cmd/dist/bin/widget"
)
if [ "$1" == "derek" ]; then
echo "Using 'derek' option"
commands=("${derek_commands[@]}")
elif [ "$1" == "local" ]; then
echo "Using local option"
commands=("${local_commands[@]}")
elif [ "$1" == "ui" ]; then
echo "Using ui option"
commands=("${ui_commands[@]}")
elif [ "$1" == "egress" ]; then
echo "Using custom egress option"
commands=("${custom_egress_commands[@]}")
elif [ "$1" == "wt" ]; then
#create a self-signed certificate for localhost
openssl req -x509 -newkey rsa:2048 -nodes -keyout localhost.key -out localhost.crt -subj '/CN=localhost' -addext 'subjectAltName = DNS:localhost'
echo "Using webtransports option"
commands=("${wt_commands[@]}")
else
echo "Unknown option $1";
usage;
fi
create_tmux_session "$SESSION_NAME" "${commands[@]}";