Пример #1
0
        /// <summary>
        /// Continues the handshake process between the current endpoint and the specified endpoint.
        /// </summary>
        /// <param name="connection">The connection information for endpoint that started the handshake.</param>
        /// <param name="information">The handshake information for the endpoint.</param>
        /// <param name="messageId">The ID of the message that carried the handshake information.</param>
        public void ContinueHandshakeWith(
            EndpointInformation connection,
            ProtocolDescription information,
            MessageId messageId)
        {
            bool shouldSendConnect;

            lock (m_Lock)
            {
                // Potentially a new endpoint so store it
                StorePotentialEndpoint(connection);
                if (!m_EndpointApprovalState.ContainsKey(connection.Id))
                {
                    return;
                }

                var tickList = m_EndpointApprovalState[connection.Id];
                tickList.HaveReceivedConnect = true;

                if (!AllowConnection(connection.ProtocolInformation.Version, information))
                {
                    var failMsg = new FailureMessage(m_Layer.Id, messageId);
                    m_Layer.SendMessageToUnregisteredEndpoint(
                        connection,
                        failMsg,
                        CommunicationConstants.DefaultMaximuNumberOfRetriesForMessageSending);

                    RemoveEndpoint(connection.Id);
                    return;
                }

                var successMessage = new SuccessMessage(m_Layer.Id, messageId);
                m_Layer.SendMessageToUnregisteredEndpoint(
                    connection,
                    successMessage,
                    CommunicationConstants.DefaultMaximuNumberOfRetriesForMessageSending);
                tickList.HaveSendConnectResponse = true;

                m_PotentialEndpoints.TryStartApproval(connection.Id, information);
                if (tickList.IsComplete())
                {
                    ApproveConnection(connection.Id);
                }

                shouldSendConnect = !tickList.HaveSendConnect;
            }

            if (shouldSendConnect)
            {
                InitiateHandshakeWith(connection);
            }
        }