Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/bolt-connection/src/bolt/bolt-protocol-v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default class BoltProtocol {
}

/**
* Returns the numerical version identifier for this protocol
* Returns the stringified version identifier for this protocol
*/
get version () {
return BOLT_PROTOCOL_V1
Expand Down
43 changes: 23 additions & 20 deletions packages/bolt-connection/src/bolt/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { newError } from 'neo4j-driver-core'
import { newError, ProtocolVersion } from 'neo4j-driver-core'
import BoltProtocolV1 from './bolt-protocol-v1'
import BoltProtocolV2 from './bolt-protocol-v2'
import BoltProtocolV3 from './bolt-protocol-v3'
Expand Down Expand Up @@ -112,8 +112,11 @@ function createProtocol (
onProtocolError,
log
) {
switch (version) {
case 1:
if (!(version instanceof ProtocolVersion) || version === undefined || version === null) {
throw newError('Unknown Bolt protocol version: ' + version)
}
switch (version.toString()) {
case '1.0':
return new BoltProtocolV1(
server,
chunker,
Expand All @@ -122,7 +125,7 @@ function createProtocol (
log,
onProtocolError
)
case 2:
case '2.0':
return new BoltProtocolV2(
server,
chunker,
Expand All @@ -131,7 +134,7 @@ function createProtocol (
log,
onProtocolError
)
case 3:
case '3.0':
return new BoltProtocolV3(
server,
chunker,
Expand All @@ -140,7 +143,7 @@ function createProtocol (
log,
onProtocolError
)
case 4.0:
case '4.0':
return new BoltProtocolV4x0(
server,
chunker,
Expand All @@ -149,7 +152,7 @@ function createProtocol (
log,
onProtocolError
)
case 4.1:
case '4.1':
return new BoltProtocolV4x1(
server,
chunker,
Expand All @@ -159,7 +162,7 @@ function createProtocol (
onProtocolError,
serversideRouting
)
case 4.2:
case '4.2':
return new BoltProtocolV4x2(
server,
chunker,
Expand All @@ -169,7 +172,7 @@ function createProtocol (
onProtocolError,
serversideRouting
)
case 4.3:
case '4.3':
return new BoltProtocolV4x3(
server,
chunker,
Expand All @@ -179,7 +182,7 @@ function createProtocol (
onProtocolError,
serversideRouting
)
case 4.4:
case '4.4':
return new BoltProtocolV4x4(
server,
chunker,
Expand All @@ -189,7 +192,7 @@ function createProtocol (
onProtocolError,
serversideRouting
)
case 5.0:
case '5.0':
return new BoltProtocolV5x0(
server,
chunker,
Expand All @@ -199,7 +202,7 @@ function createProtocol (
onProtocolError,
serversideRouting
)
case 5.1:
case '5.1':
return new BoltProtocolV5x1(
server,
chunker,
Expand All @@ -209,7 +212,7 @@ function createProtocol (
onProtocolError,
serversideRouting
)
case 5.2:
case '5.2':
return new BoltProtocolV5x2(
server,
chunker,
Expand All @@ -219,55 +222,55 @@ function createProtocol (
onProtocolError,
serversideRouting
)
case 5.3:
case '5.3':
return new BoltProtocolV5x3(server,
chunker,
packingConfig,
createResponseHandler,
log,
onProtocolError,
serversideRouting)
case 5.4:
case '5.4':
return new BoltProtocolV5x4(server,
chunker,
packingConfig,
createResponseHandler,
log,
onProtocolError,
serversideRouting)
case 5.5:
case '5.5':
return new BoltProtocolV5x5(server,
chunker,
packingConfig,
createResponseHandler,
log,
onProtocolError,
serversideRouting)
case 5.6:
case '5.6':
return new BoltProtocolV5x6(server,
chunker,
packingConfig,
createResponseHandler,
log,
onProtocolError,
serversideRouting)
case 5.7:
case '5.7':
return new BoltProtocolV5x7(server,
chunker,
packingConfig,
createResponseHandler,
log,
onProtocolError,
serversideRouting)
case 5.8:
case '5.8':
return new BoltProtocolV5x8(server,
chunker,
packingConfig,
createResponseHandler,
log,
onProtocolError,
serversideRouting)
case 6.0:
case '6.0':
return new BoltProtocolV6x0(server,
chunker,
packingConfig,
Expand Down
10 changes: 5 additions & 5 deletions packages/bolt-connection/src/bolt/handshake.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

import { alloc } from '../channel'
import { newError } from 'neo4j-driver-core'
import { newError, ProtocolVersion } from 'neo4j-driver-core'

const BOLT_MAGIC_PREAMBLE = 0x6060b017
const AVAILABLE_BOLT_PROTOCOLS = ['6.0', '5.8', '5.7', '5.6', '5.4', '5.3', '5.2', '5.1', '5.0', '4.4', '4.3', '4.2', '3.0'] // bolt protocols the client will accept, ordered by preference
Expand Down Expand Up @@ -69,7 +69,7 @@ function parseNegotiatedResponse (buffer, log) {
'(HTTP defaults to port 7474 whereas BOLT defaults to port 7687)'
)
}
return Number(h[3] + '.' + h[2])
return new ProtocolVersion(h[3], h[2])
}

function handshakeNegotiationV2 (channel, buffer, log) {
Expand Down Expand Up @@ -112,7 +112,7 @@ function handshakeNegotiationV2 (channel, buffer, log) {
selectionBuffer.writeVarInt(capabilites)
channel.write(selectionBuffer)
resolve({
protocolVersion: Number(major + '.' + minor),
protocolVersion: new ProtocolVersion(major, minor),
capabilites,
consumeRemainingBuffer: consumer => {
if (buffer.hasRemaining()) {
Expand Down Expand Up @@ -146,7 +146,7 @@ function newHandshakeBuffer () {
*/
/**
* @typedef HandshakeResult
* @property {number} protocolVersion The protocol version negotiated in the handshake
* @property {ProtocolVersion} protocolVersion The protocol version negotiated in the handshake
* @property {number} capabilites A bitmask representing the capabilities negotiated in the handshake
* @property {function(BufferConsumerCallback)} consumeRemainingBuffer A function to consume the remaining buffer if it exists
*/
Expand All @@ -160,7 +160,7 @@ function newHandshakeBuffer () {
*/
export default function handshake (channel, log) {
return initialHandshake(channel, log).then((result) => {
if (result.protocolVersion === 255.1) {
if (result.protocolVersion.equalTo(new ProtocolVersion(255, 1))) {
return handshakeNegotiationV2(channel, result.buffer, log)
} else {
return result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default class DirectConnectionProvider extends PooledConnectionProvider {

async supportsMultiDb () {
return await this._hasProtocolVersion(
version => version >= BOLT_PROTOCOL_V4_0
version => version.isGreaterOrEqualTo(BOLT_PROTOCOL_V4_0)
)
}

Expand All @@ -104,19 +104,19 @@ export default class DirectConnectionProvider extends PooledConnectionProvider {

async supportsTransactionConfig () {
return await this._hasProtocolVersion(
version => version >= BOLT_PROTOCOL_V3
version => version.isGreaterOrEqualTo(BOLT_PROTOCOL_V3)
)
}

async supportsUserImpersonation () {
return await this._hasProtocolVersion(
version => version >= BOLT_PROTOCOL_V4_4
version => version.isGreaterOrEqualTo(BOLT_PROTOCOL_V4_4)
)
}

async supportsSessionAuth () {
return await this._hasProtocolVersion(
version => version >= BOLT_PROTOCOL_V5_1
version => version.isGreaterOrEqualTo(BOLT_PROTOCOL_V5_1)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,25 +260,25 @@ export default class RoutingConnectionProvider extends PooledConnectionProvider

async supportsMultiDb () {
return await this._hasProtocolVersion(
version => version >= BOLT_PROTOCOL_V4_0
version => version.isGreaterOrEqualTo(BOLT_PROTOCOL_V4_0)
)
}

async supportsTransactionConfig () {
return await this._hasProtocolVersion(
version => version >= BOLT_PROTOCOL_V3
version => version.isGreaterOrEqualTo(BOLT_PROTOCOL_V3)
)
}

async supportsUserImpersonation () {
return await this._hasProtocolVersion(
version => version >= BOLT_PROTOCOL_V4_4
version => version.isGreaterOrEqualTo(BOLT_PROTOCOL_V4_4)
)
}

async supportsSessionAuth () {
return await this._hasProtocolVersion(
version => version >= BOLT_PROTOCOL_V5_1
version => version.isGreaterOrEqualTo(BOLT_PROTOCOL_V5_1)
)
}

Expand Down Expand Up @@ -611,7 +611,7 @@ export default class RoutingConnectionProvider extends PooledConnectionProvider
const connectionProvider = new SingleConnectionProvider(delegateConnection)

const protocolVersion = connection.protocol().version
if (protocolVersion < 4.0) {
if (protocolVersion.isLessThan({ major: 4, minor: 0 })) {
return [new Session({
mode: WRITE,
bookmarks: Bookmarks.empty(),
Expand Down
5 changes: 3 additions & 2 deletions packages/bolt-connection/test/bolt/bolt-protocol-v1.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import {
UnboundRelationship,
Node,
newError,
Vector
Vector,
ProtocolVersion
} from 'neo4j-driver-core'
import utils from '../test-utils'
import { LoginObserver } from '../../src/bolt/stream-observers'
Expand Down Expand Up @@ -224,7 +225,7 @@ describe('#unit BoltProtocolV1', () => {
it('should return correct bolt version number', () => {
const protocol = new BoltProtocolV1(null, null, false)

expect(protocol.version).toBe(1)
expect(protocol.version).toEqual(new ProtocolVersion(1, 0))
})

describe('Bolt V3', () => {
Expand Down
5 changes: 3 additions & 2 deletions packages/bolt-connection/test/bolt/bolt-protocol-v2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import {
Relationship,
Time,
UnboundRelationship,
Node
Node,
ProtocolVersion
} from 'neo4j-driver-core'

import { alloc } from '../../src/channel'
Expand Down Expand Up @@ -69,7 +70,7 @@ describe('#unit BoltProtocolV2', () => {
it('should return correct bolt version number', () => {
const protocol = new BoltProtocolV2(null, null, false)

expect(protocol.version).toBe(2)
expect(protocol.version).toEqual(new ProtocolVersion(2, 0))
})

describe('unpacker configuration', () => {
Expand Down
5 changes: 3 additions & 2 deletions packages/bolt-connection/test/bolt/bolt-protocol-v3.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ import {
Time,
UnboundRelationship,
Node,
internal
internal,
ProtocolVersion
} from 'neo4j-driver-core'

import { alloc } from '../../src/channel'
Expand Down Expand Up @@ -202,7 +203,7 @@ describe('#unit BoltProtocolV3', () => {
it('should return correct bolt version number', () => {
const protocol = new BoltProtocolV3(null, null, false)

expect(protocol.version).toBe(3)
expect(protocol.version).toEqual(new ProtocolVersion(3, 0))
})

it('should request the routing table from the correct procedure', () => {
Expand Down
5 changes: 3 additions & 2 deletions packages/bolt-connection/test/bolt/bolt-protocol-v4x0.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ import {
Time,
UnboundRelationship,
Node,
internal
internal,
ProtocolVersion
} from 'neo4j-driver-core'

import { alloc } from '../../src/channel'
Expand Down Expand Up @@ -149,7 +150,7 @@ describe('#unit BoltProtocolV4x0', () => {
it('should return correct bolt version number', () => {
const protocol = new BoltProtocolV4x0(null, null, false)

expect(protocol.version).toBe(4)
expect(protocol.version).toEqual(new ProtocolVersion(4, 0))
})

it('should request the routing table from the correct procedure', () => {
Expand Down
5 changes: 3 additions & 2 deletions packages/bolt-connection/test/bolt/bolt-protocol-v4x3.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import {
Time,
UnboundRelationship,
Node,
internal
internal,
ProtocolVersion
} from 'neo4j-driver-core'

import { alloc } from '../../src/channel'
Expand Down Expand Up @@ -169,7 +170,7 @@ describe('#unit BoltProtocolV4x3', () => {
it('should return correct bolt version number', () => {
const protocol = new BoltProtocolV4x3(null, null, false)

expect(protocol.version).toBe(4.3)
expect(protocol.version).toEqual(new ProtocolVersion(4, 3))
})

it('should update metadata', () => {
Expand Down
Loading