Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/provider refactoring #125

Merged
merged 27 commits into from
Mar 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
3cb813d
Updated Storage to work with async io
jstuczyn Feb 28, 2020
03aac5b
Updated sphinx
jstuczyn Feb 28, 2020
b6e2c25
Made relevant mix methods private
jstuczyn Feb 28, 2020
da9593c
Missed updated sphinx cargo.toml file
jstuczyn Feb 28, 2020
1d36f73
Handling of received sphinx packet (incl. store)
jstuczyn Feb 28, 2020
ec93fdb
Extra comments + derived traits
jstuczyn Feb 28, 2020
a4c9bc1
Adjusted clients ledger
jstuczyn Feb 28, 2020
73ea1e2
Pending work
jstuczyn Feb 28, 2020
3851e9e
Constructor for client storage
jstuczyn Mar 2, 2020
b8f0fde
made has token method on client ledger public
jstuczyn Mar 2, 2020
b85bc53
Fix to provider requests due to previous sphinx changes
jstuczyn Mar 2, 2020
575bcaa
Adjusted field access to AuthToken
jstuczyn Mar 2, 2020
1f69f09
Fixed address derivation
jstuczyn Mar 2, 2020
63dfbc1
Using native to_base58_string in client ledger
jstuczyn Mar 2, 2020
3a2ad5a
sphinx version upgrade
jstuczyn Mar 2, 2020
30611d0
Reversed Client ledger mapping
jstuczyn Mar 2, 2020
0f5167b
Added ledger method to remove existing token
jstuczyn Mar 2, 2020
8ed5384
Method to actually retrieve stored auth token to compare it against o…
jstuczyn Mar 2, 2020
b6727ac
Replaced retrieve token method with verify token to bypass lifetime i…
jstuczyn Mar 2, 2020
20f2f1e
Updated mockito to fix build issues
jstuczyn Mar 3, 2020
a411dec
Client changes due to updates in sphinx
jstuczyn Mar 3, 2020
59dcf77
Defined ErrorResponse type
jstuczyn Mar 3, 2020
937e15e
Removed unused 'has_client' method from the ledger
jstuczyn Mar 3, 2020
c167aca
Theoretically thread safe client storage
jstuczyn Mar 3, 2020
ff4284a
Redundant code in mix handling
jstuczyn Mar 3, 2020
3852c99
Removed commented code
jstuczyn Mar 3, 2020
4992498
Refactored client handling
jstuczyn Mar 3, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
377 changes: 220 additions & 157 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion common/clients/directory-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ serde = { version = "1.0.104", features = ["derive"] }
topology = {path = "../../topology"}

[dev-dependencies]
mockito = "0.22.0"
mockito = "0.23.0"
2 changes: 1 addition & 1 deletion common/clients/mix-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ addressing = {path = "../../addressing"}
topology = {path = "../../topology"}

## will be moved to proper dependencies once released
sphinx = { git = "https://github.com/nymtech/sphinx", rev="4e51ed38a5de6fcb454c8903f1fe5e6b52720c77" }
sphinx = { git = "https://github.com/nymtech/sphinx", rev="23f9c89b257ee0936e70afd682e9ed6a62e89eee" }
# sphinx = { path = "../../../../sphinx"}

2 changes: 1 addition & 1 deletion common/clients/provider-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ tokio = { version = "0.2", features = ["full"] }
sfw-provider-requests = { path = "../../../sfw-provider/sfw-provider-requests" }

## will be moved to proper dependencies once released
sphinx = { git = "https://github.com/nymtech/sphinx", rev="4e51ed38a5de6fcb454c8903f1fe5e6b52720c77" }
sphinx = { git = "https://github.com/nymtech/sphinx", rev="23f9c89b257ee0936e70afd682e9ed6a62e89eee" }
4 changes: 2 additions & 2 deletions common/clients/provider-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl ProviderClient {
}
};

let pull_request = PullRequest::new(self.our_address, auth_token);
let pull_request = PullRequest::new(self.our_address.clone(), auth_token);
let bytes = pull_request.to_bytes();

let response = self.send_request(bytes).await?;
Expand All @@ -103,7 +103,7 @@ impl ProviderClient {
return Err(ProviderClientError::ClientAlreadyRegisteredError);
}

let register_request = RegisterRequest::new(self.our_address);
let register_request = RegisterRequest::new(self.our_address.clone());
let bytes = register_request.to_bytes();

let response = self.send_request(bytes).await?;
Expand Down
2 changes: 1 addition & 1 deletion common/crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ rand = "0.7.2"
rand_os = "0.1"

## will be moved to proper dependencies once released
sphinx = { git = "https://github.com/nymtech/sphinx", rev="4e51ed38a5de6fcb454c8903f1fe5e6b52720c77" }
sphinx = { git = "https://github.com/nymtech/sphinx", rev="23f9c89b257ee0936e70afd682e9ed6a62e89eee" }
2 changes: 1 addition & 1 deletion common/crypto/src/identity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl MixIdentityPublicKey {
let public_key_bytes = self.to_bytes();
temporary_address.copy_from_slice(&public_key_bytes[..]);

temporary_address
DestinationAddressBytes::from_bytes(temporary_address)
}

pub fn to_bytes(&self) -> Vec<u8> {
Expand Down
2 changes: 1 addition & 1 deletion common/healthcheck/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ sfw-provider-requests = { path = "../../sfw-provider/sfw-provider-requests" }
topology = {path = "../topology" }

## will be moved to proper dependencies once released
sphinx = { git = "https://github.com/nymtech/sphinx", rev="4e51ed38a5de6fcb454c8903f1fe5e6b52720c77" }
sphinx = { git = "https://github.com/nymtech/sphinx", rev="23f9c89b257ee0936e70afd682e9ed6a62e89eee" }
# sphinx = { path = "../../../sphinx"}

[dev-dependencies]
3 changes: 2 additions & 1 deletion common/healthcheck/src/path_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ impl PathChecker {
let address = identity_keys.public_key().derive_address();

for provider in providers {
let mut provider_client = ProviderClient::new(provider.client_listener, address, None);
let mut provider_client =
ProviderClient::new(provider.client_listener, address.clone(), None);
let insertion_result = match provider_client.register().await {
Ok(token) => {
debug!("registered at provider {}", provider.pub_key);
Expand Down
2 changes: 1 addition & 1 deletion common/topology/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ addressing = {path = "../addressing"}
version-checker = {path = "../version-checker" }

## will be moved to proper dependencies once released
sphinx = { git = "https://github.com/nymtech/sphinx", rev="4e51ed38a5de6fcb454c8903f1fe5e6b52720c77" }
sphinx = { git = "https://github.com/nymtech/sphinx", rev="23f9c89b257ee0936e70afd682e9ed6a62e89eee" }
# sphinx = { path = "../../../sphinx"}
2 changes: 1 addition & 1 deletion mixnode/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ multi-tcp-client = { path = "../common/clients/multi-tcp-client" }
pemstore = {path = "../common/pemstore"}

## will be moved to proper dependencies once released
sphinx = { git = "https://github.com/nymtech/sphinx", rev="4e51ed38a5de6fcb454c8903f1fe5e6b52720c77" }
sphinx = { git = "https://github.com/nymtech/sphinx", rev="23f9c89b257ee0936e70afd682e9ed6a62e89eee" }

[build-dependencies]
built = "0.3.2"
Expand Down
2 changes: 2 additions & 0 deletions mixnode/src/node/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ pub(crate) enum MetricEvent {
}

#[derive(Debug, Clone)]
// Note: you should NEVER create more than a single instance of this using 'new()'.
// You should always use .clone() to create additional instances
struct MixMetrics {
inner: Arc<Mutex<MixMetricsInner>>,
}
Expand Down
8 changes: 4 additions & 4 deletions mixnode/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl MixNode {
}
}

pub fn start_presence_notifier(&self) {
fn start_presence_notifier(&self) {
info!("Starting presence notifier...");
let notifier_config = presence::NotifierConfig::new(
self.config.get_presence_directory_server(),
Expand All @@ -55,7 +55,7 @@ impl MixNode {
presence::Notifier::new(notifier_config).start(self.runtime.handle());
}

pub fn start_metrics_reporter(&self) -> metrics::MetricsReporter {
fn start_metrics_reporter(&self) -> metrics::MetricsReporter {
info!("Starting metrics reporter...");
metrics::MetricsController::new(
self.config.get_metrics_directory_server(),
Expand All @@ -65,7 +65,7 @@ impl MixNode {
.start(self.runtime.handle())
}

pub fn start_socket_listener(
fn start_socket_listener(
&self,
metrics_reporter: metrics::MetricsReporter,
forwarding_channel: mpsc::UnboundedSender<(SocketAddr, Vec<u8>)>,
Expand All @@ -84,7 +84,7 @@ impl MixNode {
);
}

pub fn start_packet_forwarder(&mut self) -> mpsc::UnboundedSender<(SocketAddr, Vec<u8>)> {
fn start_packet_forwarder(&mut self) -> mpsc::UnboundedSender<(SocketAddr, Vec<u8>)> {
info!("Starting packet forwarder...");

// this can later be replaced with topology information
Expand Down
2 changes: 1 addition & 1 deletion nym-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ sfw-provider-requests = { path = "../sfw-provider/sfw-provider-requests" }
topology = {path = "../common/topology" }

## will be moved to proper dependencies once released
sphinx = { git = "https://github.com/nymtech/sphinx", rev="4e51ed38a5de6fcb454c8903f1fe5e6b52720c77" }
sphinx = { git = "https://github.com/nymtech/sphinx", rev="23f9c89b257ee0936e70afd682e9ed6a62e89eee" }
# sphinx = { path = "../../sphinx"}

[build-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion nym-client/src/client/cover_traffic_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub(crate) async fn start_loop_cover_traffic_stream<T: NymTopology>(
};

let cover_message = match mix_client::packet::loop_cover_message(
our_info.address,
our_info.address.clone(),
our_info.identifier,
topology,
average_packet_delay_duration,
Expand Down
8 changes: 4 additions & 4 deletions nym-client/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl NymClient {
let mut provider_poller = provider_poller::ProviderPoller::new(
poller_input_tx,
provider_client_listener_address,
self_address,
self_address.clone(),
self.config
.get_provider_auth_token()
.map(|str_token| AuthToken::try_from_base58_string(str_token).ok())
Expand Down Expand Up @@ -149,7 +149,7 @@ impl NymClient {
let loop_cover_traffic_future =
rt.spawn(cover_traffic_stream::start_loop_cover_traffic_stream(
mix_tx.clone(),
Destination::new(self_address, Default::default()),
Destination::new(self_address.clone(), Default::default()),
topology_controller.get_inner_ref(),
self.config.get_loop_cover_traffic_average_delay(),
self.config.get_average_packet_delay(),
Expand All @@ -160,7 +160,7 @@ impl NymClient {
let topology_ref = topology_controller.get_inner_ref();
let average_packet_delay = self.config.get_average_packet_delay();
let message_sending_average_delay = self.config.get_message_sending_average_delay();

let self_address_clone = self_address.clone();
// future constantly pumping traffic at some specified average rate
// if a real message is available on 'input_rx' that might have been received from say
// the websocket, the real message is used, otherwise a loop cover message is generated
Expand All @@ -169,7 +169,7 @@ impl NymClient {
real_traffic_stream::OutQueueControl::new(
mix_tx,
input_rx,
Destination::new(self_address, Default::default()),
Destination::new(self_address_clone, Default::default()),
topology_ref,
average_packet_delay,
message_sending_average_delay,
Expand Down
2 changes: 1 addition & 1 deletion nym-client/src/client/real_traffic_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl<T: NymTopology> OutQueueControl<T> {

let next_packet = match next_message {
StreamMessage::Cover => mix_client::packet::loop_cover_message(
self.our_info.address,
self.our_info.address.clone(),
self.our_info.identifier,
topology,
self.average_packet_delay,
Expand Down
7 changes: 5 additions & 2 deletions nym-client/src/commands/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ async fn try_provider_registrations(
) -> Option<(String, AuthToken)> {
// since the order of providers is non-deterministic we can just try to get a first 'working' provider
for provider in providers {
let provider_client =
provider_client::ProviderClient::new(provider.client_listener, our_address, None);
let provider_client = provider_client::ProviderClient::new(
provider.client_listener,
our_address.clone(),
None,
);
let auth_token = provider_client.register().await;
if let Ok(token) = auth_token {
return Some((provider.pub_key, token));
Expand Down
8 changes: 4 additions & 4 deletions nym-client/src/sockets/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ fn parse_send_request(data: &[u8]) -> Result<ClientRequest, TCPSocketError> {

Ok(ClientRequest::Send {
message,
recipient_address,
recipient_address: DestinationAddressBytes::from_bytes(recipient_address),
})
}

Expand Down Expand Up @@ -153,7 +153,7 @@ impl ClientRequest {

async fn handle_own_details(self_address_bytes: DestinationAddressBytes) -> ServerResponse {
ServerResponse::OwnDetails {
address: self_address_bytes.to_vec(),
address: self_address_bytes.to_bytes().to_vec(),
}
}
}
Expand Down Expand Up @@ -274,7 +274,7 @@ async fn accept_connection<T: 'static + NymTopology>(
topology: topology.clone(),
msg_input: msg_input.clone(),
msg_query: msg_query.clone(),
self_address,
self_address: self_address.clone(),
};
match handle_connection(&buf[..n], request_handling_data).await {
Ok(res) => res,
Expand Down Expand Up @@ -313,7 +313,7 @@ pub async fn start_tcpsocket<T: 'static + NymTopology>(
stream,
message_tx.clone(),
received_messages_query_tx.clone(),
self_address,
self_address.clone(),
topology.clone(),
));
}
Expand Down
13 changes: 9 additions & 4 deletions nym-client/src/sockets/ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ impl<T: NymTopology> Connection<T> {
}
ClientRequest::Fetch => ClientRequest::handle_fetch(self.msg_query.clone()).await,
ClientRequest::GetClients => ClientRequest::handle_get_clients(&self.topology).await,
ClientRequest::OwnDetails => ClientRequest::handle_own_details(self.self_address).await,
ClientRequest::OwnDetails => {
ClientRequest::handle_own_details(self.self_address.clone()).await
}
}
}

Expand Down Expand Up @@ -218,7 +220,10 @@ impl ClientRequest {

let dummy_surb = [0; 16];

let input_msg = InputMessage(Destination::new(address, dummy_surb), message_bytes);
let input_msg = InputMessage(
Destination::new(DestinationAddressBytes::from_bytes(address), dummy_surb),
message_bytes,
);
input_tx.send(input_msg).await.unwrap();

ServerResponse::Send
Expand Down Expand Up @@ -279,7 +284,7 @@ impl ClientRequest {
}

async fn handle_own_details(self_address_bytes: DestinationAddressBytes) -> ServerResponse {
let self_address = bs58::encode(&self_address_bytes).into_string();
let self_address = self_address_bytes.to_base58_string();
ServerResponse::OwnDetails {
address: self_address,
}
Expand Down Expand Up @@ -404,7 +409,7 @@ pub async fn start_websocket<T: 'static + NymTopology>(
stream,
message_tx.clone(),
received_messages_query_tx.clone(),
self_address,
self_address.clone(),
topology.clone(),
));
}
Expand Down
2 changes: 1 addition & 1 deletion sfw-provider/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pemstore = {path = "../common/pemstore"}
sfw-provider-requests = { path = "./sfw-provider-requests" }

## will be moved to proper dependencies once released
sphinx = { git = "https://github.com/nymtech/sphinx", rev="4e51ed38a5de6fcb454c8903f1fe5e6b52720c77" }
sphinx = { git = "https://github.com/nymtech/sphinx", rev="23f9c89b257ee0936e70afd682e9ed6a62e89eee" }

[build-dependencies]
built = "0.3.2"
Expand Down
2 changes: 1 addition & 1 deletion sfw-provider/sfw-provider-requests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ edition = "2018"

[dependencies]
bs58 = "0.3.0"
sphinx = { git = "https://github.com/nymtech/sphinx", rev="4e51ed38a5de6fcb454c8903f1fe5e6b52720c77" }
sphinx = { git = "https://github.com/nymtech/sphinx", rev="23f9c89b257ee0936e70afd682e9ed6a62e89eee" }
14 changes: 13 additions & 1 deletion sfw-provider/sfw-provider-requests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub const DUMMY_MESSAGE_CONTENT: &[u8] =

// To be renamed to 'AuthToken' once it is safe to replace it
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub struct AuthToken(pub [u8; 32]);
pub struct AuthToken([u8; 32]);

#[derive(Debug)]
pub enum AuthTokenConversionError {
Expand All @@ -15,6 +15,18 @@ pub enum AuthTokenConversionError {
}

impl AuthToken {
pub fn from_bytes(bytes: [u8; 32]) -> Self {
AuthToken(bytes)
}

pub fn to_bytes(&self) -> [u8; 32] {
self.0
}

pub fn as_bytes(&self) -> &[u8] {
&self.0
}

pub fn try_from_base58_string<S: Into<String>>(
val: S,
) -> Result<Self, AuthTokenConversionError> {
Expand Down
Loading