Skip to content

Commit

Permalink
Config fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
al8n authored and iduartgomez committed Sep 20, 2024
1 parent 605ff70 commit 3c80218
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
9 changes: 4 additions & 5 deletions apps/freenet-email-app/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions crates/core/src/bin/freenet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use freenet::{
run_local_node, run_network_node,
server::serve_gateway,
};
use std::sync::Arc;
use std::{net::SocketAddr, sync::Arc};

async fn run(config: Config) -> anyhow::Result<()> {
match config.mode {
Expand All @@ -18,12 +18,13 @@ async fn run(config: Config) -> anyhow::Result<()> {

async fn run_local(config: Config) -> anyhow::Result<()> {
tracing::info!("Starting freenet node in local mode");
let socket = config.ws_api;

let port = config.ws_api.port;
let ip = config.ws_api.address;
let executor = Executor::from_config(Arc::new(config), None)
.await
.map_err(anyhow::Error::msg)?;

let socket: SocketAddr = (ip, port).into();
run_local_node(executor, socket)
.await
.map_err(anyhow::Error::msg)
Expand Down
1 change: 1 addition & 0 deletions crates/core/src/node/network_bridge/p2p_protoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ impl P2pConnManager {
tracing::info!(%self.listening_port, %self.listening_ip, %self.is_gateway, key = %self.key_pair.public(), "Opening network listener");

let mut state = EventListenerState::new();
tracing::info!(%self.listening_port, %self.listening_ip, %self.is_gateway, key = %self.key_pair.public(), "Openning network listener");

let (outbound_conn_handler, inbound_conn_handler) = create_connection_handler::<UdpSocket>(
self.key_pair.clone(),
Expand Down
22 changes: 19 additions & 3 deletions crates/core/src/transport/crypto.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
use pkcs1::EncodeRsaPrivateKey;
use rand::rngs::OsRng;
use rsa::{pkcs8, Pkcs1v15Encrypt, RsaPrivateKey, RsaPublicKey};
use rsa::{
pkcs1::{self},
pkcs8, Pkcs1v15Encrypt, RsaPrivateKey, RsaPublicKey,
};
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct TransportKeypair {
pub(super) public: TransportPublicKey,
pub(super) secret: TransportSecretKey,
Expand Down Expand Up @@ -85,7 +89,7 @@ impl From<RsaPublicKey> for TransportPublicKey {
}
}

#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize)]
pub(crate) struct TransportSecretKey(RsaPrivateKey);

impl TransportSecretKey {
Expand All @@ -106,6 +110,18 @@ impl TransportSecretKey {
.to_pkcs8_pem(line_endings)
.map(|s| s.as_str().as_bytes().to_vec())
}

pub fn to_bytes(&self) -> Result<Vec<u8>, pkcs1::Error> {
#[cfg(unix)]
let line_endings = pkcs1::LineEnding::LF;

#[cfg(windows)]
let line_endings = pkcs1::LineEnding::CRLF;

self.0
.to_pkcs1_pem(line_endings)
.map(|s| s.as_str().as_bytes().to_vec())
}
}

#[cfg(test)]
Expand Down

0 comments on commit 3c80218

Please sign in to comment.