From 343078498ee80be3f4f179d66acd8b291034670c Mon Sep 17 00:00:00 2001 From: muji Date: Fri, 6 Dec 2024 05:46:02 +0800 Subject: [PATCH] Tidy dependencies in ipc crate. --- Cargo.lock | 3 +-- crates/ipc/Cargo.toml | 3 +-- crates/ipc/src/bindings/common.rs | 2 +- crates/ipc/src/client.rs | 2 +- crates/ipc/src/error.rs | 12 ++-------- crates/ipc/src/native_bridge.rs | 4 +--- .../ipc/src/service/local_server/account.rs | 24 +++++++++---------- crates/ipc/src/service/local_server/common.rs | 9 ++++--- crates/ipc/src/service/local_server/events.rs | 16 ++++++------- crates/ipc/src/service/local_server/mod.rs | 17 ++++++------- crates/ipc/src/service/mod.rs | 5 ++-- 11 files changed, 38 insertions(+), 59 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3aa2d0d764..9884062a76 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4627,9 +4627,8 @@ dependencies = [ "rustc_version", "serde", "serde_json", - "sos-account-extras", - "sos-net", "sos-protocol", + "sos-sdk", "thiserror 1.0.69", "tokio", "tokio-stream", diff --git a/crates/ipc/Cargo.toml b/crates/ipc/Cargo.toml index d2d43b28d4..8b7ce2b0ed 100644 --- a/crates/ipc/Cargo.toml +++ b/crates/ipc/Cargo.toml @@ -22,9 +22,8 @@ serde_json.workspace = true typeshare.workspace = true parking_lot.workspace = true -sos-net = { version = "0.16", path = "../net", features = ["account", "search", "files"] } +sos-sdk = { version = "0.16", path = "../sdk", features = ["account"] } sos-protocol = { version = "0.16", path = "../protocol" } -sos-account-extras = { version = "0.16", path = "../account_extras", features = ["clipboard"] } tokio = { version = "1", features = ["rt", "rt-multi-thread", "net", "macros", "io-util", "io-std", "sync"] } tokio-stream = "0.1" diff --git a/crates/ipc/src/bindings/common.rs b/crates/ipc/src/bindings/common.rs index 104ae71454..81de9ce8bd 100644 --- a/crates/ipc/src/bindings/common.rs +++ b/crates/ipc/src/bindings/common.rs @@ -1,7 +1,7 @@ include!(concat!(env!("OUT_DIR"), "/common.rs")); use crate::{Error, Result}; -use sos_net::protocol::local_transport::{LocalRequest, LocalResponse}; +use sos_protocol::local_transport::{LocalRequest, LocalResponse}; use std::collections::HashMap; impl From for WireLocalRequest { diff --git a/crates/ipc/src/client.rs b/crates/ipc/src/client.rs index 594283dc13..3ef25eab54 100644 --- a/crates/ipc/src/client.rs +++ b/crates/ipc/src/client.rs @@ -7,12 +7,12 @@ use interprocess::local_socket::{tokio::prelude::*, GenericNamespaced}; use tokio_stream::StreamExt; use tokio_util::codec::{Framed, LengthDelimitedCodec}; -use sos_net::sdk::prelude::PublicIdentity; use sos_protocol::{ constants::routes::v1::ACCOUNTS_LIST, local_transport::{LocalRequest, LocalResponse}, NetworkError, }; +use sos_sdk::prelude::PublicIdentity; /// Socket client for inter-process communication. pub struct SocketClient { diff --git a/crates/ipc/src/error.rs b/crates/ipc/src/error.rs index c6fdf3e2a5..e5b13660e4 100644 --- a/crates/ipc/src/error.rs +++ b/crates/ipc/src/error.rs @@ -76,19 +76,11 @@ pub enum Error { /// Errors generated by the SDK library. #[error(transparent)] - Sdk(#[from] sos_net::sdk::Error), - - /// Errors generated by the networking library. - #[error(transparent)] - Net(#[from] sos_net::Error), - - /// Errors generated by the account extras library. - #[error(transparent)] - AccountExtras(#[from] sos_account_extras::Error), + Sdk(#[from] sos_sdk::Error), /// Errors generated by the protocol library. #[error(transparent)] - Protocol(#[from] sos_net::protocol::Error), + Protocol(#[from] sos_protocol::Error), /// Errors generated when a URI is invalid. #[error(transparent)] diff --git a/crates/ipc/src/native_bridge.rs b/crates/ipc/src/native_bridge.rs index c41552eaff..b8702bda61 100644 --- a/crates/ipc/src/native_bridge.rs +++ b/crates/ipc/src/native_bridge.rs @@ -9,10 +9,8 @@ use crate::{Error, Result, SocketClient}; use futures_util::{SinkExt, StreamExt}; use http::StatusCode; use once_cell::sync::Lazy; -use sos_net::sdk::{ - logs::Logger, prelude::IPC_GUI_SOCKET_NAME, url::Url, Paths, -}; use sos_protocol::local_transport::{LocalRequest, LocalResponse}; +use sos_sdk::{logs::Logger, prelude::IPC_GUI_SOCKET_NAME, url::Url, Paths}; use std::{io::ErrorKind, sync::Arc, time::Duration}; use tokio::{ sync::{mpsc, Mutex}, diff --git a/crates/ipc/src/service/local_server/account.rs b/crates/ipc/src/service/local_server/account.rs index bb90291019..fd4a71d084 100644 --- a/crates/ipc/src/service/local_server/account.rs +++ b/crates/ipc/src/service/local_server/account.rs @@ -1,11 +1,9 @@ use http::{Request, Response, StatusCode}; use hyper::body::Bytes; -use sos_net::{ - protocol::{ - server_helpers, Merge, SyncPacket, SyncStorage, WireEncodeDecode, - }, - sdk::prelude::{Account, AccountSwitcher, Identity}, +use sos_protocol::{ + server_helpers, Merge, SyncPacket, SyncStorage, WireEncodeDecode, }; +use sos_sdk::prelude::{Account, AccountSwitcher, Identity}; use std::sync::Arc; use tokio::sync::RwLock; @@ -23,7 +21,7 @@ where A: Account + Sync + Send + 'static, R: 'static, E: std::fmt::Debug - + From + + From + From + 'static, { @@ -47,7 +45,7 @@ where + 'static, R: 'static, E: std::fmt::Debug - + From + + From + From + 'static, { @@ -79,7 +77,7 @@ where + 'static, R: 'static, E: std::fmt::Debug - + From + + From + From + 'static, { @@ -98,7 +96,7 @@ where + 'static, R: 'static, E: std::fmt::Debug - + From + + From + From + 'static, { @@ -117,7 +115,7 @@ where + 'static, R: 'static, E: std::fmt::Debug - + From + + From + From + 'static, { @@ -156,7 +154,7 @@ where + 'static, R: 'static, E: std::fmt::Debug - + From + + From + From + 'static, { @@ -175,7 +173,7 @@ where + 'static, R: 'static, E: std::fmt::Debug - + From + + From + From + 'static, { @@ -214,7 +212,7 @@ where + 'static, R: 'static, E: std::fmt::Debug - + From + + From + From + 'static, { diff --git a/crates/ipc/src/service/local_server/common.rs b/crates/ipc/src/service/local_server/common.rs index b2d0ae6ad4..2b79f6abcc 100644 --- a/crates/ipc/src/service/local_server/common.rs +++ b/crates/ipc/src/service/local_server/common.rs @@ -3,12 +3,11 @@ use http::{ Request, Response, StatusCode, }; use serde::Serialize; -use sos_net::sdk::prelude::Address; - -use sos_net::protocol::constants::{ +use sos_protocol::constants::{ ENCODING_ZLIB, ENCODING_ZSTD, MIME_TYPE_JSON, MIME_TYPE_PROTOBUF, X_SOS_ACCOUNT_ID, }; +use sos_sdk::prelude::Address; use super::{Body, Incoming}; @@ -94,7 +93,7 @@ pub fn protobuf(body: Body) -> hyper::Result> { } pub fn protobuf_compress(body: Body) -> hyper::Result> { - use sos_net::protocol::compression::zlib; + use sos_protocol::compression::zlib; let Ok(buf) = zlib::encode_all(body.as_slice()) else { return internal_server_error("zlib::compress"); }; @@ -108,7 +107,7 @@ pub fn protobuf_compress(body: Body) -> hyper::Result> { /* pub fn protobuf_zstd(body: Body) -> hyper::Result> { - use sos_net::protocol::compression::zstd; + use sos_protocol::compression::zstd; let Ok(buf) = zstd::encode_all(body.as_slice(), 20) else { return internal_server_error("zstd::compress"); }; diff --git a/crates/ipc/src/service/local_server/events.rs b/crates/ipc/src/service/local_server/events.rs index 7a8e6dd04f..334d2190a2 100644 --- a/crates/ipc/src/service/local_server/events.rs +++ b/crates/ipc/src/service/local_server/events.rs @@ -1,12 +1,10 @@ use http::{Request, Response}; use hyper::body::Bytes; -use sos_net::{ - protocol::{ - server_helpers, DiffRequest, Merge, PatchRequest, ScanRequest, - SyncStorage, WireEncodeDecode, - }, - sdk::prelude::{Account, AccountSwitcher, StorageEventLogs}, +use sos_protocol::{ + server_helpers, DiffRequest, Merge, PatchRequest, ScanRequest, + SyncStorage, WireEncodeDecode, }; +use sos_sdk::prelude::{Account, AccountSwitcher, StorageEventLogs}; use std::sync::Arc; use tokio::sync::RwLock; @@ -27,7 +25,7 @@ where + 'static, R: 'static, E: std::fmt::Debug - + From + + From + From + 'static, { @@ -76,7 +74,7 @@ where + 'static, R: 'static, E: std::fmt::Debug - + From + + From + From + 'static, { @@ -121,7 +119,7 @@ where + 'static, R: 'static, E: std::fmt::Debug - + From + + From + From + 'static, { diff --git a/crates/ipc/src/service/local_server/mod.rs b/crates/ipc/src/service/local_server/mod.rs index edf3a2e89b..599870e578 100644 --- a/crates/ipc/src/service/local_server/mod.rs +++ b/crates/ipc/src/service/local_server/mod.rs @@ -1,16 +1,13 @@ use http::{Method, Request, Response, StatusCode}; use parking_lot::Mutex; -use sos_net::{ - protocol::{ - constants::routes::v1::{ - ACCOUNTS_LIST, SYNC_ACCOUNT, SYNC_ACCOUNT_EVENTS, - SYNC_ACCOUNT_STATUS, - }, - local_transport::{LocalRequest, LocalResponse}, - Merge, SyncStorage, +use sos_protocol::{ + constants::routes::v1::{ + ACCOUNTS_LIST, SYNC_ACCOUNT, SYNC_ACCOUNT_EVENTS, SYNC_ACCOUNT_STATUS, }, - sdk::prelude::{Account, AccountSwitcher}, + local_transport::{LocalRequest, LocalResponse}, + Merge, SyncStorage, }; +use sos_sdk::prelude::{Account, AccountSwitcher}; use std::{collections::HashMap, sync::Arc}; use tokio::sync::RwLock; use tower::service_fn; @@ -67,7 +64,7 @@ impl LocalServer { + 'static, R: 'static, E: std::fmt::Debug - + From + + From + From + 'static, { diff --git a/crates/ipc/src/service/mod.rs b/crates/ipc/src/service/mod.rs index 22c7a28940..797ad2a038 100644 --- a/crates/ipc/src/service/mod.rs +++ b/crates/ipc/src/service/mod.rs @@ -1,6 +1,5 @@ use crate::ServiceAppInfo; -use async_trait::async_trait; -use sos_net::sdk::account::{Account, AccountSwitcher}; +use sos_sdk::account::{Account, AccountSwitcher}; use sos_protocol::{ local_transport::{LocalRequest, LocalResponse}, @@ -44,7 +43,7 @@ impl IpcService { R: 'static, E: std::error::Error + std::fmt::Debug - + From + + From + From + 'static, {