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
use std::net::IpAddr;
use std::path::PathBuf;
use chamomile_types::{Peer, PeerId};
/// Chammomile Configs.
#[derive(Debug, Clone)]
pub struct Config {
/// Default Data saved directory.
pub db_dir: PathBuf,
/// Default binding multiaddr string.
/// Example: "/ip4/0.0.0.0/quic/7364"
pub peer: Peer,
/// Allowed MultiAddr style peer list.
pub allowlist: Vec<Peer>,
/// Blocked Ip's list.
pub blocklist: Vec<IpAddr>,
/// Allowed peer's `PeerId` list.
pub allow_peer_list: Vec<PeerId>,
/// Blocked peers's `PeerId` list.
pub block_peer_list: Vec<PeerId>,
/// If set permission is true, that server is permissioned,
/// not receive DHT's peer message, only stable connect.
/// if set permission is false, that server is permissionless,
/// receive DHT's peer message and stable's peer message.
/// if you use a permissionless server, but only receive stable's message,
/// you can set `only_stable_data` is true.
/// Recommend use `permission = false & only_stable_data = true` replace permissioned.
pub permission: bool,
/// If `only_stable_data` is true, only receive stable connected peer's data.
pub only_stable_data: bool,
/// When delivery feedback has set length, it will split length of data to return.
/// For example. set `delivery_length = 8`,
/// and when a `Data(1u64, PeerId, vec![1u8, 2u8, ..., 100u8]),
/// if send success, will return:
/// `Delivery(DeliveryType::Data, 1u64, true, vec![1u8, 2u8, ..., 8u8])`
/// if send failure, will return:
/// `Delivery(DeliveryType::Data, 1u64, false, vec![1u8, 2u8, ..., 8u8])`
pub delivery_length: usize,
}
impl Config {
pub fn default(peer: Peer) -> Self {
Self {
db_dir: PathBuf::from("./"),
peer: peer,
allowlist: vec![],
blocklist: vec![],
allow_peer_list: vec![],
block_peer_list: vec![],
permission: false,
only_stable_data: false,
delivery_length: 0,
}
}
pub fn new(
db_dir: PathBuf,
peer: Peer,
allowlist: Vec<Peer>,
blocklist: Vec<IpAddr>,
allow_peer_list: Vec<PeerId>,
block_peer_list: Vec<PeerId>,
permission: bool,
only_stable_data: bool,
delivery_length: usize,
) -> Self {
Self {
db_dir,
peer,
allowlist,
blocklist,
allow_peer_list,
block_peer_list,
permission,
only_stable_data,
delivery_length,
}
}
}