From 7f0398339dd08f78117e15941e4331ffdcfef1c9 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Thu, 3 Sep 2020 22:21:56 +0100 Subject: [PATCH] try map error back to update --- src/updates.rs | 45 +++++++++++++++++++++++++++++++-------------- templates/script.ts | 2 ++ 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/updates.rs b/src/updates.rs index 71544b6a..61a2edcf 100644 --- a/src/updates.rs +++ b/src/updates.rs @@ -85,7 +85,7 @@ enum TransmitUpdateEntry<'u> { }, Piece { piece : VisiblePieceId, - op : &'u PieceUpdateOp, + op : PieceUpdateOp<&'u PreparedPieceState>, }, SetTableSize(Pos), Log (&'u LogEntry), @@ -164,6 +164,16 @@ impl PieceUpdateOp { SetZLevel(zl) => SetZLevel(zl), }) } + pub fn map_ref_new_state(&self) -> PieceUpdateOp<&NS> { + use PieceUpdateOp::*; + match self { + Delete() => Delete(), + Insert(ns) => Insert(ns), + Modify(ns) => Modify(ns), + Move(pos) => Move(*pos), + SetZLevel(zl) => SetZLevel(*zl), + } + } pub fn map_new_state NS2>(self, f:F) -> PieceUpdateOp { #[derive(Error,Debug)] @@ -336,29 +346,36 @@ impl<'r> Drop for PrepareUpdatesBuffer<'r> { impl PreparedUpdate { pub fn for_transmit(&self, dest : ClientId) -> TransmitUpdate { + type ESVU = ErrorSignaledViaUpdate; + type PUE = PreparedUpdateEntry; + type TUE<'u> = TransmitUpdateEntry<'u>; let mut ents = vec![]; for u in &self.us { - type Prep = PreparedUpdateEntry; eprintln!("FOR_TRANSMIT TO={:?} {:?}", dest, &u); let ue = match u { - &Prep::Piece - { piece, client, sameclient_cseq : cseq, ref op } + &PUE::Piece { piece, client, sameclient_cseq : cseq, ref op } if client == dest => { let zg = op.new_z_generation(); - TransmitUpdateEntry::Recorded { piece, cseq, zg } + TUE::Recorded { piece, cseq, zg } }, - &PreparedUpdateEntry::Piece { piece, ref op, .. } => { - TransmitUpdateEntry::Piece { piece, op } + &PUE::Piece { piece, ref op, .. } => { + TUE::Piece { piece, op: op.map_ref_new_state() } }, - PreparedUpdateEntry::Log(logent) => { - TransmitUpdateEntry::Log(&logent) + PUE::Log(logent) => { + TUE::Log(&logent) }, - &PreparedUpdateEntry::SetTableSize(size) => { - TransmitUpdateEntry::SetTableSize(size) + &PUE::SetTableSize(size) => { + TUE::SetTableSize(size) }, - PreparedUpdateEntry::Error(c, e) => { - if let Some(c) = c { if *c != dest { continue } } - TransmitUpdateEntry::Error(e) + PUE::Error(c, e) => { + if *c == None || *c == Some(dest) { + TUE::Error(e) + } else if let &ESVU::PieceOpError { piece, ref state, .. } = e { + let op = PieceUpdateOp::Modify(state); + TUE::Piece { piece, op } + } else { + continue + } } }; ents.push(ue); diff --git a/templates/script.ts b/templates/script.ts index 5ea30b8e..bd985797 100644 --- a/templates/script.ts +++ b/templates/script.ts @@ -445,6 +445,8 @@ pieceops.Modify = function piece_error_handlers.PosOffTable = function() { return true ; } +piece_error_handlers.Conflict = function() +{ return true ; } function piece_modify(piece: PieceId, p: PieceInfo, info: PieceStateMessage, conflict_expected: boolean) { -- 2.30.2