Feature/coconut feature (#805)

* 'Coconut' feature in gateway

* Enabled coconut feature in gateway-requests

* Native client coconut feature

* Ibid for socks5 client

* Ibid for wasm client

* Coconut feature flag for validator-api

* Added coconut feature flag to our CI

* build.yml typo

* Continue on windows errors

* Missing quote

* Another typo in build.yml

* Reclaiming disk space when building for windows on CI
This commit is contained in:
Jędrzej Stuczyński
2021-10-11 09:17:58 +01:00
committed by GitHub
parent 51dc8c81ed
commit 4e0e081b3e
27 changed files with 397 additions and 205 deletions
+12 -6
View File
@@ -15,9 +15,6 @@ 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;
@@ -25,6 +22,11 @@ use nymsphinx::addressing::clients::Recipient;
use std::sync::Arc;
use topology::NymTopology;
#[cfg(feature = "coconut")]
use coconut_interface::Credential;
#[cfg(feature = "coconut")]
use credentials::{bandwidth::prepare_for_spending, obtain_aggregate_verification_key};
pub(crate) mod chunker;
pub(crate) mod gateways_reader;
pub(crate) mod monitor;
@@ -90,6 +92,7 @@ impl<'a> NetworkMonitorBuilder<'a> {
*encryption_keypair.public_key(),
);
#[cfg(feature = "coconut")]
let bandwidth_credential =
TEMPORARY_obtain_bandwidth_credential(self.config, identity_keypair.public_key()).await;
@@ -97,8 +100,9 @@ impl<'a> NetworkMonitorBuilder<'a> {
self.config,
gateway_status_update_sender,
Arc::clone(&identity_keypair),
bandwidth_credential,
self.config.get_gateway_sending_rate(),
#[cfg(feature = "coconut")]
bandwidth_credential,
);
let received_processor = new_received_processor(
@@ -163,6 +167,7 @@ fn new_packet_preparer(
// SECURITY:
// this implies we are re-using the same credential for all gateways all the time (which unfortunately is true!)
#[cfg(feature = "coconut")]
#[allow(non_snake_case)]
async fn TEMPORARY_obtain_bandwidth_credential(
config: &Config,
@@ -192,17 +197,18 @@ fn new_packet_sender(
config: &Config,
gateways_status_updater: GatewayClientUpdateSender,
local_identity: Arc<identity::KeyPair>,
bandwidth_credential: Credential,
max_sending_rate: usize,
#[cfg(feature = "coconut")] bandwidth_credential: Credential,
) -> 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(),
max_sending_rate,
#[cfg(feature = "coconut")]
bandwidth_credential,
)
}
@@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0
use crate::network_monitor::monitor::receiver::{GatewayClientUpdate, GatewayClientUpdateSender};
use coconut_interface::Credential;
use crypto::asymmetric::identity::{self, PUBLIC_KEY_LENGTH};
use futures::channel::mpsc;
use futures::stream::{self, FuturesUnordered, StreamExt};
@@ -22,6 +21,9 @@ use std::task::Poll;
use std::time::Duration;
use tokio::time::Instant;
#[cfg(feature = "coconut")]
use coconut_interface::Credential;
const TIME_CHUNK_SIZE: Duration = Duration::from_millis(50);
pub(crate) struct GatewayPackets {
@@ -71,7 +73,8 @@ struct FreshGatewayClientData {
// 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,
#[cfg(feature = "coconut")]
coconut_bandwidth_credential: Credential,
}
pub(crate) struct PacketSender {
@@ -93,11 +96,11 @@ 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,
max_sending_rate: usize,
#[cfg(feature = "coconut")] coconut_bandwidth_credential: Credential,
) -> Self {
PacketSender {
active_gateway_clients: HashMap::new(),
@@ -105,7 +108,8 @@ impl PacketSender {
gateways_status_updater,
local_identity,
gateway_response_timeout,
bandwidth_credential,
#[cfg(feature = "coconut")]
coconut_bandwidth_credential,
}),
gateway_connection_timeout,
max_concurrent_clients,
@@ -137,7 +141,6 @@ impl PacketSender {
message_sender,
ack_sender,
fresh_gateway_client_data.gateway_response_timeout,
fresh_gateway_client_data.bandwidth_credential.clone(),
),
(message_receiver, ack_receiver),
)
@@ -230,7 +233,14 @@ impl PacketSender {
// (an actual bug we experienced)
match tokio::time::timeout(
gateway_connection_timeout,
new_client.authenticate_and_start(),
new_client.authenticate_and_start(
#[cfg(feature = "coconut")]
Some(
fresh_gateway_client_data
.coconut_bandwidth_credential
.clone(),
),
),
)
.await
{