Browse Source

remove comments and debug lines

unitxt
andy 3 years ago
parent
commit
54a526f8c9
  1. 18
      src/patch/patch.rs

18
src/patch/patch.rs

@ -187,31 +187,21 @@ impl ServerState for PatchServerState {
},
RecvPatchPacket::FileInfoReply(pkt) => {
self.client_file_info.get_mut(&id).ok_or(PatchError::NoSuchClient(id))?.push(pkt.clone()); // it should be impossible to error here under normal conditions?
// self.patch_file_info.push(pkt.clone());
// println!("PatchServerState.patch_file_info: {:?}", self.patch_file_info);
Box::new(None.into_iter().map(move |pkt| (id, pkt)))
},
RecvPatchPacket::FileInfoListEnd(_pkt) => {
// let need_update = self.patch_file_info.iter()
// .filter(|file_info| does_file_need_updating(file_info, &self.patch_file_lookup))
// .collect::<Vec<_>>();
println!("patch server hashmap: {:?}", self.patch_file_lookup);
let need_update = self.client_file_info.get(&id)
.ok_or(PatchError::NoSuchClient(id))?
.iter()
.filter(|client_file_info| does_file_need_updating(client_file_info, &self.patch_file_lookup))
.collect::<Vec<_>>(); // collecting list of `client_file_info`s. need to map these to the patch_files and collect those
println!("ClientId({}) needs these files to be updated: {:?}", id, need_update);
// we have the file ids that need to be updated
.collect::<Vec<_>>();
let total_size = need_update.iter()
.filter_map(|client_file| self.patch_file_lookup.get(&client_file.id)) // TODO: dont unwrap?
.fold(0, |a, file_info| a + file_info.size);
let total_files = need_update.len() as u32;
println!("client {} needs {} bytes of updates across {} files", id, total_size, total_files);
let p = vec![SendPatchPacket::FilesToPatchMetadata(FilesToPatchMetadata::new(total_size, total_files)),
SendPatchPacket::PatchStartList(PatchStartList {})
];
println!("p: {:?}", p);
Box::new(p.into_iter().chain(SendFileIterator::new(self, need_update)).map(move |pkt| (id, pkt)))
}
})
@ -297,7 +287,6 @@ fn get_checksum_and_size(path: &Path) -> Result<(u32, u32), PatchError> {
fn does_file_need_updating(client_file_info: &FileInfoReply, patch_file_lookup: &HashMap<u32, PatchFile>) -> bool {
let patch_file = patch_file_lookup.get(&client_file_info.id).unwrap();
println!("checking if client_file {:?} and patch_file {:?} need to be updated", client_file_info, patch_file);
patch_file.checksum != client_file_info.checksum || patch_file.size != client_file_info.size
}
@ -312,11 +301,6 @@ struct SendFileIterator {
impl SendFileIterator {
fn new(state: &PatchServerState, client_file_info: Vec<&FileInfoReply>) -> SendFileIterator {
// let file_ids_to_update = state.patch_file_info.iter()
// .filter(|file_info| does_file_need_updating(file_info, &state.patch_file_lookup))
// .map(|k| k.id)
// .collect::<HashSet<_>>();
let file_ids_to_update = client_file_info.iter()
.map(|k| k.id)
.collect::<HashSet<_>>();

Loading…
Cancel
Save