فهرست منبع

bin/darkfid: use UrlConfig in configuration file

ghassmo 4 سال پیش
والد
کامیت
55c3532f23
2فایلهای تغییر یافته به همراه40 افزوده شده و 45 حذف شده
  1. 20 24
      bin/darkfid/darkfid_config.toml
  2. 20 21
      bin/darkfid/src/main.rs

+ 20 - 24
bin/darkfid/darkfid_config.toml

@@ -3,44 +3,40 @@
 ## Please make sure you go through all the settings so you can configure
 ## your daemon properly.
 
-# The address where darkfid should bind its RPC socket
-rpc_listen_address = "127.0.0.1:8000"
+# Path to the client database
+database_path = "~/.config/darkfi/darkfid_client.db"
+
+# Path to the wallet database
+wallet_path = "~/.config/darkfi/darkfid_wallet.db"
 
-# Whether to listen with TLS or plain TCP
-serve_tls = false
+# The wallet password
+wallet_password = "TEST_PASSWORD"
 
-# Path to DER-formatted PKCS#12 archive. (Unused if serve_tls=false)
+# Path to DER-formatted PKCS#12 archive. (used only with tls url)
 # This can be created using openssl:
 # openssl pkcs12 -export -out identity.pfx -inkey key.pem -in cert.pem -certfile chain_certs.pem
 tls_identity_path = "~/.config/darkfi/darkfid_identity.pfx"
 
-# Password for the created TLS identity. (Unused if serve_tls=false)
-tls_identity_password = "FOOBAR"
+# The address where darkfid should bind its RPC socket
+[rpc_listener_url]
+url="127.0.0.1:8000"
+# Password for the created TLS identity or tor password
+password = "FOOBAR"
 
 # The endpoint to a gatewayd protocol API
-gateway_protocol_url = "tcp://testnet.gateway-protocol.dark.fi:3333"
+[gateway_url]
+url="tcp://testnet.gateway-protocol.dark.fi:3333"
 
 # The endpoint to a gatewayd publisher API
-gateway_publisher_url = "tcp://testnet.gateway-publish.dark.fi:4444"
-
-# Path to the client database
-database_path = "~/.config/darkfi/darkfid_client.db"
-
-# Path to the wallet database
-wallet_path = "~/.config/darkfi/darkfid_wallet.db"
-
-# The wallet password
-wallet_password = "TEST_PASSWORD"
+[gateway_pub_url]
+url="tcp://testnet.gateway-publish.dark.fi:4444"
 
 # The configured cashiers to use.
 [[cashiers]]
-
 # Cashier name
 name = "testnet.cashier.dark.fi"
-
-# The RPC endpoint for a selected cashier
-#rpc_url = "tcp://127.0.0.1:9000"
-rpc_url = "tls://testnet.cashier.dark.fi:9000"
-
 # The selected cashier public key
 public_key = "129F9szk9CuMEzBb8VqnoWPuShxayUznAgUBZsGzLyMrkDBHxC3"
+# The RPC endpoint for a selected cashier
+[cashiers.rpc_url]
+url="tls://testnet.cashier.dark.fi:9000"

+ 20 - 21
bin/darkfid/src/main.rs

@@ -1,4 +1,4 @@
-use std::{collections::HashMap, net::SocketAddr, path::PathBuf, str::FromStr};
+use std::{collections::HashMap, path::PathBuf, str::FromStr};
 
 use async_executor::Executor;
 use async_std::sync::{Arc, Mutex};
@@ -34,7 +34,7 @@ use darkfi::{
         rpcserver::{listen_and_serve, RequestHandler, RpcServerConfig},
     },
     util::{
-        cli::{log_config, spawn_config, Config},
+        cli::{log_config, spawn_config, Config, UrlConfig},
         decode_base10, encode_base10, expand_path, join_config_path, NetworkName,
     },
     zk::circuit::{MintContract, SpendContract},
@@ -45,37 +45,35 @@ use darkfi::{
 pub struct CashierC {
     /// Cashier name
     pub name: String,
-    /// The RPC endpoint for a selected cashier
-    pub rpc_url: String,
     /// The selected cashier public key
     pub public_key: String,
+    /// The RPC endpoint for a selected cashier
+    pub rpc_url: UrlConfig,
 }
 
+
 /// The configuration for darkfid
 #[derive(Clone, Serialize, Deserialize, Debug)]
 pub struct DarkfidConfig {
-    /// The address where darkfid should bind its RPC socket
-    pub rpc_listen_address: SocketAddr,
-    /// Whether to listen with TLS or plain TCP
-    pub serve_tls: bool,
-    /// Path to DER-formatted PKCS#12 archive. (Unused if serve_tls=false)
-    pub tls_identity_path: String,
-    /// Password for the TLS identity. (Unused if serve_tls=false)
-    pub tls_identity_password: String,
-    /// The endpoint to a gatewayd protocol API
-    pub gateway_protocol_url: String,
-    /// The endpoint to a gatewayd publisher API
-    pub gateway_publisher_url: String,
     /// Path to the client database
     pub database_path: String,
     /// Path to the wallet database
     pub wallet_path: String,
     /// The wallet password
     pub wallet_password: String,
+    /// Path to DER-formatted PKCS#12 archive. (used only with tls listener url)
+    pub tls_identity_path: String,
+    /// The address where darkfid should bind its RPC socket
+    pub rpc_listener_url: UrlConfig,
+    /// The endpoint to a gatewayd protocol API
+    pub gateway_url: UrlConfig ,
+    /// The endpoint to a gatewayd publisher API
+    pub gateway_pub_url: UrlConfig ,
     /// The configured cashiers to use
     pub cashiers: Vec<CashierC>,
 }
 
+
 /// Darkfid cli
 #[derive(Parser)]
 #[clap(name = "darkfid")]
@@ -809,7 +807,7 @@ async fn start(
 
             cashiers.push(Cashier {
                 name: cashier.name,
-                rpc_url: Url::parse(&cashier.rpc_url)?,
+                rpc_url: Url::try_from(cashier.rpc_url)?,
                 public_key: cashier_public,
             });
 
@@ -819,7 +817,7 @@ async fn start(
 
     let client = Client::new(
         rocks.clone(),
-        (Url::parse(&config.gateway_protocol_url)?, Url::parse(&config.gateway_publisher_url)?),
+        (Url::try_from(config.gateway_url.clone())?, Url::try_from(config.gateway_pub_url.clone())?),
         wallet.clone(),
     )
     .await?;
@@ -846,11 +844,12 @@ async fn start(
 
     let mut darkfid = Darkfid::new(client, state, cashiers).await?;
 
+    // TODO fix this
     let server_config = RpcServerConfig {
-        socket_addr: config.rpc_listen_address,
-        use_tls: config.serve_tls,
+        socket_addr: config.rpc_listener_url.url.parse()?,
+        use_tls: false,
         identity_path: expand_path(&config.tls_identity_path.clone())?,
-        identity_pass: config.tls_identity_password.clone(),
+        identity_pass: config.rpc_listener_url.password.clone().unwrap(),
     };
 
     darkfid.start(executor.clone()).await?;