-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6833399
commit d2394e9
Showing
8 changed files
with
158 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
use calimero_crypto::SharedKey; | ||
use calimero_network::stream::Stream; | ||
use calimero_primitives::context::Context; | ||
use calimero_primitives::identity::PublicKey; | ||
use eyre::{bail, OptionExt}; | ||
use rand::seq::IteratorRandom; | ||
use rand::thread_rng; | ||
use tracing::debug; | ||
|
||
use crate::sync::{recv, send, Sequencer}; | ||
use crate::types::{InitPayload, MessagePayload, StreamMessage}; | ||
use crate::Node; | ||
|
||
impl Node { | ||
pub(super) async fn initiate_key_share_process( | ||
&self, | ||
context: &mut Context, | ||
our_identity: PublicKey, | ||
stream: &mut Stream, | ||
) -> eyre::Result<()> { | ||
send( | ||
stream, | ||
&StreamMessage::Init { | ||
context_id: context.id, | ||
party_id: our_identity, | ||
payload: InitPayload::KeyShare {}, | ||
}, | ||
None, | ||
) | ||
.await?; | ||
|
||
let Some(ack) = recv(stream, self.sync_config.timeout, None).await? else { | ||
bail!("connection closed while awaiting state sync handshake"); | ||
}; | ||
|
||
let sender_key = match ack { | ||
StreamMessage::Message { | ||
payload: MessagePayload::KeyShare { sender_key }, | ||
.. | ||
} => sender_key, | ||
unexpected @ (StreamMessage::Init { .. } | ||
| StreamMessage::Message { .. } | ||
| StreamMessage::OpaqueError) => { | ||
bail!("unexpected message: {:?}", unexpected) | ||
} | ||
}; | ||
|
||
// Do I store "his" SenderKey somewhere? | ||
|
||
Ok(()) | ||
} | ||
|
||
pub(super) async fn handle_key_share_request( | ||
&self, | ||
context: Context, | ||
their_identity: PublicKey, | ||
stream: &mut Stream, | ||
) -> eyre::Result<()> { | ||
debug!( | ||
context_id=%context.id, | ||
their_identity=%their_identity, | ||
"Received key share request", | ||
); | ||
|
||
let identities = self.ctx_manager.get_context_owned_identities(context.id)?; | ||
|
||
let Some(our_identity) = identities.into_iter().choose(&mut thread_rng()) else { | ||
bail!("no identities found for context: {}", context.id); | ||
}; | ||
|
||
let sender_key = self | ||
.ctx_manager | ||
.get_sender_key(&context.id, &our_identity)? | ||
.ok_or_eyre("expected own identity to have sender key")?; | ||
|
||
let mut sequencer = Sequencer::default(); | ||
|
||
let shared_key = SharedKey::new(&sender_key, &our_identity); | ||
|
||
send( | ||
stream, | ||
&StreamMessage::Message { | ||
sequence_id: sequencer.next(), | ||
payload: MessagePayload::KeyShare { sender_key }, | ||
}, | ||
Some(shared_key), // or None? | ||
) | ||
.await?; | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
diff --git a/crates/node/src/interactive_cli.rs b/crates/node/src/interactive_cli.rs | ||
index 2d720da4..d8bddbbc 100644 | ||
--- a/crates/node/src/interactive_cli.rs | ||
+++ b/crates/node/src/interactive_cli.rs | ||
@@ -12,6 +12,7 @@ pub mod peers; | ||
pub mod state; | ||
pub mod store; | ||
|
||
+use calimero_primitives::blobs::BlobId; | ||
use clap::{Parser, Subcommand}; | ||
|
||
use crate::Node; | ||
@@ -34,6 +35,7 @@ pub enum SubCommand { | ||
Peers(peers::PeersCommand), | ||
// Store(store::StoreCommand), | ||
State(state::StateCommand), | ||
+ Connect, | ||
} | ||
|
||
pub async fn handle_line(node: &mut Node, line: String) -> eyre::Result<()> { | ||
@@ -59,6 +61,14 @@ pub async fn handle_line(node: &mut Node, line: String) -> eyre::Result<()> { | ||
SubCommand::Peers(peers) => peers.run(node.network_client.clone().into()).await?, | ||
SubCommand::State(state) => state.run(node)?, | ||
// SubCommand::Store(store) => store.run(node)?, | ||
+ SubCommand::Connect => { | ||
+ let addr = | ||
+ "/ip4/18.156.18.6/udp/4001/quic-v1/p2p/12D3KooWMgoF9xzyeKJHtRvrYwdomheRbHPELagWZwTLmXb6bCVC"; | ||
+ | ||
+ let res = node.network_client.dial(addr.parse()?).await; | ||
+ | ||
+ dbg!(res); | ||
+ } | ||
} | ||
|
||
Ok(()) | ||
} |