Skip to content

Commit 055c1fd

Browse files
author
benbot
committed
more changes, working on subdomain router
1 parent 596bd52 commit 055c1fd

File tree

7 files changed

+171
-123
lines changed

7 files changed

+171
-123
lines changed

Cargo.lock

Lines changed: 1 addition & 70 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

orb-runtime/src/lib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
use std::{collections::HashMap, ptr::null};
1+
use std::collections::HashMap;
22

3-
use uuid::uuid;
43
use wasmtime::*;
54

65
#[derive(Clone, Copy, Debug)]
@@ -99,7 +98,7 @@ impl Runtime {
9998

10099
pub fn add_module(&mut self, name: &str, bytes: &[u8]) -> wasmtime::Result<()> {
101100
let module = Module::from_binary(self.get_engine(), bytes).unwrap();
102-
let result = self.modules.insert(name.to_string(), module.clone());
101+
self.modules.insert(name.to_string(), module.clone());
103102

104103
let nuuid = uuid::Uuid::new_v4().to_string();
105104
println!("nuuid: {}", nuuid);
@@ -110,7 +109,6 @@ impl Runtime {
110109
match result {
111110
Some(_) => Err(wasmtime::Error::msg("asdf")),
112111
None => Ok(()),
113-
_ => unreachable!(),
114112
}
115113
}
116114

orb-server/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ maud = "0.25.0"
1111
reqwest = { version = "0.11.18", features = ["multipart"] }
1212
tokio = { version = "1.29.1", features = ["macros", "rt-multi-thread", "net", "sync"] }
1313
orb-runtime = { path = "../orb-runtime" }
14-
diesel = { version = "2.1.0", features = [ "sqlite" ] }
1514
uuid = { version = "1.4.1", features = ["fast-rng", "v4"] }
15+
tower = "0.4.13"

orb-server/src/app_subrouter.rs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
use std::{convert::Infallible, task::Poll};
2+
3+
use axum::{http::Request, body::{HttpBody, Body}, response::Response, routing::future::RouteFuture, Router};
4+
use tower::{Service, Layer};
5+
6+
use crate::RuntimeDb;
7+
8+
#[derive(Clone)]
9+
pub struct Subrouter<S> {
10+
inner: S,
11+
runtime_db: RuntimeDb,
12+
}
13+
14+
impl<S> Subrouter<S> {
15+
fn new(inner: S, runtime_db: RuntimeDb) -> Self {
16+
Self {
17+
inner,
18+
runtime_db,
19+
}
20+
}
21+
}
22+
23+
async fn route_subdomain(subdomain: String) -> Result<(), Infallible> {
24+
todo!()
25+
// match subdomain {
26+
// crate::config::HOSTNAME => self.inner.call_with_state(req, self.runtime_db.clone()),
27+
// _ => {
28+
// let runtime_db = rt.block_on((*self.runtime_db).lock());
29+
// let orb = runtime_db.get(subdomain).unwrap();
30+
// orb.router.call(req)
31+
// },
32+
// }
33+
}
34+
35+
impl<S, B> Service<Request<B>> for Subrouter<S>
36+
where S: Service<Request<B>>,
37+
S::Future: Into<RouteFuture<Response, Infallible>>,
38+
{
39+
40+
type Response = Response;
41+
42+
type Error = Infallible;
43+
44+
type Future = RouteFuture<Response, Self::Error>;
45+
46+
fn poll_ready(&mut self, cx: &mut std::task::Context<'_>) -> Poll<Result<(), Self::Error>> {
47+
Poll::Ready(Ok(()))
48+
}
49+
50+
fn call(&mut self, req: Request<B>) -> Self::Future {
51+
self.inner.call(req).into()
52+
}
53+
}
54+
55+
56+
#[derive(Clone)]
57+
pub struct SubrouterLayer {
58+
runtime_db: RuntimeDb
59+
}
60+
61+
impl SubrouterLayer {
62+
pub fn new(runtime_db: RuntimeDb) -> Self {
63+
Self { runtime_db }
64+
}
65+
}
66+
67+
impl<S> Layer<S> for SubrouterLayer {
68+
type Service = Subrouter<S>;
69+
70+
fn layer(&self, inner: S) -> Self::Service {
71+
Subrouter::new(inner, self.runtime_db.clone())
72+
}
73+
}

orb-server/src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub const HOSTNAME: &'static str = "darch";

orb-server/src/ipfs_rfc_client.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
pub async fn save_wasm(app_name: &String, endpoint: &String, data: Vec<u8>) -> Result<(), reqwest::Error> {
2+
let client = reqwest::Client::new();
3+
4+
let route = format!("/orb/endpoint/{}/{}", app_name, endpoint);
5+
6+
let res = client
7+
.post("http://localhost:5001/api/v0/files/write")
8+
.query(&[("arg", route), ("create", "true".to_string()), ("parents", "true".to_string())])
9+
.multipart(reqwest::multipart::Form::new().part("file", reqwest::multipart::Part::bytes(data)))
10+
.send()
11+
.await?;
12+
13+
println!("Response: {:?}", res);
14+
println!("Status: {:?}", String::from_utf8(res.bytes().await?.to_vec()));
15+
16+
Ok(())
17+
}

0 commit comments

Comments
 (0)