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

ambee/giterated

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

Set up the daemon for the plugin architecture

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨d046615

Showing ⁨⁨8⁩ changed files⁩ with ⁨⁨106⁩ insertions⁩ and ⁨⁨27⁩ deletions⁩

Cargo.lock

View file
@@ -819,6 +819,7 @@ dependencies = [
819 819 "git2",
820 820 "giterated-models",
821 821 "giterated-plugin",
822 "giterated-protocol",
822 823 "jsonwebtoken",
823 824 "log",
824 825 "rand",
@@ -885,6 +886,7 @@ name = "giterated-plugin"
885 886 version = "0.1.0"
886 887 dependencies = [
887 888 "anyhow",
889 "async-trait",
888 890 "dlopen2",
889 891 "giterated-models",
890 892 "semver",

giterated-daemon/Cargo.toml

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

giterated-daemon/src/client.rs

View file
@@ -6,8 +6,11 @@ use giterated_models::{
6 6 instance::Instance,
7 7 object_backend::ObjectBackend,
8 8 };
9 use giterated_plugin::new_stack::Runtime;
10 use giterated_protocol::{AuthenticatedPayload, NetworkedObject, NetworkedOperation};
9 use giterated_plugin::new_stack::{runtime_handler::RuntimeHandle, Runtime};
10 use giterated_protocol::{
11 handlers::{NetworkedObject, NetworkedOperation},
12 AuthenticatedPayload, StackOperationState,
13 };
11 14 use tokio::net::TcpStream;
12 15 use tokio_tungstenite::{tungstenite::Message, WebSocketStream};
13 16
@@ -94,13 +97,13 @@ pub async fn client_wrapper(
94 97
95 98 pub async fn handle_client_message(
96 99 payload: AuthenticatedPayload,
97 // operation_state: StackOperationState,
98 runtime: Arc<Runtime>,
100 operation_state: StackOperationState,
101 runtime: RuntimeHandle,
99 102 ) -> Result<Vec<u8>, OperationError<Vec<u8>>> {
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")?;
103 let mut networked_object = runtime
104 .get_object::<NetworkedObject>(&payload.object, &operation_state)
105 .await
106 .as_internal_error_with_context("handling client message")?;
104 107
105 108 let message: giterated_protocol::GiteratedMessage<NetworkedObject, NetworkedOperation> =
106 109 payload.into_message();
@@ -112,9 +115,7 @@ pub async fn handle_client_message(
112 115
113 116 trace!("Calling handler for networked operation");
114 117
115 // networked_object
116 // .request(networked_operation, &operation_state)
117 // .await
118
119 todo!()
118 networked_object
119 .request(networked_operation, &operation_state)
120 .await
120 121 }

giterated-daemon/src/main.rs

View file
@@ -4,7 +4,6 @@ use giterated_daemon::{authentication::AuthenticationTokenGranter, client::clien
4 4 use giterated_models::instance::Instance;
5 5
6 6 use giterated_plugin::new_stack::Runtime;
7 use giterated_protocol::NetworkedSubstack;
8 7 use sqlx::{postgres::PgConnectOptions, ConnectOptions, PgPool};
9 8 use std::{net::SocketAddr, str::FromStr, sync::Arc};
10 9 use tokio::{
@@ -52,14 +51,6 @@ async fn main() -> Result<(), Error> {
52 51
53 52 let mut runtime = Runtime::default();
54 53
55 let networked_stack = NetworkedSubstack {
56 home_uri: Some(
57 Instance::from_str(config["giterated"]["instance"].as_str().unwrap())
58 .unwrap()
59 .0,
60 ),
61 };
62
63 54 let runtime = Arc::new(runtime);
64 55
65 56 let pool = LocalPoolHandle::new(5);

giterated-plugins/giterated-plugin/Cargo.toml

View file
@@ -12,4 +12,5 @@ thiserror = "1"
12 12 tracing = "0.1"
13 13 giterated-models = { path = "../../giterated-models" }
14 14 semver = "*"
15 serde_json = "1.0"
15 \ No newline at end of file
15 serde_json = "1.0"
16 async-trait = "0.1"

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

View file
@@ -1,9 +1,20 @@
1 use giterated_models::error::OperationError;
1 use std::fmt::Debug;
2 use std::sync::Arc;
3
4 use giterated_models::{
5 error::OperationError,
6 object::{GiteratedObject, Object, ObjectRequestError},
7 object_backend::ObjectBackend,
8 operation::GiteratedOperation,
9 };
2 10
3 11 use crate::vtable::{AnyFailure, AnySuccess, OperationVTable};
4 12
13 use super::PluginState;
14
15 #[derive(Clone)]
5 16 pub struct RuntimeHandle {
6 inner: RuntimeHandleInner,
17 inner: Arc<RuntimeHandleInner>,
7 18 }
8 19
9 20 impl RuntimeHandle {
@@ -19,6 +30,7 @@ impl RuntimeHandle {
19 30
20 31 #[repr(C)]
21 32 struct RuntimeHandleInner {
33 state: PluginState,
22 34 handle_serialized: unsafe extern "C" fn(
23 35 object_kind: &str,
24 36 operation_name: &str,
@@ -27,8 +39,38 @@ struct RuntimeHandleInner {
27 39 ) -> HandlerResult,
28 40 }
29 41
42 unsafe impl Send for RuntimeHandleInner {}
43 unsafe impl Sync for RuntimeHandleInner {}
44
30 45 #[repr(C)]
31 46 struct HandlerResult {
32 47 operation_vtable: OperationVTable,
33 48 result: Result<AnySuccess, OperationError<AnyFailure>>,
34 49 }
50
51 #[async_trait::async_trait(?Send)]
52 impl<S: Send + Sync + Clone> ObjectBackend<S> for RuntimeHandle {
53 async fn object_operation<O, D>(
54 &self,
55 object: O,
56 operation: &str,
57 payload: D,
58 operation_state: &S,
59 ) -> Result<D::Success, OperationError<D::Failure>>
60 where
61 O: GiteratedObject + Debug + 'static,
62 D: GiteratedOperation<O> + Debug + 'static,
63 D::Success: Clone,
64 D::Failure: Clone,
65 {
66 todo!()
67 }
68
69 async fn get_object<O: GiteratedObject + Debug + 'static>(
70 &self,
71 object_str: &str,
72 operation_state: &S,
73 ) -> Result<Object<S, O, Self>, OperationError<ObjectRequestError>> {
74 todo!()
75 }
76 }

giterated-plugins/giterated-protocol/Cargo.toml

View file
@@ -4,7 +4,7 @@ version = "0.1.0"
4 4 edition = "2021"
5 5
6 6 [lib]
7 name = "giterated_protocol_plugin"
7 name = "giterated_protocol"
8 8 path = "src/lib.rs"
9 9 crate-type = ["dylib", "rlib"]
10 10

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

View file
@@ -1,4 +1,4 @@
1 use std::{str::FromStr, sync::Arc};
1 use std::{ops::Deref, str::FromStr, sync::Arc};
2 2
3 3 use giterated_models::{
4 4 authenticated::{InstanceSignature, UserAuthenticationToken},
@@ -28,6 +28,47 @@ pub mod operations;
28 28 extern crate tracing;
29 29
30 30 #[derive(Clone)]
31 pub struct StackOperationState {
32 pub our_instance: Instance,
33 pub instance: Option<AuthenticatedInstance>,
34 pub user: Option<AuthenticatedUser>,
35 }
36
37 #[derive(Clone, Debug)]
38 pub struct AuthenticatedInstance(Instance);
39
40 impl AuthenticatedInstance {
41 pub fn new(instance: Instance) -> Self {
42 AuthenticatedInstance(instance)
43 }
44 }
45
46 impl Deref for AuthenticatedInstance {
47 type Target = Instance;
48
49 fn deref(&self) -> &Self::Target {
50 &self.0
51 }
52 }
53
54 #[derive(Clone, Debug)]
55 pub struct AuthenticatedUser(User);
56
57 impl AuthenticatedUser {
58 pub fn new(user: User) -> Self {
59 AuthenticatedUser(user)
60 }
61 }
62
63 impl Deref for AuthenticatedUser {
64 type Target = User;
65
66 fn deref(&self) -> &Self::Target {
67 &self.0
68 }
69 }
70
71 #[derive(Clone)]
31 72 pub struct NetworkOperationState {
32 73 authentication: Vec<Arc<dyn AuthenticationSourceProviders + Send + Sync>>,
33 74 }