From 7bb564f91e96d672b7379609d1df9ee28e8270e1 Mon Sep 17 00:00:00 2001 From: SevenOfAces Date: Mon, 17 Mar 2025 18:52:48 -0700 Subject: [PATCH] Backup --- .envrc | 1 + .gitignore | 3 +- Cargo.lock | 1288 +++++++++++++++++++++++++++++++++- Cargo.toml | 7 +- docs/WEBAPI_V1.md | 49 ++ rust-toolchain.toml | 4 + shell.nix | 42 +- src/data/mod.rs | 28 - src/data/util.rs | 33 - src/lib.rs | 14 +- src/main.rs | 4 +- src/server/access.rs | 33 + src/{data => server}/auth.rs | 27 +- src/server/mod.rs | 25 + src/server/storage.rs | 375 ++++++++++ src/server/util.rs | 33 + 16 files changed, 1877 insertions(+), 89 deletions(-) create mode 100644 .envrc create mode 100644 docs/WEBAPI_V1.md create mode 100644 rust-toolchain.toml delete mode 100644 src/data/mod.rs delete mode 100644 src/data/util.rs create mode 100644 src/server/access.rs rename src/{data => server}/auth.rs (96%) create mode 100644 src/server/mod.rs create mode 100644 src/server/storage.rs create mode 100644 src/server/util.rs diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..1d953f4 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use nix diff --git a/.gitignore b/.gitignore index 1de5659..b816370 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -target \ No newline at end of file +target +.direnv \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index bfb3722..434417a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,24 +2,428 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "actix-codec" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f7b0a21988c1bf877cf4759ef5ddaac04c1c9fe808c9142ecb78ba97d97a28a" +dependencies = [ + "bitflags", + "bytes", + "futures-core", + "futures-sink", + "memchr", + "pin-project-lite", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "actix-http" +version = "3.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa882656b67966045e4152c634051e70346939fced7117d5f0b52146a7c74c9" +dependencies = [ + "actix-codec", + "actix-rt", + "actix-service", + "actix-utils", + "base64", + "bitflags", + "brotli", + "bytes", + "bytestring", + "derive_more", + "encoding_rs", + "flate2", + "foldhash", + "futures-core", + "h2", + "http", + "httparse", + "httpdate", + "itoa", + "language-tags", + "local-channel", + "mime", + "percent-encoding", + "pin-project-lite", + "rand 0.9.0", + "sha1", + "smallvec", + "tokio", + "tokio-util", + "tracing", + "zstd", +] + +[[package]] +name = "actix-macros" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e01ed3140b2f8d422c68afa1ed2e85d996ea619c988ac834d255db32138655cb" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "actix-router" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13d324164c51f63867b57e73ba5936ea151b8a41a1d23d1031eeb9f70d0236f8" +dependencies = [ + "bytestring", + "cfg-if", + "http", + "regex", + "regex-lite", + "serde", + "tracing", +] + +[[package]] +name = "actix-rt" +version = "2.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24eda4e2a6e042aa4e55ac438a2ae052d3b5da0ecf83d7411e1a368946925208" +dependencies = [ + "futures-core", + "tokio", +] + +[[package]] +name = "actix-server" +version = "2.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6398974fd4284f4768af07965701efbbb5fdc0616bff20cade1bb14b77675e24" +dependencies = [ + "actix-rt", + "actix-service", + "actix-utils", + "futures-core", + "futures-util", + "mio", + "socket2", + "tokio", + "tracing", +] + +[[package]] +name = "actix-service" +version = "2.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e46f36bf0e5af44bdc4bdb36fbbd421aa98c79a9bce724e1edeb3894e10dc7f" +dependencies = [ + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "actix-utils" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88a1dcdff1466e3c2488e1cb5c36a71822750ad43839937f85d2f4d9f8b705d8" +dependencies = [ + "local-waker", + "pin-project-lite", +] + +[[package]] +name = "actix-web" +version = "4.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2e3b15b3dc6c6ed996e4032389e9849d4ab002b1e92fbfe85b5f307d1479b4d" +dependencies = [ + "actix-codec", + "actix-http", + "actix-macros", + "actix-router", + "actix-rt", + "actix-server", + "actix-service", + "actix-utils", + "actix-web-codegen", + "bytes", + "bytestring", + "cfg-if", + "cookie", + "derive_more", + "encoding_rs", + "foldhash", + "futures-core", + "futures-util", + "impl-more", + "itoa", + "language-tags", + "log", + "mime", + "once_cell", + "pin-project-lite", + "regex", + "regex-lite", + "serde", + "serde_json", + "serde_urlencoded", + "smallvec", + "socket2", + "time", + "tracing", + "url", +] + +[[package]] +name = "actix-web-codegen" +version = "4.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f591380e2e68490b5dfaf1dd1aa0ebe78d84ba7067078512b4ea6e4492d622b8" +dependencies = [ + "actix-router", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "addr2line" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler2" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + +[[package]] +name = "alloc-no-stdlib" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc7bb162ec39d46ab1ca8c77bf72e890535becd1751bb45f64c597edb4c8c6b3" + +[[package]] +name = "alloc-stdlib" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94fb8275041c72129eb51b7d0322c29b8387a0386127718b096429201a5d6ece" +dependencies = [ + "alloc-no-stdlib", +] + [[package]] name = "autocfg" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" +[[package]] +name = "backtrace" +version = "0.3.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" +dependencies = [ + "addr2line", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", + "windows-targets", +] + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + [[package]] name = "bitflags" version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd" +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "brotli" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc97b8f16f944bba54f0433f07e30be199b6dc2bd25937444bbad560bcea29bd" +dependencies = [ + "alloc-no-stdlib", + "alloc-stdlib", + "brotli-decompressor", +] + +[[package]] +name = "brotli-decompressor" +version = "4.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74fa05ad7d803d413eb8380983b092cbbaf9a85f151b871360e7b00cd7060b37" +dependencies = [ + "alloc-no-stdlib", + "alloc-stdlib", +] + +[[package]] +name = "bytes" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" + +[[package]] +name = "bytestring" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e465647ae23b2823b0753f50decb2d5a86d2bb2cac04788fafd1f80e45378e5f" +dependencies = [ + "bytes", +] + +[[package]] +name = "cc" +version = "1.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be714c154be609ec7f5dad223a33bf1482fff90472de28f7362806e6d4832b8c" +dependencies = [ + "jobserver", + "libc", + "shlex", +] + [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cookie" +version = "0.16.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e859cd57d0710d9e06c381b550c06e76992472a8c6d527aecd2fc673dcc231fb" +dependencies = [ + "percent-encoding", + "time", + "version_check", +] + +[[package]] +name = "cpufeatures" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +dependencies = [ + "libc", +] + +[[package]] +name = "crc32fast" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "deranged" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "powerfmt", +] + +[[package]] +name = "derive_more" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "093242cf7570c207c83073cf82f79706fe7b8317e98620a47d5be7c3d8497678" +dependencies = [ + "derive_more-impl", +] + +[[package]] +name = "derive_more-impl" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda628edc44c4bb645fbe0f758797143e4e07926f7ebf4e9bdfbd3d2ce621df3" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "unicode-xid", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "encoding_rs" +version = "0.8.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + [[package]] name = "fern" version = "0.7.1" @@ -29,12 +433,83 @@ dependencies = [ "log", ] +[[package]] +name = "flate2" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11faaf5a5236997af9848be0bef4db95824b1d534ebc64d0f0c6cf3e67bd38dc" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foldhash" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0d2fde1f7b3d48b8395d5f2de76c18a528bd6a9cdde438df747bfcba3e05d6f" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + [[package]] name = "fuchsia-cprng" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" +[[package]] +name = "futures-core" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" + +[[package]] +name = "futures-sink" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" + +[[package]] +name = "futures-task" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" + +[[package]] +name = "futures-util" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" +dependencies = [ + "futures-core", + "futures-task", + "pin-project-lite", + "pin-utils", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + [[package]] name = "getrandom" version = "0.3.1" @@ -43,16 +518,279 @@ checksum = "43a49c392881ce6d5c3b8cb70f98717b7c07aabbdff06687b9030dbfbe2725f8" dependencies = [ "cfg-if", "libc", - "wasi", + "wasi 0.13.3+wasi-0.2.2", "windows-targets", ] +[[package]] +name = "gimli" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" + +[[package]] +name = "h2" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81fe527a889e1532da5c525686d96d4c2e74cdd345badf8dfef9f6b39dd5f5e8" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" + +[[package]] +name = "http" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "icu_collections" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db2fa452206ebee18c4b5c2274dbf1de17008e874b4dc4f0aea9d01ca79e4526" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locid" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13acbb8371917fc971be86fc8057c41a64b521c184808a698c02acc242dbf637" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_locid_transform" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01d11ac35de8e40fdeda00d9e1e9d92525f3f9d887cdd7aa81d727596788b54e" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_locid_transform_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_locid_transform_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdc8ff3388f852bede6b579ad4e978ab004f139284d7b28715f773507b946f6e" + +[[package]] +name = "icu_normalizer" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19ce3e0da2ec68599d193c93d088142efd7f9c5d6fc9b803774855747dc6a84f" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "utf16_iter", + "utf8_iter", + "write16", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8cafbf7aa791e9b22bec55a167906f9e1215fd475cd22adfcf660e03e989516" + +[[package]] +name = "icu_properties" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93d6020766cfc6302c15dbbc9c8778c37e62c14427cb7f6e601d849e092aeef5" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locid_transform", + "icu_properties_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67a8effbc3dd3e4ba1afa8ad918d5684b8868b3b26500753effea8d2eed19569" + +[[package]] +name = "icu_provider" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ed421c8a8ef78d3e2dbc98a973be2f3770cb42b606e3ab18d6237c4dfde68d9" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_provider_macros", + "stable_deref_trait", + "tinystr", + "writeable", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_provider_macros" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "idna" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "686f825264d630750a544639377bae737628043f20d38bbc029e8f29ea968a7e" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daca1df1c957320b2cf139ac61e7bd64fed304c5040df000a745aa1de3b4ef71" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] +name = "impl-more" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8a5a9a0ff0086c7a148acb942baaabeadf9504d10400b5a05645853729b9cd2" + +[[package]] +name = "indexmap" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3954d50fe15b02142bf25d3b8bdadb634ec3948f103d04ffe3031bc8fe9d7058" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "itoa" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" + +[[package]] +name = "jobserver" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0" +dependencies = [ + "libc", +] + +[[package]] +name = "language-tags" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4345964bb142484797b161f473a503a434de77149dd8c7427788c6e13379388" + [[package]] name = "libc" version = "0.2.171" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c19937216e9d3aa9956d9bb8dfc0b0c8beb6058fc4f7a4dc4d850edf86a237d6" +[[package]] +name = "litemap" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23fb14cb19457329c82206317a5663005a4d404783dc74f4252769b0d5f42856" + +[[package]] +name = "local-channel" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6cbc85e69b8df4b8bb8b89ec634e7189099cea8927a276b7384ce5488e53ec8" +dependencies = [ + "futures-core", + "futures-sink", + "local-waker", +] + +[[package]] +name = "local-waker" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d873d7c67ce09b42110d801813efbc9364414e356be9935700d368351657487" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + [[package]] name = "log" version = "0.4.26" @@ -69,6 +807,7 @@ checksum = "baee0bbc17ce759db233beb01648088061bf678383130602a298e6998eedb2d8" name = "matchmaker" version = "0.1.0" dependencies = [ + "actix-web", "fern", "log", "macaddr", @@ -76,6 +815,39 @@ dependencies = [ "stopwatch", ] +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e3e04debbb59698c15bacbb6d93584a8c0ca9cc3213cb423d31f760d8843ce5" +dependencies = [ + "adler2", +] + +[[package]] +name = "mio" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2886843bf800fba2e3377cff24abf6379b4c4d5c6681eaf9ea5b0d15090450bd" +dependencies = [ + "libc", + "log", + "wasi 0.11.0+wasi-snapshot-preview1", + "windows-sys", +] + [[package]] name = "num" version = "0.1.43" @@ -114,6 +886,12 @@ dependencies = [ "rustc-serialize", ] +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + [[package]] name = "num-integer" version = "0.1.46" @@ -156,6 +934,74 @@ dependencies = [ "autocfg", ] +[[package]] +name = "object" +version = "0.36.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cde51589ab56b20a6f686b2c68f7a0bd6add753d697abf720d63f8db3ab7b1ad" + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "pin-project-lite" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + [[package]] name = "ppv-lite86" version = "0.2.21" @@ -250,12 +1096,175 @@ dependencies = [ "rand_core 0.3.1", ] +[[package]] +name = "redox_syscall" +version = "0.5.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b8c0c260b63a8219631167be35e6a988e9554dbd323f8bd08439c8ed1302bd1" +dependencies = [ + "bitflags", +] + +[[package]] +name = "regex" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-lite" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53a49587ad06b26609c52e423de037e7f57f20d53535d66e08c695f347df952a" + +[[package]] +name = "regex-syntax" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + [[package]] name = "rustc-serialize" version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fe834bc780604f4674073badbad26d7219cadfb4a2275802db12cbae17498401" +[[package]] +name = "ryu" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "serde" +version = "1.0.219" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.219" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.140" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha1" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcf8323ef1faaee30a44a340193b1ac6814fd9b7b4e88e9d4519a3e4abe1cfd" + +[[package]] +name = "socket2" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c970269d99b64e60ec3bd6ad27270092a5394c4e309314b18ae3fe575695fbe8" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + [[package]] name = "stopwatch" version = "0.0.7" @@ -276,12 +1285,173 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "synstructure" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "time" +version = "0.3.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dad298b01a40a23aac4580b67e3dbedb7cc8402f3592d7f49469de2ea4aecdd8" +dependencies = [ + "deranged", + "itoa", + "num-conv", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "765c97a5b985b7c11d7bc27fa927dc4fe6af3a6dfb021d28deb60d3bf51e76ef" + +[[package]] +name = "time-macros" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8093bc3e81c3bc5f7879de09619d06c9a5a5e45ca44dfeeb7225bae38005c5c" +dependencies = [ + "num-conv", + "time-core", +] + +[[package]] +name = "tinystr" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9117f5d4db391c1cf6927e7bea3db74b9a1c1add8f7eda9ffd5364f40f57b82f" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "tokio" +version = "1.44.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f382da615b842244d4b8738c82ed1275e6c5dd90c459a30941cd07080b06c91a" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "windows-sys", +] + +[[package]] +name = "tokio-util" +version = "0.7.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b9590b93e6fcc1739458317cccd391ad3955e2bde8913edf6f95f9e65a8f034" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tracing" +version = "0.1.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" +dependencies = [ + "log", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e672c95779cf947c5311f83787af4fa8fffd12fb27e4993211a84bdfd9610f9c" +dependencies = [ + "once_cell", +] + +[[package]] +name = "typenum" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f" + [[package]] name = "unicode-ident" version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + +[[package]] +name = "url" +version = "2.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32f8b686cadd1473f4bd0117a5d28d36b1ade384ea9b5069a1c40aefed7fda60" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf16_iter" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8232dd3cdaed5356e0f716d285e4b40b932ac434100fe9b7e0e8e935b9e6246" + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + [[package]] name = "wasi" version = "0.13.3+wasi-0.2.2" @@ -313,6 +1483,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-targets" version = "0.52.6" @@ -386,6 +1565,42 @@ dependencies = [ "bitflags", ] +[[package]] +name = "write16" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1890f4022759daae28ed4fe62859b1236caebfc61ede2f63ed4e695f3f6d936" + +[[package]] +name = "writeable" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51" + +[[package]] +name = "yoke" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "120e6aef9aa629e3d4f52dc8cc43a015c7724194c97dfaf45180d2daf2b77f40" +dependencies = [ + "serde", + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + [[package]] name = "zerocopy" version = "0.8.23" @@ -405,3 +1620,74 @@ dependencies = [ "quote", "syn", ] + +[[package]] +name = "zerofrom" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50cc42e0333e05660c3587f3bf9d0478688e15d870fab3346451ce7f8c9fbea5" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zerovec" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa2b893d79df23bfb12d5461018d408ea19dfafe76c2c7ef6d4eba614f8ff079" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zstd" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91ee311a569c327171651566e07972200e76fcfe2242a4fa446149a3881c08a" +dependencies = [ + "zstd-safe", +] + +[[package]] +name = "zstd-safe" +version = "7.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3051792fbdc2e1e143244dc28c60f73d8470e93f3f9cbd0ead44da5ed802722" +dependencies = [ + "zstd-sys", +] + +[[package]] +name = "zstd-sys" +version = "2.0.14+zstd.1.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fb060d4926e4ac3a3ad15d864e99ceb5f343c6b34f5bd6d81ae6ed417311be5" +dependencies = [ + "cc", + "pkg-config", +] diff --git a/Cargo.toml b/Cargo.toml index 10428e9..bd128e2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,17 +8,22 @@ license = "MIT License" # Used by library macaddr = "1.0.1" log = "0.4" +actix-web = "4" # Used by server runtime fern = { optional = true, version = "0.7" } + [dev-dependencies] stopwatch = "0.0.7" rand = "0.9" [features] +default = ["client", "server"] bin-deps = ["fern"] +client = [] +server = [] [[bin]] name = "matchmaker_server" path = "src/main.rs" -required-features = [] \ No newline at end of file +required-features = ["server"] \ No newline at end of file diff --git a/docs/WEBAPI_V1.md b/docs/WEBAPI_V1.md new file mode 100644 index 0000000..e76f415 --- /dev/null +++ b/docs/WEBAPI_V1.md @@ -0,0 +1,49 @@ +# Web API Documentation - Draft + +## /api/info + +### GET + +```json +{ + "supportedVersions": [ + "" + ], + "partitions": [ + "us", + "uk" + // ... + ], + "heartbeatTimeoutDuration": 7 +} +``` + +## /api/query + +### POST + +```json +{ + // if this is unspecified/null, infer a default partition + "partition": "us", + "" + // Validated against a server-side maximum and minimum + "count": 7, + // Validated to prevent out-of-bounds issues. + // This allows reading a slice of the instances, + // allowing pagination. + "offset": 0 +} +``` + +## /api/connect + + + +## /api/heartbeat + +```json +{ + "token": +} +``` \ No newline at end of file diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..5b6364a --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,4 @@ +[toolchain] +channel = "1.81" +components = ["rustfmt"] +profile = "minimal" \ No newline at end of file diff --git a/shell.nix b/shell.nix index 58a9784..381b29c 100644 --- a/shell.nix +++ b/shell.nix @@ -1,4 +1,40 @@ { pkgs ? import {} }: -pkgs.mkShell { - buildInputs = [ pkgs.cargo pkgs.rustc ]; -} \ No newline at end of file + let + overrides = (builtins.fromTOML (builtins.readFile ./rust-toolchain.toml)); + libPath = with pkgs; lib.makeLibraryPath [ + # load external libraries that you need in your rust project here + ]; +in + pkgs.mkShell rec { + buildInputs = with pkgs; [ + clang + # Replace llvmPackages with llvmPackages_X, where X is the latest LLVM version (at the time of writing, 16) + llvmPackages.bintools + rustup + ]; + RUSTC_VERSION = overrides.toolchain.channel; + # https://github.com/rust-lang/rust-bindgen#environment-variables + LIBCLANG_PATH = pkgs.lib.makeLibraryPath [ pkgs.llvmPackages_latest.libclang.lib ]; + shellHook = '' + export PATH=$PATH:''${CARGO_HOME:-~/.cargo}/bin + export PATH=$PATH:''${RUSTUP_HOME:-~/.rustup}/toolchains/$RUSTC_VERSION-x86_64-unknown-linux-gnu/bin/ + ''; + # Add precompiled library to rustc search path + RUSTFLAGS = (builtins.map (a: ''-L ${a}/lib'') [ + # add libraries here (e.g. pkgs.libvmi) + ]); + LD_LIBRARY_PATH = libPath; + # Add glibc, clang, glib, and other headers to bindgen search path + BINDGEN_EXTRA_CLANG_ARGS = + # Includes normal include path + (builtins.map (a: ''-I"${a}/include"'') [ + # add dev libraries here (e.g. pkgs.libvmi.dev) + pkgs.glibc.dev + ]) + # Includes with special directory paths + ++ [ + ''-I"${pkgs.llvmPackages_latest.libclang.lib}/lib/clang/${pkgs.llvmPackages_latest.libclang.version}/include"'' + ''-I"${pkgs.glib.dev}/include/glib-2.0"'' + ''-I${pkgs.glib.out}/lib/glib-2.0/include/'' + ]; + } diff --git a/src/data/mod.rs b/src/data/mod.rs deleted file mode 100644 index 08c4ef1..0000000 --- a/src/data/mod.rs +++ /dev/null @@ -1,28 +0,0 @@ -use auth::AuthGuard; -use util::Address; - -pub mod util; -pub mod auth; - -pub enum DataStorageError { - AlreadyExists, - AntiSpam(String) -} - -pub trait DataStorageItem { - type Id; - type Address: Address; - fn id(&self) -> Self::Id; - fn address_info(&self) -> Self::Address; -} - -pub trait DataStorage: IntoIterator { - fn update_instance(&mut self, address: &impl Address, guard: Option) - -> Result; - - fn send_heartbeat(&mut self, address: &impl Address) - -> Result<(),DataStorageError>; - - fn peek_instance(&self, id: Item::Id); -} - diff --git a/src/data/util.rs b/src/data/util.rs deleted file mode 100644 index eb5e9ca..0000000 --- a/src/data/util.rs +++ /dev/null @@ -1,33 +0,0 @@ -use std::net::IpAddr; - -use macaddr::MacAddr; - -pub trait Address: PartialEq { - fn mac(&self) -> MacAddr; - fn ip(&self) -> IpAddr; -} - -#[derive(PartialEq, Debug)] -struct SimpleAddress { - mac: MacAddr, - ip: IpAddr -} - -impl SimpleAddress { - fn new(ip: IpAddr, mac: MacAddr) -> SimpleAddress { - return SimpleAddress { - ip, - mac - } - } -} - -impl Address for SimpleAddress { - fn mac(&self) -> MacAddr { - self.mac - } - - fn ip(&self) -> IpAddr { - self.ip - } -} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index e058441..2515f9b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,9 +1,15 @@ -pub mod data; +pub mod server; + +pub enum MatchmakerError { + AlreadyExists, + InternalError(String), + LimitReached(String), + Unauthorized, + AntiSpam(String), +} pub trait Matchmaker { fn run(&mut self); } -struct DefaultMatchmaker { - -} \ No newline at end of file +struct DefaultMatchmaker {} diff --git a/src/main.rs b/src/main.rs index 8a55e80..f328e4d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1 @@ -fn main() { - -} \ No newline at end of file +fn main() {} diff --git a/src/server/access.rs b/src/server/access.rs new file mode 100644 index 0000000..93e808e --- /dev/null +++ b/src/server/access.rs @@ -0,0 +1,33 @@ +/* -------------------------------------------------------------------------- */ +/* Interfaces */ +/* -------------------------------------------------------------------------- */ + +use std::collections::HashMap; + +use super::util::Address; + +pub struct AccessInfo { + address: Address, +} + +pub trait AccessGuard { + fn check(&self, info: &AccessInfo); +} + +pub enum AccessAction { + Allow, + Block, +} + +/* -------------------------------------------------------------------------- */ +/* Rate Limiting */ +/* -------------------------------------------------------------------------- */ + +struct RateLimitAccessor {} + +pub struct RateLimitAccessGuard { + max_read: i32, + max_write: i32, + max_accessors: i32, + accessors: HashMap, +} diff --git a/src/data/auth.rs b/src/server/auth.rs similarity index 96% rename from src/data/auth.rs rename to src/server/auth.rs index d4e2908..333b63d 100644 --- a/src/data/auth.rs +++ b/src/server/auth.rs @@ -185,7 +185,7 @@ mod tests { #[derive(Debug, Clone)] pub struct CodeAuthKey { - key: u64 + key: u64, } impl CodeAuthKey { @@ -197,7 +197,7 @@ impl CodeAuthKey { pub fn new(code: &T) -> CodeAuthKey { CodeAuthKey { - key: Self::_generate_key(code) + key: Self::_generate_key(code), } } } @@ -211,20 +211,18 @@ impl PartialEq for CodeAuthKey { } pub struct CodeAuthGuard { - reference_key: CodeAuthKey + reference_key: CodeAuthKey, } impl CodeAuthGuard { fn new(key: CodeAuthKey) -> Self { - Self { - reference_key: key - } + Self { reference_key: key } } } impl AuthGuard for CodeAuthGuard { type Key = CodeAuthKey; - + fn verify(&self, key: &Self::Key) -> Result { Ok(self.reference_key == *key) } @@ -233,15 +231,14 @@ impl AuthGuard for CodeAuthGuard { /* ------------------------------- Unit Tests ------------------------------- */ #[cfg(test)] mod code_authguard_tests { + use super::*; use rand::{distr::Alphanumeric, prelude::*}; use stopwatch::Stopwatch; - use super::*; fn _create_rng_string() -> String { let mut rng = rand::rng(); let count = rng.random_range(5..100); - rng - .sample_iter(Alphanumeric) + rng.sample_iter(Alphanumeric) .take(count) .map(char::from) .collect() @@ -251,7 +248,7 @@ mod code_authguard_tests { fn basic_use() { let code_a = "reference_a"; let code_b = "reference_b"; - + // Using the keys directly let key_a = CodeAuthKey::new(&code_a); let key_b = CodeAuthKey::new(&code_b); @@ -259,7 +256,7 @@ mod code_authguard_tests { assert_eq!(key_a, key_a); assert_eq!(key_b, key_b); assert_ne!(key_a, key_b); - + // Using the CodeAuthGuard let guard = CodeAuthGuard::new(key_a.clone()); let mut result_verify = guard.verify(&key_a); @@ -274,7 +271,7 @@ mod code_authguard_tests { #[test] fn basic_benchmark_compare_speed() { // TODO: Look into better ways of performing benchmarks. - + // Some setup let key_global = CodeAuthKey::new("reference"); let count = 100000; @@ -300,9 +297,9 @@ mod code_authguard_tests { let key_local = CodeAuthKey::new(&i); assert_ne!(key_local, key_global); } - + sw.stop(); println!("Incorrect key compare perf: {}ms", sw.elapsed_ms()); } -} \ No newline at end of file +} diff --git a/src/server/mod.rs b/src/server/mod.rs new file mode 100644 index 0000000..99b34ad --- /dev/null +++ b/src/server/mod.rs @@ -0,0 +1,25 @@ +use auth::AuthGuard; +use util::Address; + +use crate::MatchmakerError; + +pub mod access; +pub mod auth; +pub mod storage; +pub mod util; + +pub trait DataStorageItem { + type Id; + fn id(&self) -> Self::Id; + fn address_info(&self) -> Address; +} + +pub trait DataStorage: IntoIterator { + fn reserve_instance( + &mut self, + address: &Address, + guard: Option, + ) -> Result; + + fn remove_instance(&mut self, id: Item::Id); +} diff --git a/src/server/storage.rs b/src/server/storage.rs new file mode 100644 index 0000000..c71d8b9 --- /dev/null +++ b/src/server/storage.rs @@ -0,0 +1,375 @@ +use std::{ + collections::{BTreeMap, HashMap}, iter::Map, net::IpAddr, sync::RwLock +}; + +use super::util::Address; + +/* -------------------------------------------------------------------------- */ +/* Instance Storage */ +/* -------------------------------------------------------------------------- */ + +#[derive(Debug)] +pub enum InstanceStorageError { + NotFound, + Full +} + +pub trait Instance { + type Id; + fn id(&self) -> Self::Id; + fn ip(&self) -> IpAddr; +} + +pub trait InstanceStorage: IntoIterator { + // Create + + // Request + fn get_by_address(&self, address: &Address) -> Result<&Item, InstanceStorageError>; + fn get_by_address_mut( + &mut self, + address: &Address, + ) -> Result<&mut Item, InstanceStorageError>; + fn get_by_id(&self, id: Item::Id) -> Result<&Item, InstanceStorageError>; + fn get_by_id_mut(&mut self, id: Item::Id) -> Result<&mut Item, InstanceStorageError>; + // Delete + fn remove_by_address(&mut self, address: &Address) -> Result<(), InstanceStorageError>; + fn remove_by_id(&mut self, id: Item::Id) -> Result<(), InstanceStorageError>; +} + +/* ------------------------- Default Implementation ------------------------- */ +pub struct BasicInstance { + id: u32, + ip: IpAddr +} + +impl Instance for BasicInstance { + type Id = u32; + fn id(&self) -> Self::Id { + self.id + } + fn ip(&self) -> IpAddr { + self.ip + } +} + +pub struct BasicInstanceStorage { + max_instances: u32, + instances: BTreeMap, +} + +impl BasicInstanceStorage { + fn new(max_instances: u32) -> Self { + Self { + instances: BTreeMap::new(), + max_instances + } + } +} + +impl InstanceStorage for BasicInstanceStorage { + fn get_by_address(&self, address: &Address) -> Result<&BasicInstance, InstanceStorageError> { + match self.instances.get(address) { + Some(v) => { + Ok(v) + }, + None => Err(InstanceStorageError::NotFound) + } + } + + fn get_by_address_mut( + &mut self, + address: &Address, + ) -> Result<&mut BasicInstance, InstanceStorageError> { + match self.instances.get_mut(address) { + Some(v) => { + Ok(v) + }, + None => Err(InstanceStorageError::NotFound) + } + } + + fn get_by_id(&self, id: ::Id) -> Result<&BasicInstance, InstanceStorageError> { + let search_result = self.instances + .iter() + .find(|v| v.1.id == id); + match search_result { + Some(v) => { + Ok(v.1) + }, + None => { + Err(InstanceStorageError::NotFound) + } + } + } + + fn get_by_id_mut(&mut self, id: ::Id) -> Result<&mut BasicInstance, InstanceStorageError> { + let search_result = self.instances + .iter_mut() + .find(|v| v.1.id == id); + match search_result { + Some(v) => { + Ok(v.1) + }, + None => { + Err(InstanceStorageError::NotFound) + } + } + } + + fn remove_by_address(&mut self, address: &Address) -> Result<(), InstanceStorageError> { + match self.instances.remove(address) { + Some(_) => { + Ok(()) + }, + None => Err(InstanceStorageError::NotFound) + } + } + + fn remove_by_id(&mut self, id: ::Id) -> Result<(), InstanceStorageError> { + let original_len = self.instances.len(); + self.instances.retain(|_, v| v.id != id); + + if self.instances.len() == original_len { + return Err(InstanceStorageError::NotFound); + } + + Ok(()) + } +} + +impl IntoIterator for BasicInstanceStorage { + type Item = BasicInstance; + type IntoIter = std::vec::IntoIter; + + fn into_iter(self) -> Self::IntoIter { + self.instances + .into_iter() + .map(|(_address, instance)| instance) + .collect::>() + .into_iter() + } +} + +#[cfg(test)] +mod basic_instance_test { + use std::net::{IpAddr, Ipv4Addr}; + + use macaddr::{MacAddr, MacAddr6}; + + use super::*; + + fn _create_sample_address(id: u8) -> Address { + let ip: IpAddr = IpAddr::V4(Ipv4Addr::new(127, 0, 0, id)); + let mac: MacAddr = MacAddr::V6(MacAddr6::new(id, id, id, id, id, id)); + + Address::new(ip, mac) + } + + #[test] + fn test_get_by_address_found() { + let mut storage = BasicInstanceStorage::new(10); + let instance = BasicInstance { id: 42, ip: IpAddr::V4(Ipv4Addr::LOCALHOST) }; + let addr = _create_sample_address(1); + storage.instances.insert(addr.clone(), instance); + let fetched = storage.get_by_address(&addr).unwrap(); + assert_eq!(fetched.id, 42); + } + + #[test] + fn test_get_by_address_not_found() { + let storage = BasicInstanceStorage::new(10); + let addr = _create_sample_address(1); + let result = storage.get_by_address(&addr); + assert!(matches!(result, Err(InstanceStorageError::NotFound))); + } + + #[test] + fn test_get_by_address_mut() { + let mut storage = BasicInstanceStorage::new(10); + let addr = _create_sample_address(1); + let instance = BasicInstance { id: 42, ip: IpAddr::V4(Ipv4Addr::LOCALHOST) }; + storage.instances.insert(addr.clone(), instance); + { + let fetched_mut = storage.get_by_address_mut(&addr).unwrap(); + fetched_mut.id = 100; + } + let fetched = storage.get_by_address(&addr).unwrap(); + assert_eq!(fetched.id, 100); + } + + #[test] + fn test_get_by_id_found() { + let mut storage = BasicInstanceStorage::new(10); + let addr = _create_sample_address(1); + let instance = BasicInstance { id: 42, ip: IpAddr::V4(Ipv4Addr::LOCALHOST) }; + storage.instances.insert(addr, instance); + let fetched = storage.get_by_id(42).unwrap(); + assert_eq!(fetched.id, 42); + } + + #[test] + fn test_get_by_id_not_found() { + let storage = BasicInstanceStorage::new(10); + let result = storage.get_by_id(42); + assert!(matches!(result, Err(InstanceStorageError::NotFound))); + } + + #[test] + fn test_get_by_id_mut() { + let mut storage = BasicInstanceStorage::new(10); + let addr = _create_sample_address(1); + let instance = BasicInstance { id: 42, ip: IpAddr::V4(Ipv4Addr::LOCALHOST) }; + storage.instances.insert(addr, instance); + { + let fetched_mut = storage.get_by_id_mut(42); + assert!(fetched_mut.is_ok()); + let fetched_mut = fetched_mut.unwrap(); + fetched_mut.id = 99; + } + let fetched = storage.get_by_id(42); + assert!(fetched.is_err()); + } + + #[test] + fn test_remove_by_address() { + let mut storage = BasicInstanceStorage::new(10); + let addr = _create_sample_address(1); + storage.instances.insert(addr.clone(), BasicInstance { id: 42, ip: IpAddr::V4(Ipv4Addr::LOCALHOST) }); + assert!(storage.remove_by_address(&addr).is_ok()); + assert!(storage.instances.is_empty()); + } + + #[test] + fn test_remove_by_address_not_found() { + let mut storage = BasicInstanceStorage::new(10); + let addr = _create_sample_address(1); + let result = storage.remove_by_address(&addr); + assert!(matches!(result, Err(InstanceStorageError::NotFound))); + } + + #[test] + fn test_remove_by_id() { + let mut storage = BasicInstanceStorage::new(10); + let addr = _create_sample_address(1); + storage.instances.insert(addr, BasicInstance { id: 42, ip: IpAddr::V4(Ipv4Addr::LOCALHOST) }); + assert!(storage.remove_by_id(42).is_ok()); + assert!(storage.instances.is_empty()); + } + + #[test] + fn test_remove_by_id_not_found() { + let mut storage = BasicInstanceStorage::new(10); + let result = storage.remove_by_id(42); + assert!(matches!(result, Err(InstanceStorageError::NotFound))); + } + + #[test] + fn test_into_iterator() { + let mut storage = BasicInstanceStorage::new(10); + storage.instances.insert(_create_sample_address(1), BasicInstance { id: 42, ip: IpAddr::V4(Ipv4Addr::LOCALHOST) }); + storage.instances.insert(_create_sample_address(2), BasicInstance { id: 43, ip: IpAddr::V4(Ipv4Addr::LOCALHOST) }); + let instances: Vec<_> = storage.into_iter().collect(); + assert_eq!(instances.len(), 2); + let ids: Vec = instances.into_iter().map(|inst| inst.id).collect(); + assert!(ids.contains(&42)); + assert!(ids.contains(&43)); + } +} + +/* -------------------------------------------------------------------------- */ +/* Attribute System */ +/* -------------------------------------------------------------------------- */ + +// TODO: Optimize the heck out of this - This is effectively a placeholder +// It will likely be *very* space inefficient. + +/* -------------------------------- Metadata -------------------------------- */ +#[repr(u8)] +#[derive(PartialEq)] +enum AttributeType { + Float, + Integer, + Boolean, + String, +} + +enum AttributeValue { + Float(f32), + Integer(i32), + Boolean(bool), + String(String), +} + +impl AttributeValue { + fn get_type(&self) -> AttributeType { + match self { + Float => AttributeType::Float, + Integer => AttributeType::Integer, + Boolean => AttributeType::Boolean, + String => AttributeType::String, + } + } +} + +enum AttributeError { + InvalidType(AttributeType), + InvalidKey(String) +} + +/* --------------------------------- Schema --------------------------------- */ + +// TODO: Builder pattern to create this +pub struct AttributeSchema { + attribute_schema: Map, +} + +pub struct AttributeSchemaElement { + default_type_and_value: AttributeValue, +} + +/* ---------------------------------- List ---------------------------------- */ + +struct AttributeListElement { + value: AttributeValue, +} + +pub struct AttributeList<'a> { + schema: &'a AttributeSchema, + data: RwLock>, +} + +impl<'a> AttributeList<'a> { + fn new(schema: &'a AttributeSchema) -> Self { + Self { + schema, + // TODO: Populate with initial values + data: RwLock::new(HashMap::new()), + } + } + + fn set_attribute(&mut self, key: &str, value: AttributeValue) -> Result<(), AttributeError> { + // ! Naive unwrap is present + let mut write = self.data.write().unwrap(); + { + let element_read = &write[key]; + if value.get_type() != element_read.value.get_type() { + return Err(AttributeError::InvalidType(value.get_type())); + } + } + { + // ! Double query + let element = write.get_mut(key); + match element { + Some(v) => { + v.value = value; + }, + None => { + // TODO: Verify that this is the best thing to do + return Err(AttributeError::InvalidKey(key.to_string())) + } + } + } + + Ok(()) + } +} diff --git a/src/server/util.rs b/src/server/util.rs new file mode 100644 index 0000000..ac6d7e9 --- /dev/null +++ b/src/server/util.rs @@ -0,0 +1,33 @@ +use std::net::IpAddr; + +use macaddr::MacAddr; + +#[derive(Debug, Hash, PartialOrd, Ord, Clone)] +pub struct Address { + mac: MacAddr, + ip: IpAddr, +} + +impl Address { + pub fn new(ip: IpAddr, mac: MacAddr) -> Self { + return Self { ip, mac }; + } + + pub fn mac(&self) -> MacAddr { + self.mac + } + + pub fn ip(&self) -> IpAddr { + self.ip + } +} + +impl PartialEq for Address { + fn eq(&self, other: &Self) -> bool { + self.ip == other.ip + } +} + +impl Eq for Address { + +} \ No newline at end of file