/// <summary> /// Handles incoming <see cref="ExtendSessionResponsePacket"/>s. /// </summary> /// <param name="connectionId">Original connection ID</param> /// <param name="packet">Incoming <see cref="ExtendSessionResponsePacket"/></param> private void extendSessionResponsePacketHandler(string connectionId, ExtendSessionResponsePacket packet) { if (packet.Success) { // Reset the session extension timer to halfway between now and the expiry sessionExtendTimer.Stop(); sessionExtendTimer.Interval = (double)packet.ExpiresIn / 2; sessionExtendTimer.Start(); } }
/// <summary> /// Handles incoming <see cref="ExtendSessionResponsePacket"/>s. /// </summary> /// <param name="connectionId">Original connection ID</param> /// <param name="packet">Incoming <see cref="ExtendSessionResponsePacket"/></param> private void extendSessionResponsePacketHandler(string connectionId, ExtendSessionResponsePacket packet) { if (packet.Success) { // Update the expiry with the newly-extended one sessionExpiry = DateTime.UtcNow + TimeSpan.FromMilliseconds(packet.ExpiresIn); // Reset the session extension timer to halfway between now and the expiry sessionExtendTimer.Stop(); sessionExtendTimer.Interval = (double)packet.ExpiresIn / 2; sessionExtendTimer.Start(); } }
/// <summary> /// Sends a failed <see cref="ExtendSessionResponsePacket"/> to a connection. /// </summary> /// <param name="connectionId">Recipient's connection ID</param> private void sendFailedExtendSessionResponsePacket(string connectionId) { RaiseLogEntry(new LogEventArgs(string.Format("Sending failed ExtendSessionResponsePacket to connection {0}", connectionId.Highlight(HighlightType.ConnectionID)), LogLevel.DEBUG)); // Create and pack a response ExtendSessionResponsePacket packet = new ExtendSessionResponsePacket { Success = false }; Any packedPacket = ProtobufPacketHelper.Pack(packet); // Send it on its way if (!netServer.TrySend(connectionId, MODULE_NAME, packedPacket.ToByteArray())) { RaiseLogEntry(new LogEventArgs("Failed to send ExtendSessionResponsePacket to connection " + connectionId.Highlight(HighlightType.ConnectionID), LogLevel.ERROR)); } }
/// <summary> /// Sends a successful <see cref="ExtendSessionResponsePacket"/> to a connection with the given expiry. /// </summary> /// <param name="connectionId">Recipient's connection ID</param> /// <param name="expiry">New session expiry</param> private void sendSuccessfulExtendSessionResponsePacket(string connectionId, DateTime expiry) { RaiseLogEntry(new LogEventArgs(string.Format("Sending successful ExtendSessionResponsePacket to connection {0}", connectionId.Highlight(HighlightType.ConnectionID)), LogLevel.DEBUG)); // Create and pack a response ExtendSessionResponsePacket packet = new ExtendSessionResponsePacket { Success = true, ExpiresIn = (int)(expiry - DateTime.UtcNow).TotalMilliseconds }; Any packedPacket = ProtobufPacketHelper.Pack(packet); // Send it on its way if (!netServer.TrySend(connectionId, MODULE_NAME, packedPacket.ToByteArray())) { RaiseLogEntry(new LogEventArgs("Failed to send ExtendSessionResponsePacket to connection " + connectionId.Highlight(HighlightType.ConnectionID), LogLevel.ERROR)); } }