Updating to work with constant sized packets

This commit is contained in:
Dave Hrycyszyn
2019-11-29 15:54:44 +00:00
parent 1eee313e6e
commit fff78cfade
2 changed files with 8 additions and 4 deletions
Generated
+1
View File
@@ -558,6 +558,7 @@ dependencies = [
"aes-ctr 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"blake2 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"chacha 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"curve25519-dalek 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"hkdf 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
+7 -4
View File
@@ -1,6 +1,6 @@
use tokio::net::TcpListener;
use tokio::prelude::*;
use sphinx::SphinxPacket;
use sphinx::{SphinxPacket, ProcessedPacket};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
@@ -14,7 +14,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let (mut inbound, _) = listener.accept().await?;
tokio::spawn(async move {
let mut buf = [0; 1024];
let mut buf = [0; 1024 + 333];
loop {
let _ = match inbound.read(&mut buf).await {
@@ -26,8 +26,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
Ok(_) => {
println!("Received a packet!");
let packet = SphinxPacket::from_bytes(buf.to_vec()).unwrap();
let (unwrapped_packet, _) = packet.process(Default::default());
let message = unwrapped_packet.payload.content;
let payload = match packet.process(Default::default()){
ProcessedPacket::ProcessedPacketFinalHop(_,payload) => Some(payload) ,
_ => None,
}.unwrap();
let message = payload.get_content();
println!("Got message: {:?}", String::from_utf8(message).unwrap());
}
Err(e) => {