38
38
sslProtocolCiphers = "AECDH-AES256-SHA"
39
39
40
40
41
- class TLSDispatcher (AdvancedDispatcher ):
41
+ class TLSDispatcher (AdvancedDispatcher ): # pylint: disable=too-many-instance-attributes
42
+ """TLS functionality for classes derived from AdvancedDispatcher"""
43
+ # pylint: disable=too-many-arguments, super-init-not-called, unused-argument
42
44
def __init__ (
43
- self , address = None , sock = None , certfile = None , keyfile = None ,
44
- server_side = False , ciphers = sslProtocolCiphers
45
+ self , address = None , sock = None , certfile = None , keyfile = None ,
46
+ server_side = False , ciphers = sslProtocolCiphers
45
47
):
46
48
self .want_read = self .want_write = True
47
49
if certfile is None :
@@ -60,6 +62,8 @@ def __init__(
60
62
self .isSSL = False
61
63
62
64
def state_tls_init (self ):
65
+ """Prepare sockets for TLS handshake"""
66
+ # pylint: disable=attribute-defined-outside-init
63
67
self .isSSL = True
64
68
self .tlsStarted = True
65
69
# Once the connection has been established, it's safe to wrap the
@@ -89,10 +93,13 @@ def state_tls_init(self):
89
93
# if hasattr(self.socket, "context"):
90
94
# self.socket.context.set_ecdh_curve("secp256k1")
91
95
92
- def state_tls_handshake (self ):
96
+ @staticmethod
97
+ def state_tls_handshake ():
98
+ """Do nothing while TLS handshake is pending, as during this phase we need to react to callbacks instead"""
93
99
return False
94
100
95
101
def writable (self ):
102
+ """Handle writable checks for TLS-enabled sockets"""
96
103
try :
97
104
if self .tlsStarted and not self .tlsDone and not self .write_buf :
98
105
return self .want_write
@@ -101,6 +108,7 @@ def writable(self):
101
108
return AdvancedDispatcher .writable (self )
102
109
103
110
def readable (self ):
111
+ """Handle readable check for TLS-enabled sockets"""
104
112
try :
105
113
# during TLS handshake, and after flushing write buffer, return status of last handshake attempt
106
114
if self .tlsStarted and not self .tlsDone and not self .write_buf :
@@ -113,7 +121,11 @@ def readable(self):
113
121
except AttributeError :
114
122
return AdvancedDispatcher .readable (self )
115
123
116
- def handle_read (self ):
124
+ def handle_read (self ): # pylint: disable=inconsistent-return-statements
125
+ """
126
+ Handle reads for sockets during TLS handshake. Requires special treatment as during the handshake, buffers must
127
+ remain empty and normal reads must be ignored
128
+ """
117
129
try :
118
130
# wait for write buffer flush
119
131
if self .tlsStarted and not self .tlsDone and not self .write_buf :
@@ -134,7 +146,11 @@ def handle_read(self):
134
146
self .handle_close ()
135
147
return
136
148
137
- def handle_write (self ):
149
+ def handle_write (self ): # pylint: disable=inconsistent-return-statements
150
+ """
151
+ Handle writes for sockets during TLS handshake. Requires special treatment as during the handshake, buffers
152
+ must remain empty and normal writes must be ignored
153
+ """
138
154
try :
139
155
# wait for write buffer flush
140
156
if self .tlsStarted and not self .tlsDone and not self .write_buf :
@@ -156,6 +172,7 @@ def handle_write(self):
156
172
return
157
173
158
174
def tls_handshake (self ):
175
+ """Perform TLS handshake and handle its stages"""
159
176
# wait for flush
160
177
if self .write_buf :
161
178
return False
@@ -175,7 +192,7 @@ def tls_handshake(self):
175
192
if not (self .want_write or self .want_read ):
176
193
raise
177
194
except socket .error as err :
178
- if err .errno in asyncore ._DISCONNECTED :
195
+ if err .errno in asyncore ._DISCONNECTED : # pylint: disable=protected-access
179
196
self .handle_close ()
180
197
else :
181
198
raise
0 commit comments