aiocoap
aiocoap copied to clipboard
Verbosity of aiocoap and dtls
Hey,
A year or two ago I created a python2 application to connect with the Ikea Tradfri devices. This was done with libcoap. Now I'm rewriting this code to python3.7 and using aiocoap 0.4a1 installed via pip as stated on the document section.
When I'm running my code I've noticed that dtls in aiocoap is putting "extra" output in the terminal. For my commandline tools this is very annoying because dtls is outputting the extra information to standard error and standard output. For all my commandline tool is have to redirect stderr to /dev/null and grep -v the decrypt messages.
Is there a way to make this less verbose, or create a option like somefunc(......., debug=False/True).?
--- snip ---
decrypt_verify(): found 300 bytes cleartext
decrypt_verify(): found 24 bytes cleartext
decrypt_verify(): found 306 bytes cleartext
+--------+-------------------------------------+-------+
| dev id | name | state |
+--------+-------------------------------------+-------+
| 65550 | lamp 1 | off |
| 65541 | lamp 2 | off |
| 65546 | lamp 3 | off |
| 65539 | lamp 4 | on |
| 65540 | lamp 5 | on |
| 65545 | lamp 6 | off |
| 65538 | lamp 7 | on |
| 65537 | lamp 8 | on |
| 65542 | lamp 9 | on |
+--------+-------------------------------------+-------+
Error in sys.excepthook:
Original exception was:
Error in sys.excepthook:
There is a way, but it requires some adaptions.
If you download DTLSSocket (https://pypi.org/project/DTLSSocket/#files) and make the following changes in the setup.py file:
define_macros=[('DTLSv12', '1'), ('WITH_SHA256', '1'), ('DTLS_CHECK_CONTENTTYPE', '1'), ('_GNU_SOURCE', '1'), ('NDEBUG', '1') ], # undef_macros = [ "NDEBUG" ], ),]
and then install DTLSSocket with $ python3 setup.py install, the extension will be compiled without the debug messages...
There's nothing aiocoap can do about this -- unfortunately, DTLSSocket outputs some extra data (which, as a library, it shouldn't). Please file an issue there (but feel free to report back here if there is no response in a reasonable timeframe).
I'll file an issue on the DTLSSocket repository. If there's no response, I'm willing to fork the module, make the required changes and try to maintain the the module for this project.
Turns out filing an issue isn't trivial, it requires singning in, and I haven't found a way to register... Might be blind, though...
On Thu, Dec 06, 2018 at 02:22:58PM -0800, moroen wrote:
it requires singning in, and I haven't found a way to register...
Oh, that's their university server -- I've dropped the author a mail pointing to this issue, that should be the easiest way forward.
The easiest way would probably be to set the loglevel [1], if that does'n help i can disable the logging in the config. AFAIK aiocoap doesn't use the DTLSSocket abstraction wich by default sets the loglevel to LOG_EMERG [2]
I'm not sure if you can file bugs in our gitlab without a University account, but you should see my mail on commits.
[1] https://git.fslab.de/jkonra2m/tinydtls-cython/blob/master/DTLSSocket/dtls.pyx#L265 [2] https://git.fslab.de/jkonra2m/tinydtls-cython/blob/master/DTLSSocket/DTLSSocket.py#L15
Thanks already guys hopefully we can file an issue
The decrypt_verify() messages are from tinydtls, and from the code, it looks like the only way to disable it, is by compiling with NDEBUG defined?
setting the loglevel should work for all messages, otherwise you might want to file a bug against tinydtls here: https://git.eclipse.org/r/#/q/status%3Aopen+project%3Atinydtls/org.eclipse.tinydtls
It's also possible to disable the decrypt_verify message by a couple of small changes to the setup.py file for DTLSSocket:
define_macros=[('DTLSv12', '1'), ('WITH_SHA256', '1'), ('DTLS_CHECK_CONTENTTYPE', '1'), ('_GNU_SOURCE', '1'), ('NDEBUG', '1') ],
and
# undef_macros = [ "NDEBUG" ], ),]
ok, i've had some time to look at the code and the problem seems to be this line: https://git.eclipse.org/c/tinydtls/org.eclipse.tinydtls.git/tree/dtls.c#n3035
the "decrypt_verify(): found %i bytes cleartext\n" is output using printf not the logsystem.
i'll change the setup.py but we should notify upstream
[edit] fixed version should now be on pypi [/edit]
Just installed latest from pypi, and confirmed that the decrypt_verify message is gone!
Thanks!
Thanks @kabel42 for fixing this!
Concerning the setLogLevel function (yes, aiocoap uses dtls.DTLS directly) -- and thus the logging: Is this aiocoap could in any form capture to ensure that it pipes any DTLS warnings into its own log, or is setting setLogLevel(DTLS_LOG_EMERG) actually best practice when using the library?
[edit: clarified between DTLSSocket and the library as a whole]
the underlying tinydtls is using printf for logging (when not running on contiki), i don't think there is an easy was to redirect that to a python buffer without modifying tinydtls. If you don't want the library to pollute your output yout want to set the loglevel to at least DTLS_LOG_CRIT.
PS. If anyone wants to make a PR, the logging happens in this funktion: https://git.eclipse.org/c/tinydtls/org.eclipse.tinydtls.git/tree/dtls_debug.c#n209
How to get rid of unwanted tinydtls messages:
When you download curl, you then download tinydtls separate and into the libcurl/ext directory.
When you're done downloading tinydtls into: libcurl/ext/tinydtls, do the following:
:libcurl/ext/tinydtsl$> configure --without-debug
Then return to the libcurl directory and make libcurl as you normally would. It'll make the tinydtls system, too, but will remove debug messages.