Config

Struct Config 

Source
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

Source

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

Source

pub fn with_addr(p2p_addr: SocketAddr, rpc_http: SocketAddr) -> Self

Source

pub fn default() -> Self

Source

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
Hide additional 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}
Source

pub async fn load_save(path: PathBuf, config: Config) -> Result<Self>

Source

pub async fn load_custom<S: SeSerialize + SeDeserializeOwned>( path: PathBuf, ) -> Option<S>

Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more