Skip to content

Commit

Permalink
checkpoint
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Platov <[email protected]>
  • Loading branch information
aplatoff committed Jan 8, 2025
1 parent c8440d0 commit 11e29e5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
10 changes: 8 additions & 2 deletions huly-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,14 @@ async fn main() -> Result<()> {
Command::Client { server, account } => {
let account: AccId = account.parse()?;
let org: OrgId = server.parse()?;
huly::client::request_membership(&secret_key.clone(), endpoint.clone(), account, org)
.await?;
huly::client::request_membership(
&secret_key.clone(),
endpoint.clone(),
account,
org,
gossip,
)
.await?;
}
Command::CreateDb => {
let _ = Db::create(&args.db)?;
Expand Down
17 changes: 16 additions & 1 deletion huly/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ use crate::membership::{
use crate::message::{Message, SignedMessage, SignedMessageType};
use anyhow::Result;
use iroh::{Endpoint, NodeId, SecretKey};
use tokio::io::AsyncWriteExt;
use iroh_gossip::net::GossipSender;
use iroh_gossip::{
net::{Event, Gossip, GossipEvent, GossipReceiver},
proto::TopicId,
};

pub async fn request_membership(
secret_key: &SecretKey,
endpoint: Endpoint,
account: AccId,
org: OrgId,
gossip: Gossip,
) -> Result<()> {
let node_id = NodeId::from_bytes(org.as_bytes())?;
let conn = endpoint.connect(node_id, Membership::ALPN).await?;
Expand All @@ -30,6 +35,16 @@ pub async fn request_membership(
let response = Message::read_async(&mut recv).await?;
println!("got membership response: {:?}", response);

let topic = TopicId::from_bytes(account.into());
// let gossip = Gossip::builder().spawn(endpoint.clone()).await?;

let (sender, receiver) = gossip
.subscribe_and_join(topic, vec![node_id])
.await?
.split();

println!("started gossip proto");

let request = ServeMeRequestType::encode(&Empty {})?;
request.write_async(&mut send).await?;
println!("sent serve me request");
Expand Down
7 changes: 5 additions & 2 deletions huly/src/membership.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,11 @@ impl ProtocolHandler for Membership {
let topic = TopicId::from_bytes(account_id.into());

println!("subscribing");
let (sender, receiver) =
this.gossip.subscribe_and_join(topic, vec![]).await?.split();
let (sender, receiver) = this
.gossip
.subscribe_and_join(topic, vec![device_id])
.await?
.split();

println!("spawning account loop");
let x = tokio::spawn(account_loop(sender, receiver));
Expand Down

0 comments on commit 11e29e5

Please sign in to comment.