1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
use crate::config::*;
use libp2p::identity::ed25519::Keypair;
#[derive(Debug)]
pub struct NetworkConfig {
pub enable_loopback: bool,
pub port_reuse: bool,
pub node_name: String,
pub node_key: Keypair,
pub psk: Option<[u8; 32]>,
pub dns: Option<DnsConfig>,
pub mdns: Option<MdnsConfig>,
pub kad: Option<KadConfig>,
pub ping: Option<PingConfig>,
pub identify: Option<IdentifyConfig>,
pub gossipsub: Option<GossipsubConfig>,
pub broadcast: Option<BroadcastConfig>,
pub bitswap: Option<BitswapConfig>,
pub keep_alive: bool,
}
#[derive(Debug)]
pub enum DnsConfig {
Custom {
config: ResolverConfig,
opts: ResolverOpts,
},
SystemWithFallback {
config: ResolverConfig,
opts: ResolverOpts,
},
}
impl NetworkConfig {
pub fn new(node_key: Keypair) -> Self {
let node_name = names::Generator::with_naming(names::Name::Numbered)
.next()
.unwrap();
let identify = IdentifyConfig::new(
"/ipfs-embed/1.0".into(),
libp2p::identity::PublicKey::Ed25519(node_key.public()),
);
Self {
enable_loopback: true,
port_reuse: true,
node_name,
node_key,
psk: None,
dns: None,
mdns: Some(MdnsConfig::default()),
kad: Some(KadConfig::default()),
ping: None,
identify: Some(identify),
gossipsub: Some(GossipsubConfig::default()),
broadcast: Some(BroadcastConfig::default()),
bitswap: Some(BitswapConfig::default()),
keep_alive: false,
}
}
}
impl Default for NetworkConfig {
fn default() -> Self {
Self::new(Keypair::generate())
}
}