Explorar o código

gateway: Use a URI for configuration.

This will enable us to implement TLS later on without breaking the
config scheme.
parazyd %!s(int64=4) %!d(string=hai) anos
pai
achega
f13f6b0d4e
Modificáronse 5 ficheiros con 30 adicións e 18 borrados
  1. 2 2
      example/config/cashierd.toml
  2. 2 2
      example/config/darkfid.toml
  3. 3 2
      src/bin/darkfid.rs
  4. 3 4
      src/client.rs
  5. 20 8
      src/service/gateway.rs

+ 2 - 2
example/config/cashierd.toml

@@ -18,10 +18,10 @@ tls_identity_path = "~/.config/darkfi/cashierd_identity.pfx"
 tls_identity_password = "FOOBAR"
 
 # The endpoint to a gatewayd protocol API
-gateway_protocol_url = "127.0.0.1:3333"
+gateway_protocol_url = "tcp://127.0.0.1:3333"
 
 # The endpoint to a gatewayd publisher API
-gateway_publisher_url = "127.0.0.1:4444"
+gateway_publisher_url = "tcp://127.0.0.1:4444"
 
 # Path to mint.params
 mint_params_path = "~/.config/darkfi/mint.params"

+ 2 - 2
example/config/darkfid.toml

@@ -18,10 +18,10 @@ tls_identity_path = "~/.config/darkfi/darkfid_identity.pfx"
 tls_identity_password = "FOOBAR"
 
 # The endpoint to a gatewayd protocol API
-gateway_protocol_url = "127.0.0.1:3333"
+gateway_protocol_url = "tcp://127.0.0.1:3333"
 
 # The endpoint to a gatewayd publisher API
-gateway_publisher_url = "127.0.0.1:4444"
+gateway_publisher_url = "tcp://127.0.0.1:4444"
 
 # Path to mint.params
 mint_params_path = "~/.config/darkfi/mint.params"

+ 3 - 2
src/bin/darkfid.rs

@@ -9,6 +9,7 @@ use clap::clap_app;
 use easy_parallel::Parallel;
 use log::debug;
 use serde_json::{json, Value};
+use url::Url;
 
 use drk::{
     blockchain::{rocks::columns, Rocks, RocksColumn},
@@ -546,8 +547,8 @@ async fn start(executor: Arc<Executor<'_>>, config: &DarkfidConfig) -> Result<()
     let client = Client::new(
         rocks.clone(),
         (
-            config.gateway_protocol_url.parse()?,
-            config.gateway_publisher_url.parse()?,
+            Url::parse(&config.gateway_protocol_url)?,
+            Url::parse(&config.gateway_publisher_url)?,
         ),
         wallet.clone(),
         mint_params,

+ 3 - 4
src/client.rs

@@ -1,10 +1,9 @@
-use std::net::SocketAddr;
-
 use async_executor::Executor;
 use async_std::sync::{Arc, Mutex};
 use bellman::groth16;
 use bls12_381::Bls12;
-use log::*;
+use log::{debug, info, warn};
+use url::Url;
 
 use crate::{
     blockchain::{rocks::columns, Rocks, RocksColumn, Slab},
@@ -49,7 +48,7 @@ pub struct Client {
 impl Client {
     pub async fn new(
         rocks: Arc<Rocks>,
-        gateway_addrs: (SocketAddr, SocketAddr),
+        gateway_addrs: (Url, Url),
         wallet: WalletPtr,
         mint_params: bellman::groth16::Parameters<Bls12>,
         spend_params: bellman::groth16::Parameters<Bls12>,

+ 20 - 8
src/service/gateway.rs

@@ -1,9 +1,12 @@
+use std::net::ToSocketAddrs;
+
 use async_std::sync::Arc;
 use std::convert::From;
 use std::net::SocketAddr;
 
 use async_executor::Executor;
-use log::*;
+use log::debug;
+use url::Url;
 
 use super::reqrep::{PeerId, Publisher, RepProtocol, Reply, ReqProtocol, Request, Subscriber};
 use crate::blockchain::{rocks::columns, RocksColumn, Slab, SlabStore};
@@ -178,24 +181,33 @@ pub struct GatewayClient {
 }
 
 impl GatewayClient {
-    pub fn new(
-        addr: SocketAddr,
-        sub_addr: SocketAddr,
-        rocks: RocksColumn<columns::Slabs>,
-    ) -> Result<Self> {
-        let protocol = ReqProtocol::new(addr, String::from("GATEWAY CLIENT"));
+    pub fn new(addr: Url, sub_addr: Url, rocks: RocksColumn<columns::Slabs>) -> Result<Self> {
+        // TODO: We'll want differentiation between TCP and TLS here.
+        let addr_sock = (addr.host().unwrap().to_string(), addr.port().unwrap())
+            .to_socket_addrs()?
+            .next()
+            .ok_or(Error::UrlParseError)?;
+        let protocol = ReqProtocol::new(addr_sock, String::from("GATEWAY CLIENT"));
 
         let slabstore = SlabStore::new(rocks)?;
 
         let (gateway_slabs_sub_s, gateway_slabs_sub_rv) = async_channel::unbounded::<Slab>();
 
+        let sub_addr_sock = (
+            sub_addr.host().unwrap().to_string(),
+            sub_addr.port().unwrap(),
+        )
+            .to_socket_addrs()?
+            .next()
+            .ok_or(Error::UrlParseError)?;
+
         Ok(GatewayClient {
             protocol,
             slabstore,
             gateway_slabs_sub_s,
             gateway_slabs_sub_rv,
             is_running: false,
-            sub_addr,
+            sub_addr: sub_addr_sock,
         })
     }