├── .github └── workflows │ └── rust.yml ├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── LICENSE ├── README.md ├── src ├── config.rs ├── connector.rs ├── error.rs ├── lib.rs ├── main.rs ├── proxy.rs ├── quic │ ├── client.rs │ ├── mod.rs │ ├── proto.rs │ ├── server │ │ ├── conn.rs │ │ ├── mod.rs │ │ └── stream.rs │ └── stream.rs └── socks5 │ ├── conn.rs │ ├── error.rs │ ├── mod.rs │ ├── proto.rs │ └── server.rs └── tests └── test.rs /.github/workflows/rust.yml: -------------------------------------------------------------------------------- 1 | name: Rust 2 | 3 | on: 4 | push: 5 | # Sequence of patterns matched against refs/tags 6 | tags: 7 | - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 8 | 9 | env: 10 | CARGO_TERM_COLOR: always 11 | 12 | jobs: 13 | build-linux: 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/checkout@v2 17 | - name: Build 18 | run: cargo build --verbose --release 19 | - name: Run tests 20 | run: cargo test --verbose 21 | - name: Create artifact directory 22 | run: mkdir artifacts 23 | - name: Upload binaries to release 24 | uses: svenstaro/upload-release-action@v1-release 25 | with: 26 | repo_token: ${{ secrets.GITHUB_TOKEN }} 27 | file: target/release/magicalane 28 | asset_name: magicalane-linux 29 | tag: ${{ github.ref }} 30 | overwrite: true 31 | build-macos: 32 | runs-on: macOS-latest 33 | steps: 34 | - uses: actions/checkout@v2 35 | - name: Build 36 | run: cargo build --verbose --release 37 | - name: Run tests 38 | run: cargo test --verbose 39 | - name: Create artifact directory 40 | run: mkdir artifacts 41 | - name: Upload binaries to release 42 | uses: svenstaro/upload-release-action@v1-release 43 | with: 44 | repo_token: ${{ secrets.GITHUB_TOKEN }} 45 | file: target/release/magicalane 46 | asset_name: magicalane-macOS 47 | tag: ${{ github.ref }} 48 | overwrite: true 49 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /.idea 3 | /log 4 | magicalane.iml 5 | .vscode/ 6 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "aho-corasick" 7 | version = "0.7.18" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" 10 | dependencies = [ 11 | "memchr", 12 | ] 13 | 14 | [[package]] 15 | name = "ansi_term" 16 | version = "0.11.0" 17 | source = "registry+https://github.com/rust-lang/crates.io-index" 18 | checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" 19 | dependencies = [ 20 | "winapi", 21 | ] 22 | 23 | [[package]] 24 | name = "ansi_term" 25 | version = "0.12.1" 26 | source = "registry+https://github.com/rust-lang/crates.io-index" 27 | checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" 28 | dependencies = [ 29 | "winapi", 30 | ] 31 | 32 | [[package]] 33 | name = "anyhow" 34 | version = "1.0.40" 35 | source = "registry+https://github.com/rust-lang/crates.io-index" 36 | checksum = "28b2cd92db5cbd74e8e5028f7e27dd7aa3090e89e4f2a197cc7c8dfb69c7063b" 37 | 38 | [[package]] 39 | name = "atty" 40 | version = "0.2.14" 41 | source = "registry+https://github.com/rust-lang/crates.io-index" 42 | checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" 43 | dependencies = [ 44 | "hermit-abi", 45 | "libc", 46 | "winapi", 47 | ] 48 | 49 | [[package]] 50 | name = "autocfg" 51 | version = "1.0.1" 52 | source = "registry+https://github.com/rust-lang/crates.io-index" 53 | checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" 54 | 55 | [[package]] 56 | name = "base64" 57 | version = "0.12.3" 58 | source = "registry+https://github.com/rust-lang/crates.io-index" 59 | checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" 60 | 61 | [[package]] 62 | name = "base64" 63 | version = "0.13.0" 64 | source = "registry+https://github.com/rust-lang/crates.io-index" 65 | checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" 66 | 67 | [[package]] 68 | name = "bencher" 69 | version = "0.1.5" 70 | source = "registry+https://github.com/rust-lang/crates.io-index" 71 | checksum = "7dfdb4953a096c551ce9ace855a604d702e6e62d77fac690575ae347571717f5" 72 | 73 | [[package]] 74 | name = "bitflags" 75 | version = "1.2.1" 76 | source = "registry+https://github.com/rust-lang/crates.io-index" 77 | checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" 78 | 79 | [[package]] 80 | name = "bumpalo" 81 | version = "3.7.0" 82 | source = "registry+https://github.com/rust-lang/crates.io-index" 83 | checksum = "9c59e7af012c713f529e7a3ee57ce9b31ddd858d4b512923602f74608b009631" 84 | 85 | [[package]] 86 | name = "bytes" 87 | version = "1.0.1" 88 | source = "registry+https://github.com/rust-lang/crates.io-index" 89 | checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040" 90 | 91 | [[package]] 92 | name = "cc" 93 | version = "1.0.68" 94 | source = "registry+https://github.com/rust-lang/crates.io-index" 95 | checksum = "4a72c244c1ff497a746a7e1fb3d14bd08420ecda70c8f25c7112f2781652d787" 96 | 97 | [[package]] 98 | name = "cfg-if" 99 | version = "0.1.10" 100 | source = "registry+https://github.com/rust-lang/crates.io-index" 101 | checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" 102 | 103 | [[package]] 104 | name = "cfg-if" 105 | version = "1.0.0" 106 | source = "registry+https://github.com/rust-lang/crates.io-index" 107 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 108 | 109 | [[package]] 110 | name = "chrono" 111 | version = "0.4.19" 112 | source = "registry+https://github.com/rust-lang/crates.io-index" 113 | checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" 114 | dependencies = [ 115 | "libc", 116 | "num-integer", 117 | "num-traits", 118 | "time", 119 | "winapi", 120 | ] 121 | 122 | [[package]] 123 | name = "clap" 124 | version = "2.33.3" 125 | source = "registry+https://github.com/rust-lang/crates.io-index" 126 | checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" 127 | dependencies = [ 128 | "ansi_term 0.11.0", 129 | "atty", 130 | "bitflags", 131 | "strsim", 132 | "textwrap", 133 | "unicode-width", 134 | "vec_map", 135 | ] 136 | 137 | [[package]] 138 | name = "core-foundation" 139 | version = "0.9.1" 140 | source = "registry+https://github.com/rust-lang/crates.io-index" 141 | checksum = "0a89e2ae426ea83155dccf10c0fa6b1463ef6d5fcb44cee0b224a408fa640a62" 142 | dependencies = [ 143 | "core-foundation-sys", 144 | "libc", 145 | ] 146 | 147 | [[package]] 148 | name = "core-foundation-sys" 149 | version = "0.8.2" 150 | source = "registry+https://github.com/rust-lang/crates.io-index" 151 | checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b" 152 | 153 | [[package]] 154 | name = "crossbeam-channel" 155 | version = "0.5.1" 156 | source = "registry+https://github.com/rust-lang/crates.io-index" 157 | checksum = "06ed27e177f16d65f0f0c22a213e17c696ace5dd64b14258b52f9417ccb52db4" 158 | dependencies = [ 159 | "cfg-if 1.0.0", 160 | "crossbeam-utils", 161 | ] 162 | 163 | [[package]] 164 | name = "crossbeam-utils" 165 | version = "0.8.5" 166 | source = "registry+https://github.com/rust-lang/crates.io-index" 167 | checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db" 168 | dependencies = [ 169 | "cfg-if 1.0.0", 170 | "lazy_static", 171 | ] 172 | 173 | [[package]] 174 | name = "ct-logs" 175 | version = "0.8.0" 176 | source = "registry+https://github.com/rust-lang/crates.io-index" 177 | checksum = "c1a816186fa68d9e426e3cb4ae4dff1fcd8e4a2c34b781bf7a822574a0d0aac8" 178 | dependencies = [ 179 | "sct", 180 | ] 181 | 182 | [[package]] 183 | name = "directories" 184 | version = "2.0.2" 185 | source = "registry+https://github.com/rust-lang/crates.io-index" 186 | checksum = "551a778172a450d7fc12e629ca3b0428d00f6afa9a43da1b630d54604e97371c" 187 | dependencies = [ 188 | "cfg-if 0.1.10", 189 | "dirs-sys", 190 | ] 191 | 192 | [[package]] 193 | name = "directories-next" 194 | version = "1.0.3" 195 | source = "registry+https://github.com/rust-lang/crates.io-index" 196 | checksum = "8a28ccebc1239c5c57f0c55986e2ac03f49af0d0ca3dff29bfcad39d60a8be56" 197 | dependencies = [ 198 | "cfg-if 1.0.0", 199 | "dirs-sys-next", 200 | ] 201 | 202 | [[package]] 203 | name = "dirs-sys" 204 | version = "0.3.6" 205 | source = "registry+https://github.com/rust-lang/crates.io-index" 206 | checksum = "03d86534ed367a67548dc68113a0f5db55432fdfbb6e6f9d77704397d95d5780" 207 | dependencies = [ 208 | "libc", 209 | "redox_users", 210 | "winapi", 211 | ] 212 | 213 | [[package]] 214 | name = "dirs-sys-next" 215 | version = "0.1.2" 216 | source = "registry+https://github.com/rust-lang/crates.io-index" 217 | checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" 218 | dependencies = [ 219 | "libc", 220 | "redox_users", 221 | "winapi", 222 | ] 223 | 224 | [[package]] 225 | name = "env_logger" 226 | version = "0.9.0" 227 | source = "registry+https://github.com/rust-lang/crates.io-index" 228 | checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3" 229 | dependencies = [ 230 | "atty", 231 | "humantime", 232 | "log", 233 | "regex", 234 | "termcolor", 235 | ] 236 | 237 | [[package]] 238 | name = "futures" 239 | version = "0.3.15" 240 | source = "registry+https://github.com/rust-lang/crates.io-index" 241 | checksum = "0e7e43a803dae2fa37c1f6a8fe121e1f7bf9548b4dfc0522a42f34145dadfc27" 242 | dependencies = [ 243 | "futures-channel", 244 | "futures-core", 245 | "futures-executor", 246 | "futures-io", 247 | "futures-sink", 248 | "futures-task", 249 | "futures-util", 250 | ] 251 | 252 | [[package]] 253 | name = "futures-channel" 254 | version = "0.3.15" 255 | source = "registry+https://github.com/rust-lang/crates.io-index" 256 | checksum = "e682a68b29a882df0545c143dc3646daefe80ba479bcdede94d5a703de2871e2" 257 | dependencies = [ 258 | "futures-core", 259 | "futures-sink", 260 | ] 261 | 262 | [[package]] 263 | name = "futures-core" 264 | version = "0.3.15" 265 | source = "registry+https://github.com/rust-lang/crates.io-index" 266 | checksum = "0402f765d8a89a26043b889b26ce3c4679d268fa6bb22cd7c6aad98340e179d1" 267 | 268 | [[package]] 269 | name = "futures-executor" 270 | version = "0.3.15" 271 | source = "registry+https://github.com/rust-lang/crates.io-index" 272 | checksum = "badaa6a909fac9e7236d0620a2f57f7664640c56575b71a7552fbd68deafab79" 273 | dependencies = [ 274 | "futures-core", 275 | "futures-task", 276 | "futures-util", 277 | ] 278 | 279 | [[package]] 280 | name = "futures-io" 281 | version = "0.3.15" 282 | source = "registry+https://github.com/rust-lang/crates.io-index" 283 | checksum = "acc499defb3b348f8d8f3f66415835a9131856ff7714bf10dadfc4ec4bdb29a1" 284 | 285 | [[package]] 286 | name = "futures-macro" 287 | version = "0.3.15" 288 | source = "registry+https://github.com/rust-lang/crates.io-index" 289 | checksum = "a4c40298486cdf52cc00cd6d6987892ba502c7656a16a4192a9992b1ccedd121" 290 | dependencies = [ 291 | "autocfg", 292 | "proc-macro-hack", 293 | "proc-macro2", 294 | "quote", 295 | "syn", 296 | ] 297 | 298 | [[package]] 299 | name = "futures-sink" 300 | version = "0.3.15" 301 | source = "registry+https://github.com/rust-lang/crates.io-index" 302 | checksum = "a57bead0ceff0d6dde8f465ecd96c9338121bb7717d3e7b108059531870c4282" 303 | 304 | [[package]] 305 | name = "futures-task" 306 | version = "0.3.15" 307 | source = "registry+https://github.com/rust-lang/crates.io-index" 308 | checksum = "8a16bef9fc1a4dddb5bee51c989e3fbba26569cbb0e31f5b303c184e3dd33dae" 309 | 310 | [[package]] 311 | name = "futures-util" 312 | version = "0.3.15" 313 | source = "registry+https://github.com/rust-lang/crates.io-index" 314 | checksum = "feb5c238d27e2bf94ffdfd27b2c29e3df4a68c4193bb6427384259e2bf191967" 315 | dependencies = [ 316 | "autocfg", 317 | "futures-channel", 318 | "futures-core", 319 | "futures-io", 320 | "futures-macro", 321 | "futures-sink", 322 | "futures-task", 323 | "memchr", 324 | "pin-project-lite", 325 | "pin-utils", 326 | "proc-macro-hack", 327 | "proc-macro-nested", 328 | "slab", 329 | ] 330 | 331 | [[package]] 332 | name = "getrandom" 333 | version = "0.1.16" 334 | source = "registry+https://github.com/rust-lang/crates.io-index" 335 | checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" 336 | dependencies = [ 337 | "cfg-if 1.0.0", 338 | "libc", 339 | "wasi 0.9.0+wasi-snapshot-preview1", 340 | ] 341 | 342 | [[package]] 343 | name = "getrandom" 344 | version = "0.2.3" 345 | source = "registry+https://github.com/rust-lang/crates.io-index" 346 | checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" 347 | dependencies = [ 348 | "cfg-if 1.0.0", 349 | "libc", 350 | "wasi 0.10.2+wasi-snapshot-preview1", 351 | ] 352 | 353 | [[package]] 354 | name = "heck" 355 | version = "0.3.3" 356 | source = "registry+https://github.com/rust-lang/crates.io-index" 357 | checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" 358 | dependencies = [ 359 | "unicode-segmentation", 360 | ] 361 | 362 | [[package]] 363 | name = "hermit-abi" 364 | version = "0.1.18" 365 | source = "registry+https://github.com/rust-lang/crates.io-index" 366 | checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" 367 | dependencies = [ 368 | "libc", 369 | ] 370 | 371 | [[package]] 372 | name = "humantime" 373 | version = "2.1.0" 374 | source = "registry+https://github.com/rust-lang/crates.io-index" 375 | checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" 376 | 377 | [[package]] 378 | name = "instant" 379 | version = "0.1.9" 380 | source = "registry+https://github.com/rust-lang/crates.io-index" 381 | checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec" 382 | dependencies = [ 383 | "cfg-if 1.0.0", 384 | ] 385 | 386 | [[package]] 387 | name = "js-sys" 388 | version = "0.3.51" 389 | source = "registry+https://github.com/rust-lang/crates.io-index" 390 | checksum = "83bdfbace3a0e81a4253f73b49e960b053e396a11012cbd49b9b74d6a2b67062" 391 | dependencies = [ 392 | "wasm-bindgen", 393 | ] 394 | 395 | [[package]] 396 | name = "lazy_static" 397 | version = "1.4.0" 398 | source = "registry+https://github.com/rust-lang/crates.io-index" 399 | checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" 400 | 401 | [[package]] 402 | name = "libc" 403 | version = "0.2.95" 404 | source = "registry+https://github.com/rust-lang/crates.io-index" 405 | checksum = "789da6d93f1b866ffe175afc5322a4d76c038605a1c3319bb57b06967ca98a36" 406 | 407 | [[package]] 408 | name = "lock_api" 409 | version = "0.4.4" 410 | source = "registry+https://github.com/rust-lang/crates.io-index" 411 | checksum = "0382880606dff6d15c9476c416d18690b72742aa7b605bb6dd6ec9030fbf07eb" 412 | dependencies = [ 413 | "scopeguard", 414 | ] 415 | 416 | [[package]] 417 | name = "log" 418 | version = "0.4.14" 419 | source = "registry+https://github.com/rust-lang/crates.io-index" 420 | checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" 421 | dependencies = [ 422 | "cfg-if 1.0.0", 423 | ] 424 | 425 | [[package]] 426 | name = "magicalane" 427 | version = "0.1.0" 428 | dependencies = [ 429 | "anyhow", 430 | "bencher", 431 | "bytes", 432 | "directories", 433 | "directories-next", 434 | "env_logger", 435 | "futures", 436 | "futures-core", 437 | "libc", 438 | "log", 439 | "pin-project", 440 | "quinn", 441 | "quinn-proto", 442 | "rand 0.7.3", 443 | "rcgen", 444 | "rustls 0.18.1", 445 | "serde", 446 | "socket2 0.4.0", 447 | "structopt", 448 | "thiserror", 449 | "tokio", 450 | "tokio-trace", 451 | "tokio-util", 452 | "toml", 453 | "tracing", 454 | "tracing-appender", 455 | "tracing-futures", 456 | "tracing-log", 457 | "tracing-subscriber", 458 | "webpki", 459 | ] 460 | 461 | [[package]] 462 | name = "matchers" 463 | version = "0.0.1" 464 | source = "registry+https://github.com/rust-lang/crates.io-index" 465 | checksum = "f099785f7595cc4b4553a174ce30dd7589ef93391ff414dbb67f62392b9e0ce1" 466 | dependencies = [ 467 | "regex-automata", 468 | ] 469 | 470 | [[package]] 471 | name = "memchr" 472 | version = "2.4.0" 473 | source = "registry+https://github.com/rust-lang/crates.io-index" 474 | checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc" 475 | 476 | [[package]] 477 | name = "mio" 478 | version = "0.7.11" 479 | source = "registry+https://github.com/rust-lang/crates.io-index" 480 | checksum = "cf80d3e903b34e0bd7282b218398aec54e082c840d9baf8339e0080a0c542956" 481 | dependencies = [ 482 | "libc", 483 | "log", 484 | "miow", 485 | "ntapi", 486 | "winapi", 487 | ] 488 | 489 | [[package]] 490 | name = "miow" 491 | version = "0.3.7" 492 | source = "registry+https://github.com/rust-lang/crates.io-index" 493 | checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" 494 | dependencies = [ 495 | "winapi", 496 | ] 497 | 498 | [[package]] 499 | name = "ntapi" 500 | version = "0.3.6" 501 | source = "registry+https://github.com/rust-lang/crates.io-index" 502 | checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" 503 | dependencies = [ 504 | "winapi", 505 | ] 506 | 507 | [[package]] 508 | name = "num-integer" 509 | version = "0.1.44" 510 | source = "registry+https://github.com/rust-lang/crates.io-index" 511 | checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" 512 | dependencies = [ 513 | "autocfg", 514 | "num-traits", 515 | ] 516 | 517 | [[package]] 518 | name = "num-traits" 519 | version = "0.2.14" 520 | source = "registry+https://github.com/rust-lang/crates.io-index" 521 | checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" 522 | dependencies = [ 523 | "autocfg", 524 | ] 525 | 526 | [[package]] 527 | name = "num_cpus" 528 | version = "1.13.0" 529 | source = "registry+https://github.com/rust-lang/crates.io-index" 530 | checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" 531 | dependencies = [ 532 | "hermit-abi", 533 | "libc", 534 | ] 535 | 536 | [[package]] 537 | name = "once_cell" 538 | version = "1.7.2" 539 | source = "registry+https://github.com/rust-lang/crates.io-index" 540 | checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3" 541 | 542 | [[package]] 543 | name = "openssl-probe" 544 | version = "0.1.4" 545 | source = "registry+https://github.com/rust-lang/crates.io-index" 546 | checksum = "28988d872ab76095a6e6ac88d99b54fd267702734fd7ffe610ca27f533ddb95a" 547 | 548 | [[package]] 549 | name = "parking_lot" 550 | version = "0.11.1" 551 | source = "registry+https://github.com/rust-lang/crates.io-index" 552 | checksum = "6d7744ac029df22dca6284efe4e898991d28e3085c706c972bcd7da4a27a15eb" 553 | dependencies = [ 554 | "instant", 555 | "lock_api", 556 | "parking_lot_core", 557 | ] 558 | 559 | [[package]] 560 | name = "parking_lot_core" 561 | version = "0.8.3" 562 | source = "registry+https://github.com/rust-lang/crates.io-index" 563 | checksum = "fa7a782938e745763fe6907fc6ba86946d72f49fe7e21de074e08128a99fb018" 564 | dependencies = [ 565 | "cfg-if 1.0.0", 566 | "instant", 567 | "libc", 568 | "redox_syscall", 569 | "smallvec", 570 | "winapi", 571 | ] 572 | 573 | [[package]] 574 | name = "pem" 575 | version = "0.8.3" 576 | source = "registry+https://github.com/rust-lang/crates.io-index" 577 | checksum = "fd56cbd21fea48d0c440b41cd69c589faacade08c992d9a54e471b79d0fd13eb" 578 | dependencies = [ 579 | "base64 0.13.0", 580 | "once_cell", 581 | "regex", 582 | ] 583 | 584 | [[package]] 585 | name = "pin-project" 586 | version = "1.0.7" 587 | source = "registry+https://github.com/rust-lang/crates.io-index" 588 | checksum = "c7509cc106041c40a4518d2af7a61530e1eed0e6285296a3d8c5472806ccc4a4" 589 | dependencies = [ 590 | "pin-project-internal", 591 | ] 592 | 593 | [[package]] 594 | name = "pin-project-internal" 595 | version = "1.0.7" 596 | source = "registry+https://github.com/rust-lang/crates.io-index" 597 | checksum = "48c950132583b500556b1efd71d45b319029f2b71518d979fcc208e16b42426f" 598 | dependencies = [ 599 | "proc-macro2", 600 | "quote", 601 | "syn", 602 | ] 603 | 604 | [[package]] 605 | name = "pin-project-lite" 606 | version = "0.2.6" 607 | source = "registry+https://github.com/rust-lang/crates.io-index" 608 | checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905" 609 | 610 | [[package]] 611 | name = "pin-utils" 612 | version = "0.1.0" 613 | source = "registry+https://github.com/rust-lang/crates.io-index" 614 | checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" 615 | 616 | [[package]] 617 | name = "ppv-lite86" 618 | version = "0.2.10" 619 | source = "registry+https://github.com/rust-lang/crates.io-index" 620 | checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" 621 | 622 | [[package]] 623 | name = "proc-macro-error" 624 | version = "1.0.4" 625 | source = "registry+https://github.com/rust-lang/crates.io-index" 626 | checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" 627 | dependencies = [ 628 | "proc-macro-error-attr", 629 | "proc-macro2", 630 | "quote", 631 | "syn", 632 | "version_check", 633 | ] 634 | 635 | [[package]] 636 | name = "proc-macro-error-attr" 637 | version = "1.0.4" 638 | source = "registry+https://github.com/rust-lang/crates.io-index" 639 | checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" 640 | dependencies = [ 641 | "proc-macro2", 642 | "quote", 643 | "version_check", 644 | ] 645 | 646 | [[package]] 647 | name = "proc-macro-hack" 648 | version = "0.5.19" 649 | source = "registry+https://github.com/rust-lang/crates.io-index" 650 | checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" 651 | 652 | [[package]] 653 | name = "proc-macro-nested" 654 | version = "0.1.7" 655 | source = "registry+https://github.com/rust-lang/crates.io-index" 656 | checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086" 657 | 658 | [[package]] 659 | name = "proc-macro2" 660 | version = "1.0.27" 661 | source = "registry+https://github.com/rust-lang/crates.io-index" 662 | checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038" 663 | dependencies = [ 664 | "unicode-xid", 665 | ] 666 | 667 | [[package]] 668 | name = "quinn" 669 | version = "0.7.2" 670 | source = "registry+https://github.com/rust-lang/crates.io-index" 671 | checksum = "c82c0a393b300104f989f3db8b8637c0d11f7a32a9c214560b47849ba8f119aa" 672 | dependencies = [ 673 | "bytes", 674 | "futures", 675 | "lazy_static", 676 | "libc", 677 | "mio", 678 | "quinn-proto", 679 | "rustls 0.19.1", 680 | "socket2 0.3.19", 681 | "thiserror", 682 | "tokio", 683 | "tracing", 684 | "webpki", 685 | ] 686 | 687 | [[package]] 688 | name = "quinn-proto" 689 | version = "0.7.3" 690 | source = "registry+https://github.com/rust-lang/crates.io-index" 691 | checksum = "047aa96ec7ee6acabad7a1318dff72e9aff8994316bf2166c9b94cbec78ca54c" 692 | dependencies = [ 693 | "bytes", 694 | "ct-logs", 695 | "rand 0.8.3", 696 | "ring", 697 | "rustls 0.19.1", 698 | "rustls-native-certs", 699 | "slab", 700 | "thiserror", 701 | "tinyvec", 702 | "tracing", 703 | "webpki", 704 | ] 705 | 706 | [[package]] 707 | name = "quote" 708 | version = "1.0.9" 709 | source = "registry+https://github.com/rust-lang/crates.io-index" 710 | checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" 711 | dependencies = [ 712 | "proc-macro2", 713 | ] 714 | 715 | [[package]] 716 | name = "rand" 717 | version = "0.7.3" 718 | source = "registry+https://github.com/rust-lang/crates.io-index" 719 | checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" 720 | dependencies = [ 721 | "getrandom 0.1.16", 722 | "libc", 723 | "rand_chacha 0.2.2", 724 | "rand_core 0.5.1", 725 | "rand_hc 0.2.0", 726 | ] 727 | 728 | [[package]] 729 | name = "rand" 730 | version = "0.8.3" 731 | source = "registry+https://github.com/rust-lang/crates.io-index" 732 | checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e" 733 | dependencies = [ 734 | "libc", 735 | "rand_chacha 0.3.0", 736 | "rand_core 0.6.2", 737 | "rand_hc 0.3.0", 738 | ] 739 | 740 | [[package]] 741 | name = "rand_chacha" 742 | version = "0.2.2" 743 | source = "registry+https://github.com/rust-lang/crates.io-index" 744 | checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" 745 | dependencies = [ 746 | "ppv-lite86", 747 | "rand_core 0.5.1", 748 | ] 749 | 750 | [[package]] 751 | name = "rand_chacha" 752 | version = "0.3.0" 753 | source = "registry+https://github.com/rust-lang/crates.io-index" 754 | checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d" 755 | dependencies = [ 756 | "ppv-lite86", 757 | "rand_core 0.6.2", 758 | ] 759 | 760 | [[package]] 761 | name = "rand_core" 762 | version = "0.5.1" 763 | source = "registry+https://github.com/rust-lang/crates.io-index" 764 | checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" 765 | dependencies = [ 766 | "getrandom 0.1.16", 767 | ] 768 | 769 | [[package]] 770 | name = "rand_core" 771 | version = "0.6.2" 772 | source = "registry+https://github.com/rust-lang/crates.io-index" 773 | checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7" 774 | dependencies = [ 775 | "getrandom 0.2.3", 776 | ] 777 | 778 | [[package]] 779 | name = "rand_hc" 780 | version = "0.2.0" 781 | source = "registry+https://github.com/rust-lang/crates.io-index" 782 | checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" 783 | dependencies = [ 784 | "rand_core 0.5.1", 785 | ] 786 | 787 | [[package]] 788 | name = "rand_hc" 789 | version = "0.3.0" 790 | source = "registry+https://github.com/rust-lang/crates.io-index" 791 | checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73" 792 | dependencies = [ 793 | "rand_core 0.6.2", 794 | ] 795 | 796 | [[package]] 797 | name = "rcgen" 798 | version = "0.8.11" 799 | source = "registry+https://github.com/rust-lang/crates.io-index" 800 | checksum = "48b4fc1b81d685fcd442a86da2e2c829d9e353142633a8159f42bf28e7e94428" 801 | dependencies = [ 802 | "chrono", 803 | "pem", 804 | "ring", 805 | "yasna", 806 | ] 807 | 808 | [[package]] 809 | name = "redox_syscall" 810 | version = "0.2.8" 811 | source = "registry+https://github.com/rust-lang/crates.io-index" 812 | checksum = "742739e41cd49414de871ea5e549afb7e2a3ac77b589bcbebe8c82fab37147fc" 813 | dependencies = [ 814 | "bitflags", 815 | ] 816 | 817 | [[package]] 818 | name = "redox_users" 819 | version = "0.4.0" 820 | source = "registry+https://github.com/rust-lang/crates.io-index" 821 | checksum = "528532f3d801c87aec9def2add9ca802fe569e44a544afe633765267840abe64" 822 | dependencies = [ 823 | "getrandom 0.2.3", 824 | "redox_syscall", 825 | ] 826 | 827 | [[package]] 828 | name = "regex" 829 | version = "1.5.4" 830 | source = "registry+https://github.com/rust-lang/crates.io-index" 831 | checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" 832 | dependencies = [ 833 | "aho-corasick", 834 | "memchr", 835 | "regex-syntax", 836 | ] 837 | 838 | [[package]] 839 | name = "regex-automata" 840 | version = "0.1.10" 841 | source = "registry+https://github.com/rust-lang/crates.io-index" 842 | checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" 843 | dependencies = [ 844 | "regex-syntax", 845 | ] 846 | 847 | [[package]] 848 | name = "regex-syntax" 849 | version = "0.6.25" 850 | source = "registry+https://github.com/rust-lang/crates.io-index" 851 | checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" 852 | 853 | [[package]] 854 | name = "ring" 855 | version = "0.16.20" 856 | source = "registry+https://github.com/rust-lang/crates.io-index" 857 | checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" 858 | dependencies = [ 859 | "cc", 860 | "libc", 861 | "once_cell", 862 | "spin", 863 | "untrusted", 864 | "web-sys", 865 | "winapi", 866 | ] 867 | 868 | [[package]] 869 | name = "rustls" 870 | version = "0.18.1" 871 | source = "registry+https://github.com/rust-lang/crates.io-index" 872 | checksum = "5d1126dcf58e93cee7d098dbda643b5f92ed724f1f6a63007c1116eed6700c81" 873 | dependencies = [ 874 | "base64 0.12.3", 875 | "log", 876 | "ring", 877 | "sct", 878 | "webpki", 879 | ] 880 | 881 | [[package]] 882 | name = "rustls" 883 | version = "0.19.1" 884 | source = "registry+https://github.com/rust-lang/crates.io-index" 885 | checksum = "35edb675feee39aec9c99fa5ff985081995a06d594114ae14cbe797ad7b7a6d7" 886 | dependencies = [ 887 | "base64 0.13.0", 888 | "log", 889 | "ring", 890 | "sct", 891 | "webpki", 892 | ] 893 | 894 | [[package]] 895 | name = "rustls-native-certs" 896 | version = "0.5.0" 897 | source = "registry+https://github.com/rust-lang/crates.io-index" 898 | checksum = "5a07b7c1885bd8ed3831c289b7870b13ef46fe0e856d288c30d9cc17d75a2092" 899 | dependencies = [ 900 | "openssl-probe", 901 | "rustls 0.19.1", 902 | "schannel", 903 | "security-framework", 904 | ] 905 | 906 | [[package]] 907 | name = "schannel" 908 | version = "0.1.19" 909 | source = "registry+https://github.com/rust-lang/crates.io-index" 910 | checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" 911 | dependencies = [ 912 | "lazy_static", 913 | "winapi", 914 | ] 915 | 916 | [[package]] 917 | name = "scopeguard" 918 | version = "1.1.0" 919 | source = "registry+https://github.com/rust-lang/crates.io-index" 920 | checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" 921 | 922 | [[package]] 923 | name = "sct" 924 | version = "0.6.1" 925 | source = "registry+https://github.com/rust-lang/crates.io-index" 926 | checksum = "b362b83898e0e69f38515b82ee15aa80636befe47c3b6d3d89a911e78fc228ce" 927 | dependencies = [ 928 | "ring", 929 | "untrusted", 930 | ] 931 | 932 | [[package]] 933 | name = "security-framework" 934 | version = "2.3.1" 935 | source = "registry+https://github.com/rust-lang/crates.io-index" 936 | checksum = "23a2ac85147a3a11d77ecf1bc7166ec0b92febfa4461c37944e180f319ece467" 937 | dependencies = [ 938 | "bitflags", 939 | "core-foundation", 940 | "core-foundation-sys", 941 | "libc", 942 | "security-framework-sys", 943 | ] 944 | 945 | [[package]] 946 | name = "security-framework-sys" 947 | version = "2.3.0" 948 | source = "registry+https://github.com/rust-lang/crates.io-index" 949 | checksum = "7e4effb91b4b8b6fb7732e670b6cee160278ff8e6bf485c7805d9e319d76e284" 950 | dependencies = [ 951 | "core-foundation-sys", 952 | "libc", 953 | ] 954 | 955 | [[package]] 956 | name = "serde" 957 | version = "1.0.133" 958 | source = "registry+https://github.com/rust-lang/crates.io-index" 959 | checksum = "97565067517b60e2d1ea8b268e59ce036de907ac523ad83a0475da04e818989a" 960 | dependencies = [ 961 | "serde_derive", 962 | ] 963 | 964 | [[package]] 965 | name = "serde_derive" 966 | version = "1.0.133" 967 | source = "registry+https://github.com/rust-lang/crates.io-index" 968 | checksum = "ed201699328568d8d08208fdd080e3ff594e6c422e438b6705905da01005d537" 969 | dependencies = [ 970 | "proc-macro2", 971 | "quote", 972 | "syn", 973 | ] 974 | 975 | [[package]] 976 | name = "sharded-slab" 977 | version = "0.1.1" 978 | source = "registry+https://github.com/rust-lang/crates.io-index" 979 | checksum = "79c719719ee05df97490f80a45acfc99e5a30ce98a1e4fb67aee422745ae14e3" 980 | dependencies = [ 981 | "lazy_static", 982 | ] 983 | 984 | [[package]] 985 | name = "signal-hook-registry" 986 | version = "1.4.0" 987 | source = "registry+https://github.com/rust-lang/crates.io-index" 988 | checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0" 989 | dependencies = [ 990 | "libc", 991 | ] 992 | 993 | [[package]] 994 | name = "slab" 995 | version = "0.4.3" 996 | source = "registry+https://github.com/rust-lang/crates.io-index" 997 | checksum = "f173ac3d1a7e3b28003f40de0b5ce7fe2710f9b9dc3fc38664cebee46b3b6527" 998 | 999 | [[package]] 1000 | name = "smallvec" 1001 | version = "1.6.1" 1002 | source = "registry+https://github.com/rust-lang/crates.io-index" 1003 | checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" 1004 | 1005 | [[package]] 1006 | name = "socket2" 1007 | version = "0.3.19" 1008 | source = "registry+https://github.com/rust-lang/crates.io-index" 1009 | checksum = "122e570113d28d773067fab24266b66753f6ea915758651696b6e35e49f88d6e" 1010 | dependencies = [ 1011 | "cfg-if 1.0.0", 1012 | "libc", 1013 | "winapi", 1014 | ] 1015 | 1016 | [[package]] 1017 | name = "socket2" 1018 | version = "0.4.0" 1019 | source = "registry+https://github.com/rust-lang/crates.io-index" 1020 | checksum = "9e3dfc207c526015c632472a77be09cf1b6e46866581aecae5cc38fb4235dea2" 1021 | dependencies = [ 1022 | "libc", 1023 | "winapi", 1024 | ] 1025 | 1026 | [[package]] 1027 | name = "spin" 1028 | version = "0.5.2" 1029 | source = "registry+https://github.com/rust-lang/crates.io-index" 1030 | checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" 1031 | 1032 | [[package]] 1033 | name = "strsim" 1034 | version = "0.8.0" 1035 | source = "registry+https://github.com/rust-lang/crates.io-index" 1036 | checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" 1037 | 1038 | [[package]] 1039 | name = "structopt" 1040 | version = "0.3.21" 1041 | source = "registry+https://github.com/rust-lang/crates.io-index" 1042 | checksum = "5277acd7ee46e63e5168a80734c9f6ee81b1367a7d8772a2d765df2a3705d28c" 1043 | dependencies = [ 1044 | "clap", 1045 | "lazy_static", 1046 | "structopt-derive", 1047 | ] 1048 | 1049 | [[package]] 1050 | name = "structopt-derive" 1051 | version = "0.4.14" 1052 | source = "registry+https://github.com/rust-lang/crates.io-index" 1053 | checksum = "5ba9cdfda491b814720b6b06e0cac513d922fc407582032e8706e9f137976f90" 1054 | dependencies = [ 1055 | "heck", 1056 | "proc-macro-error", 1057 | "proc-macro2", 1058 | "quote", 1059 | "syn", 1060 | ] 1061 | 1062 | [[package]] 1063 | name = "syn" 1064 | version = "1.0.72" 1065 | source = "registry+https://github.com/rust-lang/crates.io-index" 1066 | checksum = "a1e8cdbefb79a9a5a65e0db8b47b723ee907b7c7f8496c76a1770b5c310bab82" 1067 | dependencies = [ 1068 | "proc-macro2", 1069 | "quote", 1070 | "unicode-xid", 1071 | ] 1072 | 1073 | [[package]] 1074 | name = "termcolor" 1075 | version = "1.1.2" 1076 | source = "registry+https://github.com/rust-lang/crates.io-index" 1077 | checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" 1078 | dependencies = [ 1079 | "winapi-util", 1080 | ] 1081 | 1082 | [[package]] 1083 | name = "textwrap" 1084 | version = "0.11.0" 1085 | source = "registry+https://github.com/rust-lang/crates.io-index" 1086 | checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" 1087 | dependencies = [ 1088 | "unicode-width", 1089 | ] 1090 | 1091 | [[package]] 1092 | name = "thiserror" 1093 | version = "1.0.25" 1094 | source = "registry+https://github.com/rust-lang/crates.io-index" 1095 | checksum = "fa6f76457f59514c7eeb4e59d891395fab0b2fd1d40723ae737d64153392e9c6" 1096 | dependencies = [ 1097 | "thiserror-impl", 1098 | ] 1099 | 1100 | [[package]] 1101 | name = "thiserror-impl" 1102 | version = "1.0.25" 1103 | source = "registry+https://github.com/rust-lang/crates.io-index" 1104 | checksum = "8a36768c0fbf1bb15eca10defa29526bda730a2376c2ab4393ccfa16fb1a318d" 1105 | dependencies = [ 1106 | "proc-macro2", 1107 | "quote", 1108 | "syn", 1109 | ] 1110 | 1111 | [[package]] 1112 | name = "thread_local" 1113 | version = "1.1.3" 1114 | source = "registry+https://github.com/rust-lang/crates.io-index" 1115 | checksum = "8018d24e04c95ac8790716a5987d0fec4f8b27249ffa0f7d33f1369bdfb88cbd" 1116 | dependencies = [ 1117 | "once_cell", 1118 | ] 1119 | 1120 | [[package]] 1121 | name = "time" 1122 | version = "0.1.43" 1123 | source = "registry+https://github.com/rust-lang/crates.io-index" 1124 | checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" 1125 | dependencies = [ 1126 | "libc", 1127 | "winapi", 1128 | ] 1129 | 1130 | [[package]] 1131 | name = "tinyvec" 1132 | version = "1.2.0" 1133 | source = "registry+https://github.com/rust-lang/crates.io-index" 1134 | checksum = "5b5220f05bb7de7f3f53c7c065e1199b3172696fe2db9f9c4d8ad9b4ee74c342" 1135 | dependencies = [ 1136 | "tinyvec_macros", 1137 | ] 1138 | 1139 | [[package]] 1140 | name = "tinyvec_macros" 1141 | version = "0.1.0" 1142 | source = "registry+https://github.com/rust-lang/crates.io-index" 1143 | checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" 1144 | 1145 | [[package]] 1146 | name = "tokio" 1147 | version = "1.6.1" 1148 | source = "registry+https://github.com/rust-lang/crates.io-index" 1149 | checksum = "0a38d31d7831c6ed7aad00aa4c12d9375fd225a6dd77da1d25b707346319a975" 1150 | dependencies = [ 1151 | "autocfg", 1152 | "bytes", 1153 | "libc", 1154 | "memchr", 1155 | "mio", 1156 | "num_cpus", 1157 | "once_cell", 1158 | "parking_lot", 1159 | "pin-project-lite", 1160 | "signal-hook-registry", 1161 | "tokio-macros", 1162 | "winapi", 1163 | ] 1164 | 1165 | [[package]] 1166 | name = "tokio-macros" 1167 | version = "1.2.0" 1168 | source = "registry+https://github.com/rust-lang/crates.io-index" 1169 | checksum = "c49e3df43841dafb86046472506755d8501c5615673955f6aa17181125d13c37" 1170 | dependencies = [ 1171 | "proc-macro2", 1172 | "quote", 1173 | "syn", 1174 | ] 1175 | 1176 | [[package]] 1177 | name = "tokio-trace" 1178 | version = "0.1.0" 1179 | source = "registry+https://github.com/rust-lang/crates.io-index" 1180 | checksum = "0660d8a4599af2d56ee3e4dde82835a6f26c80e4d60a35d639f97d2729658b31" 1181 | dependencies = [ 1182 | "cfg-if 0.1.10", 1183 | "log", 1184 | "tokio-trace-core", 1185 | ] 1186 | 1187 | [[package]] 1188 | name = "tokio-trace-core" 1189 | version = "0.2.0" 1190 | source = "registry+https://github.com/rust-lang/crates.io-index" 1191 | checksum = "a9c8a256d6956f7cb5e2bdfe8b1e8022f1a09206c6c2b1ba00f3b746b260c613" 1192 | dependencies = [ 1193 | "lazy_static", 1194 | ] 1195 | 1196 | [[package]] 1197 | name = "tokio-util" 1198 | version = "0.6.7" 1199 | source = "registry+https://github.com/rust-lang/crates.io-index" 1200 | checksum = "1caa0b0c8d94a049db56b5acf8cba99dc0623aab1b26d5b5f5e2d945846b3592" 1201 | dependencies = [ 1202 | "bytes", 1203 | "futures-core", 1204 | "futures-io", 1205 | "futures-sink", 1206 | "log", 1207 | "pin-project-lite", 1208 | "slab", 1209 | "tokio", 1210 | ] 1211 | 1212 | [[package]] 1213 | name = "toml" 1214 | version = "0.5.8" 1215 | source = "registry+https://github.com/rust-lang/crates.io-index" 1216 | checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" 1217 | dependencies = [ 1218 | "serde", 1219 | ] 1220 | 1221 | [[package]] 1222 | name = "tracing" 1223 | version = "0.1.26" 1224 | source = "registry+https://github.com/rust-lang/crates.io-index" 1225 | checksum = "09adeb8c97449311ccd28a427f96fb563e7fd31aabf994189879d9da2394b89d" 1226 | dependencies = [ 1227 | "cfg-if 1.0.0", 1228 | "pin-project-lite", 1229 | "tracing-attributes", 1230 | "tracing-core", 1231 | ] 1232 | 1233 | [[package]] 1234 | name = "tracing-appender" 1235 | version = "0.1.2" 1236 | source = "registry+https://github.com/rust-lang/crates.io-index" 1237 | checksum = "9965507e507f12c8901432a33e31131222abac31edd90cabbcf85cf544b7127a" 1238 | dependencies = [ 1239 | "chrono", 1240 | "crossbeam-channel", 1241 | "tracing-subscriber", 1242 | ] 1243 | 1244 | [[package]] 1245 | name = "tracing-attributes" 1246 | version = "0.1.15" 1247 | source = "registry+https://github.com/rust-lang/crates.io-index" 1248 | checksum = "c42e6fa53307c8a17e4ccd4dc81cf5ec38db9209f59b222210375b54ee40d1e2" 1249 | dependencies = [ 1250 | "proc-macro2", 1251 | "quote", 1252 | "syn", 1253 | ] 1254 | 1255 | [[package]] 1256 | name = "tracing-core" 1257 | version = "0.1.18" 1258 | source = "registry+https://github.com/rust-lang/crates.io-index" 1259 | checksum = "a9ff14f98b1a4b289c6248a023c1c2fa1491062964e9fed67ab29c4e4da4a052" 1260 | dependencies = [ 1261 | "lazy_static", 1262 | ] 1263 | 1264 | [[package]] 1265 | name = "tracing-futures" 1266 | version = "0.2.5" 1267 | source = "registry+https://github.com/rust-lang/crates.io-index" 1268 | checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" 1269 | dependencies = [ 1270 | "pin-project", 1271 | "tracing", 1272 | ] 1273 | 1274 | [[package]] 1275 | name = "tracing-log" 1276 | version = "0.1.2" 1277 | source = "registry+https://github.com/rust-lang/crates.io-index" 1278 | checksum = "a6923477a48e41c1951f1999ef8bb5a3023eb723ceadafe78ffb65dc366761e3" 1279 | dependencies = [ 1280 | "lazy_static", 1281 | "log", 1282 | "tracing-core", 1283 | ] 1284 | 1285 | [[package]] 1286 | name = "tracing-subscriber" 1287 | version = "0.2.18" 1288 | source = "registry+https://github.com/rust-lang/crates.io-index" 1289 | checksum = "aa5553bf0883ba7c9cbe493b085c29926bd41b66afc31ff72cf17ff4fb60dcd5" 1290 | dependencies = [ 1291 | "ansi_term 0.12.1", 1292 | "chrono", 1293 | "lazy_static", 1294 | "matchers", 1295 | "regex", 1296 | "sharded-slab", 1297 | "thread_local", 1298 | "tracing", 1299 | "tracing-core", 1300 | ] 1301 | 1302 | [[package]] 1303 | name = "unicode-segmentation" 1304 | version = "1.7.1" 1305 | source = "registry+https://github.com/rust-lang/crates.io-index" 1306 | checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" 1307 | 1308 | [[package]] 1309 | name = "unicode-width" 1310 | version = "0.1.8" 1311 | source = "registry+https://github.com/rust-lang/crates.io-index" 1312 | checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" 1313 | 1314 | [[package]] 1315 | name = "unicode-xid" 1316 | version = "0.2.2" 1317 | source = "registry+https://github.com/rust-lang/crates.io-index" 1318 | checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" 1319 | 1320 | [[package]] 1321 | name = "untrusted" 1322 | version = "0.7.1" 1323 | source = "registry+https://github.com/rust-lang/crates.io-index" 1324 | checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" 1325 | 1326 | [[package]] 1327 | name = "vec_map" 1328 | version = "0.8.2" 1329 | source = "registry+https://github.com/rust-lang/crates.io-index" 1330 | checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" 1331 | 1332 | [[package]] 1333 | name = "version_check" 1334 | version = "0.9.3" 1335 | source = "registry+https://github.com/rust-lang/crates.io-index" 1336 | checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" 1337 | 1338 | [[package]] 1339 | name = "wasi" 1340 | version = "0.9.0+wasi-snapshot-preview1" 1341 | source = "registry+https://github.com/rust-lang/crates.io-index" 1342 | checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" 1343 | 1344 | [[package]] 1345 | name = "wasi" 1346 | version = "0.10.2+wasi-snapshot-preview1" 1347 | source = "registry+https://github.com/rust-lang/crates.io-index" 1348 | checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" 1349 | 1350 | [[package]] 1351 | name = "wasm-bindgen" 1352 | version = "0.2.74" 1353 | source = "registry+https://github.com/rust-lang/crates.io-index" 1354 | checksum = "d54ee1d4ed486f78874278e63e4069fc1ab9f6a18ca492076ffb90c5eb2997fd" 1355 | dependencies = [ 1356 | "cfg-if 1.0.0", 1357 | "wasm-bindgen-macro", 1358 | ] 1359 | 1360 | [[package]] 1361 | name = "wasm-bindgen-backend" 1362 | version = "0.2.74" 1363 | source = "registry+https://github.com/rust-lang/crates.io-index" 1364 | checksum = "3b33f6a0694ccfea53d94db8b2ed1c3a8a4c86dd936b13b9f0a15ec4a451b900" 1365 | dependencies = [ 1366 | "bumpalo", 1367 | "lazy_static", 1368 | "log", 1369 | "proc-macro2", 1370 | "quote", 1371 | "syn", 1372 | "wasm-bindgen-shared", 1373 | ] 1374 | 1375 | [[package]] 1376 | name = "wasm-bindgen-macro" 1377 | version = "0.2.74" 1378 | source = "registry+https://github.com/rust-lang/crates.io-index" 1379 | checksum = "088169ca61430fe1e58b8096c24975251700e7b1f6fd91cc9d59b04fb9b18bd4" 1380 | dependencies = [ 1381 | "quote", 1382 | "wasm-bindgen-macro-support", 1383 | ] 1384 | 1385 | [[package]] 1386 | name = "wasm-bindgen-macro-support" 1387 | version = "0.2.74" 1388 | source = "registry+https://github.com/rust-lang/crates.io-index" 1389 | checksum = "be2241542ff3d9f241f5e2cb6dd09b37efe786df8851c54957683a49f0987a97" 1390 | dependencies = [ 1391 | "proc-macro2", 1392 | "quote", 1393 | "syn", 1394 | "wasm-bindgen-backend", 1395 | "wasm-bindgen-shared", 1396 | ] 1397 | 1398 | [[package]] 1399 | name = "wasm-bindgen-shared" 1400 | version = "0.2.74" 1401 | source = "registry+https://github.com/rust-lang/crates.io-index" 1402 | checksum = "d7cff876b8f18eed75a66cf49b65e7f967cb354a7aa16003fb55dbfd25b44b4f" 1403 | 1404 | [[package]] 1405 | name = "web-sys" 1406 | version = "0.3.51" 1407 | source = "registry+https://github.com/rust-lang/crates.io-index" 1408 | checksum = "e828417b379f3df7111d3a2a9e5753706cae29c41f7c4029ee9fd77f3e09e582" 1409 | dependencies = [ 1410 | "js-sys", 1411 | "wasm-bindgen", 1412 | ] 1413 | 1414 | [[package]] 1415 | name = "webpki" 1416 | version = "0.21.4" 1417 | source = "registry+https://github.com/rust-lang/crates.io-index" 1418 | checksum = "b8e38c0608262c46d4a56202ebabdeb094cef7e560ca7a226c6bf055188aa4ea" 1419 | dependencies = [ 1420 | "ring", 1421 | "untrusted", 1422 | ] 1423 | 1424 | [[package]] 1425 | name = "winapi" 1426 | version = "0.3.9" 1427 | source = "registry+https://github.com/rust-lang/crates.io-index" 1428 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" 1429 | dependencies = [ 1430 | "winapi-i686-pc-windows-gnu", 1431 | "winapi-x86_64-pc-windows-gnu", 1432 | ] 1433 | 1434 | [[package]] 1435 | name = "winapi-i686-pc-windows-gnu" 1436 | version = "0.4.0" 1437 | source = "registry+https://github.com/rust-lang/crates.io-index" 1438 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 1439 | 1440 | [[package]] 1441 | name = "winapi-util" 1442 | version = "0.1.5" 1443 | source = "registry+https://github.com/rust-lang/crates.io-index" 1444 | checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" 1445 | dependencies = [ 1446 | "winapi", 1447 | ] 1448 | 1449 | [[package]] 1450 | name = "winapi-x86_64-pc-windows-gnu" 1451 | version = "0.4.0" 1452 | source = "registry+https://github.com/rust-lang/crates.io-index" 1453 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 1454 | 1455 | [[package]] 1456 | name = "yasna" 1457 | version = "0.4.0" 1458 | source = "registry+https://github.com/rust-lang/crates.io-index" 1459 | checksum = "e262a29d0e61ccf2b6190d7050d4b237535fc76ce4c1210d9caa316f71dffa75" 1460 | dependencies = [ 1461 | "chrono", 1462 | ] 1463 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "magicalane" 3 | version = "0.1.0" 4 | authors = ["magicalne"] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | [lib] 9 | name = "lib" 10 | path = "src/lib.rs" 11 | 12 | [[bin]] 13 | name = "magicalane" 14 | path = "src/main.rs" 15 | 16 | [dependencies] 17 | bytes = "1" 18 | libc = "0.2.69" 19 | quinn = "0.7.0" 20 | quinn-proto = "0.7.0" 21 | rustls = { version = "0.18.0", features = ["quic"], optional = true } 22 | log = "0.4.14" 23 | env_logger = "0.9.0" 24 | tracing = "0.1.10" 25 | tracing-log = "0.1.2" 26 | tracing-appender = "0.1" 27 | tracing-subscriber = { version = "0.2.5", default-features = false, features = ["env-filter", "fmt", "ansi", "chrono"]} 28 | tracing-futures = { version = "0.2.0", default-features = false, features = ["std-future"] } 29 | tokio-trace = { version = "0.1", features = ["log"] } 30 | futures = "0.3.1" 31 | tokio-util = { version = "0.6.7", features = ["full"] } 32 | futures-core = "0.3.5" 33 | tokio = { version = "^1.2.0", features = ["full"] } 34 | webpki = { version = "0.21", optional = true } 35 | anyhow = "1.0.22" 36 | thiserror = "1.0" 37 | toml = "0.5.8" 38 | serde = { version = "1.0", features = ["derive"] } 39 | bencher = "0.1.5" 40 | directories-next = "1.0.1" 41 | directories = "2.0" 42 | rand = "0.7" 43 | rcgen = "0.8" 44 | structopt = "0.3.0" 45 | pin-project = "1.0.7" 46 | socket2 = "0.4.0" -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Magicalane - A QUIC based proxy 2 | 3 | ## Download 4 | 5 | Checkout the recent releases. 6 | 7 | ## Run 8 | 9 | ```sh 10 | chmod +x magicalane-linux 11 | ``` 12 | 13 | `client`: 14 | 15 | ```sh 16 | ./magicalane-linux client --socks-port --password --server-host --server-port <443_or_your_server_port> 17 | ``` 18 | 19 | `server`: 20 | 21 | ``` 22 | ./magicalane-linux server --key --ca --port <443_or_your_server_port> --password 23 | ``` 24 | -------------------------------------------------------------------------------- /src/config.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | #[derive(Debug, Deserialize)] 4 | pub struct Config { 5 | pub kind: Kind, 6 | pub password: String, 7 | pub bandwidth: usize, 8 | pub verbose: bool, 9 | } 10 | 11 | #[derive(Debug, Deserialize)] 12 | pub enum Kind { 13 | Server { 14 | port: u16, 15 | ca: Option, 16 | key: Option, 17 | }, 18 | Client { 19 | proxy: ProxyConfig, 20 | socks5_port: u16, 21 | tproxy: TransparentProxyConfig, 22 | }, 23 | } 24 | 25 | #[derive(Debug, Deserialize)] 26 | pub struct ProxyConfig { 27 | pub host: String, 28 | pub port: u16, 29 | pub ca_path: Option, 30 | } 31 | 32 | #[derive(Debug, Deserialize)] 33 | #[allow(dead_code)] 34 | pub struct TransparentProxyConfig { 35 | tcp_port: u16, 36 | udp_port: u16, 37 | } 38 | -------------------------------------------------------------------------------- /src/connector.rs: -------------------------------------------------------------------------------- 1 | use std::io; 2 | 3 | use futures::future::BoxFuture; 4 | use tokio::{ 5 | io::{AsyncRead, AsyncWrite}, 6 | net::TcpStream, 7 | }; 8 | 9 | use crate::{ 10 | quic::{self, stream::QuicStream}, 11 | socks5::proto::Addr, 12 | }; 13 | 14 | pub trait Connector: Clone { 15 | type Connection: AsyncRead + AsyncWrite + Unpin; 16 | 17 | fn connect(&mut self, a: Addr) -> BoxFuture<'static, io::Result>; 18 | } 19 | 20 | #[derive(Clone)] 21 | pub struct LocalConnector; 22 | 23 | impl Connector for LocalConnector { 24 | type Connection = TcpStream; 25 | 26 | fn connect(&mut self, a: Addr) -> BoxFuture<'static, io::Result> { 27 | match a { 28 | Addr::SocketAddr(addr) => Box::pin(TcpStream::connect(addr)), 29 | Addr::DomainName(host, port) => { 30 | let addr = (String::from_utf8(host).unwrap(), port); 31 | Box::pin(TcpStream::connect(addr)) 32 | } 33 | } 34 | } 35 | } 36 | 37 | #[derive(Clone)] 38 | pub struct QuicConnector { 39 | quic_client: quic::client::ClientActorHndler, 40 | } 41 | 42 | impl QuicConnector { 43 | pub fn new(quic_client: quic::client::ClientActorHndler) -> Self { 44 | Self { quic_client } 45 | } 46 | } 47 | 48 | impl Connector for QuicConnector { 49 | type Connection = QuicStream; 50 | 51 | fn connect(&mut self, a: Addr) -> BoxFuture<'static, io::Result> { 52 | let client = self.quic_client.clone(); 53 | let stream = client.open_bi(a); 54 | Box::pin(stream) 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/error.rs: -------------------------------------------------------------------------------- 1 | use std::str::Utf8Error; 2 | 3 | use quinn::{crypto::rustls::TLSError, ParseError}; 4 | use rcgen::RcgenError; 5 | use thiserror::Error; 6 | use tokio::sync::oneshot; 7 | use tracing::dispatcher::SetGlobalDefaultError; 8 | 9 | #[derive(Error, Debug)] 10 | pub enum Error { 11 | /// Server down 12 | #[error("Server is down.")] 13 | ServerDown, 14 | #[error("SetGlobalDefaultError")] 15 | SetGlobalDefaultError(#[from] SetGlobalDefaultError), 16 | /// First byte of protocol is not implemented. 17 | #[error("Wrong protocol.")] 18 | WrongProtocol, 19 | #[error("Wrong password.")] 20 | WrongPassword, 21 | #[error("Failed to open remote addr")] 22 | OpenRemoteAddrError, 23 | #[error("Connection closed")] 24 | ConnectionClose, 25 | /// Buffer is empty. 26 | #[error("Empty buffer.")] 27 | EmptyBuffer, 28 | /// Empty password. 29 | #[error("Empty password.")] 30 | EmptyPassword, 31 | /// Parse password from [u8] to String failed. 32 | #[error("Parse password failed.")] 33 | ParsePasswordFail, 34 | #[error("Empty host.")] 35 | EmptyHost, 36 | /// Parse host from [u8] to String failed. 37 | #[error("Parse host failed.")] 38 | ParseHostFail, 39 | #[error("Empty port.")] 40 | EmptyPort, 41 | #[error("Parse port failed.")] 42 | ParsePortFail, 43 | #[error("Parse error")] 44 | ParseError, 45 | #[error("Known protocol kind")] 46 | UnknownProtocolKindError, 47 | #[error("Unknown remote host")] 48 | UnknownRemoteHost, 49 | #[error("Poll from server lost error.")] 50 | PollServerDriverLostError, 51 | #[error("io error: {0}")] 52 | IoError(#[from] std::io::Error), 53 | #[error("Generate key or cert error: {0}")] 54 | RcgenError(#[from] RcgenError), 55 | #[error("Parse key or cert error: {0}")] 56 | CertParseError(#[from] ParseError), 57 | #[error("TlsError: {0}")] 58 | TlsError(#[from] TLSError), 59 | 60 | #[error("Open remote error")] 61 | OpenRemoteError, 62 | 63 | #[error("Recvive error from channel: {0}")] 64 | OneshotRecvError(#[from] oneshot::error::RecvError), 65 | 66 | #[error("Stream read close.")] 67 | StreamClose, 68 | #[error("Stream write zero.")] 69 | StreamWriteZero, 70 | 71 | #[error("Cannot recv proxy streams")] 72 | RecvProxyStreamError, 73 | ///cert 74 | #[error("webpki error")] 75 | WebPkiError, 76 | 77 | #[error("Socks lib error: {0}")] 78 | Socs5LibError(#[from] crate::socks5::error::Error), 79 | 80 | #[error("Utf8 error")] 81 | Utf8Error(#[from] Utf8Error), 82 | 83 | #[error("Send stream error.")] 84 | SendStreamError, 85 | #[error("Send stream is not ready")] 86 | SendStreamNotReadyError, 87 | #[error("Empty remote address")] 88 | EmptyRemoteAddrError, 89 | #[error("Not binded")] 90 | NotBindedError, 91 | #[error("Not connected")] 92 | NotConnectedError, 93 | #[error("Quinn read error: {0}")] 94 | QuinnReadError(#[from] quinn::ReadError), 95 | #[error("Quinn write error: {0}")] 96 | QuinnWriteError(#[from] quinn::WriteError), 97 | #[error("Quinn endpoint error: {0}")] 98 | QuinnEndpointError(#[from] quinn::EndpointError), 99 | #[error("Quinn connect error: {0}")] 100 | QuinnConnectingError(#[from] quinn::ConnectError), 101 | #[error("Quinn connection error: {0}")] 102 | QuinnConnectionError(#[from] quinn::ConnectionError), 103 | #[error("QUinn read exact error: {0}")] 104 | QuinnReadExactError(#[from] quinn::ReadExactError), 105 | } 106 | 107 | pub type Result = std::result::Result; 108 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | use std::{ 2 | fs, 3 | path::{Path, PathBuf}, 4 | }; 5 | 6 | use error::Result; 7 | use quinn::{CertificateChain, PrivateKey}; 8 | 9 | pub mod config; 10 | pub mod connector; 11 | pub mod error; 12 | pub(crate) mod proxy; 13 | pub mod quic; 14 | pub mod socks5; 15 | 16 | pub const ALPN_QUIC: &[&[u8]] = &[b"hq-29"]; 17 | 18 | pub fn generate_key_and_cert_der( 19 | qualifier: &str, 20 | org: &str, 21 | application: &str, 22 | ) -> Result<(PathBuf, PathBuf)> { 23 | let dirs = directories::ProjectDirs::from(qualifier, org, application).unwrap(); 24 | let path = dirs.data_local_dir(); 25 | let cert_path = path.join("cert.der"); 26 | let key_path = path.join("key.der"); 27 | if !cert_path.exists() || !key_path.exists() { 28 | let cert = rcgen::generate_simple_self_signed(vec!["localhost".into()]).unwrap(); 29 | let key = cert.serialize_private_key_der(); 30 | let cert = cert.serialize_der()?; 31 | fs::create_dir_all(&path)?; 32 | fs::write(&cert_path, &cert)?; 33 | fs::write(&key_path, &key)?; 34 | } 35 | Ok((key_path, cert_path)) 36 | } 37 | 38 | pub fn generate_key_and_cert_pem( 39 | qualifier: &str, 40 | org: &str, 41 | application: &str, 42 | ) -> Result<(PathBuf, PathBuf)> { 43 | let dirs = directories::ProjectDirs::from(qualifier, org, application).unwrap(); 44 | let path = dirs.data_local_dir(); 45 | let cert_path = path.join("cert.pem"); 46 | let key_path = path.join("key.pem"); 47 | if !cert_path.exists() || !key_path.exists() { 48 | let cert = rcgen::generate_simple_self_signed(vec!["localhost".into()]).unwrap(); 49 | let key = cert.serialize_private_key_pem(); 50 | let cert = cert.serialize_pem()?; 51 | fs::create_dir_all(&path)?; 52 | fs::write(&cert_path, &cert)?; 53 | fs::write(&key_path, &key)?; 54 | } 55 | Ok((key_path, cert_path)) 56 | } 57 | 58 | pub fn load_private_key(key_path: &Path) -> Result { 59 | let key = fs::read(key_path)?; 60 | let key = if key_path.extension().map_or(false, |x| x == "der") { 61 | quinn::PrivateKey::from_der(&key)? 62 | } else { 63 | quinn::PrivateKey::from_pem(&key)? 64 | }; 65 | Ok(key) 66 | } 67 | 68 | pub fn load_private_cert(cert_path: &Path) -> Result { 69 | let cert_chain = fs::read(cert_path)?; 70 | let cert_chain = if cert_path 71 | .extension() 72 | .map_or(false, |x| x == "der" || x == "crt") 73 | { 74 | quinn::CertificateChain::from_certs(quinn::Certificate::from_der(&cert_chain)) 75 | } else { 76 | quinn::CertificateChain::from_pem(&cert_chain)? 77 | }; 78 | Ok(cert_chain) 79 | } 80 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | use anyhow::Result; 2 | use lib::config::{Config, Kind}; 3 | use lib::connector::LocalConnector; 4 | use lib::{connector, generate_key_and_cert_pem}; 5 | use structopt::StructOpt; 6 | 7 | #[derive(StructOpt, Debug)] 8 | enum Mode { 9 | Client {}, 10 | Server, 11 | } 12 | 13 | #[derive(Debug, StructOpt)] 14 | #[structopt(name = "magicalane", about = "A quic proxy.")] 15 | struct Opt { 16 | #[structopt(long)] 17 | config: String, 18 | } 19 | 20 | #[tokio::main] 21 | async fn main() -> Result<()> { 22 | let opt: Opt = Opt::from_args(); 23 | let content = std::fs::read(opt.config)?; 24 | let config: Config = toml::from_slice(&content)?; 25 | 26 | start_with_config(config).await?; 27 | Ok(()) 28 | } 29 | 30 | async fn start_with_config(config: Config) -> Result<()> { 31 | let password = config.password; 32 | let bandwidth = config.bandwidth; 33 | let kind = config.kind; 34 | env_logger::init(); 35 | match kind { 36 | Kind::Server { port, ca, key } => { 37 | let connector = LocalConnector; 38 | let key_cert = match (key, ca) { 39 | (Some(key), Some(cert)) => (key.into(), cert.into()), 40 | (_, _) => generate_key_and_cert_pem("tls", "org", "examples")?, 41 | }; 42 | let mut server = 43 | lib::quic::server::Server::new(connector, key_cert, port, password, bandwidth)?; 44 | server.run().await?; 45 | } 46 | Kind::Client { 47 | proxy, 48 | socks5_port, 49 | tproxy: _, 50 | } => { 51 | let ca_path = proxy.ca_path.map(|path| path.into()); 52 | let quic_client = lib::quic::client::ClientActorHndler::new( 53 | proxy.host, 54 | proxy.port, 55 | ca_path, 56 | password.as_bytes().to_vec(), 57 | ) 58 | .await?; 59 | let connector = connector::QuicConnector::new(quic_client); 60 | let mut socks_server = 61 | lib::socks5::server::Server::new(Some(socks5_port), connector, bandwidth).await?; 62 | socks_server.run().await?; 63 | } 64 | }; 65 | Ok(()) 66 | } 67 | -------------------------------------------------------------------------------- /src/proxy.rs: -------------------------------------------------------------------------------- 1 | use std::{ 2 | io::{Error, ErrorKind::ConnectionAborted, Result}, 3 | pin::Pin, 4 | task::{Context, Poll}, 5 | usize, 6 | }; 7 | 8 | use bytes::{Buf, BytesMut}; 9 | use futures::{ready, Future}; 10 | use tokio::io::{AsyncRead, AsyncWrite}; 11 | use tokio_util::io::{poll_read_buf, poll_write_buf}; 12 | use tracing::{error, trace}; 13 | #[pin_project::pin_project] 14 | 15 | /// Copy from linkerd2-proxy. 16 | pub struct Proxy { 17 | i: Reader, 18 | o: Reader, 19 | } 20 | 21 | impl Proxy 22 | where 23 | I: AsyncRead + AsyncWrite + Unpin, 24 | O: AsyncRead + AsyncWrite + Unpin, 25 | { 26 | pub fn new(i: I, o: O, capacity: usize) -> Self { 27 | Self { 28 | i: Reader::new(i, "src->dst", capacity), 29 | o: Reader::new(o, "dst->src", capacity), 30 | } 31 | } 32 | } 33 | 34 | impl Future for Proxy 35 | where 36 | I: AsyncRead + AsyncWrite + Unpin, 37 | O: AsyncRead + AsyncWrite + Unpin, 38 | { 39 | type Output = Result<()>; 40 | 41 | fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { 42 | let this = self.project(); 43 | trace!("poll"); 44 | let _ = this.i.poll_copy_into(cx, this.o)?; 45 | let _ = this.o.poll_copy_into(cx, this.i)?; 46 | if this.i.is_done() && this.o.is_done() { 47 | Poll::Ready(Ok(())) 48 | } else { 49 | Poll::Pending 50 | } 51 | } 52 | } 53 | 54 | enum BufRead { 55 | Read(usize), 56 | NotEmpty, 57 | Eof, 58 | } 59 | 60 | enum BufWrite { 61 | BufEmpty, 62 | Partial(usize), 63 | All(usize), 64 | } 65 | 66 | #[pin_project::pin_project] 67 | struct Reader { 68 | buf: BytesMut, 69 | is_shutdown: bool, 70 | #[pin] 71 | io: I, 72 | direction: &'static str, 73 | flushing: bool, 74 | } 75 | 76 | impl Reader 77 | where 78 | I: AsyncRead + Unpin, 79 | { 80 | fn new(io: I, direction: &'static str, capacity: usize) -> Self { 81 | Self { 82 | buf: BytesMut::with_capacity(capacity), 83 | is_shutdown: false, 84 | io, 85 | direction, 86 | flushing: false, 87 | } 88 | } 89 | 90 | fn is_done(&self) -> bool { 91 | self.is_shutdown 92 | } 93 | 94 | /// Reads data from `self` and writing it to `dst`. 95 | /// Returns ready when the stream has shutdown. 96 | fn poll_copy_into( 97 | &mut self, 98 | cx: &mut Context<'_>, 99 | dst: &mut Reader, 100 | ) -> Poll> { 101 | if dst.is_shutdown { 102 | trace!(direction = %self.direction, "already shutdown"); 103 | return Poll::Ready(Ok(())); 104 | } 105 | 106 | if self.flushing { 107 | ready!(self.poll_flush(cx, dst))?; 108 | } 109 | 110 | let mut needs_flush = false; 111 | 112 | loop { 113 | match self.poll_read(cx)? { 114 | Poll::Pending => { 115 | // If there's no data to be read and we've written data, try 116 | // flushing before returning pending. 117 | if needs_flush { 118 | // The poll status of the flush isn't relevant, as we 119 | // have registered interest in the read (and maybe the 120 | // write as well). If the flush did not complete 121 | // `self.flushing` is true so that it maybe resumed on 122 | // the next poll. 123 | let _ = self.poll_flush(cx, dst)?; 124 | } 125 | return Poll::Pending; 126 | } 127 | Poll::Ready(BufRead::NotEmpty) | Poll::Ready(BufRead::Read(_)) => { 128 | // Write buf to the dst. 129 | match self.drain_into(cx, dst)? { 130 | // All the buf was written, so continue to read. 131 | BufWrite::All(sz) => { 132 | debug_assert!(sz > 0); 133 | needs_flush = true; 134 | } 135 | // Only some of the buffered data could be written 136 | // before the dst became pending. Try to flush the 137 | // written data to get capacity. 138 | BufWrite::Partial(_) => { 139 | ready!(self.poll_flush(cx, dst))?; 140 | // `BufWrite::Partital` matches with `Poll::Pending` 141 | // If the flush completed, try writeing again to 142 | // ensure that we have a notification registered. If 143 | // all of the buffered data still cannot be written, 144 | // return pending. Otherwise, continue. 145 | if let BufWrite::Partial(_) = self.drain_into(cx, dst)? { 146 | return Poll::Pending; 147 | } 148 | needs_flush = false; 149 | } 150 | BufWrite::BufEmpty => { 151 | error!( 152 | direction = self.direction, 153 | "Invalid state: attempted to write from an empty buffer" 154 | ); 155 | debug_assert!(false, "The write buffer should never be empty"); 156 | return Poll::Ready(Ok(())); 157 | } 158 | } 159 | } 160 | Poll::Ready(BufRead::Eof) => { 161 | trace!(direction = %self.direction, "shutting down"); 162 | debug_assert!(!dst.is_shutdown, "attempted to shut down destination twice"); 163 | ready!(Pin::new(&mut dst.io).poll_shutdown(cx))?; 164 | dst.is_shutdown = true; 165 | return Poll::Ready(Ok(())); 166 | } 167 | } 168 | } 169 | } 170 | 171 | fn poll_read(&mut self, cx: &mut Context<'_>) -> Poll> { 172 | if self.buf.has_remaining() { 173 | trace!(direction = %self.direction, remaining = self.buf.remaining(), "skipping read"); 174 | return Poll::Ready(Ok(BufRead::NotEmpty)); 175 | } 176 | self.buf.clear(); 177 | trace!(direction = %self.direction, "reading"); 178 | let sz = ready!(poll_read_buf(Pin::new(&mut self.io), cx, &mut self.buf))?; 179 | trace!(direction = %self.direction, "read {}B", sz); 180 | 181 | if sz > 0 { 182 | Poll::Ready(Ok(BufRead::Read(sz))) 183 | } else { 184 | trace!("eof"); 185 | self.buf.clear(); 186 | Poll::Ready(Ok(BufRead::Eof)) 187 | } 188 | } 189 | 190 | fn drain_into( 191 | &mut self, 192 | cx: &mut Context<'_>, 193 | dst: &mut Reader, 194 | ) -> Result { 195 | let mut sz = 0; 196 | 197 | while self.buf.has_remaining() { 198 | trace!(direction = %self.direction, "writing {}B", self.buf.remaining()); 199 | let n = match poll_write_buf(Pin::new(&mut dst.io), cx, &mut self.buf)? { 200 | Poll::Pending => return Ok(BufWrite::Partial(sz)), 201 | Poll::Ready(n) => n, 202 | }; 203 | trace!(direction = %self.direction, "wrote {}B", n); 204 | if n == 0 { 205 | return Err(Error::new(ConnectionAborted, "Connection closed.")); 206 | } 207 | sz += n; 208 | } 209 | 210 | if sz == 0 { 211 | Ok(BufWrite::BufEmpty) 212 | } else { 213 | Ok(BufWrite::All(sz)) 214 | } 215 | } 216 | 217 | fn poll_flush( 218 | &mut self, 219 | cx: &mut Context<'_>, 220 | dst: &mut Reader, 221 | ) -> Poll> { 222 | trace!(direction = %self.direction, "flushing"); 223 | match Pin::new(&mut dst.io).poll_flush(cx) { 224 | Poll::Ready(Ok(_)) => { 225 | trace!(direction = %self.direction, "flushed"); 226 | Poll::Ready(Ok(())) 227 | } 228 | Poll::Ready(Err(err)) => Poll::Ready(Err(err)), 229 | Poll::Pending => { 230 | self.flushing = true; 231 | Poll::Pending 232 | } 233 | } 234 | } 235 | } 236 | -------------------------------------------------------------------------------- /src/quic/client.rs: -------------------------------------------------------------------------------- 1 | use std::{ 2 | fs, io, 3 | net::{IpAddr, Ipv4Addr, SocketAddr, ToSocketAddrs}, 4 | path::PathBuf, 5 | pin::Pin, 6 | u8, 7 | }; 8 | 9 | use crate::socks5::proto::Addr; 10 | use bytes::BytesMut; 11 | use futures::{future::poll_fn, AsyncWrite}; 12 | use log::{error, trace}; 13 | use quinn::{Connection, Endpoint, NewConnection, RecvStream, SendStream}; 14 | use socket2::{Domain, Protocol, Socket, Type}; 15 | use tokio::sync::{mpsc, oneshot}; 16 | use tokio_util::io::{poll_read_buf, poll_write_buf}; 17 | 18 | use crate::{ 19 | error::{Error, Result}, 20 | quic::{SOCKET_RECV_BUF_SIZE, SOCKET_SEND_BUF_SIZE}, 21 | ALPN_QUIC, 22 | }; 23 | 24 | use super::stream::{QuicStream, StreamActorHandler}; 25 | 26 | pub struct Client { 27 | remote_addr: SocketAddr, 28 | endpoint: Endpoint, 29 | server_name: String, 30 | } 31 | 32 | impl Client { 33 | pub async fn new(server_name: String, port: u16, cert_path: Option) -> Result { 34 | let mut client_config = quinn::ClientConfigBuilder::default(); 35 | client_config.protocols(ALPN_QUIC); 36 | client_config.enable_keylog(); 37 | cert_path 38 | .map(|path| { 39 | // This is for self-signed. 40 | fs::read(path) 41 | .map(|cert| quinn::Certificate::from_pem(&cert)) 42 | .map(|cert| match cert { 43 | Ok(cert) => { 44 | trace!("Add cert: {:?}", &cert); 45 | if let Err(err) = client_config.add_certificate_authority(cert) { 46 | error!("Client add cert failed: {:?}.", err); 47 | } 48 | } 49 | Err(err) => { 50 | error!("Client parse cert error: {:?}.", err); 51 | } 52 | }) 53 | }) 54 | .map(|r| { 55 | r.map_err(|err| { 56 | error!("Client config cert with error: {:?}.", err); 57 | }) 58 | }); 59 | let config = client_config.build(); 60 | let remote_addr = (server_name.as_str(), port) 61 | .to_socket_addrs()? 62 | .find(|add| add.is_ipv4()) 63 | .ok_or(Error::UnknownRemoteHost)?; 64 | trace!( 65 | "Connect remote: {:?}, server name: {:?}", 66 | &remote_addr, 67 | &server_name 68 | ); 69 | let mut endpoint_builder = Endpoint::builder(); 70 | endpoint_builder.default_client_config(config); 71 | let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::UNSPECIFIED), 0); 72 | // Bind this endpoint to a UDP socket on the given client address. 73 | let socket = Socket::new(Domain::IPV4, Type::DGRAM, Some(Protocol::UDP))?; 74 | let addr = addr.into(); 75 | socket.bind(&addr)?; 76 | socket.set_recv_buffer_size(SOCKET_RECV_BUF_SIZE)?; 77 | socket.set_send_buffer_size(SOCKET_SEND_BUF_SIZE)?; 78 | let udp = socket.into(); 79 | let (endpoint, _) = endpoint_builder.with_socket(udp)?; 80 | trace!("Client bind: {:?}", &addr); 81 | 82 | Ok(Self { 83 | remote_addr, 84 | endpoint, 85 | server_name, 86 | }) 87 | } 88 | 89 | pub async fn open_conn(&mut self) -> Result { 90 | let connection = self 91 | .endpoint 92 | .connect(&self.remote_addr, &self.server_name)? 93 | .await?; 94 | let NewConnection { connection, .. } = connection; 95 | Ok(connection) 96 | } 97 | } 98 | 99 | struct ClientActor { 100 | client: Client, 101 | receiver: mpsc::Receiver, 102 | stream_handler: StreamActorHandler, 103 | conn: Option, 104 | buf: BytesMut, 105 | } 106 | 107 | impl ClientActor { 108 | fn new(client: Client, receiver: mpsc::Receiver, passwd: Vec) -> Self { 109 | let stream_handler = StreamActorHandler::new(passwd); 110 | Self { 111 | client, 112 | receiver, 113 | stream_handler, 114 | conn: None, 115 | buf: BytesMut::new(), 116 | } 117 | } 118 | 119 | async fn handle(&mut self, msg: Message) { 120 | match msg { 121 | Message::OpenStream { 122 | sender, 123 | remote_addr, 124 | } => loop { 125 | if self.conn.is_none() { 126 | // Open a new connection. 127 | match self.client.open_conn().await { 128 | Ok(conn) => { 129 | if let Ok((send, recv)) = conn.open_bi().await { 130 | match self.stream_handler.send_passwd(send, recv).await { 131 | Ok(_) => { 132 | self.conn = Some(conn); 133 | } 134 | Err(err) => { 135 | trace!("Send password failed: {:?}", err); 136 | return; 137 | } 138 | } 139 | } 140 | } 141 | Err(err) => { 142 | trace!("Cannot connect to quic server: {:?}", err); 143 | let _ = sender.send(Err(err)); 144 | return; 145 | } 146 | } 147 | } 148 | let conn = self.conn.as_mut().unwrap(); 149 | match conn.open_bi().await { 150 | Ok((mut send, mut recv)) => { 151 | self.buf.clear(); 152 | remote_addr.encode(&mut self.buf); 153 | if let Err(err) = 154 | poll_fn(|cx| poll_write_buf(Pin::new(&mut send), cx, &mut self.buf)) 155 | .await 156 | { 157 | trace!("Write failed: {:?}", err); 158 | self.conn = None; 159 | continue; 160 | } 161 | if let Err(err) = poll_fn(|cx| Pin::new(&mut send).poll_flush(cx)).await { 162 | trace!("Flush failed: {:?}", err); 163 | self.conn = None; 164 | continue; 165 | } 166 | self.buf.clear(); 167 | if let Err(err) = 168 | poll_fn(|cx| poll_read_buf(Pin::new(&mut recv), cx, &mut self.buf)) 169 | .await 170 | { 171 | trace!("Read failed: {:?}", err); 172 | self.conn = None; 173 | continue; 174 | } 175 | let _ = match self.buf[0] { 176 | 0 => sender.send(Ok((send, recv))), 177 | _ => sender.send(Err(Error::OpenRemoteError)), 178 | }; 179 | return; 180 | } 181 | Err(err) => { 182 | trace!("Open stream failed: {:?}", err); 183 | self.conn = None; 184 | } 185 | } 186 | }, 187 | } 188 | } 189 | } 190 | 191 | enum Message { 192 | OpenStream { 193 | remote_addr: Addr, 194 | sender: oneshot::Sender>, 195 | }, 196 | } 197 | 198 | #[derive(Clone)] 199 | pub struct ClientActorHndler { 200 | sender: mpsc::Sender, 201 | } 202 | 203 | impl ClientActorHndler { 204 | pub async fn new( 205 | server_name: String, 206 | port: u16, 207 | cert_path: Option, 208 | passwd: Vec, 209 | ) -> Result { 210 | let client = Client::new(server_name, port, cert_path).await?; 211 | let (sender, receiver) = mpsc::channel(200); 212 | let actor = ClientActor::new(client, receiver, passwd); 213 | tokio::spawn(run_client_actor(actor)); 214 | Ok(Self { sender }) 215 | } 216 | 217 | pub async fn open_bi(self, remote_addr: Addr) -> io::Result { 218 | let (sender, respond_to) = oneshot::channel(); 219 | let msg = Message::OpenStream { 220 | sender, 221 | remote_addr, 222 | }; 223 | let _ = self.sender.send(msg).await; 224 | let (send, recv) = respond_to 225 | .await 226 | .map_err(|err| io::Error::new(io::ErrorKind::InvalidData, err))? 227 | .map_err(|err| io::Error::new(io::ErrorKind::InvalidData, err))?; 228 | let stream = QuicStream::new(recv, send); 229 | Ok(stream) 230 | } 231 | } 232 | 233 | async fn run_client_actor(mut actor: ClientActor) { 234 | trace!("Accecpt client request."); 235 | while let Some(msg) = actor.receiver.recv().await { 236 | actor.handle(msg).await; 237 | } 238 | } 239 | -------------------------------------------------------------------------------- /src/quic/mod.rs: -------------------------------------------------------------------------------- 1 | use std::usize; 2 | 3 | pub mod client; 4 | pub mod proto; 5 | pub mod server; 6 | pub mod stream; 7 | 8 | pub(crate) const SOCKET_RECV_BUF_SIZE: usize = 26214400; 9 | pub(crate) const SOCKET_SEND_BUF_SIZE: usize = 26214400; 10 | -------------------------------------------------------------------------------- /src/quic/proto.rs: -------------------------------------------------------------------------------- 1 | use std::usize; 2 | 3 | use crate::error::{Error, Result}; 4 | 5 | /// `buf` is read from IO and compare buf with password. 6 | pub fn compare_passwd(buf: &[u8], passwd: &[u8]) -> Result<()> { 7 | if buf.is_empty() { 8 | return Err(Error::EmptyPassword); 9 | } 10 | 11 | let n = buf[0] as usize; 12 | if buf.len() <= n { 13 | return Err(Error::WrongPassword); 14 | } 15 | if &buf[1..n + 1] == passwd { 16 | Ok(()) 17 | } else { 18 | Err(Error::WrongPassword) 19 | } 20 | } 21 | 22 | #[test] 23 | fn compare_passwd_test() { 24 | let passwd = [0, 1, 2, 3, 4]; 25 | let buf = [5, 0, 1, 2, 3, 4, 0, 0, 0]; 26 | assert!(compare_passwd(&buf[..], &passwd[..]).is_ok()); 27 | let buf = [4, 1, 2, 3, 4, 0, 0, 0]; 28 | assert!(compare_passwd(&buf[..], &passwd[..]).is_err()); 29 | let buf = [4, 1, 2, 3]; 30 | assert!(compare_passwd(&buf[..], &passwd[..]).is_err()); 31 | } 32 | -------------------------------------------------------------------------------- /src/quic/server/conn.rs: -------------------------------------------------------------------------------- 1 | use std::pin::Pin; 2 | 3 | use crate::connector::Connector; 4 | use bytes::{Buf, BufMut, BytesMut}; 5 | use futures::{future::poll_fn, StreamExt, TryStreamExt}; 6 | use log::trace; 7 | use quinn::IncomingBiStreams; 8 | use tokio::{ 9 | io::{AsyncRead, AsyncWrite}, 10 | spawn, 11 | }; 12 | use tokio_util::io::{poll_read_buf, poll_write_buf}; 13 | 14 | use crate::{ 15 | error::{Error, Result}, 16 | quic::{proto::compare_passwd, stream::QuicStream}, 17 | }; 18 | 19 | use super::stream::Stream; 20 | 21 | pub struct Connection { 22 | bi_streams: IncomingBiStreams, 23 | buf: BytesMut, 24 | connector: C, 25 | passwd: Vec, 26 | bandwidth: usize, 27 | } 28 | 29 | impl Connection 30 | where 31 | O: AsyncRead + AsyncWrite + Unpin + 'static, 32 | C: Connector + Send + 'static, 33 | { 34 | pub fn new( 35 | bi_streams: IncomingBiStreams, 36 | connector: C, 37 | passwd: Vec, 38 | bandwidth: usize, 39 | ) -> Self { 40 | Self { 41 | bi_streams, 42 | buf: BytesMut::new(), 43 | connector, 44 | passwd, 45 | bandwidth, 46 | } 47 | } 48 | 49 | pub async fn accept(&mut self) -> Result<()> { 50 | let me = &mut *self; 51 | match me.bi_streams.try_next().await? { 52 | Some((mut send, mut recv)) => { 53 | let n = poll_fn(|cx| poll_read_buf(Pin::new(&mut recv), cx, &mut me.buf)).await?; 54 | trace!("Read {:?}Bytes", n); 55 | if n == 0 { 56 | return Err(Error::StreamClose); 57 | } 58 | let buf = me.buf.chunk(); 59 | let ret = compare_passwd(buf, &me.passwd); 60 | let flag = match ret.as_ref() { 61 | Ok(_) => 0, 62 | Err(_) => 1, 63 | }; 64 | me.buf.clear(); 65 | me.buf.put_u8(flag); 66 | let n = poll_fn(|cx| poll_write_buf(Pin::new(&mut send), cx, &mut me.buf)).await?; 67 | trace!("Write {:?}Bytes", n); 68 | let _ = poll_fn(|cx| Pin::new(&mut send).poll_flush(cx)).await?; 69 | } 70 | None => return Err(Error::StreamClose), 71 | }; 72 | while let Some(next) = me.bi_streams.next().await { 73 | match next { 74 | Ok((send, recv)) => { 75 | let connector = me.connector.clone(); 76 | let stream = QuicStream::new(recv, send); 77 | let bandwidth = me.bandwidth; 78 | let stream = Stream::new(stream, connector, bandwidth); 79 | spawn(async move { 80 | if let Err(err) = stream.await { 81 | trace!("Stream error: {:?}", err); 82 | }; 83 | }); 84 | } 85 | Err(err) => return Err(Error::QuinnConnectionError(err)), 86 | } 87 | } 88 | 89 | Ok(()) 90 | } 91 | } 92 | 93 | impl Unpin for Connection {} 94 | -------------------------------------------------------------------------------- /src/quic/server/mod.rs: -------------------------------------------------------------------------------- 1 | pub(crate) mod conn; 2 | pub(crate) mod stream; 3 | 4 | use std::{ 5 | net::{IpAddr, Ipv4Addr, SocketAddr}, 6 | path::PathBuf, 7 | u16, 8 | }; 9 | 10 | use crate::connector::Connector; 11 | use futures::StreamExt; 12 | use log::{info, trace}; 13 | use quinn::{Endpoint, NewConnection, ServerConfig}; 14 | use socket2::{Domain, Protocol, Socket, Type}; 15 | use tokio::{ 16 | io::{AsyncRead, AsyncWrite}, 17 | spawn, 18 | }; 19 | 20 | use crate::{ 21 | error::Result, 22 | load_private_cert, load_private_key, 23 | quic::{server::conn::Connection, SOCKET_RECV_BUF_SIZE, SOCKET_SEND_BUF_SIZE}, 24 | ALPN_QUIC, 25 | }; 26 | 27 | #[pin_project::pin_project] 28 | pub struct Server { 29 | connector: C, 30 | passwd: Vec, 31 | #[pin] 32 | incoming: quinn::Incoming, 33 | bandwidth: usize, 34 | } 35 | 36 | impl Server { 37 | pub fn new( 38 | connector: C, 39 | key_cert: (PathBuf, PathBuf), 40 | port: u16, 41 | passwd: String, 42 | bandwidth: usize, 43 | ) -> Result { 44 | let server_config = ServerConfig::default(); 45 | let mut server_config = quinn::ServerConfigBuilder::new(server_config); 46 | server_config.enable_keylog(); 47 | let (key, cert) = key_cert; 48 | info!("key path: {:?}", &key); 49 | info!("cert path: {:?}", &cert); 50 | let key = load_private_key(key.as_path())?; 51 | let cert_chain = load_private_cert(cert.as_path())?; 52 | server_config.certificate(cert_chain, key)?; 53 | server_config.protocols(ALPN_QUIC); 54 | let mut endpoint_builder = Endpoint::builder(); 55 | endpoint_builder.listen(server_config.build()); 56 | let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::UNSPECIFIED), port); 57 | let socket = Socket::new(Domain::IPV4, Type::DGRAM, Some(Protocol::UDP))?; 58 | let addr = addr.into(); 59 | info!("Server bind: {:?}", &addr); 60 | socket.bind(&addr)?; 61 | socket.set_recv_buffer_size(SOCKET_RECV_BUF_SIZE)?; 62 | socket.set_send_buffer_size(SOCKET_SEND_BUF_SIZE)?; 63 | let udp = socket.into(); 64 | let (_, incoming) = endpoint_builder.with_socket(udp)?; 65 | let passwd = passwd.into_bytes(); 66 | Ok(Self { 67 | connector, 68 | passwd, 69 | incoming, 70 | bandwidth, 71 | }) 72 | } 73 | } 74 | 75 | impl Server 76 | where 77 | IO: AsyncRead + AsyncWrite + Unpin + 'static, 78 | C: Connector + Send + 'static, 79 | { 80 | pub async fn run(&mut self) -> Result<()> { 81 | while let Some(connecting) = self.incoming.next().await { 82 | trace!( 83 | "Accept connection from remote: {:?}", 84 | &connecting.remote_address() 85 | ); 86 | match connecting.await { 87 | Ok(NewConnection { bi_streams, .. }) => { 88 | let mut conn = Connection::new( 89 | bi_streams, 90 | self.connector.clone(), 91 | self.passwd.clone(), 92 | self.bandwidth, 93 | ); 94 | spawn(async move { 95 | if let Err(err) = conn.accept().await { 96 | trace!("Quic connection error: {:?}", err); 97 | } 98 | }); 99 | } 100 | Err(err) => { 101 | trace!("Connection error: {:?}", err); 102 | } 103 | } 104 | } 105 | Ok(()) 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/quic/server/stream.rs: -------------------------------------------------------------------------------- 1 | use std::{ 2 | io, 3 | pin::Pin, 4 | task::{Context, Poll}, 5 | }; 6 | 7 | use crate::{connector::Connector, proxy::Proxy, socks5::proto::Addr}; 8 | use bytes::{Buf, BufMut, BytesMut}; 9 | use futures::{future::BoxFuture, ready, Future}; 10 | use log::trace; 11 | use tokio::io::{AsyncRead, AsyncWrite}; 12 | use tokio_util::io::{poll_read_buf, poll_write_buf}; 13 | 14 | use crate::error::{Error, Result}; 15 | 16 | enum State { 17 | ReadAddrReq, 18 | OpenRemote, 19 | SendAddrRes, 20 | Finished, 21 | Proxy, 22 | } 23 | 24 | pub struct Stream { 25 | io: Option, 26 | buf: BytesMut, 27 | connector: C, 28 | connector_fut: Option>>, 29 | remote: Option, 30 | state: State, 31 | proxy: Option>, 32 | bandwidth: usize, 33 | } 34 | 35 | impl Stream 36 | where 37 | IO: AsyncRead + AsyncWrite + Unpin, 38 | O: AsyncRead + AsyncWrite + Unpin, 39 | C: Connector, 40 | { 41 | pub fn new(io: IO, connector: C, bandwidth: usize) -> Self { 42 | Self { 43 | io: Some(io), 44 | buf: BytesMut::new(), 45 | connector, 46 | connector_fut: None, 47 | remote: None, 48 | state: State::ReadAddrReq, 49 | proxy: None, 50 | bandwidth, 51 | } 52 | } 53 | 54 | fn poll_read_addr(&mut self, cx: &mut Context<'_>) -> Poll> { 55 | self.buf.clear(); 56 | let n = ready!(poll_read_buf( 57 | Pin::new(self.io.as_mut().unwrap()), 58 | cx, 59 | &mut self.buf 60 | ))?; 61 | trace!("Read addr: {:?}Bytes: {:?}", n, &self.buf[..n]); 62 | let addr = Addr::new(self.buf.chunk())?; 63 | trace!("read addr: {:?}", &addr); 64 | self.connector_fut = Some(self.connector.connect(addr)); 65 | self.state = State::OpenRemote; 66 | Poll::Ready(Ok(())) 67 | } 68 | 69 | fn poll_open_remote(&mut self, cx: &mut Context<'_>) -> Poll> { 70 | match ready!(Pin::new(&mut self.connector_fut) 71 | .as_pin_mut() 72 | .unwrap() 73 | .poll(cx)) 74 | { 75 | Ok(remote) => { 76 | trace!("Open remote successfully."); 77 | self.remote = Some(remote); 78 | } 79 | Err(err) => { 80 | trace!("Open remote failed: {:?}", err); 81 | } 82 | } 83 | self.state = State::SendAddrRes; 84 | Poll::Ready(Ok(())) 85 | } 86 | 87 | fn poll_send_addr(&mut self, cx: &mut Context<'_>) -> Poll> { 88 | let flag = if self.remote.is_some() { 0 } else { 1 }; 89 | self.buf.clear(); 90 | self.buf.put_u8(flag); 91 | let n = ready!(poll_write_buf( 92 | Pin::new(&mut self.io).as_pin_mut().unwrap(), 93 | cx, 94 | &mut self.buf 95 | ))?; 96 | trace!("Write {:?}Bytes", n); 97 | let _ = ready!(Pin::new(&mut self.io).as_pin_mut().unwrap().poll_flush(cx))?; 98 | let res = match &self.remote { 99 | Some(_) => { 100 | self.state = State::Finished; 101 | Ok(()) 102 | } 103 | None => Err(Error::OpenRemoteError), 104 | }; 105 | Poll::Ready(res) 106 | } 107 | } 108 | 109 | impl Unpin for Stream {} 110 | 111 | unsafe impl Send for Stream {} 112 | 113 | impl Future for Stream 114 | where 115 | IO: AsyncRead + AsyncWrite + Unpin, 116 | O: AsyncRead + AsyncWrite + Unpin, 117 | C: Connector, 118 | { 119 | type Output = Result<()>; 120 | 121 | fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { 122 | let me = &mut *self; 123 | loop { 124 | match me.state { 125 | State::ReadAddrReq => { 126 | let _ = ready!(me.poll_read_addr(cx))?; 127 | } 128 | State::OpenRemote => { 129 | let _ = ready!(me.poll_open_remote(cx))?; 130 | } 131 | State::SendAddrRes => { 132 | let _ = ready!(me.poll_send_addr(cx))?; 133 | } 134 | State::Finished => { 135 | let src = me.io.take().unwrap(); 136 | let dst = me.remote.take().unwrap(); 137 | let bandwidth = me.bandwidth; 138 | let proxy = Proxy::new(src, dst, bandwidth); 139 | me.proxy = Some(proxy); 140 | me.state = State::Proxy; 141 | } 142 | State::Proxy => { 143 | let _ = ready!(Pin::new(&mut me.proxy).as_pin_mut().unwrap().poll(cx))?; 144 | return Poll::Ready(Ok(())); 145 | } 146 | } 147 | } 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /src/quic/stream.rs: -------------------------------------------------------------------------------- 1 | use std::{ 2 | pin::Pin, 3 | task::{Context, Poll}, 4 | }; 5 | 6 | use bytes::BytesMut; 7 | use futures::AsyncWriteExt; 8 | use log::trace; 9 | use quinn::{RecvStream, SendStream}; 10 | use tokio::{ 11 | io::{AsyncRead, AsyncWrite}, 12 | net::TcpStream, 13 | sync::{mpsc, oneshot}, 14 | }; 15 | 16 | use crate::{ 17 | error::{Error, Result}, 18 | socks5::proto::Addr, 19 | }; 20 | 21 | const CORRECT_PASSWORD_RESPONSE: u8 = 0; 22 | const SEND_ADDR_SUCCESS_RESPONSE: u8 = 0; 23 | 24 | #[derive(Debug)] 25 | enum Message { 26 | SendPassword { 27 | send: SendStream, 28 | recv: RecvStream, 29 | sender: oneshot::Sender>, 30 | }, 31 | SendAddr { 32 | send: SendStream, 33 | recv: RecvStream, 34 | addr: Vec, 35 | sender: oneshot::Sender>, 36 | }, 37 | HandlePasswordValid { 38 | send: SendStream, 39 | recv: RecvStream, 40 | sender: oneshot::Sender>, 41 | }, 42 | HandleOpenRemote { 43 | send: SendStream, 44 | recv: RecvStream, 45 | sender: oneshot::Sender>, 46 | }, 47 | } 48 | 49 | impl Message { 50 | fn send_passwd_req( 51 | send: SendStream, 52 | recv: RecvStream, 53 | sender: oneshot::Sender>, 54 | ) -> Self { 55 | Self::SendPassword { send, recv, sender } 56 | } 57 | 58 | fn send_addr_req( 59 | send: SendStream, 60 | recv: RecvStream, 61 | addr: Vec, 62 | sender: oneshot::Sender>, 63 | ) -> Self { 64 | Self::SendAddr { 65 | send, 66 | recv, 67 | addr, 68 | sender, 69 | } 70 | } 71 | 72 | fn handle_passwd_req( 73 | send: SendStream, 74 | recv: RecvStream, 75 | sender: oneshot::Sender>, 76 | ) -> Self { 77 | Self::HandlePasswordValid { send, recv, sender } 78 | } 79 | 80 | fn handle_open_remote_req( 81 | send: SendStream, 82 | recv: RecvStream, 83 | sender: oneshot::Sender>, 84 | ) -> Self { 85 | Self::HandleOpenRemote { send, recv, sender } 86 | } 87 | } 88 | pub struct StreamActor { 89 | receiver: mpsc::Receiver, 90 | passwd: Vec, 91 | } 92 | 93 | impl StreamActor { 94 | fn new(receiver: mpsc::Receiver, passwd: Vec) -> Self { 95 | Self { receiver, passwd } 96 | } 97 | 98 | async fn handle(&mut self, msg: Message) { 99 | trace!("Accept message: {:?}", &msg); 100 | match msg { 101 | Message::SendPassword { send, recv, sender } => { 102 | let res = self.send_passwd(send, recv).await; 103 | let _ = sender.send(res); 104 | } 105 | Message::SendAddr { 106 | send, 107 | recv, 108 | addr, 109 | sender, 110 | } => { 111 | let res = self.send_addr(send, recv, addr).await; 112 | let _ = sender.send(res); 113 | } 114 | Message::HandlePasswordValid { send, recv, sender } => { 115 | let res = self.validate_passwd(send, recv).await; 116 | let _ = sender.send(res); 117 | } 118 | Message::HandleOpenRemote { send, recv, sender } => { 119 | let res = self.open_remote(send, recv).await; 120 | let _ = sender.send(res); 121 | } 122 | } 123 | } 124 | 125 | async fn send_passwd(&mut self, mut send: SendStream, mut recv: RecvStream) -> Result<()> { 126 | trace!("Send password: {:?}", &self.passwd); 127 | let mut buf = vec![self.passwd.len() as u8]; 128 | buf.extend_from_slice(&self.passwd); 129 | send.write_all(&buf).await?; 130 | trace!("Send password successfully."); 131 | send.flush().await?; 132 | let mut buf = [0u8; 1]; 133 | recv.read_exact(&mut buf).await?; 134 | if buf[0] == CORRECT_PASSWORD_RESPONSE { 135 | Ok(()) 136 | } else { 137 | Err(Error::WrongPassword) 138 | } 139 | } 140 | 141 | async fn send_addr( 142 | &mut self, 143 | mut send: SendStream, 144 | mut recv: RecvStream, 145 | addr: Vec, 146 | ) -> Result<()> { 147 | send.write_all(&addr).await?; 148 | send.flush().await?; 149 | let mut buf = [0u8; 1]; 150 | recv.read_exact(&mut buf).await?; 151 | if buf[0] == SEND_ADDR_SUCCESS_RESPONSE { 152 | Ok(()) 153 | } else { 154 | Err(Error::OpenRemoteAddrError) 155 | } 156 | } 157 | 158 | async fn validate_passwd(&mut self, mut send: SendStream, mut recv: RecvStream) -> Result<()> { 159 | let mut buf = vec![0; 128]; 160 | if let Some(n) = recv.read(&mut buf).await? { 161 | if buf[..n] == self.passwd { 162 | let buf = [0u8; 1]; 163 | send.write_all(&buf).await?; 164 | } else { 165 | let buf = [1u8; 1]; 166 | send.write_all(&buf).await?; 167 | } 168 | } 169 | Ok(()) 170 | } 171 | 172 | async fn open_remote( 173 | &mut self, 174 | mut send: SendStream, 175 | mut recv: RecvStream, 176 | ) -> Result<(SendStream, RecvStream, TcpStream)> { 177 | let mut buf = vec![0; 1024]; 178 | match recv.read(&mut buf).await? { 179 | Some(n) => { 180 | let addr = Addr::new(&buf[..n])?; 181 | let tcp_stream = match addr { 182 | Addr::SocketAddr(ip) => TcpStream::connect(ip).await?, 183 | Addr::DomainName(domain, port) => { 184 | let domain = std::str::from_utf8(&domain)?; 185 | let socket = (domain, port); 186 | TcpStream::connect(socket).await? 187 | } 188 | }; 189 | let buf = [0u8; 1]; 190 | send.write_all(&buf).await?; 191 | Ok((send, recv, tcp_stream)) 192 | } 193 | None => Err(Error::EmptyRemoteAddrError), 194 | } 195 | } 196 | } 197 | 198 | async fn run_stream_actor(mut actor: StreamActor) { 199 | trace!("StreamActor is running..."); 200 | while let Some(msg) = actor.receiver.recv().await { 201 | actor.handle(msg).await; 202 | } 203 | } 204 | 205 | #[derive(Clone)] 206 | pub struct StreamActorHandler { 207 | sender: mpsc::Sender, 208 | } 209 | 210 | impl StreamActorHandler { 211 | pub fn new(passwd: Vec) -> Self { 212 | let (sender, receiver) = mpsc::channel(200); 213 | let actor = StreamActor::new(receiver, passwd); 214 | tokio::spawn(run_stream_actor(actor)); 215 | Self { sender } 216 | } 217 | 218 | pub async fn send_passwd(&mut self, send: SendStream, recv: RecvStream) -> Result<()> { 219 | let (sender, respond_to) = oneshot::channel(); 220 | let msg = Message::send_passwd_req(send, recv, sender); 221 | let _ = self.sender.send(msg).await; 222 | respond_to.await? 223 | } 224 | 225 | pub async fn send_addr( 226 | &mut self, 227 | send: SendStream, 228 | recv: RecvStream, 229 | addr: Addr, 230 | ) -> Result<()> { 231 | let (sender, respond_to) = oneshot::channel(); 232 | let mut buf = BytesMut::new(); 233 | addr.encode(&mut buf); 234 | let addr = buf.to_vec(); 235 | let msg = Message::send_addr_req(send, recv, addr, sender); 236 | let _ = self.sender.send(msg).await; 237 | respond_to.await? 238 | } 239 | 240 | pub async fn validate_passwd(&mut self, send: SendStream, recv: RecvStream) -> Result<()> { 241 | let (sender, respond_to) = oneshot::channel(); 242 | let msg = Message::handle_passwd_req(send, recv, sender); 243 | let _ = self.sender.send(msg).await; 244 | respond_to.await? 245 | } 246 | 247 | pub async fn open_remote( 248 | &mut self, 249 | send: SendStream, 250 | recv: RecvStream, 251 | ) -> Result<(SendStream, RecvStream, TcpStream)> { 252 | let (sender, respond_to) = oneshot::channel(); 253 | let msg = Message::handle_open_remote_req(send, recv, sender); 254 | let _ = self.sender.send(msg).await; 255 | respond_to.await? 256 | } 257 | } 258 | 259 | #[pin_project::pin_project] 260 | pub struct QuicStream { 261 | #[pin] 262 | recv: RecvStream, 263 | #[pin] 264 | send: SendStream, 265 | } 266 | 267 | impl QuicStream { 268 | pub fn new(recv: RecvStream, send: SendStream) -> Self { 269 | Self { recv, send } 270 | } 271 | } 272 | 273 | impl AsyncRead for QuicStream { 274 | fn poll_read( 275 | self: Pin<&mut Self>, 276 | cx: &mut Context<'_>, 277 | buf: &mut tokio::io::ReadBuf<'_>, 278 | ) -> Poll> { 279 | let me = self.project(); 280 | me.recv.poll_read(cx, buf) 281 | } 282 | } 283 | 284 | impl AsyncWrite for QuicStream { 285 | fn poll_write( 286 | self: Pin<&mut Self>, 287 | cx: &mut Context<'_>, 288 | buf: &[u8], 289 | ) -> Poll> { 290 | self.project().send.poll_write(cx, buf) 291 | } 292 | 293 | fn poll_flush( 294 | self: Pin<&mut Self>, 295 | cx: &mut Context<'_>, 296 | ) -> Poll> { 297 | self.project().send.poll_flush(cx) 298 | } 299 | 300 | fn poll_shutdown( 301 | self: Pin<&mut Self>, 302 | cx: &mut Context<'_>, 303 | ) -> Poll> { 304 | self.project().send.poll_shutdown(cx) 305 | } 306 | } 307 | -------------------------------------------------------------------------------- /src/socks5/conn.rs: -------------------------------------------------------------------------------- 1 | use std::{ 2 | io, 3 | marker::PhantomData, 4 | pin::Pin, 5 | task::{Context, Poll}, 6 | }; 7 | 8 | use bytes::{Buf, BytesMut}; 9 | use futures::{future::BoxFuture, ready, Future}; 10 | use log::trace; 11 | use tokio::io::{AsyncRead, AsyncWrite}; 12 | use tokio_util::io::{poll_read_buf, poll_write_buf}; 13 | 14 | use crate::{connector::Connector, proxy::Proxy}; 15 | 16 | use super::{ 17 | error::Error, 18 | proto::{Addr, Command, Decoder, Encoder, Reply, Version}, 19 | Result, 20 | }; 21 | 22 | enum ConnectingState { 23 | Negotiation, 24 | SubNegotiation, 25 | OpenRemote, 26 | } 27 | struct Connecting { 28 | io: Option, 29 | buf: BytesMut, 30 | state: ConnectingState, 31 | connector: C, 32 | connector_fut: Option>>, 33 | ver: Option, 34 | addr: Option, 35 | } 36 | 37 | impl Unpin for Connecting {} 38 | 39 | impl Connecting 40 | where 41 | IO: AsyncRead + AsyncWrite + Unpin, 42 | C: Connector, 43 | O: AsyncRead + AsyncWrite + Unpin, 44 | { 45 | fn new(io: IO, connector: C) -> Self { 46 | let buf = BytesMut::new(); 47 | Self { 48 | io: Some(io), 49 | buf, 50 | state: ConnectingState::Negotiation, 51 | connector, 52 | connector_fut: None, 53 | ver: None, 54 | addr: None, 55 | } 56 | } 57 | 58 | fn poll_inner(&mut self, cx: &mut Context<'_>) -> Poll> { 59 | let me = &mut *self; 60 | loop { 61 | match &mut me.state { 62 | ConnectingState::Negotiation => { 63 | let _ = ready!(me.poll_negotiation(cx))?; 64 | } 65 | ConnectingState::SubNegotiation => { 66 | let _ = ready!(me.poll_subnegotiation(cx))?; 67 | } 68 | ConnectingState::OpenRemote => { 69 | let remote = ready!(me.poll_open_remote(cx))?; 70 | let source = me.io.take().unwrap(); 71 | return Poll::Ready(Ok((source, remote))); 72 | } 73 | } 74 | } 75 | } 76 | 77 | fn poll_negotiation(&mut self, cx: &mut Context<'_>) -> Poll> { 78 | trace!("negotiation..."); 79 | self.buf.clear(); 80 | let n = ready!(poll_read_buf( 81 | Pin::new(self.io.as_mut().unwrap()), 82 | cx, 83 | &mut self.buf 84 | ))?; 85 | if n == 0 { 86 | return Poll::Ready(Err(Error::ConnectionClose)); 87 | } 88 | let buf = self.buf.chunk(); 89 | let (ver, methods) = Decoder::parse_connecting(buf)?; 90 | let m = methods.first().unwrap(); 91 | self.buf.clear(); 92 | Encoder::encode_method_select_msg(ver, m, &mut self.buf); 93 | trace!("poll negotiation writing: {:?}", self.buf); 94 | let n = ready!(poll_write_buf( 95 | Pin::new(self.io.as_mut().unwrap()), 96 | cx, 97 | &mut self.buf 98 | ))?; 99 | if n == 0 { 100 | return Poll::Ready(Err(Error::ConnectionClose)); 101 | } 102 | ready!(Pin::new(self.io.as_mut().unwrap()).poll_flush(cx))?; 103 | self.state = ConnectingState::SubNegotiation; 104 | Poll::Ready(Ok(())) 105 | } 106 | 107 | fn poll_subnegotiation(&mut self, cx: &mut Context<'_>) -> Poll> { 108 | trace!("sub negotiation..."); 109 | self.buf.clear(); 110 | let n = ready!(poll_read_buf( 111 | Pin::new(self.io.as_mut().unwrap()), 112 | cx, 113 | &mut self.buf 114 | ))?; 115 | if n == 0 { 116 | return Poll::Ready(Err(Error::ConnectionClose)); 117 | } 118 | let buf = self.buf.chunk(); 119 | let (ver, cmd, addr) = Decoder::parse_nego_req(buf)?; 120 | match cmd { 121 | Command::Connect => { 122 | self.state = ConnectingState::OpenRemote; 123 | self.ver = Some(ver); 124 | self.addr = Some(addr); 125 | } 126 | Command::Bind => { 127 | unimplemented!() 128 | } 129 | Command::UdpAssociate => { 130 | unimplemented!() 131 | } 132 | }; 133 | Poll::Ready(Ok(())) 134 | } 135 | 136 | fn poll_open_remote(&mut self, cx: &mut Context<'_>) -> Poll> { 137 | if self.connector_fut.is_none() { 138 | let addr = self.addr.clone().unwrap(); 139 | self.connector_fut = Some(self.connector.connect(addr)); 140 | } 141 | let fut = self.connector_fut.as_mut().unwrap(); 142 | let remote_io = ready!(fut.as_mut().poll(cx))?; 143 | trace!("Remote connected."); 144 | self.buf.clear(); 145 | let ver = self.ver.as_ref().unwrap(); 146 | let addr = self.addr.as_ref().unwrap(); 147 | Encoder::encode_server_reply(ver, &Reply::Succeeded, addr, &mut self.buf); 148 | let n = ready!(poll_write_buf( 149 | Pin::new(self.io.as_mut().unwrap()), 150 | cx, 151 | &mut self.buf 152 | ))?; 153 | if n == 0 { 154 | return Poll::Ready(Err(Error::ConnectionClose)); 155 | } 156 | let _ = ready!(Pin::new(self.io.as_mut().unwrap()).poll_flush(cx))?; 157 | Poll::Ready(Ok(remote_io)) 158 | } 159 | } 160 | 161 | #[pin_project::pin_project] 162 | struct CommandConnect { 163 | ver: Version, 164 | addr: Addr, 165 | #[pin] 166 | remote_fut: Option>>, 167 | connector: C, 168 | phantom: PhantomData, 169 | } 170 | 171 | impl Future for CommandConnect 172 | where 173 | C: Connector, 174 | O: AsyncRead + AsyncWrite + Unpin, 175 | { 176 | type Output = io::Result; 177 | 178 | fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { 179 | let mut me = self.project(); 180 | if me.remote_fut.is_none() { 181 | *me.remote_fut = Some(me.connector.connect(me.addr.clone())); 182 | } 183 | let remote_io = ready!(me.remote_fut.as_pin_mut().unwrap().poll(cx))?; 184 | Poll::Ready(Ok(remote_io)) 185 | } 186 | } 187 | 188 | #[pin_project::pin_project(project = ConnStateProj)] 189 | enum ConnState { 190 | Connecting(Connecting), 191 | Connected(Proxy), 192 | } 193 | 194 | #[pin_project::pin_project] 195 | pub struct Connection { 196 | bandwidth: usize, 197 | #[pin] 198 | state: ConnState, 199 | } 200 | 201 | impl Connection 202 | where 203 | IO: AsyncRead + AsyncWrite + Unpin, 204 | C: Connector, 205 | O: AsyncRead + AsyncWrite + Unpin, 206 | { 207 | pub fn new(io: IO, connector: C, bandwidth: usize) -> Self { 208 | let connecting = Connecting::new(io, connector); 209 | Self { 210 | bandwidth, 211 | state: ConnState::Connecting(connecting), 212 | } 213 | } 214 | } 215 | 216 | impl Future for Connection 217 | where 218 | IO: AsyncRead + AsyncWrite + Unpin, 219 | C: Connector, 220 | O: AsyncRead + AsyncWrite + Unpin, 221 | { 222 | type Output = Result<()>; 223 | 224 | fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { 225 | let bandwidth = self.bandwidth; 226 | let mut me = self.project(); 227 | loop { 228 | match me.state.as_mut().project() { 229 | ConnStateProj::Connecting(connecting) => { 230 | let (i, o) = ready!(connecting.poll_inner(cx))?; 231 | let proxy = Proxy::new(i, o, bandwidth); 232 | me.state.set(ConnState::Connected(proxy)); 233 | } 234 | ConnStateProj::Connected(mut proxy) => { 235 | ready!(Pin::new(&mut proxy).poll(cx))?; 236 | return Poll::Ready(Ok(())); 237 | } 238 | } 239 | } 240 | } 241 | } 242 | 243 | /// Safety: Connection is not cloneable and shared nothing. 244 | unsafe impl Send for Connection {} 245 | -------------------------------------------------------------------------------- /src/socks5/error.rs: -------------------------------------------------------------------------------- 1 | use std::u8; 2 | 3 | use thiserror::Error; 4 | 5 | #[derive(Error, Debug)] 6 | pub enum Error { 7 | #[error("IoError: {0}")] 8 | IoError(#[from] std::io::Error), 9 | #[error("Stream colsed.")] 10 | ConnectionClose, 11 | #[error("InvalidMessage")] 12 | InvalidMessage(), 13 | #[error("InvalidVersion: {0}")] 14 | InvalidVersion(u8), 15 | #[error("InvalidMethod: {0}")] 16 | InvalidMethod(u8), 17 | #[error("InvalidCommand: {0}")] 18 | InvalidCommand(u8), 19 | #[error("InvalidAddress")] 20 | InvalidAddress, 21 | } 22 | -------------------------------------------------------------------------------- /src/socks5/mod.rs: -------------------------------------------------------------------------------- 1 | use std::mem::MaybeUninit; 2 | 3 | use bytes::BufMut; 4 | use tokio::io::ReadBuf; 5 | 6 | pub mod conn; 7 | pub mod error; 8 | pub mod proto; 9 | pub mod server; 10 | 11 | pub type Result = std::result::Result; 12 | 13 | pub fn to_read_buf<'a>(buf: &mut impl BufMut) -> ReadBuf<'a> { 14 | let dst = buf.chunk_mut(); 15 | let dst = unsafe { &mut *(dst as *mut _ as *mut [MaybeUninit]) }; 16 | ReadBuf::uninit(dst) 17 | } 18 | -------------------------------------------------------------------------------- /src/socks5/proto.rs: -------------------------------------------------------------------------------- 1 | use std::{ 2 | fmt::Debug, 3 | net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6}, 4 | usize, 5 | }; 6 | 7 | use bytes::BufMut; 8 | use log::trace; 9 | 10 | use super::{error::Error, Result}; 11 | 12 | #[derive(Debug, Clone)] 13 | pub enum Version { 14 | V4, 15 | V5, 16 | } 17 | 18 | impl Version { 19 | fn new(ver: u8) -> Result { 20 | match ver { 21 | 4 => Ok(Version::V4), 22 | 5 => Ok(Version::V5), 23 | _ => Err(Error::InvalidVersion(ver)), 24 | } 25 | } 26 | 27 | fn get_u8(&self) -> u8 { 28 | match self { 29 | Self::V4 => 4, 30 | Self::V5 => 5, 31 | } 32 | } 33 | } 34 | 35 | #[derive(Debug)] 36 | pub enum Method { 37 | NoAuth, 38 | Gssapi, 39 | UsernamePassword, 40 | Ianna, 41 | Reserverd, 42 | NoAcceptableMethod, 43 | } 44 | 45 | impl Method { 46 | pub fn new(m: u8) -> Result { 47 | match m { 48 | 0x00 => Ok(Method::NoAuth), 49 | 0x01 => Ok(Method::Gssapi), 50 | 0x02 => Ok(Method::UsernamePassword), 51 | 0x03..=0x7F => Ok(Method::Ianna), 52 | 0x80..=0xFE => Ok(Method::Reserverd), 53 | 0xFF => Ok(Method::NoAcceptableMethod), 54 | } 55 | } 56 | 57 | pub fn get_u8(&self) -> u8 { 58 | match self { 59 | Self::NoAuth => 0, 60 | Self::Gssapi => 1, 61 | Self::UsernamePassword => 2, 62 | Self::Ianna => 3, 63 | Self::Reserverd => 0x80, 64 | Self::NoAcceptableMethod => 0xFF, 65 | } 66 | } 67 | } 68 | 69 | pub enum Command { 70 | Connect, 71 | Bind, 72 | UdpAssociate, 73 | } 74 | 75 | impl Command { 76 | pub fn new(b: u8) -> Result { 77 | match b { 78 | 0x01 => Ok(Self::Connect), 79 | 0x02 => Ok(Self::Bind), 80 | 0x03 => Ok(Self::UdpAssociate), 81 | _ => Err(Error::InvalidCommand(b)), 82 | } 83 | } 84 | 85 | pub fn get_u8(&self) -> u8 { 86 | match self { 87 | Command::Connect => 0, 88 | Command::Bind => 1, 89 | Command::UdpAssociate => 2, 90 | } 91 | } 92 | } 93 | 94 | #[derive(Clone)] 95 | pub enum Addr { 96 | SocketAddr(SocketAddr), 97 | DomainName(Vec, u16), 98 | } 99 | 100 | impl Debug for Addr { 101 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 102 | match self { 103 | Addr::SocketAddr(addr) => f.write_fmt(format_args!("SocksetAddr: {}", addr)), 104 | Addr::DomainName(buf, port) => { 105 | let domain = String::from_utf8_lossy(buf); 106 | f.write_fmt(format_args!("domain: {}:{}", domain, port)) 107 | } 108 | } 109 | } 110 | } 111 | 112 | impl Addr { 113 | pub fn new(buf: &[u8]) -> Result { 114 | buf.get(0) 115 | .and_then(|tp| match *tp { 116 | 1 => { 117 | //1 flag, 4 bytes ipv4, 2 bytes port 118 | if buf.len() >= 7 { 119 | let ip = Ipv4Addr::new(buf[1], buf[2], buf[3], buf[4]); 120 | let port: u16 = ((buf[5] as u16) << 8) | (buf[6] as u16); 121 | Some(Self::SocketAddr(SocketAddr::V4(SocketAddrV4::new( 122 | ip, port, 123 | )))) 124 | } else { 125 | None 126 | } 127 | } 128 | 4 => { 129 | //1 flat, 16 bytes ipv6, 2 bytes port 130 | if buf.len() >= 19 { 131 | let port = (buf[17] as u16) << 8 | (buf[18] as u16); 132 | let ip = Ipv6Addr::new( 133 | (buf[1] as u16) << 8 | (buf[2] as u16), 134 | (buf[3] as u16) << 8 | (buf[4] as u16), 135 | (buf[5] as u16) << 8 | (buf[6] as u16), 136 | (buf[7] as u16) << 8 | (buf[8] as u16), 137 | (buf[9] as u16) << 8 | (buf[10] as u16), 138 | (buf[11] as u16) << 8 | (buf[12] as u16), 139 | (buf[13] as u16) << 8 | (buf[14] as u16), 140 | (buf[15] as u16) << 8 | (buf[16] as u16), 141 | ); 142 | Some(Self::SocketAddr(SocketAddr::V6(SocketAddrV6::new( 143 | ip, port, 0, 0, 144 | )))) 145 | } else { 146 | None 147 | } 148 | } 149 | 3 => { 150 | let size = buf.get(1).map(|l| -> usize { *l as usize }); 151 | if let Some(size) = size { 152 | trace!( 153 | "buf:[2+size]: {}, buf:[3+size]: {}", 154 | buf[2 + size], 155 | buf[3 + size] 156 | ); 157 | let port = (buf[2 + size] as u16) << 8 | (buf[3 + size] as u16); 158 | Some(Self::DomainName(Vec::from(&buf[2..(2 + size)]), port)) 159 | } else { 160 | None 161 | } 162 | } 163 | _ => None, 164 | }) 165 | .ok_or(Error::InvalidAddress) 166 | } 167 | 168 | pub fn encode(&self, buf: &mut impl BufMut) { 169 | match self { 170 | Addr::SocketAddr(addr) => match addr { 171 | SocketAddr::V4(ipv4) => { 172 | buf.put_u8(1); 173 | buf.put_slice(&ipv4.ip().octets()); 174 | buf.put_u16(ipv4.port()); 175 | } 176 | SocketAddr::V6(ipv6) => { 177 | buf.put_u8(4); 178 | buf.put_slice(&ipv6.ip().octets()); 179 | buf.put_u16(ipv6.port()); 180 | } 181 | }, 182 | Addr::DomainName(domain, port) => { 183 | buf.put_u8(3); 184 | buf.put_u8(domain.len() as u8); 185 | buf.put_slice(domain); 186 | buf.put_u16(*port); 187 | } 188 | } 189 | } 190 | } 191 | 192 | pub enum Reply { 193 | Succeeded, 194 | GeneralSocksServerFailure, 195 | ConnectionNotAllowed, 196 | NetworkUnreachable, 197 | HostUnreachable, 198 | TtlExpired, 199 | CommandNotSupported, 200 | AddressTypeNotSuported, 201 | UnAssigned, 202 | } 203 | 204 | impl Reply { 205 | pub fn new(r: u8) -> Self { 206 | match r { 207 | 0x00 => Self::Succeeded, 208 | 0x01 => Self::GeneralSocksServerFailure, 209 | 0x02 => Self::ConnectionNotAllowed, 210 | 0x03 => Self::NetworkUnreachable, 211 | 0x04 => Self::HostUnreachable, 212 | 0x05 => Self::TtlExpired, 213 | 0x06 => Self::CommandNotSupported, 214 | 0x07 => Self::AddressTypeNotSuported, 215 | _ => Self::UnAssigned, 216 | } 217 | } 218 | 219 | pub fn encode(&self) -> u8 { 220 | match self { 221 | Reply::Succeeded => 0x00, 222 | Reply::GeneralSocksServerFailure => 0x01, 223 | Reply::ConnectionNotAllowed => 0x02, 224 | Reply::NetworkUnreachable => 0x03, 225 | Reply::HostUnreachable => 0x04, 226 | Reply::TtlExpired => 0x05, 227 | Reply::CommandNotSupported => 0x06, 228 | Reply::AddressTypeNotSuported => 0x07, 229 | Reply::UnAssigned => 0x08, 230 | } 231 | } 232 | } 233 | 234 | pub struct Decoder; 235 | 236 | impl Decoder { 237 | // Version and method selection message. 238 | pub fn parse_connecting(buf: &[u8]) -> Result<(Version, Vec)> { 239 | if buf.len() < 3 { 240 | return Err(Error::InvalidMessage()); 241 | } 242 | let ver = Version::new(buf[0])?; 243 | let n = buf[1]; 244 | if n == 0 || buf[2..].len() != (n as usize) { 245 | return Err(Error::InvalidMessage()); 246 | } 247 | let methods: Vec = buf[2..] 248 | .iter() 249 | .map(|b| Method::new(*b)) 250 | .collect::>>()?; 251 | Ok((ver, methods)) 252 | } 253 | 254 | pub fn parse_nego_req(buf: &[u8]) -> Result<(Version, Command, Addr)> { 255 | let ver = match buf.get(0) { 256 | Some(b) => Version::new(*b)?, 257 | None => return Err(Error::InvalidMessage()), 258 | }; 259 | let cmd = match buf.get(1) { 260 | Some(1) => Command::Connect, 261 | Some(2) => Command::Bind, 262 | Some(3) => Command::UdpAssociate, 263 | _ => return Err(Error::InvalidMessage()), 264 | }; 265 | let buf = &buf[3..]; 266 | let addr = Addr::new(buf)?; 267 | Ok((ver, cmd, addr)) 268 | } 269 | } 270 | 271 | pub struct Encoder; 272 | 273 | impl Encoder { 274 | pub fn encode_method_select_msg(ver: Version, method: &Method, buf: &mut B) { 275 | buf.put_u8(ver.get_u8()); 276 | buf.put_u8(method.get_u8()); 277 | } 278 | 279 | pub fn encode_server_reply( 280 | ver: &Version, 281 | rep: &Reply, 282 | addr: &Addr, 283 | mut buf: &mut B, 284 | ) { 285 | buf.put_u8(ver.get_u8()); 286 | buf.put_u8(rep.encode()); 287 | buf.put_u8(0x00); //reserved 288 | addr.encode(&mut buf); 289 | } 290 | } 291 | -------------------------------------------------------------------------------- /src/socks5/server.rs: -------------------------------------------------------------------------------- 1 | use crate::connector::Connector; 2 | 3 | use super::{conn::Connection, Result}; 4 | use log::{debug, info, trace}; 5 | use tokio::{ 6 | io::{AsyncRead, AsyncWrite}, 7 | net::TcpListener, 8 | }; 9 | 10 | pub struct Server { 11 | listener: TcpListener, 12 | connector: C, 13 | bandwidth: usize, 14 | } 15 | 16 | impl Server { 17 | pub async fn new(port: Option, connector: C, bandwidth: usize) -> Result { 18 | let port = port.unwrap_or(1080); 19 | let socket_addr = ("0.0.0.0", port); 20 | let listener = TcpListener::bind(&socket_addr).await?; 21 | info!("Socks server bind to {:?}", &socket_addr); 22 | Ok(Self { 23 | listener, 24 | connector, 25 | bandwidth, 26 | }) 27 | } 28 | } 29 | impl Server 30 | where 31 | IO: AsyncRead + AsyncWrite + Unpin, 32 | C: Connector, 33 | { 34 | pub async fn run(&mut self) -> Result<()> { 35 | while let Ok((stream, addr)) = self.listener.accept().await { 36 | trace!("Accept addr: {:?}", addr); 37 | let connector = self.connector.clone(); 38 | let connection = Connection::new(stream, connector, self.bandwidth); 39 | tokio::spawn(async move { 40 | if let Err(err) = connection.await { 41 | debug!("Connection error: {:?}", err); 42 | } 43 | }); 44 | } 45 | Ok(()) 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /tests/test.rs: -------------------------------------------------------------------------------- 1 | use lib::connector::LocalConnector; 2 | use lib::error::Result; 3 | use lib::{ 4 | connector::QuicConnector, 5 | generate_key_and_cert_der, 6 | quic::{self, server::Server}, 7 | }; 8 | use tracing::Level; 9 | 10 | #[tokio::test] 11 | #[ignore = "integration test"] 12 | pub async fn server_test() -> Result<()> { 13 | let subscriber = tracing_subscriber::fmt() 14 | .with_max_level(Level::INFO) 15 | .with_writer(std::io::stderr) 16 | .finish(); 17 | tracing::subscriber::set_global_default(subscriber).expect("no global subscriber has been set"); 18 | let connector = LocalConnector; 19 | let key_cert = generate_key_and_cert_der("tls", "org", "examples")?; 20 | let mut server = Server::new(connector, key_cert, 3333, String::from("pwd"), 8024)?; 21 | server.run().await?; 22 | Ok(()) 23 | } 24 | 25 | #[tokio::test] 26 | #[ignore = "integration test"] 27 | pub async fn client_test() -> Result<()> { 28 | let subscriber = tracing_subscriber::fmt() 29 | .with_max_level(Level::INFO) 30 | .with_writer(std::io::stderr) 31 | .finish(); 32 | tracing::subscriber::set_global_default(subscriber).expect("no global subscriber has been set"); 33 | let (_, cert) = generate_key_and_cert_der("tls", "org", "examples")?; 34 | let quic_client = quic::client::ClientActorHndler::new( 35 | "localhost".to_string(), 36 | 3333, 37 | Some(cert), 38 | "pwd".as_bytes().to_vec(), 39 | ) 40 | .await?; 41 | let connector = QuicConnector::new(quic_client); 42 | let mut socks_server = lib::socks5::server::Server::new(None, connector, 8024).await?; 43 | socks_server.run().await?; 44 | Ok(()) 45 | } 46 | --------------------------------------------------------------------------------