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
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ jobs:
- run: rustup update stable && rustup default stable
# hashgraph-like-consensus's build.rs shells out to protoc via prost-build.
- run: sudo apt-get update && sudo apt-get install -y protobuf-compiler
# chat-cli pulls in components' embedded_p2p_delivery feature, whose
# build.rs links liblogosdelivery (built via Nix or LOGOS_DELIVERY_LIB_DIR).
# The smoketest job builds and exercises it under Nix; here we keep the
# toolchain-only job fast by skipping it.
- run: cargo build --verbose --workspace --exclude chat-cli
- run: cargo test --verbose --workspace --exclude chat-cli
# chat-cli and the embedded-logos-delivery crate link liblogosdelivery
# (built via Nix or LOGOS_DELIVERY_LIB_DIR). The smoketest job builds and
# exercises them under Nix; here we keep the toolchain-only job fast by
# skipping them.
- run: cargo build --verbose --workspace --exclude chat-cli --exclude embedded-logos-delivery
- run: cargo test --verbose --workspace --exclude chat-cli --exclude embedded-logos-delivery

clippy:
name: Clippy
Expand Down
26 changes: 26 additions & 0 deletions Cargo.lock

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

10 changes: 7 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ members = [
"core/shared-traits",
"core/sqlite",
"core/storage",
"crates/client",
"crates/logos-chat",
"crates/generic-chat",
"extensions/components",
"extensions/embedded-logos-delivery",
]

default-members = [
Expand All @@ -25,7 +27,7 @@ default-members = [
"core/shared-traits",
"core/sqlite",
"core/storage",
"crates/client",
"crates/generic-chat",
]

[workspace.dependencies]
Expand All @@ -34,8 +36,10 @@ logos-account = { path = "core/account" }
chat-sqlite = { path = "core/sqlite" }
components = { path = "extensions/components" }
crypto = { path = "core/crypto" }
embedded-logos-delivery = { path = "extensions/embedded-logos-delivery" }
libchat = { path = "core/conversations" }
logos-chat = { path = "crates/client" }
logos-chat = { path = "crates/logos-chat" }
logos-generic-chat = { path = "crates/generic-chat" }
shared-traits = { path = "core/shared-traits" }
storage = { path = "core/storage" }

Expand Down
2 changes: 1 addition & 1 deletion bin/chat-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ path = "src/main.rs"
# Workspace dependencies (sorted)
crossbeam-channel = { workspace = true }
logos-account = { workspace = true, features = ["dev"] }
logos-chat = { workspace = true, features = ["embedded-p2p-delivery"] }
logos-chat = { workspace = true }

# External dependencies (sorted)
anyhow = "1.0"
Expand Down
56 changes: 21 additions & 35 deletions bin/chat-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ use std::path::{Path, PathBuf};
use anyhow::{Context, Result};
use clap::{Parser, ValueEnum};
use crossbeam_channel::Receiver;
use logos_account::TestLogosAccount;
use logos_chat::{
AccountDirectory, ChatClient, ChatClientBuilder, ChatStore, DelegateSigner, Event,
HttpRegistry, LogosChatClient, LogosConfig, NETWORK_PRESET, REGISTRY_ENDPOINT,
RegistrationService, StorageConfig, Transport,
AccountDirectory, ChatClient, ChatStore, Event, LogosConfig, P2pConfig, RegistrationService,
Transport,
};

use app::ChatApp;
Expand Down Expand Up @@ -78,24 +76,27 @@ fn main() -> Result<()> {
let db_str = db_path(&cli)?;

match cli.transport {
// logos-delivery is the transport baked into `LogosChatClient`, so the
// Logos client opens it from config rather than receiving one.
TransportKind::LogosDelivery => {
let preset = cli.preset.as_deref().unwrap_or(NETWORK_PRESET);
println!("Starting logos-delivery node (preset={preset})...");
println!("This may take a few seconds while connecting to the network.");

let mut config = LogosConfig::new(db_str, "chat-cli");
let mut p2p_config = P2pConfig::default();
if let Some(port) = cli.port {
config.set_tcp_port(port);
p2p_config.tcp_port = port;
}
if let Some(preset) = cli.preset.as_deref() {
config.set_preset(preset);
p2p_config.preset = preset.to_string();
}

println!(
"Starting logos-delivery node (preset={})...",
p2p_config.preset
);
println!("This may take a few seconds while connecting to the network.");

let mut config = LogosConfig::new(db_str, "chat-cli");
if let Some(registry_url) = cli.registry_url.as_deref() {
config.set_registry_url(registry_url);
}
let (client, events) = LogosChatClient::open(config)
config.set_p2p_config(p2p_config);
let (client, events) = logos_chat::open(config)
.map_err(|e| anyhow::anyhow!("{e:?}"))
.context("failed to open chat client")?;

Expand All @@ -104,32 +105,17 @@ fn main() -> Result<()> {
}
// The file transport is a local-only path: it reuses the Logos service
// stack (delegate identity, HTTP registry, encrypted storage) but swaps
// the transport, so it builds a client directly instead of going through
// `LogosChatClient`.
// the transport in via `open_with_transport`.
TransportKind::File => {
let transport_dir = cli.data.join("transport");
let transport = transport::file::FileTransport::new(&transport_dir)
.context("failed to create file transport")?;

let endpoint = cli.registry_url.as_deref().unwrap_or(REGISTRY_ENDPOINT);
// A fresh dev account endorsing a fresh delegate each launch,
// mirroring `LogosChatClient::open`.
let account = TestLogosAccount::new();
let delegate = DelegateSigner::random();
let mut registry = HttpRegistry::new(endpoint);
account
.add_delegate_signer(&mut registry, delegate.public_key())
.map_err(|e| anyhow::anyhow!("{e:?}"))
.context("failed to publish the device bundle")?;
let (client, events) = ChatClientBuilder::new(account.address())
.ident(delegate)
.transport(transport)
.registration(registry)
.storage_config(StorageConfig::Encrypted {
path: db_str,
key: "chat-cli".to_string(),
})
.build()
let mut config = LogosConfig::new(db_str, "chat-cli");
if let Some(registry_url) = cli.registry_url.as_deref() {
config.set_registry_url(registry_url);
}
let (client, events) = logos_chat::open_with_transport(config, transport)
.map_err(|e| anyhow::anyhow!("{e:?}"))
.context("failed to open chat client")?;

Expand Down
10 changes: 0 additions & 10 deletions crates/client/src/config.rs

This file was deleted.

123 changes: 0 additions & 123 deletions crates/client/src/logos.rs

This file was deleted.

5 changes: 1 addition & 4 deletions crates/client/Cargo.toml → crates/generic-chat/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
[package]
name = "logos-chat"
name = "logos-generic-chat"
version = "0.1.0"
edition = "2024"

[lib]
crate-type = ["rlib"]

[features]
embedded-p2p-delivery = ["components/embedded_p2p_delivery"]

[dependencies]
# Workspace dependencies (sorted)
chat-sqlite = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# message-exchange

An example Rust application built on top of [`crates/client`](../../).
An example Rust application built on top of [`crates/generic-chat`](../../).

It demonstrates that creating a working chat client in pure Rust is trivial: depend on
`crates/client`, pick a `DeliveryService` implementation (here the in-memory
`crates/generic-chat`, pick a `DeliveryService` implementation (here the in-memory
`InProcessDelivery` shipped with the crate), and wire up `ChatClient`. No boilerplate, no FFI.

## Running
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use components::EphemeralRegistry;
use logos_account::TestLogosAccount;
use logos_chat::{ChatClientBuilder, Event, InProcessDelivery, MessageBus};
use logos_generic_chat::{ChatClientBuilder, Event, InProcessDelivery, MessageBus};
use std::time::Duration;

fn main() {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 0 additions & 6 deletions crates/client/src/lib.rs → crates/generic-chat/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
mod builder;
mod client;
mod config;
mod delegate;
mod delivery_in_process;
mod errors;
mod event;
#[cfg(feature = "embedded-p2p-delivery")]
mod logos;

pub use builder::{ChatClientBuilder, Unset};
pub use client::{ChatClient, Transport};
pub use config::{DEFAULT_TCP_PORT, NETWORK_PRESET, REGISTRY_ENDPOINT};
pub use delegate::DelegateSigner;
pub use delivery_in_process::{InProcessDelivery, MessageBus};
pub use errors::ClientError;
pub use event::{Event, MessageSender};
#[cfg(feature = "embedded-p2p-delivery")]
pub use logos::{LogosChatClient, LogosConfig};

// Re-export types callers need to interact with ChatClient.
pub use libchat::{
Expand Down
Loading
Loading