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
|
2024-03-08 04:00:36 +00:00
|
|
|
<https://github.com/toxygen-project/toxygen> ```next_gen``` branch by Ingvar.
|
2023-12-07 19:38:26 +00:00
|
|
|
|
2024-03-08 04:00:36 +00:00
|
|
|
There is not complete coverage of the c-toxcore api - they're written to support
|
|
|
|
the [toxygeb](https://git.plastiras.org/emdee/toxygen) client.
|
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```
|
2024-02-24 16:04:19 +00:00
|
|
|
and the list of still unwrapped calls as of Feb. 2024 can be found in
|
2024-03-08 04:00:36 +00:00
|
|
|
```docs/tox.c-toxcore.missing```. The code is typed so that every call in
|
|
|
|
```tox*.py``` should have the right signature, and it runs ```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
|
2024-02-19 12:45:23 +00:00
|
|
|
easy to fix. There is a good coverage integration testsuite in ```toxygen_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
|
|
|
|
|
2024-02-24 16:04:19 +00:00
|
|
|
Edit the Makefile and run ```make install``` or ```cd src```
|
|
|
|
and run ```toxygen_wrapper/tests/tests_wrapper.py```
|
2022-09-24 04:00:03 +00:00
|
|
|
|
2024-02-19 12:45:23 +00:00
|
|
|
Then you need a ```libs``` directory beside the ```toxygen_wrapper``` directory
|
2022-09-26 04:37:38 +00:00
|
|
|
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,
|
2023-12-15 14:24:07 +00:00
|
|
|
the environment variable TOXCORE_LIBS overrides the location of ```libs```;
|
2024-02-19 12:45:23 +00:00
|
|
|
look in the file ```toxygen_wrapper/libtox.py``` for the details.
|
2023-12-15 14:24:07 +00:00
|
|
|
|
|
|
|
# Tests
|
|
|
|
|
2024-02-24 16:04:19 +00:00
|
|
|
To test, run ```python3 src/toxygen_wrapper/tests/tests_wrapper.py --help```
|
2022-09-26 04:37:38 +00:00
|
|
|
|
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
|
2024-02-19 12:45:23 +00:00
|
|
|
```toxygen_wrapper/tests/tests_wrapper.py```.
|
2022-09-26 06:20:28 +00:00
|
|
|
|
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
|
|
|
|
2024-02-24 15:52:18 +00:00
|
|
|
Because this is using Ctypes, you can run it under a python-enabled gdb,
|
|
|
|
which if you compiled the c-toxcore library ```-DCMAKE_BUILD_TYPE="Debug"```
|
|
|
|
means that you can run both the Python and the C under gdb. This is HUGE!
|
|
|
|
The incantation is something like this:
|
|
|
|
```
|
|
|
|
gdb -ex r --args /usr/bin/python3 src/toxygen_wrapper/tests/tests_wrapper.py
|
|
|
|
```
|
|
|
|
with some suitable settings of PYTHONPATH and maybe LD_LIBRARY_PATH.
|
|
|
|
|
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
|
2024-03-08 04:00:36 +00:00
|
|
|
java, go, etc. bindings instead, based on a homebrew generator written
|
|
|
|
in undocumented, uncommented code in a language almost nobody knows, that
|
|
|
|
nobody has installed, written by anonymous coders that are not open to suggestions.
|
|
|
|
There's no active support by ```gdb`` for debugging Cython and python together
|
|
|
|
like there is for cmake and ```gdb```. These bindings have no support for NGC
|
|
|
|
groups; and no significant tests.
|
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.
|
2024-02-24 15:52:18 +00:00
|
|
|
No support for NGC but good tests. Abandonned.
|
2024-02-25 03:11:22 +00:00
|
|
|
This was the basis for the TokTok/py-toxcore-c code until recently,
|
|
|
|
and a version is on the 0.2.0 branch of
|
|
|
|
[TokTok/py-toxcore-c](https://github.com/TokTok/py-toxcore-c)
|
2022-10-07 04:47:34 +00:00
|
|
|
|
2024-03-08 04:00:36 +00:00
|
|
|
To our point of view, the ability of these ```ctypes``` to follow code python and C
|
|
|
|
code in the debugger is a crucial advantage.
|
2022-10-18 00:16:56 +00:00
|
|
|
|
2024-02-14 03:05:14 +00:00
|
|
|
## Updates
|
|
|
|
|
|
|
|
Although Tox works over Tor, we do not recommend its usage for
|
|
|
|
anonymity as it leaks DNS requests due to a 6-year old known security
|
2024-02-17 20:33:51 +00:00
|
|
|
issue: https://github.com/TokTok/c-toxcore/issues/469 unless your Tox client
|
2024-02-19 12:45:23 +00:00
|
|
|
does hostname lookups before calling Tox (like toxygen does). Otherwise,
|
|
|
|
do not use it for anonymous communication unless you have a firewall in place.
|
2024-02-17 20:33:51 +00:00
|
|
|
|
2024-02-19 12:45:23 +00:00
|
|
|
The Tox project does not follow semantic versioning of its main structures
|
2024-02-25 03:11:22 +00:00
|
|
|
or setters so the project may break the underlying ctypes wrapper at any time;
|
2024-02-19 12:45:23 +00:00
|
|
|
it's not possible to use Tox version numbers to tell what the API will be.
|
2024-03-08 04:00:36 +00:00
|
|
|
In which case you may have to go into the tox.py file in
|
2024-02-17 20:33:51 +00:00
|
|
|
https://git.plastiras.org/emdee/toxygen_wrapper to fix it yourself.
|
2024-02-19 12:45:23 +00:00
|
|
|
The last tested git commit is 5dd9ee3f65423a4095cacb8396a5d406a27610c7
|
|
|
|
2024-02-10
|
2024-02-14 03:05:14 +00:00
|
|
|
|
2024-02-04 01:07:37 +00:00
|
|
|
Up-to-date code is on https://git.plastiras.org/emdee/toxygen_wrapper
|
|
|
|
|
2022-10-18 00:16:56 +00:00
|
|
|
Work on this project is suspended until the
|
2022-10-27 06:50:47 +00:00
|
|
|
[MultiDevice](https://git.plastiras.org/emdee/tox_profile/wiki/MultiDevice-Announcements-POC) problem is solved. Fork me!
|
2024-02-04 01:07:37 +00:00
|
|
|
|