Пример #1
0
        public override void Handle(ApplicationProtocolRequest request)
        {
            EnsureMagic();

            ApplicationProtocolResponse response;

            if (!request.ProtocolName().Equals(_supportedApplicationProtocol.identifier().canonicalName()))
            {
                response = ApplicationProtocolResponse.NoProtocol;
                _channel.writeAndFlush(response);
                Decline(string.Format("Requested protocol {0} not supported", request.ProtocolName()));
            }
            else
            {
                Optional <Protocol_ApplicationProtocol> selected = _applicationProtocolRepository.select(request.ProtocolName(), SupportedVersionsFor(request));

                if (selected.Present)
                {
                    Protocol_ApplicationProtocol selectedProtocol = selected.get();
                    _protocolStackBuilder.application(selectedProtocol);
                    response = new ApplicationProtocolResponse(SUCCESS, selectedProtocol.category(), selectedProtocol.implementation());
                    _channel.writeAndFlush(response);
                }
                else
                {
                    response = ApplicationProtocolResponse.NoProtocol;
                    _channel.writeAndFlush(response);
                    Decline(string.Format("Do not support requested protocol {0} versions {1}", request.ProtocolName(), request.Versions()));
                }
            }
        }
Пример #2
0
 private void InitializeInstanceFields()
 {
     _supportedApplicationProtocol  = new ApplicationSupportedProtocols(_applicationProtocolIdentifier, emptyList());
     _applicationProtocolRepository = new ApplicationProtocolRepository(TestProtocols_TestApplicationProtocols.values(), _supportedApplicationProtocol);
     _modifierProtocolRepository    = new ModifierProtocolRepository(TestProtocols_TestModifierProtocols.values(), _supportedModifierProtocols);
     _expectedApplicationProtocol   = _applicationProtocolRepository.select(_applicationProtocolIdentifier.canonicalName(), _raftVersion).get();
 }
Пример #3
0
        public override void Handle(ApplicationProtocolResponse applicationProtocolResponse)
        {
            EnsureMagic();
            if (applicationProtocolResponse.StatusCode() != SUCCESS)
            {
                Decline("Unsuccessful application protocol response");
                return;
            }

            Optional <Protocol_ApplicationProtocol> protocol = _applicationProtocolRepository.select(applicationProtocolResponse.ProtocolName(), applicationProtocolResponse.Version());

            if (!protocol.Present)
            {
                ProtocolSelection <int, Protocol_ApplicationProtocol> knownApplicationProtocolVersions = _applicationProtocolRepository.getAll(_supportedApplicationProtocol.identifier(), _supportedApplicationProtocol.versions());
                Decline(string.Format("Mismatch of application protocols between client and server: Server protocol {0} version {1:D}: Client protocol {2} versions {3}", applicationProtocolResponse.ProtocolName(), applicationProtocolResponse.Version(), knownApplicationProtocolVersions.Identifier(), knownApplicationProtocolVersions.Versions()));
            }
            else
            {
                _negotiatedApplicationProtocol = protocol.get();

                SendSwitchOverRequestIfReady();
            }
        }