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/omega-mv/blob/main/om/tls/test/bench/bench.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / om / tls / test / bench / bench.om` 239 lines ยท 4924 bytes Raw Blame History 1 note bench.om: HTTPS benchmark client for om/tls (program mode, composed after every om/tls unit). 2 note usage: bench MODE PORT N PATH STOREFILE 3 note MODE h: N full handshakes to 127.0.0.1:PORT (TLS name bench.test), close_notify after each; 4 note sample = ns from before the TCP connect to the end of tls_connect 5 note MODE g: N HTTPS GETs of PATH (HTTP/1.0, one connection each, read to close_notify); 6 note sample = ns from before the TCP connect to the end of the response 7 note MODE b: N bulk reads of PATH; sample = ns from the request write to the end of the response 8 note (the handshake is excluded) 9 note MODE d: one GET of PATH, the decrypted response bytes go to stdout (correctness gate) 10 note Every sample prints "S NANOSECONDS BYTES" on stdout. No resumption, no tickets are used. 11 note Exit 0 on success, 10 + code on a TLS failure, 2 usage, 3 connect failure, 4 short body. 12 13 text bnusage "usage: bench h|g|b|d PORT N PATH STOREFILE\n" 14 text bnhost "bench.test" 15 text bnip "127.0.0.1" 16 text bnget1 "GET /" 17 text bnget2 " HTTP/1.0" 18 text bnerr "TLSERR " 19 text bnnl "\n" 20 const BNERR ulong `4611686018427387904` 21 22 fn bn_arg i ulong a edit uchar * to ulong 23 n = argread i a 0 len a 24 if lt n 0 25 ret 0 26 end 27 ret ulong n 28 end 29 30 fn bn_num a view uchar * to ulong 31 v = ulong 0 32 for i ulong len a 33 d = ulong get a i 34 if or lt d 48 gt d 57 35 ret 0 36 end 37 v = add mul v 10 sub d 48 38 if gt v `99999999` 39 ret 0 40 end 41 end 42 ret v 43 end 44 45 fn bn_dec v ulong o edit uchar * p ulong to ulong 46 t = new uchar 24 0 47 n = ulong 0 48 x = v 49 while true bound 24 50 put t n uchar add 48 rem x 10 51 n = add n 1 52 x = div x 10 53 if eq x 0 54 break 55 end 56 end 57 for i ulong n 58 put o add p i get t sub sub n 1 i 59 end 60 ret add p n 61 end 62 63 note "S ns bytes\n" 64 fn bn_emit ns ulong by ulong to void 65 o = new uchar 64 0 66 put o 0 83 67 put o 1 32 68 p = bn_dec ns o 2 69 put o p 32 70 p = bn_dec by o add p 1 71 put o p 10 72 w = write 1 o 0 add p 1 73 end 74 75 note request "GET /PATH HTTP/1.0\r\n\r\n" into w[4096..) from the path w[256..256+pl); 76 note returns its length 77 fn bn_req w edit uchar * pl ulong to ulong 78 p = ulong 4096 79 for i ulong len bnget1 80 put w p get bnget1 i 81 p = add p 1 82 end 83 for i ulong pl 84 put w p get w add 256 i 85 p = add p 1 86 end 87 for i ulong len bnget2 88 put w p get bnget2 i 89 p = add p 1 90 end 91 put w p 13 92 put w add p 1 10 93 put w add p 2 13 94 put w add p 3 10 95 ret sub add p 4 4096 96 end 97 98 note read to close_notify; bytes received, or 1 shl 62 plus the code on error. dump 1 copies to stdout 99 fn bn_drain c edit uchar * dump ulong to ulong 100 b = new uchar 16384 0 101 t = ulong 0 102 while true bound 999999 103 r = tls_read c b 104 if eq r 0 105 ret t 106 end 107 if lt r 0 108 ret add BNERR ulong neg r 109 end 110 t = add t ulong r 111 if eq dump 1 112 w = write 1 b 0 ulong r 113 end 114 end 115 ret t 116 end 117 118 fn bn_fail e ulong to int 119 m = new uchar 256 0 120 w = write 2 bnerr 0 len bnerr 121 n = tls_errname e m 122 w = write 2 m 0 n 123 w = write 2 bnnl 0 1 124 ret int add 10 e 125 end 126 127 note s: 0 mode (104 h, 103 g, 98 b, 100 d), 1 port, 2 fd, 3 start ns, 4 sample ns, 5 bytes 128 note connect and handshake; 0, 1000 on a connect failure, or a TLS code 129 fn bn_hs c edit uchar * st view uchar * s edit ulong * to ulong 130 e = tls_init c bnhost 0 131 if ne e 0 132 ret e 133 end 134 t0 = monons 135 fd = tls_dial bnip get s 1 136 if lt fd 0 137 ret 1000 138 end 139 e = tls_connect c st int fd 140 t1 = monons 141 put s 2 ulong fd 142 put s 3 ulong t0 143 put s 4 sub ulong t1 ulong t0 144 put s 5 0 145 if ne e 0 146 x = fclose int fd 147 ret e 148 end 149 ret 0 150 end 151 152 note after the handshake: close (h) or send the request and read the response; s[6] = request time 153 fn bn_xfer c edit uchar * rq view uchar * s edit ulong * to ulong 154 if eq get s 0 104 155 tls_close c 156 x = fclose int get s 2 157 ret 0 158 end 159 put s 6 ulong monons 160 r = tls_write c rq 161 if lt r 0 162 x = fclose int get s 2 163 ret ulong neg r 164 end 165 dump = ulong 0 166 if eq get s 0 100 167 dump = 1 168 end 169 n = bn_drain c dump 170 put s 7 ulong monons 171 tls_close c 172 x = fclose int get s 2 173 if ge n BNERR 174 ret sub n BNERR 175 end 176 put s 5 n 177 put s 4 sub get s 7 get s 3 178 if eq get s 0 98 179 put s 4 sub get s 7 get s 6 180 end 181 ret 0 182 end 183 184 note arguments into s: 0 mode, 1 port, 8 count, 9 request length (request at w[4096..)); 0 or 2 185 fn bn_args w edit uchar * s edit ulong * to ulong 186 if ne argcnt 6 187 ret 2 188 end 189 if ne bn_arg 1 part w 0 256 1 190 ret 2 191 end 192 put s 0 ulong get w 0 193 put s 1 bn_num part w 0 bn_arg 2 part w 0 256 194 put s 8 bn_num part w 0 bn_arg 3 part w 0 256 195 if or eq get s 1 0 eq get s 8 0 196 ret 2 197 end 198 md = get s 0 199 if and and ne md 104 ne md 103 and ne md 98 ne md 100 200 ret 2 201 end 202 put s 9 bn_req w bn_arg 4 part w 256 1024 203 ret 0 204 end 205 206 fn bn_main c edit uchar * st edit uchar * w edit uchar * to int 207 s = new ulong 12 0 208 if ne bn_args w s 0 209 x = write 2 bnusage 0 len bnusage 210 ret 2 211 end 212 e = tls_storef st part w 0 bn_arg 5 part w 0 256 213 if ne e 0 214 ret bn_fail e 215 end 216 for i ulong get s 8 217 e = bn_hs c st s 218 if eq e 0 219 e = bn_xfer c part w 4096 get s 9 s 220 end 221 if eq e 1000 222 ret 3 223 end 224 if ne e 0 225 ret bn_fail e 226 end 227 if ne get s 0 100 228 bn_emit get s 4 get s 5 229 end 230 end 231 ret 0 232 end 233 234 fn main to int 235 c = new uchar 119296 0 236 st = new uchar 262144 0 237 w = new uchar 8192 0 238 ret bn_main c st w 239 end