Thus, a simplified version of the connection with the DHT node and the duty cycle can be represented as: The public key of the local DHT node can be found in the system log after the daemon starts. For more information on starting the daemon, see the corresponding README., and for tox.pkg project deb distributions, the tox-bootstrapd package installation is self- sufficient. The configuration of the daemon is specified in the /etc/nf file and is well documented. It can be assembled together with the toxcore library, as well as get in binary form from the developers repository. To raise a local node, you will need to install and configure the tox-bootstrapd daemon. An additional plus of having a local node, in addition to constant communication with it, is the “strengthening" of the Tox network itself. You can try to reduce the required number of DHT nodes to connect by raising your own local DHT node. In the case of loading from the status file, the client should not try to connect within 10 seconds after the first call tox_iterate and, if there is no connection, repeat the aggressive connection strategy above.įor a bot that plans to always be in touch, these recommendations look a bit overcomplicated. Īccording to the Tox Client Guidelines, every 5 seconds a client should try to connect to at least four random nodes until the kernel reports a successful connection (see tox_self_connection_status_cb ). An initial list of DHT nodes can be found on the project wiki. The DHT node is determined by the IP address, port number, and public key. Specific handlers and their arguments will be discussed below. Default values can be obtained by calling the tox_options_default method : In python, it can be a dictionary with fields of the same name. To initialize the kernel, the Tox_Options structure is used as a parameter. You must use this function even if Tox_Options.udp_enabled was set to false.īelow we will dwell on each step of working with the API in a little more detail. | This function will attempt to connect to the node using UDP. | Sends a "get nodes" request to the given bootstrap node with IP, port, and public key to setup connections. | tox_bootstrap(address, port, public_key) | This function can be used to initiate TCP connections to different ports on the same bootstrap node, or to add TCP relays without using them as bootstrap nodes. | Adds additional host:port pair as TCP relay. | tox_add_tcp_relay(address, port, public_key) When using the python wrapper, you can get help for the library in the following way: For those who do not want to engage in self-assembly of the library from the source, there are also links to ready-made binary packages for common distributions. Pause tox_iteration_interval and return to the previous step.īecause the main way to gain knowledge of the Tox API is to read the source code (written in C), to simplify further presentation, I will use a wrapper for the python language ( pytoxcore on github ).The main duty cycle ( tox_iterate ) and event handling.Connection to one or more DHT nodes ( tox_bootstrap ).Setting callback functions for event processing ( tox_callback_ * ) - event handlers are called from the main loop (4) and the main logic of the application is usually concentrated in them.Initialization of the kernel ( tox_new ) - here you set the protocols (IPv4 / IPv6, UDP / TCP), proxy settings (HTTP / SOCKS5), the ranges of ports used and (if available) download the previously saved state with the list of contacts.The general cycle of work with the Tox API can be represented sequentially in the form: Checksum (2 bytes or 4 characters) - XOR operation on the public key and the value “nospam”, serves to quickly check the correctness of ToxID.Protection against spam "nospam" (4 bytes or 8 characters) - a random data set, the change of which allows you to continue to maintain previously authorized contacts, but ignore requests from new ones.Public key (32 bytes or 64 characters).The contact unit is ToxID (aka “address” in terms of API) - a hexadecimal string of 76 characters in length, encoding: ToxDNS - a subsystem for obtaining ToxID from a human-readable address (an approximate analogue of email or JabberID) through a query to DNS.ToxAV - a subsystem of voice and video calls.ToxCore is, in fact, the core itself, which allows you to manage contacts, messages, files, avatars, statuses and group chats.The Tox kernel ( toxcore on github ) consists of three parts: Against the background of the general enthusiasm for creating bots for Telegram, I would like to talk about the Tox instant messenger API and show on the example of a simple echo bot how you can create your own just as easily and quickly.
0 Comments
Leave a Reply. |