1#[cfg(not(target_arch = "wasm32"))]
2pub mod native;
3#[cfg(target_arch = "wasm32")]
4pub mod wasm;
5
6mod behaviour;
7mod bootstrap;
8pub mod common;
9mod event_handlers;
10pub mod helpers;
11mod network_node;
12pub mod protocol;
13
14pub use common::Libp2pNetwork;
15
16#[derive(Debug, Clone)]
18pub struct NodeOptions {
19 pub listen_addresses: Vec<String>,
20 pub bootstrap_peers: Vec<String>,
21 pub max_connections: u32,
22 pub dht_client_mode: bool,
23 pub dht_discovery_enabled: bool,
24 pub stun_servers: Option<Vec<String>>,
25}
26
27impl Default for NodeOptions {
28 fn default() -> Self {
29 Self {
30 listen_addresses: vec!["/ip4/0.0.0.0/tcp/0".into()],
31 bootstrap_peers: chat_core::config::BOOTSTRAP_PEERS.iter().map(|s| s.to_string()).collect(),
32 max_connections: 100,
33 dht_client_mode: true,
34 dht_discovery_enabled: true,
35 stun_servers: Some(vec![
36 "stun:stun.l.google.com:19302".into(),
37 "stun:global.stun.twilio.com:3478".into(),
38 ]),
39 }
40 }
41}
42
43pub async fn build_node(options: NodeOptions) -> chat_core::error::ChatResult<Libp2pNetwork> {
45 #[cfg(not(target_arch = "wasm32"))]
46 {
47 native::build_node(options).await
48 }
49 #[cfg(target_arch = "wasm32")]
50 {
51 wasm::build_node(options).await
52 }
53}