toxygen_wrapper/README.md

85 lines
3.6 KiB
Markdown
Raw Normal View History

2022-09-24 03:41:12 +00:00
# toxygen_wrapper
2022-09-26 04:37:38 +00:00
[ctypes](https://docs.python.org/3/library/ctypes.html)
2022-09-26 04:54:59 +00:00
wrapping of [Tox](https://tox.chat/)
[```libtoxcore```](https://github.com/TokTok/c-toxcore) into Python.
2022-09-26 04:37:38 +00:00
Taken from the ```wrapper``` directory of the now abandoned
2022-09-26 04:54:59 +00:00
<https://github.com/toxygen-project/toxygen> ```next_gen``` branch
2022-09-24 04:35:33 +00:00
by Ingvar.
2022-09-25 07:21:16 +00:00
The basics of NGC groups are supported, as well as AV and toxencryptsave.
2022-09-26 04:37:38 +00:00
There is no coverage of conferences as they are not used in ```toxygen```
2022-09-26 03:32:07 +00:00
and the list of still unwrapped calls as of Sept. 2022 can be found in
2022-09-26 04:37:38 +00:00
```tox.c-toxcore.missing```. The code still needs double-checking
that every call in ```tox.py``` has the right signature, but it runs
2022-09-26 04:54:59 +00:00
```toxygen``` with no apparent issues.
2022-09-26 03:32:07 +00:00
It has been tested with UDP and TCP proxy (Tor). It has ***not*** been
2022-09-26 04:37:38 +00:00
tested on Windows, and there may be some minor breakage, which should be
2022-10-01 19:01:20 +00:00
easy to fix. There is a good coverage integration testsuite in ```wrapper_tests```.
2022-10-07 04:47:34 +00:00
Change to that directory and run ```tests_wrapper.py --help```; the test
suite gives a good set of examples of usage.
2022-09-24 04:00:03 +00:00
## Install
Put the parent of the wrapper directory on your PYTHONPATH and
2022-09-26 03:32:07 +00:00
touch a file called `__init__.py` in its parent directory.
2022-09-24 04:00:03 +00:00
2022-09-26 04:37:38 +00:00
Then you need a ```libs``` directory beside the `wrapper` directory
and you need to link your ```libtoxcore.so``` and ```libtoxav.so```
and ```libtoxencryptsave.so``` into it. Link all 3 filenames
to ```libtoxcore.so``` if you have only ```libtoxcore.so```
(which is usually the case if you built ```c-toxcore``` with ```cmake```
rather than ```autogen/configure```). If you want to be different,
then just straighten out the filenames in ```libtox.py```.
2022-09-26 06:20:28 +00:00
As is, the code in ```tox.py``` is very verbose. Edit the file to change
```
def LOG_ERROR(a): print('EROR> '+a)
def LOG_WARN(a): print('WARN> '+a)
def LOG_INFO(a): print('INFO> '+a)
def LOG_DEBUG(a): print('DBUG> '+a)
def LOG_TRACE(a): pass # print('TRAC> '+a)
```
to all ```pass #``` or use ```logging.logger``` to suite your tastes.
```logging.logger``` can be dangerous in callbacks in ```Qt``` applications,
so we use simple print statements as default. The same applies to
```wrapper/tests_wrapper.py```.
2022-09-24 04:00:03 +00:00
## Prerequisites
2022-09-24 04:35:33 +00:00
No prerequisites in Python3.
2022-09-24 04:00:03 +00:00
2022-09-24 04:35:33 +00:00
## Other wrappers
2022-09-24 04:00:03 +00:00
There are a number of other wrappings into Python of Tox core.
2022-09-26 04:37:38 +00:00
This one uses [ctypes](https://docs.python.org/3/library/ctypes.html)
which has its merits - there is no need to recompile anything as with
Cython - change the Python file and it's done. And you can follow things
in a Python debugger, or with the utterly stupendous Python feature of
2022-09-26 04:54:59 +00:00
```gdb``` (```gdb -ex r --args /usr/bin/python3.9 <pyfile>```).
2022-09-26 04:37:38 +00:00
2022-09-25 07:21:16 +00:00
CTYPES code can be brittle, segfaulting if you've got things wrong,
2022-09-24 04:35:33 +00:00
but if your wrapping is right, it is very efficient and easy to work on.
2022-09-26 04:54:59 +00:00
The [faulthandler](https://docs.python.org/3/library/faulthandler.html)
module can be helpful in debugging crashes
(e.g. from segmentation faults produced by erroneous C library wrapping).
2022-09-24 04:00:03 +00:00
Others include:
2022-09-24 04:35:33 +00:00
* <https://github.com/TokTok/py-toxcore-c> Cython bindings.
Incomplete and not really actively supported. Maybe it will get
worked on in the future, but TokTok seems to be working on
2022-09-25 07:21:16 +00:00
java, rust, scalla, go, etc. bindings instead.
No support for NGC groups or toxencryptsave.
2022-09-24 04:35:33 +00:00
* <https://github.com/oxij/PyTox>
forked from https://github.com/aitjcize/PyTox
by Wei-Ning Huang <aitjcize@gmail.com>.
2022-09-25 07:21:16 +00:00
Hardcore C wrapping which is not easy to keep up to date.
No support for NGC or toxencryptsave. Abandonned.
This was the basis for the TokTok/py-toxcore-c code until recently.
2022-10-07 04:47:34 +00:00
To our point of view, the ability of CTYPEs to follow code in the
debugger is crucial.