From f98aba540c133cd7e4cd23f7629cd000e7b9234b Mon Sep 17 00:00:00 2001 From: Marcin Anforowicz Date: Sun, 1 Dec 2024 08:52:09 -0800 Subject: [PATCH] Improved docs a bit --- gday_contact_exchange_protocol/src/lib.rs | 10 +++++----- gday_file_transfer/src/lib.rs | 1 - gday_file_transfer/src/transfer.rs | 7 +------ 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/gday_contact_exchange_protocol/src/lib.rs b/gday_contact_exchange_protocol/src/lib.rs index 4795b85..63cf66b 100644 --- a/gday_contact_exchange_protocol/src/lib.rs +++ b/gday_contact_exchange_protocol/src/lib.rs @@ -32,7 +32,7 @@ //! // an error message. //! let request = ClientMsg::CreateRoom { room_code }; //! write_to(request, &mut tls_ipv4)?; -//! let response: ServerMsg = read_from(&mut tls_ipv4)?; +//! let ServerMsg::RoomCreated = read_from(&mut tls_ipv4)? else { panic!() }; //! //! // Both peers sends ClientMsg::RecordPublicAddr //! // from their IPv4 and/or IPv6 endpoints. @@ -40,9 +40,9 @@ //! // The server responds with ServerMsg::ReceivedAddr or an error message. //! let request = ClientMsg::RecordPublicAddr { room_code, is_creator: true }; //! write_to(request, &mut tls_ipv4)?; -//! let response: ServerMsg = read_from(&mut tls_ipv4)?; +//! let ServerMsg::ReceivedAddr = read_from(&mut tls_ipv4)? else { panic!() }; //! write_to(request, &mut tls_ipv6)?; -//! let response: ServerMsg = read_from(&mut tls_ipv6)?; +//! let ServerMsg::ReceivedAddr = read_from(&mut tls_ipv6)? else { panic!() }; //! //! // Both peers share their local address with the server. //! // The server immediately responds with ServerMsg::ClientContact, @@ -53,12 +53,12 @@ //! }; //! let request = ClientMsg::ReadyToShare { local_contact, room_code, is_creator: true }; //! write_to(request, &mut tls_ipv4)?; -//! let response: ServerMsg = read_from(&mut tls_ipv4)?; +//! let ServerMsg::ClientContact(my_contact) = read_from(&mut tls_ipv4)? else { panic!() }; //! //! // Once both clients have sent ClientMsg::ReadyToShare, //! // the server sends both clients a ServerMsg::PeerContact //! // containing the FullContact of the peer. -//! let response: ServerMsg = read_from(&mut tls_ipv4)?; +//! let ServerMsg::PeerContact(peer_contact) = read_from(&mut tls_ipv4)? else { panic!() }; //! //! // The server then closes the room, and the peers disconnect. //! diff --git a/gday_file_transfer/src/lib.rs b/gday_file_transfer/src/lib.rs index d0f05b4..4690190 100644 --- a/gday_file_transfer/src/lib.rs +++ b/gday_file_transfer/src/lib.rs @@ -22,7 +22,6 @@ //! # //! # let rt = tokio::runtime::Builder::new_current_thread().build().unwrap(); //! # rt.block_on( async { -//! //! # let (stream1, stream2) = tokio::io::duplex(64); //! # let mut stream1 = tokio::io::BufReader::new(stream1); //! # let mut stream2 = tokio::io::BufReader::new(stream2); diff --git a/gday_file_transfer/src/transfer.rs b/gday_file_transfer/src/transfer.rs index 404161d..3a581ae 100644 --- a/gday_file_transfer/src/transfer.rs +++ b/gday_file_transfer/src/transfer.rs @@ -1,6 +1,4 @@ -use tokio::io::{ - AsyncBufRead, AsyncBufReadExt, AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, -}; +use tokio::io::{AsyncBufRead, AsyncBufReadExt, AsyncRead, AsyncWrite, AsyncWriteExt}; use crate::{Error, FileMeta, FileMetaLocal, FileOfferMsg, FileResponseMsg}; use std::io::{ErrorKind, Seek, SeekFrom}; @@ -147,9 +145,6 @@ pub async fn receive_files( return Err(Error::UnexpectedFileLen); } - // only take the length of the remaining part of the file from the reader - let mut reader = (&mut reader).take(offer.len - start); - net_to_file(&mut reader, &mut file, offer.len - start).await?; } reader.progress.processed_files += 1;