From: Ian Jackson Date: Wed, 30 Sep 2020 22:14:40 +0000 (+0100) Subject: change type of IsResponseToClientOp X-Git-Tag: otter-0.2.0~814 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=f4db3a70897f53f11a6f9f099c499cb54e4acd22;p=otter.git change type of IsResponseToClientOp Signed-off-by: Ian Jackson --- diff --git a/src/api.rs b/src/api.rs index 41b716e3..7ef93980 100644 --- a/src/api.rs +++ b/src/api.rs @@ -141,7 +141,7 @@ fn api_piece_op(form : Json>) }, Ok((update, logents)) => { let mut buf = PrepareUpdatesBuffer::new(g, - IsResponseToClientOp::Predictable((client, form.cseq)), + Some((WhatResponseToClientOp::Predictable, client, form.cseq)), Some(1 + logents.len())); buf.piece_update(piece, update, &lens); diff --git a/src/cmdlistener.rs b/src/cmdlistener.rs index bd9f391c..95d93170 100644 --- a/src/cmdlistener.rs +++ b/src/cmdlistener.rs @@ -370,8 +370,7 @@ impl UpdateHandler { }, Online => { let estimate = updates.pcs.len() + updates.log.len(); - let irc = IsResponseToClientOp::No; - let mut buf = PrepareUpdatesBuffer::new(g, irc, Some(estimate)); + let mut buf = PrepareUpdatesBuffer::new(g, None, Some(estimate)); for (upiece, uuop) in updates.pcs { let lens = TransparentLens { }; buf.piece_update(upiece, uuop, &lens); @@ -387,8 +386,7 @@ impl UpdateHandler { use UpdateHandler::*; match self { Bulk(bulk) => { - let irc = IsResponseToClientOp::No; - let mut buf = PrepareUpdatesBuffer::new(g, irc, None); + let mut buf = PrepareUpdatesBuffer::new(g, None, None); for (upiece, uuop) in bulk.pieces { let lens = TransparentLens { }; buf.piece_update(upiece, uuop, &lens); diff --git a/src/global.rs b/src/global.rs index 710efa3e..1389881c 100644 --- a/src/global.rs +++ b/src/global.rs @@ -448,8 +448,7 @@ impl InstanceGuard<'_> { let lens = TransparentLens { }; let estimate = updated_pieces.len() + 1; - let mut buf = PrepareUpdatesBuffer::new( - self, IsResponseToClientOp::No , Some(estimate)); + let mut buf = PrepareUpdatesBuffer::new(self, None , Some(estimate)); for &piece in &updated_pieces { buf.piece_update(piece, PieceUpdateOp::Modify(()), &lens); } diff --git a/src/updates.rs b/src/updates.rs index 77ba0912..72d792c8 100644 --- a/src/updates.rs +++ b/src/updates.rs @@ -42,7 +42,7 @@ pub struct PreparedUpdate { #[derive(Debug)] pub enum PreparedUpdateEntry { Piece { - by_client: IsResponseToClientOp<(ClientId, ClientSequence)>, + by_client: IsResponseToClientOp, piece : VisiblePieceId, op : PieceUpdateOp, }, @@ -239,28 +239,32 @@ impl PieceUpdateOp { pub struct PrepareUpdatesBuffer<'r> { g : &'r mut Instance, us : Vec, - by_client : IsResponseToClientOp<(ClientId, ClientSequence)>, + by_client : IsResponseToClientOp, gen : Option, } +/// In PROTOCOL.md terms, None is a Server update +type IsResponseToClientOp = Option<( + WhatResponseToClientOp, + ClientId, + ClientSequence, +)>; #[derive(Debug,Copy,Clone)] -pub enum IsResponseToClientOp { - /// In PROTOCOL.md terms, a Server update - No, +pub enum WhatResponseToClientOp { /// In PROTOCOL.md terms, a Client update - Predictable(T), + Predictable, /// In PROTOCOL.md terms, a Client update which also updates /// the visible piece image (which is just server-controlled). - UpdateSvg(T), + UpdateSvg, /// In PROTOCOL.md terms, a Client update which results in /// an immediate Server update. When the client knows this /// is going to happen it can help the user avoid conflicts. - Unpredictable(T), + Unpredictable, } impl<'r> PrepareUpdatesBuffer<'r> { pub fn new(g: &'r mut Instance, - by_client: IsResponseToClientOp<(ClientId, ClientSequence)>, + by_client: IsResponseToClientOp, estimate: Option) -> Self { let us = estimate.map_or(vec![], Vec::with_capacity); @@ -280,7 +284,7 @@ impl<'r> PrepareUpdatesBuffer<'r> { } fn new_for_error(ig: &'r mut Instance) -> Self { - Self::new(ig, IsResponseToClientOp::No, Some(1)) + Self::new(ig, None, Some(1)) } pub fn piece_report_error(ig: &mut Instance, error: PieceOpError, piece: PieceId, @@ -314,7 +318,7 @@ impl<'r> PrepareUpdatesBuffer<'r> { fn piece_update_fallible(&mut self, piece: PieceId, update: PieceUpdateOp<()>, lens: &dyn Lens) -> PreparedUpdateEntry { - type IRC = IsResponseToClientOp<(ClientId, ClientSequence)>; + type WRC = WhatResponseToClientOp; let gen = self.gen(); let gs = &mut self.g.gs; @@ -327,8 +331,8 @@ impl<'r> PrepareUpdatesBuffer<'r> { gs.max_z.update_max(pc.zlevel.z); if let Some(new_lastclient) = match self.by_client { - IRC::Predictable((tclient,_)) | - IRC::UpdateSvg((tclient,_)) + Some((WRC::Predictable,tclient,_)) | + Some((WRC::UpdateSvg, tclient,_)) => if tclient == pc.lastclient { None } else { Some(tclient) } _ => Some(Default::default()), } { @@ -412,19 +416,15 @@ impl<'r> Drop for PrepareUpdatesBuffer<'r> { // ---------- for traansmission ---------- -type IRC = IsResponseToClientOp<(ClientId, ClientSequence)>; +type WRC = WhatResponseToClientOp; impl PreparedUpdate { - fn is_client(by_client: &IsResponseToClientOp<(ClientId, ClientSequence)>, + fn is_client(by_client: &IsResponseToClientOp, ref_client: ClientId) -> Option { - use IsResponseToClientOp::*; - let &(c,cseq) = match by_client { - Predictable (x) => x, - UpdateSvg (x) => x, - Unpredictable(x) => x, - No => return None, - }; - if c == ref_client { Some(cseq) } else { None } + match by_client { + &Some((_,c,cseq)) if c == ref_client => Some(cseq), + _ => None, + } } pub fn for_transmit(&self, dest : ClientId) -> TransmitUpdate { @@ -443,16 +443,15 @@ impl PreparedUpdate { Piece, }; let ftg = if let Some(cseq) = Self::is_client(&by_client, dest) { - match by_client { - IRC::Predictable(_) => FTG::Recorded(cseq, None), - IRC::UpdateSvg(_) => FTG::Recorded(cseq, ns()), - IRC::Unpredictable(_) => if let Some(ns) = ns() { + match by_client.unwrap().0 { + WRC::Predictable => FTG::Recorded(cseq, None), + WRC::UpdateSvg => FTG::Recorded(cseq, ns()), + WRC::Unpredictable => if let Some(ns) = ns() { FTG::Exactly(TUE::RecordedUnpredictable { piece, cseq, ns }) } else { error!("internal error: for_transmit PreparedUpdateEntry::Piece with RecordedUnpredictable but PieceOp no NS"); FTG::Piece } - _ => unreachable!(), } } else { FTG::Piece