mirror of
https://github.com/exo-explore/exo.git
synced 2026-08-07 02:53:04 -04:00
found the max message size
This commit is contained in:
1 parent
c8753c6237
commit
f53ab8d018
2 files changed
+54
-7
No files matched your search
@@ -40,14 +40,16 @@ async fn main() {
|
||||
println!("Enter messages via STDIN and they will be sent to connected peers using Gossipsub");
|
||||
|
||||
let jh1 = tokio::spawn(async move {
|
||||
while let Ok(Some(line)) = stdin.next_line().await {
|
||||
if let Err(e) = send.broadcast(line.into()).await {
|
||||
println!("Publish error: {e:?}");
|
||||
loop {
|
||||
if let Ok(Some(line)) = stdin.next_line().await {
|
||||
if let Err(e) = send.broadcast(line.into()).await {
|
||||
println!("Publish error: {e:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
let jh2 = tokio::spawn(async move {
|
||||
let _ = tokio::spawn(async move {
|
||||
while let Some(Ok(event)) = recv.next().await {
|
||||
match event {
|
||||
// on gossipsub incoming
|
||||
@@ -72,8 +74,9 @@ async fn main() {
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
jh1.await.unwrap();
|
||||
jh2.await.unwrap();
|
||||
_jh.await.unwrap();
|
||||
}
|
||||
@@ -50,7 +50,11 @@ impl ExoNet {
|
||||
let mdns = MdnsDiscovery::builder().build(endpoint.id())?;
|
||||
endpoint.discovery().add(mdns.clone());
|
||||
let alpn = format!("/exo_discovery_network/{}", namespace).to_owned();
|
||||
let gossip = Gossip::builder().alpn(&alpn).spawn(endpoint.clone());
|
||||
// max msg size 4MB
|
||||
let gossip = Gossip::builder()
|
||||
.max_message_size(4 * 1024 * 1024)
|
||||
.alpn(&alpn)
|
||||
.spawn(endpoint.clone());
|
||||
let router = Router::builder(endpoint)
|
||||
.accept(&alpn, gossip.clone())
|
||||
.spawn();
|
||||
@@ -139,7 +143,12 @@ fn str_to_topic_id(data: &str) -> TopicId {
|
||||
#[allow(dead_code)]
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use std::{sync::Arc, time::Duration};
|
||||
|
||||
use iroh::{SecretKey, discovery::mdns::DiscoveryEvent};
|
||||
use iroh_gossip::api::{Event, Message};
|
||||
use n0_future::StreamExt;
|
||||
use tokio::time::sleep;
|
||||
|
||||
use crate::ExoNet;
|
||||
|
||||
@@ -155,4 +164,39 @@ mod test {
|
||||
let fut = ExoNet::init_iroh(SecretKey::generate(&mut rand::rng()), "");
|
||||
is_send(&fut);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_two_endpoints() {
|
||||
let net1 = Arc::new(
|
||||
ExoNet::init_iroh(SecretKey::generate(&mut rand::rng()), "")
|
||||
.await
|
||||
.unwrap(),
|
||||
);
|
||||
let net2 = Arc::new(
|
||||
ExoNet::init_iroh(SecretKey::generate(&mut rand::rng()), "")
|
||||
.await
|
||||
.unwrap(),
|
||||
);
|
||||
|
||||
let cn1 = Arc::clone(&net1);
|
||||
let cn2 = Arc::clone(&net2);
|
||||
tokio::spawn(async move { cn1.start_auto_dialer().await });
|
||||
tokio::spawn(async move { cn2.start_auto_dialer().await });
|
||||
|
||||
while net1.known_peers.lock().await.is_empty() {
|
||||
sleep(Duration::from_secs(1)).await
|
||||
}
|
||||
while net2.known_peers.lock().await.is_empty() {
|
||||
sleep(Duration::from_secs(1)).await
|
||||
}
|
||||
let (send, _) = net1.subscribe("yo").await.unwrap();
|
||||
let (_, mut recv) = net2.subscribe("yo").await.unwrap();
|
||||
|
||||
let msg = "woah";
|
||||
send.broadcast(msg.into()).await.unwrap();
|
||||
let Some(Ok(Event::Received(Message { content, .. }))) = recv.next().await else {
|
||||
panic!()
|
||||
};
|
||||
assert_eq!(content, msg);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user