Selaa lähdekoodia

Release fdca73452a; Documentation and Restructuration

master
Dirk Alders 4 vuotta sitten
vanhempi
commit
35d9f688a4

+ 335
- 209
__init__.py Näytä tiedosto

@@ -15,12 +15,13 @@ socket_protocol (Socket Protocol)
15 15
 
16 16
 **Submodules:**
17 17
 
18
+* :class:`socket_protocol.data_storage`
18 19
 * :class:`socket_protocol.pure_json_protocol`
19 20
 * :class:`socket_protocol.struct_json_protocol`
20 21
 
21 22
 **Unittest:**
22 23
 
23
-        See also the :download:`unittest <../pylibs/socket_protocol/_testresults_/unittest.pdf>` documentation.
24
+        See also the :download:`unittest <socket_protocol/_testresults_/unittest.pdf>` documentation.
24 25
 
25 26
 **Module Documentation:**
26 27
 
@@ -52,12 +53,80 @@ For more Information read the sphinx documentation.""" % __name__.replace('_', '
52 53
 __INTERPRETER__ = (2, 3)
53 54
 """The Tested Interpreter-Versions"""
54 55
 
56
+SID_AUTH_REQUEST = 0
57
+"""SID for authentification request"""
58
+SID_AUTH_RESPONSE = 1
59
+"""SID for authentification response"""
60
+DID_AUTH_SEED = 0
61
+"""DID for authentification (seed)"""
62
+DID_AUTH_KEY = 1
63
+"""DID for authentification (key)"""
64
+SID_CHANNEL_NAME_REQUEST = 8
65
+"""SID for channel name exchange request """
66
+SID_CHANNEL_NAME_RESPONSE = 9
67
+"""SID for channel name exchange response"""
68
+DID_CHANNEL_NAME = 0
69
+"""DID for channel name """
70
+SID_READ_REQUEST = 10
71
+"""SID for a read data request"""
72
+SID_READ_RESPONSE = 11
73
+"""SID for read data response"""
74
+SID_WRITE_REQUEST = 20
75
+"""SID for a write data request"""
76
+SID_WRITE_RESPONSE = 21
77
+"""SID for a write data response"""
78
+SID_EXECUTE_REQUEST = 30
79
+"""SID for a execute request"""
80
+SID_EXECUTE_RESPONSE = 31
81
+"""SID for a execute response"""
82
+
83
+STATUS_OKAY = 0
84
+"""Status for 'okay'"""
85
+STATUS_BUFFERING_UNHANDLED_REQUEST = 1
86
+"""Status for 'unhandled request'"""
87
+STATUS_CALLBACK_ERROR = 2
88
+"""Status for 'callback errors'"""
89
+STATUS_AUTH_REQUIRED = 3
90
+"""Status for 'authentification is required'"""
91
+STATUS_SERVICE_OR_DATA_UNKNOWN = 4
92
+"""Status for 'service or data unknown'"""
93
+STATUS_CHECKSUM_ERROR = 5
94
+"""Status for 'checksum error'"""
95
+STATUS_OPERATION_NOT_PERMITTED = 6
96
+"""Status for 'operation not permitted'"""
97
+
98
+AUTH_STATE_UNTRUSTED_CONNECTION = 0
99
+"""Authentification Status for an 'Untrusted Connection'"""
100
+AUTH_STATE_SEED_REQUESTED = 1
101
+"""Authentification Status for 'Seed was requested'"""
102
+AUTH_STATE_SEED_TRANSFERRED = 2
103
+"""Authentification Status for 'Seed has been sent'"""
104
+AUTH_STATE_KEY_TRANSFERRED = 3
105
+"""Authentification Status for 'Key has been sent'"""
106
+AUTH_STATE_TRUSTED_CONNECTION = 4
107
+"""Authentification Status for a 'Trusted Connection'"""
108
+AUTH_STATE__NAMES = {AUTH_STATE_UNTRUSTED_CONNECTION: 'Untrusted Connection',
109
+                     AUTH_STATE_SEED_REQUESTED: 'Seed was requested',
110
+                     AUTH_STATE_SEED_TRANSFERRED: 'Seed has been sent',
111
+                     AUTH_STATE_KEY_TRANSFERRED: 'Key has been sent',
112
+                     AUTH_STATE_TRUSTED_CONNECTION: 'Trusted Connection'}
113
+"""Authentification Status names for previous defined authentification states"""
114
+
115
+
116
+class RequestSidExistsError(Exception):
117
+    pass
118
+
119
+
120
+class ResponseSidExistsError(Exception):
121
+    pass
122
+
55 123
 
56 124
 class _callback_storage(dict):
57 125
     DEFAULT_CHANNEL_NAME = 'all_others'
58 126
 
59
-    def __init__(self, channel_name):
127
+    def __init__(self, channel_name, log_prefix):
60 128
         self.init_channel_name(channel_name)
129
+        self.__log_prefix__ = log_prefix
61 130
         dict.__init__(self)
62 131
 
63 132
     def init_channel_name(self, channel_name):
@@ -67,31 +136,28 @@ class _callback_storage(dict):
67 136
             self.logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__ + '.' + channel_name)
68 137
 
69 138
     def get(self, service_id, data_id):
70
-        if service_id is not None and data_id is not None:
71
-            try:
72
-                return self[service_id][data_id]
73
-            except KeyError:
74
-                pass  # nothing to append
75
-        if data_id is not None:
76
-            try:
77
-                return self[None][data_id]
78
-            except KeyError:
79
-                pass  # nothing to append
80
-        if service_id is not None:
81
-            try:
82
-                return self[service_id][None]
83
-            except KeyError:
84
-                pass  # nothing to append
85
-        try:
139
+        if dict.get(self, service_id, {}).get(data_id, None) is not None:
140
+            return self[service_id][data_id]
141
+        elif dict.get(self, service_id, {}).get(None, None) is not None:
142
+            return self[service_id][None]
143
+        elif dict.get(self, None, {}).get(data_id, None) is not None:
144
+            return self[None][data_id]
145
+        elif dict.get(self, None, {}).get(None, None) is not None:
86 146
             return self[None][None]
87
-        except KeyError:
88
-            pass  # nothing to append
89
-        return (None, None, None)
147
+        else:
148
+            return (None, None, None)
90 149
 
91 150
     def add(self, service_id, data_id, callback, *args, **kwargs):
92 151
         cb_data = self.get(service_id, data_id)
93
-        if cb_data != (None, None, None):
94
-            self.logger.warning("Overwriting existing callback %s for service_id (%s) and data_id (%s) to %s!", repr(cb_data[0].__name__), repr(service_id), repr(data_id), repr(callback.__name__))
152
+        if dict.get(self, service_id, {}).get(data_id, None) is not None:
153
+            if callback is None:
154
+                self.logger.warning("%s Deleting existing callback %s for service_id (%s) and data_id (%s)!", self.__log_prefix__(), repr(cb_data[0].__name__), repr(service_id), repr(data_id))
155
+                del(self[service_id][data_id])
156
+                return
157
+            else:
158
+                self.logger.warning("%s Overwriting existing callback %s for service_id (%s) and data_id (%s) to %s!", self.__log_prefix__(), repr(cb_data[0].__name__), repr(service_id), repr(data_id), repr(callback.__name__))
159
+        else:
160
+            self.logger.debug("%s Adding callback %s for SID=%s and DID=%s", self.__log_prefix__(), repr(callback.__name__), repr(service_id), repr(data_id))
95 161
         if service_id not in self:
96 162
             self[service_id] = {}
97 163
         self[service_id][data_id] = (callback, args, kwargs)
@@ -99,6 +165,8 @@ class _callback_storage(dict):
99 165
 
100 166
 class data_storage(dict):
101 167
     """
168
+    This is a storage object for socket_protocol messages.
169
+
102 170
     :param status: The message status.
103 171
     :type status: int
104 172
     :param service_id: The Service-ID.
@@ -107,70 +175,74 @@ class data_storage(dict):
107 175
     :type data_id: int
108 176
     :param data: The transfered data.
109 177
     :type data: any
110
-
111
-    This is a storage object for socket_protocol messages.
112 178
     """
113 179
 
114 180
     KEY_STATUS = 'status'
115 181
     KEY_SERVICE_ID = 'service_id'
116 182
     KEY_DATA_ID = 'data_id'
117 183
     KEY_DATA = 'data'
184
+    ALL_KEYS = [KEY_DATA, KEY_DATA_ID, KEY_SERVICE_ID, KEY_STATUS]
118 185
 
119 186
     def __init__(self, *args, **kwargs):
120 187
         dict.__init__(self, *args, **kwargs)
188
+        for key in self.ALL_KEYS:
189
+            if key not in self:
190
+                self[key] = None
121 191
 
122 192
     def get_status(self, default=None):
123 193
         """
124
-        :param default: The default value, if no data is available.
125
-
126 194
         This Method returns the message status.
195
+
196
+        :param default: The default value, if no data is available.
127 197
         """
128 198
         return self.get(self.KEY_STATUS, default)
129 199
 
130 200
     def get_service_id(self, default=None):
131 201
         """
132
-        :param default: The default value, if no data is available.
133
-
134 202
         This Method returns the message Service-ID.
203
+
204
+        :param default: The default value, if no data is available.
135 205
         """
136 206
         return self.get(self.KEY_SERVICE_ID, default)
137 207
 
138 208
     def get_data_id(self, default=None):
139 209
         """
140
-        :param default: The default value, if no data is available.
141
-
142 210
         This Method returns the message Data-ID.
211
+
212
+        :param default: The default value, if no data is available.
143 213
         """
144 214
         return self.get(self.KEY_DATA_ID, default)
145 215
 
146 216
     def get_data(self, default=None):
147 217
         """
148
-        :param default: The default value, if no data is available.
149
-
150 218
         This Method returns the message data.
219
+
220
+        :param default: The default value, if no data is available.
151 221
         """
152 222
         return self.get(self.KEY_DATA, default)
153 223
 
154 224
 
155 225
 class pure_json_protocol(object):
156 226
     """
227
+    This `class` supports to transfer a message and it's data.
228
+
157 229
     :param comm_instance: A communication instance.
158 230
     :type comm_instance: instance
159 231
     :param secret: An optinal secret (e.g. created by ``binascii.hexlify(os.urandom(24))``).
160 232
     :type secret: str
161
-    :param auto_auth: An optional parameter (True) to enable automatic authentification, otherwise you need to do it manually, if needed.
233
+    :param auto_auth: An optional parameter to enable (True) automatic authentification, otherwise you need to do it manually, if needed.
162 234
     :type auto_auth: bool
163 235
     :param channel_name: An optional parameter to set a channel name for logging of the communication.
164 236
     :type channel_name: str
165 237
 
166
-    .. hint:: This `class` supports to transfer a Service-ID, Data-ID and Data.
238
+    .. hint::
167 239
 
168
-        * The Service-ID is designed to identify the type of the communication (e.g. READ_REQUEST, WRITE_REQUEST, READ_RESPONSE, WRITE_RESPONSE, ...)
240
+        * The Service-ID is designed to identify the type of the communication (e.g. :const:`READ_REQUEST`, :const:`WRITE_REQUEST`, :const:`READ_RESPONSE`, :const:`WRITE_RESPONSE`, ...)
169 241
         * The Data-ID is designed to identify the requests / responses using the same Service_ID.
170 242
 
171 243
     .. note:: The :class:`comm_instance` needs to have at least the following interface:
172 244
 
173
-        * A Method :func:`comm_instance.init_channel_name` to set the channel name if needed.
245
+        * A Method :func:`comm_instance.init_channel_name` to set the channel name.
174 246
         * A Constant :const:`comm_instance.IS_CLIENT` to identify that the :class:`comm_instance` is a client (True) or a server (False).
175 247
         * A Method :func:`comm_instance.is_connected` to identify if the instance is connected (True) or not (False).
176 248
         * A Method :func:`comm_instance.reconnect` to initiate a reconnect.
@@ -187,107 +259,60 @@ class pure_json_protocol(object):
187 259
     """
188 260
     DEFAULT_CHANNEL_NAME = 'all_others'
189 261
 
190
-    SID_AUTH_SEED_REQUEST = 1
191
-    """SID for requesting a seed for authentification"""
192
-    SID_AUTH_KEY_REQUEST = 2
193
-    """SID for requesting a key for the given seed"""
194
-    SID_AUTH_KEY_CHECK_REQUEST = 3
195
-    """SID for request for checking a key"""
196
-    SID_AUTH_KEY_CHECK_RESPONSE = 4
197
-    """SID for the authentification response"""
198
-    SID_CHANNEL_NAME_REQUEST = 5
199
-    """SID for requesting a channel name exchange"""
200
-    SID_CHANNEL_NAME_RESPONSE = 6
201
-    """SID for the channel name response"""
202
-    SID_READ_REQUEST = 10
203
-    """SID for a read data request"""
204
-    SID_READ_RESPONSE = 11
205
-    """SID for read data response"""
206
-    SID_WRITE_REQUEST = 20
207
-    """SID for a write data request"""
208
-    SID_WRITE_RESPONSE = 21
209
-    """SID for a write data response"""
210
-    SID_EXECUTE_REQUEST = 30
211
-    """SID for a execute request"""
212
-    SID_EXECUTE_RESPONSE = 31
213
-    """SID for a execute response"""
214
-
215
-    SID__RESPONSE_DICT = {SID_AUTH_SEED_REQUEST: SID_AUTH_KEY_REQUEST,
216
-                          SID_AUTH_KEY_REQUEST: SID_AUTH_KEY_CHECK_REQUEST,
217
-                          SID_AUTH_KEY_CHECK_REQUEST: SID_AUTH_KEY_CHECK_RESPONSE,
218
-                          SID_CHANNEL_NAME_REQUEST: SID_CHANNEL_NAME_RESPONSE,
219
-                          SID_READ_REQUEST: SID_READ_RESPONSE,
220
-                          SID_WRITE_REQUEST: SID_WRITE_RESPONSE,
221
-                          SID_EXECUTE_REQUEST: SID_EXECUTE_RESPONSE}
222
-    """Dictionary to get the SID for the response by the key which is the SID for the request"""
223
-
224
-    SID__NO_AUTH_LIST = [
225
-        SID_AUTH_SEED_REQUEST,
226
-        SID_AUTH_KEY_REQUEST,
227
-        SID_AUTH_KEY_CHECK_REQUEST,
228
-        SID_AUTH_KEY_CHECK_RESPONSE,
229
-        SID_CHANNEL_NAME_REQUEST,
230
-        SID_CHANNEL_NAME_RESPONSE
231
-    ]
232
-    """List of SIDs without need of an authentification"""
233
-
234
-    STATUS_OKAY = 0
235
-    """Status for 'okay'"""
236
-    STATUS_BUFFERING_UNHANDLED_REQUEST = 1
237
-    """Status for 'unhandled request'"""
238
-    STATUS_AUTH_REQUIRED = 2
239
-    """Status for 'authentification is required'"""
240
-    STATUS_SERVICE_OR_DATA_UNKNOWN = 3
241
-    """Status for 'service or data unknown'"""
242
-    STATUS_CHECKSUM_ERROR = 4
243
-    """Status for 'checksum error'"""
244
-    STATUS_OPERATION_NOT_PERMITTED = 5
245
-    """Status for 'operation not permitted'"""
246
-    STATUS__NAMES = {STATUS_OKAY: 'Okay',
247
-                     STATUS_BUFFERING_UNHANDLED_REQUEST: 'Request has no callback. Data buffered.',
248
-                     STATUS_AUTH_REQUIRED: 'Authentification required',
249
-                     STATUS_SERVICE_OR_DATA_UNKNOWN: 'Service or Data unknown',
250
-                     STATUS_CHECKSUM_ERROR: 'Checksum Error',
251
-                     STATUS_OPERATION_NOT_PERMITTED: 'Operation not permitted'}
252
-    """Status names for previous defined states"""
253
-
254
-    AUTH_STATE_UNKNOWN_CLIENT = 0
255
-    """Authentification Status for 'Unknown Client'"""
256
-    AUTH_STATE_SEED_REQUESTED = 1
257
-    """Authentification Status for 'Seed was requested'"""
258
-    AUTH_STATE_SEED_TRANSFERRED = 2
259
-    """Authentification Status for 'Seed has been sent'"""
260
-    AUTH_STATE_KEY_TRANSFERRED = 3
261
-    """Authentification Status for 'Key has been sent'"""
262
-    AUTH_STATE_TRUSTED_CLIENT = 4
263
-    """Authentification Status for 'Trusted Connection'"""
264
-    AUTH_STATE__NAMES = {AUTH_STATE_UNKNOWN_CLIENT: 'Unknown Client',
265
-                         AUTH_STATE_SEED_REQUESTED: 'Seed was requested',
266
-                         AUTH_STATE_SEED_TRANSFERRED: 'Seed has been sent',
267
-                         AUTH_STATE_KEY_TRANSFERRED: 'Key has been sent',
268
-                         AUTH_STATE_TRUSTED_CLIENT: 'Trusted Connection'}
269
-    """Authentification Status names for previous defined authentification states"""
270
-
271 262
     def __init__(self, comm_instance, secret=None, auto_auth=False, channel_name=None):
272 263
         self.__comm_inst__ = comm_instance
273 264
         self.__secret__ = secret
274 265
         self.__auto_auth__ = auto_auth
275 266
         #
276
-        self.__callbacks__ = _callback_storage(channel_name)
267
+        self.__auth_whitelist__ = {}
268
+        self.__sid_response_dict__ = {}
269
+        self.__sid_name_dict__ = {}
270
+        self.__did_name_dict__ = {}
271
+        #
272
+        self.__status_name_dict = {}
273
+        self.add_status(STATUS_OKAY, 'okay')
274
+        self.add_status(STATUS_BUFFERING_UNHANDLED_REQUEST, 'no callback for service, data buffered.')
275
+        self.add_status(STATUS_CALLBACK_ERROR, 'callback error.')
276
+        self.add_status(STATUS_AUTH_REQUIRED, 'authentification required')
277
+        self.add_status(STATUS_SERVICE_OR_DATA_UNKNOWN, 'service or data unknown')
278
+        self.add_status(STATUS_CHECKSUM_ERROR, 'checksum error')
279
+        self.add_status(STATUS_OPERATION_NOT_PERMITTED, 'operation not permitted')
280
+        #
281
+        self.__callbacks__ = _callback_storage(channel_name, self.__log_prefix__)
277 282
         self.__init_channel_name__(channel_name)
278 283
         #
279 284
         self.__clean_receive_buffer__()
280
-        self.__callbacks__.add(self.SID_AUTH_SEED_REQUEST, 0, self.__authentificate_create_seed__)
281
-        self.__callbacks__.add(self.SID_AUTH_KEY_REQUEST, 0, self.__authentificate_create_key__)
282
-        self.__callbacks__.add(self.SID_AUTH_KEY_CHECK_REQUEST, 0, self.__authentificate_check_key__)
283
-        self.__callbacks__.add(self.SID_AUTH_KEY_CHECK_RESPONSE, 0, self.__authentificate_process_feedback__)
284
-        self.__callbacks__.add(self.SID_CHANNEL_NAME_REQUEST, 0, self.__channel_name_request__)
285
-        self.__callbacks__.add(self.SID_CHANNEL_NAME_RESPONSE, 0, self.__channel_name_response__)
285
+
286
+        self.add_service(SID_AUTH_REQUEST, SID_AUTH_RESPONSE, 'authentification request', 'authentification response')
287
+        self.add_data((SID_AUTH_REQUEST, SID_AUTH_RESPONSE), DID_AUTH_SEED, 'seed')
288
+        self.add_data(SID_AUTH_REQUEST, DID_AUTH_KEY, 'key')
289
+        self.add_data(SID_AUTH_RESPONSE, DID_AUTH_KEY, 'key')
290
+        self.add_msg_to_auth_whitelist_(SID_AUTH_REQUEST, DID_AUTH_SEED)
291
+        self.add_msg_to_auth_whitelist_(SID_AUTH_RESPONSE, DID_AUTH_SEED)
292
+        self.add_msg_to_auth_whitelist_(SID_AUTH_REQUEST, DID_AUTH_KEY)
293
+        self.add_msg_to_auth_whitelist_(SID_AUTH_RESPONSE, DID_AUTH_KEY)
294
+        self.__callbacks__.add(SID_AUTH_REQUEST, DID_AUTH_SEED, self.__authentificate_create_seed__)
295
+        self.__callbacks__.add(SID_AUTH_RESPONSE, DID_AUTH_SEED, self.__authentificate_create_key__)
296
+        self.__callbacks__.add(SID_AUTH_REQUEST, DID_AUTH_KEY, self.__authentificate_check_key__)
297
+        self.__callbacks__.add(SID_AUTH_RESPONSE, DID_AUTH_KEY, self.__authentificate_process_feedback__)
286 298
         self.__authentification_state_reset__()
299
+
300
+        self.add_service(SID_CHANNEL_NAME_REQUEST, SID_CHANNEL_NAME_RESPONSE, 'channel name request', 'channel name response')
301
+        self.add_data((SID_CHANNEL_NAME_REQUEST, SID_CHANNEL_NAME_RESPONSE), DID_CHANNEL_NAME, 'name')
302
+        self.add_msg_to_auth_whitelist_(SID_CHANNEL_NAME_REQUEST, DID_CHANNEL_NAME)
303
+        self.add_msg_to_auth_whitelist_(SID_CHANNEL_NAME_RESPONSE, DID_CHANNEL_NAME)
304
+        self.__callbacks__.add(SID_CHANNEL_NAME_REQUEST, DID_CHANNEL_NAME, self.__channel_name_request__)
305
+        self.__callbacks__.add(SID_CHANNEL_NAME_RESPONSE, DID_CHANNEL_NAME, self.__channel_name_response__)
306
+
307
+        self.add_service(SID_READ_REQUEST, SID_READ_RESPONSE, 'read data request', 'read data response')
308
+        self.add_service(SID_WRITE_REQUEST, SID_WRITE_RESPONSE, 'write data request', 'write data response')
309
+        self.add_service(SID_EXECUTE_REQUEST, SID_EXECUTE_RESPONSE, 'execute request', 'execute response')
310
+
287 311
         self.__seed__ = None
288 312
         self.__comm_inst__.register_callback(self.__data_available_callback__)
289 313
         self.__comm_inst__.register_connect_callback(self.__connection_established__)
290 314
         self.__comm_inst__.register_disconnect_callback(self.__authentification_state_reset__)
315
+        logger.info('%s Initialisation finished.', self.__log_prefix__())
291 316
 
292 317
     def __analyse_frame__(self, frame):
293 318
         if sys.version_info >= (3, 0):
@@ -298,39 +323,35 @@ class pure_json_protocol(object):
298 323
     def __authentificate_check_key__(self, msg):
299 324
         key = msg.get_data()
300 325
         if key == self.__authentificate_salt_and_hash__(self.__seed__):
301
-            self.__authentification_state__ = self.AUTH_STATE_TRUSTED_CLIENT
302
-            self.logger.info("%s Got correct key, sending positive authentification feedback", self.__log_prefix__())
303
-            return self.STATUS_OKAY, True
326
+            self.__authentification_state__ = AUTH_STATE_TRUSTED_CONNECTION
327
+            return STATUS_OKAY, True
304 328
         else:
305
-            self.__authentification_state__ = self.AUTH_STATE_UNKNOWN_CLIENT
306
-            self.logger.info("%s Got incorrect key, sending negative authentification feedback", self.__log_prefix__())
307
-            return self.STATUS_OKAY, False
329
+            self.__authentification_state__ = AUTH_STATE_UNTRUSTED_CONNECTION
330
+            return STATUS_OKAY, False
308 331
 
309 332
     def __authentificate_create_key__(self, msg):
310
-        self.logger.info("%s Got seed, sending key for authentification", self.__log_prefix__())
311
-        self.__authentification_state__ = self.AUTH_STATE_KEY_TRANSFERRED
333
+        self.__authentification_state__ = AUTH_STATE_KEY_TRANSFERRED
312 334
         seed = msg.get_data()
313 335
         key = self.__authentificate_salt_and_hash__(seed)
314
-        return self.STATUS_OKAY, key
336
+        self.send(SID_AUTH_REQUEST, DID_AUTH_KEY, key)
315 337
 
316 338
     def __authentificate_create_seed__(self, msg):
317
-        self.logger.info("%s Got seed request, sending seed for authentification", self.__log_prefix__())
318
-        self.__authentification_state__ = self.AUTH_STATE_SEED_TRANSFERRED
339
+        self.__authentification_state__ = AUTH_STATE_SEED_TRANSFERRED
319 340
         if sys.version_info >= (3, 0):
320 341
             self.__seed__ = binascii.hexlify(os.urandom(32)).decode('utf-8')
321 342
         else:
322 343
             self.__seed__ = binascii.hexlify(os.urandom(32))
323
-        return self.STATUS_OKAY, self.__seed__
344
+        return STATUS_OKAY, self.__seed__
324 345
 
325 346
     def __authentificate_process_feedback__(self, msg):
326 347
         feedback = msg.get_data()
327 348
         if feedback:
328
-            self.__authentification_state__ = self.AUTH_STATE_TRUSTED_CLIENT
349
+            self.__authentification_state__ = AUTH_STATE_TRUSTED_CONNECTION
329 350
             self.logger.info("%s Got positive authentification feedback", self.__log_prefix__())
330 351
         else:
331
-            self.__authentification_state__ = self.AUTH_STATE_UNKNOWN_CLIENT
352
+            self.__authentification_state__ = AUTH_STATE_UNTRUSTED_CONNECTION
332 353
             self.logger.warning("%s Got negative authentification feedback", self.__log_prefix__())
333
-        return self.STATUS_OKAY, None
354
+        return STATUS_OKAY, None
334 355
 
335 356
     def __authentificate_salt_and_hash__(self, seed):
336 357
         if sys.version_info >= (3, 0):
@@ -339,8 +360,11 @@ class pure_json_protocol(object):
339 360
             return hashlib.sha512(seed.encode('utf-8') + self.__secret__.encode('utf-8')).hexdigest()
340 361
 
341 362
     def __authentification_state_reset__(self):
342
-        self.logger.info("%s Resetting authentification state to AUTH_STATE_UNKNOWN_CLIENT", self.__log_prefix__())
343
-        self.__authentification_state__ = self.AUTH_STATE_UNKNOWN_CLIENT
363
+        self.logger.info("%s Resetting authentification state to AUTH_STATE_UNTRUSTED_CONNECTION", self.__log_prefix__())
364
+        self.__authentification_state__ = AUTH_STATE_UNTRUSTED_CONNECTION
365
+
366
+    def __authentification_required__(self, service_id, data_id):
367
+        return data_id not in self.__auth_whitelist__.get(service_id, [])
344 368
 
345 369
     def __buffer_received_data__(self, msg):
346 370
         if not msg.get_service_id() in self.__msg_buffer__:
@@ -371,12 +395,12 @@ class pure_json_protocol(object):
371 395
         if self.__channel_name__ is None and data is not None:
372 396
             self.__init_channel_name__(data)
373 397
             self.logger.info('%s channel name is now %s', self.__log_prefix__(), repr(self.__channel_name__))
374
-        return self.STATUS_OKAY, None
398
+        return STATUS_OKAY, None
375 399
 
376 400
     def __channel_name_request__(self, msg):
377 401
         data = msg.get_data()
378 402
         if data is None:
379
-            return self.STATUS_OKAY, self.__channel_name__
403
+            return STATUS_OKAY, self.__channel_name__
380 404
         else:
381 405
             prev_channel_name = self.__channel_name__
382 406
             self.__init_channel_name__(data)
@@ -384,7 +408,7 @@ class pure_json_protocol(object):
384 408
                 self.logger.warning('%s overwriting user defined channel name from %s to %s', self.__log_prefix__(), repr(prev_channel_name), repr(data))
385 409
             elif prev_channel_name is None:
386 410
                 self.logger.info('%s channel name is now %s', self.__log_prefix__(), repr(self.__channel_name__))
387
-            return self.STATUS_OKAY, None
411
+            return STATUS_OKAY, None
388 412
 
389 413
     def __check_frame_checksum__(self, frame):
390 414
         return self.__calc_chksum__(frame[:-4]) == frame[-4:]
@@ -393,63 +417,77 @@ class pure_json_protocol(object):
393 417
         self.logger.debug("%s Cleaning up receive-buffer", self.__log_prefix__())
394 418
         self.__msg_buffer__ = {}
395 419
 
420
+    def __connection_established__(self):
421
+        self.__clean_receive_buffer__()
422
+        if self.__comm_inst__.IS_CLIENT:
423
+            self.send(SID_CHANNEL_NAME_REQUEST, 0, self.__channel_name__)
424
+        if self.__auto_auth__ and self.__comm_inst__.IS_CLIENT and self.__secret__ is not None:
425
+            self.authentificate()
426
+
396 427
     def __data_available_callback__(self, comm_inst):
397 428
         frame = comm_inst.receive()
429
+        msg = self.__analyse_frame__(frame)
398 430
         if not self.__check_frame_checksum__(frame):
399
-            self.logger.warning("%s Received message has a wrong checksum and will be ignored: %s.", self.__log_prefix__(), stringtools.hexlify(frame))
431
+            # Wrong Checksum
432
+            self.logger.warning("%s RX <- Received message has a wrong checksum. Message will be ignored.", self.__log_prefix__())
433
+            return  # No response needed
434
+        elif not self.check_authentification_state() and self.__authentification_required__(msg.get_service_id(), msg.get_data_id()):
435
+            # Authentification required
436
+            if msg.get_service_id() in self.__sid_response_dict__.keys():
437
+                self.logger.warning("%s RX <- Authentification is required. Just sending negative response.", self.__log_prefix__())
438
+                status = STATUS_AUTH_REQUIRED
439
+                data = None
440
+            else:
441
+                self.logger.warning("%s RX <- Authentification is required. Message will be ignored.", self.__log_prefix__())
442
+                return  # No response needed
400 443
         else:
401
-            msg = self.__analyse_frame__(frame)
444
+            # Valid message
402 445
             self.logger.info(
403
-                '%s RX <- status: %s, service_id: %s, data_id: %s, data: "%s"',
446
+                '%s RX <- %s, %s, data: "%s"',
404 447
                 self.__log_prefix__(),
405
-                repr(msg.get_status()),
406
-                repr(msg.get_service_id()),
407
-                repr(msg.get_data_id()),
448
+                self.__get_message_name__(msg.get_service_id(), msg.get_data_id()),
449
+                self.__get_status_name__(msg.get_status()),
408 450
                 repr(msg.get_data())
409 451
             )
452
+            if msg.get_status() not in [STATUS_OKAY]:
453
+                self.logger.warning("%s RX <- Message has a peculiar status: %s", self.__log_prefix__(), self.__get_status_name__(msg.get_status()))
410 454
             callback, args, kwargs = self.__callbacks__.get(msg.get_service_id(), msg.get_data_id())
411
-            if msg.get_service_id() in self.SID__RESPONSE_DICT.keys():
455
+            if msg.get_service_id() in self.__sid_response_dict__.keys():
412 456
                 #
413 457
                 # REQUEST RECEIVED
414 458
                 #
415
-                if self.__secret__ is not None and not self.check_authentification_state() and msg.get_service_id() not in self.SID__NO_AUTH_LIST:
416
-                    status = self.STATUS_AUTH_REQUIRED
417
-                    data = None
418
-                    self.logger.warning("%s Received message needs authentification: %s. Sending negative response.", self.__log_prefix__(), self.AUTH_STATE__NAMES.get(self.__authentification_state__, 'Unknown authentification status!'))
419
-                elif callback is None:
420
-                    self.logger.warning("%s Received message with no registered callback. Sending negative response.", self.__log_prefix__())
421
-                    status = self.STATUS_BUFFERING_UNHANDLED_REQUEST
459
+                if callback is None:
460
+                    self.logger.warning("%s RX <- Message with no registered callback. Sending negative response.", self.__log_prefix__())
461
+                    status = STATUS_BUFFERING_UNHANDLED_REQUEST
422 462
                     data = None
423 463
                 else:
424 464
                     try:
425
-                        self.logger.debug("%s Executing callback %s to process received data", self.__log_prefix__(), callback.__name__)
465
+                        self.logger.debug("%s RX <- Executing callback %s to process received data", self.__log_prefix__(), callback.__name__)
426 466
                         status, data = callback(msg, *args, **kwargs)
427
-                    except TypeError:
428
-                        raise TypeError('Check return value of callback function {callback_name} for service_id  {service_id} and data_id {data_id}'.format(callback_name=callback.__name__, service_id=repr(msg.get_service_id()), data_id=repr(msg.get_data_id())))
429
-                self.send(self.SID__RESPONSE_DICT[msg.get_service_id()], msg.get_data_id(), data, status=status)
467
+                    except Exception:
468
+                        logger.error('{lp} RX <- Exception raised. Check callback {callback_name} and it\'s return values for service_id  {service_id} and data_id {data_id}'.format(lp=self.__log_prefix__(), callback_name=callback.__name__, service_id=repr(msg.get_service_id()), data_id=repr(msg.get_data_id())))
469
+                        status = STATUS_CALLBACK_ERROR
470
+                        data = None
430 471
             else:
431 472
                 #
432 473
                 # RESPONSE RECEIVED
433 474
                 #
434
-                if msg.get_status() not in [self.STATUS_OKAY]:
435
-                    self.logger.warning("%s Received message has a peculiar status: %s", self.__log_prefix__(), self.STATUS__NAMES.get(msg.get_status(), 'Unknown status response!'))
436 475
                 if callback is None:
437
-                    status = self.STATUS_OKAY
438
-                    data = None
439 476
                     self.__buffer_received_data__(msg)
440 477
                 else:
441
-                    try:
442
-                        self.logger.debug("%s Executing callback %s to process received data", self.__log_prefix__(), callback.__name__)
443
-                        status, data = callback(msg, *args, **kwargs)
444
-                    except TypeError:
445
-                        raise TypeError('Check return value of callback function {callback_name} for service_id  {service_id} and data_id {data_id}'.format(callback_name=callback.__name__, service_id=repr(msg.get_service_id()), data_id=repr(msg.get_data_id())))
478
+                    self.logger.debug("%s Executing callback %s to process received data", self.__log_prefix__(), callback.__name__)
479
+                    callback(msg, *args, **kwargs)
480
+                return  # No response needed
481
+        self.send(self.__sid_response_dict__[msg.get_service_id()], msg.get_data_id(), data, status=status)
446 482
 
447
-    def __connection_established__(self):
448
-        self.__clean_receive_buffer__()
449
-        if not self.__comm_inst__.IS_CLIENT:
450
-            self.send(self.SID_CHANNEL_NAME_REQUEST, 0, self.__channel_name__)
451
-        if self.__auto_auth__ and self.__comm_inst__.IS_CLIENT and self.__secret__ is not None:
452
-            self.authentificate()
483
+    def __get_message_name__(self, service_id, data_id):
484
+        return 'service: %s, data_id: %s' % (
485
+            self.__sid_name_dict__.get(service_id, repr(service_id)),
486
+            self.__did_name_dict__.get(service_id, {}).get(data_id, repr(data_id)),
487
+        )
488
+
489
+    def __get_status_name__(self, status):
490
+        return 'status: %s' % (self.__status_name_dict.get(status, 'unknown status: %s' % repr(status)))
453 491
 
454 492
     def __init_channel_name__(self, channel_name):
455 493
         self.__comm_inst__.init_channel_name(channel_name)
@@ -460,47 +498,119 @@ class pure_json_protocol(object):
460 498
             self.logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__ + '.' + channel_name)
461 499
 
462 500
     def __log_prefix__(self):
463
-        return ' SP client:' if self.__comm_inst__.IS_CLIENT else ' SP server:'
501
+        return 'SP client:' if self.__comm_inst__.IS_CLIENT else 'SP server:'
464 502
 
465 503
     def __mk_msg__(self, status, service_id, data_id, data):
466 504
         return data_storage({data_storage.KEY_DATA_ID: data_id, data_storage.KEY_SERVICE_ID: service_id, data_storage.KEY_STATUS: status, data_storage.KEY_DATA: data})
467 505
 
506
+    def add_data(self, service_id, data_id, name):
507
+        """
508
+        Method to add a name for a specific message.
509
+
510
+        :param service_id: The Service-ID of the message. See class definitions starting with ``SID_``.
511
+        :type service_id: int or list of ints
512
+        :param data_id: The Data-ID of the message.
513
+        :type data_id: int
514
+        :param name: The Name for the transfered message.
515
+        :type name: str
516
+        """
517
+        try:
518
+            iter(service_id)
519
+        except Exception:
520
+            service_id = (service_id, )
521
+
522
+        for sid in service_id:
523
+            if sid not in self.__did_name_dict__:
524
+                self.__did_name_dict__[sid] = {}
525
+            self.__did_name_dict__[sid][data_id] = name
526
+
527
+    def add_msg_to_auth_whitelist_(self, service_id, data_id):
528
+        """
529
+        Method to add a specific message to the list, where no authentification is required.
530
+
531
+        :param service_id: The Service-ID of the message. See class definitions starting with ``SID_``.
532
+        :type service_id: int
533
+        :param data_id: The Data-ID of the message.
534
+        :type data_id: int
535
+        """
536
+        if service_id not in self.__auth_whitelist__:
537
+            self.__auth_whitelist__[service_id] = []
538
+        self.__auth_whitelist__[service_id].append(data_id)
539
+        logger.debug('%s Adding Message (%s) to the authentification whitelist', self.__log_prefix__(), self.__get_message_name__(service_id, data_id))
540
+
541
+    def add_service(self, req_sid, resp_sid, req_name=None, resp_name=None):
542
+        """
543
+        Method to add a Service defined by Request- and Response Serivce-ID.
544
+
545
+        :param req_sid: The Request Service-ID.
546
+        :type req_sid: int
547
+        :param resp_sid: The Response Service-ID.
548
+        :type resp_sid: int
549
+        """
550
+        if req_sid in self.__sid_response_dict__:
551
+            logger.error('%s Service with Request-SID=%d and Response-SID=%d not added, because request SID is already registered', self.__log_prefix__(), req_sid, resp_sid)
552
+            raise RequestSidExistsError("Request for this Service is already registered")
553
+        elif resp_sid in self.__sid_response_dict__.values():
554
+            logger.error('%s Service with Request-SID=%d and Response-SID=%d not added, because response SID is already registered', self.__log_prefix__(), req_sid, resp_sid)
555
+            raise ResponseSidExistsError("Response for this Service is already registered")
556
+        else:
557
+            self.__sid_response_dict__[req_sid] = resp_sid
558
+            if req_name is not None:
559
+                self.__sid_name_dict__[req_sid] = req_name
560
+            if resp_name is not None:
561
+                self.__sid_name_dict__[resp_sid] = resp_name
562
+            logger.debug('%s Adding Service with Request=%s and Response=%s', self.__log_prefix__(), req_name or repr(req_sid), resp_name or repr(resp_sid))
563
+
564
+    def add_status(self, status, name):
565
+        """
566
+        Method to add a name for a status.
567
+
568
+        :param status: The Status. See class definitions starting with ``STATUS_``.
569
+        :type status: int
570
+        :param name: The Name for the Status.
571
+        :type name: str
572
+        """
573
+        self.__status_name_dict[status] = name
574
+
468 575
     def authentificate(self, timeout=2):
469 576
         """
577
+        This method authetificates the client at the server.
578
+
470 579
         :param timeout: The timeout for the authentification (requesting seed, sending key and getting authentification_feedback).
471 580
         :type timeout: float
472 581
         :returns: True, if authentification was successfull; False, if not.
473 582
         :rtype: bool
474 583
 
475
-        This method authetificates the client at the server.
476
-
477 584
         .. note:: An authentification will only processed, if a secret had been given on initialisation.
478 585
 
479 586
         .. note:: Client and Server needs to use the same secret.
480 587
         """
481 588
         if self.__secret__ is not None:
482
-            self.__authentification_state__ = self.AUTH_STATE_SEED_REQUESTED
483
-            self.logger.info("%s Requesting seed for authentification", self.__log_prefix__())
484
-            self.send(self.SID_AUTH_SEED_REQUEST, 0, None)
589
+            self.__authentification_state__ = AUTH_STATE_SEED_REQUESTED
590
+            self.send(SID_AUTH_REQUEST, DID_AUTH_SEED, None)
485 591
             cnt = 0
486 592
             while cnt < timeout * 10:
487 593
                 time.sleep(0.1)
488
-                if self.__authentification_state__ == self.AUTH_STATE_TRUSTED_CLIENT:
594
+                if self.__authentification_state__ == AUTH_STATE_TRUSTED_CONNECTION:
489 595
                     return True
490
-                elif self.__authentification_state__ == self.AUTH_STATE_UNKNOWN_CLIENT:
596
+                elif self.__authentification_state__ == AUTH_STATE_UNTRUSTED_CONNECTION:
491 597
                     break
492 598
                 cnt += 1
493 599
         return False
494 600
 
495 601
     def check_authentification_state(self):
496 602
         """
603
+        This Method return the Authitification State as boolean value.
604
+
497 605
         :return: True, if authentification state is okay, otherwise False
498 606
         :rtype: bool
499 607
         """
500
-        return self.__authentification_state__ == self.AUTH_STATE_TRUSTED_CLIENT
608
+        return self.__secret__ is None or self.__authentification_state__ == AUTH_STATE_TRUSTED_CONNECTION
501 609
 
502 610
     def connection_established(self):
503 611
         """
612
+        This Method returns the Connection state including authentification as a boolean value.
613
+
504 614
         :return: True, if the connection is established (incl. authentification, if a secret has been given)
505 615
         :rtype: bool
506 616
         """
@@ -508,15 +618,17 @@ class pure_json_protocol(object):
508 618
 
509 619
     def is_connected(self):
510 620
         """
621
+        This Methods returns Connection state of the Communication Instance :func:`comm_instance.is_connected`.
622
+
511 623
         :return: True if the :class:`comm_instance` is connected, otherwise False..
512 624
         :rtype: bool
513
-
514
-        This methods returns the return value of :func:`comm_instance.is_connected`.
515 625
         """
516 626
         return self.__comm_inst__.is_connected()
517 627
 
518 628
     def receive(self, service_id, data_id, timeout=1):
519 629
         """
630
+        This Method returns a message object for a defined message or None, if this message is not available after the given timout.
631
+
520 632
         :param service_id: The Service-ID for the message. See class definitions starting with ``SID_``.
521 633
         :type service_id: int
522 634
         :param data_id: The Data-ID for the message.
@@ -547,37 +659,44 @@ class pure_json_protocol(object):
547 659
 
548 660
     def register_callback(self, service_id, data_id, callback, *args, **kwargs):
549 661
         """
662
+        This method registers a callback for the given parameters. Giving ``None`` means, that all Service-IDs or all Data-IDs are used.
663
+        If a message hitting these parameters has been received, the callback will be executed.
664
+
550 665
         :param service_id: The Service-ID for the message. See class definitions starting with ``SID_``.
551 666
         :type service_id: int
552 667
         :param data_id: The Data-ID for the message.
553 668
         :type data_id: int
554
-        :returns: True, if registration was successfull; False, if registration failed (e.g. existance of a callback for this configuration)
555
-        :rtype: bool
556
-
557
-        This method registers a callback for the given parameters. Givin ``None`` means, that all Service-IDs or all Data-IDs are used.
558
-        If a message hitting these parameters has been received, the callback will be executed.
559 669
 
560 670
         .. note:: The :func:`callback` is priorised in the following order:
561 671
 
562 672
             * Callbacks with defined Service-ID and Data-ID.
563
-            * Callbacks with a defined Data-ID.
564
-            * Callbacks with a defined Service-ID.
565
-            * Unspecific Callbacks
673
+            * Callbacks with a defined Service-ID and all Data-IDs.
674
+            * Callbacks with a defined Data-ID and all Service-IDs.
675
+            * Unspecific Callbacks.
566 676
 
567 677
         .. note:: The :func:`callback` is executed with these arguments:
568 678
 
569
-            :param msg: A :class:`data_storage` object containing all message information.
570
-            :returns: (:const:`status`, :const:`response_data`)
679
+            **Parameters given at the callback call:**
571 680
 
572
-            * :const:`status`: A status as defined as a constant of this class :const:`STA_*` to be used as status for the response.
681
+            * The first Arguments is the received message as :class:`data_storage` object.
682
+            * Further arguments given at registration.
683
+            * Further keyword arguments given at registration.
684
+
685
+            **Return value of the callback:**
686
+
687
+            If the Callback is a Request Callback for a registered Service, the return value has to be a tuple or list with
688
+
689
+            * :const:`response_status`: The response status (see class definitions starting with :const:`STA_*`.
573 690
             * :const:`response_data`: A JSON iterable object to be used as data for the response.
574 691
 
575
-        .. note:: Only callbacks defined in :const:`pure_json_protocol.SID__RESPONSE_DICT` will send a response, using a Service-ID given in the dict and the same Data-ID to the client.
692
+        .. note:: Only registered services will respond via the callbacks return values with the same data_id.
576 693
         """
577 694
         self.__callbacks__.add(service_id, data_id, callback, *args, **kwargs)
578 695
 
579
-    def send(self, service_id, data_id, data, status=STATUS_OKAY, timeout=2, log_lvl=logging.INFO):
696
+    def send(self, service_id, data_id, data, status=STATUS_OKAY, timeout=2):
580 697
         """
698
+        This methods sends out a message with the given content.
699
+
581 700
         :param service_id: The Service-ID for the message. See class definitions starting with ``SERVICE_``.
582 701
         :type service_id: int
583 702
         :param data_id: The Data-ID for the message.
@@ -588,15 +707,22 @@ class pure_json_protocol(object):
588 707
         :type status: int
589 708
         :param timeout: The timeout for sending data (e.g. time to establish new connection).
590 709
         :type timeout: float
591
-        :param rx_log_lvl: The log level to log outgoing TX-data
592
-        :type rx_log_lvl: int
593 710
         :return: True if data had been sent, otherwise False.
594 711
         :rtype: bool
595
-
596
-        This methods sends out a message with the given content.
597 712
         """
598
-        self.logger.log(log_lvl, '%s TX -> status: %d, service_id: %d, data_id: %d, data: "%s"', self.__log_prefix__(), status, service_id, data_id, repr(data))
599
-        return self.__comm_inst__.send(self.__build_frame__(service_id, data_id, data, status), timeout=timeout, log_lvl=logging.DEBUG)
713
+        if (self.check_authentification_state() or not self.__authentification_required__(service_id, data_id)) or (service_id in self.__sid_response_dict__.values() and status == STATUS_AUTH_REQUIRED and data is None):
714
+            self.logger.info(
715
+                '%s TX <- %s, %s, data: "%s"',
716
+                self.__log_prefix__(),
717
+                self.__get_message_name__(service_id, data_id),
718
+                self.__get_status_name__(status),
719
+                repr(data)
720
+            )
721
+            return self.__comm_inst__.send(self.__build_frame__(service_id, data_id, data, status), timeout=timeout, log_lvl=logging.DEBUG)
722
+        else:
723
+            # Authentification required
724
+            self.logger.warning("%s TX -> Authentification is required. Message %s, %s, data: %s will be ignored.", self.__log_prefix__(), self.__get_message_name__(service_id, data_id), self.__get_status_name__(status), repr(data))
725
+            return False
600 726
 
601 727
 
602 728
 class struct_json_protocol(pure_json_protocol):
@@ -617,7 +743,7 @@ class struct_json_protocol(pure_json_protocol):
617 743
             data = json.loads(frame[12:-1])
618 744
         return self.__mk_msg__(status, service_id, data_id, data)
619 745
 
620
-    def __build_frame__(self, service_id, data_id, data, status=pure_json_protocol.STATUS_OKAY):
746
+    def __build_frame__(self, service_id, data_id, data, status=STATUS_OKAY):
621 747
         frame = struct.pack('>III', status, service_id, data_id)
622 748
         if sys.version_info >= (3, 0):
623 749
             frame += bytes(json.dumps(data), 'utf-8')

BIN
_docs_/_downloads/37503cb17b21b2c78bb8b07730976f24/unittest.pdf Näytä tiedosto


BIN
_docs_/_downloads/f482679fb1771f4d05403bb87fd0cc34/unittest.pdf Näytä tiedosto


+ 45
- 33
_docs_/genindex.html Näytä tiedosto

@@ -161,19 +161,27 @@
161 161
 <h2 id="A">A</h2>
162 162
 <table style="width: 100%" class="indextable genindextable"><tr>
163 163
   <td style="width: 33%; vertical-align: top;"><ul>
164
-      <li><a href="index.html#socket_protocol.pure_json_protocol.AUTH_STATE__NAMES">AUTH_STATE__NAMES (socket_protocol.pure_json_protocol attribute)</a>
164
+      <li><a href="index.html#socket_protocol.pure_json_protocol.add_data">add_data() (socket_protocol.pure_json_protocol method)</a>
165 165
 </li>
166
-      <li><a href="index.html#socket_protocol.pure_json_protocol.AUTH_STATE_KEY_TRANSFERRED">AUTH_STATE_KEY_TRANSFERRED (socket_protocol.pure_json_protocol attribute)</a>
166
+      <li><a href="index.html#socket_protocol.pure_json_protocol.add_msg_to_auth_whitelist_">add_msg_to_auth_whitelist_() (socket_protocol.pure_json_protocol method)</a>
167 167
 </li>
168
-      <li><a href="index.html#socket_protocol.pure_json_protocol.AUTH_STATE_SEED_REQUESTED">AUTH_STATE_SEED_REQUESTED (socket_protocol.pure_json_protocol attribute)</a>
168
+      <li><a href="index.html#socket_protocol.pure_json_protocol.add_service">add_service() (socket_protocol.pure_json_protocol method)</a>
169
+</li>
170
+      <li><a href="index.html#socket_protocol.pure_json_protocol.add_status">add_status() (socket_protocol.pure_json_protocol method)</a>
171
+</li>
172
+      <li><a href="index.html#socket_protocol.AUTH_STATE__NAMES">AUTH_STATE__NAMES (in module socket_protocol)</a>
169 173
 </li>
170 174
   </ul></td>
171 175
   <td style="width: 33%; vertical-align: top;"><ul>
172
-      <li><a href="index.html#socket_protocol.pure_json_protocol.AUTH_STATE_SEED_TRANSFERRED">AUTH_STATE_SEED_TRANSFERRED (socket_protocol.pure_json_protocol attribute)</a>
176
+      <li><a href="index.html#socket_protocol.AUTH_STATE_KEY_TRANSFERRED">AUTH_STATE_KEY_TRANSFERRED (in module socket_protocol)</a>
177
+</li>
178
+      <li><a href="index.html#socket_protocol.AUTH_STATE_SEED_REQUESTED">AUTH_STATE_SEED_REQUESTED (in module socket_protocol)</a>
173 179
 </li>
174
-      <li><a href="index.html#socket_protocol.pure_json_protocol.AUTH_STATE_TRUSTED_CLIENT">AUTH_STATE_TRUSTED_CLIENT (socket_protocol.pure_json_protocol attribute)</a>
180
+      <li><a href="index.html#socket_protocol.AUTH_STATE_SEED_TRANSFERRED">AUTH_STATE_SEED_TRANSFERRED (in module socket_protocol)</a>
175 181
 </li>
176
-      <li><a href="index.html#socket_protocol.pure_json_protocol.AUTH_STATE_UNKNOWN_CLIENT">AUTH_STATE_UNKNOWN_CLIENT (socket_protocol.pure_json_protocol attribute)</a>
182
+      <li><a href="index.html#socket_protocol.AUTH_STATE_TRUSTED_CONNECTION">AUTH_STATE_TRUSTED_CONNECTION (in module socket_protocol)</a>
183
+</li>
184
+      <li><a href="index.html#socket_protocol.AUTH_STATE_UNTRUSTED_CONNECTION">AUTH_STATE_UNTRUSTED_CONNECTION (in module socket_protocol)</a>
177 185
 </li>
178 186
       <li><a href="index.html#socket_protocol.pure_json_protocol.authentificate">authentificate() (socket_protocol.pure_json_protocol method)</a>
179 187
 </li>
@@ -196,6 +204,14 @@
196 204
 <table style="width: 100%" class="indextable genindextable"><tr>
197 205
   <td style="width: 33%; vertical-align: top;"><ul>
198 206
       <li><a href="index.html#socket_protocol.data_storage">data_storage (class in socket_protocol)</a>
207
+</li>
208
+      <li><a href="index.html#socket_protocol.DID_AUTH_KEY">DID_AUTH_KEY (in module socket_protocol)</a>
209
+</li>
210
+  </ul></td>
211
+  <td style="width: 33%; vertical-align: top;"><ul>
212
+      <li><a href="index.html#socket_protocol.DID_AUTH_SEED">DID_AUTH_SEED (in module socket_protocol)</a>
213
+</li>
214
+      <li><a href="index.html#socket_protocol.DID_CHANNEL_NAME">DID_CHANNEL_NAME (in module socket_protocol)</a>
199 215
 </li>
200 216
   </ul></td>
201 217
 </tr></table>
@@ -237,11 +253,15 @@
237 253
   <td style="width: 33%; vertical-align: top;"><ul>
238 254
       <li><a href="index.html#socket_protocol.pure_json_protocol.receive">receive() (socket_protocol.pure_json_protocol method)</a>
239 255
 </li>
240
-  </ul></td>
241
-  <td style="width: 33%; vertical-align: top;"><ul>
242 256
       <li><a href="index.html#socket_protocol.pure_json_protocol.reconnect">reconnect() (socket_protocol.pure_json_protocol method)</a>
243 257
 </li>
258
+  </ul></td>
259
+  <td style="width: 33%; vertical-align: top;"><ul>
244 260
       <li><a href="index.html#socket_protocol.pure_json_protocol.register_callback">register_callback() (socket_protocol.pure_json_protocol method)</a>
261
+</li>
262
+      <li><a href="index.html#socket_protocol.RequestSidExistsError">RequestSidExistsError</a>
263
+</li>
264
+      <li><a href="index.html#socket_protocol.ResponseSidExistsError">ResponseSidExistsError</a>
245 265
 </li>
246 266
   </ul></td>
247 267
 </tr></table>
@@ -251,51 +271,43 @@
251 271
   <td style="width: 33%; vertical-align: top;"><ul>
252 272
       <li><a href="index.html#socket_protocol.pure_json_protocol.send">send() (socket_protocol.pure_json_protocol method)</a>
253 273
 </li>
254
-      <li><a href="index.html#socket_protocol.pure_json_protocol.SID__NO_AUTH_LIST">SID__NO_AUTH_LIST (socket_protocol.pure_json_protocol attribute)</a>
274
+      <li><a href="index.html#socket_protocol.SID_AUTH_REQUEST">SID_AUTH_REQUEST (in module socket_protocol)</a>
255 275
 </li>
256
-      <li><a href="index.html#socket_protocol.pure_json_protocol.SID__RESPONSE_DICT">SID__RESPONSE_DICT (socket_protocol.pure_json_protocol attribute)</a>
276
+      <li><a href="index.html#socket_protocol.SID_AUTH_RESPONSE">SID_AUTH_RESPONSE (in module socket_protocol)</a>
257 277
 </li>
258
-      <li><a href="index.html#socket_protocol.pure_json_protocol.SID_AUTH_KEY_CHECK_REQUEST">SID_AUTH_KEY_CHECK_REQUEST (socket_protocol.pure_json_protocol attribute)</a>
278
+      <li><a href="index.html#socket_protocol.SID_CHANNEL_NAME_REQUEST">SID_CHANNEL_NAME_REQUEST (in module socket_protocol)</a>
259 279
 </li>
260
-      <li><a href="index.html#socket_protocol.pure_json_protocol.SID_AUTH_KEY_CHECK_RESPONSE">SID_AUTH_KEY_CHECK_RESPONSE (socket_protocol.pure_json_protocol attribute)</a>
280
+      <li><a href="index.html#socket_protocol.SID_CHANNEL_NAME_RESPONSE">SID_CHANNEL_NAME_RESPONSE (in module socket_protocol)</a>
261 281
 </li>
262
-      <li><a href="index.html#socket_protocol.pure_json_protocol.SID_AUTH_KEY_REQUEST">SID_AUTH_KEY_REQUEST (socket_protocol.pure_json_protocol attribute)</a>
282
+      <li><a href="index.html#socket_protocol.SID_EXECUTE_REQUEST">SID_EXECUTE_REQUEST (in module socket_protocol)</a>
263 283
 </li>
264
-      <li><a href="index.html#socket_protocol.pure_json_protocol.SID_AUTH_SEED_REQUEST">SID_AUTH_SEED_REQUEST (socket_protocol.pure_json_protocol attribute)</a>
284
+      <li><a href="index.html#socket_protocol.SID_EXECUTE_RESPONSE">SID_EXECUTE_RESPONSE (in module socket_protocol)</a>
265 285
 </li>
266
-      <li><a href="index.html#socket_protocol.pure_json_protocol.SID_CHANNEL_NAME_REQUEST">SID_CHANNEL_NAME_REQUEST (socket_protocol.pure_json_protocol attribute)</a>
286
+      <li><a href="index.html#socket_protocol.SID_READ_REQUEST">SID_READ_REQUEST (in module socket_protocol)</a>
267 287
 </li>
268
-      <li><a href="index.html#socket_protocol.pure_json_protocol.SID_CHANNEL_NAME_RESPONSE">SID_CHANNEL_NAME_RESPONSE (socket_protocol.pure_json_protocol attribute)</a>
288
+      <li><a href="index.html#socket_protocol.SID_READ_RESPONSE">SID_READ_RESPONSE (in module socket_protocol)</a>
269 289
 </li>
270
-      <li><a href="index.html#socket_protocol.pure_json_protocol.SID_EXECUTE_REQUEST">SID_EXECUTE_REQUEST (socket_protocol.pure_json_protocol attribute)</a>
271
-</li>
272
-      <li><a href="index.html#socket_protocol.pure_json_protocol.SID_EXECUTE_RESPONSE">SID_EXECUTE_RESPONSE (socket_protocol.pure_json_protocol attribute)</a>
273
-</li>
274
-      <li><a href="index.html#socket_protocol.pure_json_protocol.SID_READ_REQUEST">SID_READ_REQUEST (socket_protocol.pure_json_protocol attribute)</a>
290
+      <li><a href="index.html#socket_protocol.SID_WRITE_REQUEST">SID_WRITE_REQUEST (in module socket_protocol)</a>
275 291
 </li>
276 292
   </ul></td>
277 293
   <td style="width: 33%; vertical-align: top;"><ul>
278
-      <li><a href="index.html#socket_protocol.pure_json_protocol.SID_READ_RESPONSE">SID_READ_RESPONSE (socket_protocol.pure_json_protocol attribute)</a>
279
-</li>
280
-      <li><a href="index.html#socket_protocol.pure_json_protocol.SID_WRITE_REQUEST">SID_WRITE_REQUEST (socket_protocol.pure_json_protocol attribute)</a>
281
-</li>
282
-      <li><a href="index.html#socket_protocol.pure_json_protocol.SID_WRITE_RESPONSE">SID_WRITE_RESPONSE (socket_protocol.pure_json_protocol attribute)</a>
294
+      <li><a href="index.html#socket_protocol.SID_WRITE_RESPONSE">SID_WRITE_RESPONSE (in module socket_protocol)</a>
283 295
 </li>
284 296
       <li><a href="index.html#module-socket_protocol">socket_protocol (module)</a>
285 297
 </li>
286
-      <li><a href="index.html#socket_protocol.pure_json_protocol.STATUS__NAMES">STATUS__NAMES (socket_protocol.pure_json_protocol attribute)</a>
298
+      <li><a href="index.html#socket_protocol.STATUS_AUTH_REQUIRED">STATUS_AUTH_REQUIRED (in module socket_protocol)</a>
287 299
 </li>
288
-      <li><a href="index.html#socket_protocol.pure_json_protocol.STATUS_AUTH_REQUIRED">STATUS_AUTH_REQUIRED (socket_protocol.pure_json_protocol attribute)</a>
300
+      <li><a href="index.html#socket_protocol.STATUS_BUFFERING_UNHANDLED_REQUEST">STATUS_BUFFERING_UNHANDLED_REQUEST (in module socket_protocol)</a>
289 301
 </li>
290
-      <li><a href="index.html#socket_protocol.pure_json_protocol.STATUS_BUFFERING_UNHANDLED_REQUEST">STATUS_BUFFERING_UNHANDLED_REQUEST (socket_protocol.pure_json_protocol attribute)</a>
302
+      <li><a href="index.html#socket_protocol.STATUS_CALLBACK_ERROR">STATUS_CALLBACK_ERROR (in module socket_protocol)</a>
291 303
 </li>
292
-      <li><a href="index.html#socket_protocol.pure_json_protocol.STATUS_CHECKSUM_ERROR">STATUS_CHECKSUM_ERROR (socket_protocol.pure_json_protocol attribute)</a>
304
+      <li><a href="index.html#socket_protocol.STATUS_CHECKSUM_ERROR">STATUS_CHECKSUM_ERROR (in module socket_protocol)</a>
293 305
 </li>
294
-      <li><a href="index.html#socket_protocol.pure_json_protocol.STATUS_OKAY">STATUS_OKAY (socket_protocol.pure_json_protocol attribute)</a>
306
+      <li><a href="index.html#socket_protocol.STATUS_OKAY">STATUS_OKAY (in module socket_protocol)</a>
295 307
 </li>
296
-      <li><a href="index.html#socket_protocol.pure_json_protocol.STATUS_OPERATION_NOT_PERMITTED">STATUS_OPERATION_NOT_PERMITTED (socket_protocol.pure_json_protocol attribute)</a>
308
+      <li><a href="index.html#socket_protocol.STATUS_OPERATION_NOT_PERMITTED">STATUS_OPERATION_NOT_PERMITTED (in module socket_protocol)</a>
297 309
 </li>
298
-      <li><a href="index.html#socket_protocol.pure_json_protocol.STATUS_SERVICE_OR_DATA_UNKNOWN">STATUS_SERVICE_OR_DATA_UNKNOWN (socket_protocol.pure_json_protocol attribute)</a>
310
+      <li><a href="index.html#socket_protocol.STATUS_SERVICE_OR_DATA_UNKNOWN">STATUS_SERVICE_OR_DATA_UNKNOWN (in module socket_protocol)</a>
299 311
 </li>
300 312
       <li><a href="index.html#socket_protocol.struct_json_protocol">struct_json_protocol (class in socket_protocol)</a>
301 313
 </li>

+ 278
- 206
_docs_/index.html Näytä tiedosto

@@ -165,17 +165,185 @@
165 165
 <div>This Module supports point to point communication for client-server issues.</div></blockquote>
166 166
 <p><strong>Submodules:</strong></p>
167 167
 <ul class="simple">
168
+<li><a class="reference internal" href="#socket_protocol.data_storage" title="socket_protocol.data_storage"><code class="xref py py-class docutils literal notranslate"><span class="pre">socket_protocol.data_storage</span></code></a></li>
168 169
 <li><a class="reference internal" href="#socket_protocol.pure_json_protocol" title="socket_protocol.pure_json_protocol"><code class="xref py py-class docutils literal notranslate"><span class="pre">socket_protocol.pure_json_protocol</span></code></a></li>
169 170
 <li><a class="reference internal" href="#socket_protocol.struct_json_protocol" title="socket_protocol.struct_json_protocol"><code class="xref py py-class docutils literal notranslate"><span class="pre">socket_protocol.struct_json_protocol</span></code></a></li>
170 171
 </ul>
171 172
 <p><strong>Unittest:</strong></p>
172 173
 <blockquote>
173
-<div>See also the <a class="reference download internal" download="" href="_downloads/f482679fb1771f4d05403bb87fd0cc34/unittest.pdf"><code class="xref download docutils literal notranslate"><span class="pre">unittest</span></code></a> documentation.</div></blockquote>
174
+<div>See also the <a class="reference download internal" download="" href="_downloads/37503cb17b21b2c78bb8b07730976f24/unittest.pdf"><code class="xref download docutils literal notranslate"><span class="pre">unittest</span></code></a> documentation.</div></blockquote>
174 175
 <p><strong>Module Documentation:</strong></p>
176
+<dl class="data">
177
+<dt id="socket_protocol.AUTH_STATE_KEY_TRANSFERRED">
178
+<code class="descclassname">socket_protocol.</code><code class="descname">AUTH_STATE_KEY_TRANSFERRED</code><em class="property"> = 3</em><a class="headerlink" href="#socket_protocol.AUTH_STATE_KEY_TRANSFERRED" title="Permalink to this definition">¶</a></dt>
179
+<dd><p>Authentification Status for ‘Key has been sent’</p>
180
+</dd></dl>
181
+
182
+<dl class="data">
183
+<dt id="socket_protocol.AUTH_STATE_SEED_REQUESTED">
184
+<code class="descclassname">socket_protocol.</code><code class="descname">AUTH_STATE_SEED_REQUESTED</code><em class="property"> = 1</em><a class="headerlink" href="#socket_protocol.AUTH_STATE_SEED_REQUESTED" title="Permalink to this definition">¶</a></dt>
185
+<dd><p>Authentification Status for ‘Seed was requested’</p>
186
+</dd></dl>
187
+
188
+<dl class="data">
189
+<dt id="socket_protocol.AUTH_STATE_SEED_TRANSFERRED">
190
+<code class="descclassname">socket_protocol.</code><code class="descname">AUTH_STATE_SEED_TRANSFERRED</code><em class="property"> = 2</em><a class="headerlink" href="#socket_protocol.AUTH_STATE_SEED_TRANSFERRED" title="Permalink to this definition">¶</a></dt>
191
+<dd><p>Authentification Status for ‘Seed has been sent’</p>
192
+</dd></dl>
193
+
194
+<dl class="data">
195
+<dt id="socket_protocol.AUTH_STATE_TRUSTED_CONNECTION">
196
+<code class="descclassname">socket_protocol.</code><code class="descname">AUTH_STATE_TRUSTED_CONNECTION</code><em class="property"> = 4</em><a class="headerlink" href="#socket_protocol.AUTH_STATE_TRUSTED_CONNECTION" title="Permalink to this definition">¶</a></dt>
197
+<dd><p>Authentification Status for a ‘Trusted Connection’</p>
198
+</dd></dl>
199
+
200
+<dl class="data">
201
+<dt id="socket_protocol.AUTH_STATE_UNTRUSTED_CONNECTION">
202
+<code class="descclassname">socket_protocol.</code><code class="descname">AUTH_STATE_UNTRUSTED_CONNECTION</code><em class="property"> = 0</em><a class="headerlink" href="#socket_protocol.AUTH_STATE_UNTRUSTED_CONNECTION" title="Permalink to this definition">¶</a></dt>
203
+<dd><p>Authentification Status for an ‘Untrusted Connection’</p>
204
+</dd></dl>
205
+
206
+<dl class="data">
207
+<dt id="socket_protocol.AUTH_STATE__NAMES">
208
+<code class="descclassname">socket_protocol.</code><code class="descname">AUTH_STATE__NAMES</code><em class="property"> = {0: 'Untrusted Connection', 1: 'Seed was requested', 2: 'Seed has been sent', 3: 'Key has been sent', 4: 'Trusted Connection'}</em><a class="headerlink" href="#socket_protocol.AUTH_STATE__NAMES" title="Permalink to this definition">¶</a></dt>
209
+<dd><p>Authentification Status names for previous defined authentification states</p>
210
+</dd></dl>
211
+
212
+<dl class="data">
213
+<dt id="socket_protocol.DID_AUTH_KEY">
214
+<code class="descclassname">socket_protocol.</code><code class="descname">DID_AUTH_KEY</code><em class="property"> = 1</em><a class="headerlink" href="#socket_protocol.DID_AUTH_KEY" title="Permalink to this definition">¶</a></dt>
215
+<dd><p>DID for authentification (key)</p>
216
+</dd></dl>
217
+
218
+<dl class="data">
219
+<dt id="socket_protocol.DID_AUTH_SEED">
220
+<code class="descclassname">socket_protocol.</code><code class="descname">DID_AUTH_SEED</code><em class="property"> = 0</em><a class="headerlink" href="#socket_protocol.DID_AUTH_SEED" title="Permalink to this definition">¶</a></dt>
221
+<dd><p>DID for authentification (seed)</p>
222
+</dd></dl>
223
+
224
+<dl class="data">
225
+<dt id="socket_protocol.DID_CHANNEL_NAME">
226
+<code class="descclassname">socket_protocol.</code><code class="descname">DID_CHANNEL_NAME</code><em class="property"> = 0</em><a class="headerlink" href="#socket_protocol.DID_CHANNEL_NAME" title="Permalink to this definition">¶</a></dt>
227
+<dd><p>DID for channel name</p>
228
+</dd></dl>
229
+
230
+<dl class="exception">
231
+<dt id="socket_protocol.RequestSidExistsError">
232
+<em class="property">exception </em><code class="descclassname">socket_protocol.</code><code class="descname">RequestSidExistsError</code><a class="headerlink" href="#socket_protocol.RequestSidExistsError" title="Permalink to this definition">¶</a></dt>
233
+<dd></dd></dl>
234
+
235
+<dl class="exception">
236
+<dt id="socket_protocol.ResponseSidExistsError">
237
+<em class="property">exception </em><code class="descclassname">socket_protocol.</code><code class="descname">ResponseSidExistsError</code><a class="headerlink" href="#socket_protocol.ResponseSidExistsError" title="Permalink to this definition">¶</a></dt>
238
+<dd></dd></dl>
239
+
240
+<dl class="data">
241
+<dt id="socket_protocol.SID_AUTH_REQUEST">
242
+<code class="descclassname">socket_protocol.</code><code class="descname">SID_AUTH_REQUEST</code><em class="property"> = 0</em><a class="headerlink" href="#socket_protocol.SID_AUTH_REQUEST" title="Permalink to this definition">¶</a></dt>
243
+<dd><p>SID for authentification request</p>
244
+</dd></dl>
245
+
246
+<dl class="data">
247
+<dt id="socket_protocol.SID_AUTH_RESPONSE">
248
+<code class="descclassname">socket_protocol.</code><code class="descname">SID_AUTH_RESPONSE</code><em class="property"> = 1</em><a class="headerlink" href="#socket_protocol.SID_AUTH_RESPONSE" title="Permalink to this definition">¶</a></dt>
249
+<dd><p>SID for authentification response</p>
250
+</dd></dl>
251
+
252
+<dl class="data">
253
+<dt id="socket_protocol.SID_CHANNEL_NAME_REQUEST">
254
+<code class="descclassname">socket_protocol.</code><code class="descname">SID_CHANNEL_NAME_REQUEST</code><em class="property"> = 8</em><a class="headerlink" href="#socket_protocol.SID_CHANNEL_NAME_REQUEST" title="Permalink to this definition">¶</a></dt>
255
+<dd><p>SID for channel name exchange request</p>
256
+</dd></dl>
257
+
258
+<dl class="data">
259
+<dt id="socket_protocol.SID_CHANNEL_NAME_RESPONSE">
260
+<code class="descclassname">socket_protocol.</code><code class="descname">SID_CHANNEL_NAME_RESPONSE</code><em class="property"> = 9</em><a class="headerlink" href="#socket_protocol.SID_CHANNEL_NAME_RESPONSE" title="Permalink to this definition">¶</a></dt>
261
+<dd><p>SID for channel name exchange response</p>
262
+</dd></dl>
263
+
264
+<dl class="data">
265
+<dt id="socket_protocol.SID_EXECUTE_REQUEST">
266
+<code class="descclassname">socket_protocol.</code><code class="descname">SID_EXECUTE_REQUEST</code><em class="property"> = 30</em><a class="headerlink" href="#socket_protocol.SID_EXECUTE_REQUEST" title="Permalink to this definition">¶</a></dt>
267
+<dd><p>SID for a execute request</p>
268
+</dd></dl>
269
+
270
+<dl class="data">
271
+<dt id="socket_protocol.SID_EXECUTE_RESPONSE">
272
+<code class="descclassname">socket_protocol.</code><code class="descname">SID_EXECUTE_RESPONSE</code><em class="property"> = 31</em><a class="headerlink" href="#socket_protocol.SID_EXECUTE_RESPONSE" title="Permalink to this definition">¶</a></dt>
273
+<dd><p>SID for a execute response</p>
274
+</dd></dl>
275
+
276
+<dl class="data">
277
+<dt id="socket_protocol.SID_READ_REQUEST">
278
+<code class="descclassname">socket_protocol.</code><code class="descname">SID_READ_REQUEST</code><em class="property"> = 10</em><a class="headerlink" href="#socket_protocol.SID_READ_REQUEST" title="Permalink to this definition">¶</a></dt>
279
+<dd><p>SID for a read data request</p>
280
+</dd></dl>
281
+
282
+<dl class="data">
283
+<dt id="socket_protocol.SID_READ_RESPONSE">
284
+<code class="descclassname">socket_protocol.</code><code class="descname">SID_READ_RESPONSE</code><em class="property"> = 11</em><a class="headerlink" href="#socket_protocol.SID_READ_RESPONSE" title="Permalink to this definition">¶</a></dt>
285
+<dd><p>SID for read data response</p>
286
+</dd></dl>
287
+
288
+<dl class="data">
289
+<dt id="socket_protocol.SID_WRITE_REQUEST">
290
+<code class="descclassname">socket_protocol.</code><code class="descname">SID_WRITE_REQUEST</code><em class="property"> = 20</em><a class="headerlink" href="#socket_protocol.SID_WRITE_REQUEST" title="Permalink to this definition">¶</a></dt>
291
+<dd><p>SID for a write data request</p>
292
+</dd></dl>
293
+
294
+<dl class="data">
295
+<dt id="socket_protocol.SID_WRITE_RESPONSE">
296
+<code class="descclassname">socket_protocol.</code><code class="descname">SID_WRITE_RESPONSE</code><em class="property"> = 21</em><a class="headerlink" href="#socket_protocol.SID_WRITE_RESPONSE" title="Permalink to this definition">¶</a></dt>
297
+<dd><p>SID for a write data response</p>
298
+</dd></dl>
299
+
300
+<dl class="data">
301
+<dt id="socket_protocol.STATUS_AUTH_REQUIRED">
302
+<code class="descclassname">socket_protocol.</code><code class="descname">STATUS_AUTH_REQUIRED</code><em class="property"> = 3</em><a class="headerlink" href="#socket_protocol.STATUS_AUTH_REQUIRED" title="Permalink to this definition">¶</a></dt>
303
+<dd><p>Status for ‘authentification is required’</p>
304
+</dd></dl>
305
+
306
+<dl class="data">
307
+<dt id="socket_protocol.STATUS_BUFFERING_UNHANDLED_REQUEST">
308
+<code class="descclassname">socket_protocol.</code><code class="descname">STATUS_BUFFERING_UNHANDLED_REQUEST</code><em class="property"> = 1</em><a class="headerlink" href="#socket_protocol.STATUS_BUFFERING_UNHANDLED_REQUEST" title="Permalink to this definition">¶</a></dt>
309
+<dd><p>Status for ‘unhandled request’</p>
310
+</dd></dl>
311
+
312
+<dl class="data">
313
+<dt id="socket_protocol.STATUS_CALLBACK_ERROR">
314
+<code class="descclassname">socket_protocol.</code><code class="descname">STATUS_CALLBACK_ERROR</code><em class="property"> = 2</em><a class="headerlink" href="#socket_protocol.STATUS_CALLBACK_ERROR" title="Permalink to this definition">¶</a></dt>
315
+<dd><p>Status for ‘callback errors’</p>
316
+</dd></dl>
317
+
318
+<dl class="data">
319
+<dt id="socket_protocol.STATUS_CHECKSUM_ERROR">
320
+<code class="descclassname">socket_protocol.</code><code class="descname">STATUS_CHECKSUM_ERROR</code><em class="property"> = 5</em><a class="headerlink" href="#socket_protocol.STATUS_CHECKSUM_ERROR" title="Permalink to this definition">¶</a></dt>
321
+<dd><p>Status for ‘checksum error’</p>
322
+</dd></dl>
323
+
324
+<dl class="data">
325
+<dt id="socket_protocol.STATUS_OKAY">
326
+<code class="descclassname">socket_protocol.</code><code class="descname">STATUS_OKAY</code><em class="property"> = 0</em><a class="headerlink" href="#socket_protocol.STATUS_OKAY" title="Permalink to this definition">¶</a></dt>
327
+<dd><p>Status for ‘okay’</p>
328
+</dd></dl>
329
+
330
+<dl class="data">
331
+<dt id="socket_protocol.STATUS_OPERATION_NOT_PERMITTED">
332
+<code class="descclassname">socket_protocol.</code><code class="descname">STATUS_OPERATION_NOT_PERMITTED</code><em class="property"> = 6</em><a class="headerlink" href="#socket_protocol.STATUS_OPERATION_NOT_PERMITTED" title="Permalink to this definition">¶</a></dt>
333
+<dd><p>Status for ‘operation not permitted’</p>
334
+</dd></dl>
335
+
336
+<dl class="data">
337
+<dt id="socket_protocol.STATUS_SERVICE_OR_DATA_UNKNOWN">
338
+<code class="descclassname">socket_protocol.</code><code class="descname">STATUS_SERVICE_OR_DATA_UNKNOWN</code><em class="property"> = 4</em><a class="headerlink" href="#socket_protocol.STATUS_SERVICE_OR_DATA_UNKNOWN" title="Permalink to this definition">¶</a></dt>
339
+<dd><p>Status for ‘service or data unknown’</p>
340
+</dd></dl>
341
+
175 342
 <dl class="class">
176 343
 <dt id="socket_protocol.data_storage">
177 344
 <em class="property">class </em><code class="descclassname">socket_protocol.</code><code class="descname">data_storage</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#socket_protocol.data_storage" title="Permalink to this definition">¶</a></dt>
178
-<dd><table class="docutils field-list" frame="void" rules="none">
345
+<dd><p>This is a storage object for socket_protocol messages.</p>
346
+<table class="docutils field-list" frame="void" rules="none">
179 347
 <col class="field-name" />
180 348
 <col class="field-body" />
181 349
 <tbody valign="top">
@@ -189,11 +357,11 @@
189 357
 </tr>
190 358
 </tbody>
191 359
 </table>
192
-<p>This is a storage object for socket_protocol messages.</p>
193 360
 <dl class="method">
194 361
 <dt id="socket_protocol.data_storage.get_data">
195 362
 <code class="descname">get_data</code><span class="sig-paren">(</span><em>default=None</em><span class="sig-paren">)</span><a class="headerlink" href="#socket_protocol.data_storage.get_data" title="Permalink to this definition">¶</a></dt>
196
-<dd><table class="docutils field-list" frame="void" rules="none">
363
+<dd><p>This Method returns the message data.</p>
364
+<table class="docutils field-list" frame="void" rules="none">
197 365
 <col class="field-name" />
198 366
 <col class="field-body" />
199 367
 <tbody valign="top">
@@ -201,13 +369,13 @@
201 369
 </tr>
202 370
 </tbody>
203 371
 </table>
204
-<p>This Method returns the message data.</p>
205 372
 </dd></dl>
206 373
 
207 374
 <dl class="method">
208 375
 <dt id="socket_protocol.data_storage.get_data_id">
209 376
 <code class="descname">get_data_id</code><span class="sig-paren">(</span><em>default=None</em><span class="sig-paren">)</span><a class="headerlink" href="#socket_protocol.data_storage.get_data_id" title="Permalink to this definition">¶</a></dt>
210
-<dd><table class="docutils field-list" frame="void" rules="none">
377
+<dd><p>This Method returns the message Data-ID.</p>
378
+<table class="docutils field-list" frame="void" rules="none">
211 379
 <col class="field-name" />
212 380
 <col class="field-body" />
213 381
 <tbody valign="top">
@@ -215,13 +383,13 @@
215 383
 </tr>
216 384
 </tbody>
217 385
 </table>
218
-<p>This Method returns the message Data-ID.</p>
219 386
 </dd></dl>
220 387
 
221 388
 <dl class="method">
222 389
 <dt id="socket_protocol.data_storage.get_service_id">
223 390
 <code class="descname">get_service_id</code><span class="sig-paren">(</span><em>default=None</em><span class="sig-paren">)</span><a class="headerlink" href="#socket_protocol.data_storage.get_service_id" title="Permalink to this definition">¶</a></dt>
224
-<dd><table class="docutils field-list" frame="void" rules="none">
391
+<dd><p>This Method returns the message Service-ID.</p>
392
+<table class="docutils field-list" frame="void" rules="none">
225 393
 <col class="field-name" />
226 394
 <col class="field-body" />
227 395
 <tbody valign="top">
@@ -229,13 +397,13 @@
229 397
 </tr>
230 398
 </tbody>
231 399
 </table>
232
-<p>This Method returns the message Service-ID.</p>
233 400
 </dd></dl>
234 401
 
235 402
 <dl class="method">
236 403
 <dt id="socket_protocol.data_storage.get_status">
237 404
 <code class="descname">get_status</code><span class="sig-paren">(</span><em>default=None</em><span class="sig-paren">)</span><a class="headerlink" href="#socket_protocol.data_storage.get_status" title="Permalink to this definition">¶</a></dt>
238
-<dd><table class="docutils field-list" frame="void" rules="none">
405
+<dd><p>This Method returns the message status.</p>
406
+<table class="docutils field-list" frame="void" rules="none">
239 407
 <col class="field-name" />
240 408
 <col class="field-body" />
241 409
 <tbody valign="top">
@@ -243,7 +411,6 @@
243 411
 </tr>
244 412
 </tbody>
245 413
 </table>
246
-<p>This Method returns the message status.</p>
247 414
 </dd></dl>
248 415
 
249 416
 </dd></dl>
@@ -251,14 +418,15 @@
251 418
 <dl class="class">
252 419
 <dt id="socket_protocol.pure_json_protocol">
253 420
 <em class="property">class </em><code class="descclassname">socket_protocol.</code><code class="descname">pure_json_protocol</code><span class="sig-paren">(</span><em>comm_instance</em>, <em>secret=None</em>, <em>auto_auth=False</em>, <em>channel_name=None</em><span class="sig-paren">)</span><a class="headerlink" href="#socket_protocol.pure_json_protocol" title="Permalink to this definition">¶</a></dt>
254
-<dd><table class="docutils field-list" frame="void" rules="none">
421
+<dd><p>This <cite>class</cite> supports to transfer a message and it’s data.</p>
422
+<table class="docutils field-list" frame="void" rules="none">
255 423
 <col class="field-name" />
256 424
 <col class="field-body" />
257 425
 <tbody valign="top">
258 426
 <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
259 427
 <li><strong>comm_instance</strong> (<em>instance</em>) – A communication instance.</li>
260 428
 <li><strong>secret</strong> (<em>str</em>) – An optinal secret (e.g. created by <code class="docutils literal notranslate"><span class="pre">binascii.hexlify(os.urandom(24))</span></code>).</li>
261
-<li><strong>auto_auth</strong> (<em>bool</em>) – An optional parameter (True) to enable automatic authentification, otherwise you need to do it manually, if needed.</li>
429
+<li><strong>auto_auth</strong> (<em>bool</em>) – An optional parameter to enable (True) automatic authentification, otherwise you need to do it manually, if needed.</li>
262 430
 <li><strong>channel_name</strong> (<em>str</em>) – An optional parameter to set a channel name for logging of the communication.</li>
263 431
 </ul>
264 432
 </td>
@@ -267,9 +435,8 @@
267 435
 </table>
268 436
 <div class="admonition hint">
269 437
 <p class="first admonition-title">Hint</p>
270
-<p>This <cite>class</cite> supports to transfer a Service-ID, Data-ID and Data.</p>
271 438
 <ul class="last simple">
272
-<li>The Service-ID is designed to identify the type of the communication (e.g. READ_REQUEST, WRITE_REQUEST, READ_RESPONSE, WRITE_RESPONSE, …)</li>
439
+<li>The Service-ID is designed to identify the type of the communication (e.g. <code class="xref py py-const docutils literal notranslate"><span class="pre">READ_REQUEST</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">WRITE_REQUEST</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">READ_RESPONSE</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">WRITE_RESPONSE</span></code>, …)</li>
273 440
 <li>The Data-ID is designed to identify the requests / responses using the same Service_ID.</li>
274 441
 </ul>
275 442
 </div>
@@ -277,7 +444,7 @@
277 444
 <p class="first admonition-title">Note</p>
278 445
 <p>The <code class="xref py py-class docutils literal notranslate"><span class="pre">comm_instance</span></code> needs to have at least the following interface:</p>
279 446
 <ul class="last simple">
280
-<li>A Method <code class="xref py py-func docutils literal notranslate"><span class="pre">comm_instance.init_channel_name()</span></code> to set the channel name if needed.</li>
447
+<li>A Method <code class="xref py py-func docutils literal notranslate"><span class="pre">comm_instance.init_channel_name()</span></code> to set the channel name.</li>
281 448
 <li>A Constant <code class="xref py py-const docutils literal notranslate"><span class="pre">comm_instance.IS_CLIENT</span></code> to identify that the <code class="xref py py-class docutils literal notranslate"><span class="pre">comm_instance</span></code> is a client (True) or a server (False).</li>
282 449
 <li>A Method <code class="xref py py-func docutils literal notranslate"><span class="pre">comm_instance.is_connected()</span></code> to identify if the instance is connected (True) or not (False).</li>
283 450
 <li>A Method <code class="xref py py-func docutils literal notranslate"><span class="pre">comm_instance.reconnect()</span></code> to initiate a reconnect.</li>
@@ -298,172 +465,84 @@
298 465
 <li>If a channel_name is given at both communication sides and they are different, the client name is taken over and the server will log a warning message.</li>
299 466
 </ul>
300 467
 </div>
301
-<dl class="attribute">
302
-<dt id="socket_protocol.pure_json_protocol.AUTH_STATE_KEY_TRANSFERRED">
303
-<code class="descname">AUTH_STATE_KEY_TRANSFERRED</code><em class="property"> = 3</em><a class="headerlink" href="#socket_protocol.pure_json_protocol.AUTH_STATE_KEY_TRANSFERRED" title="Permalink to this definition">¶</a></dt>
304
-<dd><p>Authentification Status for ‘Key has been sent’</p>
305
-</dd></dl>
306
-
307
-<dl class="attribute">
308
-<dt id="socket_protocol.pure_json_protocol.AUTH_STATE_SEED_REQUESTED">
309
-<code class="descname">AUTH_STATE_SEED_REQUESTED</code><em class="property"> = 1</em><a class="headerlink" href="#socket_protocol.pure_json_protocol.AUTH_STATE_SEED_REQUESTED" title="Permalink to this definition">¶</a></dt>
310
-<dd><p>Authentification Status for ‘Seed was requested’</p>
311
-</dd></dl>
312
-
313
-<dl class="attribute">
314
-<dt id="socket_protocol.pure_json_protocol.AUTH_STATE_SEED_TRANSFERRED">
315
-<code class="descname">AUTH_STATE_SEED_TRANSFERRED</code><em class="property"> = 2</em><a class="headerlink" href="#socket_protocol.pure_json_protocol.AUTH_STATE_SEED_TRANSFERRED" title="Permalink to this definition">¶</a></dt>
316
-<dd><p>Authentification Status for ‘Seed has been sent’</p>
317
-</dd></dl>
318
-
319
-<dl class="attribute">
320
-<dt id="socket_protocol.pure_json_protocol.AUTH_STATE_TRUSTED_CLIENT">
321
-<code class="descname">AUTH_STATE_TRUSTED_CLIENT</code><em class="property"> = 4</em><a class="headerlink" href="#socket_protocol.pure_json_protocol.AUTH_STATE_TRUSTED_CLIENT" title="Permalink to this definition">¶</a></dt>
322
-<dd><p>Authentification Status for ‘Trusted Connection’</p>
323
-</dd></dl>
324
-
325
-<dl class="attribute">
326
-<dt id="socket_protocol.pure_json_protocol.AUTH_STATE_UNKNOWN_CLIENT">
327
-<code class="descname">AUTH_STATE_UNKNOWN_CLIENT</code><em class="property"> = 0</em><a class="headerlink" href="#socket_protocol.pure_json_protocol.AUTH_STATE_UNKNOWN_CLIENT" title="Permalink to this definition">¶</a></dt>
328
-<dd><p>Authentification Status for ‘Unknown Client’</p>
329
-</dd></dl>
330
-
331
-<dl class="attribute">
332
-<dt id="socket_protocol.pure_json_protocol.AUTH_STATE__NAMES">
333
-<code class="descname">AUTH_STATE__NAMES</code><em class="property"> = {0: 'Unknown Client', 1: 'Seed was requested', 2: 'Seed has been sent', 3: 'Key has been sent', 4: 'Trusted Connection'}</em><a class="headerlink" href="#socket_protocol.pure_json_protocol.AUTH_STATE__NAMES" title="Permalink to this definition">¶</a></dt>
334
-<dd><p>Authentification Status names for previous defined authentification states</p>
335
-</dd></dl>
336
-
337
-<dl class="attribute">
338
-<dt id="socket_protocol.pure_json_protocol.SID_AUTH_KEY_CHECK_REQUEST">
339
-<code class="descname">SID_AUTH_KEY_CHECK_REQUEST</code><em class="property"> = 3</em><a class="headerlink" href="#socket_protocol.pure_json_protocol.SID_AUTH_KEY_CHECK_REQUEST" title="Permalink to this definition">¶</a></dt>
340
-<dd><p>SID for request for checking a key</p>
341
-</dd></dl>
342
-
343
-<dl class="attribute">
344
-<dt id="socket_protocol.pure_json_protocol.SID_AUTH_KEY_CHECK_RESPONSE">
345
-<code class="descname">SID_AUTH_KEY_CHECK_RESPONSE</code><em class="property"> = 4</em><a class="headerlink" href="#socket_protocol.pure_json_protocol.SID_AUTH_KEY_CHECK_RESPONSE" title="Permalink to this definition">¶</a></dt>
346
-<dd><p>SID for the authentification response</p>
347
-</dd></dl>
348
-
349
-<dl class="attribute">
350
-<dt id="socket_protocol.pure_json_protocol.SID_AUTH_KEY_REQUEST">
351
-<code class="descname">SID_AUTH_KEY_REQUEST</code><em class="property"> = 2</em><a class="headerlink" href="#socket_protocol.pure_json_protocol.SID_AUTH_KEY_REQUEST" title="Permalink to this definition">¶</a></dt>
352
-<dd><p>SID for requesting a key for the given seed</p>
353
-</dd></dl>
354
-
355
-<dl class="attribute">
356
-<dt id="socket_protocol.pure_json_protocol.SID_AUTH_SEED_REQUEST">
357
-<code class="descname">SID_AUTH_SEED_REQUEST</code><em class="property"> = 1</em><a class="headerlink" href="#socket_protocol.pure_json_protocol.SID_AUTH_SEED_REQUEST" title="Permalink to this definition">¶</a></dt>
358
-<dd><p>SID for requesting a seed for authentification</p>
359
-</dd></dl>
360
-
361
-<dl class="attribute">
362
-<dt id="socket_protocol.pure_json_protocol.SID_CHANNEL_NAME_REQUEST">
363
-<code class="descname">SID_CHANNEL_NAME_REQUEST</code><em class="property"> = 5</em><a class="headerlink" href="#socket_protocol.pure_json_protocol.SID_CHANNEL_NAME_REQUEST" title="Permalink to this definition">¶</a></dt>
364
-<dd><p>SID for requesting a channel name exchange</p>
365
-</dd></dl>
366
-
367
-<dl class="attribute">
368
-<dt id="socket_protocol.pure_json_protocol.SID_CHANNEL_NAME_RESPONSE">
369
-<code class="descname">SID_CHANNEL_NAME_RESPONSE</code><em class="property"> = 6</em><a class="headerlink" href="#socket_protocol.pure_json_protocol.SID_CHANNEL_NAME_RESPONSE" title="Permalink to this definition">¶</a></dt>
370
-<dd><p>SID for the channel name response</p>
371
-</dd></dl>
372
-
373
-<dl class="attribute">
374
-<dt id="socket_protocol.pure_json_protocol.SID_EXECUTE_REQUEST">
375
-<code class="descname">SID_EXECUTE_REQUEST</code><em class="property"> = 30</em><a class="headerlink" href="#socket_protocol.pure_json_protocol.SID_EXECUTE_REQUEST" title="Permalink to this definition">¶</a></dt>
376
-<dd><p>SID for a execute request</p>
377
-</dd></dl>
378
-
379
-<dl class="attribute">
380
-<dt id="socket_protocol.pure_json_protocol.SID_EXECUTE_RESPONSE">
381
-<code class="descname">SID_EXECUTE_RESPONSE</code><em class="property"> = 31</em><a class="headerlink" href="#socket_protocol.pure_json_protocol.SID_EXECUTE_RESPONSE" title="Permalink to this definition">¶</a></dt>
382
-<dd><p>SID for a execute response</p>
383
-</dd></dl>
384
-
385
-<dl class="attribute">
386
-<dt id="socket_protocol.pure_json_protocol.SID_READ_REQUEST">
387
-<code class="descname">SID_READ_REQUEST</code><em class="property"> = 10</em><a class="headerlink" href="#socket_protocol.pure_json_protocol.SID_READ_REQUEST" title="Permalink to this definition">¶</a></dt>
388
-<dd><p>SID for a read data request</p>
389
-</dd></dl>
390
-
391
-<dl class="attribute">
392
-<dt id="socket_protocol.pure_json_protocol.SID_READ_RESPONSE">
393
-<code class="descname">SID_READ_RESPONSE</code><em class="property"> = 11</em><a class="headerlink" href="#socket_protocol.pure_json_protocol.SID_READ_RESPONSE" title="Permalink to this definition">¶</a></dt>
394
-<dd><p>SID for read data response</p>
395
-</dd></dl>
396
-
397
-<dl class="attribute">
398
-<dt id="socket_protocol.pure_json_protocol.SID_WRITE_REQUEST">
399
-<code class="descname">SID_WRITE_REQUEST</code><em class="property"> = 20</em><a class="headerlink" href="#socket_protocol.pure_json_protocol.SID_WRITE_REQUEST" title="Permalink to this definition">¶</a></dt>
400
-<dd><p>SID for a write data request</p>
401
-</dd></dl>
402
-
403
-<dl class="attribute">
404
-<dt id="socket_protocol.pure_json_protocol.SID_WRITE_RESPONSE">
405
-<code class="descname">SID_WRITE_RESPONSE</code><em class="property"> = 21</em><a class="headerlink" href="#socket_protocol.pure_json_protocol.SID_WRITE_RESPONSE" title="Permalink to this definition">¶</a></dt>
406
-<dd><p>SID for a write data response</p>
407
-</dd></dl>
408
-
409
-<dl class="attribute">
410
-<dt id="socket_protocol.pure_json_protocol.SID__NO_AUTH_LIST">
411
-<code class="descname">SID__NO_AUTH_LIST</code><em class="property"> = [1, 2, 3, 4, 5, 6]</em><a class="headerlink" href="#socket_protocol.pure_json_protocol.SID__NO_AUTH_LIST" title="Permalink to this definition">¶</a></dt>
412
-<dd><p>List of SIDs without need of an authentification</p>
413
-</dd></dl>
414
-
415
-<dl class="attribute">
416
-<dt id="socket_protocol.pure_json_protocol.SID__RESPONSE_DICT">
417
-<code class="descname">SID__RESPONSE_DICT</code><em class="property"> = {1: 2, 2: 3, 3: 4, 5: 6, 10: 11, 20: 21, 30: 31}</em><a class="headerlink" href="#socket_protocol.pure_json_protocol.SID__RESPONSE_DICT" title="Permalink to this definition">¶</a></dt>
418
-<dd><p>Dictionary to get the SID for the response by the key which is the SID for the request</p>
419
-</dd></dl>
420
-
421
-<dl class="attribute">
422
-<dt id="socket_protocol.pure_json_protocol.STATUS_AUTH_REQUIRED">
423
-<code class="descname">STATUS_AUTH_REQUIRED</code><em class="property"> = 2</em><a class="headerlink" href="#socket_protocol.pure_json_protocol.STATUS_AUTH_REQUIRED" title="Permalink to this definition">¶</a></dt>
424
-<dd><p>Status for ‘authentification is required’</p>
425
-</dd></dl>
426
-
427
-<dl class="attribute">
428
-<dt id="socket_protocol.pure_json_protocol.STATUS_BUFFERING_UNHANDLED_REQUEST">
429
-<code class="descname">STATUS_BUFFERING_UNHANDLED_REQUEST</code><em class="property"> = 1</em><a class="headerlink" href="#socket_protocol.pure_json_protocol.STATUS_BUFFERING_UNHANDLED_REQUEST" title="Permalink to this definition">¶</a></dt>
430
-<dd><p>Status for ‘unhandled request’</p>
431
-</dd></dl>
432
-
433
-<dl class="attribute">
434
-<dt id="socket_protocol.pure_json_protocol.STATUS_CHECKSUM_ERROR">
435
-<code class="descname">STATUS_CHECKSUM_ERROR</code><em class="property"> = 4</em><a class="headerlink" href="#socket_protocol.pure_json_protocol.STATUS_CHECKSUM_ERROR" title="Permalink to this definition">¶</a></dt>
436
-<dd><p>Status for ‘checksum error’</p>
437
-</dd></dl>
438
-
439
-<dl class="attribute">
440
-<dt id="socket_protocol.pure_json_protocol.STATUS_OKAY">
441
-<code class="descname">STATUS_OKAY</code><em class="property"> = 0</em><a class="headerlink" href="#socket_protocol.pure_json_protocol.STATUS_OKAY" title="Permalink to this definition">¶</a></dt>
442
-<dd><p>Status for ‘okay’</p>
468
+<dl class="method">
469
+<dt id="socket_protocol.pure_json_protocol.add_data">
470
+<code class="descname">add_data</code><span class="sig-paren">(</span><em>service_id</em>, <em>data_id</em>, <em>name</em><span class="sig-paren">)</span><a class="headerlink" href="#socket_protocol.pure_json_protocol.add_data" title="Permalink to this definition">¶</a></dt>
471
+<dd><p>Method to add a name for a specific message.</p>
472
+<table class="docutils field-list" frame="void" rules="none">
473
+<col class="field-name" />
474
+<col class="field-body" />
475
+<tbody valign="top">
476
+<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
477
+<li><strong>service_id</strong> (<em>int</em><em> or </em><em>list of ints</em>) – The Service-ID of the message. See class definitions starting with <code class="docutils literal notranslate"><span class="pre">SID_</span></code>.</li>
478
+<li><strong>data_id</strong> (<em>int</em>) – The Data-ID of the message.</li>
479
+<li><strong>name</strong> (<em>str</em>) – The Name for the transfered message.</li>
480
+</ul>
481
+</td>
482
+</tr>
483
+</tbody>
484
+</table>
443 485
 </dd></dl>
444 486
 
445
-<dl class="attribute">
446
-<dt id="socket_protocol.pure_json_protocol.STATUS_OPERATION_NOT_PERMITTED">
447
-<code class="descname">STATUS_OPERATION_NOT_PERMITTED</code><em class="property"> = 5</em><a class="headerlink" href="#socket_protocol.pure_json_protocol.STATUS_OPERATION_NOT_PERMITTED" title="Permalink to this definition">¶</a></dt>
448
-<dd><p>Status for ‘operation not permitted’</p>
487
+<dl class="method">
488
+<dt id="socket_protocol.pure_json_protocol.add_msg_to_auth_whitelist_">
489
+<code class="descname">add_msg_to_auth_whitelist_</code><span class="sig-paren">(</span><em>service_id</em>, <em>data_id</em><span class="sig-paren">)</span><a class="headerlink" href="#socket_protocol.pure_json_protocol.add_msg_to_auth_whitelist_" title="Permalink to this definition">¶</a></dt>
490
+<dd><p>Method to add a specific message to the list, where no authentification is required.</p>
491
+<table class="docutils field-list" frame="void" rules="none">
492
+<col class="field-name" />
493
+<col class="field-body" />
494
+<tbody valign="top">
495
+<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
496
+<li><strong>service_id</strong> (<em>int</em>) – The Service-ID of the message. See class definitions starting with <code class="docutils literal notranslate"><span class="pre">SID_</span></code>.</li>
497
+<li><strong>data_id</strong> (<em>int</em>) – The Data-ID of the message.</li>
498
+</ul>
499
+</td>
500
+</tr>
501
+</tbody>
502
+</table>
449 503
 </dd></dl>
450 504
 
451
-<dl class="attribute">
452
-<dt id="socket_protocol.pure_json_protocol.STATUS_SERVICE_OR_DATA_UNKNOWN">
453
-<code class="descname">STATUS_SERVICE_OR_DATA_UNKNOWN</code><em class="property"> = 3</em><a class="headerlink" href="#socket_protocol.pure_json_protocol.STATUS_SERVICE_OR_DATA_UNKNOWN" title="Permalink to this definition">¶</a></dt>
454
-<dd><p>Status for ‘service or data unknown’</p>
505
+<dl class="method">
506
+<dt id="socket_protocol.pure_json_protocol.add_service">
507
+<code class="descname">add_service</code><span class="sig-paren">(</span><em>req_sid</em>, <em>resp_sid</em>, <em>req_name=None</em>, <em>resp_name=None</em><span class="sig-paren">)</span><a class="headerlink" href="#socket_protocol.pure_json_protocol.add_service" title="Permalink to this definition">¶</a></dt>
508
+<dd><p>Method to add a Service defined by Request- and Response Serivce-ID.</p>
509
+<table class="docutils field-list" frame="void" rules="none">
510
+<col class="field-name" />
511
+<col class="field-body" />
512
+<tbody valign="top">
513
+<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
514
+<li><strong>req_sid</strong> (<em>int</em>) – The Request Service-ID.</li>
515
+<li><strong>resp_sid</strong> (<em>int</em>) – The Response Service-ID.</li>
516
+</ul>
517
+</td>
518
+</tr>
519
+</tbody>
520
+</table>
455 521
 </dd></dl>
456 522
 
457
-<dl class="attribute">
458
-<dt id="socket_protocol.pure_json_protocol.STATUS__NAMES">
459
-<code class="descname">STATUS__NAMES</code><em class="property"> = {0: 'Okay', 1: 'Request has no callback. Data buffered.', 2: 'Authentification required', 3: 'Service or Data unknown', 4: 'Checksum Error', 5: 'Operation not permitted'}</em><a class="headerlink" href="#socket_protocol.pure_json_protocol.STATUS__NAMES" title="Permalink to this definition">¶</a></dt>
460
-<dd><p>Status names for previous defined states</p>
523
+<dl class="method">
524
+<dt id="socket_protocol.pure_json_protocol.add_status">
525
+<code class="descname">add_status</code><span class="sig-paren">(</span><em>status</em>, <em>name</em><span class="sig-paren">)</span><a class="headerlink" href="#socket_protocol.pure_json_protocol.add_status" title="Permalink to this definition">¶</a></dt>
526
+<dd><p>Method to add a name for a status.</p>
527
+<table class="docutils field-list" frame="void" rules="none">
528
+<col class="field-name" />
529
+<col class="field-body" />
530
+<tbody valign="top">
531
+<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
532
+<li><strong>status</strong> (<em>int</em>) – The Status. See class definitions starting with <code class="docutils literal notranslate"><span class="pre">STATUS_</span></code>.</li>
533
+<li><strong>name</strong> (<em>str</em>) – The Name for the Status.</li>
534
+</ul>
535
+</td>
536
+</tr>
537
+</tbody>
538
+</table>
461 539
 </dd></dl>
462 540
 
463 541
 <dl class="method">
464 542
 <dt id="socket_protocol.pure_json_protocol.authentificate">
465 543
 <code class="descname">authentificate</code><span class="sig-paren">(</span><em>timeout=2</em><span class="sig-paren">)</span><a class="headerlink" href="#socket_protocol.pure_json_protocol.authentificate" title="Permalink to this definition">¶</a></dt>
466
-<dd><table class="docutils field-list" frame="void" rules="none">
544
+<dd><p>This method authetificates the client at the server.</p>
545
+<table class="docutils field-list" frame="void" rules="none">
467 546
 <col class="field-name" />
468 547
 <col class="field-body" />
469 548
 <tbody valign="top">
@@ -475,7 +554,6 @@
475 554
 </tr>
476 555
 </tbody>
477 556
 </table>
478
-<p>This method authetificates the client at the server.</p>
479 557
 <div class="admonition note">
480 558
 <p class="first admonition-title">Note</p>
481 559
 <p class="last">An authentification will only processed, if a secret had been given on initialisation.</p>
@@ -489,7 +567,8 @@
489 567
 <dl class="method">
490 568
 <dt id="socket_protocol.pure_json_protocol.check_authentification_state">
491 569
 <code class="descname">check_authentification_state</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#socket_protocol.pure_json_protocol.check_authentification_state" title="Permalink to this definition">¶</a></dt>
492
-<dd><table class="docutils field-list" frame="void" rules="none">
570
+<dd><p>This Method return the Authitification State as boolean value.</p>
571
+<table class="docutils field-list" frame="void" rules="none">
493 572
 <col class="field-name" />
494 573
 <col class="field-body" />
495 574
 <tbody valign="top">
@@ -504,7 +583,8 @@
504 583
 <dl class="method">
505 584
 <dt id="socket_protocol.pure_json_protocol.connection_established">
506 585
 <code class="descname">connection_established</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#socket_protocol.pure_json_protocol.connection_established" title="Permalink to this definition">¶</a></dt>
507
-<dd><table class="docutils field-list" frame="void" rules="none">
586
+<dd><p>This Method returns the Connection state including authentification as a boolean value.</p>
587
+<table class="docutils field-list" frame="void" rules="none">
508 588
 <col class="field-name" />
509 589
 <col class="field-body" />
510 590
 <tbody valign="top">
@@ -519,7 +599,8 @@
519 599
 <dl class="method">
520 600
 <dt id="socket_protocol.pure_json_protocol.is_connected">
521 601
 <code class="descname">is_connected</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#socket_protocol.pure_json_protocol.is_connected" title="Permalink to this definition">¶</a></dt>
522
-<dd><table class="docutils field-list" frame="void" rules="none">
602
+<dd><p>This Methods returns Connection state of the Communication Instance <code class="xref py py-func docutils literal notranslate"><span class="pre">comm_instance.is_connected()</span></code>.</p>
603
+<table class="docutils field-list" frame="void" rules="none">
523 604
 <col class="field-name" />
524 605
 <col class="field-body" />
525 606
 <tbody valign="top">
@@ -529,13 +610,13 @@
529 610
 </tr>
530 611
 </tbody>
531 612
 </table>
532
-<p>This methods returns the return value of <code class="xref py py-func docutils literal notranslate"><span class="pre">comm_instance.is_connected()</span></code>.</p>
533 613
 </dd></dl>
534 614
 
535 615
 <dl class="method">
536 616
 <dt id="socket_protocol.pure_json_protocol.receive">
537 617
 <code class="descname">receive</code><span class="sig-paren">(</span><em>service_id</em>, <em>data_id</em>, <em>timeout=1</em><span class="sig-paren">)</span><a class="headerlink" href="#socket_protocol.pure_json_protocol.receive" title="Permalink to this definition">¶</a></dt>
538
-<dd><table class="docutils field-list" frame="void" rules="none">
618
+<dd><p>This Method returns a message object for a defined message or None, if this message is not available after the given timout.</p>
619
+<table class="docutils field-list" frame="void" rules="none">
539 620
 <col class="field-name" />
540 621
 <col class="field-body" />
541 622
 <tbody valign="top">
@@ -565,64 +646,57 @@
565 646
 <dl class="method">
566 647
 <dt id="socket_protocol.pure_json_protocol.register_callback">
567 648
 <code class="descname">register_callback</code><span class="sig-paren">(</span><em>service_id</em>, <em>data_id</em>, <em>callback</em>, <em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#socket_protocol.pure_json_protocol.register_callback" title="Permalink to this definition">¶</a></dt>
568
-<dd><table class="docutils field-list" frame="void" rules="none">
649
+<dd><p>This method registers a callback for the given parameters. Giving <code class="docutils literal notranslate"><span class="pre">None</span></code> means, that all Service-IDs or all Data-IDs are used.
650
+If a message hitting these parameters has been received, the callback will be executed.</p>
651
+<table class="docutils field-list" frame="void" rules="none">
569 652
 <col class="field-name" />
570 653
 <col class="field-body" />
571 654
 <tbody valign="top">
572
-<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
655
+<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
573 656
 <li><strong>service_id</strong> (<em>int</em>) – The Service-ID for the message. See class definitions starting with <code class="docutils literal notranslate"><span class="pre">SID_</span></code>.</li>
574 657
 <li><strong>data_id</strong> (<em>int</em>) – The Data-ID for the message.</li>
575 658
 </ul>
576 659
 </td>
577 660
 </tr>
578
-<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">True, if registration was successfull; False, if registration failed (e.g. existance of a callback for this configuration)</p>
579
-</td>
580
-</tr>
581
-<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">bool</p>
582
-</td>
583
-</tr>
584 661
 </tbody>
585 662
 </table>
586
-<p>This method registers a callback for the given parameters. Givin <code class="docutils literal notranslate"><span class="pre">None</span></code> means, that all Service-IDs or all Data-IDs are used.
587
-If a message hitting these parameters has been received, the callback will be executed.</p>
588 663
 <div class="admonition note">
589 664
 <p class="first admonition-title">Note</p>
590 665
 <p>The <code class="xref py py-func docutils literal notranslate"><span class="pre">callback()</span></code> is priorised in the following order:</p>
591 666
 <ul class="last simple">
592 667
 <li>Callbacks with defined Service-ID and Data-ID.</li>
593
-<li>Callbacks with a defined Data-ID.</li>
594
-<li>Callbacks with a defined Service-ID.</li>
595
-<li>Unspecific Callbacks</li>
668
+<li>Callbacks with a defined Service-ID and all Data-IDs.</li>
669
+<li>Callbacks with a defined Data-ID and all Service-IDs.</li>
670
+<li>Unspecific Callbacks.</li>
596 671
 </ul>
597 672
 </div>
598 673
 <div class="admonition note">
599 674
 <p class="first admonition-title">Note</p>
600 675
 <p>The <code class="xref py py-func docutils literal notranslate"><span class="pre">callback()</span></code> is executed with these arguments:</p>
601
-<table class="docutils field-list" frame="void" rules="none">
602
-<col class="field-name" />
603
-<col class="field-body" />
604
-<tbody valign="top">
605
-<tr class="field-odd field"><th class="field-name">param msg:</th><td class="field-body">A <a class="reference internal" href="#socket_protocol.data_storage" title="socket_protocol.data_storage"><code class="xref py py-class docutils literal notranslate"><span class="pre">data_storage</span></code></a> object containing all message information.</td>
606
-</tr>
607
-<tr class="field-even field"><th class="field-name">returns:</th><td class="field-body">(<code class="xref py py-const docutils literal notranslate"><span class="pre">status</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">response_data</span></code>)</td>
608
-</tr>
609
-</tbody>
610
-</table>
676
+<p><strong>Parameters given at the callback call:</strong></p>
677
+<ul class="simple">
678
+<li>The first Arguments is the received message as <a class="reference internal" href="#socket_protocol.data_storage" title="socket_protocol.data_storage"><code class="xref py py-class docutils literal notranslate"><span class="pre">data_storage</span></code></a> object.</li>
679
+<li>Further arguments given at registration.</li>
680
+<li>Further keyword arguments given at registration.</li>
681
+</ul>
682
+<p><strong>Return value of the callback:</strong></p>
683
+<p>If the Callback is a Request Callback for a registered Service, the return value has to be a tuple or list with</p>
611 684
 <ul class="last simple">
612
-<li><code class="xref py py-const docutils literal notranslate"><span class="pre">status</span></code>: A status as defined as a constant of this class <code class="xref py py-const docutils literal notranslate"><span class="pre">STA_*</span></code> to be used as status for the response.</li>
685
+<li><code class="xref py py-const docutils literal notranslate"><span class="pre">response_status</span></code>: The response status (see class definitions starting with <code class="xref py py-const docutils literal notranslate"><span class="pre">STA_*</span></code>.</li>
613 686
 <li><code class="xref py py-const docutils literal notranslate"><span class="pre">response_data</span></code>: A JSON iterable object to be used as data for the response.</li>
614 687
 </ul>
615 688
 </div>
616 689
 <div class="admonition note">
617 690
 <p class="first admonition-title">Note</p>
618
-<p class="last">Only callbacks defined in <a class="reference internal" href="#socket_protocol.pure_json_protocol.SID__RESPONSE_DICT" title="socket_protocol.pure_json_protocol.SID__RESPONSE_DICT"><code class="xref py py-const docutils literal notranslate"><span class="pre">pure_json_protocol.SID__RESPONSE_DICT</span></code></a> will send a response, using a Service-ID given in the dict and the same Data-ID to the client.</p>
691
+<p class="last">Only registered services will respond via the callbacks return values with the same data_id.</p>
619 692
 </div>
620 693
 </dd></dl>
621 694
 
622 695
 <dl class="method">
623 696
 <dt id="socket_protocol.pure_json_protocol.send">
624
-<code class="descname">send</code><span class="sig-paren">(</span><em>service_id</em>, <em>data_id</em>, <em>data</em>, <em>status=0</em>, <em>timeout=2</em>, <em>log_lvl=20</em><span class="sig-paren">)</span><a class="headerlink" href="#socket_protocol.pure_json_protocol.send" title="Permalink to this definition">¶</a></dt>
625
-<dd><table class="docutils field-list" frame="void" rules="none">
697
+<code class="descname">send</code><span class="sig-paren">(</span><em>service_id</em>, <em>data_id</em>, <em>data</em>, <em>status=0</em>, <em>timeout=2</em><span class="sig-paren">)</span><a class="headerlink" href="#socket_protocol.pure_json_protocol.send" title="Permalink to this definition">¶</a></dt>
698
+<dd><p>This methods sends out a message with the given content.</p>
699
+<table class="docutils field-list" frame="void" rules="none">
626 700
 <col class="field-name" />
627 701
 <col class="field-body" />
628 702
 <tbody valign="top">
@@ -632,7 +706,6 @@ If a message hitting these parameters has been received, the callback will be ex
632 706
 <li><strong>data</strong> (<em>str</em>) – The data to be transfered. The data needs to be json compatible.</li>
633 707
 <li><strong>status</strong> (<em>int</em>) – The Status for the message. All requests should have <code class="docutils literal notranslate"><span class="pre">STATUS_OKAY</span></code>.</li>
634 708
 <li><strong>timeout</strong> (<em>float</em>) – The timeout for sending data (e.g. time to establish new connection).</li>
635
-<li><strong>rx_log_lvl</strong> (<em>int</em>) – The log level to log outgoing TX-data</li>
636 709
 </ul>
637 710
 </td>
638 711
 </tr>
@@ -644,7 +717,6 @@ If a message hitting these parameters has been received, the callback will be ex
644 717
 </tr>
645 718
 </tbody>
646 719
 </table>
647
-<p>This methods sends out a message with the given content.</p>
648 720
 </dd></dl>
649 721
 
650 722
 </dd></dl>

BIN
_docs_/objects.inv Näytä tiedosto


+ 1
- 1
_docs_/searchindex.js
File diff suppressed because it is too large
Näytä tiedosto


+ 11
- 0
_examples_/Makefile Näytä tiedosto

@@ -0,0 +1,11 @@
1
+EXAMPLES = $(wildcard *.py)
2
+LOGFILES = ${EXAMPLES:.py=.log}
3
+
4
+.PHONY: all
5
+all: $(LOGFILES)
6
+
7
+%.log: %.py
8
+	python3 $< > $@
9
+
10
+clean:
11
+	rm -f $(LOGFILES)

+ 78602
- 22731
_testresults_/unittest.json
File diff suppressed because it is too large
Näytä tiedosto


BIN
_testresults_/unittest.pdf Näytä tiedosto


Loading…
Peruuta
Tallenna