예제 #1
0
        protected void SendConnectChallengeResponse(IPEndPoint addr, Nonce clientNonce, bool wantsKeyExchange, bool wantsCertificate)
        {
            var stream = new PacketStream();

            stream.Write((byte)PacketType.ConnectChallengeResponse);

            clientNonce.Write(stream);

            var identityToken = ComputeClientIdentityToken(addr, clientNonce);

            stream.Write(identityToken);

            PuzzleManager.CurrentNonce.Write(stream);
            stream.Write(PuzzleManager.CurrentDifficulty);

            // ReSharper disable PossibleNullReferenceException
            if (stream.WriteFlag(RequiresKeyExchange || (wantsKeyExchange && PrivateKey != null)))
            {
                stream.Write(stream.WriteFlag(wantsCertificate && Certificate != null) ? Certificate : PrivateKey.GetPublicKey());
            }
            // ReSharper restore PossibleNullReferenceException

            stream.SendTo(Socket, addr);
        }