mirror of
https://github.com/chatmail/core.git
synced 2026-05-16 21:36:30 +03:00
Bring back code to persist iroh secret
This commit is contained in:
@@ -9,6 +9,7 @@ use iroh_net::magic_endpoint::accept_conn;
|
|||||||
use iroh_net::NodeId;
|
use iroh_net::NodeId;
|
||||||
use iroh_net::{derp::DerpMode, key::SecretKey, MagicEndpoint};
|
use iroh_net::{derp::DerpMode, key::SecretKey, MagicEndpoint};
|
||||||
|
|
||||||
|
use crate::config::Config;
|
||||||
use crate::contact::ContactId;
|
use crate::contact::ContactId;
|
||||||
use crate::context::Context;
|
use crate::context::Context;
|
||||||
use crate::message::{Message, MsgId};
|
use crate::message::{Message, MsgId};
|
||||||
@@ -18,7 +19,7 @@ use crate::webxdc::StatusUpdateItem;
|
|||||||
impl Context {
|
impl Context {
|
||||||
/// Create magic endpoint and gossip for the context.
|
/// Create magic endpoint and gossip for the context.
|
||||||
pub async fn create_gossip(&self) -> Result<()> {
|
pub async fn create_gossip(&self) -> Result<()> {
|
||||||
let secret_key: SecretKey = self.generate_iroh_keypair();
|
let secret_key: SecretKey = self.get_or_generate_iroh_keypair().await?;
|
||||||
println!("> our secret key: {}", base32::fmt(secret_key.to_bytes()));
|
println!("> our secret key: {}", base32::fmt(secret_key.to_bytes()));
|
||||||
|
|
||||||
if self.endpoint.lock().await.is_some() {
|
if self.endpoint.lock().await.is_some() {
|
||||||
@@ -145,9 +146,17 @@ impl Context {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the iroh gossip secret key from the database or create one.
|
/// Get the iroh gossip secret key from the database or generate a new one and persist it.
|
||||||
pub fn generate_iroh_keypair(&self) -> SecretKey {
|
pub async fn get_or_generate_iroh_keypair(&self) -> Result<SecretKey> {
|
||||||
SecretKey::generate()
|
match self.get_config_parsed(Config::IrohSecretKey).await? {
|
||||||
|
Some(key) => Ok(key),
|
||||||
|
None => {
|
||||||
|
let key = SecretKey::generate();
|
||||||
|
self.set_config(Config::IrohSecretKey, Some(&key.to_string()))
|
||||||
|
.await?;
|
||||||
|
Ok(key)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user