Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ members = [
"common",
"mercury",
"jupiter",
"jupiter/migration",
"ceres",
"libra",
"vault",
"aries",
"saturn",
"orion",
"orion-server",
"third-party",
"observatory",
"scorpio",
"context",
]
default-members = ["mega", "mono", "libra", "aries", "orion", "orion-server"]
resolver = "1"
Expand All @@ -28,12 +27,12 @@ mercury = { path = "mercury" }
jupiter = { path = "jupiter" }
ceres = { path = "ceres" }
callisto = { path = "jupiter/callisto" }
migration = { path = "jupiter/migration" }
gemini = { path = "gemini" }
vault = { path = "vault" }
saturn = { path = "saturn" }
mono = { path = "mono" }
orion = { path = "orion" }
context = { path = "context" }

anyhow = "1.0.98"
serde = "1.0.219"
Expand All @@ -50,7 +49,6 @@ tokio-stream = "0.1.17"
tokio-test = "0.4.4"
tokio-util = "0.7.15"
clap = "4.5.39"
async-std = "1.13.1"
async-trait = "0.1.88"
async-stream = "0.3.6"
bytes = "1.10.1"
Expand Down
1 change: 1 addition & 0 deletions aries/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ common = { workspace = true }
callisto = { workspace = true }
gemini = { workspace = true }
jupiter = { workspace = true }
vault = { workspace = true }

tokio = { workspace = true }
clap = { workspace = true, features = ["derive"] }
Expand Down
8 changes: 4 additions & 4 deletions aries/src/service/api/ca_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub fn routers() -> Router<AppState> {
}

async fn get_method_router(
_state: State<AppState>,
state: State<AppState>,
Query(_params): Query<RelayGetParams>,
uri: Uri,
) -> Result<Response<Body>, (StatusCode, String)> {
Expand All @@ -29,7 +29,7 @@ async fn get_method_router(
return Err((StatusCode::BAD_REQUEST, "Bad request".to_string()));
}
};
return match gemini::ca::server::get_certificate(name).await {
return match gemini::ca::server::get_certificate(&state.vault, name) {
Ok(cert) => Ok(Response::builder().body(Body::from(cert)).unwrap()),
Err(e) => Err((StatusCode::INTERNAL_SERVER_ERROR, e.to_string())),
};
Expand All @@ -41,7 +41,7 @@ async fn get_method_router(
}

async fn post_method_router(
_state: State<AppState>,
state: State<AppState>,
uri: Uri,
req: Request<Body>,
) -> Result<Response<Body>, (StatusCode, String)> {
Expand All @@ -55,7 +55,7 @@ async fn post_method_router(
};
let bytes = to_bytes(req.into_body(), usize::MAX).await.unwrap();
let csr = String::from_utf8(bytes.to_vec()).unwrap();
return match gemini::ca::server::issue_certificate(name, csr).await {
return match gemini::ca::server::issue_certificate(&state.vault, name, csr) {
Ok(cert) => Ok(Response::builder().body(Body::from(cert)).unwrap()),
Err(e) => Err((StatusCode::INTERNAL_SERVER_ERROR, e.to_string())),
};
Expand Down
8 changes: 4 additions & 4 deletions aries/src/service/api/nostr_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async fn receive(
}
};
//save
let storage = state.context.services.relay_storage.clone();
let storage = state.storage.services.relay_storage.clone();
if storage
.get_nostr_event_by_id(&ztm_nostr_event.id)
.await
Expand Down Expand Up @@ -89,7 +89,7 @@ async fn receive(
filters: filters_json.clone(),
id: Uuid::new_v4().to_string(),
};
let storage = state.context.services.relay_storage.clone();
let storage = state.storage.services.relay_storage.clone();
let req_list: Vec<Req> = storage
.get_all_nostr_req_by_subscription_id(&subscription_id.to_string())
.await
Expand All @@ -113,7 +113,7 @@ pub async fn event_list(
Query(_query): Query<HashMap<String, String>>,
state: State<AppState>,
) -> Result<Json<Vec<NostrEvent>>, (StatusCode, String)> {
let storage = state.context.services.relay_storage.clone();
let storage = state.storage.services.relay_storage.clone();
let event_list: Vec<NostrEvent> = storage
.get_all_nostr_event()
.await
Expand All @@ -128,7 +128,7 @@ pub async fn req_list(
Query(_query): Query<HashMap<String, String>>,
state: State<AppState>,
) -> Result<Json<Vec<Req>>, (StatusCode, String)> {
let storage = state.context.services.relay_storage.clone();
let storage = state.storage.services.relay_storage.clone();
let req_list: Vec<Req> = storage
.get_all_nostr_req()
.await
Expand Down
18 changes: 13 additions & 5 deletions aries/src/service/relay_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ use axum::routing::get;
use axum::{Json, Router};
use clap::Parser;
use common::config::Config;
use jupiter::context::Context;
use jupiter::storage::Storage;
use std::net::SocketAddr;
use std::str::FromStr;
use std::sync::Arc;
use tower::ServiceBuilder;
use tower_http::cors::{Any, CorsLayer};
use tower_http::decompression::RequestDecompressionLayer;
use tower_http::trace::TraceLayer;
use vault::integration::VaultCore;

use super::api;

Expand All @@ -29,7 +30,8 @@ pub struct RelayOptions {

#[derive(Clone)]
pub struct AppState {
pub context: Context,
pub storage: Storage,
pub vault: VaultCore,
pub relay_option: RelayOptions,
}

Expand All @@ -38,8 +40,10 @@ pub async fn run_relay_server(config: Arc<Config>, option: RelayOptions) {
let server_url = format!("{}:{}", option.host, option.relay_port);
tracing::info!("start relay server: {server_url}");
tokio::spawn(async move {
let context = Context::new(config).await;
gemini::p2p::relay::run(context, option.host, option.relay_port).await
let storage = Storage::new(config).await;
let vault = VaultCore::new(storage.clone());
let relay = gemini::p2p::relay::P2PRelay::new(storage, vault);
relay.run(option.host, option.relay_port).await
});
let addr = SocketAddr::from_str(&server_url).unwrap();
let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
Expand All @@ -49,8 +53,12 @@ pub async fn run_relay_server(config: Arc<Config>, option: RelayOptions) {
}

pub async fn app(config: Arc<Config>, relay_option: RelayOptions) -> Router {
let storage = Storage::new(config).await;
let vault = VaultCore::new(storage.clone());

let state = AppState {
context: Context::new(config).await,
storage,
vault,
relay_option,
};

Expand Down
20 changes: 10 additions & 10 deletions ceres/src/api_service/import_api_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::path::PathBuf;

use async_trait::async_trait;

use jupiter::context::Context;
use jupiter::storage::Storage;
use mercury::errors::GitError;
use mercury::hash::SHA1;
use mercury::internal::object::commit::Commit;
Expand All @@ -20,14 +20,14 @@ use crate::protocol::repo::Repo;

#[derive(Clone)]
pub struct ImportApiService {
pub context: Context,
pub storage: Storage,
pub repo: Repo,
}

#[async_trait]
impl ApiHandler for ImportApiService {
fn get_context(&self) -> Context {
self.context.clone()
fn get_context(&self) -> Storage {
self.storage.clone()
}

async fn create_monorepo_file(&self, _: CreateFileInfo) -> Result<(), GitError> {
Expand All @@ -47,7 +47,7 @@ impl ApiHandler for ImportApiService {
}

async fn get_root_commit(&self) -> Commit {
let storage = self.context.services.git_db_storage.clone();
let storage = self.storage.services.git_db_storage.clone();
let refs = storage
.get_default_ref(self.repo.repo_id)
.await
Expand All @@ -62,7 +62,7 @@ impl ApiHandler for ImportApiService {
}

async fn get_root_tree(&self) -> Tree {
let storage = self.context.services.git_db_storage.clone();
let storage = self.storage.services.git_db_storage.clone();
let refs = storage
.get_default_ref(self.repo.repo_id)
.await
Expand All @@ -83,7 +83,7 @@ impl ApiHandler for ImportApiService {
}

async fn get_tree_by_hash(&self, hash: &str) -> Tree {
self.context
self.storage
.services
.git_db_storage
.get_tree_by_hash(self.repo.repo_id, hash)
Expand All @@ -94,7 +94,7 @@ impl ApiHandler for ImportApiService {
}

async fn get_commit_by_hash(&self, hash: &str) -> Option<Commit> {
let storage = self.context.services.git_db_storage.clone();
let storage = self.storage.services.git_db_storage.clone();
let commit = storage
.get_commit_by_hash(self.repo.repo_id, hash)
.await
Expand All @@ -103,7 +103,7 @@ impl ApiHandler for ImportApiService {
}

async fn get_tree_relate_commit(&self, t_hash: &str) -> Commit {
let storage = self.context.services.git_db_storage.clone();
let storage = self.storage.services.git_db_storage.clone();
let tree_info = storage
.get_tree_by_hash(self.repo.repo_id, t_hash)
.await
Expand All @@ -118,7 +118,7 @@ impl ApiHandler for ImportApiService {
}

async fn get_commits_by_hashes(&self, c_hashes: Vec<String>) -> Result<Vec<Commit>, GitError> {
let storage = self.context.services.git_db_storage.clone();
let storage = self.storage.services.git_db_storage.clone();
let commits = storage
.get_commits_by_hashes(self.repo.repo_id, &c_hashes)
.await
Expand Down
4 changes: 2 additions & 2 deletions ceres/src/api_service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use async_trait::async_trait;

use callisto::raw_blob;
use common::errors::MegaError;
use jupiter::{context::Context, utils::converter::generate_git_keep_with_timestamp};
use jupiter::{storage::Storage, utils::converter::generate_git_keep_with_timestamp};
use mercury::{
errors::GitError,
hash::SHA1,
Expand All @@ -33,7 +33,7 @@ pub struct GitObjectCache {

#[async_trait]
pub trait ApiHandler: Send + Sync {
fn get_context(&self) -> Context;
fn get_context(&self) -> Storage;

async fn create_monorepo_file(&self, file_info: CreateFileInfo) -> Result<(), GitError>;

Expand Down
Loading
Loading