mirror of
https://github.com/chatmail/core.git
synced 2026-05-15 12:56:30 +03:00
logs
This commit is contained in:
@@ -8,6 +8,7 @@ use crate::tools::time;
|
|||||||
use crate::webxdc::StatusUpdateItem;
|
use crate::webxdc::StatusUpdateItem;
|
||||||
use anyhow::{anyhow, Context as _, Result};
|
use anyhow::{anyhow, Context as _, Result};
|
||||||
use image::EncodableLayout;
|
use image::EncodableLayout;
|
||||||
|
use iroh_base::base32;
|
||||||
use iroh_gossip::net::{Gossip, GOSSIP_ALPN};
|
use iroh_gossip::net::{Gossip, GOSSIP_ALPN};
|
||||||
use iroh_gossip::proto::{Event as IrohEvent, TopicId};
|
use iroh_gossip::proto::{Event as IrohEvent, TopicId};
|
||||||
use iroh_net::magic_endpoint::accept_conn;
|
use iroh_net::magic_endpoint::accept_conn;
|
||||||
@@ -19,6 +20,8 @@ impl Context {
|
|||||||
pub async fn create_gossip(&self) -> Result<()> {
|
pub async fn create_gossip(&self) -> Result<()> {
|
||||||
let secret_key: SecretKey = self.get_or_create_iroh_keypair().await?;
|
let secret_key: SecretKey = self.get_or_create_iroh_keypair().await?;
|
||||||
|
|
||||||
|
println!("> our secret key: {}", base32::fmt(secret_key.to_bytes()));
|
||||||
|
|
||||||
if self.endpoint.lock().await.is_some() {
|
if self.endpoint.lock().await.is_some() {
|
||||||
warn!(
|
warn!(
|
||||||
self,
|
self,
|
||||||
@@ -32,12 +35,6 @@ impl Context {
|
|||||||
.secret_key(secret_key)
|
.secret_key(secret_key)
|
||||||
.alpns(vec![GOSSIP_ALPN.to_vec()])
|
.alpns(vec![GOSSIP_ALPN.to_vec()])
|
||||||
.derp_mode(DerpMode::Default)
|
.derp_mode(DerpMode::Default)
|
||||||
.peers_data_path(
|
|
||||||
self.blobdir
|
|
||||||
.parent()
|
|
||||||
.context("Can't get parent of blob dir")?
|
|
||||||
.to_path_buf(),
|
|
||||||
)
|
|
||||||
.bind(0)
|
.bind(0)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
@@ -72,6 +69,17 @@ impl Context {
|
|||||||
warn!(self, "joining gossip with zero peers");
|
warn!(self, "joining gossip with zero peers");
|
||||||
} else {
|
} else {
|
||||||
info!(self, "joining gossip with peers: {peers:?}");
|
info!(self, "joining gossip with peers: {peers:?}");
|
||||||
|
info!(
|
||||||
|
self,
|
||||||
|
"{:?}",
|
||||||
|
self.endpoint
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.as_ref()
|
||||||
|
.unwrap()
|
||||||
|
.my_addr()
|
||||||
|
.await?
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: add timeout as the returned future might be pending forever
|
// TODO: add timeout as the returned future might be pending forever
|
||||||
@@ -139,7 +147,8 @@ impl Context {
|
|||||||
|
|
||||||
/// Get the iroh gossip secret key from the database or create one.
|
/// Get the iroh gossip secret key from the database or create one.
|
||||||
pub async fn get_or_create_iroh_keypair(&self) -> Result<SecretKey> {
|
pub async fn get_or_create_iroh_keypair(&self) -> Result<SecretKey> {
|
||||||
match self.get_config_parsed(Config::IrohSecretKey).await? {
|
Ok(SecretKey::generate())
|
||||||
|
/* match self.get_config_parsed(Config::IrohSecretKey).await? {
|
||||||
Some(key) => Ok(key),
|
Some(key) => Ok(key),
|
||||||
None => {
|
None => {
|
||||||
let key = SecretKey::generate();
|
let key = SecretKey::generate();
|
||||||
@@ -147,7 +156,7 @@ impl Context {
|
|||||||
.await?;
|
.await?;
|
||||||
Ok(key)
|
Ok(key)
|
||||||
}
|
}
|
||||||
}
|
} */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -457,9 +457,15 @@ pub(crate) async fn receive_imf_inner(
|
|||||||
|
|
||||||
let node_id = node_addr.node_id;
|
let node_id = node_addr.node_id;
|
||||||
for topic in topics {
|
for topic in topics {
|
||||||
|
println!("Adding peer: {:?}", node_id);
|
||||||
context
|
context
|
||||||
.add_peer_for_topic(instance_id, topic, node_id)
|
.add_peer_for_topic(instance_id, topic, node_id)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"New peer topics: {:?}",
|
||||||
|
context.get_peers_for_topic(topic).await?
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
|||||||
@@ -500,8 +500,6 @@ impl Context {
|
|||||||
let mut ephemeral = status_update.gossip_topic.is_some();
|
let mut ephemeral = status_update.gossip_topic.is_some();
|
||||||
if send_now {
|
if send_now {
|
||||||
if let Some(ref topic) = status_update.gossip_topic {
|
if let Some(ref topic) = status_update.gossip_topic {
|
||||||
// find out if any row with `topic = topic` exists in the gossip_peers table
|
|
||||||
|
|
||||||
let topic = TopicId::from_str(&iroh_base::base32::fmt(
|
let topic = TopicId::from_str(&iroh_base::base32::fmt(
|
||||||
topic.get(0..32).context("Can't get 32 bytes from topic")?,
|
topic.get(0..32).context("Can't get 32 bytes from topic")?,
|
||||||
))?;
|
))?;
|
||||||
@@ -539,6 +537,10 @@ impl Context {
|
|||||||
ephemeral = false;
|
ephemeral = false;
|
||||||
} else {
|
} else {
|
||||||
if let Some(ref gossip) = *self.gossip.lock().await {
|
if let Some(ref gossip) = *self.gossip.lock().await {
|
||||||
|
println!(
|
||||||
|
"sending to topic {topic} with peers: {:?}",
|
||||||
|
self.get_peers_for_topic(topic).await?
|
||||||
|
);
|
||||||
gossip
|
gossip
|
||||||
.broadcast(topic, serde_json::to_string(&status_update)?.into())
|
.broadcast(topic, serde_json::to_string(&status_update)?.into())
|
||||||
.await?;
|
.await?;
|
||||||
|
|||||||
Reference in New Issue
Block a user