linera_service/cli_wrappers/
mod.rs1pub mod local_net;
9#[cfg(all(with_testing, feature = "remote-net"))]
10pub mod remote_net;
12mod wallet;
14
15use anyhow::Result;
16use async_trait::async_trait;
17pub use linera_faucet_client::Faucet;
18#[cfg(with_testing)]
19pub use wallet::NotificationsExt;
20pub use wallet::{ApplicationWrapper, ClientWrapper, FaucetService, NodeService, OnClientDrop};
21
22#[async_trait]
24pub trait LineraNetConfig {
25 type Net: LineraNet + Sized + Send + Sync + 'static;
26
27 async fn instantiate(self) -> Result<(Self::Net, ClientWrapper)>;
28}
29
30#[async_trait]
32pub trait LineraNet {
33 async fn ensure_is_running(&mut self) -> Result<()>;
34
35 async fn make_client(&mut self) -> ClientWrapper;
36
37 async fn terminate(&mut self) -> Result<()>;
38}
39
40#[derive(Copy, Clone)]
42pub enum Network {
43 Grpc,
44 Grpcs,
45 Tcp,
46 Udp,
47}
48
49#[derive(Copy, Clone)]
51pub struct NetworkConfig {
52 pub internal: Network,
54 pub external: Network,
56}
57
58impl Network {
59 fn toml(&self) -> &'static str {
60 match self {
61 Network::Grpc => "{ Grpc = \"ClearText\" }",
62 Network::Grpcs => "{ Grpc = \"Tls\" }",
63 Network::Tcp => "{ Simple = \"Tcp\" }",
64 Network::Udp => "{ Simple = \"Udp\" }",
65 }
66 }
67
68 pub fn short(&self) -> &'static str {
69 match self {
70 Network::Grpc => "grpc",
71 Network::Grpcs => "grpcs",
72 Network::Tcp => "tcp",
73 Network::Udp => "udp",
74 }
75 }
76
77 pub fn drop_tls(&self) -> Self {
78 match self {
79 Network::Grpc => Network::Grpc,
80 Network::Grpcs => Network::Grpc,
81 Network::Tcp => Network::Tcp,
82 Network::Udp => Network::Udp,
83 }
84 }
85
86 pub fn localhost(&self) -> &'static str {
87 match self {
88 Network::Grpc | Network::Grpcs => "localhost",
89 Network::Tcp | Network::Udp => "127.0.0.1",
90 }
91 }
92
93 pub fn schema(&self) -> &'static str {
95 match self {
96 Network::Grpc | Network::Grpcs => "grpc",
97 Network::Tcp => "tcp",
98 Network::Udp => "udp",
99 }
100 }
101}