Skip to content

Commit 2e139d9

Browse files
authored
Implement bolt 5.0 + new style element ids (#672)
* Add packstream support for element_id fields * Implement bolt 5.0 and add it to the handshake * Fix typo in error message
1 parent 99221cc commit 2e139d9

File tree

16 files changed

+1206
-155
lines changed

16 files changed

+1206
-155
lines changed

neo4j/_async/io/_bolt.py

+19-14
Original file line numberDiff line numberDiff line change
@@ -182,20 +182,21 @@ def protocol_handlers(cls, protocol_version=None):
182182
# Carry out Bolt subclass imports locally to avoid circular dependency issues.
183183
from ._bolt3 import AsyncBolt3
184184
from ._bolt4 import (
185-
AsyncBolt4x0,
186185
AsyncBolt4x1,
187186
AsyncBolt4x2,
188187
AsyncBolt4x3,
189188
AsyncBolt4x4,
190189
)
190+
from ._bolt5 import AsyncBolt5x0
191191

192192
handlers = {
193193
AsyncBolt3.PROTOCOL_VERSION: AsyncBolt3,
194-
AsyncBolt4x0.PROTOCOL_VERSION: AsyncBolt4x0,
194+
# 4.0 unsupported because no space left in the handshake
195195
AsyncBolt4x1.PROTOCOL_VERSION: AsyncBolt4x1,
196196
AsyncBolt4x2.PROTOCOL_VERSION: AsyncBolt4x2,
197197
AsyncBolt4x3.PROTOCOL_VERSION: AsyncBolt4x3,
198198
AsyncBolt4x4.PROTOCOL_VERSION: AsyncBolt4x4,
199+
AsyncBolt5x0.PROTOCOL_VERSION: AsyncBolt5x0,
199200
}
200201

201202
if protocol_version is None:
@@ -215,9 +216,9 @@ def version_list(cls, versions, limit=4):
215216
preference. The number of protocol versions (or ranges)
216217
returned is limited to four.
217218
"""
218-
# In fact, 4.3 is the fist version to support ranges. However, the range
219-
# support got backported to 4.2. But even if the server is too old to
220-
# have the backport, negotiating BOLT 4.1 is no problem as it's
219+
# In fact, 4.3 is the fist version to support ranges. However, the
220+
# range support got backported to 4.2. But even if the server is too
221+
# old to have the backport, negotiating BOLT 4.1 is no problem as it's
221222
# equivalent to 4.2
222223
first_with_range_support = Version(4, 2)
223224
result = []
@@ -313,9 +314,12 @@ def time_remaining():
313314
if pool_config.protocol_version == (3, 0):
314315
from ._bolt3 import AsyncBolt3
315316
bolt_cls = AsyncBolt3
316-
elif pool_config.protocol_version == (4, 0):
317-
from ._bolt4 import AsyncBolt4x0
318-
bolt_cls = AsyncBolt4x0
317+
# Implementation for 4.0 exists, but there was no space left in the
318+
# handshake to offer this version to the server. Hence, the server
319+
# should never request us to speak bolt 4.0.
320+
# elif pool_config.protocol_version == (4, 0):
321+
# from ._bolt4 import AsyncBolt4x0
322+
# bolt_cls = AsyncBolt4x0
319323
elif pool_config.protocol_version == (4, 1):
320324
from ._bolt4 import AsyncBolt4x1
321325
bolt_cls = AsyncBolt4x1
@@ -328,15 +332,18 @@ def time_remaining():
328332
elif pool_config.protocol_version == (4, 4):
329333
from ._bolt4 import AsyncBolt4x4
330334
bolt_cls = AsyncBolt4x4
335+
elif pool_config.protocol_version == (5, 0):
336+
from ._bolt5 import AsyncBolt5x0
337+
bolt_cls = AsyncBolt5x0
331338
else:
332339
log.debug("[#%04X] S: <CLOSE>", s.getsockname()[1])
333340
AsyncBoltSocket.close_socket(s)
334341

335342
supported_versions = cls.protocol_handlers().keys()
336343
raise BoltHandshakeError(
337344
"The Neo4J server does not support communication with this "
338-
"driver. This driver have support for Bolt Protocols {}"
339-
"".format(supported_versions),
345+
"driver. This driver has support for Bolt protocols "
346+
"{}".format(tuple(map(str, supported_versions))),
340347
address=address, request_data=handshake, response_data=data
341348
)
342349

@@ -670,13 +677,11 @@ async def close_non_blocking(self):
670677
self.socket.settimeout(0)
671678
await self.close()
672679

673-
@abc.abstractmethod
674680
def closed(self):
675-
pass
681+
return self._closed
676682

677-
@abc.abstractmethod
678683
def defunct(self):
679-
pass
684+
return self._defunct
680685

681686
def is_idle_for(self, timeout):
682687
"""Check if connection has been idle for at least the given timeout.

neo4j/_async/io/_bolt3.py

-6
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,3 @@ async def _process_message(self, details, summary_signature,
363363
raise BoltProtocolError("Unexpected response message with signature %02X" % summary_signature, address=self.unresolved_address)
364364

365365
return len(details), 1
366-
367-
def closed(self):
368-
return self._closed
369-
370-
def defunct(self):
371-
return self._defunct

neo4j/_async/io/_bolt4.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
class AsyncBolt4x0(AsyncBolt):
5454
""" Protocol handler for Bolt 4.0.
5555
56-
This is supported by Neo4j versions 4.0, 4.1 and 4.2.
56+
This is supported by Neo4j versions 4.0-4.4.
5757
"""
5858

5959
PROTOCOL_VERSION = Version(4, 0)
@@ -312,12 +312,6 @@ async def _process_message(self, details, summary_signature,
312312

313313
return len(details), 1
314314

315-
def closed(self):
316-
return self._closed
317-
318-
def defunct(self):
319-
return self._defunct
320-
321315

322316
class AsyncBolt4x1(AsyncBolt4x0):
323317
""" Protocol handler for Bolt 4.1.

0 commit comments

Comments
 (0)