JavaScript is disabled, refresh for a better experience. ambee/giterated

ambee/giterated

Git repository hosting, collaboration, and discovery for the Fediverse.

Huge refactor to prep for moving the daemon over to the plugin architecture

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨5df753c

Showing ⁨⁨37⁩ changed files⁩ with ⁨⁨1781⁩ insertions⁩ and ⁨⁨670⁩ deletions⁩

Cargo.lock

View file
@@ -54,25 +54,15 @@ dependencies = [
54 54
55 55 [[package]]
56 56 name = "ahash"
57 version = "0.7.6"
57 version = "0.8.6"
58 58 source = "registry+https://github.com/rust-lang/crates.io-index"
59 checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47"
60 dependencies = [
61 "getrandom",
62 "once_cell",
63 "version_check",
64 ]
65
66 [[package]]
67 name = "ahash"
68 version = "0.8.3"
69 source = "registry+https://github.com/rust-lang/crates.io-index"
70 checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f"
59 checksum = "91429305e9f0a25f6205c5b8e0d2db09e0708a7a6df0f42212bb56c32c8ac97a"
71 60 dependencies = [
72 61 "cfg-if",
73 62 "getrandom",
74 63 "once_cell",
75 64 "version_check",
65 "zerocopy",
76 66 ]
77 67
78 68 [[package]]
@@ -125,9 +115,9 @@ dependencies = [
125 115
126 116 [[package]]
127 117 name = "async-trait"
128 version = "0.1.73"
118 version = "0.1.74"
129 119 source = "registry+https://github.com/rust-lang/crates.io-index"
130 checksum = "bc00ceb34980c03614e35a3a4e218276a0a824e911d07651cd0d858a51e8c0f0"
120 checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9"
131 121 dependencies = [
132 122 "proc-macro2",
133 123 "quote",
@@ -172,9 +162,9 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
172 162
173 163 [[package]]
174 164 name = "base64"
175 version = "0.21.4"
165 version = "0.21.5"
176 166 source = "registry+https://github.com/rust-lang/crates.io-index"
177 checksum = "9ba43ea6f343b788c8764558649e08df62f86c6ef251fdaeb1ffd010a9ae50a2"
167 checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9"
178 168
179 169 [[package]]
180 170 name = "base64ct"
@@ -199,9 +189,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
199 189
200 190 [[package]]
201 191 name = "bitflags"
202 version = "2.4.0"
192 version = "2.4.1"
203 193 source = "registry+https://github.com/rust-lang/crates.io-index"
204 checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635"
194 checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07"
205 195 dependencies = [
206 196 "serde",
207 197 ]
@@ -232,9 +222,9 @@ checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec"
232 222
233 223 [[package]]
234 224 name = "bytecount"
235 version = "0.6.4"
225 version = "0.6.7"
236 226 source = "registry+https://github.com/rust-lang/crates.io-index"
237 checksum = "ad152d03a2c813c80bb94fedbf3a3f02b28f793e39e7c214c8a0bcc196343de7"
227 checksum = "e1e5f035d16fc623ae5f74981db80a439803888314e3a555fd6f04acd51a3205"
238 228
239 229 [[package]]
240 230 name = "byteorder"
@@ -344,9 +334,9 @@ checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa"
344 334
345 335 [[package]]
346 336 name = "cpufeatures"
347 version = "0.2.9"
337 version = "0.2.11"
348 338 source = "registry+https://github.com/rust-lang/crates.io-index"
349 checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1"
339 checksum = "ce420fe07aecd3e67c5f910618fe65e94158f6dcc0adf44e00d69ce2bdfe0fd0"
350 340 dependencies = [
351 341 "libc",
352 342 ]
@@ -362,9 +352,9 @@ dependencies = [
362 352
363 353 [[package]]
364 354 name = "crc-catalog"
365 version = "2.2.0"
355 version = "2.4.0"
366 356 source = "registry+https://github.com/rust-lang/crates.io-index"
367 checksum = "9cace84e55f07e7301bae1c519df89cdad8cc3cd868413d3fdbdeca9ff3db484"
357 checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5"
368 358
369 359 [[package]]
370 360 name = "crossbeam-channel"
@@ -466,9 +456,12 @@ dependencies = [
466 456
467 457 [[package]]
468 458 name = "deranged"
469 version = "0.3.8"
459 version = "0.3.9"
470 460 source = "registry+https://github.com/rust-lang/crates.io-index"
471 checksum = "f2696e8a945f658fd14dc3b87242e6b80cd0f36ff04ea560fa39082368847946"
461 checksum = "0f32d04922c60427da6f9fef14d042d9edddef64cb9d4ce0d64d0685fbeb1fd3"
462 dependencies = [
463 "powerfmt",
464 ]
472 465
473 466 [[package]]
474 467 name = "digest"
@@ -640,9 +633,9 @@ dependencies = [
640 633
641 634 [[package]]
642 635 name = "futures-channel"
643 version = "0.3.28"
636 version = "0.3.29"
644 637 source = "registry+https://github.com/rust-lang/crates.io-index"
645 checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2"
638 checksum = "ff4dd66668b557604244583e3e1e1eada8c5c2e96a6d0d6653ede395b78bbacb"
646 639 dependencies = [
647 640 "futures-core",
648 641 "futures-sink",
@@ -650,15 +643,15 @@ dependencies = [
650 643
651 644 [[package]]
652 645 name = "futures-core"
653 version = "0.3.28"
646 version = "0.3.29"
654 647 source = "registry+https://github.com/rust-lang/crates.io-index"
655 checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c"
648 checksum = "eb1d22c66e66d9d72e1758f0bd7d4fd0bee04cad842ee34587d68c07e45d088c"
656 649
657 650 [[package]]
658 651 name = "futures-executor"
659 version = "0.3.28"
652 version = "0.3.29"
660 653 source = "registry+https://github.com/rust-lang/crates.io-index"
661 checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0"
654 checksum = "0f4fb8693db0cf099eadcca0efe2a5a22e4550f98ed16aba6c48700da29597bc"
662 655 dependencies = [
663 656 "futures-core",
664 657 "futures-task",
@@ -678,15 +671,15 @@ dependencies = [
678 671
679 672 [[package]]
680 673 name = "futures-io"
681 version = "0.3.28"
674 version = "0.3.29"
682 675 source = "registry+https://github.com/rust-lang/crates.io-index"
683 checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964"
676 checksum = "8bf34a163b5c4c52d0478a4d757da8fb65cabef42ba90515efee0f6f9fa45aaa"
684 677
685 678 [[package]]
686 679 name = "futures-macro"
687 version = "0.3.28"
680 version = "0.3.29"
688 681 source = "registry+https://github.com/rust-lang/crates.io-index"
689 checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72"
682 checksum = "53b153fd91e4b0147f4aced87be237c98248656bb01050b96bf3ee89220a8ddb"
690 683 dependencies = [
691 684 "proc-macro2",
692 685 "quote",
@@ -695,21 +688,21 @@ dependencies = [
695 688
696 689 [[package]]
697 690 name = "futures-sink"
698 version = "0.3.28"
691 version = "0.3.29"
699 692 source = "registry+https://github.com/rust-lang/crates.io-index"
700 checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e"
693 checksum = "e36d3378ee38c2a36ad710c5d30c2911d752cb941c00c72dbabfb786a7970817"
701 694
702 695 [[package]]
703 696 name = "futures-task"
704 version = "0.3.28"
697 version = "0.3.29"
705 698 source = "registry+https://github.com/rust-lang/crates.io-index"
706 checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65"
699 checksum = "efd193069b0ddadc69c46389b740bbccdd97203899b48d09c5f7969591d6bae2"
707 700
708 701 [[package]]
709 702 name = "futures-util"
710 version = "0.3.28"
703 version = "0.3.29"
711 704 source = "registry+https://github.com/rust-lang/crates.io-index"
712 checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533"
705 checksum = "a19526d624e703a3179b3d322efec918b6246ea0fa51d41124525f00f1cc8104"
713 706 dependencies = [
714 707 "futures-core",
715 708 "futures-io",
@@ -775,6 +768,24 @@ dependencies = [
775 768 ]
776 769
777 770 [[package]]
771 name = "giterated-backend"
772 version = "0.1.0"
773 dependencies = [
774 "anyhow",
775 "giterated-models",
776 "giterated-plugin",
777 "giterated-plugin-sys",
778 "serde",
779 "serde_json",
780 "sqlx",
781 "thiserror",
782 "tokio",
783 "toml",
784 "tracing",
785 "tracing-subscriber",
786 ]
787
788 [[package]]
778 789 name = "giterated-cache"
779 790 version = "0.1.0"
780 791 dependencies = [
@@ -800,16 +811,14 @@ dependencies = [
800 811 "anyhow",
801 812 "argon2",
802 813 "async-trait",
803 "base64 0.21.4",
814 "base64 0.21.5",
804 815 "bincode",
805 816 "chrono",
806 817 "deadpool",
807 818 "futures-util",
808 819 "git2",
809 "giterated-cache",
810 820 "giterated-models",
811 "giterated-protocol",
812 "giterated-stack",
821 "giterated-plugin",
813 822 "jsonwebtoken",
814 823 "log",
815 824 "rand",
@@ -838,9 +847,13 @@ dependencies = [
838 847 "giterated-plugin",
839 848 "giterated-plugin-sys",
840 849 "serde",
850 "serde_json",
841 851 "sqlx",
842 852 "thiserror",
843 853 "tokio",
854 "toml",
855 "tracing",
856 "tracing-subscriber",
844 857 ]
845 858
846 859 [[package]]
@@ -849,7 +862,7 @@ version = "0.1.0"
849 862 dependencies = [
850 863 "anyhow",
851 864 "async-trait",
852 "base64 0.21.4",
865 "base64 0.21.5",
853 866 "bincode",
854 867 "chrono",
855 868 "git2",
@@ -893,10 +906,13 @@ dependencies = [
893 906 name = "giterated-protocol"
894 907 version = "0.1.0"
895 908 dependencies = [
909 "anyhow",
896 910 "async-trait",
897 911 "bincode",
898 912 "futures-util",
899 "giterated-stack",
913 "giterated-models",
914 "giterated-plugin",
915 "giterated-plugin-sys",
900 916 "rand",
901 917 "rsa",
902 918 "serde",
@@ -904,7 +920,9 @@ dependencies = [
904 920 "thiserror",
905 921 "tokio",
906 922 "tokio-tungstenite",
923 "toml",
907 924 "tracing",
925 "tracing-subscriber",
908 926 ]
909 927
910 928 [[package]]
@@ -953,17 +971,14 @@ name = "hashbrown"
953 971 version = "0.12.3"
954 972 source = "registry+https://github.com/rust-lang/crates.io-index"
955 973 checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
956 dependencies = [
957 "ahash 0.7.6",
958 ]
959 974
960 975 [[package]]
961 976 name = "hashbrown"
962 version = "0.14.1"
977 version = "0.14.2"
963 978 source = "registry+https://github.com/rust-lang/crates.io-index"
964 checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12"
979 checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156"
965 980 dependencies = [
966 "ahash 0.8.3",
981 "ahash",
967 982 "allocator-api2",
968 983 ]
969 984
@@ -973,7 +988,7 @@ version = "0.8.4"
973 988 source = "registry+https://github.com/rust-lang/crates.io-index"
974 989 checksum = "e8094feaf31ff591f651a2664fb9cfd92bba7a60ce3197265e9482ebe753c8f7"
975 990 dependencies = [
976 "hashbrown 0.14.1",
991 "hashbrown 0.14.2",
977 992 ]
978 993
979 994 [[package]]
@@ -1075,7 +1090,7 @@ dependencies = [
1075 1090 "httpdate",
1076 1091 "itoa",
1077 1092 "pin-project-lite",
1078 "socket2 0.4.9",
1093 "socket2 0.4.10",
1079 1094 "tokio",
1080 1095 "tower-service",
1081 1096 "tracing",
@@ -1097,16 +1112,16 @@ dependencies = [
1097 1112
1098 1113 [[package]]
1099 1114 name = "iana-time-zone"
1100 version = "0.1.57"
1115 version = "0.1.58"
1101 1116 source = "registry+https://github.com/rust-lang/crates.io-index"
1102 checksum = "2fad5b825842d2b38bd206f3e81d6957625fd7f0a361e345c30e01a0ae2dd613"
1117 checksum = "8326b86b6cff230b97d0d312a6c40a60726df3332e721f72a1b035f451663b20"
1103 1118 dependencies = [
1104 1119 "android_system_properties",
1105 1120 "core-foundation-sys",
1106 1121 "iana-time-zone-haiku",
1107 1122 "js-sys",
1108 1123 "wasm-bindgen",
1109 "windows",
1124 "windows-core",
1110 1125 ]
1111 1126
1112 1127 [[package]]
@@ -1140,12 +1155,12 @@ dependencies = [
1140 1155
1141 1156 [[package]]
1142 1157 name = "indexmap"
1143 version = "2.0.2"
1158 version = "2.1.0"
1144 1159 source = "registry+https://github.com/rust-lang/crates.io-index"
1145 checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897"
1160 checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f"
1146 1161 dependencies = [
1147 1162 "equivalent",
1148 "hashbrown 0.14.1",
1163 "hashbrown 0.14.2",
1149 1164 ]
1150 1165
1151 1166 [[package]]
@@ -1159,9 +1174,9 @@ dependencies = [
1159 1174
1160 1175 [[package]]
1161 1176 name = "ipnet"
1162 version = "2.8.0"
1177 version = "2.9.0"
1163 1178 source = "registry+https://github.com/rust-lang/crates.io-index"
1164 checksum = "28b29a3cd74f0f4598934efe3aeba42bae0eb4680554128851ebbecb02af14e6"
1179 checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3"
1165 1180
1166 1181 [[package]]
1167 1182 name = "itertools"
@@ -1189,9 +1204,9 @@ dependencies = [
1189 1204
1190 1205 [[package]]
1191 1206 name = "js-sys"
1192 version = "0.3.64"
1207 version = "0.3.65"
1193 1208 source = "registry+https://github.com/rust-lang/crates.io-index"
1194 checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a"
1209 checksum = "54c0c35952f67de54bb584e9fd912b3023117cbafc0a77d8f3dee1fb5f572fe8"
1195 1210 dependencies = [
1196 1211 "wasm-bindgen",
1197 1212 ]
@@ -1202,7 +1217,7 @@ version = "8.3.0"
1202 1217 source = "registry+https://github.com/rust-lang/crates.io-index"
1203 1218 checksum = "6971da4d9c3aa03c3d8f3ff0f4155b534aad021292003895a469716b2a230378"
1204 1219 dependencies = [
1205 "base64 0.21.4",
1220 "base64 0.21.5",
1206 1221 "pem",
1207 1222 "ring",
1208 1223 "serde",
@@ -1221,9 +1236,9 @@ dependencies = [
1221 1236
1222 1237 [[package]]
1223 1238 name = "libc"
1224 version = "0.2.149"
1239 version = "0.2.150"
1225 1240 source = "registry+https://github.com/rust-lang/crates.io-index"
1226 checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b"
1241 checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c"
1227 1242
1228 1243 [[package]]
1229 1244 name = "libgit2-sys"
@@ -1290,9 +1305,9 @@ checksum = "da2479e8c062e40bf0066ffa0bc823de0a9368974af99c9f6df941d2c231e03f"
1290 1305
1291 1306 [[package]]
1292 1307 name = "lock_api"
1293 version = "0.4.10"
1308 version = "0.4.11"
1294 1309 source = "registry+https://github.com/rust-lang/crates.io-index"
1295 checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16"
1310 checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45"
1296 1311 dependencies = [
1297 1312 "autocfg",
1298 1313 "scopeguard",
@@ -1361,9 +1376,9 @@ dependencies = [
1361 1376
1362 1377 [[package]]
1363 1378 name = "mio"
1364 version = "0.8.8"
1379 version = "0.8.9"
1365 1380 source = "registry+https://github.com/rust-lang/crates.io-index"
1366 checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2"
1381 checksum = "3dce281c5e46beae905d4de1870d8b1509a9142b62eedf18b443b011ca8343d0"
1367 1382 dependencies = [
1368 1383 "libc",
1369 1384 "wasi",
@@ -1524,11 +1539,11 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
1524 1539
1525 1540 [[package]]
1526 1541 name = "openssl"
1527 version = "0.10.57"
1542 version = "0.10.59"
1528 1543 source = "registry+https://github.com/rust-lang/crates.io-index"
1529 checksum = "bac25ee399abb46215765b1cb35bc0212377e58a061560d8b29b024fd0430e7c"
1544 checksum = "7a257ad03cd8fb16ad4172fedf8094451e1af1c4b70097636ef2eac9a5f0cc33"
1530 1545 dependencies = [
1531 "bitflags 2.4.0",
1546 "bitflags 2.4.1",
1532 1547 "cfg-if",
1533 1548 "foreign-types",
1534 1549 "libc",
@@ -1556,9 +1571,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
1556 1571
1557 1572 [[package]]
1558 1573 name = "openssl-sys"
1559 version = "0.9.93"
1574 version = "0.9.95"
1560 1575 source = "registry+https://github.com/rust-lang/crates.io-index"
1561 checksum = "db4d56a4c0478783083cfafcc42493dd4a981d41669da64b4572a2a089b51b1d"
1576 checksum = "40a4130519a360279579c2053038317e40eff64d13fd3f004f9e1b72b8a6aaf9"
1562 1577 dependencies = [
1563 1578 "cc",
1564 1579 "libc",
@@ -1584,9 +1599,9 @@ dependencies = [
1584 1599
1585 1600 [[package]]
1586 1601 name = "parking_lot_core"
1587 version = "0.9.8"
1602 version = "0.9.9"
1588 1603 source = "registry+https://github.com/rust-lang/crates.io-index"
1589 checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447"
1604 checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e"
1590 1605 dependencies = [
1591 1606 "cfg-if",
1592 1607 "libc",
@@ -1688,6 +1703,12 @@ dependencies = [
1688 1703 ]
1689 1704
1690 1705 [[package]]
1706 name = "powerfmt"
1707 version = "0.2.0"
1708 source = "registry+https://github.com/rust-lang/crates.io-index"
1709 checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
1710
1711 [[package]]
1691 1712 name = "ppv-lite86"
1692 1713 version = "0.2.17"
1693 1714 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1779,9 +1800,9 @@ dependencies = [
1779 1800
1780 1801 [[package]]
1781 1802 name = "redox_syscall"
1782 version = "0.3.5"
1803 version = "0.4.1"
1783 1804 source = "registry+https://github.com/rust-lang/crates.io-index"
1784 checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29"
1805 checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa"
1785 1806 dependencies = [
1786 1807 "bitflags 1.3.2",
1787 1808 ]
@@ -1792,7 +1813,7 @@ version = "0.11.22"
1792 1813 source = "registry+https://github.com/rust-lang/crates.io-index"
1793 1814 checksum = "046cd98826c46c2ac8ddecae268eb5c2e58628688a5fc7a2643704a73faba95b"
1794 1815 dependencies = [
1795 "base64 0.21.4",
1816 "base64 0.21.5",
1796 1817 "bytes",
1797 1818 "encoding_rs",
1798 1819 "futures-core",
@@ -1847,16 +1868,14 @@ dependencies = [
1847 1868
1848 1869 [[package]]
1849 1870 name = "rsa"
1850 version = "0.9.2"
1871 version = "0.9.3"
1851 1872 source = "registry+https://github.com/rust-lang/crates.io-index"
1852 checksum = "6ab43bb47d23c1a631b4b680199a45255dce26fa9ab2fa902581f624ff13e6a8"
1873 checksum = "86ef35bf3e7fe15a53c4ab08a998e42271eab13eb0db224126bc7bc4c4bad96d"
1853 1874 dependencies = [
1854 "byteorder",
1855 1875 "const-oid",
1856 1876 "digest",
1857 1877 "num-bigint-dig",
1858 1878 "num-integer",
1859 "num-iter",
1860 1879 "num-traits",
1861 1880 "pkcs1",
1862 1881 "pkcs8",
@@ -1885,11 +1904,11 @@ dependencies = [
1885 1904
1886 1905 [[package]]
1887 1906 name = "rustix"
1888 version = "0.38.18"
1907 version = "0.38.21"
1889 1908 source = "registry+https://github.com/rust-lang/crates.io-index"
1890 checksum = "5a74ee2d7c2581cd139b42447d7d9389b889bdaad3a73f1ebb16f2a3237bb19c"
1909 checksum = "2b426b0506e5d50a7d8dafcf2e81471400deb602392c7dd110815afb4eaf02a3"
1891 1910 dependencies = [
1892 "bitflags 2.4.0",
1911 "bitflags 2.4.1",
1893 1912 "errno",
1894 1913 "libc",
1895 1914 "linux-raw-sys",
@@ -1970,18 +1989,18 @@ dependencies = [
1970 1989
1971 1990 [[package]]
1972 1991 name = "serde"
1973 version = "1.0.188"
1992 version = "1.0.190"
1974 1993 source = "registry+https://github.com/rust-lang/crates.io-index"
1975 checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e"
1994 checksum = "91d3c334ca1ee894a2c6f6ad698fe8c435b76d504b13d436f0685d648d6d96f7"
1976 1995 dependencies = [
1977 1996 "serde_derive",
1978 1997 ]
1979 1998
1980 1999 [[package]]
1981 2000 name = "serde_derive"
1982 version = "1.0.188"
2001 version = "1.0.190"
1983 2002 source = "registry+https://github.com/rust-lang/crates.io-index"
1984 checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2"
2003 checksum = "67c5609f394e5c2bd7fc51efda478004ea80ef42fee983d5c67a65e34f32c0e3"
1985 2004 dependencies = [
1986 2005 "proc-macro2",
1987 2006 "quote",
@@ -1990,9 +2009,9 @@ dependencies = [
1990 2009
1991 2010 [[package]]
1992 2011 name = "serde_json"
1993 version = "1.0.107"
2012 version = "1.0.108"
1994 2013 source = "registry+https://github.com/rust-lang/crates.io-index"
1995 checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65"
2014 checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b"
1996 2015 dependencies = [
1997 2016 "itoa",
1998 2017 "ryu",
@@ -2001,9 +2020,9 @@ dependencies = [
2001 2020
2002 2021 [[package]]
2003 2022 name = "serde_spanned"
2004 version = "0.6.3"
2023 version = "0.6.4"
2005 2024 source = "registry+https://github.com/rust-lang/crates.io-index"
2006 checksum = "96426c9936fd7a0124915f9185ea1d20aa9445cc9821142f0a73bc9207a2e186"
2025 checksum = "12022b835073e5b11e90a14f86838ceb1c8fb0325b72416845c487ac0fa95e80"
2007 2026 dependencies = [
2008 2027 "serde",
2009 2028 ]
@@ -2114,9 +2133,9 @@ checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a"
2114 2133
2115 2134 [[package]]
2116 2135 name = "socket2"
2117 version = "0.4.9"
2136 version = "0.4.10"
2118 2137 source = "registry+https://github.com/rust-lang/crates.io-index"
2119 checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662"
2138 checksum = "9f7916fc008ca5542385b89a3d3ce689953c143e9304a9bf8beec1de48994c0d"
2120 2139 dependencies = [
2121 2140 "libc",
2122 2141 "winapi",
@@ -2124,9 +2143,9 @@ dependencies = [
2124 2143
2125 2144 [[package]]
2126 2145 name = "socket2"
2127 version = "0.5.4"
2146 version = "0.5.5"
2128 2147 source = "registry+https://github.com/rust-lang/crates.io-index"
2129 checksum = "4031e820eb552adee9295814c0ced9e5cf38ddf1e8b7d566d6de8e2538ea989e"
2148 checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9"
2130 2149 dependencies = [
2131 2150 "libc",
2132 2151 "windows-sys",
@@ -2187,7 +2206,7 @@ version = "0.7.2"
2187 2206 source = "registry+https://github.com/rust-lang/crates.io-index"
2188 2207 checksum = "8d6753e460c998bbd4cd8c6f0ed9a64346fcca0723d6e75e52fdc351c5d2169d"
2189 2208 dependencies = [
2190 "ahash 0.8.3",
2209 "ahash",
2191 2210 "atoi",
2192 2211 "byteorder",
2193 2212 "bytes",
@@ -2204,7 +2223,7 @@ dependencies = [
2204 2223 "futures-util",
2205 2224 "hashlink",
2206 2225 "hex",
2207 "indexmap 2.0.2",
2226 "indexmap 2.1.0",
2208 2227 "log",
2209 2228 "memchr",
2210 2229 "native-tls",
@@ -2269,8 +2288,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
2269 2288 checksum = "864b869fdf56263f4c95c45483191ea0af340f9f3e3e7b4d57a61c7c87a970db"
2270 2289 dependencies = [
2271 2290 "atoi",
2272 "base64 0.21.4",
2273 "bitflags 2.4.0",
2291 "base64 0.21.5",
2292 "bitflags 2.4.1",
2274 2293 "byteorder",
2275 2294 "bytes",
2276 2295 "chrono",
@@ -2312,8 +2331,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
2312 2331 checksum = "eb7ae0e6a97fb3ba33b23ac2671a5ce6e3cabe003f451abd5a56e7951d975624"
2313 2332 dependencies = [
2314 2333 "atoi",
2315 "base64 0.21.4",
2316 "bitflags 2.4.0",
2334 "base64 0.21.5",
2335 "bitflags 2.4.1",
2317 2336 "byteorder",
2318 2337 "chrono",
2319 2338 "crc",
@@ -2436,9 +2455,9 @@ checksum = "7b2093cf4c8eb1e67749a6762251bc9cd836b6fc171623bd0a9d324d37af2417"
2436 2455
2437 2456 [[package]]
2438 2457 name = "tempfile"
2439 version = "3.8.0"
2458 version = "3.8.1"
2440 2459 source = "registry+https://github.com/rust-lang/crates.io-index"
2441 checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef"
2460 checksum = "7ef1adac450ad7f4b3c28589471ade84f25f731a7a0fe30d71dfa9f60fd808e5"
2442 2461 dependencies = [
2443 2462 "cfg-if",
2444 2463 "fastrand",
@@ -2449,18 +2468,18 @@ dependencies = [
2449 2468
2450 2469 [[package]]
2451 2470 name = "thiserror"
2452 version = "1.0.49"
2471 version = "1.0.50"
2453 2472 source = "registry+https://github.com/rust-lang/crates.io-index"
2454 checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4"
2473 checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2"
2455 2474 dependencies = [
2456 2475 "thiserror-impl",
2457 2476 ]
2458 2477
2459 2478 [[package]]
2460 2479 name = "thiserror-impl"
2461 version = "1.0.49"
2480 version = "1.0.50"
2462 2481 source = "registry+https://github.com/rust-lang/crates.io-index"
2463 checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc"
2482 checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8"
2464 2483 dependencies = [
2465 2484 "proc-macro2",
2466 2485 "quote",
@@ -2479,12 +2498,13 @@ dependencies = [
2479 2498
2480 2499 [[package]]
2481 2500 name = "time"
2482 version = "0.3.29"
2501 version = "0.3.30"
2483 2502 source = "registry+https://github.com/rust-lang/crates.io-index"
2484 checksum = "426f806f4089c493dcac0d24c29c01e2c38baf8e30f1b716ee37e83d200b18fe"
2503 checksum = "c4a34ab300f2dee6e562c10a046fc05e358b29f9bf92277f30c3c8d82275f6f5"
2485 2504 dependencies = [
2486 2505 "deranged",
2487 2506 "itoa",
2507 "powerfmt",
2488 2508 "serde",
2489 2509 "time-core",
2490 2510 "time-macros",
@@ -2534,7 +2554,7 @@ dependencies = [
2534 2554 "parking_lot",
2535 2555 "pin-project-lite",
2536 2556 "signal-hook-registry",
2537 "socket2 0.5.4",
2557 "socket2 0.5.5",
2538 2558 "tokio-macros",
2539 2559 "windows-sys",
2540 2560 ]
@@ -2585,15 +2605,15 @@ dependencies = [
2585 2605
2586 2606 [[package]]
2587 2607 name = "tokio-util"
2588 version = "0.7.9"
2608 version = "0.7.10"
2589 2609 source = "registry+https://github.com/rust-lang/crates.io-index"
2590 checksum = "1d68074620f57a0b21594d9735eb2e98ab38b17f80d3fcb189fca266771ca60d"
2610 checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15"
2591 2611 dependencies = [
2592 2612 "bytes",
2593 2613 "futures-core",
2594 2614 "futures-sink",
2595 2615 "futures-util",
2596 "hashbrown 0.12.3",
2616 "hashbrown 0.14.2",
2597 2617 "pin-project-lite",
2598 2618 "tokio",
2599 2619 "tracing",
@@ -2613,9 +2633,9 @@ dependencies = [
2613 2633
2614 2634 [[package]]
2615 2635 name = "toml_datetime"
2616 version = "0.6.3"
2636 version = "0.6.5"
2617 2637 source = "registry+https://github.com/rust-lang/crates.io-index"
2618 checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b"
2638 checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1"
2619 2639 dependencies = [
2620 2640 "serde",
2621 2641 ]
@@ -2626,7 +2646,7 @@ version = "0.19.15"
2626 2646 source = "registry+https://github.com/rust-lang/crates.io-index"
2627 2647 checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421"
2628 2648 dependencies = [
2629 "indexmap 2.0.2",
2649 "indexmap 2.1.0",
2630 2650 "serde",
2631 2651 "serde_spanned",
2632 2652 "toml_datetime",
@@ -2641,11 +2661,10 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52"
2641 2661
2642 2662 [[package]]
2643 2663 name = "tracing"
2644 version = "0.1.37"
2664 version = "0.1.40"
2645 2665 source = "registry+https://github.com/rust-lang/crates.io-index"
2646 checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8"
2666 checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef"
2647 2667 dependencies = [
2648 "cfg-if",
2649 2668 "log",
2650 2669 "pin-project-lite",
2651 2670 "tracing-attributes",
@@ -2654,9 +2673,9 @@ dependencies = [
2654 2673
2655 2674 [[package]]
2656 2675 name = "tracing-attributes"
2657 version = "0.1.26"
2676 version = "0.1.27"
2658 2677 source = "registry+https://github.com/rust-lang/crates.io-index"
2659 checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab"
2678 checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7"
2660 2679 dependencies = [
2661 2680 "proc-macro2",
2662 2681 "quote",
@@ -2665,9 +2684,9 @@ dependencies = [
2665 2684
2666 2685 [[package]]
2667 2686 name = "tracing-core"
2668 version = "0.1.31"
2687 version = "0.1.32"
2669 2688 source = "registry+https://github.com/rust-lang/crates.io-index"
2670 checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a"
2689 checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54"
2671 2690 dependencies = [
2672 2691 "once_cell",
2673 2692 "valuable",
@@ -2675,12 +2694,12 @@ dependencies = [
2675 2694
2676 2695 [[package]]
2677 2696 name = "tracing-log"
2678 version = "0.1.3"
2697 version = "0.1.4"
2679 2698 source = "registry+https://github.com/rust-lang/crates.io-index"
2680 checksum = "78ddad33d2d10b1ed7eb9d1f518a5674713876e97e5bb9b7345a7984fbb4f922"
2699 checksum = "f751112709b4e791d8ce53e32c4ed2d353565a795ce84da2285393f41557bdf2"
2681 2700 dependencies = [
2682 "lazy_static",
2683 2701 "log",
2702 "once_cell",
2684 2703 "tracing-core",
2685 2704 ]
2686 2705
@@ -2813,9 +2832,9 @@ checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
2813 2832
2814 2833 [[package]]
2815 2834 name = "uuid"
2816 version = "1.4.1"
2835 version = "1.5.0"
2817 2836 source = "registry+https://github.com/rust-lang/crates.io-index"
2818 checksum = "79daa5ed5740825c40b389c5e50312b9c86df53fccd33f281df655642b43869d"
2837 checksum = "88ad59a7560b41a70d191093a945f0b87bc1deeda46fb237479708a1d6b6cdfc"
2819 2838 dependencies = [
2820 2839 "getrandom",
2821 2840 ]
@@ -2865,9 +2884,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
2865 2884
2866 2885 [[package]]
2867 2886 name = "wasm-bindgen"
2868 version = "0.2.87"
2887 version = "0.2.88"
2869 2888 source = "registry+https://github.com/rust-lang/crates.io-index"
2870 checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342"
2889 checksum = "7daec296f25a1bae309c0cd5c29c4b260e510e6d813c286b19eaadf409d40fce"
2871 2890 dependencies = [
2872 2891 "cfg-if",
2873 2892 "wasm-bindgen-macro",
@@ -2875,9 +2894,9 @@ dependencies = [
2875 2894
2876 2895 [[package]]
2877 2896 name = "wasm-bindgen-backend"
2878 version = "0.2.87"
2897 version = "0.2.88"
2879 2898 source = "registry+https://github.com/rust-lang/crates.io-index"
2880 checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd"
2899 checksum = "e397f4664c0e4e428e8313a469aaa58310d302159845980fd23b0f22a847f217"
2881 2900 dependencies = [
2882 2901 "bumpalo",
2883 2902 "log",
@@ -2890,9 +2909,9 @@ dependencies = [
2890 2909
2891 2910 [[package]]
2892 2911 name = "wasm-bindgen-futures"
2893 version = "0.4.37"
2912 version = "0.4.38"
2894 2913 source = "registry+https://github.com/rust-lang/crates.io-index"
2895 checksum = "c02dbc21516f9f1f04f187958890d7e6026df8d16540b7ad9492bc34a67cea03"
2914 checksum = "9afec9963e3d0994cac82455b2b3502b81a7f40f9a0d32181f7528d9f4b43e02"
2896 2915 dependencies = [
2897 2916 "cfg-if",
2898 2917 "js-sys",
@@ -2902,9 +2921,9 @@ dependencies = [
2902 2921
2903 2922 [[package]]
2904 2923 name = "wasm-bindgen-macro"
2905 version = "0.2.87"
2924 version = "0.2.88"
2906 2925 source = "registry+https://github.com/rust-lang/crates.io-index"
2907 checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d"
2926 checksum = "5961017b3b08ad5f3fe39f1e79877f8ee7c23c5e5fd5eb80de95abc41f1f16b2"
2908 2927 dependencies = [
2909 2928 "quote",
2910 2929 "wasm-bindgen-macro-support",
@@ -2912,9 +2931,9 @@ dependencies = [
2912 2931
2913 2932 [[package]]
2914 2933 name = "wasm-bindgen-macro-support"
2915 version = "0.2.87"
2934 version = "0.2.88"
2916 2935 source = "registry+https://github.com/rust-lang/crates.io-index"
2917 checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b"
2936 checksum = "c5353b8dab669f5e10f5bd76df26a9360c748f054f862ff5f3f8aae0c7fb3907"
2918 2937 dependencies = [
2919 2938 "proc-macro2",
2920 2939 "quote",
@@ -2925,15 +2944,15 @@ dependencies = [
2925 2944
2926 2945 [[package]]
2927 2946 name = "wasm-bindgen-shared"
2928 version = "0.2.87"
2947 version = "0.2.88"
2929 2948 source = "registry+https://github.com/rust-lang/crates.io-index"
2930 checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1"
2949 checksum = "0d046c5d029ba91a1ed14da14dca44b68bf2f124cfbaf741c54151fdb3e0750b"
2931 2950
2932 2951 [[package]]
2933 2952 name = "web-sys"
2934 version = "0.3.64"
2953 version = "0.3.65"
2935 2954 source = "registry+https://github.com/rust-lang/crates.io-index"
2936 checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b"
2955 checksum = "5db499c5f66323272151db0e666cd34f78617522fb0c1604d31a27c50c206a85"
2937 2956 dependencies = [
2938 2957 "js-sys",
2939 2958 "wasm-bindgen",
@@ -2977,10 +2996,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
2977 2996 checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
2978 2997
2979 2998 [[package]]
2980 name = "windows"
2981 version = "0.48.0"
2999 name = "windows-core"
3000 version = "0.51.1"
2982 3001 source = "registry+https://github.com/rust-lang/crates.io-index"
2983 checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f"
3002 checksum = "f1f8cf84f35d2db49a46868f947758c7a1138116f7fac3bc844f43ade1292e64"
2984 3003 dependencies = [
2985 3004 "windows-targets",
2986 3005 ]
@@ -3053,9 +3072,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
3053 3072
3054 3073 [[package]]
3055 3074 name = "winnow"
3056 version = "0.5.16"
3075 version = "0.5.19"
3057 3076 source = "registry+https://github.com/rust-lang/crates.io-index"
3058 checksum = "037711d82167854aff2018dfd193aa0fef5370f456732f0d5a0c59b0f1b4b907"
3077 checksum = "829846f3e3db426d4cee4510841b71a8e58aa2a76b1132579487ae430ccd9c7b"
3059 3078 dependencies = [
3060 3079 "memchr",
3061 3080 ]
@@ -3071,6 +3090,26 @@ dependencies = [
3071 3090 ]
3072 3091
3073 3092 [[package]]
3093 name = "zerocopy"
3094 version = "0.7.25"
3095 source = "registry+https://github.com/rust-lang/crates.io-index"
3096 checksum = "8cd369a67c0edfef15010f980c3cbe45d7f651deac2cd67ce097cd801de16557"
3097 dependencies = [
3098 "zerocopy-derive",
3099 ]
3100
3101 [[package]]
3102 name = "zerocopy-derive"
3103 version = "0.7.25"
3104 source = "registry+https://github.com/rust-lang/crates.io-index"
3105 checksum = "c2f140bda219a26ccc0cdb03dba58af72590c53b22642577d88a927bc5c87d6b"
3106 dependencies = [
3107 "proc-macro2",
3108 "quote",
3109 "syn 2.0.38",
3110 ]
3111
3112 [[package]]
3074 3113 name = "zeroize"
3075 3114 version = "1.6.0"
3076 3115 source = "registry+https://github.com/rust-lang/crates.io-index"

Cargo.toml

View file
@@ -4,9 +4,10 @@ members = [
4 4 "giterated-models",
5 5 "giterated-stack",
6 6 "giterated-cache",
7 "giterated-protocol",
8 7 "giterated-plugins/giterated-plugin",
9 8 "giterated-plugins/giterated-plugin-sys",
10 9 "giterated-plugins/example-plugin",
11 "giterated-plugins/giterated-issues"
10 "giterated-plugins/giterated-backend",
11 "giterated-plugins/giterated-issues",
12 "giterated-plugins/giterated-protocol"
12 13 ]
12 13 \ No newline at end of file

giterated-daemon/Cargo.toml

View file
@@ -30,9 +30,7 @@ argon2 = "0.5"
30 30 aes-gcm = "0.10"
31 31 semver = {version = "1.0", features = ["serde"]}
32 32 giterated-models = { path = "../giterated-models" }
33 giterated-stack = { path = "../giterated-stack" }
34 giterated-cache = { path = "../giterated-cache" }
35 giterated-protocol = { path = "../giterated-protocol" }
33 giterated-plugin = { path = "../giterated-plugins/giterated-plugin" }
36 34 deadpool = "0.9"
37 35 bincode = "1.3"
38 36 tokio-util = {version = "0.7", features = ["rt"]}

giterated-daemon/src/client.rs

View file
@@ -1,18 +1,20 @@
1 use std::sync::Arc;
2
1 3 use futures_util::{SinkExt, StreamExt};
2 4 use giterated_models::{
3 5 error::{IntoInternalError, OperationError},
4 6 instance::Instance,
5 7 object_backend::ObjectBackend,
6 8 };
9 use giterated_plugin::new_stack::Runtime;
7 10 use giterated_protocol::{AuthenticatedPayload, NetworkedObject, NetworkedOperation};
8 use giterated_stack::{GiteratedStack, StackOperationState};
9 11 use tokio::net::TcpStream;
10 12 use tokio_tungstenite::{tungstenite::Message, WebSocketStream};
11 13
12 14 pub async fn client_wrapper(
13 15 our_instance: Instance,
14 16 mut socket: WebSocketStream<TcpStream>,
15 runtime: GiteratedStack,
17 runtime: Arc<Runtime>,
16 18 ) {
17 19 loop {
18 20 let message = socket.next().await;
@@ -65,39 +67,40 @@ pub async fn client_wrapper(
65 67 payload.operation
66 68 );
67 69
68 let operation_state = StackOperationState {
69 our_instance: our_instance.clone(),
70 runtime: runtime.clone(),
71 instance: None,
72 user: None,
73 };
70 todo!()
71
72 // let operation_state = StackOperationState {
73 // our_instance: our_instance.clone(),
74 // instance: None,
75 // user: None,
76 // };
74 77
75 let result = handle_client_message(payload, operation_state, runtime.clone()).await;
78 // let result = handle_client_message(payload, operation_state, runtime.clone()).await;
76 79
77 80 // Grab operation errors so we can log them, they don't make it across the network
78 if let Err(OperationError::Internal(internal_error)) = &result {
79 error!("An internal error has occurred:\n{:?}", internal_error);
80 }
81 // if let Err(OperationError::Internal(internal_error)) = &result {
82 // error!("An internal error has occurred:\n{:?}", internal_error);
83 // }
81 84
82 // Map error to the network variant
83 let result = result.map_err(|e| e.into_network());
85 // // Map error to the network variant
86 // let result = result.map_err(|e| e.into_network());
84 87
85 socket
86 .send(Message::Binary(bincode::serialize(&result).unwrap()))
87 .await
88 .expect("there was an error sending a message, this is a problem for the receiver");
88 // socket
89 // .send(Message::Binary(bincode::serialize(&result).unwrap()))
90 // .await
91 // .expect("there was an error sending a message, this is a problem for the receiver");
89 92 }
90 93 }
91 94
92 95 pub async fn handle_client_message(
93 96 payload: AuthenticatedPayload,
94 operation_state: StackOperationState,
95 runtime: GiteratedStack,
97 // operation_state: StackOperationState,
98 runtime: Arc<Runtime>,
96 99 ) -> Result<Vec<u8>, OperationError<Vec<u8>>> {
97 let mut networked_object = runtime
98 .get_object::<NetworkedObject>(&payload.object, &operation_state)
99 .await
100 .as_internal_error_with_context("handling client message")?;
100 // let mut networked_object = runtime
101 // .get_object::<NetworkedObject>(&payload.object, &operation_state)
102 // .await
103 // .as_internal_error_with_context("handling client message")?;
101 104
102 105 let message: giterated_protocol::GiteratedMessage<NetworkedObject, NetworkedOperation> =
103 106 payload.into_message();
@@ -109,7 +112,9 @@ pub async fn handle_client_message(
109 112
110 113 trace!("Calling handler for networked operation");
111 114
112 networked_object
113 .request(networked_operation, &operation_state)
114 .await
115 // networked_object
116 // .request(networked_operation, &operation_state)
117 // .await
118
119 todo!()
115 120 }

giterated-daemon/src/lib.rs

View file
@@ -3,9 +3,7 @@ use std::str::FromStr;
3 3 use semver::{Version, VersionReq};
4 4
5 5 pub mod authentication;
6 pub mod backend;
7 6 pub mod client;
8 pub mod database_backend;
9 7
10 8 #[macro_use]
11 9 extern crate tracing;

giterated-daemon/src/main.rs

View file
@@ -1,18 +1,10 @@
1 1 use anyhow::Error;
2 use giterated_cache::CacheSubstack;
3 use giterated_daemon::{
4 authentication::AuthenticationTokenGranter,
5 backend::{
6 git::GitBackend, settings::DatabaseSettings, user::UserAuth, RepositoryBackend, UserBackend,
7 },
8 client::client_wrapper,
9 database_backend::DatabaseBackend,
10 };
2 use giterated_daemon::{authentication::AuthenticationTokenGranter, client::client_wrapper};
11 3
12 4 use giterated_models::instance::Instance;
13 5
6 use giterated_plugin::new_stack::Runtime;
14 7 use giterated_protocol::NetworkedSubstack;
15 use giterated_stack::GiteratedStackBuilder;
16 8 use sqlx::{postgres::PgConnectOptions, ConnectOptions, PgPool};
17 9 use std::{net::SocketAddr, str::FromStr, sync::Arc};
18 10 use tokio::{
@@ -51,55 +43,14 @@ async fn main() -> Result<(), Error> {
51 43 sqlx::migrate!().run(&db_pool).await?;
52 44 info!("Connected");
53 45
54 let stack_cell = Arc::new(OnceCell::default());
55
56 let settings = Arc::new(Mutex::new(DatabaseSettings {
57 pg_pool: db_pool.clone(),
58 stack: stack_cell.clone(),
59 }));
60
61 let repository_backend: Arc<Mutex<dyn RepositoryBackend + Send>> =
62 Arc::new(Mutex::new(GitBackend {
63 pg_pool: db_pool.clone(),
64 repository_folder: String::from(
65 config["giterated"]["backend"]["git"]["root"]
66 .as_str()
67 .unwrap(),
68 ),
69 instance: Instance::from_str(config["giterated"]["instance"].as_str().unwrap())
70 .unwrap(),
71 stack: stack_cell.clone(),
72 }));
73
74 46 let token_granter = Arc::new(Mutex::new(AuthenticationTokenGranter {
75 47 config: config.clone(),
76 48 instance: Instance::from_str(config["giterated"]["instance"].as_str().unwrap()).unwrap(),
77 49 }));
78 50
79 let user_backend: Arc<Mutex<dyn UserBackend + Send>> = Arc::new(Mutex::new(UserAuth::new(
80 db_pool.clone(),
81 &Instance::from_str(config["giterated"]["instance"].as_str().unwrap()).unwrap(),
82 token_granter.clone(),
83 settings.clone(),
84 )));
85
86 51 info!("Connected");
87 52
88 let database_backend = DatabaseBackend::new(
89 Instance::from_str(config["giterated"]["instance"].as_str().unwrap()).unwrap(),
90 user_backend.clone(),
91 repository_backend.clone(),
92 db_pool.clone(),
93 stack_cell.clone(),
94 );
95
96 let mut runtime = GiteratedStackBuilder::default();
97
98 let database_backend = database_backend.into_substack();
99 runtime.merge_builder(database_backend);
100
101 let cache_backend = CacheSubstack::default();
102 runtime.merge_builder(cache_backend.into_substack());
53 let mut runtime = Runtime::default();
103 54
104 55 let networked_stack = NetworkedSubstack {
105 56 home_uri: Some(
@@ -108,13 +59,8 @@ async fn main() -> Result<(), Error> {
108 59 .0,
109 60 ),
110 61 };
111 runtime.merge_builder(networked_stack.into_server_substack());
112
113 let runtime = runtime.finish();
114 62
115 stack_cell
116 .set(runtime.clone())
117 .expect("failed to store global daemon stack");
63 let runtime = Arc::new(runtime);
118 64
119 65 let pool = LocalPoolHandle::new(5);
120 66

giterated-models/src/repository/mod.rs

View file
@@ -49,6 +49,16 @@ pub struct Repository {
49 49 pub instance: Instance,
50 50 }
51 51
52 impl Repository {
53 pub fn new(instance: Instance, owner: User, name: String) -> Self {
54 Self {
55 owner,
56 name,
57 instance,
58 }
59 }
60 }
61
52 62 impl Display for Repository {
53 63 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
54 64 f.write_str(&format!("{}/{}@{}", self.owner, self.name, self.instance))

giterated-plugins/example-plugin/src/lib.rs

View file
@@ -9,7 +9,7 @@ use giterated_models::{
9 9 use giterated_plugin::{
10 10 handle::PluginInitializationState,
11 11 new_stack::{FFIPluginMeta, PluginState},
12 HostVTable, InitializationVTable,
12 vtable::{HostVTable, InitializationVTable},
13 13 };
14 14 use giterated_plugin_sys::PluginStackBuilder;
15 15 use tracing::{info, trace_span, Level};
@@ -62,7 +62,7 @@ pub extern "C" fn initialize_registration(
62 62 let mut builder = PluginStackBuilder::new((), state, init_vtable);
63 63
64 64 builder.object::<Instance>().object::<User>();
65 builder.operation_handler(handler);
65 builder.operation(handler);
66 66 builder.value(value_getter);
67 67 // builder.setting_getter(setting_getter);
68 68

giterated-plugins/giterated-backend/Cargo.toml

View file
@@ -0,0 +1,20 @@
1 [package]
2 name = "giterated-backend"
3 version = "0.1.0"
4 edition = "2021"
5
6 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7
8 [dependencies]
9 giterated-plugin = { path = "../giterated-plugin" }
10 giterated-models = { path = "../../giterated-models" }
11 serde = { version = "1.0", features = [ "derive" ]}
12 anyhow = "1"
13 thiserror = "1"
14 sqlx = { version = "0.7", features = [ "runtime-tokio", "tls-native-tls", "postgres", "macros", "migrate", "chrono" ] }
15 tokio = { version = "1.32", features = [ "full" ] }
16 giterated-plugin-sys = { path = "../giterated-plugin-sys" }
17 toml = { version = "0.7" }
18 tracing = "0.1"
19 tracing-subscriber = "0.3"
20 serde_json = "1.0"

giterated-plugins/giterated-backend/src/handlers.rs

View file
@@ -0,0 +1,28 @@
1 use std::sync::Arc;
2
3 use giterated_models::{
4 error::{OperationError, RepositoryError, UserError},
5 repository::{Repository, RepositoryInfoRequest, RepositorySummary, RepositoryView},
6 user::{User, UserRepositoriesRequest},
7 };
8 use giterated_plugin::new_stack::{OperationState, Runtime, State};
9
10 use crate::DatabaseBackend;
11
12 pub async fn user_get_repositories(
13 state: DatabaseBackend,
14 object: User,
15 request: UserRepositoriesRequest,
16 ) -> Result<Vec<RepositorySummary>, OperationError<UserError>> {
17 todo!()
18 }
19
20 pub async fn repository_info(
21 state: DatabaseBackend,
22 object: Repository,
23 request: RepositoryInfoRequest,
24 runtime: Arc<Runtime>,
25 State(operation_state): State<OperationState>,
26 ) -> Result<RepositoryView, OperationError<RepositoryError>> {
27 todo!()
28 }

giterated-plugins/giterated-backend/src/lib.rs

View file
@@ -0,0 +1,16 @@
1 pub mod handlers;
2 pub mod value;
3
4 use giterated_models::{instance::Instance, repository::Repository, user::User};
5 use giterated_plugin_sys::{PluginStackBuilder, ValueSettingExt};
6 use handlers::{repository_info, user_get_repositories};
7 use sqlx::PgPool;
8 use value::{user_get_bio, user_get_display_name, user_set_bio, user_set_display_name};
9
10 /// A backend implementation which attempts to resolve data from the instance's database.
11 #[derive(Debug, Clone)]
12 #[allow(unused)]
13 pub struct DatabaseBackend {
14 pub(self) our_instance: Instance,
15 pub(self) pool: PgPool,
16 }

giterated-plugins/giterated-backend/src/value.rs

View file
@@ -0,0 +1,36 @@
1 use giterated_models::{
2 error::OperationError,
3 user::{Bio, DisplayName, User},
4 };
5
6 use crate::DatabaseBackend;
7
8 pub async fn user_get_display_name(
9 state: DatabaseBackend,
10 user: User,
11 ) -> Result<DisplayName, OperationError<anyhow::Error>> {
12 todo!()
13 }
14
15 pub async fn user_set_display_name(
16 state: DatabaseBackend,
17 user: User,
18 display_name: DisplayName,
19 ) -> Result<(), OperationError<anyhow::Error>> {
20 todo!()
21 }
22
23 pub async fn user_get_bio(
24 state: DatabaseBackend,
25 user: User,
26 ) -> Result<Bio, OperationError<anyhow::Error>> {
27 todo!()
28 }
29
30 pub async fn user_set_bio(
31 state: DatabaseBackend,
32 user: User,
33 bio: Bio,
34 ) -> Result<(), OperationError<anyhow::Error>> {
35 todo!()
36 }

giterated-plugins/giterated-issues/Cargo.toml

View file
@@ -3,6 +3,11 @@ name = "giterated-issues"
3 3 version = "0.1.0"
4 4 edition = "2021"
5 5
6 [lib]
7 name = "giterated_issues"
8 path = "src/lib.rs"
9 crate-type = ["rlib", "dylib"]
10
6 11 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7 12
8 13 [dependencies]
@@ -14,3 +19,7 @@ thiserror = "1"
14 19 sqlx = { version = "0.7", features = [ "runtime-tokio", "tls-native-tls", "postgres", "macros", "migrate", "chrono" ] }
15 20 tokio = { version = "1.32", features = [ "full" ] }
16 21 giterated-plugin-sys = { path = "../giterated-plugin-sys" }
22 toml = { version = "0.7" }
23 tracing = "0.1"
24 tracing-subscriber = "0.3"
25 serde_json = "1.0"

giterated-plugins/giterated-issues/src/lib.rs

View file
@@ -1,11 +1,15 @@
1 use std::{fmt::Display, str::FromStr, sync::OnceLock};
1 use std::{
2 fmt::Display,
3 str::FromStr,
4 sync::{Arc, OnceLock},
5 };
2 6
3 7 use anyhow::Error;
4 8 use giterated_models::{object::GiteratedObject, repository::Repository};
5 9 use giterated_plugin::{
6 10 handle::PluginInitializationState,
7 11 new_stack::{FFIPluginMeta, PluginState},
8 HostVTable, InitializationVTable,
12 vtable::{HostVTable, InitializationVTable},
9 13 };
10 14 use giterated_plugin_sys::PluginStackBuilder;
11 15 use handlers::{
@@ -15,7 +19,16 @@ use handlers::{
15 19 };
16 20 use serde::{Deserialize, Serialize};
17 21 use setting::{Contents, NotificationsOverride};
18 use sqlx::PgPool;
22 use sqlx::{postgres::PgConnectOptions, PgPool};
23 use tokio::{
24 fs::File,
25 io::AsyncReadExt,
26 runtime::Runtime,
27 spawn,
28 task::{block_in_place, spawn_blocking},
29 };
30 use toml::Table;
31 use tracing::{debug, info};
19 32 use value::{Author, CommentCount, CreationDate, Name};
20 33
21 34 pub mod db;
@@ -74,6 +87,7 @@ impl FromStr for Issue {
74 87 pub struct IssueParseError;
75 88
76 89 static INIT_VTABLE: OnceLock<InitializationVTable> = OnceLock::new();
90 static ASYNC_RUNTIME: OnceLock<Runtime> = OnceLock::new();
77 91
78 92 #[no_mangle]
79 93 pub extern "C" fn plugin_meta() -> FFIPluginMeta {
@@ -116,12 +130,39 @@ pub extern "C" fn initialize() -> PluginState {
116 130 pub extern "C" fn initialize_registration(
117 131 state: *mut PluginInitializationState,
118 132 ) -> *mut PluginInitializationState {
133 let runtime = Runtime::new().unwrap();
134
119 135 // let _guard: tracing::span::EnteredSpan = trace_span!("initialize_registration").entered();
120 136 let init_vtable = INIT_VTABLE.get().unwrap();
121 137
122 let plugin_state = { todo!() };
138 let db_pool = runtime.block_on(async {
139 let config: Table = {
140 let mut file = File::open("Giterated.toml").await.unwrap();
141 let mut text = String::new();
142 file.read_to_string(&mut text).await.unwrap();
143 text.parse().unwrap()
144 };
145 let db_conn_options = PgConnectOptions::new()
146 .host(config["postgres"]["host"].as_str().unwrap())
147 .port(config["postgres"]["port"].as_integer().unwrap() as u16)
148 .database(config["postgres"]["database"].as_str().unwrap())
149 .username(config["postgres"]["user"].as_str().unwrap())
150 .password(config["postgres"]["password"].as_str().unwrap());
151 let db_pool = PgPool::connect_with(db_conn_options).await.unwrap();
152
153 debug!("Running database migrations...");
154 // sqlx::migrate!().run(&db_pool).await.unwrap();
155 info!("Connected");
156
157 db_pool
158 });
159
160 ASYNC_RUNTIME.set(runtime).unwrap();
161
162 let plugin_state = IssuesPluginState { pool: db_pool };
123 163
124 let mut builder = PluginStackBuilder::new(plugin_state, state, init_vtable);
164 let mut builder: PluginStackBuilder<'_, IssuesPluginState> =
165 PluginStackBuilder::new(plugin_state, state, init_vtable);
125 166
126 167 builder.object::<Issue>();
127 168
@@ -138,10 +179,10 @@ pub extern "C" fn initialize_registration(
138 179 .value(issue_value_author);
139 180
140 181 builder
141 .operation_handler(create_issue_request)
142 .operation_handler(query_issues_request)
143 .operation_handler(edit_issue_request)
144 .operation_handler(issue_post_comment_request);
182 .operation(create_issue_request)
183 .operation(query_issues_request)
184 .operation(edit_issue_request)
185 .operation(issue_post_comment_request);
145 186
146 187 state
147 188 }

giterated-plugins/giterated-issues/src/main.rs

View file
@@ -0,0 +1,45 @@
1 use std::str::FromStr;
2
3 use giterated_issues::operations::CreateIssueRequest;
4 use giterated_models::{
5 instance::Instance,
6 object::{GiteratedObject, ObjectRequest},
7 operation::GiteratedOperation,
8 repository::Repository,
9 user::User,
10 };
11 use giterated_plugin::{handle::PluginHandle, new_stack::Runtime};
12 use tracing::Level;
13
14 #[tokio::main]
15 pub async fn main() {
16 tracing_subscriber::fmt()
17 .pretty()
18 .with_thread_names(true)
19 .with_max_level(Level::TRACE)
20 .init();
21
22 let mut handle = PluginHandle::from_dylib("giterated_issues.dll").unwrap();
23
24 let mut runtime = Runtime::default();
25
26 runtime.insert_plugin(handle);
27
28 let operation = CreateIssueRequest {
29 name: String::from("test issue"),
30 contents: String::from("hey!"),
31 author: User::from_str("amber:giterated.dev").unwrap(),
32 };
33
34 match runtime.handle_typed(
35 Repository::from_str("barson:giterated.dev/[email protected]").unwrap(),
36 operation,
37 ) {
38 Ok(success) => {
39 println!("Success in create issue: {:?}", success)
40 }
41 Err(err) => {
42 println!("Error in create issue: {:?}", err)
43 }
44 }
45 }

giterated-plugins/giterated-plugin-sys/src/lib.rs

View file
@@ -6,13 +6,17 @@ use giterated_models::{
6 6 };
7 7 use giterated_plugin::{
8 8 callback::{
9 IntoPluginOperationHandler, IntoPluginSettingGetter, IntoPluginSettingSetter,
9 CallbackPtr, IntoPluginOperationHandler, IntoPluginSettingGetter, IntoPluginSettingSetter,
10 10 IntoPluginValueGetter, OperationHandlerCallback, SettingGetterCallback,
11 11 ValueGetterCallback,
12 12 },
13 13 handle::PluginInitializationState,
14 InitializationVTable, IntoObjectVTable, IntoOperationVTable, IntoSettingVTable,
15 IntoValueVTable, ObjectVtable, OperationVTable, SettingVtable, ValueVTable,
14 new_stack::PluginState,
15 vtable::{
16 InitializationVTable, IntoObjectVTable, IntoOperationVTable, IntoSettingVTable,
17 IntoValueVTable, ObjectVtable, OperationVTable, SettingVtable, ValueVTable,
18 },
19 AnyObject, NewAnyValue,
16 20 };
17 21 use tracing::trace_span;
18 22
@@ -45,7 +49,7 @@ impl<'init, S> PluginStackBuilder<'init, S> {
45 49 self
46 50 }
47 51
48 pub fn operation<O, D>(&mut self) -> &mut Self
52 pub fn register_operation<O, D>(&mut self) -> &mut Self
49 53 where
50 54 D: IntoOperationVTable<O> + GiteratedOperation<O>,
51 55 O: GiteratedObject,
@@ -133,12 +137,13 @@ impl<'init, S> PluginStackBuilder<'init, S> {
133 137 self
134 138 }
135 139
136 pub fn operation_handler<
140 pub fn operation<
137 141 DS,
138 142 DF,
143 A,
139 144 O: GiteratedObject + IntoObjectVTable,
140 145 D: IntoOperationVTable<O> + GiteratedOperation<O>,
141 T: IntoPluginOperationHandler<S, O, D, DS, DF>,
146 T: IntoPluginOperationHandler<S, O, D, DS, DF, A>,
142 147 >(
143 148 &mut self,
144 149 handler: T,
@@ -150,14 +155,14 @@ impl<'init, S> PluginStackBuilder<'init, S> {
150 155 self.init_state,
151 156 O::object_name(),
152 157 D::operation_name(),
153 OperationHandlerCallback::new::<S, O, D, DS, DF, T>(handler),
158 OperationHandlerCallback::new::<S, O, D, DS, DF, A, T>(handler),
154 159 )
155 160 }
156 161
157 162 // TODO: Yikes?
158 163 self.object::<O>();
159 164
160 self.operation::<O, D>();
165 self.register_operation::<O, D>();
161 166
162 167 self
163 168 }
@@ -209,3 +214,57 @@ impl<'init, S> PluginStackBuilder<'init, S> {
209 214 // self
210 215 // }
211 216 }
217
218 pub trait ValueSettingExt<PS> {
219 fn value_setting<O, VS, HG, HS>(&mut self, get: HG, set: HS) -> &mut Self
220 where
221 O: GiteratedObject + IntoObjectVTable + 'static,
222 VS: GiteratedObjectValue<Object = O> + IntoValueVTable<O> + Setting + IntoSettingVTable,
223 HG: IntoPluginSettingGetter<PS, O, VS>,
224 HS: IntoPluginSettingSetter<PS, O, VS>;
225 }
226
227 impl<PS> ValueSettingExt<PS> for PluginStackBuilder<'_, PS> {
228 fn value_setting<O, VS, HG, HS>(&mut self, get: HG, set: HS) -> &mut Self
229 where
230 O: GiteratedObject + IntoObjectVTable + 'static,
231 VS: GiteratedObjectValue<Object = O> + IntoValueVTable<O> + Setting + IntoSettingVTable,
232 HG: IntoPluginSettingGetter<PS, O, VS>,
233 HS: IntoPluginSettingSetter<PS, O, VS>,
234 {
235 self
236 }
237 }
238
239 pub trait ValueSettingGetter<S, O, V> {
240 unsafe extern "C" fn get_value(
241 callback: CallbackPtr,
242 state: &PluginState,
243 object: AnyObject,
244 ) -> Result<NewAnyValue, ()>;
245
246 fn callback_ptr(&self) -> CallbackPtr;
247 }
248
249 impl<S, O, VS, HG> ValueSettingGetter<S, O, VS> for HG
250 where
251 O: GiteratedObject,
252 VS: GiteratedObjectValue<Object = O>,
253 HG: IntoPluginSettingGetter<S, O, VS>,
254 {
255 unsafe extern "C" fn get_value(
256 callback: CallbackPtr,
257 state: &PluginState,
258 object: AnyObject,
259 ) -> Result<NewAnyValue, ()> {
260 let result = HG::get_setting(callback, state, object)?;
261
262 let setting = *result.transmute_owned::<VS>();
263
264 Ok(NewAnyValue::new(setting))
265 }
266
267 fn callback_ptr(&self) -> CallbackPtr {
268 self.callback_ptr()
269 }
270 }

giterated-plugins/giterated-plugin/src/callback/mod.rs

View file
@@ -1,10 +1,14 @@
1 1 mod operation;
2 use std::sync::Arc;
3
2 4 pub use operation::*;
3 5 mod value;
4 6 pub use value::*;
5 7 mod setting;
6 8 pub use setting::*;
7 9
10 use crate::new_stack::{PluginState, Runtime};
11
8 12 /// A container for a callback pointer, used to provide an internal callback function or
9 13 /// state to a plugin when performing a callback.
10 14 #[derive(Clone, Copy)]
@@ -16,3 +20,9 @@ impl CallbackPtr {
16 20 Self(callback)
17 21 }
18 22 }
23
24 #[repr(C)]
25 pub struct RuntimeState {
26 pub runtime: Arc<Runtime>,
27 pub operation_state: PluginState,
28 }

giterated-plugins/giterated-plugin/src/callback/operation.rs

View file
@@ -1,20 +1,28 @@
1 1 use giterated_models::error::OperationError;
2 2
3 use crate::{new_stack::PluginState, AnyObject, AnyOperation};
3 use crate::{
4 new_stack::{PluginState, Runtime, State},
5 AnyObject, AnyOperation,
6 };
4 7
5 use std::{any::type_name, fmt::Debug, future::Future};
8 use std::{any::type_name, fmt::Debug, future::Future, sync::Arc};
6 9
7 use super::CallbackPtr;
10 use super::{CallbackPtr, RuntimeState};
8 11
9 12 #[derive(Clone, Copy)]
10 13 pub struct OperationHandlerCallback {
11 14 pub callback_ptr: CallbackPtr,
12 pub func:
13 unsafe extern "C" fn(CallbackPtr, &PluginState, object: AnyObject, operation: AnyOperation),
15 pub func: unsafe extern "C" fn(
16 CallbackPtr,
17 &RuntimeState,
18 &PluginState,
19 object: AnyObject,
20 operation: AnyOperation,
21 ),
14 22 }
15 23
16 24 impl OperationHandlerCallback {
17 pub fn new<S, O, D, DS, DF, T: IntoPluginOperationHandler<S, O, D, DS, DF>>(
25 pub fn new<S, O, D, DS, DF, A, T: IntoPluginOperationHandler<S, O, D, DS, DF, A>>(
18 26 handler: T,
19 27 ) -> Self {
20 28 OperationHandlerCallback {
@@ -24,9 +32,10 @@ impl OperationHandlerCallback {
24 32 }
25 33 }
26 34
27 pub trait IntoPluginOperationHandler<S, O, D, DS, DF> {
35 pub trait IntoPluginOperationHandler<S, O, D, DS, DF, A> {
28 36 unsafe extern "C" fn handle(
29 37 callback_ptr: CallbackPtr,
38 runtime_state: &RuntimeState,
30 39 state: &PluginState,
31 40 object: AnyObject,
32 41 operation: AnyOperation,
@@ -34,7 +43,7 @@ pub trait IntoPluginOperationHandler<S, O, D, DS, DF> {
34 43 fn callback_ptr(&self) -> CallbackPtr;
35 44 }
36 45
37 impl<F, S, O, D, DS, DF, Fut> IntoPluginOperationHandler<S, O, D, DS, DF> for F
46 impl<F, S, O, D, DS, DF, Fut> IntoPluginOperationHandler<S, O, D, DS, DF, ()> for F
38 47 where
39 48 Fut: Future<Output = Result<DS, OperationError<DF>>>,
40 49 F: Fn(S, O, D) -> Fut,
@@ -44,6 +53,7 @@ where
44 53 {
45 54 unsafe extern "C" fn handle(
46 55 callback: CallbackPtr,
56 runtime_state: &RuntimeState,
47 57 state: &PluginState,
48 58 mut object: AnyObject,
49 59 mut operation: AnyOperation,
@@ -73,3 +83,94 @@ where
73 83 unsafe { CallbackPtr::from_raw(self as *const _ as *const ()) }
74 84 }
75 85 }
86
87 impl<F, S, O, D, DS, DF, Fut, A1> IntoPluginOperationHandler<S, O, D, DS, DF, (A1,)> for F
88 where
89 Fut: Future<Output = Result<DS, OperationError<DF>>>,
90 F: Fn(S, O, D, A1) -> Fut,
91 S: Clone + Debug,
92 O: Debug,
93 D: Debug,
94 {
95 unsafe extern "C" fn handle(
96 callback_ptr: CallbackPtr,
97 runtime_state: &RuntimeState,
98 state: &PluginState,
99 object: AnyObject,
100 operation: AnyOperation,
101 ) {
102 todo!()
103 }
104
105 fn callback_ptr(&self) -> CallbackPtr {
106 todo!()
107 }
108 }
109
110 impl<F, S, O, D, DS, DF, Fut, A1, A2> IntoPluginOperationHandler<S, O, D, DS, DF, (A1, A2)> for F
111 where
112 Fut: Future<Output = Result<DS, OperationError<DF>>>,
113 F: Fn(S, O, D, A1, A2) -> Fut,
114 S: Clone + Debug,
115 O: Debug,
116 D: Debug,
117 {
118 unsafe extern "C" fn handle(
119 callback_ptr: CallbackPtr,
120 runtime_state: &RuntimeState,
121 state: &PluginState,
122 object: AnyObject,
123 operation: AnyOperation,
124 ) {
125 todo!()
126 }
127
128 fn callback_ptr(&self) -> CallbackPtr {
129 todo!()
130 }
131 }
132
133 pub trait FromOperationState<S, O, D>: Sized {
134 fn from_operation_state(
135 state: &S,
136 runtime_state: &RuntimeState,
137 object: &O,
138 operation: &D,
139 ) -> Result<Self, OperationError<anyhow::Error>>;
140 }
141
142 impl<S, O, D> FromOperationState<S, O, D> for Arc<Runtime> {
143 fn from_operation_state(
144 state: &S,
145 runtime_state: &RuntimeState,
146 object: &O,
147 operation: &D,
148 ) -> Result<Self, OperationError<anyhow::Error>> {
149 Ok(runtime_state.runtime.clone())
150 }
151 }
152
153 impl<S, O, D, T> FromOperationState<S, O, D> for Option<T>
154 where
155 T: FromOperationState<S, O, D>,
156 {
157 fn from_operation_state(
158 state: &S,
159 runtime_state: &RuntimeState,
160 object: &O,
161 operation: &D,
162 ) -> Result<Self, OperationError<anyhow::Error>> {
163 Ok(T::from_operation_state(state, runtime_state, object, operation).ok())
164 }
165 }
166
167 impl<S, O, D, OS: Clone> FromOperationState<S, O, D> for State<OS> {
168 fn from_operation_state(
169 state: &S,
170 runtime_state: &RuntimeState,
171 object: &O,
172 operation: &D,
173 ) -> Result<Self, OperationError<anyhow::Error>> {
174 Ok(unsafe { State(runtime_state.operation_state.transmute_ref::<OS>().clone()) })
175 }
176 }

giterated-plugins/giterated-plugin/src/callback/value.rs

View file
@@ -1,10 +1,13 @@
1 1 use std::future::Future;
2 2
3 3 use giterated_models::{
4 error::OperationError, object::GiteratedObject, value::GiteratedObjectValue,
4 error::OperationError, object::GiteratedObject, settings::Setting, value::GiteratedObjectValue,
5 5 };
6 6
7 use crate::{new_stack::PluginState, AnyObject, NewAnyValue};
7 use crate::{
8 new_stack::PluginState,
9 vtable::{AnyObject, NewAnyValue},
10 };
8 11
9 12 use super::CallbackPtr;
10 13

giterated-plugins/giterated-plugin/src/handle.rs

View file
@@ -11,8 +11,8 @@ use crate::{
11 11 ObjectOperationPair, ObjectSettingPair, ObjectValuePair, PluginMeta, PluginState,
12 12 RuntimeHandlers, TypeMetadata,
13 13 },
14 FFISettingMeta, FFIValueChangeHandler, FFIValueMeta, GiteratedPluginApi, InitializationVTable,
15 ObjectVtable, OperationVTable, SettingVtable, ValueVTable,
14 vtable::{InitializationVTable, ObjectVtable, OperationVTable, SettingVtable, ValueVTable},
15 GiteratedPluginApi,
16 16 };
17 17
18 18 #[derive(Clone)]
@@ -23,6 +23,9 @@ pub struct PluginHandle {
23 23 pub state: PluginState,
24 24 }
25 25
26 unsafe impl Send for PluginHandle {}
27 unsafe impl Sync for PluginHandle {}
28
26 29 impl PluginHandle {
27 30 pub fn from_dylib(path: &str) -> Result<Self, CreationError> {
28 31 let mut handle = unsafe { Container::load(path) }?;
@@ -132,7 +135,6 @@ pub struct PluginInitializationTable<'a> {
132 135 impl<'a> PluginInitializationTable<'a> {
133 136 pub unsafe fn func_table(&mut self) -> InitializationVTable {
134 137 InitializationVTable {
135 register_value_change,
136 138 register_object,
137 139 register_operation,
138 140 register_setting,
@@ -144,15 +146,6 @@ impl<'a> PluginInitializationTable<'a> {
144 146 }
145 147 }
146 148
147 unsafe extern "C" fn register_value_change(
148 state: *mut PluginInitializationState,
149 object_kind: &str,
150 value_name: &str,
151 vtable: FFIValueChangeHandler,
152 ) {
153 todo!()
154 }
155
156 149 unsafe extern "C" fn register_object(
157 150 state: *mut PluginInitializationState,
158 151 object_kind: &'static str,

giterated-plugins/giterated-plugin/src/lib.rs

View file
@@ -17,6 +17,9 @@ use giterated_models::{
17 17 use handle::PluginInitializationState;
18 18 use new_stack::{FFIPluginMeta, PluginState};
19 19
20 pub use vtable::{AnyFailure, AnyObject, AnyOperation, AnySuccess, NewAnySetting, NewAnyValue};
21 use vtable::{HostVTable, InitializationVTable};
22
20 23 #[derive(WrapperApi)]
21 24 pub struct GiteratedPluginApi {
22 25 plugin_meta: unsafe extern "C" fn() -> FFIPluginMeta,
@@ -41,384 +44,16 @@ impl<T: ?Sized> FFIBox<T> {
41 44 }
42 45 }
43 46
44 #[repr(C)]
45 pub struct FFIObject(&'static str);
46
47 #[repr(C)]
48 struct FFIOperationHandler(
49 for<'a> unsafe extern "C" fn(operation: FFIOperation<'a>) -> Result<FFIBox<[u8]>, FFIBox<[u8]>>,
50 );
51
52 #[repr(C)]
53 struct FFIOperation<'a> {
54 operation_name: &'a str,
55 object_name: &'a str,
56 object: FFIObject,
57 operation: &'a [u8],
58 }
59
60 #[derive(Clone, Copy)]
61 #[repr(C)]
62 pub struct OperationVTable {
63 pub serialize: unsafe extern "C" fn(AnyObject) -> Result<FFIBox<[u8]>, ()>,
64 pub deserialize: unsafe extern "C" fn(&[u8]) -> Result<AnyOperation, ()>,
65 pub is_same: unsafe extern "C" fn(AnyObject) -> bool,
66 pub serialize_success: unsafe extern "C" fn(()) -> Result<FFIBox<[u8]>, ()>,
67 pub serialize_failure: unsafe extern "C" fn(()) -> Result<FFIBox<[u8]>, ()>,
68 pub deserialize_success: unsafe extern "C" fn(&[u8]) -> Result<(), ()>,
69 pub deserialize_failure: unsafe extern "C" fn(&[u8]) -> Result<(), ()>,
70 }
71
72 impl OperationVTable {
73 pub fn new<O, T: IntoOperationVTable<O>>() -> Self {
74 Self {
75 serialize: T::serialize,
76 deserialize: T::deserialize,
77 is_same: T::is_same,
78 serialize_success: T::serialize_success,
79 serialize_failure: T::serialize_failure,
80 deserialize_success: T::deserialize_success,
81 deserialize_failure: T::deserialize_failure,
82 }
83 }
84 }
85
86 pub struct AnyOperation {
87 /// A pointer to the plugin-local object type. We are not capable of
88 /// knowing what this type is, we use the provided vtable.
89 inner: FFIBox<()>,
90 vtable: OperationVTable,
91 }
92
93 impl AnyOperation {
94 pub unsafe fn transmute_owned<T>(&mut self) -> Box<T> {
95 Box::from_raw(self.inner.0 as *mut T)
96 }
97
98 pub unsafe fn transmute_ref<T>(&self) -> &T {
99 let ptr: *const T = transmute(self.inner.0);
100
101 ptr.as_ref().unwrap()
102 }
103 }
104
105 #[repr(C)]
106 pub struct FFIValueChangeHandler();
107
108 #[derive(Clone, Copy)]
109 #[repr(C)]
110 pub struct ObjectVtable {
111 pub to_str: unsafe extern "C" fn(AnyObject) -> FFIBox<str>,
112 pub from_str: unsafe extern "C" fn(&str) -> Result<AnyObject, FFIBox<str>>,
113 pub home_uri: unsafe extern "C" fn(AnyObject) -> FFIBox<str>,
114 pub is_same: unsafe extern "C" fn(AnyObject) -> bool,
115 }
116
117 impl ObjectVtable {
118 pub const fn new<T: IntoObjectVTable>() -> Self {
119 Self {
120 to_str: T::to_str,
121 from_str: T::from_str,
122 home_uri: T::home_uri,
123 is_same: T::is_same,
124 }
125 }
126 }
127
128 #[repr(C)]
129 pub struct NewAnySetting {
130 /// A pointer to the plugin-local object type. We are not capable of
131 /// knowing what this type is, we use the provided vtable.
132 inner: FFIBox<()>,
133 vtable: SettingVtable,
134 }
135
136 impl NewAnySetting {
137 pub fn new<V: IntoSettingVTable>(value: V) -> Self {
138 Self {
139 inner: FFIBox::from_box(Box::new(value)).untyped(),
140 vtable: SettingVtable::new::<V>(),
141 }
142 }
143 }
144
145 #[derive(Clone, Copy)]
146 #[repr(C)]
147 pub struct SettingVtable {
148 pub deserialize: unsafe extern "C" fn(&[u8]) -> Result<(), ()>,
149 pub serialize: unsafe extern "C" fn(NewAnySetting) -> Result<FFIBox<[u8]>, ()>,
150 }
151
152 impl SettingVtable {
153 pub fn new<T: IntoSettingVTable>() -> Self {
154 Self {
155 deserialize: T::deserialize,
156 serialize: T::serialize,
157 }
158 }
159 }
160
161 #[repr(C)]
162 pub struct NewAnyValue {
163 /// A pointer to the plugin-local object type. We are not capable of
164 /// knowing what this type is, we use the provided vtable.
165 inner: FFIBox<()>,
166 vtable: ValueVTable,
167 }
168
169 impl NewAnyValue {
170 pub fn new<O, V: IntoValueVTable<O>>(value: V) -> Self {
171 NewAnyValue {
172 inner: FFIBox::from_box(Box::new(value)).untyped(),
173 vtable: ValueVTable::new::<O, V>(),
174 }
175 }
176 }
177
178 #[derive(Clone, Copy)]
179 #[repr(C)]
180 pub struct ValueVTable {
181 pub deserialize: unsafe extern "C" fn(&[u8]) -> Result<NewAnyValue, ()>,
182 pub serialize: unsafe extern "C" fn(NewAnyValue) -> Result<FFIBox<[u8]>, ()>,
183 }
184
185 impl ValueVTable {
186 pub fn new<O, T: IntoValueVTable<O>>() -> Self {
187 Self {
188 deserialize: T::deserialize,
189 serialize: T::serialize,
190 }
191 }
192 }
193
194 pub trait IntoObjectVTable {
195 unsafe extern "C" fn to_str(this: AnyObject) -> FFIBox<str>;
196 unsafe extern "C" fn from_str(src: &str) -> Result<AnyObject, FFIBox<str>>;
197 unsafe extern "C" fn home_uri(this: AnyObject) -> FFIBox<str>;
198 unsafe extern "C" fn is_same(other: AnyObject) -> bool;
199 }
200
201 impl<T: GiteratedObject + 'static> IntoObjectVTable for T {
202 unsafe extern "C" fn to_str(mut this: AnyObject) -> FFIBox<str> {
203 let this: &Box<T> = this.transmute_ref();
204
205 let result = this.to_string();
206
207 FFIBox::from_box(result.into_boxed_str())
208 }
209
210 unsafe extern "C" fn from_str(src: &str) -> Result<AnyObject, FFIBox<str>> {
211 let result = T::from_object_str(src).unwrap();
212
213 let any_object = AnyObject::new(result);
214
215 Ok(any_object)
216 }
217
218 unsafe extern "C" fn home_uri(this: AnyObject) -> FFIBox<str> {
219 todo!()
220 }
221
222 unsafe extern "C" fn is_same(other: AnyObject) -> bool {
47 impl<T: ?Sized> AsRef<T> for FFIBox<T> {
48 fn as_ref(&self) -> &T {
223 49 todo!()
224 50 }
225 51 }
226 52
227 pub trait IntoOperationVTable<O> {
228 unsafe extern "C" fn serialize(this: AnyObject) -> Result<FFIBox<[u8]>, ()>;
229 unsafe extern "C" fn deserialize(src: &[u8]) -> Result<AnyOperation, ()>;
230 unsafe extern "C" fn is_same(this: AnyObject) -> bool;
231 unsafe extern "C" fn serialize_success(success: ()) -> Result<FFIBox<[u8]>, ()>;
232 unsafe extern "C" fn serialize_failure(failure: ()) -> Result<FFIBox<[u8]>, ()>;
233 unsafe extern "C" fn deserialize_success(src: &[u8]) -> Result<(), ()>;
234 unsafe extern "C" fn deserialize_failure(src: &[u8]) -> Result<(), ()>;
235 }
53 impl<T: ?Sized> std::ops::Deref for FFIBox<T> {
54 type Target = T;
236 55
237 impl<O, D> IntoOperationVTable<O> for D
238 where
239 D: GiteratedOperation<O>,
240 O: GiteratedObject,
241 {
242 unsafe extern "C" fn serialize(this: AnyObject) -> Result<FFIBox<[u8]>, ()> {
243 todo!()
244 }
245
246 unsafe extern "C" fn deserialize(src: &[u8]) -> Result<AnyOperation, ()> {
247 let deserialized: D = serde_json::from_slice(src).unwrap();
248
249 Ok(AnyOperation {
250 inner: FFIBox::from_box(Box::new(deserialized)).untyped(),
251 vtable: OperationVTable::new::<O, D>(),
252 })
253 }
254
255 unsafe extern "C" fn is_same(this: AnyObject) -> bool {
256 todo!()
257 }
258
259 unsafe extern "C" fn serialize_success(success: ()) -> Result<FFIBox<[u8]>, ()> {
260 todo!()
261 }
262
263 unsafe extern "C" fn serialize_failure(failure: ()) -> Result<FFIBox<[u8]>, ()> {
264 todo!()
265 }
266
267 unsafe extern "C" fn deserialize_success(src: &[u8]) -> Result<(), ()> {
268 todo!()
269 }
270
271 unsafe extern "C" fn deserialize_failure(src: &[u8]) -> Result<(), ()> {
272 todo!()
56 fn deref(&self) -> &Self::Target {
57 unsafe { self.0.as_ref() }.unwrap()
273 58 }
274 59 }
275
276 pub trait IntoSettingVTable {
277 unsafe extern "C" fn deserialize(src: &[u8]) -> Result<(), ()>;
278 unsafe extern "C" fn serialize(this: NewAnySetting) -> Result<FFIBox<[u8]>, ()>;
279 }
280
281 impl<S> IntoSettingVTable for S
282 where
283 S: Setting,
284 {
285 unsafe extern "C" fn deserialize(src: &[u8]) -> Result<(), ()> {
286 todo!()
287 }
288
289 unsafe extern "C" fn serialize(this: NewAnySetting) -> Result<FFIBox<[u8]>, ()> {
290 todo!()
291 }
292 }
293
294 pub trait IntoValueVTable<O> {
295 unsafe extern "C" fn deserialize(src: &[u8]) -> Result<NewAnyValue, ()>;
296 unsafe extern "C" fn serialize(this: NewAnyValue) -> Result<FFIBox<[u8]>, ()>;
297 }
298
299 impl<O, V> IntoValueVTable<O> for V
300 where
301 O: GiteratedObject,
302 V: GiteratedObjectValue<Object = O>,
303 {
304 unsafe extern "C" fn deserialize(src: &[u8]) -> Result<NewAnyValue, ()> {
305 let _guard = trace_span!(
306 "deserialize value",
307 object = O::object_name(),
308 value = V::value_name()
309 );
310
311 trace!("Deserializing");
312 let deserialized: V = serde_json::from_slice(src).unwrap();
313
314 Ok(NewAnyValue {
315 inner: FFIBox::from_box(Box::new(deserialized)).untyped(),
316 vtable: ValueVTable::new::<O, V>(),
317 })
318 }
319
320 unsafe extern "C" fn serialize(this: NewAnyValue) -> Result<FFIBox<[u8]>, ()> {
321 todo!()
322 }
323 }
324
325 #[repr(C)]
326 pub struct AnyObject {
327 /// A pointer to the plugin-local object type. We are not capable of
328 /// knowing what this type is, we use the provided vtable.
329 inner: FFIBox<()>,
330 vtable: ObjectVtable,
331 }
332
333 impl AnyObject {
334 pub fn new<T: IntoObjectVTable>(inner: T) -> Self {
335 Self {
336 inner: FFIBox::from_box(Box::new(inner)).untyped(),
337 vtable: ObjectVtable::new::<T>(),
338 }
339 }
340 }
341
342 impl AnyObject {
343 pub unsafe fn transmute_owned<T>(&mut self) -> Box<T> {
344 Box::from_raw(self.inner.0 as *mut T)
345 }
346
347 pub unsafe fn transmute_ref<T>(&self) -> &T {
348 let ptr: *const T = transmute(self.inner.0);
349
350 ptr.as_ref().unwrap()
351 }
352 }
353
354 #[repr(C)]
355 pub struct FFISettingMeta();
356
357 #[repr(C)]
358 pub struct FFIValueMeta();
359
360 #[repr(C)]
361 pub struct HostVTable {
362 register_operation: unsafe extern "C" fn(&str, &str, FFIOperationHandler),
363 register_value_change: unsafe extern "C" fn(&str, &str, FFIValueChangeHandler),
364 register_object: unsafe extern "C" fn(&str, ObjectVtable),
365 register_setting: unsafe extern "C" fn(&str, &str, FFISettingMeta),
366 register_value: unsafe extern "C" fn(&str, &str, FFIValueMeta),
367 }
368
369 #[repr(C)]
370 #[derive(Clone, Copy)]
371 pub struct InitializationVTable {
372 pub register_value_change:
373 unsafe extern "C" fn(*mut PluginInitializationState, &str, &str, FFIValueChangeHandler),
374 pub register_object:
375 unsafe extern "C" fn(*mut PluginInitializationState, &'static str, ObjectVtable),
376 pub register_operation: unsafe extern "C" fn(
377 *mut PluginInitializationState,
378 &'static str,
379 &'static str,
380 OperationVTable,
381 ),
382 pub register_setting: unsafe extern "C" fn(
383 *mut PluginInitializationState,
384 &'static str,
385 &'static str,
386 SettingVtable,
387 ),
388 pub register_value: unsafe extern "C" fn(
389 *mut PluginInitializationState,
390 &'static str,
391 &'static str,
392 ValueVTable,
393 ),
394
395 pub operation_handler: unsafe extern "C" fn(
396 *mut PluginInitializationState,
397 &'static str,
398 &'static str,
399 OperationHandlerCallback,
400 ),
401
402 pub value_getter: unsafe extern "C" fn(
403 *mut PluginInitializationState,
404 &'static str,
405 &'static str,
406 ValueGetterCallback,
407 ),
408
409 pub setting_getter: unsafe extern "C" fn(
410 *mut PluginInitializationState,
411 &'static str,
412 &'static str,
413 SettingGetterCallback,
414 ),
415 }
416
417 impl Debug for InitializationVTable {
418 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
419 f.debug_struct("InitializationVTable").finish()
420 }
421 }
422
423 unsafe impl Sync for InitializationVTable {}
424 unsafe impl Send for InitializationVTable {}

giterated-plugins/giterated-plugin/src/new_stack/mod.rs

View file
@@ -1,9 +1,14 @@
1 1 pub mod operation_walker;
2 pub mod runtime_handler;
2 3
3 4 use std::{
4 5 any::type_name, collections::HashMap, fmt::Debug, mem::transmute, ptr::null_mut, sync::Arc,
5 6 };
6 7
8 use giterated_models::{
9 error::OperationError, instance::Instance, object::GiteratedObject,
10 operation::GiteratedOperation,
11 };
7 12 use semver::Version;
8 13 use tracing::{debug, debug_span, field::DebugValue, span, trace, trace_span, warn, Level};
9 14
@@ -13,12 +18,25 @@ use crate::{
13 18 ValueChangeCallback, ValueGetterCallback,
14 19 },
15 20 handle::{PluginHandle, PluginInitializationState},
16 AnyObject, AnyOperation, FFIBox, NewAnySetting, NewAnyValue, ObjectVtable, OperationVTable,
17 SettingVtable, ValueVTable,
21 vtable::{ObjectVtable, OperationVTable, SettingVtable, ValueVTable},
18 22 };
19 23
20 24 use self::operation_walker::OperationHandlerRules;
21 25
26 pub struct State<S>(pub S);
27
28 impl<S> std::ops::Deref for State<S> {
29 type Target = S;
30
31 fn deref(&self) -> &Self::Target {
32 &self.0
33 }
34 }
35
36 pub struct OperationState {
37 pub our_instance: Instance,
38 }
39
22 40 #[derive(Default)]
23 41 pub struct TypeMetadata {
24 42 pub objects: HashMap<&'static str, ObjectVtable>,
@@ -224,10 +242,20 @@ impl Runtime {
224 242 operation_name: &str,
225 243 object: &str,
226 244 operation_payload: &[u8],
227 ) -> Result<(), HandlerError> {
228 let rules = self.handlers.handle_operation(object_kind, operation_name);
245 ) -> Result<(), OperationError<()>> {
246 // let rules = self.handlers.handle_operation(object_kind, operation_name);
247
248 // rules.handle(object, operation_payload)
249
250 todo!()
251 }
229 252
230 rules.handle(object, operation_payload)
253 pub fn handle_typed<O: GiteratedObject, D: GiteratedOperation<O>>(
254 &self,
255 object: O,
256 operation: D,
257 ) -> Result<D::Success, OperationError<D::Failure>> {
258 todo!()
231 259 }
232 260 }
233 261
@@ -241,6 +269,9 @@ pub struct RuntimeHandlers {
241 269 setting_change: HashMap<ObjectSettingPair<'static>, (RuntimeDomain, SettingChangeCallback)>,
242 270 }
243 271
272 unsafe impl Send for RuntimeHandlers {}
273 unsafe impl Sync for RuntimeHandlers {}
274
244 275 impl RuntimeHandlers {
245 276 pub fn operation_handler(
246 277 &mut self,

giterated-plugins/giterated-plugin/src/new_stack/operation_walker.rs

View file
@@ -1,3 +1,4 @@
1 use crate::callback::RuntimeState;
1 2 use giterated_models::{operation::GiteratedOperation, settings::GetSetting, value::GetValue};
2 3 use tracing::{debug_span, trace, trace_span};
3 4
@@ -39,7 +40,12 @@ impl<'o> OperationHandlerRules<'o> {
39 40 }
40 41 }
41 42
42 pub fn handle(&self, object: &str, operation_payload: &[u8]) -> Result<(), HandlerError> {
43 pub fn handle(
44 &self,
45 runtime_state: &RuntimeState,
46 object: &str,
47 operation_payload: &[u8],
48 ) -> Result<(), HandlerError> {
43 49 // object_kind: `any`
44 50 // operation_kind: `typed`
45 51 if let Some(handler) = self
@@ -210,6 +216,7 @@ impl<'o> OperationHandlerRules<'o> {
210 216 let result = unsafe {
211 217 (handler.func)(
212 218 handler.callback_ptr,
219 runtime_state,
213 220 &domain.plugin.state,
214 221 object,
215 222 operation,

giterated-plugins/giterated-plugin/src/new_stack/runtime_handler.rs

View file
@@ -0,0 +1,34 @@
1 use giterated_models::error::OperationError;
2
3 use crate::vtable::{AnyFailure, AnySuccess, OperationVTable};
4
5 pub struct RuntimeHandle {
6 inner: RuntimeHandleInner,
7 }
8
9 impl RuntimeHandle {
10 pub async fn handle_serialized(
11 &self,
12 operation_name: &str,
13 object: &str,
14 operation: &[u8],
15 ) -> Result<Vec<u8>, OperationError<Vec<u8>>> {
16 todo!()
17 }
18 }
19
20 #[repr(C)]
21 struct RuntimeHandleInner {
22 handle_serialized: unsafe extern "C" fn(
23 object_kind: &str,
24 operation_name: &str,
25 object: &str,
26 operation_payload: &[u8],
27 ) -> HandlerResult,
28 }
29
30 #[repr(C)]
31 struct HandlerResult {
32 operation_vtable: OperationVTable,
33 result: Result<AnySuccess, OperationError<AnyFailure>>,
34 }

giterated-plugins/giterated-plugin/src/vtable/host.rs

View file
@@ -0,0 +1,64 @@
1 use super::{ObjectVtable, OperationVTable, SettingVtable, ValueVTable};
2 use crate::{
3 callback::{OperationHandlerCallback, SettingGetterCallback, ValueGetterCallback},
4 handle::PluginInitializationState,
5 };
6 use std::fmt::Debug;
7
8 #[repr(C)]
9 pub struct HostVTable {}
10
11 #[repr(C)]
12 #[derive(Clone, Copy)]
13 pub struct InitializationVTable {
14 pub register_object:
15 unsafe extern "C" fn(*mut PluginInitializationState, &'static str, ObjectVtable),
16 pub register_operation: unsafe extern "C" fn(
17 *mut PluginInitializationState,
18 &'static str,
19 &'static str,
20 OperationVTable,
21 ),
22 pub register_setting: unsafe extern "C" fn(
23 *mut PluginInitializationState,
24 &'static str,
25 &'static str,
26 SettingVtable,
27 ),
28 pub register_value: unsafe extern "C" fn(
29 *mut PluginInitializationState,
30 &'static str,
31 &'static str,
32 ValueVTable,
33 ),
34
35 pub operation_handler: unsafe extern "C" fn(
36 *mut PluginInitializationState,
37 &'static str,
38 &'static str,
39 OperationHandlerCallback,
40 ),
41
42 pub value_getter: unsafe extern "C" fn(
43 *mut PluginInitializationState,
44 &'static str,
45 &'static str,
46 ValueGetterCallback,
47 ),
48
49 pub setting_getter: unsafe extern "C" fn(
50 *mut PluginInitializationState,
51 &'static str,
52 &'static str,
53 SettingGetterCallback,
54 ),
55 }
56
57 impl Debug for InitializationVTable {
58 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
59 f.debug_struct("InitializationVTable").finish()
60 }
61 }
62
63 unsafe impl Sync for InitializationVTable {}
64 unsafe impl Send for InitializationVTable {}

giterated-plugins/giterated-plugin/src/vtable/mod.rs

View file
@@ -1,3 +1,13 @@
1 1 //! Giterated's VTable System
2 2 //!
3 3 //! Docs here? :)
4 mod setting;
5 pub use setting::*;
6 mod operation;
7 pub use operation::*;
8 mod object;
9 pub use object::*;
10 mod value;
11 pub use value::*;
12 mod host;
13 pub use host::*;

giterated-plugins/giterated-plugin/src/vtable/object.rs

View file
@@ -0,0 +1,109 @@
1 use std::mem::transmute;
2
3 use giterated_models::object::GiteratedObject;
4
5 use crate::FFIBox;
6
7 #[derive(Clone, Copy)]
8 #[repr(C)]
9 pub struct ObjectVtable {
10 object_kind: *const u8,
11 object_kind_len: usize,
12 pub to_str: unsafe extern "C" fn(AnyObject) -> FFIBox<str>,
13 pub from_str: unsafe extern "C" fn(&str) -> Result<AnyObject, FFIBox<str>>,
14 pub home_uri: unsafe extern "C" fn(&AnyObject) -> FFIBox<str>,
15 pub is_same: unsafe extern "C" fn(AnyObject) -> bool,
16 }
17
18 impl ObjectVtable {
19 pub fn new<T: IntoObjectVTable>() -> Self {
20 let object_kind = T::object_kind().as_ptr();
21 let object_kind_len = T::object_kind().len();
22
23 Self {
24 to_str: T::to_str,
25 from_str: T::from_str,
26 home_uri: T::home_uri,
27 is_same: T::is_same,
28 object_kind,
29 object_kind_len,
30 }
31 }
32
33 pub fn kind(&self) -> &'static str {
34 let slice = unsafe { std::slice::from_raw_parts(self.object_kind, self.object_kind_len) };
35
36 std::str::from_utf8(slice).unwrap()
37 }
38 }
39
40 pub trait IntoObjectVTable {
41 fn object_kind() -> &'static str;
42 unsafe extern "C" fn to_str(this: AnyObject) -> FFIBox<str>;
43 unsafe extern "C" fn from_str(src: &str) -> Result<AnyObject, FFIBox<str>>;
44 unsafe extern "C" fn home_uri(this: &AnyObject) -> FFIBox<str>;
45 unsafe extern "C" fn is_same(other: AnyObject) -> bool;
46 }
47
48 impl<T: GiteratedObject + 'static> IntoObjectVTable for T {
49 unsafe extern "C" fn to_str(mut this: AnyObject) -> FFIBox<str> {
50 let this: &Box<T> = this.transmute_ref();
51
52 let result = this.to_string();
53
54 FFIBox::from_box(result.into_boxed_str())
55 }
56
57 unsafe extern "C" fn from_str(src: &str) -> Result<AnyObject, FFIBox<str>> {
58 let result = T::from_object_str(src).unwrap();
59
60 let any_object = AnyObject::new(result);
61
62 Ok(any_object)
63 }
64
65 unsafe extern "C" fn home_uri(this: &AnyObject) -> FFIBox<str> {
66 todo!()
67 }
68
69 unsafe extern "C" fn is_same(other: AnyObject) -> bool {
70 todo!()
71 }
72
73 fn object_kind() -> &'static str {
74 todo!()
75 }
76 }
77
78 #[repr(C)]
79 pub struct AnyObject {
80 /// A pointer to the plugin-local object type. We are not capable of
81 /// knowing what this type is, we use the provided vtable.
82 inner: FFIBox<()>,
83 vtable: ObjectVtable,
84 }
85
86 impl AnyObject {
87 pub fn new<T: IntoObjectVTable>(inner: T) -> Self {
88 Self {
89 inner: FFIBox::from_box(Box::new(inner)).untyped(),
90 vtable: ObjectVtable::new::<T>(),
91 }
92 }
93
94 pub fn vtable(&self) -> ObjectVtable {
95 self.vtable
96 }
97 }
98
99 impl AnyObject {
100 pub unsafe fn transmute_owned<T>(&mut self) -> Box<T> {
101 Box::from_raw(self.inner.0 as *mut T)
102 }
103
104 pub unsafe fn transmute_ref<T>(&self) -> &T {
105 let ptr: *const T = transmute(self.inner.0);
106
107 ptr.as_ref().unwrap()
108 }
109 }

giterated-plugins/giterated-plugin/src/vtable/operation.rs

View file
@@ -0,0 +1,136 @@
1 use std::mem::transmute;
2
3 use giterated_models::{object::GiteratedObject, operation::GiteratedOperation};
4
5 use crate::FFIBox;
6
7 use super::AnyObject;
8
9 #[derive(Clone, Copy)]
10 #[repr(C)]
11 pub struct OperationVTable {
12 operation_kind: *const u8,
13 operation_kind_len: usize,
14 pub serialize: unsafe extern "C" fn(&AnyOperation) -> Result<FFIBox<[u8]>, ()>,
15 pub deserialize: unsafe extern "C" fn(&[u8]) -> Result<AnyOperation, ()>,
16 pub is_same: unsafe extern "C" fn(AnyObject) -> bool,
17 pub serialize_success: unsafe extern "C" fn(()) -> Result<FFIBox<[u8]>, ()>,
18 pub serialize_failure: unsafe extern "C" fn(()) -> Result<FFIBox<[u8]>, ()>,
19 pub deserialize_success: unsafe extern "C" fn(&[u8]) -> Result<AnySuccess, ()>,
20 pub deserialize_failure: unsafe extern "C" fn(&[u8]) -> Result<AnyFailure, ()>,
21 }
22
23 impl OperationVTable {
24 pub fn new<O, T: IntoOperationVTable<O>>() -> Self {
25 let operation_kind = T::operation_kind().as_ptr();
26 let operation_kind_len = T::operation_kind().len();
27
28 Self {
29 serialize: T::serialize,
30 deserialize: T::deserialize,
31 is_same: T::is_same,
32 serialize_success: T::serialize_success,
33 serialize_failure: T::serialize_failure,
34 deserialize_success: T::deserialize_success,
35 deserialize_failure: T::deserialize_failure,
36 operation_kind,
37 operation_kind_len,
38 }
39 }
40
41 pub fn kind(&self) -> &'static str {
42 let slice =
43 unsafe { std::slice::from_raw_parts(self.operation_kind, self.operation_kind_len) };
44
45 std::str::from_utf8(slice).unwrap()
46 }
47 }
48
49 pub struct AnyOperation {
50 /// A pointer to the plugin-local object type. We are not capable of
51 /// knowing what this type is, we use the provided vtable.
52 inner: FFIBox<()>,
53 vtable: OperationVTable,
54 }
55
56 impl AnyOperation {
57 pub unsafe fn transmute_owned<T>(&mut self) -> Box<T> {
58 Box::from_raw(self.inner.0 as *mut T)
59 }
60
61 pub unsafe fn transmute_ref<T>(&self) -> &T {
62 let ptr: *const T = transmute(self.inner.0);
63
64 ptr.as_ref().unwrap()
65 }
66
67 pub fn vtable(&self) -> OperationVTable {
68 self.vtable
69 }
70 }
71
72 #[repr(C)]
73 pub struct AnySuccess {
74 inner: FFIBox<()>,
75 vtable: OperationVTable,
76 }
77
78 #[repr(C)]
79 pub struct AnyFailure {
80 inner: FFIBox<()>,
81 vtable: OperationVTable,
82 }
83
84 pub trait IntoOperationVTable<O> {
85 fn operation_kind() -> &'static str;
86 unsafe extern "C" fn serialize(this: &AnyOperation) -> Result<FFIBox<[u8]>, ()>;
87 unsafe extern "C" fn deserialize(src: &[u8]) -> Result<AnyOperation, ()>;
88 unsafe extern "C" fn is_same(this: AnyObject) -> bool;
89 unsafe extern "C" fn serialize_success(success: ()) -> Result<FFIBox<[u8]>, ()>;
90 unsafe extern "C" fn serialize_failure(failure: ()) -> Result<FFIBox<[u8]>, ()>;
91 unsafe extern "C" fn deserialize_success(src: &[u8]) -> Result<AnySuccess, ()>;
92 unsafe extern "C" fn deserialize_failure(src: &[u8]) -> Result<AnyFailure, ()>;
93 }
94
95 impl<O, D> IntoOperationVTable<O> for D
96 where
97 D: GiteratedOperation<O>,
98 O: GiteratedObject,
99 {
100 unsafe extern "C" fn serialize(this: &AnyOperation) -> Result<FFIBox<[u8]>, ()> {
101 todo!()
102 }
103
104 unsafe extern "C" fn deserialize(src: &[u8]) -> Result<AnyOperation, ()> {
105 let deserialized: D = serde_json::from_slice(src).unwrap();
106
107 Ok(AnyOperation {
108 inner: FFIBox::from_box(Box::new(deserialized)).untyped(),
109 vtable: OperationVTable::new::<O, D>(),
110 })
111 }
112
113 unsafe extern "C" fn is_same(this: AnyObject) -> bool {
114 todo!()
115 }
116
117 unsafe extern "C" fn serialize_success(success: ()) -> Result<FFIBox<[u8]>, ()> {
118 todo!()
119 }
120
121 unsafe extern "C" fn serialize_failure(failure: ()) -> Result<FFIBox<[u8]>, ()> {
122 todo!()
123 }
124
125 unsafe extern "C" fn deserialize_success(src: &[u8]) -> Result<AnySuccess, ()> {
126 todo!()
127 }
128
129 unsafe extern "C" fn deserialize_failure(src: &[u8]) -> Result<AnyFailure, ()> {
130 todo!()
131 }
132
133 fn operation_kind() -> &'static str {
134 todo!()
135 }
136 }

giterated-plugins/giterated-plugin/src/vtable/setting.rs

View file
@@ -0,0 +1,66 @@
1 use std::mem::transmute;
2
3 use giterated_models::settings::Setting;
4
5 use crate::FFIBox;
6
7 #[repr(C)]
8 pub struct NewAnySetting {
9 /// A pointer to the plugin-local object type. We are not capable of
10 /// knowing what this type is, we use the provided vtable.
11 inner: FFIBox<()>,
12 vtable: SettingVtable,
13 }
14
15 impl NewAnySetting {
16 pub fn new<V: IntoSettingVTable>(value: V) -> Self {
17 Self {
18 inner: FFIBox::from_box(Box::new(value)).untyped(),
19 vtable: SettingVtable::new::<V>(),
20 }
21 }
22
23 pub unsafe fn transmute_owned<T>(self) -> Box<T> {
24 Box::from_raw(self.inner.0 as *mut T)
25 }
26
27 pub unsafe fn transmute_ref<T>(&self) -> &T {
28 let ptr: *const T = transmute(self.inner.0);
29
30 ptr.as_ref().unwrap()
31 }
32 }
33
34 #[derive(Clone, Copy)]
35 #[repr(C)]
36 pub struct SettingVtable {
37 pub deserialize: unsafe extern "C" fn(&[u8]) -> Result<(), ()>,
38 pub serialize: unsafe extern "C" fn(NewAnySetting) -> Result<FFIBox<[u8]>, ()>,
39 }
40
41 impl SettingVtable {
42 pub fn new<T: IntoSettingVTable>() -> Self {
43 Self {
44 deserialize: T::deserialize,
45 serialize: T::serialize,
46 }
47 }
48 }
49
50 pub trait IntoSettingVTable {
51 unsafe extern "C" fn deserialize(src: &[u8]) -> Result<(), ()>;
52 unsafe extern "C" fn serialize(this: NewAnySetting) -> Result<FFIBox<[u8]>, ()>;
53 }
54
55 impl<S> IntoSettingVTable for S
56 where
57 S: Setting,
58 {
59 unsafe extern "C" fn deserialize(src: &[u8]) -> Result<(), ()> {
60 todo!()
61 }
62
63 unsafe extern "C" fn serialize(this: NewAnySetting) -> Result<FFIBox<[u8]>, ()> {
64 todo!()
65 }
66 }

giterated-plugins/giterated-plugin/src/vtable/value.rs

View file
@@ -0,0 +1,67 @@
1 use giterated_models::{object::GiteratedObject, value::GiteratedObjectValue};
2
3 use crate::FFIBox;
4
5 #[repr(C)]
6 pub struct NewAnyValue {
7 /// A pointer to the plugin-local object type. We are not capable of
8 /// knowing what this type is, we use the provided vtable.
9 inner: FFIBox<()>,
10 vtable: ValueVTable,
11 }
12
13 impl NewAnyValue {
14 pub fn new<O, V: IntoValueVTable<O>>(value: V) -> Self {
15 NewAnyValue {
16 inner: FFIBox::from_box(Box::new(value)).untyped(),
17 vtable: ValueVTable::new::<O, V>(),
18 }
19 }
20 }
21
22 #[derive(Clone, Copy)]
23 #[repr(C)]
24 pub struct ValueVTable {
25 pub deserialize: unsafe extern "C" fn(&[u8]) -> Result<NewAnyValue, ()>,
26 pub serialize: unsafe extern "C" fn(NewAnyValue) -> Result<FFIBox<[u8]>, ()>,
27 }
28
29 impl ValueVTable {
30 pub fn new<O, T: IntoValueVTable<O>>() -> Self {
31 Self {
32 deserialize: T::deserialize,
33 serialize: T::serialize,
34 }
35 }
36 }
37
38 pub trait IntoValueVTable<O> {
39 unsafe extern "C" fn deserialize(src: &[u8]) -> Result<NewAnyValue, ()>;
40 unsafe extern "C" fn serialize(this: NewAnyValue) -> Result<FFIBox<[u8]>, ()>;
41 }
42
43 impl<O, V> IntoValueVTable<O> for V
44 where
45 O: GiteratedObject,
46 V: GiteratedObjectValue<Object = O>,
47 {
48 unsafe extern "C" fn deserialize(src: &[u8]) -> Result<NewAnyValue, ()> {
49 let _guard = trace_span!(
50 "deserialize value",
51 object = O::object_name(),
52 value = V::value_name()
53 );
54
55 trace!("Deserializing");
56 let deserialized: V = serde_json::from_slice(src).unwrap();
57
58 Ok(NewAnyValue {
59 inner: FFIBox::from_box(Box::new(deserialized)).untyped(),
60 vtable: ValueVTable::new::<O, V>(),
61 })
62 }
63
64 unsafe extern "C" fn serialize(this: NewAnyValue) -> Result<FFIBox<[u8]>, ()> {
65 todo!()
66 }
67 }

giterated-plugins/giterated-protocol/Cargo.toml

View file
@@ -0,0 +1,30 @@
1 [package]
2 name = "giterated-protocol"
3 version = "0.1.0"
4 edition = "2021"
5
6 [lib]
7 name = "giterated_protocol_plugin"
8 path = "src/lib.rs"
9 crate-type = ["dylib", "rlib"]
10
11 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
12
13 [dependencies]
14 giterated-plugin = { path = "../giterated-plugin" }
15 giterated-models = { path = "../../giterated-models" }
16 serde = { version = "1.0", features = [ "derive" ]}
17 anyhow = "1"
18 giterated-plugin-sys = { path = "../giterated-plugin-sys" }
19 toml = { version = "0.7" }
20 tracing = "0.1"
21 tracing-subscriber = "0.3"
22 serde_json = "1.0"
23 rand = "0.8"
24 rsa = {version = "0.9", features = ["sha2"]}
25 tokio-tungstenite = { version = "0.20" }
26 tokio = { version = "1.32.0", features = ["full"] }
27 thiserror = "1"
28 bincode = "1.3"
29 futures-util = "0.3"
30 async-trait = "0.1"
30 \ No newline at end of file

giterated-plugins/giterated-protocol/src/handlers.rs

View file
@@ -0,0 +1,255 @@
1 use std::{fmt::Display, net::SocketAddr, str::FromStr, sync::Arc};
2
3 use anyhow::Error;
4 use futures_util::{SinkExt, StreamExt};
5 use giterated_models::{
6 error::{NetworkOperationError, OperationError},
7 instance::Instance,
8 object::GiteratedObject,
9 operation::GiteratedOperation,
10 };
11 use giterated_plugin::{
12 new_stack::{runtime_handler::RuntimeHandle, Runtime},
13 AnyFailure, AnyObject, AnyOperation, AnySuccess,
14 };
15 use serde::{Deserialize, Serialize};
16 use tokio::net::TcpStream;
17 use tokio_tungstenite::{connect_async, tungstenite::Message, MaybeTlsStream, WebSocketStream};
18
19 use crate::{Authenticated, GiteratedMessage, ProtocolState, RemoteError};
20
21 pub async fn handle_network_operation<OS: Send + Sync + Clone + 'static>(
22 state: ProtocolState,
23 object: NetworkedObject,
24 operation: NetworkedOperation,
25 runtime: RuntimeHandle,
26 ) -> Result<Vec<u8>, OperationError<Vec<u8>>> {
27 trace!("Handle network operation {}", operation.name);
28
29 runtime
30 .handle_serialized(&object.0, &operation.name, &operation.payload)
31 .await
32 }
33
34 #[derive(Clone, Debug, Serialize, Deserialize)]
35 pub struct NetworkedObject(pub String);
36
37 impl FromStr for NetworkedObject {
38 type Err = ();
39
40 fn from_str(s: &str) -> Result<Self, Self::Err> {
41 Ok(NetworkedObject(s.to_string()))
42 }
43 }
44
45 impl Display for NetworkedObject {
46 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
47 f.write_str(&self.0)
48 }
49 }
50
51 impl GiteratedObject for NetworkedObject {
52 fn object_name() -> &'static str {
53 "networked_object"
54 }
55
56 fn from_object_str(_object_str: &str) -> Result<Self, Error> {
57 todo!()
58 }
59
60 fn home_uri(&self) -> String {
61 todo!()
62 }
63 }
64
65 #[derive(Clone, Debug, Serialize, Deserialize)]
66 pub struct NetworkedOperation {
67 pub name: String,
68 pub payload: Vec<u8>,
69 }
70
71 impl NetworkedOperation {
72 pub fn new(name: String, payload: Vec<u8>) -> Self {
73 Self { name, payload }
74 }
75 }
76
77 impl GiteratedOperation<NetworkedObject> for NetworkedOperation {
78 type Success = Vec<u8>;
79
80 type Failure = Vec<u8>;
81
82 fn operation_name() -> &'static str {
83 "networked_operation"
84 }
85 }
86
87 /// Handler which will attempt to resolve any operation that doesn't resolve locally
88 /// against a remote instance.
89 pub async fn try_handle_with_remote<OS>(
90 state: ProtocolState,
91 object: AnyObject,
92 operation: AnyOperation,
93 ) -> Result<AnySuccess, OperationError<AnyFailure>> {
94 // if object.is::<NetworkedObject>() {
95 // return Err(OperationError::Unhandled);
96 // }
97 // trace!(
98 // "Try handling object operation {}::{} with remote",
99 // object.kind(),
100 // operation.kind().operation_name
101 // );
102 // TODO:
103 // Ideally we support pass-through on object types that aren't used locally.
104 // For now, we aren't worrying about that.
105 let object_meta = object.vtable().clone();
106
107 let operation_meta = operation.vtable().clone();
108
109 // trace!(
110 // "Serializing with {}::{}",
111 // operation.kind().object_name,
112 // operation.kind().operation_name
113 // );
114
115 let object_home_uri = unsafe { (object_meta.home_uri)(&object) };
116
117 if let Some(home_uri) = state.home_uri {
118 if &home_uri == object_home_uri.as_ref() {
119 // This isn't a remote request, requests aren't supposed to hit this layer
120 // if they're not remote.
121 // warn!("Try handling object operation {}::{}, resolved object home uri as local home uri. This is a bug.", object.kind(),
122 // operation.kind().operation_name);
123
124 return Err(OperationError::Unhandled);
125 }
126 }
127
128 // trace!(
129 // "Handling object operation {}::{} sending payload",
130 // object.kind(),
131 // operation.kind().operation_name
132 // );
133
134 let object = NetworkedObject(unsafe { (object_meta.to_str)(object).as_ref().to_string() });
135
136 let payload = unsafe { (operation_meta.serialize)(&operation) }.unwrap();
137 let payload = Vec::from(payload.as_ref());
138
139 let operation = NetworkedOperation::new(operation_meta.kind().to_string(), payload);
140
141 // let authenticated = Authenticated::new(object, operation);
142
143 let message = GiteratedMessage {
144 object,
145 operation: NetworkedOperation::operation_name().to_string(),
146 payload: operation,
147 };
148
149 let authenticated = Authenticated::new(message);
150
151 let mut socket: WebSocketStream<MaybeTlsStream<TcpStream>> = connect_to(
152 &Instance::from_str(&object_home_uri).unwrap(),
153 &Some(("127.0.0.1:1111").parse().unwrap()),
154 )
155 .await
156 .unwrap();
157
158 // TODO AUTH
159
160 let result: Result<Vec<u8>, OperationError<Vec<u8>>> =
161 send_expect(&mut socket, authenticated).await;
162
163 match result {
164 Ok(success) => {
165 let success = unsafe { (operation_meta.deserialize_success)(&success) }.unwrap();
166
167 Ok(success)
168 }
169 Err(err) => Err(match err {
170 OperationError::Operation(failure) => {
171 let failure = unsafe { (operation_meta.deserialize_failure)(&failure) }.unwrap();
172
173 OperationError::Operation(failure)
174 }
175 OperationError::Internal(internal) => OperationError::Internal(internal),
176 OperationError::Unhandled => OperationError::Unhandled,
177 }),
178 }
179 }
180
181 type Socket = WebSocketStream<MaybeTlsStream<TcpStream>>;
182
183 async fn connect_to(
184 instance: &Instance,
185
186 socket_addr: &Option<SocketAddr>,
187 ) -> Result<Socket, Error> {
188 if let Some(addr) = socket_addr {
189 info!(
190 "Connecting to {}",
191 format!("ws://{}/.giterated/daemon/", addr)
192 );
193
194 let (websocket, _response) =
195 connect_async(&format!("ws://{}/.giterated/daemon/", addr)).await?;
196
197 info!("Connection established with {}", addr);
198
199 Ok(websocket)
200 } else {
201 info!(
202 "Connecting to {}",
203 format!("wss://{}/.giterated/daemon/", instance.0)
204 );
205
206 let (websocket, _response) =
207 connect_async(&format!("wss://{}/.giterated/daemon/", instance.0)).await?;
208
209 info!("Connection established with {}", instance.0);
210
211 Ok(websocket)
212 }
213 }
214
215 async fn send_expect<O: GiteratedObject, D: GiteratedOperation<O>>(
216 socket: &mut Socket,
217 message: Authenticated<O, D>,
218 ) -> Result<Vec<u8>, OperationError<Vec<u8>>> {
219 let payload = bincode::serialize(&message.into_payload()).unwrap();
220
221 socket.send(Message::Binary(payload)).await.unwrap();
222
223 while let Some(message) = socket.next().await {
224 let payload = match message.unwrap() {
225 Message::Binary(payload) => payload,
226
227 _ => {
228 continue;
229 }
230 };
231
232 let raw_result =
233 bincode::deserialize::<Result<Vec<u8>, NetworkOperationError<Vec<u8>>>>(&payload)
234 .map_err(|e| OperationError::Internal(Error::from(e)))?;
235
236 trace!(
237 "Received response for networked operation {}::{}.",
238 O::object_name(),
239 D::operation_name()
240 );
241
242 return match raw_result {
243 Ok(success) => Ok(success),
244 Err(err) => Err(match err {
245 NetworkOperationError::Operation(operation_error) => {
246 OperationError::Operation(operation_error)
247 }
248 NetworkOperationError::Internal => OperationError::Internal(RemoteError.into()),
249 NetworkOperationError::Unhandled => OperationError::Unhandled,
250 }),
251 };
252 }
253
254 panic!()
255 }

giterated-plugins/giterated-protocol/src/lib.rs

View file
@@ -0,0 +1,259 @@
1 use std::{str::FromStr, sync::Arc};
2
3 use giterated_models::{
4 authenticated::{InstanceSignature, UserAuthenticationToken},
5 instance::Instance,
6 object::GiteratedObject,
7 operation::GiteratedOperation,
8 user::User,
9 };
10 use handlers::{NetworkedObject, NetworkedOperation};
11 use object::NetworkAnyObject;
12 use operations::NetworkAnyOperation;
13 use rsa::{
14 pkcs1::DecodeRsaPrivateKey,
15 pss::SigningKey,
16 sha2::Sha256,
17 signature::{RandomizedSigner, SignatureEncoding},
18 RsaPrivateKey,
19 };
20 use serde::{Deserialize, Serialize};
21 use std::fmt::Debug;
22
23 pub mod handlers;
24 pub mod object;
25 pub mod operations;
26
27 #[macro_use]
28 extern crate tracing;
29
30 #[derive(Clone)]
31 pub struct NetworkOperationState {
32 authentication: Vec<Arc<dyn AuthenticationSourceProviders + Send + Sync>>,
33 }
34
35 impl NetworkOperationState {
36 pub fn new() -> Self {
37 Self {
38 authentication: vec![],
39 }
40 }
41
42 pub fn authenticate(
43 &mut self,
44 provider: impl AuthenticationSourceProviders + Send + Sync + 'static,
45 ) {
46 self.authentication.push(Arc::new(provider))
47 }
48 }
49
50 #[derive(Debug, Clone, Hash, PartialEq, Eq, Serialize, Deserialize)]
51 pub struct AuthenticatedPayload {
52 pub source: Vec<AuthenticationSource>,
53 pub object: String,
54 pub operation: String,
55 pub payload: Vec<u8>,
56 }
57
58 impl AuthenticatedPayload {
59 pub fn into_message(self) -> GiteratedMessage<NetworkedObject, NetworkedOperation> {
60 GiteratedMessage {
61 object: NetworkedObject::from_str(&self.object).unwrap(),
62 operation: self.operation,
63 payload: serde_json::from_slice(&self.payload).unwrap(),
64 }
65 }
66 }
67
68 pub trait AuthenticationSourceProvider: Debug {
69 fn authenticate(&self, payload: &Vec<u8>) -> AuthenticationSource;
70 }
71
72 pub trait AuthenticationSourceProviders: Debug {
73 fn authenticate_all(&self, payload: &Vec<u8>) -> Vec<AuthenticationSource>;
74 }
75
76 impl<A> AuthenticationSourceProviders for A
77 where
78 A: AuthenticationSourceProvider,
79 {
80 fn authenticate_all(&self, payload: &Vec<u8>) -> Vec<AuthenticationSource> {
81 vec![self.authenticate(payload)]
82 }
83 }
84
85 impl<A, B> AuthenticationSourceProviders for (A, B)
86 where
87 A: AuthenticationSourceProvider,
88 B: AuthenticationSourceProvider,
89 {
90 fn authenticate_all(&self, payload: &Vec<u8>) -> Vec<AuthenticationSource> {
91 let (first, second) = self;
92
93 vec![first.authenticate(payload), second.authenticate(payload)]
94 }
95 }
96
97 #[derive(Clone, Debug)]
98 pub struct UserAuthenticator {
99 pub user: User,
100 pub token: UserAuthenticationToken,
101 }
102
103 impl AuthenticationSourceProvider for UserAuthenticator {
104 fn authenticate(&self, _payload: &Vec<u8>) -> AuthenticationSource {
105 AuthenticationSource::User {
106 user: self.user.clone(),
107 token: self.token.clone(),
108 }
109 }
110 }
111
112 #[derive(Debug, Clone)]
113 pub struct InstanceAuthenticator {
114 pub instance: Instance,
115 pub private_key: String,
116 }
117
118 impl AuthenticationSourceProvider for InstanceAuthenticator {
119 fn authenticate(&self, payload: &Vec<u8>) -> AuthenticationSource {
120 let mut rng = rand::thread_rng();
121
122 let private_key = RsaPrivateKey::from_pkcs1_pem(&self.private_key).unwrap();
123 let signing_key = SigningKey::<Sha256>::new(private_key);
124 let signature = signing_key.sign_with_rng(&mut rng, payload);
125
126 AuthenticationSource::Instance {
127 instance: self.instance.clone(),
128 // TODO: Actually parse signature from private key
129 signature: InstanceSignature(signature.to_bytes().into_vec()),
130 }
131 }
132 }
133
134 #[derive(Clone, Debug, Hash, PartialEq, Eq, Serialize, Deserialize)]
135 pub enum AuthenticationSource {
136 User {
137 user: User,
138 token: UserAuthenticationToken,
139 },
140 Instance {
141 instance: Instance,
142 signature: InstanceSignature,
143 },
144 }
145
146 #[derive(Serialize)]
147 #[serde(bound(deserialize = "O: GiteratedObject, V: GiteratedOperation<O>"))]
148 pub struct GiteratedMessage<O: GiteratedObject, V: GiteratedOperation<O>> {
149 #[serde(with = "string")]
150 pub object: O,
151 pub operation: String,
152 pub payload: V,
153 }
154
155 #[allow(unused)]
156 mod string {
157 use std::fmt::Display;
158 use std::str::FromStr;
159
160 use serde::{de, Deserialize, Deserializer, Serializer};
161
162 pub fn serialize<T, S>(value: &T, serializer: S) -> Result<S::Ok, S::Error>
163 where
164 T: Display,
165 S: Serializer,
166 {
167 serializer.collect_str(value)
168 }
169
170 pub fn deserialize<'de, T, D>(deserializer: D) -> Result<T, D::Error>
171 where
172 T: FromStr,
173 T::Err: Display,
174 D: Deserializer<'de>,
175 {
176 String::deserialize(deserializer)?
177 .parse()
178 .map_err(de::Error::custom)
179 }
180 }
181
182 impl GiteratedMessage<NetworkAnyObject, NetworkAnyOperation> {
183 pub fn try_into<O: GiteratedObject, V: GiteratedOperation<O>>(
184 &self,
185 ) -> Result<GiteratedMessage<O, V>, ()> {
186 let object = O::from_object_str(&self.object.0).map_err(|_| ())?;
187 let payload = serde_json::from_slice::<V>(&self.payload.0).map_err(|_| ())?;
188
189 Ok(GiteratedMessage {
190 object,
191 operation: self.operation.clone(),
192 payload,
193 })
194 }
195 }
196
197 impl<V: GiteratedOperation<O> + Debug, O: GiteratedObject + Debug> Debug
198 for GiteratedMessage<O, V>
199 {
200 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
201 f.debug_struct("GiteratedMessage")
202 .field("object", &self.object)
203 .field("operation", &self.operation)
204 .field("payload", &self.payload)
205 .finish()
206 }
207 }
208
209 #[derive(Debug, Clone, thiserror::Error)]
210 #[error("a remote internal error occurred")]
211 pub struct RemoteError;
212
213 #[derive(Debug, thiserror::Error)]
214 #[error("a remote internal error occurred")]
215
216 pub struct NetworkError;
217
218 #[derive(Debug)]
219 pub struct Authenticated<O: GiteratedObject, D: GiteratedOperation<O>> {
220 pub source: Vec<Arc<dyn AuthenticationSourceProviders + Send + Sync>>,
221 pub message: GiteratedMessage<O, D>,
222 }
223
224 impl<O: GiteratedObject, D: GiteratedOperation<O>> Authenticated<O, D> {
225 pub fn new(message: GiteratedMessage<O, D>) -> Self {
226 Self {
227 source: vec![],
228 message,
229 }
230 }
231
232 pub fn append_authentication(
233 &mut self,
234 authentication: Arc<dyn AuthenticationSourceProviders + Send + Sync>,
235 ) {
236 self.source.push(authentication);
237 }
238
239 pub fn into_payload(mut self) -> AuthenticatedPayload {
240 let payload = serde_json::to_vec(&self.message.payload).unwrap();
241
242 AuthenticatedPayload {
243 object: self.message.object.to_string(),
244 operation: self.message.operation,
245 source: self
246 .source
247 .drain(..)
248 .map(|provider| provider.as_ref().authenticate_all(&payload))
249 .flatten()
250 .collect::<Vec<_>>(),
251 payload,
252 }
253 }
254 }
255
256 #[derive(Clone, Debug)]
257 pub struct ProtocolState {
258 pub home_uri: Option<String>,
259 }

giterated-plugins/giterated-protocol/src/object.rs

View file
@@ -0,0 +1,38 @@
1 use std::{convert::Infallible, fmt::Display, str::FromStr};
2
3 use anyhow::Error;
4 use giterated_models::object::GiteratedObject;
5 use serde::{Deserialize, Serialize};
6
7 #[derive(Clone, Debug, Serialize, Deserialize)]
8 #[serde(transparent)]
9 #[repr(transparent)]
10 pub struct NetworkAnyObject(pub String);
11
12 impl GiteratedObject for NetworkAnyObject {
13 fn object_name() -> &'static str {
14 "network_object"
15 }
16
17 fn from_object_str(object_str: &str) -> Result<Self, Error> {
18 Ok(Self(object_str.to_string()))
19 }
20
21 fn home_uri(&self) -> String {
22 todo!()
23 }
24 }
25
26 impl Display for NetworkAnyObject {
27 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28 f.write_str(&self.0)
29 }
30 }
31
32 impl FromStr for NetworkAnyObject {
33 type Err = Infallible;
34
35 fn from_str(s: &str) -> Result<Self, Self::Err> {
36 Ok(Self(s.to_owned()))
37 }
38 }

giterated-plugins/giterated-protocol/src/operations.rs

View file
@@ -0,0 +1,13 @@
1 use giterated_models::{object::GiteratedObject, operation::GiteratedOperation};
2 use serde::{Deserialize, Serialize};
3
4 #[derive(Clone, Debug, Serialize, Deserialize)]
5 #[serde(transparent)]
6 #[repr(transparent)]
7 pub struct NetworkAnyOperation(pub Vec<u8>);
8
9 impl<O: GiteratedObject> GiteratedOperation<O> for NetworkAnyOperation {
10 type Success = Vec<u8>;
11
12 type Failure = Vec<u8>;
13 }

giterated-protocol/Cargo.toml

View file
@@ -1,5 +1,5 @@
1 1 [package]
2 name = "giterated-protocol"
2 name = "giterated-protocol-old"
3 3 version = "0.1.0"
4 4 authors = ["Amber Kowalski"]
5 5 edition = "2021"

giterated-stack/src/lib.rs

View file
@@ -421,7 +421,6 @@ impl<A: AuthorizedOperation<Instance> + Send + Sync> FromOperationState<Instance
421 421 #[derive(Clone)]
422 422 pub struct StackOperationState {
423 423 pub our_instance: Instance,
424 pub runtime: GiteratedStack<StackOperationState>,
425 424 pub instance: Option<AuthenticatedInstance>,
426 425 pub user: Option<AuthenticatedUser>,
427 426 }