Feature/nymd client integration (#736)
* Calculating gas fees * Ability to set custom fees * Added extra test * Removed commented code * Moved all msg types to common contract crate * Temporarily disabling get_tx method * Finishing up nymd client API * Comment fix * Remaining fee values * Some cleanup * Removed needless borrow * Fixed imports in contract tests * Moved error types around * New ValidatorClient * Experiment with new type of defaults * Removed dead module * Dealt with unwrap * Migrated mixnode to use new validator client * Migrated gateway to use new validator client * Mixnode and gateway adjustments * More exported defaults * Clients using new validator client * Fixed mixnode upgrade * Moved default values to a new crate * Changed behaviour of validator client features * Migrated basic functions of validator api * Updated config + fixed startup * Fixed wasm client build * Integration with the explorer api * Removed tokio dev dependency * Needless borrow * Fixex wasm client build * Fixed tauri client build * Needless borrows * Fixed client upgrade print * Removed redundant comments * Made note on aggregated verification key into a doc comment * Removed mixnet contract references from verloc * Modified default validators structure * Reformatted validator-api Cargo.toml file * Removed commented code * Made the doc comment example a no-run * Fixed a upgrade print... again * Adjusted the doc example * Removed unused import
This commit is contained in:
committed by
GitHub
parent
eec211e038
commit
a274edffba
@@ -7,7 +7,7 @@ use crate::node::client_handling::clients_handler::{
|
||||
use crate::node::client_handling::websocket::message_receiver::{
|
||||
MixMessageReceiver, MixMessageSender,
|
||||
};
|
||||
use coconut_interface::get_aggregated_verification_key;
|
||||
use coconut_interface::VerificationKey;
|
||||
use crypto::asymmetric::identity;
|
||||
use futures::{
|
||||
channel::{mpsc, oneshot},
|
||||
@@ -30,7 +30,6 @@ use tokio_tungstenite::{
|
||||
tungstenite::{protocol::Message, Error as WsError},
|
||||
WebSocketStream,
|
||||
};
|
||||
use validator_client::validator_api::Client as ValidatorAPIClient;
|
||||
|
||||
//// TODO: note for my future self to consider the following idea:
|
||||
//// split the socket connection into sink and stream
|
||||
@@ -58,7 +57,8 @@ pub(crate) struct Handle<R, S> {
|
||||
outbound_mix_sender: MixForwardingSender,
|
||||
socket_connection: SocketStream<S>,
|
||||
local_identity: Arc<identity::KeyPair>,
|
||||
validator_urls: Vec<String>,
|
||||
|
||||
aggregated_verification_key: VerificationKey,
|
||||
}
|
||||
|
||||
impl<R, S> Handle<R, S>
|
||||
@@ -73,7 +73,7 @@ where
|
||||
clients_handler_sender: ClientsHandlerRequestSender,
|
||||
outbound_mix_sender: MixForwardingSender,
|
||||
local_identity: Arc<identity::KeyPair>,
|
||||
validator_urls: Vec<String>,
|
||||
aggregated_verification_key: VerificationKey,
|
||||
) -> Self {
|
||||
Handle {
|
||||
rng,
|
||||
@@ -83,7 +83,7 @@ where
|
||||
outbound_mix_sender,
|
||||
socket_connection: SocketStream::RawTcp(conn),
|
||||
local_identity,
|
||||
validator_urls,
|
||||
aggregated_verification_key,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,18 +114,12 @@ where
|
||||
debug_assert!(self.socket_connection.is_websocket());
|
||||
match &mut self.socket_connection {
|
||||
SocketStream::UpgradedWebSocket(ws_stream) => {
|
||||
let verification_key = get_aggregated_verification_key(
|
||||
self.validator_urls.clone(),
|
||||
&ValidatorAPIClient::default(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
gateway_handshake(
|
||||
&mut self.rng,
|
||||
ws_stream,
|
||||
self.local_identity.as_ref(),
|
||||
init_msg,
|
||||
&verification_key,
|
||||
&self.aggregated_verification_key,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
use crate::node::client_handling::clients_handler::ClientsHandlerRequestSender;
|
||||
use crate::node::client_handling::websocket::connection_handler::Handle;
|
||||
use coconut_interface::VerificationKey;
|
||||
use crypto::asymmetric::identity;
|
||||
use log::*;
|
||||
use mixnet_client::forwarder::MixForwardingSender;
|
||||
@@ -15,19 +16,19 @@ use tokio::task::JoinHandle;
|
||||
pub(crate) struct Listener {
|
||||
address: SocketAddr,
|
||||
local_identity: Arc<identity::KeyPair>,
|
||||
validator_urls: Vec<String>,
|
||||
aggregated_verification_key: VerificationKey,
|
||||
}
|
||||
|
||||
impl Listener {
|
||||
pub(crate) fn new(
|
||||
address: SocketAddr,
|
||||
local_identity: Arc<identity::KeyPair>,
|
||||
validator_urls: Vec<String>,
|
||||
aggregated_verification_key: VerificationKey,
|
||||
) -> Self {
|
||||
Listener {
|
||||
address,
|
||||
local_identity,
|
||||
validator_urls,
|
||||
aggregated_verification_key,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +58,7 @@ impl Listener {
|
||||
clients_handler_sender.clone(),
|
||||
outbound_mix_sender.clone(),
|
||||
Arc::clone(&self.local_identity),
|
||||
self.validator_urls.clone(),
|
||||
self.aggregated_verification_key.clone(),
|
||||
);
|
||||
tokio::spawn(async move { handle.start_handling().await });
|
||||
}
|
||||
|
||||
+14
-7
@@ -6,9 +6,13 @@ use crate::node::client_handling::clients_handler::{ClientsHandler, ClientsHandl
|
||||
use crate::node::client_handling::websocket;
|
||||
use crate::node::mixnet_handling::receiver::connection_handler::ConnectionHandler;
|
||||
use crate::node::storage::{inboxes, ClientLedger};
|
||||
use coconut_interface::VerificationKey;
|
||||
use credentials::obtain_aggregate_verification_key;
|
||||
use crypto::asymmetric::{encryption, identity};
|
||||
use log::*;
|
||||
use mixnet_client::forwarder::{MixForwardingSender, PacketForwarder};
|
||||
use rand::seq::SliceRandom;
|
||||
use rand::thread_rng;
|
||||
use std::net::SocketAddr;
|
||||
use std::process;
|
||||
use std::sync::Arc;
|
||||
@@ -81,6 +85,7 @@ impl Gateway {
|
||||
&self,
|
||||
forwarding_channel: MixForwardingSender,
|
||||
clients_handler_sender: ClientsHandlerRequestSender,
|
||||
verification_key: VerificationKey,
|
||||
) {
|
||||
info!("Starting client [web]socket listener...");
|
||||
|
||||
@@ -92,7 +97,7 @@ impl Gateway {
|
||||
websocket::Listener::new(
|
||||
listening_address,
|
||||
Arc::clone(&self.identity),
|
||||
self.config.get_validator_rest_endpoints(),
|
||||
verification_key,
|
||||
)
|
||||
.start(clients_handler_sender, forwarding_channel);
|
||||
}
|
||||
@@ -135,11 +140,11 @@ impl Gateway {
|
||||
|
||||
// TODO: ask DH whether this function still makes sense in ^0.10
|
||||
async fn check_if_same_ip_gateway_exists(&self) -> Option<String> {
|
||||
let validator_client_config = validator_client::Config::new(
|
||||
self.config.get_validator_rest_endpoints(),
|
||||
self.config.get_validator_mixnet_contract_address(),
|
||||
);
|
||||
let validator_client = validator_client::Client::new(validator_client_config);
|
||||
let endpoints = self.config.get_validator_api_endpoints();
|
||||
let validator_api = endpoints
|
||||
.choose(&mut thread_rng())
|
||||
.expect("The list of validator apis is empty");
|
||||
let validator_client = validator_client::ApiClient::new(validator_api.clone());
|
||||
|
||||
let existing_gateways = match validator_client.get_cached_gateways().await {
|
||||
Ok(gateways) => gateways,
|
||||
@@ -178,11 +183,13 @@ impl Gateway {
|
||||
}
|
||||
}
|
||||
|
||||
let validators_verification_key = obtain_aggregate_verification_key(&self.config.get_validator_api_endpoints()).await.expect("failed to contact validators to obtain their verification keys");
|
||||
|
||||
let mix_forwarding_channel = self.start_packet_forwarder();
|
||||
let clients_handler_sender = self.start_clients_handler();
|
||||
|
||||
self.start_mix_socket_listener(clients_handler_sender.clone(), mix_forwarding_channel.clone());
|
||||
self.start_client_websocket_listener(mix_forwarding_channel, clients_handler_sender);
|
||||
self.start_client_websocket_listener(mix_forwarding_channel, clients_handler_sender, validators_verification_key);
|
||||
|
||||
info!("Finished nym gateway startup procedure - it should now be able to receive mix and client traffic!");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user