Example #1
0
        /// <summary>
        /// Initiates the handshake process between the current endpoint and the specified endpoint.
        /// </summary>
        /// <param name="information">The connection information for the endpoint.</param>
        private void InitiateHandshakeWith(EndpointInformation information)
        {
            var template       = information.ProtocolInformation.MessageAddress.ToChannelTemplate();
            var connectionInfo = m_Layer.LocalConnectionFor(information.ProtocolInformation.Version, template);

            if (connectionInfo != null)
            {
                lock (m_Lock)
                {
                    Debug.Assert(m_EndpointApprovalState.ContainsKey(information.Id), "The endpoint tick list is not stored.");
                    var tickList = m_EndpointApprovalState[information.Id];

                    if (!tickList.HaveSendConnect && !m_PotentialEndpoints.CanCommunicateWithEndpoint(information.Id))
                    {
                        tickList.HaveSendConnect = true;

                        var message = new EndpointConnectMessage(
                            m_Layer.Id,
                            new DiscoveryInformation(m_DiscoveryChannel.EntryChannel(template)),
                            new ProtocolInformation(
                                information.ProtocolInformation.Version,
                                connectionInfo.Item2,
                                connectionInfo.Item3),
                            m_Descriptions.ToStorage());
                        var task = m_Layer.SendMessageToUnregisteredEndpointAndWaitForResponse(
                            information,
                            message,
                            CommunicationConstants.DefaultMaximuNumberOfRetriesForMessageSending,
                            m_SendTimeout);
                        task.ContinueWith(HandleResponseToConnectMessage, TaskContinuationOptions.ExecuteSynchronously);
                    }
                }
            }
        }