Browse Source

Channel logging merge

master
Dirk Alders 4 years ago
parent
commit
c04c1abeea
3 changed files with 18680 additions and 13375 deletions
  1. 101
    0
      __init__.py
  2. 18579
    13375
      _testresults_/unittest.json
  3. BIN
      _testresults_/unittest.pdf

+ 101
- 0
__init__.py View File

@@ -88,7 +88,11 @@ class callback_storage(dict):
88 88
     def add(self, service_id, data_id, callback, *args, **kwargs):
89 89
         cb_data = self.get(service_id, data_id)
90 90
         if cb_data != (None, None, None):
91
+<<<<<<< HEAD
91 92
             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__))
93
+=======
94
+            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__))
95
+>>>>>>> 8beacaef2257e82852e1c0b5442ec4d09b891b7c
92 96
         if service_id not in self:
93 97
             self[service_id] = {}
94 98
         self[service_id][data_id] = (callback, args, kwargs)
@@ -143,8 +147,11 @@ class struct_json_protocol(object):
143 147
 
144 148
     .. literalinclude:: ../../socket_protocol/_examples_/socket_protocol__struct_json_protocol_client.log
145 149
     """
150
+<<<<<<< HEAD
146 151
     DEFAULT_CHANNEL_NAME = 'all_others'
147 152
 
153
+=======
154
+>>>>>>> 8beacaef2257e82852e1c0b5442ec4d09b891b7c
148 155
     SID_AUTH_SEED_REQUEST = 1
149 156
     SID_AUTH_KEY_REQUEST = 2
150 157
     SID_AUTH_KEY_CHECK_REQUEST = 3
@@ -196,9 +203,13 @@ class struct_json_protocol(object):
196 203
         self.__comm_inst__ = comm_instance
197 204
         self.__secret__ = secret
198 205
         self.__auto_auth__ = auto_auth
206
+<<<<<<< HEAD
199 207
         #
200 208
         self.__callbacks__ = callback_storage(channel_name)
201 209
         self.__init_channel_name__(channel_name)
210
+=======
211
+        self.__channel_name__ = channel_name
212
+>>>>>>> 8beacaef2257e82852e1c0b5442ec4d09b891b7c
202 213
         #
203 214
         self.__clean_receive_buffer__()
204 215
         self.__callbacks__.add(self.SID_AUTH_SEED_REQUEST, 0, self.__authentificate_create_seed__)
@@ -213,6 +224,7 @@ class struct_json_protocol(object):
213 224
         self.__comm_inst__.register_connect_callback(self.__connection_established__)
214 225
         self.__comm_inst__.register_disconnect_callback(self.__authentification_state_reset__)
215 226
 
227
+<<<<<<< HEAD
216 228
     def __init_channel_name__(self, channel_name):
217 229
         self.__comm_inst__.init_channel_name(channel_name)
218 230
         self.__callbacks__.init_channel_name(channel_name)
@@ -229,6 +241,14 @@ class struct_json_protocol(object):
229 241
 
230 242
     def __log_prefix__(self):
231 243
         return ' SP client:' if self.__comm_inst__.IS_CLIENT else ' SP server:'
244
+=======
245
+    def __log_prefix__(self):
246
+        postfix = ' (client)' if self.__comm_inst__.IS_CLIENT else ' (server)'
247
+        if self.__channel_name__ is None:
248
+            return __name__ + postfix + ':'
249
+        else:
250
+            return self.__channel_name__ + postfix + ':'
251
+>>>>>>> 8beacaef2257e82852e1c0b5442ec4d09b891b7c
232 252
 
233 253
     def connected(self):
234 254
         return self.__comm_inst__.is_connected()
@@ -252,22 +272,39 @@ class struct_json_protocol(object):
252 272
             return self.STATUS_OKAY, self.__channel_name__
253 273
         else:
254 274
             prev_channel_name = self.__channel_name__
275
+<<<<<<< HEAD
255 276
             self.__init_channel_name__(data)
256 277
             if prev_channel_name is not None and prev_channel_name != data:
257 278
                 self.logger.warning('%s overwriting user defined channel name from %s to %s', self.__log_prefix__(), repr(prev_channel_name), repr(data))
258 279
             elif prev_channel_name is None:
259 280
                 self.logger.info('%s channel name is now %s', self.__log_prefix__(), repr(self.__channel_name__))
281
+=======
282
+            self.__channel_name__ = data
283
+            if prev_channel_name is not None and prev_channel_name != data:
284
+                logger.warning('%s overwriting user defined channel name from %s to %s', self.__log_prefix__(), repr(prev_channel_name), repr(data))
285
+            elif prev_channel_name is None:
286
+                logger.info('%s channel name is now %s', self.__log_prefix__(), repr(self.__channel_name__))
287
+>>>>>>> 8beacaef2257e82852e1c0b5442ec4d09b891b7c
260 288
             return self.STATUS_OKAY, None
261 289
 
262 290
     def __channel_name_response__(self, msg):
263 291
         data = msg.get_data()
264 292
         if self.__channel_name__ is None and data is not None:
293
+<<<<<<< HEAD
265 294
             self.__init_channel_name__(data)
266 295
             self.logger.info('%s channel name is now %s', self.__log_prefix__(), repr(self.__channel_name__))
267 296
         return self.STATUS_OKAY, None
268 297
 
269 298
     def __authentification_state_reset__(self):
270 299
         self.logger.info("%s Resetting authentification state to AUTH_STATE_UNKNOWN_CLIENT", self.__log_prefix__())
300
+=======
301
+            self.__channel_name__ = data
302
+            logger.info('%s channel name is now %s', self.__log_prefix__(), repr(self.__channel_name__))
303
+        return self.STATUS_OKAY, None
304
+
305
+    def __authentification_state_reset__(self):
306
+        logger.info("%s Resetting authentification state to AUTH_STATE_UNKNOWN_CLIENT", self.__log_prefix__())
307
+>>>>>>> 8beacaef2257e82852e1c0b5442ec4d09b891b7c
271 308
         self.__authentification_state__ = self.AUTH_STATE_UNKNOWN_CLIENT
272 309
 
273 310
     def __analyse_frame__(self, frame):
@@ -306,7 +343,11 @@ class struct_json_protocol(object):
306 343
     def __data_available_callback__(self, comm_inst):
307 344
         frame = comm_inst.receive()
308 345
         if not self.__check_frame_checksum__(frame):
346
+<<<<<<< HEAD
309 347
             self.logger.warning("%s Received message has a wrong checksum and will be ignored: %s.", self.__log_prefix__(), stringtools.hexlify(frame))
348
+=======
349
+            logger.warning("%s Received message has a wrong checksum and will be ignored: %s.", self.__log_prefix__(), stringtools.hexlify(frame))
350
+>>>>>>> 8beacaef2257e82852e1c0b5442ec4d09b891b7c
310 351
         else:
311 352
             msg = self.__analyse_frame__(frame)
312 353
             self.logger.info(
@@ -325,14 +366,24 @@ class struct_json_protocol(object):
325 366
                 if self.__secret__ is not None and not self.check_authentification_state() and msg.get_service_id() not in self.SID_AUTH_LIST:
326 367
                     status = self.STATUS_AUTH_REQUIRED
327 368
                     data = None
369
+<<<<<<< HEAD
328 370
                     self.logger.warning("%s Received message needs authentification: %s. Sending negative response.", self.__log_prefix__(), self.AUTH_STATUS_NAMES.get(self.__authentification_state__, 'Unknown authentification status!'))
329 371
                 elif callback is None:
330 372
                     self.logger.warning("%s Received message with no registered callback. Sending negative response.", self.__log_prefix__())
373
+=======
374
+                    logger.warning("%s Received message needs authentification: %s. Sending negative response.", self.__log_prefix__(), self.AUTH_STATUS_NAMES.get(self.__authentification_state__, 'Unknown authentification status!'))
375
+                elif callback is None:
376
+                    logger.warning("%s Received message with no registered callback. Sending negative response.", self.__log_prefix__())
377
+>>>>>>> 8beacaef2257e82852e1c0b5442ec4d09b891b7c
331 378
                     status = self.STATUS_BUFFERING_UNHANDLED_REQUEST
332 379
                     data = None
333 380
                 else:
334 381
                     try:
382
+<<<<<<< HEAD
335 383
                         self.logger.debug("%s Executing callback %s to process received data", self.__log_prefix__(), callback.__name__)
384
+=======
385
+                        logger.debug("%s Executing callback %s to process received data", self.__log_prefix__(), callback.__name__)
386
+>>>>>>> 8beacaef2257e82852e1c0b5442ec4d09b891b7c
336 387
                         status, data = callback(msg, *args, **kwargs)
337 388
                     except TypeError:
338 389
                         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())))
@@ -342,14 +393,22 @@ class struct_json_protocol(object):
342 393
                 # RESPONSE RECEIVED
343 394
                 #
344 395
                 if msg.get_status() not in [self.STATUS_OKAY]:
396
+<<<<<<< HEAD
345 397
                     self.logger.warning("%s Received message has a peculiar status: %s", self.__log_prefix__(), self.STATUS_NAMES.get(msg.get_status(), 'Unknown status response!'))
398
+=======
399
+                    logger.warning("%s Received message has a peculiar status: %s", self.__log_prefix__(), self.STATUS_NAMES.get(msg.get_status(), 'Unknown status response!'))
400
+>>>>>>> 8beacaef2257e82852e1c0b5442ec4d09b891b7c
346 401
                 if callback is None:
347 402
                     status = self.STATUS_OKAY
348 403
                     data = None
349 404
                     self.__buffer_received_data__(msg)
350 405
                 else:
351 406
                     try:
407
+<<<<<<< HEAD
352 408
                         self.logger.debug("%s Executing callback %s to process received data", self.__log_prefix__(), callback.__name__)
409
+=======
410
+                        logger.debug("%s Executing callback %s to process received data", self.__log_prefix__(), callback.__name__)
411
+>>>>>>> 8beacaef2257e82852e1c0b5442ec4d09b891b7c
353 412
                         status, data = callback(msg, *args, **kwargs)
354 413
                     except TypeError:
355 414
                         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())))
@@ -360,10 +419,17 @@ class struct_json_protocol(object):
360 419
         if not msg.get_data_id() in self.__msg_buffer__[msg.get_service_id()]:
361 420
             self.__msg_buffer__[msg.get_service_id()][msg.get_data_id()] = []
362 421
         self.__msg_buffer__[msg.get_service_id()][msg.get_data_id()].append(msg)
422
+<<<<<<< HEAD
363 423
         self.logger.debug("%s Message data is stored in buffer and is now ready to be retrieved by receive method", self.__log_prefix__())
364 424
 
365 425
     def __clean_receive_buffer__(self):
366 426
         self.logger.debug("%s Cleaning up receive-buffer", self.__log_prefix__())
427
+=======
428
+        logger.debug("%s Message data is stored in buffer and is now ready to be retrieved by receive method", self.__log_prefix__())
429
+
430
+    def __clean_receive_buffer__(self):
431
+        logger.debug("%s Cleaning up receive-buffer", self.__log_prefix__())
432
+>>>>>>> 8beacaef2257e82852e1c0b5442ec4d09b891b7c
367 433
         self.__msg_buffer__ = {}
368 434
 
369 435
     def receive(self, service_id, data_id, timeout=1):
@@ -377,7 +443,11 @@ class struct_json_protocol(object):
377 443
             cnt += 1
378 444
             time.sleep(0.1)
379 445
         if data is None and cnt >= timeout * 10:
446
+<<<<<<< HEAD
380 447
             self.logger.warning('%s TIMEOUT (%ss): Requested data (service_id: %s; data_id: %s) not in buffer.', self.__log_prefix__(), repr(timeout), repr(service_id), repr(data_id))
448
+=======
449
+            logger.warning('%s TIMEOUT (%ss): Requested data (service_id: %s; data_id: %s) not in buffer.', self.__log_prefix__(), repr(timeout), repr(service_id), repr(data_id))
450
+>>>>>>> 8beacaef2257e82852e1c0b5442ec4d09b891b7c
381 451
         return data
382 452
 
383 453
     def __mk_msg__(self, status, service_id, data_id, data):
@@ -402,7 +472,11 @@ class struct_json_protocol(object):
402 472
 
403 473
         This methods sends out a message with the given content.
404 474
         """
475
+<<<<<<< HEAD
405 476
         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))
477
+=======
478
+        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))
479
+>>>>>>> 8beacaef2257e82852e1c0b5442ec4d09b891b7c
406 480
         return self.__comm_inst__.send(self.__build_frame__(service_id, data_id, data, status), timeout=timeout, log_lvl=logging.DEBUG)
407 481
 
408 482
     def register_callback(self, service_id, data_id, callback, *args, **kwargs):
@@ -446,7 +520,11 @@ class struct_json_protocol(object):
446 520
         """
447 521
         if self.__secret__ is not None:
448 522
             self.__authentification_state__ = self.AUTH_STATE_SEED_REQUESTED
523
+<<<<<<< HEAD
449 524
             self.logger.info("%s Requesting seed for authentification", self.__log_prefix__())
525
+=======
526
+            logger.info("%s Requesting seed for authentification", self.__log_prefix__())
527
+>>>>>>> 8beacaef2257e82852e1c0b5442ec4d09b891b7c
450 528
             self.send(self.SID_AUTH_SEED_REQUEST, 0, None)
451 529
             cnt = 0
452 530
             while cnt < timeout * 10:
@@ -472,7 +550,11 @@ class struct_json_protocol(object):
472 550
             return hashlib.sha512(seed.encode('utf-8') + self.__secret__.encode('utf-8')).hexdigest()
473 551
 
474 552
     def __authentificate_create_seed__(self, msg):
553
+<<<<<<< HEAD
475 554
         self.logger.info("%s Got seed request, sending seed for authentification", self.__log_prefix__())
555
+=======
556
+        logger.info("%s Got seed request, sending seed for authentification", self.__log_prefix__())
557
+>>>>>>> 8beacaef2257e82852e1c0b5442ec4d09b891b7c
476 558
         self.__authentification_state__ = self.AUTH_STATE_SEED_TRANSFERRED
477 559
         if sys.version_info >= (3, 0):
478 560
             self.__seed__ = binascii.hexlify(os.urandom(32)).decode('utf-8')
@@ -481,7 +563,11 @@ class struct_json_protocol(object):
481 563
         return self.STATUS_OKAY, self.__seed__
482 564
 
483 565
     def __authentificate_create_key__(self, msg):
566
+<<<<<<< HEAD
484 567
         self.logger.info("%s Got seed, sending key for authentification", self.__log_prefix__())
568
+=======
569
+        logger.info("%s Got seed, sending key for authentification", self.__log_prefix__())
570
+>>>>>>> 8beacaef2257e82852e1c0b5442ec4d09b891b7c
485 571
         self.__authentification_state__ = self.AUTH_STATE_KEY_TRANSFERRED
486 572
         seed = msg.get_data()
487 573
         key = self.__authentificate_salt_and_hash__(seed)
@@ -491,21 +577,36 @@ class struct_json_protocol(object):
491 577
         key = msg.get_data()
492 578
         if key == self.__authentificate_salt_and_hash__(self.__seed__):
493 579
             self.__authentification_state__ = self.AUTH_STATE_TRUSTED_CLIENT
580
+<<<<<<< HEAD
494 581
             self.logger.info("%s Got correct key, sending positive authentification feedback", self.__log_prefix__())
495 582
             return self.STATUS_OKAY, True
496 583
         else:
497 584
             self.__authentification_state__ = self.AUTH_STATE_UNKNOWN_CLIENT
498 585
             self.logger.info("%s Got incorrect key, sending negative authentification feedback", self.__log_prefix__())
586
+=======
587
+            logger.info("%s Got correct key, sending positive authentification feedback", self.__log_prefix__())
588
+            return self.STATUS_OKAY, True
589
+        else:
590
+            self.__authentification_state__ = self.AUTH_STATE_UNKNOWN_CLIENT
591
+            logger.info("%s Got incorrect key, sending negative authentification feedback", self.__log_prefix__())
592
+>>>>>>> 8beacaef2257e82852e1c0b5442ec4d09b891b7c
499 593
             return self.STATUS_OKAY, False
500 594
 
501 595
     def __authentificate_process_feedback__(self, msg):
502 596
         feedback = msg.get_data()
503 597
         if feedback:
504 598
             self.__authentification_state__ = self.AUTH_STATE_TRUSTED_CLIENT
599
+<<<<<<< HEAD
505 600
             self.logger.info("%s Got positive authentification feedback", self.__log_prefix__())
506 601
         else:
507 602
             self.__authentification_state__ = self.AUTH_STATE_UNKNOWN_CLIENT
508 603
             self.logger.warning("%s Got negative authentification feedback", self.__log_prefix__())
604
+=======
605
+            logger.info("%s Got positive authentification feedback", self.__log_prefix__())
606
+        else:
607
+            self.__authentification_state__ = self.AUTH_STATE_UNKNOWN_CLIENT
608
+            logger.warning("%s Got negative authentification feedback", self.__log_prefix__())
609
+>>>>>>> 8beacaef2257e82852e1c0b5442ec4d09b891b7c
509 610
         return self.STATUS_OKAY, None
510 611
 
511 612
 

+ 18579
- 13375
_testresults_/unittest.json
File diff suppressed because it is too large
View File


BIN
_testresults_/unittest.pdf View File


Loading…
Cancel
Save