Skip to content

Commit

Permalink
Main example reformatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jmlepisto committed Nov 15, 2024
1 parent a618038 commit 34dd4f7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 19 deletions.
27 changes: 18 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,24 @@ fn main() {
let mut buf_alice_send = [0u8; 4096];
let mut buf_alice_receive = [0u8; 4096];

// Write handshake message and deliver to peer
let n = alice.write_message(&[], &mut buf_alice_send).unwrap();
my_send_function(&buf_alice_send[..n]);

// Receive handshake message and process it
let n = my_receive_function(&mut buf_alice_receive);
let _ = alice.read_message(&buf_alice_receive[..n], &mut[]).unwrap();

assert!(alice.is_finished());
// Send and receive handshake messages until the handshake is completed
loop {
if alice.is_write_turn() {
// Write handshake message to buf_alice_send
let n = alice.write_message(&[], &mut buf_alice_send).unwrap();
// --> Deliver buf_alice_send[..n] to peer
my_send_function(&buf_alice_send[..n]);
} else {
// <-- Receive message from peer to &buf_alice_receive
let n = my_receive_function(&mut buf_alice_receive);
// Process received handshake message
let _ = alice.read_message(&buf_alice_receive[..n], &mut[]).unwrap();
}

if alice.is_finished() {
break;
}
}

// Move to transport state
let mut alice = alice.finalize().unwrap();
Expand Down
27 changes: 17 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,24 @@
//! ).unwrap();
//!
//! let mut buf_alice_send = [0u8; 4096];
//! let mut buf_alice_receive = [0u8; 4096];
//!
//! // Write handshake message and deliver to peer
//! let n = alice.write_message(&[], &mut buf_alice_send).unwrap();
//! // --> Send &buf_alice_send[..n]) to peer
//!
//! // Receive handshake message and process it
//! // <-- Receive message from peer to &buf_alice_receive
//! let _ = alice.read_message(&buf_alice_receive[..n], &mut[]).unwrap();
//!
//! assert!(alice.is_finished());
//! // Send and receive handshake messages until the handshake is completed
//! loop {
//! if alice.is_write_turn() {
//! // Write handshake message to buf_alice_send
//! let n = alice.write_message(&[], &mut buf_alice_send).unwrap();
//! // --> Deliver buf_alice_send[..n] to peer
//! } else {
//! // <-- Receive message from peer to &buf_alice_receive
//! let buf_alice_receive = [0u8];
//! // Process received handshake message
//! let _ = alice.read_message(&buf_alice_receive, &mut[]).unwrap();
//! }
//!
//! if alice.is_finished() {
//! break;
//! }
//! }
//!
//! // Move to transport state
//! let mut alice = alice.finalize().unwrap();
Expand Down

0 comments on commit 34dd4f7

Please sign in to comment.