-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintergration.sh
More file actions
executable file
·181 lines (158 loc) · 3.42 KB
/
intergration.sh
File metadata and controls
executable file
·181 lines (158 loc) · 3.42 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
172
173
174
175
176
177
178
179
180
181
#!/bin/sh
set -eu
while IFS= read -r cmd; do
case "$cmd" in
'' | \#*)
continue
;;
esac
command -v "$cmd" >/dev/null || {
printf '%s not found\n' "$cmd" >&2
exit 127
}
done <<"EOF"
# build and observe tools
cargo
htop
pv
socat
tmux
# base utils
cat
cp
dirname
mktemp
rm
sed
EOF
SCRIPT_DIR=$(
CDPATH= cd -- "$(dirname -- "$0")" && pwd
)
SESSION="udp-bench"
HTOP_TEMP_DIR="$(mktemp -d)"
mkdir -p "$HTOP_TEMP_DIR/htop"
cleanup() {
if [ -d "$HTOP_TEMP_DIR" ]; then
rm -rf "$HTOP_TEMP_DIR"
fi
if tmux has-session -t "$SESSION" 2>/dev/null; then
tmux kill-session -t "$SESSION" 2>/dev/null
fi
}
trap cleanup EXIT
cp "$HOME/.config/htop/htoprc" "$HTOP_TEMP_DIR/htop/htoprc"
cat <<EOF >"$HTOP_TEMP_DIR/htop/htoprc"
config_reader_min_version=3
fields=48 0 18 39 40 46 47 49 53 1
highlight_base_name=1
highlight_deleted_exe=1
shadow_distribution_path_prefix=0
highlight_megabytes=1
highlight_threads=1
find_comm_in_cmdline=1
show_merged_command=1
show_thread_names=1
show_program_path=1
color_scheme=0
enable_mouse=1
delay=15
hide_function_bar=2
header_layout=one_100
column_meters_0=!
column_meter_modes_0=!
sort_key=46
sort_direction=-1
screen:Main=PID M_VIRT M_RESIDENT M_SHARE STATE PERCENT_CPU PERCENT_MEM TIME ELAPSED Command
.sort_key=PERCENT_CPU
.tree_sort_key=PERCENT_CPU
.tree_view_always_by_pid=0
.tree_view=0
.sort_direction=-1
.tree_sort_direction=-1
.all_branches_collapsed=0
EOF
buf_size=65487
method="xor"
io_uring=0
while getopts "b:s:i" opt; do
case "$opt" in
b)
case "$OPTARG" in
*[!0-9]* | "")
buf_size=65487
;;
*)
buf_size="$OPTARG"
;;
esac
;;
s)
case "$OPTARG" in
xor | dns)
method="$OPTARG"
;;
*)
method="xor"
;;
esac
;;
i)
io_uring=1
;;
\?)
exit 2
;;
esac
done
shift $((OPTIND - 1))
if [ $# -ne 0 ]; then
echo "unknow argument: $*" >&2
exit 2
fi
method_opt="-sxor"
mtu_size=$((buf_size + 48))
if [ "$method" = "dns" ]; then
method_opt="-sdnspad"
buf_size=$((buf_size - 56))
fi
(
cd "$SCRIPT_DIR" || exit 1
EXTRA_ARGS=""
if [ "$io_uring" -eq 1 ]; then
export RUSTFLAGS="--cfg tokio_unstable"
EXTRA_ARGS="--features io-uring"
fi
cargo build --release $EXTRA_ARGS
)
sleep 0.025
TARGET_DIR=$(
cd "$SCRIPT_DIR" &&
cargo metadata --format-version 1 --no-deps |
sed -n 's/.*"target_directory":"\([^"]*\)".*/\1/p'
)
tmux new-session -d -s "$SESSION" \
"exec socat -u -b $buf_size UDP-RECV:12345,bind=127.0.0.2,rcvbuf=33554432 \
EXEC:\"/bin/pv -B$buf_size -k -8 -b -t -r -p -X\""
tmux set-option -g prefix None
tmux set-option status off
tmux bind-key -n C-c kill-session
tmux bind-key -n q kill-session
tmux new-window -d -t "$SESSION" \
"exec socat -b $buf_size /dev/zero UDP-SENDTO:127.0.0.1:12345,sndbuf=33554432"
tmux select-window -t "$SESSION":0
tmux split-window -v \
"sh -c \"\"$TARGET_DIR\"/release/xor \
-l127.0.0.1:12345 -r127.0.0.2:12345 -t0x30 -o5 -m$mtu_size $method_opt; sleep infinity\""
tmux bind-key -n k if-shell -F '#{!=:#{@sent_once},1}' \
'send-keys -t 0.1 C-c; set -pt 0.1 @sent_once 1'
tmux split-window -v \
"exec env XDG_CONFIG_HOME=\"$HTOP_TEMP_DIR\" htop \
-p \"\$(pidof xor)\" \
-p \"\$(pidof xor socat | tr ' ' ',')\"\
-p \"\$(pidof socat pv | tr ' ' ',')\""
tmux set-hook -t "$SESSION" -a client-resized \
"resize-pane -t 0.0 -y 1"
tmux set-hook -t "$SESSION" -a client-resized \
"resize-pane -t 0.1 -y 3"
tmux select-pane -t "$SESSION":0.1
tmux attach-session -t "$SESSION"