diff options
| author | diogo464 <[email protected]> | 2025-07-09 14:24:25 +0100 |
|---|---|---|
| committer | diogo464 <[email protected]> | 2025-07-09 14:24:25 +0100 |
| commit | a5178fbb0bde3ff9f863ef0cca48748cb993390a (patch) | |
| tree | 9448cd051c4909f8fb4e1afaff1b9dda3278a5b2 | |
| parent | 8018cd7a378baee5c5e1fab85bba2592c9244c72 (diff) | |
rust init snapshot
| -rw-r--r-- | .gitignore | 7 | ||||
| -rw-r--r-- | Cargo.lock | 827 | ||||
| -rw-r--r-- | Cargo.toml | 15 | ||||
| -rw-r--r-- | src/latency_matrix.rs | 99 | ||||
| -rw-r--r-- | src/machine.rs | 101 | ||||
| -rw-r--r-- | src/main.rs | 252 |
6 files changed, 1301 insertions, 0 deletions
| @@ -1,2 +1,9 @@ | |||
| 1 | /target | 1 | /target |
| 2 | __pycache__/ | 2 | __pycache__/ |
| 3 | |||
| 4 | |||
| 5 | # Added by cargo | ||
| 6 | # | ||
| 7 | # already existing elements were commented out | ||
| 8 | |||
| 9 | #/target | ||
diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..b4d33c2 --- /dev/null +++ b/Cargo.lock | |||
| @@ -0,0 +1,827 @@ | |||
| 1 | # This file is automatically @generated by Cargo. | ||
| 2 | # It is not intended for manual editing. | ||
| 3 | version = 4 | ||
| 4 | |||
| 5 | [[package]] | ||
| 6 | name = "addr2line" | ||
| 7 | version = "0.24.2" | ||
| 8 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 9 | checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1" | ||
| 10 | dependencies = [ | ||
| 11 | "gimli", | ||
| 12 | ] | ||
| 13 | |||
| 14 | [[package]] | ||
| 15 | name = "adler2" | ||
| 16 | version = "2.0.1" | ||
| 17 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 18 | checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" | ||
| 19 | |||
| 20 | [[package]] | ||
| 21 | name = "aho-corasick" | ||
| 22 | version = "1.1.3" | ||
| 23 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 24 | checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" | ||
| 25 | dependencies = [ | ||
| 26 | "memchr", | ||
| 27 | ] | ||
| 28 | |||
| 29 | [[package]] | ||
| 30 | name = "anstream" | ||
| 31 | version = "0.6.19" | ||
| 32 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 33 | checksum = "301af1932e46185686725e0fad2f8f2aa7da69dd70bf6ecc44d6b703844a3933" | ||
| 34 | dependencies = [ | ||
| 35 | "anstyle", | ||
| 36 | "anstyle-parse", | ||
| 37 | "anstyle-query", | ||
| 38 | "anstyle-wincon", | ||
| 39 | "colorchoice", | ||
| 40 | "is_terminal_polyfill", | ||
| 41 | "utf8parse", | ||
| 42 | ] | ||
| 43 | |||
| 44 | [[package]] | ||
| 45 | name = "anstyle" | ||
| 46 | version = "1.0.11" | ||
| 47 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 48 | checksum = "862ed96ca487e809f1c8e5a8447f6ee2cf102f846893800b20cebdf541fc6bbd" | ||
| 49 | |||
| 50 | [[package]] | ||
| 51 | name = "anstyle-parse" | ||
| 52 | version = "0.2.7" | ||
| 53 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 54 | checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2" | ||
| 55 | dependencies = [ | ||
| 56 | "utf8parse", | ||
| 57 | ] | ||
| 58 | |||
| 59 | [[package]] | ||
| 60 | name = "anstyle-query" | ||
| 61 | version = "1.1.3" | ||
| 62 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 63 | checksum = "6c8bdeb6047d8983be085bab0ba1472e6dc604e7041dbf6fcd5e71523014fae9" | ||
| 64 | dependencies = [ | ||
| 65 | "windows-sys 0.59.0", | ||
| 66 | ] | ||
| 67 | |||
| 68 | [[package]] | ||
| 69 | name = "anstyle-wincon" | ||
| 70 | version = "3.0.9" | ||
| 71 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 72 | checksum = "403f75924867bb1033c59fbf0797484329750cfbe3c4325cd33127941fabc882" | ||
| 73 | dependencies = [ | ||
| 74 | "anstyle", | ||
| 75 | "once_cell_polyfill", | ||
| 76 | "windows-sys 0.59.0", | ||
| 77 | ] | ||
| 78 | |||
| 79 | [[package]] | ||
| 80 | name = "autocfg" | ||
| 81 | version = "1.5.0" | ||
| 82 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 83 | checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" | ||
| 84 | |||
| 85 | [[package]] | ||
| 86 | name = "backtrace" | ||
| 87 | version = "0.3.75" | ||
| 88 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 89 | checksum = "6806a6321ec58106fea15becdad98371e28d92ccbc7c8f1b3b6dd724fe8f1002" | ||
| 90 | dependencies = [ | ||
| 91 | "addr2line", | ||
| 92 | "cfg-if", | ||
| 93 | "libc", | ||
| 94 | "miniz_oxide", | ||
| 95 | "object", | ||
| 96 | "rustc-demangle", | ||
| 97 | "windows-targets", | ||
| 98 | ] | ||
| 99 | |||
| 100 | [[package]] | ||
| 101 | name = "bitflags" | ||
| 102 | version = "2.9.1" | ||
| 103 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 104 | checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" | ||
| 105 | |||
| 106 | [[package]] | ||
| 107 | name = "bytes" | ||
| 108 | version = "1.10.1" | ||
| 109 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 110 | checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" | ||
| 111 | |||
| 112 | [[package]] | ||
| 113 | name = "cfg-if" | ||
| 114 | version = "1.0.1" | ||
| 115 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 116 | checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268" | ||
| 117 | |||
| 118 | [[package]] | ||
| 119 | name = "clap" | ||
| 120 | version = "4.5.40" | ||
| 121 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 122 | checksum = "40b6887a1d8685cebccf115538db5c0efe625ccac9696ad45c409d96566e910f" | ||
| 123 | dependencies = [ | ||
| 124 | "clap_builder", | ||
| 125 | "clap_derive", | ||
| 126 | ] | ||
| 127 | |||
| 128 | [[package]] | ||
| 129 | name = "clap_builder" | ||
| 130 | version = "4.5.40" | ||
| 131 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 132 | checksum = "e0c66c08ce9f0c698cbce5c0279d0bb6ac936d8674174fe48f736533b964f59e" | ||
| 133 | dependencies = [ | ||
| 134 | "anstream", | ||
| 135 | "anstyle", | ||
| 136 | "clap_lex", | ||
| 137 | "strsim", | ||
| 138 | ] | ||
| 139 | |||
| 140 | [[package]] | ||
| 141 | name = "clap_derive" | ||
| 142 | version = "4.5.40" | ||
| 143 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 144 | checksum = "d2c7947ae4cc3d851207c1adb5b5e260ff0cca11446b1d6d1423788e442257ce" | ||
| 145 | dependencies = [ | ||
| 146 | "heck", | ||
| 147 | "proc-macro2", | ||
| 148 | "quote", | ||
| 149 | "syn", | ||
| 150 | ] | ||
| 151 | |||
| 152 | [[package]] | ||
| 153 | name = "clap_lex" | ||
| 154 | version = "0.7.5" | ||
| 155 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 156 | checksum = "b94f61472cee1439c0b966b47e3aca9ae07e45d070759512cd390ea2bebc6675" | ||
| 157 | |||
| 158 | [[package]] | ||
| 159 | name = "color-eyre" | ||
| 160 | version = "0.6.5" | ||
| 161 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 162 | checksum = "e5920befb47832a6d61ee3a3a846565cfa39b331331e68a3b1d1116630f2f26d" | ||
| 163 | dependencies = [ | ||
| 164 | "backtrace", | ||
| 165 | "color-spantrace", | ||
| 166 | "eyre", | ||
| 167 | "indenter", | ||
| 168 | "once_cell", | ||
| 169 | "owo-colors", | ||
| 170 | "tracing-error", | ||
| 171 | ] | ||
| 172 | |||
| 173 | [[package]] | ||
| 174 | name = "color-spantrace" | ||
| 175 | version = "0.3.0" | ||
| 176 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 177 | checksum = "b8b88ea9df13354b55bc7234ebcce36e6ef896aca2e42a15de9e10edce01b427" | ||
| 178 | dependencies = [ | ||
| 179 | "once_cell", | ||
| 180 | "owo-colors", | ||
| 181 | "tracing-core", | ||
| 182 | "tracing-error", | ||
| 183 | ] | ||
| 184 | |||
| 185 | [[package]] | ||
| 186 | name = "colorchoice" | ||
| 187 | version = "1.0.4" | ||
| 188 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 189 | checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" | ||
| 190 | |||
| 191 | [[package]] | ||
| 192 | name = "eyre" | ||
| 193 | version = "0.6.12" | ||
| 194 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 195 | checksum = "7cd915d99f24784cdc19fd37ef22b97e3ff0ae756c7e492e9fbfe897d61e2aec" | ||
| 196 | dependencies = [ | ||
| 197 | "indenter", | ||
| 198 | "once_cell", | ||
| 199 | ] | ||
| 200 | |||
| 201 | [[package]] | ||
| 202 | name = "gimli" | ||
| 203 | version = "0.31.1" | ||
| 204 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 205 | checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" | ||
| 206 | |||
| 207 | [[package]] | ||
| 208 | name = "heck" | ||
| 209 | version = "0.5.0" | ||
| 210 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 211 | checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" | ||
| 212 | |||
| 213 | [[package]] | ||
| 214 | name = "indenter" | ||
| 215 | version = "0.3.3" | ||
| 216 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 217 | checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" | ||
| 218 | |||
| 219 | [[package]] | ||
| 220 | name = "io-uring" | ||
| 221 | version = "0.7.8" | ||
| 222 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 223 | checksum = "b86e202f00093dcba4275d4636b93ef9dd75d025ae560d2521b45ea28ab49013" | ||
| 224 | dependencies = [ | ||
| 225 | "bitflags", | ||
| 226 | "cfg-if", | ||
| 227 | "libc", | ||
| 228 | ] | ||
| 229 | |||
| 230 | [[package]] | ||
| 231 | name = "is_terminal_polyfill" | ||
| 232 | version = "1.70.1" | ||
| 233 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 234 | checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" | ||
| 235 | |||
| 236 | [[package]] | ||
| 237 | name = "itoa" | ||
| 238 | version = "1.0.15" | ||
| 239 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 240 | checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" | ||
| 241 | |||
| 242 | [[package]] | ||
| 243 | name = "lazy_static" | ||
| 244 | version = "1.5.0" | ||
| 245 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 246 | checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" | ||
| 247 | |||
| 248 | [[package]] | ||
| 249 | name = "libc" | ||
| 250 | version = "0.2.174" | ||
| 251 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 252 | checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" | ||
| 253 | |||
| 254 | [[package]] | ||
| 255 | name = "lock_api" | ||
| 256 | version = "0.4.13" | ||
| 257 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 258 | checksum = "96936507f153605bddfcda068dd804796c84324ed2510809e5b2a624c81da765" | ||
| 259 | dependencies = [ | ||
| 260 | "autocfg", | ||
| 261 | "scopeguard", | ||
| 262 | ] | ||
| 263 | |||
| 264 | [[package]] | ||
| 265 | name = "log" | ||
| 266 | version = "0.4.27" | ||
| 267 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 268 | checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" | ||
| 269 | |||
| 270 | [[package]] | ||
| 271 | name = "matchers" | ||
| 272 | version = "0.1.0" | ||
| 273 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 274 | checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" | ||
| 275 | dependencies = [ | ||
| 276 | "regex-automata 0.1.10", | ||
| 277 | ] | ||
| 278 | |||
| 279 | [[package]] | ||
| 280 | name = "memchr" | ||
| 281 | version = "2.7.5" | ||
| 282 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 283 | checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0" | ||
| 284 | |||
| 285 | [[package]] | ||
| 286 | name = "miniz_oxide" | ||
| 287 | version = "0.8.9" | ||
| 288 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 289 | checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316" | ||
| 290 | dependencies = [ | ||
| 291 | "adler2", | ||
| 292 | ] | ||
| 293 | |||
| 294 | [[package]] | ||
| 295 | name = "mio" | ||
| 296 | version = "1.0.4" | ||
| 297 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 298 | checksum = "78bed444cc8a2160f01cbcf811ef18cac863ad68ae8ca62092e8db51d51c761c" | ||
| 299 | dependencies = [ | ||
| 300 | "libc", | ||
| 301 | "wasi", | ||
| 302 | "windows-sys 0.59.0", | ||
| 303 | ] | ||
| 304 | |||
| 305 | [[package]] | ||
| 306 | name = "nu-ansi-term" | ||
| 307 | version = "0.46.0" | ||
| 308 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 309 | checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" | ||
| 310 | dependencies = [ | ||
| 311 | "overload", | ||
| 312 | "winapi", | ||
| 313 | ] | ||
| 314 | |||
| 315 | [[package]] | ||
| 316 | name = "oar-p2p-net" | ||
| 317 | version = "0.1.0" | ||
| 318 | dependencies = [ | ||
| 319 | "clap", | ||
| 320 | "color-eyre", | ||
| 321 | "eyre", | ||
| 322 | "serde", | ||
| 323 | "serde_json", | ||
| 324 | "thiserror", | ||
| 325 | "tokio", | ||
| 326 | "tracing", | ||
| 327 | "tracing-subscriber", | ||
| 328 | ] | ||
| 329 | |||
| 330 | [[package]] | ||
| 331 | name = "object" | ||
| 332 | version = "0.36.7" | ||
| 333 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 334 | checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87" | ||
| 335 | dependencies = [ | ||
| 336 | "memchr", | ||
| 337 | ] | ||
| 338 | |||
| 339 | [[package]] | ||
| 340 | name = "once_cell" | ||
| 341 | version = "1.21.3" | ||
| 342 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 343 | checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" | ||
| 344 | |||
| 345 | [[package]] | ||
| 346 | name = "once_cell_polyfill" | ||
| 347 | version = "1.70.1" | ||
| 348 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 349 | checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad" | ||
| 350 | |||
| 351 | [[package]] | ||
| 352 | name = "overload" | ||
| 353 | version = "0.1.1" | ||
| 354 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 355 | checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" | ||
| 356 | |||
| 357 | [[package]] | ||
| 358 | name = "owo-colors" | ||
| 359 | version = "4.2.2" | ||
| 360 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 361 | checksum = "48dd4f4a2c8405440fd0462561f0e5806bd0f77e86f51c761481bdd4018b545e" | ||
| 362 | |||
| 363 | [[package]] | ||
| 364 | name = "parking_lot" | ||
| 365 | version = "0.12.4" | ||
| 366 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 367 | checksum = "70d58bf43669b5795d1576d0641cfb6fbb2057bf629506267a92807158584a13" | ||
| 368 | dependencies = [ | ||
| 369 | "lock_api", | ||
| 370 | "parking_lot_core", | ||
| 371 | ] | ||
| 372 | |||
| 373 | [[package]] | ||
| 374 | name = "parking_lot_core" | ||
| 375 | version = "0.9.11" | ||
| 376 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 377 | checksum = "bc838d2a56b5b1a6c25f55575dfc605fabb63bb2365f6c2353ef9159aa69e4a5" | ||
| 378 | dependencies = [ | ||
| 379 | "cfg-if", | ||
| 380 | "libc", | ||
| 381 | "redox_syscall", | ||
| 382 | "smallvec", | ||
| 383 | "windows-targets", | ||
| 384 | ] | ||
| 385 | |||
| 386 | [[package]] | ||
| 387 | name = "pin-project-lite" | ||
| 388 | version = "0.2.16" | ||
| 389 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 390 | checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" | ||
| 391 | |||
| 392 | [[package]] | ||
| 393 | name = "proc-macro2" | ||
| 394 | version = "1.0.95" | ||
| 395 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 396 | checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" | ||
| 397 | dependencies = [ | ||
| 398 | "unicode-ident", | ||
| 399 | ] | ||
| 400 | |||
| 401 | [[package]] | ||
| 402 | name = "quote" | ||
| 403 | version = "1.0.40" | ||
| 404 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 405 | checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" | ||
| 406 | dependencies = [ | ||
| 407 | "proc-macro2", | ||
| 408 | ] | ||
| 409 | |||
| 410 | [[package]] | ||
| 411 | name = "redox_syscall" | ||
| 412 | version = "0.5.13" | ||
| 413 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 414 | checksum = "0d04b7d0ee6b4a0207a0a7adb104d23ecb0b47d6beae7152d0fa34b692b29fd6" | ||
| 415 | dependencies = [ | ||
| 416 | "bitflags", | ||
| 417 | ] | ||
| 418 | |||
| 419 | [[package]] | ||
| 420 | name = "regex" | ||
| 421 | version = "1.11.1" | ||
| 422 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 423 | checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" | ||
| 424 | dependencies = [ | ||
| 425 | "aho-corasick", | ||
| 426 | "memchr", | ||
| 427 | "regex-automata 0.4.9", | ||
| 428 | "regex-syntax 0.8.5", | ||
| 429 | ] | ||
| 430 | |||
| 431 | [[package]] | ||
| 432 | name = "regex-automata" | ||
| 433 | version = "0.1.10" | ||
| 434 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 435 | checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" | ||
| 436 | dependencies = [ | ||
| 437 | "regex-syntax 0.6.29", | ||
| 438 | ] | ||
| 439 | |||
| 440 | [[package]] | ||
| 441 | name = "regex-automata" | ||
| 442 | version = "0.4.9" | ||
| 443 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 444 | checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" | ||
| 445 | dependencies = [ | ||
| 446 | "aho-corasick", | ||
| 447 | "memchr", | ||
| 448 | "regex-syntax 0.8.5", | ||
| 449 | ] | ||
| 450 | |||
| 451 | [[package]] | ||
| 452 | name = "regex-syntax" | ||
| 453 | version = "0.6.29" | ||
| 454 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 455 | checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" | ||
| 456 | |||
| 457 | [[package]] | ||
| 458 | name = "regex-syntax" | ||
| 459 | version = "0.8.5" | ||
| 460 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 461 | checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" | ||
| 462 | |||
| 463 | [[package]] | ||
| 464 | name = "rustc-demangle" | ||
| 465 | version = "0.1.25" | ||
| 466 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 467 | checksum = "989e6739f80c4ad5b13e0fd7fe89531180375b18520cc8c82080e4dc4035b84f" | ||
| 468 | |||
| 469 | [[package]] | ||
| 470 | name = "ryu" | ||
| 471 | version = "1.0.20" | ||
| 472 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 473 | checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" | ||
| 474 | |||
| 475 | [[package]] | ||
| 476 | name = "scopeguard" | ||
| 477 | version = "1.2.0" | ||
| 478 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 479 | checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" | ||
| 480 | |||
| 481 | [[package]] | ||
| 482 | name = "serde" | ||
| 483 | version = "1.0.219" | ||
| 484 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 485 | checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" | ||
| 486 | dependencies = [ | ||
| 487 | "serde_derive", | ||
| 488 | ] | ||
| 489 | |||
| 490 | [[package]] | ||
| 491 | name = "serde_derive" | ||
| 492 | version = "1.0.219" | ||
| 493 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 494 | checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" | ||
| 495 | dependencies = [ | ||
| 496 | "proc-macro2", | ||
| 497 | "quote", | ||
| 498 | "syn", | ||
| 499 | ] | ||
| 500 | |||
| 501 | [[package]] | ||
| 502 | name = "serde_json" | ||
| 503 | version = "1.0.140" | ||
| 504 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 505 | checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" | ||
| 506 | dependencies = [ | ||
| 507 | "itoa", | ||
| 508 | "memchr", | ||
| 509 | "ryu", | ||
| 510 | "serde", | ||
| 511 | ] | ||
| 512 | |||
| 513 | [[package]] | ||
| 514 | name = "sharded-slab" | ||
| 515 | version = "0.1.7" | ||
| 516 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 517 | checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" | ||
| 518 | dependencies = [ | ||
| 519 | "lazy_static", | ||
| 520 | ] | ||
| 521 | |||
| 522 | [[package]] | ||
| 523 | name = "signal-hook-registry" | ||
| 524 | version = "1.4.5" | ||
| 525 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 526 | checksum = "9203b8055f63a2a00e2f593bb0510367fe707d7ff1e5c872de2f537b339e5410" | ||
| 527 | dependencies = [ | ||
| 528 | "libc", | ||
| 529 | ] | ||
| 530 | |||
| 531 | [[package]] | ||
| 532 | name = "slab" | ||
| 533 | version = "0.4.10" | ||
| 534 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 535 | checksum = "04dc19736151f35336d325007ac991178d504a119863a2fcb3758cdb5e52c50d" | ||
| 536 | |||
| 537 | [[package]] | ||
| 538 | name = "smallvec" | ||
| 539 | version = "1.15.1" | ||
| 540 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 541 | checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" | ||
| 542 | |||
| 543 | [[package]] | ||
| 544 | name = "socket2" | ||
| 545 | version = "0.5.10" | ||
| 546 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 547 | checksum = "e22376abed350d73dd1cd119b57ffccad95b4e585a7cda43e286245ce23c0678" | ||
| 548 | dependencies = [ | ||
| 549 | "libc", | ||
| 550 | "windows-sys 0.52.0", | ||
| 551 | ] | ||
| 552 | |||
| 553 | [[package]] | ||
| 554 | name = "strsim" | ||
| 555 | version = "0.11.1" | ||
| 556 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 557 | checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" | ||
| 558 | |||
| 559 | [[package]] | ||
| 560 | name = "syn" | ||
| 561 | version = "2.0.104" | ||
| 562 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 563 | checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40" | ||
| 564 | dependencies = [ | ||
| 565 | "proc-macro2", | ||
| 566 | "quote", | ||
| 567 | "unicode-ident", | ||
| 568 | ] | ||
| 569 | |||
| 570 | [[package]] | ||
| 571 | name = "thiserror" | ||
| 572 | version = "2.0.12" | ||
| 573 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 574 | checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708" | ||
| 575 | dependencies = [ | ||
| 576 | "thiserror-impl", | ||
| 577 | ] | ||
| 578 | |||
| 579 | [[package]] | ||
| 580 | name = "thiserror-impl" | ||
| 581 | version = "2.0.12" | ||
| 582 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 583 | checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" | ||
| 584 | dependencies = [ | ||
| 585 | "proc-macro2", | ||
| 586 | "quote", | ||
| 587 | "syn", | ||
| 588 | ] | ||
| 589 | |||
| 590 | [[package]] | ||
| 591 | name = "thread_local" | ||
| 592 | version = "1.1.9" | ||
| 593 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 594 | checksum = "f60246a4944f24f6e018aa17cdeffb7818b76356965d03b07d6a9886e8962185" | ||
| 595 | dependencies = [ | ||
| 596 | "cfg-if", | ||
| 597 | ] | ||
| 598 | |||
| 599 | [[package]] | ||
| 600 | name = "tokio" | ||
| 601 | version = "1.46.1" | ||
| 602 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 603 | checksum = "0cc3a2344dafbe23a245241fe8b09735b521110d30fcefbbd5feb1797ca35d17" | ||
| 604 | dependencies = [ | ||
| 605 | "backtrace", | ||
| 606 | "bytes", | ||
| 607 | "io-uring", | ||
| 608 | "libc", | ||
| 609 | "mio", | ||
| 610 | "parking_lot", | ||
| 611 | "pin-project-lite", | ||
| 612 | "signal-hook-registry", | ||
| 613 | "slab", | ||
| 614 | "socket2", | ||
| 615 | "tokio-macros", | ||
| 616 | "windows-sys 0.52.0", | ||
| 617 | ] | ||
| 618 | |||
| 619 | [[package]] | ||
| 620 | name = "tokio-macros" | ||
| 621 | version = "2.5.0" | ||
| 622 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 623 | checksum = "6e06d43f1345a3bcd39f6a56dbb7dcab2ba47e68e8ac134855e7e2bdbaf8cab8" | ||
| 624 | dependencies = [ | ||
| 625 | "proc-macro2", | ||
| 626 | "quote", | ||
| 627 | "syn", | ||
| 628 | ] | ||
| 629 | |||
| 630 | [[package]] | ||
| 631 | name = "tracing" | ||
| 632 | version = "0.1.41" | ||
| 633 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 634 | checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" | ||
| 635 | dependencies = [ | ||
| 636 | "pin-project-lite", | ||
| 637 | "tracing-attributes", | ||
| 638 | "tracing-core", | ||
| 639 | ] | ||
| 640 | |||
| 641 | [[package]] | ||
| 642 | name = "tracing-attributes" | ||
| 643 | version = "0.1.30" | ||
| 644 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 645 | checksum = "81383ab64e72a7a8b8e13130c49e3dab29def6d0c7d76a03087b3cf71c5c6903" | ||
| 646 | dependencies = [ | ||
| 647 | "proc-macro2", | ||
| 648 | "quote", | ||
| 649 | "syn", | ||
| 650 | ] | ||
| 651 | |||
| 652 | [[package]] | ||
| 653 | name = "tracing-core" | ||
| 654 | version = "0.1.34" | ||
| 655 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 656 | checksum = "b9d12581f227e93f094d3af2ae690a574abb8a2b9b7a96e7cfe9647b2b617678" | ||
| 657 | dependencies = [ | ||
| 658 | "once_cell", | ||
| 659 | "valuable", | ||
| 660 | ] | ||
| 661 | |||
| 662 | [[package]] | ||
| 663 | name = "tracing-error" | ||
| 664 | version = "0.2.1" | ||
| 665 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 666 | checksum = "8b1581020d7a273442f5b45074a6a57d5757ad0a47dac0e9f0bd57b81936f3db" | ||
| 667 | dependencies = [ | ||
| 668 | "tracing", | ||
| 669 | "tracing-subscriber", | ||
| 670 | ] | ||
| 671 | |||
| 672 | [[package]] | ||
| 673 | name = "tracing-log" | ||
| 674 | version = "0.2.0" | ||
| 675 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 676 | checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" | ||
| 677 | dependencies = [ | ||
| 678 | "log", | ||
| 679 | "once_cell", | ||
| 680 | "tracing-core", | ||
| 681 | ] | ||
| 682 | |||
| 683 | [[package]] | ||
| 684 | name = "tracing-subscriber" | ||
| 685 | version = "0.3.19" | ||
| 686 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 687 | checksum = "e8189decb5ac0fa7bc8b96b7cb9b2701d60d48805aca84a238004d665fcc4008" | ||
| 688 | dependencies = [ | ||
| 689 | "matchers", | ||
| 690 | "nu-ansi-term", | ||
| 691 | "once_cell", | ||
| 692 | "regex", | ||
| 693 | "sharded-slab", | ||
| 694 | "smallvec", | ||
| 695 | "thread_local", | ||
| 696 | "tracing", | ||
| 697 | "tracing-core", | ||
| 698 | "tracing-log", | ||
| 699 | ] | ||
| 700 | |||
| 701 | [[package]] | ||
| 702 | name = "unicode-ident" | ||
| 703 | version = "1.0.18" | ||
| 704 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 705 | checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" | ||
| 706 | |||
| 707 | [[package]] | ||
| 708 | name = "utf8parse" | ||
| 709 | version = "0.2.2" | ||
| 710 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 711 | checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" | ||
| 712 | |||
| 713 | [[package]] | ||
| 714 | name = "valuable" | ||
| 715 | version = "0.1.1" | ||
| 716 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 717 | checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" | ||
| 718 | |||
| 719 | [[package]] | ||
| 720 | name = "wasi" | ||
| 721 | version = "0.11.1+wasi-snapshot-preview1" | ||
| 722 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 723 | checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" | ||
| 724 | |||
| 725 | [[package]] | ||
| 726 | name = "winapi" | ||
| 727 | version = "0.3.9" | ||
| 728 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 729 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" | ||
| 730 | dependencies = [ | ||
| 731 | "winapi-i686-pc-windows-gnu", | ||
| 732 | "winapi-x86_64-pc-windows-gnu", | ||
| 733 | ] | ||
| 734 | |||
| 735 | [[package]] | ||
| 736 | name = "winapi-i686-pc-windows-gnu" | ||
| 737 | version = "0.4.0" | ||
| 738 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 739 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" | ||
| 740 | |||
| 741 | [[package]] | ||
| 742 | name = "winapi-x86_64-pc-windows-gnu" | ||
| 743 | version = "0.4.0" | ||
| 744 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 745 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" | ||
| 746 | |||
| 747 | [[package]] | ||
| 748 | name = "windows-sys" | ||
| 749 | version = "0.52.0" | ||
| 750 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 751 | checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" | ||
| 752 | dependencies = [ | ||
| 753 | "windows-targets", | ||
| 754 | ] | ||
| 755 | |||
| 756 | [[package]] | ||
| 757 | name = "windows-sys" | ||
| 758 | version = "0.59.0" | ||
| 759 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 760 | checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" | ||
| 761 | dependencies = [ | ||
| 762 | "windows-targets", | ||
| 763 | ] | ||
| 764 | |||
| 765 | [[package]] | ||
| 766 | name = "windows-targets" | ||
| 767 | version = "0.52.6" | ||
| 768 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 769 | checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" | ||
| 770 | dependencies = [ | ||
| 771 | "windows_aarch64_gnullvm", | ||
| 772 | "windows_aarch64_msvc", | ||
| 773 | "windows_i686_gnu", | ||
| 774 | "windows_i686_gnullvm", | ||
| 775 | "windows_i686_msvc", | ||
| 776 | "windows_x86_64_gnu", | ||
| 777 | "windows_x86_64_gnullvm", | ||
| 778 | "windows_x86_64_msvc", | ||
| 779 | ] | ||
| 780 | |||
| 781 | [[package]] | ||
| 782 | name = "windows_aarch64_gnullvm" | ||
| 783 | version = "0.52.6" | ||
| 784 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 785 | checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" | ||
| 786 | |||
| 787 | [[package]] | ||
| 788 | name = "windows_aarch64_msvc" | ||
| 789 | version = "0.52.6" | ||
| 790 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 791 | checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" | ||
| 792 | |||
| 793 | [[package]] | ||
| 794 | name = "windows_i686_gnu" | ||
| 795 | version = "0.52.6" | ||
| 796 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 797 | checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" | ||
| 798 | |||
| 799 | [[package]] | ||
| 800 | name = "windows_i686_gnullvm" | ||
| 801 | version = "0.52.6" | ||
| 802 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 803 | checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" | ||
| 804 | |||
| 805 | [[package]] | ||
| 806 | name = "windows_i686_msvc" | ||
| 807 | version = "0.52.6" | ||
| 808 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 809 | checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" | ||
| 810 | |||
| 811 | [[package]] | ||
| 812 | name = "windows_x86_64_gnu" | ||
| 813 | version = "0.52.6" | ||
| 814 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 815 | checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" | ||
| 816 | |||
| 817 | [[package]] | ||
| 818 | name = "windows_x86_64_gnullvm" | ||
| 819 | version = "0.52.6" | ||
| 820 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 821 | checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" | ||
| 822 | |||
| 823 | [[package]] | ||
| 824 | name = "windows_x86_64_msvc" | ||
| 825 | version = "0.52.6" | ||
| 826 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 827 | checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" | ||
diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..86d95c8 --- /dev/null +++ b/Cargo.toml | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | [package] | ||
| 2 | name = "oar-p2p-net" | ||
| 3 | version = "0.1.0" | ||
| 4 | edition = "2024" | ||
| 5 | |||
| 6 | [dependencies] | ||
| 7 | clap = { version = "4.5.40", features = ["derive", "env"] } | ||
| 8 | color-eyre = "0.6.5" | ||
| 9 | eyre = "0.6.12" | ||
| 10 | serde = { version = "1.0.219", features = ["derive"] } | ||
| 11 | serde_json = "1.0.140" | ||
| 12 | thiserror = "2.0.12" | ||
| 13 | tokio = { version = "1.46.1", features = ["full"] } | ||
| 14 | tracing = "0.1.41" | ||
| 15 | tracing-subscriber = { version = "0.3.19", features = ["env-filter"] } | ||
diff --git a/src/latency_matrix.rs b/src/latency_matrix.rs new file mode 100644 index 0000000..b40df9e --- /dev/null +++ b/src/latency_matrix.rs | |||
| @@ -0,0 +1,99 @@ | |||
| 1 | use std::str::FromStr; | ||
| 2 | use std::time::Duration; | ||
| 3 | use thiserror::Error; | ||
| 4 | |||
| 5 | #[derive(Debug, Error)] | ||
| 6 | pub enum InvalidLatencyMatrix { | ||
| 7 | #[error( | ||
| 8 | "invalid line dimension: line {line} had dimension {dimension} but expected {expected}" | ||
| 9 | )] | ||
| 10 | InvalidLineDimension { | ||
| 11 | line: usize, | ||
| 12 | dimension: usize, | ||
| 13 | expected: usize, | ||
| 14 | }, | ||
| 15 | #[error("invalid latency value '{value}': {error}")] | ||
| 16 | InvalidLatencyValue { value: String, error: String }, | ||
| 17 | } | ||
| 18 | |||
| 19 | pub enum TimeUnit { | ||
| 20 | Seconds, | ||
| 21 | Milliseconds, | ||
| 22 | } | ||
| 23 | |||
| 24 | #[derive(Debug, Clone)] | ||
| 25 | pub struct LatencyMatrix { | ||
| 26 | dimension: usize, | ||
| 27 | latencies: Vec<Duration>, | ||
| 28 | } | ||
| 29 | |||
| 30 | impl LatencyMatrix { | ||
| 31 | fn new(dimension: usize, latencies: Vec<Duration>) -> Self { | ||
| 32 | assert_eq!(dimension * dimension, latencies.len()); | ||
| 33 | Self { | ||
| 34 | dimension, | ||
| 35 | latencies, | ||
| 36 | } | ||
| 37 | } | ||
| 38 | |||
| 39 | pub fn latency(&self, row: usize, col: usize) -> Duration { | ||
| 40 | self.latencies[self.dimension * row + col] | ||
| 41 | } | ||
| 42 | |||
| 43 | pub fn dimension(&self) -> usize { | ||
| 44 | self.dimension | ||
| 45 | } | ||
| 46 | |||
| 47 | pub fn parse(content: &str, unit: TimeUnit) -> Result<Self, InvalidLatencyMatrix> { | ||
| 48 | let mut dimension = None; | ||
| 49 | let mut latencies = Vec::default(); | ||
| 50 | for (line_idx, line) in content.lines().enumerate() { | ||
| 51 | let line = line.trim(); | ||
| 52 | if line.is_empty() { | ||
| 53 | continue; | ||
| 54 | } | ||
| 55 | |||
| 56 | let mut current_dimension = 0; | ||
| 57 | for component in line.split_whitespace() { | ||
| 58 | current_dimension += 1; | ||
| 59 | let component_value = match component.parse::<f64>() { | ||
| 60 | Ok(value) => value, | ||
| 61 | Err(err) => { | ||
| 62 | return Err(InvalidLatencyMatrix::InvalidLatencyValue { | ||
| 63 | value: component.to_string(), | ||
| 64 | error: err.to_string(), | ||
| 65 | }); | ||
| 66 | } | ||
| 67 | }; | ||
| 68 | |||
| 69 | latencies.push(Duration::from_secs_f64(match unit { | ||
| 70 | TimeUnit::Seconds => component_value, | ||
| 71 | TimeUnit::Milliseconds => component_value / 1000.0, | ||
| 72 | })); | ||
| 73 | } | ||
| 74 | |||
| 75 | match dimension { | ||
| 76 | Some(dimension) => { | ||
| 77 | if current_dimension != dimension { | ||
| 78 | return Err(InvalidLatencyMatrix::InvalidLineDimension { | ||
| 79 | line: line_idx, | ||
| 80 | dimension: current_dimension, | ||
| 81 | expected: dimension, | ||
| 82 | }); | ||
| 83 | } | ||
| 84 | } | ||
| 85 | None => dimension = Some(current_dimension), | ||
| 86 | } | ||
| 87 | } | ||
| 88 | |||
| 89 | Ok(Self::new(dimension.unwrap_or(0), latencies)) | ||
| 90 | } | ||
| 91 | } | ||
| 92 | |||
| 93 | impl FromStr for LatencyMatrix { | ||
| 94 | type Err = InvalidLatencyMatrix; | ||
| 95 | |||
| 96 | fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
| 97 | Self::parse(s, TimeUnit::Milliseconds) | ||
| 98 | } | ||
| 99 | } | ||
diff --git a/src/machine.rs b/src/machine.rs new file mode 100644 index 0000000..f1ad94d --- /dev/null +++ b/src/machine.rs | |||
| @@ -0,0 +1,101 @@ | |||
| 1 | macro_rules! define_machines { | ||
| 2 | ($(($name:ident, $idx:expr, $hostname:expr, $interface:expr)),*) => { | ||
| 3 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
| 4 | pub enum Machine { | ||
| 5 | $($name,)* | ||
| 6 | } | ||
| 7 | |||
| 8 | impl std::fmt::Display for Machine { | ||
| 9 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
| 10 | f.write_str(self.hostname()) | ||
| 11 | } | ||
| 12 | } | ||
| 13 | |||
| 14 | impl Machine { | ||
| 15 | pub fn hostname(&self) -> &'static str { | ||
| 16 | match self { | ||
| 17 | $(Self::$name => $hostname,)* | ||
| 18 | } | ||
| 19 | } | ||
| 20 | |||
| 21 | pub fn index(&self) -> usize { | ||
| 22 | match self { | ||
| 23 | $(Self::$name => $idx,)* | ||
| 24 | } | ||
| 25 | } | ||
| 26 | |||
| 27 | pub fn from_hostname(hostname: &str) -> Option<Self> { | ||
| 28 | match hostname { | ||
| 29 | $($hostname => Some(Self::$name),)* | ||
| 30 | _ => None | ||
| 31 | } | ||
| 32 | } | ||
| 33 | |||
| 34 | pub fn interface(&self) -> &'static str { | ||
| 35 | match self { | ||
| 36 | $(Self::$name => $interface,)* | ||
| 37 | } | ||
| 38 | } | ||
| 39 | } | ||
| 40 | }; | ||
| 41 | } | ||
| 42 | |||
| 43 | define_machines!( | ||
| 44 | (Alakazam01, 0, "alakazam-01", todo!()), | ||
| 45 | (Alakazam02, 1, "alakazam-02", todo!()), | ||
| 46 | (Alakazam03, 2, "alakazam-03", todo!()), | ||
| 47 | (Alakazam04, 3, "alakazam-04", todo!()), | ||
| 48 | (Alakazam05, 4, "alakazam-05", todo!()), | ||
| 49 | (Alakazam06, 5, "alakazam-06", todo!()), | ||
| 50 | (Alakazam07, 6, "alakazam-07", todo!()), | ||
| 51 | (Alakazam08, 7, "alakazam-08", todo!()), | ||
| 52 | (Bulbasaur1, 8, "bulbasaur-1", todo!()), | ||
| 53 | (Bulbasaur2, 9, "bulbasaur-2", todo!()), | ||
| 54 | (Bulbasaur3, 10, "bulbasaur-3", todo!()), | ||
| 55 | (Charmander1, 11, "charmander-1", "bond0"), | ||
| 56 | (Charmander2, 12, "charmander-2", "bond0"), | ||
| 57 | (Charmander3, 13, "charmander-3", "bond0"), | ||
| 58 | (Charmander4, 14, "charmander-4", "bond0"), | ||
| 59 | (Charmander5, 15, "charmander-5", "bond0"), | ||
| 60 | (Gengar1, 16, "gengar-1", "bond0"), | ||
| 61 | (Gengar2, 17, "gengar-2", "bond0"), | ||
| 62 | (Gengar3, 18, "gengar-3", "bond0"), | ||
| 63 | (Gengar4, 19, "gengar-4", "bond0"), | ||
| 64 | (Gengar5, 20, "gengar-5", "bond0"), | ||
| 65 | (Kadabra01, 21, "kadabra-01", todo!()), | ||
| 66 | (Kadabra02, 22, "kadabra-02", todo!()), | ||
| 67 | (Kadabra03, 23, "kadabra-03", todo!()), | ||
| 68 | (Kadabra04, 24, "kadabra-04", todo!()), | ||
| 69 | (Kadabra05, 25, "kadabra-05", todo!()), | ||
| 70 | (Kadabra06, 26, "kadabra-06", todo!()), | ||
| 71 | (Kadabra07, 27, "kadabra-07", todo!()), | ||
| 72 | (Kadabra08, 28, "kadabra-08", todo!()), | ||
| 73 | (Lugia1, 29, "lugia-1", "bond0"), | ||
| 74 | (Lugia2, 30, "lugia-2", "bond0"), | ||
| 75 | (Lugia3, 31, "lugia-3", "bond0"), | ||
| 76 | (Lugia4, 32, "lugia-4", "bond0"), | ||
| 77 | (Lugia5, 33, "lugia-5", "bond0"), | ||
| 78 | (Magikarp1, 34, "magikarp-1", todo!()), | ||
| 79 | (Moltres01, 35, "moltres-01", todo!()), | ||
| 80 | (Moltres02, 36, "moltres-02", todo!()), | ||
| 81 | (Moltres03, 37, "moltres-03", todo!()), | ||
| 82 | (Moltres04, 38, "moltres-04", todo!()), | ||
| 83 | (Moltres05, 39, "moltres-05", todo!()), | ||
| 84 | (Moltres06, 40, "moltres-06", todo!()), | ||
| 85 | (Moltres07, 41, "moltres-07", todo!()), | ||
| 86 | (Moltres08, 42, "moltres-08", todo!()), | ||
| 87 | (Moltres09, 43, "moltres-09", todo!()), | ||
| 88 | (Moltres10, 44, "moltres-10", todo!()), | ||
| 89 | (Oddish1, 45, "oddish-1", todo!()), | ||
| 90 | (Psyduck1, 46, "psyduck-1", todo!()), | ||
| 91 | (Psyduck2, 47, "psyduck-2", todo!()), | ||
| 92 | (Psyduck3, 48, "psyduck-3", todo!()), | ||
| 93 | (Shelder1, 49, "shelder-1", todo!()), | ||
| 94 | (Squirtle1, 50, "squirtle-1", todo!()), | ||
| 95 | (Squirtle2, 51, "squirtle-2", todo!()), | ||
| 96 | (Squirtle3, 52, "squirtle-3", todo!()), | ||
| 97 | (Squirtle4, 53, "squirtle-4", todo!()), | ||
| 98 | (Staryu1, 54, "staryu-1", todo!()), | ||
| 99 | (Sudowoodo1, 55, "sudowoodo-1", todo!()), | ||
| 100 | (Vulpix1, 56, "vulpix-1", todo!()) | ||
| 101 | ); | ||
diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..dfbddc0 --- /dev/null +++ b/src/main.rs | |||
| @@ -0,0 +1,252 @@ | |||
| 1 | use std::collections::{HashMap, HashSet}; | ||
| 2 | |||
| 3 | use clap::Parser; | ||
| 4 | use eyre::Context as _; | ||
| 5 | use machine::Machine; | ||
| 6 | use serde::Deserialize; | ||
| 7 | use tokio::process::Command; | ||
| 8 | |||
| 9 | pub mod latency_matrix; | ||
| 10 | pub mod machine; | ||
| 11 | |||
| 12 | #[derive(Debug, Parser)] | ||
| 13 | pub struct Args { | ||
| 14 | #[clap(long, env = "OAR_JOB_ID")] | ||
| 15 | pub job_id: Option<u32>, | ||
| 16 | #[clap(long, env = "FRONTEND_HOSTNAME")] | ||
| 17 | pub frontend_hostname: Option<String>, | ||
| 18 | } | ||
| 19 | |||
| 20 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
| 21 | pub enum ExecutionNode { | ||
| 22 | Frontend, | ||
| 23 | Machine(Machine), | ||
| 24 | Unknown, | ||
| 25 | } | ||
| 26 | |||
| 27 | pub struct Context { | ||
| 28 | pub node: ExecutionNode, | ||
| 29 | pub job_id: Option<u32>, | ||
| 30 | pub frontend_hostname: Option<String>, | ||
| 31 | } | ||
| 32 | |||
| 33 | pub struct MachineConfig { | ||
| 34 | machine | ||
| 35 | } | ||
| 36 | |||
| 37 | #[tokio::main] | ||
| 38 | async fn main() -> eyre::Result<()> { | ||
| 39 | tracing_subscriber::fmt::init(); | ||
| 40 | color_eyre::install()?; | ||
| 41 | |||
| 42 | let args = Args::parse(); | ||
| 43 | let node = get_execution_node()?; | ||
| 44 | let context = Context { | ||
| 45 | node, | ||
| 46 | job_id: args.job_id, | ||
| 47 | frontend_hostname: args.frontend_hostname, | ||
| 48 | }; | ||
| 49 | let machines = list_job_machines(&context).await?; | ||
| 50 | |||
| 51 | // listing oar job machines | ||
| 52 | // if we are in the frontend we use oarstat | ||
| 53 | // if we are in a job machine we read the cpuset file | ||
| 54 | // if we are outside the cluster we use ssh cluster oarstat | ||
| 55 | |||
| 56 | // machine generate configurations | ||
| 57 | // this does not require any connections | ||
| 58 | |||
| 59 | // machine cleanup interface | ||
| 60 | // requires running commands inside a container inside a machine | ||
| 61 | // we could generate a cleanup bash script and execute that in oneshot | ||
| 62 | |||
| 63 | // machine apply configuration | ||
| 64 | // this also requires running some scripts inside a container inside the machine | ||
| 65 | |||
| 66 | Ok(()) | ||
| 67 | } | ||
| 68 | |||
| 69 | async fn list_job_machines(ctx: &Context) -> eyre::Result<Vec<Machine>> { | ||
| 70 | match ctx.node { | ||
| 71 | ExecutionNode::Frontend => { | ||
| 72 | let job_id = match ctx.job_id { | ||
| 73 | Some(job_id) => job_id, | ||
| 74 | None => return Err(eyre::eyre!("job id is required when running from cluster")), | ||
| 75 | }; | ||
| 76 | |||
| 77 | let output = Command::new("oarstat") | ||
| 78 | .arg("-j") | ||
| 79 | .arg(job_id.to_string()) | ||
| 80 | .arg("-J") | ||
| 81 | .output() | ||
| 82 | .await?; | ||
| 83 | |||
| 84 | if !output.status.success() { | ||
| 85 | tracing::error!( | ||
| 86 | "stdout: {}", | ||
| 87 | std::str::from_utf8(&output.stdout).unwrap_or("stderr contains invalid uft-8") | ||
| 88 | ); | ||
| 89 | tracing::error!( | ||
| 90 | "stderr: {}", | ||
| 91 | std::str::from_utf8(&output.stderr).unwrap_or("stderr contains invalid uft-8") | ||
| 92 | ); | ||
| 93 | return Err(eyre::eyre!("failed to run oarstat")); | ||
| 94 | } | ||
| 95 | |||
| 96 | let stdout = std::str::from_utf8(&output.stdout)?; | ||
| 97 | extract_machines_from_oar_stat_json(&stdout, job_id) | ||
| 98 | } | ||
| 99 | ExecutionNode::Unknown => { | ||
| 100 | let frontend_hostname = match ctx.frontend_hostname.as_ref() { | ||
| 101 | Some(hostname) => hostname, | ||
| 102 | None => { | ||
| 103 | return Err(eyre::eyre!( | ||
| 104 | "frontend hostname is requiredwhen running from outside the cluster" | ||
| 105 | )); | ||
| 106 | } | ||
| 107 | }; | ||
| 108 | |||
| 109 | let job_id = match ctx.job_id { | ||
| 110 | Some(job_id) => job_id, | ||
| 111 | None => return Err(eyre::eyre!("job id is required when running from cluster")), | ||
| 112 | }; | ||
| 113 | |||
| 114 | let output = Command::new("ssh") | ||
| 115 | .arg(frontend_hostname) | ||
| 116 | .arg("oarstat") | ||
| 117 | .arg("-j") | ||
| 118 | .arg(job_id.to_string()) | ||
| 119 | .arg("-J") | ||
| 120 | .output() | ||
| 121 | .await?; | ||
| 122 | |||
| 123 | if !output.status.success() { | ||
| 124 | return Err(eyre::eyre!("failed to run oarstat")); | ||
| 125 | } | ||
| 126 | |||
| 127 | let stdout = std::str::from_utf8(&output.stdout)?; | ||
| 128 | extract_machines_from_oar_stat_json(&stdout, job_id) | ||
| 129 | } | ||
| 130 | ExecutionNode::Machine(_) => { | ||
| 131 | let nodefile = std::env::var("OAR_NODEFILE").context("reading OAR_NODEFILE env var")?; | ||
| 132 | let content = tokio::fs::read_to_string(&nodefile).await?; | ||
| 133 | let unique_lines = content | ||
| 134 | .lines() | ||
| 135 | .map(|l| l.trim()) | ||
| 136 | .filter(|l| !l.is_empty()) | ||
| 137 | .collect::<HashSet<_>>(); | ||
| 138 | let mut machines = Vec::default(); | ||
| 139 | for hostname in unique_lines { | ||
| 140 | let machine = match Machine::from_hostname(hostname) { | ||
| 141 | Some(machine) => machine, | ||
| 142 | None => return Err(eyre::eyre!("unknown machine: {hostname}")), | ||
| 143 | }; | ||
| 144 | machines.push(machine); | ||
| 145 | } | ||
| 146 | Ok(machines) | ||
| 147 | } | ||
| 148 | } | ||
| 149 | } | ||
| 150 | |||
| 151 | fn extract_machines_from_oar_stat_json(output: &str, job_id: u32) -> eyre::Result<Vec<Machine>> { | ||
| 152 | #[derive(Debug, Deserialize)] | ||
| 153 | struct JobSchema { | ||
| 154 | assigned_network_address: Vec<String>, | ||
| 155 | } | ||
| 156 | let map = serde_json::from_str::<HashMap<String, JobSchema>>(output)?; | ||
| 157 | let key = job_id.to_string(); | ||
| 158 | let data = map | ||
| 159 | .get(&key) | ||
| 160 | .ok_or_else(|| eyre::eyre!("missing job key"))?; | ||
| 161 | let mut machines = Vec::default(); | ||
| 162 | for hostname in data.assigned_network_address.iter() { | ||
| 163 | match Machine::from_hostname(hostname) { | ||
| 164 | Some(machine) => machines.push(machine), | ||
| 165 | None => return Err(eyre::eyre!("unknown machine: '{hostname}'")), | ||
| 166 | } | ||
| 167 | } | ||
| 168 | Ok(machines) | ||
| 169 | } | ||
| 170 | |||
| 171 | fn get_execution_node() -> eyre::Result<ExecutionNode> { | ||
| 172 | let hostname = get_hostname()?; | ||
| 173 | let node = match hostname.as_str() { | ||
| 174 | "frontend" => ExecutionNode::Frontend, | ||
| 175 | _ => match Machine::from_hostname(&hostname) { | ||
| 176 | Some(machine) => ExecutionNode::Machine(machine), | ||
| 177 | _ => ExecutionNode::Unknown, | ||
| 178 | }, | ||
| 179 | }; | ||
| 180 | Ok(node) | ||
| 181 | } | ||
| 182 | |||
| 183 | fn get_hostname() -> eyre::Result<String> { | ||
| 184 | std::env::var("HOSTNAME").context("reading HOSTNAME env var") | ||
| 185 | } | ||
| 186 | |||
| 187 | #[cfg(test)] | ||
| 188 | mod test { | ||
| 189 | use super::*; | ||
| 190 | |||
| 191 | const OAR_STAT_JSON_JOB_ID: u32 = 36627; | ||
| 192 | const OAR_STAT_JSON_OUTPUT: &'static str = r#" | ||
| 193 | { | ||
| 194 | "36627" : { | ||
| 195 | "types" : [], | ||
| 196 | "reservation" : "None", | ||
| 197 | "dependencies" : [], | ||
| 198 | "Job_Id" : 36627, | ||
| 199 | "assigned_network_address" : [ | ||
| 200 | "gengar-1", | ||
| 201 | "gengar-2" | ||
| 202 | ], | ||
| 203 | "owner" : "diogo464", | ||
| 204 | "properties" : "(( ( dedicated='NO' OR dedicated='protocol-labs' )) AND desktop_computing = 'NO') AND drain='NO'", | ||
| 205 | "startTime" : 1751979909, | ||
| 206 | "cpuset_name" : "diogo464_36627", | ||
| 207 | "stderr_file" : "OAR.36627.stderr", | ||
| 208 | "queue" : "default", | ||
| 209 | "state" : "Running", | ||
| 210 | "stdout_file" : "OAR.36627.stdout", | ||
| 211 | "array_index" : 1, | ||
| 212 | "array_id" : 36627, | ||
| 213 | "assigned_resources" : [ | ||
| 214 | 419, | ||
| 215 | 420, | ||
| 216 | 421, | ||
| 217 | 422, | ||
| 218 | 423, | ||
| 219 | 424, | ||
| 220 | 425, | ||
| 221 | 426, | ||
| 222 | 427, | ||
| 223 | 428, | ||
| 224 | 429, | ||
| 225 | 430, | ||
| 226 | 431, | ||
| 227 | 432, | ||
| 228 | 433, | ||
| 229 | 434 | ||
| 230 | ], | ||
| 231 | "name" : null, | ||
| 232 | "resubmit_job_id" : 0, | ||
| 233 | "message" : "R=16,W=12:0:0,J=B (Karma=0.087,quota_ok)", | ||
| 234 | "launchingDirectory" : "/home/diogo464", | ||
| 235 | "jobType" : "PASSIVE", | ||
| 236 | "submissionTime" : 1751979897, | ||
| 237 | "project" : "default", | ||
| 238 | "command" : "sleep 365d" | ||
| 239 | } | ||
| 240 | } | ||
| 241 | "#; | ||
| 242 | |||
| 243 | #[test] | ||
| 244 | fn test_extract_machines_from_oar_stat_json() { | ||
| 245 | let machines = | ||
| 246 | extract_machines_from_oar_stat_json(OAR_STAT_JSON_OUTPUT, OAR_STAT_JSON_JOB_ID) | ||
| 247 | .unwrap(); | ||
| 248 | assert_eq!(machines.len(), 2); | ||
| 249 | assert_eq!(machines[0], Machine::Gengar1); | ||
| 250 | assert_eq!(machines[1], Machine::Gengar2); | ||
| 251 | } | ||
| 252 | } | ||
