Fix errors
This commit is contained in:
parent
1d6ccc5d1b
commit
347ef56d56
11 changed files with 43 additions and 33 deletions
|
@ -7,9 +7,11 @@ license.workspace = true
|
||||||
repository.workspace = true
|
repository.workspace = true
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["dep:caretta-sync-macros"]
|
default = ["macros"]
|
||||||
mobile = ["dep:caretta-sync-mobile"]
|
mobile = ["dep:caretta-sync-mobile"]
|
||||||
desktop = ["dep:caretta-sync-cli"]
|
cli = ["dep:caretta-sync-cli"]
|
||||||
|
desktop = ["cli"]
|
||||||
|
macros = ["dep:caretta-sync-macros"]
|
||||||
test = ["caretta-sync-core/test"]
|
test = ["caretta-sync-core/test"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use clap::Args;
|
use clap::Args;
|
||||||
use caretta_core::{
|
use caretta_sync_core::{
|
||||||
utils::runnable::Runnable,
|
utils::runnable::Runnable,
|
||||||
proto::*,
|
proto::*,
|
||||||
};
|
};
|
||||||
|
@ -15,7 +15,7 @@ impl Runnable for PeerListCommandArgs {
|
||||||
async fn run(self, app_name: &'static str) {
|
async fn run(self, app_name: &'static str) {
|
||||||
let config = self.config.into_config(app_name).await;
|
let config = self.config.into_config(app_name).await;
|
||||||
let path = String::from("unix://") + config.rpc.socket_path.as_os_str().to_str().expect("Invalid string");
|
let path = String::from("unix://") + config.rpc.socket_path.as_os_str().to_str().expect("Invalid string");
|
||||||
let mut client = caretta_core::proto::cached_peer_service_client::CachedPeerServiceClient::connect(path).await.expect("Unix socket should be accessible");
|
let mut client = caretta_sync_core::proto::cached_peer_service_client::CachedPeerServiceClient::connect(path).await.expect("Unix socket should be accessible");
|
||||||
let request = tonic::Request::new(CachedPeerListRequest {});
|
let request = tonic::Request::new(CachedPeerListRequest {});
|
||||||
let response = client.list(request).await.expect("Faild to request/response");
|
let response = client.list(request).await.expect("Faild to request/response");
|
||||||
println!("{:?}", response);
|
println!("{:?}", response);
|
||||||
|
|
|
@ -6,7 +6,7 @@ pub use info::*;
|
||||||
pub use list::*;
|
pub use list::*;
|
||||||
pub use ping::*;
|
pub use ping::*;
|
||||||
|
|
||||||
use caretta_core::utils::runnable::Runnable;
|
use caretta_sync_core::utils::runnable::Runnable;
|
||||||
use clap::{Args, Subcommand};
|
use clap::{Args, Subcommand};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ pub use storage::{StorageConfig, PartialStorageConfig};
|
||||||
pub use p2p::{P2pConfig, PartialP2pConfig};
|
pub use p2p::{P2pConfig, PartialP2pConfig};
|
||||||
pub use rpc::*;
|
pub use rpc::*;
|
||||||
|
|
||||||
#[cfg(feature="desktop")]
|
#[cfg(feature="cli")]
|
||||||
use clap::Args;
|
use clap::Args;
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
@ -52,14 +52,14 @@ impl TryFrom<PartialConfig> for Config {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature="desktop", derive(Args))]
|
#[cfg_attr(feature="cli", derive(Args))]
|
||||||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
|
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
|
||||||
pub struct PartialConfig {
|
pub struct PartialConfig {
|
||||||
#[cfg_attr(feature="desktop", command(flatten))]
|
#[cfg_attr(feature="cli", command(flatten))]
|
||||||
pub p2p: Option<PartialP2pConfig>,
|
pub p2p: Option<PartialP2pConfig>,
|
||||||
#[cfg_attr(feature="desktop", command(flatten))]
|
#[cfg_attr(feature="cli", command(flatten))]
|
||||||
pub storage: Option<PartialStorageConfig>,
|
pub storage: Option<PartialStorageConfig>,
|
||||||
#[cfg_attr(feature="desktop", command(flatten))]
|
#[cfg_attr(feature="cli", command(flatten))]
|
||||||
pub rpc: Option<PartialRpcConfig>,
|
pub rpc: Option<PartialRpcConfig>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::{net::{IpAddr, Ipv4Addr}, ops, path::{Path, PathBuf}};
|
use std::{net::{IpAddr, Ipv4Addr}, ops, path::{Path, PathBuf}};
|
||||||
|
|
||||||
use base64::{prelude::BASE64_STANDARD, Engine};
|
use base64::{prelude::BASE64_STANDARD, Engine};
|
||||||
#[cfg(feature="desktop")]
|
#[cfg(feature="cli")]
|
||||||
use clap::Args;
|
use clap::Args;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use libp2p::{identity::{self, DecodingError, Keypair}, noise, ping, swarm::SwarmEvent, tcp, yamux, Swarm};
|
use libp2p::{identity::{self, DecodingError, Keypair}, noise, ping, swarm::SwarmEvent, tcp, yamux, Swarm};
|
||||||
|
@ -81,14 +81,14 @@ impl TryFrom<PartialP2pConfig> for P2pConfig {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature="desktop",derive(Args))]
|
#[cfg_attr(feature="cli",derive(Args))]
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
|
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
|
||||||
pub struct PartialP2pConfig {
|
pub struct PartialP2pConfig {
|
||||||
#[cfg_attr(feature="desktop",arg(long))]
|
#[cfg_attr(feature="cli",arg(long))]
|
||||||
pub private_key: Option<String>,
|
pub private_key: Option<String>,
|
||||||
#[cfg_attr(feature="desktop",arg(long))]
|
#[cfg_attr(feature="cli",arg(long))]
|
||||||
pub listen_ips: Option<Vec<IpAddr>>,
|
pub listen_ips: Option<Vec<IpAddr>>,
|
||||||
#[cfg_attr(feature="desktop",arg(long))]
|
#[cfg_attr(feature="cli",arg(long))]
|
||||||
pub port: Option<u16>,
|
pub port: Option<u16>,
|
||||||
}
|
}
|
||||||
impl PartialP2pConfig {
|
impl PartialP2pConfig {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use std::{net::{IpAddr, Ipv4Addr, SocketAddr, TcpListener}, path::PathBuf, str::FromStr};
|
use std::{net::{IpAddr, Ipv4Addr, SocketAddr, TcpListener}, path::PathBuf, str::FromStr};
|
||||||
#[cfg(feature="desktop")]
|
#[cfg(feature="cli")]
|
||||||
use clap::Args;
|
use clap::Args;
|
||||||
use crate::{config::PartialConfig, utils::{emptiable::Emptiable, mergeable::Mergeable}};
|
use crate::{config::PartialConfig, utils::{emptiable::Emptiable, mergeable::Mergeable}};
|
||||||
use libp2p::mdns::Config;
|
use libp2p::mdns::Config;
|
||||||
|
@ -24,7 +24,7 @@ impl TryFrom<PartialRpcConfig> for RpcConfig {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature="desktop", derive(Args))]
|
#[cfg_attr(feature="cli", derive(Args))]
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
|
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
|
||||||
pub struct PartialRpcConfig {
|
pub struct PartialRpcConfig {
|
||||||
pub socket_path: Option<PathBuf>,
|
pub socket_path: Option<PathBuf>,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
#[cfg(feature="desktop")]
|
#[cfg(feature="cli")]
|
||||||
use clap::Args;
|
use clap::Args;
|
||||||
|
|
||||||
#[cfg(any(test, feature="test"))]
|
#[cfg(any(test, feature="test"))]
|
||||||
|
@ -25,12 +25,12 @@ impl TryFrom<PartialStorageConfig> for StorageConfig {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg_attr(feature="desktop", derive(Args))]
|
#[cfg_attr(feature="cli", derive(Args))]
|
||||||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
|
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
|
||||||
pub struct PartialStorageConfig {
|
pub struct PartialStorageConfig {
|
||||||
#[cfg_attr(feature="desktop", arg(long))]
|
#[cfg_attr(feature="cli", arg(long))]
|
||||||
pub data_directory: Option<PathBuf>,
|
pub data_directory: Option<PathBuf>,
|
||||||
#[cfg_attr(feature="desktop", arg(long))]
|
#[cfg_attr(feature="cli", arg(long))]
|
||||||
pub cache_directory: Option<PathBuf>,
|
pub cache_directory: Option<PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use caretta::{
|
use caretta_sync::{
|
||||||
config::P2pConfig,
|
config::P2pConfig,
|
||||||
proto::cached_peer_service_server::CachedPeerServiceServer,
|
proto::cached_peer_service_server::CachedPeerServiceServer,
|
||||||
server::ServerTrait,
|
server::ServerTrait,
|
||||||
|
@ -12,7 +12,7 @@ use tokio_stream::wrappers::UnixListenerStream;
|
||||||
pub struct Server{}
|
pub struct Server{}
|
||||||
|
|
||||||
impl ServerTrait for Server {
|
impl ServerTrait for Server {
|
||||||
async fn serve_p2p<T>(config: &T) -> Result<(), caretta::error::Error>
|
async fn serve_p2p<T>(config: &T) -> Result<(), caretta_sync::error::Error>
|
||||||
where
|
where
|
||||||
T: AsRef<P2pConfig>
|
T: AsRef<P2pConfig>
|
||||||
{
|
{
|
||||||
|
@ -23,7 +23,7 @@ impl ServerTrait for Server {
|
||||||
noise::Config::new,
|
noise::Config::new,
|
||||||
yamux::Config::default,
|
yamux::Config::default,
|
||||||
)?
|
)?
|
||||||
.with_behaviour(|keypair| caretta::p2p::Behaviour::try_from(keypair).unwrap())?
|
.with_behaviour(|keypair| caretta_sync::p2p::Behaviour::try_from(keypair).unwrap())?
|
||||||
.build();
|
.build();
|
||||||
swarm.listen_on("/ip4/0.0.0.0/tcp/0".parse()?)?;
|
swarm.listen_on("/ip4/0.0.0.0/tcp/0".parse()?)?;
|
||||||
loop{
|
loop{
|
||||||
|
@ -41,8 +41,8 @@ impl ServerTrait for Server {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn serve_rpc<T>(config: &T) -> Result<(), caretta::error::Error>
|
async fn serve_rpc<T>(config: &T) -> Result<(), caretta_sync::error::Error>
|
||||||
where T: AsRef<caretta::config::RpcConfig> {
|
where T: AsRef<caretta_sync::config::RpcConfig> {
|
||||||
let path = config.as_ref().socket_path.clone();
|
let path = config.as_ref().socket_path.clone();
|
||||||
if let Some(x) = path.parent() {
|
if let Some(x) = path.parent() {
|
||||||
if !x.exists() {
|
if !x.exists() {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use caretta_sync_example_core::server::Server;
|
use caretta_sync_demo_core::server::Server;
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
use caretta::{cli::*, utils::runnable::Runnable};
|
use caretta_sync::{cli::*, utils::runnable::Runnable};
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, Parser, Runnable)]
|
#[derive(Debug, Parser, Runnable)]
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use caretta::utils::runnable::Runnable;
|
use caretta_sync::utils::runnable::Runnable;
|
||||||
use caretta_sync_example_core::global::APP_NAME;
|
use caretta_sync_demo_core::global::APP_NAME;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
|
||||||
use crate::cli::Cli;
|
use crate::cli::Cli;
|
||||||
|
|
14
src/lib.rs
14
src/lib.rs
|
@ -1,5 +1,13 @@
|
||||||
pub use caretta_sync_core::*;
|
pub use caretta_sync_core::*;
|
||||||
#[cfg(feature = "desktop")]
|
#[cfg(feature = "cli")]
|
||||||
pub use caretta_sync_desktop::*;
|
pub use caretta_sync_cli::*;
|
||||||
#[cfg(feature = "mobile")]
|
#[cfg(feature = "mobile")]
|
||||||
pub use caretta_sync_mobile::*;
|
pub use caretta_sync_mobile::*;
|
||||||
|
|
||||||
|
#[cfg(feature = "macros")]
|
||||||
|
pub mod utils {
|
||||||
|
pub mod runnable {
|
||||||
|
pub use caretta_sync_core::utils::runnable::Runnable;
|
||||||
|
pub use caretta_sync_macros::Runnable;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue