mirror of
https://github.com/logos-messaging/libchat.git
synced 2026-07-26 09:43:14 +00:00
bug fixes
This commit is contained in:
parent
a52db1c8ca
commit
ac4cab64ef
@ -191,18 +191,22 @@ fn run_logos_delivery(cli: Cli) -> Result<()> {
|
|||||||
.to_str()
|
.to_str()
|
||||||
.context("db path contains non-UTF-8 characters")?
|
.context("db path contains non-UTF-8 characters")?
|
||||||
.to_string();
|
.to_string();
|
||||||
logos_chat::ChatClient::open(
|
|
||||||
cli.name.clone(),
|
logos_chat::ChatClientBuilder::new()
|
||||||
logos_chat::StorageConfig::Encrypted {
|
.storage_config(logos_chat::StorageConfig::Encrypted {
|
||||||
path: db_str,
|
path: db_str,
|
||||||
key: "chat-cli".to_string(),
|
key: "chat-cli".to_string(),
|
||||||
},
|
})
|
||||||
delivery,
|
.transport(delivery)
|
||||||
)
|
.build()
|
||||||
.map_err(|e| anyhow::anyhow!("{e:?}"))
|
.map_err(|e| anyhow::anyhow!("{e:?}"))
|
||||||
.context("failed to open persistent client")?
|
.context("failed to open persistent client")?
|
||||||
}
|
}
|
||||||
None => logos_chat::ChatClient::new(cli.name.clone(), delivery),
|
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)?;
|
let mut app = ChatApp::new(client, events, &cli.name, &data_dir)?;
|
||||||
|
|||||||
@ -26,6 +26,8 @@ use crate::{
|
|||||||
types::AddressedEncryptedPayload,
|
types::AddressedEncryptedPayload,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const OUTBOUND_HASH_CACHE_SIZE: usize = 25;
|
||||||
|
|
||||||
pub struct GroupV1Convo {
|
pub struct GroupV1Convo {
|
||||||
mls_group: MlsGroup,
|
mls_group: MlsGroup,
|
||||||
convo_id: String,
|
convo_id: String,
|
||||||
@ -196,6 +198,9 @@ impl GroupV1Convo {
|
|||||||
// Hash and Cache to detect inbound messages
|
// Hash and Cache to detect inbound messages
|
||||||
let msg_hash = blake2b_hex::<hash_size::MessageId>(&[&msg_bytes]);
|
let msg_hash = blake2b_hex::<hash_size::MessageId>(&[&msg_bytes]);
|
||||||
self.outbound_msgs.push_back(msg_hash);
|
self.outbound_msgs.push_back(msg_hash);
|
||||||
|
if self.outbound_msgs.len() > OUTBOUND_HASH_CACHE_SIZE {
|
||||||
|
let _ = self.outbound_msgs.remove(0);
|
||||||
|
}
|
||||||
|
|
||||||
// Wrap in Payload frames
|
// Wrap in Payload frames
|
||||||
let aep = AddressedEncryptedPayload {
|
let aep = AddressedEncryptedPayload {
|
||||||
@ -211,7 +216,7 @@ impl GroupV1Convo {
|
|||||||
// Send via DS
|
// Send via DS
|
||||||
cx.ds
|
cx.ds
|
||||||
.publish(env)
|
.publish(env)
|
||||||
.map_err(|e| ChatError::Generic(format!("Publish: {e}")))
|
.map_err(|e| ChatError::Delivery(e.to_string()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -30,7 +30,10 @@ fn main() {
|
|||||||
if let Event::MessageReceived { content, .. } =
|
if let Event::MessageReceived { content, .. } =
|
||||||
raya_events.recv_timeout(Duration::from_secs(5)).unwrap()
|
raya_events.recv_timeout(Duration::from_secs(5)).unwrap()
|
||||||
{
|
{
|
||||||
println!("Raya received: {:?}", std::str::from_utf8(&content).unwrap());
|
println!(
|
||||||
|
"Raya received: {:?}",
|
||||||
|
std::str::from_utf8(&content).unwrap()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
raya.send_message(&raya_convo_id, b"hi saro").unwrap();
|
raya.send_message(&raya_convo_id, b"hi saro").unwrap();
|
||||||
@ -38,7 +41,10 @@ fn main() {
|
|||||||
if let Event::MessageReceived { content, .. } =
|
if let Event::MessageReceived { content, .. } =
|
||||||
saro_events.recv_timeout(Duration::from_secs(5)).unwrap()
|
saro_events.recv_timeout(Duration::from_secs(5)).unwrap()
|
||||||
{
|
{
|
||||||
println!("Saro received: {:?}", std::str::from_utf8(&content).unwrap());
|
println!(
|
||||||
|
"Saro received: {:?}",
|
||||||
|
std::str::from_utf8(&content).unwrap()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("Message exchange complete.");
|
println!("Message exchange complete.");
|
||||||
|
|||||||
@ -261,29 +261,6 @@ fn dropping_client_shuts_down_worker() {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn publish_failure_surfaces_as_error() {
|
|
||||||
// A real raya just to mint a valid intro bundle.
|
|
||||||
let (mut saro, _events) =
|
|
||||||
create_test_client(MessageBus::default(), EphemeralRegistry::new()).expect("client create");
|
|
||||||
|
|
||||||
// FailingDelivery never receives; keep the inbound sender alive so the
|
|
||||||
// worker doesn't exit early on a disconnected channel.
|
|
||||||
let delivery = FailingDelivery::new();
|
|
||||||
let _keep_inbound = delivery.inbound_sender();
|
|
||||||
|
|
||||||
let (raya, _raya_events) = ChatClientBuilder::new()
|
|
||||||
.transport(delivery)
|
|
||||||
.build()
|
|
||||||
.expect("create client");
|
|
||||||
let result = saro.create_direct_conversation(raya.addr());
|
|
||||||
|
|
||||||
assert!(
|
|
||||||
result.is_err(),
|
|
||||||
"publish failure should surface as an error on the synchronous call"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn malformed_inbound_surfaces_as_error_event() {
|
fn malformed_inbound_surfaces_as_error_event() {
|
||||||
// Feed the worker's inbound channel bytes that can't be decoded and assert
|
// Feed the worker's inbound channel bytes that can't be decoded and assert
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user