Example #1
0
            public void ShouldThrowExceptionIfVersionIsNotSupported(int version, string errorMessage)
            {
                var exception = Record.Exception(() => BoltProtocolFactory.ForVersion(version));

                exception.Should().BeOfType <NotSupportedException>();
                exception.Message.Should().StartWith(errorMessage);
            }
Example #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void start() throws Throwable
        public override void Start()
        {
            Log log     = _logService.getInternalLog(typeof(BoltServer));
            Log userLog = _logService.getUserLog(typeof(BoltServer));

            InternalLoggerFactory.DefaultFactory = new Netty4LoggerFactory(_logService.InternalLogProvider);

            Authentication authentication = CreateAuthentication();

            TransportThrottleGroup throttleGroup = new TransportThrottleGroup(_config, _clock);

            BoltSchedulerProvider   boltSchedulerProvider   = _life.add(new ExecutorBoltSchedulerProvider(_config, new CachedThreadPoolExecutorFactory(log), _jobScheduler, _logService));
            BoltConnectionFactory   boltConnectionFactory   = CreateConnectionFactory(_config, boltSchedulerProvider, throttleGroup, _logService, _clock);
            BoltStateMachineFactory boltStateMachineFactory = CreateBoltFactory(authentication, _clock);

            BoltProtocolFactory boltProtocolFactory = CreateBoltProtocolFactory(boltConnectionFactory, boltStateMachineFactory);

            if (_config.enabledBoltConnectors().Count > 0 && !_config.get(GraphDatabaseSettings.disconnected))
            {
                NettyServer server = new NettyServer(_jobScheduler.threadFactory(Group.BOLT_NETWORK_IO), CreateConnectors(boltProtocolFactory, throttleGroup, log), _connectorPortRegister, userLog);
                _life.add(server);
                log.Info("Bolt server loaded");
            }

            _life.start();               // init and start the nested lifecycle
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHandleFragmentedMessage()
        public virtual void ShouldHandleFragmentedMessage()
        {
            // Given
            BoltProtocol        protocol       = NewBoltProtocol(1);
            BoltProtocolFactory handlerFactory = NewProtocolFactory(1, protocol);
            EmbeddedChannel     channel        = new EmbeddedChannel(new ProtocolHandshaker(handlerFactory, _boltChannel, _logProvider, false, true));

            // When
            channel.writeInbound(Unpooled.wrappedBuffer(new sbyte[] { ( sbyte )0x60, ( sbyte )0x60, unchecked (( sbyte )0xB0) }));
            assertEquals(0, channel.outboundMessages().size());
            channel.writeInbound(Unpooled.wrappedBuffer(new sbyte[] { ( sbyte )0x17, 0, 0, 0 }));
            assertEquals(0, channel.outboundMessages().size());
            channel.writeInbound(Unpooled.wrappedBuffer(new sbyte[] { 0, 0, 0 }));
            assertEquals(0, channel.outboundMessages().size());
            channel.writeInbound(Unpooled.wrappedBuffer(new sbyte[] { 0, 1, 0, 0, 0 }));
            assertEquals(0, channel.outboundMessages().size());
            channel.writeInbound(Unpooled.wrappedBuffer(new sbyte[] { 0, 0, 0 }));
            assertEquals(0, channel.outboundMessages().size());
            channel.writeInbound(Unpooled.wrappedBuffer(new sbyte[] { 0, 0 }));

            // Then
            assertEquals(1, channel.outboundMessages().size());
            assertByteBufEquals(Unpooled.buffer().writeInt(1), channel.readOutbound());

            Thrown.expect(typeof(NoSuchElementException));
            channel.pipeline().remove(typeof(ProtocolHandshaker));

            assertTrue(channel.Active);
            verify(protocol).install();
        }
Example #4
0
 public ProtocolHandshaker(BoltProtocolFactory boltProtocolFactory, BoltChannel boltChannel, LogProvider logging, bool encryptionRequired, bool encrypted)
 {
     this._boltProtocolFactory = boltProtocolFactory;
     this._boltChannel         = boltChannel;
     this._log = logging.getLog(this.GetType());
     this._encryptionRequired = encryptionRequired;
     this._encrypted          = encrypted;
 }
Example #5
0
            public void ShouldCreateBoltProtocolV2()
            {
                var connMock = new Mock <ITcpSocketClient>();

                TcpSocketClientTestSetup.CreateWriteStreamMock(connMock);
                TcpSocketClientTestSetup.CreateReadStreamMock(connMock);
                var boltProtocol = BoltProtocolFactory.ForVersion(2);

                boltProtocol.Should().BeOfType <BoltProtocolV2>();
            }
            public void ShouldCreateBoltProtocolV1()
            {
                var connMock = new Mock <ITcpSocketClient>();

                TcpSocketClientTestSetup.CreateWriteStreamMock(connMock);
                TcpSocketClientTestSetup.CreateReadStreamMock(connMock);
                var boltProtocol = BoltProtocolFactory.Create(1, connMock.Object, new BufferSettings(Config.DefaultConfig));

                boltProtocol.Should().BeOfType <BoltProtocolV1>();
            }
 internal TransportSelectionHandler(BoltChannel boltChannel, SslContext sslCtx, bool encryptionRequired, bool isEncrypted, LogProvider logging, BoltProtocolFactory boltProtocolFactory)
 {
     this._boltChannel         = boltChannel;
     this._sslCtx              = sslCtx;
     this._encryptionRequired  = encryptionRequired;
     this._isEncrypted         = isEncrypted;
     this._logging             = logging;
     this._boltProtocolFactory = boltProtocolFactory;
     this._log = logging.GetLog(typeof(TransportSelectionHandler));
 }
Example #8
0
 public SocketTransport(string connector, ListenSocketAddress address, SslContext sslCtx, bool encryptionRequired, LogProvider logging, TransportThrottleGroup throttleGroup, BoltProtocolFactory boltProtocolFactory, NetworkConnectionTracker connectionTracker)
 {
     this._connector           = connector;
     this._address             = address;
     this._sslCtx              = sslCtx;
     this._encryptionRequired  = encryptionRequired;
     this._logging             = logging;
     this._throttleGroup       = throttleGroup;
     this._boltProtocolFactory = boltProtocolFactory;
     this._connectionTracker   = connectionTracker;
 }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRejectIfInsecureWhenEncryptionRequired()
        public virtual void ShouldRejectIfInsecureWhenEncryptionRequired()
        {
            // Given
            BoltProtocol        protocol       = NewBoltProtocol(1);
            BoltProtocolFactory handlerFactory = NewProtocolFactory(1, protocol);
            EmbeddedChannel     channel        = new EmbeddedChannel(new ProtocolHandshaker(handlerFactory, _boltChannel, _logProvider, true, false));

            // When
            ByteBuf input = Unpooled.wrappedBuffer(new sbyte[] { ( sbyte )0x60, ( sbyte )0x60, unchecked (( sbyte )0xB0), ( sbyte )0x17 }, new sbyte[] { 0, 0, 0, 1 }, new sbyte[] { 0, 0, 0, 2 }, new sbyte[] { 0, 0, 0, 3 }, new sbyte[] { 0, 0, 0, 4 });                 // fourth choice - no protocol

            channel.writeInbound(input);

            // Then
            assertEquals(0, channel.outboundMessages().size());
            assertFalse(channel.Active);
            verify(protocol, never()).install();
        }
Example #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRejectIfHttp()
        public virtual void ShouldRejectIfHttp()
        {
            // Given
            BoltProtocol        protocol       = NewBoltProtocol(1);
            BoltProtocolFactory handlerFactory = NewProtocolFactory(1, protocol);
            EmbeddedChannel     channel        = new EmbeddedChannel(new ProtocolHandshaker(handlerFactory, _boltChannel, _logProvider, false, true));

            // When
            FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "http://hello_world:10000");

            request.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, 0);
            channel.writeInbound(request);

            // Then
            assertEquals(0, channel.outboundMessages().size());
            assertFalse(channel.Active);
            verify(protocol, never()).install();
            _logProvider.assertExactly(AssertableLogProvider.inLog(typeof(ProtocolHandshaker)).warn("Unsupported connection type: 'HTTP'. Bolt protocol only operates over a TCP connection or WebSocket."));
        }
Example #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldFallbackToNoProtocolIfNoMatch()
        public virtual void ShouldFallbackToNoProtocolIfNoMatch()
        {
            // Given
            BoltProtocol        protocol       = NewBoltProtocol(1);
            BoltProtocolFactory handlerFactory = NewProtocolFactory(1, protocol);
            EmbeddedChannel     channel        = new EmbeddedChannel(new ProtocolHandshaker(handlerFactory, _boltChannel, _logProvider, false, true));

            // When
            ByteBuf input = Unpooled.wrappedBuffer(new sbyte[] { ( sbyte )0x60, ( sbyte )0x60, unchecked (( sbyte )0xB0), ( sbyte )0x17 }, new sbyte[] { 0, 0, 0, 0 }, new sbyte[] { 0, 0, 0, 2 }, new sbyte[] { 0, 0, 0, 3 }, new sbyte[] { 0, 0, 0, 4 });                 // fourth choice - no protocol

            channel.writeInbound(input);

            // Then
            assertEquals(1, channel.outboundMessages().size());
            assertByteBufEquals(Unpooled.buffer().writeInt(0), channel.readOutbound());

            assertFalse(channel.Active);
            verify(protocol, never()).install();
        }
Example #12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHandleMaxVersionNumber()
        public virtual void ShouldHandleMaxVersionNumber()
        {
            long maxVersionNumber = 4_294_967_295L;

            // Given
            BoltProtocol        protocol       = NewBoltProtocol(maxVersionNumber);
            BoltProtocolFactory handlerFactory = NewProtocolFactory(maxVersionNumber, protocol);
            EmbeddedChannel     channel        = new EmbeddedChannel(new ProtocolHandshaker(handlerFactory, _boltChannel, _logProvider, false, true));

            // When
            ByteBuf input = Unpooled.wrappedBuffer(new sbyte[] { ( sbyte )0x60, ( sbyte )0x60, unchecked (( sbyte )0xB0), ( sbyte )0x17 }, new sbyte[] { unchecked (( sbyte )0xFF), unchecked (( sbyte )0xFF), unchecked (( sbyte )0xFF), unchecked (( sbyte )0xFF) }, new sbyte[] { 0, 0, 0, 0 }, new sbyte[] { 0, 0, 0, 0 }, new sbyte[] { 0, 0, 0, 0 });                         // fourth choice - no protocol

            channel.writeInbound(input);

            // Then
            assertEquals(1, channel.outboundMessages().size());
            assertByteBufEquals(Unpooled.buffer().writeInt((int)maxVersionNumber), channel.readOutbound());

            Thrown.expect(typeof(NoSuchElementException));
            channel.pipeline().remove(typeof(ProtocolHandshaker));

            assertTrue(channel.Active);
            verify(protocol).install();
        }
Example #13
0
        private NettyServer.ProtocolInitializer CreateProtocolInitializer(BoltConnector connector, BoltProtocolFactory boltProtocolFactory, TransportThrottleGroup throttleGroup, Log log)
        {
            SslContext sslCtx;
            bool       requireEncryption;

            BoltConnector.EncryptionLevel encryptionLevel = _config.get(connector.EncryptionLevel);
            SslPolicyLoader sslPolicyLoader = _dependencyResolver.resolveDependency(typeof(SslPolicyLoader));

            switch (encryptionLevel)
            {
            case BoltConnector.EncryptionLevel.REQUIRED:
                // Encrypted connections are mandatory, a self-signed certificate may be generated.
                requireEncryption = true;
                sslCtx            = CreateSslContext(sslPolicyLoader, _config);
                break;

            case BoltConnector.EncryptionLevel.OPTIONAL:
                // Encrypted connections are optional, a self-signed certificate may be generated.
                requireEncryption = false;
                sslCtx            = CreateSslContext(sslPolicyLoader, _config);
                break;

            case BoltConnector.EncryptionLevel.DISABLED:
                // Encryption is turned off, no self-signed certificate will be generated.
                requireEncryption = false;
                sslCtx            = null;
                break;

            default:
                // In the unlikely event that we happen to fall through to the default option here,
                // there is a mismatch between the BoltConnector.EncryptionLevel enum and the options
                // handled in this switch statement. In this case, we'll log a warning and default to
                // disabling encryption, since this mirrors the functionality introduced in 3.0.
                log.Warn("Unhandled encryption level %s - assuming DISABLED.", encryptionLevel.name());
                requireEncryption = false;
                sslCtx            = null;
                break;
            }

            ListenSocketAddress listenAddress = _config.get(connector.ListenAddress);

            return(new SocketTransport(connector.Key(), listenAddress, sslCtx, requireEncryption, _logService.InternalLogProvider, throttleGroup, boltProtocolFactory, _connectionTracker));
        }
Example #14
0
 private IDictionary <BoltConnector, NettyServer.ProtocolInitializer> CreateConnectors(BoltProtocolFactory boltProtocolFactory, TransportThrottleGroup throttleGroup, Log log)
 {
     return(_config.enabledBoltConnectors().ToDictionary(identity(), connector => CreateProtocolInitializer(connector, boltProtocolFactory, throttleGroup, log)));
 }