Constellation, Spacedust, Slingshot, UFOs: atproto crates and services for microcosm

Compare changes

Choose any two refs to compare.

+21
.github/workflows/build.yml
··· 1 + name: Build 2 + 3 + on: 4 + push: 5 + tags: 6 + - "reflector-v*.*.*" 7 + 8 + jobs: 9 + build: 10 + runs-on: ubuntu-latest 11 + permissions: 12 + contents: write 13 + 14 + steps: 15 + - uses: actions/checkout@v4 16 + - name: build reflector 17 + run: cargo build --bin reflector --release && mv target/release/reflector target/release/reflector_amd64 18 + - name: release 19 + uses: softprops/action-gh-release@v2 20 + with: 21 + files: target/release/reflector_amd64
+1 -1
.github/workflows/checks.yml
··· 28 28 - name: get nightly toolchain for jetstream fmt 29 29 run: rustup toolchain install nightly --allow-downgrade -c rustfmt 30 30 - name: fmt 31 - run: cargo fmt --package links --package constellation --package ufos --package spacedust --package who-am-i --package slingshot -- --check 31 + run: cargo fmt --package links --package constellation --package ufos --package spacedust --package who-am-i --package slingshot --package pocket -- --check 32 32 - name: fmt jetstream (nightly) 33 33 run: cargo +nightly fmt --package jetstream -- --check 34 34 - name: clippy
+199 -179
Cargo.lock
··· 162 162 "proc-macro2", 163 163 "quote", 164 164 "serde", 165 - "syn 2.0.103", 165 + "syn 2.0.106", 166 166 ] 167 167 168 168 [[package]] ··· 204 204 dependencies = [ 205 205 "proc-macro2", 206 206 "quote", 207 - "syn 2.0.103", 207 + "syn 2.0.106", 208 208 "synstructure", 209 209 ] 210 210 ··· 216 216 dependencies = [ 217 217 "proc-macro2", 218 218 "quote", 219 - "syn 2.0.103", 219 + "syn 2.0.106", 220 220 ] 221 221 222 222 [[package]] ··· 274 274 dependencies = [ 275 275 "proc-macro2", 276 276 "quote", 277 - "syn 2.0.103", 277 + "syn 2.0.106", 278 278 ] 279 279 280 280 [[package]] ··· 291 291 dependencies = [ 292 292 "proc-macro2", 293 293 "quote", 294 - "syn 2.0.103", 294 + "syn 2.0.106", 295 295 ] 296 296 297 297 [[package]] ··· 507 507 "derive_utils", 508 508 "proc-macro2", 509 509 "quote", 510 - "syn 2.0.103", 510 + "syn 2.0.106", 511 511 ] 512 512 513 513 [[package]] ··· 603 603 "axum-core", 604 604 "bytes", 605 605 "cookie", 606 + "form_urlencoded", 606 607 "futures-util", 607 608 "headers", 608 609 "http", ··· 612 613 "pin-project-lite", 613 614 "rustversion", 614 615 "serde", 616 + "serde_html_form", 617 + "serde_path_to_error", 615 618 "tower", 616 619 "tower-layer", 617 620 "tower-service", ··· 746 749 "regex", 747 750 "rustc-hash 1.1.0", 748 751 "shlex", 749 - "syn 2.0.103", 752 + "syn 2.0.106", 750 753 "which", 751 754 ] 752 755 ··· 765 768 "regex", 766 769 "rustc-hash 1.1.0", 767 770 "shlex", 768 - "syn 2.0.103", 771 + "syn 2.0.106", 769 772 ] 770 773 771 774 [[package]] ··· 783 786 "regex", 784 787 "rustc-hash 2.1.1", 785 788 "shlex", 786 - "syn 2.0.103", 789 + "syn 2.0.106", 787 790 ] 788 791 789 792 [[package]] ··· 859 862 860 863 [[package]] 861 864 name = "camino" 862 - version = "1.1.9" 865 + version = "1.2.1" 863 866 source = "registry+https://github.com/rust-lang/crates.io-index" 864 - checksum = "8b96ec4966b5813e2c0507c1f86115c8c5abaadc3980879c3424042a02fd1ad3" 867 + checksum = "276a59bf2b2c967788139340c9f0c5b12d7fd6630315c15c217e559de85d2609" 865 868 dependencies = [ 866 - "serde", 869 + "serde_core", 867 870 ] 868 871 869 872 [[package]] ··· 989 992 990 993 [[package]] 991 994 name = "clap" 992 - version = "4.5.46" 995 + version = "4.5.48" 993 996 source = "registry+https://github.com/rust-lang/crates.io-index" 994 - checksum = "2c5e4fcf9c21d2e544ca1ee9d8552de13019a42aa7dbf32747fa7aaf1df76e57" 997 + checksum = "e2134bb3ea021b78629caa971416385309e0131b351b25e01dc16fb54e1b5fae" 995 998 dependencies = [ 996 999 "clap_builder", 997 1000 "clap_derive", ··· 999 1002 1000 1003 [[package]] 1001 1004 name = "clap_builder" 1002 - version = "4.5.46" 1005 + version = "4.5.48" 1003 1006 source = "registry+https://github.com/rust-lang/crates.io-index" 1004 - checksum = "fecb53a0e6fcfb055f686001bc2e2592fa527efaf38dbe81a6a9563562e57d41" 1007 + checksum = "c2ba64afa3c0a6df7fa517765e31314e983f51dda798ffba27b988194fb65dc9" 1005 1008 dependencies = [ 1006 1009 "anstream", 1007 1010 "anstyle", ··· 1011 1014 1012 1015 [[package]] 1013 1016 name = "clap_derive" 1014 - version = "4.5.45" 1017 + version = "4.5.47" 1015 1018 source = "registry+https://github.com/rust-lang/crates.io-index" 1016 - checksum = "14cb31bb0a7d536caef2639baa7fad459e15c3144efefa6dbd1c84562c4739f6" 1019 + checksum = "bbfd7eae0b0f1a6e63d4b13c9c478de77c2eb546fba158ad50b4203dc24b9f9c" 1017 1020 dependencies = [ 1018 1021 "heck", 1019 1022 "proc-macro2", 1020 1023 "quote", 1021 - "syn 2.0.103", 1024 + "syn 2.0.106", 1022 1025 ] 1023 1026 1024 1027 [[package]] ··· 1310 1313 "proc-macro2", 1311 1314 "quote", 1312 1315 "strsim 0.11.1", 1313 - "syn 2.0.103", 1316 + "syn 2.0.106", 1314 1317 ] 1315 1318 1316 1319 [[package]] ··· 1332 1335 dependencies = [ 1333 1336 "darling_core 0.20.11", 1334 1337 "quote", 1335 - "syn 2.0.103", 1338 + "syn 2.0.106", 1336 1339 ] 1337 1340 1338 1341 [[package]] ··· 1372 1375 checksum = "18e4fdb82bd54a12e42fb58a800dcae6b9e13982238ce2296dc3570b92148e1f" 1373 1376 dependencies = [ 1374 1377 "data-encoding", 1375 - "syn 2.0.103", 1378 + "syn 2.0.106", 1376 1379 ] 1377 1380 1378 1381 [[package]] ··· 1434 1437 "darling 0.20.11", 1435 1438 "proc-macro2", 1436 1439 "quote", 1437 - "syn 2.0.103", 1440 + "syn 2.0.106", 1438 1441 ] 1439 1442 1440 1443 [[package]] ··· 1444 1447 checksum = "ab63b0e2bf4d5928aff72e83a7dace85d7bba5fe12dcc3c5a572d78caffd3f3c" 1445 1448 dependencies = [ 1446 1449 "derive_builder_core", 1447 - "syn 2.0.103", 1450 + "syn 2.0.106", 1448 1451 ] 1449 1452 1450 1453 [[package]] ··· 1464 1467 dependencies = [ 1465 1468 "proc-macro2", 1466 1469 "quote", 1467 - "syn 2.0.103", 1470 + "syn 2.0.106", 1468 1471 "unicode-xid", 1469 1472 ] 1470 1473 ··· 1476 1479 dependencies = [ 1477 1480 "proc-macro2", 1478 1481 "quote", 1479 - "syn 2.0.103", 1482 + "syn 2.0.106", 1480 1483 ] 1481 1484 1482 1485 [[package]] ··· 1520 1523 dependencies = [ 1521 1524 "proc-macro2", 1522 1525 "quote", 1523 - "syn 2.0.103", 1526 + "syn 2.0.106", 1524 1527 ] 1525 1528 1526 1529 [[package]] ··· 1537 1540 1538 1541 [[package]] 1539 1542 name = "dropshot" 1540 - version = "0.16.2" 1543 + version = "0.16.3" 1541 1544 source = "registry+https://github.com/rust-lang/crates.io-index" 1542 - checksum = "50e8fed669e35e757646ad10f97c4d26dd22cce3da689b307954f7000d2719d0" 1545 + checksum = "eedf902e40c1024b8ed9ca16378a54e9655cdf0e698245ba82d81a3778dcbc54" 1543 1546 dependencies = [ 1544 1547 "async-stream", 1545 1548 "async-trait", ··· 1556 1559 "http-body-util", 1557 1560 "hyper", 1558 1561 "hyper-util", 1559 - "indexmap 2.9.0", 1562 + "indexmap 2.11.4", 1560 1563 "multer", 1561 1564 "openapiv3", 1562 1565 "paste", ··· 1579 1582 "thiserror 2.0.16", 1580 1583 "tokio", 1581 1584 "tokio-rustls 0.25.0", 1582 - "toml", 1585 + "toml 0.9.7", 1583 1586 "uuid", 1584 1587 "version_check", 1585 1588 "waitgroup", ··· 1587 1590 1588 1591 [[package]] 1589 1592 name = "dropshot_endpoint" 1590 - version = "0.16.2" 1593 + version = "0.16.4" 1591 1594 source = "registry+https://github.com/rust-lang/crates.io-index" 1592 - checksum = "acebb687581abdeaa2c89fa448818a5f803b0e68e5d7e7a1cf585a8f3c5c57ac" 1595 + checksum = "89d09440e73a9dcf8a0f7fbd6ab889a7751d59f0fe76e5082a0a6d5623ec6da3" 1593 1596 dependencies = [ 1594 1597 "heck", 1595 1598 "proc-macro2", ··· 1597 1600 "semver", 1598 1601 "serde", 1599 1602 "serde_tokenstream", 1600 - "syn 2.0.103", 1603 + "syn 2.0.106", 1601 1604 ] 1602 1605 1603 1606 [[package]] ··· 1670 1673 "heck", 1671 1674 "proc-macro2", 1672 1675 "quote", 1673 - "syn 2.0.103", 1676 + "syn 2.0.106", 1674 1677 ] 1675 1678 1676 1679 [[package]] ··· 1682 1685 "once_cell", 1683 1686 "proc-macro2", 1684 1687 "quote", 1685 - "syn 2.0.103", 1688 + "syn 2.0.106", 1686 1689 ] 1687 1690 1688 1691 [[package]] ··· 1793 1796 [[package]] 1794 1797 name = "fjall" 1795 1798 version = "2.11.2" 1796 - source = "git+https://github.com/fjall-rs/fjall.git#42d811f7c8cc9004407d520d37d2a1d8d246c03d" 1799 + source = "git+https://github.com/fjall-rs/fjall.git?rev=fb229572bb7d1d6966a596994dc1708e47ec57d8#fb229572bb7d1d6966a596994dc1708e47ec57d8" 1797 1800 dependencies = [ 1798 1801 "byteorder", 1799 1802 "byteview", ··· 2062 2065 dependencies = [ 2063 2066 "proc-macro2", 2064 2067 "quote", 2065 - "syn 2.0.103", 2068 + "syn 2.0.106", 2066 2069 ] 2067 2070 2068 2071 [[package]] ··· 2187 2190 "futures-core", 2188 2191 "futures-sink", 2189 2192 "http", 2190 - "indexmap 2.9.0", 2193 + "indexmap 2.11.4", 2191 2194 "slab", 2192 2195 "tokio", 2193 2196 "tokio-util", ··· 2557 2560 "js-sys", 2558 2561 "log", 2559 2562 "wasm-bindgen", 2560 - "windows-core 0.61.0", 2563 + "windows-core", 2561 2564 ] 2562 2565 2563 2566 [[package]] ··· 2684 2687 dependencies = [ 2685 2688 "proc-macro2", 2686 2689 "quote", 2687 - "syn 2.0.103", 2690 + "syn 2.0.106", 2688 2691 ] 2689 2692 2690 2693 [[package]] ··· 2727 2730 2728 2731 [[package]] 2729 2732 name = "indexmap" 2730 - version = "2.9.0" 2733 + version = "2.11.4" 2731 2734 source = "registry+https://github.com/rust-lang/crates.io-index" 2732 - checksum = "cea70ddb795996207ad57735b50c5982d8844f38ba9ee5f1aedcfb708a2aa11e" 2735 + checksum = "4b0f83760fb341a774ed326568e19f5a863af4a952def8c39f9ab92fd95b88e5" 2733 2736 dependencies = [ 2734 2737 "equivalent", 2735 2738 "hashbrown 0.15.2", 2736 2739 "serde", 2740 + "serde_core", 2737 2741 ] 2738 2742 2739 2743 [[package]] ··· 2887 2891 dependencies = [ 2888 2892 "proc-macro2", 2889 2893 "quote", 2890 - "syn 2.0.103", 2894 + "syn 2.0.106", 2891 2895 ] 2892 2896 2893 2897 [[package]] ··· 3148 3152 3149 3153 [[package]] 3150 3154 name = "log" 3151 - version = "0.4.27" 3155 + version = "0.4.28" 3152 3156 source = "registry+https://github.com/rust-lang/crates.io-index" 3153 - checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" 3157 + checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432" 3154 3158 3155 3159 [[package]] 3156 3160 name = "loom" ··· 3264 3268 "spin", 3265 3269 "tokio", 3266 3270 "tokio-util", 3267 - "toml", 3271 + "toml 0.8.23", 3268 3272 "tracing", 3269 3273 "tracing-subscriber", 3270 3274 ] ··· 3300 3304 3301 3305 [[package]] 3302 3306 name = "matchers" 3303 - version = "0.1.0" 3307 + version = "0.2.0" 3304 3308 source = "registry+https://github.com/rust-lang/crates.io-index" 3305 - checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" 3309 + checksum = "d1525a2a28c7f4fa0fc98bb91ae755d1e2d1505079e05539e35bc876b5d65ae9" 3306 3310 dependencies = [ 3307 - "regex-automata 0.1.10", 3311 + "regex-automata", 3308 3312 ] 3309 3313 3310 3314 [[package]] ··· 3354 3358 "http-body-util", 3355 3359 "hyper", 3356 3360 "hyper-util", 3357 - "indexmap 2.9.0", 3361 + "indexmap 2.11.4", 3358 3362 "ipnet", 3359 3363 "metrics", 3360 3364 "metrics-util 0.19.0", ··· 3375 3379 "hyper", 3376 3380 "hyper-rustls", 3377 3381 "hyper-util", 3378 - "indexmap 2.9.0", 3382 + "indexmap 2.11.4", 3379 3383 "ipnet", 3380 3384 "metrics", 3381 3385 "metrics-util 0.20.0", ··· 3603 3607 3604 3608 [[package]] 3605 3609 name = "nu-ansi-term" 3606 - version = "0.46.0" 3610 + version = "0.50.1" 3607 3611 source = "registry+https://github.com/rust-lang/crates.io-index" 3608 - checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" 3612 + checksum = "d4a28e057d01f97e61255210fcff094d74ed0466038633e95017f5beb68e4399" 3609 3613 dependencies = [ 3610 - "overload", 3611 - "winapi", 3614 + "windows-sys 0.52.0", 3612 3615 ] 3613 3616 3614 3617 [[package]] ··· 3738 3741 3739 3742 [[package]] 3740 3743 name = "openapiv3" 3741 - version = "2.0.0" 3744 + version = "2.2.0" 3742 3745 source = "registry+https://github.com/rust-lang/crates.io-index" 3743 - checksum = "cc02deea53ffe807708244e5914f6b099ad7015a207ee24317c22112e17d9c5c" 3746 + checksum = "5c8d427828b22ae1fff2833a03d8486c2c881367f1c336349f307f321e7f4d05" 3744 3747 dependencies = [ 3745 - "indexmap 2.9.0", 3748 + "indexmap 2.11.4", 3746 3749 "serde", 3747 3750 "serde_json", 3748 3751 ] ··· 3770 3773 dependencies = [ 3771 3774 "proc-macro2", 3772 3775 "quote", 3773 - "syn 2.0.103", 3776 + "syn 2.0.106", 3774 3777 ] 3775 3778 3776 3779 [[package]] ··· 3809 3812 dependencies = [ 3810 3813 "hashbrown 0.13.2", 3811 3814 ] 3812 - 3813 - [[package]] 3814 - name = "overload" 3815 - version = "0.1.1" 3816 - source = "registry+https://github.com/rust-lang/crates.io-index" 3817 - checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" 3818 3815 3819 3816 [[package]] 3820 3817 name = "p256" ··· 3953 3950 "pest_meta", 3954 3951 "proc-macro2", 3955 3952 "quote", 3956 - "syn 2.0.103", 3953 + "syn 2.0.106", 3957 3954 ] 3958 3955 3959 3956 [[package]] ··· 3983 3980 dependencies = [ 3984 3981 "proc-macro2", 3985 3982 "quote", 3986 - "syn 2.0.103", 3983 + "syn 2.0.106", 3987 3984 ] 3988 3985 3989 3986 [[package]] ··· 4101 4098 "proc-macro-crate", 4102 4099 "proc-macro2", 4103 4100 "quote", 4104 - "syn 2.0.103", 4101 + "syn 2.0.106", 4105 4102 ] 4106 4103 4107 4104 [[package]] ··· 4114 4111 "bytes", 4115 4112 "derive_more", 4116 4113 "futures-util", 4117 - "indexmap 2.9.0", 4114 + "indexmap 2.11.4", 4118 4115 "itertools 0.14.0", 4119 4116 "mime", 4120 4117 "num-traits", ··· 4138 4135 dependencies = [ 4139 4136 "darling 0.20.11", 4140 4137 "http", 4141 - "indexmap 2.9.0", 4138 + "indexmap 2.11.4", 4142 4139 "mime", 4143 4140 "proc-macro-crate", 4144 4141 "proc-macro2", 4145 4142 "quote", 4146 4143 "regex", 4147 - "syn 2.0.103", 4144 + "syn 2.0.106", 4148 4145 "thiserror 2.0.16", 4149 4146 ] 4150 4147 ··· 4185 4182 checksum = "6837b9e10d61f45f987d50808f83d1ee3d206c66acf650c3e4ae2e1f6ddedf55" 4186 4183 dependencies = [ 4187 4184 "proc-macro2", 4188 - "syn 2.0.103", 4185 + "syn 2.0.106", 4189 4186 ] 4190 4187 4191 4188 [[package]] ··· 4496 4493 dependencies = [ 4497 4494 "proc-macro2", 4498 4495 "quote", 4499 - "syn 2.0.103", 4496 + "syn 2.0.106", 4497 + ] 4498 + 4499 + [[package]] 4500 + name = "reflector" 4501 + version = "0.1.0" 4502 + dependencies = [ 4503 + "clap", 4504 + "log", 4505 + "poem", 4506 + "serde", 4507 + "tokio", 4508 + "tracing-subscriber", 4500 4509 ] 4501 4510 4502 4511 [[package]] ··· 4507 4516 dependencies = [ 4508 4517 "aho-corasick", 4509 4518 "memchr", 4510 - "regex-automata 0.4.9", 4511 - "regex-syntax 0.8.5", 4512 - ] 4513 - 4514 - [[package]] 4515 - name = "regex-automata" 4516 - version = "0.1.10" 4517 - source = "registry+https://github.com/rust-lang/crates.io-index" 4518 - checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" 4519 - dependencies = [ 4520 - "regex-syntax 0.6.29", 4519 + "regex-automata", 4520 + "regex-syntax", 4521 4521 ] 4522 4522 4523 4523 [[package]] ··· 4528 4528 dependencies = [ 4529 4529 "aho-corasick", 4530 4530 "memchr", 4531 - "regex-syntax 0.8.5", 4531 + "regex-syntax", 4532 4532 ] 4533 4533 4534 4534 [[package]] 4535 4535 name = "regex-syntax" 4536 - version = "0.6.29" 4537 - source = "registry+https://github.com/rust-lang/crates.io-index" 4538 - checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" 4539 - 4540 - [[package]] 4541 - name = "regex-syntax" 4542 4536 version = "0.8.5" 4543 4537 source = "registry+https://github.com/rust-lang/crates.io-index" 4544 4538 checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" 4545 4539 4546 4540 [[package]] 4547 4541 name = "reqwest" 4548 - version = "0.12.22" 4542 + version = "0.12.23" 4549 4543 source = "registry+https://github.com/rust-lang/crates.io-index" 4550 - checksum = "cbc931937e6ca3a06e3b6c0aa7841849b160a90351d6ab467a8b9b9959767531" 4544 + checksum = "d429f34c8092b2d42c7c93cec323bb4adeb7c67698f70839adec842ec10c7ceb" 4551 4545 dependencies = [ 4552 4546 "async-compression", 4553 4547 "base64 0.22.1", ··· 4881 4875 "proc-macro2", 4882 4876 "quote", 4883 4877 "serde_derive_internals", 4884 - "syn 2.0.103", 4878 + "syn 2.0.106", 4885 4879 ] 4886 4880 4887 4881 [[package]] ··· 4980 4974 4981 4975 [[package]] 4982 4976 name = "serde" 4983 - version = "1.0.219" 4977 + version = "1.0.228" 4984 4978 source = "registry+https://github.com/rust-lang/crates.io-index" 4985 - checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" 4979 + checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" 4986 4980 dependencies = [ 4981 + "serde_core", 4987 4982 "serde_derive", 4988 4983 ] 4989 4984 ··· 4997 4992 ] 4998 4993 4999 4994 [[package]] 4995 + name = "serde_core" 4996 + version = "1.0.228" 4997 + source = "registry+https://github.com/rust-lang/crates.io-index" 4998 + checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" 4999 + dependencies = [ 5000 + "serde_derive", 5001 + ] 5002 + 5003 + [[package]] 5000 5004 name = "serde_derive" 5001 - version = "1.0.219" 5005 + version = "1.0.228" 5002 5006 source = "registry+https://github.com/rust-lang/crates.io-index" 5003 - checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" 5007 + checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" 5004 5008 dependencies = [ 5005 5009 "proc-macro2", 5006 5010 "quote", 5007 - "syn 2.0.103", 5011 + "syn 2.0.106", 5008 5012 ] 5009 5013 5010 5014 [[package]] ··· 5015 5019 dependencies = [ 5016 5020 "proc-macro2", 5017 5021 "quote", 5018 - "syn 2.0.103", 5022 + "syn 2.0.106", 5019 5023 ] 5020 5024 5021 5025 [[package]] ··· 5025 5029 checksum = "9d2de91cf02bbc07cde38891769ccd5d4f073d22a40683aa4bc7a95781aaa2c4" 5026 5030 dependencies = [ 5027 5031 "form_urlencoded", 5028 - "indexmap 2.9.0", 5032 + "indexmap 2.11.4", 5029 5033 "itoa", 5030 5034 "ryu", 5031 5035 "serde", ··· 5033 5037 5034 5038 [[package]] 5035 5039 name = "serde_json" 5036 - version = "1.0.141" 5040 + version = "1.0.145" 5037 5041 source = "registry+https://github.com/rust-lang/crates.io-index" 5038 - checksum = "30b9eff21ebe718216c6ec64e1d9ac57087aad11efc64e32002bce4a0d4c03d3" 5042 + checksum = "402a6f66d8c709116cf22f558eab210f5a50187f702eb4d7e5ef38d9a7f1c79c" 5039 5043 dependencies = [ 5040 5044 "itoa", 5041 5045 "memchr", 5042 5046 "ryu", 5043 5047 "serde", 5048 + "serde_core", 5044 5049 ] 5045 5050 5046 5051 [[package]] ··· 5076 5081 ] 5077 5082 5078 5083 [[package]] 5084 + name = "serde_spanned" 5085 + version = "1.0.2" 5086 + source = "registry+https://github.com/rust-lang/crates.io-index" 5087 + checksum = "5417783452c2be558477e104686f7de5dae53dba813c28435e0e70f82d9b04ee" 5088 + dependencies = [ 5089 + "serde_core", 5090 + ] 5091 + 5092 + [[package]] 5079 5093 name = "serde_tokenstream" 5080 5094 version = "0.2.2" 5081 5095 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 5084 5098 "proc-macro2", 5085 5099 "quote", 5086 5100 "serde", 5087 - "syn 2.0.103", 5101 + "syn 2.0.106", 5088 5102 ] 5089 5103 5090 5104 [[package]] ··· 5109 5123 "chrono", 5110 5124 "hex", 5111 5125 "indexmap 1.9.3", 5112 - "indexmap 2.9.0", 5126 + "indexmap 2.11.4", 5113 5127 "serde", 5114 5128 "serde_derive", 5115 5129 "serde_json", ··· 5126 5140 "darling 0.20.11", 5127 5141 "proc-macro2", 5128 5142 "quote", 5129 - "syn 2.0.103", 5143 + "syn 2.0.106", 5130 5144 ] 5131 5145 5132 5146 [[package]] ··· 5135 5149 source = "registry+https://github.com/rust-lang/crates.io-index" 5136 5150 checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" 5137 5151 dependencies = [ 5138 - "indexmap 2.9.0", 5152 + "indexmap 2.11.4", 5139 5153 "itoa", 5140 5154 "ryu", 5141 5155 "serde", ··· 5428 5442 5429 5443 [[package]] 5430 5444 name = "syn" 5431 - version = "2.0.103" 5445 + version = "2.0.106" 5432 5446 source = "registry+https://github.com/rust-lang/crates.io-index" 5433 - checksum = "e4307e30089d6fd6aff212f2da3a1f9e32f3223b1f010fb09b7c95f90f3ca1e8" 5447 + checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6" 5434 5448 dependencies = [ 5435 5449 "proc-macro2", 5436 5450 "quote", ··· 5454 5468 dependencies = [ 5455 5469 "proc-macro2", 5456 5470 "quote", 5457 - "syn 2.0.103", 5471 + "syn 2.0.106", 5458 5472 ] 5459 5473 5460 5474 [[package]] ··· 5540 5554 dependencies = [ 5541 5555 "proc-macro2", 5542 5556 "quote", 5543 - "syn 2.0.103", 5557 + "syn 2.0.106", 5544 5558 ] 5545 5559 5546 5560 [[package]] ··· 5551 5565 dependencies = [ 5552 5566 "proc-macro2", 5553 5567 "quote", 5554 - "syn 2.0.103", 5568 + "syn 2.0.106", 5555 5569 ] 5556 5570 5557 5571 [[package]] ··· 5650 5664 5651 5665 [[package]] 5652 5666 name = "tokio" 5653 - version = "1.47.0" 5667 + version = "1.47.1" 5654 5668 source = "registry+https://github.com/rust-lang/crates.io-index" 5655 - checksum = "43864ed400b6043a4757a25c7a64a8efde741aed79a056a2fb348a406701bb35" 5669 + checksum = "89e49afdadebb872d3145a5638b59eb0691ea23e46ca484037cfab3b76b95038" 5656 5670 dependencies = [ 5657 5671 "backtrace", 5658 5672 "bytes", ··· 5676 5690 dependencies = [ 5677 5691 "proc-macro2", 5678 5692 "quote", 5679 - "syn 2.0.103", 5693 + "syn 2.0.106", 5680 5694 ] 5681 5695 5682 5696 [[package]] ··· 5767 5781 checksum = "dc1beb996b9d83529a9e75c17a1686767d148d70663143c7854d8b4a09ced362" 5768 5782 dependencies = [ 5769 5783 "serde", 5770 - "serde_spanned", 5771 - "toml_datetime", 5784 + "serde_spanned 0.6.9", 5785 + "toml_datetime 0.6.11", 5772 5786 "toml_edit", 5773 5787 ] 5774 5788 5775 5789 [[package]] 5790 + name = "toml" 5791 + version = "0.9.7" 5792 + source = "registry+https://github.com/rust-lang/crates.io-index" 5793 + checksum = "00e5e5d9bf2475ac9d4f0d9edab68cc573dc2fd644b0dba36b0c30a92dd9eaa0" 5794 + dependencies = [ 5795 + "indexmap 2.11.4", 5796 + "serde_core", 5797 + "serde_spanned 1.0.2", 5798 + "toml_datetime 0.7.2", 5799 + "toml_parser", 5800 + "toml_writer", 5801 + "winnow", 5802 + ] 5803 + 5804 + [[package]] 5776 5805 name = "toml_datetime" 5777 5806 version = "0.6.11" 5778 5807 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 5782 5811 ] 5783 5812 5784 5813 [[package]] 5814 + name = "toml_datetime" 5815 + version = "0.7.2" 5816 + source = "registry+https://github.com/rust-lang/crates.io-index" 5817 + checksum = "32f1085dec27c2b6632b04c80b3bb1b4300d6495d1e129693bdda7d91e72eec1" 5818 + dependencies = [ 5819 + "serde_core", 5820 + ] 5821 + 5822 + [[package]] 5785 5823 name = "toml_edit" 5786 5824 version = "0.22.27" 5787 5825 source = "registry+https://github.com/rust-lang/crates.io-index" 5788 5826 checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a" 5789 5827 dependencies = [ 5790 - "indexmap 2.9.0", 5828 + "indexmap 2.11.4", 5791 5829 "serde", 5792 - "serde_spanned", 5793 - "toml_datetime", 5830 + "serde_spanned 0.6.9", 5831 + "toml_datetime 0.6.11", 5794 5832 "toml_write", 5795 5833 "winnow", 5796 5834 ] 5797 5835 5798 5836 [[package]] 5837 + name = "toml_parser" 5838 + version = "1.0.3" 5839 + source = "registry+https://github.com/rust-lang/crates.io-index" 5840 + checksum = "4cf893c33be71572e0e9aa6dd15e6677937abd686b066eac3f8cd3531688a627" 5841 + dependencies = [ 5842 + "winnow", 5843 + ] 5844 + 5845 + [[package]] 5799 5846 name = "toml_write" 5800 5847 version = "0.1.2" 5801 5848 source = "registry+https://github.com/rust-lang/crates.io-index" 5802 5849 checksum = "5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801" 5850 + 5851 + [[package]] 5852 + name = "toml_writer" 5853 + version = "1.0.3" 5854 + source = "registry+https://github.com/rust-lang/crates.io-index" 5855 + checksum = "d163a63c116ce562a22cda521fcc4d79152e7aba014456fb5eb442f6d6a10109" 5803 5856 5804 5857 [[package]] 5805 5858 name = "tower" ··· 5867 5920 dependencies = [ 5868 5921 "proc-macro2", 5869 5922 "quote", 5870 - "syn 2.0.103", 5923 + "syn 2.0.106", 5871 5924 ] 5872 5925 5873 5926 [[package]] ··· 5893 5946 5894 5947 [[package]] 5895 5948 name = "tracing-subscriber" 5896 - version = "0.3.19" 5949 + version = "0.3.20" 5897 5950 source = "registry+https://github.com/rust-lang/crates.io-index" 5898 - checksum = "e8189decb5ac0fa7bc8b96b7cb9b2701d60d48805aca84a238004d665fcc4008" 5951 + checksum = "2054a14f5307d601f88daf0553e1cbf472acc4f2c51afab632431cdcd72124d5" 5899 5952 dependencies = [ 5900 5953 "matchers", 5901 5954 "nu-ansi-term", 5902 5955 "once_cell", 5903 - "regex", 5956 + "regex-automata", 5904 5957 "sharded-slab", 5905 5958 "smallvec", 5906 5959 "thread_local", ··· 5917 5970 dependencies = [ 5918 5971 "proc-macro2", 5919 5972 "quote", 5920 - "syn 2.0.103", 5973 + "syn 2.0.106", 5921 5974 ] 5922 5975 5923 5976 [[package]] ··· 5996 6049 "clap", 5997 6050 "dropshot", 5998 6051 "env_logger", 5999 - "fjall 2.11.2 (git+https://github.com/fjall-rs/fjall.git)", 6052 + "fjall 2.11.2 (git+https://github.com/fjall-rs/fjall.git?rev=fb229572bb7d1d6966a596994dc1708e47ec57d8)", 6000 6053 "getrandom 0.3.3", 6001 6054 "http", 6002 6055 "jetstream", ··· 6117 6170 6118 6171 [[package]] 6119 6172 name = "uuid" 6120 - version = "1.16.0" 6173 + version = "1.18.1" 6121 6174 source = "registry+https://github.com/rust-lang/crates.io-index" 6122 - checksum = "458f7a779bf54acc9f347480ac654f68407d3aab21269a6e3c9f922acd9e2da9" 6175 + checksum = "2f87b8aa10b915a06587d0dec516c282ff295b475d94abf425d62b57710070a2" 6123 6176 dependencies = [ 6124 6177 "getrandom 0.3.3", 6178 + "js-sys", 6125 6179 "serde", 6180 + "wasm-bindgen", 6126 6181 ] 6127 6182 6128 6183 [[package]] ··· 6237 6292 "log", 6238 6293 "proc-macro2", 6239 6294 "quote", 6240 - "syn 2.0.103", 6295 + "syn 2.0.106", 6241 6296 "wasm-bindgen-shared", 6242 6297 ] 6243 6298 ··· 6272 6327 dependencies = [ 6273 6328 "proc-macro2", 6274 6329 "quote", 6275 - "syn 2.0.103", 6330 + "syn 2.0.106", 6276 6331 "wasm-bindgen-backend", 6277 6332 "wasm-bindgen-shared", 6278 6333 ] ··· 6400 6455 source = "registry+https://github.com/rust-lang/crates.io-index" 6401 6456 checksum = "dd04d41d93c4992d421894c18c8b43496aa748dd4c081bac0dc93eb0489272b6" 6402 6457 dependencies = [ 6403 - "windows-core 0.58.0", 6458 + "windows-core", 6404 6459 "windows-targets 0.52.6", 6405 6460 ] 6406 6461 ··· 6410 6465 source = "registry+https://github.com/rust-lang/crates.io-index" 6411 6466 checksum = "6ba6d44ec8c2591c134257ce647b7ea6b20335bf6379a27dac5f1641fcf59f99" 6412 6467 dependencies = [ 6413 - "windows-implement 0.58.0", 6414 - "windows-interface 0.58.0", 6468 + "windows-implement", 6469 + "windows-interface", 6415 6470 "windows-result 0.2.0", 6416 6471 "windows-strings 0.1.0", 6417 6472 "windows-targets 0.52.6", 6418 6473 ] 6419 6474 6420 6475 [[package]] 6421 - name = "windows-core" 6422 - version = "0.61.0" 6423 - source = "registry+https://github.com/rust-lang/crates.io-index" 6424 - checksum = "4763c1de310c86d75a878046489e2e5ba02c649d185f21c67d4cf8a56d098980" 6425 - dependencies = [ 6426 - "windows-implement 0.60.0", 6427 - "windows-interface 0.59.1", 6428 - "windows-link", 6429 - "windows-result 0.3.4", 6430 - "windows-strings 0.4.2", 6431 - ] 6432 - 6433 - [[package]] 6434 6476 name = "windows-implement" 6435 6477 version = "0.58.0" 6436 6478 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 6438 6480 dependencies = [ 6439 6481 "proc-macro2", 6440 6482 "quote", 6441 - "syn 2.0.103", 6442 - ] 6443 - 6444 - [[package]] 6445 - name = "windows-implement" 6446 - version = "0.60.0" 6447 - source = "registry+https://github.com/rust-lang/crates.io-index" 6448 - checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836" 6449 - dependencies = [ 6450 - "proc-macro2", 6451 - "quote", 6452 - "syn 2.0.103", 6483 + "syn 2.0.106", 6453 6484 ] 6454 6485 6455 6486 [[package]] ··· 6460 6491 dependencies = [ 6461 6492 "proc-macro2", 6462 6493 "quote", 6463 - "syn 2.0.103", 6464 - ] 6465 - 6466 - [[package]] 6467 - name = "windows-interface" 6468 - version = "0.59.1" 6469 - source = "registry+https://github.com/rust-lang/crates.io-index" 6470 - checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8" 6471 - dependencies = [ 6472 - "proc-macro2", 6473 - "quote", 6474 - "syn 2.0.103", 6494 + "syn 2.0.106", 6475 6495 ] 6476 6496 6477 6497 [[package]] ··· 6678 6698 6679 6699 [[package]] 6680 6700 name = "winnow" 6681 - version = "0.7.11" 6701 + version = "0.7.13" 6682 6702 source = "registry+https://github.com/rust-lang/crates.io-index" 6683 - checksum = "74c7b26e3480b707944fc872477815d29a8e429d2f93a1ce000f5fa84a15cbcd" 6703 + checksum = "21a0236b59786fed61e2a80582dd500fe61f18b5dca67a4a067d0bc9039339cf" 6684 6704 dependencies = [ 6685 6705 "memchr", 6686 6706 ] ··· 6777 6797 dependencies = [ 6778 6798 "proc-macro2", 6779 6799 "quote", 6780 - "syn 2.0.103", 6800 + "syn 2.0.106", 6781 6801 "synstructure", 6782 6802 ] 6783 6803 ··· 6807 6827 dependencies = [ 6808 6828 "proc-macro2", 6809 6829 "quote", 6810 - "syn 2.0.103", 6830 + "syn 2.0.106", 6811 6831 ] 6812 6832 6813 6833 [[package]] ··· 6818 6838 dependencies = [ 6819 6839 "proc-macro2", 6820 6840 "quote", 6821 - "syn 2.0.103", 6841 + "syn 2.0.106", 6822 6842 ] 6823 6843 6824 6844 [[package]] ··· 6838 6858 dependencies = [ 6839 6859 "proc-macro2", 6840 6860 "quote", 6841 - "syn 2.0.103", 6861 + "syn 2.0.106", 6842 6862 "synstructure", 6843 6863 ] 6844 6864 ··· 6860 6880 dependencies = [ 6861 6881 "proc-macro2", 6862 6882 "quote", 6863 - "syn 2.0.103", 6883 + "syn 2.0.106", 6864 6884 ] 6865 6885 6866 6886 [[package]] ··· 6882 6902 dependencies = [ 6883 6903 "proc-macro2", 6884 6904 "quote", 6885 - "syn 2.0.103", 6905 + "syn 2.0.106", 6886 6906 ] 6887 6907 6888 6908 [[package]]
+1
Cargo.toml
··· 11 11 "slingshot", 12 12 "quasar", 13 13 "pocket", 14 + "reflector", 14 15 ]
+8 -1
Makefile
··· 5 5 cargo test --all-features 6 6 7 7 fmt: 8 - cargo fmt --package links --package constellation --package ufos --package spacedust --package who-am-i --package slingshot 8 + cargo fmt --package links \ 9 + --package constellation \ 10 + --package ufos \ 11 + --package spacedust \ 12 + --package who-am-i \ 13 + --package slingshot \ 14 + --package pocket \ 15 + --package reflector 9 16 cargo +nightly fmt --package jetstream 10 17 11 18 clippy:
+1 -1
constellation/Cargo.toml
··· 8 8 anyhow = "1.0.95" 9 9 askama = { version = "0.12.1", features = ["serde-json"] } 10 10 axum = "0.8.1" 11 - axum-extra = { version = "0.10.0", features = ["typed-header"] } 11 + axum-extra = { version = "0.10.0", features = ["query", "typed-header"] } 12 12 axum-metrics = "0.2" 13 13 bincode = "1.3.3" 14 14 clap = { version = "4.5.26", features = ["derive"] }
+661
constellation/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 + <one line to give the program's name and a brief idea of what it does.> 633 + Copyright (C) <year> <name of author> 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/>.
+3
constellation/LICENSE.future
··· 1 + constellation's source code is currently only available under the AGPL license. 2 + 3 + it MAY be relicensed in the future to MIT and/or Apache 2.0, at the sole discretion of the microcosm organization, but is not available under these licenses today.
+9
constellation/readme.md
··· 83 83 ``` 84 84 85 85 86 + ## Contributions 87 + 88 + ### Licensing 89 + 90 + Constellation's source code is currently available exclusively under the AGPL license (see [LICENSE](./LICENSE)). 91 + 92 + In the future, its code MAY become available under the MIT and/or Apache2.0 licenses, at the sole discretion of the microcosm organization. Contributing implies acceptance with this possible future licensing change. The change has not happed yet and is not guaranteed. 93 + 94 + 86 95 some todos 87 96 88 97 - [x] find links and write them to rocksdb
+75 -16
constellation/src/bin/main.rs
··· 1 1 use anyhow::{bail, Result}; 2 2 use clap::{Parser, ValueEnum}; 3 3 use metrics_exporter_prometheus::PrometheusBuilder; 4 + use std::net::SocketAddr; 4 5 use std::num::NonZero; 5 6 use std::path::PathBuf; 6 7 use std::sync::{atomic::AtomicU32, Arc}; ··· 21 22 #[derive(Parser, Debug)] 22 23 #[command(version, about, long_about = None)] 23 24 struct Args { 24 - #[arg(short, long)] 25 + /// constellation server's listen address 26 + #[arg(long)] 27 + #[clap(default_value = "0.0.0.0:6789")] 28 + bind: SocketAddr, 29 + /// optionally disable the metrics server 30 + #[arg(long)] 31 + #[clap(default_value_t = false)] 32 + collect_metrics: bool, 33 + /// metrics server's listen address 34 + #[arg(long)] 35 + #[clap(default_value = "0.0.0.0:8765")] 36 + bind_metrics: SocketAddr, 25 37 /// Jetstream server to connect to (exclusive with --fixture). Provide either a wss:// URL, or a shorhand value: 26 38 /// 'us-east-1', 'us-east-2', 'us-west-1', or 'us-west-2' 27 39 #[arg(short, long)] ··· 46 58 /// Saved jsonl from jetstream to use instead of a live subscription 47 59 #[arg(short, long)] 48 60 fixture: Option<PathBuf>, 61 + /// run a scan across the target id table and write all key -> ids to id -> keys 62 + #[arg(long, action)] 63 + repair_target_ids: bool, 49 64 } 50 65 51 66 #[derive(Debug, Clone, ValueEnum)] ··· 78 93 let stream = jetstream_url(&args.jetstream); 79 94 println!("using jetstream server {stream:?}...",); 80 95 96 + let bind = args.bind; 97 + let metrics_bind = args.bind_metrics; 98 + 99 + let collect_metrics = args.collect_metrics; 81 100 let stay_alive = CancellationToken::new(); 82 101 83 102 match args.backend { 84 - StorageBackend::Memory => run(MemStorage::new(), fixture, None, stream, stay_alive), 103 + StorageBackend::Memory => run( 104 + MemStorage::new(), 105 + fixture, 106 + None, 107 + stream, 108 + bind, 109 + metrics_bind, 110 + collect_metrics, 111 + stay_alive, 112 + ), 85 113 #[cfg(feature = "rocks")] 86 114 StorageBackend::Rocks => { 87 115 let storage_dir = args.data.clone().unwrap_or("rocks.test".into()); ··· 96 124 rocks.start_backup(backup_dir, auto_backup, stay_alive.clone())?; 97 125 } 98 126 println!("rocks ready."); 99 - run(rocks, fixture, args.data, stream, stay_alive) 127 + std::thread::scope(|s| { 128 + if args.repair_target_ids { 129 + let rocks = rocks.clone(); 130 + let stay_alive = stay_alive.clone(); 131 + s.spawn(move || { 132 + let rep = rocks.run_repair(time::Duration::from_millis(0), stay_alive); 133 + eprintln!("repair finished: {rep:?}"); 134 + rep 135 + }); 136 + } 137 + s.spawn(|| { 138 + let r = run( 139 + rocks, 140 + fixture, 141 + args.data, 142 + stream, 143 + bind, 144 + metrics_bind, 145 + collect_metrics, 146 + stay_alive, 147 + ); 148 + eprintln!("run finished: {r:?}"); 149 + r 150 + }); 151 + }); 152 + Ok(()) 100 153 } 101 154 } 102 155 } 103 156 157 + #[allow(clippy::too_many_lines)] 158 + #[allow(clippy::too_many_arguments)] 104 159 fn run( 105 160 mut storage: impl LinkStorage, 106 161 fixture: Option<PathBuf>, 107 162 data_dir: Option<PathBuf>, 108 163 stream: String, 164 + bind: SocketAddr, 165 + metrics_bind: SocketAddr, 166 + collect_metrics: bool, 109 167 stay_alive: CancellationToken, 110 168 ) -> Result<()> { 111 169 ctrlc::set_handler({ ··· 150 208 .build() 151 209 .expect("axum startup") 152 210 .block_on(async { 153 - install_metrics_server()?; 154 - serve(readable, "0.0.0.0:6789", staying_alive).await 211 + // Install metrics server only if requested 212 + if collect_metrics { 213 + install_metrics_server(metrics_bind)?; 214 + } 215 + serve(readable, bind, staying_alive).await 155 216 }) 156 217 .unwrap(); 157 218 stay_alive.drop_guard(); 158 219 } 159 220 }); 160 221 161 - s.spawn(move || { // monitor thread 222 + // only spawn monitoring thread if the metrics server is running 223 + if collect_metrics { 224 + s.spawn(move || { // monitor thread 162 225 let stay_alive = stay_alive.clone(); 163 226 let check_alive = stay_alive.clone(); 164 227 ··· 184 247 185 248 'monitor: loop { 186 249 match readable.get_stats() { 187 - Ok(StorageStats { dids, targetables, linking_records }) => { 250 + Ok(StorageStats { dids, targetables, linking_records, .. }) => { 188 251 metrics::gauge!("storage.stats.dids").set(dids as f64); 189 252 metrics::gauge!("storage.stats.targetables").set(targetables as f64); 190 253 metrics::gauge!("storage.stats.linking_records").set(linking_records as f64); ··· 210 273 } 211 274 } 212 275 stay_alive.drop_guard(); 213 - }); 276 + }); 277 + } 214 278 }); 215 279 216 280 println!("byeeee"); ··· 218 282 Ok(()) 219 283 } 220 284 221 - fn install_metrics_server() -> Result<()> { 285 + fn install_metrics_server(metrics_bind: SocketAddr) -> Result<()> { 222 286 println!("installing metrics server..."); 223 - let host = [0, 0, 0, 0]; 224 - let port = 8765; 225 287 PrometheusBuilder::new() 226 288 .set_quantiles(&[0.5, 0.9, 0.99, 1.0])? 227 289 .set_bucket_duration(time::Duration::from_secs(30))? 228 290 .set_bucket_count(NonZero::new(10).unwrap()) // count * duration = 5 mins. stuff doesn't happen that fast here. 229 291 .set_enable_unit_suffix(true) 230 - .with_http_listener((host, port)) 292 + .with_http_listener(metrics_bind) 231 293 .install()?; 232 - println!( 233 - "metrics server installed! listening on http://{}.{}.{}.{}:{port}", 234 - host[0], host[1], host[2], host[3] 235 - ); 294 + println!("metrics server installed! listening at {metrics_bind:?}"); 236 295 Ok(()) 237 296 } 238 297
+2
constellation/src/bin/rocks-restore-from-backup.rs
··· 3 3 use clap::Parser; 4 4 use std::path::PathBuf; 5 5 6 + #[cfg(feature = "rocks")] 6 7 use rocksdb::backup::{BackupEngine, BackupEngineOptions, RestoreOptions}; 7 8 8 9 use std::time; ··· 19 20 to_data_dir: PathBuf, 20 21 } 21 22 23 + #[cfg(feature = "rocks")] 22 24 fn main() -> Result<()> { 23 25 let args = Args::parse(); 24 26
+13 -6
constellation/src/consumer/jetstream.rs
··· 226 226 println!("jetstream closed the websocket cleanly."); 227 227 break; 228 228 } 229 - r => eprintln!("jetstream: close result after error: {r:?}"), 229 + Err(_) => { 230 + counter!("jetstream_read_fail", "url" => stream.clone(), "reason" => "dirty close").increment(1); 231 + println!("jetstream failed to close the websocket cleanly."); 232 + break; 233 + } 234 + Ok(r) => { 235 + eprintln!("jetstream: close result after error: {r:?}"); 236 + counter!("jetstream_read_fail", "url" => stream.clone(), "reason" => "read error") 237 + .increment(1); 238 + // if we didn't immediately get ConnectionClosed, we should keep polling read 239 + // until we get it. 240 + continue; 241 + } 230 242 } 231 - counter!("jetstream_read_fail", "url" => stream.clone(), "reason" => "read error") 232 - .increment(1); 233 - // if we didn't immediately get ConnectionClosed, we should keep polling read 234 - // until we get it. 235 - continue; 236 243 } 237 244 }; 238 245
+8 -6
constellation/src/server/filters.rs
··· 5 5 Ok({ 6 6 if let Some(link) = parse_any_link(s) { 7 7 match link { 8 - Link::AtUri(at_uri) => at_uri.strip_prefix("at://").map(|noproto| { 9 - format!("https://atproto-browser-plus-links.vercel.app/at/{noproto}") 10 - }), 11 - Link::Did(did) => Some(format!( 12 - "https://atproto-browser-plus-links.vercel.app/at/{did}" 13 - )), 8 + Link::AtUri(at_uri) => at_uri 9 + .strip_prefix("at://") 10 + .map(|noproto| format!("https://pdsls.dev/at://{noproto}")), 11 + Link::Did(did) => Some(format!("https://pdsls.dev/at://{did}")), 14 12 Link::Uri(uri) => Some(uri), 15 13 } 16 14 } else { ··· 22 20 pub fn human_number(n: &u64) -> askama::Result<String> { 23 21 Ok(n.to_formatted_string(&Locale::en)) 24 22 } 23 + 24 + pub fn to_u64(n: usize) -> askama::Result<u64> { 25 + Ok(n as u64) 26 + }
+334 -21
constellation/src/server/mod.rs
··· 11 11 use bincode::Options; 12 12 use serde::{Deserialize, Serialize}; 13 13 use serde_with::serde_as; 14 - use std::collections::HashMap; 14 + use std::collections::{HashMap, HashSet}; 15 15 use std::time::{Duration, UNIX_EPOCH}; 16 16 use tokio::net::{TcpListener, ToSocketAddrs}; 17 - use tokio::task::block_in_place; 17 + use tokio::task::spawn_blocking; 18 18 use tokio_util::sync::CancellationToken; 19 19 20 20 use crate::storage::{LinkReader, StorageStats}; ··· 25 25 26 26 use acceptable::{acceptable, ExtractAccept}; 27 27 28 - const DEFAULT_CURSOR_LIMIT: u64 = 16; 29 - const DEFAULT_CURSOR_LIMIT_MAX: u64 = 100; 28 + const DEFAULT_CURSOR_LIMIT: u64 = 100; 29 + const DEFAULT_CURSOR_LIMIT_MAX: u64 = 1000; 30 + 31 + fn get_default_cursor_limit() -> u64 { 32 + DEFAULT_CURSOR_LIMIT 33 + } 30 34 31 - const INDEX_BEGAN_AT_TS: u64 = 1738083600; // TODO: not this 35 + fn to500(e: tokio::task::JoinError) -> http::StatusCode { 36 + eprintln!("handler error: {e}"); 37 + http::StatusCode::INTERNAL_SERVER_ERROR 38 + } 32 39 33 40 pub async fn serve<S, A>(store: S, addr: A, stay_alive: CancellationToken) -> anyhow::Result<()> 34 41 where ··· 41 48 "/", 42 49 get({ 43 50 let store = store.clone(); 44 - move |accept| async { block_in_place(|| hello(accept, store)) } 51 + move |accept| async { 52 + spawn_blocking(|| hello(accept, store)) 53 + .await 54 + .map_err(to500)? 55 + } 56 + }), 57 + ) 58 + .route( 59 + "/xrpc/blue.microcosm.links.getManyToManyCounts", 60 + get({ 61 + let store = store.clone(); 62 + move |accept, query| async { 63 + spawn_blocking(|| get_many_to_many_counts(accept, query, store)) 64 + .await 65 + .map_err(to500)? 66 + } 45 67 }), 46 68 ) 47 69 .route( 48 70 "/links/count", 49 71 get({ 50 72 let store = store.clone(); 51 - move |accept, query| async { block_in_place(|| count_links(accept, query, store)) } 73 + move |accept, query| async { 74 + spawn_blocking(|| count_links(accept, query, store)) 75 + .await 76 + .map_err(to500)? 77 + } 52 78 }), 53 79 ) 54 80 .route( ··· 56 82 get({ 57 83 let store = store.clone(); 58 84 move |accept, query| async { 59 - block_in_place(|| count_distinct_dids(accept, query, store)) 85 + spawn_blocking(|| count_distinct_dids(accept, query, store)) 86 + .await 87 + .map_err(to500)? 88 + } 89 + }), 90 + ) 91 + .route( 92 + "/xrpc/blue.microcosm.links.getBacklinks", 93 + get({ 94 + let store = store.clone(); 95 + move |accept, query| async { 96 + spawn_blocking(|| get_backlinks(accept, query, store)) 97 + .await 98 + .map_err(to500)? 60 99 } 61 100 }), 62 101 ) ··· 64 103 "/links", 65 104 get({ 66 105 let store = store.clone(); 67 - move |accept, query| async { block_in_place(|| get_links(accept, query, store)) } 106 + move |accept, query| async { 107 + spawn_blocking(|| get_links(accept, query, store)) 108 + .await 109 + .map_err(to500)? 110 + } 68 111 }), 69 112 ) 70 113 .route( ··· 72 115 get({ 73 116 let store = store.clone(); 74 117 move |accept, query| async { 75 - block_in_place(|| get_distinct_dids(accept, query, store)) 118 + spawn_blocking(|| get_distinct_dids(accept, query, store)) 119 + .await 120 + .map_err(to500)? 76 121 } 77 122 }), 78 123 ) ··· 82 127 get({ 83 128 let store = store.clone(); 84 129 move |accept, query| async { 85 - block_in_place(|| count_all_links(accept, query, store)) 130 + spawn_blocking(|| count_all_links(accept, query, store)) 131 + .await 132 + .map_err(to500)? 86 133 } 87 134 }), 88 135 ) ··· 91 138 get({ 92 139 let store = store.clone(); 93 140 move |accept, query| async { 94 - block_in_place(|| explore_links(accept, query, store)) 141 + spawn_blocking(|| explore_links(accept, query, store)) 142 + .await 143 + .map_err(to500)? 95 144 } 96 145 }), 97 146 ) ··· 150 199 #[template(path = "hello.html.j2")] 151 200 struct HelloReponse { 152 201 help: &'static str, 153 - days_indexed: u64, 202 + days_indexed: Option<u64>, 154 203 stats: StorageStats, 155 204 } 156 205 fn hello( ··· 160 209 let stats = store 161 210 .get_stats() 162 211 .map_err(|_| http::StatusCode::INTERNAL_SERVER_ERROR)?; 163 - let days_indexed = (UNIX_EPOCH + Duration::from_secs(INDEX_BEGAN_AT_TS)) 164 - .elapsed() 212 + let days_indexed = stats 213 + .started_at 214 + .map(|c| (UNIX_EPOCH + Duration::from_micros(c)).elapsed()) 215 + .transpose() 165 216 .map_err(|_| http::StatusCode::INTERNAL_SERVER_ERROR)? 166 - .as_secs() 167 - / 86400; 217 + .map(|d| d.as_secs() / 86_400); 168 218 Ok(acceptable(accept, HelloReponse { 169 219 help: "open this URL in a web browser (or request with Accept: text/html) for information about this API.", 170 220 days_indexed, ··· 173 223 } 174 224 175 225 #[derive(Clone, Deserialize)] 226 + #[serde(rename_all = "camelCase")] 227 + struct GetManyToManyCountsQuery { 228 + subject: String, 229 + source: String, 230 + /// path to the secondary link in the linking record 231 + path_to_other: String, 232 + /// filter to linking records (join of the m2m) by these DIDs 233 + #[serde(default)] 234 + did: Vec<String>, 235 + /// filter to specific secondary records 236 + #[serde(default)] 237 + other_subject: Vec<String>, 238 + cursor: Option<OpaqueApiCursor>, 239 + /// Set the max number of links to return per page of results 240 + #[serde(default = "get_default_cursor_limit")] 241 + limit: u64, 242 + } 243 + #[derive(Serialize)] 244 + struct OtherSubjectCount { 245 + subject: String, 246 + total: u64, 247 + distinct: u64, 248 + } 249 + #[derive(Template, Serialize)] 250 + #[template(path = "get-many-to-many-counts.html.j2")] 251 + struct GetManyToManyCountsResponse { 252 + counts_by_other_subject: Vec<OtherSubjectCount>, 253 + cursor: Option<OpaqueApiCursor>, 254 + #[serde(skip_serializing)] 255 + query: GetManyToManyCountsQuery, 256 + } 257 + fn get_many_to_many_counts( 258 + accept: ExtractAccept, 259 + query: axum_extra::extract::Query<GetManyToManyCountsQuery>, 260 + store: impl LinkReader, 261 + ) -> Result<impl IntoResponse, http::StatusCode> { 262 + let cursor_key = query 263 + .cursor 264 + .clone() 265 + .map(|oc| ApiKeyedCursor::try_from(oc).map_err(|_| http::StatusCode::BAD_REQUEST)) 266 + .transpose()? 267 + .map(|c| c.next); 268 + 269 + let limit = query.limit; 270 + if limit > DEFAULT_CURSOR_LIMIT_MAX { 271 + return Err(http::StatusCode::BAD_REQUEST); 272 + } 273 + 274 + let filter_dids: HashSet<Did> = HashSet::from_iter( 275 + query 276 + .did 277 + .iter() 278 + .map(|d| d.trim()) 279 + .filter(|d| !d.is_empty()) 280 + .map(|d| Did(d.to_string())), 281 + ); 282 + 283 + let filter_other_subjects: HashSet<String> = HashSet::from_iter( 284 + query 285 + .other_subject 286 + .iter() 287 + .map(|s| s.trim().to_string()) 288 + .filter(|s| !s.is_empty()), 289 + ); 290 + 291 + let Some((collection, path)) = query.source.split_once(':') else { 292 + return Err(http::StatusCode::BAD_REQUEST); 293 + }; 294 + let path = format!(".{path}"); 295 + 296 + let path_to_other = format!(".{}", query.path_to_other); 297 + 298 + let paged = store 299 + .get_many_to_many_counts( 300 + &query.subject, 301 + collection, 302 + &path, 303 + &path_to_other, 304 + limit, 305 + cursor_key, 306 + &filter_dids, 307 + &filter_other_subjects, 308 + ) 309 + .map_err(|_| http::StatusCode::INTERNAL_SERVER_ERROR)?; 310 + 311 + let cursor = paged.next.map(|next| ApiKeyedCursor { next }.into()); 312 + 313 + let items = paged 314 + .items 315 + .into_iter() 316 + .map(|(subject, total, distinct)| OtherSubjectCount { 317 + subject, 318 + total, 319 + distinct, 320 + }) 321 + .collect(); 322 + 323 + Ok(acceptable( 324 + accept, 325 + GetManyToManyCountsResponse { 326 + counts_by_other_subject: items, 327 + cursor, 328 + query: (*query).clone(), 329 + }, 330 + )) 331 + } 332 + 333 + #[derive(Clone, Deserialize)] 176 334 struct GetLinksCountQuery { 177 335 target: String, 178 336 collection: String, ··· 233 391 } 234 392 235 393 #[derive(Clone, Deserialize)] 394 + struct GetBacklinksQuery { 395 + /// The link target 396 + /// 397 + /// can be an AT-URI, plain DID, or regular URI 398 + subject: String, 399 + /// Filter links only from this link source 400 + /// 401 + /// eg.: `app.bsky.feed.like:subject.uri` 402 + source: String, 403 + cursor: Option<OpaqueApiCursor>, 404 + /// Filter links only from these DIDs 405 + /// 406 + /// include multiple times to filter by multiple source DIDs 407 + #[serde(default)] 408 + did: Vec<String>, 409 + /// Set the max number of links to return per page of results 410 + #[serde(default = "get_default_cursor_limit")] 411 + limit: u64, 412 + // TODO: allow reverse (er, forward) order as well 413 + } 414 + #[derive(Template, Serialize)] 415 + #[template(path = "get-backlinks.html.j2")] 416 + struct GetBacklinksResponse { 417 + total: u64, 418 + records: Vec<RecordId>, 419 + cursor: Option<OpaqueApiCursor>, 420 + #[serde(skip_serializing)] 421 + query: GetBacklinksQuery, 422 + #[serde(skip_serializing)] 423 + collection: String, 424 + #[serde(skip_serializing)] 425 + path: String, 426 + } 427 + fn get_backlinks( 428 + accept: ExtractAccept, 429 + query: axum_extra::extract::Query<GetBacklinksQuery>, // supports multiple param occurrences 430 + store: impl LinkReader, 431 + ) -> Result<impl IntoResponse, http::StatusCode> { 432 + let until = query 433 + .cursor 434 + .clone() 435 + .map(|oc| ApiCursor::try_from(oc).map_err(|_| http::StatusCode::BAD_REQUEST)) 436 + .transpose()? 437 + .map(|c| c.next); 438 + 439 + let limit = query.limit; 440 + if limit > DEFAULT_CURSOR_LIMIT_MAX { 441 + return Err(http::StatusCode::BAD_REQUEST); 442 + } 443 + 444 + let filter_dids: HashSet<Did> = HashSet::from_iter( 445 + query 446 + .did 447 + .iter() 448 + .map(|d| d.trim()) 449 + .filter(|d| !d.is_empty()) 450 + .map(|d| Did(d.to_string())), 451 + ); 452 + 453 + let Some((collection, path)) = query.source.split_once(':') else { 454 + return Err(http::StatusCode::BAD_REQUEST); 455 + }; 456 + let path = format!(".{path}"); 457 + 458 + let paged = store 459 + .get_links( 460 + &query.subject, 461 + collection, 462 + &path, 463 + limit, 464 + until, 465 + &filter_dids, 466 + ) 467 + .map_err(|_| http::StatusCode::INTERNAL_SERVER_ERROR)?; 468 + 469 + let cursor = paged.next.map(|next| { 470 + ApiCursor { 471 + version: paged.version, 472 + next, 473 + } 474 + .into() 475 + }); 476 + 477 + Ok(acceptable( 478 + accept, 479 + GetBacklinksResponse { 480 + total: paged.total, 481 + records: paged.items, 482 + cursor, 483 + query: (*query).clone(), 484 + collection: collection.to_string(), 485 + path, 486 + }, 487 + )) 488 + } 489 + 490 + #[derive(Clone, Deserialize)] 236 491 struct GetLinkItemsQuery { 237 492 target: String, 238 493 collection: String, 239 494 path: String, 240 495 cursor: Option<OpaqueApiCursor>, 241 - limit: Option<u64>, 496 + /// Filter links only from these DIDs 497 + /// 498 + /// include multiple times to filter by multiple source DIDs 499 + #[serde(default)] 500 + did: Vec<String>, 501 + /// [deprecated] Filter links only from these DIDs 502 + /// 503 + /// format: comma-separated sequence of DIDs 504 + /// 505 + /// errors: if `did` parameter is also present 506 + /// 507 + /// deprecated: use `did`, which can be repeated multiple times 508 + from_dids: Option<String>, // comma separated: gross 509 + #[serde(default = "get_default_cursor_limit")] 510 + limit: u64, 242 511 // TODO: allow reverse (er, forward) order as well 243 512 } 244 513 #[derive(Template, Serialize)] ··· 255 524 } 256 525 fn get_links( 257 526 accept: ExtractAccept, 258 - query: Query<GetLinkItemsQuery>, 527 + query: axum_extra::extract::Query<GetLinkItemsQuery>, // supports multiple param occurrences 259 528 store: impl LinkReader, 260 529 ) -> Result<impl IntoResponse, http::StatusCode> { 261 530 let until = query ··· 265 534 .transpose()? 266 535 .map(|c| c.next); 267 536 268 - let limit = query.limit.unwrap_or(DEFAULT_CURSOR_LIMIT); 537 + let limit = query.limit; 269 538 if limit > DEFAULT_CURSOR_LIMIT_MAX { 270 539 return Err(http::StatusCode::BAD_REQUEST); 271 540 } 272 541 542 + let mut filter_dids: HashSet<Did> = HashSet::from_iter( 543 + query 544 + .did 545 + .iter() 546 + .map(|d| d.trim()) 547 + .filter(|d| !d.is_empty()) 548 + .map(|d| Did(d.to_string())), 549 + ); 550 + 551 + if let Some(comma_joined) = &query.from_dids { 552 + if !filter_dids.is_empty() { 553 + return Err(http::StatusCode::BAD_REQUEST); 554 + } 555 + for did in comma_joined.split(',') { 556 + filter_dids.insert(Did(did.to_string())); 557 + } 558 + } 559 + 273 560 let paged = store 274 - .get_links(&query.target, &query.collection, &query.path, limit, until) 561 + .get_links( 562 + &query.target, 563 + &query.collection, 564 + &query.path, 565 + limit, 566 + until, 567 + &filter_dids, 568 + ) 275 569 .map_err(|_| http::StatusCode::INTERNAL_SERVER_ERROR)?; 276 570 277 571 let cursor = paged.next.map(|next| { ··· 433 727 OpaqueApiCursor(bincode::DefaultOptions::new().serialize(&item).unwrap()) 434 728 } 435 729 } 730 + 731 + #[derive(Serialize, Deserialize)] // for bincode 732 + struct ApiKeyedCursor { 733 + next: String, // the key 734 + } 735 + 736 + impl TryFrom<OpaqueApiCursor> for ApiKeyedCursor { 737 + type Error = bincode::Error; 738 + 739 + fn try_from(item: OpaqueApiCursor) -> Result<Self, Self::Error> { 740 + bincode::DefaultOptions::new().deserialize(&item.0) 741 + } 742 + } 743 + 744 + impl From<ApiKeyedCursor> for OpaqueApiCursor { 745 + fn from(item: ApiKeyedCursor) -> Self { 746 + OpaqueApiCursor(bincode::DefaultOptions::new().serialize(&item).unwrap()) 747 + } 748 + }
+93 -1
constellation/src/storage/mem_store.rs
··· 1 - use super::{LinkReader, LinkStorage, PagedAppendingCollection, StorageStats}; 1 + use super::{ 2 + LinkReader, LinkStorage, PagedAppendingCollection, PagedOrderedCollection, StorageStats, 3 + }; 2 4 use crate::{ActionableEvent, CountsByCount, Did, RecordId}; 3 5 use anyhow::Result; 4 6 use links::CollectedLink; ··· 132 134 } 133 135 134 136 impl LinkReader for MemStorage { 137 + fn get_many_to_many_counts( 138 + &self, 139 + target: &str, 140 + collection: &str, 141 + path: &str, 142 + path_to_other: &str, 143 + limit: u64, 144 + after: Option<String>, 145 + filter_dids: &HashSet<Did>, 146 + filter_to_targets: &HashSet<String>, 147 + ) -> Result<PagedOrderedCollection<(String, u64, u64), String>> { 148 + let data = self.0.lock().unwrap(); 149 + let Some(paths) = data.targets.get(&Target::new(target)) else { 150 + return Ok(PagedOrderedCollection::default()); 151 + }; 152 + let Some(linkers) = paths.get(&Source::new(collection, path)) else { 153 + return Ok(PagedOrderedCollection::default()); 154 + }; 155 + 156 + let path_to_other = RecordPath::new(path_to_other); 157 + let filter_to_targets: HashSet<Target> = 158 + HashSet::from_iter(filter_to_targets.iter().map(|s| Target::new(s))); 159 + 160 + let mut grouped_counts: HashMap<Target, (u64, HashSet<Did>)> = HashMap::new(); 161 + for (did, rkey) in linkers.iter().flatten().cloned() { 162 + if !filter_dids.is_empty() && !filter_dids.contains(&did) { 163 + continue; 164 + } 165 + if let Some(fwd_target) = data 166 + .links 167 + .get(&did) 168 + .unwrap_or(&HashMap::new()) 169 + .get(&RepoId { 170 + collection: collection.to_string(), 171 + rkey, 172 + }) 173 + .unwrap_or(&Vec::new()) 174 + .iter() 175 + .filter_map(|(path, target)| { 176 + if *path == path_to_other 177 + && (filter_to_targets.is_empty() || filter_to_targets.contains(target)) 178 + { 179 + Some(target) 180 + } else { 181 + None 182 + } 183 + }) 184 + .take(1) 185 + .next() 186 + { 187 + let e = grouped_counts.entry(fwd_target.clone()).or_default(); 188 + e.0 += 1; 189 + e.1.insert(did.clone()); 190 + } 191 + } 192 + let mut items: Vec<(String, u64, u64)> = grouped_counts 193 + .iter() 194 + .map(|(k, (n, u))| (k.0.clone(), *n, u.len() as u64)) 195 + .collect(); 196 + items.sort(); 197 + items = items 198 + .into_iter() 199 + .skip_while(|(t, _, _)| after.as_ref().map(|a| t <= a).unwrap_or(false)) 200 + .take(limit as usize) 201 + .collect(); 202 + let next = if items.len() as u64 >= limit { 203 + items.last().map(|(t, _, _)| t.clone()) 204 + } else { 205 + None 206 + }; 207 + Ok(PagedOrderedCollection { items, next }) 208 + } 209 + 135 210 fn get_count(&self, target: &str, collection: &str, path: &str) -> Result<u64> { 136 211 let data = self.0.lock().unwrap(); 137 212 let Some(paths) = data.targets.get(&Target::new(target)) else { ··· 166 241 path: &str, 167 242 limit: u64, 168 243 until: Option<u64>, 244 + filter_dids: &HashSet<Did>, 169 245 ) -> Result<PagedAppendingCollection<RecordId>> { 170 246 let data = self.0.lock().unwrap(); 171 247 let Some(paths) = data.targets.get(&Target::new(target)) else { ··· 183 259 next: None, 184 260 total: 0, 185 261 }); 262 + }; 263 + 264 + let did_rkeys: Vec<_> = if !filter_dids.is_empty() { 265 + did_rkeys 266 + .iter() 267 + .filter(|m| { 268 + Option::<(Did, RKey)>::clone(m) 269 + .map(|(did, _)| filter_dids.contains(&did)) 270 + .unwrap_or(false) 271 + }) 272 + .cloned() 273 + .collect() 274 + } else { 275 + did_rkeys.to_vec() 186 276 }; 187 277 188 278 let total = did_rkeys.len(); ··· 338 428 dids, 339 429 targetables, 340 430 linking_records, 431 + started_at: None, 432 + other_data: Default::default(), 341 433 }) 342 434 } 343 435 }
+484 -14
constellation/src/storage/mod.rs
··· 1 1 use crate::{ActionableEvent, CountsByCount, Did, RecordId}; 2 2 use anyhow::Result; 3 3 use serde::{Deserialize, Serialize}; 4 - use std::collections::HashMap; 4 + use std::collections::{HashMap, HashSet}; 5 5 6 6 pub mod mem_store; 7 7 pub use mem_store::MemStorage; ··· 19 19 pub total: u64, 20 20 } 21 21 22 + /// A paged collection whose keys are sorted instead of indexed 23 + /// 24 + /// this has weaker guarantees than PagedAppendingCollection: it might 25 + /// return a totally consistent snapshot. but it should avoid duplicates 26 + /// and each page should at least be internally consistent. 27 + #[derive(Debug, PartialEq, Default)] 28 + pub struct PagedOrderedCollection<T, K: Ord> { 29 + pub items: Vec<T>, 30 + pub next: Option<K>, 31 + } 32 + 22 33 #[derive(Debug, Deserialize, Serialize, PartialEq)] 23 34 pub struct StorageStats { 24 35 /// estimate of how many accounts we've seen create links. the _subjects_ of any links are not represented here. ··· 33 44 /// records with multiple links are single-counted. 34 45 /// for LSM stores, deleted links don't decrement this, and updated records with any links will likely increment it. 35 46 pub linking_records: u64, 47 + 48 + /// first jetstream cursor when this instance first started 49 + pub started_at: Option<u64>, 50 + 51 + /// anything else we want to throw in 52 + pub other_data: HashMap<String, u64>, 36 53 } 37 54 38 55 pub trait LinkStorage: Send + Sync { ··· 48 65 } 49 66 50 67 pub trait LinkReader: Clone + Send + Sync + 'static { 68 + #[allow(clippy::too_many_arguments)] 69 + fn get_many_to_many_counts( 70 + &self, 71 + target: &str, 72 + collection: &str, 73 + path: &str, 74 + path_to_other: &str, 75 + limit: u64, 76 + after: Option<String>, 77 + filter_dids: &HashSet<Did>, 78 + filter_to_targets: &HashSet<String>, 79 + ) -> Result<PagedOrderedCollection<(String, u64, u64), String>>; 80 + 51 81 fn get_count(&self, target: &str, collection: &str, path: &str) -> Result<u64>; 52 82 53 83 fn get_distinct_did_count(&self, target: &str, collection: &str, path: &str) -> Result<u64>; ··· 59 89 path: &str, 60 90 limit: u64, 61 91 until: Option<u64>, 92 + filter_dids: &HashSet<Did>, 62 93 ) -> Result<PagedAppendingCollection<RecordId>>; 63 94 64 95 fn get_distinct_dids( ··· 145 176 ); 146 177 assert_eq!(storage.get_distinct_did_count("", "", "")?, 0); 147 178 assert_eq!( 148 - storage.get_links("a.com", "app.t.c", ".abc.uri", 100, None)?, 179 + storage.get_links( 180 + "a.com", 181 + "app.t.c", 182 + ".abc.uri", 183 + 100, 184 + None, 185 + &HashSet::default() 186 + )?, 149 187 PagedAppendingCollection { 150 188 version: (0, 0), 151 189 items: vec![], ··· 641 679 0, 642 680 )?; 643 681 assert_eq!( 644 - storage.get_links("a.com", "app.t.c", ".abc.uri", 100, None)?, 682 + storage.get_links( 683 + "a.com", 684 + "app.t.c", 685 + ".abc.uri", 686 + 100, 687 + None, 688 + &HashSet::default() 689 + )?, 645 690 PagedAppendingCollection { 646 691 version: (1, 0), 647 692 items: vec![RecordId { ··· 682 727 0, 683 728 )?; 684 729 } 685 - let links = storage.get_links("a.com", "app.t.c", ".abc.uri", 2, None)?; 730 + let links = 731 + storage.get_links("a.com", "app.t.c", ".abc.uri", 2, None, &HashSet::default())?; 686 732 let dids = storage.get_distinct_dids("a.com", "app.t.c", ".abc.uri", 2, None)?; 687 733 assert_eq!( 688 734 links, ··· 713 759 total: 5, 714 760 } 715 761 ); 716 - let links = storage.get_links("a.com", "app.t.c", ".abc.uri", 2, links.next)?; 762 + let links = storage.get_links( 763 + "a.com", 764 + "app.t.c", 765 + ".abc.uri", 766 + 2, 767 + links.next, 768 + &HashSet::default(), 769 + )?; 717 770 let dids = storage.get_distinct_dids("a.com", "app.t.c", ".abc.uri", 2, dids.next)?; 718 771 assert_eq!( 719 772 links, ··· 744 797 total: 5, 745 798 } 746 799 ); 747 - let links = storage.get_links("a.com", "app.t.c", ".abc.uri", 2, links.next)?; 800 + let links = storage.get_links( 801 + "a.com", 802 + "app.t.c", 803 + ".abc.uri", 804 + 2, 805 + links.next, 806 + &HashSet::default(), 807 + )?; 748 808 let dids = storage.get_distinct_dids("a.com", "app.t.c", ".abc.uri", 2, dids.next)?; 749 809 assert_eq!( 750 810 links, ··· 771 831 assert_stats(storage.get_stats()?, 5..=5, 1..=1, 5..=5); 772 832 }); 773 833 834 + test_each_storage!(get_filtered_links, |storage| { 835 + let links = storage.get_links( 836 + "a.com", 837 + "app.t.c", 838 + ".abc.uri", 839 + 2, 840 + None, 841 + &HashSet::from([Did("did:plc:linker".to_string())]), 842 + )?; 843 + assert_eq!( 844 + links, 845 + PagedAppendingCollection { 846 + version: (0, 0), 847 + items: vec![], 848 + next: None, 849 + total: 0, 850 + } 851 + ); 852 + 853 + storage.push( 854 + &ActionableEvent::CreateLinks { 855 + record_id: RecordId { 856 + did: "did:plc:linker".into(), 857 + collection: "app.t.c".into(), 858 + rkey: "asdf".into(), 859 + }, 860 + links: vec![CollectedLink { 861 + target: Link::Uri("a.com".into()), 862 + path: ".abc.uri".into(), 863 + }], 864 + }, 865 + 0, 866 + )?; 867 + 868 + let links = storage.get_links( 869 + "a.com", 870 + "app.t.c", 871 + ".abc.uri", 872 + 2, 873 + None, 874 + &HashSet::from([Did("did:plc:linker".to_string())]), 875 + )?; 876 + assert_eq!( 877 + links, 878 + PagedAppendingCollection { 879 + version: (1, 0), 880 + items: vec![RecordId { 881 + did: "did:plc:linker".into(), 882 + collection: "app.t.c".into(), 883 + rkey: "asdf".into(), 884 + },], 885 + next: None, 886 + total: 1, 887 + } 888 + ); 889 + 890 + let links = storage.get_links( 891 + "a.com", 892 + "app.t.c", 893 + ".abc.uri", 894 + 2, 895 + None, 896 + &HashSet::from([Did("did:plc:someone-else".to_string())]), 897 + )?; 898 + assert_eq!( 899 + links, 900 + PagedAppendingCollection { 901 + version: (0, 0), 902 + items: vec![], 903 + next: None, 904 + total: 0, 905 + } 906 + ); 907 + 908 + storage.push( 909 + &ActionableEvent::CreateLinks { 910 + record_id: RecordId { 911 + did: "did:plc:linker".into(), 912 + collection: "app.t.c".into(), 913 + rkey: "asdf-2".into(), 914 + }, 915 + links: vec![CollectedLink { 916 + target: Link::Uri("a.com".into()), 917 + path: ".abc.uri".into(), 918 + }], 919 + }, 920 + 0, 921 + )?; 922 + storage.push( 923 + &ActionableEvent::CreateLinks { 924 + record_id: RecordId { 925 + did: "did:plc:someone-else".into(), 926 + collection: "app.t.c".into(), 927 + rkey: "asdf".into(), 928 + }, 929 + links: vec![CollectedLink { 930 + target: Link::Uri("a.com".into()), 931 + path: ".abc.uri".into(), 932 + }], 933 + }, 934 + 0, 935 + )?; 936 + 937 + let links = storage.get_links( 938 + "a.com", 939 + "app.t.c", 940 + ".abc.uri", 941 + 2, 942 + None, 943 + &HashSet::from([Did("did:plc:linker".to_string())]), 944 + )?; 945 + assert_eq!( 946 + links, 947 + PagedAppendingCollection { 948 + version: (2, 0), 949 + items: vec![ 950 + RecordId { 951 + did: "did:plc:linker".into(), 952 + collection: "app.t.c".into(), 953 + rkey: "asdf-2".into(), 954 + }, 955 + RecordId { 956 + did: "did:plc:linker".into(), 957 + collection: "app.t.c".into(), 958 + rkey: "asdf".into(), 959 + }, 960 + ], 961 + next: None, 962 + total: 2, 963 + } 964 + ); 965 + 966 + let links = storage.get_links( 967 + "a.com", 968 + "app.t.c", 969 + ".abc.uri", 970 + 2, 971 + None, 972 + &HashSet::from([ 973 + Did("did:plc:linker".to_string()), 974 + Did("did:plc:someone-else".to_string()), 975 + ]), 976 + )?; 977 + assert_eq!( 978 + links, 979 + PagedAppendingCollection { 980 + version: (3, 0), 981 + items: vec![ 982 + RecordId { 983 + did: "did:plc:someone-else".into(), 984 + collection: "app.t.c".into(), 985 + rkey: "asdf".into(), 986 + }, 987 + RecordId { 988 + did: "did:plc:linker".into(), 989 + collection: "app.t.c".into(), 990 + rkey: "asdf-2".into(), 991 + }, 992 + ], 993 + next: Some(1), 994 + total: 3, 995 + } 996 + ); 997 + 998 + let links = storage.get_links( 999 + "a.com", 1000 + "app.t.c", 1001 + ".abc.uri", 1002 + 2, 1003 + None, 1004 + &HashSet::from([Did("did:plc:someone-unknown".to_string())]), 1005 + )?; 1006 + assert_eq!( 1007 + links, 1008 + PagedAppendingCollection { 1009 + version: (0, 0), 1010 + items: vec![], 1011 + next: None, 1012 + total: 0, 1013 + } 1014 + ); 1015 + }); 1016 + 774 1017 test_each_storage!(get_links_exact_multiple, |storage| { 775 1018 for i in 1..=4 { 776 1019 storage.push( ··· 788 1031 0, 789 1032 )?; 790 1033 } 791 - let links = storage.get_links("a.com", "app.t.c", ".abc.uri", 2, None)?; 1034 + let links = 1035 + storage.get_links("a.com", "app.t.c", ".abc.uri", 2, None, &HashSet::default())?; 792 1036 assert_eq!( 793 1037 links, 794 1038 PagedAppendingCollection { ··· 809 1053 total: 4, 810 1054 } 811 1055 ); 812 - let links = storage.get_links("a.com", "app.t.c", ".abc.uri", 2, links.next)?; 1056 + let links = storage.get_links( 1057 + "a.com", 1058 + "app.t.c", 1059 + ".abc.uri", 1060 + 2, 1061 + links.next, 1062 + &HashSet::default(), 1063 + )?; 813 1064 assert_eq!( 814 1065 links, 815 1066 PagedAppendingCollection { ··· 850 1101 0, 851 1102 )?; 852 1103 } 853 - let links = storage.get_links("a.com", "app.t.c", ".abc.uri", 2, None)?; 1104 + let links = 1105 + storage.get_links("a.com", "app.t.c", ".abc.uri", 2, None, &HashSet::default())?; 854 1106 assert_eq!( 855 1107 links, 856 1108 PagedAppendingCollection { ··· 885 1137 }, 886 1138 0, 887 1139 )?; 888 - let links = storage.get_links("a.com", "app.t.c", ".abc.uri", 2, links.next)?; 1140 + let links = storage.get_links( 1141 + "a.com", 1142 + "app.t.c", 1143 + ".abc.uri", 1144 + 2, 1145 + links.next, 1146 + &HashSet::default(), 1147 + )?; 889 1148 assert_eq!( 890 1149 links, 891 1150 PagedAppendingCollection { ··· 926 1185 0, 927 1186 )?; 928 1187 } 929 - let links = storage.get_links("a.com", "app.t.c", ".abc.uri", 2, None)?; 1188 + let links = 1189 + storage.get_links("a.com", "app.t.c", ".abc.uri", 2, None, &HashSet::default())?; 930 1190 assert_eq!( 931 1191 links, 932 1192 PagedAppendingCollection { ··· 955 1215 }), 956 1216 0, 957 1217 )?; 958 - let links = storage.get_links("a.com", "app.t.c", ".abc.uri", 2, links.next)?; 1218 + let links = storage.get_links( 1219 + "a.com", 1220 + "app.t.c", 1221 + ".abc.uri", 1222 + 2, 1223 + links.next, 1224 + &HashSet::default(), 1225 + )?; 959 1226 assert_eq!( 960 1227 links, 961 1228 PagedAppendingCollection { ··· 989 1256 0, 990 1257 )?; 991 1258 } 992 - let links = storage.get_links("a.com", "app.t.c", ".abc.uri", 2, None)?; 1259 + let links = 1260 + storage.get_links("a.com", "app.t.c", ".abc.uri", 2, None, &HashSet::default())?; 993 1261 assert_eq!( 994 1262 links, 995 1263 PagedAppendingCollection { ··· 1014 1282 &ActionableEvent::DeactivateAccount("did:plc:asdf-1".into()), 1015 1283 0, 1016 1284 )?; 1017 - let links = storage.get_links("a.com", "app.t.c", ".abc.uri", 2, links.next)?; 1285 + let links = storage.get_links( 1286 + "a.com", 1287 + "app.t.c", 1288 + ".abc.uri", 1289 + 2, 1290 + links.next, 1291 + &HashSet::default(), 1292 + )?; 1018 1293 assert_eq!( 1019 1294 links, 1020 1295 PagedAppendingCollection { ··· 1081 1356 counts 1082 1357 }); 1083 1358 assert_stats(storage.get_stats()?, 1..=1, 2..=2, 1..=1); 1359 + }); 1360 + 1361 + //////// many-to-many ///////// 1362 + 1363 + test_each_storage!(get_m2m_counts_empty, |storage| { 1364 + assert_eq!( 1365 + storage.get_many_to_many_counts( 1366 + "a.com", 1367 + "a.b.c", 1368 + ".d.e", 1369 + ".f.g", 1370 + 10, 1371 + None, 1372 + &HashSet::new(), 1373 + &HashSet::new(), 1374 + )?, 1375 + PagedOrderedCollection { 1376 + items: vec![], 1377 + next: None, 1378 + } 1379 + ); 1380 + }); 1381 + 1382 + test_each_storage!(get_m2m_counts_single, |storage| { 1383 + storage.push( 1384 + &ActionableEvent::CreateLinks { 1385 + record_id: RecordId { 1386 + did: "did:plc:asdf".into(), 1387 + collection: "app.t.c".into(), 1388 + rkey: "asdf".into(), 1389 + }, 1390 + links: vec![ 1391 + CollectedLink { 1392 + target: Link::Uri("a.com".into()), 1393 + path: ".abc.uri".into(), 1394 + }, 1395 + CollectedLink { 1396 + target: Link::Uri("b.com".into()), 1397 + path: ".def.uri".into(), 1398 + }, 1399 + CollectedLink { 1400 + target: Link::Uri("b.com".into()), 1401 + path: ".ghi.uri".into(), 1402 + }, 1403 + ], 1404 + }, 1405 + 0, 1406 + )?; 1407 + assert_eq!( 1408 + storage.get_many_to_many_counts( 1409 + "a.com", 1410 + "app.t.c", 1411 + ".abc.uri", 1412 + ".def.uri", 1413 + 10, 1414 + None, 1415 + &HashSet::new(), 1416 + &HashSet::new(), 1417 + )?, 1418 + PagedOrderedCollection { 1419 + items: vec![("b.com".to_string(), 1, 1)], 1420 + next: None, 1421 + } 1422 + ); 1423 + }); 1424 + 1425 + test_each_storage!(get_m2m_counts_filters, |storage| { 1426 + storage.push( 1427 + &ActionableEvent::CreateLinks { 1428 + record_id: RecordId { 1429 + did: "did:plc:asdf".into(), 1430 + collection: "app.t.c".into(), 1431 + rkey: "asdf".into(), 1432 + }, 1433 + links: vec![ 1434 + CollectedLink { 1435 + target: Link::Uri("a.com".into()), 1436 + path: ".abc.uri".into(), 1437 + }, 1438 + CollectedLink { 1439 + target: Link::Uri("b.com".into()), 1440 + path: ".def.uri".into(), 1441 + }, 1442 + ], 1443 + }, 1444 + 0, 1445 + )?; 1446 + storage.push( 1447 + &ActionableEvent::CreateLinks { 1448 + record_id: RecordId { 1449 + did: "did:plc:asdfasdf".into(), 1450 + collection: "app.t.c".into(), 1451 + rkey: "asdf".into(), 1452 + }, 1453 + links: vec![ 1454 + CollectedLink { 1455 + target: Link::Uri("a.com".into()), 1456 + path: ".abc.uri".into(), 1457 + }, 1458 + CollectedLink { 1459 + target: Link::Uri("b.com".into()), 1460 + path: ".def.uri".into(), 1461 + }, 1462 + ], 1463 + }, 1464 + 1, 1465 + )?; 1466 + storage.push( 1467 + &ActionableEvent::CreateLinks { 1468 + record_id: RecordId { 1469 + did: "did:plc:fdsa".into(), 1470 + collection: "app.t.c".into(), 1471 + rkey: "asdf".into(), 1472 + }, 1473 + links: vec![ 1474 + CollectedLink { 1475 + target: Link::Uri("a.com".into()), 1476 + path: ".abc.uri".into(), 1477 + }, 1478 + CollectedLink { 1479 + target: Link::Uri("c.com".into()), 1480 + path: ".def.uri".into(), 1481 + }, 1482 + ], 1483 + }, 1484 + 2, 1485 + )?; 1486 + storage.push( 1487 + &ActionableEvent::CreateLinks { 1488 + record_id: RecordId { 1489 + did: "did:plc:fdsa".into(), 1490 + collection: "app.t.c".into(), 1491 + rkey: "asdf2".into(), 1492 + }, 1493 + links: vec![ 1494 + CollectedLink { 1495 + target: Link::Uri("a.com".into()), 1496 + path: ".abc.uri".into(), 1497 + }, 1498 + CollectedLink { 1499 + target: Link::Uri("c.com".into()), 1500 + path: ".def.uri".into(), 1501 + }, 1502 + ], 1503 + }, 1504 + 3, 1505 + )?; 1506 + assert_eq!( 1507 + storage.get_many_to_many_counts( 1508 + "a.com", 1509 + "app.t.c", 1510 + ".abc.uri", 1511 + ".def.uri", 1512 + 10, 1513 + None, 1514 + &HashSet::new(), 1515 + &HashSet::new(), 1516 + )?, 1517 + PagedOrderedCollection { 1518 + items: vec![("b.com".to_string(), 2, 2), ("c.com".to_string(), 2, 1),], 1519 + next: None, 1520 + } 1521 + ); 1522 + assert_eq!( 1523 + storage.get_many_to_many_counts( 1524 + "a.com", 1525 + "app.t.c", 1526 + ".abc.uri", 1527 + ".def.uri", 1528 + 10, 1529 + None, 1530 + &HashSet::from_iter([Did("did:plc:fdsa".to_string())]), 1531 + &HashSet::new(), 1532 + )?, 1533 + PagedOrderedCollection { 1534 + items: vec![("c.com".to_string(), 2, 1),], 1535 + next: None, 1536 + } 1537 + ); 1538 + assert_eq!( 1539 + storage.get_many_to_many_counts( 1540 + "a.com", 1541 + "app.t.c", 1542 + ".abc.uri", 1543 + ".def.uri", 1544 + 10, 1545 + None, 1546 + &HashSet::new(), 1547 + &HashSet::from_iter(["b.com".to_string()]), 1548 + )?, 1549 + PagedOrderedCollection { 1550 + items: vec![("b.com".to_string(), 2, 2),], 1551 + next: None, 1552 + } 1553 + ); 1084 1554 }); 1085 1555 }
+361 -41
constellation/src/storage/rocks_store.rs
··· 1 - use super::{ActionableEvent, LinkReader, LinkStorage, PagedAppendingCollection, StorageStats}; 1 + use super::{ 2 + ActionableEvent, LinkReader, LinkStorage, PagedAppendingCollection, PagedOrderedCollection, 3 + StorageStats, 4 + }; 2 5 use crate::{CountsByCount, Did, RecordId}; 3 6 use anyhow::{bail, Result}; 4 7 use bincode::Options as BincodeOptions; ··· 11 14 MultiThreaded, Options, PrefixRange, ReadOptions, WriteBatch, 12 15 }; 13 16 use serde::{Deserialize, Serialize}; 14 - use std::collections::{HashMap, HashSet}; 17 + use std::collections::{BTreeMap, HashMap, HashSet}; 15 18 use std::io::Read; 16 19 use std::marker::PhantomData; 17 20 use std::path::{Path, PathBuf}; ··· 20 23 Arc, 21 24 }; 22 25 use std::thread; 23 - use std::time::{Duration, Instant}; 26 + use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH}; 24 27 use tokio_util::sync::CancellationToken; 25 28 26 29 static DID_IDS_CF: &str = "did_ids"; ··· 29 32 static LINK_TARGETS_CF: &str = "link_targets"; 30 33 31 34 static JETSTREAM_CURSOR_KEY: &str = "jetstream_cursor"; 35 + static STARTED_AT_KEY: &str = "jetstream_first_cursor"; 36 + // add reverse mappings for targets if this db was running before that was a thing 37 + static TARGET_ID_REPAIR_STATE_KEY: &str = "target_id_table_repair_state"; 38 + 39 + static COZY_FIRST_CURSOR: u64 = 1_738_083_600_000_000; // constellation.microcosm.blue started 40 + 41 + #[derive(Debug, Clone, Serialize, Deserialize)] 42 + struct TargetIdRepairState { 43 + /// start time for repair, microseconds timestamp 44 + current_us_started_at: u64, 45 + /// id table's latest id when repair started 46 + id_when_started: u64, 47 + /// id table id 48 + latest_repaired_i: u64, 49 + } 50 + impl AsRocksValue for TargetIdRepairState {} 51 + impl ValueFromRocks for TargetIdRepairState {} 32 52 33 53 // todo: actually understand and set these options probably better 34 54 fn rocks_opts_base() -> Options { ··· 56 76 #[derive(Debug, Clone)] 57 77 pub struct RocksStorage { 58 78 pub db: Arc<DBWithThreadMode<MultiThreaded>>, // TODO: mov seqs here (concat merge op will be fun) 59 - did_id_table: IdTable<Did, DidIdValue, true>, 60 - target_id_table: IdTable<TargetKey, TargetId, false>, 79 + did_id_table: IdTable<Did, DidIdValue>, 80 + target_id_table: IdTable<TargetKey, TargetId>, 61 81 is_writer: bool, 62 82 backup_task: Arc<Option<thread::JoinHandle<Result<()>>>>, 63 83 } ··· 85 105 fn cf_descriptor(&self) -> ColumnFamilyDescriptor { 86 106 ColumnFamilyDescriptor::new(&self.name, rocks_opts_base()) 87 107 } 88 - fn init<const WITH_REVERSE: bool>( 89 - self, 90 - db: &DBWithThreadMode<MultiThreaded>, 91 - ) -> Result<IdTable<Orig, IdVal, WITH_REVERSE>> { 108 + fn init(self, db: &DBWithThreadMode<MultiThreaded>) -> Result<IdTable<Orig, IdVal>> { 92 109 if db.cf_handle(&self.name).is_none() { 93 110 bail!("failed to get cf handle from db -- was the db open with our .cf_descriptor()?"); 94 111 } ··· 119 136 } 120 137 } 121 138 #[derive(Debug, Clone)] 122 - struct IdTable<Orig, IdVal: IdTableValue, const WITH_REVERSE: bool> 139 + struct IdTable<Orig, IdVal: IdTableValue> 123 140 where 124 141 Orig: KeyFromRocks, 125 142 for<'a> &'a Orig: AsRocksKey, ··· 127 144 base: IdTableBase<Orig, IdVal>, 128 145 priv_id_seq: u64, 129 146 } 130 - impl<Orig: Clone, IdVal: IdTableValue, const WITH_REVERSE: bool> IdTable<Orig, IdVal, WITH_REVERSE> 147 + impl<Orig: Clone, IdVal: IdTableValue> IdTable<Orig, IdVal> 131 148 where 132 149 Orig: KeyFromRocks, 133 150 for<'v> &'v IdVal: AsRocksValue, ··· 139 156 _key_marker: PhantomData, 140 157 _val_marker: PhantomData, 141 158 name: name.into(), 142 - id_seq: Arc::new(AtomicU64::new(0)), // zero is "uninint", first seq num will be 1 159 + id_seq: Arc::new(AtomicU64::new(0)), // zero is "uninit", first seq num will be 1 143 160 } 144 161 } 145 162 fn get_id_val( ··· 178 195 id_value 179 196 })) 180 197 } 198 + 181 199 fn estimate_count(&self) -> u64 { 182 200 self.base.id_seq.load(Ordering::SeqCst) - 1 // -1 because seq zero is reserved 183 201 } 184 - } 185 - impl<Orig: Clone, IdVal: IdTableValue> IdTable<Orig, IdVal, true> 186 - where 187 - Orig: KeyFromRocks, 188 - for<'v> &'v IdVal: AsRocksValue, 189 - for<'k> &'k Orig: AsRocksKey, 190 - { 202 + 191 203 fn get_or_create_id_val( 192 204 &mut self, 193 205 db: &DBWithThreadMode<MultiThreaded>, ··· 215 227 } 216 228 } 217 229 } 218 - impl<Orig: Clone, IdVal: IdTableValue> IdTable<Orig, IdVal, false> 219 - where 220 - Orig: KeyFromRocks, 221 - for<'v> &'v IdVal: AsRocksValue, 222 - for<'k> &'k Orig: AsRocksKey, 223 - { 224 - fn get_or_create_id_val( 225 - &mut self, 226 - db: &DBWithThreadMode<MultiThreaded>, 227 - batch: &mut WriteBatch, 228 - orig: &Orig, 229 - ) -> Result<IdVal> { 230 - let cf = db.cf_handle(&self.base.name).unwrap(); 231 - self.__get_or_create_id_val(&cf, db, batch, orig) 232 - } 233 - } 234 230 235 231 impl IdTableValue for DidIdValue { 236 232 fn new(v: u64) -> Self { ··· 249 245 } 250 246 } 251 247 248 + fn now() -> u64 { 249 + SystemTime::now() 250 + .duration_since(UNIX_EPOCH) 251 + .unwrap() 252 + .as_micros() as u64 253 + } 254 + 252 255 impl RocksStorage { 253 256 pub fn new(path: impl AsRef<Path>) -> Result<Self> { 254 257 Self::describe_metrics(); 255 - RocksStorage::open_readmode(path, false) 258 + let me = RocksStorage::open_readmode(path, false)?; 259 + me.global_init()?; 260 + Ok(me) 256 261 } 257 262 258 263 pub fn open_readonly(path: impl AsRef<Path>) -> Result<Self> { ··· 260 265 } 261 266 262 267 fn open_readmode(path: impl AsRef<Path>, readonly: bool) -> Result<Self> { 263 - let did_id_table = IdTable::<_, _, true>::setup(DID_IDS_CF); 264 - let target_id_table = IdTable::<_, _, false>::setup(TARGET_IDS_CF); 268 + let did_id_table = IdTable::setup(DID_IDS_CF); 269 + let target_id_table = IdTable::setup(TARGET_IDS_CF); 265 270 271 + // note: global stuff like jetstream cursor goes in the default cf 272 + // these are bonus extra cfs 266 273 let cfs = vec![ 267 274 // id reference tables 268 275 did_id_table.cf_descriptor(), ··· 296 303 is_writer: !readonly, 297 304 backup_task: None.into(), 298 305 }) 306 + } 307 + 308 + fn global_init(&self) -> Result<()> { 309 + let first_run = self.db.get(JETSTREAM_CURSOR_KEY)?.is_some(); 310 + if first_run { 311 + self.db.put(STARTED_AT_KEY, _rv(now()))?; 312 + 313 + // hack / temporary: if we're a new db, put in a completed repair 314 + // state so we don't run repairs (repairs are for old-code dbs) 315 + let completed = TargetIdRepairState { 316 + id_when_started: 0, 317 + current_us_started_at: 0, 318 + latest_repaired_i: 0, 319 + }; 320 + self.db.put(TARGET_ID_REPAIR_STATE_KEY, _rv(completed))?; 321 + } 322 + Ok(()) 323 + } 324 + 325 + pub fn run_repair(&self, breather: Duration, stay_alive: CancellationToken) -> Result<bool> { 326 + let mut state = match self 327 + .db 328 + .get(TARGET_ID_REPAIR_STATE_KEY)? 329 + .map(|s| _vr(&s)) 330 + .transpose()? 331 + { 332 + Some(s) => s, 333 + None => TargetIdRepairState { 334 + id_when_started: self.did_id_table.priv_id_seq, 335 + current_us_started_at: now(), 336 + latest_repaired_i: 0, 337 + }, 338 + }; 339 + 340 + eprintln!("initial repair state: {state:?}"); 341 + 342 + let cf = self.db.cf_handle(TARGET_IDS_CF).unwrap(); 343 + 344 + let mut iter = self.db.raw_iterator_cf(&cf); 345 + iter.seek_to_first(); 346 + 347 + eprintln!("repair iterator sent to first key"); 348 + 349 + // skip ahead if we're done some, or take a single first step 350 + for _ in 0..state.latest_repaired_i { 351 + iter.next(); 352 + } 353 + 354 + eprintln!( 355 + "repair iterator skipped to {}th key", 356 + state.latest_repaired_i 357 + ); 358 + 359 + let mut maybe_done = false; 360 + 361 + let mut write_fast = rocksdb::WriteOptions::default(); 362 + write_fast.set_sync(false); 363 + write_fast.disable_wal(true); 364 + 365 + while !stay_alive.is_cancelled() && !maybe_done { 366 + // let mut batch = WriteBatch::default(); 367 + 368 + let mut any_written = false; 369 + 370 + for _ in 0..1000 { 371 + if state.latest_repaired_i % 1_000_000 == 0 { 372 + eprintln!("target iter at {}", state.latest_repaired_i); 373 + } 374 + state.latest_repaired_i += 1; 375 + 376 + if !iter.valid() { 377 + eprintln!("invalid iter, are we done repairing?"); 378 + maybe_done = true; 379 + break; 380 + }; 381 + 382 + // eprintln!("iterator seems to be valid! getting the key..."); 383 + let raw_key = iter.key().unwrap(); 384 + if raw_key.len() == 8 { 385 + // eprintln!("found an 8-byte key, skipping it since it's probably an id..."); 386 + iter.next(); 387 + continue; 388 + } 389 + let target: TargetKey = _kr::<TargetKey>(raw_key)?; 390 + let target_id: TargetId = _vr(iter.value().unwrap())?; 391 + 392 + self.db 393 + .put_cf_opt(&cf, target_id.id().to_be_bytes(), _rv(&target), &write_fast)?; 394 + any_written = true; 395 + iter.next(); 396 + } 397 + 398 + if any_written { 399 + self.db 400 + .put(TARGET_ID_REPAIR_STATE_KEY, _rv(state.clone()))?; 401 + std::thread::sleep(breather); 402 + } 403 + } 404 + 405 + eprintln!("repair iterator done."); 406 + 407 + Ok(false) 299 408 } 300 409 301 410 pub fn start_backup( ··· 826 935 } 827 936 828 937 impl LinkReader for RocksStorage { 938 + fn get_many_to_many_counts( 939 + &self, 940 + target: &str, 941 + collection: &str, 942 + path: &str, 943 + path_to_other: &str, 944 + limit: u64, 945 + after: Option<String>, 946 + filter_dids: &HashSet<Did>, 947 + filter_to_targets: &HashSet<String>, 948 + ) -> Result<PagedOrderedCollection<(String, u64, u64), String>> { 949 + let collection = Collection(collection.to_string()); 950 + let path = RPath(path.to_string()); 951 + 952 + let target_key = TargetKey(Target(target.to_string()), collection.clone(), path.clone()); 953 + 954 + // unfortunately the cursor is a, uh, stringified number. 955 + // this was easier for the memstore (plain target, not target id), and 956 + // making it generic is a bit awful. 957 + // so... parse the number out of a string here :( 958 + // TODO: this should bubble up to a BAD_REQUEST response 959 + let after = after.map(|s| s.parse::<u64>().map(TargetId)).transpose()?; 960 + 961 + let Some(target_id) = self.target_id_table.get_id_val(&self.db, &target_key)? else { 962 + eprintln!("nothin doin for this target, {target_key:?}"); 963 + return Ok(Default::default()); 964 + }; 965 + 966 + let filter_did_ids: HashMap<DidId, bool> = filter_dids 967 + .iter() 968 + .filter_map(|did| self.did_id_table.get_id_val(&self.db, did).transpose()) 969 + .collect::<Result<Vec<DidIdValue>>>()? 970 + .into_iter() 971 + .map(|DidIdValue(id, active)| (id, active)) 972 + .collect(); 973 + 974 + // stored targets are keyed by triples of (target, collection, path). 975 + // target filtering only consideres the target itself, so we actually 976 + // need to do a prefix iteration of all target ids for this target and 977 + // keep them all. 978 + // i *think* the number of keys at a target prefix should usually be 979 + // pretty small, so this is hopefully fine. but if it turns out to be 980 + // large, we can push this filtering back into the main links loop and 981 + // do forward db queries per backlink to get the raw target back out. 982 + let mut filter_to_target_ids: HashSet<TargetId> = HashSet::new(); 983 + for t in filter_to_targets { 984 + for (_, target_id) in self.iter_targets_for_target(&Target(t.to_string())) { 985 + filter_to_target_ids.insert(target_id); 986 + } 987 + } 988 + 989 + let linkers = self.get_target_linkers(&target_id)?; 990 + 991 + let mut grouped_counts: BTreeMap<TargetId, (u64, HashSet<DidId>)> = BTreeMap::new(); 992 + 993 + for (did_id, rkey) in linkers.0 { 994 + if did_id.is_empty() { 995 + continue; 996 + } 997 + 998 + if !filter_did_ids.is_empty() && filter_did_ids.get(&did_id) != Some(&true) { 999 + continue; 1000 + } 1001 + 1002 + let record_link_key = RecordLinkKey(did_id, collection.clone(), rkey); 1003 + let Some(targets) = self.get_record_link_targets(&record_link_key)? else { 1004 + continue; 1005 + }; 1006 + 1007 + let Some(fwd_target) = targets 1008 + .0 1009 + .into_iter() 1010 + .filter_map(|RecordLinkTarget(rpath, target_id)| { 1011 + if rpath.0 == path_to_other 1012 + && (filter_to_target_ids.is_empty() 1013 + || filter_to_target_ids.contains(&target_id)) 1014 + { 1015 + Some(target_id) 1016 + } else { 1017 + None 1018 + } 1019 + }) 1020 + .take(1) 1021 + .next() 1022 + else { 1023 + eprintln!("no forward match"); 1024 + continue; 1025 + }; 1026 + 1027 + // small relief: we page over target ids, so we can already bail 1028 + // reprocessing previous pages here 1029 + if after.as_ref().map(|a| fwd_target <= *a).unwrap_or(false) { 1030 + continue; 1031 + } 1032 + 1033 + // aand we can skip target ids that must be on future pages 1034 + // (this check continues after the did-lookup, which we have to do) 1035 + let page_is_full = grouped_counts.len() as u64 >= limit; 1036 + if page_is_full { 1037 + let current_max = grouped_counts.keys().next_back().unwrap(); // limit should be non-zero bleh 1038 + if fwd_target > *current_max { 1039 + continue; 1040 + } 1041 + } 1042 + 1043 + // bit painful: 2-step lookup to make sure this did is active 1044 + let Some(did) = self.did_id_table.get_val_from_id(&self.db, did_id.0)? else { 1045 + eprintln!("failed to look up did from did_id {did_id:?}"); 1046 + continue; 1047 + }; 1048 + let Some(DidIdValue(_, active)) = self.did_id_table.get_id_val(&self.db, &did)? else { 1049 + eprintln!("failed to look up did_value from did_id {did_id:?}: {did:?}: data consistency bug?"); 1050 + continue; 1051 + }; 1052 + if !active { 1053 + continue; 1054 + } 1055 + 1056 + // page-management, continued 1057 + // if we have a full page, and we're inserting a *new* key less than 1058 + // the current max, then we can evict the current max 1059 + let mut should_evict = false; 1060 + let entry = grouped_counts.entry(fwd_target.clone()).or_insert_with(|| { 1061 + // this is a *new* key, so kick the max if we're full 1062 + should_evict = page_is_full; 1063 + Default::default() 1064 + }); 1065 + entry.0 += 1; 1066 + entry.1.insert(did_id); 1067 + 1068 + if should_evict { 1069 + grouped_counts.pop_last(); 1070 + } 1071 + } 1072 + 1073 + let mut items: Vec<(String, u64, u64)> = Vec::with_capacity(grouped_counts.len()); 1074 + for (target_id, (n, dids)) in &grouped_counts { 1075 + let Some(target) = self 1076 + .target_id_table 1077 + .get_val_from_id(&self.db, target_id.0)? 1078 + else { 1079 + eprintln!("failed to look up target from target_id {target_id:?}"); 1080 + continue; 1081 + }; 1082 + items.push((target.0 .0, *n, dids.len() as u64)); 1083 + } 1084 + 1085 + let next = if grouped_counts.len() as u64 >= limit { 1086 + // yeah.... it's a number saved as a string......sorry 1087 + grouped_counts 1088 + .keys() 1089 + .next_back() 1090 + .map(|k| format!("{}", k.0)) 1091 + } else { 1092 + None 1093 + }; 1094 + 1095 + Ok(PagedOrderedCollection { items, next }) 1096 + } 1097 + 829 1098 fn get_count(&self, target: &str, collection: &str, path: &str) -> Result<u64> { 830 1099 let target_key = TargetKey( 831 1100 Target(target.to_string()), ··· 860 1129 path: &str, 861 1130 limit: u64, 862 1131 until: Option<u64>, 1132 + filter_dids: &HashSet<Did>, 863 1133 ) -> Result<PagedAppendingCollection<RecordId>> { 864 1134 let target_key = TargetKey( 865 1135 Target(target.to_string()), ··· 876 1146 }); 877 1147 }; 878 1148 879 - let linkers = self.get_target_linkers(&target_id)?; 1149 + let mut linkers = self.get_target_linkers(&target_id)?; 1150 + if !filter_dids.is_empty() { 1151 + let mut did_filter = HashSet::new(); 1152 + for did in filter_dids { 1153 + let Some(DidIdValue(did_id, active)) = 1154 + self.did_id_table.get_id_val(&self.db, did)? 1155 + else { 1156 + eprintln!("failed to find a did_id for {did:?}"); 1157 + continue; 1158 + }; 1159 + if !active { 1160 + eprintln!("excluding inactive did from filtered results"); 1161 + continue; 1162 + } 1163 + did_filter.insert(did_id); 1164 + } 1165 + linkers.0.retain(|linker| did_filter.contains(&linker.0)); 1166 + } 880 1167 881 1168 let (alive, gone) = linkers.count(); 882 1169 let total = alive + gone; ··· 1024 1311 .map(|s| s.parse::<u64>()) 1025 1312 .transpose()? 1026 1313 .unwrap_or(0); 1314 + let started_at = self 1315 + .db 1316 + .get(STARTED_AT_KEY)? 1317 + .map(|c| _vr(&c)) 1318 + .transpose()? 1319 + .unwrap_or(COZY_FIRST_CURSOR); 1320 + 1321 + let other_data = self 1322 + .db 1323 + .get(TARGET_ID_REPAIR_STATE_KEY)? 1324 + .map(|s| _vr(&s)) 1325 + .transpose()? 1326 + .map( 1327 + |TargetIdRepairState { 1328 + current_us_started_at, 1329 + id_when_started, 1330 + latest_repaired_i, 1331 + }| { 1332 + HashMap::from([ 1333 + ("current_us_started_at".to_string(), current_us_started_at), 1334 + ("id_when_started".to_string(), id_when_started), 1335 + ("latest_repaired_i".to_string(), latest_repaired_i), 1336 + ]) 1337 + }, 1338 + ) 1339 + .unwrap_or(HashMap::default()); 1340 + 1027 1341 Ok(StorageStats { 1028 1342 dids, 1029 1343 targetables, 1030 1344 linking_records, 1345 + started_at: Some(started_at), 1346 + other_data, 1031 1347 }) 1032 1348 } 1033 1349 } ··· 1053 1369 impl AsRocksValue for &TargetId {} 1054 1370 impl KeyFromRocks for TargetKey {} 1055 1371 impl ValueFromRocks for TargetId {} 1372 + 1373 + // temp? 1374 + impl KeyFromRocks for TargetId {} 1375 + impl AsRocksValue for &TargetKey {} 1056 1376 1057 1377 // target_links table 1058 1378 impl AsRocksKey for &TargetId {} ··· 1124 1444 } 1125 1445 1126 1446 // target ids 1127 - #[derive(Debug, Clone, Serialize, Deserialize)] 1447 + #[derive(Debug, Clone, Serialize, Deserialize, PartialOrd, Ord, PartialEq, Eq, Hash)] 1128 1448 struct TargetId(u64); // key 1129 1449 1130 - #[derive(Debug, Clone, Serialize, Deserialize)] 1450 + #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)] 1131 1451 pub struct Target(pub String); // the actual target/uri 1132 1452 1133 1453 // targets (uris, dids, etc.): the reverse index
+1 -1
constellation/templates/dids.html.j2
··· 27 27 {% for did in linking_dids %} 28 28 <pre style="display: block; margin: 1em 2em" class="code"><strong>DID</strong>: {{ did.0 }} 29 29 -> see <a href="/links/all?target={{ did.0|urlencode }}">links to this DID</a> 30 - -> browse <a href="https://atproto-browser-plus-links.vercel.app/at/{{ did.0|urlencode }}">this DID record</a></pre> 30 + -> browse <a href="https://pdsls.dev/at://{{ did.0 }}">this DID record</a></pre> 31 31 {% endfor %} 32 32 33 33 {% if let Some(c) = cursor %}
+54
constellation/templates/get-backlinks.html.j2
··· 1 + {% extends "base.html.j2" %} 2 + {% import "try-it-macros.html.j2" as try_it %} 3 + 4 + {% block title %}Backlinks{% endblock %} 5 + {% block description %}All {{ query.source }} records with links to {{ query.subject }}{% endblock %} 6 + 7 + {% block content %} 8 + 9 + {% call try_it::get_backlinks(query.subject, query.source, query.did, query.limit) %} 10 + 11 + <h2> 12 + Links to <code>{{ query.subject }}</code> 13 + {% if let Some(browseable_uri) = query.subject|to_browseable %} 14 + <small style="font-weight: normal; font-size: 1rem"><a href="{{ browseable_uri }}">browse record</a></small> 15 + {% endif %} 16 + </h2> 17 + 18 + <p><strong>{{ total|human_number }} links</strong> from <code>{{ query.source }}</code>.</p> 19 + 20 + <ul> 21 + <li>See distinct linking DIDs at <code>/links/distinct-dids</code>: <a href="/links/distinct-dids?target={{ query.subject|urlencode }}&collection={{ collection|urlencode }}&path={{ path|urlencode }}">/links/distinct-dids?target={{ query.subject }}&collection={{ collection }}&path={{ path }}</a></li> 22 + <li>See all links to this target at <code>/links/all</code>: <a href="/links/all?target={{ query.subject|urlencode }}">/links/all?target={{ query.subject }}</a></li> 23 + </ul> 24 + 25 + <h3>Links, most recent first:</h3> 26 + 27 + {% for record in records %} 28 + <pre style="display: block; margin: 1em 2em" class="code"><strong>DID</strong>: {{ record.did().0 }} (<a href="/links/all?target={{ record.did().0|urlencode }}">DID links</a>) 29 + <strong>Collection</strong>: {{ record.collection }} 30 + <strong>RKey</strong>: {{ record.rkey }} 31 + -> <a href="https://pdsls.dev/at://{{ record.did().0 }}/{{ record.collection }}/{{ record.rkey }}">browse record</a></pre> 32 + {% endfor %} 33 + 34 + {% if let Some(c) = cursor %} 35 + <form method="get" action="/xrpc/blue.microcosm.links.getBacklinks"> 36 + <input type="hidden" name="subject" value="{{ query.subject }}" /> 37 + <input type="hidden" name="source" value="{{ query.source }}" /> 38 + <input type="hidden" name="limit" value="{{ query.limit }}" /> 39 + {% for did in query.did %} 40 + <input type="hidden" name="did" value="{{ did }}" /> 41 + {% endfor %} 42 + <input type="hidden" name="cursor" value={{ c|json|safe }} /> 43 + <button type="submit">next page&hellip;</button> 44 + </form> 45 + {% else %} 46 + <button disabled><em>end of results</em></button> 47 + {% endif %} 48 + 49 + <details> 50 + <summary>Raw JSON response</summary> 51 + <pre class="code">{{ self|tojson }}</pre> 52 + </details> 53 + 54 + {% endblock %}
+67
constellation/templates/get-many-to-many-counts.html.j2
··· 1 + {% extends "base.html.j2" %} 2 + {% import "try-it-macros.html.j2" as try_it %} 3 + 4 + {% block title %}Many to Many counts{% endblock %} 5 + {% block description %}Counts of many-to-many {{ query.source }} join records with links to {{ query.subject }} and a secondary target at {{ query.path_to_other }}{% endblock %} 6 + 7 + {% block content %} 8 + 9 + {% call try_it::get_many_to_many_counts( 10 + query.subject, 11 + query.source, 12 + query.path_to_other, 13 + query.did, 14 + query.other_subject, 15 + query.limit, 16 + ) %} 17 + 18 + <h2> 19 + Many-to-many links to <code>{{ query.subject }}</code> joining through <code>{{ query.path_to_other }}</code> 20 + {% if let Some(browseable_uri) = query.subject|to_browseable %} 21 + <small style="font-weight: normal; font-size: 1rem"><a href="{{ browseable_uri }}">browse record</a></small> 22 + {% endif %} 23 + </h2> 24 + 25 + <p><strong>{% if cursor.is_some() || query.cursor.is_some() %}more than {% endif %}{{ counts_by_other_subject.len()|to_u64|human_number }} joins</strong> <code>{{ query.source }}โ†’{{ query.path_to_other }}</code></p> 26 + 27 + <ul> 28 + <li>See direct backlinks at <code>/xrpc/blue.microcosm.links.getBacklinks</code>: <a href="/xrpc/blue.microcosm.links.getBacklinks?subject={{ query.subject|urlencode }}&source={{ query.source|urlencode }}">/xrpc/blue.microcosm.links.getBacklinks?subject={{ query.subject }}&source={{ query.source }}</a></li> 29 + <li>See all links to this target at <code>/links/all</code>: <a href="/links/all?target={{ query.subject|urlencode }}">/links/all?target={{ query.subject }}</a></li> 30 + </ul> 31 + 32 + <h3>Counts by other subject:</h3> 33 + 34 + {% for counts in counts_by_other_subject %} 35 + <pre style="display: block; margin: 1em 2em" class="code"><strong>Joined subject</strong>: {{ counts.subject }} 36 + <strong>Joining records</strong>: {{ counts.total }} 37 + <strong>Unique joiner ids</strong>: {{ counts.distinct }} 38 + -> {% if let Some(browseable_uri) = counts.subject|to_browseable -%} 39 + <a href="{{ browseable_uri }}">browse record</a> 40 + {%- endif %}</pre> 41 + {% endfor %} 42 + 43 + {% if let Some(c) = cursor %} 44 + <form method="get" action="/xrpc/blue.microcosm.links.getManyToManyCounts"> 45 + <input type="hidden" name="subject" value="{{ query.subject }}" /> 46 + <input type="hidden" name="source" value="{{ query.source }}" /> 47 + <input type="hidden" name="pathToOther" value="{{ query.path_to_other }}" /> 48 + {% for did in query.did %} 49 + <input type="hidden" name="did" value="{{ did }}" /> 50 + {% endfor %} 51 + {% for otherSubject in query.other_subject %} 52 + <input type="hidden" name="otherSubject" value="{{ otherSubject }}" /> 53 + {% endfor %} 54 + <input type="hidden" name="limit" value="{{ query.limit }}" /> 55 + <input type="hidden" name="cursor" value={{ c|json|safe }} /> 56 + <button type="submit">next page&hellip;</button> 57 + </form> 58 + {% else %} 59 + <button disabled><em>end of results</em></button> 60 + {% endif %} 61 + 62 + <details> 63 + <summary>Raw JSON response</summary> 64 + <pre class="code">{{ self|tojson }}</pre> 65 + </details> 66 + 67 + {% endblock %}
+65 -7
constellation/templates/hello.html.j2
··· 19 19 <p>It works by recursively walking <em>all</em> records coming through the firehose, searching for anything that looks like a link. Links are indexed by the target they point at, the collection the record came from, and the JSON path to the link in that record.</p> 20 20 21 21 <p> 22 - This server has indexed <span class="stat">{{ stats.linking_records|human_number }}</span> links between <span class="stat">{{ stats.targetables|human_number }}</span> targets and sources from <span class="stat">{{ stats.dids|human_number }}</span> identities over <span class="stat">{{ days_indexed|human_number }}</span> days.<br/> 23 - <small>(indexing new records in real time, backfill still TODO)</small> 22 + This server has indexed <span class="stat">{{ stats.linking_records|human_number }}</span> links between <span class="stat">{{ stats.targetables|human_number }}</span> targets and sources from <span class="stat">{{ stats.dids|human_number }}</span> identities over <span class="stat"> 23 + {%- if let Some(days) = days_indexed %} 24 + {{ days|human_number }} 25 + {% else %} 26 + ??? 27 + {% endif -%} 28 + </span> days.<br/> 29 + <small>(indexing new records in real time, backfill coming soon!)</small> 24 30 </p> 25 31 26 - <p>The API is currently <strong>unstable</strong>. But feel free to use it! If you want to be nice, put your project name and bsky username (or email) in your user-agent header for api requests.</p> 32 + {# {% for k, v in stats.other_data.iter() %} 33 + <p><strong>{{ k }}</strong>: {{ v }}</p> 34 + {% endfor %} #} 35 + 36 + <p>You're welcome to use this public instance! Please do not build the torment nexus. If you want to be nice, put your project name and bsky username (or email) in your user-agent header for api requests.</p> 27 37 28 38 29 39 <h2>API Endpoints</h2> 30 40 41 + <h3 class="route"><code>GET /xrpc/blue.microcosm.links.getBacklinks</code></h3> 42 + 43 + <p>A list of records linking to any record, identity, or uri.</p> 44 + 45 + <h4>Query parameters:</h4> 46 + 47 + <ul> 48 + <li><p><code>subject</code>: required, must url-encode. Example: <code>at://did:plc:vc7f4oafdgxsihk4cry2xpze/app.bsky.feed.post/3lgwdn7vd722r</code></p></li> 49 + <li><p><code>source</code>: required. Example: <code>app.bsky.feed.like:subject.uri</code></p></li> 50 + <li><p><code>did</code>: optional, filter links to those from specific users. Include multiple times to filter by multiple users. Example: <code>did=did:plc:vc7f4oafdgxsihk4cry2xpze&did=did:plc:vc7f4oafdgxsihk4cry2xpze</code></p></li> 51 + <li><p><code>limit</code>: optional. Default: <code>16</code>. Maximum: <code>100</code></p></li> 52 + </ul> 53 + 54 + <p style="margin-bottom: 0"><strong>Try it:</strong></p> 55 + {% call try_it::get_backlinks("at://did:plc:a4pqq234yw7fqbddawjo7y35/app.bsky.feed.post/3m237ilwc372e", "app.bsky.feed.like:subject.uri", [""], 16) %} 56 + 57 + 58 + <h3 class="route"><code>GET /xrpc/blue.microcosm.links.getManyToManyCounts</code></h3> 59 + 60 + <p>TODO: description</p> 61 + 62 + <h4>Query parameters:</h4> 63 + 64 + <ul> 65 + <li><p><code>subject</code>: required, must url-encode. Example: <code>at://did:plc:vc7f4oafdgxsihk4cry2xpze/app.bsky.feed.post/3lgwdn7vd722r</code></p></li> 66 + <li><p><code>source</code>: required. Example: <code>app.bsky.feed.like:subject.uri</code></p></li> 67 + <li><p><code>pathToOther</code>: required. Path to the secondary link in the many-to-many record. Example: <code>otherThing.uri</code></p></li> 68 + <li><p><code>did</code>: optional, filter links to those from specific users. Include multiple times to filter by multiple users. Example: <code>did=did:plc:vc7f4oafdgxsihk4cry2xpze&did=did:plc:vc7f4oafdgxsihk4cry2xpze</code></p></li> 69 + <li><p><code>otherSubject</code>: optional, filter secondary links to specific subjects. Include multiple times to filter by multiple users. Example: <code>at://did:plc:vc7f4oafdgxsihk4cry2xpze/app.bsky.feed.post/3lgwdn7vd722r</code></p></li> 70 + <li><p><code>limit</code>: optional. Default: <code>16</code>. Maximum: <code>100</code></p></li> 71 + </ul> 72 + 73 + <p style="margin-bottom: 0"><strong>Try it:</strong></p> 74 + {% call try_it::get_many_to_many_counts( 75 + "at://did:plc:wshs7t2adsemcrrd4snkeqli/sh.tangled.label.definition/good-first-issue", 76 + "sh.tangled.label.op:add[].key", 77 + "subject", 78 + [""], 79 + [""], 80 + 25, 81 + ) %} 82 + 83 + 31 84 <h3 class="route"><code>GET /links</code></h3> 32 85 33 86 <p>A list of records linking to a target.</p> 34 87 88 + <p>[DEPRECATED]: use <code>GET /xrpc/blue.microcosm.links.getBacklinks</code>. New apps should avoid it, but this endpoint <strong>will</strong> remain supported for the forseeable future.</p> 89 + 35 90 <h4>Query parameters:</h4> 36 91 37 92 <ul> 38 - <li><code>target</code>: required, must url-encode. Example: <code>at://did:plc:vc7f4oafdgxsihk4cry2xpze/app.bsky.feed.post/3lgwdn7vd722r</code></li> 39 - <li><code>collection</code>: required. Example: <code>app.bsky.feed.like</code></li> 40 - <li><code>path</code>: required, must url-encode. Example: <code>.subject.uri</code></li> 93 + <li><p><code>target</code>: required, must url-encode. Example: <code>at://did:plc:vc7f4oafdgxsihk4cry2xpze/app.bsky.feed.post/3lgwdn7vd722r</code></p></li> 94 + <li><p><code>collection</code>: required. Example: <code>app.bsky.feed.like</code></p></li> 95 + <li><p><code>path</code>: required, must url-encode. Example: <code>.subject.uri</code></p></li> 96 + <li><p><code>did</code>: optional, filter links to those from specific users. Include multiple times to filter by multiple users. Example: <code>did=did:plc:vc7f4oafdgxsihk4cry2xpze&did=did:plc:vc7f4oafdgxsihk4cry2xpze</code></p></li> 97 + <li><p><code>from_dids</code> [deprecated]: optional. Use <code>did</code> instead. Example: <code>from_dids=did:plc:vc7f4oafdgxsihk4cry2xpze,did:plc:vc7f4oafdgxsihk4cry2xpze</code></p></li> 98 + <li><p><code>limit</code>: optional. Default: <code>16</code>. Maximum: <code>100</code></p></li> 41 99 </ul> 42 100 43 101 <p style="margin-bottom: 0"><strong>Try it:</strong></p> 44 - {% call try_it::links("at://did:plc:vc7f4oafdgxsihk4cry2xpze/app.bsky.feed.post/3lgwdn7vd722r", "app.bsky.feed.like", ".subject.uri") %} 102 + {% call try_it::links("at://did:plc:a4pqq234yw7fqbddawjo7y35/app.bsky.feed.post/3m237ilwc372e", "app.bsky.feed.like", ".subject.uri", [""], 16) %} 45 103 46 104 47 105 <h3 class="route"><code>GET /links/distinct-dids</code></h3>
+2 -2
constellation/templates/links.html.j2
··· 6 6 7 7 {% block content %} 8 8 9 - {% call try_it::links(query.target, query.collection, query.path) %} 9 + {% call try_it::links(query.target, query.collection, query.path, query.did, query.limit) %} 10 10 11 11 <h2> 12 12 Links to <code>{{ query.target }}</code> ··· 28 28 <pre style="display: block; margin: 1em 2em" class="code"><strong>DID</strong>: {{ record.did().0 }} (<a href="/links/all?target={{ record.did().0|urlencode }}">DID links</a>) 29 29 <strong>Collection</strong>: {{ record.collection }} 30 30 <strong>RKey</strong>: {{ record.rkey }} 31 - -> <a href="https://atproto-browser-plus-links.vercel.app/at/{{ record.did().0|urlencode }}/{{ record.collection }}/{{ record.rkey }}">browse record</a></pre> 31 + -> <a href="https://pdsls.dev/at://{{ record.did().0 }}/{{ record.collection }}/{{ record.rkey }}">browse record</a></pre> 32 32 {% endfor %} 33 33 34 34 {% if let Some(c) = cursor %}
+88 -3
constellation/templates/try-it-macros.html.j2
··· 1 - {% macro links(target, collection, path) %} 1 + {% macro get_backlinks(subject, source, dids, limit) %} 2 + <form method="get" action="/xrpc/blue.microcosm.links.getBacklinks"> 3 + <pre class="code"><strong>GET</strong> /xrpc/blue.microcosm.links.getBacklinks 4 + ?subject= <input type="text" name="subject" value="{{ subject }}" placeholder="at-uri, did, uri..." /> 5 + &source= <input type="text" name="source" value="{{ source }}" placeholder="app.bsky.feed.like:subject.uri" /> 6 + {%- for did in dids %}{% if !did.is_empty() %} 7 + &did= <input type="text" name="did" value="{{ did }}" placeholder="did:plc:..." />{% endif %}{% endfor %} 8 + <span id="did-placeholder"></span> <button id="add-did">+ did filter</button> 9 + &limit= <input type="number" name="limit" value="{{ limit }}" max="100" placeholder="100" /> <button type="submit">get links</button></pre> 10 + </form> 11 + <script> 12 + const addDidButton = document.getElementById('add-did'); 13 + const didPlaceholder = document.getElementById('did-placeholder'); 14 + addDidButton.addEventListener('click', e => { 15 + e.preventDefault(); 16 + const i = document.createElement('input'); 17 + i.placeholder = 'did:plc:...'; 18 + i.name = "did" 19 + const p = addDidButton.parentNode; 20 + p.insertBefore(document.createTextNode('&did= '), didPlaceholder); 21 + p.insertBefore(i, didPlaceholder); 22 + p.insertBefore(document.createTextNode('\n '), didPlaceholder); 23 + }); 24 + </script> 25 + {% endmacro %} 26 + 27 + {% macro get_many_to_many_counts(subject, source, pathToOther, dids, otherSubjects, limit) %} 28 + <form method="get" action="/xrpc/blue.microcosm.links.getManyToManyCounts"> 29 + <pre class="code"><strong>GET</strong> /xrpc/blue.microcosm.links.getManyToManyCounts 30 + ?subject= <input type="text" name="subject" value="{{ subject }}" placeholder="at-uri, did, uri..." /> 31 + &source= <input type="text" name="source" value="{{ source }}" placeholder="app.bsky.feed.like:subject.uri" /> 32 + &pathToOther= <input type="text" name="pathToOther" value="{{ pathToOther }}" placeholder="otherThing.uri" /> 33 + {%- for did in dids %}{% if !did.is_empty() %} 34 + &did= <input type="text" name="did" value="{{ did }}" placeholder="did:plc:..." />{% endif %}{% endfor %} 35 + <span id="m2m-subject-placeholder"></span> <button id="m2m-add-subject">+ other subject filter</button> 36 + {%- for otherSubject in otherSubjects %}{% if !otherSubject.is_empty() %} 37 + &otherSubject= <input type="text" name="did" value="{{ otherSubject }}" placeholder="at-uri, did, uri..." />{% endif %}{% endfor %} 38 + <span id="m2m-did-placeholder"></span> <button id="m2m-add-did">+ did filter</button> 39 + &limit= <input type="number" name="limit" value="{{ limit }}" max="100" placeholder="100" /> <button type="submit">get links</button></pre> 40 + </form> 41 + <script> 42 + const m2mAddDidButton = document.getElementById('m2m-add-did'); 43 + const m2mDidPlaceholder = document.getElementById('m2m-did-placeholder'); 44 + m2mAddDidButton.addEventListener('click', e => { 45 + e.preventDefault(); 46 + const i = document.createElement('input'); 47 + i.placeholder = 'did:plc:...'; 48 + i.name = "did" 49 + const p = m2mAddDidButton.parentNode; 50 + p.insertBefore(document.createTextNode('&did= '), m2mDidPlaceholder); 51 + p.insertBefore(i, m2mDidPlaceholder); 52 + p.insertBefore(document.createTextNode('\n '), m2mDidPlaceholder); 53 + }); 54 + const m2mAddSubjectButton = document.getElementById('m2m-add-subject'); 55 + const m2mSubjectPlaceholder = document.getElementById('m2m-subject-placeholder'); 56 + m2mAddSubjectButton.addEventListener('click', e => { 57 + e.preventDefault(); 58 + const i = document.createElement('input'); 59 + i.placeholder = 'at-uri, did, uri...'; 60 + i.name = "otherSubject" 61 + const p = m2mAddSubjectButton.parentNode; 62 + p.insertBefore(document.createTextNode('&otherSubject= '), m2mSubjectPlaceholder); 63 + p.insertBefore(i, m2mSubjectPlaceholder); 64 + p.insertBefore(document.createTextNode('\n '), m2mSubjectPlaceholder); 65 + }); 66 + </script> 67 + {% endmacro %} 68 + 69 + {% macro links(target, collection, path, dids, limit) %} 2 70 <form method="get" action="/links"> 3 71 <pre class="code"><strong>GET</strong> /links 4 72 ?target= <input type="text" name="target" value="{{ target }}" placeholder="target" /> 5 73 &collection= <input type="text" name="collection" value="{{ collection }}" placeholder="collection" /> 6 - &path= <input type="text" name="path" value="{{ path }}" placeholder="path" /> <button type="submit">get links</button></pre> 74 + &path= <input type="text" name="path" value="{{ path }}" placeholder="path" /> 75 + {%- for did in dids %}{% if !did.is_empty() %} 76 + &did= <input type="text" name="did" value="{{ did }}" placeholder="did:plc:..." />{% endif %}{% endfor %} 77 + <span id="did-placeholder"></span> <button id="add-did">+ did filter</button> 78 + &limit= <input type="number" name="limit" value="{{ limit }}" max="100" placeholder="100" /> <button type="submit">get links</button></pre> 7 79 </form> 80 + <script> 81 + const addDidButton = document.getElementById('add-did'); 82 + const didPlaceholder = document.getElementById('did-placeholder'); 83 + addDidButton.addEventListener('click', e => { 84 + e.preventDefault(); 85 + const i = document.createElement('input'); 86 + i.placeholder = 'did:plc:...'; 87 + i.name = "did" 88 + const p = addDidButton.parentNode; 89 + p.insertBefore(document.createTextNode('&did= '), didPlaceholder); 90 + p.insertBefore(i, didPlaceholder); 91 + p.insertBefore(document.createTextNode('\n '), didPlaceholder); 92 + }); 93 + </script> 8 94 {% endmacro %} 9 - 10 95 11 96 {% macro dids(target, collection, path) %} 12 97 <form method="get" action="/links/distinct-dids">
+95
lexicons/blue.microcosm/links/getBacklinks.json
··· 1 + { 2 + "lexicon": 1, 3 + "id": "blue.microcosm.links.getBacklinks", 4 + "defs": { 5 + "main": { 6 + "type": "query", 7 + "description": "a list of records linking to any record, identity, or uri", 8 + "parameters": { 9 + "type": "params", 10 + "required": [ 11 + "subject", 12 + "source" 13 + ], 14 + "properties": { 15 + "subject": { 16 + "type": "string", 17 + "format": "uri", 18 + "description": "the target being linked to (at-uri, did, or uri)" 19 + }, 20 + "source": { 21 + "type": "string", 22 + "description": "collection and path specification (e.g., 'app.bsky.feed.like:subject.uri')" 23 + }, 24 + "did": { 25 + "type": "array", 26 + "description": "filter links to those from specific users", 27 + "items": { 28 + "type": "string", 29 + "format": "did" 30 + } 31 + }, 32 + "limit": { 33 + "type": "integer", 34 + "minimum": 1, 35 + "maximum": 100, 36 + "default": 16, 37 + "description": "number of results to return" 38 + } 39 + } 40 + }, 41 + "output": { 42 + "encoding": "application/json", 43 + "schema": { 44 + "type": "object", 45 + "required": [ 46 + "total", 47 + "records" 48 + ], 49 + "properties": { 50 + "total": { 51 + "type": "integer", 52 + "description": "total number of matching links" 53 + }, 54 + "records": { 55 + "type": "array", 56 + "items": { 57 + "type": "ref", 58 + "ref": "#linkRecord" 59 + } 60 + }, 61 + "cursor": { 62 + "type": "string", 63 + "description": "pagination cursor" 64 + } 65 + } 66 + } 67 + } 68 + }, 69 + "linkRecord": { 70 + "type": "object", 71 + "required": [ 72 + "did", 73 + "collection", 74 + "rkey" 75 + ], 76 + "properties": { 77 + "did": { 78 + "type": "string", 79 + "format": "did", 80 + "description": "the DID of the linking record's repository" 81 + }, 82 + "collection": { 83 + "type": "string", 84 + "format": "nsid", 85 + "description": "the collection of the linking record" 86 + }, 87 + "rkey": { 88 + "type": "string", 89 + "format": "record-key", 90 + "description": "the record key of the linking record" 91 + } 92 + } 93 + } 94 + } 95 + }
+99
lexicons/blue.microcosm/links/getManyToManyCounts.json
··· 1 + { 2 + "lexicon": 1, 3 + "id": "blue.microcosm.links.getManyToManyCounts", 4 + "defs": { 5 + "main": { 6 + "type": "query", 7 + "description": "count many-to-many relationships with secondary link paths", 8 + "parameters": { 9 + "type": "params", 10 + "required": [ 11 + "subject", 12 + "source", 13 + "pathToOther" 14 + ], 15 + "properties": { 16 + "subject": { 17 + "type": "string", 18 + "format": "uri", 19 + "description": "the primary target being linked to (at-uri, did, or uri)" 20 + }, 21 + "source": { 22 + "type": "string", 23 + "description": "collection and path specification for the primary link" 24 + }, 25 + "pathToOther": { 26 + "type": "string", 27 + "description": "path to the secondary link in the many-to-many record (e.g., 'otherThing.uri')" 28 + }, 29 + "did": { 30 + "type": "array", 31 + "description": "filter links to those from specific users", 32 + "items": { 33 + "type": "string", 34 + "format": "did" 35 + } 36 + }, 37 + "otherSubject": { 38 + "type": "array", 39 + "description": "filter secondary links to specific subjects", 40 + "items": { 41 + "type": "string" 42 + } 43 + }, 44 + "limit": { 45 + "type": "integer", 46 + "minimum": 1, 47 + "maximum": 100, 48 + "default": 16, 49 + "description": "number of results to return" 50 + } 51 + } 52 + }, 53 + "output": { 54 + "encoding": "application/json", 55 + "schema": { 56 + "type": "object", 57 + "required": [ 58 + "counts_by_other_subject" 59 + ], 60 + "properties": { 61 + "counts_by_other_subject": { 62 + "type": "array", 63 + "items": { 64 + "type": "ref", 65 + "ref": "#countBySubject" 66 + } 67 + }, 68 + "cursor": { 69 + "type": "string", 70 + "description": "pagination cursor" 71 + } 72 + } 73 + } 74 + } 75 + }, 76 + "countBySubject": { 77 + "type": "object", 78 + "required": [ 79 + "subject", 80 + "total", 81 + "distinct" 82 + ], 83 + "properties": { 84 + "subject": { 85 + "type": "string", 86 + "description": "the secondary subject being counted" 87 + }, 88 + "total": { 89 + "type": "integer", 90 + "description": "total number of links to this subject" 91 + }, 92 + "distinct": { 93 + "type": "integer", 94 + "description": "number of distinct DIDs linking to this subject" 95 + } 96 + } 97 + } 98 + } 99 + }
+56
lexicons/com.bad-example/identity/resolveMiniDoc.json
··· 1 + { 2 + "lexicon": 1, 3 + "id": "com.bad-example.identity.resolveMiniDoc", 4 + "defs": { 5 + "main": { 6 + "type": "query", 7 + "description": "like com.atproto.identity.resolveIdentity but instead of the full didDoc it returns an atproto-relevant subset", 8 + "parameters": { 9 + "type": "params", 10 + "required": [ 11 + "identifier" 12 + ], 13 + "properties": { 14 + "identifier": { 15 + "type": "string", 16 + "format": "at-identifier", 17 + "description": "handle or DID to resolve" 18 + } 19 + } 20 + }, 21 + "output": { 22 + "encoding": "application/json", 23 + "schema": { 24 + "type": "object", 25 + "required": [ 26 + "did", 27 + "handle", 28 + "pds", 29 + "signing_key" 30 + ], 31 + "properties": { 32 + "did": { 33 + "type": "string", 34 + "format": "did", 35 + "description": "DID, bi-directionally verified if a handle was provided in the query" 36 + }, 37 + "handle": { 38 + "type": "string", 39 + "format": "handle", 40 + "description": "the validated handle of the account or 'handle.invalid' if the handle did not bi-directionally match the DID document" 41 + }, 42 + "pds": { 43 + "type": "string", 44 + "format": "uri", 45 + "description": "the identity's PDS URL" 46 + }, 47 + "signing_key": { 48 + "type": "string", 49 + "description": "the atproto signing key publicKeyMultibase" 50 + } 51 + } 52 + } 53 + } 54 + } 55 + } 56 + }
+54
lexicons/com.bad-example/repo/getUriRecord.json
··· 1 + { 2 + "lexicon": 1, 3 + "id": "com.bad-example.repo.getUriRecord", 4 + "defs": { 5 + "main": { 6 + "type": "query", 7 + "description": "ergonomic complement to com.atproto.repo.getRecord which accepts an at-uri instead of individual repo/collection/rkey params", 8 + "parameters": { 9 + "type": "params", 10 + "required": [ 11 + "at_uri" 12 + ], 13 + "properties": { 14 + "at_uri": { 15 + "type": "string", 16 + "format": "at-uri", 17 + "description": "the at-uri of the record (identifier can be a DID or handle)" 18 + }, 19 + "cid": { 20 + "type": "string", 21 + "format": "cid", 22 + "description": "optional CID of the version of the record. if not specified, return the most recent version. if specified and a newer version exists, returns 404." 23 + } 24 + } 25 + }, 26 + "output": { 27 + "encoding": "application/json", 28 + "schema": { 29 + "type": "object", 30 + "required": [ 31 + "uri", 32 + "value" 33 + ], 34 + "properties": { 35 + "uri": { 36 + "type": "string", 37 + "format": "at-uri", 38 + "description": "at-uri for this record" 39 + }, 40 + "cid": { 41 + "type": "string", 42 + "format": "cid", 43 + "description": "CID for this exact version of the record" 44 + }, 45 + "value": { 46 + "type": "unknown", 47 + "description": "the record itself" 48 + } 49 + } 50 + } 51 + } 52 + } 53 + } 54 + }
+1
pocket/.gitignore
··· 1 + prefs.sqlite3*
+17
pocket/api-description.md
··· 1 + _A pocket dimension to stash a bit of non-public user data._ 2 + 3 + 4 + # Pocket: user preference storage 5 + 6 + This API leverages atproto service proxying to offer a bit of per-user per-app non-public data storage. 7 + Perfect for things like application preferences that might be better left out of the public PDS data. 8 + 9 + The intent is to use oauth scopes to isolate storage on a per-application basis, and to allow easy data migration from a community hosted instance to your own if you end up needing that. 10 + 11 + 12 + ### Current status 13 + 14 + > [!important] 15 + > Pocket is currently in a **v0, pre-release state**. There is one production instance and you can use it! Expect short downtimes for restarts as development progresses and occaisional data loss until it's stable. 16 + 17 + ATProto might end up adding a similar feature to [PDSs](https://atproto.com/guides/glossary#pds-personal-data-server). If/when that happens, you should use it instead of this!
+3 -1
pocket/src/lib.rs
··· 1 1 mod server; 2 + mod storage; 2 3 mod token; 3 4 4 5 pub use server::serve; 5 - pub use token::verify; 6 + pub use storage::Storage; 7 + pub use token::TokenVerifier;
+29 -4
pocket/src/main.rs
··· 1 - use pocket::serve; 1 + use clap::Parser; 2 + use pocket::{Storage, serve}; 3 + use std::path::PathBuf; 4 + 5 + /// Slingshot record edge cache 6 + #[derive(Parser, Debug, Clone)] 7 + #[command(version, about, long_about = None)] 8 + struct Args { 9 + /// path to the sqlite db file 10 + #[arg(long)] 11 + db: Option<PathBuf>, 12 + /// just initialize the db and exit 13 + #[arg(long, action)] 14 + init_db: bool, 15 + /// the domain for serving a did doc (unused if running behind reflector) 16 + #[arg(long)] 17 + domain: Option<String>, 18 + } 2 19 3 20 #[tokio::main] 4 21 async fn main() { 5 22 tracing_subscriber::fmt::init(); 6 - println!("Hello, world!"); 7 - serve("mac.cinnebar-tet.ts.net").await 23 + log::info!("๐Ÿ‘– hi"); 24 + let args = Args::parse(); 25 + let domain = args.domain.unwrap_or("bad-example.com".into()); 26 + let db_path = args.db.unwrap_or("prefs.sqlite3".into()); 27 + if args.init_db { 28 + Storage::init(&db_path).unwrap(); 29 + log::info!("๐Ÿ‘– initialized db at {db_path:?}. bye") 30 + } else { 31 + let storage = Storage::connect(db_path).unwrap(); 32 + serve(&domain, storage).await 33 + } 8 34 } 9 -
+136 -79
pocket/src/server.rs
··· 1 + use crate::{Storage, TokenVerifier}; 1 2 use poem::{ 2 - endpoint::make_sync, 3 - Endpoint, 4 - Route, 5 - Server, 6 - EndpointExt, 7 - http::{Method, HeaderMap}, 3 + Endpoint, EndpointExt, Route, Server, 4 + endpoint::{StaticFileEndpoint, make_sync}, 5 + http::Method, 6 + listener::TcpListener, 8 7 middleware::{CatchPanic, Cors, Tracing}, 9 - listener::TcpListener, 10 8 }; 11 9 use poem_openapi::{ 12 - ContactObject, 13 - ExternalDocumentObject, 14 - OpenApi, 15 - OpenApiService, 16 - Tags, 17 - Object, 18 - ApiResponse, 10 + ApiResponse, ContactObject, ExternalDocumentObject, Object, OpenApi, OpenApiService, 11 + SecurityScheme, Tags, 12 + auth::Bearer, 13 + payload::{Json, PlainText}, 19 14 types::Example, 20 - auth::Bearer, 21 - payload::Json, 22 - SecurityScheme, 23 15 }; 24 - use crate::verify; 25 16 use serde::Serialize; 26 17 use serde_json::{Value, json}; 27 - 18 + use std::sync::{Arc, Mutex}; 28 19 29 20 #[derive(Debug, SecurityScheme)] 30 21 #[oai(ty = "bearer")] 31 - struct BlahAuth(Bearer); 32 - 22 + struct XrpcAuth(Bearer); 33 23 34 24 #[derive(Tags)] 35 25 enum ApiTags { 36 - /// Bluesky-compatible APIs. 37 - #[oai(rename = "app.bsky.* queries")] 38 - AppBsky, 26 + /// Custom pocket APIs 27 + #[oai(rename = "Pocket APIs")] 28 + Pocket, 39 29 } 40 30 41 31 #[derive(Object)] ··· 62 52 }) 63 53 } 64 54 65 - #[derive(Object)] 55 + #[derive(Debug, Object)] 66 56 #[oai(example = true)] 67 - struct GetBskyPrefsResponseObject { 57 + struct BskyPrefsObject { 68 58 /// at-uri for this record 69 59 preferences: Value, 70 60 } 71 - impl Example for GetBskyPrefsResponseObject { 61 + impl Example for BskyPrefsObject { 72 62 fn example() -> Self { 73 63 Self { 74 64 preferences: json!({ ··· 82 72 enum GetBskyPrefsResponse { 83 73 /// Record found 84 74 #[oai(status = 200)] 85 - Ok(Json<GetBskyPrefsResponseObject>), 75 + Ok(Json<BskyPrefsObject>), 76 + /// Bad request or no preferences to return 77 + #[oai(status = 400)] 78 + BadRequest(XrpcError), 79 + } 80 + 81 + #[derive(ApiResponse)] 82 + enum PutBskyPrefsResponse { 83 + /// Record found 84 + #[oai(status = 200)] 85 + Ok(PlainText<String>), 86 86 /// Bad request or no preferences to return 87 87 #[oai(status = 400)] 88 88 BadRequest(XrpcError), ··· 92 92 } 93 93 94 94 struct Xrpc { 95 - domain: String, 95 + verifier: TokenVerifier, 96 + storage: Arc<Mutex<Storage>>, 96 97 } 97 98 98 99 #[OpenApi] 99 100 impl Xrpc { 100 - /// app.bsky.actor.getPreferences 101 + /// com.bad-example.pocket.getPreferences 101 102 /// 102 - /// get stored bluesky prefs 103 + /// get stored preferencess 103 104 #[oai( 104 - path = "/app.bsky.actor.getPreferences", 105 + path = "/com.bad-example.pocket.getPreferences", 105 106 method = "get", 106 - tag = "ApiTags::AppBsky" 107 + tag = "ApiTags::Pocket" 107 108 )] 108 - async fn app_bsky_get_prefs( 109 - &self, 110 - BlahAuth(auth): BlahAuth, 111 - m: &HeaderMap, 112 - ) -> GetBskyPrefsResponse { 113 - log::warn!("hm: {m:?}"); 114 - match verify( 115 - &format!("did:web:{}#bsky_appview", self.domain), 116 - "app.bsky.actor.getPreferences", 117 - &auth.token, 118 - ).await { 119 - Ok(did) => log::info!("wooo! {did}"), 120 - Err(err) => return GetBskyPrefsResponse::BadRequest(xrpc_error("booo", err)), 109 + async fn pocket_get_prefs(&self, XrpcAuth(auth): XrpcAuth) -> GetBskyPrefsResponse { 110 + let (did, aud) = match self 111 + .verifier 112 + .verify("com.bad-example.pocket.getPreferences", &auth.token) 113 + .await 114 + { 115 + Ok(d) => d, 116 + Err(e) => return GetBskyPrefsResponse::BadRequest(xrpc_error("boooo", e.to_string())), 117 + }; 118 + log::info!("verified did: {did}/{aud}"); 119 + 120 + let storage = self.storage.clone(); 121 + 122 + let Ok(Ok(res)) = tokio::task::spawn_blocking(move || { 123 + storage 124 + .lock() 125 + .unwrap() 126 + .get(&did, &aud) 127 + .inspect_err(|e| log::error!("failed to get prefs: {e}")) 128 + }) 129 + .await 130 + else { 131 + return GetBskyPrefsResponse::BadRequest(xrpc_error("boooo", "failed to get from db")); 132 + }; 133 + 134 + let Some(serialized) = res else { 135 + return GetBskyPrefsResponse::BadRequest(xrpc_error( 136 + "NotFound", 137 + "could not find prefs for u", 138 + )); 139 + }; 140 + 141 + let preferences = match serde_json::from_str(&serialized) { 142 + Ok(v) => v, 143 + Err(e) => { 144 + log::error!("failed to deserialize prefs: {e}"); 145 + return GetBskyPrefsResponse::BadRequest(xrpc_error( 146 + "boooo", 147 + "failed to deserialize prefs", 148 + )); 149 + } 121 150 }; 122 - log::warn!("got bearer: {:?}", auth.token); 123 - GetBskyPrefsResponse::Ok(Json(GetBskyPrefsResponseObject::example())) 151 + 152 + GetBskyPrefsResponse::Ok(Json(BskyPrefsObject { preferences })) 124 153 } 125 154 126 - /// app.bsky.actor.putPreferences 155 + /// com.bad-example.pocket.putPreferences 127 156 /// 128 157 /// store bluesky prefs 129 158 #[oai( 130 - path = "/app.bsky.actor.putPreferences", 159 + path = "/com.bad-example.pocket.putPreferences", 131 160 method = "post", 132 - tag = "ApiTags::AppBsky" 161 + tag = "ApiTags::Pocket" 133 162 )] 134 - async fn app_bsky_put_prefs( 163 + async fn pocket_put_prefs( 135 164 &self, 136 - Json(prefs): Json<Value>, 137 - ) -> () { 165 + XrpcAuth(auth): XrpcAuth, 166 + Json(prefs): Json<BskyPrefsObject>, 167 + ) -> PutBskyPrefsResponse { 168 + let (did, aud) = match self 169 + .verifier 170 + .verify("com.bad-example.pocket.putPreferences", &auth.token) 171 + .await 172 + { 173 + Ok(d) => d, 174 + Err(e) => return PutBskyPrefsResponse::BadRequest(xrpc_error("boooo", e.to_string())), 175 + }; 176 + log::info!("verified did: {did}/{aud}"); 138 177 log::warn!("received prefs: {prefs:?}"); 139 - () 178 + 179 + let storage = self.storage.clone(); 180 + let serialized = prefs.preferences.to_string(); 181 + 182 + let Ok(Ok(())) = tokio::task::spawn_blocking(move || { 183 + storage 184 + .lock() 185 + .unwrap() 186 + .put(&did, &aud, &serialized) 187 + .inspect_err(|e| log::error!("failed to insert prefs: {e}")) 188 + }) 189 + .await 190 + else { 191 + return PutBskyPrefsResponse::BadRequest(xrpc_error("boooo", "failed to put to db")); 192 + }; 193 + 194 + PutBskyPrefsResponse::Ok(PlainText("saved.".to_string())) 140 195 } 141 196 } 142 197 ··· 150 205 #[derive(Debug, Clone, Serialize)] 151 206 struct AppViewDoc { 152 207 id: String, 153 - service: [AppViewService; 1], 208 + service: [AppViewService; 2], 154 209 } 155 210 /// Serve a did document for did:web for this to be an xrpc appview 156 211 fn get_did_doc(domain: &str) -> impl Endpoint + use<> { 157 212 let doc = poem::web::Json(AppViewDoc { 158 213 id: format!("did:web:{domain}"), 159 - service: [AppViewService { 160 - id: "#bsky_appview".to_string(), 161 - r#type: "PocketBlueskyPreferences".to_string(), 162 - service_endpoint: format!("https://{domain}"), 163 - }], 214 + service: [ 215 + AppViewService { 216 + id: "#pocket_prefs".to_string(), 217 + r#type: "PocketPreferences".to_string(), 218 + service_endpoint: format!("https://{domain}"), 219 + }, 220 + AppViewService { 221 + id: "#bsky_appview".to_string(), 222 + r#type: "BlueskyAppview".to_string(), 223 + service_endpoint: format!("https://{domain}"), 224 + }, 225 + ], 164 226 }); 165 227 make_sync(move |_| doc.clone()) 166 228 } 167 229 168 - pub async fn serve( 169 - domain: &str, 170 - ) -> () { 230 + pub async fn serve(domain: &str, storage: Storage) -> () { 231 + let verifier = TokenVerifier::default(); 171 232 let api_service = OpenApiService::new( 172 - Xrpc { domain: domain.to_string() }, 233 + Xrpc { 234 + verifier, 235 + storage: Arc::new(Mutex::new(storage)), 236 + }, 173 237 "Pocket", 174 238 env!("CARGO_PKG_VERSION"), 175 239 ) ··· 180 244 .name("@microcosm.blue") 181 245 .url("https://bsky.app/profile/microcosm.blue"), 182 246 ) 183 - // .description(include_str!("../api-description.md")) 184 - .external_document(ExternalDocumentObject::new( 185 - "https://microcosm.blue/pocket", 186 - )); 247 + .description(include_str!("../api-description.md")) 248 + .external_document(ExternalDocumentObject::new("https://microcosm.blue/pocket")); 187 249 188 250 let app = Route::new() 189 - .at("/.well-known/did.json", get_did_doc(&domain)) 251 + .nest("/openapi", api_service.spec_endpoint()) 190 252 .nest("/xrpc/", api_service) 191 - // .at("/", StaticFileEndpoint::new("./static/index.html")) 192 - // .nest("/openapi", api_service.spec_endpoint()) 253 + .at("/.well-known/did.json", get_did_doc(domain)) 254 + .at("/", StaticFileEndpoint::new("./static/index.html")) 193 255 .with( 194 256 Cors::new() 195 257 .allow_method(Method::GET) 196 - .allow_method(Method::POST) 258 + .allow_method(Method::POST), 197 259 ) 198 260 .with(CatchPanic::new()) 199 261 .with(Tracing); 200 262 201 263 let listener = TcpListener::bind("127.0.0.1:3000"); 202 - Server::new(listener) 203 - .name("pocket") 204 - .run(app) 205 - .await 206 - .unwrap(); 207 - 264 + Server::new(listener).name("pocket").run(app).await.unwrap(); 208 265 }
+50
pocket/src/storage.rs
··· 1 + use rusqlite::{Connection, OptionalExtension, Result}; 2 + use std::path::Path; 3 + 4 + pub struct Storage { 5 + con: Connection, 6 + } 7 + 8 + impl Storage { 9 + pub fn connect(path: impl AsRef<Path>) -> Result<Self> { 10 + let con = Connection::open(path)?; 11 + con.pragma_update(None, "journal_mode", "WAL")?; 12 + con.pragma_update(None, "synchronous", "NORMAL")?; 13 + con.pragma_update(None, "busy_timeout", "100")?; 14 + con.pragma_update(None, "foreign_keys", "ON")?; 15 + Ok(Self { con }) 16 + } 17 + pub fn init(path: impl AsRef<Path>) -> Result<Self> { 18 + let me = Self::connect(path)?; 19 + me.con.execute( 20 + r#" 21 + create table prefs ( 22 + actor text not null, 23 + aud text not null, 24 + pref text not null, 25 + primary key (actor, aud) 26 + ) strict"#, 27 + (), 28 + )?; 29 + Ok(me) 30 + } 31 + pub fn put(&self, actor: &str, aud: &str, pref: &str) -> Result<()> { 32 + self.con.execute( 33 + r#"insert into prefs (actor, aud, pref) 34 + values (?1, ?2, ?3) 35 + on conflict do update set pref = excluded.pref"#, 36 + [actor, aud, pref], 37 + )?; 38 + Ok(()) 39 + } 40 + pub fn get(&self, actor: &str, aud: &str) -> Result<Option<String>> { 41 + self.con 42 + .query_one( 43 + r#"select pref from prefs 44 + where actor = ?1 and aud = ?2"#, 45 + [actor, aud], 46 + |row| row.get(0), 47 + ) 48 + .optional() 49 + } 50 + }
+122 -51
pocket/src/token.rs
··· 1 - use jwt_compact::{Claims, UntrustedToken}; 2 1 use atrium_crypto::did::parse_multikey; 3 2 use atrium_crypto::verify::Verifier; 4 - use std::collections::HashMap; 3 + use jwt_compact::UntrustedToken; 5 4 use serde::Deserialize; 5 + use std::collections::HashMap; 6 + use std::time::Duration; 7 + use thiserror::Error; 6 8 7 9 #[derive(Debug, Deserialize)] 8 10 struct MiniDoc { 9 11 signing_key: String, 12 + did: String, 10 13 } 11 14 12 - pub async fn verify( 13 - expected_aud: &str, 14 - expected_lxm: &str, 15 - token: &str, 16 - ) -> Result<String, &'static str> { 17 - let untrusted = UntrustedToken::new(token).unwrap(); 15 + #[derive(Error, Debug)] 16 + pub enum VerifyError { 17 + #[error("The cross-service authorization token failed verification: {0}")] 18 + VerificationFailed(&'static str), 19 + #[error("Error trying to resolve the DID to a signing key, retry in a moment: {0}")] 20 + ResolutionFailed(&'static str), 21 + } 22 + 23 + pub struct TokenVerifier { 24 + client: reqwest::Client, 25 + } 26 + 27 + impl TokenVerifier { 28 + pub fn new() -> Self { 29 + let client = reqwest::Client::builder() 30 + .user_agent(format!( 31 + "microcosm pocket v{} (dev: @bad-example.com)", 32 + env!("CARGO_PKG_VERSION") 33 + )) 34 + .no_proxy() 35 + .timeout(Duration::from_secs(12)) // slingshot timeout is 10s 36 + .build() 37 + .unwrap(); 38 + Self { client } 39 + } 40 + 41 + pub async fn verify( 42 + &self, 43 + expected_lxm: &str, 44 + token: &str, 45 + ) -> Result<(String, String), VerifyError> { 46 + let untrusted = UntrustedToken::new(token).unwrap(); 47 + 48 + // danger! unfortunately we need to decode the DID from the jwt body before we have a public key to verify the jwt with 49 + let Ok(untrusted_claims) = 50 + untrusted.deserialize_claims_unchecked::<HashMap<String, String>>() 51 + else { 52 + return Err(VerifyError::VerificationFailed( 53 + "could not deserialize jtw claims", 54 + )); 55 + }; 18 56 19 - let claims: Claims<HashMap<String, String>> = untrusted.deserialize_claims_unchecked().unwrap(); 57 + // get the (untrusted!) claimed DID 58 + let Some(untrusted_did) = untrusted_claims.custom.get("iss") else { 59 + return Err(VerifyError::VerificationFailed( 60 + "jwt must include the user's did in `iss`", 61 + )); 62 + }; 20 63 21 - let Some(did) = claims.custom.get("iss") else { 22 - return Err("jwt must include the user's did in `iss`"); 23 - }; 64 + // bail if it's not even a user-ish did 65 + if !untrusted_did.starts_with("did:") { 66 + return Err(VerifyError::VerificationFailed("iss should be a did")); 67 + } 68 + if untrusted_did.contains("#") { 69 + return Err(VerifyError::VerificationFailed( 70 + "iss should be a user did without a service identifier", 71 + )); 72 + } 24 73 25 - if !did.starts_with("did:") { 26 - return Err("iss should be a did"); 27 - } 28 - if did.contains("#") { 29 - return Err("iss should be a user did without a service identifier"); 30 - } 74 + let endpoint = 75 + "https://slingshot.microcosm.blue/xrpc/com.bad-example.identity.resolveMiniDoc"; 76 + let doc: MiniDoc = self 77 + .client 78 + .get(format!("{endpoint}?identifier={untrusted_did}")) 79 + .send() 80 + .await 81 + .map_err(|_| VerifyError::ResolutionFailed("failed to fetch minidoc"))? 82 + .error_for_status() 83 + .map_err(|_| VerifyError::ResolutionFailed("non-ok response for minidoc"))? 84 + .json() 85 + .await 86 + .map_err(|_| VerifyError::ResolutionFailed("failed to parse json to minidoc"))?; 31 87 32 - println!("Claims: {claims:#?}"); 33 - println!("did: {did:#?}"); 88 + // sanity check before we go ahead with this signing key 89 + if doc.did != *untrusted_did { 90 + return Err(VerifyError::VerificationFailed( 91 + "wtf, resolveMiniDoc returned a doc for a different DID, slingshot bug", 92 + )); 93 + } 34 94 35 - let endpoint = "https://slingshot.microcosm.blue/xrpc/com.bad-example.identity.resolveMiniDoc"; 36 - let doc: MiniDoc = reqwest::get(format!("{endpoint}?identifier={did}")) 37 - .await 38 - .unwrap() 39 - .error_for_status() 40 - .unwrap() 41 - .json() 42 - .await 43 - .unwrap(); 95 + let Ok((alg, public_key)) = parse_multikey(&doc.signing_key) else { 96 + return Err(VerifyError::VerificationFailed( 97 + "could not parse signing key form minidoc", 98 + )); 99 + }; 44 100 45 - log::info!("got minidoc response: {doc:?}"); 101 + // i _guess_ we've successfully bootstrapped the verification of the jwt unless this fails 102 + if let Err(e) = Verifier::default().verify( 103 + alg, 104 + &public_key, 105 + &untrusted.signed_data, 106 + untrusted.signature_bytes(), 107 + ) { 108 + log::warn!("jwt verification failed: {e}"); 109 + return Err(VerifyError::VerificationFailed( 110 + "jwt signature verification failed", 111 + )); 112 + } 46 113 47 - let (alg, public_key) = parse_multikey(&doc.signing_key).unwrap(); 48 - log::info!("parsed key: {public_key:?}"); 114 + // past this point we're should have established trust. crossing ts and dotting is. 115 + let did = &untrusted_did; 116 + let claims = &untrusted_claims; 49 117 50 - Verifier::default().verify( 51 - alg, 52 - &public_key, 53 - &untrusted.signed_data, 54 - untrusted.signature_bytes(), 55 - ).unwrap(); 56 - // if this passes, then our claims were trustworthy after all(??) 118 + let Some(aud) = claims.custom.get("aud") else { 119 + return Err(VerifyError::VerificationFailed("missing aud")); 120 + }; 121 + let Some(mut aud) = aud.strip_prefix("did:web:") else { 122 + return Err(VerifyError::VerificationFailed("expected a did:web aud")); 123 + }; 124 + if let Some((aud_without_hash, _)) = aud.split_once("#") { 125 + log::warn!("aud claim is missing service id fragment: {aud:?}"); 126 + aud = aud_without_hash; 127 + } 128 + let Some(lxm) = claims.custom.get("lxm") else { 129 + return Err(VerifyError::VerificationFailed("missing lxm")); 130 + }; 131 + if lxm != expected_lxm { 132 + return Err(VerifyError::VerificationFailed("wrong lxm")); 133 + } 57 134 58 - let Some(aud) = claims.custom.get("aud") else { 59 - return Err("missing aud"); 60 - }; 61 - if aud != expected_aud { 62 - return Err("wrong aud"); 135 + Ok((did.to_string(), aud.to_string())) 63 136 } 64 - let Some(lxm) = claims.custom.get("lxm") else { 65 - return Err("missing lxm"); 66 - }; 67 - if lxm != expected_lxm { 68 - return Err("wrong lxm"); 137 + } 138 + 139 + impl Default for TokenVerifier { 140 + fn default() -> Self { 141 + Self::new() 69 142 } 70 - 71 - Ok(did.to_string()) 72 143 }
+67
pocket/static/index.html
··· 1 + <!doctype html> 2 + <html lang="en"> 3 + <head> 4 + <meta charset="utf-8" /> 5 + <title>Pocket: atproto user preference storage</title> 6 + <meta name="viewport" content="width=device-width, initial-scale=1" /> 7 + <meta name="description" content="API Documentation for Pocket, a simple user-preference storage system for atproto" /> 8 + <style> 9 + :root { 10 + --scalar-small: 13px; 11 + } 12 + .scalar-app .markdown .markdown-alert { 13 + font-size: var(--scalar-small); 14 + } 15 + .sidebar-heading-link-title { 16 + line-height: 1.2; 17 + } 18 + .custom-header { 19 + height: 42px; 20 + background-color: #221828; 21 + box-shadow: inset 0 -1px 0 var(--scalar-border-color); 22 + color: var(--scalar-color-1); 23 + font-size: var(--scalar-font-size-3); 24 + font-family: 'Iowan Old Style', 'Palatino Linotype', 'URW Palladio L', P052, serif; 25 + padding: 0 18px; 26 + justify-content: space-between; 27 + } 28 + .custom-header, 29 + .custom-header nav { 30 + display: flex; 31 + align-items: center; 32 + gap: 18px; 33 + } 34 + .custom-header a:hover { 35 + color: var(--scalar-color-2); 36 + } 37 + 38 + .light-mode .custom-header { 39 + background-color: thistle; 40 + } 41 + </style> 42 + </head> 43 + <body> 44 + <header class="custom-header scalar-app"> 45 + <p> 46 + TODO: thing 47 + </p> 48 + <nav> 49 + <b>a <a href="https://microcosm.blue">microcosm</a> project</b> 50 + <a href="https://bsky.app/profile/microcosm.blue">@microcosm.blue</a> 51 + <a href="https://github.com/at-microcosm">github</a> 52 + </nav> 53 + </header> 54 + 55 + <script id="api-reference" type="application/json" data-url="/openapi"></script> 56 + 57 + <script> 58 + var configuration = { 59 + theme: 'purple', 60 + hideModels: true, 61 + } 62 + document.getElementById('api-reference').dataset.configuration = JSON.stringify(configuration) 63 + </script> 64 + 65 + <script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"></script> 66 + </body> 67 + </html>
+2
quasar/src/lib.rs
··· 1 1 mod storage; 2 + 3 + pub use storage::Storage;
+1 -1
quasar/src/storage.rs
··· 1 1 2 - trait Storage { 2 + pub trait Storage { 3 3 4 4 }
+12
reflector/Cargo.toml
··· 1 + [package] 2 + name = "reflector" 3 + version = "0.1.0" 4 + edition = "2024" 5 + 6 + [dependencies] 7 + clap = { version = "4.5.47", features = ["derive"] } 8 + log = "0.4.28" 9 + poem = "3.1.12" 10 + serde = { version = "1.0.219", features = ["derive"] } 11 + tokio = "1.47.1" 12 + tracing-subscriber = { version = "0.3.20", features = ["env-filter"] }
+9
reflector/readme.md
··· 1 + # reflector 2 + 3 + a tiny did:web service server that maps subdomains to a single service endpoint 4 + 5 + receiving requests from multiple subdomains is left as a problem for the reverse proxy to solve, since acme wildcard certificates (ie. letsencrypt) require the most complicated and involved challenge type (DNS). 6 + 7 + caddy [has good support for](https://caddyserver.com/docs/caddyfile/patterns#wildcard-certificates) configuring the wildcard DNS challenge with various DNS providers, and also supports [on-demand](https://caddyserver.com/docs/automatic-https#using-on-demand-tls) provisioning via the simpler methods. 8 + 9 + if you only need a small fixed number of subdomains, you can also use certbot or otherwise individually configure them in your reverse proxy.
+112
reflector/src/main.rs
··· 1 + use clap::Parser; 2 + use poem::{ 3 + EndpointExt, Response, Route, Server, get, handler, 4 + http::StatusCode, 5 + listener::TcpListener, 6 + middleware::{AddData, Tracing}, 7 + web::{Data, Json, Query, TypedHeader, headers::Host}, 8 + }; 9 + use serde::{Deserialize, Serialize}; 10 + 11 + #[handler] 12 + fn hello() -> String { 13 + "ษนoส‡ษ”วส…โ…Žวษน".to_string() 14 + } 15 + 16 + #[derive(Debug, Serialize)] 17 + struct DidDoc { 18 + id: String, 19 + service: [DidService; 1], 20 + } 21 + 22 + #[derive(Debug, Clone, Serialize)] 23 + #[serde(rename_all = "camelCase")] 24 + struct DidService { 25 + id: String, 26 + r#type: String, 27 + service_endpoint: String, 28 + } 29 + 30 + #[handler] 31 + fn did_doc(TypedHeader(host): TypedHeader<Host>, service: Data<&DidService>) -> Json<DidDoc> { 32 + Json(DidDoc { 33 + id: format!("did:web:{}", host.hostname()), 34 + service: [service.clone()], 35 + }) 36 + } 37 + 38 + #[derive(Deserialize)] 39 + struct AskQuery { 40 + domain: String, 41 + } 42 + #[handler] 43 + fn ask_caddy( 44 + Data(parent): Data<&Option<String>>, 45 + Query(AskQuery { domain }): Query<AskQuery>, 46 + ) -> Response { 47 + if let Some(parent) = parent 48 + && let Some(prefix) = domain.strip_suffix(&format!(".{parent}")) 49 + && !prefix.contains('.') 50 + { 51 + // no sub-sub-domains allowed 52 + return Response::builder().body("ok"); 53 + }; 54 + Response::builder() 55 + .status(StatusCode::FORBIDDEN) 56 + .body("nope") 57 + } 58 + 59 + /// Slingshot record edge cache 60 + #[derive(Parser, Debug, Clone)] 61 + #[command(version, about, long_about = None)] 62 + struct Args { 63 + /// The DID document service ID to serve 64 + /// 65 + /// must start with a '#', like `#bsky_appview' 66 + #[arg(long)] 67 + id: String, 68 + /// Service type 69 + /// 70 + /// Not sure exactly what its requirements are. 'BlueskyAppview' for example 71 + #[arg(long)] 72 + r#type: String, 73 + /// The HTTPS endpoint for the service 74 + #[arg(long)] 75 + service_endpoint: String, 76 + /// The parent domain; requests should come from subdomains of this 77 + #[arg(long)] 78 + domain: Option<String>, 79 + } 80 + 81 + impl From<Args> for DidService { 82 + fn from(a: Args) -> Self { 83 + Self { 84 + id: a.id, 85 + r#type: a.r#type, 86 + service_endpoint: a.service_endpoint, 87 + } 88 + } 89 + } 90 + 91 + #[tokio::main(flavor = "current_thread")] 92 + async fn main() { 93 + tracing_subscriber::fmt::init(); 94 + log::info!("ษนoส‡ษ”วส…โ…Žวษน"); 95 + 96 + let args = Args::parse(); 97 + let domain = args.domain.clone(); 98 + let service: DidService = args.into(); 99 + 100 + Server::new(TcpListener::bind("0.0.0.0:3001")) 101 + .run( 102 + Route::new() 103 + .at("/", get(hello)) 104 + .at("/.well-known/did.json", get(did_doc)) 105 + .at("/ask", get(ask_caddy)) 106 + .with(AddData::new(service)) 107 + .with(AddData::new(domain)) 108 + .with(Tracing), 109 + ) 110 + .await 111 + .unwrap() 112 + }
+11 -11
slingshot/src/server.rs
··· 437 437 Ok(did) => did, 438 438 Err(_) => { 439 439 let Ok(alleged_handle) = Handle::new(identifier) else { 440 - return invalid("identifier was not a valid DID or handle"); 440 + return invalid("Identifier was not a valid DID or handle"); 441 441 }; 442 442 443 443 match self.identity.handle_to_did(alleged_handle.clone()).await { ··· 453 453 Err(e) => { 454 454 log::debug!("failed to resolve handle: {e}"); 455 455 // TODO: ServerError not BadRequest 456 - return invalid("errored while trying to resolve handle to DID"); 456 + return invalid("Errored while trying to resolve handle to DID"); 457 457 } 458 458 } 459 459 } 460 460 }; 461 461 let Ok(partial_doc) = self.identity.did_to_partial_mini_doc(&did).await else { 462 - return invalid("failed to get DID doc"); 462 + return invalid("Failed to get DID doc"); 463 463 }; 464 464 let Some(partial_doc) = partial_doc else { 465 - return invalid("failed to find DID doc"); 465 + return invalid("Failed to find DID doc"); 466 466 }; 467 467 468 468 // ok so here's where we're at: ··· 483 483 .handle_to_did(partial_doc.unverified_handle.clone()) 484 484 .await 485 485 else { 486 - return invalid("failed to get did doc's handle"); 486 + return invalid("Failed to get DID doc's handle"); 487 487 }; 488 488 let Some(handle_did) = handle_did else { 489 - return invalid("failed to resolve did doc's handle"); 489 + return invalid("Failed to resolve DID doc's handle"); 490 490 }; 491 491 if handle_did == did { 492 492 partial_doc.unverified_handle.to_string() ··· 516 516 let Ok(handle) = Handle::new(repo) else { 517 517 return GetRecordResponse::BadRequest(xrpc_error( 518 518 "InvalidRequest", 519 - "repo was not a valid DID or handle", 519 + "Repo was not a valid DID or handle", 520 520 )); 521 521 }; 522 522 match self.identity.handle_to_did(handle).await { ··· 534 534 log::debug!("handle resolution failed: {e}"); 535 535 return GetRecordResponse::ServerError(xrpc_error( 536 536 "ResolutionFailed", 537 - "errored while trying to resolve handle to DID", 537 + "Errored while trying to resolve handle to DID", 538 538 )); 539 539 } 540 540 } ··· 544 544 let Ok(collection) = Nsid::new(collection) else { 545 545 return GetRecordResponse::BadRequest(xrpc_error( 546 546 "InvalidRequest", 547 - "invalid NSID for collection", 547 + "Invalid NSID for collection", 548 548 )); 549 549 }; 550 550 551 551 let Ok(rkey) = RecordKey::new(rkey) else { 552 - return GetRecordResponse::BadRequest(xrpc_error("InvalidRequest", "invalid rkey")); 552 + return GetRecordResponse::BadRequest(xrpc_error("InvalidRequest", "Invalid rkey")); 553 553 }; 554 554 555 555 let cid: Option<Cid> = if let Some(cid) = cid { 556 556 let Ok(cid) = Cid::from_str(&cid) else { 557 - return GetRecordResponse::BadRequest(xrpc_error("InvalidRequest", "invalid CID")); 557 + return GetRecordResponse::BadRequest(xrpc_error("InvalidRequest", "Invalid CID")); 558 558 }; 559 559 Some(cid) 560 560 } else {
+2
spacedust/src/error.rs
··· 30 30 TooManySourcesWanted, 31 31 #[error("more wantedSubjectDids were requested than allowed (max 10,000)")] 32 32 TooManyDidsWanted, 33 + #[error("more wantedSubjectPrefixes were requested than allowed (max 100)")] 34 + TooManySubjectPrefixesWanted, 33 35 #[error("more wantedSubjects were requested than allowed (max 50,000)")] 34 36 TooManySubjectsWanted, 35 37 }
+11 -2
spacedust/src/server.rs
··· 227 227 #[serde(default)] 228 228 pub wanted_subjects: HashSet<String>, 229 229 #[serde(default)] 230 + pub wanted_subject_prefixes: HashSet<String>, 231 + #[serde(default)] 230 232 pub wanted_subject_dids: HashSet<String>, 231 233 #[serde(default)] 232 234 pub wanted_sources: HashSet<String>, ··· 241 243 /// 242 244 /// The at-uri must be url-encoded 243 245 /// 244 - /// Pass this parameter multiple times to specify multiple collections, like 246 + /// Pass this parameter multiple times to specify multiple subjects, like 245 247 /// `wantedSubjects=[...]&wantedSubjects=[...]` 246 248 pub wanted_subjects: String, 249 + /// One or more at-uri, URI, or DID prefixes to receive links about 250 + /// 251 + /// The uri must be url-encoded 252 + /// 253 + /// Pass this parameter multiple times to specify multiple prefixes, like 254 + /// `wantedSubjectPrefixes=[...]&wantedSubjectPrefixes=[...]` 255 + pub wanted_subject_prefixes: String, 247 256 /// One or more DIDs to receive links about 248 257 /// 249 - /// Pass this parameter multiple times to specify multiple collections 258 + /// Pass this parameter multiple times to specify multiple subjects 250 259 pub wanted_subject_dids: String, 251 260 /// One or more link sources to receive links about 252 261 ///
+15 -6
spacedust/src/subscriber.rs
··· 42 42 loop { 43 43 tokio::select! { 44 44 l = receiver.recv() => match l { 45 - Ok(link) => if self.filter(&link.properties) { 46 - if let Err(e) = ws_sender.send(link.message.clone()).await { 47 - log::warn!("failed to send link, dropping subscriber: {e:?}"); 48 - break; 49 - } 45 + Ok(link) => if self.filter(&link.properties) 46 + && let Err(e) = ws_sender.send(link.message.clone()).await 47 + { 48 + log::warn!("failed to send link, dropping subscriber: {e:?}"); 49 + break; 50 50 }, 51 51 Err(RecvError::Closed) => self.shutdown.cancel(), 52 52 Err(RecvError::Lagged(n)) => { ··· 124 124 let query = &self.query; 125 125 126 126 // subject + subject DIDs are logical OR 127 - if !(query.wanted_subjects.is_empty() && query.wanted_subject_dids.is_empty() 127 + if !(query.wanted_subjects.is_empty() 128 + && query.wanted_subject_prefixes.is_empty() 129 + && query.wanted_subject_dids.is_empty() 128 130 || query.wanted_subjects.contains(&properties.subject) 131 + || query 132 + .wanted_subject_prefixes 133 + .iter() 134 + .any(|p| properties.subject.starts_with(p)) 129 135 || properties 130 136 .subject_did 131 137 .as_ref() ··· 154 160 } 155 161 if opts.wanted_subject_dids.len() > 10_000 { 156 162 return Err(SubscriberUpdateError::TooManyDidsWanted); 163 + } 164 + if opts.wanted_subject_prefixes.len() > 100 { 165 + return Err(SubscriberUpdateError::TooManySubjectPrefixesWanted); 157 166 } 158 167 if opts.wanted_subjects.len() > 50_000 { 159 168 return Err(SubscriberUpdateError::TooManySubjectsWanted);
+1 -1
ufos/Cargo.toml
··· 13 13 clap = { version = "4.5.31", features = ["derive"] } 14 14 dropshot = "0.16.0" 15 15 env_logger = "0.11.7" 16 - fjall = { git = "https://github.com/fjall-rs/fjall.git", features = ["lz4"] } 16 + fjall = { git = "https://github.com/fjall-rs/fjall.git", rev = "fb229572bb7d1d6966a596994dc1708e47ec57d8", features = ["lz4"] } 17 17 getrandom = "0.3.3" 18 18 http = "1.3.1" 19 19 jetstream = { path = "../jetstream", features = ["metrics"] }
+4 -4
who-am-i/src/server.rs
··· 268 268 Some(parent_host), 269 269 ); 270 270 } 271 - if let Some(ref app) = params.app { 272 - if !allowed_hosts.contains(app) { 273 - return err("Login is not allowed for this app", false, Some(app)); 274 - } 271 + if let Some(ref app) = params.app 272 + && !allowed_hosts.contains(app) 273 + { 274 + return err("Login is not allowed for this app", false, Some(app)); 275 275 } 276 276 let parent_origin = url.origin().ascii_serialization(); 277 277 if parent_origin == "null" {