private void FinalizeHandshake(HandshakeFrame handshakeFrame) { _extensionService.ServerConfirm(handshakeFrame); _connection.SetHandshakeCompleted(); _state = ServerState.Ready; var extensionId = _extensionService.FindFirstExtensionId("batch-ack", "ack"); if (extensionId != 0) { var name = _extensionService.FindFirstExtensionNamed("batch-ack", "ack"); var extProperties = handshakeFrame.GetExtension(name); var ackExtension = (IAckExtension)_extensionService.Get(extensionId); _ackReceiver = ackExtension.CreateAckReceiver(_connection, extensionId, DeliverMessage, extProperties); _ackSender = ackExtension.CreateAckSender(_connection, extensionId, extProperties); } extensionId = _extensionService.FindFirstExtensionId("json", "protobuf", "xml"); if (extensionId != 0) { var payloadExtension = (IPayloadExtension)_extensionService.Get(extensionId); _payloadSerializer = payloadExtension.CreatePayloadSerializer(); } if (HandshakeCompleted != null) { HandshakeCompleted(); } }
public void Reset() { //these will be re-negotiated _ackReceiver.Dispose(); _ackReceiver = null; _ackSender.Dispose(); _ackSender = null; _connection.Reset(); _extensionService.Reset(); _sequenceCounter = 0; _state = ServerState.WaitingOnInitialHandshake; }
private void OnServerHandshakeFrame(object source, HandshakeFrameReceivedEventArgs e) { if (_state != ClientState.ServerToClientHandshake) { throw new Exception("Server handshake should not be received during " + _state); } var frame = _extensionService.ClientConfirmExtensions(e.Handshake, _connection.Identity); _state = ClientState.Ready; _connection.SetHandshakeCompleted(); _connection.Send(frame); //TODO: This is a mess. Create a better way // to identify and activate extensions. // maybe by defining extension behavior like IInboundMessageProcessor. var id = _extensionService.FindFirstExtensionId("json", "xml", "protobuf"); if (id > 0) { _payloadSerializer = (((IPayloadExtension)_extensionService.Get(id))).CreatePayloadSerializer(); } id = _extensionService.FindFirstExtensionId("dotnet"); if (id > 0) { _dotNetExtension = (DotNetTypeExtension)_extensionService.Get(id); } _ackExtensionId = _extensionService.FindFirstExtensionId("batch-ack", "ack"); if (_ackExtensionId != 0) { var name = _extensionService.FindFirstExtensionNamed("batch-ack", "ack"); var extProperties = frame.GetExtension(name); var ackExtension = (IAckExtension)_extensionService.Get(_ackExtensionId); _ackReceiver = ackExtension.CreateAckReceiver(_connection, _ackExtensionId, DeliverMessage, extProperties); _ackSender = ackExtension.CreateAckSender(_connection, _ackExtensionId, extProperties); } _authenticationEvent.Set(); }
private void OnServerHandshakeFrame(object source, HandshakeFrameReceivedEventArgs e) { if (_state != ClientState.ServerToClientHandshake) { throw new Exception("Server handshake should not be received during " + _state); } var frame = _extensionService.ClientConfirmExtensions(e.Handshake, _connection.Identity); _state = ClientState.Ready; _connection.SetHandshakeCompleted(); _connection.Send(frame); var name = _extensionService.FindFirstExtensionNamed("json", "xml", "protobuf"); switch (name) { case "json": _payloadSerializer = new FastJsonSerializer(); break; } _ackExtensionId = _extensionService.FindFirstExtensionId("batch-ack", "ack"); if (_ackExtensionId != 0) { name = _extensionService.FindFirstExtensionNamed("batch-ack", "ack"); var extProperties = frame.GetExtension(name); var ackExtension = (IAckExtension)_extensionService.Get(_ackExtensionId); _ackReceiver = ackExtension.CreateAckReceiver(_connection, _ackExtensionId, DeliverMessage, extProperties); _ackSender = ackExtension.CreateAckSender(_connection, _ackExtensionId, extProperties); } _authenticationEvent.Set(); }
private void OnServerHandshakeFrame(object source, HandshakeFrameReceivedEventArgs e) { if (_state != ClientState.ServerToClientHandshake) throw new Exception("Server handshake should not be received during " + _state); var frame = _extensionService.ClientConfirmExtensions(e.Handshake, _connection.Identity); _state = ClientState.Ready; _connection.SetHandshakeCompleted(); _connection.Send(frame); //TODO: This is a mess. Create a better way // to identify and activate extensions. // maybe by defining extension behavior like IInboundMessageProcessor. var id = _extensionService.FindFirstExtensionId("json", "xml", "protobuf"); if (id > 0) _payloadSerializer = (((IPayloadExtension)_extensionService.Get(id))).CreatePayloadSerializer(); id = _extensionService.FindFirstExtensionId("dotnet"); if (id > 0) _dotNetExtension = (DotNetTypeExtension) _extensionService.Get(id); _ackExtensionId = _extensionService.FindFirstExtensionId("batch-ack", "ack"); if (_ackExtensionId != 0) { var name = _extensionService.FindFirstExtensionNamed("batch-ack", "ack"); var extProperties = frame.GetExtension(name); var ackExtension = (IAckExtension) _extensionService.Get(_ackExtensionId); _ackReceiver = ackExtension.CreateAckReceiver(_connection, _ackExtensionId, DeliverMessage, extProperties); _ackSender = ackExtension.CreateAckSender(_connection, _ackExtensionId, extProperties); } _authenticationEvent.Set(); }
private void FinalizeHandshake(HandshakeFrame handshakeFrame) { _extensionService.ServerConfirm(handshakeFrame); _connection.SetHandshakeCompleted(); _state = ServerState.Ready; var extensionId = _extensionService.FindFirstExtensionId("batch-ack", "ack"); if (extensionId != 0) { var name = _extensionService.FindFirstExtensionNamed("batch-ack", "ack"); var extProperties = handshakeFrame.GetExtension(name); var ackExtension = (IAckExtension) _extensionService.Get(extensionId); _ackReceiver = ackExtension.CreateAckReceiver(_connection, extensionId, DeliverMessage, extProperties); _ackSender = ackExtension.CreateAckSender(_connection, extensionId, extProperties); } extensionId = _extensionService.FindFirstExtensionId("json", "protobuf", "xml"); if (extensionId != 0) { var payloadExtension = (IPayloadExtension) _extensionService.Get(extensionId); _payloadSerializer = payloadExtension.CreatePayloadSerializer(); } if (HandshakeCompleted != null) HandshakeCompleted(); }