mirror of
https://github.com/CompeyDev/ruck.git
synced 2025-01-08 11:49:09 +00:00
Still broken
This commit is contained in:
parent
28a97f675e
commit
02f5fca565
2 changed files with 12 additions and 7 deletions
|
@ -43,9 +43,7 @@ pub async fn receive(password: &String) -> Result<()> {
|
||||||
let (socket, key) = handshake.negotiate(socket, s1).await?;
|
let (socket, key) = handshake.negotiate(socket, s1).await?;
|
||||||
let mut connection = Connection::new(socket, key);
|
let mut connection = Connection::new(socket, key);
|
||||||
// Wait for offered files, respond with desired files
|
// Wait for offered files, respond with desired files
|
||||||
let desired_files = request_specific_files(&mut connection).await?;
|
let std_file_handles = request_specific_files(&mut connection).await?;
|
||||||
// Create files
|
|
||||||
let std_file_handles = create_or_find_files(desired_files).await?;
|
|
||||||
// Download them
|
// Download them
|
||||||
connection.download_files(std_file_handles).await?;
|
connection.download_files(std_file_handles).await?;
|
||||||
return Ok(());
|
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
|
// Wait for offer message
|
||||||
let offer_message = conn.await_msg().await?;
|
let offer_message = conn.await_msg().await?;
|
||||||
let offered_files: Vec<FileOffer> = match offer_message {
|
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
|
// Prompt user for confirmation of files
|
||||||
let desired_files = prompt_user_for_file_confirmation(offered_files).await;
|
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 {
|
let file_request_msg = Message::FileRequest(FileRequestPayload {
|
||||||
chunks: desired_files
|
chunks: std_file_handles
|
||||||
.iter()
|
.iter()
|
||||||
.map(|file| ChunkHeader {
|
.map(|file| ChunkHeader {
|
||||||
id: file.id,
|
id: file.id,
|
||||||
start: 0,
|
start: file.start,
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
});
|
});
|
||||||
conn.send_msg(file_request_msg).await?;
|
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>> {
|
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?,
|
Err(_) => File::create(filename).await?,
|
||||||
};
|
};
|
||||||
let metadata = file.metadata().await?;
|
let metadata = file.metadata().await?;
|
||||||
|
println!(
|
||||||
|
"Current len: {:?}, Full Size: {:?}",
|
||||||
|
metadata.len(),
|
||||||
|
desired_file.size
|
||||||
|
);
|
||||||
let std_file_handle =
|
let std_file_handle =
|
||||||
StdFileHandle::new(desired_file.id, file, metadata.len(), desired_file.size).await?;
|
StdFileHandle::new(desired_file.id, file, metadata.len(), desired_file.size).await?;
|
||||||
v.push(std_file_handle)
|
v.push(std_file_handle)
|
||||||
|
|
|
@ -85,6 +85,7 @@ impl FileHandle {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn to_std(self, chunk_header: &ChunkHeader) -> Result<StdFileHandle> {
|
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
|
StdFileHandle::new(self.id, self.file, chunk_header.start, self.md.len()).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue