Skip to content
Closed
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
15 changes: 9 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ jobs:
steps:
- uses: actions/checkout@v4
- run: rustup update stable && rustup default stable
- uses: Swatinem/rust-cache@v2
# 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's build.rs unconditionally links liblogosdelivery and requires
# LOGOS_DELIVERY_LIB_DIR. The smoketest job builds and exercises it under
# Nix; here we keep the toolchain-only job fast by skipping it.
# 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

Expand All @@ -33,6 +35,7 @@ jobs:
- uses: actions/checkout@v4
- run: rustup update stable && rustup default stable
- run: rustup component add clippy
- uses: Swatinem/rust-cache@v2
# 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
- run: cargo clippy --all-targets --all-features --workspace --exclude chat-cli -- -D warnings
Expand Down Expand Up @@ -72,13 +75,13 @@ jobs:
# nim-zlib instead of reusing a cached output. No retry on purpose: a
# single build must now succeed deterministically. Re-run the job a few
# times for more samples.
run: nix build .#logos-delivery --override-input nixpkgs github:kaichaosun/nixpkgs/fix-gitfetch --print-build-logs
run: nix build .#logos-delivery --print-build-logs
# Build and run chat-cli through the dev shell so it links against the
# same Nix glibc as the prebuilt liblogosdelivery.so. A plain `cargo
# build` uses the runner's system glibc, which is older than Nix's and
# mismatches it at runtime (libc.so.6: version `GLIBC_ABI_DT_X86_64_PLT'
# not found, required by Nix glibc's libm.so.6).
- name: Build chat-cli (logos-delivery)
run: nix develop -c bash -c 'LOGOS_DELIVERY_LIB_DIR=./result/lib cargo build --release -p chat-cli'
- name: Build chat-cli
run: nix develop -c bash -c 'cargo build -p chat-cli'
- name: Run chat-cli smoketest
run: nix develop -c ./target/release/chat-cli --name ci-test --smoketest
2 changes: 2 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions bin/chat-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ path = "src/main.rs"

[dependencies]
# Workspace dependencies (sorted)
components = { workspace = true , features = ["embedded_p2p_delivery"]}
crossbeam-channel = { workspace = true }
logos-chat = { workspace = true }


# External dependencies (sorted)
anyhow = "1.0"
arboard = "3"
Expand Down
18 changes: 0 additions & 18 deletions bin/chat-cli/build.rs

This file was deleted.

99 changes: 25 additions & 74 deletions bin/chat-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,33 @@ use logos_chat::{
RegistrationService, StorageConfig, Transport,
};

use components::{EmbeddedP2pDeliveryService, P2pConfig};

#[derive(Debug)]
struct P2pTransport(EmbeddedP2pDeliveryService);

impl logos_chat::DeliveryService for P2pTransport {
type Error = <EmbeddedP2pDeliveryService as logos_chat::DeliveryService>::Error;
fn publish(&mut self, envelope: logos_chat::AddressedEnvelope) -> Result<(), Self::Error> {
self.0.publish(envelope)
}
fn subscribe(&mut self, addr: &str) -> Result<(), Self::Error> {
self.0.subscribe(addr)
}
}

impl logos_chat::Transport for P2pTransport {
fn inbound(&mut self) -> crossbeam_channel::Receiver<Vec<u8>> {
self.0.inbound_queue()
}
}

use app::ChatApp;

#[derive(Copy, Clone, Debug, ValueEnum)]
#[value(rename_all = "kebab-case")]
enum TransportKind {
File,
#[cfg(logos_delivery)]
LogosDelivery,
}

Expand Down Expand Up @@ -79,19 +99,18 @@ fn main() -> Result<()> {
.context("failed to create file transport")?;
run(transport, &cli)
}
#[cfg(logos_delivery)]
TransportKind::LogosDelivery => {
use transport::logos_delivery::{Config, Service};

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

let cfg = Config {
let cfg = P2pConfig {
preset: cli.preset.clone(),
tcp_port: cli.port,
..Default::default()
};
let transport = Service::start(cfg).context("failed to start logos-delivery")?;
let transport = P2pTransport(
EmbeddedP2pDeliveryService::start(cfg).context("failed to start logos-delivery")?,
);

println!("Node connected. Initializing chat client...");
run(transport, &cli)
Expand Down Expand Up @@ -160,74 +179,6 @@ where
result
}

#[cfg_attr(not(logos_delivery), allow(dead_code, unused_variables))]
fn run_logos_delivery(cli: Cli) -> Result<()> {
#[cfg(logos_delivery)]
{
use transport::logos_delivery::{Config, Service};

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

let logos_cfg = Config {
preset: cli.preset.clone(),
tcp_port: cli.port,
..Default::default()
};
let delivery = Service::start(logos_cfg).context("failed to start logos-delivery")?;

eprintln!("Node connected. Initializing chat client...");

let data_dir = cli
.db
.as_ref()
.and_then(|p| p.parent())
.map(|p| p.to_path_buf())
.unwrap_or_else(|| cli.data.clone());

let (client, events) = match cli.db {
Some(ref path) => {
let db_str = path
.to_str()
.context("db path contains non-UTF-8 characters")?
.to_string();

logos_chat::ChatClientBuilder::new()
.storage_config(logos_chat::StorageConfig::Encrypted {
path: db_str,
key: "chat-cli".to_string(),
})
.transport(delivery)
.build()
.map_err(|e| anyhow::anyhow!("{e:?}"))
.context("failed to open persistent client")?
}
None => logos_chat::ChatClientBuilder::new()
.transport(delivery)
.build()
.map_err(|e| anyhow::anyhow!("{e:?}"))
.context("failed to open chat client")?,
};

let mut app = ChatApp::new(client, events, &cli.name, &data_dir)?;

if cli.smoketest {
return Ok(());
}

let mut terminal = ui::init().context("failed to initialize terminal")?;
let result = run_app(&mut terminal, &mut app);
ui::restore().context("failed to restore terminal")?;
return result;
}

#[cfg(not(logos_delivery))]
anyhow::bail!(
"logos-delivery transport is not available in this build.\n\
Build with LOGOS_DELIVERY_LIB_DIR set to enable it."
)
}

fn run_app<I, T, R, S>(terminal: &mut ui::Tui, app: &mut ChatApp<I, T, R, S>) -> Result<()>
where
I: IdentityProvider + Send,
Expand Down
2 changes: 0 additions & 2 deletions bin/chat-cli/src/transport.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
pub mod file;
#[cfg(logos_delivery)]
pub mod logos_delivery;
5 changes: 5 additions & 0 deletions extensions/components/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
name = "components"
version = "0.1.0"
edition = "2024"
links = "logosdelivery"

[features]
embedded_p2p_delivery = []

[dependencies]
# Workspace dependencies (sorted)
Expand All @@ -15,5 +19,6 @@ crossbeam-channel = { workspace = true }
hex = "0.4.3"
reqwest = { version = "0.12", default-features = false, features = ["blocking", "json", "rustls-tls"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
thiserror = "2"
tracing = "0.1"
Loading
Loading