Skip to content

Enabling BoltProtocol v5 and the new elementId in the graph types #884

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Mar 15, 2022
Merged
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
40 changes: 40 additions & 0 deletions packages/bolt-connection/src/bolt/bolt-protocol-v5x0.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* 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.
*/
import BoltProtocolV44 from './bolt-protocol-v4x4'
import { v5 } from '../packstream'

import { internal } from 'neo4j-driver-core'

const {
constants: { BOLT_PROTOCOL_V5_0 },
} = internal

export default class BoltProtocol extends BoltProtocolV44 {
get version() {
return BOLT_PROTOCOL_V5_0
}

_createPacker (chunker) {
return new v5.Packer(chunker)
}

_createUnpacker (disableLosslessIntegers, useBigInt) {
return new v5.Unpacker(disableLosslessIntegers, useBigInt)
}
}
11 changes: 11 additions & 0 deletions packages/bolt-connection/src/bolt/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import BoltProtocolV4x1 from './bolt-protocol-v4x1'
import BoltProtocolV4x2 from './bolt-protocol-v4x2'
import BoltProtocolV4x3 from './bolt-protocol-v4x3'
import BoltProtocolV4x4 from './bolt-protocol-v4x4'
import BoltProtocolV5x0 from './bolt-protocol-v5x0'
import { Chunker, Dechunker } from '../channel'
import ResponseHandler from './response-handler'

Expand Down Expand Up @@ -175,6 +176,16 @@ function createProtocol (
onProtocolError,
serversideRouting
)
case 5.0:
return new BoltProtocolV5x0(
server,
chunker,
packingConfig,
createResponseHandler,
log,
onProtocolError,
serversideRouting
)
default:
throw newError('Unknown Bolt protocol version: ' + version)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/bolt-connection/src/bolt/handshake.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ function parseNegotiatedResponse (buffer) {
*/
function newHandshakeBuffer () {
return createHandshakeMessage([
version(5, 0),
[version(4, 4), version(4, 2)],
version(4, 1),
version(4, 0),
version(3, 0)
])
}
Expand Down
3 changes: 2 additions & 1 deletion packages/bolt-connection/src/packstream/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

import * as v1 from './packstream-v1'
import * as v2 from './packstream-v2'
import * as v5 from './packstream-v5'

export { v1, v2 }
export { v1, v2, v5 }

export default v2
12 changes: 6 additions & 6 deletions packages/bolt-connection/src/packstream/packstream-v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -646,18 +646,18 @@ class Unpacker {
// information about their start and end nodes, that's instead
// inferred from the path sequence. This is us inferring (and,
// for performance reasons remembering) the start/end of a rel.
rels[relIndex - 1] = rel = rel.bind(
prevNode.identity,
nextNode.identity
rels[relIndex - 1] = rel = rel.bindTo(
prevNode,
nextNode
)
}
} else {
rel = rels[-relIndex - 1]
if (rel instanceof UnboundRelationship) {
// See above
rels[-relIndex - 1] = rel = rel.bind(
nextNode.identity,
prevNode.identity
rels[-relIndex - 1] = rel = rel.bindTo(
nextNode,
prevNode
)
}
}
Expand Down
102 changes: 102 additions & 0 deletions packages/bolt-connection/src/packstream/packstream-v5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/**
* 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.
*/

import * as v2 from './packstream-v2'
import {
Node,
Relationship,
UnboundRelationship,
int
} from 'neo4j-driver-core'

const NODE_STRUCT_SIZE = 4
const RELATIONSHIP_STRUCT_SIZE = 8
const UNBOUND_RELATIONSHIP_STRUCT_SIZE = 4

export class Packer extends v2.Packer {
// This implementation is the same
}

export class Unpacker extends v2.Unpacker {
/**
* @constructor
* @param {boolean} disableLosslessIntegers if this unpacker should convert all received integers to native JS numbers.
* @param {boolean} useBigInt if this unpacker should convert all received integers to Bigint
*/
constructor (disableLosslessIntegers = false, useBigInt = false) {
this._disableLosslessIntegers = disableLosslessIntegers
this._useBigInt = useBigInt
this._defaultIdentity = this._getDefaultIdentity()
}

_getDefaultIdentity() {
if (this._useBigInt) {
return BigInt(-1)
} else if (this._disableLosslessIntegers) {
return -1
} else {
return int(-1)
}
}

_unpackNode (structSize, buffer) {
this._verifyStructSize('Node', NODE_STRUCT_SIZE, structSize)

return new Node(
_valueOrDefault(this.unpack(buffer), this._defaultIdentity), // Identity
this.unpack(buffer), // Labels
this.unpack(buffer), // Properties,
this.unpack(buffer) // ElementId
)
}

_unpackRelationship (structSize, buffer) {
this._verifyStructSize('Relationship', RELATIONSHIP_STRUCT_SIZE, structSize)

return new Relationship(
_valueOrDefault(this.unpack(buffer), this._defaultIdentity), // Identity
_valueOrDefault(this.unpack(buffer), this._defaultIdentity), // Start Node Identity
_valueOrDefault(this.unpack(buffer), this._defaultIdentity), // End Node Identity
this.unpack(buffer), // Type
this.unpack(buffer), // Properties,
this.unpack(buffer), // ElementId
this.unpack(buffer), // Start Node Element Id
this.unpack(buffer) // End Node Element Id
)
}

_unpackUnboundRelationship (structSize, buffer) {
this._verifyStructSize(
'UnboundRelationship',
UNBOUND_RELATIONSHIP_STRUCT_SIZE,
structSize
)

return new UnboundRelationship(
_valueOrDefault(this.unpack(buffer), this._defaultIdentity), // Identity
this.unpack(buffer), // Type
this.unpack(buffer), // Properties
this.unpack(buffer) // ElementId
)
}
}

function _valueOrDefault(value, defaultValue) {
return value === null ? defaultValue : value
}
Loading