darkfi/net/transport/nym.rs
1/* This file is part of DarkFi (https://dark.fi)
2 *
3 * Copyright (C) 2020-2026 Dyne.org foundation
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as
7 * published by the Free Software Foundation, either version 3 of the
8 * License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
19use std::{io, time::Duration};
20
21use rand::{rngs::OsRng, RngCore};
22use url::Url;
23
24use crate::util::encoding::base32;
25
26/// Unique, randomly-generated per-connection ID that's used to
27/// identify which connection a message belongs to.
28// TODO: remove this when implemented properly
29#[allow(dead_code)]
30#[derive(Clone, Eq, PartialEq, Hash)]
31struct ConnectionId([u8; 32]);
32
33impl ConnectionId {
34 fn _generate() -> Self {
35 let mut bytes = [0u8; 32];
36 OsRng.fill_bytes(&mut bytes);
37 Self(bytes)
38 }
39
40 fn _from_bytes(bytes: &[u8]) -> Self {
41 let mut id = [0u8; 32];
42 id[..].copy_from_slice(&bytes[0..32]);
43 ConnectionId(id)
44 }
45}
46
47impl std::fmt::Debug for ConnectionId {
48 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
49 write!(f, "{}", base32::encode(false, &self.0).to_ascii_lowercase())
50 }
51}
52
53/// Nym Dialer implementation
54#[derive(Debug, Clone)]
55pub struct NymDialer;
56
57impl NymDialer {
58 /// Instantiate a new [`NymDialer`] object
59 pub(crate) async fn new() -> io::Result<Self> {
60 Ok(Self {})
61 }
62
63 pub(crate) async fn _do_dial(
64 &self,
65 _endpoint: Url, // Recipient
66 _timeout: Option<Duration>,
67 ) -> io::Result<()> {
68 let _id = ConnectionId::_generate();
69
70 Ok(())
71 }
72}