Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omtls/blob/main/tests/drv/speed.om # omtls omtls: a TLS 1.3 client (RFC 8446) written fresh in seeded Omega, for mailhand. Not audited by a cryptographer. Free (Apache-2.0). Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omtls / tests / drv / speed.om` 242 lines ยท 4485 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note tests/drv/speed.om: handshakes per second and bulk throughput of the client. 3 note usage: build/drv_speed FIXTURE-DIR hs N SUITE [PORT] N full handshakes (SUITE 4865 or 4867) 4 note build/drv_speed FIXTURE-DIR bulk MIB SUITE [PORT] one connection, MIB MiB of application data sent 5 note Without PORT the peer is the test server (tests/srv/tlssrv.om) forked on a private loopback port, so the time 6 note includes the server's work on the same machine; with PORT the peer is an external server on 127.0.0.1 (for 7 note example `openssl s_server`) presenting a mail.test certificate from FIXTURE-DIR's root. 8 note Prints one line: "SPEED hs suite=S n=N ns=T per_second=R" or "SPEED bulk suite=S bytes=B ns=T mib_per_second=R" 9 global sp_v ulong 16 10 global sp_dir uchar 4096 11 text sp_host "mail.test" 12 text sp_via "127.0.0.1" 13 text sp_none "" 14 text sp_root "/root.pem" 15 text sp_key "/leaf-key.txt" 16 text sp_good "/leaf-good.der" 17 text sp_l1 "SPEED hs suite=" 18 text sp_l2 "SPEED bulk suite=" 19 text sp_n " n=" 20 text sp_b " bytes=" 21 text sp_ns " ns=" 22 text sp_ps " per_second=" 23 text sp_mps " mib_per_second_x1000=" 24 text sp_nl "\n" 25 text sp_fail "SPEED FAIL error=" 26 27 fn sp_say t view uchar * to void 28 k = write 1 t 0 len t 29 end 30 fn sp_num n ulong to void 31 d = new uchar 24 0 32 v = n 33 i = ulong 24 34 while true bound 30 35 i = sub i 1 36 put d i uchar add 48 rem v 10 37 v = div v 10 38 if eq v 0 39 break 40 end 41 end 42 k = write 1 d i sub 24 i 43 end 44 fn sp_arg i ulong b edit uchar 4096 to ulong 45 if ge i ulong argcnt 46 ret 0 47 end 48 k = argread i b 0 4096 49 if lt k 0 50 ret 0 51 end 52 ret ulong k 53 end 54 fn sp_argnum i ulong to ulong 55 b = new uchar 4096 0 56 n = sp_arg i b 57 v = ulong 0 58 for j ulong n 59 c = get b j 60 if or lt c 48 gt c 57 61 ret 0 62 end 63 v = add mul v 10 ulong sub c 48 64 end 65 ret v 66 end 67 fn sp_path p edit uchar 4096 t view uchar * to ulong 68 n = get sp_v 0 69 for i ulong n 70 put p i get sp_dir i 71 end 72 for i ulong len t 73 put p add n i get t i 74 end 75 ret add n len t 76 end 77 fn sp_listen pa edit ulong 1 to long 78 sa = new uchar 16 0 79 rnd = new uchar 2 0 80 for tries ulong 50 81 k = random rnd 0 2 0 82 pt = add 40000 rem or shl ulong get rnd 0 8 ulong get rnd 1 20000 83 put sa 0 2 84 put sa 2 uchar shr pt 8 85 put sa 3 uchar and pt 255 86 put sa 4 127 87 put sa 7 1 88 fd = socknew 2 524289 0 89 b = bind int fd sa 0 16 90 if eq b 0 91 if eq listen int fd 64 0 92 put pa 0 pt 93 ret fd 94 end 95 end 96 z = fclose int fd 97 end 98 ret -1 99 end 100 note the forked server: `count` connections; for bulk it reads until close_notify 101 fn sp_server lfd int count ulong suite ulong to void 102 p = new uchar 4096 0 103 q = new uchar 4096 0 104 n = sp_path p sp_good 105 m = sp_path q sp_key 106 if not ot_ts_load part p 0 n part q 0 m 107 exit 90 108 end 109 ot_ts_mode 0 suite 0 110 b = new uchar 65536 0 111 for i ulong count 112 fd = accept lfd 0 113 if lt fd 0 114 exit 91 115 end 116 c = ot_ts_accept int fd 117 if eq c 0 118 while true bound `9223372036854775807` 119 r = ot_tl_read b 120 if le r 0 121 break 122 end 123 end 124 ot_tl_close 125 else 126 z = fclose int fd 127 end 128 end 129 exit 0 130 end 131 fn sp_hs n ulong port ulong to bool 132 t0 = monons 133 for i ulong n 134 c = ot_tl_connect sp_host port sp_none 135 if ne c 0 136 sp_say sp_fail 137 sp_num ulong c 138 sp_say sp_nl 139 ret false 140 end 141 ot_tl_close 142 end 143 t = ulong sub monons t0 144 sp_say sp_l1 145 sp_num ot_tl_suite 146 sp_say sp_n 147 sp_num n 148 sp_say sp_ns 149 sp_num t 150 sp_say sp_ps 151 sp_num div mul n `1000000000` t 152 sp_say sp_nl 153 ret true 154 end 155 fn sp_bulk mib ulong port ulong to bool 156 b = new uchar `1048576` 7 157 c = ot_tl_connect sp_host port sp_none 158 if ne c 0 159 sp_say sp_fail 160 sp_num ulong c 161 sp_say sp_nl 162 ret false 163 end 164 t0 = monons 165 for i ulong mib 166 if not ot_tl_write b 167 sp_say sp_fail 168 sp_num ulong ot_tl_err 169 sp_say sp_nl 170 ret false 171 end 172 end 173 ot_tl_close 174 t = ulong sub monons t0 175 sp_say sp_l2 176 sp_num ot_tl_suite 177 sp_say sp_b 178 sp_num mul mib `1048576` 179 sp_say sp_ns 180 sp_num t 181 sp_say sp_mps 182 sp_num div mul mib `1000000000000` t 183 sp_say sp_nl 184 ret true 185 end 186 fn sp_setup to bool 187 p = new uchar 4096 0 188 n = sp_path p sp_root 189 if le ot_tl_roots part p 0 n 0 190 ret false 191 end 192 ret ot_tl_via sp_via 193 end 194 fn main to int 195 k = argread 1 sp_dir 0 4000 196 if le k 0 197 ret 2 198 end 199 put sp_v 0 ulong k 200 mb = new uchar 4096 0 201 ml = sp_arg 2 mb 202 hs = and eq ml 2 eq get mb 0 104 203 n = sp_argnum 3 204 suite = sp_argnum 4 205 port = sp_argnum 5 206 if not sp_setup 207 ret 2 208 end 209 ot_tl_deadline `60000000000` 210 pid = long 0 211 pa = new ulong 1 0 212 wb = new uchar 4 0 213 if eq port 0 214 lfd = sp_listen pa 215 if lt lfd 0 216 ret 3 217 end 218 port = get pa 0 219 cnt = ulong 1 220 if hs 221 cnt = n 222 end 223 pid = fork 224 if eq pid 0 225 sp_server int lfd cnt suite 226 end 227 z = fclose int lfd 228 end 229 ok = false 230 if hs 231 ok = sp_hs n port 232 else 233 ok = sp_bulk n port 234 end 235 if gt pid 0 236 w = waitpid int pid wb 0 4 0 237 end 238 if ok 239 ret 0 240 end 241 ret 1 242 end