Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(libp2p): typed data crate + client server feature set #2877

Merged
merged 14 commits into from
Jan 9, 2025
19 changes: 16 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ torii-graphql = { path = "crates/torii/graphql" }
torii-grpc = { path = "crates/torii/grpc" }
torii-relay = { path = "crates/torii/libp2p" }
torii-server = { path = "crates/torii/server" }
torii-typed-data = { path = "crates/torii/typed-data" }

# saya
saya-core = { path = "crates/saya/core" }
Expand Down
2 changes: 1 addition & 1 deletion crates/torii/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ starknet-crypto.workspace = true
thiserror.workspace = true
tokio = { version = "1.32.0", features = [ "sync" ], default-features = false }
torii-grpc = { workspace = true, features = [ "client" ] }
torii-relay = { workspace = true }
torii-relay = { workspace = true, features = [ "client" ] }
url.workspace = true

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/torii/client/src/client/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub enum Error {
#[error(transparent)]
GrpcClient(#[from] torii_grpc::client::Error),
#[error(transparent)]
RelayClient(#[from] torii_relay::errors::Error),
RelayClient(#[from] torii_relay::error::Error),
#[error(transparent)]
Model(#[from] ModelError),
#[error("Unsupported query")]
Expand Down
15 changes: 9 additions & 6 deletions crates/torii/libp2p/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ name = "torii-relay"
repository.workspace = true
version.workspace = true

[features]
client = [ ]
default = [ "client", "server" ]
server = [ "dep:sqlx", "dep:torii-core" ]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
Expand All @@ -13,17 +18,17 @@ rand.workspace = true
serde.workspace = true
# preserve order
anyhow.workspace = true
cainome.workspace = true
chrono.workspace = true
crypto-bigint.workspace = true
dojo-types.workspace = true
dojo-world.workspace = true
indexmap.workspace = true
serde_json.workspace = true
starknet-crypto.workspace = true
starknet.workspace = true
starknet-crypto.workspace = true
thiserror.workspace = true
torii-typed-data.workspace = true
tracing.workspace = true
sqlx = { workspace = true, optional = true }
torii-core = { workspace = true, optional = true }

[dev-dependencies]
katana-runner.workspace = true
Expand All @@ -34,8 +39,6 @@ tracing-subscriber.workspace = true
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
libp2p = { git = "https://github.com/libp2p/rust-libp2p", features = [ "dns", "ed25519", "gossipsub", "identify", "macros", "noise", "ping", "quic", "relay", "tcp", "tokio", "websocket", "yamux" ], rev = "cdc9638" }
libp2p-webrtc = { git = "https://github.com/libp2p/rust-libp2p", features = [ "pem", "tokio" ], rev = "cdc9638" }
sqlx.workspace = true
torii-core.workspace = true

[target.'cfg(target_arch = "wasm32")'.dependencies]
libp2p = { git = "https://github.com/libp2p/rust-libp2p", features = [ "ed25519", "gossipsub", "identify", "macros", "noise", "ping", "tcp", "wasm-bindgen", "yamux" ], rev = "cdc9638" }
Expand Down
2 changes: 1 addition & 1 deletion crates/torii/libp2p/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use tracing::info;
pub mod events;
use crate::client::events::ClientEvent;
use crate::constants;
use crate::errors::Error;
use crate::error::Error;
use crate::types::Message;

pub(crate) const LOG_TARGET: &str = "torii::relay::client";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use libp2p::gossipsub::{PublishError, SubscriptionError};
use libp2p::noise;
use starknet::providers::ProviderError;
use thiserror::Error;
use torii_typed_data::error::Error as TypedDataError;

#[derive(Error, Debug)]
pub enum Error {
Expand Down Expand Up @@ -41,12 +42,15 @@ pub enum Error {
#[error("Failed to read certificate: {0}")]
ReadCertificateError(anyhow::Error),

#[error("Invalid message provided: {0}")]
InvalidMessageError(String),

#[error("Invalid type provided: {0}")]
InvalidTypeError(String),

#[error(transparent)]
ProviderError(#[from] ProviderError),

#[error(transparent)]
TypedDataError(#[from] TypedDataError),

#[error("Invalid message provided: {0}")]
InvalidMessageError(String),
}
14 changes: 9 additions & 5 deletions crates/torii/libp2p/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#![warn(unused_crate_dependencies)]

pub mod client;
mod constants;
pub mod errors;
#[cfg(not(target_arch = "wasm32"))]
pub mod error;

#[cfg(feature = "client")]
pub mod client;
#[cfg(feature = "server")]
pub mod server;
mod tests;
pub mod typed_data;

#[cfg(test)]
mod test;

pub mod types;
7 changes: 4 additions & 3 deletions crates/torii/libp2p/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ use tracing::{info, warn};
use webrtc::tokio::Certificate;

use crate::constants;
use crate::errors::Error;
use crate::error::Error;

mod events;

use torii_typed_data::typed_data::{parse_value_to_ty, PrimitiveType, TypedData};

use crate::server::events::ServerEvent;
use crate::typed_data::{parse_value_to_ty, PrimitiveType, TypedData};
use crate::types::Message;

pub(crate) const LOG_TARGET: &str = "torii::relay::server";
Expand Down Expand Up @@ -128,7 +129,7 @@ impl<P: Provider + Sync> Relay<P> {
relay: relay::Behaviour::new(key.public().to_peer_id(), Default::default()),
ping: ping::Behaviour::new(ping::Config::new()),
identify: identify::Behaviour::new(identify::Config::new(
format!("/torii-relay/{}", env!("CARGO_PKG_VERSION")),
format!("/{}/{}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION")),
key.public(),
)),
gossipsub: gossipsub::Behaviour::new(
Expand Down
Loading
Loading