diff --git a/Cargo.lock b/Cargo.lock index c3ab037..b827c1b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -52,7 +52,7 @@ dependencies = [ "actix-rt", "actix-service", "actix-utils", - "ahash 0.8.11", + "ahash", "base64 0.22.1", "bitflags 2.6.0", "brotli", @@ -169,7 +169,7 @@ dependencies = [ "actix-service", "actix-utils", "actix-web-codegen", - "ahash 0.8.11", + "ahash", "bytes", "bytestring", "cfg-if", @@ -222,17 +222,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" -[[package]] -name = "ahash" -version = "0.7.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "891477e0c6a8957309ee5c45a6368af3ae14bb510732d2684ffa19af310920f9" -dependencies = [ - "getrandom", - "once_cell", - "version_check", -] - [[package]] name = "ahash" version = "0.8.11" @@ -352,12 +341,6 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" -[[package]] -name = "arrayvec" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" - [[package]] name = "async-attributes" version = "1.1.2" @@ -703,7 +686,6 @@ dependencies = [ "rand_hc", "reqwest", "sea-orm", - "sea-orm-cli", "sea-orm-migration", "sea-query", "serde", @@ -763,17 +745,6 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" -[[package]] -name = "bigdecimal" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6773ddc0eafc0e509fb60e48dff7f450f8e674a0686ae8605e8d9901bd5eefa" -dependencies = [ - "num-bigint", - "num-integer", - "num-traits", -] - [[package]] name = "bincode" version = "1.3.3" @@ -813,18 +784,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "blake2" version = "0.10.6" @@ -856,30 +815,6 @@ dependencies = [ "piper", ] -[[package]] -name = "borsh" -version = "1.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6362ed55def622cddc70a4746a68554d7b687713770de539e59a739b249f8ed" -dependencies = [ - "borsh-derive", - "cfg_aliases 0.2.1", -] - -[[package]] -name = "borsh-derive" -version = "1.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3ef8005764f53cd4dca619f5bf64cafd4664dada50ece25e4d81de54c80cc0b" -dependencies = [ - "once_cell", - "proc-macro-crate 3.1.0", - "proc-macro2", - "quote", - "syn 2.0.72", - "syn_derive", -] - [[package]] name = "brotli" version = "6.0.0" @@ -917,28 +852,6 @@ version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" -[[package]] -name = "bytecheck" -version = "0.6.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23cdc57ce23ac53c931e88a43d06d070a6fd142f2617be5855eb75efc9beb1c2" -dependencies = [ - "bytecheck_derive", - "ptr_meta", - "simdutf8", -] - -[[package]] -name = "bytecheck_derive" -version = "0.6.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3db406d29fbcd95542e92559bed4d8ad92636d1ca8b3b72ede10b4bcc010e659" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "byteorder" version = "1.5.0" @@ -1020,12 +933,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" -[[package]] -name = "cfg_aliases" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" - [[package]] name = "cgroups-rs" version = "0.3.4" @@ -1514,18 +1421,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" dependencies = [ "powerfmt", - "serde", -] - -[[package]] -name = "derivative" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", ] [[package]] @@ -1637,6 +1532,18 @@ dependencies = [ "spki", ] +[[package]] +name = "educe" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4bd92664bf78c4d3dba9b7cdafce6fa15b13ed3ed16175218196942e99168a8" +dependencies = [ + "enum-ordinalize", + "proc-macro2", + "quote", + "syn 2.0.72", +] + [[package]] name = "either" version = "1.13.0" @@ -1693,6 +1600,26 @@ dependencies = [ "syn 2.0.72", ] +[[package]] +name = "enum-ordinalize" +version = "4.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea0dcfa4e54eeb516fe454635a95753ddd39acda650ce703031c6973e315dd5" +dependencies = [ + "enum-ordinalize-derive", +] + +[[package]] +name = "enum-ordinalize-derive" +version = "4.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d28318a75d4aead5c4db25382e8ef717932d0346600cacae6357eb5941bc5ff" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.72", +] + [[package]] name = "env_logger" version = "0.10.2" @@ -1861,21 +1788,6 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -1932,12 +1844,6 @@ dependencies = [ "web-sys", ] -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "fuse3" version = "0.7.2" @@ -2337,7 +2243,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "956caa58d4857bc9941749d55e4bd3000032d8212762586fa5705632967140e7" dependencies = [ - "proc-macro-crate 1.3.1", + "proc-macro-crate", "proc-macro2", "quote", "syn 2.0.72", @@ -2446,9 +2352,6 @@ name = "hashbrown" version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" -dependencies = [ - "ahash 0.7.8", -] [[package]] name = "hashbrown" @@ -2456,7 +2359,7 @@ version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" dependencies = [ - "ahash 0.8.11", + "ahash", ] [[package]] @@ -2465,7 +2368,7 @@ version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" dependencies = [ - "ahash 0.8.11", + "ahash", "allocator-api2", ] @@ -3537,7 +3440,7 @@ version = "1.0.0-alpha.57" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "10bc10261f46b8df263b80e7779d1748b1880488cd951fbb9e096430cead10e6" dependencies = [ - "ahash 0.8.11", + "ahash", "bitflags 2.6.0", "const-str", "cssparser", @@ -3787,23 +3690,6 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "defc4c55412d89136f966bbb339008b474350e5e6e78d2714439c386b3137a03" -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "nix" version = "0.25.1" @@ -3824,7 +3710,7 @@ checksum = "ab2156c4fce2f8df6c499cc1c763e4394b7482525bf2a9701c9d79d215f519e4" dependencies = [ "bitflags 2.6.0", "cfg-if", - "cfg_aliases 0.1.1", + "cfg_aliases", "libc", "memoffset", ] @@ -3861,16 +3747,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "num-bigint" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" -dependencies = [ - "num-integer", - "num-traits", -] - [[package]] name = "num-bigint-dig" version = "0.8.4" @@ -3955,50 +3831,12 @@ version = "11.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b410bbe7e14ab526a0e86877eb47c6996a2bd7746f027ba551028c925390e4e9" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags 2.6.0", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.72", -] - [[package]] name = "openssl-probe" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "opentelemetry" version = "0.23.0" @@ -4488,15 +4326,6 @@ dependencies = [ "toml_edit 0.19.15", ] -[[package]] -name = "proc-macro-crate" -version = "3.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d37c51ca738a55da99dc0c4a34860fd675453b8b36209178c2249bb13651284" -dependencies = [ - "toml_edit 0.21.1", -] - [[package]] name = "proc-macro-error" version = "1.0.4" @@ -4653,26 +4482,6 @@ dependencies = [ "serde_json", ] -[[package]] -name = "ptr_meta" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0738ccf7ea06b608c10564b31debd4f5bc5e197fc8bfe088f68ae5ce81e7a4f1" -dependencies = [ - "ptr_meta_derive", -] - -[[package]] -name = "ptr_meta_derive" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16b845dbfca988fa33db069c0e230574d15a3088f147a87b64c7589eb662c9ac" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "pulldown-cmark" version = "0.10.3" @@ -4724,11 +4533,11 @@ dependencies = [ [[package]] name = "quick_cache" -version = "0.4.3" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a4b807ec70346b4fac3c13ae967634237847d49871f623fe0d455403346bad4" +checksum = "ec932c60e6faf77dc6601ea149a23d821598b019b450bb1d98fe89c0301c0b61" dependencies = [ - "ahash 0.8.11", + "ahash", "equivalent", "hashbrown 0.14.5", "parking_lot", @@ -4766,12 +4575,6 @@ dependencies = [ "syn 2.0.72", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -4888,15 +4691,6 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" -[[package]] -name = "rend" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71fe3824f5629716b1589be05dacd749f6aa084c87e00e016714a8cdfccc997c" -dependencies = [ - "bytecheck", -] - [[package]] name = "reqwest" version = "0.11.27" @@ -4974,35 +4768,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "rkyv" -version = "0.7.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cba464629b3394fc4dbc6f940ff8f5b4ff5c7aef40f29166fd4ad12acbc99c0" -dependencies = [ - "bitvec", - "bytecheck", - "bytes", - "hashbrown 0.12.3", - "ptr_meta", - "rend", - "rkyv_derive", - "seahash", - "tinyvec", - "uuid", -] - -[[package]] -name = "rkyv_derive" -version = "0.7.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7dddfff8de25e6f62b9d64e6e432bf1c6736c57d20323e15ee10435fbda7c65" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "rlua" version = "0.19.8" @@ -5093,22 +4858,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "rust_decimal" -version = "1.35.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1790d1c4c0ca81211399e0e0af16333276f375209e71a37b67698a373db5b47a" -dependencies = [ - "arrayvec", - "borsh", - "bytes", - "num-traits", - "rand", - "rkyv", - "serde", - "serde_json", -] - [[package]] name = "rustc-demangle" version = "0.1.24" @@ -5303,71 +5052,49 @@ dependencies = [ [[package]] name = "sea-orm" -version = "0.12.15" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8814e37dc25de54398ee62228323657520b7f29713b8e238649385dbe473ee0" +checksum = "f9d4ec1cdd8bdd3553d3c946079f58efa33fedc477f32603652652abcef96fe6" dependencies = [ "async-stream", "async-trait", - "bigdecimal", "chrono", "futures", "log", "ouroboros", - "rust_decimal", "sea-orm-macros", "sea-query", "sea-query-binder", "serde", - "serde_json", "sqlx", "strum", "thiserror", - "time", "tracing", "url", - "uuid", ] [[package]] name = "sea-orm-cli" -version = "0.12.15" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "620bc560062ae251b1366bde43b3f1508445cab5c2c8cbdb397034638ab1b357" +checksum = "d525eee597817631f800857b0c2fe8645ec9c65b4304176a44bf14b93366009e" dependencies = [ - "async-std", "chrono", "clap", "dotenvy", "glob", "regex", - "sea-orm-codegen", "sea-schema", - "sqlx", "tracing", "tracing-subscriber", "url", ] -[[package]] -name = "sea-orm-codegen" -version = "0.12.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6edc65d76c9a0d693611b8dafac12802406a426410f95beb63ae1ce69354a703" -dependencies = [ - "heck 0.4.1", - "proc-macro2", - "quote", - "sea-query", - "syn 2.0.72", - "tracing", -] - [[package]] name = "sea-orm-macros" -version = "0.12.15" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e115c6b078e013aa963cc2d38c196c2c40b05f03d0ac872fe06b6e0d5265603" +checksum = "f363ead48b625a6f8f905322a820464f728fa4fe4f1c222bed5234ccf8fb8555" dependencies = [ "heck 0.4.1", "proc-macro2", @@ -5379,9 +5106,9 @@ dependencies = [ [[package]] name = "sea-orm-migration" -version = "0.12.15" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee8269bc6ff71afd6b78aa4333ac237a69eebd2cdb439036291e64fb4b8db23c" +checksum = "5df62369752f91b9295f8d71c146d84f818301a9ae7295106ebe8bbaa989a072" dependencies = [ "async-trait", "clap", @@ -5396,36 +5123,26 @@ dependencies = [ [[package]] name = "sea-query" -version = "0.30.7" +version = "0.31.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4166a1e072292d46dc91f31617c2a1cdaf55a8be4b5c9f4bf2ba248e3ac4999b" +checksum = "7e5073b2cfed767511a57d18115f3b3d8bcb5690bf8c89518caec6cb22c0cd74" dependencies = [ - "bigdecimal", "chrono", - "derivative", + "educe", "inherent", "ordered-float 3.9.2", - "rust_decimal", "sea-query-derive", - "serde_json", - "time", - "uuid", ] [[package]] name = "sea-query-binder" -version = "0.5.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36bbb68df92e820e4d5aeb17b4acd5cc8b5d18b2c36a4dd6f4626aabfa7ab1b9" +checksum = "754965d4aee6145bec25d0898e5c931e6c22859789ce62fd85a42a15ed5a8ce3" dependencies = [ - "bigdecimal", "chrono", - "rust_decimal", "sea-query", - "serde_json", "sqlx", - "time", - "uuid", ] [[package]] @@ -5443,35 +5160,27 @@ dependencies = [ [[package]] name = "sea-schema" -version = "0.14.2" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30d148608012d25222442d1ebbfafd1228dbc5221baf4ec35596494e27a2394e" +checksum = "ad52149fc81836ea7424c3425d8f6ed8ad448dd16d2e4f6a3907ba46f3f2fd78" dependencies = [ "futures", "sea-query", - "sea-query-binder", "sea-schema-derive", - "sqlx", ] [[package]] name = "sea-schema-derive" -version = "0.2.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6f686050f76bffc4f635cda8aea6df5548666b830b52387e8bc7de11056d11e" +checksum = "debdc8729c37fdbf88472f97fd470393089f997a909e535ff67c544d18cfccf0" dependencies = [ "heck 0.4.1", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.72", ] -[[package]] -name = "seahash" -version = "4.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b" - [[package]] name = "sec1" version = "0.7.3" @@ -5741,12 +5450,6 @@ dependencies = [ "rand_core", ] -[[package]] -name = "simdutf8" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f27f6278552951f1f2b8cf9da965d10969b2efdea95a6ec47987ab46edfe263a" - [[package]] name = "siphasher" version = "0.3.11" @@ -5855,11 +5558,10 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24ba59a9342a3d9bab6c56c118be528b27c9b60e490080e9711a04dccac83ef6" dependencies = [ - "ahash 0.8.11", + "ahash", "async-io 1.13.0", "async-std", "atoi", - "bigdecimal", "byteorder", "bytes", "chrono", @@ -5877,11 +5579,9 @@ dependencies = [ "indexmap 2.3.0", "log", "memchr", - "native-tls", "once_cell", "paste", "percent-encoding", - "rust_decimal", "rustls 0.21.12", "rustls-pemfile 1.0.4", "serde", @@ -5890,12 +5590,10 @@ dependencies = [ "smallvec", "sqlformat", "thiserror", - "time", "tokio", "tokio-stream", "tracing", "url", - "uuid", "webpki-roots", ] @@ -5947,7 +5645,6 @@ checksum = "1ed31390216d20e538e447a7a9b959e06ed9fc51c37b514b46eb758016ecd418" dependencies = [ "atoi", "base64 0.21.7", - "bigdecimal", "bitflags 2.6.0", "byteorder", "bytes", @@ -5972,7 +5669,6 @@ dependencies = [ "percent-encoding", "rand", "rsa", - "rust_decimal", "serde", "sha1", "sha2", @@ -5980,9 +5676,7 @@ dependencies = [ "sqlx-core", "stringprep", "thiserror", - "time", "tracing", - "uuid", "whoami", ] @@ -5994,7 +5688,6 @@ checksum = "7c824eb80b894f926f89a0b9da0c7f435d27cdd35b8c655b114e58223918577e" dependencies = [ "atoi", "base64 0.21.7", - "bigdecimal", "bitflags 2.6.0", "byteorder", "chrono", @@ -6013,10 +5706,8 @@ dependencies = [ "log", "md-5", "memchr", - "num-bigint", "once_cell", "rand", - "rust_decimal", "serde", "serde_json", "sha2", @@ -6024,9 +5715,7 @@ dependencies = [ "sqlx-core", "stringprep", "thiserror", - "time", "tracing", - "uuid", "whoami", ] @@ -6049,11 +5738,9 @@ dependencies = [ "percent-encoding", "serde", "sqlx-core", - "time", "tracing", "url", "urlencoding", - "uuid", ] [[package]] @@ -6087,9 +5774,9 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "strum" -version = "0.25.0" +version = "0.26.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125" +checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" [[package]] name = "subtle" @@ -6202,12 +5889,6 @@ dependencies = [ "syn 2.0.72", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "tar" version = "0.4.41" @@ -6468,17 +6149,6 @@ dependencies = [ "winnow 0.5.40", ] -[[package]] -name = "toml_edit" -version = "0.21.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1" -dependencies = [ - "indexmap 2.3.0", - "toml_datetime", - "winnow 0.5.40", -] - [[package]] name = "toml_edit" version = "0.22.20" @@ -7387,15 +7057,6 @@ version = "0.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d135d17ab770252ad95e9a872d365cf3090e3be864a34ab46f48555993efc904" -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - [[package]] name = "xattr" version = "1.3.1" diff --git a/Cargo.toml b/Cargo.toml index bc64bbd..3f7c999 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,11 +37,11 @@ version = "0.11.0" default-features = false [workspace.dependencies.sea-orm] -version = "0.12.11" +version = "1.0.0" default-features = false [workspace.dependencies.sea-orm-migration] -version = "0.12.11" +version = "1.0.0" default-features = false [profile.wasm-release] diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 74a05ed..4d44323 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -19,7 +19,7 @@ futures = "0.3.29" bincode = "1.3.3" base64 = "0.21.5" tonic-web = { workspace = true } -quick_cache = "0.4.0" +quick_cache = "0.6.2" hickory-resolver = "0.24.0" crossbeam-queue = "0.3.8" dashmap = "5.5.3" @@ -36,7 +36,6 @@ opentelemetry-semantic-conventions = "0.16.0" tracing-opentelemetry = { version = "0.24.0", features = ["metrics"] } tracing-core = "0.1.32" migration = { path = "./migration", optional = true } -sea-orm-cli = { version = "0.12.12", optional = true } governor = "0.6.0" http = "^0.2" lazy_static = "1.5.0" @@ -69,7 +68,7 @@ version = "^0.4" features = ["cors", "trace"] [dependencies.sea-query] -version = "0.30.4" +version = "0.31.0" features = ["thread-safe", "with-chrono", "backend-sqlite"] [dependencies.chrono] @@ -102,7 +101,8 @@ workspace = true features = ["macros", "rt-multi-thread", "full", "time"] [dependencies.sea-orm] -version = "0.12.11" +workspace = true +default-features = false features = [ "runtime-tokio-rustls", "macros", @@ -124,12 +124,12 @@ version = "0.9.8" features = ["mutex", "spin_mutex", "rwlock"] [dependencies.sea-orm-migration] -# workspace = true -version = "0.12.11" +workspace = true optional = true +default-features = false features = ["runtime-tokio-rustls", "sqlx-sqlite", "with-chrono"] [features] default = ["insecure-print"] -standalone = ["dep:migration", "dep:sea-orm-migration", "dep:sea-orm-cli"] +standalone = ["dep:migration", "dep:sea-orm-migration"] insecure-print = ["sea-orm/debug-print"] diff --git a/backend/migration/Cargo.toml b/backend/migration/Cargo.toml index c98a0f3..f5325a9 100644 --- a/backend/migration/Cargo.toml +++ b/backend/migration/Cargo.toml @@ -22,7 +22,7 @@ version = "1" features = ["attributes", "tokio1"] [dependencies.sea-orm] -version = "0.12.11" +workspace = true default-features = false features = [ "runtime-async-std-rustls", @@ -34,8 +34,7 @@ features = [ ] [dependencies.sea-orm-migration] -# workspace = true -version = "0.12.11" +workspace = true default-features = true features = [ # Enable at least one `ASYNC_RUNTIME` and `DATABASE_DRIVER` feature if you want to run migration via CLI. diff --git a/backend/migration/src/m20231207_000001_create_table.rs b/backend/migration/src/m20231207_000001_create_table.rs index b7d2519..bd95c52 100644 --- a/backend/migration/src/m20231207_000001_create_table.rs +++ b/backend/migration/src/m20231207_000001_create_table.rs @@ -668,17 +668,25 @@ impl MigrationTrait for Migration { index!(manager, Problem, AcceptCount); index!(manager, Problem, Difficulty); index!(manager, Problem, Order); + index!(manager, Problem, Content); + index!(manager, Problem, Title); + index!(manager, Submit, Committed); index!(manager, Submit, Time); index!(manager, Submit, Memory); + index!(manager, Submit, UserId); + index!(manager, Contest, Hoster); index!(manager, Contest, Public); index!(manager, Contest, End); index!(manager, Contest, Begin); + index!(manager, User, Score); index!(manager, User, Username); + index!(manager, Token, Rand); index!(manager, Token, Expiry); + index!(manager, Chat, CreateAt); manager diff --git a/backend/src/endpoint/announcement.rs b/backend/src/endpoint/announcement.rs index d3dcdc4..2c664f9 100644 --- a/backend/src/endpoint/announcement.rs +++ b/backend/src/endpoint/announcement.rs @@ -175,7 +175,7 @@ impl Announcement for ArcServer { let id = *model.id.as_ref(); - tracing::info!(count.announcement = 1, id = id); + info!(count.announcement = 1, id = id); Ok(id.into()) }) @@ -197,7 +197,7 @@ impl Announcement for ArcServer { req.bound_check()?; req.get_or_insert(|req| async move { - tracing::trace!(id = req.id); + trace!(id = req.id); let mut model = Entity::find_by_id(req.id) .with_auth(&auth) @@ -242,7 +242,7 @@ impl Announcement for ArcServer { if result.rows_affected == 0 { Err(Error::NotInDB) } else { - tracing::info!(counter.announcement = -1, id = req.id); + info!(counter.announcement = -1, id = req.id); Ok(()) } }) diff --git a/backend/src/endpoint/chat.rs b/backend/src/endpoint/chat.rs index 14b6f17..2357665 100644 --- a/backend/src/endpoint/chat.rs +++ b/backend/src/endpoint/chat.rs @@ -51,7 +51,7 @@ impl Chat for ArcServer { .map_err(Into::::into)?; let id = *model.id.as_ref(); - tracing::debug!(id = id, "chat_created"); + debug!(id = id, "chat_created"); Ok(id.into()) }) @@ -80,7 +80,7 @@ impl Chat for ArcServer { if result.rows_affected == 0 { Err(Error::NotInDB) } else { - tracing::info!(counter.chat = -1, id = req.id); + info!(counter.chat = -1, id = req.id); Ok(()) } }) diff --git a/backend/src/endpoint/contest.rs b/backend/src/endpoint/contest.rs index 9ba8bdf..a31f7ef 100644 --- a/backend/src/endpoint/contest.rs +++ b/backend/src/endpoint/contest.rs @@ -1,9 +1,9 @@ use super::*; - use crate::entity::{ contest::{Paginator, *}, - *, + problem, *, }; +use sea_orm::sea_query::Expr; use grpc::backend::contest_server::*; @@ -164,7 +164,7 @@ impl Contest for ArcServer { let id = *model.id.as_ref(); - tracing::info!(count.contest = 1, id = id); + info!(count.contest = 1, id = id); Ok(id.into()) }) @@ -185,7 +185,7 @@ impl Contest for ArcServer { let (_, perm) = auth.assume_login()?; req.get_or_insert(|req| async move { - tracing::trace!(id = req.id); + trace!(id = req.id); let mut model = Entity::find_by_id(req.id).with_auth(&auth).write()? .one(self.db.deref()) @@ -238,6 +238,8 @@ impl Contest for ArcServer { let (auth, req) = self.rate_limit(req).in_current_span().await?; req.get_or_insert(|req| async move { + let txn = self.db.begin().await?; + let result = Entity::delete_by_id(req.id) .with_auth(&auth) .write()? @@ -246,12 +248,20 @@ impl Contest for ArcServer { .await .map_err(Into::::into)?; + problem::Entity::update_many() + .col_expr(problem::Column::ContestId, Expr::value(Value::Int(None))) + .filter(crate::entity::testcase::Column::ProblemId.eq(req.id)) + .exec(&txn) + .instrument(info_span!("remove_child")) + .await?; + + txn.commit().await.map_err(|_| Error::Retry)?; + if result.rows_affected == 0 { - Err(Error::NotInDB) - } else { - tracing::info!(counter.contest = -1, id = req.id); - Ok(()) + return Err(Error::NotInDB); } + info!(counter.contest = -1, id = req.id); + Ok(()) }) .await .with_grpc() @@ -260,47 +270,30 @@ impl Contest for ArcServer { #[instrument( skip_all, level = "info", - name = "oj.backend.Contest/join", + name = "oj.backend.Contest/publish", err(level = "debug", Display) )] - async fn join(&self, req: Request) -> Result, Status> { + async fn publish(&self, req: Request) -> Result, Status> { let (auth, req) = self.rate_limit(req).in_current_span().await?; - let (user_id, _) = auth.assume_login()?; req.get_or_insert(|req| async move { - let model = Entity::find_by_id(req.id) + let mut model = Entity::find_by_id(req.id) .with_auth(&auth) - .read()? + .write()? + .columns([Column::Id]) .one(self.db.deref()) .instrument(info_span!("fetch").or_current()) .await .map_err(Into::::into)? - .ok_or(Error::NotInDB)?; - // FIXME: abstract away password checking logic - - if let Some(tar) = model.password { - let password = req - .password - .as_ref() - .ok_or(Error::NotInPayload("password"))?; - if !self.crypto.hash_eq(password, &tar) { - return Err(Error::PermissionDeny("mismatched password")); - } - } - - let pivot = user_contest::ActiveModel { - user_id: ActiveValue::Set(user_id), - contest_id: ActiveValue::Set(model.id), - ..Default::default() - }; + .ok_or(Error::NotInDB)? + .into_active_model(); - pivot - .save(self.db.deref()) - .instrument(info_span!("insert_pviot").or_current()) - .await - .map_err(Into::::into)?; + model.public = ActiveValue::Set(true); - tracing::debug!(user_id = user_id, contest_id = req.id); + model + .update(self.db.deref()) + .instrument(info_span!("update").or_current()) + .await?; Ok(()) }) .await @@ -310,10 +303,10 @@ impl Contest for ArcServer { #[instrument( skip_all, level = "info", - name = "oj.backend.Contest/publish", + name = "oj.backend.Contest/unpublish", err(level = "debug", Display) )] - async fn publish(&self, req: Request) -> Result, Status> { + async fn unpublish(&self, req: Request) -> Result, Status> { let (auth, req) = self.rate_limit(req).in_current_span().await?; req.get_or_insert(|req| async move { @@ -328,7 +321,7 @@ impl Contest for ArcServer { .ok_or(Error::NotInDB)? .into_active_model(); - model.public = ActiveValue::Set(true); + model.public = ActiveValue::Set(false); model .update(self.db.deref()) @@ -343,30 +336,47 @@ impl Contest for ArcServer { #[instrument( skip_all, level = "info", - name = "oj.backend.Contest/unpublish", + name = "oj.backend.Contest/join", err(level = "debug", Display) )] - async fn unpublish(&self, req: Request) -> Result, Status> { + async fn join(&self, req: Request) -> Result, Status> { let (auth, req) = self.rate_limit(req).in_current_span().await?; + let (user_id, _) = auth.assume_login()?; req.get_or_insert(|req| async move { - let mut model = Entity::find_by_id(req.id) + let model = Entity::find_by_id(req.id) .with_auth(&auth) - .write()? - .columns([Column::Id]) + .read()? .one(self.db.deref()) .instrument(info_span!("fetch").or_current()) .await .map_err(Into::::into)? - .ok_or(Error::NotInDB)? - .into_active_model(); + .ok_or(Error::NotInDB)?; + // FIXME: abstract away password checking logic - model.public = ActiveValue::Set(false); + if let Some(tar) = model.password { + let password = req + .password + .as_ref() + .ok_or(Error::NotInPayload("password"))?; + if !self.crypto.hash_eq(password, &tar) { + return Err(Error::PermissionDeny("mismatched password")); + } + } - model - .update(self.db.deref()) - .instrument(info_span!("update").or_current()) - .await?; + let pivot = user_contest::ActiveModel { + user_id: ActiveValue::Set(user_id), + contest_id: ActiveValue::Set(model.id), + ..Default::default() + }; + + pivot + .save(self.db.deref()) + .instrument(info_span!("insert_pviot").or_current()) + .await + .map_err(Into::::into)?; + + debug!(user_id = user_id, contest_id = req.id); Ok(()) }) .await diff --git a/backend/src/endpoint/education.rs b/backend/src/endpoint/education.rs index ad58625..ea48d9e 100644 --- a/backend/src/endpoint/education.rs +++ b/backend/src/endpoint/education.rs @@ -104,7 +104,7 @@ impl Education for ArcServer { let id = *model.id.as_ref(); - tracing::info!(count.education = 1, id = id); + info!(count.education = 1, id = id); Ok(id.into()) }) @@ -123,7 +123,7 @@ impl Education for ArcServer { req.bound_check()?; req.get_or_insert(|req| async move { - tracing::trace!(id = req.id); + trace!(id = req.id); let mut model = Entity::find_by_id(req.id) .with_auth(&auth) .write()? @@ -167,7 +167,7 @@ impl Education for ArcServer { if result.rows_affected == 0 { Err(Error::NotInDB) } else { - tracing::info!(counter.education = -1, id = req.id); + info!(counter.education = -1, id = req.id); Ok(()) } }) diff --git a/backend/src/endpoint/imgur.rs b/backend/src/endpoint/imgur.rs index ea1cd41..0a824b7 100644 --- a/backend/src/endpoint/imgur.rs +++ b/backend/src/endpoint/imgur.rs @@ -19,7 +19,7 @@ impl Image for ArcServer { req.get_or_insert(|req| async move { let url = self.imgur.upload(req.data).await?; - tracing::debug!(counter.image = 1, uri = url); + debug!(counter.image = 1, uri = url); Ok(UploadResponse { url }) }) .await diff --git a/backend/src/endpoint/problem.rs b/backend/src/endpoint/problem.rs index 7aa5228..56f15f8 100644 --- a/backend/src/endpoint/problem.rs +++ b/backend/src/endpoint/problem.rs @@ -1,7 +1,8 @@ use super::*; use grpc::backend::problem_server::*; +use sea_orm::sea_query::Expr; -use crate::entity::{contest, problem::Paginator, problem::*}; +use crate::entity::{contest, problem::Paginator, problem::*, testcase}; impl<'a> From> for ProblemFullInfo { fn from(value: WithAuth<'a, Model>) -> Self { @@ -139,7 +140,7 @@ impl Problem for ArcServer { let id = *model.id.as_ref(); - tracing::info!(count.problem = 1, id = id); + info!(count.problem = 1, id = id); Ok(id.into()) }) @@ -191,17 +192,28 @@ impl Problem for ArcServer { async fn remove(&self, req: Request) -> Result, Status> { let (auth, req) = self.rate_limit(req).in_current_span().await?; req.get_or_insert(|req| async move { + let txn = self.db.begin().await?; + let result = Entity::delete_by_id(req.id) .with_auth(&auth) .write()? - .exec(self.db.deref()) + .exec(&txn) .instrument(info_span!("remove").or_current()) - .await - .map_err(Into::::into)?; + .await?; + + testcase::Entity::update_many() + .col_expr(testcase::Column::ProblemId, Expr::value(Value::Int(None))) + .filter(testcase::Column::ProblemId.eq(req.id)) + .exec(&txn) + .instrument(info_span!("remove_child")) + .await?; + + txn.commit().await.map_err(|_| Error::Retry)?; if result.rows_affected == 0 { return Err(Error::NotInDB); } + info!(count.problem = -1, id = req.id); Ok(()) }) .await @@ -286,7 +298,7 @@ impl Problem for ArcServer { let mut model = model.ok_or(Error::NotInDB)?.into_active_model(); if let Some(x) = model.contest_id.into_value() { - tracing::debug!(old_id = x.to_string()); + debug!(old_id = x.to_string()); } model.contest_id = ActiveValue::Set(None); model diff --git a/backend/src/endpoint/submit.rs b/backend/src/endpoint/submit.rs index 06b3e23..6023018 100644 --- a/backend/src/endpoint/submit.rs +++ b/backend/src/endpoint/submit.rs @@ -91,11 +91,11 @@ impl Submit for ArcServer { async fn info(&self, req: Request) -> Result, Status> { let (auth, req) = self.rate_limit(req).in_current_span().await?; - tracing::debug!(id = req.id); + debug!(id = req.id); let model = Entity::read_filter(Entity::find_by_id(req.id), &auth)? .one(self.db.deref()) - .instrument(tracing::debug_span!("fetch").or_current()) + .instrument(debug_span!("fetch").or_current()) .await .map_err(Into::::into)? .ok_or(Error::NotInDB)?; @@ -156,7 +156,7 @@ impl Submit for ArcServer { .instrument(info_span!("construct_submit").or_current()) .await?; - tracing::info!(counter.submit = 1, id = id); + info!(counter.submit = 1, id = id); Ok(id.into()) }) @@ -189,7 +189,7 @@ impl Submit for ArcServer { if result.rows_affected == 0 { Err(Error::NotInDB) } else { - tracing::info!(counter.submit = -1, id = req.id); + info!(counter.submit = -1, id = req.id); Ok(()) } }) diff --git a/backend/src/endpoint/testcase.rs b/backend/src/endpoint/testcase.rs index 77c2331..8aed017 100644 --- a/backend/src/endpoint/testcase.rs +++ b/backend/src/endpoint/testcase.rs @@ -102,7 +102,7 @@ impl Testcase for ArcServer { let id = *model.id.as_ref(); - tracing::info!(count.testcase = 1, id = id); + info!(count.testcase = 1, id = id); Ok(id.into()) }) @@ -121,7 +121,7 @@ impl Testcase for ArcServer { req.bound_check()?; req.get_or_insert(|req| async move { - tracing::trace!(id = req.id); + trace!(id = req.id); let mut model = Entity::write_filter(Entity::find_by_id(req.id), &auth)? .one(self.db.deref()) .instrument(info_span!("fetch").or_current()) @@ -162,7 +162,7 @@ impl Testcase for ArcServer { if result.rows_affected == 0 { Err(Error::NotInDB) } else { - tracing::info!(counter.testcase = -1, id = req.id); + info!(counter.testcase = -1, id = req.id); Ok(()) } }) @@ -197,6 +197,7 @@ impl Testcase for ArcServer { let problem: problem::IdModel = problem.ok_or(Error::NotInDB)?; let mut model = model.ok_or(Error::NotInDB)?.into_active_model(); + // FIXME: use is_set(), be sure to know what Option in sea_orm said if let ActiveValue::Set(Some(v)) = model.problem_id { return Err(Error::AlreadyExist("testcase already linked")); } diff --git a/backend/src/endpoint/token.rs b/backend/src/endpoint/token.rs index ca106a3..d3be66a 100644 --- a/backend/src/endpoint/token.rs +++ b/backend/src/endpoint/token.rs @@ -77,7 +77,7 @@ impl Token for ArcServer { // FIXME: add request_id let (_, req) = self.rate_limit(req).in_current_span().await?; - tracing::debug!(username = req.username); + debug!(username = req.username); let model = user::Entity::find() .filter(user::Column::Username.eq(req.username)) @@ -99,7 +99,7 @@ impl Token for ArcServer { expiry: into_prost(expiry), })) } else { - tracing::trace!("password_mismatch"); + trace!("password_mismatch"); Err(Error::PermissionDeny("wrong password").into()) } } @@ -164,7 +164,7 @@ impl Token for ArcServer { .remove(token.to_string()) .in_current_span() .await?; - tracing::event!(Level::TRACE, token = token); + event!(Level::TRACE, token = token); return Ok(Response::new(())); } diff --git a/backend/src/endpoint/user.rs b/backend/src/endpoint/user.rs index c86fb14..b8efe38 100644 --- a/backend/src/endpoint/user.rs +++ b/backend/src/endpoint/user.rs @@ -118,7 +118,7 @@ impl User for ArcServer { let mut model: ActiveModel = Default::default(); - tracing::debug!(username = req.info.username); + debug!(username = req.info.username); let hash = self.crypto.hash(req.info.password.as_str()); @@ -133,7 +133,7 @@ impl User for ArcServer { .map_err(Into::::into)?; let id = *model.id.as_ref(); - tracing::info!(counter.user = 1, id = id); + info!(counter.user = 1, id = id); Ok(id.into()) }) @@ -213,7 +213,7 @@ impl User for ArcServer { if result.rows_affected == 0 { Err(Error::NotInDB) } else { - tracing::info!(counter.announcement = -1, id = req.id); + info!(counter.announcement = -1, id = req.id); Ok(()) } }) diff --git a/backend/src/entity/contest.rs b/backend/src/entity/contest.rs index c1d9f6f..2086219 100644 --- a/backend/src/entity/contest.rs +++ b/backend/src/entity/contest.rs @@ -21,7 +21,7 @@ pub struct Model { pub title: String, pub content: String, pub tags: String, - #[sea_orm(column_type = "Binary(BlobSize::Blob(None))", nullable)] + #[sea_orm(column_type = "Blob", nullable)] pub password: Option>, #[sea_orm(column_type = "Time")] pub create_at: chrono::NaiveDateTime, diff --git a/backend/src/entity/submit.rs b/backend/src/entity/submit.rs index dde3b63..ec5cd74 100644 --- a/backend/src/entity/submit.rs +++ b/backend/src/entity/submit.rs @@ -17,7 +17,7 @@ pub struct Model { pub accuracy: Option, pub committed: bool, pub lang: String, - #[sea_orm(column_type = "Binary(BlobSize::Blob(None))")] + #[sea_orm(column_type = "Blob")] pub code: Vec, #[sea_orm(nullable)] pub memory: Option, diff --git a/backend/src/entity/testcase.rs b/backend/src/entity/testcase.rs index 3584978..85c57f1 100644 --- a/backend/src/entity/testcase.rs +++ b/backend/src/entity/testcase.rs @@ -9,9 +9,9 @@ pub struct Model { pub user_id: i32, #[sea_orm(nullable)] pub problem_id: Option, - #[sea_orm(column_type = "Binary(BlobSize::Blob(None))")] + #[sea_orm(column_type = "Blob")] pub input: Vec, - #[sea_orm(column_type = "Binary(BlobSize::Blob(None))")] + #[sea_orm(column_type = "Blob")] pub output: Vec, pub score: u32, pub order: f32, diff --git a/backend/src/entity/token.rs b/backend/src/entity/token.rs index f72f623..5ffed7f 100644 --- a/backend/src/entity/token.rs +++ b/backend/src/entity/token.rs @@ -10,7 +10,7 @@ pub struct Model { #[sea_orm(primary_key)] pub id: i32, pub user_id: i32, - #[sea_orm(column_type = "Binary(BlobSize::Blob(None))")] + #[sea_orm(column_type = "Blob")] pub rand: Vec, pub permission: i32, #[sea_orm(column_type = "Time")] diff --git a/backend/src/entity/user.rs b/backend/src/entity/user.rs index d38ead6..cf66fde 100644 --- a/backend/src/entity/user.rs +++ b/backend/src/entity/user.rs @@ -13,7 +13,7 @@ pub struct Model { pub permission: i32, pub score: i64, pub username: String, - #[sea_orm(column_type = "Binary(BlobSize::Blob(None))")] + #[sea_orm(column_type = "Blob")] pub password: Vec, #[sea_orm(column_type = "Time")] pub create_at: chrono::NaiveDateTime, diff --git a/backend/src/entity/util/helper.rs b/backend/src/entity/util/helper.rs index 0c3694d..5d69f9b 100644 --- a/backend/src/entity/util/helper.rs +++ b/backend/src/entity/util/helper.rs @@ -4,8 +4,8 @@ use std::ops::Deref; +use sea_orm::sea_query::*; use sea_orm::*; -use sea_query::*; use tracing::instrument; use crate::util::error::Error; @@ -190,3 +190,21 @@ impl MaxCount { }) } } + +/// convert sized span to single-direction span +/// +/// Return None if span cannot be converted(cross boundary). +/// +/// It panics if overflow(u64 to i64). +/// +/// See `dev.md` for sized span and single-direction span. +pub(super) fn to_inner_size_offset(size: u64, offset: i64) -> Option<(i64, u64)> { + // cross boundary + if offset.is_negative() && size > offset.unsigned_abs() { + return None; + } + match offset.is_negative() { + true => Some((-(size as i64), offset.unsigned_abs() - size)), + false => Some((size as i64, offset as u64)), + } +} diff --git a/backend/src/entity/util/paginator.rs b/backend/src/entity/util/paginator.rs index a7d98a1..7af82bb 100644 --- a/backend/src/entity/util/paginator.rs +++ b/backend/src/entity/util/paginator.rs @@ -20,7 +20,7 @@ use std::marker::PhantomData; use crate::util::error::Error; -const PAGINATE_GUARANTEE: u64 = 96; +const PAGINATE_GUARANTEE: u64 = 256; #[async_trait] pub trait PaginateRaw @@ -172,8 +172,8 @@ impl> PaginateRaw for PrimaryKeyPaginator async fn new_fetch( data: S::Data, auth: &Auth, - _size: u64, - _offset: u64, + size: u64, + offset: u64, abs_dir: bool, db: &DatabaseConnection, ) -> Result<(Self, Vec), Error> { @@ -181,7 +181,9 @@ impl> PaginateRaw for PrimaryKeyPaginator S::filter(auth, &data, db).await?, ::ID, abs_dir, - ); + ) + .limit(size) + .offset(offset); let models = R::all(query, db).await?; @@ -360,6 +362,14 @@ impl, R: Reflect> PaginateRaw for ColumnPaginator { #[serde(skip)] @@ -388,9 +398,15 @@ impl<'de, P: PaginateRaw> Deserialize<'de> for UninitPaginator

{ } impl UninitPaginator

{ + /// construct a paginator with its initial query argument. pub fn new(data: ::Data, start_from_end: bool) -> Self { Self::Uninit(data, start_from_end) } + /// fetch some entries + /// + /// Return `Error::BadArgument` when + /// 1. offset is when paginator has yet to be initialized and offset is negative + /// 2. span crosses the boundary, pub async fn fetch( &mut self, size: u64, @@ -399,17 +415,8 @@ impl UninitPaginator

{ db: &DatabaseConnection, ) -> Result, Error> { if let UninitPaginator::Init(x) = self { - let size = size.min((i64::MAX - 1) as u64) as i64; - let offset = offset.max(i64::MIN + 1); - let (size, offset) = match offset < 0 { - true => ( - -size, - (-offset) - .checked_sub(size) - .ok_or(Error::BadArgument("size"))? as u64, - ), - false => (size, offset as u64), - }; + let (size, offset) = + to_inner_size_offset(size, offset).ok_or(Error::BadArgument("size"))?; x.fetch(auth, size, offset, db).await.map(|mut x| { if size.is_negative() { x.reverse(); @@ -417,14 +424,22 @@ impl UninitPaginator

{ x }) } else if let UninitPaginator::Uninit(x, start_from_end) = std::mem::take(self) { + if offset.is_negative() { + return Err(Error::BadArgument("offset")); + } let (paginator, list) = - P::new_fetch(x, auth, size, offset.max(0) as u64, start_from_end, db).await?; + P::new_fetch(x, auth, size, offset as u64, start_from_end, db).await?; *self = UninitPaginator::Init(paginator); Ok(list) } else { unreachable!("Cannot in middle state") } } + /// get how many column are remaining the **absolute forward** direction of paginator + /// + /// If more than [`PAGINATE_GUARANTEE`], it returns [`PAGINATE_GUARANTEE`]. + /// + /// It passes [`sea_orm::DbErr`] to the callee. pub async fn remain(&self, auth: &Auth, db: &DatabaseConnection) -> Result where P: Remain, diff --git a/backend/src/server/db.rs b/backend/src/server/db.rs index 78dd833..4d1c20b 100644 --- a/backend/src/server/db.rs +++ b/backend/src/server/db.rs @@ -48,15 +48,9 @@ pub async fn init( #[cfg(feature = "standalone")] /// Run migration async fn migrate(db: &DatabaseConnection) -> super::Result<()> { - sea_orm_migration::cli::run_migrate( - ::migration::Migrator, - db, - Some(sea_orm_cli::cli::MigrateSubcommands::Up { num: None }), - false, - ) - .await - .map_err(InitError::AutoMigrate)?; - Ok(()) + <::migration::Migrator as migration::MigratorTrait>::up(db, None) + .await + .map_err(InitError::AutoMigrate) } #[instrument(skip_all, name = "construct_admin")] diff --git a/backend/src/server/error.rs b/backend/src/server/error.rs index d8af457..ba996c9 100644 --- a/backend/src/server/error.rs +++ b/backend/src/server/error.rs @@ -8,7 +8,7 @@ pub enum InitError { OptimizeDB(sea_orm::DbErr), #[cfg(feature = "standalone")] #[error("Fail to run auto migration: `{0}`")] - AutoMigrate(Box), + AutoMigrate(sea_orm::DbErr), #[error("Fail to create initial user: `{0}`")] UserCreation(sea_orm::DbErr), #[error("Fail to parse config: `{0}`")] diff --git a/backend/src/util/bound.rs b/backend/src/util/bound.rs index 845a0fb..2c46a87 100644 --- a/backend/src/util/bound.rs +++ b/backend/src/util/bound.rs @@ -53,7 +53,7 @@ macro_rules! list_paginator_request { paste::paste! { impl BoundCheck for [] { fn check(&self) -> bool { - if self.size==0{ + if self.size == 0 || self.size >= i32::MAX as u64 || self.offset.unsigned_abs() >= i32::MAX as u64{ true }else if let Some(x) = &self.request { (match x { @@ -82,7 +82,12 @@ list_paginator_request!(User); impl BoundCheck for ListTokenRequest { fn check(&self) -> bool { - if let Some(list_token_request::Request::Paginator(x)) = &self.request { + if self.size == 0 + || self.size >= i32::MAX as u64 + || self.offset.unsigned_abs() >= i32::MAX as u64 + { + true + } else if let Some(list_token_request::Request::Paginator(x)) = &self.request { x.len() > 512 } else { false @@ -92,12 +97,15 @@ impl BoundCheck for ListTokenRequest { impl BoundCheck for ListChatRequest { fn check(&self) -> bool { - self.offset == 0 || self.offset > 4096 || self.size > 128 + self.offset == 0 || self.offset.unsigned_abs() > 4096 || self.size > 128 } } impl BoundCheck for ListSubmitRequest { fn check(&self) -> bool { - if self.offset == 0 { + if self.size == 0 + || self.size >= i32::MAX as u64 + || self.offset.unsigned_abs() >= i32::MAX as u64 + { true } else if let Some(list_submit_request::Request::Paginator(x)) = &self.request { x.len() > 512 @@ -108,7 +116,12 @@ impl BoundCheck for ListSubmitRequest { } impl BoundCheck for ListTestcaseRequest { fn check(&self) -> bool { - if let Some(list_testcase_request::Request::Paginator(x)) = &self.request { + if self.size == 0 + || self.size >= i32::MAX as u64 + || self.offset.unsigned_abs() >= i32::MAX as u64 + { + true + } else if let Some(list_testcase_request::Request::Paginator(x)) = &self.request { x.len() > 512 } else { false diff --git a/backend/src/util/error.rs b/backend/src/util/error.rs index 92461c1..9c9d449 100644 --- a/backend/src/util/error.rs +++ b/backend/src/util/error.rs @@ -33,8 +33,6 @@ pub enum Error { Unreachable(&'static str), #[error("Number too large(or small)")] NumberTooLarge, - // #[error("Buffer `{0}` too large")] - // BufferTooLarge(&'static str), #[error("`{0}` Already exist")] AlreadyExist(&'static str), #[error("require permission `{0}`")] @@ -47,6 +45,8 @@ pub enum Error { Judger(#[from] judger::Error), #[error("token error: `{0}`")] Token(#[from] token::Error), + #[error("retry later")] + Retry, } impl From for Error { @@ -103,6 +103,7 @@ impl From for Status { Error::Image(x) => report_internal!(error, "{}", x), Error::Judger(x) => x.into(), Error::Token(x) => x.into(), + Error::Retry => Status::aborted("Should retry"), } } } @@ -110,7 +111,7 @@ impl From for Status { /// Tracing information for error /// /// useful to log the tracing information to client -/// without exposing the server's internal erro +/// without exposing the server's internal error pub struct Tracing { trace_id: TraceId, span_id: SpanId, diff --git a/judger/src/error.rs b/judger/src/error.rs index 3225eee..2c155a8 100644 --- a/judger/src/error.rs +++ b/judger/src/error.rs @@ -8,8 +8,8 @@ pub enum Error { Io(#[from] std::io::Error), #[error("sandbox error: {0}")] Sandbox(#[from] SandboxError), - /// the program is running on a 32 bit platform, - /// and have a object reached [`u32::MAX`] + /// the program is running on a 32-bit platform, + /// and have an object reached [`u32::MAX`] #[error("32 bit problem")] Platform, } @@ -23,10 +23,10 @@ impl From for Status { #[derive(thiserror::Error, Debug)] pub enum ClientError { - #[error("invaild secret")] - InvaildSecret, - #[error("invaild language uuid")] - InvaildLanguageUuid, + #[error("invalid secret")] + InvalidSecret, + #[error("invalid language uuid")] + InvalidLanguageUuid, #[error("impossible memory requirement")] ImpossibleMemoryRequirement, } @@ -34,9 +34,9 @@ pub enum ClientError { impl From for Status { fn from(value: ClientError) -> Self { match value { - ClientError::InvaildSecret => Status::permission_denied("Invaild secret"), - ClientError::InvaildLanguageUuid => { - Status::failed_precondition("Invaild language uuid") + ClientError::InvalidSecret => Status::permission_denied("Invalid secret"), + ClientError::InvalidLanguageUuid => { + Status::failed_precondition("Invalid language uuid") } ClientError::ImpossibleMemoryRequirement => { Status::failed_precondition("Impossible memory requirement") diff --git a/judger/src/filesystem/adapter/error.rs b/judger/src/filesystem/adapter/error.rs index 0e10451..0c51c97 100644 --- a/judger/src/filesystem/adapter/error.rs +++ b/judger/src/filesystem/adapter/error.rs @@ -20,17 +20,17 @@ pub enum FuseError { #[error("unimplemented")] Unimplemented, #[error("missed inode")] - InvaildIno, + InvalidIno, #[error("missed handle")] HandleNotFound, - #[error("underlaying file error")] - Underlaying, + #[error("underlying file error")] + Underlying, #[error("invalid path")] InvalidPath, #[error("permission deny")] PermissionDeny, #[error("invalid argument")] - InvialdArg, + InvalidArg, #[error("Already exist")] AlreadyExist, } @@ -47,9 +47,9 @@ impl From for fuse3::Errno { log::info!("out of resource"); libc::ENOMEM } - FuseError::InvalidPath | FuseError::InvaildIno => libc::ENOENT, + FuseError::InvalidPath | FuseError::InvalidIno => libc::ENOENT, FuseError::PermissionDeny => libc::EACCES, - FuseError::InvialdArg => libc::EINVAL, + FuseError::InvalidArg => libc::EINVAL, FuseError::AlreadyExist => libc::EEXIST, err => { log::warn!("FUSE driver broken: {}", err); diff --git a/judger/src/filesystem/adapter/fuse.rs b/judger/src/filesystem/adapter/fuse.rs index 0e5b220..8d98c37 100644 --- a/judger/src/filesystem/adapter/fuse.rs +++ b/judger/src/filesystem/adapter/fuse.rs @@ -3,7 +3,6 @@ use std::{ffi::OsStr, num::NonZeroU32, path::Path, sync::Arc}; use bytes::Bytes; use futures_core::Future; use spin::Mutex; -use tokio::fs::metadata; use tokio::io::{AsyncRead, AsyncSeek}; use tokio::sync::Mutex as AsyncMutex; @@ -87,7 +86,7 @@ where async fn lookup(&self, req: Request, parent: u64, name: &OsStr) -> FuseResult { let tree = self.tree.lock(); - let parent_node = tree.get(parent as usize).ok_or(FuseError::InvaildIno)?; + let parent_node = tree.get(parent as usize).ok_or(FuseError::InvalidIno)?; let node = parent_node .get_by_component(name) .ok_or(FuseError::InvalidPath)?; @@ -122,7 +121,7 @@ where } async fn opendir(&self, _: Request, inode: u64, flags: u32) -> FuseResult { let tree = self.tree.lock(); - let node = tree.get(inode as usize).ok_or(FuseError::InvaildIno)?; + let node = tree.get(inode as usize).ok_or(FuseError::InvalidIno)?; if node.get_value().kind() != FileType::Directory { return Err(FuseError::NotDir.into()); } @@ -135,7 +134,7 @@ where // ignore write permission, because some application may open files // with write permission but never write let tree = self.tree.lock(); - let node = tree.get(inode as usize).ok_or(FuseError::InvaildIno)?; + let node = tree.get(inode as usize).ok_or(FuseError::InvalidIno)?; if node.get_value().kind() == FileType::Directory { return Err(FuseError::IsDir.into()); } @@ -152,7 +151,7 @@ where offset: i64, ) -> FuseResult>> { let tree = self.tree.lock(); - let node = tree.get(parent as usize).ok_or(FuseError::InvaildIno)?; + let node = tree.get(parent as usize).ok_or(FuseError::InvalidIno)?; if node.get_value().kind() != FileType::Directory { return Err(FuseError::NotDir.into()); @@ -201,7 +200,7 @@ where _: u64, ) -> FuseResult>> { let tree = self.tree.lock(); - let node = tree.get(parent as usize).ok_or(FuseError::InvaildIno)?; + let node = tree.get(parent as usize).ok_or(FuseError::InvalidIno)?; if node.get_value().kind() != FileType::Directory { return Err(FuseError::NotDir.into()); @@ -322,7 +321,7 @@ where _: u32, ) -> FuseResult<()> { let tree = self.tree.lock(); - let node = tree.get(inode as usize).ok_or(FuseError::InvaildIno)?; + let node = tree.get(inode as usize).ok_or(FuseError::InvalidIno)?; match node.get_value().kind() { FileType::Directory | FileType::NamedPipe | FileType::CharDevice => { @@ -342,7 +341,7 @@ where _: u32, ) -> FuseResult { let tree = self.tree.lock(); - let node = tree.get(inode as usize).ok_or(FuseError::InvaildIno)?; + let node = tree.get(inode as usize).ok_or(FuseError::InvalidIno)?; // FIXME: unsure about the inode Ok(reply_attr(&req, node.get_value(), inode)) } @@ -354,7 +353,7 @@ where _: SetAttr, ) -> FuseResult { let tree = self.tree.lock(); - let node = tree.get(inode as usize).ok_or(FuseError::InvaildIno)?; + let node = tree.get(inode as usize).ok_or(FuseError::InvalidIno)?; Ok(reply_attr(&req, node.get_value(), inode)) } async fn create( @@ -366,7 +365,7 @@ where flags: u32, ) -> FuseResult { let mut tree = self.tree.lock(); - let mut parent_node = tree.get_mut(parent as usize).ok_or(FuseError::InvaildIno)?; + let mut parent_node = tree.get_mut(parent as usize).ok_or(FuseError::InvalidIno)?; if parent_node.get_value().kind() != FileType::Directory { return Err(FuseError::NotDir.into()); } @@ -389,7 +388,7 @@ where _: u32, ) -> FuseResult { let mut tree = self.tree.lock(); - let mut parent_node = tree.get_mut(parent as usize).ok_or(FuseError::InvaildIno)?; + let mut parent_node = tree.get_mut(parent as usize).ok_or(FuseError::InvalidIno)?; if parent_node.get_value().kind() != FileType::Directory { return Err(FuseError::NotDir.into()); } @@ -401,18 +400,18 @@ where } async fn readlink(&self, _: Request, inode: Inode) -> FuseResult { let tree = self.tree.lock(); - let node = tree.get(inode as usize).ok_or(FuseError::InvaildIno)?; + let node = tree.get(inode as usize).ok_or(FuseError::InvalidIno)?; let link = node .get_value() .get_symlink() - .ok_or(FuseError::InvialdArg)?; + .ok_or(FuseError::InvalidArg)?; Ok(ReplyData { data: Bytes::copy_from_slice(link.as_encoded_bytes()), }) } async fn unlink(&self, _: Request, parent: Inode, name: &OsStr) -> FuseResult<()> { let mut tree = self.tree.lock(); - let mut parent_node = tree.get_mut(parent as usize).ok_or(FuseError::InvaildIno)?; + let mut parent_node = tree.get_mut(parent as usize).ok_or(FuseError::InvalidIno)?; if parent_node.get_value().kind() != FileType::Directory { return Err(FuseError::NotDir.into()); } diff --git a/judger/src/filesystem/adapter/reply.rs b/judger/src/filesystem/adapter/reply.rs index 8de93a3..ed587a3 100644 --- a/judger/src/filesystem/adapter/reply.rs +++ b/judger/src/filesystem/adapter/reply.rs @@ -1,4 +1,4 @@ -//! collection of function that fill the value of +//! collection of function that fill with the value of //! reply packets back to fuse connection use std::{ffi::OsString, time::Duration}; diff --git a/judger/src/filesystem/entry/mod.rs b/judger/src/filesystem/entry/mod.rs index 8f83ea2..bb25b91 100644 --- a/judger/src/filesystem/entry/mod.rs +++ b/judger/src/filesystem/entry/mod.rs @@ -136,7 +136,7 @@ where pub async fn write(&mut self, offset: u64, data: &[u8], resource: &Resource) -> Option { // FIXME: consume logic should move somewhere else let required_size = data.len() as u64 + offset; - resource.comsume_other(required_size.saturating_sub(self.get_size()))?; + resource.consume_other(required_size.saturating_sub(self.get_size()))?; match self { Self::MemFile(block) => Some(block.write(offset, data).await.unwrap()), diff --git a/judger/src/filesystem/mod.rs b/judger/src/filesystem/mod.rs index 3393101..289ba14 100644 --- a/judger/src/filesystem/mod.rs +++ b/judger/src/filesystem/mod.rs @@ -1,5 +1,5 @@ -//! Filesystem module that is mountable(actuallly mount and -//! is accessible for user in this operation system) +//! Filesystem module that is mountable(actually mount and +//! is accessible for user in this operating system) mod adapter; mod entry; mod handle; diff --git a/judger/src/filesystem/resource.rs b/judger/src/filesystem/resource.rs index 55db660..0c3721a 100644 --- a/judger/src/filesystem/resource.rs +++ b/judger/src/filesystem/resource.rs @@ -11,7 +11,7 @@ impl Resource { Self(AtomicU64::new(cap)) } /// consume some amount of resource - pub fn comsume(&self, size: u32) -> Option<()> { + pub fn consume(&self, size: u32) -> Option<()> { let a = self.0.fetch_sub(size as u64, Ordering::AcqRel); if (a & (1 << 63)) != 0 { None @@ -23,8 +23,8 @@ impl Resource { /// /// return None if the resource is not enough or the size /// is out of range (greater than[`u32::MAX`]) - pub fn comsume_other>(&self, size: T) -> Option<()> { + pub fn consume_other>(&self, size: T) -> Option<()> { let size = size.try_into().ok()?; - self.comsume(size) + self.consume(size) } } diff --git a/judger/src/filesystem/table.rs b/judger/src/filesystem/table.rs index 8618192..ff18f47 100644 --- a/judger/src/filesystem/table.rs +++ b/judger/src/filesystem/table.rs @@ -294,7 +294,7 @@ mod test { use super::*; #[test] fn test_adj_table() { - let mut table = super::AdjTable::new(); + let mut table = AdjTable::new(); let mut root = table.insert_root(0); root.insert(OsStr::new("a").into(), 1); let mut b = root.insert(OsStr::new("b").into(), 2).unwrap(); @@ -306,7 +306,7 @@ mod test { } #[test] fn get_or_insert() { - let mut table = super::AdjTable::new(); + let mut table = AdjTable::new(); table.insert_root(0); table.insert_by_path( vec!["abc", "efg", "123", "456"] @@ -325,7 +325,7 @@ mod test { } #[test] fn parent_child_insert() { - let mut table = super::AdjTable::new(); + let mut table = AdjTable::new(); let mut root = table.insert_root(0); // inode 1 assert_eq!(root.get_id(), 1); let mut a = root.insert(OsStr::new("a").into(), 1).unwrap(); // inode 2 diff --git a/judger/src/language/spec/mod.rs b/judger/src/language/spec/mod.rs index 449910d..2d49a91 100644 --- a/judger/src/language/spec/mod.rs +++ b/judger/src/language/spec/mod.rs @@ -107,7 +107,7 @@ impl Spec { let mut raw: Raw = toml::from_str(content).unwrap(); raw.fill(); - // FIXME: use compsition instead + // FIXME: use composition instead Self { info: LangInfo::from(&raw), id: raw.id, diff --git a/judger/src/language/stage/judge.rs b/judger/src/language/stage/judge.rs index 6ec8099..1cb734b 100644 --- a/judger/src/language/stage/judge.rs +++ b/judger/src/language/stage/judge.rs @@ -43,7 +43,7 @@ impl Judger { } } } - AssertionMode::SkipContinousSpace => { + AssertionMode::SkipContinuousSpace => { // skip space and newline, continous space is consider same let output = output.iter().map(|x| match x { b'\n' | b' ' => b' ', diff --git a/judger/src/language/stage/mod.rs b/judger/src/language/stage/mod.rs index 41f755e..8af73dd 100644 --- a/judger/src/language/stage/mod.rs +++ b/judger/src/language/stage/mod.rs @@ -11,7 +11,7 @@ pub use run::Runner; /// internal status code, use to decouple the grpc status code /// -/// Status code is commonly use in OJ, it include example such as: AC, WA... +/// Status code is commonly use in OJ, it includes example such as: AC, WA... #[derive(Clone, Copy, PartialEq, Eq, Debug)] pub enum StatusCode { Accepted, @@ -27,7 +27,7 @@ pub enum StatusCode { /// internal assertion mode, use to decouple the grpc status code /// -/// Assertion mode reperesent how the output is compared +/// Assertion mode represent how the output is compared #[derive(Clone, Copy)] pub enum AssertionMode { /// Skip single space and newline @@ -36,10 +36,10 @@ pub enum AssertionMode { /// /// `a\nb` and `a\n\nb` are different SkipSpace, - /// Skip continous space and newline + /// Skip continuous space and newline /// /// `ab`, `a\nb` and `a\n\nb` are the same - SkipContinousSpace, + SkipContinuousSpace, /// Exact match Exact, } @@ -56,7 +56,7 @@ impl From for AssertionMode { match rule { JudgeMatchRule::ExactSame => AssertionMode::Exact, JudgeMatchRule::IgnoreSnl => AssertionMode::SkipSpace, - JudgeMatchRule::SkipSnl => AssertionMode::SkipContinousSpace, + JudgeMatchRule::SkipSnl => AssertionMode::SkipContinuousSpace, } } } diff --git a/judger/src/language/stage/run.rs b/judger/src/language/stage/run.rs index ebc9d78..bd674dc 100644 --- a/judger/src/language/stage/run.rs +++ b/judger/src/language/stage/run.rs @@ -46,7 +46,7 @@ impl Runner { /// See [`Context`] for more information struct RunCtx { spec: Arc, - path: std::path::PathBuf, + path: PathBuf, limit: Stat, } diff --git a/judger/src/sandbox/monitor/mem_cpu.rs b/judger/src/sandbox/monitor/mem_cpu.rs index 2856d7d..0cbe87a 100644 --- a/judger/src/sandbox/monitor/mem_cpu.rs +++ b/judger/src/sandbox/monitor/mem_cpu.rs @@ -126,7 +126,7 @@ impl super::Monitor for Monitor { /// get the final resource usage /// /// Please remember thatActively limit(notify) cpu resource is achieved - /// by polling the cgroup, therefore the delay requirespecial attention, + /// by polling the cgroup, therefore the delay require special attention, /// it is only guaranteed to below limitation provided + [`MONITOR_ACCURACY`]. async fn stat(self) -> Self::Resource { // FIXME: check running process, this line is commented out because of uncollected process diff --git a/judger/src/sandbox/monitor/mod.rs b/judger/src/sandbox/monitor/mod.rs index 08bac8f..eed17b6 100644 --- a/judger/src/sandbox/monitor/mod.rs +++ b/judger/src/sandbox/monitor/mod.rs @@ -24,7 +24,7 @@ lazy_static::lazy_static! { pub trait Monitor { type Resource; - /// wait for exhuast of resource + /// wait for exhaust of resource /// /// This function is cancel safe. async fn wait_exhaust(&mut self) -> MonitorKind { @@ -37,9 +37,9 @@ pub trait Monitor { tokio::time::sleep(Duration::from_millis(12)).await; } } - /// poll for exhuast of resource + /// poll for exhaust of resource /// - /// Implementor should do bith [`wait_exhaust`] and [`poll_exhaust`] + /// Implementor should do both [`wait_exhaust`] and [`poll_exhaust`] /// for better performance. fn poll_exhaust(&mut self) -> Option; /// get the resource usage diff --git a/judger/src/sandbox/monitor/output.rs b/judger/src/sandbox/monitor/output.rs index f5aaa46..b437446 100644 --- a/judger/src/sandbox/monitor/output.rs +++ b/judger/src/sandbox/monitor/output.rs @@ -82,7 +82,7 @@ mod test { #[tokio::test] async fn monitor_output_limit() { - let (mut stdin, stdout) = tokio::io::duplex(1024); + let (mut stdin, stdout) = duplex(1024); let mut monitor = Monitor::inner_new(9, stdout); stdin.write_all(b"1234567890").await.unwrap(); assert_eq!( diff --git a/judger/src/sandbox/monitor/wrapper.rs b/judger/src/sandbox/monitor/wrapper.rs index d58539b..3a18d0b 100644 --- a/judger/src/sandbox/monitor/wrapper.rs +++ b/judger/src/sandbox/monitor/wrapper.rs @@ -66,9 +66,9 @@ impl<'a> CgroupWrapper<'a> { /// get memory usage(statistics) pub fn memory(&self) -> Memory { let controller = self.0.controller_of::().unwrap(); - let kusage = controller.kmem_stat(); + let kernel_usage = controller.kmem_stat(); - let kernel = kusage.max_usage_in_bytes; + let kernel = kernel_usage.max_usage_in_bytes; let user = controller.memory_stat().max_usage_in_bytes; let total = kernel + user; @@ -96,7 +96,7 @@ impl CgroupWrapperOwned { } /// poll until cgroup is deleted /// - /// After the cgroup is empty(`tasks` is empty), the cgroup is can be delete safely + /// After the cgroup is empty(`tasks` is empty), the cgroup is can be deleted safely /// /// However, in some rare cases, the monitor is reading file in cgroup /// when the cgroup is about to be deleted, this will cause the cgroup to stay busy diff --git a/judger/src/sandbox/process/lifetime.rs b/judger/src/sandbox/process/lifetime.rs index ba86017..02b918c 100644 --- a/judger/src/sandbox/process/lifetime.rs +++ b/judger/src/sandbox/process/lifetime.rs @@ -9,7 +9,7 @@ use tokio::{ process::*, time, }; -/// A unlaunched process that is mounted with a filesystem +/// A not yet launched process that is mounted with a filesystem struct MountedProcess { context: C, fs: C::FS, @@ -84,10 +84,9 @@ impl Process { let root = self.fs.get_path(); // FIXME: check spec before unwrap let jail = self.context.get_args().next().unwrap(); - let unjailed = [root.as_ref().as_os_str(), jail].join(OsStr::new("")); - let unjailed = PathBuf::from(unjailed); + let real_path = PathBuf::from([root.as_ref().as_os_str(), jail].join(OsStr::new(""))); - let mut ancestors = unjailed.ancestors(); + let mut ancestors = real_path.ancestors(); ancestors.next().unwrap(); ancestors.next().unwrap().as_os_str().to_os_string() } diff --git a/judger/src/sandbox/process/mod.rs b/judger/src/sandbox/process/mod.rs index 7b1e026..f2ef3b0 100644 --- a/judger/src/sandbox/process/mod.rs +++ b/judger/src/sandbox/process/mod.rs @@ -1,6 +1,6 @@ -//! A module that provides a way to setup environment for a process and run. +//! A module that provides a way to set up environment for a process and run. //! -//! Using this module should be SAFE(can't launching a process without +//! Using this module should be SAFE(can't launch a process without //! explicit resource limitation) //! //! ```norun diff --git a/judger/src/sandbox/process/nsjail.rs b/judger/src/sandbox/process/nsjail.rs index 5d07766..9f9d768 100644 --- a/judger/src/sandbox/process/nsjail.rs +++ b/judger/src/sandbox/process/nsjail.rs @@ -14,7 +14,7 @@ pub trait Argument { fn get_args(self) -> impl Iterator>; } -/// factory pattern for conbinating arguments +/// factory pattern for combining arguments #[derive(Default)] pub struct ArgFactory { args: Vec>, @@ -31,7 +31,7 @@ impl ArgFactory { } } -/// base auguments for nsjail +/// base arguments for nsjail pub struct BaseArg; impl Argument for BaseArg { diff --git a/judger/src/server.rs b/judger/src/server.rs index 51d0e8b..f2ac022 100644 --- a/judger/src/server.rs +++ b/judger/src/server.rs @@ -16,7 +16,7 @@ use crate::{ const PLUGIN_PATH: &str = "plugins"; -fn check_secret(req: tonic::Request) -> Result { +fn check_secret(req: Request) -> Result { let (meta, _, payload) = req.into_parts(); if CONFIG.secret.is_none() { return Ok(payload); @@ -24,13 +24,13 @@ fn check_secret(req: tonic::Request) -> Result { let secret = CONFIG.secret.as_ref().unwrap(); if let Some(header) = meta.get("Authorization") { let secret = ["basic ", secret].concat().into_bytes(); - let vaild = header + let valid = header .as_bytes() .iter() .zip(secret.iter()) .map(|(&a, &b)| a == b) .reduce(|a, b| a && b); - if vaild.unwrap_or(false) { + if valid.unwrap_or(false) { return Ok(payload); } } @@ -64,12 +64,12 @@ impl Judger for Server { let cpu = payload.time; let source = payload.code; let uuid = - Uuid::from_str(&payload.lang_uid).map_err(|_| ClientError::InvaildLanguageUuid)?; + Uuid::from_str(&payload.lang_uid).map_err(|_| ClientError::InvalidLanguageUuid)?; let plugin = self .plugins .get(&uuid) - .ok_or(ClientError::InvaildLanguageUuid)?; + .ok_or(ClientError::InvalidLanguageUuid)?; let resource: u32 = plugin .get_memory_reserved(payload.memory) .try_into() @@ -106,7 +106,7 @@ impl Judger for Server { }))) } - async fn judger_info(&self, req: tonic::Request<()>) -> Result, Status> { + async fn judger_info(&self, req: Request<()>) -> Result, Status> { check_secret(req)?; let list = self .plugins @@ -123,10 +123,7 @@ impl Judger for Server { type ExecStream = tokio_stream::Once>; - async fn exec( - &self, - req: Request, - ) -> Result, tonic::Status> { + async fn exec(&self, req: Request) -> Result, Status> { let payload = check_secret(req)?; let memory = payload.memory; @@ -136,12 +133,12 @@ impl Judger for Server { let input = payload.input; let uuid = - Uuid::from_str(&payload.lang_uid).map_err(|_| ClientError::InvaildLanguageUuid)?; + Uuid::from_str(&payload.lang_uid).map_err(|_| ClientError::InvalidLanguageUuid)?; let plugin = self .plugins .get(&uuid) - .ok_or(ClientError::InvaildLanguageUuid)?; + .ok_or(ClientError::InvalidLanguageUuid)?; let resource: u32 = plugin .get_memory_reserved(payload.memory)