diff options
Diffstat (limited to 'toxcore/tox.h')
-rw-r--r-- | toxcore/tox.h | 106 |
1 files changed, 94 insertions, 12 deletions
diff --git a/toxcore/tox.h b/toxcore/tox.h index 6d5db49f..89242f1f 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 |
30 | extern "C" { | 46 | extern "C" { |
31 | #endif | 47 | #endif |
@@ -36,19 +52,61 @@ 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 | ||
40 | typedef union { | 59 | typedef 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 | |||
66 | typedef union { | ||
67 | uint8_t uint8[16]; | ||
68 | uint16_t uint16[8]; | ||
69 | uint32_t uint32[4]; | ||
70 | struct in6_addr in6_addr; | ||
71 | } tox_IP6; | ||
72 | |||
73 | typedef struct { | ||
74 | sa_family_t family; | ||
75 | union { | ||
76 | tox_IP4 ip4; | ||
77 | tox_IP6 ip6; | ||
78 | }; | ||
79 | } tox_IPAny; | ||
45 | 80 | ||
81 | typedef union { | ||
82 | struct { | ||
83 | tox_IP4 ip; | ||
84 | uint16_t port; | ||
85 | /* Not used for anything right now. */ | ||
86 | uint16_t padding; | ||
87 | }; | ||
88 | uint8_t uint8[8]; | ||
89 | } tox_IP4_Port; | ||
90 | |||
91 | /* will replace IP_Port as soon as the complete infrastructure is in place | ||
92 | * removed the unused union and padding also */ | ||
46 | typedef struct { | 93 | typedef struct { |
47 | tox_IP ip; | 94 | tox_IPAny ip; |
48 | uint16_t port; | 95 | uint16_t port; |
49 | /* Not used for anything right now. */ | 96 | } tox_IPAny_Port; |
50 | uint16_t padding; | 97 | |
51 | } tox_IP_Port; | 98 | /* #undef TOX_ENABLE_IPV6 */ |
99 | #define TOX_ENABLE_IPV6 | ||
100 | #ifdef TOX_ENABLE_IPV6 | ||
101 | #define TOX_ENABLE_IPV6_DEFAULT 1 | ||
102 | typedef tox_IPAny tox_IP; | ||
103 | typedef tox_IPAny_Port tox_IP_Port; | ||
104 | #else | ||
105 | #define TOX_ENABLE_IPV6_DEFAULT 0 | ||
106 | typedef tox_IP4 tox_IP; | ||
107 | typedef tox_IP4_Port tox_IP_Port; | ||
108 | #endif | ||
109 | |||
52 | 110 | ||
53 | /* Errors for m_addfriend | 111 | /* Errors for m_addfriend |
54 | * FAERR - Friend Add Error | 112 | * FAERR - Friend Add Error |
@@ -342,22 +400,46 @@ int tox_group_message_send(Tox *tox, int groupnumber, uint8_t *message, uint32_t | |||
342 | 400 | ||
343 | /******************END OF GROUP CHAT FUNCTIONS************************/ | 401 | /******************END OF GROUP CHAT FUNCTIONS************************/ |
344 | 402 | ||
345 | /* Use this function to bootstrap the client. | 403 | /* |
346 | * Sends a get nodes request to the given node with ip port and public_key. | 404 | * Use these two functions to bootstrap the client. |
405 | */ | ||
406 | /* Sends a "get nodes" request to the given node with ip, port and public_key | ||
407 | * to setup connections | ||
347 | */ | 408 | */ |
348 | void tox_bootstrap(Tox *tox, tox_IP_Port ip_port, uint8_t *public_key); | 409 | void tox_bootstrap_from_ip(Tox *tox, tox_IP_Port ip_port, uint8_t *public_key); |
410 | /* Resolves address into an IP address. If successful, sends a "get nodes" | ||
411 | * request to the given node with ip, port and public_key to setup connections | ||
412 | * | ||
413 | * address can be a hostname or an IP address (IPv4 or IPv6). | ||
414 | * if ipv6enabled is 0 (zero), the resolving sticks STRICTLY to IPv4 addresses | ||
415 | * if ipv6enabled is not 0 (zero), the resolving looks for IPv6 addresses first, | ||
416 | * then IPv4 addresses. | ||
417 | * | ||
418 | * returns 1 if the address could be converted into an IP address | ||
419 | * returns 0 otherwise | ||
420 | */ | ||
421 | int tox_bootstrap_from_address(Tox *tox, const char *address, uint8_t ipv6enabled, | ||
422 | uint16_t port, uint8_t *public_key); | ||
349 | 423 | ||
350 | /* return 0 if we are not connected to the DHT. | 424 | /* return 0 if we are not connected to the DHT. |
351 | * return 1 if we are. | 425 | * return 1 if we are. |
352 | */ | 426 | */ |
353 | int tox_isconnected(Tox *tox); | 427 | int tox_isconnected(Tox *tox); |
354 | 428 | ||
355 | /* Run this at startup. | 429 | /* |
430 | * Run this function at startup. | ||
431 | * | ||
432 | * Initializes a tox structure | ||
433 | * The type of communication socket depends on ipv6enabled: | ||
434 | * If set to 0 (zero), creates an IPv4 socket which subsequently only allows | ||
435 | * IPv4 communication | ||
436 | * If set to anything else, creates an IPv6 socket which allows both IPv4 AND | ||
437 | * IPv6 communication | ||
356 | * | 438 | * |
357 | * return allocated instance of tox on success. | 439 | * return allocated instance of tox on success. |
358 | * return 0 if there are problems. | 440 | * return 0 if there are problems. |
359 | */ | 441 | */ |
360 | Tox *tox_new(void); | 442 | Tox *tox_new(uint8_t ipv6enabled); |
361 | 443 | ||
362 | /* Run this before closing shop. | 444 | /* Run this before closing shop. |
363 | * Free all datastructures. */ | 445 | * Free all datastructures. */ |