Skip to content

Commit

Permalink
Add Bolt 4.4 support
Browse files Browse the repository at this point in the history
This initial update brings 4.4 support that is based on 4.3.
  • Loading branch information
injectives committed Oct 4, 2021
1 parent cd02074 commit f29cf07
Show file tree
Hide file tree
Showing 11 changed files with 1,038 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.neo4j.driver.internal.messaging.v4.BoltProtocolV4;
import org.neo4j.driver.internal.messaging.v41.BoltProtocolV41;
import org.neo4j.driver.internal.messaging.v42.BoltProtocolV42;
import org.neo4j.driver.internal.messaging.v43.BoltProtocolV43;
import org.neo4j.driver.internal.messaging.v44.BoltProtocolV44;

import static io.netty.buffer.Unpooled.copyInt;
import static io.netty.buffer.Unpooled.unreleasableBuffer;
Expand All @@ -42,7 +42,7 @@ public final class BoltProtocolUtil

private static final ByteBuf HANDSHAKE_BUF = unreleasableBuffer( copyInt(
BOLT_MAGIC_PREAMBLE,
BoltProtocolV43.VERSION.toIntRange( BoltProtocolV42.VERSION ),
BoltProtocolV44.VERSION.toIntRange( BoltProtocolV42.VERSION ),
BoltProtocolV41.VERSION.toInt(),
BoltProtocolV4.VERSION.toInt(),
BoltProtocolV3.VERSION.toInt() ) ).asReadOnly();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.neo4j.driver.internal.messaging.v41.BoltProtocolV41;
import org.neo4j.driver.internal.messaging.v42.BoltProtocolV42;
import org.neo4j.driver.internal.messaging.v43.BoltProtocolV43;
import org.neo4j.driver.internal.messaging.v44.BoltProtocolV44;
import org.neo4j.driver.internal.spi.Connection;

import static org.neo4j.driver.internal.async.connection.ChannelAttributes.protocolVersion;
Expand Down Expand Up @@ -166,6 +167,10 @@ else if ( BoltProtocolV43.VERSION.equals( version ) )
{
return BoltProtocolV43.INSTANCE;
}
else if ( BoltProtocolV44.VERSION.equals( version ) )
{
return BoltProtocolV44.INSTANCE;
}
throw new ClientException( "Unknown protocol version: " + version );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.neo4j.driver.internal.messaging.v44;

import org.neo4j.driver.internal.messaging.BoltProtocol;
import org.neo4j.driver.internal.messaging.BoltProtocolVersion;
import org.neo4j.driver.internal.messaging.MessageFormat;
import org.neo4j.driver.internal.messaging.v43.BoltProtocolV43;

/**
* Definition of the Bolt Protocol 4.4
*/
public class BoltProtocolV44 extends BoltProtocolV43
{
public static final BoltProtocolVersion VERSION = new BoltProtocolVersion( 4, 4 );
public static final BoltProtocol INSTANCE = new BoltProtocolV44();

@Override
public MessageFormat createMessageFormat()
{
return new MessageFormatV44();
}

@Override
public BoltProtocolVersion version()
{
return VERSION;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.neo4j.driver.internal.messaging.v44;

import org.neo4j.driver.internal.messaging.MessageFormat;
import org.neo4j.driver.internal.messaging.common.CommonMessageReader;
import org.neo4j.driver.internal.packstream.PackInput;
import org.neo4j.driver.internal.packstream.PackOutput;

/**
* Bolt message format v4.4
*/
public class MessageFormatV44 implements MessageFormat
{
@Override
public MessageFormat.Writer newWriter( PackOutput output )
{
return new MessageWriterV44( output );
}

@Override
public MessageFormat.Reader newReader( PackInput input )
{
return new CommonMessageReader( input );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.neo4j.driver.internal.messaging.v44;

import java.util.Map;

import org.neo4j.driver.internal.messaging.AbstractMessageWriter;
import org.neo4j.driver.internal.messaging.MessageEncoder;
import org.neo4j.driver.internal.messaging.common.CommonValuePacker;
import org.neo4j.driver.internal.messaging.encode.BeginMessageEncoder;
import org.neo4j.driver.internal.messaging.encode.CommitMessageEncoder;
import org.neo4j.driver.internal.messaging.encode.DiscardMessageEncoder;
import org.neo4j.driver.internal.messaging.encode.GoodbyeMessageEncoder;
import org.neo4j.driver.internal.messaging.encode.HelloMessageEncoder;
import org.neo4j.driver.internal.messaging.encode.PullMessageEncoder;
import org.neo4j.driver.internal.messaging.encode.ResetMessageEncoder;
import org.neo4j.driver.internal.messaging.encode.RollbackMessageEncoder;
import org.neo4j.driver.internal.messaging.encode.RouteMessageEncoder;
import org.neo4j.driver.internal.messaging.encode.RunWithMetadataMessageEncoder;
import org.neo4j.driver.internal.messaging.request.BeginMessage;
import org.neo4j.driver.internal.messaging.request.CommitMessage;
import org.neo4j.driver.internal.messaging.request.DiscardMessage;
import org.neo4j.driver.internal.messaging.request.GoodbyeMessage;
import org.neo4j.driver.internal.messaging.request.HelloMessage;
import org.neo4j.driver.internal.messaging.request.PullMessage;
import org.neo4j.driver.internal.messaging.request.ResetMessage;
import org.neo4j.driver.internal.messaging.request.RollbackMessage;
import org.neo4j.driver.internal.messaging.request.RouteMessage;
import org.neo4j.driver.internal.messaging.request.RunWithMetadataMessage;
import org.neo4j.driver.internal.packstream.PackOutput;
import org.neo4j.driver.internal.util.Iterables;

/**
* Bolt message writer v4.4
*/
public class MessageWriterV44 extends AbstractMessageWriter
{
public MessageWriterV44( PackOutput output )
{
super( new CommonValuePacker( output ), buildEncoders() );
}

private static Map<Byte,MessageEncoder> buildEncoders()
{
Map<Byte,MessageEncoder> result = Iterables.newHashMapWithSize( 9 );
result.put( HelloMessage.SIGNATURE, new HelloMessageEncoder() );
result.put( GoodbyeMessage.SIGNATURE, new GoodbyeMessageEncoder() );
result.put( RunWithMetadataMessage.SIGNATURE, new RunWithMetadataMessageEncoder() );
result.put( RouteMessage.SIGNATURE, new RouteMessageEncoder() );

result.put( DiscardMessage.SIGNATURE, new DiscardMessageEncoder() );
result.put( PullMessage.SIGNATURE, new PullMessageEncoder() );

result.put( BeginMessage.SIGNATURE, new BeginMessageEncoder() );
result.put( CommitMessage.SIGNATURE, new CommitMessageEncoder() );
result.put( RollbackMessage.SIGNATURE, new RollbackMessageEncoder() );

result.put( ResetMessage.SIGNATURE, new ResetMessageEncoder() );
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.neo4j.driver.internal.messaging.v3.BoltProtocolV3;
import org.neo4j.driver.internal.messaging.v4.BoltProtocolV4;
import org.neo4j.driver.internal.messaging.v41.BoltProtocolV41;
import org.neo4j.driver.internal.messaging.v43.BoltProtocolV43;
import org.neo4j.driver.internal.messaging.v44.BoltProtocolV44;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.neo4j.driver.internal.async.connection.BoltProtocolUtil.BOLT_MAGIC_PREAMBLE;
Expand All @@ -43,15 +43,15 @@ void shouldReturnHandshakeBuf()
{
assertByteBufContains(
handshakeBuf(),
BOLT_MAGIC_PREAMBLE, (1 << 16) | BoltProtocolV43.VERSION.toInt(), BoltProtocolV41.VERSION.toInt(),
BOLT_MAGIC_PREAMBLE, (2 << 16) | BoltProtocolV44.VERSION.toInt(), BoltProtocolV41.VERSION.toInt(),
BoltProtocolV4.VERSION.toInt(), BoltProtocolV3.VERSION.toInt()
);
}

@Test
void shouldReturnHandshakeString()
{
assertEquals( "[0x6060b017, 66308, 260, 4, 3]", handshakeString() );
assertEquals( "[0x6060b017, 132100, 260, 4, 3]", handshakeString() );
}

@Test
Expand Down
Loading

0 comments on commit f29cf07

Please sign in to comment.