Skip to content

Commit 71cfc5f

Browse files
Agent/P2p: fix build when DNS feature is disabled
1 parent c9e1dad commit 71cfc5f

File tree

5 files changed

+20
-19
lines changed

5 files changed

+20
-19
lines changed

drasyl-agent/src/agent/network_listener.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use crate::agent::AgentInner;
2-
use crate::agent::dns::AgentDnsInterface;
32
use crate::network::Network;
43
use ipnet::Ipv4Net;
54
use std::collections::HashMap;
6-
use std::net::Ipv4Addr;
75
use std::sync::Arc;
86
use tokio::sync::MutexGuard;
97
use tracing::trace;
@@ -53,6 +51,8 @@ impl AgentInner {
5351
.collect();
5452
trace!("Collected {} IPs: {:?}", all_ips.len(), all_ips);
5553

54+
#[cfg(feature = "dns")]
55+
use crate::agent::dns::AgentDnsInterface;
5656
let networks_change = NetworkChange {
5757
routes: Some(all_routes),
5858
ips: Some(all_ips),

drasyl-agent/src/ffi.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,8 +616,9 @@ impl Drop for AgentPtr {
616616

617617
#[repr(C)]
618618
pub struct NetworkChange {
619-
pub ips: *const c_char, // Comma-separated IPs, NULL if not available
620-
pub routes: *const c_char, // Comma-separated routes, NULL if not available
619+
pub ips: *const c_char, // Comma-separated IPs, NULL if not available
620+
pub routes: *const c_char, // Comma-separated routes, NULL if not available
621+
#[cfg(feature = "dns")]
621622
pub dns_server: *const c_char, // DNS server, NULL if not available
622623
}
623624

@@ -676,6 +677,7 @@ pub extern "C" fn drasyl_agent_start(
676677
.unwrap_or_default();
677678

678679
// Convert DNS server to string
680+
#[cfg(feature = "dns")]
679681
let dns_server_str = if let Some(dns_server) = change.dns_server {
680682
CString::new(dns_server.to_string()).unwrap_or_default()
681683
} else {
@@ -685,6 +687,7 @@ pub extern "C" fn drasyl_agent_start(
685687
let c_change = NetworkChange {
686688
ips: ips_str.as_ptr(),
687689
routes: routes_str.as_ptr(),
690+
#[cfg(feature = "dns")]
688691
dns_server: dns_server_str.as_ptr(),
689692
};
690693

drasyl-p2p/benches/crypto.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
// benches/curve25519.rs
2-
use criterion::{black_box, criterion_group, criterion_main, Criterion};
2+
use criterion::{Criterion, black_box, criterion_group, criterion_main};
33
use drasyl_p2p::crypto::{
4-
compute_kx_session_keys,
5-
convert_ed25519_pk_to_curve25519_pk,
6-
convert_ed25519_sk_to_curve25519_sk,
7-
generate_sign_keypair,
8-
AgreementPubKey, AgreementSecKey, SigningPubKey, SigningSecKey, SessionKey,
4+
AgreementPubKey, AgreementSecKey, SessionKey, SigningPubKey, SigningSecKey,
5+
compute_kx_session_keys, convert_ed25519_pk_to_curve25519_pk,
6+
convert_ed25519_sk_to_curve25519_sk, generate_sign_keypair,
97
};
108
use libsodium_sys as sodium;
119

1210
fn sodium_init_once() {
1311
static ONCE: std::sync::Once = std::sync::Once::new();
14-
ONCE.call_once(|| unsafe { let _ = sodium::sodium_init(); });
12+
ONCE.call_once(|| unsafe {
13+
let _ = sodium::sodium_init();
14+
});
1515
}
1616

1717
// --- Helpers: neue Impl ausschließlich über crypto/mod.rs -------------------
@@ -67,11 +67,9 @@ fn bench_kx_session_keys(c: &mut Criterion) {
6767
// neue Impl: compute_kx_session_keys aus crypto/mod.rs
6868
group.bench_function("new-impl/kx", |b| {
6969
b.iter(|| {
70-
let (rx, tx): (SessionKey, SessionKey) = compute_kx_session_keys(
71-
black_box(&my_pk),
72-
black_box(&my_sk),
73-
black_box(&peer_pk),
74-
).unwrap();
70+
let (rx, tx): (SessionKey, SessionKey) =
71+
compute_kx_session_keys(black_box(&my_pk), black_box(&my_sk), black_box(&peer_pk))
72+
.unwrap();
7573
black_box((rx, tx));
7674
});
7775
});

drasyl-p2p/src/crypto/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ mod error;
22
mod session_key;
33

44
pub use error::*;
5-
use rand_chacha::rand_core::{RngCore, SeedableRng};
65
use rand_chacha::ChaCha20Rng;
6+
use rand_chacha::rand_core::{RngCore, SeedableRng};
77
pub use session_key::SessionKey;
88
use std::cell::RefCell;
99

@@ -130,7 +130,7 @@ pub fn convert_ed25519_sk_to_curve25519_sk(sk: &SigningSecKey) -> Result<Agreeme
130130
.map_err(|_| Error::DalekError)?;
131131

132132
// 1) SHA-512(seed)
133-
let mut h: [u8; SHA512_BYTES] = Sha512::digest(&seed).into();
133+
let mut h: [u8; SHA512_BYTES] = Sha512::digest(seed).into();
134134

135135
// 2) X25519 clamping
136136
h[0] &= 248;

drasyl-p2p/tests/crypto.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fn sodium_init_once() {
1313
// ---------------------------------------------------------------------------
1414
mod old_ref {
1515
use super::*;
16-
16+
1717
pub(crate) const ED25519_SECRETKEYBYTES: usize = 64;
1818
pub(crate) const ED25519_PUBLICKEYBYTES: usize = 32;
1919
pub(crate) const CURVE25519_SECRETKEYBYTES: usize = 32;

0 commit comments

Comments
 (0)