예제 #1
0
        public void CheckAndPerformBackupRevert(Message <D> LatestEditsReceived)
        {
            if (LatestEditsReceived == null || LatestEditsReceived.Diffs.Where(v => v.Version >= Shadow.PeerVersion).Count() == 0)
            {
                return;
            }

            // 4 : Check whether our shadow versions are out of sync and we need to rebase to the version in BackupShadow
            if (Shadow.PeerVersion != LatestEditsReceived.Diffs.Select(d => d.Version).Min() || Shadow.Version != LatestEditsReceived.SenderPeerVersion) // Only do this if the message has edits in, otherwise this could be a missed message that can still be processed as is in historic order without clearing and rediffing
            {
                if (BackupShadow.PeerVersion == Shadow.PeerVersion && BackupShadow.Version == Shadow.Version)
                {
                    throw new Exception("Attempting to revert to backup, but already reverted; DiffSyncer is unrecoverable");
                }
                // Something is wrong e.g. missing packet. Return shadow to backup shadow which should be synced on both sides, and we can issue a new sync against that.
                Shadow             = new ShadowState <PATCHER, D, S>(BackupShadow.StateObject);
                Shadow.PeerVersion = BackupShadow.PeerVersion;
                Shadow.Version     = BackupShadow.Version;

                Live.Version = Shadow.Version;
                UnconfirmedEdits.Diffs.Clear();
                //Live.Version = Shadow.Version;
            }
        }
예제 #2
0
 /// <summary>
 /// Initialize with a shadow that isn't the same as live. Useful when starting a session where
 /// we may not be able to tell the peer what the initial state is, but the server can initialize
 /// with a default state.
 /// </summary>
 /// <param name="o"></param>
 /// <param name="shadow"></param>
 public void Initialize(PATCHER live, PATCHER shadow, PATCHER backupshadow)
 {
     Live         = new LiveState <PATCHER, D, S>(live);
     Shadow       = new ShadowState <PATCHER, D, S>(shadow);
     BackupShadow = new BackupShadowState <PATCHER, D, S>(backupshadow);
 }