private static byte[] ConstructHandshakePacketContent(HandshakeInfo handshakeInfo) { using (var builder = new PacketBuilder()) { builder.WriteInt16(handshakeInfo.Version); builder.WriteLengthString(handshakeInfo.Subversion); builder.WriteBytes(handshakeInfo.ServerIv); builder.WriteBytes(handshakeInfo.ClientIv); // Locale ID (used for localizations and test servers) builder.WriteByte(handshakeInfo.LocaleId); return builder.ToByteArray(); } }
/// <inheritdoc /> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="endpointCrypto"/> or <paramref name="handshakeInfo"/> are <see langword="null"/>. /// </exception> public void Start(EndpointCrypto endpointCrypto, HandshakeInfo handshakeInfo) { Guard.NotNull(() => endpointCrypto, endpointCrypto); Guard.NotNull(() => handshakeInfo, handshakeInfo); this.ThrowIfNoPacketReceivedSubscriber(); this.Crypto = endpointCrypto; byte[] handshake = ConstructHandshakePacket(handshakeInfo); this.BaseSession.Start(); this.BaseSession.Write(handshake); }
private static byte[] ConstructHandshakePacket(HandshakeInfo handshakeInfo) { var content = ConstructHandshakePacketContent(handshakeInfo); using (var builder = new PacketBuilder()) { if (handshakeInfo.Header.HasValue) { builder.WriteInt16(handshakeInfo.Header.Value); } else { builder.WriteInt16((ushort)content.Length); } builder.WriteBytes(content); return builder.ToByteArray(); } }