Skip to content

Commit b500a3e

Browse files
conn: store client and server protocol info
Store client and server protocol version and features in connection object, similar to go-tarantool [1]. Before the patch, we stored only products: minimal protocol version of server and client and the list of features supported both by client and server. 1. tarantool/go-tarantool#226 Part of #267
1 parent 80c12dc commit b500a3e

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

Diff for: tarantool/connection.py

+28-26
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import ctypes.util
2121
from ctypes import c_ssize_t
2222
from typing import Optional, Union
23+
from copy import copy
2324

2425
import msgpack
2526

@@ -838,6 +839,10 @@ def __init__(self, host, port,
838839
self.version_id = None
839840
self.uuid = None
840841
self._salt = None
842+
self._client_protocol_version = CONNECTOR_IPROTO_VERSION
843+
self._client_features = copy(CONNECTOR_FEATURES)
844+
self._server_protocol_version = None
845+
self._server_features = None
841846

842847
if connect_now:
843848
self.connect()
@@ -1044,10 +1049,11 @@ def handshake(self):
10441049
if greeting.protocol != "Binary":
10451050
raise NetworkError("Unsupported protocol: " + greeting.protocol)
10461051
self.version_id = greeting.version_id
1047-
if self.version_id >= version_id(2, 10, 0):
1048-
self._check_features()
10491052
self.uuid = greeting.uuid
10501053
self._salt = greeting.salt
1054+
1055+
self._check_features()
1056+
10511057
if self.user:
10521058
self.authenticate(self.user, self.password)
10531059

@@ -2057,32 +2063,28 @@ def _check_features(self):
20572063
:exc:`~tarantool.error.SslError`
20582064
"""
20592065

2060-
try:
2061-
request = RequestProtocolVersion(self,
2062-
CONNECTOR_IPROTO_VERSION,
2063-
CONNECTOR_FEATURES)
2064-
response = self._send_request(request)
2065-
server_protocol_version = response.protocol_version
2066-
server_features = response.features
2067-
server_auth_type = response.auth_type
2068-
except DatabaseError as exc:
2069-
if exc.code == ER_UNKNOWN_REQUEST_TYPE:
2070-
server_protocol_version = None
2071-
server_features = []
2072-
server_auth_type = None
2073-
else:
2074-
raise exc
2075-
2076-
if server_protocol_version is not None:
2077-
self._protocol_version = min(server_protocol_version,
2078-
CONNECTOR_IPROTO_VERSION)
2066+
if self.version_id >= version_id(2, 10, 0):
2067+
try:
2068+
request = RequestProtocolVersion(self,
2069+
self._client_protocol_version,
2070+
self._client_features)
2071+
response = self._send_request(request)
2072+
self._server_protocol_version = response.protocol_version
2073+
self._server_features = response.features
2074+
self._server_auth_type = response.auth_type
2075+
except DatabaseError as exc:
2076+
if exc.code != ER_UNKNOWN_REQUEST_TYPE:
2077+
raise exc
2078+
2079+
if self._server_protocol_version is not None:
2080+
self._protocol_version = min(self._server_protocol_version,
2081+
self._client_protocol_version)
20792082

20802083
# Intercept lists of features
2081-
features_list = [val for val in CONNECTOR_FEATURES if val in server_features]
2082-
for val in features_list:
2083-
self._features[val] = True
2084-
2085-
self._server_auth_type = server_auth_type
2084+
if self._server_features is not None:
2085+
features_list = [val for val in self._client_features if val in self._server_features]
2086+
for val in features_list:
2087+
self._features[val] = True
20862088

20872089
def _packer_factory(self):
20882090
return self._packer_factory_impl(self)

0 commit comments

Comments
 (0)