pub struct Config {Show 14 fields
pub db_path: Option<PathBuf>,
pub secret: [u8; 32],
pub group_ids: Vec<GroupId>,
pub permission: bool,
pub only_stable_data: bool,
pub p2p_peer: Peer,
pub p2p_allowlist: Vec<Peer>,
pub p2p_blocklist: Vec<IpAddr>,
pub p2p_allow_peer_list: Vec<PeerId>,
pub p2p_block_peer_list: Vec<PeerId>,
pub rpc_http: Option<SocketAddr>,
pub rpc_ws: Option<SocketAddr>,
pub rpc_channel: Option<ChannelAddr>,
pub rpc_index: Option<PathBuf>,
}Expand description
load config from config file.
Fields§
§db_path: Option<PathBuf>§secret: [u8; 32]§group_ids: Vec<GroupId>§permission: bool§only_stable_data: bool§p2p_peer: Peer§p2p_allowlist: Vec<Peer>§p2p_blocklist: Vec<IpAddr>§p2p_allow_peer_list: Vec<PeerId>§p2p_block_peer_list: Vec<PeerId>§rpc_http: Option<SocketAddr>§rpc_ws: Option<SocketAddr>§rpc_channel: Option<ChannelAddr>§rpc_index: Option<PathBuf>Implementations§
Source§impl Config
impl Config
Sourcepub fn split(self) -> ([u8; 32], Vec<GroupId>, P2pConfig, RpcConfig)
pub fn split(self) -> ([u8; 32], Vec<GroupId>, P2pConfig, RpcConfig)
Examples found in repository?
examples/stop.rs (line 7)
5async fn main() {
6 let config = Config::load(PathBuf::from("./")).await;
7 let (_secret, ids, p2p_config, _rpc_config) = config.split();
8 let (send_send, send_recv) = new_send_channel();
9 let (recv_send, mut recv_recv) = new_receive_channel();
10
11 let peer_id = start_main(ids, p2p_config, recv_send, send_recv, None, None)
12 .await
13 .unwrap();
14 println!("Example: peer id: {:?}", peer_id);
15
16 println!("Network will stop after 5s...");
17 tokio::time::sleep(Duration::from_secs(5)).await;
18
19 let _ = send_send
20 .send(SendMessage::Network(NetworkType::NetworkStop))
21 .await;
22
23 while let Some(_) = recv_recv.recv().await {
24 //
25 }
26
27 println!("Network is stopped.");
28}Source§impl Config
impl Config
pub fn with_addr(p2p_addr: SocketAddr, rpc_http: SocketAddr) -> Self
pub fn default() -> Self
Sourcepub async fn load(path: PathBuf) -> Self
pub async fn load(path: PathBuf) -> Self
Examples found in repository?
examples/app_with_config_file.rs (line 8)
5async fn main() {
6 // use crate root directory's config.toml
7 let dir_path = PathBuf::from(".");
8 let config = Config::load(dir_path).await;
9
10 let (peer_addr, _send, mut out_recv) = start_with_config(config).await.unwrap();
11 println!("Example: peer id: {}", peer_addr.short_show());
12
13 while let Some(message) = out_recv.recv().await {
14 match message {
15 _ => {}
16 }
17 }
18}More examples
examples/stop.rs (line 6)
5async fn main() {
6 let config = Config::load(PathBuf::from("./")).await;
7 let (_secret, ids, p2p_config, _rpc_config) = config.split();
8 let (send_send, send_recv) = new_send_channel();
9 let (recv_send, mut recv_recv) = new_receive_channel();
10
11 let peer_id = start_main(ids, p2p_config, recv_send, send_recv, None, None)
12 .await
13 .unwrap();
14 println!("Example: peer id: {:?}", peer_id);
15
16 println!("Network will stop after 5s...");
17 tokio::time::sleep(Duration::from_secs(5)).await;
18
19 let _ = send_send
20 .send(SendMessage::Network(NetworkType::NetworkStop))
21 .await;
22
23 while let Some(_) = recv_recv.recv().await {
24 //
25 }
26
27 println!("Network is stopped.");
28}pub async fn load_save(path: PathBuf, config: Config) -> Result<Self>
pub async fn load_custom<S: SeSerialize + SeDeserializeOwned>( path: PathBuf, ) -> Option<S>
pub async fn append_custom(path: PathBuf, s: &str) -> Result<()>
Auto Trait Implementations§
impl Freeze for Config
impl !RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl !UnwindSafe for Config
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more