diff options
61 files changed, 169 insertions, 197 deletions
diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 41c5870..e3abfbd 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -9,7 +9,7 @@ env: jobs: build_and_test: - name: karyons - latest + name: karyon - latest runs-on: ubuntu-latest strategy: matrix: @@ -12,8 +12,8 @@ version = "0.1.0" edition = "2021" [workspace.dependencies] -karyons_core = { path = "core" } -karyons_net = { path = "net" } -karyons_p2p = { path = "p2p" } -karyons_jsonrpc = { path = "jsonrpc" } +karyon_core = { path = "core" } +karyon_net = { path = "net" } +karyon_p2p = { path = "p2p" } +karyon_jsonrpc = { path = "jsonrpc" } @@ -1,4 +1,4 @@ -# karyons +# karyon An infrastructure for peer-to-peer, decentralized, and collaborative software. @@ -11,33 +11,33 @@ Join us on: ## Crates -- [karyons core](./core): Essential utilities and core functionality. -- [karyons net](./net): Provides a network interface for TCP, UDP, and Unix, +- [karyon core](./core): Essential utilities and core functionality. +- [karyon net](./net): Provides a network interface for TCP, UDP, and Unix, along with common network functionality. -- [karyons p2p](./p2p): A lightweight, extensible, and customizable +- [karyon p2p](./p2p): A lightweight, extensible, and customizable peer-to-peer (p2p) network stack. -- [karyons jsonrpc](./jsonrpc): A fast and small async +- [karyon jsonrpc](./jsonrpc): A fast and small async [JSONRPC2.0](https://www.jsonrpc.org/specification) implementation. -- karyons crdt: A [CRDT](https://en.wikipedia.org/wiki/Conflict-free_replicated_data_type) +- karyon crdt: A [CRDT](https://en.wikipedia.org/wiki/Conflict-free_replicated_data_type) implementation for building collaborative software. -- karyons base: A lightweight, extensible database that operates with karyons crdt. +- karyon base: A lightweight, extensible database that operates with karyon crdt. ## Status -This project is a work in progress. The current focus is on shipping karyons -crdt and karyons store, along with major changes to the network stack. You can +This project is a work in progress. The current focus is on shipping `karyon +crdt` and `karyon store`, along with major changes to the network stack. You can check the [issues](https://github.com/karyons/karyons/issues) for updates on ongoing tasks. ## Docs Online documentation for the main crates: -[karyons_p2p](https://karyons.github.io/karyons/karyons_p2p), -[karyons_jsonrpc](https://karyons.github.io/karyons/karyons_jsonrpc) +[karyon_p2p](https://karyons.github.io/karyons/karyon_p2p), +[karyon_jsonrpc](https://karyons.github.io/karyons/karyon_jsonrpc) For the internal crates: -[karyons_core](https://karyons.github.io/karyons/karyons_core), -[karyons_net](https://karyons.github.io/karyons/karyons_net) +[karyon_core](https://karyons.github.io/karyons/karyon_core), +[karyon_net](https://karyons.github.io/karyons/karyon_net) ## Thanks diff --git a/core/Cargo.toml b/core/Cargo.toml index 3c8cb9c..66c9f05 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "karyons_core" +name = "karyon_core" version.workspace = true edition.workspace = true diff --git a/core/src/async_util/backoff.rs b/core/src/async_util/backoff.rs index a231229..4a0ab35 100644 --- a/core/src/async_util/backoff.rs +++ b/core/src/async_util/backoff.rs @@ -12,7 +12,7 @@ use smol::Timer; /// # Examples /// /// ``` -/// use karyons_core::async_util::Backoff; +/// use karyon_core::async_util::Backoff; /// /// async { /// let backoff = Backoff::new(300, 3000); diff --git a/core/src/async_util/condvar.rs b/core/src/async_util/condvar.rs index 7396d0d..73e76fc 100644 --- a/core/src/async_util/condvar.rs +++ b/core/src/async_util/condvar.rs @@ -19,7 +19,7 @@ use crate::util::random_16; /// /// use smol::lock::Mutex; /// -/// use karyons_core::async_util::CondVar; +/// use karyon_core::async_util::CondVar; /// /// async { /// diff --git a/core/src/async_util/condwait.rs b/core/src/async_util/condwait.rs index cd4b269..6aa8a3c 100644 --- a/core/src/async_util/condwait.rs +++ b/core/src/async_util/condwait.rs @@ -9,7 +9,7 @@ use super::CondVar; ///``` /// use std::sync::Arc; /// -/// use karyons_core::async_util::CondWait; +/// use karyon_core::async_util::CondWait; /// /// async { /// let cond_wait = Arc::new(CondWait::new()); diff --git a/core/src/async_util/select.rs b/core/src/async_util/select.rs index 8f2f7f6..0977fa9 100644 --- a/core/src/async_util/select.rs +++ b/core/src/async_util/select.rs @@ -12,7 +12,7 @@ use smol::future::Future; /// ``` /// use std::future; /// -/// use karyons_core::async_util::{select, Either}; +/// use karyon_core::async_util::{select, Either}; /// /// async { /// let fut1 = future::pending::<String>(); diff --git a/core/src/async_util/task_group.rs b/core/src/async_util/task_group.rs index 3fc0cb7..7129af2 100644 --- a/core/src/async_util/task_group.rs +++ b/core/src/async_util/task_group.rs @@ -14,7 +14,7 @@ use super::{select, CondWait, Either}; /// /// use std::sync::Arc; /// -/// use karyons_core::async_util::TaskGroup; +/// use karyon_core::async_util::TaskGroup; /// /// async { /// diff --git a/core/src/async_util/timeout.rs b/core/src/async_util/timeout.rs index 6ab35c4..cf3c490 100644 --- a/core/src/async_util/timeout.rs +++ b/core/src/async_util/timeout.rs @@ -13,7 +13,7 @@ use crate::{error::Error, Result}; /// ``` /// use std::{future, time::Duration}; /// -/// use karyons_core::async_util::timeout; +/// use karyon_core::async_util::timeout; /// /// async { /// let fut = future::pending::<()>(); diff --git a/core/src/event.rs b/core/src/event.rs index f2c5510..ef40205 100644 --- a/core/src/event.rs +++ b/core/src/event.rs @@ -24,7 +24,7 @@ type Listeners<T> = HashMap<T, HashMap<String, HashMap<EventListenerID, Sender<E /// # Example /// /// ``` -/// use karyons_core::event::{EventSys, EventValueTopic, EventValue}; +/// use karyon_core::event::{EventSys, EventValueTopic, EventValue}; /// /// async { /// let event_sys = EventSys::new(); diff --git a/core/src/executor.rs b/core/src/executor.rs deleted file mode 100644 index 136f6ea..0000000 --- a/core/src/executor.rs +++ /dev/null @@ -1,28 +0,0 @@ - - -/// Returns an estimate of the default amount of parallelism a program should use. -/// see `std::thread::available_parallelism` -fn available_parallelism() -> usize { - thread::available_parallelism() - .map(NonZeroUsize::get) - .unwrap_or(1) -} - -/// Run a multi-threaded executor -pub fn run_executor<T>(main_future: impl Future<Output = T>, ex: Executor<'_>) { - let (signal, shutdown) = channel::unbounded::<()>(); - - let num_threads = available_parallelism(); - - Parallel::new() - .each(0..(num_threads), |_| { - future::block_on(ex.run(shutdown.recv())) - }) - // Run the main future on the current thread. - .finish(|| { - future::block_on(async { - main_future.await; - drop(signal); - }) - }); -} diff --git a/core/src/lib.rs b/core/src/lib.rs index a4ea432..442b642 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -5,7 +5,7 @@ pub mod util; /// [`smol`](https://github.com/smol-rs/smol) async runtime. pub mod async_util; -/// Represents karyons's Core Error. +/// Represents karyon's Core Error. pub mod error; /// [`event::EventSys`] implementation. diff --git a/core/src/pubsub.rs b/core/src/pubsub.rs index 306d42f..f5cb69b 100644 --- a/core/src/pubsub.rs +++ b/core/src/pubsub.rs @@ -12,7 +12,7 @@ pub type SubscriptionID = u16; // # Example /// /// ``` -/// use karyons_core::pubsub::{Publisher}; +/// use karyon_core::pubsub::{Publisher}; /// /// async { /// let publisher = Publisher::new(); diff --git a/jsonrpc/Cargo.toml b/jsonrpc/Cargo.toml index 12bea1a..4556708 100644 --- a/jsonrpc/Cargo.toml +++ b/jsonrpc/Cargo.toml @@ -1,11 +1,11 @@ [package] -name = "karyons_jsonrpc" +name = "karyon_jsonrpc" version.workspace = true edition.workspace = true [dependencies] -karyons_core.workspace = true -karyons_net.workspace = true +karyon_core.workspace = true +karyon_net.workspace = true smol = "1.3.0" log = "0.4.20" diff --git a/jsonrpc/README.md b/jsonrpc/README.md index f7ee641..af7dfe2 100644 --- a/jsonrpc/README.md +++ b/jsonrpc/README.md @@ -1,4 +1,4 @@ -# karyons jsonrpc +# karyon jsonrpc A fast and lightweight async implementation of [JSON-RPC 2.0](https://www.jsonrpc.org/specification), supporting the Tcp and Unix protocols. @@ -11,7 +11,7 @@ use std::sync::Arc; use serde_json::Value; use smol::net::{TcpStream, TcpListener}; -use karyons_jsonrpc::{JsonRPCError, Server, Client, register_service, ServerConfig, ClientConfig}; +use karyon_jsonrpc::{JsonRPCError, Server, Client, register_service, ServerConfig, ClientConfig}; struct HelloWorld {} diff --git a/jsonrpc/examples/client.rs b/jsonrpc/examples/client.rs index b28760d..2c8cf83 100644 --- a/jsonrpc/examples/client.rs +++ b/jsonrpc/examples/client.rs @@ -1,7 +1,7 @@ use serde::{Deserialize, Serialize}; use smol::net::TcpStream; -use karyons_jsonrpc::{Client, ClientConfig}; +use karyon_jsonrpc::{Client, ClientConfig}; #[derive(Deserialize, Serialize)] struct Req { diff --git a/jsonrpc/examples/server.rs b/jsonrpc/examples/server.rs index b09232f..6953433 100644 --- a/jsonrpc/examples/server.rs +++ b/jsonrpc/examples/server.rs @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize}; use serde_json::Value; use smol::net::TcpListener; -use karyons_jsonrpc::{register_service, JsonRPCError, Server, ServerConfig}; +use karyon_jsonrpc::{register_service, JsonRPCError, Server, ServerConfig}; struct Calc { version: String, diff --git a/jsonrpc/src/client.rs b/jsonrpc/src/client.rs index 69c2e6d..8e413e2 100644 --- a/jsonrpc/src/client.rs +++ b/jsonrpc/src/client.rs @@ -1,8 +1,8 @@ use log::debug; use serde::{de::DeserializeOwned, Serialize}; -use karyons_core::util::random_32; -use karyons_net::ToConn; +use karyon_core::util::random_32; +use karyon_net::ToConn; use crate::{ codec::{Codec, CodecConfig}, diff --git a/jsonrpc/src/codec.rs b/jsonrpc/src/codec.rs index 5dac8da..451cdb4 100644 --- a/jsonrpc/src/codec.rs +++ b/jsonrpc/src/codec.rs @@ -1,7 +1,7 @@ use memchr::memchr; -use karyons_core::async_util::timeout; -use karyons_net::Conn; +use karyon_core::async_util::timeout; +use karyon_net::Conn; use crate::{Error, Result}; diff --git a/jsonrpc/src/error.rs b/jsonrpc/src/error.rs index 5437c6d..8bc8c49 100644 --- a/jsonrpc/src/error.rs +++ b/jsonrpc/src/error.rs @@ -2,7 +2,7 @@ use thiserror::Error as ThisError; pub type Result<T> = std::result::Result<T, Error>; -/// Represents karyons's jsonrpc Error. +/// Represents karyon's jsonrpc Error. #[derive(ThisError, Debug)] pub enum Error { #[error(transparent)] @@ -27,8 +27,8 @@ pub enum Error { InvalidMsg(&'static str), #[error(transparent)] - KaryonsCore(#[from] karyons_core::error::Error), + KaryonCore(#[from] karyon_core::error::Error), #[error(transparent)] - KaryonsNet(#[from] karyons_net::NetError), + KaryonNet(#[from] karyon_net::NetError), } diff --git a/jsonrpc/src/lib.rs b/jsonrpc/src/lib.rs index da9047d..df66363 100644 --- a/jsonrpc/src/lib.rs +++ b/jsonrpc/src/lib.rs @@ -9,7 +9,7 @@ //! use serde_json::Value; //! use smol::net::{TcpStream, TcpListener}; //! -//! use karyons_jsonrpc::{JsonRPCError, Server, Client, register_service, ServerConfig, ClientConfig}; +//! use karyon_jsonrpc::{JsonRPCError, Server, Client, register_service, ServerConfig, ClientConfig}; //! //! struct HelloWorld {} //! @@ -63,7 +63,7 @@ pub use error::Error as JsonRPCError; pub use server::{Server, ServerConfig}; pub use service::{RPCMethod, RPCService}; -pub use karyons_net::Endpoint; +pub use karyon_net::Endpoint; const JSONRPC_VERSION: &str = "2.0"; use error::{Error, Result}; diff --git a/jsonrpc/src/server.rs b/jsonrpc/src/server.rs index 4f1bada..92920ad 100644 --- a/jsonrpc/src/server.rs +++ b/jsonrpc/src/server.rs @@ -3,12 +3,12 @@ use std::{collections::HashMap, sync::Arc}; use log::{debug, error, warn}; use smol::lock::RwLock; -use karyons_core::{ +use karyon_core::{ async_util::{TaskGroup, TaskResult}, Executor, }; -use karyons_net::{Conn, Listener, ToListener}; +use karyon_net::{Conn, Listener, ToListener}; use crate::{ codec::{Codec, CodecConfig}, @@ -44,7 +44,7 @@ impl<'a> Server<'a> { /// Returns the local endpoint. pub fn local_endpoint(&self) -> Result<Endpoint> { - self.listener.local_endpoint().map_err(Error::KaryonsNet) + self.listener.local_endpoint().map_err(Error::KaryonNet) } /// Starts the RPC server diff --git a/jsonrpc/src/service.rs b/jsonrpc/src/service.rs index 62ec726..943442c 100644 --- a/jsonrpc/src/service.rs +++ b/jsonrpc/src/service.rs @@ -20,7 +20,7 @@ pub trait RPCService: Sync + Send { /// ``` /// use serde_json::Value; /// -/// use karyons_jsonrpc::{JsonRPCError, register_service}; +/// use karyon_jsonrpc::{JsonRPCError, register_service}; /// /// struct Hello {} /// @@ -36,11 +36,11 @@ pub trait RPCService: Sync + Send { #[macro_export] macro_rules! register_service { ($t:ty, $($m:ident),*) => { - impl karyons_jsonrpc::RPCService for $t { + impl karyon_jsonrpc::RPCService for $t { fn get_method<'a>( &'a self, name: &'a str - ) -> Option<karyons_jsonrpc::RPCMethod> { + ) -> Option<karyon_jsonrpc::RPCMethod> { match name { $( stringify!($m) => { diff --git a/net/Cargo.toml b/net/Cargo.toml index d2cb884..5fecff5 100644 --- a/net/Cargo.toml +++ b/net/Cargo.toml @@ -1,12 +1,12 @@ [package] -name = "karyons_net" +name = "karyon_net" version.workspace = true edition.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -karyons_core.workspace = true +karyon_core.workspace = true smol = "1.3.0" async-trait = "0.1.73" diff --git a/net/src/connection.rs b/net/src/connection.rs index 3c047a0..73606a2 100644 --- a/net/src/connection.rs +++ b/net/src/connection.rs @@ -40,7 +40,7 @@ pub trait Connection: Send + Sync { /// #Example /// /// ``` -/// use karyons_net::{Endpoint, dial}; +/// use karyon_net::{Endpoint, dial}; /// /// async { /// let endpoint: Endpoint = "tcp://127.0.0.1:3000".parse().unwrap(); diff --git a/net/src/endpoint.rs b/net/src/endpoint.rs index 1a1f975..fdb2735 100644 --- a/net/src/endpoint.rs +++ b/net/src/endpoint.rs @@ -13,14 +13,14 @@ use crate::{Error, Result}; /// Port defined as a u16. pub type Port = u16; -/// Endpoint defines generic network endpoints for karyons. +/// Endpoint defines generic network endpoints for karyon. /// /// # Example /// /// ``` /// use std::net::SocketAddr; /// -/// use karyons_net::Endpoint; +/// use karyon_net::Endpoint; /// /// let endpoint: Endpoint = "tcp://127.0.0.1:3000".parse().unwrap(); /// diff --git a/net/src/error.rs b/net/src/error.rs index 5dd6348..0d96d64 100644 --- a/net/src/error.rs +++ b/net/src/error.rs @@ -35,7 +35,7 @@ pub enum Error { InvalidDnsNameError(#[from] async_rustls::rustls::client::InvalidDnsNameError), #[error(transparent)] - KaryonsCore(#[from] karyons_core::error::Error), + KaryonCore(#[from] karyon_core::error::Error), } impl<T> From<smol::channel::SendError<T>> for Error { diff --git a/net/src/lib.rs b/net/src/lib.rs index ff466af..5b9bdd7 100644 --- a/net/src/lib.rs +++ b/net/src/lib.rs @@ -18,8 +18,8 @@ pub use { use error::{Error, Result}; -/// Represents karyons's Net Error +/// Represents karyon's Net Error pub use error::Error as NetError; -/// Represents karyons's Net Result +/// Represents karyon's Net Result pub use error::Result as NetResult; diff --git a/net/src/listener.rs b/net/src/listener.rs index cab5330..f12f33e 100644 --- a/net/src/listener.rs +++ b/net/src/listener.rs @@ -27,7 +27,7 @@ pub trait ConnListener: Send + Sync { /// #Example /// /// ``` -/// use karyons_net::{Endpoint, listen}; +/// use karyon_net::{Endpoint, listen}; /// /// async { /// let endpoint: Endpoint = "tcp://127.0.0.1:3000".parse().unwrap(); diff --git a/p2p/Cargo.toml b/p2p/Cargo.toml index 31bac2d..441c8f9 100644 --- a/p2p/Cargo.toml +++ b/p2p/Cargo.toml @@ -1,13 +1,13 @@ [package] -name = "karyons_p2p" +name = "karyon_p2p" version.workspace = true edition.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -karyons_core = { workspace = true, features=["crypto"] } -karyons_net.workspace = true +karyon_core = { workspace = true, features=["crypto"] } +karyon_net.workspace = true smol = "1.3.0" async-trait = "0.1.73" diff --git a/p2p/README.md b/p2p/README.md index 098cc26..e00d9e5 100644 --- a/p2p/README.md +++ b/p2p/README.md @@ -1,6 +1,6 @@ -# karyons p2p +# karyon p2p -karyons p2p serves as the foundational stack for the karyons project. It offers +karyon p2p serves as the foundational stack for the karyon project. It offers a lightweight, extensible, and customizable peer-to-peer (p2p) network stack that seamlessly integrates with any p2p project. @@ -8,11 +8,11 @@ that seamlessly integrates with any p2p project. ### Discovery -karyons p2p uses a customized version of the Kademlia for discovering new peers +karyon p2p uses a customized version of the Kademlia for discovering new peers in the network. This approach is based on Kademlia but with several significant differences and optimizations. Some of the main changes: -1. karyons p2p uses TCP for the lookup process, while UDP is used for +1. karyon p2p uses TCP for the lookup process, while UDP is used for validating and refreshing the routing table. The reason for this choice is that the lookup process is infrequent, and the work required to manage messages with UDP is largely equivalent to using TCP for this purpose. @@ -21,11 +21,11 @@ differences and optimizations. Some of the main changes: use UDP. 2. In contrast to traditional Kademlia, which often employs 160 buckets, - karyons p2p reduces the number of buckets to 32. This optimization is a + karyon p2p reduces the number of buckets to 32. This optimization is a result of the observation that most nodes tend to map into the last few buckets, with the majority of other buckets remaining empty. -3. While Kademlia typically uses a 160-bit key to identify a peer, karyons p2p +3. While Kademlia typically uses a 160-bit key to identify a peer, karyon p2p uses a 256-bit key. > Despite criticisms of Kademlia's vulnerabilities, particularly concerning @@ -38,7 +38,7 @@ differences and optimizations. Some of the main changes: ### Peer ID -In the karyons p2p network, each peer is identified by a 256-bit (32-byte) Peer ID. +In the karyon p2p network, each peer is identified by a 256-bit (32-byte) Peer ID. ### Seeding @@ -67,8 +67,8 @@ is added to the `PeerPool`. ### Protocols -In the karyons p2p network, we have two types of protocols: core protocols and -custom protocols. Core protocols are prebuilt into karyons p2p, such as the +In the karyon p2p network, we have two types of protocols: core protocols and +custom protocols. Core protocols are prebuilt into karyon p2p, such as the Ping protocol used to maintain connections. Custom protocols, on the other hand, are protocols that you define for your application to provide its core functionality. @@ -138,5 +138,5 @@ If you have tmux installed, you can run the network simulation script in the examples directory to run 12 peers simultaneously. ```bash -$ RUST_LOG=karyons=info ./net_simulation.sh +$ RUST_LOG=karyon=info ./net_simulation.sh ``` diff --git a/p2p/examples/chat.rs b/p2p/examples/chat.rs index 99cde7b..cc822d9 100644 --- a/p2p/examples/chat.rs +++ b/p2p/examples/chat.rs @@ -7,10 +7,10 @@ use async_trait::async_trait; use clap::Parser; use smol::{channel, Executor}; -use karyons_core::crypto::{KeyPair, KeyPairType}; -use karyons_net::{Endpoint, Port}; +use karyon_core::crypto::{KeyPair, KeyPairType}; +use karyon_net::{Endpoint, Port}; -use karyons_p2p::{ +use karyon_p2p::{ protocol::{ArcProtocol, Protocol, ProtocolEvent, ProtocolID}, ArcPeer, Backend, Config, P2pError, Version, }; diff --git a/p2p/examples/chat_simulation.sh b/p2p/examples/chat_simulation.sh index 82bbe96..0cc63cc 100755 --- a/p2p/examples/chat_simulation.sh +++ b/p2p/examples/chat_simulation.sh @@ -3,23 +3,23 @@ # build cargo build --release --example chat -tmux new-session -d -s karyons_chat +tmux new-session -d -s karyon_chat -tmux send-keys -t karyons_chat "../../target/release/examples/chat --username 'user1'\ +tmux send-keys -t karyon_chat "../../target/release/examples/chat --username 'user1'\ -l 'tcp://127.0.0.1:40000' -d '40010'" Enter -tmux split-window -h -t karyons_chat -tmux send-keys -t karyons_chat "../../target/release/examples/chat --username 'user2'\ +tmux split-window -h -t karyon_chat +tmux send-keys -t karyon_chat "../../target/release/examples/chat --username 'user2'\ -l 'tcp://127.0.0.1:40001' -d '40011' -b 'tcp://127.0.0.1:40010 ' " Enter -tmux split-window -h -t karyons_chat -tmux send-keys -t karyons_chat "../../target/release/examples/chat --username 'user3'\ +tmux split-window -h -t karyon_chat +tmux send-keys -t karyon_chat "../../target/release/examples/chat --username 'user3'\ -l 'tcp://127.0.0.1:40002' -d '40012' -b 'tcp://127.0.0.1:40010'" Enter -tmux split-window -h -t karyons_chat -tmux send-keys -t karyons_chat "../../target/release/examples/chat --username 'user4'\ +tmux split-window -h -t karyon_chat +tmux send-keys -t karyon_chat "../../target/release/examples/chat --username 'user4'\ -b 'tcp://127.0.0.1:40010'" Enter tmux select-layout tiled -tmux attach -t karyons_chat +tmux attach -t karyon_chat diff --git a/p2p/examples/monitor.rs b/p2p/examples/monitor.rs index 0b6571c..b074352 100644 --- a/p2p/examples/monitor.rs +++ b/p2p/examples/monitor.rs @@ -5,10 +5,10 @@ use std::sync::Arc; use clap::Parser; use smol::{channel, Executor}; -use karyons_core::crypto::{KeyPair, KeyPairType}; -use karyons_net::{Endpoint, Port}; +use karyon_core::crypto::{KeyPair, KeyPairType}; +use karyon_net::{Endpoint, Port}; -use karyons_p2p::{Backend, Config}; +use karyon_p2p::{Backend, Config}; use shared::run_executor; diff --git a/p2p/examples/net_simulation.sh b/p2p/examples/net_simulation.sh index dd489e5..7cb8410 100755 --- a/p2p/examples/net_simulation.sh +++ b/p2p/examples/net_simulation.sh @@ -3,71 +3,71 @@ # build cargo build --release --example peer -tmux new-session -d -s karyons_p2p +tmux new-session -d -s karyon_p2p -tmux send-keys -t karyons_p2p "../../target/release/examples/peer\ +tmux send-keys -t karyon_p2p "../../target/release/examples/peer\ -l 'tcp://127.0.0.1:30000' -d '30010'" Enter -tmux split-window -h -t karyons_p2p -tmux send-keys -t karyons_p2p "../../target/release/examples/peer\ +tmux split-window -h -t karyon_p2p +tmux send-keys -t karyon_p2p "../../target/release/examples/peer\ -l 'tcp://127.0.0.1:30001' -d '30011' -b 'tcp://127.0.0.1:30010 ' " Enter -tmux split-window -h -t karyons_p2p -tmux send-keys -t karyons_p2p "../../target/release/examples/peer\ +tmux split-window -h -t karyon_p2p +tmux send-keys -t karyon_p2p "../../target/release/examples/peer\ -l 'tcp://127.0.0.1:30002' -d '30012' -b 'tcp://127.0.0.1:30010'" Enter -tmux split-window -h -t karyons_p2p -tmux send-keys -t karyons_p2p "../../target/release/examples/peer\ +tmux split-window -h -t karyon_p2p +tmux send-keys -t karyon_p2p "../../target/release/examples/peer\ -l 'tcp://127.0.0.1:30003' -d '30013' -b 'tcp://127.0.0.1:30010'" Enter -tmux split-window -h -t karyons_p2p -tmux send-keys -t karyons_p2p "../../target/release/examples/peer\ +tmux split-window -h -t karyon_p2p +tmux send-keys -t karyon_p2p "../../target/release/examples/peer\ -l 'tcp://127.0.0.1:30004' -d '30014' -b 'tcp://127.0.0.1:30010'" Enter -tmux split-window -h -t karyons_p2p -tmux send-keys -t karyons_p2p "../../target/release/examples/peer\ +tmux split-window -h -t karyon_p2p +tmux send-keys -t karyon_p2p "../../target/release/examples/peer\ -l 'tcp://127.0.0.1:30005' -d '30015' -b 'tcp://127.0.0.1:30010'" Enter tmux select-layout even-horizontal sleep 3; -tmux select-pane -t karyons_p2p:0.0 +tmux select-pane -t karyon_p2p:0.0 -tmux split-window -v -t karyons_p2p -tmux send-keys -t karyons_p2p "../../target/release/examples/peer\ +tmux split-window -v -t karyon_p2p +tmux send-keys -t karyon_p2p "../../target/release/examples/peer\ -b 'tcp://127.0.0.1:30010' -b 'tcp://127.0.0.1:30011'" Enter -tmux select-pane -t karyons_p2p:0.2 +tmux select-pane -t karyon_p2p:0.2 -tmux split-window -v -t karyons_p2p -tmux send-keys -t karyons_p2p "../../target/release/examples/peer\ +tmux split-window -v -t karyon_p2p +tmux send-keys -t karyon_p2p "../../target/release/examples/peer\ -b 'tcp://127.0.0.1:30010' -b 'tcp://127.0.0.1:30012' -p 'tcp://127.0.0.1:30005'" Enter -tmux select-pane -t karyons_p2p:0.4 +tmux select-pane -t karyon_p2p:0.4 -tmux split-window -v -t karyons_p2p -tmux send-keys -t karyons_p2p "../../target/release/examples/peer\ +tmux split-window -v -t karyon_p2p +tmux send-keys -t karyon_p2p "../../target/release/examples/peer\ -b 'tcp://127.0.0.1:30010' -b 'tcp://127.0.0.1:30013'" Enter -tmux select-pane -t karyons_p2p:0.6 +tmux select-pane -t karyon_p2p:0.6 -tmux split-window -v -t karyons_p2p -tmux send-keys -t karyons_p2p "../../target/release/examples/peer\ +tmux split-window -v -t karyon_p2p +tmux send-keys -t karyon_p2p "../../target/release/examples/peer\ -b 'tcp://127.0.0.1:30010' -b 'tcp://127.0.0.1:30014'" Enter -tmux select-pane -t karyons_p2p:0.8 +tmux select-pane -t karyon_p2p:0.8 -tmux split-window -v -t karyons_p2p -tmux send-keys -t karyons_p2p "../../target/release/examples/peer\ +tmux split-window -v -t karyon_p2p +tmux send-keys -t karyon_p2p "../../target/release/examples/peer\ -b 'tcp://127.0.0.1:30010' -b 'tcp://127.0.0.1:30015'" Enter -tmux select-pane -t karyons_p2p:0.10 +tmux select-pane -t karyon_p2p:0.10 -tmux split-window -v -t karyons_p2p -tmux send-keys -t karyons_p2p "../../target/release/examples/peer\ +tmux split-window -v -t karyon_p2p +tmux send-keys -t karyon_p2p "../../target/release/examples/peer\ -b 'tcp://127.0.0.1:30010' -b 'tcp://127.0.0.1:30015' -b 'tcp://127.0.0.1:30011'" Enter -# tmux set-window-option -t karyons_p2p synchronize-panes on +# tmux set-window-option -t karyon_p2p synchronize-panes on -tmux attach -t karyons_p2p +tmux attach -t karyon_p2p diff --git a/p2p/examples/peer.rs b/p2p/examples/peer.rs index c0b05c6..06586b6 100644 --- a/p2p/examples/peer.rs +++ b/p2p/examples/peer.rs @@ -5,10 +5,10 @@ use std::sync::Arc; use clap::Parser; use smol::{channel, Executor}; -use karyons_core::crypto::{KeyPair, KeyPairType}; -use karyons_net::{Endpoint, Port}; +use karyon_core::crypto::{KeyPair, KeyPairType}; +use karyon_net::{Endpoint, Port}; -use karyons_p2p::{Backend, Config}; +use karyon_p2p::{Backend, Config}; use shared::run_executor; diff --git a/p2p/examples/shared/mod.rs b/p2p/examples/shared/mod.rs index 9a8e387..aad40d7 100644 --- a/p2p/examples/shared/mod.rs +++ b/p2p/examples/shared/mod.rs @@ -3,7 +3,7 @@ use std::{num::NonZeroUsize, thread}; use easy_parallel::Parallel; use smol::{channel, future, future::Future}; -use karyons_core::Executor; +use karyon_core::Executor; /// Returns an estimate of the default amount of parallelism a program should use. /// see `std::thread::available_parallelism` diff --git a/p2p/src/backend.rs b/p2p/src/backend.rs index f0740b1..703e7de 100644 --- a/p2p/src/backend.rs +++ b/p2p/src/backend.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use log::info; -use karyons_core::{crypto::KeyPair, pubsub::Subscription, GlobalExecutor}; +use karyon_core::{crypto::KeyPair, pubsub::Subscription, GlobalExecutor}; use crate::{ config::Config, diff --git a/p2p/src/codec.rs b/p2p/src/codec.rs index e521824..726a2f7 100644 --- a/p2p/src/codec.rs +++ b/p2p/src/codec.rs @@ -2,12 +2,12 @@ use std::time::Duration; use bincode::{Decode, Encode}; -use karyons_core::{ +use karyon_core::{ async_util::timeout, util::{decode, encode, encode_into_slice}, }; -use karyons_net::{Connection, NetError}; +use karyon_net::{Connection, NetError}; use crate::{ message::{NetMsg, NetMsgCmd, NetMsgHeader, MAX_ALLOWED_MSG_SIZE, MSG_HEADER_SIZE}, diff --git a/p2p/src/config.rs b/p2p/src/config.rs index 2c5d5ec..fffbebd 100644 --- a/p2p/src/config.rs +++ b/p2p/src/config.rs @@ -1,4 +1,4 @@ -use karyons_net::{Endpoint, Port}; +use karyon_net::{Endpoint, Port}; use crate::Version; diff --git a/p2p/src/connection.rs b/p2p/src/connection.rs index e0a3bbd..9fa57cb 100644 --- a/p2p/src/connection.rs +++ b/p2p/src/connection.rs @@ -2,8 +2,8 @@ use std::{collections::VecDeque, fmt, sync::Arc}; use smol::{channel::Sender, lock::Mutex}; -use karyons_core::async_util::CondVar; -use karyons_net::Conn; +use karyon_core::async_util::CondVar; +use karyon_net::Conn; use crate::Result; diff --git a/p2p/src/connector.rs b/p2p/src/connector.rs index 835b1c9..12fbaed 100644 --- a/p2p/src/connector.rs +++ b/p2p/src/connector.rs @@ -2,12 +2,12 @@ use std::{future::Future, sync::Arc}; use log::{error, trace, warn}; -use karyons_core::{ +use karyon_core::{ async_util::{Backoff, TaskGroup, TaskResult}, crypto::KeyPair, GlobalExecutor, }; -use karyons_net::{dial, tls, Conn, Endpoint, NetError}; +use karyon_net::{dial, tls, Conn, Endpoint, NetError}; use crate::{ monitor::{ConnEvent, Monitor}, @@ -146,6 +146,6 @@ impl Connector { } else { dial(endpoint).await } - .map_err(Error::KaryonsNet) + .map_err(Error::KaryonNet) } } diff --git a/p2p/src/discovery/lookup.rs b/p2p/src/discovery/lookup.rs index aefc3a0..1d73306 100644 --- a/p2p/src/discovery/lookup.rs +++ b/p2p/src/discovery/lookup.rs @@ -5,9 +5,9 @@ use log::{error, trace}; use rand::{rngs::OsRng, seq::SliceRandom, RngCore}; use smol::lock::{Mutex, RwLock}; -use karyons_core::{async_util::timeout, crypto::KeyPair, util::decode, GlobalExecutor}; +use karyon_core::{async_util::timeout, crypto::KeyPair, util::decode, GlobalExecutor}; -use karyons_net::{Conn, Endpoint}; +use karyon_net::{Conn, Endpoint}; use crate::{ codec::Codec, diff --git a/p2p/src/discovery/mod.rs b/p2p/src/discovery/mod.rs index 8091991..040a415 100644 --- a/p2p/src/discovery/mod.rs +++ b/p2p/src/discovery/mod.rs @@ -7,13 +7,13 @@ use log::{error, info}; use rand::{rngs::OsRng, seq::SliceRandom}; use smol::lock::Mutex; -use karyons_core::{ +use karyon_core::{ async_util::{Backoff, TaskGroup, TaskResult}, crypto::KeyPair, GlobalExecutor, }; -use karyons_net::{Conn, Endpoint}; +use karyon_net::{Conn, Endpoint}; use crate::{ config::Config, diff --git a/p2p/src/discovery/refresh.rs b/p2p/src/discovery/refresh.rs index 180ac27..ed111fb 100644 --- a/p2p/src/discovery/refresh.rs +++ b/p2p/src/discovery/refresh.rs @@ -9,13 +9,13 @@ use smol::{ Timer, }; -use karyons_core::{ +use karyon_core::{ async_util::{timeout, Backoff, TaskGroup, TaskResult}, util::{decode, encode}, GlobalExecutor, }; -use karyons_net::{dial_udp, listen_udp, Addr, Connection, Endpoint, NetError, Port, UdpConn}; +use karyon_net::{dial_udp, listen_udp, Addr, Connection, Endpoint, NetError, Port, UdpConn}; /// Maximum failures for an entry before removing it from the routing table. pub const MAX_FAILURES: u32 = 3; @@ -200,7 +200,7 @@ impl RefreshService { while retry < self.config.refresh_connect_retries { match self.send_ping_msg(&conn).await { Ok(()) => return Ok(()), - Err(Error::KaryonsNet(NetError::Timeout)) => { + Err(Error::KaryonNet(NetError::Timeout)) => { retry += 1; backoff.sleep().await; } diff --git a/p2p/src/error.rs b/p2p/src/error.rs index 6274d4c..11de0f1 100644 --- a/p2p/src/error.rs +++ b/p2p/src/error.rs @@ -2,7 +2,7 @@ use thiserror::Error as ThisError; pub type Result<T> = std::result::Result<T, Error>; -/// Represents karyons's p2p Error. +/// Represents karyon's p2p Error. #[derive(ThisError, Debug)] pub enum Error { #[error(transparent)] @@ -75,10 +75,10 @@ pub enum Error { ChannelRecv(#[from] smol::channel::RecvError), #[error(transparent)] - KaryonsCore(#[from] karyons_core::error::Error), + KaryonCore(#[from] karyon_core::error::Error), #[error(transparent)] - KaryonsNet(#[from] karyons_net::NetError), + KaryonNet(#[from] karyon_net::NetError), } impl<T> From<smol::channel::SendError<T>> for Error { diff --git a/p2p/src/lib.rs b/p2p/src/lib.rs index 39f4bc1..3605359 100644 --- a/p2p/src/lib.rs +++ b/p2p/src/lib.rs @@ -7,8 +7,8 @@ //! use easy_parallel::Parallel; //! use smol::{channel as smol_channel, future, Executor}; //! -//! use karyons_core::crypto::{KeyPair, KeyPairType}; -//! use karyons_p2p::{Backend, Config, PeerID}; +//! use karyon_core::crypto::{KeyPair, KeyPairType}; +//! use karyon_p2p::{Backend, Config, PeerID}; //! //! let key_pair = KeyPair::generate(&KeyPairType::Ed25519); //! diff --git a/p2p/src/listener.rs b/p2p/src/listener.rs index 416a0d4..ab6f7c1 100644 --- a/p2p/src/listener.rs +++ b/p2p/src/listener.rs @@ -2,13 +2,13 @@ use std::{future::Future, sync::Arc}; use log::{debug, error, info}; -use karyons_core::{ +use karyon_core::{ async_util::{TaskGroup, TaskResult}, crypto::KeyPair, GlobalExecutor, }; -use karyons_net::{listen, tls, Conn, ConnListener, Endpoint}; +use karyon_net::{listen, tls, Conn, ConnListener, Endpoint}; use crate::{ monitor::{ConnEvent, Monitor}, @@ -159,6 +159,6 @@ impl Listener { } else { listen(endpoint).await } - .map_err(Error::KaryonsNet) + .map_err(Error::KaryonNet) } } diff --git a/p2p/src/message.rs b/p2p/src/message.rs index 6b23322..1342110 100644 --- a/p2p/src/message.rs +++ b/p2p/src/message.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use bincode::{Decode, Encode}; -use karyons_net::{Addr, Port}; +use karyon_net::{Addr, Port}; use crate::{protocol::ProtocolID, routing_table::Entry, version::VersionInt, PeerID}; diff --git a/p2p/src/monitor.rs b/p2p/src/monitor.rs index 1ea6a0b..b0ce028 100644 --- a/p2p/src/monitor.rs +++ b/p2p/src/monitor.rs @@ -2,9 +2,9 @@ use std::fmt; use crate::PeerID; -use karyons_core::pubsub::{ArcPublisher, Publisher, Subscription}; +use karyon_core::pubsub::{ArcPublisher, Publisher, Subscription}; -use karyons_net::Endpoint; +use karyon_net::Endpoint; /// Responsible for network and system monitoring. /// @@ -17,8 +17,8 @@ use karyons_net::Endpoint; /// /// use smol::Executor; /// -/// use karyons_core::crypto::{KeyPair, KeyPairType}; -/// use karyons_p2p::{Config, Backend, PeerID}; +/// use karyon_core::crypto::{KeyPair, KeyPairType}; +/// use karyon_p2p::{Config, Backend, PeerID}; /// /// async { /// diff --git a/p2p/src/peer/mod.rs b/p2p/src/peer/mod.rs index 37c0e2a..1e98f1b 100644 --- a/p2p/src/peer/mod.rs +++ b/p2p/src/peer/mod.rs @@ -10,14 +10,14 @@ use smol::{ lock::RwLock, }; -use karyons_core::{ +use karyon_core::{ async_util::{select, Either, TaskGroup, TaskResult}, event::{ArcEventSys, EventListener, EventSys}, util::{decode, encode}, GlobalExecutor, }; -use karyons_net::Endpoint; +use karyon_net::Endpoint; use crate::{ codec::{Codec, CodecMsg}, diff --git a/p2p/src/peer/peer_id.rs b/p2p/src/peer/peer_id.rs index 0208e05..f907aa7 100644 --- a/p2p/src/peer/peer_id.rs +++ b/p2p/src/peer/peer_id.rs @@ -2,7 +2,7 @@ use bincode::{Decode, Encode}; use rand::{rngs::OsRng, RngCore}; use sha2::{Digest, Sha256}; -use karyons_core::crypto::PublicKey; +use karyon_core::crypto::PublicKey; use crate::Error; diff --git a/p2p/src/peer_pool.rs b/p2p/src/peer_pool.rs index ee9ebf9..ead6d8f 100644 --- a/p2p/src/peer_pool.rs +++ b/p2p/src/peer_pool.rs @@ -10,13 +10,13 @@ use smol::{ lock::{Mutex, RwLock}, }; -use karyons_core::{ +use karyon_core::{ async_util::{TaskGroup, TaskResult}, util::decode, GlobalExecutor, }; -use karyons_net::Conn; +use karyon_net::Conn; use crate::{ codec::{Codec, CodecMsg}, diff --git a/p2p/src/protocol.rs b/p2p/src/protocol.rs index 7261f19..f28659c 100644 --- a/p2p/src/protocol.rs +++ b/p2p/src/protocol.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use async_trait::async_trait; -use karyons_core::event::EventValue; +use karyon_core::event::EventValue; use crate::{peer::ArcPeer, version::Version, Result}; @@ -37,8 +37,8 @@ impl EventValue for ProtocolEvent { /// use async_trait::async_trait; /// use smol::Executor; /// -/// use karyons_core::crypto::{KeyPair, KeyPairType}; -/// use karyons_p2p::{ +/// use karyon_core::crypto::{KeyPair, KeyPairType}; +/// use karyon_p2p::{ /// protocol::{ArcProtocol, Protocol, ProtocolID, ProtocolEvent}, /// Backend, PeerID, Config, Version, P2pError, ArcPeer}; /// diff --git a/p2p/src/protocols/ping.rs b/p2p/src/protocols/ping.rs index ec7afe2..22c1b3d 100644 --- a/p2p/src/protocols/ping.rs +++ b/p2p/src/protocols/ping.rs @@ -11,14 +11,14 @@ use smol::{ Timer, }; -use karyons_core::{ +use karyon_core::{ async_util::{select, timeout, Either, TaskGroup, TaskResult}, event::EventListener, util::decode, GlobalExecutor, }; -use karyons_net::NetError; +use karyon_net::NetError; use crate::{ peer::ArcPeer, diff --git a/p2p/src/routing_table/entry.rs b/p2p/src/routing_table/entry.rs index c5fa65d..3fc8a6b 100644 --- a/p2p/src/routing_table/entry.rs +++ b/p2p/src/routing_table/entry.rs @@ -1,6 +1,6 @@ use bincode::{Decode, Encode}; -use karyons_net::{Addr, Port}; +use karyon_net::{Addr, Port}; /// Specifies the size of the key, in bytes. pub const KEY_SIZE: usize = 32; diff --git a/p2p/src/routing_table/mod.rs b/p2p/src/routing_table/mod.rs index cfc3128..6854546 100644 --- a/p2p/src/routing_table/mod.rs +++ b/p2p/src/routing_table/mod.rs @@ -11,7 +11,7 @@ pub use entry::{xor_distance, Entry, Key}; use rand::{rngs::OsRng, seq::SliceRandom}; -use karyons_net::Addr; +use karyon_net::Addr; use bucket::BUCKET_SIZE; use entry::KEY_SIZE; @@ -284,7 +284,7 @@ mod tests { use super::bucket::ALL_ENTRY; use super::*; - use karyons_net::Addr; + use karyon_net::Addr; struct Setup { local_key: Key, diff --git a/p2p/src/slots.rs b/p2p/src/slots.rs index d3a1d0a..0ee0b93 100644 --- a/p2p/src/slots.rs +++ b/p2p/src/slots.rs @@ -1,6 +1,6 @@ use std::sync::atomic::{AtomicUsize, Ordering}; -use karyons_core::async_util::CondWait; +use karyon_core::async_util::CondWait; /// Manages available inbound and outbound slots. pub struct ConnectionSlots { diff --git a/p2p/src/tls_config.rs b/p2p/src/tls_config.rs index 5d5e90e..9fe64f5 100644 --- a/p2p/src/tls_config.rs +++ b/p2p/src/tls_config.rs @@ -8,7 +8,7 @@ use async_rustls::rustls::{ use log::error; use x509_parser::{certificate::X509Certificate, parse_x509_certificate}; -use karyons_core::crypto::{KeyPair, KeyPairType, PublicKey}; +use karyon_core::crypto::{KeyPair, KeyPairType, PublicKey}; use crate::{PeerID, Result}; diff --git a/p2p/src/version.rs b/p2p/src/version.rs index a101b28..f5cc1d6 100644 --- a/p2p/src/version.rs +++ b/p2p/src/version.rs @@ -5,12 +5,12 @@ use semver::VersionReq; use crate::{Error, Result}; -/// Represents the network version and protocol version used in karyons p2p. +/// Represents the network version and protocol version used in karyon p2p. /// /// # Example /// /// ``` -/// use karyons_p2p::Version; +/// use karyon_p2p::Version; /// /// let version: Version = "0.2.0, >0.1.0".parse().unwrap(); /// |