This should have been 10 separate commits
This commit is contained in:
@@ -20,7 +20,7 @@ use crate::clients::directory::requests::presence_topology_get::{
|
||||
PresenceTopologyGetRequester, Request as PresenceTopologyRequest,
|
||||
};
|
||||
|
||||
mod metrics;
|
||||
pub mod metrics;
|
||||
pub mod presence;
|
||||
pub mod requests;
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ impl MixClient {
|
||||
let host = Ipv4Addr::new(b[0], b[1], b[2], b[3]);
|
||||
let port: u16 = u16::from_be_bytes([b[4], b[5]]);
|
||||
let socket_address = SocketAddrV4::new(host, port);
|
||||
println!("socket addr: {:?}", socket_address);
|
||||
|
||||
let mut stream = tokio::net::TcpStream::connect(socket_address).await?;
|
||||
stream.write_all(&bytes[..]).await?;
|
||||
|
||||
+2
-4
@@ -15,7 +15,7 @@ pub mod validator;
|
||||
|
||||
|
||||
// TODO: put that in config once it exists
|
||||
const LOOP_COVER_AVERAGE_DELAY: f64 = 10.0;
|
||||
const LOOP_COVER_AVERAGE_DELAY: f64 = 0.5;
|
||||
// assume seconds
|
||||
const MESSAGE_SENDING_AVERAGE_DELAY: f64 = 10.0;
|
||||
// assume seconds;
|
||||
@@ -41,9 +41,7 @@ impl MixTrafficController {
|
||||
let mix_client = MixClient::new();
|
||||
while let Some(mix_message) = rx.next().await {
|
||||
println!("[MIX TRAFFIC CONTROL] - got a mix_message for {:?}", mix_message.0);
|
||||
// here NodeAddressBytes would be transformed into a SocketAddr with SOME library call...
|
||||
let node_net_address = "127.0.0.1:8080";
|
||||
let send_res = mix_client.send(mix_message.1, node_net_address.parse().unwrap()).await;
|
||||
let send_res = mix_client.send(mix_message.1, mix_message.0).await;
|
||||
match send_res {
|
||||
Ok(_) => println!("We successfully sent the message!"),
|
||||
Err(e) => eprintln!("We failed to send the message :( - {:?}", e),
|
||||
|
||||
+1
-46
@@ -25,7 +25,7 @@ pub fn execute(matches: &ArgMatches) {
|
||||
let client = NymClient::new(my_address);
|
||||
client.start().unwrap();
|
||||
// Grab the network topology from the remote directory server
|
||||
let topology = get_topology(is_local);
|
||||
// let topology = get_topology(is_local);
|
||||
|
||||
// // Grab the network topology from the remote directory server
|
||||
// let topology = get_topology();
|
||||
@@ -111,51 +111,6 @@ pub fn execute(matches: &ArgMatches) {
|
||||
// })
|
||||
}
|
||||
|
||||
fn get_topology(is_local: bool) -> Topology {
|
||||
let url = if is_local {
|
||||
"http://localhost:8080".to_string()
|
||||
} else {
|
||||
"https://directory.nymtech.net".to_string()
|
||||
};
|
||||
println!("Using directory server: {:?}", url);
|
||||
let directory_config = directory::Config { base_url: url };
|
||||
let directory = directory::Client::new(directory_config);
|
||||
|
||||
let topology = directory
|
||||
.presence_topology
|
||||
.get()
|
||||
.expect("Failed to retrieve network topology.");
|
||||
topology
|
||||
}
|
||||
|
||||
fn route_from(topology: &Topology, route_len: usize) -> Vec<SphinxNode> {
|
||||
let mut route = vec![];
|
||||
let nodes = topology.mix_nodes.iter();
|
||||
for mix in nodes.take(route_len) {
|
||||
let address_bytes = socket_bytes_from_string(mix.host.clone());
|
||||
let decoded_key_bytes = base64::decode_config(&mix.pub_key, base64::URL_SAFE).unwrap();
|
||||
let key_bytes = bytes::zero_pad_to_32(decoded_key_bytes);
|
||||
let key = MontgomeryPoint(key_bytes);
|
||||
let sphinx_node = SphinxNode {
|
||||
address: address_bytes,
|
||||
pub_key: key,
|
||||
};
|
||||
route.push(sphinx_node);
|
||||
}
|
||||
route
|
||||
}
|
||||
|
||||
fn socket_bytes_from_string(address: String) -> [u8; 32] {
|
||||
let socket: SocketAddrV4 = address.parse().unwrap();
|
||||
let host_bytes = socket.ip().octets();
|
||||
let port_bytes = socket.port().to_be_bytes();
|
||||
let mut address_bytes = [0u8; 32];
|
||||
address_bytes.copy_from_slice(&host_bytes);
|
||||
address_bytes[4] = port_bytes[0];
|
||||
address_bytes[5] = port_bytes[1];
|
||||
address_bytes
|
||||
}
|
||||
|
||||
// TODO: where do we retrieve this guy from?
|
||||
fn get_destination() -> Destination {
|
||||
Destination {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
pub mod clients;
|
||||
pub mod identity;
|
||||
pub mod persistence;
|
||||
pub mod utils;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
pub mod bytes;
|
||||
pub mod poisson;
|
||||
pub mod sphinx;
|
||||
pub mod topology;
|
||||
|
||||
+16
-11
@@ -1,4 +1,4 @@
|
||||
use crate::utils::bytes;
|
||||
use crate::utils::{bytes, topology};
|
||||
use sphinx::route::{Destination, DestinationAddressBytes, Node, NodeAddressBytes, SURBIdentifier};
|
||||
use sphinx::SphinxPacket;
|
||||
|
||||
@@ -18,19 +18,24 @@ pub fn encapsulate_message(
|
||||
message: Vec<u8>,
|
||||
) -> (NodeAddressBytes, SphinxPacket) {
|
||||
// here we would be getting topology, etc
|
||||
let first_node_address = bytes::zero_pad_to_32("127.0.0.1:8080".as_bytes().to_vec());
|
||||
let dummy_route = vec![
|
||||
Node::new(first_node_address, Default::default()),
|
||||
Node::new(
|
||||
bytes::zero_pad_to_32("127.0.0.1:8081".as_bytes().to_vec()),
|
||||
Default::default(),
|
||||
),
|
||||
];
|
||||
|
||||
let delays = sphinx::header::delays::generate(dummy_route.len());
|
||||
let topology = topology::get_topology(true);
|
||||
let mixes_route = topology::route_from(&topology, 1);
|
||||
|
||||
let provider = Node::new(
|
||||
topology::socket_bytes_from_string("127.0.0.1:8081".to_string()),
|
||||
// bytes::zero_pad_to_32("127.0.0.1:8081".as_bytes().to_vec()),
|
||||
Default::default(),
|
||||
);
|
||||
|
||||
let route = [mixes_route, vec![provider]].concat();
|
||||
|
||||
let delays = sphinx::header::delays::generate(route.len());
|
||||
|
||||
// build the packet
|
||||
let packet = sphinx::SphinxPacket::new(message, &dummy_route[..], &recipient, &delays).unwrap();
|
||||
let packet = sphinx::SphinxPacket::new(message, &route[..], &recipient, &delays).unwrap();
|
||||
|
||||
let first_node_address = route.first().unwrap().address;
|
||||
|
||||
(first_node_address, packet)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
use crate::clients::directory;
|
||||
use crate::clients::directory::presence::Topology;
|
||||
use crate::clients::directory::requests::presence_topology_get::PresenceTopologyGetRequester;
|
||||
use crate::clients::directory::DirectoryClient;
|
||||
use crate::clients::mix::MixClient;
|
||||
use crate::clients::provider::ProviderClient;
|
||||
use crate::utils::bytes;
|
||||
use curve25519_dalek::montgomery::MontgomeryPoint;
|
||||
use sphinx::route::Node as SphinxNode;
|
||||
use std::net::SocketAddrV4;
|
||||
use std::string::ToString;
|
||||
|
||||
pub(crate) fn get_topology(is_local: bool) -> Topology {
|
||||
let url = if is_local {
|
||||
"http://localhost:8080".to_string()
|
||||
} else {
|
||||
"https://directory.nymtech.net".to_string()
|
||||
};
|
||||
println!("Using directory server: {:?}", url);
|
||||
let directory_config = directory::Config { base_url: url };
|
||||
let directory = directory::Client::new(directory_config);
|
||||
|
||||
let topology = directory
|
||||
.presence_topology
|
||||
.get()
|
||||
.expect("Failed to retrieve network topology.");
|
||||
topology
|
||||
}
|
||||
|
||||
pub(crate) fn route_from(topology: &Topology, route_len: usize) -> Vec<SphinxNode> {
|
||||
let mut route = vec![];
|
||||
let nodes = topology.mix_nodes.iter();
|
||||
for mix in nodes.take(route_len) {
|
||||
let address_bytes = socket_bytes_from_string(mix.host.clone());
|
||||
let decoded_key_bytes = base64::decode_config(&mix.pub_key, base64::URL_SAFE).unwrap();
|
||||
let key_bytes = bytes::zero_pad_to_32(decoded_key_bytes);
|
||||
let key = MontgomeryPoint(key_bytes);
|
||||
let sphinx_node = SphinxNode {
|
||||
address: address_bytes,
|
||||
pub_key: key,
|
||||
};
|
||||
route.push(sphinx_node);
|
||||
}
|
||||
route
|
||||
}
|
||||
|
||||
pub(crate) fn socket_bytes_from_string(address: String) -> [u8; 32] {
|
||||
let socket: SocketAddrV4 = address.parse().unwrap();
|
||||
let host_bytes = socket.ip().octets();
|
||||
let port_bytes = socket.port().to_be_bytes();
|
||||
let mut address_bytes = [0u8; 32];
|
||||
|
||||
address_bytes[0] = host_bytes[0];
|
||||
address_bytes[1] = host_bytes[1];
|
||||
address_bytes[2] = host_bytes[2];
|
||||
address_bytes[3] = host_bytes[3];
|
||||
|
||||
address_bytes[4] = port_bytes[0];
|
||||
address_bytes[5] = port_bytes[1];
|
||||
address_bytes
|
||||
}
|
||||
Reference in New Issue
Block a user