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;
27
28 async fn instantiate(self) -> Result<(Self::Net, ClientWrapper)>;
30}
31
32#[async_trait]
34pub trait LineraNet {
35 async fn ensure_is_running(&mut self) -> Result<()>;
37
38 async fn make_client(&mut self) -> ClientWrapper;
40
41 async fn terminate(&mut self) -> Result<()>;
43}
44
45#[derive(Copy, Clone)]
47pub enum Network {
48 Grpc,
50 Grpcs,
52 Tcp,
54 Udp,
56}
57
58#[derive(Copy, Clone)]
60pub struct NetworkConfig {
61 pub internal: Network,
63 pub external: Network,
65}
66
67impl Network {
68 fn toml(&self) -> &'static str {
69 match self {
70 Network::Grpc => "{ Grpc = \"ClearText\" }",
71 Network::Grpcs => "{ Grpc = \"Tls\" }",
72 Network::Tcp => "{ Simple = \"Tcp\" }",
73 Network::Udp => "{ Simple = \"Udp\" }",
74 }
75 }
76
77 pub fn short(&self) -> &'static str {
79 match self {
80 Network::Grpc => "grpc",
81 Network::Grpcs => "grpcs",
82 Network::Tcp => "tcp",
83 Network::Udp => "udp",
84 }
85 }
86
87 pub fn drop_tls(&self) -> Self {
89 match self {
90 Network::Grpc => Network::Grpc,
91 Network::Grpcs => Network::Grpc,
92 Network::Tcp => Network::Tcp,
93 Network::Udp => Network::Udp,
94 }
95 }
96
97 pub fn localhost(&self) -> &'static str {
99 match self {
100 Network::Grpc | Network::Grpcs => "localhost",
101 Network::Tcp | Network::Udp => "127.0.0.1",
102 }
103 }
104
105 pub fn schema(&self) -> &'static str {
107 match self {
108 Network::Grpc | Network::Grpcs => "grpc",
109 Network::Tcp => "tcp",
110 Network::Udp => "udp",
111 }
112 }
113}