Still broken

This commit is contained in:
Donald Knuth 2022-09-03 15:12:47 -04:00
parent 28a97f675e
commit 02f5fca565
2 changed files with 12 additions and 7 deletions

View file

@ -43,9 +43,7 @@ pub async fn receive(password: &String) -> Result<()> {
let (socket, key) = handshake.negotiate(socket, s1).await?;
let mut connection = Connection::new(socket, key);
// Wait for offered files, respond with desired files
let desired_files = request_specific_files(&mut connection).await?;
// Create files
let std_file_handles = create_or_find_files(desired_files).await?;
let std_file_handles = request_specific_files(&mut connection).await?;
// Download them
connection.download_files(std_file_handles).await?;
return Ok(());
@ -72,7 +70,7 @@ pub async fn offer_files(
}
}
pub async fn request_specific_files(conn: &mut Connection) -> Result<Vec<FileOffer>> {
pub async fn request_specific_files(conn: &mut Connection) -> Result<Vec<StdFileHandle>> {
// Wait for offer message
let offer_message = conn.await_msg().await?;
let offered_files: Vec<FileOffer> = match offer_message {
@ -81,17 +79,18 @@ pub async fn request_specific_files(conn: &mut Connection) -> Result<Vec<FileOff
};
// Prompt user for confirmation of files
let desired_files = prompt_user_for_file_confirmation(offered_files).await;
let std_file_handles = create_or_find_files(desired_files).await?;
let file_request_msg = Message::FileRequest(FileRequestPayload {
chunks: desired_files
chunks: std_file_handles
.iter()
.map(|file| ChunkHeader {
id: file.id,
start: 0,
start: file.start,
})
.collect(),
});
conn.send_msg(file_request_msg).await?;
Ok(desired_files)
Ok(std_file_handles)
}
pub async fn create_or_find_files(desired_files: Vec<FileOffer>) -> Result<Vec<StdFileHandle>> {
@ -110,6 +109,11 @@ pub async fn create_or_find_files(desired_files: Vec<FileOffer>) -> Result<Vec<S
Err(_) => File::create(filename).await?,
};
let metadata = file.metadata().await?;
println!(
"Current len: {:?}, Full Size: {:?}",
metadata.len(),
desired_file.size
);
let std_file_handle =
StdFileHandle::new(desired_file.id, file, metadata.len(), desired_file.size).await?;
v.push(std_file_handle)

View file

@ -85,6 +85,7 @@ impl FileHandle {
}
async fn to_std(self, chunk_header: &ChunkHeader) -> Result<StdFileHandle> {
println!("{:?} requested start?", chunk_header.start);
StdFileHandle::new(self.id, self.file, chunk_header.start, self.md.len()).await
}