5858from neo4j .routing import RoutingTable
5959
6060
61- MAGIC_PREAMBLE = 0x6060B017
62-
63- DEFAULT_MAX_CONNECTION_LIFETIME = 3600 # 1h
64-
65- DEFAULT_KEEP_ALIVE = True
66-
67- DEFAULT_CONNECTION_TIMEOUT = 5.0 # 5s
68-
69-
7061# Set up logger
7162log = getLogger ("neo4j" )
7263
7364
7465class Bolt :
75- """ Server connection for Bolt protocol v1 .
66+ """ Server connection for Bolt protocol version 3 .
7667
7768 A :class:`.Connection` should be constructed following a
7869 successful Bolt handshake and takes the socket over which
@@ -81,6 +72,8 @@ class Bolt:
8172 .. note:: logs at INFO level
8273 """
8374
75+ MAGIC_PREAMBLE = 0x6060B017
76+
8477 #: The protocol version in use on this connection
8578 protocol_version = 0
8679
@@ -921,6 +914,8 @@ def _connect(resolved_address, timeout=None, **config):
921914 :param config:
922915 :return: socket object
923916 """
917+ config = PoolConfig .consume (config )
918+
924919 s = None
925920 try :
926921 if len (resolved_address ) == 2 :
@@ -932,13 +927,13 @@ def _connect(resolved_address, timeout=None, **config):
932927 "{!r}" .format (resolved_address ))
933928 t = s .gettimeout ()
934929 if timeout is None :
935- s .settimeout (DEFAULT_CONNECTION_TIMEOUT )
930+ s .settimeout (config . connect_timeout )
936931 else :
937932 s .settimeout (timeout )
938933 log .debug ("[#0000] C: <OPEN> %s" , resolved_address )
939934 s .connect (resolved_address )
940935 s .settimeout (t )
941- keep_alive = 1 if config .get ( " keep_alive" , DEFAULT_KEEP_ALIVE ) else 0
936+ keep_alive = 1 if config .keep_alive else 0
942937 s .setsockopt (SOL_SOCKET , SO_KEEPALIVE , keep_alive )
943938 except SocketTimeout :
944939 log .debug ("[#0000] C: <TIMEOUT> %s" , resolved_address )
@@ -991,10 +986,9 @@ def _handshake(s, resolved_address):
991986
992987 # Send details of the protocol versions supported
993988 supported_versions = [3 , 0 , 0 , 0 ]
994- handshake = [MAGIC_PREAMBLE ] + supported_versions
995- log .debug ("[#%04X] C: <MAGIC> 0x%08X" , local_port , MAGIC_PREAMBLE )
996- log .debug ("[#%04X] C: <HANDSHAKE> 0x%08X 0x%08X 0x%08X 0x%08X" ,
997- local_port , * supported_versions )
989+ handshake = [Bolt .MAGIC_PREAMBLE ] + supported_versions
990+ log .debug ("[#%04X] C: <MAGIC> 0x%08X" , local_port , Bolt .MAGIC_PREAMBLE )
991+ log .debug ("[#%04X] C: <HANDSHAKE> 0x%08X 0x%08X 0x%08X 0x%08X" , local_port , * supported_versions )
998992 data = b"" .join (struct_pack (">I" , num ) for num in handshake )
999993 s .sendall (data )
1000994
0 commit comments