|
@@ -180,8 +180,9 @@ class struct_json_protocol(object):
|
180
|
180
|
AUTH_STATE_KEY_TRANSFERRED: 'Key has been sent',
|
181
|
181
|
AUTH_STATE_TRUSTED_CLIENT: 'Trusted Client'}
|
182
|
182
|
|
183
|
|
- def __init__(self, comm_instance, secret=None):
|
|
183
|
+ def __init__(self, comm_instance, secret=None, auto_auth=False):
|
184
|
184
|
self.__secret__ = secret
|
|
185
|
+ self.__auto_auth__ = auto_auth
|
185
|
186
|
self.__clean_receive_buffer__()
|
186
|
187
|
self.__callbacks__ = callback_storage()
|
187
|
188
|
self.__callbacks__.add(self.SID_AUTH_SEED_REQUEST, 0, self.__authentificate_create_seed__)
|
|
@@ -192,7 +193,7 @@ class struct_json_protocol(object):
|
192
|
193
|
self.__seed__ = None
|
193
|
194
|
self.__comm_inst__ = comm_instance
|
194
|
195
|
self.__comm_inst__.register_callback(self.__data_available_callback__)
|
195
|
|
- self.__comm_inst__.register_connect_callback(self.__clean_receive_buffer__)
|
|
196
|
+ self.__comm_inst__.register_connect_callback(self.__connection_established__)
|
196
|
197
|
self.__comm_inst__.register_disconnect_callback(self.__authentification_state_reset__)
|
197
|
198
|
|
198
|
199
|
def is_connected(self):
|
|
@@ -201,6 +202,11 @@ class struct_json_protocol(object):
|
201
|
202
|
def reconnect(self):
|
202
|
203
|
return self.__comm_inst__.reconnect()
|
203
|
204
|
|
|
205
|
+ def __connection_established__(self):
|
|
206
|
+ self.__clean_receive_buffer__()
|
|
207
|
+ if self.__auto_auth__ and self.__comm_inst__.IS_CLIENT and self.__secret__ is not None:
|
|
208
|
+ self.authentificate()
|
|
209
|
+
|
204
|
210
|
def __authentification_state_reset__(self):
|
205
|
211
|
logger.info("%s Resetting authentification state to AUTH_STATE_UNKNOWN_CLIENT", self.LOG_PREFIX)
|
206
|
212
|
self.__authentification_state__ = self.AUTH_STATE_UNKNOWN_CLIENT
|
|
@@ -468,8 +474,8 @@ class pure_json_protocol(struct_json_protocol):
|
468
|
474
|
|
469
|
475
|
.. literalinclude:: ../../socket_protocol/_examples_/socket_protocol__pure_json_protocol_client.log
|
470
|
476
|
"""
|
471
|
|
- def __init__(self, comm_instance, secret=None):
|
472
|
|
- struct_json_protocol.__init__(self, comm_instance, secret)
|
|
477
|
+ def __init__(self, *args, **kwargs):
|
|
478
|
+ struct_json_protocol.__init__(self, *args, **kwargs)
|
473
|
479
|
|
474
|
480
|
def __build_frame__(self, service_id, data_id, data, status=struct_json_protocol.STATUS_OKAY):
|
475
|
481
|
data_frame = json.dumps(self.__mk_msg__(status, service_id, data_id, data))
|