/// <summary> /// Interpret a server's handshake, either requesting a package /// of strings or completing the handshake. /// /// Uncached flow: <code> /// Client | Server /// | <-------------- Hash | <- you are here on client /// | Need Strings ------> | /// | <----------- Strings | /// | Dont Need Strings -> | /// </code> /// /// Cached flow: <code> /// Client | Server /// | <-------------- Hash | <- you are here on client /// | Dont Need Strings -> | /// </code> /// /// Verification failure flow: <code> /// Client | Server /// | <-------------- Hash | <- you are here on client /// | Need Strings ------> | /// | <----------- Strings | /// + Hash Failed | /// | Need Strings ------> | /// | <----------- Strings | /// | Dont Need Strings -> | /// </code> /// /// NOTE: Verification failure flow is currently not implemented. /// </summary> /// <exception cref="InvalidOperationException">Mapped strings are locked.</exception> /// <seealso cref="NetworkInitialize"/> private void HandleServerHandshake(MsgMapStrServerHandshake msgMapStr) { DebugTools.Assert(_net.IsClient); _serverHash = msgMapStr.Hash; var hashStr = ConvertToBase64Url(msgMapStr.Hash !); LogSzr.Debug($"Received server handshake with hash {hashStr}."); var fileName = CacheForHash(hashStr); if (!File.Exists(fileName)) { LogSzr.Debug($"No string cache for {hashStr}."); var handshake = _net.CreateNetMessage <MsgMapStrClientHandshake>(); LogSzr.Debug("Asking server to send mapped strings."); handshake.NeedsStrings = true; msgMapStr.MsgChannel.SendMessage(handshake); } else { LogSzr.Debug($"We had a cached string map that matches {hashStr}."); using var file = File.OpenRead(fileName); var added = _dict.LoadFromPackage(file, out _); _stringMapHash = msgMapStr.Hash !; LogSzr.Debug($"Read {added} strings from cache {hashStr}."); LogSzr.Debug($"Locked in at {_dict.StringCount} mapped strings."); // ok we're good now var channel = msgMapStr.MsgChannel; OnClientCompleteHandshake(_net, channel); } }
private void HandleServerHandshake(MsgMapStrServerHandshake message) { ClientHandshakeComplete?.Invoke(); }