public void TryRemoveWithApprovedEndpoint() { var storage = new EndpointInformationStorage(); var endpoint = new EndpointId("a"); var connection = new EndpointInformation( new EndpointId("a"), new DiscoveryInformation(new Uri("http://localhost/discovery/invalid")), new ProtocolInformation( new Version(), new Uri("http://localhost/protocol/invalid"))); Assert.IsTrue(storage.TryAdd(endpoint, connection)); Assert.IsFalse(storage.CanCommunicateWithEndpoint(endpoint)); Assert.IsTrue(storage.HasBeenContacted(endpoint)); Assert.IsFalse(storage.IsWaitingForApproval(endpoint)); var description = new ProtocolDescription(new List <CommunicationSubject>()); Assert.IsTrue(storage.TryStartApproval(endpoint, description)); Assert.IsTrue(storage.TryCompleteApproval(endpoint)); Assert.IsTrue(storage.CanCommunicateWithEndpoint(endpoint)); Assert.IsFalse(storage.IsWaitingForApproval(endpoint)); Assert.IsTrue(storage.TryRemoveEndpoint(endpoint)); Assert.IsFalse(storage.CanCommunicateWithEndpoint(endpoint)); Assert.IsFalse(storage.IsWaitingForApproval(endpoint)); Assert.IsFalse(storage.HasBeenContacted(endpoint)); }
public bool TryStartApproval(EndpointId endpoint, ProtocolDescription description) { if ((endpoint != null) && (description != null)) { lock (m_Lock) { if (m_ContactedEndpoints.ContainsKey(endpoint) && !m_EndpointsWaitingForApproval.ContainsKey(endpoint) && !m_ApprovedEndpoints.ContainsKey(endpoint)) { var info = m_ContactedEndpoints[endpoint]; m_ContactedEndpoints.Remove(endpoint); m_EndpointsWaitingForApproval.Add( endpoint, new Tuple <EndpointInformation, ProtocolDescription>( info, description)); return(true); } } } return(false); }
public void TryUpdateWithApprovalUnderWay() { var endpoint = new EndpointId("a"); var connection = new EndpointInformation( new EndpointId("a"), new DiscoveryInformation(new Uri("http://localhost/discovery/invalid")), new ProtocolInformation( new Version(), new Uri("http://localhost/protocol/invalid"))); var description = new ProtocolDescription(new List <CommunicationSubject>()); var storage = new EndpointInformationStorage(); Assert.IsTrue(storage.TryAdd(endpoint, connection)); Assert.IsTrue(storage.TryStartApproval(endpoint, description)); var newConnection = new EndpointInformation( endpoint, new DiscoveryInformation(new Uri("http://other/discovery/invalid")), new ProtocolInformation( new Version(), new Uri("http://other/protocol/invalid"))); Assert.IsTrue(storage.TryUpdate(newConnection)); EndpointInformation storedConnection; storage.TryGetConnectionFor(endpoint, out storedConnection); Assert.AreSame(newConnection, storedConnection); }
public void TryApprove() { var endpoint = new EndpointId("a"); var connection = new EndpointInformation( new EndpointId("a"), new DiscoveryInformation(new Uri("http://localhost/discovery/invalid")), new ProtocolInformation( new Version(), new Uri("http://localhost/protocol/invalid"))); var description = new ProtocolDescription(new List <CommunicationSubject>()); var storage = new EndpointInformationStorage(); var wasApproved = false; storage.OnEndpointConnected += (s, e) => { wasApproved = true; Assert.AreSame(connection.Id, e.Endpoint); }; Assert.IsTrue(storage.TryAdd(endpoint, connection)); Assert.IsFalse(storage.CanCommunicateWithEndpoint(endpoint)); Assert.IsTrue(storage.HasBeenContacted(endpoint)); Assert.IsFalse(storage.IsWaitingForApproval(endpoint)); Assert.IsTrue(storage.TryStartApproval(endpoint, description)); Assert.IsTrue(storage.TryCompleteApproval(endpoint)); Assert.IsTrue(storage.CanCommunicateWithEndpoint(endpoint)); Assert.IsFalse(storage.HasBeenContacted(endpoint)); Assert.IsFalse(storage.IsWaitingForApproval(endpoint)); Assert.IsTrue(wasApproved); }
public void TryStartApproveWithNullEndpoint() { var storage = new EndpointInformationStorage(); var description = new ProtocolDescription(new List <CommunicationSubject>()); Assert.IsFalse(storage.TryStartApproval(null, description)); }
private bool AllowConnection(Version requiredProtocolVersion, ProtocolDescription information) { if (!m_ConnectionApprovers.ContainsKey(requiredProtocolVersion)) { return(false); } var approver = m_ConnectionApprovers[requiredProtocolVersion]; return(approver.IsEndpointAllowedToConnect(information)); }
/// <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); } }