diff --git a/src/directory.rs b/src/directory.rs new file mode 100644 index 0000000000..18ef0356e3 --- /dev/null +++ b/src/directory.rs @@ -0,0 +1,70 @@ +use sphinx::route::{Node as SphinxNode, Destination}; + +pub struct DirectoryClient {} + +impl DirectoryClient { + pub fn new() -> DirectoryClient { + DirectoryClient {} + } + + // Hardcoded for now. Later, this should make a network request to the directory server (if one + // has not yet been made), parse the returned JSON, memoize the full tree of active nodes, + // and return the list of currently active mix nodes. + pub fn get_mixes(&self) -> Vec { + fake_directory_mixes() + } + + pub fn get_destination(&self) -> Destination { + Destination { + address: [0u8;32], + identifier: [0u8; 16], + } + } +} + + + +#[cfg(test)] +mod retrieving_mixnode_list { + use super::*; + + #[test] + fn always_works_because_it_is_hardcoded() { + let directory = DirectoryClient::new(); + let expected = fake_directory_mixes().as_slice().to_owned(); + + let mixes = directory.get_mixes(); + + assert_eq!(expected, mixes.as_slice()); + } +} + +#[cfg(test)] +mod retrieving_destinations { + use super::*; + + #[test] + fn always_works_because_it_is_hardcoded() { + let directory = DirectoryClient::new(); + let expected = Destination { + address: [0u8;32], + identifier: [0u8; 16], + }; + + let destination = directory.get_destination(); + + assert_eq!(expected, destination); + } +} + +fn fake_directory_mixes() -> Vec { + let node1 = sphinx::route::Node{ + address: [0u8;32], + pub_key: Default::default() + }; + let node2 = sphinx::route::Node{ + address: [1u8;32], + pub_key: Default::default() + }; + vec![node1, node2] +} \ No newline at end of file diff --git a/src/mix.rs b/src/mix.rs new file mode 100644 index 0000000000..4e903d644c --- /dev/null +++ b/src/mix.rs @@ -0,0 +1,41 @@ +use crate::directory::DirectoryClient; +use sphinx::SphinxPacket; +use sphinx::route::Node; + +struct MixClient {} + +impl MixClient { + fn new() -> MixClient { + MixClient {} + } + + fn send(&self, packet: SphinxPacket, mix: &Node) { + let bytes = packet.to_bytes(); + // now we shoot it into space! + } +} + + +#[cfg(test)] +mod sending_a_sphinx_packet { + use super::*; + use sphinx::SphinxPacket; + + #[test] + fn works() { + // arrange + let directory = DirectoryClient::new(); + let message = "Hello, Sphinx!".as_bytes().to_vec(); + let mixes = directory.get_mixes(); + let destination = directory.get_destination(); + let packet = SphinxPacket::new(message, &mixes, &destination); + let mix_client = MixClient::new(); + let first_hop = mixes.first().unwrap(); + + // act + mix_client.send(packet, first_hop); + + // assert + // wtf are we supposed to assert here? + } +} \ No newline at end of file diff --git a/src/validator.rs b/src/validator.rs new file mode 100644 index 0000000000..e69de29bb2