Skip to content

Implement bolt 5.0 + new style element ids #672

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 7 commits into from
Mar 14, 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
33 changes: 19 additions & 14 deletions neo4j/_async/io/_bolt.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,20 +182,21 @@ def protocol_handlers(cls, protocol_version=None):
# Carry out Bolt subclass imports locally to avoid circular dependency issues.
from ._bolt3 import AsyncBolt3
from ._bolt4 import (
AsyncBolt4x0,
AsyncBolt4x1,
AsyncBolt4x2,
AsyncBolt4x3,
AsyncBolt4x4,
)
from ._bolt5 import AsyncBolt5x0

handlers = {
AsyncBolt3.PROTOCOL_VERSION: AsyncBolt3,
AsyncBolt4x0.PROTOCOL_VERSION: AsyncBolt4x0,
# 4.0 unsupported because no space left in the handshake
AsyncBolt4x1.PROTOCOL_VERSION: AsyncBolt4x1,
AsyncBolt4x2.PROTOCOL_VERSION: AsyncBolt4x2,
AsyncBolt4x3.PROTOCOL_VERSION: AsyncBolt4x3,
AsyncBolt4x4.PROTOCOL_VERSION: AsyncBolt4x4,
AsyncBolt5x0.PROTOCOL_VERSION: AsyncBolt5x0,
}

if protocol_version is None:
Expand All @@ -215,9 +216,9 @@ def version_list(cls, versions, limit=4):
preference. The number of protocol versions (or ranges)
returned is limited to four.
"""
# In fact, 4.3 is the fist version to support ranges. However, the range
# support got backported to 4.2. But even if the server is too old to
# have the backport, negotiating BOLT 4.1 is no problem as it's
# In fact, 4.3 is the fist version to support ranges. However, the
# range support got backported to 4.2. But even if the server is too
# old to have the backport, negotiating BOLT 4.1 is no problem as it's
# equivalent to 4.2
first_with_range_support = Version(4, 2)
result = []
Expand Down Expand Up @@ -313,9 +314,12 @@ def time_remaining():
if pool_config.protocol_version == (3, 0):
from ._bolt3 import AsyncBolt3
bolt_cls = AsyncBolt3
elif pool_config.protocol_version == (4, 0):
from ._bolt4 import AsyncBolt4x0
bolt_cls = AsyncBolt4x0
# Implementation for 4.0 exists, but there was no space left in the
# handshake to offer this version to the server. Hence, the server
# should never request us to speak bolt 4.0.
# elif pool_config.protocol_version == (4, 0):
# from ._bolt4 import AsyncBolt4x0
# bolt_cls = AsyncBolt4x0
elif pool_config.protocol_version == (4, 1):
from ._bolt4 import AsyncBolt4x1
bolt_cls = AsyncBolt4x1
Expand All @@ -328,15 +332,18 @@ def time_remaining():
elif pool_config.protocol_version == (4, 4):
from ._bolt4 import AsyncBolt4x4
bolt_cls = AsyncBolt4x4
elif pool_config.protocol_version == (5, 0):
from ._bolt5 import AsyncBolt5x0
bolt_cls = AsyncBolt5x0
else:
log.debug("[#%04X] S: <CLOSE>", s.getsockname()[1])
AsyncBoltSocket.close_socket(s)

supported_versions = cls.protocol_handlers().keys()
raise BoltHandshakeError(
"The Neo4J server does not support communication with this "
"driver. This driver have support for Bolt Protocols {}"
"".format(supported_versions),
"driver. This driver has support for Bolt protocols "
"{}".format(tuple(map(str, supported_versions))),
address=address, request_data=handshake, response_data=data
)

Expand Down Expand Up @@ -670,13 +677,11 @@ async def close_non_blocking(self):
self.socket.settimeout(0)
await self.close()

@abc.abstractmethod
def closed(self):
pass
return self._closed

@abc.abstractmethod
def defunct(self):
pass
return self._defunct

def is_idle_for(self, timeout):
"""Check if connection has been idle for at least the given timeout.
Expand Down
6 changes: 0 additions & 6 deletions neo4j/_async/io/_bolt3.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,3 @@ async def _process_message(self, details, summary_signature,
raise BoltProtocolError("Unexpected response message with signature %02X" % summary_signature, address=self.unresolved_address)

return len(details), 1

def closed(self):
return self._closed

def defunct(self):
return self._defunct
8 changes: 1 addition & 7 deletions neo4j/_async/io/_bolt4.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
class AsyncBolt4x0(AsyncBolt):
""" Protocol handler for Bolt 4.0.

This is supported by Neo4j versions 4.0, 4.1 and 4.2.
This is supported by Neo4j versions 4.0-4.4.
"""

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

return len(details), 1

def closed(self):
return self._closed

def defunct(self):
return self._defunct


class AsyncBolt4x1(AsyncBolt4x0):
""" Protocol handler for Bolt 4.1.
Expand Down
Loading