summaryrefslogtreecommitdiff
path: root/toxcore/tox.h
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/tox.h')
-rw-r--r--toxcore/tox.h101
1 files changed, 89 insertions, 12 deletions
diff --git a/toxcore/tox.h b/toxcore/tox.h
index 6d5db49f..c52a644f 100644
--- a/toxcore/tox.h
+++ b/toxcore/tox.h
@@ -26,6 +26,22 @@
26 26
27#include <stdint.h> 27#include <stdint.h>
28 28
29#ifdef WIN32
30#ifndef WINVER
31//Windows XP
32#define WINVER 0x0501
33#endif
34
35#include <winsock2.h>
36#include <windows.h>
37#include <ws2tcpip.h>
38
39#else
40
41#include <netinet/ip.h>
42
43#endif
44
29#ifdef __cplusplus 45#ifdef __cplusplus
30extern "C" { 46extern "C" {
31#endif 47#endif
@@ -36,19 +52,56 @@ extern "C" {
36 52
37#define TOX_FRIEND_ADDRESS_SIZE (TOX_CLIENT_ID_SIZE + sizeof(uint32_t) + sizeof(uint16_t)) 53#define TOX_FRIEND_ADDRESS_SIZE (TOX_CLIENT_ID_SIZE + sizeof(uint32_t) + sizeof(uint16_t))
38 54
55#define TOX_PORTRANGE_FROM 33445
56#define TOX_PORTRANGE_TO 33455
57#define TOX_PORT_DEFAULT TOX_PORTRANGE_FROM
39 58
40typedef union { 59typedef union {
41 uint8_t c[4]; 60 uint8_t c[4];
42 uint16_t s[2]; 61 uint16_t s[2];
43 uint32_t i; 62 uint32_t i;
44} tox_IP; 63} tox_IP4;
64
65
66typedef struct in6_addr tox_IP6;
67
68typedef struct {
69 sa_family_t family;
70 union {
71 tox_IP4 ip4;
72 tox_IP6 ip6;
73 };
74} tox_IPAny;
45 75
76typedef union {
77 struct {
78 tox_IP4 ip;
79 uint16_t port;
80 /* Not used for anything right now. */
81 uint16_t padding;
82 };
83 uint8_t uint8[8];
84} tox_IP4_Port;
85
86/* will replace IP_Port as soon as the complete infrastructure is in place
87 * removed the unused union and padding also */
46typedef struct { 88typedef struct {
47 tox_IP ip; 89 tox_IPAny ip;
48 uint16_t port; 90 uint16_t port;
49 /* Not used for anything right now. */ 91} tox_IPAny_Port;
50 uint16_t padding; 92
51} tox_IP_Port; 93/* #undef TOX_ENABLE_IPV6 */
94#define TOX_ENABLE_IPV6
95#ifdef TOX_ENABLE_IPV6
96#define TOX_ENABLE_IPV6_DEFAULT 1
97typedef tox_IPAny tox_IP;
98typedef tox_IPAny_Port tox_IP_Port;
99#else
100#define TOX_ENABLE_IPV6_DEFAULT 0
101typedef tox_IP4 tox_IP;
102typedef tox_IP4_Port tox_IP_Port;
103#endif
104
52 105
53/* Errors for m_addfriend 106/* Errors for m_addfriend
54 * FAERR - Friend Add Error 107 * FAERR - Friend Add Error
@@ -342,22 +395,46 @@ int tox_group_message_send(Tox *tox, int groupnumber, uint8_t *message, uint32_t
342 395
343/******************END OF GROUP CHAT FUNCTIONS************************/ 396/******************END OF GROUP CHAT FUNCTIONS************************/
344 397
345/* Use this function to bootstrap the client. 398/*
346 * Sends a get nodes request to the given node with ip port and public_key. 399 * Use these two functions to bootstrap the client.
347 */ 400 */
348void tox_bootstrap(Tox *tox, tox_IP_Port ip_port, uint8_t *public_key); 401/* Sends a "get nodes" request to the given node with ip, port and public_key
402 * to setup connections
403 */
404void tox_bootstrap_from_ip(Tox *tox, tox_IP_Port ip_port, uint8_t *public_key);
405/* Resolves address into an IP address. If successful, sends a "get nodes"
406 * request to the given node with ip, port and public_key to setup connections
407 *
408 * address can be a hostname or an IP address (IPv4 or IPv6).
409 * if ipv6enabled is 0 (zero), the resolving sticks STRICTLY to IPv4 addresses
410 * if ipv6enabled is not 0 (zero), the resolving looks for IPv6 addresses first,
411 * then IPv4 addresses.
412 *
413 * returns 1 if the address could be converted into an IP address
414 * returns 0 otherwise
415 */
416int tox_bootstrap_from_address(Tox *tox, const char *address, uint8_t ipv6enabled,
417 uint16_t port, uint8_t *public_key);
349 418
350/* return 0 if we are not connected to the DHT. 419/* return 0 if we are not connected to the DHT.
351 * return 1 if we are. 420 * return 1 if we are.
352 */ 421 */
353int tox_isconnected(Tox *tox); 422int tox_isconnected(Tox *tox);
354 423
355/* Run this at startup. 424/*
425 * Run this function at startup.
426 *
427 * Initializes a tox structure
428 * The type of communication socket depends on ipv6enabled:
429 * If set to 0 (zero), creates an IPv4 socket which subsequently only allows
430 * IPv4 communication
431 * If set to anything else, creates an IPv6 socket which allows both IPv4 AND
432 * IPv6 communication
356 * 433 *
357 * return allocated instance of tox on success. 434 * return allocated instance of tox on success.
358 * return 0 if there are problems. 435 * return 0 if there are problems.
359 */ 436 */
360Tox *tox_new(void); 437Tox *tox_new(uint8_t ipv6enabled);
361 438
362/* Run this before closing shop. 439/* Run this before closing shop.
363 * Free all datastructures. */ 440 * Free all datastructures. */