|
|
|
|
180
|
AUTH_STATE_KEY_TRANSFERRED: 'Key has been sent',
|
180
|
AUTH_STATE_KEY_TRANSFERRED: 'Key has been sent',
|
181
|
AUTH_STATE_TRUSTED_CLIENT: 'Trusted Client'}
|
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
|
self.__secret__ = secret
|
184
|
self.__secret__ = secret
|
|
|
185
|
+ self.__auto_auth__ = auto_auth
|
185
|
self.__clean_receive_buffer__()
|
186
|
self.__clean_receive_buffer__()
|
186
|
self.__callbacks__ = callback_storage()
|
187
|
self.__callbacks__ = callback_storage()
|
187
|
self.__callbacks__.add(self.SID_AUTH_SEED_REQUEST, 0, self.__authentificate_create_seed__)
|
188
|
self.__callbacks__.add(self.SID_AUTH_SEED_REQUEST, 0, self.__authentificate_create_seed__)
|
|
|
|
|
192
|
self.__seed__ = None
|
193
|
self.__seed__ = None
|
193
|
self.__comm_inst__ = comm_instance
|
194
|
self.__comm_inst__ = comm_instance
|
194
|
self.__comm_inst__.register_callback(self.__data_available_callback__)
|
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
|
self.__comm_inst__.register_disconnect_callback(self.__authentification_state_reset__)
|
197
|
self.__comm_inst__.register_disconnect_callback(self.__authentification_state_reset__)
|
197
|
|
198
|
|
198
|
def is_connected(self):
|
199
|
def is_connected(self):
|
|
|
|
|
201
|
def reconnect(self):
|
202
|
def reconnect(self):
|
202
|
return self.__comm_inst__.reconnect()
|
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
|
def __authentification_state_reset__(self):
|
210
|
def __authentification_state_reset__(self):
|
205
|
logger.info("%s Resetting authentification state to AUTH_STATE_UNKNOWN_CLIENT", self.LOG_PREFIX)
|
211
|
logger.info("%s Resetting authentification state to AUTH_STATE_UNKNOWN_CLIENT", self.LOG_PREFIX)
|
206
|
self.__authentification_state__ = self.AUTH_STATE_UNKNOWN_CLIENT
|
212
|
self.__authentification_state__ = self.AUTH_STATE_UNKNOWN_CLIENT
|
|
|
|
|
468
|
|
474
|
|
469
|
.. literalinclude:: ../../socket_protocol/_examples_/socket_protocol__pure_json_protocol_client.log
|
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
|
def __build_frame__(self, service_id, data_id, data, status=struct_json_protocol.STATUS_OKAY):
|
480
|
def __build_frame__(self, service_id, data_id, data, status=struct_json_protocol.STATUS_OKAY):
|
475
|
data_frame = json.dumps(self.__mk_msg__(status, service_id, data_id, data))
|
481
|
data_frame = json.dumps(self.__mk_msg__(status, service_id, data_id, data))
|