This repository has been archived by the owner on Nov 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
/
config.rs
64 lines (58 loc) · 1.58 KB
/
config.rs
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
use libp2p::Multiaddr;
use serde::{Deserialize, Serialize};
#[derive(Deserialize, Serialize, Debug)]
pub struct ServerConfig {
/// Public IP address of the node, eg. `/ip4/127.0.0.1`
#[serde(default = "ServerConfig::default_addresses")]
pub addresses: Vec<Multiaddr>,
/// Port to listen on
#[serde(default = "ServerConfig::default_port")]
pub port: u16,
/// Address to bind to
#[serde(default = "ServerConfig::default_addr")]
pub addr: String,
#[serde(default)]
pub origin: OriginConfig,
}
impl ServerConfig {
fn default_addresses() -> Vec<Multiaddr> {
vec!["/ip4/127.0.0.1/tcp/4069".parse().unwrap()]
}
fn default_port() -> u16 {
4069
}
fn default_addr() -> String {
"0.0.0.0".to_string()
}
}
impl Default for ServerConfig {
fn default() -> Self {
Self {
addresses: Self::default_addresses(),
port: Self::default_port(),
addr: Self::default_addr(),
origin: Default::default(),
}
}
}
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
pub struct OriginConfig {
/// Ipfs gateway url
#[serde(default = "OriginConfig::default_ipfs_gateway")]
pub ipfs_gateway: String,
/// Intended for testing purposes
pub use_https: Option<bool>,
}
impl OriginConfig {
pub fn default_ipfs_gateway() -> String {
"ipfs.io".to_string()
}
}
impl Default for OriginConfig {
fn default() -> Self {
Self {
ipfs_gateway: Self::default_ipfs_gateway(),
use_https: None,
}
}
}