diff --git a/Cargo.lock b/Cargo.lock index 549606f022..6180700f9a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,14 +17,6 @@ dependencies = [ "tokio 0.1.22", ] -[[package]] -name = "addressing" -version = "0.1.0" -dependencies = [ - "log 0.4.8", - "pretty_env_logger", -] - [[package]] name = "adler32" version = "1.0.4" @@ -931,13 +923,13 @@ dependencies = [ name = "healthcheck" version = "0.1.0" dependencies = [ - "addressing", "crypto", "directory-client", "futures 0.3.4", "itertools", "log 0.4.8", "multi-tcp-client", + "nymsphinx", "pretty_env_logger", "provider-client", "rand 0.7.3", @@ -1432,8 +1424,8 @@ dependencies = [ name = "mix-client" version = "0.1.0" dependencies = [ - "addressing", "log 0.4.8", + "nymsphinx", "pretty_env_logger", "rand 0.7.3", "rand_distr", @@ -1537,7 +1529,6 @@ dependencies = [ name = "nym-client" version = "0.5.0" dependencies = [ - "addressing", "bs58", "built", "clap", @@ -1572,7 +1563,6 @@ dependencies = [ name = "nym-mixnode" version = "0.5.0" dependencies = [ - "addressing", "bs58", "built", "clap", @@ -1585,6 +1575,7 @@ dependencies = [ "futures 0.3.4", "log 0.4.8", "multi-tcp-client", + "nymsphinx", "pemstore", "pretty_env_logger", "serde", @@ -1654,11 +1645,9 @@ dependencies = [ name = "nymsphinx" version = "0.1.0" dependencies = [ - "addressing", "log 0.4.8", "rand 0.7.3", "sphinx", - "topology", ] [[package]] @@ -2858,10 +2847,10 @@ dependencies = [ name = "topology" version = "0.1.0" dependencies = [ - "addressing", "bs58", "itertools", "log 0.4.8", + "nymsphinx", "pretty_env_logger", "rand 0.7.3", "serde", diff --git a/Cargo.toml b/Cargo.toml index 45c534e23f..3b3a61111d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,6 @@ members = [ "common/clients/multi-tcp-client", "common/clients/provider-client", "common/clients/validator-client", - "common/addressing", "common/config", "common/crypto", "common/healthcheck", diff --git a/common/addressing/Cargo.toml b/common/addressing/Cargo.toml deleted file mode 100644 index 304a25dbc9..0000000000 --- a/common/addressing/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "addressing" -version = "0.1.0" -authors = ["Jedrzej Stuczynski "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -log = "0.4" -pretty_env_logger = "0.3" \ No newline at end of file diff --git a/common/addressing/src/lib.rs b/common/addressing/src/lib.rs deleted file mode 100644 index 529d93924d..0000000000 --- a/common/addressing/src/lib.rs +++ /dev/null @@ -1,80 +0,0 @@ -use std::convert::{TryFrom, TryInto}; -use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr}; - -pub enum AddressType { - V4, - V6, -} - -impl Into for AddressType { - fn into(self) -> u8 { - use AddressType::*; - - match self { - V4 => 4, - V6 => 6, - } - } -} - -#[derive(Debug)] -pub enum AddressTypeError { - InvalidPrefixError, -} - -impl TryFrom for AddressType { - type Error = AddressTypeError; - - fn try_from(value: u8) -> Result { - use AddressType::*; - use AddressTypeError::*; - - match value { - 4 => Ok(V4), - 6 => Ok(V6), - _ => Err(InvalidPrefixError), - } - } -} - -/// FLAG || port || octets || zeropad -pub fn encoded_bytes_from_socket_address(address: SocketAddr) -> [u8; 32] { - let port_bytes = address.port().to_be_bytes(); - - let encoded_host: Vec = match address.ip() { - IpAddr::V4(ip) => std::iter::once(AddressType::V4.into()) - .chain(port_bytes.iter().cloned()) - .chain(ip.octets().iter().cloned()) - .chain(std::iter::repeat(0)) - .take(32) - .collect(), - IpAddr::V6(ip) => std::iter::once(AddressType::V6.into()) - .chain(port_bytes.iter().cloned()) - .chain(ip.octets().iter().cloned()) - .chain(std::iter::repeat(0)) - .take(32) - .collect(), - }; - - let mut address_bytes = [0u8; 32]; - address_bytes.copy_from_slice(&encoded_host[..32]); - - address_bytes -} - -pub fn socket_address_from_encoded_bytes(b: [u8; 32]) -> Result { - let address_type: AddressType = b[0].try_into()?; - - let port: u16 = u16::from_be_bytes([b[1], b[2]]); - - let ip = match address_type { - AddressType::V4 => IpAddr::V4(Ipv4Addr::new(b[3], b[4], b[5], b[6])), - AddressType::V6 => { - let mut address_octets = [0u8; 16]; - address_octets.copy_from_slice(&b[3..19]); - IpAddr::V6(Ipv6Addr::from(address_octets)) - } - }; - - Ok(SocketAddr::new(ip, port)) -} diff --git a/common/clients/mix-client/Cargo.toml b/common/clients/mix-client/Cargo.toml index 1f65945e4e..502be0fb84 100644 --- a/common/clients/mix-client/Cargo.toml +++ b/common/clients/mix-client/Cargo.toml @@ -14,7 +14,7 @@ rand_distr = "0.2.2" tokio = { version = "0.2", features = ["full"] } ## internal -addressing = {path = "../../addressing"} +nymsphinx = {path = "../../nymsphinx"} topology = {path = "../../topology"} ## will be moved to proper dependencies once released diff --git a/common/clients/mix-client/src/packet.rs b/common/clients/mix-client/src/packet.rs index 6b25afd6b1..29dee4db3d 100644 --- a/common/clients/mix-client/src/packet.rs +++ b/common/clients/mix-client/src/packet.rs @@ -1,7 +1,7 @@ -use addressing; -use addressing::AddressTypeError; +use nymsphinx::addressing::nodes::{NymNodeRoutingAddress, NymNodeRoutingAddressError}; use sphinx::route::{Destination, DestinationAddressBytes, SURBIdentifier}; use sphinx::SphinxPacket; +use std::convert::TryFrom; use std::net::SocketAddr; use std::time; use topology::{NymTopology, NymTopologyError}; @@ -32,8 +32,8 @@ impl From for SphinxPacketEncapsulationError } } -impl From for SphinxPacketEncapsulationError { - fn from(_: AddressTypeError) -> Self { +impl From for SphinxPacketEncapsulationError { + fn from(_: NymNodeRoutingAddressError) -> Self { use SphinxPacketEncapsulationError::*; InvalidFirstMixAddress } @@ -96,9 +96,9 @@ pub fn encapsulate_message( // we know the mix route must be valid otherwise we would have already returned an error let first_node_address = - addressing::socket_address_from_encoded_bytes(route.first().unwrap().address.to_bytes())?; + NymNodeRoutingAddress::try_from(route.first().unwrap().address.clone())?; - Ok((first_node_address, packet)) + Ok((first_node_address.into(), packet)) } pub fn encapsulate_message_route( @@ -113,7 +113,7 @@ pub fn encapsulate_message_route( let packet = sphinx::SphinxPacket::new(message, &route[..], &recipient, &delays)?; let first_node_address = - addressing::socket_address_from_encoded_bytes(route.first().unwrap().address.to_bytes())?; + NymNodeRoutingAddress::try_from(route.first().unwrap().address.clone())?; - Ok((first_node_address, packet)) + Ok((first_node_address.into(), packet)) } diff --git a/common/healthcheck/Cargo.toml b/common/healthcheck/Cargo.toml index 22e4c0c454..4f94b73733 100644 --- a/common/healthcheck/Cargo.toml +++ b/common/healthcheck/Cargo.toml @@ -18,10 +18,10 @@ serde_derive = "1.0.104" tokio = { version = "0.2", features = ["full"] } ## internal -addressing = {path = "../addressing" } crypto = { path = "../crypto" } directory-client = { path = "../clients/directory-client" } multi-tcp-client = { path = "../clients/multi-tcp-client" } +nymsphinx = {path = "../nymsphinx" } provider-client = { path = "../clients/provider-client" } sfw-provider-requests = { path = "../../sfw-provider/sfw-provider-requests" } topology = {path = "../topology" } diff --git a/common/healthcheck/src/path_check.rs b/common/healthcheck/src/path_check.rs index f565e12e7f..5a356195dc 100644 --- a/common/healthcheck/src/path_check.rs +++ b/common/healthcheck/src/path_check.rs @@ -1,10 +1,13 @@ use crypto::identity::MixIdentityKeyPair; use itertools::Itertools; use log::{debug, error, info, trace, warn}; +use nymsphinx::addressing::nodes::NymNodeRoutingAddress; use provider_client::{ProviderClient, ProviderClientError}; use sphinx::header::delays::Delay; use sphinx::route::{Destination, Node as SphinxNode}; use std::collections::HashMap; +use std::convert::TryFrom; +use std::net::SocketAddr; use std::time::Duration; use topology::provider; @@ -217,9 +220,10 @@ impl PathChecker { .expect("We checked the path to contain at least one entry"); // we generated the bytes data so unwrap is fine - let first_node_address = - addressing::socket_address_from_encoded_bytes(layer_one_mix.address.to_bytes()) - .unwrap(); + let first_node_address: SocketAddr = + NymNodeRoutingAddress::try_from(layer_one_mix.address.clone()) + .unwrap() + .into(); let delays: Vec<_> = path.iter().map(|_| Delay::new_from_nanos(0)).collect(); diff --git a/common/nymsphinx/Cargo.toml b/common/nymsphinx/Cargo.toml index 9909717ce0..1954f3ae26 100644 --- a/common/nymsphinx/Cargo.toml +++ b/common/nymsphinx/Cargo.toml @@ -10,12 +10,6 @@ edition = "2018" log = "0.4.8" rand = "0.7.3" -# TODO: eventually move this functionality to this crate and remove `addressing` completely -addressing = {path = "../addressing" } - -topology = {path = "../topology" } - - ## will be moved to proper dependencies once released sphinx = { git = "https://github.com/nymtech/sphinx", rev="44d8f2aece5049eaa4fe84b7948758ce82b4b80d" } diff --git a/common/nymsphinx/src/addressing/mod.rs b/common/nymsphinx/src/addressing/mod.rs new file mode 100644 index 0000000000..69e3fea510 --- /dev/null +++ b/common/nymsphinx/src/addressing/mod.rs @@ -0,0 +1 @@ +pub mod nodes; diff --git a/common/nymsphinx/src/addressing/nodes.rs b/common/nymsphinx/src/addressing/nodes.rs new file mode 100644 index 0000000000..af0a16e09b --- /dev/null +++ b/common/nymsphinx/src/addressing/nodes.rs @@ -0,0 +1,206 @@ +use sphinx::constants::NODE_ADDRESS_LENGTH; +use sphinx::route::NodeAddressBytes; +use std::convert::{TryFrom, TryInto}; +use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr}; + +/// This module is responsible for encoding and decoding node routing information, so that +/// they could be later put into an appropriate field in a sphinx header. +/// Currently, that routing information is an IP address, but in principle it can be anything +/// for as long as it's going to fit in the field. + +#[derive(Debug)] +pub enum NymNodeRoutingAddressError { + InsufficientNumberOfBytesAvailableError, + InvalidIPVersion, +} + +/// Current representation of Node routing information used in Nym system. +/// At this point of time it is a simple `SocketAddr`. +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] +pub struct NymNodeRoutingAddress(SocketAddr); + +impl NymNodeRoutingAddress { + /// Minimum number of bytes that need to be available to represent self. + /// The value has no upper bound as when converted into bytes, it's always + /// padded with zeroes to be exactly NODE_ADDRESS_LENGTH long. + pub fn bytes_min_len(&self) -> usize { + match self.0 { + SocketAddr::V4(_) => 7, + SocketAddr::V6(_) => 19, + } + } + + /// Converts self into a vector of bytes. + /// Note, this represents a generic bytes vector, not necessarily a NodeAddressBytes + /// and hence is not zero-padded. + pub fn as_bytes(&self) -> Vec { + let port_bytes = self.0.port().to_be_bytes(); + let ip_octets_vec = match self.0.ip() { + IpAddr::V4(ip) => ip.octets().to_vec(), + IpAddr::V6(ip) => ip.octets().to_vec(), + }; + + std::iter::once(self.addr_type_as_u8()) + .chain(port_bytes.iter().cloned()) + .chain(ip_octets_vec.iter().cloned()) + .collect() + } + + /// Tries to recover `Self` from a bytes slice. + /// Does not care if it's zero-padded or not. + pub fn try_from_bytes(b: &[u8]) -> Result { + // the bare minimum to represent `Self` is 7 bytes (for the shorter V4 version) + if b.len() < 7 { + return Err(NymNodeRoutingAddressError::InsufficientNumberOfBytesAvailableError); + } + + let ip_version = b[0]; + let port: u16 = u16::from_be_bytes([b[1], b[2]]); + let ip = match ip_version { + 4 => IpAddr::V4(Ipv4Addr::new(b[3], b[4], b[5], b[6])), + 6 => { + if b.len() < 19 { + return Err( + NymNodeRoutingAddressError::InsufficientNumberOfBytesAvailableError, + ); + } + let mut address_octets = [0u8; 16]; + address_octets.copy_from_slice(&b[3..19]); + IpAddr::V6(Ipv6Addr::from(address_octets)) + } + _ => return Err(NymNodeRoutingAddressError::InvalidIPVersion), + }; + + Ok(Self(SocketAddr::new(ip, port))) + } + + /// Single byte representation of self ip version. + pub fn addr_type_as_u8(&self) -> u8 { + match self.0 { + SocketAddr::V4(_) => 4, + SocketAddr::V6(_) => 6, + } + } +} + +/// Considering `NymNodeRoutingAddress` is equivalent to a `SocketAddr` at this point, +/// it makes perfect sense to allow the bilateral transformation. +impl From for NymNodeRoutingAddress { + fn from(addr: SocketAddr) -> Self { + Self(addr) + } +} + +/// Considering `NymNodeRoutingAddress` is equivalent to a `SocketAddr` at this point, +/// it makes perfect sense to allow the bilateral transformation. +impl Into for NymNodeRoutingAddress { + fn into(self) -> SocketAddr { + self.0 + } +} + +impl TryInto for NymNodeRoutingAddress { + type Error = NymNodeRoutingAddressError; + + /// `NymNodeRoutingAddress` (as a `SocketAddr`) is represented the following way: + /// VersionFlag || port || octets || zeropad + /// VersionFlag is one byte representing whether self is ipv4 or ipv6 address, + /// port is 16bit big endian representation of port value + /// octets is bytes representation of octets making up the ip address of the socket address + /// (either 4 bytes for ipv4 or 16 bytes for ipv6) + /// zeropad is padding of 0 for the `NymNodeRoutingAddress` to be + /// exactly `NODE_ADDRESS_LENGTH` long. + fn try_into(self) -> Result { + // first check if we have enough bytes to represent `self`: + if self.bytes_min_len() > NODE_ADDRESS_LENGTH { + return Err(NymNodeRoutingAddressError::InsufficientNumberOfBytesAvailableError); + } + + let unpadded_address = self.as_bytes(); + let padded_address: Vec<_> = unpadded_address + .into_iter() + .chain(std::iter::repeat(0)) + .take(NODE_ADDRESS_LENGTH) + .collect(); + + let mut node_address_bytes = [0u8; 32]; + node_address_bytes.copy_from_slice(&padded_address); + + Ok(NodeAddressBytes::from_bytes(node_address_bytes)) + } +} + +impl TryFrom for NymNodeRoutingAddress { + type Error = NymNodeRoutingAddressError; + + fn try_from(value: NodeAddressBytes) -> Result { + Self::try_from_bytes(value.as_bytes()) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn nym_node_routing_address_can_be_converted_to_and_from_bytes_for_v4_address() { + let address = NymNodeRoutingAddress(SocketAddr::new(IpAddr::from([1, 2, 3, 4]), 42)); + let address_bytes = address.as_bytes(); + assert_eq!( + address, + NymNodeRoutingAddress::try_from_bytes(&address_bytes).unwrap() + ) + } + + #[test] + fn nym_node_routing_address_can_be_converted_to_and_from_bytes_for_v6_address() { + let address = NymNodeRoutingAddress(SocketAddr::new( + IpAddr::from([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]), + 42, + )); + let address_bytes = address.as_bytes(); + assert_eq!( + address, + NymNodeRoutingAddress::try_from_bytes(&address_bytes).unwrap() + ) + } + + #[test] + fn nym_node_routing_address_can_be_converted_to_and_from_bytes_for_empty_v4_address() { + let address = NymNodeRoutingAddress(SocketAddr::new(IpAddr::from([0, 0, 0, 0]), 42)); + let address_bytes = address.as_bytes(); + assert_eq!( + address, + NymNodeRoutingAddress::try_from_bytes(&address_bytes).unwrap() + ) + } + + #[test] + fn nym_node_routing_address_can_be_converted_to_and_from_bytes_for_empty_v6_address() { + let address = NymNodeRoutingAddress(SocketAddr::new( + IpAddr::from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), + 42, + )); + let address_bytes = address.as_bytes(); + assert_eq!( + address, + NymNodeRoutingAddress::try_from_bytes(&address_bytes).unwrap() + ) + } + + #[test] + fn nym_node_routing_address_can_be_converted_to_and_from_node_address_bytes_with_no_data_loss() + { + let address_v4 = NymNodeRoutingAddress(SocketAddr::new(IpAddr::from([1, 2, 3, 4]), 42)); + let address_v6 = NymNodeRoutingAddress(SocketAddr::new( + IpAddr::from([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]), + 42, + )); + + let node_address1: NodeAddressBytes = address_v4.try_into().unwrap(); + let node_address2: NodeAddressBytes = address_v6.try_into().unwrap(); + + assert_eq!(address_v4, node_address1.try_into().unwrap()); + assert_eq!(address_v6, node_address2.try_into().unwrap()); + } +} diff --git a/common/nymsphinx/src/chunking/mod.rs b/common/nymsphinx/src/chunking/mod.rs index d97ab34310..578560b644 100644 --- a/common/nymsphinx/src/chunking/mod.rs +++ b/common/nymsphinx/src/chunking/mod.rs @@ -1,9 +1,4 @@ use crate::chunking::set::split_into_sets; -use addressing::AddressTypeError; -use sphinx::route::{Destination, Node}; -use std::net::SocketAddr; -use std::time; -use topology::{NymTopology, NymTopologyError}; pub mod fragment; pub mod reconstruction; @@ -48,25 +43,6 @@ pub enum ChunkingError { UnexpectedFragmentCount, } -impl From for ChunkingError { - fn from(_: NymTopologyError) -> Self { - use ChunkingError::*; - NoValidRoutesAvailableError - } -} - -// this will later be completely removed when `addressing` crate is moved into this crate -impl From for ChunkingError { - fn from(_: AddressTypeError) -> Self { - use ChunkingError::*; - InvalidTopologyError - } -} - -// the user of this library can either prepare payloads for sphinx packets that he needs to -// encapsulate themselves by creating [sphinx] headers. -// or alternatively provide network topology and get bytes ready to be sent over the network - /// Takes the entire message and splits it into bytes chunks that will fit into sphinx packets /// directly. After receiving they can be combined using `reconstruction::MessageReconstructor` /// to obtain the original message back. @@ -78,43 +54,3 @@ pub fn split_and_prepare_payloads(message: &[u8]) -> Vec> { .map(|fragment| fragment.into_bytes()) .collect() } - -// note that for very long messages, this function will take a very long time to complete -// due to expensive sphinx wrapping operations - -/// Takes the entire message and splits it into bytes chunks that are then encapsulated into -/// sphinx packets usingn provided network topology. The resultant bytes chunks can be sent -/// directly on the wire to the `SocketAddr` part of the tuple. -/// After being received back by a client they can be combined using `reconstruction::MessageReconstructor` -/// to obtain the original message back. -pub fn split_and_encapsulate_message( - message: &[u8], - // TODO: in the future this will require also a specific provider of this particular recipient - recipient: Destination, - average_delay: time::Duration, - topology: &T, -) -> Result)>, ChunkingError> { - let ready_payloads = split_and_prepare_payloads(message); - - let mut providers = topology.providers(); - if providers.is_empty() { - return Err(ChunkingError::NoValidProvidersError); - } - let provider: Node = providers.pop().unwrap().into(); - - let mut encapsulated_sphinx_packets = Vec::new(); - for message_fragment in ready_payloads { - let route = topology.route_to(provider.clone())?; - let delays = - sphinx::header::delays::generate_from_average_duration(route.len(), average_delay); - let packet = - sphinx::SphinxPacket::new(message_fragment, &route[..], &recipient, &delays).unwrap(); // this cannot fail unless there's an underlying bug which we must find and fix anyway - let first_node_address = addressing::socket_address_from_encoded_bytes( - route.first().unwrap().address.to_bytes(), - )?; - - encapsulated_sphinx_packets.push((first_node_address, packet.to_bytes())); - } - - Ok(encapsulated_sphinx_packets) -} diff --git a/common/nymsphinx/src/lib.rs b/common/nymsphinx/src/lib.rs index 22b124dc84..79bf24329f 100644 --- a/common/nymsphinx/src/lib.rs +++ b/common/nymsphinx/src/lib.rs @@ -1,3 +1,4 @@ +pub mod addressing; pub mod chunking; // Future consideration: currently in a lot of places, the payloads have randomised content diff --git a/common/topology/Cargo.toml b/common/topology/Cargo.toml index f52e074d77..4f64d5f429 100644 --- a/common/topology/Cargo.toml +++ b/common/topology/Cargo.toml @@ -15,7 +15,7 @@ rand = "0.7.2" serde = { version = "1.0.104", features = ["derive"] } ## internal -addressing = {path = "../addressing"} +nymsphinx = {path = "../nymsphinx"} version-checker = {path = "../version-checker" } ## will be moved to proper dependencies once released diff --git a/common/topology/src/mix.rs b/common/topology/src/mix.rs index abf04e72b5..fd5ae78fee 100644 --- a/common/topology/src/mix.rs +++ b/common/topology/src/mix.rs @@ -1,6 +1,7 @@ use crate::filter; +use nymsphinx::addressing::nodes::NymNodeRoutingAddress; use sphinx::route::Node as SphinxNode; -use sphinx::route::NodeAddressBytes; +use std::convert::TryInto; use std::net::SocketAddr; #[derive(Debug, Clone)] @@ -29,10 +30,10 @@ impl filter::Versioned for Node { impl Into for Node { fn into(self) -> SphinxNode { - let address_bytes = addressing::encoded_bytes_from_socket_address(self.host); + let node_address_bytes = NymNodeRoutingAddress::from(self.host).try_into().unwrap(); let key_bytes = self.get_pub_key_bytes(); let key = sphinx::key::new(key_bytes); - SphinxNode::new(NodeAddressBytes::from_bytes(address_bytes), key) + SphinxNode::new(node_address_bytes, key) } } diff --git a/common/topology/src/provider.rs b/common/topology/src/provider.rs index 7687489e3c..d1ed27e909 100644 --- a/common/topology/src/provider.rs +++ b/common/topology/src/provider.rs @@ -1,6 +1,7 @@ use crate::filter; +use nymsphinx::addressing::nodes::NymNodeRoutingAddress; use sphinx::route::Node as SphinxNode; -use sphinx::route::NodeAddressBytes; +use std::convert::TryInto; use std::net::SocketAddr; #[derive(Debug, Clone)] @@ -35,10 +36,12 @@ impl filter::Versioned for Node { impl Into for Node { fn into(self) -> SphinxNode { - let address_bytes = addressing::encoded_bytes_from_socket_address(self.mixnet_listener); + let node_address_bytes = NymNodeRoutingAddress::from(self.mixnet_listener) + .try_into() + .unwrap(); let key_bytes = self.get_pub_key_bytes(); let key = sphinx::key::new(key_bytes); - SphinxNode::new(NodeAddressBytes::from_bytes(address_bytes), key) + SphinxNode::new(node_address_bytes, key) } } diff --git a/mixnode/Cargo.toml b/mixnode/Cargo.toml index 1d22c565c8..e98a252747 100644 --- a/mixnode/Cargo.toml +++ b/mixnode/Cargo.toml @@ -20,11 +20,11 @@ serde = { version = "1.0.104", features = ["derive"] } tokio = { version = "0.2", features = ["full"] } ## internal -addressing = {path = "../common/addressing" } config = {path = "../common/config"} crypto = {path = "../common/crypto"} directory-client = { path = "../common/clients/directory-client" } multi-tcp-client = { path = "../common/clients/multi-tcp-client" } +nymsphinx = {path = "../common/nymsphinx" } pemstore = {path = "../common/pemstore"} topology = {path = "../common/topology"} diff --git a/mixnode/src/node/packet_processing.rs b/mixnode/src/node/packet_processing.rs index ec6187e9aa..21ad6fdce7 100644 --- a/mixnode/src/node/packet_processing.rs +++ b/mixnode/src/node/packet_processing.rs @@ -1,10 +1,11 @@ use crate::node::metrics; -use addressing::AddressTypeError; use crypto::encryption; use log::*; +use nymsphinx::addressing::nodes::{NymNodeRoutingAddress, NymNodeRoutingAddressError}; use sphinx::header::delays::Delay as SphinxDelay; use sphinx::route::NodeAddressBytes; use sphinx::{ProcessedPacket, SphinxPacket}; +use std::convert::TryFrom; use std::net::SocketAddr; use std::ops::Deref; use std::sync::Arc; @@ -32,8 +33,8 @@ impl From for MixProcessingError { } } -impl From for MixProcessingError { - fn from(_: AddressTypeError) -> Self { +impl From for MixProcessingError { + fn from(_: NymNodeRoutingAddressError) -> Self { use MixProcessingError::*; InvalidHopAddress @@ -68,8 +69,7 @@ impl PacketProcessor { forward_address: NodeAddressBytes, delay: SphinxDelay, ) -> Result { - let next_hop_address = - addressing::socket_address_from_encoded_bytes(forward_address.to_bytes())?; + let next_hop_address: SocketAddr = NymNodeRoutingAddress::try_from(forward_address)?.into(); // Delay packet for as long as required tokio::time::delay_for(delay.to_duration()).await; diff --git a/nym-client/Cargo.toml b/nym-client/Cargo.toml index 24b85cafdf..487a7932e7 100644 --- a/nym-client/Cargo.toml +++ b/nym-client/Cargo.toml @@ -28,7 +28,6 @@ tokio = { version = "0.2", features = ["full"] } tokio-tungstenite = "0.10.1" ## internal -addressing = {path = "../common/addressing" } config = {path = "../common/config"} crypto = {path = "../common/crypto"} directory-client = { path = "../common/clients/directory-client" }