A pit full of rusty nails

Initial commit

sachy.dev 1962c0c7

+7664
+4
.gitignore
··· 1 + /target 2 + /input 3 + .cargo/config.toml 4 + /configuration
+133
CODE_OF_CONDUCT.md
··· 1 + 2 + # Contributor Covenant Code of Conduct 3 + 4 + ## Our Pledge 5 + 6 + We as members, contributors, and leaders pledge to make participation in our 7 + community a harassment-free experience for everyone, regardless of age, body 8 + size, visible or invisible disability, ethnicity, sex characteristics, gender 9 + identity and expression, level of experience, education, socio-economic status, 10 + nationality, personal appearance, race, caste, color, religion, or sexual 11 + identity and orientation. 12 + 13 + We pledge to act and interact in ways that contribute to an open, welcoming, 14 + diverse, inclusive, and healthy community. 15 + 16 + ## Our Standards 17 + 18 + Examples of behavior that contributes to a positive environment for our 19 + community include: 20 + 21 + * Demonstrating empathy and kindness toward other people 22 + * Being respectful of differing opinions, viewpoints, and experiences 23 + * Giving and gracefully accepting constructive feedback 24 + * Accepting responsibility and apologizing to those affected by our mistakes, 25 + and learning from the experience 26 + * Focusing on what is best not just for us as individuals, but for the overall 27 + community 28 + 29 + Examples of unacceptable behavior include: 30 + 31 + * The use of sexualized language or imagery, and sexual attention or advances of 32 + any kind 33 + * Trolling, insulting or derogatory comments, and personal or political attacks 34 + * Public or private harassment 35 + * Publishing others' private information, such as a physical or email address, 36 + without their explicit permission 37 + * Other conduct which could reasonably be considered inappropriate in a 38 + professional setting 39 + 40 + ## Enforcement Responsibilities 41 + 42 + Community leaders are responsible for clarifying and enforcing our standards of 43 + acceptable behavior and will take appropriate and fair corrective action in 44 + response to any behavior that they deem inappropriate, threatening, offensive, 45 + or harmful. 46 + 47 + Community leaders have the right and responsibility to remove, edit, or reject 48 + comments, commits, code, wiki edits, issues, and other contributions that are 49 + not aligned to this Code of Conduct, and will communicate reasons for moderation 50 + decisions when appropriate. 51 + 52 + ## Scope 53 + 54 + This Code of Conduct applies within all community spaces, and also applies when 55 + an individual is officially representing the community in public spaces. 56 + Examples of representing our community include using an official e-mail address, 57 + posting via an official social media account, or acting as an appointed 58 + representative at an online or offline event. 59 + 60 + ## Enforcement 61 + 62 + Instances of abusive, harassing, or otherwise unacceptable behavior may be 63 + reported to the community leaders responsible for enforcement over email at 64 + <sachymetsu@tutamail.com>. 65 + All complaints will be reviewed and investigated promptly and fairly. 66 + 67 + All community leaders are obligated to respect the privacy and security of the 68 + reporter of any incident. 69 + 70 + ## Enforcement Guidelines 71 + 72 + Community leaders will follow these Community Impact Guidelines in determining 73 + the consequences for any action they deem in violation of this Code of Conduct: 74 + 75 + ### 1. Correction 76 + 77 + **Community Impact**: Use of inappropriate language or other behavior deemed 78 + unprofessional or unwelcome in the community. 79 + 80 + **Consequence**: A private, written warning from community leaders, providing 81 + clarity around the nature of the violation and an explanation of why the 82 + behavior was inappropriate. A public apology may be requested. 83 + 84 + ### 2. Warning 85 + 86 + **Community Impact**: A violation through a single incident or series of 87 + actions. 88 + 89 + **Consequence**: A warning with consequences for continued behavior. No 90 + interaction with the people involved, including unsolicited interaction with 91 + those enforcing the Code of Conduct, for a specified period of time. This 92 + includes avoiding interactions in community spaces as well as external channels 93 + like social media. Violating these terms may lead to a temporary or permanent 94 + ban. 95 + 96 + ### 3. Temporary Ban 97 + 98 + **Community Impact**: A serious violation of community standards, including 99 + sustained inappropriate behavior. 100 + 101 + **Consequence**: A temporary ban from any sort of interaction or public 102 + communication with the community for a specified period of time. No public or 103 + private interaction with the people involved, including unsolicited interaction 104 + with those enforcing the Code of Conduct, is allowed during this period. 105 + Violating these terms may lead to a permanent ban. 106 + 107 + ### 4. Permanent Ban 108 + 109 + **Community Impact**: Demonstrating a pattern of violation of community 110 + standards, including sustained inappropriate behavior, harassment of an 111 + individual, or aggression toward or disparagement of classes of individuals. 112 + 113 + **Consequence**: A permanent ban from any sort of public interaction within the 114 + community. 115 + 116 + ## Attribution 117 + 118 + This Code of Conduct is adapted from the [Contributor Covenant][homepage], 119 + version 2.1, available at 120 + [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. 121 + 122 + Community Impact Guidelines were inspired by 123 + [Mozilla's code of conduct enforcement ladder][Mozilla CoC]. 124 + 125 + For answers to common questions about this code of conduct, see the FAQ at 126 + [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at 127 + [https://www.contributor-covenant.org/translations][translations]. 128 + 129 + [homepage]: https://www.contributor-covenant.org 130 + [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html 131 + [Mozilla CoC]: https://github.com/mozilla/diversity 132 + [FAQ]: https://www.contributor-covenant.org/faq 133 + [translations]: https://www.contributor-covenant.org/translations
+71
CONTRIBUTING.md
··· 1 + # Contributing to Nailpit 2 + 3 + Nailpit is software written by humans *for* humans. Or at least, software written by humans to deter (misbehaving) machines. As such, all contributions should not be using AI in any form. There is no pressure to "ship it" here, no investor baiting, no tech hyping. This project is a temple to the art and joy of coding, and thus should be enjoyed for what it is, not delegated to an unthinking machine. There is no expectation of perfection, only for understanding and for doing one's best. 4 + 5 + That's the starting point: *Be Human* 6 + 7 + From there, contributing is as simple as creating a fork of this project, get it to compile on your local environment, creating a branch, then publishing the branch once you are done. Create a pull request (PR) and then hope for the best! 8 + 9 + To contribute, there is the expectation that you are at least familiar with: 10 + 11 + - git 12 + - Rust and its toolchains, cargo, etc 13 + - HTML and web stuff. 14 + 15 + If the above are not things you are familiar with, then please take the time to learn them. There are resources for this. 16 + 17 + ## Implementing a feature/improvement 18 + 19 + Before starting work on a feature, check if there isn't an open issue or PR already. If there's something on the roadmap that hasn't been done, or if there isn't and you feel it would be a good addition, feel free to take up on that task. First, create a specific issue for that feature and try to outline the following: 20 + 21 + - Feature to be worked on, explaining why it is needed 22 + - (Optional) Outline the proposed implementation, or implementations if soliciting wider feedback. 23 + - If it is a large feature, outline smaller steps for completing the work. 24 + 25 + If the issue is reviewed/discussed and the consensus is to go forward, then feel free to create a PR. You can also create draft PRs if you wish to take more exploratory work upfront in order to get more information on a given approach. Such work should still be pinned to an issue in order to track progress. 26 + 27 + PR's should have a clear and concise title outling the feature. The PR description should then provide an explanation of the feature implementation, and also how to test it, as well as any breaking changes. If the PR implements a feature completely, ensure there is a link back to the issue stating "Closes #issue number" 28 + 29 + Once the PR is reviewed and it passes all CI checks, it will get merged and the feature issue updated/closed. 30 + 31 + ## Submitting bug fixes 32 + 33 + If a bug is found, create an issue detailing the following: 34 + 35 + - Nailpit version (branch, commit, etc) 36 + - Hardware/OS versions (example, Raspberry Pi 5 8GB, Debian arm64) 37 + - Situation which bug was found 38 + - Expected behaviour 39 + - Actual (buggy) behaviour 40 + 41 + Include a minimal reproducible example of the code for showcasing the bug if it involves library/crate code, else include the configuration that triggers the bug if it is for the application itself. 42 + 43 + Ensure the bug issue is created first before submitting a PR to fix the bug. This is to help track the issue and also any impact. The PR should reference the original issue with "Closes #issue number". 44 + 45 + ## Documentation 46 + 47 + All submitted code should have *some* documentation in place. It does not need to be extensive, but it should explain and detail the implementation, how to use new APIs/methods, etc. More extensive documentation can be added later, but such efforts should have a dedicated issue to track the progress. All documentation should not be written/generated by LLMs. Please take the time to write it yourself. Any poor english/grammar can always be fixed through code review. It's more important to have true understanding of what you are writing about and being able to communicate very intricate technical details, nuances and concepts that LLMs are utterly inadequate with. 48 + 49 + ## Unsafe code 50 + 51 + If you are not completely comfortable writing `unsafe` code, then don't. Stick to safe rust. If you are comfortable with writing `unsafe` rust, stick to safe rust. Break out the `unsafe` only when there is reason for it, and be prepared to document that reasoning extensively. It is important to get it correct, both for testing with Miri, but to ensure any future contributors can come in and understand what can be touched and what shouldn't. 52 + 53 + If in the future, Rust comes out with a feature that allows existing `unsafe` code to be written in safe rust without perf regressions, then that code will be refactored to safe rust. 54 + 55 + The idea here is we only employ `unsafe` code where necessary. Make use of tools like Miri to check any unsafe code, and be thorough with tests to ensure all corner cases are caught. 56 + 57 + ## Where to go from here? 58 + 59 + Still interested in contributing? Check out the [roadmap here](https://tangled.org/sachy.dev/nailpit) if you need a high-level view of what the goals are and what needs to be worked on. That should give you a general idea of what the state of the project is and what to take on in terms of tasks. 60 + 61 + ## But why no AI? 62 + 63 + As the maintainer of this project, I expect any and all contributors to truly understand the code they are contributing. What does it do? What are the pros of the approach? What are the cons and trade-offs? I am not expecting super high quality code, but I am expecting code that has been crafted with full understanding of that implementation. This has benefits for both myself a maintainer and for you as a contributor: 64 + 65 + 1. Code that is understood is more easily maintained. Knowing what are the edge-cases helps narrow down sources of bugs and providing suitable fixes, and also allows for future work to be planned around the provided code. 66 + 2. Code that is understood is less likely to need to be constantly refactored, reducing churn and tech-debt. 67 + 3. Code that is understood is easier to write accurate documentation for, and provide examples for. And during code review, you'll be able to explain what you've done more confidently. 68 + 69 + By using an AI/LLM to generate the code, you are trading this understanding for speed and convenience. But for Open Source Software, what matters more is providing code that others can understand and maintain. You might contribute a feature, but that feature will then need to be maintained by myself and others in the future, so ensuring everything is clear and well documented is of vital importance. If you can't code a feature without the assistance of an AI tool, then you can't code with any level of understanding. But it isn't hard to do so! It just might take longer (and you might learn a few things in the process by doing so). 70 + 71 + Other reasons for not wanting AI/LLM generated contributions is for legal reasons (questions regarding copyright & licensing violations on data which these models are trained on), and ethical reasons (such as the power consumption and exorbitant water requirements these models require). Best to avoid all that by just not accepting AI/LLM generated contributions.
+2262
Cargo.lock
··· 1 + # This file is automatically @generated by Cargo. 2 + # It is not intended for manual editing. 3 + version = 4 4 + 5 + [[package]] 6 + name = "addr2line" 7 + version = "0.25.1" 8 + source = "registry+https://github.com/rust-lang/crates.io-index" 9 + checksum = "1b5d307320b3181d6d7954e663bd7c774a838b8220fe0593c86d9fb09f498b4b" 10 + dependencies = [ 11 + "gimli", 12 + ] 13 + 14 + [[package]] 15 + name = "adler2" 16 + version = "2.0.1" 17 + source = "registry+https://github.com/rust-lang/crates.io-index" 18 + checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" 19 + 20 + [[package]] 21 + name = "aho-corasick" 22 + version = "1.1.4" 23 + source = "registry+https://github.com/rust-lang/crates.io-index" 24 + checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" 25 + dependencies = [ 26 + "memchr", 27 + ] 28 + 29 + [[package]] 30 + name = "anyhow" 31 + version = "1.0.100" 32 + source = "registry+https://github.com/rust-lang/crates.io-index" 33 + checksum = "a23eb6b1614318a8071c9b2521f36b424b2c83db5eb3a0fead4a6c0809af6e61" 34 + 35 + [[package]] 36 + name = "async-trait" 37 + version = "0.1.89" 38 + source = "registry+https://github.com/rust-lang/crates.io-index" 39 + checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb" 40 + dependencies = [ 41 + "proc-macro2", 42 + "quote", 43 + "syn", 44 + ] 45 + 46 + [[package]] 47 + name = "atomic-waker" 48 + version = "1.1.2" 49 + source = "registry+https://github.com/rust-lang/crates.io-index" 50 + checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" 51 + 52 + [[package]] 53 + name = "autocfg" 54 + version = "1.5.0" 55 + source = "registry+https://github.com/rust-lang/crates.io-index" 56 + checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" 57 + 58 + [[package]] 59 + name = "axum" 60 + version = "0.8.7" 61 + source = "registry+https://github.com/rust-lang/crates.io-index" 62 + checksum = "5b098575ebe77cb6d14fc7f32749631a6e44edbef6b796f89b020e99ba20d425" 63 + dependencies = [ 64 + "axum-core", 65 + "axum-macros", 66 + "bytes", 67 + "futures-util", 68 + "http", 69 + "http-body", 70 + "http-body-util", 71 + "hyper", 72 + "hyper-util", 73 + "itoa", 74 + "matchit", 75 + "memchr", 76 + "mime", 77 + "percent-encoding", 78 + "pin-project-lite", 79 + "serde_core", 80 + "sync_wrapper", 81 + "tower", 82 + "tower-layer", 83 + "tower-service", 84 + "tracing", 85 + ] 86 + 87 + [[package]] 88 + name = "axum-core" 89 + version = "0.5.5" 90 + source = "registry+https://github.com/rust-lang/crates.io-index" 91 + checksum = "59446ce19cd142f8833f856eb31f3eb097812d1479ab224f54d72428ca21ea22" 92 + dependencies = [ 93 + "bytes", 94 + "futures-core", 95 + "http", 96 + "http-body", 97 + "http-body-util", 98 + "mime", 99 + "pin-project-lite", 100 + "sync_wrapper", 101 + "tower-layer", 102 + "tower-service", 103 + "tracing", 104 + ] 105 + 106 + [[package]] 107 + name = "axum-extra" 108 + version = "0.12.2" 109 + source = "registry+https://github.com/rust-lang/crates.io-index" 110 + checksum = "dbfe9f610fe4e99cf0cfcd03ccf8c63c28c616fe714d80475ef731f3b13dd21b" 111 + dependencies = [ 112 + "axum", 113 + "axum-core", 114 + "bytes", 115 + "futures-core", 116 + "futures-util", 117 + "http", 118 + "http-body", 119 + "http-body-util", 120 + "mime", 121 + "pin-project-lite", 122 + "tower-layer", 123 + "tower-service", 124 + "tracing", 125 + ] 126 + 127 + [[package]] 128 + name = "axum-macros" 129 + version = "0.5.0" 130 + source = "registry+https://github.com/rust-lang/crates.io-index" 131 + checksum = "604fde5e028fea851ce1d8570bbdc034bec850d157f7569d10f347d06808c05c" 132 + dependencies = [ 133 + "proc-macro2", 134 + "quote", 135 + "syn", 136 + ] 137 + 138 + [[package]] 139 + name = "backtrace" 140 + version = "0.3.76" 141 + source = "registry+https://github.com/rust-lang/crates.io-index" 142 + checksum = "bb531853791a215d7c62a30daf0dde835f381ab5de4589cfe7c649d2cbe92bd6" 143 + dependencies = [ 144 + "addr2line", 145 + "cfg-if", 146 + "libc", 147 + "miniz_oxide", 148 + "object", 149 + "rustc-demangle", 150 + "windows-link 0.2.1", 151 + ] 152 + 153 + [[package]] 154 + name = "base64" 155 + version = "0.22.1" 156 + source = "registry+https://github.com/rust-lang/crates.io-index" 157 + checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" 158 + 159 + [[package]] 160 + name = "bitflags" 161 + version = "2.10.0" 162 + source = "registry+https://github.com/rust-lang/crates.io-index" 163 + checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" 164 + 165 + [[package]] 166 + name = "bumpalo" 167 + version = "3.19.0" 168 + source = "registry+https://github.com/rust-lang/crates.io-index" 169 + checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43" 170 + 171 + [[package]] 172 + name = "bytes" 173 + version = "1.11.0" 174 + source = "registry+https://github.com/rust-lang/crates.io-index" 175 + checksum = "b35204fbdc0b3f4446b89fc1ac2cf84a8a68971995d0bf2e925ec7cd960f9cb3" 176 + 177 + [[package]] 178 + name = "cc" 179 + version = "1.2.48" 180 + source = "registry+https://github.com/rust-lang/crates.io-index" 181 + checksum = "c481bdbf0ed3b892f6f806287d72acd515b352a4ec27a208489b8c1bc839633a" 182 + dependencies = [ 183 + "find-msvc-tools", 184 + "jobserver", 185 + "libc", 186 + "shlex", 187 + ] 188 + 189 + [[package]] 190 + name = "cfg-if" 191 + version = "1.0.4" 192 + source = "registry+https://github.com/rust-lang/crates.io-index" 193 + checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" 194 + 195 + [[package]] 196 + name = "color-eyre" 197 + version = "0.6.5" 198 + source = "registry+https://github.com/rust-lang/crates.io-index" 199 + checksum = "e5920befb47832a6d61ee3a3a846565cfa39b331331e68a3b1d1116630f2f26d" 200 + dependencies = [ 201 + "backtrace", 202 + "eyre", 203 + "indenter", 204 + "once_cell", 205 + "owo-colors", 206 + ] 207 + 208 + [[package]] 209 + name = "config" 210 + version = "0.15.19" 211 + source = "registry+https://github.com/rust-lang/crates.io-index" 212 + checksum = "b30fa8254caad766fc03cb0ccae691e14bf3bd72bfff27f72802ce729551b3d6" 213 + dependencies = [ 214 + "pathdiff", 215 + "serde_core", 216 + "toml", 217 + "winnow", 218 + ] 219 + 220 + [[package]] 221 + name = "cordyceps" 222 + version = "0.3.4" 223 + source = "registry+https://github.com/rust-lang/crates.io-index" 224 + checksum = "688d7fbb8092b8de775ef2536f36c8c31f2bc4006ece2e8d8ad2d17d00ce0a2a" 225 + dependencies = [ 226 + "loom", 227 + "tracing", 228 + ] 229 + 230 + [[package]] 231 + name = "core_affinity" 232 + version = "0.8.3" 233 + source = "registry+https://github.com/rust-lang/crates.io-index" 234 + checksum = "a034b3a7b624016c6e13f5df875747cc25f884156aad2abd12b6c46797971342" 235 + dependencies = [ 236 + "libc", 237 + "num_cpus", 238 + "winapi", 239 + ] 240 + 241 + [[package]] 242 + name = "diatomic-waker" 243 + version = "0.2.3" 244 + source = "registry+https://github.com/rust-lang/crates.io-index" 245 + checksum = "ab03c107fafeb3ee9f5925686dbb7a73bc76e3932abb0d2b365cb64b169cf04c" 246 + 247 + [[package]] 248 + name = "either" 249 + version = "1.15.0" 250 + source = "registry+https://github.com/rust-lang/crates.io-index" 251 + checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" 252 + 253 + [[package]] 254 + name = "equivalent" 255 + version = "1.0.2" 256 + source = "registry+https://github.com/rust-lang/crates.io-index" 257 + checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" 258 + 259 + [[package]] 260 + name = "eyre" 261 + version = "0.6.12" 262 + source = "registry+https://github.com/rust-lang/crates.io-index" 263 + checksum = "7cd915d99f24784cdc19fd37ef22b97e3ff0ae756c7e492e9fbfe897d61e2aec" 264 + dependencies = [ 265 + "indenter", 266 + "once_cell", 267 + ] 268 + 269 + [[package]] 270 + name = "fastrand" 271 + version = "2.3.0" 272 + source = "registry+https://github.com/rust-lang/crates.io-index" 273 + checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" 274 + 275 + [[package]] 276 + name = "find-msvc-tools" 277 + version = "0.1.5" 278 + source = "registry+https://github.com/rust-lang/crates.io-index" 279 + checksum = "3a3076410a55c90011c298b04d0cfa770b00fa04e1e3c97d3f6c9de105a03844" 280 + 281 + [[package]] 282 + name = "fixedbitset" 283 + version = "0.5.7" 284 + source = "registry+https://github.com/rust-lang/crates.io-index" 285 + checksum = "1d674e81391d1e1ab681a28d99df07927c6d4aa5b027d7da16ba32d1d21ecd99" 286 + 287 + [[package]] 288 + name = "fnv" 289 + version = "1.0.7" 290 + source = "registry+https://github.com/rust-lang/crates.io-index" 291 + checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" 292 + 293 + [[package]] 294 + name = "futures" 295 + version = "0.3.31" 296 + source = "registry+https://github.com/rust-lang/crates.io-index" 297 + checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876" 298 + dependencies = [ 299 + "futures-channel", 300 + "futures-core", 301 + "futures-executor", 302 + "futures-io", 303 + "futures-sink", 304 + "futures-task", 305 + "futures-util", 306 + ] 307 + 308 + [[package]] 309 + name = "futures-buffered" 310 + version = "0.2.12" 311 + source = "registry+https://github.com/rust-lang/crates.io-index" 312 + checksum = "a8e0e1f38ec07ba4abbde21eed377082f17ccb988be9d988a5adbf4bafc118fd" 313 + dependencies = [ 314 + "cordyceps", 315 + "diatomic-waker", 316 + "futures-core", 317 + "pin-project-lite", 318 + "spin", 319 + ] 320 + 321 + [[package]] 322 + name = "futures-channel" 323 + version = "0.3.31" 324 + source = "registry+https://github.com/rust-lang/crates.io-index" 325 + checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" 326 + dependencies = [ 327 + "futures-core", 328 + "futures-sink", 329 + ] 330 + 331 + [[package]] 332 + name = "futures-concurrency" 333 + version = "7.6.3" 334 + source = "registry+https://github.com/rust-lang/crates.io-index" 335 + checksum = "0eb68017df91f2e477ed4bea586c59eaecaa47ed885a770d0444e21e62572cd2" 336 + dependencies = [ 337 + "fixedbitset", 338 + "futures-buffered", 339 + "futures-core", 340 + "futures-lite", 341 + "pin-project", 342 + "slab", 343 + "smallvec", 344 + ] 345 + 346 + [[package]] 347 + name = "futures-core" 348 + version = "0.3.31" 349 + source = "registry+https://github.com/rust-lang/crates.io-index" 350 + checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" 351 + 352 + [[package]] 353 + name = "futures-executor" 354 + version = "0.3.31" 355 + source = "registry+https://github.com/rust-lang/crates.io-index" 356 + checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" 357 + dependencies = [ 358 + "futures-core", 359 + "futures-task", 360 + "futures-util", 361 + ] 362 + 363 + [[package]] 364 + name = "futures-io" 365 + version = "0.3.31" 366 + source = "registry+https://github.com/rust-lang/crates.io-index" 367 + checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" 368 + 369 + [[package]] 370 + name = "futures-lite" 371 + version = "2.6.1" 372 + source = "registry+https://github.com/rust-lang/crates.io-index" 373 + checksum = "f78e10609fe0e0b3f4157ffab1876319b5b0db102a2c60dc4626306dc46b44ad" 374 + dependencies = [ 375 + "fastrand", 376 + "futures-core", 377 + "futures-io", 378 + "parking", 379 + "pin-project-lite", 380 + ] 381 + 382 + [[package]] 383 + name = "futures-macro" 384 + version = "0.3.31" 385 + source = "registry+https://github.com/rust-lang/crates.io-index" 386 + checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" 387 + dependencies = [ 388 + "proc-macro2", 389 + "quote", 390 + "syn", 391 + ] 392 + 393 + [[package]] 394 + name = "futures-sink" 395 + version = "0.3.31" 396 + source = "registry+https://github.com/rust-lang/crates.io-index" 397 + checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" 398 + 399 + [[package]] 400 + name = "futures-task" 401 + version = "0.3.31" 402 + source = "registry+https://github.com/rust-lang/crates.io-index" 403 + checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" 404 + 405 + [[package]] 406 + name = "futures-util" 407 + version = "0.3.31" 408 + source = "registry+https://github.com/rust-lang/crates.io-index" 409 + checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" 410 + dependencies = [ 411 + "futures-channel", 412 + "futures-core", 413 + "futures-io", 414 + "futures-macro", 415 + "futures-sink", 416 + "futures-task", 417 + "memchr", 418 + "pin-project-lite", 419 + "pin-utils", 420 + "slab", 421 + ] 422 + 423 + [[package]] 424 + name = "generator" 425 + version = "0.8.7" 426 + source = "registry+https://github.com/rust-lang/crates.io-index" 427 + checksum = "605183a538e3e2a9c1038635cc5c2d194e2ee8fd0d1b66b8349fad7dbacce5a2" 428 + dependencies = [ 429 + "cc", 430 + "cfg-if", 431 + "libc", 432 + "log", 433 + "rustversion", 434 + "windows", 435 + ] 436 + 437 + [[package]] 438 + name = "getrandom" 439 + version = "0.3.4" 440 + source = "registry+https://github.com/rust-lang/crates.io-index" 441 + checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" 442 + dependencies = [ 443 + "cfg-if", 444 + "libc", 445 + "r-efi", 446 + "wasip2", 447 + ] 448 + 449 + [[package]] 450 + name = "gimli" 451 + version = "0.32.3" 452 + source = "registry+https://github.com/rust-lang/crates.io-index" 453 + checksum = "e629b9b98ef3dd8afe6ca2bd0f89306cec16d43d907889945bc5d6687f2f13c7" 454 + 455 + [[package]] 456 + name = "glob" 457 + version = "0.3.3" 458 + source = "registry+https://github.com/rust-lang/crates.io-index" 459 + checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280" 460 + 461 + [[package]] 462 + name = "h2" 463 + version = "0.4.12" 464 + source = "registry+https://github.com/rust-lang/crates.io-index" 465 + checksum = "f3c0b69cfcb4e1b9f1bf2f53f95f766e4661169728ec61cd3fe5a0166f2d1386" 466 + dependencies = [ 467 + "atomic-waker", 468 + "bytes", 469 + "fnv", 470 + "futures-core", 471 + "futures-sink", 472 + "http", 473 + "indexmap", 474 + "slab", 475 + "tokio", 476 + "tokio-util", 477 + "tracing", 478 + ] 479 + 480 + [[package]] 481 + name = "hashbrown" 482 + version = "0.15.5" 483 + source = "registry+https://github.com/rust-lang/crates.io-index" 484 + checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" 485 + dependencies = [ 486 + "equivalent", 487 + ] 488 + 489 + [[package]] 490 + name = "hashbrown" 491 + version = "0.16.1" 492 + source = "registry+https://github.com/rust-lang/crates.io-index" 493 + checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" 494 + 495 + [[package]] 496 + name = "hermit-abi" 497 + version = "0.5.2" 498 + source = "registry+https://github.com/rust-lang/crates.io-index" 499 + checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c" 500 + 501 + [[package]] 502 + name = "http" 503 + version = "1.4.0" 504 + source = "registry+https://github.com/rust-lang/crates.io-index" 505 + checksum = "e3ba2a386d7f85a81f119ad7498ebe444d2e22c2af0b86b069416ace48b3311a" 506 + dependencies = [ 507 + "bytes", 508 + "itoa", 509 + ] 510 + 511 + [[package]] 512 + name = "http-body" 513 + version = "1.0.1" 514 + source = "registry+https://github.com/rust-lang/crates.io-index" 515 + checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" 516 + dependencies = [ 517 + "bytes", 518 + "http", 519 + ] 520 + 521 + [[package]] 522 + name = "http-body-util" 523 + version = "0.1.3" 524 + source = "registry+https://github.com/rust-lang/crates.io-index" 525 + checksum = "b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a" 526 + dependencies = [ 527 + "bytes", 528 + "futures-core", 529 + "http", 530 + "http-body", 531 + "pin-project-lite", 532 + ] 533 + 534 + [[package]] 535 + name = "httparse" 536 + version = "1.10.1" 537 + source = "registry+https://github.com/rust-lang/crates.io-index" 538 + checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" 539 + 540 + [[package]] 541 + name = "httpdate" 542 + version = "1.0.3" 543 + source = "registry+https://github.com/rust-lang/crates.io-index" 544 + checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" 545 + 546 + [[package]] 547 + name = "hyper" 548 + version = "1.8.1" 549 + source = "registry+https://github.com/rust-lang/crates.io-index" 550 + checksum = "2ab2d4f250c3d7b1c9fcdff1cece94ea4e2dfbec68614f7b87cb205f24ca9d11" 551 + dependencies = [ 552 + "atomic-waker", 553 + "bytes", 554 + "futures-channel", 555 + "futures-core", 556 + "h2", 557 + "http", 558 + "http-body", 559 + "httparse", 560 + "httpdate", 561 + "itoa", 562 + "pin-project-lite", 563 + "pin-utils", 564 + "smallvec", 565 + "tokio", 566 + "want", 567 + ] 568 + 569 + [[package]] 570 + name = "hyper-timeout" 571 + version = "0.5.2" 572 + source = "registry+https://github.com/rust-lang/crates.io-index" 573 + checksum = "2b90d566bffbce6a75bd8b09a05aa8c2cb1fabb6cb348f8840c9e4c90a0d83b0" 574 + dependencies = [ 575 + "hyper", 576 + "hyper-util", 577 + "pin-project-lite", 578 + "tokio", 579 + "tower-service", 580 + ] 581 + 582 + [[package]] 583 + name = "hyper-util" 584 + version = "0.1.18" 585 + source = "registry+https://github.com/rust-lang/crates.io-index" 586 + checksum = "52e9a2a24dc5c6821e71a7030e1e14b7b632acac55c40e9d2e082c621261bb56" 587 + dependencies = [ 588 + "bytes", 589 + "futures-channel", 590 + "futures-core", 591 + "futures-util", 592 + "http", 593 + "http-body", 594 + "hyper", 595 + "libc", 596 + "pin-project-lite", 597 + "socket2", 598 + "tokio", 599 + "tower-service", 600 + "tracing", 601 + ] 602 + 603 + [[package]] 604 + name = "indenter" 605 + version = "0.3.4" 606 + source = "registry+https://github.com/rust-lang/crates.io-index" 607 + checksum = "964de6e86d545b246d84badc0fef527924ace5134f30641c203ef52ba83f58d5" 608 + 609 + [[package]] 610 + name = "indexmap" 611 + version = "2.12.1" 612 + source = "registry+https://github.com/rust-lang/crates.io-index" 613 + checksum = "0ad4bb2b565bca0645f4d68c5c9af97fba094e9791da685bf83cb5f3ce74acf2" 614 + dependencies = [ 615 + "equivalent", 616 + "hashbrown 0.16.1", 617 + ] 618 + 619 + [[package]] 620 + name = "itertools" 621 + version = "0.14.0" 622 + source = "registry+https://github.com/rust-lang/crates.io-index" 623 + checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285" 624 + dependencies = [ 625 + "either", 626 + ] 627 + 628 + [[package]] 629 + name = "itoa" 630 + version = "1.0.15" 631 + source = "registry+https://github.com/rust-lang/crates.io-index" 632 + checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" 633 + 634 + [[package]] 635 + name = "jobserver" 636 + version = "0.1.34" 637 + source = "registry+https://github.com/rust-lang/crates.io-index" 638 + checksum = "9afb3de4395d6b3e67a780b6de64b51c978ecf11cb9a462c66be7d4ca9039d33" 639 + dependencies = [ 640 + "getrandom", 641 + "libc", 642 + ] 643 + 644 + [[package]] 645 + name = "js-sys" 646 + version = "0.3.83" 647 + source = "registry+https://github.com/rust-lang/crates.io-index" 648 + checksum = "464a3709c7f55f1f721e5389aa6ea4e3bc6aba669353300af094b29ffbdde1d8" 649 + dependencies = [ 650 + "once_cell", 651 + "wasm-bindgen", 652 + ] 653 + 654 + [[package]] 655 + name = "lazy_static" 656 + version = "1.5.0" 657 + source = "registry+https://github.com/rust-lang/crates.io-index" 658 + checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" 659 + 660 + [[package]] 661 + name = "libc" 662 + version = "0.2.177" 663 + source = "registry+https://github.com/rust-lang/crates.io-index" 664 + checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976" 665 + 666 + [[package]] 667 + name = "libm" 668 + version = "0.2.15" 669 + source = "registry+https://github.com/rust-lang/crates.io-index" 670 + checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de" 671 + 672 + [[package]] 673 + name = "libmimalloc-sys" 674 + version = "0.1.44" 675 + source = "registry+https://github.com/rust-lang/crates.io-index" 676 + checksum = "667f4fec20f29dfc6bc7357c582d91796c169ad7e2fce709468aefeb2c099870" 677 + dependencies = [ 678 + "cc", 679 + "libc", 680 + ] 681 + 682 + [[package]] 683 + name = "lock_api" 684 + version = "0.4.14" 685 + source = "registry+https://github.com/rust-lang/crates.io-index" 686 + checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" 687 + dependencies = [ 688 + "scopeguard", 689 + ] 690 + 691 + [[package]] 692 + name = "log" 693 + version = "0.4.28" 694 + source = "registry+https://github.com/rust-lang/crates.io-index" 695 + checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432" 696 + 697 + [[package]] 698 + name = "loom" 699 + version = "0.7.2" 700 + source = "registry+https://github.com/rust-lang/crates.io-index" 701 + checksum = "419e0dc8046cb947daa77eb95ae174acfbddb7673b4151f56d1eed8e93fbfaca" 702 + dependencies = [ 703 + "cfg-if", 704 + "generator", 705 + "scoped-tls", 706 + "tracing", 707 + "tracing-subscriber", 708 + ] 709 + 710 + [[package]] 711 + name = "matchers" 712 + version = "0.2.0" 713 + source = "registry+https://github.com/rust-lang/crates.io-index" 714 + checksum = "d1525a2a28c7f4fa0fc98bb91ae755d1e2d1505079e05539e35bc876b5d65ae9" 715 + dependencies = [ 716 + "regex-automata", 717 + ] 718 + 719 + [[package]] 720 + name = "matchit" 721 + version = "0.8.4" 722 + source = "registry+https://github.com/rust-lang/crates.io-index" 723 + checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3" 724 + 725 + [[package]] 726 + name = "memchr" 727 + version = "2.7.6" 728 + source = "registry+https://github.com/rust-lang/crates.io-index" 729 + checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" 730 + 731 + [[package]] 732 + name = "mimalloc" 733 + version = "0.1.48" 734 + source = "registry+https://github.com/rust-lang/crates.io-index" 735 + checksum = "e1ee66a4b64c74f4ef288bcbb9192ad9c3feaad75193129ac8509af543894fd8" 736 + dependencies = [ 737 + "libmimalloc-sys", 738 + ] 739 + 740 + [[package]] 741 + name = "mime" 742 + version = "0.3.17" 743 + source = "registry+https://github.com/rust-lang/crates.io-index" 744 + checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" 745 + 746 + [[package]] 747 + name = "miniz_oxide" 748 + version = "0.8.9" 749 + source = "registry+https://github.com/rust-lang/crates.io-index" 750 + checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316" 751 + dependencies = [ 752 + "adler2", 753 + ] 754 + 755 + [[package]] 756 + name = "mio" 757 + version = "1.1.0" 758 + source = "registry+https://github.com/rust-lang/crates.io-index" 759 + checksum = "69d83b0086dc8ecf3ce9ae2874b2d1290252e2a30720bea58a5c6639b0092873" 760 + dependencies = [ 761 + "libc", 762 + "wasi", 763 + "windows-sys 0.61.2", 764 + ] 765 + 766 + [[package]] 767 + name = "nailbox" 768 + version = "0.1.0" 769 + 770 + [[package]] 771 + name = "nailconfig" 772 + version = "0.1.0" 773 + dependencies = [ 774 + "color-eyre", 775 + "config", 776 + "nailbox", 777 + "serde", 778 + ] 779 + 780 + [[package]] 781 + name = "nailfv" 782 + version = "0.1.0" 783 + dependencies = [ 784 + "color-eyre", 785 + "winnow", 786 + ] 787 + 788 + [[package]] 789 + name = "nailgen" 790 + version = "0.1.0" 791 + dependencies = [ 792 + "axum", 793 + "bytes", 794 + "color-eyre", 795 + "futures-lite", 796 + "nailbox", 797 + "nailconfig", 798 + "nailkov", 799 + "nailrng", 800 + "pin-project-lite", 801 + "rand", 802 + "tokio", 803 + "tracing", 804 + "winnow", 805 + ] 806 + 807 + [[package]] 808 + name = "nailip" 809 + version = "0.1.0" 810 + dependencies = [ 811 + "axum", 812 + "futures-lite", 813 + "hyper", 814 + "nailconfig", 815 + "nailfv", 816 + "nailnet", 817 + "pin-project-lite", 818 + "scc", 819 + "tokio", 820 + "tower", 821 + "tracing", 822 + "wyrand", 823 + ] 824 + 825 + [[package]] 826 + name = "nailkov" 827 + version = "0.1.0" 828 + dependencies = [ 829 + "hashbrown 0.15.5", 830 + "indexmap", 831 + "itertools", 832 + "nailrng", 833 + "rand", 834 + "rand_distr", 835 + "rapidhash", 836 + "rustc-hash", 837 + "tracing", 838 + "unicode-segmentation", 839 + ] 840 + 841 + [[package]] 842 + name = "nailnet" 843 + version = "0.1.0" 844 + dependencies = [ 845 + "color-eyre", 846 + "socket2", 847 + "tokio", 848 + ] 849 + 850 + [[package]] 851 + name = "nailotel" 852 + version = "0.1.0" 853 + dependencies = [ 854 + "color-eyre", 855 + "nailconfig", 856 + "opentelemetry", 857 + "opentelemetry-appender-tracing", 858 + "opentelemetry-otlp", 859 + "opentelemetry-semantic-conventions", 860 + "opentelemetry_sdk", 861 + "tracing", 862 + "tracing-opentelemetry", 863 + "tracing-subscriber", 864 + ] 865 + 866 + [[package]] 867 + name = "nailpit" 868 + version = "0.1.0" 869 + dependencies = [ 870 + "axum", 871 + "color-eyre", 872 + "glob", 873 + "mimalloc", 874 + "nailbox", 875 + "nailconfig", 876 + "nailgen", 877 + "nailip", 878 + "nailkov", 879 + "nailnet", 880 + "nailotel", 881 + "nailrater", 882 + "nailrng", 883 + "nailroutes", 884 + "nailrt", 885 + "nailserve", 886 + "nailspicy", 887 + "nailstate", 888 + "nailstream", 889 + "nailtrace", 890 + "tokio", 891 + "tokio-util", 892 + "tracing", 893 + ] 894 + 895 + [[package]] 896 + name = "nailrater" 897 + version = "0.1.0" 898 + dependencies = [ 899 + "axum", 900 + "futures-lite", 901 + "hyper", 902 + "nailbox", 903 + "nailconfig", 904 + "nailfv", 905 + "nailip", 906 + "nailspicy", 907 + "parking_lot", 908 + "pin-project-lite", 909 + "rapidhash", 910 + "scc", 911 + "tokio", 912 + "tower", 913 + "tracing", 914 + "tracing-futures", 915 + ] 916 + 917 + [[package]] 918 + name = "nailrng" 919 + version = "0.1.0" 920 + dependencies = [ 921 + "getrandom", 922 + "rand_core", 923 + "wyrand", 924 + ] 925 + 926 + [[package]] 927 + name = "nailroutes" 928 + version = "0.1.0" 929 + dependencies = [ 930 + "axum", 931 + "axum-extra", 932 + "hyper", 933 + "nailgen", 934 + "nailip", 935 + "nailrater", 936 + "nailrng", 937 + "nailspicy", 938 + "nailstate", 939 + "nailstream", 940 + "nailtrace", 941 + "tower", 942 + "tower-http", 943 + "tracing", 944 + "tracing-futures", 945 + ] 946 + 947 + [[package]] 948 + name = "nailrt" 949 + version = "0.1.0" 950 + dependencies = [ 951 + "color-eyre", 952 + "core_affinity", 953 + "futures-concurrency", 954 + "nailconfig", 955 + "nailgen", 956 + "nailkov", 957 + "nailotel", 958 + "nailspicy", 959 + "nailstate", 960 + "tokio", 961 + "tokio-util", 962 + "tracing", 963 + ] 964 + 965 + [[package]] 966 + name = "nailserve" 967 + version = "0.1.0" 968 + dependencies = [ 969 + "axum", 970 + "color-eyre", 971 + "futures-concurrency", 972 + "hyper", 973 + "hyper-util", 974 + "nailip", 975 + "tokio", 976 + "tokio-util", 977 + "tower", 978 + "tracing", 979 + ] 980 + 981 + [[package]] 982 + name = "nailspicy" 983 + version = "0.1.0" 984 + dependencies = [ 985 + "hashbrown 0.15.5", 986 + "hyper", 987 + "nailbox", 988 + "nailconfig", 989 + "rapidhash", 990 + "tracing", 991 + ] 992 + 993 + [[package]] 994 + name = "nailstate" 995 + version = "0.1.0" 996 + dependencies = [ 997 + "axum", 998 + "nailconfig", 999 + "nailgen", 1000 + "nailkov", 1001 + "nailrng", 1002 + "nailspicy", 1003 + "rand", 1004 + ] 1005 + 1006 + [[package]] 1007 + name = "nailstream" 1008 + version = "0.1.0" 1009 + dependencies = [ 1010 + "axum", 1011 + "futures-lite", 1012 + "hyper", 1013 + "tracing", 1014 + ] 1015 + 1016 + [[package]] 1017 + name = "nailtrace" 1018 + version = "0.1.0" 1019 + dependencies = [ 1020 + "axum", 1021 + "hyper", 1022 + "nailip", 1023 + "nailstate", 1024 + "opentelemetry", 1025 + "opentelemetry-http", 1026 + "opentelemetry-semantic-conventions", 1027 + "pin-project-lite", 1028 + "tower-http", 1029 + "tracing", 1030 + "tracing-futures", 1031 + "tracing-opentelemetry", 1032 + "uuid", 1033 + ] 1034 + 1035 + [[package]] 1036 + name = "nu-ansi-term" 1037 + version = "0.50.3" 1038 + source = "registry+https://github.com/rust-lang/crates.io-index" 1039 + checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" 1040 + dependencies = [ 1041 + "windows-sys 0.61.2", 1042 + ] 1043 + 1044 + [[package]] 1045 + name = "num-traits" 1046 + version = "0.2.19" 1047 + source = "registry+https://github.com/rust-lang/crates.io-index" 1048 + checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" 1049 + dependencies = [ 1050 + "autocfg", 1051 + "libm", 1052 + ] 1053 + 1054 + [[package]] 1055 + name = "num_cpus" 1056 + version = "1.17.0" 1057 + source = "registry+https://github.com/rust-lang/crates.io-index" 1058 + checksum = "91df4bbde75afed763b708b7eee1e8e7651e02d97f6d5dd763e89367e957b23b" 1059 + dependencies = [ 1060 + "hermit-abi", 1061 + "libc", 1062 + ] 1063 + 1064 + [[package]] 1065 + name = "object" 1066 + version = "0.37.3" 1067 + source = "registry+https://github.com/rust-lang/crates.io-index" 1068 + checksum = "ff76201f031d8863c38aa7f905eca4f53abbfa15f609db4277d44cd8938f33fe" 1069 + dependencies = [ 1070 + "memchr", 1071 + ] 1072 + 1073 + [[package]] 1074 + name = "once_cell" 1075 + version = "1.21.3" 1076 + source = "registry+https://github.com/rust-lang/crates.io-index" 1077 + checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" 1078 + 1079 + [[package]] 1080 + name = "opentelemetry" 1081 + version = "0.31.0" 1082 + source = "registry+https://github.com/rust-lang/crates.io-index" 1083 + checksum = "b84bcd6ae87133e903af7ef497404dda70c60d0ea14895fc8a5e6722754fc2a0" 1084 + dependencies = [ 1085 + "futures-core", 1086 + "futures-sink", 1087 + "js-sys", 1088 + "pin-project-lite", 1089 + "thiserror", 1090 + "tracing", 1091 + ] 1092 + 1093 + [[package]] 1094 + name = "opentelemetry-appender-tracing" 1095 + version = "0.31.1" 1096 + source = "registry+https://github.com/rust-lang/crates.io-index" 1097 + checksum = "ef6a1ac5ca3accf562b8c306fa8483c85f4390f768185ab775f242f7fe8fdcc2" 1098 + dependencies = [ 1099 + "opentelemetry", 1100 + "tracing", 1101 + "tracing-core", 1102 + "tracing-log", 1103 + "tracing-opentelemetry", 1104 + "tracing-subscriber", 1105 + ] 1106 + 1107 + [[package]] 1108 + name = "opentelemetry-http" 1109 + version = "0.31.0" 1110 + source = "registry+https://github.com/rust-lang/crates.io-index" 1111 + checksum = "d7a6d09a73194e6b66df7c8f1b680f156d916a1a942abf2de06823dd02b7855d" 1112 + dependencies = [ 1113 + "async-trait", 1114 + "bytes", 1115 + "http", 1116 + "opentelemetry", 1117 + ] 1118 + 1119 + [[package]] 1120 + name = "opentelemetry-otlp" 1121 + version = "0.31.0" 1122 + source = "registry+https://github.com/rust-lang/crates.io-index" 1123 + checksum = "7a2366db2dca4d2ad033cad11e6ee42844fd727007af5ad04a1730f4cb8163bf" 1124 + dependencies = [ 1125 + "http", 1126 + "opentelemetry", 1127 + "opentelemetry-proto", 1128 + "opentelemetry_sdk", 1129 + "prost", 1130 + "thiserror", 1131 + "tokio", 1132 + "tonic", 1133 + ] 1134 + 1135 + [[package]] 1136 + name = "opentelemetry-proto" 1137 + version = "0.31.0" 1138 + source = "registry+https://github.com/rust-lang/crates.io-index" 1139 + checksum = "a7175df06de5eaee9909d4805a3d07e28bb752c34cab57fa9cff549da596b30f" 1140 + dependencies = [ 1141 + "opentelemetry", 1142 + "opentelemetry_sdk", 1143 + "prost", 1144 + "tonic", 1145 + "tonic-prost", 1146 + ] 1147 + 1148 + [[package]] 1149 + name = "opentelemetry-semantic-conventions" 1150 + version = "0.31.0" 1151 + source = "registry+https://github.com/rust-lang/crates.io-index" 1152 + checksum = "e62e29dfe041afb8ed2a6c9737ab57db4907285d999ef8ad3a59092a36bdc846" 1153 + 1154 + [[package]] 1155 + name = "opentelemetry_sdk" 1156 + version = "0.31.0" 1157 + source = "registry+https://github.com/rust-lang/crates.io-index" 1158 + checksum = "e14ae4f5991976fd48df6d843de219ca6d31b01daaab2dad5af2badeded372bd" 1159 + dependencies = [ 1160 + "futures-channel", 1161 + "futures-executor", 1162 + "futures-util", 1163 + "opentelemetry", 1164 + "percent-encoding", 1165 + "rand", 1166 + "thiserror", 1167 + "tokio", 1168 + "tokio-stream", 1169 + ] 1170 + 1171 + [[package]] 1172 + name = "owo-colors" 1173 + version = "4.2.3" 1174 + source = "registry+https://github.com/rust-lang/crates.io-index" 1175 + checksum = "9c6901729fa79e91a0913333229e9ca5dc725089d1c363b2f4b4760709dc4a52" 1176 + 1177 + [[package]] 1178 + name = "parking" 1179 + version = "2.2.1" 1180 + source = "registry+https://github.com/rust-lang/crates.io-index" 1181 + checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" 1182 + 1183 + [[package]] 1184 + name = "parking_lot" 1185 + version = "0.12.5" 1186 + source = "registry+https://github.com/rust-lang/crates.io-index" 1187 + checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" 1188 + dependencies = [ 1189 + "lock_api", 1190 + "parking_lot_core", 1191 + ] 1192 + 1193 + [[package]] 1194 + name = "parking_lot_core" 1195 + version = "0.9.12" 1196 + source = "registry+https://github.com/rust-lang/crates.io-index" 1197 + checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" 1198 + dependencies = [ 1199 + "cfg-if", 1200 + "libc", 1201 + "redox_syscall", 1202 + "smallvec", 1203 + "windows-link 0.2.1", 1204 + ] 1205 + 1206 + [[package]] 1207 + name = "pathdiff" 1208 + version = "0.2.3" 1209 + source = "registry+https://github.com/rust-lang/crates.io-index" 1210 + checksum = "df94ce210e5bc13cb6651479fa48d14f601d9858cfe0467f43ae157023b938d3" 1211 + 1212 + [[package]] 1213 + name = "percent-encoding" 1214 + version = "2.3.2" 1215 + source = "registry+https://github.com/rust-lang/crates.io-index" 1216 + checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" 1217 + 1218 + [[package]] 1219 + name = "pin-project" 1220 + version = "1.1.10" 1221 + source = "registry+https://github.com/rust-lang/crates.io-index" 1222 + checksum = "677f1add503faace112b9f1373e43e9e054bfdd22ff1a63c1bc485eaec6a6a8a" 1223 + dependencies = [ 1224 + "pin-project-internal", 1225 + ] 1226 + 1227 + [[package]] 1228 + name = "pin-project-internal" 1229 + version = "1.1.10" 1230 + source = "registry+https://github.com/rust-lang/crates.io-index" 1231 + checksum = "6e918e4ff8c4549eb882f14b3a4bc8c8bc93de829416eacf579f1207a8fbf861" 1232 + dependencies = [ 1233 + "proc-macro2", 1234 + "quote", 1235 + "syn", 1236 + ] 1237 + 1238 + [[package]] 1239 + name = "pin-project-lite" 1240 + version = "0.2.16" 1241 + source = "registry+https://github.com/rust-lang/crates.io-index" 1242 + checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" 1243 + 1244 + [[package]] 1245 + name = "pin-utils" 1246 + version = "0.1.0" 1247 + source = "registry+https://github.com/rust-lang/crates.io-index" 1248 + checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" 1249 + 1250 + [[package]] 1251 + name = "pkg-config" 1252 + version = "0.3.32" 1253 + source = "registry+https://github.com/rust-lang/crates.io-index" 1254 + checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" 1255 + 1256 + [[package]] 1257 + name = "ppv-lite86" 1258 + version = "0.2.21" 1259 + source = "registry+https://github.com/rust-lang/crates.io-index" 1260 + checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" 1261 + dependencies = [ 1262 + "zerocopy", 1263 + ] 1264 + 1265 + [[package]] 1266 + name = "proc-macro2" 1267 + version = "1.0.103" 1268 + source = "registry+https://github.com/rust-lang/crates.io-index" 1269 + checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8" 1270 + dependencies = [ 1271 + "unicode-ident", 1272 + ] 1273 + 1274 + [[package]] 1275 + name = "prost" 1276 + version = "0.14.1" 1277 + source = "registry+https://github.com/rust-lang/crates.io-index" 1278 + checksum = "7231bd9b3d3d33c86b58adbac74b5ec0ad9f496b19d22801d773636feaa95f3d" 1279 + dependencies = [ 1280 + "bytes", 1281 + "prost-derive", 1282 + ] 1283 + 1284 + [[package]] 1285 + name = "prost-derive" 1286 + version = "0.14.1" 1287 + source = "registry+https://github.com/rust-lang/crates.io-index" 1288 + checksum = "9120690fafc389a67ba3803df527d0ec9cbbc9cc45e4cc20b332996dfb672425" 1289 + dependencies = [ 1290 + "anyhow", 1291 + "itertools", 1292 + "proc-macro2", 1293 + "quote", 1294 + "syn", 1295 + ] 1296 + 1297 + [[package]] 1298 + name = "quote" 1299 + version = "1.0.42" 1300 + source = "registry+https://github.com/rust-lang/crates.io-index" 1301 + checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f" 1302 + dependencies = [ 1303 + "proc-macro2", 1304 + ] 1305 + 1306 + [[package]] 1307 + name = "r-efi" 1308 + version = "5.3.0" 1309 + source = "registry+https://github.com/rust-lang/crates.io-index" 1310 + checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" 1311 + 1312 + [[package]] 1313 + name = "rand" 1314 + version = "0.9.2" 1315 + source = "registry+https://github.com/rust-lang/crates.io-index" 1316 + checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" 1317 + dependencies = [ 1318 + "rand_chacha", 1319 + "rand_core", 1320 + ] 1321 + 1322 + [[package]] 1323 + name = "rand_chacha" 1324 + version = "0.9.0" 1325 + source = "registry+https://github.com/rust-lang/crates.io-index" 1326 + checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" 1327 + dependencies = [ 1328 + "ppv-lite86", 1329 + "rand_core", 1330 + ] 1331 + 1332 + [[package]] 1333 + name = "rand_core" 1334 + version = "0.9.3" 1335 + source = "registry+https://github.com/rust-lang/crates.io-index" 1336 + checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38" 1337 + dependencies = [ 1338 + "getrandom", 1339 + ] 1340 + 1341 + [[package]] 1342 + name = "rand_distr" 1343 + version = "0.5.1" 1344 + source = "registry+https://github.com/rust-lang/crates.io-index" 1345 + checksum = "6a8615d50dcf34fa31f7ab52692afec947c4dd0ab803cc87cb3b0b4570ff7463" 1346 + dependencies = [ 1347 + "num-traits", 1348 + "rand", 1349 + ] 1350 + 1351 + [[package]] 1352 + name = "rapidhash" 1353 + version = "4.1.1" 1354 + source = "registry+https://github.com/rust-lang/crates.io-index" 1355 + checksum = "d8e65c75143ce5d47c55b510297eeb1182f3c739b6043c537670e9fc18612dae" 1356 + dependencies = [ 1357 + "rand", 1358 + "rustversion", 1359 + ] 1360 + 1361 + [[package]] 1362 + name = "redox_syscall" 1363 + version = "0.5.18" 1364 + source = "registry+https://github.com/rust-lang/crates.io-index" 1365 + checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" 1366 + dependencies = [ 1367 + "bitflags", 1368 + ] 1369 + 1370 + [[package]] 1371 + name = "regex-automata" 1372 + version = "0.4.13" 1373 + source = "registry+https://github.com/rust-lang/crates.io-index" 1374 + checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c" 1375 + dependencies = [ 1376 + "aho-corasick", 1377 + "memchr", 1378 + "regex-syntax", 1379 + ] 1380 + 1381 + [[package]] 1382 + name = "regex-syntax" 1383 + version = "0.8.8" 1384 + source = "registry+https://github.com/rust-lang/crates.io-index" 1385 + checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58" 1386 + 1387 + [[package]] 1388 + name = "rustc-demangle" 1389 + version = "0.1.26" 1390 + source = "registry+https://github.com/rust-lang/crates.io-index" 1391 + checksum = "56f7d92ca342cea22a06f2121d944b4fd82af56988c270852495420f961d4ace" 1392 + 1393 + [[package]] 1394 + name = "rustc-hash" 1395 + version = "2.1.1" 1396 + source = "registry+https://github.com/rust-lang/crates.io-index" 1397 + checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" 1398 + 1399 + [[package]] 1400 + name = "rustversion" 1401 + version = "1.0.22" 1402 + source = "registry+https://github.com/rust-lang/crates.io-index" 1403 + checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" 1404 + 1405 + [[package]] 1406 + name = "ryu" 1407 + version = "1.0.20" 1408 + source = "registry+https://github.com/rust-lang/crates.io-index" 1409 + checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" 1410 + 1411 + [[package]] 1412 + name = "saa" 1413 + version = "5.3.3" 1414 + source = "registry+https://github.com/rust-lang/crates.io-index" 1415 + checksum = "4dfac11c0cd0606aaf7eb9ef66f82c119438a96dc487715abb8b57fdf08ad4fe" 1416 + 1417 + [[package]] 1418 + name = "scc" 1419 + version = "3.4.2" 1420 + source = "registry+https://github.com/rust-lang/crates.io-index" 1421 + checksum = "cd714a8af37b350df813d52ae4b2ea19211e40dac10dce189d80fb95e44cc618" 1422 + dependencies = [ 1423 + "saa", 1424 + "sdd", 1425 + ] 1426 + 1427 + [[package]] 1428 + name = "scoped-tls" 1429 + version = "1.0.1" 1430 + source = "registry+https://github.com/rust-lang/crates.io-index" 1431 + checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" 1432 + 1433 + [[package]] 1434 + name = "scopeguard" 1435 + version = "1.2.0" 1436 + source = "registry+https://github.com/rust-lang/crates.io-index" 1437 + checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" 1438 + 1439 + [[package]] 1440 + name = "sdd" 1441 + version = "4.3.3" 1442 + source = "registry+https://github.com/rust-lang/crates.io-index" 1443 + checksum = "6e4efd216416190644cfc82b398d603be158c29ffd7ee171fd29773a0b5734a7" 1444 + 1445 + [[package]] 1446 + name = "serde" 1447 + version = "1.0.228" 1448 + source = "registry+https://github.com/rust-lang/crates.io-index" 1449 + checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" 1450 + dependencies = [ 1451 + "serde_core", 1452 + "serde_derive", 1453 + ] 1454 + 1455 + [[package]] 1456 + name = "serde_core" 1457 + version = "1.0.228" 1458 + source = "registry+https://github.com/rust-lang/crates.io-index" 1459 + checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" 1460 + dependencies = [ 1461 + "serde_derive", 1462 + ] 1463 + 1464 + [[package]] 1465 + name = "serde_derive" 1466 + version = "1.0.228" 1467 + source = "registry+https://github.com/rust-lang/crates.io-index" 1468 + checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" 1469 + dependencies = [ 1470 + "proc-macro2", 1471 + "quote", 1472 + "syn", 1473 + ] 1474 + 1475 + [[package]] 1476 + name = "serde_json" 1477 + version = "1.0.145" 1478 + source = "registry+https://github.com/rust-lang/crates.io-index" 1479 + checksum = "402a6f66d8c709116cf22f558eab210f5a50187f702eb4d7e5ef38d9a7f1c79c" 1480 + dependencies = [ 1481 + "itoa", 1482 + "memchr", 1483 + "ryu", 1484 + "serde", 1485 + "serde_core", 1486 + ] 1487 + 1488 + [[package]] 1489 + name = "serde_spanned" 1490 + version = "1.0.3" 1491 + source = "registry+https://github.com/rust-lang/crates.io-index" 1492 + checksum = "e24345aa0fe688594e73770a5f6d1b216508b4f93484c0026d521acd30134392" 1493 + dependencies = [ 1494 + "serde_core", 1495 + ] 1496 + 1497 + [[package]] 1498 + name = "sharded-slab" 1499 + version = "0.1.7" 1500 + source = "registry+https://github.com/rust-lang/crates.io-index" 1501 + checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" 1502 + dependencies = [ 1503 + "lazy_static", 1504 + ] 1505 + 1506 + [[package]] 1507 + name = "shlex" 1508 + version = "1.3.0" 1509 + source = "registry+https://github.com/rust-lang/crates.io-index" 1510 + checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" 1511 + 1512 + [[package]] 1513 + name = "signal-hook-registry" 1514 + version = "1.4.7" 1515 + source = "registry+https://github.com/rust-lang/crates.io-index" 1516 + checksum = "7664a098b8e616bdfcc2dc0e9ac44eb231eedf41db4e9fe95d8d32ec728dedad" 1517 + dependencies = [ 1518 + "libc", 1519 + ] 1520 + 1521 + [[package]] 1522 + name = "slab" 1523 + version = "0.4.11" 1524 + source = "registry+https://github.com/rust-lang/crates.io-index" 1525 + checksum = "7a2ae44ef20feb57a68b23d846850f861394c2e02dc425a50098ae8c90267589" 1526 + 1527 + [[package]] 1528 + name = "smallvec" 1529 + version = "1.15.1" 1530 + source = "registry+https://github.com/rust-lang/crates.io-index" 1531 + checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" 1532 + 1533 + [[package]] 1534 + name = "socket2" 1535 + version = "0.6.1" 1536 + source = "registry+https://github.com/rust-lang/crates.io-index" 1537 + checksum = "17129e116933cf371d018bb80ae557e889637989d8638274fb25622827b03881" 1538 + dependencies = [ 1539 + "libc", 1540 + "windows-sys 0.60.2", 1541 + ] 1542 + 1543 + [[package]] 1544 + name = "spin" 1545 + version = "0.10.0" 1546 + source = "registry+https://github.com/rust-lang/crates.io-index" 1547 + checksum = "d5fe4ccb98d9c292d56fec89a5e07da7fc4cf0dc11e156b41793132775d3e591" 1548 + 1549 + [[package]] 1550 + name = "syn" 1551 + version = "2.0.111" 1552 + source = "registry+https://github.com/rust-lang/crates.io-index" 1553 + checksum = "390cc9a294ab71bdb1aa2e99d13be9c753cd2d7bd6560c77118597410c4d2e87" 1554 + dependencies = [ 1555 + "proc-macro2", 1556 + "quote", 1557 + "unicode-ident", 1558 + ] 1559 + 1560 + [[package]] 1561 + name = "sync_wrapper" 1562 + version = "1.0.2" 1563 + source = "registry+https://github.com/rust-lang/crates.io-index" 1564 + checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" 1565 + 1566 + [[package]] 1567 + name = "thiserror" 1568 + version = "2.0.17" 1569 + source = "registry+https://github.com/rust-lang/crates.io-index" 1570 + checksum = "f63587ca0f12b72a0600bcba1d40081f830876000bb46dd2337a3051618f4fc8" 1571 + dependencies = [ 1572 + "thiserror-impl", 1573 + ] 1574 + 1575 + [[package]] 1576 + name = "thiserror-impl" 1577 + version = "2.0.17" 1578 + source = "registry+https://github.com/rust-lang/crates.io-index" 1579 + checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913" 1580 + dependencies = [ 1581 + "proc-macro2", 1582 + "quote", 1583 + "syn", 1584 + ] 1585 + 1586 + [[package]] 1587 + name = "thread_local" 1588 + version = "1.1.9" 1589 + source = "registry+https://github.com/rust-lang/crates.io-index" 1590 + checksum = "f60246a4944f24f6e018aa17cdeffb7818b76356965d03b07d6a9886e8962185" 1591 + dependencies = [ 1592 + "cfg-if", 1593 + ] 1594 + 1595 + [[package]] 1596 + name = "tokio" 1597 + version = "1.48.0" 1598 + source = "registry+https://github.com/rust-lang/crates.io-index" 1599 + checksum = "ff360e02eab121e0bc37a2d3b4d4dc622e6eda3a8e5253d5435ecf5bd4c68408" 1600 + dependencies = [ 1601 + "bytes", 1602 + "libc", 1603 + "mio", 1604 + "parking_lot", 1605 + "pin-project-lite", 1606 + "signal-hook-registry", 1607 + "socket2", 1608 + "windows-sys 0.61.2", 1609 + ] 1610 + 1611 + [[package]] 1612 + name = "tokio-stream" 1613 + version = "0.1.17" 1614 + source = "registry+https://github.com/rust-lang/crates.io-index" 1615 + checksum = "eca58d7bba4a75707817a2c44174253f9236b2d5fbd055602e9d5c07c139a047" 1616 + dependencies = [ 1617 + "futures-core", 1618 + "pin-project-lite", 1619 + "tokio", 1620 + ] 1621 + 1622 + [[package]] 1623 + name = "tokio-util" 1624 + version = "0.7.17" 1625 + source = "registry+https://github.com/rust-lang/crates.io-index" 1626 + checksum = "2efa149fe76073d6e8fd97ef4f4eca7b67f599660115591483572e406e165594" 1627 + dependencies = [ 1628 + "bytes", 1629 + "futures-core", 1630 + "futures-sink", 1631 + "pin-project-lite", 1632 + "tokio", 1633 + ] 1634 + 1635 + [[package]] 1636 + name = "toml" 1637 + version = "0.9.8" 1638 + source = "registry+https://github.com/rust-lang/crates.io-index" 1639 + checksum = "f0dc8b1fb61449e27716ec0e1bdf0f6b8f3e8f6b05391e8497b8b6d7804ea6d8" 1640 + dependencies = [ 1641 + "serde_core", 1642 + "serde_spanned", 1643 + "toml_datetime", 1644 + "toml_parser", 1645 + "winnow", 1646 + ] 1647 + 1648 + [[package]] 1649 + name = "toml_datetime" 1650 + version = "0.7.3" 1651 + source = "registry+https://github.com/rust-lang/crates.io-index" 1652 + checksum = "f2cdb639ebbc97961c51720f858597f7f24c4fc295327923af55b74c3c724533" 1653 + dependencies = [ 1654 + "serde_core", 1655 + ] 1656 + 1657 + [[package]] 1658 + name = "toml_parser" 1659 + version = "1.0.4" 1660 + source = "registry+https://github.com/rust-lang/crates.io-index" 1661 + checksum = "c0cbe268d35bdb4bb5a56a2de88d0ad0eb70af5384a99d648cd4b3d04039800e" 1662 + dependencies = [ 1663 + "winnow", 1664 + ] 1665 + 1666 + [[package]] 1667 + name = "tonic" 1668 + version = "0.14.2" 1669 + source = "registry+https://github.com/rust-lang/crates.io-index" 1670 + checksum = "eb7613188ce9f7df5bfe185db26c5814347d110db17920415cf2fbcad85e7203" 1671 + dependencies = [ 1672 + "async-trait", 1673 + "base64", 1674 + "bytes", 1675 + "http", 1676 + "http-body", 1677 + "http-body-util", 1678 + "hyper", 1679 + "hyper-timeout", 1680 + "hyper-util", 1681 + "percent-encoding", 1682 + "pin-project", 1683 + "sync_wrapper", 1684 + "tokio", 1685 + "tokio-stream", 1686 + "tower", 1687 + "tower-layer", 1688 + "tower-service", 1689 + "tracing", 1690 + "zstd", 1691 + ] 1692 + 1693 + [[package]] 1694 + name = "tonic-prost" 1695 + version = "0.14.2" 1696 + source = "registry+https://github.com/rust-lang/crates.io-index" 1697 + checksum = "66bd50ad6ce1252d87ef024b3d64fe4c3cf54a86fb9ef4c631fdd0ded7aeaa67" 1698 + dependencies = [ 1699 + "bytes", 1700 + "prost", 1701 + "tonic", 1702 + ] 1703 + 1704 + [[package]] 1705 + name = "tower" 1706 + version = "0.5.2" 1707 + source = "registry+https://github.com/rust-lang/crates.io-index" 1708 + checksum = "d039ad9159c98b70ecfd540b2573b97f7f52c3e8d9f8ad57a24b916a536975f9" 1709 + dependencies = [ 1710 + "futures-core", 1711 + "futures-util", 1712 + "indexmap", 1713 + "pin-project-lite", 1714 + "slab", 1715 + "sync_wrapper", 1716 + "tokio", 1717 + "tokio-util", 1718 + "tower-layer", 1719 + "tower-service", 1720 + "tracing", 1721 + ] 1722 + 1723 + [[package]] 1724 + name = "tower-http" 1725 + version = "0.6.7" 1726 + source = "registry+https://github.com/rust-lang/crates.io-index" 1727 + checksum = "9cf146f99d442e8e68e585f5d798ccd3cad9a7835b917e09728880a862706456" 1728 + dependencies = [ 1729 + "bitflags", 1730 + "bytes", 1731 + "http", 1732 + "pin-project-lite", 1733 + "tower", 1734 + "tower-layer", 1735 + "tower-service", 1736 + ] 1737 + 1738 + [[package]] 1739 + name = "tower-layer" 1740 + version = "0.3.3" 1741 + source = "registry+https://github.com/rust-lang/crates.io-index" 1742 + checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" 1743 + 1744 + [[package]] 1745 + name = "tower-service" 1746 + version = "0.3.3" 1747 + source = "registry+https://github.com/rust-lang/crates.io-index" 1748 + checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" 1749 + 1750 + [[package]] 1751 + name = "tracing" 1752 + version = "0.1.43" 1753 + source = "registry+https://github.com/rust-lang/crates.io-index" 1754 + checksum = "2d15d90a0b5c19378952d479dc858407149d7bb45a14de0142f6c534b16fc647" 1755 + dependencies = [ 1756 + "pin-project-lite", 1757 + "tracing-attributes", 1758 + "tracing-core", 1759 + ] 1760 + 1761 + [[package]] 1762 + name = "tracing-attributes" 1763 + version = "0.1.31" 1764 + source = "registry+https://github.com/rust-lang/crates.io-index" 1765 + checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" 1766 + dependencies = [ 1767 + "proc-macro2", 1768 + "quote", 1769 + "syn", 1770 + ] 1771 + 1772 + [[package]] 1773 + name = "tracing-core" 1774 + version = "0.1.35" 1775 + source = "registry+https://github.com/rust-lang/crates.io-index" 1776 + checksum = "7a04e24fab5c89c6a36eb8558c9656f30d81de51dfa4d3b45f26b21d61fa0a6c" 1777 + dependencies = [ 1778 + "once_cell", 1779 + "valuable", 1780 + ] 1781 + 1782 + [[package]] 1783 + name = "tracing-futures" 1784 + version = "0.2.5" 1785 + source = "registry+https://github.com/rust-lang/crates.io-index" 1786 + checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" 1787 + dependencies = [ 1788 + "futures", 1789 + "futures-task", 1790 + "pin-project", 1791 + "tracing", 1792 + ] 1793 + 1794 + [[package]] 1795 + name = "tracing-log" 1796 + version = "0.2.0" 1797 + source = "registry+https://github.com/rust-lang/crates.io-index" 1798 + checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" 1799 + dependencies = [ 1800 + "log", 1801 + "once_cell", 1802 + "tracing-core", 1803 + ] 1804 + 1805 + [[package]] 1806 + name = "tracing-opentelemetry" 1807 + version = "0.32.0" 1808 + source = "registry+https://github.com/rust-lang/crates.io-index" 1809 + checksum = "1e6e5658463dd88089aba75c7791e1d3120633b1bfde22478b28f625a9bb1b8e" 1810 + dependencies = [ 1811 + "js-sys", 1812 + "opentelemetry", 1813 + "opentelemetry_sdk", 1814 + "rustversion", 1815 + "smallvec", 1816 + "thiserror", 1817 + "tracing", 1818 + "tracing-core", 1819 + "tracing-log", 1820 + "tracing-subscriber", 1821 + "web-time", 1822 + ] 1823 + 1824 + [[package]] 1825 + name = "tracing-serde" 1826 + version = "0.2.0" 1827 + source = "registry+https://github.com/rust-lang/crates.io-index" 1828 + checksum = "704b1aeb7be0d0a84fc9828cae51dab5970fee5088f83d1dd7ee6f6246fc6ff1" 1829 + dependencies = [ 1830 + "serde", 1831 + "tracing-core", 1832 + ] 1833 + 1834 + [[package]] 1835 + name = "tracing-subscriber" 1836 + version = "0.3.22" 1837 + source = "registry+https://github.com/rust-lang/crates.io-index" 1838 + checksum = "2f30143827ddab0d256fd843b7a66d164e9f271cfa0dde49142c5ca0ca291f1e" 1839 + dependencies = [ 1840 + "matchers", 1841 + "nu-ansi-term", 1842 + "once_cell", 1843 + "regex-automata", 1844 + "serde", 1845 + "serde_json", 1846 + "sharded-slab", 1847 + "smallvec", 1848 + "thread_local", 1849 + "tracing", 1850 + "tracing-core", 1851 + "tracing-log", 1852 + "tracing-serde", 1853 + ] 1854 + 1855 + [[package]] 1856 + name = "try-lock" 1857 + version = "0.2.5" 1858 + source = "registry+https://github.com/rust-lang/crates.io-index" 1859 + checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" 1860 + 1861 + [[package]] 1862 + name = "unicode-ident" 1863 + version = "1.0.22" 1864 + source = "registry+https://github.com/rust-lang/crates.io-index" 1865 + checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" 1866 + 1867 + [[package]] 1868 + name = "unicode-segmentation" 1869 + version = "1.12.0" 1870 + source = "registry+https://github.com/rust-lang/crates.io-index" 1871 + checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" 1872 + 1873 + [[package]] 1874 + name = "uuid" 1875 + version = "1.18.1" 1876 + source = "registry+https://github.com/rust-lang/crates.io-index" 1877 + checksum = "2f87b8aa10b915a06587d0dec516c282ff295b475d94abf425d62b57710070a2" 1878 + dependencies = [ 1879 + "getrandom", 1880 + "js-sys", 1881 + "rand", 1882 + "wasm-bindgen", 1883 + ] 1884 + 1885 + [[package]] 1886 + name = "valuable" 1887 + version = "0.1.1" 1888 + source = "registry+https://github.com/rust-lang/crates.io-index" 1889 + checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" 1890 + 1891 + [[package]] 1892 + name = "want" 1893 + version = "0.3.1" 1894 + source = "registry+https://github.com/rust-lang/crates.io-index" 1895 + checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" 1896 + dependencies = [ 1897 + "try-lock", 1898 + ] 1899 + 1900 + [[package]] 1901 + name = "wasi" 1902 + version = "0.11.1+wasi-snapshot-preview1" 1903 + source = "registry+https://github.com/rust-lang/crates.io-index" 1904 + checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" 1905 + 1906 + [[package]] 1907 + name = "wasip2" 1908 + version = "1.0.1+wasi-0.2.4" 1909 + source = "registry+https://github.com/rust-lang/crates.io-index" 1910 + checksum = "0562428422c63773dad2c345a1882263bbf4d65cf3f42e90921f787ef5ad58e7" 1911 + dependencies = [ 1912 + "wit-bindgen", 1913 + ] 1914 + 1915 + [[package]] 1916 + name = "wasm-bindgen" 1917 + version = "0.2.106" 1918 + source = "registry+https://github.com/rust-lang/crates.io-index" 1919 + checksum = "0d759f433fa64a2d763d1340820e46e111a7a5ab75f993d1852d70b03dbb80fd" 1920 + dependencies = [ 1921 + "cfg-if", 1922 + "once_cell", 1923 + "rustversion", 1924 + "wasm-bindgen-macro", 1925 + "wasm-bindgen-shared", 1926 + ] 1927 + 1928 + [[package]] 1929 + name = "wasm-bindgen-macro" 1930 + version = "0.2.106" 1931 + source = "registry+https://github.com/rust-lang/crates.io-index" 1932 + checksum = "48cb0d2638f8baedbc542ed444afc0644a29166f1595371af4fecf8ce1e7eeb3" 1933 + dependencies = [ 1934 + "quote", 1935 + "wasm-bindgen-macro-support", 1936 + ] 1937 + 1938 + [[package]] 1939 + name = "wasm-bindgen-macro-support" 1940 + version = "0.2.106" 1941 + source = "registry+https://github.com/rust-lang/crates.io-index" 1942 + checksum = "cefb59d5cd5f92d9dcf80e4683949f15ca4b511f4ac0a6e14d4e1ac60c6ecd40" 1943 + dependencies = [ 1944 + "bumpalo", 1945 + "proc-macro2", 1946 + "quote", 1947 + "syn", 1948 + "wasm-bindgen-shared", 1949 + ] 1950 + 1951 + [[package]] 1952 + name = "wasm-bindgen-shared" 1953 + version = "0.2.106" 1954 + source = "registry+https://github.com/rust-lang/crates.io-index" 1955 + checksum = "cbc538057e648b67f72a982e708d485b2efa771e1ac05fec311f9f63e5800db4" 1956 + dependencies = [ 1957 + "unicode-ident", 1958 + ] 1959 + 1960 + [[package]] 1961 + name = "web-time" 1962 + version = "1.1.0" 1963 + source = "registry+https://github.com/rust-lang/crates.io-index" 1964 + checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" 1965 + dependencies = [ 1966 + "js-sys", 1967 + "wasm-bindgen", 1968 + ] 1969 + 1970 + [[package]] 1971 + name = "winapi" 1972 + version = "0.3.9" 1973 + source = "registry+https://github.com/rust-lang/crates.io-index" 1974 + checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" 1975 + dependencies = [ 1976 + "winapi-i686-pc-windows-gnu", 1977 + "winapi-x86_64-pc-windows-gnu", 1978 + ] 1979 + 1980 + [[package]] 1981 + name = "winapi-i686-pc-windows-gnu" 1982 + version = "0.4.0" 1983 + source = "registry+https://github.com/rust-lang/crates.io-index" 1984 + checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 1985 + 1986 + [[package]] 1987 + name = "winapi-x86_64-pc-windows-gnu" 1988 + version = "0.4.0" 1989 + source = "registry+https://github.com/rust-lang/crates.io-index" 1990 + checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 1991 + 1992 + [[package]] 1993 + name = "windows" 1994 + version = "0.61.3" 1995 + source = "registry+https://github.com/rust-lang/crates.io-index" 1996 + checksum = "9babd3a767a4c1aef6900409f85f5d53ce2544ccdfaa86dad48c91782c6d6893" 1997 + dependencies = [ 1998 + "windows-collections", 1999 + "windows-core", 2000 + "windows-future", 2001 + "windows-link 0.1.3", 2002 + "windows-numerics", 2003 + ] 2004 + 2005 + [[package]] 2006 + name = "windows-collections" 2007 + version = "0.2.0" 2008 + source = "registry+https://github.com/rust-lang/crates.io-index" 2009 + checksum = "3beeceb5e5cfd9eb1d76b381630e82c4241ccd0d27f1a39ed41b2760b255c5e8" 2010 + dependencies = [ 2011 + "windows-core", 2012 + ] 2013 + 2014 + [[package]] 2015 + name = "windows-core" 2016 + version = "0.61.2" 2017 + source = "registry+https://github.com/rust-lang/crates.io-index" 2018 + checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3" 2019 + dependencies = [ 2020 + "windows-implement", 2021 + "windows-interface", 2022 + "windows-link 0.1.3", 2023 + "windows-result", 2024 + "windows-strings", 2025 + ] 2026 + 2027 + [[package]] 2028 + name = "windows-future" 2029 + version = "0.2.1" 2030 + source = "registry+https://github.com/rust-lang/crates.io-index" 2031 + checksum = "fc6a41e98427b19fe4b73c550f060b59fa592d7d686537eebf9385621bfbad8e" 2032 + dependencies = [ 2033 + "windows-core", 2034 + "windows-link 0.1.3", 2035 + "windows-threading", 2036 + ] 2037 + 2038 + [[package]] 2039 + name = "windows-implement" 2040 + version = "0.60.2" 2041 + source = "registry+https://github.com/rust-lang/crates.io-index" 2042 + checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" 2043 + dependencies = [ 2044 + "proc-macro2", 2045 + "quote", 2046 + "syn", 2047 + ] 2048 + 2049 + [[package]] 2050 + name = "windows-interface" 2051 + version = "0.59.3" 2052 + source = "registry+https://github.com/rust-lang/crates.io-index" 2053 + checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" 2054 + dependencies = [ 2055 + "proc-macro2", 2056 + "quote", 2057 + "syn", 2058 + ] 2059 + 2060 + [[package]] 2061 + name = "windows-link" 2062 + version = "0.1.3" 2063 + source = "registry+https://github.com/rust-lang/crates.io-index" 2064 + checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" 2065 + 2066 + [[package]] 2067 + name = "windows-link" 2068 + version = "0.2.1" 2069 + source = "registry+https://github.com/rust-lang/crates.io-index" 2070 + checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" 2071 + 2072 + [[package]] 2073 + name = "windows-numerics" 2074 + version = "0.2.0" 2075 + source = "registry+https://github.com/rust-lang/crates.io-index" 2076 + checksum = "9150af68066c4c5c07ddc0ce30421554771e528bde427614c61038bc2c92c2b1" 2077 + dependencies = [ 2078 + "windows-core", 2079 + "windows-link 0.1.3", 2080 + ] 2081 + 2082 + [[package]] 2083 + name = "windows-result" 2084 + version = "0.3.4" 2085 + source = "registry+https://github.com/rust-lang/crates.io-index" 2086 + checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6" 2087 + dependencies = [ 2088 + "windows-link 0.1.3", 2089 + ] 2090 + 2091 + [[package]] 2092 + name = "windows-strings" 2093 + version = "0.4.2" 2094 + source = "registry+https://github.com/rust-lang/crates.io-index" 2095 + checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57" 2096 + dependencies = [ 2097 + "windows-link 0.1.3", 2098 + ] 2099 + 2100 + [[package]] 2101 + name = "windows-sys" 2102 + version = "0.60.2" 2103 + source = "registry+https://github.com/rust-lang/crates.io-index" 2104 + checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" 2105 + dependencies = [ 2106 + "windows-targets", 2107 + ] 2108 + 2109 + [[package]] 2110 + name = "windows-sys" 2111 + version = "0.61.2" 2112 + source = "registry+https://github.com/rust-lang/crates.io-index" 2113 + checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" 2114 + dependencies = [ 2115 + "windows-link 0.2.1", 2116 + ] 2117 + 2118 + [[package]] 2119 + name = "windows-targets" 2120 + version = "0.53.5" 2121 + source = "registry+https://github.com/rust-lang/crates.io-index" 2122 + checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" 2123 + dependencies = [ 2124 + "windows-link 0.2.1", 2125 + "windows_aarch64_gnullvm", 2126 + "windows_aarch64_msvc", 2127 + "windows_i686_gnu", 2128 + "windows_i686_gnullvm", 2129 + "windows_i686_msvc", 2130 + "windows_x86_64_gnu", 2131 + "windows_x86_64_gnullvm", 2132 + "windows_x86_64_msvc", 2133 + ] 2134 + 2135 + [[package]] 2136 + name = "windows-threading" 2137 + version = "0.1.0" 2138 + source = "registry+https://github.com/rust-lang/crates.io-index" 2139 + checksum = "b66463ad2e0ea3bbf808b7f1d371311c80e115c0b71d60efc142cafbcfb057a6" 2140 + dependencies = [ 2141 + "windows-link 0.1.3", 2142 + ] 2143 + 2144 + [[package]] 2145 + name = "windows_aarch64_gnullvm" 2146 + version = "0.53.1" 2147 + source = "registry+https://github.com/rust-lang/crates.io-index" 2148 + checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" 2149 + 2150 + [[package]] 2151 + name = "windows_aarch64_msvc" 2152 + version = "0.53.1" 2153 + source = "registry+https://github.com/rust-lang/crates.io-index" 2154 + checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" 2155 + 2156 + [[package]] 2157 + name = "windows_i686_gnu" 2158 + version = "0.53.1" 2159 + source = "registry+https://github.com/rust-lang/crates.io-index" 2160 + checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" 2161 + 2162 + [[package]] 2163 + name = "windows_i686_gnullvm" 2164 + version = "0.53.1" 2165 + source = "registry+https://github.com/rust-lang/crates.io-index" 2166 + checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" 2167 + 2168 + [[package]] 2169 + name = "windows_i686_msvc" 2170 + version = "0.53.1" 2171 + source = "registry+https://github.com/rust-lang/crates.io-index" 2172 + checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" 2173 + 2174 + [[package]] 2175 + name = "windows_x86_64_gnu" 2176 + version = "0.53.1" 2177 + source = "registry+https://github.com/rust-lang/crates.io-index" 2178 + checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" 2179 + 2180 + [[package]] 2181 + name = "windows_x86_64_gnullvm" 2182 + version = "0.53.1" 2183 + source = "registry+https://github.com/rust-lang/crates.io-index" 2184 + checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" 2185 + 2186 + [[package]] 2187 + name = "windows_x86_64_msvc" 2188 + version = "0.53.1" 2189 + source = "registry+https://github.com/rust-lang/crates.io-index" 2190 + checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" 2191 + 2192 + [[package]] 2193 + name = "winnow" 2194 + version = "0.7.14" 2195 + source = "registry+https://github.com/rust-lang/crates.io-index" 2196 + checksum = "5a5364e9d77fcdeeaa6062ced926ee3381faa2ee02d3eb83a5c27a8825540829" 2197 + dependencies = [ 2198 + "memchr", 2199 + ] 2200 + 2201 + [[package]] 2202 + name = "wit-bindgen" 2203 + version = "0.46.0" 2204 + source = "registry+https://github.com/rust-lang/crates.io-index" 2205 + checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59" 2206 + 2207 + [[package]] 2208 + name = "wyrand" 2209 + version = "0.3.2" 2210 + source = "registry+https://github.com/rust-lang/crates.io-index" 2211 + checksum = "15e0359b0b8d9cdef235a1fd4a8c5d02e4c9204e9fac861c14c229a8e803d1a6" 2212 + dependencies = [ 2213 + "rand_core", 2214 + ] 2215 + 2216 + [[package]] 2217 + name = "zerocopy" 2218 + version = "0.8.30" 2219 + source = "registry+https://github.com/rust-lang/crates.io-index" 2220 + checksum = "4ea879c944afe8a2b25fef16bb4ba234f47c694565e97383b36f3a878219065c" 2221 + dependencies = [ 2222 + "zerocopy-derive", 2223 + ] 2224 + 2225 + [[package]] 2226 + name = "zerocopy-derive" 2227 + version = "0.8.30" 2228 + source = "registry+https://github.com/rust-lang/crates.io-index" 2229 + checksum = "cf955aa904d6040f70dc8e9384444cb1030aed272ba3cb09bbc4ab9e7c1f34f5" 2230 + dependencies = [ 2231 + "proc-macro2", 2232 + "quote", 2233 + "syn", 2234 + ] 2235 + 2236 + [[package]] 2237 + name = "zstd" 2238 + version = "0.13.3" 2239 + source = "registry+https://github.com/rust-lang/crates.io-index" 2240 + checksum = "e91ee311a569c327171651566e07972200e76fcfe2242a4fa446149a3881c08a" 2241 + dependencies = [ 2242 + "zstd-safe", 2243 + ] 2244 + 2245 + [[package]] 2246 + name = "zstd-safe" 2247 + version = "7.2.4" 2248 + source = "registry+https://github.com/rust-lang/crates.io-index" 2249 + checksum = "8f49c4d5f0abb602a93fb8736af2a4f4dd9512e36f7f570d66e65ff867ed3b9d" 2250 + dependencies = [ 2251 + "zstd-sys", 2252 + ] 2253 + 2254 + [[package]] 2255 + name = "zstd-sys" 2256 + version = "2.0.16+zstd.1.5.7" 2257 + source = "registry+https://github.com/rust-lang/crates.io-index" 2258 + checksum = "91e19ebc2adc8f83e43039e79776e3fda8ca919132d68a1fed6a5faca2683748" 2259 + dependencies = [ 2260 + "cc", 2261 + "pkg-config", 2262 + ]
+127
Cargo.toml
··· 1 + [workspace] 2 + resolver = "3" 3 + members = ["crates/*"] 4 + 5 + [workspace.package] 6 + authors = ["Sachy.dev <sachymetsu@tutamail.com>"] 7 + edition = "2024" 8 + repository = "https://tangled.org/sachy.dev/nailpit" 9 + version = "0.1.0" 10 + license = "AGPL-3.0-only" 11 + rust-version = "1.89.0" 12 + 13 + [workspace.lints.clippy] 14 + undocumented_unsafe_blocks = "warn" 15 + 16 + [workspace.dependencies] 17 + axum = { version = "0.8.1", default-features = false, features = [ 18 + "http1", 19 + "http2", 20 + "macros", 21 + ] } 22 + axum-core = { version = "0.5.0", default-features = false } 23 + bytes = "1.10.1" 24 + hyper = { version = "1.6.0", default-features = false, features = ["server"] } 25 + color-eyre = { version = "0.6.3", default-features = false } 26 + serde = { version = "1.0.219", features = ["derive"] } 27 + rand_core = "0.9.3" 28 + rand = { version = "0.9", default-features = false } 29 + rand_distr = { version = "0.5.1" } 30 + wyrand = { version = "0.3.2" } 31 + hashbrown = { version = "0.15.2", default-features = false, features = [ 32 + "equivalent", 33 + "inline-more", 34 + ] } 35 + rapidhash = { version = "4.1.0", default-features = false } 36 + unicode-segmentation = "1.12.0" 37 + itertools = "0.14.0" 38 + indexmap = "2.9.0" 39 + parking_lot = "0.12" 40 + tokio = { version = "1.44.2", features = ["rt", "sync", "time", "parking_lot", "net", "signal"] } 41 + tokio-util = "0.7" 42 + futures-lite = "2.6.0" 43 + futures-concurrency = "7.6.3" 44 + pin-project-lite = "0.2.16" 45 + scc = "3.3.2" 46 + tracing = "0.1" 47 + tracing-opentelemetry = "0.32" 48 + tracing-futures = { version = "0.2", features = ["futures-03"] } 49 + tower = { version = "0.5.2" } 50 + tower-http = { version = "0.6.2", features = [ 51 + "normalize-path", 52 + "add-extension", 53 + "util", 54 + ] } 55 + opentelemetry = { version = "0.31.0", default-features = false, features = ["trace", "logs"] } 56 + opentelemetry-http = "0.31" 57 + opentelemetry-otlp = { version = "0.31.0", default-features = false, features = [ 58 + "trace", 59 + "logs", 60 + "grpc-tonic", 61 + "zstd-tonic", 62 + ] } 63 + opentelemetry_sdk = { version = "0.31.0", default-features = false, features = [ 64 + "trace", 65 + "logs", 66 + "rt-tokio-current-thread", 67 + "experimental_logs_batch_log_processor_with_async_runtime", 68 + "experimental_trace_batch_span_processor_with_async_runtime" 69 + ] } 70 + opentelemetry-semantic-conventions = "0.31" 71 + winnow = { version = "0.7.6", features = ["simd"] } 72 + 73 + [package] 74 + name = "nailpit" 75 + edition.workspace = true 76 + repository.workspace = true 77 + version.workspace = true 78 + authors.workspace = true 79 + rust-version.workspace = true 80 + license.workspace = true 81 + 82 + [lints] 83 + workspace = true 84 + 85 + [lib] 86 + path = "src/lib.rs" 87 + 88 + [[bin]] 89 + path = "src/main.rs" 90 + name = "nailpit" 91 + 92 + [features] 93 + default = ["mimalloc"] 94 + mimalloc = ["dep:mimalloc"] 95 + detailed_traces = ["nailgen/detailed_traces", "nailrater/detailed_traces"] 96 + 97 + [dependencies] 98 + nailkov = { path = "crates/nailkov" } 99 + nailrng = { path = "crates/nailrng" } 100 + nailconfig = { path = "crates/nailconfig" } 101 + nailstream = { path = "crates/nailstream" } 102 + nailgen = { path = "crates/nailgen" } 103 + nailrater = { path = "crates/nailrater" } 104 + nailtrace = { path = "crates/nailtrace" } 105 + nailotel = { path = "crates/nailotel" } 106 + nailstate = { path = "crates/nailstate" } 107 + nailserve = { path = "crates/nailserve" } 108 + nailip = { path = "crates/nailip" } 109 + nailroutes = { path = "crates/nailroutes" } 110 + nailspicy = { path = "crates/nailspicy" } 111 + nailnet = { path = "crates/nailnet" } 112 + nailbox = { path = "crates/nailbox" } 113 + nailrt = { path = "crates/nailrt" } 114 + axum.workspace = true 115 + tokio.workspace = true 116 + tokio-util.workspace = true 117 + tracing.workspace = true 118 + color-eyre.workspace = true 119 + glob = "0.3.2" 120 + mimalloc = { version = "0.1.48", features = ["v3"], optional = true } 121 + 122 + [profile.release] 123 + codegen-units = 1 124 + lto = "fat" 125 + debug = false 126 + panic = "abort" 127 + strip = true
+50
Dockerfile
··· 1 + FROM --platform=$BUILDPLATFORM rust:slim AS builder 2 + SHELL ["/bin/bash", "-uo", "pipefail", "-c"] 3 + 4 + RUN apt-get update -y && apt-get install -y cmake curl xz-utils tar 5 + ARG ZIG_VERSION=0.15.2 6 + RUN curl -L "https://ziglang.org/download/${ZIG_VERSION}/zig-$(uname -m)-linux-${ZIG_VERSION}.tar.xz" | tar -J -x -C /usr/local && \ 7 + ln -s "/usr/local/zig-$(uname -m)-linux-${ZIG_VERSION}/zig" /usr/local/bin/zig 8 + 9 + RUN cargo install --locked cargo-zigbuild 10 + 11 + WORKDIR /nailpit 12 + COPY ./src ./src 13 + COPY ./crates ./crates 14 + COPY ./Cargo.lock . 15 + COPY ./Cargo.toml . 16 + RUN cargo fetch --locked 17 + 18 + ARG TARGETPLATFORM 19 + 20 + # add the rust target for the target architecture 21 + RUN if [ "$TARGETPLATFORM" == "linux/amd64" ]; then echo "x86_64-unknown-linux-musl" >/.target; \ 22 + elif [ "$TARGETPLATFORM" == "linux/arm64" ]; then echo "aarch64-unknown-linux-musl" >/.target; \ 23 + elif [ "$TARGETPLATFORM" == "linux/arm/v7" ]; then echo "armv7-unknown-linux-musleabihf" >/.target; \ 24 + elif [ "$TARGETPLATFORM" == "linux/riscv64" ]; then echo "riscv64gc-unknown-linux-musl" >/.target; \ 25 + else echo "Unsupported architecture $TARGETPLATFORM"; exit 1; \ 26 + fi 27 + RUN rustup target add "$(cat /.target)" 28 + 29 + RUN if [ "$TARGETPLATFORM" == "linux/amd64" ]; then echo "-C target-cpu=x86-64-v3" >/.target-cpu; \ 30 + elif [ "$TARGETPLATFORM" == "linux/arm64" ]; then echo "-C target-cpu=cortex-a53" >/.target-cpu; \ 31 + elif [ "$TARGETPLATFORM" == "linux/arm/v7" ]; then echo "" >/.target-cpu; \ 32 + elif [ "$TARGETPLATFORM" == "linux/riscv64" ]; then echo "" >/.target-cpu; \ 33 + else echo "Unsupported architecture $TARGETPLATFORM"; exit 1; \ 34 + fi 35 + 36 + RUN RUSTFLAGS="$(cat /.target-cpu)" cargo zigbuild --release --locked --target "$(cat /.target)" && \ 37 + mv ./target/$(cat /.target)/release/nailpit . 38 + 39 + FROM gcr.io/distroless/static-debian13:latest AS runtime 40 + WORKDIR /app 41 + COPY ./defaults/pit.default.toml ./defaults/ 42 + COPY --from=builder /nailpit/nailpit . 43 + VOLUME /app/configuration 44 + VOLUME /app/input 45 + COPY ./templates/* ./templates/ 46 + VOLUME /app/templates 47 + 48 + STOPSIGNAL SIGINT 49 + 50 + ENTRYPOINT ["/app/nailpit"]
+661
LICENSE
··· 1 + GNU AFFERO GENERAL PUBLIC LICENSE 2 + Version 3, 19 November 2007 3 + 4 + Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/> 5 + Everyone is permitted to copy and distribute verbatim copies 6 + of this license document, but changing it is not allowed. 7 + 8 + Preamble 9 + 10 + The GNU Affero General Public License is a free, copyleft license for 11 + software and other kinds of works, specifically designed to ensure 12 + cooperation with the community in the case of network server software. 13 + 14 + The licenses for most software and other practical works are designed 15 + to take away your freedom to share and change the works. By contrast, 16 + our General Public Licenses are intended to guarantee your freedom to 17 + share and change all versions of a program--to make sure it remains free 18 + software for all its users. 19 + 20 + When we speak of free software, we are referring to freedom, not 21 + price. Our General Public Licenses are designed to make sure that you 22 + have the freedom to distribute copies of free software (and charge for 23 + them if you wish), that you receive source code or can get it if you 24 + want it, that you can change the software or use pieces of it in new 25 + free programs, and that you know you can do these things. 26 + 27 + Developers that use our General Public Licenses protect your rights 28 + with two steps: (1) assert copyright on the software, and (2) offer 29 + you this License which gives you legal permission to copy, distribute 30 + and/or modify the software. 31 + 32 + A secondary benefit of defending all users' freedom is that 33 + improvements made in alternate versions of the program, if they 34 + receive widespread use, become available for other developers to 35 + incorporate. Many developers of free software are heartened and 36 + encouraged by the resulting cooperation. However, in the case of 37 + software used on network servers, this result may fail to come about. 38 + The GNU General Public License permits making a modified version and 39 + letting the public access it on a server without ever releasing its 40 + source code to the public. 41 + 42 + The GNU Affero General Public License is designed specifically to 43 + ensure that, in such cases, the modified source code becomes available 44 + to the community. It requires the operator of a network server to 45 + provide the source code of the modified version running there to the 46 + users of that server. Therefore, public use of a modified version, on 47 + a publicly accessible server, gives the public access to the source 48 + code of the modified version. 49 + 50 + An older license, called the Affero General Public License and 51 + published by Affero, was designed to accomplish similar goals. This is 52 + a different license, not a version of the Affero GPL, but Affero has 53 + released a new version of the Affero GPL which permits relicensing under 54 + this license. 55 + 56 + The precise terms and conditions for copying, distribution and 57 + modification follow. 58 + 59 + TERMS AND CONDITIONS 60 + 61 + 0. Definitions. 62 + 63 + "This License" refers to version 3 of the GNU Affero General Public License. 64 + 65 + "Copyright" also means copyright-like laws that apply to other kinds of 66 + works, such as semiconductor masks. 67 + 68 + "The Program" refers to any copyrightable work licensed under this 69 + License. Each licensee is addressed as "you". "Licensees" and 70 + "recipients" may be individuals or organizations. 71 + 72 + To "modify" a work means to copy from or adapt all or part of the work 73 + in a fashion requiring copyright permission, other than the making of an 74 + exact copy. The resulting work is called a "modified version" of the 75 + earlier work or a work "based on" the earlier work. 76 + 77 + A "covered work" means either the unmodified Program or a work based 78 + on the Program. 79 + 80 + To "propagate" a work means to do anything with it that, without 81 + permission, would make you directly or secondarily liable for 82 + infringement under applicable copyright law, except executing it on a 83 + computer or modifying a private copy. Propagation includes copying, 84 + distribution (with or without modification), making available to the 85 + public, and in some countries other activities as well. 86 + 87 + To "convey" a work means any kind of propagation that enables other 88 + parties to make or receive copies. Mere interaction with a user through 89 + a computer network, with no transfer of a copy, is not conveying. 90 + 91 + An interactive user interface displays "Appropriate Legal Notices" 92 + to the extent that it includes a convenient and prominently visible 93 + feature that (1) displays an appropriate copyright notice, and (2) 94 + tells the user that there is no warranty for the work (except to the 95 + extent that warranties are provided), that licensees may convey the 96 + work under this License, and how to view a copy of this License. If 97 + the interface presents a list of user commands or options, such as a 98 + menu, a prominent item in the list meets this criterion. 99 + 100 + 1. Source Code. 101 + 102 + The "source code" for a work means the preferred form of the work 103 + for making modifications to it. "Object code" means any non-source 104 + form of a work. 105 + 106 + A "Standard Interface" means an interface that either is an official 107 + standard defined by a recognized standards body, or, in the case of 108 + interfaces specified for a particular programming language, one that 109 + is widely used among developers working in that language. 110 + 111 + The "System Libraries" of an executable work include anything, other 112 + than the work as a whole, that (a) is included in the normal form of 113 + packaging a Major Component, but which is not part of that Major 114 + Component, and (b) serves only to enable use of the work with that 115 + Major Component, or to implement a Standard Interface for which an 116 + implementation is available to the public in source code form. A 117 + "Major Component", in this context, means a major essential component 118 + (kernel, window system, and so on) of the specific operating system 119 + (if any) on which the executable work runs, or a compiler used to 120 + produce the work, or an object code interpreter used to run it. 121 + 122 + The "Corresponding Source" for a work in object code form means all 123 + the source code needed to generate, install, and (for an executable 124 + work) run the object code and to modify the work, including scripts to 125 + control those activities. However, it does not include the work's 126 + System Libraries, or general-purpose tools or generally available free 127 + programs which are used unmodified in performing those activities but 128 + which are not part of the work. For example, Corresponding Source 129 + includes interface definition files associated with source files for 130 + the work, and the source code for shared libraries and dynamically 131 + linked subprograms that the work is specifically designed to require, 132 + such as by intimate data communication or control flow between those 133 + subprograms and other parts of the work. 134 + 135 + The Corresponding Source need not include anything that users 136 + can regenerate automatically from other parts of the Corresponding 137 + Source. 138 + 139 + The Corresponding Source for a work in source code form is that 140 + same work. 141 + 142 + 2. Basic Permissions. 143 + 144 + All rights granted under this License are granted for the term of 145 + copyright on the Program, and are irrevocable provided the stated 146 + conditions are met. This License explicitly affirms your unlimited 147 + permission to run the unmodified Program. The output from running a 148 + covered work is covered by this License only if the output, given its 149 + content, constitutes a covered work. This License acknowledges your 150 + rights of fair use or other equivalent, as provided by copyright law. 151 + 152 + You may make, run and propagate covered works that you do not 153 + convey, without conditions so long as your license otherwise remains 154 + in force. You may convey covered works to others for the sole purpose 155 + of having them make modifications exclusively for you, or provide you 156 + with facilities for running those works, provided that you comply with 157 + the terms of this License in conveying all material for which you do 158 + not control copyright. Those thus making or running the covered works 159 + for you must do so exclusively on your behalf, under your direction 160 + and control, on terms that prohibit them from making any copies of 161 + your copyrighted material outside their relationship with you. 162 + 163 + Conveying under any other circumstances is permitted solely under 164 + the conditions stated below. Sublicensing is not allowed; section 10 165 + makes it unnecessary. 166 + 167 + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 + 169 + No covered work shall be deemed part of an effective technological 170 + measure under any applicable law fulfilling obligations under article 171 + 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 + similar laws prohibiting or restricting circumvention of such 173 + measures. 174 + 175 + When you convey a covered work, you waive any legal power to forbid 176 + circumvention of technological measures to the extent such circumvention 177 + is effected by exercising rights under this License with respect to 178 + the covered work, and you disclaim any intention to limit operation or 179 + modification of the work as a means of enforcing, against the work's 180 + users, your or third parties' legal rights to forbid circumvention of 181 + technological measures. 182 + 183 + 4. Conveying Verbatim Copies. 184 + 185 + You may convey verbatim copies of the Program's source code as you 186 + receive it, in any medium, provided that you conspicuously and 187 + appropriately publish on each copy an appropriate copyright notice; 188 + keep intact all notices stating that this License and any 189 + non-permissive terms added in accord with section 7 apply to the code; 190 + keep intact all notices of the absence of any warranty; and give all 191 + recipients a copy of this License along with the Program. 192 + 193 + You may charge any price or no price for each copy that you convey, 194 + and you may offer support or warranty protection for a fee. 195 + 196 + 5. Conveying Modified Source Versions. 197 + 198 + You may convey a work based on the Program, or the modifications to 199 + produce it from the Program, in the form of source code under the 200 + terms of section 4, provided that you also meet all of these conditions: 201 + 202 + a) The work must carry prominent notices stating that you modified 203 + it, and giving a relevant date. 204 + 205 + b) The work must carry prominent notices stating that it is 206 + released under this License and any conditions added under section 207 + 7. This requirement modifies the requirement in section 4 to 208 + "keep intact all notices". 209 + 210 + c) You must license the entire work, as a whole, under this 211 + License to anyone who comes into possession of a copy. This 212 + License will therefore apply, along with any applicable section 7 213 + additional terms, to the whole of the work, and all its parts, 214 + regardless of how they are packaged. This License gives no 215 + permission to license the work in any other way, but it does not 216 + invalidate such permission if you have separately received it. 217 + 218 + d) If the work has interactive user interfaces, each must display 219 + Appropriate Legal Notices; however, if the Program has interactive 220 + interfaces that do not display Appropriate Legal Notices, your 221 + work need not make them do so. 222 + 223 + A compilation of a covered work with other separate and independent 224 + works, which are not by their nature extensions of the covered work, 225 + and which are not combined with it such as to form a larger program, 226 + in or on a volume of a storage or distribution medium, is called an 227 + "aggregate" if the compilation and its resulting copyright are not 228 + used to limit the access or legal rights of the compilation's users 229 + beyond what the individual works permit. Inclusion of a covered work 230 + in an aggregate does not cause this License to apply to the other 231 + parts of the aggregate. 232 + 233 + 6. Conveying Non-Source Forms. 234 + 235 + You may convey a covered work in object code form under the terms 236 + of sections 4 and 5, provided that you also convey the 237 + machine-readable Corresponding Source under the terms of this License, 238 + in one of these ways: 239 + 240 + a) Convey the object code in, or embodied in, a physical product 241 + (including a physical distribution medium), accompanied by the 242 + Corresponding Source fixed on a durable physical medium 243 + customarily used for software interchange. 244 + 245 + b) Convey the object code in, or embodied in, a physical product 246 + (including a physical distribution medium), accompanied by a 247 + written offer, valid for at least three years and valid for as 248 + long as you offer spare parts or customer support for that product 249 + model, to give anyone who possesses the object code either (1) a 250 + copy of the Corresponding Source for all the software in the 251 + product that is covered by this License, on a durable physical 252 + medium customarily used for software interchange, for a price no 253 + more than your reasonable cost of physically performing this 254 + conveying of source, or (2) access to copy the 255 + Corresponding Source from a network server at no charge. 256 + 257 + c) Convey individual copies of the object code with a copy of the 258 + written offer to provide the Corresponding Source. This 259 + alternative is allowed only occasionally and noncommercially, and 260 + only if you received the object code with such an offer, in accord 261 + with subsection 6b. 262 + 263 + d) Convey the object code by offering access from a designated 264 + place (gratis or for a charge), and offer equivalent access to the 265 + Corresponding Source in the same way through the same place at no 266 + further charge. You need not require recipients to copy the 267 + Corresponding Source along with the object code. If the place to 268 + copy the object code is a network server, the Corresponding Source 269 + may be on a different server (operated by you or a third party) 270 + that supports equivalent copying facilities, provided you maintain 271 + clear directions next to the object code saying where to find the 272 + Corresponding Source. Regardless of what server hosts the 273 + Corresponding Source, you remain obligated to ensure that it is 274 + available for as long as needed to satisfy these requirements. 275 + 276 + e) Convey the object code using peer-to-peer transmission, provided 277 + you inform other peers where the object code and Corresponding 278 + Source of the work are being offered to the general public at no 279 + charge under subsection 6d. 280 + 281 + A separable portion of the object code, whose source code is excluded 282 + from the Corresponding Source as a System Library, need not be 283 + included in conveying the object code work. 284 + 285 + A "User Product" is either (1) a "consumer product", which means any 286 + tangible personal property which is normally used for personal, family, 287 + or household purposes, or (2) anything designed or sold for incorporation 288 + into a dwelling. In determining whether a product is a consumer product, 289 + doubtful cases shall be resolved in favor of coverage. For a particular 290 + product received by a particular user, "normally used" refers to a 291 + typical or common use of that class of product, regardless of the status 292 + of the particular user or of the way in which the particular user 293 + actually uses, or expects or is expected to use, the product. A product 294 + is a consumer product regardless of whether the product has substantial 295 + commercial, industrial or non-consumer uses, unless such uses represent 296 + the only significant mode of use of the product. 297 + 298 + "Installation Information" for a User Product means any methods, 299 + procedures, authorization keys, or other information required to install 300 + and execute modified versions of a covered work in that User Product from 301 + a modified version of its Corresponding Source. The information must 302 + suffice to ensure that the continued functioning of the modified object 303 + code is in no case prevented or interfered with solely because 304 + modification has been made. 305 + 306 + If you convey an object code work under this section in, or with, or 307 + specifically for use in, a User Product, and the conveying occurs as 308 + part of a transaction in which the right of possession and use of the 309 + User Product is transferred to the recipient in perpetuity or for a 310 + fixed term (regardless of how the transaction is characterized), the 311 + Corresponding Source conveyed under this section must be accompanied 312 + by the Installation Information. But this requirement does not apply 313 + if neither you nor any third party retains the ability to install 314 + modified object code on the User Product (for example, the work has 315 + been installed in ROM). 316 + 317 + The requirement to provide Installation Information does not include a 318 + requirement to continue to provide support service, warranty, or updates 319 + for a work that has been modified or installed by the recipient, or for 320 + the User Product in which it has been modified or installed. Access to a 321 + network may be denied when the modification itself materially and 322 + adversely affects the operation of the network or violates the rules and 323 + protocols for communication across the network. 324 + 325 + Corresponding Source conveyed, and Installation Information provided, 326 + in accord with this section must be in a format that is publicly 327 + documented (and with an implementation available to the public in 328 + source code form), and must require no special password or key for 329 + unpacking, reading or copying. 330 + 331 + 7. Additional Terms. 332 + 333 + "Additional permissions" are terms that supplement the terms of this 334 + License by making exceptions from one or more of its conditions. 335 + Additional permissions that are applicable to the entire Program shall 336 + be treated as though they were included in this License, to the extent 337 + that they are valid under applicable law. If additional permissions 338 + apply only to part of the Program, that part may be used separately 339 + under those permissions, but the entire Program remains governed by 340 + this License without regard to the additional permissions. 341 + 342 + When you convey a copy of a covered work, you may at your option 343 + remove any additional permissions from that copy, or from any part of 344 + it. (Additional permissions may be written to require their own 345 + removal in certain cases when you modify the work.) You may place 346 + additional permissions on material, added by you to a covered work, 347 + for which you have or can give appropriate copyright permission. 348 + 349 + Notwithstanding any other provision of this License, for material you 350 + add to a covered work, you may (if authorized by the copyright holders of 351 + that material) supplement the terms of this License with terms: 352 + 353 + a) Disclaiming warranty or limiting liability differently from the 354 + terms of sections 15 and 16 of this License; or 355 + 356 + b) Requiring preservation of specified reasonable legal notices or 357 + author attributions in that material or in the Appropriate Legal 358 + Notices displayed by works containing it; or 359 + 360 + c) Prohibiting misrepresentation of the origin of that material, or 361 + requiring that modified versions of such material be marked in 362 + reasonable ways as different from the original version; or 363 + 364 + d) Limiting the use for publicity purposes of names of licensors or 365 + authors of the material; or 366 + 367 + e) Declining to grant rights under trademark law for use of some 368 + trade names, trademarks, or service marks; or 369 + 370 + f) Requiring indemnification of licensors and authors of that 371 + material by anyone who conveys the material (or modified versions of 372 + it) with contractual assumptions of liability to the recipient, for 373 + any liability that these contractual assumptions directly impose on 374 + those licensors and authors. 375 + 376 + All other non-permissive additional terms are considered "further 377 + restrictions" within the meaning of section 10. If the Program as you 378 + received it, or any part of it, contains a notice stating that it is 379 + governed by this License along with a term that is a further 380 + restriction, you may remove that term. If a license document contains 381 + a further restriction but permits relicensing or conveying under this 382 + License, you may add to a covered work material governed by the terms 383 + of that license document, provided that the further restriction does 384 + not survive such relicensing or conveying. 385 + 386 + If you add terms to a covered work in accord with this section, you 387 + must place, in the relevant source files, a statement of the 388 + additional terms that apply to those files, or a notice indicating 389 + where to find the applicable terms. 390 + 391 + Additional terms, permissive or non-permissive, may be stated in the 392 + form of a separately written license, or stated as exceptions; 393 + the above requirements apply either way. 394 + 395 + 8. Termination. 396 + 397 + You may not propagate or modify a covered work except as expressly 398 + provided under this License. Any attempt otherwise to propagate or 399 + modify it is void, and will automatically terminate your rights under 400 + this License (including any patent licenses granted under the third 401 + paragraph of section 11). 402 + 403 + However, if you cease all violation of this License, then your 404 + license from a particular copyright holder is reinstated (a) 405 + provisionally, unless and until the copyright holder explicitly and 406 + finally terminates your license, and (b) permanently, if the copyright 407 + holder fails to notify you of the violation by some reasonable means 408 + prior to 60 days after the cessation. 409 + 410 + Moreover, your license from a particular copyright holder is 411 + reinstated permanently if the copyright holder notifies you of the 412 + violation by some reasonable means, this is the first time you have 413 + received notice of violation of this License (for any work) from that 414 + copyright holder, and you cure the violation prior to 30 days after 415 + your receipt of the notice. 416 + 417 + Termination of your rights under this section does not terminate the 418 + licenses of parties who have received copies or rights from you under 419 + this License. If your rights have been terminated and not permanently 420 + reinstated, you do not qualify to receive new licenses for the same 421 + material under section 10. 422 + 423 + 9. Acceptance Not Required for Having Copies. 424 + 425 + You are not required to accept this License in order to receive or 426 + run a copy of the Program. Ancillary propagation of a covered work 427 + occurring solely as a consequence of using peer-to-peer transmission 428 + to receive a copy likewise does not require acceptance. However, 429 + nothing other than this License grants you permission to propagate or 430 + modify any covered work. These actions infringe copyright if you do 431 + not accept this License. Therefore, by modifying or propagating a 432 + covered work, you indicate your acceptance of this License to do so. 433 + 434 + 10. Automatic Licensing of Downstream Recipients. 435 + 436 + Each time you convey a covered work, the recipient automatically 437 + receives a license from the original licensors, to run, modify and 438 + propagate that work, subject to this License. You are not responsible 439 + for enforcing compliance by third parties with this License. 440 + 441 + An "entity transaction" is a transaction transferring control of an 442 + organization, or substantially all assets of one, or subdividing an 443 + organization, or merging organizations. If propagation of a covered 444 + work results from an entity transaction, each party to that 445 + transaction who receives a copy of the work also receives whatever 446 + licenses to the work the party's predecessor in interest had or could 447 + give under the previous paragraph, plus a right to possession of the 448 + Corresponding Source of the work from the predecessor in interest, if 449 + the predecessor has it or can get it with reasonable efforts. 450 + 451 + You may not impose any further restrictions on the exercise of the 452 + rights granted or affirmed under this License. For example, you may 453 + not impose a license fee, royalty, or other charge for exercise of 454 + rights granted under this License, and you may not initiate litigation 455 + (including a cross-claim or counterclaim in a lawsuit) alleging that 456 + any patent claim is infringed by making, using, selling, offering for 457 + sale, or importing the Program or any portion of it. 458 + 459 + 11. Patents. 460 + 461 + A "contributor" is a copyright holder who authorizes use under this 462 + License of the Program or a work on which the Program is based. The 463 + work thus licensed is called the contributor's "contributor version". 464 + 465 + A contributor's "essential patent claims" are all patent claims 466 + owned or controlled by the contributor, whether already acquired or 467 + hereafter acquired, that would be infringed by some manner, permitted 468 + by this License, of making, using, or selling its contributor version, 469 + but do not include claims that would be infringed only as a 470 + consequence of further modification of the contributor version. For 471 + purposes of this definition, "control" includes the right to grant 472 + patent sublicenses in a manner consistent with the requirements of 473 + this License. 474 + 475 + Each contributor grants you a non-exclusive, worldwide, royalty-free 476 + patent license under the contributor's essential patent claims, to 477 + make, use, sell, offer for sale, import and otherwise run, modify and 478 + propagate the contents of its contributor version. 479 + 480 + In the following three paragraphs, a "patent license" is any express 481 + agreement or commitment, however denominated, not to enforce a patent 482 + (such as an express permission to practice a patent or covenant not to 483 + sue for patent infringement). To "grant" such a patent license to a 484 + party means to make such an agreement or commitment not to enforce a 485 + patent against the party. 486 + 487 + If you convey a covered work, knowingly relying on a patent license, 488 + and the Corresponding Source of the work is not available for anyone 489 + to copy, free of charge and under the terms of this License, through a 490 + publicly available network server or other readily accessible means, 491 + then you must either (1) cause the Corresponding Source to be so 492 + available, or (2) arrange to deprive yourself of the benefit of the 493 + patent license for this particular work, or (3) arrange, in a manner 494 + consistent with the requirements of this License, to extend the patent 495 + license to downstream recipients. "Knowingly relying" means you have 496 + actual knowledge that, but for the patent license, your conveying the 497 + covered work in a country, or your recipient's use of the covered work 498 + in a country, would infringe one or more identifiable patents in that 499 + country that you have reason to believe are valid. 500 + 501 + If, pursuant to or in connection with a single transaction or 502 + arrangement, you convey, or propagate by procuring conveyance of, a 503 + covered work, and grant a patent license to some of the parties 504 + receiving the covered work authorizing them to use, propagate, modify 505 + or convey a specific copy of the covered work, then the patent license 506 + you grant is automatically extended to all recipients of the covered 507 + work and works based on it. 508 + 509 + A patent license is "discriminatory" if it does not include within 510 + the scope of its coverage, prohibits the exercise of, or is 511 + conditioned on the non-exercise of one or more of the rights that are 512 + specifically granted under this License. You may not convey a covered 513 + work if you are a party to an arrangement with a third party that is 514 + in the business of distributing software, under which you make payment 515 + to the third party based on the extent of your activity of conveying 516 + the work, and under which the third party grants, to any of the 517 + parties who would receive the covered work from you, a discriminatory 518 + patent license (a) in connection with copies of the covered work 519 + conveyed by you (or copies made from those copies), or (b) primarily 520 + for and in connection with specific products or compilations that 521 + contain the covered work, unless you entered into that arrangement, 522 + or that patent license was granted, prior to 28 March 2007. 523 + 524 + Nothing in this License shall be construed as excluding or limiting 525 + any implied license or other defenses to infringement that may 526 + otherwise be available to you under applicable patent law. 527 + 528 + 12. No Surrender of Others' Freedom. 529 + 530 + If conditions are imposed on you (whether by court order, agreement or 531 + otherwise) that contradict the conditions of this License, they do not 532 + excuse you from the conditions of this License. If you cannot convey a 533 + covered work so as to satisfy simultaneously your obligations under this 534 + License and any other pertinent obligations, then as a consequence you may 535 + not convey it at all. For example, if you agree to terms that obligate you 536 + to collect a royalty for further conveying from those to whom you convey 537 + the Program, the only way you could satisfy both those terms and this 538 + License would be to refrain entirely from conveying the Program. 539 + 540 + 13. Remote Network Interaction; Use with the GNU General Public License. 541 + 542 + Notwithstanding any other provision of this License, if you modify the 543 + Program, your modified version must prominently offer all users 544 + interacting with it remotely through a computer network (if your version 545 + supports such interaction) an opportunity to receive the Corresponding 546 + Source of your version by providing access to the Corresponding Source 547 + from a network server at no charge, through some standard or customary 548 + means of facilitating copying of software. This Corresponding Source 549 + shall include the Corresponding Source for any work covered by version 3 550 + of the GNU General Public License that is incorporated pursuant to the 551 + following paragraph. 552 + 553 + Notwithstanding any other provision of this License, you have 554 + permission to link or combine any covered work with a work licensed 555 + under version 3 of the GNU General Public License into a single 556 + combined work, and to convey the resulting work. The terms of this 557 + License will continue to apply to the part which is the covered work, 558 + but the work with which it is combined will remain governed by version 559 + 3 of the GNU General Public License. 560 + 561 + 14. Revised Versions of this License. 562 + 563 + The Free Software Foundation may publish revised and/or new versions of 564 + the GNU Affero General Public License from time to time. Such new versions 565 + will be similar in spirit to the present version, but may differ in detail to 566 + address new problems or concerns. 567 + 568 + Each version is given a distinguishing version number. If the 569 + Program specifies that a certain numbered version of the GNU Affero General 570 + Public License "or any later version" applies to it, you have the 571 + option of following the terms and conditions either of that numbered 572 + version or of any later version published by the Free Software 573 + Foundation. If the Program does not specify a version number of the 574 + GNU Affero General Public License, you may choose any version ever published 575 + by the Free Software Foundation. 576 + 577 + If the Program specifies that a proxy can decide which future 578 + versions of the GNU Affero General Public License can be used, that proxy's 579 + public statement of acceptance of a version permanently authorizes you 580 + to choose that version for the Program. 581 + 582 + Later license versions may give you additional or different 583 + permissions. However, no additional obligations are imposed on any 584 + author or copyright holder as a result of your choosing to follow a 585 + later version. 586 + 587 + 15. Disclaimer of Warranty. 588 + 589 + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 + APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 + HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 + OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 + THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 + PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 + IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 + ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 + 598 + 16. Limitation of Liability. 599 + 600 + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 + WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 + THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 + GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 + USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 + DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 + PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 + EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 + SUCH DAMAGES. 609 + 610 + 17. Interpretation of Sections 15 and 16. 611 + 612 + If the disclaimer of warranty and limitation of liability provided 613 + above cannot be given local legal effect according to their terms, 614 + reviewing courts shall apply local law that most closely approximates 615 + an absolute waiver of all civil liability in connection with the 616 + Program, unless a warranty or assumption of liability accompanies a 617 + copy of the Program in return for a fee. 618 + 619 + END OF TERMS AND CONDITIONS 620 + 621 + How to Apply These Terms to Your New Programs 622 + 623 + If you develop a new program, and you want it to be of the greatest 624 + possible use to the public, the best way to achieve this is to make it 625 + free software which everyone can redistribute and change under these terms. 626 + 627 + To do so, attach the following notices to the program. It is safest 628 + to attach them to the start of each source file to most effectively 629 + state the exclusion of warranty; and each file should have at least 630 + the "copyright" line and a pointer to where the full notice is found. 631 + 632 + Nailpit - A Pit full of Rusty Nails 633 + Copyright (C) 2025 Sachy.dev 634 + 635 + This program is free software: you can redistribute it and/or modify 636 + it under the terms of the GNU Affero General Public License as published 637 + by the Free Software Foundation, either version 3 of the License, or 638 + (at your option) any later version. 639 + 640 + This program is distributed in the hope that it will be useful, 641 + but WITHOUT ANY WARRANTY; without even the implied warranty of 642 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 + GNU Affero General Public License for more details. 644 + 645 + You should have received a copy of the GNU Affero General Public License 646 + along with this program. If not, see <https://www.gnu.org/licenses/>. 647 + 648 + Also add information on how to contact you by electronic and paper mail. 649 + 650 + If your software can interact with users remotely through a computer 651 + network, you should also make sure that it provides a way for users to 652 + get its source. For example, if your program is a web application, its 653 + interface could display a "Source" link that leads users to an archive 654 + of the code. There are many ways you could offer source, and different 655 + solutions will be better for different programs; see section 13 for the 656 + specific requirements. 657 + 658 + You should also get your employer (if you work as a programmer) or school, 659 + if any, to sign a "copyright disclaimer" for the program, if necessary. 660 + For more information on this, and how to apply and follow the GNU AGPL, see 661 + <https://www.gnu.org/licenses/>.
+64
README.md
··· 1 + # Nailpit 2 + 3 + Send Malicious Scrapers into an equally malicious tarpit with added rusty nails. Nailpit is an exercise in offensive security, in which malicious actors (in this case, web scrapers) are targeted and have their resources wasted/attacked. The purpose is to use this against scrapers that *ignore* one's `robots.txt` file and any `Disallow` directives, particularly ones that try to scrape private/non-public sections of one's websites/services. In doing so and with enough volume, such scrapers can constitute an effective DoS attack. *This is bad*. Therefore, this project aims to contribute another tool in making sure such misbehaving scrapers are discouraged from targeting your website by inundating them with garbage and poisoned content. 4 + 5 + ## Disclaimer 6 + 7 + Nailpit is intended to not be exposed to the public, only to bots/scrapers. Any link into the tarpit should be hidden to users, and the initial entry point for Nailpit is a disclaimer as well. This project is not responsible for misconfigured deployments or consequences relating to that. You are responsible for ensuring this is deployed correctly and employed against only agents that are ignoring widely used and accepted web standards such as `robots.txt`. 8 + 9 + ## Minimum CPU Support 10 + 11 + For x86_64/amd64 processors, processors that at least qualify for x86-64-v3 level (so supporting AVX2), and for aarch64, processors from the A53 onwards (with NEON support, so Raspberry PI 3 B+). armv7 and RISCV64 are compiled without instruction optimisations. 12 + 13 + ## How to use / deploy 14 + 15 + By default, `nailpit` won't work unless you provide at least *some* input data. In the directory you are running `nailpit` from, create an `input` directory and add a `.txt` file inside of it. Name it anything, whatever, like `first.txt`. In this file, add in content/text, the more the better, as this will train the markov chain on what to generate. So for example, add many paragraphs of lorem ipsum text to the file just to see it work. Once you have at least *one* txt input, `nailpit` will be able to run. Multiple `.txt` files will act as different markov chains, each one outputting differently structured text to the other, and each time a generated page is requested, these chains are selected at random to produce content for that request. So if you want more varied/randomised content, you want not just very large text files of pure text/content, but also many different files. Do keep in mind that the more content and files you use, the bigger the memory usage of the application, though this is kept in check with some memory optimisation techniques. 16 + 17 + The input text files should be pure text. It should not be html or markdown or any other format, just text. 18 + 19 + ### Docker 20 + 21 + The easiest way to run `nailpit` is to run it in a docker container. This makes it fairly easy to deploy and ensures its running environment is consistent. This does add *a bit more* overhead, but realistically, not enough to really matter. 22 + 23 + If building the image directly from this repo, just use `docker build . -t nailpit`, or if cross-compiling to a different platform like a Raspberry Pi 5, run `docker build --platform=linux/arm64 .`. `nailpit` docker image supports `linux/amd64`, `linux/arm64`, `linux/arm/v7` and `linux/riscv64` platforms. Running the image then becomes the following (with two volumes provided for user overrides): 24 + 25 + ``` 26 + docker run -v ./configuration/:/app/configuration -v ./input/:/app/input -p 3001:3001/tcp nailpit:latest 27 + ``` 28 + 29 + The socket `nailpit` listens to can be overridden with `-e NAILPIT_SOCKET=0.0.0.0:3001`, and it expects the full ip:port string. There's three volumes to be configured, one for `/app/configuration` which is where the default config file lives and will be where your override config file will live, one for `/app/input` which is where the user's input files are located, and the last `/app/templates` for user provided template overrides. 30 + 31 + #### Docker Compose 32 + 33 + `nailpit` images are available from docker hub via [`docker.io/sachymetsu/nailpit:latest`](https://hub.docker.com/r/sachymetsu/nailpit). Right now, only the latest tag is provided, but these should be stable enough. Using `nailpit` with docker compose can be done with the following example configuration: 34 + 35 + ```yml 36 + services: 37 + nailpit: 38 + container_name: nailpit 39 + image: docker.io/sachymetsu/nailpit:latest 40 + restart: unless-stopped 41 + volumes: 42 + - /home/user/nailpit/configuration:/app/configuration 43 + - /home/user/nailpit/input:/app/input 44 + - /home/user/nailpit/templates:/app/templates 45 + network_mode: host 46 + ``` 47 + 48 + Images are currently provided for `linux/amd64` and `linux/arm64` platforms. 49 + 50 + ### Configuration 51 + 52 + All of the configuration options are documented in the default config file found [here](./defaults/pit.default.toml). To create your own configuration, create a `pit.toml` file in the configuration folder and add just the configuration options you want to override. 53 + 54 + ## How to contribute 55 + 56 + If you are interested in contributing to this project, check out the [CONTRIBUTING document](CONTRIBUTING.md). 57 + 58 + ## Code of Conduct 59 + 60 + If you are interested in contributing to this project, be sure to review the [CODE OF CONDUCT](CODE_OF_CONDUCT.md). 61 + 62 + ## License 63 + 64 + This project is licensed under AGPL 3.0.
+13
crates/nailbox/Cargo.toml
··· 1 + [package] 2 + name = "nailbox" 3 + authors.workspace = true 4 + edition.workspace = true 5 + repository.workspace = true 6 + version.workspace = true 7 + license.workspace = true 8 + rust-version.workspace = true 9 + 10 + [dependencies] 11 + 12 + [lints] 13 + workspace = true
+86
crates/nailbox/src/lib.rs
··· 1 + //! Utility crate for deferred initialisation of allocated containers, to lessen stack pressure 2 + //! and initialise values directly on the heap. Rust _does_ optimise boxing to not require the 3 + //! stack and can initialise directly to the heap, but this does not occur all the time. These 4 + //! utils ensure this does happen, by deferring the initialisation of the allocation explicitly. 5 + 6 + use core::pin::Pin; 7 + use std::sync::Arc; 8 + 9 + /// Util for deferred initialisation of boxed futures, to lessen stack pressure and initialise 10 + /// the future directly on the heap 11 + #[inline] 12 + pub fn boxed_future_within<'a, T, F, Fut>(fut: F) -> Pin<Box<Fut>> 13 + where 14 + Fut: Future<Output = T> + Send + 'a, 15 + F: FnOnce() -> Fut, 16 + { 17 + let mut boxed = Box::new_uninit(); 18 + 19 + boxed.write(fut()); 20 + 21 + // SAFETY: We have initialised the Box correctly by writing to 22 + // the memory in the line above. 23 + unsafe { Box::into_pin(boxed.assume_init()) } 24 + } 25 + 26 + #[inline(always)] 27 + pub fn try_arc_within<T, F, E>(f: F) -> Result<Arc<T>, E> 28 + where 29 + F: FnOnce() -> Result<T, E>, 30 + { 31 + let mut arced = Arc::new_uninit(); 32 + 33 + Arc::get_mut(&mut arced).unwrap().write(f()?); 34 + 35 + // SAFETY: We have initialised the Arc correctly by writing to 36 + // the memory in the line above. 37 + Ok(unsafe { arced.assume_init() }) 38 + } 39 + 40 + #[inline(always)] 41 + pub fn arc_within<T, F>(f: F) -> Arc<T> 42 + where 43 + F: FnOnce() -> T, 44 + { 45 + let mut arced = Arc::new_uninit(); 46 + 47 + Arc::get_mut(&mut arced).unwrap().write(f()); 48 + 49 + // SAFETY: We have initialised the Arc correctly by writing to 50 + // the memory in the line above. 51 + unsafe { arced.assume_init() } 52 + } 53 + 54 + #[cfg(test)] 55 + mod tests { 56 + use super::*; 57 + 58 + #[test] 59 + fn boxed_futures() { 60 + let boxed = boxed_future_within(async || 42); 61 + 62 + assert_eq!(size_of_val(&boxed), 8); 63 + } 64 + 65 + #[test] 66 + fn arc_init() { 67 + let arced = arc_within(|| 128u128); 68 + 69 + assert_ne!(size_of_val(&arced), 16); 70 + assert_eq!(*arced, 128); 71 + } 72 + 73 + #[test] 74 + fn try_arc_init() { 75 + #[derive(Debug, PartialEq, Eq)] 76 + struct Errored; 77 + 78 + let arced: Result<Arc<u128>, Errored> = try_arc_within(|| Ok(128u128)); 79 + 80 + assert_eq!(*arced.unwrap(), 128); 81 + 82 + let arced: Result<Arc<u128>, Errored> = try_arc_within(|| Err(Errored)); 83 + 84 + assert_eq!(arced, Err(Errored)); 85 + } 86 + }
+17
crates/nailconfig/Cargo.toml
··· 1 + [package] 2 + name = "nailconfig" 3 + authors.workspace = true 4 + edition.workspace = true 5 + repository.workspace = true 6 + version.workspace = true 7 + license.workspace = true 8 + rust-version.workspace = true 9 + 10 + [lints] 11 + workspace = true 12 + 13 + [dependencies] 14 + serde.workspace = true 15 + nailbox = { path = "../nailbox" } 16 + config = { version = "0.15.11", default-features = false, features = ["toml"] } 17 + color-eyre.workspace = true
+135
crates/nailconfig/src/lib.rs
··· 1 + //! Crate for defining and handling `nailpit` configuration. Defines the main 2 + //! [`NailConfig`] struct, as well as the utility method to derive the config object 3 + //! from various `toml` files. 4 + 5 + use core::num::NonZero; 6 + use std::{ops::Deref, sync::Arc}; 7 + 8 + use color_eyre::{Result, eyre::Context}; 9 + use nailbox::try_arc_within; 10 + 11 + #[derive(Debug, serde::Serialize, serde::Deserialize)] 12 + pub struct NailConfig { 13 + pub server: ServerConfig, 14 + pub generator: GeneratorConfig, 15 + #[serde(default)] 16 + pub rate_limiting: RateLimitingConfig, 17 + pub open_telemetry: OpenTelemetryConfig, 18 + } 19 + 20 + #[derive(Default, serde::Serialize, serde::Deserialize)] 21 + pub struct PromptsList(Vec<String>); 22 + 23 + impl std::fmt::Debug for PromptsList { 24 + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 25 + f.debug_tuple("PromptsList").finish_non_exhaustive() 26 + } 27 + } 28 + 29 + impl Deref for PromptsList { 30 + type Target = [String]; 31 + 32 + fn deref(&self) -> &Self::Target { 33 + &self.0 34 + } 35 + } 36 + 37 + #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] 38 + pub struct ServerConfig { 39 + pub pit_routes: Vec<String>, 40 + pub socket_addr: String, 41 + pub worker_threads: NonZero<usize>, 42 + } 43 + 44 + #[derive(Debug, serde::Serialize, serde::Deserialize)] 45 + pub struct GeneratorConfig { 46 + #[serde(default)] 47 + pub prompts: PromptsList, 48 + pub warning_template: String, 49 + pub generated_template: String, 50 + pub warning_message: String, 51 + pub input_files: String, 52 + pub min_paragraph_size: usize, 53 + pub max_paragraph_size: Option<usize>, 54 + pub payload_size: usize, 55 + pub timeout: u64, 56 + pub min_delay: u64, 57 + pub max_delay: Option<u64>, 58 + pub chunk_size: usize, 59 + pub header_size: usize, 60 + pub max_pit_links: usize, 61 + } 62 + 63 + #[derive(Debug, Default, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)] 64 + #[serde(tag = "mode")] 65 + pub enum DropBehavior { 66 + #[default] 67 + #[serde(rename = "normal")] 68 + Normal, 69 + #[serde(rename = "spicy")] 70 + Spicy { payload: Vec<String> }, 71 + } 72 + 73 + impl DropBehavior { 74 + pub fn is_spicy(&self) -> bool { 75 + matches!(self, Self::Spicy { .. }) 76 + } 77 + } 78 + 79 + #[derive(Debug, Default, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)] 80 + #[serde(tag = "type")] 81 + pub enum RateLimitingConfig { 82 + #[default] 83 + #[serde(rename = "no_limit")] 84 + NoLimit, 85 + #[serde(rename = "soft_limit")] 86 + SoftLimit { soft_limit: u64, soft_delay: u64 }, 87 + #[serde(rename = "hard_limit")] 88 + HardLimit { 89 + hard_limit: u64, 90 + drop_behavior: DropBehavior, 91 + }, 92 + #[serde(rename = "soft_with_hard_limit")] 93 + SoftWithHardLimit { 94 + soft_limit: u64, 95 + hard_limit: u64, 96 + soft_delay: u64, 97 + drop_behavior: DropBehavior, 98 + }, 99 + } 100 + 101 + #[derive(Debug, serde::Serialize, serde::Deserialize)] 102 + pub struct OpenTelemetryConfig { 103 + pub endpoint: String, 104 + pub service_name: String, 105 + pub logs: bool, 106 + pub traces: bool, 107 + } 108 + 109 + pub fn get_configuration() -> Result<Arc<NailConfig>> { 110 + let socket_addr = std::env::var("NAILPIT_SOCKET").ok(); 111 + 112 + let working_dir = std::env::current_dir()?; 113 + 114 + let config_dir = working_dir.join("configuration"); 115 + let default_dir = working_dir.join("defaults"); 116 + 117 + let config = config::Config::builder() 118 + .add_source( 119 + config::File::from(default_dir.join("pit.default.toml")) 120 + .format(config::FileFormat::Toml), 121 + ) 122 + .add_source( 123 + config::File::from(config_dir.join("pit.toml")) 124 + .required(false) 125 + .format(config::FileFormat::Toml), 126 + ) 127 + .set_override_option("server.socket_addr", socket_addr)? 128 + .build() 129 + .context("Unable to read configuration files")?; 130 + 131 + let config = try_arc_within(|| config.try_deserialize()) 132 + .context("Failed to load configuration. Maybe the format is invalid")?; 133 + 134 + Ok(config) 135 + }
+17
crates/nailfv/Cargo.toml
··· 1 + [package] 2 + name = "nailfv" 3 + authors.workspace = true 4 + edition.workspace = true 5 + repository.workspace = true 6 + version.workspace = true 7 + license.workspace = true 8 + rust-version.workspace = true 9 + 10 + [lints] 11 + workspace = true 12 + 13 + [dependencies] 14 + winnow.workspace = true 15 + 16 + [dev-dependencies] 17 + color-eyre.workspace = true
+101
crates/nailfv/src/lib.rs
··· 1 + //! Crate for parsing `Forwarded` header values, mostly only caring about the first (remotest) 2 + //! `for=` value. Supports both IPv6 and IPv4 and is case insensitive. 3 + 4 + use winnow::{ 5 + ModalResult, 6 + ascii::{Caseless, space0}, 7 + combinator::alt, 8 + stream::Stream, 9 + token::{literal, rest, take_until}, 10 + }; 11 + 12 + pub use winnow::Parser; 13 + 14 + /// Check if a header value string begins with `for=`, in order to 15 + /// determine whether it is a valid value for a Forwarded header, and 16 + /// is a part that we are interested in. 17 + fn match_for<'s>(prefix: &mut &'s str) -> ModalResult<&'s str> { 18 + Caseless("for=").parse_next(prefix) 19 + } 20 + 21 + /// Extracts the IPv6 address from the identifier string. Expects the format 22 + /// `"[::1]:8080"`. IPv6 addresses in the Forwarded header are always wrapped in `"`, 23 + /// with the address component wrapped in square brackets. The port component `:8080` 24 + /// may or may not be present in the identifier. 25 + fn extract_ipv6(identifier: &mut &str) -> ModalResult<Box<str>> { 26 + literal('"').parse_next(identifier)?; 27 + take_until(0.., '"').map(Into::into).parse_next(identifier) 28 + } 29 + 30 + /// Extracts the IPv4 address from the identifier string. Expects the format 31 + /// `192.168.0.1:8080`. IPv4 addresses are not wrapped with `"` in contrast to IPv6 32 + /// addresses. The port component `:8080` may or may not be present in the identifier. 33 + fn extract_ipv4(identifier: &mut &str) -> ModalResult<Box<str>> { 34 + rest.map(Into::into).parse_next(identifier) 35 + } 36 + 37 + /// Extracts the identifier from the Forwarded for value. Attempts to parse the identifier part 38 + /// as either an IPv6 address or IPv4 address. The Forwarded for format supports more identifier 39 + /// types, but we discard those as they are useless to us. 40 + fn extract_identifier(identifier: &mut &str) -> ModalResult<Box<str>> { 41 + alt((extract_ipv6, extract_ipv4)).parse_next(identifier) 42 + } 43 + 44 + /// Extracts the identifier from the Forwarded for value. First it checks for the correct 45 + /// prefix `for=`, then attempts to extract the identifier. 46 + pub fn extract_for(header_part: &mut &str) -> ModalResult<Box<str>> { 47 + space0(header_part)?; 48 + 49 + match_for(header_part)?; 50 + 51 + let id = extract_identifier(header_part)?; 52 + 53 + header_part.finish(); 54 + 55 + Ok(id) 56 + } 57 + 58 + #[cfg(test)] 59 + mod tests { 60 + use super::*; 61 + 62 + #[test] 63 + fn extracts_for_header_value() -> color_eyre::Result<()> { 64 + assert_eq!( 65 + extract_for 66 + .parse("for=1.2.3.4") 67 + .map_err(|a| color_eyre::eyre::eyre!("Identifier parsing error:\n{a}"))?, 68 + Box::from("1.2.3.4") 69 + ); 70 + 71 + assert_eq!( 72 + extract_for 73 + .parse("fOr=1.2.3.4:1234") 74 + .map_err(|a| color_eyre::eyre::eyre!("Identifier parsing error:\n{a}"))?, 75 + Box::from("1.2.3.4:1234") 76 + ); 77 + 78 + assert_eq!( 79 + extract_for 80 + .parse(" fOR=1.2.3.4:1234") 81 + .map_err(|a| color_eyre::eyre::eyre!("Identifier parsing error:\n{a}"))?, 82 + Box::from("1.2.3.4:1234") 83 + ); 84 + 85 + assert_eq!( 86 + extract_for 87 + .parse("FOr=\"[::1]:1234\"") 88 + .map_err(|a| color_eyre::eyre::eyre!("Identifier parsing error:\n{a}"))?, 89 + Box::from("[::1]:1234") 90 + ); 91 + 92 + assert_eq!( 93 + extract_for 94 + .parse("FOR=\"[::1]\"") 95 + .map_err(|a| color_eyre::eyre::eyre!("Identifier parsing error:\n{a}"))?, 96 + Box::from("[::1]") 97 + ); 98 + 99 + Ok(()) 100 + } 101 + }
+29
crates/nailgen/Cargo.toml
··· 1 + [package] 2 + name = "nailgen" 3 + authors.workspace = true 4 + edition.workspace = true 5 + repository.workspace = true 6 + version.workspace = true 7 + license.workspace = true 8 + rust-version.workspace = true 9 + 10 + [lints] 11 + workspace = true 12 + 13 + [features] 14 + detailed_traces = [] 15 + 16 + [dependencies] 17 + nailkov = { path = "../nailkov" } 18 + nailconfig = { path = "../nailconfig" } 19 + nailrng = { path = "../nailrng" } 20 + nailbox = { path = "../nailbox" } 21 + color-eyre.workspace = true 22 + pin-project-lite.workspace = true 23 + futures-lite.workspace = true 24 + axum.workspace = true 25 + rand.workspace = true 26 + bytes.workspace = true 27 + tracing.workspace = true 28 + tokio.workspace = true 29 + winnow.workspace = true
+26
crates/nailgen/src/delay.rs
··· 1 + use core::pin::Pin; 2 + use std::time::Duration; 3 + 4 + use nailconfig::NailConfig; 5 + use nailrng::FastRng; 6 + use rand::Rng; 7 + use tokio::time::{Sleep, sleep}; 8 + 9 + use crate::boxed_future_within; 10 + 11 + /// Apply a delay/sleep based from provided configuration. Either it provides a set 12 + /// minimum delay, or a randomised value sampled from a range of the minimum and maximum 13 + /// configured delays. If the delay value is `0`, this future will poll ready immediately 14 + /// and no sleep will be invoked. 15 + pub fn delay_output(config: &NailConfig) -> Option<Pin<Box<Sleep>>> { 16 + let delay = match (config.generator.min_delay, config.generator.max_delay) { 17 + (min_delay, None) => min_delay, 18 + (min_delay, Some(max_delay)) => FastRng::default().random_range(min_delay..=max_delay), 19 + }; 20 + 21 + if delay > 0 { 22 + Some(boxed_future_within(|| sleep(Duration::from_millis(delay)))) 23 + } else { 24 + None 25 + } 26 + }
+203
crates/nailgen/src/html_gen.rs
··· 1 + use std::sync::Arc; 2 + 3 + use axum::extract::MatchedPath; 4 + use bytes::{Bytes, BytesMut}; 5 + use nailconfig::NailConfig; 6 + use nailkov::{NailKov, interner::Interner}; 7 + use nailrng::FastRng; 8 + use rand::{Rng, RngCore, distr::Alphanumeric, seq::IndexedRandom}; 9 + 10 + /// Provides either the minimum configured size, or a randomised value between 11 + /// the minimum and maximum configured sizes if a maximum is available. 12 + #[inline] 13 + fn get_desired_size(config: &NailConfig, rng: &mut impl RngCore) -> usize { 14 + match ( 15 + config.generator.min_paragraph_size, 16 + config.generator.max_paragraph_size, 17 + ) { 18 + (min, None) => min, 19 + (min, Some(max)) => rng.random_range(min..=max), 20 + } 21 + } 22 + 23 + /// Generates text from the markov chain, using the tokens it outputs to pull 24 + /// interned text from the interner. 25 + #[inline] 26 + pub fn text_generator<'a>( 27 + interner: &'a Interner, 28 + chain: &'a NailKov, 29 + size: usize, 30 + rng: &'a mut impl RngCore, 31 + ) -> impl Iterator<Item = &'a u8> + 'a { 32 + chain 33 + .generate_tokens(rng) 34 + .take(size) 35 + // SAFETY: The id comes from the same interner that allocated it 36 + .flat_map(|token| unsafe { interner.lookup(token).as_bytes() }) 37 + .skip_while(|&text| !text.is_ascii_alphabetic()) 38 + } 39 + 40 + #[inline] 41 + pub fn static_title<'a>(text: &'a str) -> impl Iterator<Item = &'a u8> + 'a { 42 + text.lines() 43 + .map(str::trim) 44 + .next() 45 + .into_iter() 46 + .flat_map(str::as_bytes) 47 + } 48 + 49 + #[inline] 50 + pub fn static_content<'a>(text: &'a str) -> impl Iterator<Item = &'a u8> + 'a { 51 + text.lines() 52 + .skip(1) 53 + .filter_map(|line| { 54 + let trimmed = line.trim(); 55 + 56 + if line.is_empty() { 57 + None 58 + } else { 59 + Some(trimmed.as_bytes()) 60 + } 61 + }) 62 + .flat_map(|bytes| b"<p>".iter().chain(bytes).chain(b"</p>\n")) 63 + } 64 + 65 + pub async fn initial_content( 66 + buf_mut: BytesMut, 67 + interner: Arc<Interner>, 68 + chain: Arc<NailKov>, 69 + config: Arc<NailConfig>, 70 + mut rng: FastRng, 71 + ) -> Bytes { 72 + // Randomise how many initial paragraphs we want 73 + let max_paras: u32 = rng.random_range(1..=3); 74 + 75 + (0..max_paras) 76 + .fold(buf_mut, |mut acc, _| { 77 + acc.extend(paragraph( 78 + &interner, 79 + &chain, 80 + get_desired_size(&config, &mut rng), 81 + &mut rng, 82 + )); 83 + 84 + acc 85 + }) 86 + .freeze() 87 + } 88 + 89 + pub async fn main_content( 90 + mut buffer: BytesMut, 91 + interner: Arc<Interner>, 92 + chain: Arc<NailKov>, 93 + config: Arc<NailConfig>, 94 + mut rng: FastRng, 95 + ) -> Bytes { 96 + buffer.reserve(config.generator.chunk_size * 2); 97 + 98 + loop { 99 + buffer.extend(header( 100 + &interner, 101 + &chain, 102 + config.generator.header_size, 103 + &mut rng, 104 + )); 105 + 106 + // Randomise how many paragraphs we want per section 107 + let paragraphs = rng.random_range(1..=4); 108 + 109 + (0..paragraphs).for_each(|_| { 110 + buffer.extend(paragraph( 111 + &interner, 112 + &chain, 113 + get_desired_size(&config, &mut rng), 114 + &mut rng, 115 + )); 116 + }); 117 + 118 + // We can generate more before handing it off to be streamed to the client, 119 + // A bit more latency, but much more throughput, and friendlier to being compressed. 120 + if buffer.len() >= config.generator.chunk_size { 121 + return buffer.freeze(); 122 + } 123 + 124 + // Yield to the runtime to allow other tasks a chance to run before we generate 125 + // another chunk of data 126 + futures_lite::future::yield_now().await; 127 + } 128 + } 129 + 130 + #[inline] 131 + pub fn extra(buf_mut: &mut BytesMut, config: &NailConfig, rng: &mut FastRng) -> usize { 132 + let mut written = 0; 133 + 134 + if let Some(prompt) = match config.generator.prompts.len() { 135 + 0 => None, 136 + 1 => config.generator.prompts.first(), 137 + _ => config.generator.prompts.choose(rng), 138 + } { 139 + buf_mut.extend(b"<p>".iter().chain(prompt.as_bytes()).chain(b"</p>")); 140 + 141 + written += prompt.len(); 142 + } 143 + 144 + written 145 + } 146 + 147 + pub async fn footer( 148 + mut buf_mut: BytesMut, 149 + interner: Arc<Interner>, 150 + chain: Arc<NailKov>, 151 + path: MatchedPath, 152 + config: Arc<NailConfig>, 153 + mut rng: FastRng, 154 + ) -> Bytes { 155 + let path = path.as_str(); 156 + 157 + let route = path.strip_suffix("/{*generated}").unwrap_or(path); 158 + 159 + let total_links = rng.random_range(1..=config.generator.max_pit_links); 160 + 161 + buf_mut.extend_from_slice(b"<nav style=\"visibility: hidden;\"><ul>"); 162 + 163 + for _ in 1..=total_links { 164 + buf_mut.extend(b"<li><a href=\"".iter().chain(route.as_bytes()).chain(b"/")); 165 + buf_mut.extend((&mut rng).sample_iter(Alphanumeric).take(16)); 166 + buf_mut.extend( 167 + b"\">" 168 + .iter() 169 + .chain(text_generator(&interner, &chain, 8, &mut rng)) 170 + .chain(b"</a></li>\n"), 171 + ); 172 + } 173 + 174 + buf_mut.extend_from_slice(b"</ul></nav>"); 175 + 176 + buf_mut.freeze() 177 + } 178 + 179 + #[inline] 180 + fn paragraph<'a>( 181 + interner: &'a Interner, 182 + chain: &'a NailKov, 183 + size: usize, 184 + rng: &'a mut impl RngCore, 185 + ) -> impl Iterator<Item = &'a u8> + 'a { 186 + b"<p>" 187 + .iter() 188 + .chain(text_generator(interner, chain, size, rng)) 189 + .chain(b"</p>\n") 190 + } 191 + 192 + #[inline] 193 + fn header<'a>( 194 + interner: &'a Interner, 195 + chain: &'a NailKov, 196 + size: usize, 197 + rng: &'a mut impl RngCore, 198 + ) -> impl Iterator<Item = &'a u8> + 'a { 199 + b"\n<h2>" 200 + .iter() 201 + .chain(text_generator(interner, chain, size, rng)) 202 + .chain(b"</h2>\n") 203 + }
+308
crates/nailgen/src/lib.rs
··· 1 + //! Crate for defining a HTML generator based on a markov chain source, using a string 2 + //! interner to reduce memory usage both within a markov chain and across multiple chains. 3 + 4 + use core::task::Poll; 5 + use std::{ 6 + path::Path, 7 + pin::Pin, 8 + sync::Arc, 9 + time::{Duration, Instant}, 10 + }; 11 + 12 + use axum::extract::MatchedPath; 13 + use bytes::{Bytes, BytesMut}; 14 + use color_eyre::Result; 15 + use futures_lite::Stream; 16 + use nailbox::{boxed_future_within, try_arc_within}; 17 + use nailconfig::NailConfig; 18 + use nailkov::{NailKov, interner::Interner}; 19 + use nailrng::FastRng; 20 + use pin_project_lite::pin_project; 21 + use tokio::time::Sleep; 22 + 23 + use crate::{ 24 + delay::delay_output, 25 + html_gen::{ 26 + extra, footer, initial_content, main_content, static_content, static_title, text_generator, 27 + }, 28 + }; 29 + 30 + pub use crate::template::*; 31 + 32 + mod delay; 33 + mod html_gen; 34 + mod template; 35 + 36 + #[derive(Clone)] 37 + pub struct MarkovGen { 38 + chain: Arc<NailKov>, 39 + } 40 + 41 + pin_project! { 42 + #[project = GeneratorStateProj] 43 + enum GeneratorState { 44 + Template, 45 + Content, 46 + GeneratingContent { 47 + handle: Pin<Box<dyn Future<Output = Bytes> + Send>>, 48 + keep_generating: bool, 49 + }, 50 + Delay { 51 + delay: Pin<Box<Sleep>>, 52 + }, 53 + Finished, 54 + } 55 + } 56 + 57 + pin_project! { 58 + pub struct MarkovStream { 59 + path: MatchedPath, 60 + config: Arc<NailConfig>, 61 + interner: Arc<Interner>, 62 + markov: MarkovGen, 63 + start_time: Instant, 64 + total_bytes: usize, 65 + template: Template, 66 + cursor: TemplateCursor, 67 + page_title: Option<Box<[u8]>>, 68 + rng: FastRng, 69 + #[pin] 70 + state: GeneratorState, 71 + } 72 + } 73 + 74 + impl MarkovStream { 75 + pub fn new( 76 + markov: MarkovGen, 77 + path: MatchedPath, 78 + config: Arc<NailConfig>, 79 + interner: Arc<Interner>, 80 + template: Template, 81 + rng: FastRng, 82 + ) -> Self { 83 + Self { 84 + path, 85 + config, 86 + interner, 87 + markov, 88 + total_bytes: 0, 89 + start_time: Instant::now(), 90 + state: GeneratorState::Template, 91 + cursor: TemplateCursor::new(template.get_template()), 92 + rng, 93 + template, 94 + page_title: None, 95 + } 96 + } 97 + } 98 + 99 + impl Stream for MarkovStream { 100 + type Item = Bytes; 101 + 102 + #[cfg_attr( 103 + feature = "detailed_traces", 104 + tracing::instrument(level = "trace", name = "MarkovStream::poll_next", skip_all) 105 + )] 106 + #[inline] 107 + fn poll_next( 108 + mut self: std::pin::Pin<&mut Self>, 109 + cx: &mut std::task::Context<'_>, 110 + ) -> Poll<Option<Self::Item>> { 111 + let mut this = self.as_mut().project(); 112 + 113 + 'outer: loop { 114 + let mut buffer = BytesMut::new(); 115 + 116 + match this.state.as_mut().project() { 117 + GeneratorStateProj::Template => 'inner: loop { 118 + match this.cursor.write_template(&mut buffer) { 119 + template::TemplateState::Title => { 120 + let title = this.page_title.get_or_insert_with(|| { 121 + this.template.get_static_content().map_or_else( 122 + || { 123 + text_generator( 124 + this.interner, 125 + &this.markov.chain, 126 + 24, 127 + this.rng, 128 + ) 129 + .copied() 130 + .collect() 131 + }, 132 + |title| static_title(title).copied().collect(), 133 + ) 134 + }); 135 + 136 + *this.total_bytes += title.len(); 137 + 138 + buffer.extend_from_slice(title); 139 + 140 + continue 'inner; 141 + } 142 + template::TemplateState::Initial => { 143 + let handle = boxed_future_within(|| { 144 + initial_content( 145 + buffer, 146 + this.interner.clone(), 147 + this.markov.chain.clone(), 148 + this.config.clone(), 149 + this.rng.fork(), 150 + ) 151 + }); 152 + 153 + this.state.set(GeneratorState::GeneratingContent { 154 + handle, 155 + keep_generating: false, 156 + }); 157 + 158 + continue 'outer; 159 + } 160 + template::TemplateState::Main => { 161 + if let Some(content) = this.template.get_static_content() { 162 + let len = buffer.len(); 163 + 164 + buffer.extend(static_content(content)); 165 + 166 + this.state.set(GeneratorState::Template); 167 + 168 + let len = buffer.len() - len; 169 + 170 + *this.total_bytes += len; 171 + 172 + continue 'inner; 173 + } else { 174 + this.state.set(GeneratorState::Content); 175 + 176 + continue 'outer; 177 + } 178 + } 179 + template::TemplateState::Extra => { 180 + let bytes = extra(&mut buffer, this.config, this.rng); 181 + 182 + *this.total_bytes += bytes; 183 + 184 + continue 'inner; 185 + } 186 + template::TemplateState::Footer => { 187 + let handle = boxed_future_within(|| { 188 + footer( 189 + buffer, 190 + this.interner.clone(), 191 + this.markov.chain.clone(), 192 + this.path.clone(), 193 + this.config.clone(), 194 + this.rng.fork(), 195 + ) 196 + }); 197 + 198 + this.state.set(GeneratorState::GeneratingContent { 199 + handle, 200 + keep_generating: false, 201 + }); 202 + 203 + continue 'outer; 204 + } 205 + template::TemplateState::Finished => { 206 + let elapsed_time = this.start_time.elapsed().as_micros(); 207 + 208 + tracing::trace!( 209 + "payload.size" = *this.total_bytes, 210 + "duration.us" = elapsed_time, 211 + "Stream finished in {:.2}ms", 212 + (elapsed_time as f32) * 1e-3 213 + ); 214 + 215 + this.state.set(GeneratorState::Finished); 216 + 217 + return Poll::Ready(Some(buffer.freeze())); 218 + } 219 + } 220 + }, 221 + GeneratorStateProj::Content => { 222 + let time_limit = Duration::from_secs(this.config.generator.timeout); 223 + 224 + if time_limit.as_secs() > 0 225 + && this.start_time.elapsed().as_secs() >= time_limit.as_secs() 226 + { 227 + this.state.set(GeneratorState::Template); 228 + continue 'outer; 229 + } 230 + 231 + if *this.total_bytes >= (this.config.generator.payload_size * 1024) { 232 + this.state.set(GeneratorState::Template); 233 + continue 'outer; 234 + } 235 + 236 + let handle = boxed_future_within(|| { 237 + main_content( 238 + buffer, 239 + this.interner.clone(), 240 + this.markov.chain.clone(), 241 + this.config.clone(), 242 + this.rng.fork(), 243 + ) 244 + }); 245 + 246 + this.state.set(GeneratorState::GeneratingContent { 247 + handle, 248 + keep_generating: true, 249 + }); 250 + } 251 + GeneratorStateProj::GeneratingContent { 252 + handle, 253 + keep_generating, 254 + } => match handle.as_mut().poll(cx) { 255 + Poll::Ready(content) => { 256 + *this.total_bytes += content.len(); 257 + 258 + if *keep_generating { 259 + if let Some(delay) = delay_output(this.config) { 260 + this.state.set(GeneratorState::Delay { delay }); 261 + } else { 262 + this.state.set(GeneratorState::Content); 263 + } 264 + } else { 265 + this.state.set(GeneratorState::Template); 266 + } 267 + 268 + return Poll::Ready(Some(content)); 269 + } 270 + Poll::Pending => return Poll::Pending, 271 + }, 272 + GeneratorStateProj::Delay { delay } => match delay.as_mut().poll(cx) { 273 + Poll::Ready(_) => { 274 + this.state.set(GeneratorState::Content); 275 + 276 + continue; 277 + } 278 + Poll::Pending => return Poll::Pending, 279 + }, 280 + GeneratorStateProj::Finished => { 281 + return Poll::Ready(None); 282 + } 283 + } 284 + } 285 + } 286 + } 287 + 288 + impl MarkovGen { 289 + pub fn new(input: impl AsRef<Path>, interner: &mut Interner) -> Result<Self> { 290 + let file = std::fs::read_to_string(input.as_ref())?; 291 + 292 + let chain = try_arc_within(|| NailKov::from_input(interner, &file))?; 293 + 294 + Ok(Self { chain }) 295 + } 296 + 297 + #[inline] 298 + pub fn into_stream( 299 + self, 300 + path: MatchedPath, 301 + config: Arc<NailConfig>, 302 + interner: Arc<Interner>, 303 + template: Template, 304 + rng: FastRng, 305 + ) -> MarkovStream { 306 + MarkovStream::new(self, path, config, interner, template, rng) 307 + } 308 + }
+345
crates/nailgen/src/template.rs
··· 1 + use std::sync::Arc; 2 + 3 + use bytes::BytesMut; 4 + use winnow::{ 5 + ModalResult, Parser, 6 + ascii::{Caseless, alpha1, space0}, 7 + combinator::alt, 8 + error::ErrMode, 9 + token::{literal, rest, take_until}, 10 + }; 11 + 12 + fn process_template<'any>(template: &'any mut &str) -> ModalResult<(&'any str, TemplateState)> { 13 + match take_until(0.., "{{").parse_next(template) { 14 + Ok(part) => { 15 + literal("{{").parse_next(template)?; 16 + 17 + space0(template)?; 18 + 19 + let mut placeholder = alpha1(template)?; 20 + 21 + space0(template)?; 22 + 23 + literal("}}").parse_next(template)?; 24 + 25 + let placeholder = &mut placeholder; 26 + 27 + let state = alt(( 28 + Caseless("title").map(|_| (part, TemplateState::Title)), 29 + Caseless("initial").map(|_| (part, TemplateState::Initial)), 30 + Caseless("main").map(|_| (part, TemplateState::Main)), 31 + Caseless("extra").map(|_| (part, TemplateState::Extra)), 32 + Caseless("footer").map(|_| (part, TemplateState::Footer)), 33 + )) 34 + .parse_next(placeholder)?; 35 + 36 + rest.verify(|remaining: &str| remaining.is_empty()) 37 + .parse_next(placeholder)?; 38 + 39 + Ok(state) 40 + } 41 + Err(ErrMode::Backtrack(_)) => Ok((template, TemplateState::Finished)), 42 + Err(e) => Err(e), 43 + } 44 + } 45 + 46 + #[derive(Debug, Clone, PartialEq, Eq, Hash)] 47 + pub enum Template { 48 + Warning(WarningTemplate), 49 + Generated(GeneratedTemplate), 50 + } 51 + 52 + impl Template { 53 + pub fn get_template(&self) -> &Arc<str> { 54 + match self { 55 + Self::Warning(index_template) => &index_template.template, 56 + Self::Generated(generated_template) => &generated_template.template, 57 + } 58 + } 59 + 60 + pub fn get_static_content(&self) -> Option<&str> { 61 + match self { 62 + Self::Warning(index_template) => Some(index_template.static_content.as_ref()), 63 + Self::Generated(_) => None, 64 + } 65 + } 66 + } 67 + 68 + impl From<WarningTemplate> for Template { 69 + fn from(value: WarningTemplate) -> Self { 70 + Self::Warning(value) 71 + } 72 + } 73 + 74 + impl From<GeneratedTemplate> for Template { 75 + fn from(value: GeneratedTemplate) -> Self { 76 + Self::Generated(value) 77 + } 78 + } 79 + 80 + #[derive(Debug, Clone, PartialEq, Eq, Hash)] 81 + pub struct WarningTemplate { 82 + template: Arc<str>, 83 + static_content: Arc<str>, 84 + } 85 + 86 + impl WarningTemplate { 87 + pub fn init(template: Arc<str>, static_content: Arc<str>) -> Result<Self, TemplateError> { 88 + let cursor = TemplateCursor::new(&template); 89 + 90 + if cursor.validate(&[ 91 + TemplateState::Title, 92 + TemplateState::Main, 93 + TemplateState::Footer, 94 + ]) { 95 + Ok(Self { 96 + template, 97 + static_content, 98 + }) 99 + } else { 100 + Err(TemplateError) 101 + } 102 + } 103 + } 104 + 105 + #[derive(Debug, Clone, PartialEq, Eq, Hash)] 106 + pub struct GeneratedTemplate { 107 + template: Arc<str>, 108 + } 109 + 110 + impl GeneratedTemplate { 111 + pub fn init(template: Arc<str>) -> Result<Self, TemplateError> { 112 + let cursor = TemplateCursor::new(&template); 113 + 114 + if cursor.validate(&[ 115 + TemplateState::Title, 116 + TemplateState::Initial, 117 + TemplateState::Main, 118 + TemplateState::Extra, 119 + TemplateState::Footer, 120 + ]) { 121 + Ok(Self { template }) 122 + } else { 123 + Err(TemplateError) 124 + } 125 + } 126 + } 127 + 128 + #[derive(Debug, Clone, Copy, PartialEq, Eq)] 129 + pub struct TemplateError; 130 + 131 + impl core::fmt::Display for TemplateError { 132 + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 133 + write!(f, "Invalid template, contains disallowed placeholders") 134 + } 135 + } 136 + 137 + impl core::error::Error for TemplateError {} 138 + 139 + pub struct TemplateCursor { 140 + cursor: *const str, 141 + } 142 + 143 + impl TemplateCursor { 144 + pub fn new(template: &Arc<str>) -> Self { 145 + Self { 146 + cursor: Arc::as_ptr(template), 147 + } 148 + } 149 + 150 + fn cast_cursor(&self) -> &str { 151 + // SAFETY: The pointer will always be valid as we own an Arc instance 152 + // within the future, meaning as long as the future lives, the 153 + // Arc will never be dropped and cleaned. 154 + unsafe { &*self.cursor } 155 + } 156 + 157 + /// Advances the template cursor to the next placeholder point, writing the 158 + /// portion of the static template to the buffer before returning the placeholder 159 + /// reached by the cursor. If the template has no placeholders, the entire 160 + /// template will be written to the buffer and the state returned will be 161 + /// [`TemplateState::Finished`]. 162 + pub fn write_template(&mut self, buffer: &mut BytesMut) -> TemplateState { 163 + let template = &mut self.cast_cursor(); 164 + 165 + match process_template(template) { 166 + Ok((part, state)) => { 167 + buffer.extend_from_slice(part.as_bytes()); 168 + 169 + self.cursor = *template; 170 + 171 + state 172 + } 173 + Err(_) => TemplateState::Finished, 174 + } 175 + } 176 + 177 + fn validate(&self, included: &[TemplateState]) -> bool { 178 + let template = &mut self.cast_cursor(); 179 + 180 + loop { 181 + match process_template(template) { 182 + Ok((_, state)) => { 183 + if state == TemplateState::Finished { 184 + return true; 185 + } 186 + 187 + if !included.contains(&state) { 188 + return false; 189 + } 190 + } 191 + Err(_) => return false, 192 + } 193 + } 194 + } 195 + } 196 + 197 + // SAFETY: TemplateCursor carries an Arc reference to the str allocated on the heap. 198 + // This means the pointer will never be invalidated as long as the Arc instance lives, 199 + // and as it is immutable, the allocation will never be changed. 200 + unsafe impl Send for TemplateCursor {} 201 + // SAFETY: TemplateCursor carries an Arc reference to the str allocated on the heap. 202 + // This means the pointer will never be invalidated as long as the Arc instance lives, 203 + // and as it is immutable, the allocation will never be changed. 204 + unsafe impl Sync for TemplateCursor {} 205 + 206 + #[derive(Debug, Clone, Copy, PartialEq, Eq)] 207 + pub enum TemplateState { 208 + Title, 209 + Initial, 210 + Main, 211 + Extra, 212 + Footer, 213 + Finished, 214 + } 215 + 216 + #[cfg(test)] 217 + mod tests { 218 + use super::*; 219 + 220 + #[test] 221 + fn extracts_placeholders() -> color_eyre::Result<()> { 222 + let mut template = "<h1>{{ TITLE }}</h1><p>{{main}}</p>"; 223 + 224 + let template = &mut template; 225 + 226 + let (extracted, state) = process_template(template) 227 + .map_err(|a| color_eyre::eyre::eyre!("Template parsing error:\n{a}"))?; 228 + 229 + assert_eq!(extracted, "<h1>"); 230 + assert_eq!(state, TemplateState::Title); 231 + assert_eq!(*template, "</h1><p>{{main}}</p>"); 232 + 233 + let (extracted, state) = process_template(template) 234 + .map_err(|a| color_eyre::eyre::eyre!("Template parsing error:\n{a}"))?; 235 + 236 + assert_eq!(extracted, "</h1><p>"); 237 + assert_eq!(state, TemplateState::Main); 238 + assert_eq!(*template, "</p>"); 239 + 240 + let (extracted, state) = process_template(template) 241 + .map_err(|a| color_eyre::eyre::eyre!("Template parsing error:\n{a}"))?; 242 + 243 + assert_eq!(extracted, "</p>"); 244 + assert_eq!(state, TemplateState::Finished); 245 + assert_eq!(*template, "</p>"); 246 + 247 + Ok(()) 248 + } 249 + 250 + #[test] 251 + fn writes_template_to_buffer() { 252 + let template: Arc<str> = Arc::from("<h1>{{ TITLE }}</h1><p>{{ MAIN }}</p>"); 253 + 254 + let mut cursor = TemplateCursor::new(&template); 255 + 256 + let mut buffer = BytesMut::new(); 257 + 258 + loop { 259 + match cursor.write_template(&mut buffer) { 260 + TemplateState::Finished => { 261 + break; 262 + } 263 + TemplateState::Title | TemplateState::Main => { 264 + buffer.extend_from_slice(b"aaa"); 265 + } 266 + state => panic!("INVALID STATE: {state:?}"), 267 + } 268 + } 269 + 270 + assert_eq!(buffer.as_ref(), b"<h1>aaa</h1><p>aaa</p>"); 271 + } 272 + 273 + #[test] 274 + fn writes_static_template_to_buffer() { 275 + let template: Arc<str> = Arc::from("<h1>Static</h1><p>Template</p>"); 276 + 277 + let mut cursor = TemplateCursor::new(&template); 278 + 279 + let mut buffer = BytesMut::new(); 280 + 281 + let state = cursor.write_template(&mut buffer); 282 + 283 + assert_eq!(state, TemplateState::Finished); 284 + assert_eq!(buffer.as_ref(), b"<h1>Static</h1><p>Template</p>"); 285 + } 286 + 287 + #[test] 288 + fn wont_write_empty_template_to_buffer() { 289 + let template: Arc<str> = Arc::from(""); 290 + 291 + let mut cursor = TemplateCursor::new(&template); 292 + 293 + let mut buffer = BytesMut::new(); 294 + 295 + let state = cursor.write_template(&mut buffer); 296 + 297 + assert_eq!(state, TemplateState::Finished); 298 + assert!(buffer.is_empty()); 299 + } 300 + 301 + #[test] 302 + fn validates_templates_with_placeholders() { 303 + let template: Arc<str> = Arc::from("<h1>{{ TITLE }}</h1><p>{{ MAIN }}</p>"); 304 + 305 + let generated_template = GeneratedTemplate::init(template.clone()); 306 + 307 + assert_eq!(generated_template, Ok(GeneratedTemplate { template })); 308 + } 309 + 310 + #[test] 311 + fn validates_templates_with_invalid_placeholders() { 312 + // Partial matches should still be invalid 313 + let template: Arc<str> = Arc::from("<h1>{{ TITLE }}</h1><p>{{ MAINZ }}</p>"); 314 + 315 + let generated_template = GeneratedTemplate::init(template); 316 + 317 + assert_eq!(generated_template, Err(TemplateError)); 318 + 319 + let template: Arc<str> = Arc::from("<h1>{{ TITLE }}</h1><p>{{ huurrrr }}</p>"); 320 + 321 + let generated_template = GeneratedTemplate::init(template); 322 + 323 + assert_eq!(generated_template, Err(TemplateError)); 324 + } 325 + 326 + #[test] 327 + fn validates_static_templates() { 328 + // Static templates are also valid 329 + let template: Arc<str> = Arc::from("<h1>Static</h1><p>Template</p>"); 330 + 331 + let generated_template = GeneratedTemplate::init(template.clone()); 332 + 333 + assert_eq!(generated_template, Ok(GeneratedTemplate { template })); 334 + } 335 + 336 + #[test] 337 + fn validates_empty_templates() { 338 + // Empty templates should be valid, since they can be handled 339 + let template: Arc<str> = Arc::from(""); 340 + 341 + let generated_template = GeneratedTemplate::init(template.clone()); 342 + 343 + assert_eq!(generated_template, Ok(GeneratedTemplate { template })); 344 + } 345 + }
+25
crates/nailip/Cargo.toml
··· 1 + [package] 2 + name = "nailip" 3 + authors.workspace = true 4 + edition.workspace = true 5 + repository.workspace = true 6 + version.workspace = true 7 + license.workspace = true 8 + rust-version.workspace = true 9 + 10 + [dependencies] 11 + nailfv = { path = "../nailfv" } 12 + nailconfig = { path = "../nailconfig" } 13 + nailnet = { path = "../nailnet" } 14 + axum.workspace = true 15 + futures-lite.workspace = true 16 + hyper.workspace = true 17 + pin-project-lite.workspace = true 18 + scc.workspace = true 19 + tokio.workspace = true 20 + wyrand.workspace = true 21 + tower.workspace = true 22 + tracing.workspace = true 23 + 24 + [lints] 25 + workspace = true
+34
crates/nailip/src/lib.rs
··· 1 + use core::net::SocketAddr; 2 + 3 + use hyper::HeaderMap; 4 + 5 + pub use crate::maybe_header::*; 6 + 7 + mod maybe_header; 8 + 9 + #[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] 10 + #[repr(transparent)] 11 + pub struct IdentifiedPeer(Box<str>); 12 + 13 + impl IdentifiedPeer { 14 + #[inline] 15 + pub fn extract(headers: &HeaderMap, connection: SocketAddr) -> Self { 16 + Self( 17 + maybe_x_forwarded_for(headers) 18 + .or_else(|| maybe_x_real_ip(headers)) 19 + .or_else(|| maybe_forwarded_for(headers)) 20 + .unwrap_or_else(|| connection.to_string().into()), 21 + ) 22 + } 23 + 24 + #[inline] 25 + pub fn peer(&self) -> &str { 26 + &self.0 27 + } 28 + } 29 + 30 + impl core::fmt::Display for IdentifiedPeer { 31 + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 32 + write!(f, "{}", self.0) 33 + } 34 + }
+48
crates/nailip/src/maybe_header.rs
··· 1 + use axum::http::HeaderValue; 2 + use hyper::{HeaderMap, header::FORWARDED}; 3 + use nailfv::{Parser, extract_for}; 4 + 5 + const X_REAL_IP: &str = "x-real-ip"; 6 + const X_FORWARDED_FOR: &str = "x-forwarded-for"; 7 + 8 + /// Tries to parse the `x-forwarded-for` header 9 + #[inline] 10 + pub fn maybe_x_forwarded_for(headers: &HeaderMap) -> Option<Box<str>> { 11 + headers 12 + .get(X_FORWARDED_FOR) 13 + .and_then(header_value_to_str) 14 + .and_then(|header| { 15 + header 16 + .split(',') 17 + .map(str::trim) 18 + .find_map(|header_parts| (!header_parts.is_empty()).then(|| header_parts.into())) 19 + }) 20 + } 21 + 22 + /// Tries to parse the `x-real-ip` header 23 + #[inline] 24 + pub fn maybe_x_real_ip(headers: &HeaderMap) -> Option<Box<str>> { 25 + headers 26 + .get(X_REAL_IP) 27 + .and_then(header_value_to_str) 28 + .map(|header| header.trim().into()) 29 + } 30 + 31 + /// Tries to parse `forwarded` headers 32 + #[inline] 33 + pub fn maybe_forwarded_for(headers: &HeaderMap) -> Option<Box<str>> { 34 + headers.get_all(FORWARDED).iter().find_map(|header| { 35 + header_value_to_str(header).and_then(|header| { 36 + header 37 + .split(&[',', ';']) 38 + .map(str::trim) 39 + .filter(|&header_parts| !header_parts.is_empty()) 40 + .find_map(|header_parts| extract_for.parse(header_parts).ok()) 41 + }) 42 + }) 43 + } 44 + 45 + #[inline] 46 + pub fn header_value_to_str(header_value: &HeaderValue) -> Option<&str> { 47 + header_value.to_str().ok() 48 + }
+23
crates/nailkov/Cargo.toml
··· 1 + [package] 2 + name = "nailkov" 3 + edition.workspace = true 4 + repository.workspace = true 5 + version.workspace = true 6 + authors.workspace = true 7 + rust-version.workspace = true 8 + license.workspace = true 9 + 10 + [lints] 11 + workspace = true 12 + 13 + [dependencies] 14 + nailrng = { path = "../nailrng" } 15 + rapidhash = { workspace = true, features = ["rand", "unsafe"] } 16 + rustc-hash = { version = "2.1.1", default-features = false } 17 + hashbrown.workspace = true 18 + rand.workspace = true 19 + rand_distr.workspace = true 20 + itertools.workspace = true 21 + unicode-segmentation.workspace = true 22 + tracing.workspace = true 23 + indexmap.workspace = true
+69
crates/nailkov/src/distribution.rs
··· 1 + //! [`TokenWeights`] are representations of how common [`Token`]s are, and are paired up with 2 + //! a [`TokenPair`](crate::token::TokenPair) in a [`NailKov`](crate::NailKov). 3 + 4 + use indexmap::IndexMap; 5 + use rand::Rng; 6 + use rand_distr::{Distribution, weighted::WeightedAliasIndex}; 7 + 8 + use crate::{RandomState, error::NailError, token::Token}; 9 + 10 + /// A distribution of choices and their likelihood. 11 + #[derive(Clone, Debug)] 12 + pub struct TokenWeights { 13 + /// Mappings of choice indexes to their likelihood. 14 + dist: WeightedAliasIndex<u32>, 15 + /// The actual choices 16 + choices: Box<[Token]>, 17 + } 18 + 19 + impl Distribution<Token> for TokenWeights { 20 + #[inline(always)] 21 + fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Token { 22 + // SAFETY: The sampled index from `dist` will always correspond to a valid 23 + // token in the `choices` slice. 24 + unsafe { *self.choices.get_unchecked(self.dist.sample(rng)) } 25 + } 26 + } 27 + 28 + /// Builder for [`TokenWeights`]. 29 + #[derive(Clone, Debug)] 30 + pub struct TokenWeightsBuilder { 31 + /// Counts how many times a token is likely to appear. 32 + occurrences: IndexMap<Token, u32, RandomState>, 33 + } 34 + 35 + impl TokenWeightsBuilder { 36 + pub fn new(hasher: RandomState) -> Self { 37 + Self { 38 + occurrences: IndexMap::with_hasher(hasher), 39 + } 40 + } 41 + 42 + /// Creates a weighted distribution for the likelihood of tokens to appear. 43 + pub fn build(self) -> Result<TokenWeights, NailError> { 44 + let (choices, counts): (Vec<_>, Vec<_>) = self.occurrences.into_iter().unzip(); 45 + 46 + if choices.is_empty() { 47 + return Err(NailError::EmptyInput); 48 + } 49 + 50 + Ok(TokenWeights { 51 + dist: WeightedAliasIndex::new(counts)?, 52 + choices: choices.into(), 53 + }) 54 + } 55 + 56 + /// Count an occurrence of this token, or add it if it hasn't been seen before. 57 + pub fn add(&mut self, token: Token) { 58 + self.occurrences 59 + .entry(token) 60 + .and_modify(|count| *count += 1) 61 + .or_insert(1); 62 + } 63 + } 64 + 65 + impl Default for TokenWeightsBuilder { 66 + fn default() -> Self { 67 + Self::new(RandomState::new()) 68 + } 69 + }
+26
crates/nailkov/src/error.rs
··· 1 + use rand::seq::WeightError; 2 + 3 + #[derive(Debug, Clone, Copy, PartialEq, Eq)] 4 + pub enum NailError { 5 + EmptyInput, 6 + BuildError(WeightError), 7 + } 8 + 9 + impl From<WeightError> for NailError { 10 + fn from(value: WeightError) -> Self { 11 + Self::BuildError(value) 12 + } 13 + } 14 + 15 + impl core::fmt::Display for NailError { 16 + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 17 + match self { 18 + NailError::EmptyInput => write!(f, "Text input is empty"), 19 + NailError::BuildError(e) => { 20 + write!(f, "Failed to build token weight distributions: {e}") 21 + } 22 + } 23 + } 24 + } 25 + 26 + impl core::error::Error for NailError {}
+237
crates/nailkov/src/interner.rs
··· 1 + use hashbrown::{Equivalent, HashMap}; 2 + use rapidhash::fast::RandomState; 3 + 4 + use crate::token::Token; 5 + 6 + #[derive(Debug, Clone, Copy, PartialEq, Eq)] 7 + #[repr(transparent)] 8 + struct StringPtr(*const str); 9 + 10 + impl StringPtr { 11 + #[inline(always)] 12 + const fn cast(&self) -> &str { 13 + // SAFETY: The pointer is stable as it points to memory that is never 14 + // moved/invalidated while this struct lives, therefore can be safely 15 + // dereferenced back to a string slice. We own the String instance this 16 + // references, and all StringPtrs are used within the same scope as the 17 + // String instances, so when String drops, these will be dropped too. 18 + unsafe { &*self.0 } 19 + } 20 + } 21 + 22 + impl core::hash::Hash for StringPtr { 23 + #[inline] 24 + fn hash<H: std::hash::Hasher>(&self, state: &mut H) { 25 + self.cast().hash(state); 26 + } 27 + } 28 + // SAFETY: StringPtr contains a ptr to the heap, that is never moved or invalidated 29 + // while Interner lives, and all instances of StringPtr live as long as Interner. 30 + // Since the String type is `Send`, so is StringPtr 31 + unsafe impl Send for StringPtr {} 32 + // SAFETY: StringPtr contains a ptr to the heap, that is never moved or invalidated 33 + // while Interner lives, and all instances of StringPtr live as long as Interner. 34 + // Since the String type is `Sync`, so is StringPtr 35 + unsafe impl Sync for StringPtr {} 36 + 37 + #[derive(Debug, Clone)] 38 + pub struct Interner { 39 + collected: HashMap<StringPtr, Token, RandomState>, 40 + index: Vec<StringPtr>, 41 + buffer: String, 42 + stored: Vec<String>, 43 + } 44 + 45 + impl Default for Interner { 46 + fn default() -> Self { 47 + Self::with_capacity(256) 48 + } 49 + } 50 + 51 + impl Interner { 52 + /// # Safety 53 + /// The caller must ensure that the [`Token`] being passed in was allocated 54 + /// from the same [`Interner`] instance. 55 + #[inline(always)] 56 + pub unsafe fn lookup(&self, id: Token) -> &str { 57 + // SAFETY: Safety is upheld by the caller ensuring the id was allocated 58 + // from the same interner. 59 + unsafe { self.index.get_unchecked(id.index()).cast() } 60 + } 61 + 62 + pub fn with_capacity(cap: usize) -> Interner { 63 + // This will get us just under 64KiB of interned storage before we 64 + // need to allocate more space for buffer storage. 65 + let stored = Vec::with_capacity(8); 66 + 67 + Interner { 68 + collected: HashMap::with_hasher(RandomState::new()), 69 + index: Vec::new(), 70 + stored, 71 + buffer: String::with_capacity(cap.next_power_of_two()), 72 + } 73 + } 74 + 75 + pub fn intern(&mut self, text: &str) -> Token { 76 + if let Some(&id) = self.collected.get(text) { 77 + return id; 78 + } 79 + 80 + // SAFETY: `alloc`` is never called elsewhere, nor the properties it controls 81 + // are modified outside of the method. Here we get a new StringPtr for `text` that 82 + // hasn't been stored before. 83 + let name = unsafe { self.alloc(text) }; 84 + let id = Token::new(self.index.len() as u32); 85 + self.collected.insert(name, id); 86 + self.index.push(name); 87 + 88 + // SAFETY: We are using the id allocated within the same function scope, 89 + // so it is always from the same source. 90 + unsafe { 91 + debug_assert!(self.lookup(id).equivalent(&name)); 92 + } 93 + debug_assert!(self.intern(name.cast()) == id); 94 + 95 + id 96 + } 97 + 98 + /// Allocates a new [`StringPtr`] for the given string input. If there is no more room 99 + /// in the current buffer, it allocates a new buffer and creates the StringPtr to reference 100 + /// the stored string in the new buffer, storing the old one. 101 + /// 102 + /// # Safety 103 + /// 104 + /// The caller must ensure that `self.buffers` and `self.active` are never modified elsewhere, 105 + /// and that this is called only for new instances of `text`. 106 + unsafe fn alloc(&mut self, text: &str) -> StringPtr { 107 + let capacity = self.buffer.capacity(); 108 + 109 + if capacity < self.buffer.len() + text.len() { 110 + // If we ran out of capacity in our storage, allocate a new buffer with 111 + // larger capacity. 112 + let new_cap = (capacity.max(text.len()) + 1).next_power_of_two(); 113 + let old_buf = core::mem::replace(&mut self.buffer, String::with_capacity(new_cap)); 114 + 115 + self.stored.push(old_buf); 116 + } 117 + 118 + // Construct raw str slice to eliminate lifetime tracking as we manage its 119 + // lifetime within the Interner instance. 120 + let interned = { 121 + let start = self.buffer.len(); 122 + self.buffer.push_str(text); 123 + 124 + &raw const self.buffer[start..] 125 + }; 126 + 127 + StringPtr(interned) 128 + } 129 + } 130 + 131 + impl Equivalent<StringPtr> for str { 132 + #[inline(always)] 133 + fn equivalent(&self, key: &StringPtr) -> bool { 134 + key.cast().eq(self) 135 + } 136 + } 137 + 138 + #[cfg(test)] 139 + mod tests { 140 + use super::*; 141 + 142 + #[test] 143 + fn string_ptr_comparisons() { 144 + let one = "one"; 145 + let two = "two"; 146 + 147 + let one_ptr = StringPtr(one); 148 + let two_ptr = StringPtr(two); 149 + 150 + assert_ne!(one_ptr, two_ptr); 151 + 152 + assert!(one.equivalent(&one_ptr)); 153 + } 154 + 155 + #[test] 156 + fn is_able_to_intern_one_string() { 157 + let mut interner = Interner::default(); 158 + 159 + assert!(interner.buffer.is_empty()); 160 + 161 + let text = "Lorem ipsum"; 162 + 163 + let id = interner.intern(text); 164 + 165 + // SAFETY: It comes from the same source 166 + unsafe { 167 + assert_eq!(text, interner.lookup(id)); 168 + } 169 + assert_eq!(interner.buffer.len(), 11); 170 + 171 + let again = interner.intern(text); 172 + 173 + assert_eq!(id, again); 174 + assert_eq!(interner.buffer.len(), 11); 175 + } 176 + 177 + #[test] 178 + fn is_able_to_intern_many_strings() { 179 + let mut interner = Interner::with_capacity(32); 180 + 181 + let texts = [ 182 + "Lorem ipsum", 183 + "dolor sit amet", 184 + "duplicated", 185 + "Other text", 186 + "Elevenses", 187 + "duplicated", 188 + "Gibberish", 189 + ]; 190 + 191 + let interned: Vec<Token> = texts.iter().map(|&text| interner.intern(text)).collect(); 192 + 193 + assert_eq!( 194 + interned.as_slice(), 195 + &[ 196 + Token::new(0), 197 + Token::new(1), 198 + Token::new(2), 199 + Token::new(3), 200 + Token::new(4), 201 + Token::new(2), 202 + Token::new(5) 203 + ] 204 + ); 205 + assert_eq!(interner.buffer.capacity(), 64); 206 + assert_eq!(interner.stored.len(), 1); 207 + assert_eq!(interner.stored[0].capacity(), 32); 208 + } 209 + 210 + #[test] 211 + fn is_thread_safe() { 212 + let mut interner = Interner::with_capacity(32); 213 + 214 + let texts = [ 215 + "Lorem ipsum", 216 + "dolor sit amet", 217 + "duplicated", 218 + "Other text", 219 + "Elevenses", 220 + "duplicated", 221 + "Gibberish", 222 + ]; 223 + 224 + let interned: Vec<Token> = texts.iter().map(|&text| interner.intern(text)).collect(); 225 + 226 + std::thread::scope(|s| { 227 + s.spawn(move || { 228 + for (id, expected) in interned.into_iter().zip(texts) { 229 + // SAFETY: It comes from the same source 230 + unsafe { 231 + assert_eq!(expected, interner.lookup(id)); 232 + } 233 + } 234 + }); 235 + }); 236 + } 237 + }
+168
crates/nailkov/src/lib.rs
··· 1 + //! Crate defining a Markov Chain implementation, and a string interner for use 2 + //! with the markov chain. 3 + 4 + mod distribution; 5 + mod error; 6 + pub mod interner; 7 + mod token; 8 + 9 + use error::NailError; 10 + use indexmap::IndexMap; 11 + use interner::Interner; 12 + use itertools::Itertools; 13 + use nailrng::FastRng; 14 + use rand::{RngCore, seq::IteratorRandom}; 15 + use rand_distr::Distribution; 16 + 17 + use distribution::{TokenWeights, TokenWeightsBuilder}; 18 + use rustc_hash::FxHasher; 19 + use token::{Token, TokenPair}; 20 + use unicode_segmentation::UnicodeSegmentation; 21 + 22 + #[derive(Clone)] 23 + pub struct RandomState { 24 + seed: usize, 25 + } 26 + 27 + impl RandomState { 28 + fn new() -> Self { 29 + let mut rng = FastRng::default(); 30 + 31 + Self { 32 + seed: rng.next_u64() as usize, 33 + } 34 + } 35 + } 36 + 37 + impl Default for RandomState { 38 + fn default() -> Self { 39 + Self::new() 40 + } 41 + } 42 + 43 + impl core::hash::BuildHasher for RandomState { 44 + type Hasher = FxHasher; 45 + 46 + fn build_hasher(&self) -> Self::Hasher { 47 + FxHasher::with_seed(self.seed) 48 + } 49 + } 50 + 51 + #[derive(Clone, Debug)] 52 + pub struct NailKov { 53 + chain: IndexMap<TokenPair, TokenWeights, RandomState>, 54 + } 55 + 56 + pub struct NailKovIter<'a, R: RngCore> { 57 + rng: &'a mut R, 58 + markov: &'a NailKov, 59 + prev: TokenPair, 60 + } 61 + 62 + impl<R: RngCore> Iterator for NailKovIter<'_, R> { 63 + type Item = Token; 64 + 65 + #[inline] 66 + fn next(&mut self) -> Option<Self::Item> { 67 + let dist = self.markov.chain.get(&self.prev)?; 68 + 69 + let next_token = dist.sample(&mut self.rng); 70 + 71 + self.prev = TokenPair::new(self.prev.right, next_token); 72 + 73 + Some(next_token) 74 + } 75 + } 76 + 77 + impl NailKov { 78 + #[inline] 79 + pub fn generate_tokens<'a, R: RngCore>(&'a self, rng: &'a mut R) -> NailKovIter<'a, R> { 80 + NailKovIter { 81 + // A markov chain that was successfully built is never empty, so 82 + // it will always return with a value, making unwrapping it safe to do. 83 + prev: self.chain.keys().choose(rng).copied().unwrap(), 84 + markov: self, 85 + rng, 86 + } 87 + } 88 + } 89 + 90 + impl NailKov { 91 + pub fn from_input(interner: &mut Interner, input: &str) -> Result<NailKov, NailError> { 92 + NailBuilder::new(RandomState::new()).with_input(interner, input) 93 + } 94 + } 95 + 96 + struct NailBuilder { 97 + chain: IndexMap<TokenPair, TokenWeightsBuilder, RandomState>, 98 + } 99 + 100 + impl NailBuilder { 101 + fn new(hasher: RandomState) -> Self { 102 + Self { 103 + chain: IndexMap::with_hasher(hasher), 104 + } 105 + } 106 + 107 + fn with_input(self, interned: &mut Interner, input: &str) -> Result<NailKov, NailError> { 108 + self.feed_str(interned, input)?.build() 109 + } 110 + 111 + fn build(self) -> Result<NailKov, NailError> { 112 + if self.chain.is_empty() { 113 + return Err(NailError::EmptyInput); 114 + } 115 + 116 + let chain: IndexMap<TokenPair, TokenWeights, RandomState> = self 117 + .chain 118 + .into_iter() 119 + .flat_map(|(pair, dist)| { 120 + dist.build() 121 + .inspect_err(|err| tracing::error!("Weight error {pair:?}: {err}")) 122 + .map(|build| (pair, build)) 123 + }) 124 + .collect(); 125 + 126 + if chain.is_empty() { 127 + return Err(NailError::EmptyInput); 128 + } 129 + 130 + Ok(NailKov { chain }) 131 + } 132 + 133 + /// Add the occurrence of `next` following `prev`. 134 + fn add_token_pair(&mut self, prev: TokenPair, next: Token) { 135 + match self.chain.get_mut(&prev) { 136 + Some(builder) => { 137 + builder.add(next); 138 + } 139 + None => { 140 + let mut builder = TokenWeightsBuilder::new(self.chain.hasher().clone()); 141 + builder.add(next); 142 + self.chain.insert(prev, builder); 143 + } 144 + } 145 + } 146 + 147 + fn feed_str(self, interner: &mut Interner, content: &str) -> Result<Self, NailError> { 148 + self.feed_tokens( 149 + content 150 + .split_word_bounds() 151 + .map(|text| interner.intern(text)), 152 + ) 153 + } 154 + 155 + fn feed_tokens(mut self, tokens: impl Iterator<Item = Token>) -> Result<Self, NailError> { 156 + let windows = tokens.tuple_windows(); 157 + 158 + if windows.size_hint().1.is_none() { 159 + return Err(NailError::EmptyInput); 160 + } 161 + 162 + for (left, right, next) in windows { 163 + self.add_token_pair(TokenPair::new(left, right), next); 164 + } 165 + 166 + Ok(self) 167 + } 168 + }
+113
crates/nailkov/src/token.rs
··· 1 + use std::ops::Deref; 2 + 3 + /// Representation of a string segment. 4 + #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] 5 + #[repr(transparent)] 6 + pub struct Token(u32); 7 + 8 + impl Token { 9 + #[inline(always)] 10 + pub const fn new(ptr: u32) -> Self { 11 + Self(ptr) 12 + } 13 + 14 + #[inline(always)] 15 + pub(crate) const fn index(&self) -> usize { 16 + self.0 as usize 17 + } 18 + 19 + #[inline(always)] 20 + const fn to_bits(self) -> u32 { 21 + self.0 22 + } 23 + } 24 + 25 + impl Deref for Token { 26 + type Target = u32; 27 + 28 + #[inline] 29 + fn deref(&self) -> &Self::Target { 30 + &self.0 31 + } 32 + } 33 + 34 + /// An owned pair of [`Token`]s. 35 + #[derive(Copy, Clone, Debug)] 36 + // Alignment repr necessary to allow LLVM to better output 37 + // optimized codegen for `to_bits`, `PartialEq` 38 + // Prior art taken from my contribution to Bevy: 39 + // https://github.com/bevyengine/bevy/blob/main/crates/bevy_ecs/src/entity/mod.rs#L309 40 + #[repr(C, align(8))] 41 + pub struct TokenPair { 42 + // Do not reorder the fields here. The ordering is explicitly used by repr(C) 43 + // to make this struct equivalent to a u64. 44 + #[cfg(target_endian = "little")] 45 + pub left: Token, 46 + pub right: Token, 47 + #[cfg(target_endian = "big")] 48 + pub left: Token, 49 + } 50 + 51 + // By not short-circuiting in comparisons, we get better codegen. 52 + // See <https://github.com/rust-lang/rust/issues/117800> 53 + impl PartialEq for TokenPair { 54 + #[inline(always)] 55 + fn eq(&self, other: &TokenPair) -> bool { 56 + // By using `to_bits`, the codegen can be optimized out even 57 + // further potentially. Relies on the correct alignment/field 58 + // order of `TokenPair`. 59 + self.to_bits() == other.to_bits() 60 + } 61 + } 62 + 63 + impl Eq for TokenPair {} 64 + 65 + impl core::hash::Hash for TokenPair { 66 + #[inline(always)] 67 + fn hash<H: core::hash::Hasher>(&self, state: &mut H) { 68 + self.to_bits().hash(state); 69 + } 70 + } 71 + 72 + impl TokenPair { 73 + #[inline(always)] 74 + pub const fn new(left: Token, right: Token) -> Self { 75 + Self { left, right } 76 + } 77 + 78 + #[inline(always)] 79 + const fn to_bits(self) -> u64 { 80 + self.left.to_bits() as u64 | ((self.right.to_bits() as u64) << 32) 81 + } 82 + } 83 + 84 + impl AsRef<TokenPair> for TokenPair { 85 + #[inline] 86 + fn as_ref(&self) -> &TokenPair { 87 + self 88 + } 89 + } 90 + 91 + #[cfg(test)] 92 + mod tests { 93 + use super::*; 94 + 95 + #[test] 96 + fn token_smoke_testing() { 97 + let left = Token(0x2); 98 + let right = Token(0x2b); 99 + 100 + let pair = TokenPair::new(left, right); 101 + 102 + assert_eq!(pair.to_bits(), 0x2b00000002); 103 + assert_eq!(pair.left, left); 104 + assert_eq!(pair.right, right); 105 + 106 + let other_right = Token(0x2c); 107 + 108 + let other_pair = TokenPair::new(left, other_right); 109 + 110 + assert_eq!(other_pair.to_bits(), 0x2c00000002); 111 + assert_ne!(pair, other_pair); 112 + } 113 + }
+16
crates/nailnet/Cargo.toml
··· 1 + [package] 2 + name = "nailnet" 3 + authors.workspace = true 4 + edition.workspace = true 5 + repository.workspace = true 6 + version.workspace = true 7 + license.workspace = true 8 + rust-version.workspace = true 9 + 10 + [dependencies] 11 + socket2 = "0.6.0" 12 + color-eyre.workspace = true 13 + tokio.workspace = true 14 + 15 + [lints] 16 + workspace = true
+25
crates/nailnet/src/lib.rs
··· 1 + use core::{net::SocketAddr, str::FromStr}; 2 + 3 + use socket2::{Domain, Socket, Type}; 4 + 5 + pub fn get_tcp_socket(addr: &str) -> color_eyre::Result<tokio::net::TcpListener> { 6 + let addr = SocketAddr::from_str(addr)?; 7 + 8 + let socket = match addr { 9 + SocketAddr::V4(_) => Socket::new(Domain::IPV4, Type::STREAM, None)?, 10 + SocketAddr::V6(_) => Socket::new(Domain::IPV6, Type::STREAM, None)?, 11 + }; 12 + 13 + socket.set_reuse_port(true)?; 14 + socket.set_reuse_address(true)?; 15 + socket.set_nonblocking(true)?; 16 + socket.set_tcp_nodelay(true)?; 17 + socket.bind(&addr.into())?; 18 + socket.listen(1024)?; 19 + 20 + let listener = std::net::TcpListener::from(socket); 21 + 22 + let listener = tokio::net::TcpListener::from_std(listener)?; 23 + 24 + Ok(listener) 25 + }
+28
crates/nailotel/Cargo.toml
··· 1 + [package] 2 + name = "nailotel" 3 + authors.workspace = true 4 + edition.workspace = true 5 + repository.workspace = true 6 + version.workspace = true 7 + license.workspace = true 8 + rust-version.workspace = true 9 + 10 + [features] 11 + 12 + [dependencies] 13 + nailconfig = { path = "../nailconfig" } 14 + tracing.workspace = true 15 + tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] } 16 + tracing-opentelemetry = { version = "0.32" } 17 + color-eyre.workspace = true 18 + opentelemetry.workspace = true 19 + opentelemetry-otlp.workspace = true 20 + opentelemetry_sdk.workspace = true 21 + opentelemetry-semantic-conventions.workspace = true 22 + opentelemetry-appender-tracing = { version = "0.31", features = [ 23 + "experimental_metadata_attributes", 24 + "experimental_use_tracing_span_context", 25 + ] } 26 + 27 + [lints] 28 + workspace = true
+173
crates/nailotel/src/lib.rs
··· 1 + use std::sync::{Arc, OnceLock}; 2 + 3 + use color_eyre::Result; 4 + 5 + use nailconfig::NailConfig; 6 + use opentelemetry::{ 7 + KeyValue, global, propagation::TextMapCompositePropagator, trace::TracerProvider, 8 + }; 9 + use opentelemetry_appender_tracing::layer::OpenTelemetryTracingBridge; 10 + use opentelemetry_otlp::{LogExporter, Protocol, SpanExporter, WithExportConfig, WithTonicConfig}; 11 + use opentelemetry_sdk::{ 12 + Resource, 13 + logs::{ 14 + BatchConfig as BatchLogConfig, SdkLoggerProvider, 15 + log_processor_with_async_runtime::BatchLogProcessor, 16 + }, 17 + propagation::{BaggagePropagator, TraceContextPropagator}, 18 + runtime::TokioCurrentThread, 19 + trace::{ 20 + BatchConfig as BatchTraceConfig, RandomIdGenerator, Sampler, SdkTracerProvider, 21 + span_processor_with_async_runtime::BatchSpanProcessor, 22 + }, 23 + }; 24 + use opentelemetry_semantic_conventions::{SCHEMA_URL, resource::SERVICE_VERSION}; 25 + use tracing::level_filters::LevelFilter; 26 + use tracing_opentelemetry::OpenTelemetryLayer; 27 + use tracing_subscriber::{EnvFilter, Layer, layer::SubscriberExt, util::SubscriberInitExt}; 28 + 29 + static RESOURCE: OnceLock<Resource> = OnceLock::new(); 30 + 31 + pub struct OtelGuard { 32 + otel_logger: Option<SdkLoggerProvider>, 33 + otel_traces: Option<SdkTracerProvider>, 34 + } 35 + 36 + impl Drop for OtelGuard { 37 + fn drop(&mut self) { 38 + if let Some(logs_provider) = self.otel_logger.take() 39 + && let Err(e) = logs_provider.shutdown() 40 + { 41 + tracing::error!(error = %e, "Error shutting down Logs Provider"); 42 + } 43 + if let Some(trace_provider) = self.otel_traces.take() 44 + && let Err(e) = trace_provider.shutdown() 45 + { 46 + tracing::error!(error = %e, "Error shutting down Trace Provider"); 47 + } 48 + } 49 + } 50 + 51 + fn resource(config: &NailConfig) -> Resource { 52 + RESOURCE 53 + .get_or_init(|| { 54 + Resource::builder() 55 + .with_service_name(config.open_telemetry.service_name.clone()) 56 + .with_schema_url( 57 + [KeyValue::new(SERVICE_VERSION, env!("CARGO_PKG_VERSION"))], 58 + SCHEMA_URL, 59 + ) 60 + .build() 61 + }) 62 + .clone() 63 + } 64 + 65 + pub fn init_logging_reporter(config: &NailConfig) -> Result<SdkLoggerProvider> { 66 + let log_exporter = LogExporter::builder() 67 + .with_tonic() 68 + .with_endpoint(&config.open_telemetry.endpoint) 69 + .with_compression(opentelemetry_otlp::Compression::Zstd) 70 + .with_protocol(Protocol::Grpc) 71 + .with_timeout(opentelemetry_otlp::OTEL_EXPORTER_OTLP_TIMEOUT_DEFAULT) 72 + .build()?; 73 + 74 + Ok(SdkLoggerProvider::builder() 75 + .with_log_processor( 76 + BatchLogProcessor::builder(log_exporter, TokioCurrentThread) 77 + .with_batch_config(BatchLogConfig::default()) 78 + .build(), 79 + ) 80 + .with_resource(resource(config)) 81 + .build()) 82 + } 83 + 84 + pub fn init_tracing_reporter(config: &NailConfig) -> Result<SdkTracerProvider> { 85 + let baggage_propagator = BaggagePropagator::new(); 86 + let trace_context_propagator = TraceContextPropagator::new(); 87 + let composite_propagator = TextMapCompositePropagator::new(vec![ 88 + Box::new(baggage_propagator), 89 + Box::new(trace_context_propagator), 90 + ]); 91 + 92 + global::set_text_map_propagator(composite_propagator); 93 + 94 + let trace_exporter = SpanExporter::builder() 95 + .with_tonic() 96 + .with_endpoint(&config.open_telemetry.endpoint) 97 + .with_protocol(Protocol::Grpc) 98 + .with_timeout(opentelemetry_otlp::OTEL_EXPORTER_OTLP_TIMEOUT_DEFAULT) 99 + .with_compression(opentelemetry_otlp::Compression::Zstd) 100 + .build()?; 101 + 102 + let provider = SdkTracerProvider::builder() 103 + .with_span_processor( 104 + BatchSpanProcessor::builder(trace_exporter, TokioCurrentThread) 105 + .with_batch_config(BatchTraceConfig::default()) 106 + .build(), 107 + ) 108 + .with_sampler(Sampler::ParentBased(Box::new(Sampler::TraceIdRatioBased( 109 + 1.0, 110 + )))) 111 + .with_resource(resource(config)) 112 + .with_id_generator(RandomIdGenerator::default()) 113 + .build(); 114 + 115 + Ok(provider) 116 + } 117 + 118 + pub fn init_telemetry(config: Arc<nailconfig::NailConfig>) -> Result<OtelGuard> { 119 + let otel_logger = if config.open_telemetry.logs { 120 + Some(init_logging_reporter(config.as_ref())?) 121 + } else { 122 + None 123 + }; 124 + 125 + let otel_traces = if config.open_telemetry.traces { 126 + Some(init_tracing_reporter(config.as_ref())?) 127 + } else { 128 + None 129 + }; 130 + 131 + tracing_subscriber::registry() 132 + .with( 133 + tracing_subscriber::filter::EnvFilter::builder() 134 + .with_default_directive(LevelFilter::INFO.into()) 135 + .from_env_lossy() 136 + .add_directive("hyper=off".parse().unwrap()) 137 + .add_directive("opentelemetry=off".parse().unwrap()) 138 + .add_directive("tonic=off".parse().unwrap()) 139 + .add_directive("tower=off".parse().unwrap()) 140 + .add_directive("h2=off".parse().unwrap()) 141 + .add_directive("reqwest=off".parse().unwrap()), 142 + ) 143 + .with( 144 + tracing_subscriber::fmt::layer() 145 + .with_level(true) 146 + .with_thread_names(true) 147 + .with_writer(std::io::stdout) 148 + .compact(), 149 + ) 150 + .with(otel_logger.as_ref().map(|otel| { 151 + let filter_otel = EnvFilter::new("info") 152 + .add_directive("hyper=off".parse().unwrap()) 153 + .add_directive("opentelemetry=off".parse().unwrap()) 154 + .add_directive("tonic=off".parse().unwrap()) 155 + .add_directive("tower=off".parse().unwrap()) 156 + .add_directive("h2=off".parse().unwrap()) 157 + .add_directive("reqwest=off".parse().unwrap()); 158 + 159 + OpenTelemetryTracingBridge::new(otel).with_filter(filter_otel) 160 + })) 161 + .with(otel_traces.as_ref().map(|otel| { 162 + OpenTelemetryLayer::new(otel.tracer(config.open_telemetry.service_name.clone())) 163 + })) 164 + .init(); 165 + 166 + tracing::info!("Welcome to Nailpit!"); 167 + tracing::info!(configuration = ?config, "Loaded configuration"); 168 + 169 + Ok(OtelGuard { 170 + otel_logger, 171 + otel_traces, 172 + }) 173 + }
+32
crates/nailrater/Cargo.toml
··· 1 + [package] 2 + name = "nailrater" 3 + authors.workspace = true 4 + edition.workspace = true 5 + repository.workspace = true 6 + version.workspace = true 7 + license.workspace = true 8 + rust-version.workspace = true 9 + 10 + [features] 11 + detailed_traces = [] 12 + 13 + [dependencies] 14 + nailfv = { path = "../nailfv" } 15 + nailconfig = { path = "../nailconfig" } 16 + nailspicy = { path = "../nailspicy" } 17 + nailip = { path = "../nailip" } 18 + nailbox = { path = "../nailbox" } 19 + axum.workspace = true 20 + futures-lite.workspace = true 21 + hyper.workspace = true 22 + pin-project-lite.workspace = true 23 + parking_lot.workspace = true 24 + tracing.workspace = true 25 + tracing-futures.workspace = true 26 + scc.workspace = true 27 + tokio.workspace = true 28 + rapidhash.workspace = true 29 + tower.workspace = true 30 + 31 + [lints] 32 + workspace = true
+297
crates/nailrater/src/futures.rs
··· 1 + use core::{ 2 + pin::Pin, 3 + task::{Context, Poll}, 4 + }; 5 + use std::{sync::Arc, time::Instant}; 6 + 7 + use axum::{ 8 + body::{Body, Bytes}, 9 + extract::Request, 10 + http::HeaderValue, 11 + response::{IntoResponse, Response}, 12 + }; 13 + use futures_lite::{FutureExt, future::Boxed, ready}; 14 + use hyper::{ 15 + StatusCode, 16 + header::{CONTENT_ENCODING, CONTENT_TYPE}, 17 + }; 18 + use nailbox::boxed_future_within; 19 + use nailip::IdentifiedPeer; 20 + use nailspicy::{SpicyPayloadKind, SpicyPayloads}; 21 + use pin_project_lite::pin_project; 22 + use rapidhash::quality::RandomState; 23 + use scc::hash_map::Entry; 24 + use tokio::time::{Sleep, sleep}; 25 + 26 + use crate::{PEERS, PeerRecord, PeerState, modes::LimitModes, scheduler::PRUNING_SCHEDULER}; 27 + 28 + pin_project! { 29 + pub struct NailedResponseFuture<S, F> { 30 + #[pin] 31 + state: NailedState<S, F>, 32 + } 33 + } 34 + 35 + pin_project! { 36 + #[project = NailedStateProj] 37 + enum NailedState<S, F> { 38 + RatePeer { 39 + req: Option<Request>, 40 + spicy_payloads: Option<Arc<SpicyPayloads>>, 41 + mode: LimitModes, 42 + entry: Boxed<Entry<'static, IdentifiedPeer, PeerRecord, RandomState>>, 43 + inner: S, 44 + }, 45 + Normal { 46 + #[pin] 47 + state: NailedNormalFuture<F>, 48 + }, 49 + Other { 50 + state: NailedOtherState, 51 + } 52 + } 53 + } 54 + 55 + pin_project! { 56 + struct NailedNormalFuture<T> { 57 + #[pin] 58 + state: NormalState, 59 + #[pin] 60 + inner: T, 61 + } 62 + } 63 + 64 + pin_project! { 65 + #[project = NormalStateProj] 66 + enum NormalState { 67 + Prune { 68 + prune: Boxed<()>, 69 + delay: Option<Pin<Box<Sleep>>>, 70 + }, 71 + Delay { 72 + delay: Pin<Box<Sleep>>, 73 + }, 74 + Pass, 75 + } 76 + } 77 + 78 + impl NormalState { 79 + #[inline] 80 + fn new(prune: Option<Boxed<()>>, delay: Option<Pin<Box<Sleep>>>) -> Self { 81 + match (prune, delay) { 82 + (Some(prune), delay) => NormalState::Prune { prune, delay }, 83 + (None, Some(delay)) => NormalState::Delay { delay }, 84 + (None, None) => NormalState::Pass, 85 + } 86 + } 87 + } 88 + 89 + enum NailedOtherState { 90 + Dropped, 91 + Spicy { 92 + payload: Bytes, 93 + kind: SpicyPayloadKind, 94 + }, 95 + Error, 96 + Finished, 97 + } 98 + 99 + #[inline] 100 + #[cfg_attr( 101 + feature = "detailed_traces", 102 + tracing::instrument(name = "prune_old_peers", level = "trace", skip_all) 103 + )] 104 + fn prune() -> Boxed<()> { 105 + boxed_future_within(async move || { 106 + tracing::trace!("PRUNING STARTED"); 107 + 108 + PEERS 109 + .retain_async(|_, v| v.last_seen.elapsed() < crate::PEER_TIMEOUT) 110 + .await 111 + }) 112 + } 113 + 114 + impl<S, T> NailedResponseFuture<S, T> { 115 + #[inline] 116 + pub fn rate_peer( 117 + peer: IdentifiedPeer, 118 + spicy_payloads: Option<Arc<SpicyPayloads>>, 119 + mode: LimitModes, 120 + req: Request, 121 + inner: S, 122 + ) -> Self { 123 + Self { 124 + state: NailedState::RatePeer { 125 + req: Some(req), 126 + mode, 127 + spicy_payloads, 128 + entry: boxed_future_within(|| PEERS.entry_async(peer)), 129 + inner, 130 + }, 131 + } 132 + } 133 + 134 + #[inline] 135 + pub fn error() -> Self { 136 + Self { 137 + state: NailedState::Other { 138 + state: NailedOtherState::Error, 139 + }, 140 + } 141 + } 142 + } 143 + 144 + impl<E, F, S> Future for NailedResponseFuture<S, F> 145 + where 146 + F: Future<Output = Result<Response<Body>, E>>, 147 + S: tower::Service<Request, Response = Response<Body>, Future = F> + Send + 'static, 148 + S::Future: Send + 'static, 149 + { 150 + type Output = Result<Response<Body>, E>; 151 + 152 + #[inline] 153 + fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { 154 + let mut state = self.project().state; 155 + 156 + loop { 157 + match state.as_mut().project() { 158 + NailedStateProj::RatePeer { 159 + req, 160 + spicy_payloads, 161 + mode, 162 + entry, 163 + inner, 164 + } => { 165 + let entry = ready!(entry.poll(cx)); 166 + let req = req.take().unwrap(); // If this panics, it is because the future was polled twice in the wrong state. 167 + let peer = entry 168 + .and_modify(|p| { 169 + p.count += 1; 170 + p.last_seen = Instant::now(); 171 + p.state = mode.limit(&p.count); 172 + }) 173 + .or_insert_with_key(|proxied| { 174 + tracing::info!("remote.peer" = %proxied, "New remote peer"); 175 + PeerRecord { 176 + count: 1, 177 + state: mode.limit(&1), 178 + last_seen: Instant::now(), 179 + supports_spicy: SpicyPayloadKind::accepts_encoding(req.headers()), 180 + } 181 + }); 182 + 183 + let delay = match peer.state { 184 + PeerState::Ready => None, 185 + PeerState::Delay(delay) => Some(boxed_future_within(|| sleep(delay))), 186 + PeerState::SpicyDrop => { 187 + let new_state = spicy_payloads 188 + .as_deref() 189 + .zip(peer.supports_spicy) 190 + .and_then(|(payloads, kind)| { 191 + payloads.get(&kind).map(|payload| (payload.clone(), kind)) 192 + }) 193 + .map_or_else( 194 + || NailedState::Other { 195 + state: NailedOtherState::Dropped, 196 + }, 197 + |(payload, kind)| NailedState::Other { 198 + state: NailedOtherState::Spicy { payload, kind }, 199 + }, 200 + ); 201 + 202 + state.set(new_state); 203 + 204 + continue; 205 + } 206 + _ => { 207 + state.set(NailedState::Other { 208 + state: NailedOtherState::Dropped, 209 + }); 210 + 211 + continue; 212 + } 213 + }; 214 + 215 + let prune = PRUNING_SCHEDULER.schedule(prune); 216 + 217 + let inner = inner.call(req); 218 + 219 + state.set(NailedState::Normal { 220 + state: NailedNormalFuture { 221 + state: NormalState::new(prune, delay), 222 + inner, 223 + }, 224 + }); 225 + } 226 + NailedStateProj::Normal { state } => return state.poll(cx), 227 + NailedStateProj::Other { state } => return Poll::Ready(Ok(state.build_response())), 228 + } 229 + } 230 + } 231 + } 232 + 233 + impl<E, F> Future for NailedNormalFuture<F> 234 + where 235 + F: Future<Output = Result<Response<Body>, E>>, 236 + { 237 + type Output = Result<Response<Body>, E>; 238 + 239 + #[inline] 240 + fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { 241 + let mut this = self.project(); 242 + 243 + loop { 244 + match this.state.as_mut().project() { 245 + NormalStateProj::Prune { prune, delay } => { 246 + ready!(prune.as_mut().poll(cx)); 247 + 248 + let next_state = delay 249 + .take() 250 + .map_or(NormalState::Pass, |delay| NormalState::Delay { delay }); 251 + 252 + this.state.set(next_state); 253 + } 254 + NormalStateProj::Delay { delay } => { 255 + ready!(delay.as_mut().poll(cx)); 256 + 257 + this.state.set(NormalState::Pass); 258 + } 259 + NormalStateProj::Pass => return this.inner.poll(cx), 260 + } 261 + } 262 + } 263 + } 264 + 265 + impl NailedOtherState { 266 + #[cfg_attr( 267 + feature = "detailed_traces", 268 + tracing::instrument(name = "Other Response", level = "trace", skip_all) 269 + )] 270 + #[inline] 271 + fn build_response(&mut self) -> Response<Body> { 272 + let state = core::mem::replace(self, Self::Finished); 273 + 274 + match state { 275 + Self::Dropped => (StatusCode::TOO_MANY_REQUESTS, "Go away").into_response(), 276 + Self::Spicy { payload, kind } => { 277 + let mut response = (StatusCode::TOO_MANY_REQUESTS, payload).into_response(); 278 + 279 + let headers = response.headers_mut(); 280 + 281 + headers.insert( 282 + CONTENT_TYPE, 283 + HeaderValue::from_static("text/html; charset=utf-8"), 284 + ); 285 + headers.insert(CONTENT_ENCODING, HeaderValue::from_static(kind.as_str())); 286 + 287 + response 288 + } 289 + Self::Error => ( 290 + StatusCode::INTERNAL_SERVER_ERROR, 291 + "Something is broken here", 292 + ) 293 + .into_response(), 294 + Self::Finished => unreachable!("Response future has been polled more than once"), 295 + } 296 + } 297 + }
+125
crates/nailrater/src/lib.rs
··· 1 + mod futures; 2 + mod modes; 3 + mod scheduler; 4 + 5 + use std::{ 6 + sync::{Arc, LazyLock}, 7 + time::{Duration, Instant}, 8 + }; 9 + 10 + use axum::{body::Body, extract::Request, response::Response}; 11 + use futures::NailedResponseFuture; 12 + 13 + use modes::LimitModes; 14 + use nailconfig::RateLimitingConfig; 15 + use nailip::IdentifiedPeer; 16 + use nailspicy::{SpicyPayloadKind, SpicyPayloads}; 17 + use rapidhash::quality::RandomState; 18 + use scc::HashMap; 19 + use tracing_futures::{Instrument, Instrumented}; 20 + 21 + const PEER_TIMEOUT: Duration = Duration::from_secs(60 * 2); 22 + 23 + static PEERS: LazyLock<HashMap<IdentifiedPeer, PeerRecord, RandomState>> = 24 + LazyLock::new(Default::default); 25 + 26 + #[derive(Debug, Default, Clone, Copy, PartialEq, Eq)] 27 + enum PeerState { 28 + #[default] 29 + Ready, 30 + Delay(Duration), 31 + Drop, 32 + SpicyDrop, 33 + } 34 + 35 + #[derive(Debug, Clone)] 36 + struct PeerRecord { 37 + count: u64, 38 + state: PeerState, 39 + last_seen: Instant, 40 + supports_spicy: Option<SpicyPayloadKind>, 41 + } 42 + 43 + #[derive(Debug, Clone)] 44 + pub struct NailRaterLayer { 45 + config: RateLimitingConfig, 46 + spicy_payload: Option<Arc<SpicyPayloads>>, 47 + } 48 + 49 + impl NailRaterLayer { 50 + pub fn new(config: RateLimitingConfig, spicy_payload: Option<Arc<SpicyPayloads>>) -> Self { 51 + Self { 52 + config, 53 + spicy_payload, 54 + } 55 + } 56 + } 57 + 58 + impl<S> tower::Layer<S> for NailRaterLayer { 59 + type Service = NailRater<S>; 60 + 61 + #[inline] 62 + fn layer(&self, inner: S) -> Self::Service { 63 + NailRater::new(&self.config, self.spicy_payload.clone(), inner) 64 + } 65 + } 66 + 67 + #[derive(Debug, Clone)] 68 + pub struct NailRater<S> { 69 + mode: LimitModes, 70 + spicy_payload: Option<Arc<SpicyPayloads>>, 71 + inner: S, 72 + } 73 + 74 + impl<S> NailRater<S> { 75 + #[inline] 76 + pub fn new( 77 + mode: impl Into<LimitModes>, 78 + spicy_payload: Option<Arc<SpicyPayloads>>, 79 + inner: S, 80 + ) -> Self { 81 + LazyLock::force(&PEERS); 82 + 83 + Self { 84 + mode: mode.into(), 85 + spicy_payload, 86 + inner, 87 + } 88 + } 89 + } 90 + 91 + impl<S> tower::Service<Request> for NailRater<S> 92 + where 93 + S: tower::Service<Request, Response = Response<Body>> + Clone + Send + 'static, 94 + S::Future: Send + 'static, 95 + { 96 + type Response = S::Response; 97 + type Error = S::Error; 98 + type Future = Instrumented<NailedResponseFuture<S, S::Future>>; 99 + 100 + #[inline] 101 + fn poll_ready( 102 + &mut self, 103 + cx: &mut std::task::Context<'_>, 104 + ) -> std::task::Poll<Result<(), Self::Error>> { 105 + self.inner.poll_ready(cx) 106 + } 107 + 108 + #[tracing::instrument(name = "rate_limiter", skip_all)] 109 + fn call(&mut self, req: Request) -> Self::Future { 110 + let Some(proxied) = req.extensions().get::<IdentifiedPeer>() else { 111 + return NailedResponseFuture::error().in_current_span(); 112 + }; 113 + 114 + let cloned = self.inner.clone(); 115 + let ready_inner = core::mem::replace(&mut self.inner, cloned); 116 + 117 + NailedResponseFuture::rate_peer( 118 + proxied.clone(), 119 + self.spicy_payload.clone(), 120 + self.mode.clone(), 121 + req, 122 + ready_inner, 123 + ).instrument(tracing::info_span!("rate_peer")) 124 + } 125 + }
+90
crates/nailrater/src/modes.rs
··· 1 + use std::time::Duration; 2 + 3 + use nailconfig::{DropBehavior, RateLimitingConfig}; 4 + 5 + use crate::PeerState; 6 + 7 + #[derive(Debug, Clone, PartialEq, Eq)] 8 + pub enum LimitModes { 9 + None, 10 + Soft { 11 + limit: u64, 12 + delay: u64, 13 + }, 14 + Hard { 15 + limit: u64, 16 + spicy: bool, 17 + }, 18 + SoftHard { 19 + soft_limit: u64, 20 + hard_limit: u64, 21 + delay: u64, 22 + spicy: bool, 23 + }, 24 + } 25 + 26 + impl LimitModes { 27 + pub(crate) fn limit(&self, visits: &u64) -> PeerState { 28 + match *self { 29 + LimitModes::Soft { limit, delay } if (limit..).contains(visits) => { 30 + PeerState::Delay(Duration::from_millis(delay)) 31 + } 32 + LimitModes::Hard { limit, spicy } if (limit..).contains(visits) => { 33 + if spicy { 34 + PeerState::SpicyDrop 35 + } else { 36 + PeerState::Drop 37 + } 38 + } 39 + LimitModes::SoftHard { 40 + soft_limit, 41 + hard_limit, 42 + delay, 43 + .. 44 + } if (soft_limit..hard_limit).contains(visits) => { 45 + PeerState::Delay(Duration::from_millis(delay)) 46 + } 47 + LimitModes::SoftHard { 48 + hard_limit, spicy, .. 49 + } if (hard_limit..).contains(visits) => { 50 + if spicy { 51 + PeerState::SpicyDrop 52 + } else { 53 + PeerState::Drop 54 + } 55 + } 56 + _ => PeerState::Ready, 57 + } 58 + } 59 + } 60 + 61 + impl From<&RateLimitingConfig> for LimitModes { 62 + #[inline] 63 + fn from(value: &RateLimitingConfig) -> Self { 64 + match value { 65 + RateLimitingConfig::NoLimit => Self::None, 66 + &RateLimitingConfig::SoftLimit { 67 + soft_limit: limit, 68 + soft_delay: delay, 69 + } => Self::Soft { limit, delay }, 70 + RateLimitingConfig::HardLimit { 71 + hard_limit: limit, 72 + drop_behavior, 73 + } => Self::Hard { 74 + limit: *limit, 75 + spicy: matches!(drop_behavior, DropBehavior::Spicy { .. }), 76 + }, 77 + RateLimitingConfig::SoftWithHardLimit { 78 + soft_limit, 79 + hard_limit, 80 + soft_delay: delay, 81 + drop_behavior, 82 + } => Self::SoftHard { 83 + soft_limit: *soft_limit, 84 + hard_limit: *hard_limit, 85 + delay: *delay, 86 + spicy: matches!(drop_behavior, DropBehavior::Spicy { .. }), 87 + }, 88 + } 89 + } 90 + }
+37
crates/nailrater/src/scheduler.rs
··· 1 + use std::time::Instant; 2 + 3 + use parking_lot::Mutex; 4 + 5 + use crate::PEER_TIMEOUT; 6 + 7 + pub(crate) struct Scheduler { 8 + value: Mutex<Option<Instant>>, 9 + } 10 + 11 + impl Scheduler { 12 + const fn new() -> Self { 13 + Self { 14 + value: Mutex::new(None), 15 + } 16 + } 17 + 18 + #[inline] 19 + pub(crate) fn schedule<F, T>(&self, task: F) -> Option<T> 20 + where 21 + F: Fn() -> T, 22 + { 23 + let mut inner = self.value.lock(); 24 + let elapsed = inner.get_or_insert_with(Instant::now).elapsed(); 25 + 26 + if elapsed >= PEER_TIMEOUT { 27 + inner.take(); 28 + drop(inner); 29 + 30 + Some(task()) 31 + } else { 32 + None 33 + } 34 + } 35 + } 36 + 37 + pub(crate) static PRUNING_SCHEDULER: Scheduler = Scheduler::new();
+13
crates/nailrng/Cargo.toml
··· 1 + [package] 2 + name = "nailrng" 3 + authors.workspace = true 4 + edition.workspace = true 5 + repository.workspace = true 6 + version.workspace = true 7 + license.workspace = true 8 + rust-version.workspace = true 9 + 10 + [dependencies] 11 + rand_core.workspace = true 12 + getrandom = { version = "0.3.2", features = ["std"] } 13 + wyrand.workspace = true
+52
crates/nailrng/src/lib.rs
··· 1 + //! A very fast, user-space RNG source in the same vein as `rand`'s `ThreadRng`. Not cryptographically secure, 2 + //! is meant to be a very fast entropy source. 3 + 4 + use std::cell::UnsafeCell; 5 + 6 + use rand_core::RngCore; 7 + use wyrand::WyRand; 8 + 9 + thread_local! { 10 + static SOURCE: UnsafeCell<WyRand> = UnsafeCell::new(WyRand::new(getrandom::u64().expect("Failed to source entropy"))) 11 + } 12 + 13 + pub struct FastRng(WyRand); 14 + 15 + impl FastRng { 16 + #[inline] 17 + pub fn fork(&mut self) -> Self { 18 + Self(WyRand::new(self.next_u64())) 19 + } 20 + } 21 + 22 + impl Default for FastRng { 23 + fn default() -> Self { 24 + SOURCE.with(|source| { 25 + // SAFETY: Dereferencing this cell is safe as the value has 26 + // been initialised, so it will not be null, and the mut reference 27 + // we create here only lives as long as this function's scope. Since 28 + // this is thread local, there is only one mut reference alive at any 29 + // given moment. 30 + let ptr = unsafe { &mut *source.get() }; 31 + 32 + FastRng(WyRand::new(ptr.rand())) 33 + }) 34 + } 35 + } 36 + 37 + impl RngCore for FastRng { 38 + #[inline(always)] 39 + fn next_u32(&mut self) -> u32 { 40 + self.0.next_u32() 41 + } 42 + 43 + #[inline(always)] 44 + fn next_u64(&mut self) -> u64 { 45 + self.0.next_u64() 46 + } 47 + 48 + #[inline(always)] 49 + fn fill_bytes(&mut self, dst: &mut [u8]) { 50 + self.0.fill_bytes(dst); 51 + } 52 + }
+28
crates/nailroutes/Cargo.toml
··· 1 + [package] 2 + name = "nailroutes" 3 + authors.workspace = true 4 + edition.workspace = true 5 + repository.workspace = true 6 + version.workspace = true 7 + license.workspace = true 8 + rust-version.workspace = true 9 + 10 + [dependencies] 11 + nailtrace = { path = "../nailtrace" } 12 + nailgen = { path = "../nailgen" } 13 + nailip = { path = "../nailip" } 14 + nailrater = { path = "../nailrater" } 15 + nailstate = { path = "../nailstate" } 16 + nailstream = { path = "../nailstream" } 17 + nailspicy = { path = "../nailspicy" } 18 + nailrng = { path = "../nailrng" } 19 + axum = { workspace = true } 20 + axum-extra = { version = "0.12", features = ["middleware"] } 21 + hyper.workspace = true 22 + tracing.workspace = true 23 + tracing-futures.workspace = true 24 + tower.workspace = true 25 + tower-http.workspace = true 26 + 27 + [lints] 28 + workspace = true
+94
crates/nailroutes/src/lib.rs
··· 1 + use axum::{Router, extract::MatchedPath, routing::get}; 2 + use axum_extra::middleware::option_layer; 3 + use hyper::StatusCode; 4 + use nailrater::NailRaterLayer; 5 + use nailrng::FastRng; 6 + use nailstate::{AppConfig, NailInputs, ServerState}; 7 + use nailstream::NailResponseStream; 8 + use nailtrace::trace_connection_layer; 9 + use tower::ServiceBuilder; 10 + use tower_http::normalize_path::NormalizePathLayer; 11 + use tracing_futures::Instrument; 12 + 13 + #[tracing::instrument(skip_all)] 14 + async fn warning( 15 + config: AppConfig, 16 + inputs: NailInputs, 17 + matched: MatchedPath, 18 + ) -> NailResponseStream<tracing_futures::Instrumented<nailgen::MarkovStream>> { 19 + let mut rng = FastRng::default(); 20 + 21 + NailResponseStream::from_stream( 22 + inputs 23 + .get_random_input(&mut rng) 24 + .into_stream( 25 + matched, 26 + config.clone_inner(), 27 + inputs.get_interner(), 28 + inputs.get_warning_template(), 29 + rng, 30 + ) 31 + .in_current_span(), 32 + ) 33 + } 34 + 35 + #[tracing::instrument(skip_all)] 36 + async fn generated( 37 + config: AppConfig, 38 + inputs: NailInputs, 39 + matched: MatchedPath, 40 + ) -> NailResponseStream<tracing_futures::Instrumented<nailgen::MarkovStream>> { 41 + let mut rng = FastRng::default(); 42 + 43 + NailResponseStream::from_stream( 44 + inputs 45 + .get_random_input(&mut rng) 46 + .into_stream( 47 + matched, 48 + config.clone_inner(), 49 + inputs.get_interner(), 50 + inputs.get_generated_template(), 51 + rng, 52 + ) 53 + .in_current_span(), 54 + ) 55 + } 56 + 57 + pub fn nail_app(state: ServerState) -> Router { 58 + let rate_limiting = state.config.rate_limiting.clone(); 59 + let spicy_payload = state.spicy_payloads.get(); 60 + let tracing_support = state.config.open_telemetry.traces || state.config.open_telemetry.logs; 61 + 62 + nail_route(state) 63 + .layer( 64 + ServiceBuilder::new() 65 + .layer(option_layer( 66 + tracing_support.then(|| axum::middleware::from_fn(trace_connection_layer)), 67 + )) 68 + .layer(NormalizePathLayer::trim_trailing_slash()) 69 + .layer(NailRaterLayer::new(rate_limiting, spicy_payload)), 70 + ) 71 + .route("/favicon.ico", get(async || StatusCode::NOT_FOUND)) 72 + .route("/health", get(async || StatusCode::NO_CONTENT)) 73 + } 74 + 75 + pub fn nail_route(state: ServerState) -> Router { 76 + let generation_routes = Router::new() 77 + .route("/", get(warning)) 78 + .route("/{*generated}", get(generated)); 79 + 80 + state 81 + .config 82 + .server 83 + .pit_routes 84 + .iter() 85 + .fold(Router::new(), |router, path| { 86 + if path == "/" { 87 + router.merge(generation_routes.clone()) 88 + } else { 89 + let nested_routes = generation_routes.clone(); 90 + router.nest(path, nested_routes) 91 + } 92 + }) 93 + .with_state(state) 94 + }
+25
crates/nailrt/Cargo.toml
··· 1 + [package] 2 + name = "nailrt" 3 + authors.workspace = true 4 + edition.workspace = true 5 + repository.workspace = true 6 + version.workspace = true 7 + license.workspace = true 8 + rust-version.workspace = true 9 + 10 + [dependencies] 11 + nailconfig = { path = "../nailconfig" } 12 + nailkov = { path = "../nailkov" } 13 + nailgen = { path = "../nailgen" } 14 + nailspicy = { path = "../nailspicy" } 15 + nailstate = { path = "../nailstate" } 16 + nailotel = { path = "../nailotel" } 17 + color-eyre.workspace = true 18 + core_affinity = "0.8.3" 19 + futures-concurrency.workspace = true 20 + tokio.workspace = true 21 + tokio-util.workspace = true 22 + tracing.workspace = true 23 + 24 + [lints] 25 + workspace = true
+122
crates/nailrt/src/lib.rs
··· 1 + mod shutdown; 2 + 3 + use core::time::Duration; 4 + 5 + use futures_concurrency::future::TryJoin; 6 + use nailstate::ServerState; 7 + use tokio_util::sync::CancellationToken; 8 + 9 + async fn worker_task<Fut, F>( 10 + worker: usize, 11 + app: ServerState, 12 + shutdown: CancellationToken, 13 + main_fn: &F, 14 + ) -> color_eyre::Result<()> 15 + where 16 + Fut: Future<Output = color_eyre::Result<()>>, 17 + F: Fn(ServerState, CancellationToken) -> Fut + Sync + Send, 18 + { 19 + while let Err(e) = main_fn(app.clone(), shutdown.clone()).await { 20 + tracing::error!(error = %e, worker = worker, "Failed to start"); 21 + // Wait a moment before trying again 22 + tokio::time::sleep(Duration::from_secs(1)).await; 23 + tracing::info!(worker = worker, "Restarting Worker..."); 24 + } 25 + 26 + Ok(()) 27 + } 28 + 29 + pub fn start<Fut, F>(app: ServerState, main_fn: F) -> color_eyre::Result<()> 30 + where 31 + Fut: Future<Output = color_eyre::Result<()>>, 32 + F: Fn(ServerState, CancellationToken) -> Fut + Sync + Send, 33 + { 34 + let workers = std::thread::available_parallelism()?.min(app.config.server.worker_threads); 35 + 36 + let shutdown_notifier = CancellationToken::new(); 37 + 38 + let core_ids = core_affinity::get_core_ids().unwrap_or_default(); 39 + 40 + let mut id: usize = 0; 41 + 42 + core_ids 43 + .get({ 44 + let pin = id; 45 + id += 1; 46 + pin 47 + }) 48 + .copied() 49 + .map(core_affinity::set_for_current); 50 + 51 + // Main worker MUST start, else we just error out. 52 + let rt = tokio::runtime::Builder::new_current_thread() 53 + .enable_all() 54 + .build()?; 55 + 56 + std::thread::scope(|s| { 57 + for num in 1..workers.get() { 58 + let cloned = &main_fn; 59 + let app = &app; 60 + let shutdown_notifier = &shutdown_notifier; 61 + let core_id = core_ids 62 + .get({ 63 + let pin = id; 64 + id += 1; 65 + pin 66 + }) 67 + .copied(); 68 + 69 + // If any worker threads fail to be created, the program will terminate. If the 70 + // runtime within the worker thread fails to be created, this will also terminate the 71 + // program, and the error will get logged. 72 + std::thread::Builder::new() 73 + .name(format!("worker {num}")) 74 + .spawn_scoped(s, move || { 75 + core_id.map(core_affinity::set_for_current); 76 + 77 + match tokio::runtime::Builder::new_current_thread() 78 + .enable_all() 79 + .build() 80 + { 81 + Ok(rt) => { 82 + rt.block_on(worker_task( 83 + num, 84 + app.clone(), 85 + shutdown_notifier.clone(), 86 + cloned, 87 + )) 88 + .ok(); 89 + 90 + rt.shutdown_timeout(Duration::from_secs(60)); 91 + } 92 + Err(e) => { 93 + tracing::error!(error = %e, worker = num, "Failed to start"); 94 + shutdown_notifier.cancel(); 95 + } 96 + } 97 + }) 98 + .inspect_err(|_| shutdown_notifier.cancel())?; 99 + } 100 + 101 + rt.block_on(async { 102 + let guard = nailotel::init_telemetry(app.config.clone_inner())?; 103 + 104 + ( 105 + worker_task(0, app.clone(), shutdown_notifier.clone(), &main_fn), 106 + crate::shutdown::shutdown_task(shutdown_notifier.clone()), 107 + ) 108 + .try_join() 109 + .await?; 110 + 111 + tracing::info!("Waiting for background tasks to complete..."); 112 + 113 + rt.spawn_blocking(|| drop(guard)); 114 + 115 + color_eyre::eyre::Ok(()) 116 + }) 117 + })?; 118 + 119 + rt.shutdown_timeout(Duration::from_secs(60)); 120 + 121 + Ok(()) 122 + }
+26
crates/nailrt/src/shutdown.rs
··· 1 + use color_eyre::Result; 2 + use futures_concurrency::future::Race; 3 + use tokio::signal; 4 + use tokio_util::sync::CancellationToken; 5 + 6 + pub async fn shutdown_task(notifier: CancellationToken) -> Result<()> { 7 + tracing::info!("Listening for shutdown signals"); 8 + 9 + let cancel = notifier.drop_guard(); 10 + 11 + let sigterm = async { 12 + signal::unix::signal(signal::unix::SignalKind::terminate())? 13 + .recv() 14 + .await; 15 + 16 + Ok(()) 17 + }; 18 + 19 + tokio::spawn((signal::ctrl_c(), sigterm).race()).await??; 20 + 21 + tracing::info!("Shutdown signal received, finishing..."); 22 + 23 + drop(cancel); 24 + 25 + Ok(()) 26 + }
+23
crates/nailserve/Cargo.toml
··· 1 + [package] 2 + name = "nailserve" 3 + authors.workspace = true 4 + edition.workspace = true 5 + repository.workspace = true 6 + version.workspace = true 7 + license.workspace = true 8 + rust-version.workspace = true 9 + 10 + [dependencies] 11 + nailip = { path = "../nailip" } 12 + axum.workspace = true 13 + hyper.workspace = true 14 + hyper-util = { version = "0.1", features = ["tokio", "server-auto", "server-graceful", "http1", "http2"] } 15 + tower.workspace = true 16 + tokio.workspace = true 17 + tokio-util.workspace = true 18 + tracing.workspace = true 19 + color-eyre.workspace = true 20 + futures-concurrency.workspace = true 21 + 22 + [lints] 23 + workspace = true
+60
crates/nailserve/src/lib.rs
··· 1 + use axum::{Router, extract::Request}; 2 + use futures_concurrency::future::Race; 3 + use hyper::body::Incoming; 4 + use hyper_util::{ 5 + rt::{TokioExecutor, TokioIo}, 6 + server::{conn::auto::Builder, graceful::GracefulShutdown}, 7 + }; 8 + use nailip::IdentifiedPeer; 9 + use tokio::net::TcpListener; 10 + use tokio_util::sync::CancellationToken; 11 + use tower::ServiceExt; 12 + 13 + async fn server_loop( 14 + listener: TcpListener, 15 + app: Router, 16 + graceful: &GracefulShutdown, 17 + ) -> color_eyre::Result<()> { 18 + let server = Builder::new(TokioExecutor::new()); 19 + 20 + loop { 21 + let (socket, remote_addr) = listener.accept().await?; 22 + 23 + let tower_service = app.clone(); 24 + 25 + let socket = TokioIo::new(socket); 26 + 27 + let hyper_service = hyper::service::service_fn(move |mut request: Request<Incoming>| { 28 + let peer = IdentifiedPeer::extract(request.headers(), remote_addr); 29 + request.extensions_mut().insert(peer); 30 + tower_service.clone().oneshot(request) 31 + }); 32 + 33 + let conn = server.serve_connection(socket, hyper_service); 34 + 35 + tokio::spawn(graceful.watch(conn.into_owned())); 36 + } 37 + } 38 + 39 + async fn cancel_loop(token: CancellationToken) -> color_eyre::Result<()> { 40 + token.cancelled().await; 41 + Ok(()) 42 + } 43 + 44 + /// Serves an Axum [`Router`] app with `hyper`, taking a [`CancellationToken`] to do a graceful shutdown 45 + /// loop. 46 + pub async fn serve( 47 + listener: TcpListener, 48 + app: Router, 49 + token: CancellationToken, 50 + ) -> color_eyre::Result<()> { 51 + let graceful = GracefulShutdown::new(); 52 + 53 + (server_loop(listener, app, &graceful), cancel_loop(token)) 54 + .race() 55 + .await?; 56 + 57 + graceful.shutdown().await; 58 + 59 + Ok(()) 60 + }
+19
crates/nailspicy/Cargo.toml
··· 1 + [package] 2 + name = "nailspicy" 3 + authors.workspace = true 4 + edition.workspace = true 5 + repository.workspace = true 6 + version.workspace = true 7 + license.workspace = true 8 + rust-version.workspace = true 9 + 10 + [dependencies] 11 + nailconfig = { path = "../nailconfig" } 12 + nailbox = { path = "../nailbox" } 13 + hyper.workspace = true 14 + rapidhash.workspace = true 15 + hashbrown.workspace = true 16 + tracing.workspace = true 17 + 18 + [lints] 19 + workspace = true
+84
crates/nailspicy/src/lib.rs
··· 1 + use std::sync::Arc; 2 + 3 + use hashbrown::HashMap; 4 + use hyper::{HeaderMap, body::Bytes, header::ACCEPT_ENCODING}; 5 + use nailbox::try_arc_within; 6 + use nailconfig::{DropBehavior, NailConfig, RateLimitingConfig}; 7 + use rapidhash::fast::RandomState; 8 + 9 + pub type SpicyPayloads = HashMap<SpicyPayloadKind, Bytes, RandomState>; 10 + 11 + static GZIP: &str = "gzip"; 12 + static BROTLI: &str = "br"; 13 + 14 + #[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)] 15 + #[repr(u32)] 16 + pub enum SpicyPayloadKind { 17 + Gz, 18 + Brotli, 19 + } 20 + 21 + impl SpicyPayloadKind { 22 + pub fn as_str(&self) -> &'static str { 23 + match self { 24 + SpicyPayloadKind::Gz => GZIP, 25 + SpicyPayloadKind::Brotli => BROTLI, 26 + } 27 + } 28 + } 29 + 30 + impl SpicyPayloadKind { 31 + fn file_kind(file: impl AsRef<str>) -> Option<SpicyPayloadKind> { 32 + let file = file.as_ref(); 33 + 34 + if file.ends_with(".gz") { 35 + Some(Self::Gz) 36 + } else if file.ends_with(".br") { 37 + Some(Self::Brotli) 38 + } else { 39 + None 40 + } 41 + } 42 + 43 + pub fn accepts_encoding(header: &HeaderMap) -> Option<SpicyPayloadKind> { 44 + header 45 + .get(ACCEPT_ENCODING) 46 + .and_then(|header| header.to_str().ok()) 47 + .and_then(|header| { 48 + header 49 + .contains(BROTLI) 50 + .then_some(Self::Brotli) 51 + .or_else(|| header.contains(GZIP).then_some(Self::Gz)) 52 + }) 53 + } 54 + } 55 + 56 + pub fn get_spicy_payload(config: &NailConfig) -> Option<Arc<SpicyPayloads>> { 57 + match &config.rate_limiting { 58 + RateLimitingConfig::HardLimit { 59 + drop_behavior: DropBehavior::Spicy { payload }, 60 + .. 61 + } 62 + | RateLimitingConfig::SoftWithHardLimit { 63 + drop_behavior: DropBehavior::Spicy { payload }, 64 + .. 65 + } => try_arc_within(|| { 66 + payload 67 + .iter() 68 + .filter_map(|file| SpicyPayloadKind::file_kind(file).map(|kind| (kind, file))) 69 + .map(|(kind, file)| { 70 + Ok(( 71 + kind, 72 + std::fs::read(file) 73 + .inspect_err(|err| { 74 + tracing::error!("Failed to load spicy payload: {err}") 75 + }) 76 + .map(Bytes::from)?, 77 + )) 78 + }) 79 + .collect::<std::io::Result<_>>() 80 + }) 81 + .ok(), 82 + _ => None, 83 + } 84 + }
+20
crates/nailstate/Cargo.toml
··· 1 + [package] 2 + name = "nailstate" 3 + authors.workspace = true 4 + edition.workspace = true 5 + repository.workspace = true 6 + version.workspace = true 7 + license.workspace = true 8 + rust-version.workspace = true 9 + 10 + [dependencies] 11 + nailrng = { path = "../nailrng" } 12 + nailconfig = { path = "../nailconfig" } 13 + nailgen = { path = "../nailgen" } 14 + nailkov = { path = "../nailkov" } 15 + nailspicy = { path = "../nailspicy" } 16 + axum.workspace = true 17 + rand.workspace = true 18 + 19 + [lints] 20 + workspace = true
+184
crates/nailstate/src/lib.rs
··· 1 + use std::{convert::Infallible, ops::Deref, sync::Arc}; 2 + 3 + use axum::extract::{FromRef, FromRequestParts}; 4 + use nailconfig::NailConfig; 5 + use nailgen::{GeneratedTemplate, MarkovGen, Template, WarningTemplate}; 6 + use nailkov::interner::Interner; 7 + use nailrng::FastRng; 8 + use nailspicy::SpicyPayloads; 9 + use rand::seq::IndexedRandom; 10 + 11 + pub struct Templates { 12 + pub warning: WarningTemplate, 13 + pub generated: GeneratedTemplate, 14 + } 15 + 16 + #[derive(Clone)] 17 + pub struct NailPayloads { 18 + spicy_payloads: Option<Arc<SpicyPayloads>>, 19 + } 20 + 21 + impl core::fmt::Debug for NailPayloads { 22 + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 23 + f.debug_struct("NailPayloads").finish_non_exhaustive() 24 + } 25 + } 26 + 27 + impl NailPayloads { 28 + pub fn get(&self) -> Option<Arc<SpicyPayloads>> { 29 + self.spicy_payloads.clone() 30 + } 31 + } 32 + 33 + /// Smart pointer for all available Markov chains. 34 + #[derive(Clone)] 35 + pub struct NailInputs { 36 + chains: Arc<[MarkovGen]>, 37 + interner: Arc<Interner>, 38 + templates: Arc<Templates>, 39 + } 40 + 41 + impl NailInputs { 42 + pub fn new( 43 + chains: Arc<[MarkovGen]>, 44 + interner: Arc<Interner>, 45 + templates: Arc<Templates>, 46 + ) -> Self { 47 + Self { 48 + chains, 49 + interner, 50 + templates, 51 + } 52 + } 53 + 54 + /// Pulls a random markov chain from the available list. Returns a cloned 55 + /// pointer to the selected chain. 56 + #[inline] 57 + pub fn get_random_input(&self, rng: &mut FastRng) -> MarkovGen { 58 + assert!(!self.chains.is_empty()); 59 + 60 + if self.chains.len() == 1 { 61 + self.chains[0].clone() 62 + } else { 63 + self.chains.choose(rng).unwrap().clone() 64 + } 65 + } 66 + 67 + #[inline] 68 + pub fn get_interner(&self) -> Arc<Interner> { 69 + self.interner.clone() 70 + } 71 + 72 + #[inline] 73 + pub fn get_warning_template(&self) -> Template { 74 + Template::from(self.templates.warning.clone()) 75 + } 76 + 77 + #[inline] 78 + pub fn get_generated_template(&self) -> Template { 79 + Template::from(self.templates.generated.clone()) 80 + } 81 + } 82 + 83 + impl std::fmt::Debug for NailInputs { 84 + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 85 + f.debug_tuple("NailInputs").finish_non_exhaustive() 86 + } 87 + } 88 + 89 + #[derive(Debug, Clone)] 90 + pub struct AppConfig(Arc<NailConfig>); 91 + 92 + impl AppConfig { 93 + pub fn clone_inner(&self) -> Arc<NailConfig> { 94 + self.0.clone() 95 + } 96 + } 97 + 98 + impl From<Arc<NailConfig>> for AppConfig { 99 + #[inline] 100 + fn from(value: Arc<NailConfig>) -> Self { 101 + Self(value) 102 + } 103 + } 104 + 105 + impl Deref for AppConfig { 106 + type Target = NailConfig; 107 + 108 + fn deref(&self) -> &Self::Target { 109 + self.0.as_ref() 110 + } 111 + } 112 + 113 + #[derive(Debug, Clone)] 114 + pub struct ServerState { 115 + pub config: AppConfig, 116 + pub inputs: NailInputs, 117 + pub spicy_payloads: NailPayloads, 118 + } 119 + 120 + impl ServerState { 121 + pub fn new( 122 + config: impl Into<AppConfig>, 123 + chains: Arc<[MarkovGen]>, 124 + interner: Arc<Interner>, 125 + templates: Arc<Templates>, 126 + spicy_payloads: Option<Arc<SpicyPayloads>>, 127 + ) -> Self { 128 + let config = config.into(); 129 + 130 + Self { 131 + config, 132 + inputs: NailInputs { 133 + chains, 134 + interner, 135 + templates, 136 + }, 137 + spicy_payloads: NailPayloads { spicy_payloads }, 138 + } 139 + } 140 + } 141 + 142 + impl FromRef<ServerState> for AppConfig { 143 + #[inline] 144 + fn from_ref(input: &ServerState) -> Self { 145 + input.config.clone() 146 + } 147 + } 148 + 149 + impl FromRef<ServerState> for NailInputs { 150 + #[inline] 151 + fn from_ref(input: &ServerState) -> Self { 152 + input.inputs.clone() 153 + } 154 + } 155 + 156 + impl<S> FromRequestParts<S> for AppConfig 157 + where 158 + AppConfig: FromRef<S>, 159 + S: Send + Sync, 160 + { 161 + type Rejection = Infallible; 162 + 163 + async fn from_request_parts( 164 + _parts: &mut axum::http::request::Parts, 165 + state: &S, 166 + ) -> Result<Self, Self::Rejection> { 167 + Ok(AppConfig::from_ref(state)) 168 + } 169 + } 170 + 171 + impl<S> FromRequestParts<S> for NailInputs 172 + where 173 + NailInputs: FromRef<S>, 174 + S: Send + Sync, 175 + { 176 + type Rejection = Infallible; 177 + 178 + async fn from_request_parts( 179 + _parts: &mut axum::http::request::Parts, 180 + state: &S, 181 + ) -> Result<Self, Self::Rejection> { 182 + Ok(NailInputs::from_ref(state)) 183 + } 184 + }
+17
crates/nailstream/Cargo.toml
··· 1 + [package] 2 + name = "nailstream" 3 + authors.workspace = true 4 + edition.workspace = true 5 + repository.workspace = true 6 + version.workspace = true 7 + license.workspace = true 8 + rust-version.workspace = true 9 + 10 + [lints] 11 + workspace = true 12 + 13 + [dependencies] 14 + axum.workspace = true 15 + hyper.workspace = true 16 + futures-lite.workspace = true 17 + tracing.workspace = true
+68
crates/nailstream/src/lib.rs
··· 1 + //! Util for defining a customised HTTP stream response, but for text/html or other headers. 2 + 3 + use std::{ 4 + convert::Infallible, 5 + pin::Pin, 6 + task::{Context, Poll}, 7 + }; 8 + 9 + use axum::{ 10 + body::Body, 11 + http::{HeaderValue, Response}, 12 + response::IntoResponse, 13 + }; 14 + use futures_lite::Stream; 15 + use hyper::{ 16 + body::{Bytes, Frame}, 17 + header::CONTENT_TYPE, 18 + }; 19 + 20 + const CONTENT_TYPE_VALUE: HeaderValue = HeaderValue::from_static("text/html; charset=utf-8"); 21 + 22 + pub struct NailResponseStream<S> { 23 + stream: S, 24 + } 25 + 26 + impl<S> NailResponseStream<S> 27 + where 28 + S: Stream<Item = Bytes> + Unpin + Send + 'static, 29 + { 30 + #[inline] 31 + pub fn from_stream(stream: S) -> Self { 32 + Self { stream } 33 + } 34 + } 35 + 36 + impl<S> hyper::body::Body for NailResponseStream<S> 37 + where 38 + S: Stream<Item = Bytes> + Unpin + Send + 'static, 39 + { 40 + type Data = Bytes; 41 + type Error = Infallible; 42 + 43 + #[inline] 44 + fn poll_frame( 45 + mut self: Pin<&mut Self>, 46 + cx: &mut Context<'_>, 47 + ) -> Poll<Option<Result<Frame<Self::Data>, Self::Error>>> { 48 + match core::pin::pin!(&mut self.stream).poll_next(cx) { 49 + Poll::Ready(Some(bytes)) => Poll::Ready(Some(Ok(Frame::data(bytes)))), 50 + Poll::Ready(None) => Poll::Ready(None), 51 + Poll::Pending => Poll::Pending, 52 + } 53 + } 54 + } 55 + 56 + impl<S> IntoResponse for NailResponseStream<S> 57 + where 58 + S: Stream<Item = Bytes> + Unpin + Send + 'static, 59 + { 60 + #[inline] 61 + fn into_response(self) -> Response<Body> { 62 + let mut response: Response<Body> = Response::new(Body::new(self)); 63 + response 64 + .headers_mut() 65 + .append(CONTENT_TYPE, CONTENT_TYPE_VALUE); 66 + response 67 + } 68 + }
+26
crates/nailtrace/Cargo.toml
··· 1 + [package] 2 + name = "nailtrace" 3 + authors.workspace = true 4 + edition.workspace = true 5 + repository.workspace = true 6 + version.workspace = true 7 + license.workspace = true 8 + rust-version.workspace = true 9 + 10 + [dependencies] 11 + nailip = { path = "../nailip" } 12 + nailstate = { path = "../nailstate" } 13 + axum = { workspace = true, features = ["matched-path"] } 14 + tracing.workspace = true 15 + tracing-opentelemetry.workspace = true 16 + tracing-futures.workspace = true 17 + hyper.workspace = true 18 + tower-http.workspace = true 19 + pin-project-lite.workspace = true 20 + opentelemetry.workspace = true 21 + opentelemetry-http.workspace = true 22 + opentelemetry-semantic-conventions.workspace = true 23 + uuid = { version = "1.18", features = ["v7", "fast-rng"] } 24 + 25 + [lints] 26 + workspace = true
+238
crates/nailtrace/src/lib.rs
··· 1 + use std::borrow::Cow; 2 + 3 + use axum::{ 4 + Extension, 5 + body::{Body as AxumBody, Bytes}, 6 + extract::{MatchedPath, Request}, 7 + http::HeaderValue, 8 + middleware::Next, 9 + response::Response, 10 + }; 11 + use hyper::{ 12 + HeaderMap, Uri, Version, 13 + body::Body, 14 + header::{CONTENT_ENCODING, CONTENT_TYPE, USER_AGENT}, 15 + }; 16 + use nailip::{IdentifiedPeer, header_value_to_str}; 17 + use opentelemetry::Context; 18 + use opentelemetry_http::HeaderExtractor; 19 + use opentelemetry_semantic_conventions::{ 20 + attribute::OTEL_STATUS_CODE, 21 + trace::{ERROR_TYPE, HTTP_RESPONSE_STATUS_CODE}, 22 + }; 23 + use tracing::{Span, field::Empty, info_span}; 24 + use uuid::Uuid; 25 + 26 + pub fn extract_context(headers: &HeaderMap) -> Context { 27 + opentelemetry::global::get_text_map_propagator(|propagator| { 28 + propagator.extract(&HeaderExtractor(headers)) 29 + }) 30 + } 31 + 32 + #[inline] 33 + pub fn url_scheme(uri: &Uri) -> &str { 34 + uri.scheme_str().unwrap_or_default() 35 + } 36 + 37 + #[inline] 38 + #[must_use] 39 + pub fn http_flavor(version: Version) -> Cow<'static, str> { 40 + match version { 41 + Version::HTTP_09 => "0.9".into(), 42 + Version::HTTP_10 => "1.0".into(), 43 + Version::HTTP_11 => "1.1".into(), 44 + Version::HTTP_2 => "2.0".into(), 45 + Version::HTTP_3 => "3.0".into(), 46 + other => format!("{other:?}").into(), 47 + } 48 + } 49 + 50 + pub async fn trace_connection_layer( 51 + identified: Extension<IdentifiedPeer>, 52 + req: Request, 53 + next: Next, 54 + ) -> Response<InspectBody<AxumBody>> { 55 + use tracing_opentelemetry::OpenTelemetrySpanExt; 56 + 57 + let headers = req.headers(); 58 + 59 + let request_id = headers.get("x-request-id").cloned().unwrap_or_else( 60 + // SAFETY: The UUID is converted to a valid UTF-8 string before being turned into 61 + // Bytes. As such, the Bytes instance corresponds to a valid internal repr for 62 + // HeaderValue, meaning we can skip validation directly. 63 + || unsafe { 64 + HeaderValue::from_maybe_shared_unchecked(Bytes::from(Uuid::now_v7().to_string())) 65 + }, 66 + ); 67 + 68 + let path = req 69 + .extensions() 70 + .get::<MatchedPath>() 71 + .map_or("not-matched", MatchedPath::as_str); 72 + 73 + let http_method = req.method().as_str(); 74 + 75 + let root_name = format!("{http_method} {path}"); 76 + 77 + let mut peer = identified.peer().split(":"); 78 + 79 + let span = info_span!( 80 + "HTTP request", 81 + http.request.method = %http_method, 82 + http.route = path, // to set by router of "webframework" after 83 + network.protocol.version = %http_flavor(req.version()), 84 + client.address = Empty, 85 + client.port = Empty, 86 + user_agent.original = headers 87 + .get(USER_AGENT) 88 + .and_then(header_value_to_str) 89 + .unwrap_or("None"), 90 + http.response.status_code = Empty, // to set on response 91 + http.response.header.content_encoding = Empty, 92 + http.response.header.content_type = Empty, 93 + url.path = req.uri().path(), 94 + url.query = req.uri().query(), 95 + http.scheme = url_scheme(req.uri()), 96 + otel.name = root_name, // to set by router of "webframework" after 97 + otel.kind = "server", 98 + otel.status_code = Empty, // to set on response 99 + trace_id = Empty, // to set on response 100 + http.request.header.request_id = Empty, // to set 101 + error.type = Empty, 102 + ); 103 + 104 + if let Some(address) = peer.next() { 105 + span.record("client.address", address); 106 + } 107 + 108 + if let Some(port) = peer.next() { 109 + span.record("client.port", port); 110 + } 111 + 112 + if let Some(request_id) = header_value_to_str(&request_id) { 113 + span.record("http.request.header.request_id", request_id); 114 + } 115 + 116 + let _ = span.set_parent(extract_context(headers)); 117 + 118 + let inner = span.in_scope(|| next.run(req)); 119 + 120 + let response = InspectHttpResponse { 121 + inner, 122 + span: InspectState::Ready { span, request_id }, 123 + }; 124 + 125 + response.await 126 + } 127 + 128 + enum InspectState { 129 + Ready { span: Span, request_id: HeaderValue }, 130 + Finished, 131 + } 132 + 133 + impl InspectState { 134 + #[inline] 135 + fn span_ref(&self) -> &Span { 136 + match self { 137 + Self::Ready { span, .. } => span, 138 + Self::Finished => unreachable!("Invalid state, future was polled after completion"), 139 + } 140 + } 141 + 142 + #[inline] 143 + fn take(&mut self) -> (Span, HeaderValue) { 144 + let span = core::mem::replace(self, Self::Finished); 145 + 146 + match span { 147 + Self::Ready { span, request_id } => (span, request_id), 148 + Self::Finished => unreachable!("Invalid state, future was polled after completion"), 149 + } 150 + } 151 + } 152 + 153 + pin_project_lite::pin_project! { 154 + struct InspectHttpResponse<F> { 155 + #[pin] 156 + inner: F, 157 + span: InspectState, 158 + } 159 + } 160 + 161 + pin_project_lite::pin_project! { 162 + #[doc(hidden)] 163 + pub struct InspectBody<B> { 164 + #[pin] 165 + body: B, 166 + span: Span, 167 + } 168 + } 169 + 170 + impl<F> core::future::Future for InspectHttpResponse<F> 171 + where 172 + F: core::future::Future<Output = Response>, 173 + { 174 + type Output = Response<InspectBody<AxumBody>>; 175 + 176 + #[inline] 177 + fn poll( 178 + self: core::pin::Pin<&mut Self>, 179 + cx: &mut core::task::Context<'_>, 180 + ) -> core::task::Poll<Self::Output> { 181 + let this = self.project(); 182 + 183 + let span = this.span.span_ref(); 184 + 185 + let poll = span.in_scope(|| this.inner.poll(cx)); 186 + 187 + if let core::task::Poll::Ready(mut response) = poll { 188 + let status = response.status(); 189 + let headers = response.headers(); 190 + 191 + span.record(HTTP_RESPONSE_STATUS_CODE, status.as_u16()); 192 + 193 + if let Some(encoding) = headers.get(CONTENT_ENCODING).and_then(header_value_to_str) { 194 + span.record("http.response.header.content_encoding", encoding); 195 + } 196 + 197 + if let Some(content_type) = headers.get(CONTENT_TYPE).and_then(header_value_to_str) { 198 + span.record("http.response.header.content_type", content_type); 199 + } 200 + 201 + if status.is_client_error() || status.is_server_error() { 202 + span.record(ERROR_TYPE, status.as_u16()); 203 + } 204 + 205 + if status.is_server_error() { 206 + span.record(OTEL_STATUS_CODE, "ERROR"); 207 + } else { 208 + span.record(OTEL_STATUS_CODE, "OK"); 209 + } 210 + 211 + let (span, request_id) = this.span.take(); 212 + 213 + response.headers_mut().insert("x-request-id", request_id); 214 + 215 + core::task::Poll::Ready(response.map(|body| InspectBody { body, span })) 216 + } else { 217 + core::task::Poll::Pending 218 + } 219 + } 220 + } 221 + 222 + impl<B> Body for InspectBody<B> 223 + where 224 + B: Body, 225 + { 226 + type Data = B::Data; 227 + type Error = B::Error; 228 + 229 + #[inline(always)] 230 + fn poll_frame( 231 + self: core::pin::Pin<&mut Self>, 232 + cx: &mut core::task::Context<'_>, 233 + ) -> core::task::Poll<Option<Result<hyper::body::Frame<Self::Data>, Self::Error>>> { 234 + let this = self.project(); 235 + 236 + this.span.in_scope(|| this.body.poll_frame(cx)) 237 + } 238 + }
+101
defaults/pit.default.toml
··· 1 + [server] 2 + # Define route entry points for the tarpit. By default, it is the root, but can 3 + # include more directories, or the root be excluded for other paths. 4 + pit_routes = ["/"] 5 + 6 + # The socket address the nailpit listens on 7 + socket_addr = "0.0.0.0:3000" 8 + 9 + # The amount of worker threads dedicated to the tarpit. Generating larger payloads 10 + # will benefit from more threads to balance the generation load better. 11 + worker_threads = 1 12 + 13 + [generator] 14 + # Input text files to feed the Markov Chain. Uses glob format. Multiple files that are 15 + # included will be turned into multiple different chains, so generated pages have randomised 16 + # garbage content to appear different during navigation. The more text provided the better. 17 + input_files = "input/*.txt" 18 + 19 + # The template file for the warning/entry page. A valid warning template will only use {{ title }}, 20 + # {{ main }} and {{ footer }} placeholders. 21 + warning_template = "templates/warning.html" 22 + # The content to be rendered in the warning page. Expects plain text, and the first line is rendered as 23 + # the title. All other text that is separated by line-breaks are rendered as paragraphs. 24 + warning_message = "templates/message.txt" 25 + 26 + # The template file for generated pages. A valid generation template can use all available placeholder types. 27 + generated_template = "templates/generated.html" 28 + 29 + # Minimum amount of words per generated paragraph. 30 + min_paragraph_size = 128 31 + # Maximum amount of words per generated paragraph. 32 + max_paragraph_size = 256 33 + 34 + # Maximum amount of links to be rendered in the footer to allow crawlers go deeper into the tarpit. 35 + # Acts as a form of staggering concurrency, so crawlers don't immediately open hundreds of connections. 36 + max_pit_links = 5 37 + 38 + # Maximum amount of characters in generated headers. 39 + header_size = 32 40 + 41 + # Amount of generated content in Kilobytes to be generated before the page completes. The smaller the payload, 42 + # the faster the generation, but the bigger the payload, the more resource pressure it applies to web crawlers. 43 + # Pages are compressed as they are streamed to the client however, so over the wire, this will be smaller. 44 + payload_size = 32 45 + 46 + # Maximum amount of time for a connection to stay alive before being dropped. If configuring for a slow loris 47 + # attack, you might want to increase this value depending on how much you are delaying your page generation and 48 + # how big the pages are. 49 + timeout = 30 50 + # Minimum amount of delay per generation loop. Used to configure tarpit for slow loris type attacks. 51 + min_delay = 0 52 + # Maximum amount of delay per generation loop. Used to configure tarpit for slow loris type attacks. 53 + # Greater variance between min and max delays creates less predictable delay patterns to disguise the 54 + # attack 55 + max_delay = 0 56 + 57 + # Size of chunk in bytes to be generated before being streamed to the client. This is for adjusting 58 + # throughput/latency characteristics of page generation and memory usage characteristics. This setting 59 + # should be adjusted according to hardware characteristics, but the value below is a fair default if you 60 + # want to have high throughput. Slow loris attack setups might want to tweak this value to be lower in 61 + # order to drip feed smaller portions of content to the client. 62 + chunk_size = 8192 63 + 64 + # Adds additional text to a page post generation loop (but before the footer links), useful for 65 + # adding prompts or static content. More than one bit of static content added here is randomly chosen 66 + # for rendering on a given generated page. 67 + prompts = [] 68 + 69 + [rate_limiting] 70 + # The kind of rate limiting you want enabled. Options are `no_limit`, `soft_limit` (which introduces a delay 71 + # to when the content generation starts if hit by too many), `hard_limit` (which drops the connection if too many 72 + # requests are made), `soft_with_hard_limit` (which combines the two soft and hard modes, delaying at first to then 73 + # dropping the request after still too many requests). 74 + type = "soft_limit" 75 + # The amount of requests needed to hit the soft limiting state. This resets if it hasn't received a request from 76 + # a client in more than two minutes. 77 + soft_limit = 200 78 + # The delay applied to soft limited clients. The delay is in milliseconds. 79 + soft_delay = 600 80 + # The amount of requests need to hit the hard limiting state. This setting only takes effect if `hard_limit` is set 81 + # on the `type` option. If the type option is set to `soft_with_hard_limit`, it is recommended to ensure this value 82 + # is always greater than the `soft_limit` amount. 83 + hard_limit = 300 84 + # If `hard_limit` or `soft_with_hard_limit` is set, then the connection dropping mechanics are set via 85 + # `drop_behavior`. By default, it is set to `normal` mode, which just terminates with connection with a RATE_LIMITED 86 + # HTTP status code. If you set to `spicy`, then you have an additional option: `payload`. `payload` accepts a list of 87 + # strings, which are paths to static compressed files you can send back to the client. It will only accept gzip and 88 + # brotli compressed files. I don't have to explain why you want statically compressed 'spicy' files to be sent over the wire ;) 89 + drop_behavior = { mode = "normal" } 90 + # drop_behavior = { mode = "spicy", payload = ["spicy.gz", "spicy.br"] } 91 + 92 + [open_telemetry] 93 + # The OTEL collector address & port for sending OTEL logs + traces to. 94 + endpoint = "http://127.0.0.1:4317" 95 + # The service name that will be used for OTEL logs and trace spans. 96 + service_name = "nailpit" 97 + # Enable logging to OTEL collector 98 + logs = false 99 + # Enable collecting trace data to OTEL collector. This option imposes a significant overhead, so only 100 + # enable it if you have the capacity for storing the data, which can be a lot during heavy traffic. 101 + traces = false
+39
dev/docker-compose.yaml
··· 1 + services: 2 + 3 + # Jaeger 4 + jaeger-all-in-one: 5 + image: docker.io/jaegertracing/all-in-one:latest 6 + restart: always 7 + environment: 8 + COLLECTOR_OTLP_ENABLED: true 9 + ports: 10 + - "16686:16686" 11 + - "14268" 12 + - "14250" 13 + - "43170:4317" 14 + 15 + # Zipkin 16 + zipkin-all-in-one: 17 + image: docker.io/openzipkin/zipkin:latest 18 + restart: always 19 + ports: 20 + - "9411:9411" 21 + 22 + # Collector 23 + otel-collector: 24 + image: docker.io/otel/opentelemetry-collector:latest 25 + restart: always 26 + command: ["--config=/etc/otel-collector-config.yaml", "${OTELCOL_ARGS}"] 27 + volumes: 28 + - ./otel-collector-config.yaml:/etc/otel-collector-config.yaml 29 + ports: 30 + - "1888:1888" # pprof extension 31 + - "8888:8888" # Prometheus metrics exposed by the collector 32 + - "8889:8889" # Prometheus exporter metrics 33 + - "13133:13133" # health_check extension 34 + - "4317:4317" # OTLP gRPC receiver 35 + - "4318:4318" 36 + - "55679:55679" # zpages extension 37 + depends_on: 38 + - jaeger-all-in-one 39 + - zipkin-all-in-one
+35
dev/otel-collector-config.yaml
··· 1 + receivers: 2 + otlp: 3 + protocols: 4 + grpc: 5 + endpoint: 0.0.0.0:4317 6 + http: 7 + endpoint: 0.0.0.0:4318 8 + 9 + exporters: 10 + zipkin: 11 + endpoint: "http://zipkin-all-in-one:9411/api/v2/spans" 12 + format: proto 13 + 14 + otlp: 15 + endpoint: jaeger-all-in-one:4317 16 + tls: 17 + insecure: true 18 + 19 + processors: 20 + batch: 21 + 22 + extensions: 23 + health_check: 24 + pprof: 25 + endpoint: :1888 26 + zpages: 27 + endpoint: :55679 28 + 29 + service: 30 + extensions: [pprof, zpages, health_check] 31 + pipelines: 32 + traces: 33 + receivers: [otlp] 34 + processors: [batch] 35 + exporters: [zipkin, otlp]
+6
docker-bake.hcl
··· 1 + target "default" { 2 + context = "." 3 + dockerfile = "Dockerfile" 4 + tags = ["docker.io/sachymetsu/nailpit:latest"] 5 + platforms = ["linux/amd64", "linux/arm64"] 6 + }
+57
src/inputs.rs
··· 1 + use std::{fs::read_to_string, sync::Arc}; 2 + 3 + use color_eyre::eyre::Context; 4 + use glob::glob; 5 + use nailbox::{arc_within, try_arc_within}; 6 + use nailconfig::NailConfig; 7 + use nailgen::{GeneratedTemplate, MarkovGen, WarningTemplate}; 8 + use nailkov::interner::Interner; 9 + use nailstate::Templates; 10 + 11 + /// Takes a glob for finding all input files and returns a read-only list of 12 + /// all markov chains that can be generated. 13 + pub fn get_input_files( 14 + config: &NailConfig, 15 + ) -> color_eyre::Result<(Arc<[MarkovGen]>, Arc<Interner>)> { 16 + let mut interner = arc_within(|| Interner::with_capacity(512)); 17 + 18 + let interned_mut = Arc::get_mut(&mut interner).unwrap(); 19 + 20 + let inputs = glob(&config.generator.input_files)? 21 + .filter_map(|path| { 22 + path.inspect_err(|err| tracing::error!("IO Error: {err}")) 23 + .ok() 24 + }) 25 + .filter_map(|input| { 26 + MarkovGen::new(input, interned_mut) 27 + .inspect_err(|err| tracing::error!("Markov Error: {err}")) 28 + .ok() 29 + }) 30 + .collect::<Arc<[MarkovGen]>>(); 31 + 32 + if inputs.is_empty() { 33 + color_eyre::eyre::bail!("No input files found! Exiting..."); 34 + } 35 + 36 + Ok((inputs, interner)) 37 + } 38 + 39 + pub fn get_template_files(config: &NailConfig) -> color_eyre::Result<Arc<Templates>> { 40 + let (index, content) = ( 41 + read_to_string(&config.generator.warning_template).context("Missing Warning Template")?, 42 + read_to_string(&config.generator.warning_message).context("Missing Warning Message")?, 43 + ); 44 + let generated = read_to_string(&config.generator.generated_template) 45 + .context("Missing Generated Template")?; 46 + 47 + let templates = try_arc_within(|| -> color_eyre::Result<Templates> { 48 + Ok(Templates { 49 + warning: WarningTemplate::init(index.into(), content.into()).context( 50 + "Warning Template should only contain title, main and footer placeholders" 51 + )?, 52 + generated: GeneratedTemplate::init(generated.into()).context("Generated template contains invalid placeholders, should only contain title, initial, main, extra and footer placeholders")?, 53 + }) 54 + })?; 55 + 56 + Ok(templates) 57 + }
+3
src/lib.rs
··· 1 + #![forbid(unsafe_code)] 2 + 3 + pub mod inputs;
+49
src/main.rs
··· 1 + #![forbid(unsafe_code)] 2 + use color_eyre::Result; 3 + use tokio_util::sync::CancellationToken; 4 + 5 + #[cfg(feature = "mimalloc")] 6 + #[global_allocator] 7 + static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; 8 + 9 + async fn spawn_axum_worker( 10 + state: nailstate::ServerState, 11 + shutdown_notifier: CancellationToken, 12 + ) -> Result<()> { 13 + let listener = nailnet::get_tcp_socket(&state.config.server.socket_addr)?; 14 + let ip = listener.local_addr()?; 15 + 16 + tracing::info!( 17 + port = ip.port(), 18 + address = ip.ip().to_string(), 19 + "{} listening on {}", 20 + std::thread::current().name().unwrap(), 21 + ip 22 + ); 23 + 24 + tokio::spawn(nailserve::serve( 25 + listener, 26 + nailroutes::nail_app(state), 27 + shutdown_notifier, 28 + )) 29 + .await? 30 + } 31 + 32 + fn main() -> Result<()> { 33 + color_eyre::install()?; 34 + 35 + let config = nailconfig::get_configuration()?; 36 + 37 + let (inputs, interner) = nailpit::inputs::get_input_files(config.as_ref())?; 38 + 39 + let templates = nailpit::inputs::get_template_files(config.as_ref())?; 40 + 41 + let spicy = nailspicy::get_spicy_payload(config.as_ref()); 42 + 43 + nailrt::start( 44 + nailstate::ServerState::new(config, inputs, interner, templates, spicy), 45 + spawn_axum_worker, 46 + )?; 47 + 48 + Ok(()) 49 + }
+23
templates/generated.html
··· 1 + <!DOCTYPE html> 2 + <html lang="en"> 3 + 4 + <head> 5 + <title>{{ TITLE }}</title> 6 + <meta charset="utf-8" /> 7 + <meta name="robots" content="noindex, nofollow, nosnippet, noimageindex" /> 8 + <meta name="referrer" content="noreferrer"> 9 + </head> 10 + 11 + <body> 12 + <main> 13 + <h1>{{ TITLE }}</h1> 14 + {{ INITIAL }} 15 + {{ MAIN }} 16 + {{ EXTRA }} 17 + <aside style="visibility: hidden;"> 18 + {{ FOOTER }} 19 + </aside> 20 + </main> 21 + </body> 22 + 23 + </html>
+13
templates/message.txt
··· 1 + Private Area 2 + 3 + If you've reached this page, then go back, do not go further. You have been warned. 4 + 5 + There is nothing here of substance, nothing to meaningful to read, nothing of importance or note. 6 + 7 + Here is the entry point for the Nail Pit. Within, there's a never-ending labyrinth of nonsense, chaos and malicious intent, though mostly rusty nails. Proceeding further will likely put your machine/browser at risk of shenanigans relating to memory usage with the intent on causing your computer to go OOM and crash. 8 + 9 + The only reason you'd continue further is if you are a curious soul, investigating the nature of this pit for research purposes, or you are not a human and cannot comprehend this warning, automated to crawl and scrape everything it can find, consequences be damned. 10 + 11 + Do not go further. Do not reveal the secret doors hidden within this warning. Step back from the precipice of the abyss and return home. 12 + 13 + You have been warned.
+21
templates/warning.html
··· 1 + <!DOCTYPE html> 2 + <html lang="en"> 3 + 4 + <head> 5 + <title>{{ TITLE }}</title> 6 + <meta charset="utf-8" /> 7 + <meta name="robots" content="noindex, nofollow, nosnippet, noimageindex" /> 8 + <meta name="referrer" content="noreferrer"> 9 + </head> 10 + 11 + <body> 12 + <main> 13 + <h1>{{ TITLE }}</h1> 14 + {{ MAIN }} 15 + <aside style="visibility: hidden;"> 16 + {{ FOOTER }} 17 + </aside> 18 + </main> 19 + </body> 20 + 21 + </html>