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
@@ -15,8 +15,12 @@ use crate::network_monitor::monitor::summary_producer::SummaryProducer;
|
||||
use crate::network_monitor::monitor::Monitor;
|
||||
use crate::network_monitor::tested_network::TestedNetwork;
|
||||
use crate::storage::NodeStatusStorage;
|
||||
use coconut_interface::Credential;
|
||||
use credentials::bandwidth::prepare_for_spending;
|
||||
use credentials::obtain_aggregate_verification_key;
|
||||
use crypto::asymmetric::{encryption, identity};
|
||||
use futures::channel::mpsc;
|
||||
use log::info;
|
||||
use nymsphinx::addressing::clients::Recipient;
|
||||
use std::sync::Arc;
|
||||
use topology::NymTopology;
|
||||
@@ -44,7 +48,7 @@ impl NetworkMonitorRunnables {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn new_monitor_runnables(
|
||||
pub(crate) async fn new_monitor_runnables(
|
||||
config: &Config,
|
||||
v4_topology: NymTopology,
|
||||
v6_topology: NymTopology,
|
||||
@@ -86,10 +90,14 @@ pub(crate) fn new_monitor_runnables(
|
||||
*encryption_keypair.public_key(),
|
||||
);
|
||||
|
||||
let bandwidth_credential =
|
||||
TEMPORARY_obtain_bandwidth_credential(config, identity_keypair.public_key()).await;
|
||||
|
||||
let packet_sender = new_packet_sender(
|
||||
config,
|
||||
gateway_status_update_sender,
|
||||
Arc::clone(&identity_keypair),
|
||||
bandwidth_credential,
|
||||
config.get_gateway_sending_rate(),
|
||||
);
|
||||
|
||||
@@ -135,15 +143,44 @@ fn new_packet_preparer(
|
||||
)
|
||||
}
|
||||
|
||||
// SECURITY:
|
||||
// this implies we are re-using the same credential for all gateways all the time (which unfortunately is true!)
|
||||
#[allow(non_snake_case)]
|
||||
async fn TEMPORARY_obtain_bandwidth_credential(
|
||||
config: &Config,
|
||||
identity: &identity::PublicKey,
|
||||
) -> Credential {
|
||||
info!("Trying to obtain bandwidth credential...");
|
||||
let validators = config.get_all_validator_api_endpoints();
|
||||
|
||||
let verification_key = obtain_aggregate_verification_key(&validators)
|
||||
.await
|
||||
.expect("could not obtain aggregate verification key of ALL validators");
|
||||
|
||||
let bandwidth_credential =
|
||||
credentials::bandwidth::obtain_signature(&identity.to_bytes(), &validators)
|
||||
.await
|
||||
.expect("failed to obtain bandwidth credential!");
|
||||
|
||||
prepare_for_spending(
|
||||
&identity.to_bytes(),
|
||||
&bandwidth_credential,
|
||||
&verification_key,
|
||||
)
|
||||
.expect("failed to prepare bandwidth credential for spending!")
|
||||
}
|
||||
|
||||
fn new_packet_sender(
|
||||
config: &Config,
|
||||
gateways_status_updater: GatewayClientUpdateSender,
|
||||
local_identity: Arc<identity::KeyPair>,
|
||||
bandwidth_credential: Credential,
|
||||
max_sending_rate: usize,
|
||||
) -> PacketSender {
|
||||
PacketSender::new(
|
||||
gateways_status_updater,
|
||||
local_identity,
|
||||
bandwidth_credential,
|
||||
config.get_gateway_response_timeout(),
|
||||
config.get_gateway_connection_timeout(),
|
||||
config.get_max_concurrent_gateway_clients(),
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// Copyright 2021 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use crate::config::DEFAULT_VALIDATOR_HOST;
|
||||
use crate::network_monitor::monitor::receiver::{GatewayClientUpdate, GatewayClientUpdateSender};
|
||||
use coconut_interface::Credential;
|
||||
use crypto::asymmetric::identity::{self, PUBLIC_KEY_LENGTH};
|
||||
@@ -22,7 +21,6 @@ use std::sync::Arc;
|
||||
use std::task::Poll;
|
||||
use std::time::Duration;
|
||||
use tokio::time::Instant;
|
||||
use validator_client::validator_api::VALIDATOR_API_PORT;
|
||||
|
||||
const TIME_CHUNK_SIZE: Duration = Duration::from_millis(50);
|
||||
|
||||
@@ -65,6 +63,15 @@ struct FreshGatewayClientData {
|
||||
gateways_status_updater: GatewayClientUpdateSender,
|
||||
local_identity: Arc<identity::KeyPair>,
|
||||
gateway_response_timeout: Duration,
|
||||
|
||||
// I guess in the future this struct will require aggregated verification key and....
|
||||
// ... something for obtaining actual credential
|
||||
|
||||
// TODO:
|
||||
// SECURITY:
|
||||
// since currently we have no double spending protection, just to get things running
|
||||
// we're re-using the same credential for all gateways all the time. THIS IS VERY BAD!!
|
||||
bandwidth_credential: Credential,
|
||||
}
|
||||
|
||||
pub(crate) struct PacketSender {
|
||||
@@ -84,6 +91,7 @@ impl PacketSender {
|
||||
pub(crate) fn new(
|
||||
gateways_status_updater: GatewayClientUpdateSender,
|
||||
local_identity: Arc<identity::KeyPair>,
|
||||
bandwidth_credential: Credential,
|
||||
gateway_response_timeout: Duration,
|
||||
gateway_connection_timeout: Duration,
|
||||
max_concurrent_clients: usize,
|
||||
@@ -95,6 +103,7 @@ impl PacketSender {
|
||||
gateways_status_updater,
|
||||
local_identity,
|
||||
gateway_response_timeout,
|
||||
bandwidth_credential,
|
||||
}),
|
||||
gateway_connection_timeout,
|
||||
max_concurrent_clients,
|
||||
@@ -114,16 +123,6 @@ impl PacketSender {
|
||||
// use old shared keys
|
||||
let (message_sender, message_receiver) = mpsc::unbounded();
|
||||
|
||||
let coconut_credential = Credential::init(
|
||||
vec![format!(
|
||||
"http://{}:{}",
|
||||
DEFAULT_VALIDATOR_HOST, VALIDATOR_API_PORT
|
||||
)],
|
||||
identity,
|
||||
)
|
||||
.await
|
||||
.expect("Could not initialize coconut credential");
|
||||
|
||||
// currently we do not care about acks at all, but we must keep the channel alive
|
||||
// so that the gateway client would not crash
|
||||
let (ack_sender, ack_receiver) = mpsc::unbounded();
|
||||
@@ -136,7 +135,7 @@ impl PacketSender {
|
||||
message_sender,
|
||||
ack_sender,
|
||||
fresh_gateway_client_data.gateway_response_timeout,
|
||||
coconut_credential,
|
||||
fresh_gateway_client_data.bandwidth_credential.clone(),
|
||||
),
|
||||
(message_receiver, ack_receiver),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user