Skip to content
Open
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
14 changes: 7 additions & 7 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion core/conversations/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ storage = { workspace = true }
alloy = "2.0"
base64 = "0.22"
chat-proto = { git = "https://github.com/logos-messaging/chat_proto", rev = "37ec98a151f6d50aab2905802ac0a896477e62ea" }
de-mls = { git = "https://github.com/vacp2p/de-mls", tag = "v4.0.0" }
de-mls = { git = "https://github.com/vacp2p/de-mls", branch = "main"}
double-ratchets = { path = "../double-ratchets" }
hashgraph-like-consensus = "0.5.1"
hex = "0.4.3"
Expand Down
54 changes: 16 additions & 38 deletions core/conversations/src/conversation/group_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@ use crate::{Content, WakeupService};
use alloy::signers::local::PrivateKeySigner;
use blake2::{Blake2b, Digest, digest::consts::U6};
use chat_proto::logoschat::encryption::{EncryptedPayload, Plaintext, encrypted_payload};
use de_mls::defaults::{
DefaultConsensusPlugin, DefaultPeerScoring, DefaultStewardList, InMemoryPeerScoreStorage,
};
use de_mls::protos::de_mls::messages::v1::{
AppMessage as AppMessageProto, MemberWelcome, app_message,
};
use de_mls::{
ConsensusPlugin, ConsensusServiceFor, Conversation, ConversationConfig, ConversationEvent,
DeterministicStewardList, PeerScoringService, ScoringConfig, StewardListConfig,
Conversation, ConversationConfig, ConversationEvent, PeerScoringService, ScoringConfig,
default_score_deltas,
defaults::{DefaultConsensusPlugin, DefaultPeerScoring, InMemoryPeerScoreStorage},
};
use hashgraph_like_consensus::signing::EthereumConsensusSigner;
use prost::Message;
Expand Down Expand Up @@ -48,27 +45,16 @@ fn rand_app_id() -> Arc<[u8]> {
/// Peer-scoring plug-in: the library default over in-memory storage.
fn make_scoring() -> DefaultPeerScoring {
PeerScoringService::new(
InMemoryPeerScoreStorage::new(),
InMemoryPeerScoreStorage::default(),
default_score_deltas(),
ScoringConfig::default(),
)
}

/// Steward-list plug-in: the library default, seedless — the library stamps the
/// conversation-id sort salt when it builds the conversation.
fn make_steward() -> DefaultStewardList {
DeterministicStewardList::empty(StewardListConfig::default())
}

/// Consensus service: the library default over a fresh in-memory store and a
/// random Ethereum consensus signer.
fn make_consensus() -> ConsensusServiceFor<DefaultConsensusPlugin> {
ConsensusServiceFor::<DefaultConsensusPlugin>::new_with_components(
DefaultConsensusPlugin::new_storage(),
DefaultConsensusPlugin::new_event_bus(),
EthereumConsensusSigner::new(PrivateKeySigner::random()),
10,
)
fn make_consensus() -> DefaultConsensusPlugin {
DefaultConsensusPlugin::new(EthereumConsensusSigner::new(PrivateKeySigner::random()))
Comment on lines +56 to +57

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[?] In the future should the consensus signer match the MLS Signer? Or is it best to keep it separate?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +56 to +57

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[?] It is safe to assume in the future that any implementor of ConsensusSignatureScheme would suffice here? Or is there a strict dependence on secp256K1 or the ethAddress format?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No strict dependency anymore. At least I tried implementing general trait based on this idea, so if you find any contradictions let me know

}

/// TEST-ONLY millisecond timers. de-mls deadlines are real wall-clock, so the
Expand All @@ -88,7 +74,7 @@ fn demls_config() -> ConversationConfig {

pub struct GroupV2Convo {
convo_id: String,
conversation: Conversation<DefaultConsensusPlugin, DefaultPeerScoring, DefaultStewardList>,
conversation: Conversation<DefaultConsensusPlugin, InMemoryPeerScoreStorage>,
/// Member-ids we proposed via add_member. We forward a welcome only to joiners WE invited.
pending_invites: Vec<Vec<u8>>,
}
Expand All @@ -111,19 +97,17 @@ impl GroupV2Convo {
service_ctx: &mut ServiceContext<S>,
) -> Result<Self, ChatError> {
let convo_id = rand_string(5);
let member = member_id(service_ctx);
let conversation = Conversation::create(
&convo_id,
&member_id(service_ctx),
&service_ctx.mls_provider,
service_ctx.mls_identity.get_credential(),
CIPHER_SUITE,
&service_ctx.mls_identity,
&make_consensus(),
make_scoring(),
make_steward(),
make_consensus(),
rand_app_id(),
demls_config(),
&member,
)?;
let convo = GroupV2Convo {
convo_id,
Expand All @@ -145,18 +129,16 @@ impl GroupV2Convo {
service_ctx: &mut ServiceContext<S>,
welcome: &MemberWelcome,
) -> Result<Self, ChatError> {
let member = member_id(service_ctx);
let Some(conv) = Conversation::join(
&member_id(service_ctx),
&service_ctx.mls_provider,
&service_ctx.mls_identity,
&welcome.welcome_bytes,
&welcome.conversation_sync_bytes,
&make_consensus(),
make_scoring(),
make_steward(),
make_consensus(),
rand_app_id(),
demls_config(),
&member,
&service_ctx.mls_identity,
)?
else {
return Err(ChatError::generic("welcome not addressed to this member"));
Expand Down Expand Up @@ -217,8 +199,8 @@ where
) -> Result<(), ChatError> {
self.conversation.send_message(
&service_ctx.mls_provider,
content.to_vec(),
&service_ctx.mls_identity,
content.to_vec(),
)?;
self.after_op(service_ctx)?;
Ok(())
Expand All @@ -244,9 +226,9 @@ where

self.conversation.process_inbound(
&service_ctx.mls_provider,
&service_ctx.mls_identity,
&frame.sender_app_id,
&inner,
&service_ctx.mls_identity,
)?;
self.conversation
.poll(&service_ctx.mls_provider, &service_ctx.mls_identity);
Expand Down Expand Up @@ -289,7 +271,6 @@ where
// Record who WE invited before touching the conversation: after_op
// forwards a welcome only to joiners in pending_invites (the de-mls
// member-id is the invitee's id bytes).
let mut kps = Vec::with_capacity(members.len());
for member in members {
let kp_bytes = service_ctx
.registry
Expand All @@ -298,14 +279,11 @@ where
.ok_or_else(|| ChatError::generic("No key package"))?;
self.pending_invites
.push(member.as_str().as_bytes().to_vec());
kps.push(kp_bytes);
}

for kp_bytes in &kps {
self.conversation.add_member(
&service_ctx.mls_provider,
kp_bytes,
&service_ctx.mls_identity,
member.as_str().as_bytes(),
&kp_bytes,
)?;
}
self.after_op(service_ctx)?;
Expand Down Expand Up @@ -379,7 +357,7 @@ impl GroupV2Convo {

fn events_to_content(&self, events: &[ConversationEvent]) -> Option<ConvoOutcome> {
events.iter().find_map(|evt| match evt {
ConversationEvent::AppMessage(AppMessageProto {
ConversationEvent::ConversationMessage(AppMessageProto {
payload: Some(app_message::Payload::ConversationMessage(cm)),
}) => Some(ConvoOutcome {
convo_id: self.convo_id.clone(),
Expand Down
Loading