Просмотр исходного кода

cashierd: Add a dns_addr field in the config, and serve features with config.

parazyd 4 лет назад
Родитель
Сommit
743ab63af6
4 измененных файлов с 38 добавлено и 6 удалено
  1. 3 0
      example/config/cashierd.toml
  2. 3 0
      example/config_local/cashierd.toml
  3. 30 6
      src/bin/cashierd.rs
  4. 2 0
      src/cli/cli_config.rs

+ 3 - 0
example/config/cashierd.toml

@@ -3,6 +3,9 @@
 ## Please make sure you go through all the settings so you can configre
 ## your daemon properly.
 
+# The DNS name of the cashier (can also be an IP, or a .onion address)
+dns_addr = "testnet.cashier.dark.fi"
+
 # The endpoint where cashierd will bind its RPC socket
 rpc_listen_address = "127.0.0.1:9000"
 

+ 3 - 0
example/config_local/cashierd.toml

@@ -3,6 +3,9 @@
 ## Please make sure you go through all the settings so you can configre
 ## your daemon properly.
 
+# The DNS name of the cashier (can also be an IP, or a .onion address)
+dns_addr = "testnet.cashier.dark.fi"
+
 # The endpoint where cashierd will bind its RPC socket
 rpc_listen_address = "127.0.0.1:9000"
 

+ 30 - 6
src/bin/cashierd.rs

@@ -53,6 +53,7 @@ struct Cashierd {
     cashier_wallet: Arc<CashierDb>,
     networks: Vec<Network>,
     public_key: String,
+    config: CashierdConfig,
 }
 
 #[async_trait]
@@ -87,7 +88,8 @@ impl Cashierd {
 
         let mut networks = Vec::new();
 
-        for network in config.networks {
+        let cfg = config.clone();
+        for network in cfg.networks {
             networks.push(Network {
                 name: NetworkName::from_str(&network.name)?,
                 blockchain: network.blockchain,
@@ -102,6 +104,7 @@ impl Cashierd {
             cashier_wallet,
             networks,
             public_key: String::from(""),
+            config,
         })
     }
 
@@ -428,17 +431,38 @@ impl Cashierd {
     }
 
     async fn features(&self, id: Value, _params: Value) -> JsonResult {
+        let tcp_port: Option<u16>;
+        let tls_port: Option<u16>;
+        let onionaddr: Option<String>;
+        let dnsaddr: Option<String>;
+
+        if self.config.serve_tls {
+            tls_port = Some(self.config.rpc_listen_address.port());
+            tcp_port = None;
+        } else {
+            tcp_port = Some(self.config.rpc_listen_address.port());
+            tls_port = None;
+        }
+
+        if self.config.dns_addr.ends_with(".onion") {
+            onionaddr = Some(self.config.dns_addr.clone());
+            dnsaddr = None;
+        } else {
+            dnsaddr = Some(self.config.dns_addr.clone());
+            onionaddr = None;
+        }
+
         let mut resp: serde_json::Value = json!(
             {
-                "server_version": "0.1.0",
+                "server_version": env!("CARGO_PKG_VERSION"),
                 "protocol_version": "1.0",
                 "public_key": self.public_key,
                 "networks": [],
                 "hosts": {
-                    "tcp_port": null,
-                    "tls_port": 9000,
-                    "onion_addr": null,
-                    "dns_addr": "testnet.cashier.dark.fi"
+                    "tcp_port": tcp_port,
+                    "tls_port": tls_port,
+                    "onion_addr": onionaddr,
+                    "dns_addr": dnsaddr,
                 }
             }
         );

+ 2 - 0
src/cli/cli_config.rs

@@ -117,6 +117,8 @@ pub struct FeatureNetwork {
 
 #[derive(Clone, Serialize, Deserialize, Debug)]
 pub struct CashierdConfig {
+    /// The DNS name of the cashier (can also be an IP, or a .onion address)
+    pub dns_addr: String,
     /// The endpoint where cashierd will bind its RPC socket
     pub rpc_listen_address: SocketAddr,
     /// Whether to listen with TLS or plain TCP