From 97b9fd40dbba9b94144862f719a2a4ca8f12af22 Mon Sep 17 00:00:00 2001 From: GDR! Date: Fri, 19 Jun 2015 20:25:14 +0200 Subject: [PATCH] The program now compiles with new toxcore (67df1ab7ce) --- client.c | 63 ++++++++++++------ main.c | 154 +++++++++++++++++++++++++++++--------------- main.h | 4 +- tox_bootstrap.h | 168 ++++++++++++++++++++++++++++++++++++------------ util.c | 19 +++++- util.h | 2 + 6 files changed, 293 insertions(+), 117 deletions(-) diff --git a/client.c b/client.c index 58b31ab..d2ef837 100644 --- a/client.c +++ b/client.c @@ -216,14 +216,18 @@ int handle_server_tcp_fin_frame(protocol_frame *rcvd_frame) int do_client_loop(char *tox_id_str) { unsigned char tox_packet_buf[PROTOCOL_MAX_PACKET_SIZE]; - unsigned char tox_id[TOX_FRIEND_ADDRESS_SIZE]; + unsigned char tox_id[TOX_ADDRESS_SIZE]; uint32_t friendnumber; struct timeval tv; fd_set fds; + TOX_ERR_FRIEND_QUERY friend_query_error; + TOX_ERR_FRIEND_CUSTOM_PACKET custom_packet_error; client_tunnel.sockfd = 0; FD_ZERO(&client_master_fdset); + tox_callback_friend_lossless_packet(tox, parse_lossless_packet, NULL); + if(!string_to_id(tox_id, tox_id_str)) { log_printf(L_ERROR, "Invalid Tox ID"); @@ -241,7 +245,7 @@ int do_client_loop(char *tox_id_str) while(1) { /* Let tox do its stuff */ - tox_do(tox); + tox_iterate(tox); switch(state) { @@ -249,7 +253,7 @@ int do_client_loop(char *tox_id_str) * Send friend request */ case CLIENT_STATE_INITIAL: - if(tox_isconnected(tox)) + if(connection_status != TOX_CONNECTION_NONE) { state = CLIENT_STATE_CONNECTED; } @@ -258,37 +262,50 @@ int do_client_loop(char *tox_id_str) { uint8_t data[] = "Hi, fellow tuntox instance!"; uint16_t length = sizeof(data); + TOX_ERR_FRIEND_ADD add_error; log_printf(L_INFO, "Connected. Sending friend request.\n"); - friendnumber = tox_add_friend( + friendnumber = tox_friend_add( tox, tox_id, data, - length + length, + &add_error ); - if(friendnumber < 0) + if(friendnumber == UINT32_MAX) { - log_printf(L_ERROR, "Error %d adding friend %s\n", friendnumber, tox_id); + log_printf(L_ERROR, "Error %u adding friend %s\n", add_error, tox_id); exit(-1); } - tox_lossless_packet_registerhandler(tox, friendnumber, (PROTOCOL_MAGIC_V1)>>8, parse_lossless_packet, (void*)&friendnumber); state = CLIENT_STATE_SENTREQUEST; log_printf(L_INFO, "Waiting for friend to accept us...\n"); } break; case CLIENT_STATE_SENTREQUEST: - if(tox_get_friend_connection_status(tox, friendnumber) == 1) - { - log_printf(L_INFO, "Friend request accepted!\n"); - state = CLIENT_STATE_REQUEST_ACCEPTED; - } - else { + TOX_CONNECTION friend_connection_status; + friend_connection_status = tox_friend_get_connection_status(tox, friendnumber, &friend_query_error); + if(friend_query_error != TOX_ERR_FRIEND_QUERY_OK) + { + log_printf(L_DEBUG, "tox_friend_get_connection_status: error %u", friend_query_error); + } + else + { + if(friend_connection_status != TOX_CONNECTION_NONE) + { + const char* status = readable_connection_status(friend_connection_status); + log_printf(L_INFO, "Friend request accepted (%s)!\n", status); + state = CLIENT_STATE_REQUEST_ACCEPTED; + } + else + { + } + } + break; } - break; case CLIENT_STATE_REQUEST_ACCEPTED: if(ping_mode) { @@ -312,14 +329,22 @@ int do_client_loop(char *tox_id_str) }; clock_gettime(CLOCK_MONOTONIC, &ping_sent_time); - tox_send_lossless_packet( + tox_friend_send_lossless_packet( tox, friendnumber, data, - sizeof(data) + sizeof(data), + &custom_packet_error ); } - state = CLIENT_STATE_PING_SENT; + if(custom_packet_error == TOX_ERR_FRIEND_CUSTOM_PACKET_OK) + { + state = CLIENT_STATE_PING_SENT; + } + else + { + log_printf(L_WARNING, "When sending ping packet: %u", custom_packet_error); + } break; case CLIENT_STATE_PING_SENT: /* Just sit there and wait for pong */ @@ -452,7 +477,7 @@ int do_client_loop(char *tox_id_str) break; } - usleep(tox_do_interval(tox) * 1000); + usleep(tox_iteration_interval(tox) * 1000); } } diff --git a/main.c b/main.c index b37d6ab..035f705 100644 --- a/main.c +++ b/main.c @@ -3,9 +3,10 @@ #include "tox_bootstrap.h" #include "log.h" -static Tox_Options tox_options; +static struct Tox_Options tox_options; Tox *tox; int client_socket = 0; +TOX_CONNECTION connection_status = TOX_CONNECTION_NONE; /** CONFIGURATION OPTIONS **/ /* Whether we're a client */ @@ -123,7 +124,8 @@ static void do_bootstrap(Tox *tox) int i = 0; while(i < 4) { struct bootstrap_node *d = &bootstrap_nodes[j % countof(bootstrap_nodes)]; - tox_bootstrap_from_address(tox, d->address, d->port, d->key); + tox_bootstrap(tox, d->address, d->port, d->key, 0); + tox_add_tcp_relay(tox, d->address, d->port, d->key, 0); i++; j++; } @@ -135,11 +137,16 @@ void set_tox_username(Tox *tox) unsigned char hostname[1024]; struct addrinfo hints, *info, *p; int gai_result; + TOX_ERR_SET_INFO error; gethostname(hostname, 1024); hostname[1023] = '\0'; - tox_set_name(tox, hostname, strlen(hostname)); + tox_self_set_name(tox, hostname, strlen(hostname), &error); + if(error != TOX_ERR_SET_INFO_OK) + { + log_printf(L_DEBUG, "tox_self_set_name() failed (%u)", error); + } } /* Get sockaddr, IPv4 or IPv6 */ @@ -233,6 +240,7 @@ int send_frame(protocol_frame *frame, uint8_t *data) int rv = -1; int try = 0; int i; + TOX_ERR_FRIEND_CUSTOM_PACKET custom_packet_error; data[0] = PROTOCOL_MAGIC_HIGH; data[1] = PROTOCOL_MAGIC_LOW; @@ -249,21 +257,29 @@ int send_frame(protocol_frame *frame, uint8_t *data) try++; - rv = tox_send_lossless_packet( + rv = tox_friend_send_lossless_packet( tox, frame->friendnumber, data, - frame->data_length + PROTOCOL_BUFFER_OFFSET + frame->data_length + PROTOCOL_BUFFER_OFFSET, + &custom_packet_error ); - if(rv < 0) + if(custom_packet_error == TOX_ERR_FRIEND_CUSTOM_PACKET_OK) { - /* If this branch is ran, most likely we've hit congestion control. */ - log_printf(L_DEBUG, "[%d] Failed to send packet to friend %d\n", i, frame->friendnumber); + break; } else { - break; + /* If this branch is ran, most likely we've hit congestion control. */ + if(custom_packet_error == TOX_ERR_FRIEND_CUSTOM_PACKET_SENDQ) + { + log_printf(L_DEBUG, "[%d] Failed to send packet to friend %d (Packet queue is full)\n", i, frame->friendnumber, custom_packet_error); + } + else + { + log_printf(L_DEBUG, "[%d] Failed to send packet to friend %d (err: %u)\n", i, frame->friendnumber, custom_packet_error); + } } if(i == 0) i = 2; @@ -271,7 +287,7 @@ int send_frame(protocol_frame *frame, uint8_t *data) for(j = 0; j < i; j++) { - tox_do(tox); + tox_iterate(tox); usleep(j * 10000); } } @@ -490,33 +506,33 @@ int handle_frame(protocol_frame *frame) * It checks for basic inconsistiencies and allocates the * protocol_frame structure. */ -int parse_lossless_packet(Tox *tox, int32_t friendnumber, const uint8_t *data, uint32_t len, void *tmp) +void parse_lossless_packet(Tox *tox, uint32_t friendnumber, const uint8_t *data, size_t len, void *tmp) { protocol_frame *frame = NULL; if(len < PROTOCOL_BUFFER_OFFSET) { log_printf(L_WARNING, "Received too short data frame - only %d bytes, at least %d expected\n", len, PROTOCOL_BUFFER_OFFSET); - return -1; + return; } if(!data) { log_printf(L_ERROR, "Got NULL pointer from toxcore - WTF?\n"); - return -1; + return; } if(data[0] != PROTOCOL_MAGIC_HIGH || data[1] != PROTOCOL_MAGIC_LOW) { log_printf(L_WARNING, "Received data frame with invalid protocol magic number 0x%x%x\n", data[0], data[1]); - return -1; + return; } frame = calloc(1, sizeof(protocol_frame)); if(!frame) { log_printf(L_ERROR, "Could not allocate memory for protocol_frame_t\n"); - return -1; + return; } /* TODO check if friendnumber is the same in sender and connid tunnel*/ @@ -531,13 +547,13 @@ int parse_lossless_packet(Tox *tox, int32_t friendnumber, const uint8_t *data, u if(len < frame->data_length + PROTOCOL_BUFFER_OFFSET) { log_printf(L_WARNING, "Received frame too small (attempted buffer overflow?): %d bytes, excepted at least %d bytes\n", len, frame->data_length + PROTOCOL_BUFFER_OFFSET); - return -1; + return; } if(frame->data_length > (TOX_MAX_CUSTOM_PACKET_SIZE - PROTOCOL_BUFFER_OFFSET)) { log_printf(L_WARNING, "Declared data length too big (attempted buffer overflow?): %d bytes, excepted at most %d bytes\n", frame->data_length, (TOX_MAX_CUSTOM_PACKET_SIZE - PROTOCOL_BUFFER_OFFSET)); - return -1; + return; } handle_frame(frame); @@ -582,9 +598,9 @@ static void write_save(Tox *tox) uint8_t path_tmp[512], path_real[512], *p; FILE *file; - size = tox_size(tox); + size = tox_get_savedata_size(tox); data = malloc(size); - tox_save(tox, data); + tox_get_savedata(tox, data); strncpy(path_real, config_path, sizeof(config_path)); @@ -621,7 +637,7 @@ static void write_save(Tox *tox) } /* Load tox identity from a file */ -static int load_save(Tox *tox) +static size_t load_save(uint8_t **out_data) { void *data; uint32_t size; @@ -639,9 +655,8 @@ static int load_save(Tox *tox) if(data) { - tox_load(tox, data, size); - free(data); - return 1; + *out_data = data; + return size; } else { @@ -650,20 +665,33 @@ static int load_save(Tox *tox) } } -void accept_friend_request(Tox *tox, const uint8_t *public_key, const uint8_t *data, uint16_t length, void *userdata) +void accept_friend_request(Tox *tox, const uint8_t *public_key, const uint8_t *message, size_t length, void *userdata) { - unsigned char tox_printable_id[TOX_FRIEND_ADDRESS_SIZE * 2 + 1]; + unsigned char tox_printable_id[TOX_ADDRESS_SIZE * 2 + 1]; int32_t friendnumber; + TOX_ERR_FRIEND_ADD friend_add_error; log_printf(L_DEBUG, "Got friend request\n"); - friendnumber = tox_add_friend_norequest(tox, public_key); + friendnumber = tox_friend_add_norequest(tox, public_key, &friend_add_error); + if(friend_add_error != TOX_ERR_FRIEND_ADD_OK) + { + log_printf(L_WARNING, "Could not add friend: err %u", friend_add_error); + return; + } memset(tox_printable_id, '\0', sizeof(tox_printable_id)); id_to_string(tox_printable_id, public_key); log_printf(L_INFO, "Accepted friend request from %s as %d\n", tox_printable_id, friendnumber); +} - tox_lossless_packet_registerhandler(tox, friendnumber, (PROTOCOL_MAGIC_V1)>>8, parse_lossless_packet, NULL); +/* Callback for tox_callback_self_connection_status() */ +void handle_connection_status_change(Tox *tox, TOX_CONNECTION p_connection_status, void *user_data) +{ + const char *status = NULL; + connection_status = p_connection_status; + status = readable_connection_status(connection_status); + log_printf(L_INFO, "Connection status changed: %s", status); } void cleanup(int status, void *tmp) @@ -686,7 +714,9 @@ int do_server_loop() unsigned char tox_packet_buf[PROTOCOL_MAX_PACKET_SIZE]; tunnel *tun = NULL; tunnel *tmp = NULL; - int connected = 0; + TOX_CONNECTION connected = 0; + + tox_callback_friend_lossless_packet(tox, parse_lossless_packet, NULL); tv.tv_sec = 0; tv.tv_usec = 20000; @@ -695,19 +725,19 @@ int do_server_loop() while(1) { - int tmp_isconnected = 0; + TOX_CONNECTION tmp_isconnected = 0; uint32_t tox_do_interval_ms; /* Let tox do its stuff */ - tox_do(tox); + tox_iterate(tox); /* Get the desired sleep time, used in select() later */ - tox_do_interval_ms = tox_do_interval(tox); + tox_do_interval_ms = tox_iteration_interval(tox); tv.tv_usec = (tox_do_interval_ms % 1000) * 1000; tv.tv_sec = tox_do_interval_ms / 1000; /* Check change in connection state */ - tmp_isconnected = tox_isconnected(tox); + tmp_isconnected = connection_status; if(tmp_isconnected != connected) { connected = tmp_isconnected; @@ -926,9 +956,12 @@ void help() int main(int argc, char *argv[]) { - unsigned char tox_id[TOX_FRIEND_ADDRESS_SIZE]; - unsigned char tox_printable_id[TOX_FRIEND_ADDRESS_SIZE * 2 + 1]; + unsigned char tox_id[TOX_ADDRESS_SIZE]; + unsigned char tox_printable_id[TOX_ADDRESS_SIZE * 2 + 1]; + TOX_ERR_NEW tox_new_err; int oc; + size_t save_size = 0; + uint8_t *save_data = NULL; log_init(); @@ -1033,34 +1066,53 @@ int main(int argc, char *argv[]) print_version(); /* Bootstrap tox */ - tox_options.ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; - tox_options.udp_disabled = 0; - tox_options.proxy_enabled = 0; + tox_options_default(&tox_options); + if(!client_mode) + { + uint8_t *save_data = NULL; + save_size = load_save(&save_data); + if(save_data && save_size) + { + tox_options.savedata_type = TOX_SAVEDATA_TYPE_TOX_SAVE; + tox_options.savedata_data = save_data; + tox_options.savedata_length = save_size; + } + } - tox = tox_new(&tox_options); + tox = tox_new(&tox_options, &tox_new_err); if(tox == NULL) { - log_printf(L_DEBUG, "tox_new() failed - trying without proxy\n"); - if(!tox_options.proxy_enabled || (tox_options.proxy_enabled = 0, (tox = tox_new(&tox_options)) == NULL)) + log_printf(L_DEBUG, "tox_new() failed (%u) - trying without proxy\n", tox_new_err); + if((tox_options.proxy_type != TOX_PROXY_TYPE_NONE) || (tox_options.proxy_type = TOX_PROXY_TYPE_NONE, (tox = tox_new(&tox_options, &tox_new_err)) == NULL)) { - log_printf(L_DEBUG, "tox_new() failed - trying without IPv6\n"); - if(!tox_options.ipv6enabled || (tox_options.ipv6enabled = 0, (tox = tox_new(&tox_options)) == NULL)) + log_printf(L_DEBUG, "tox_new() failed (%u) - trying without IPv6\n", tox_new_err); + if(!tox_options.ipv6_enabled || (tox_options.ipv6_enabled = 0, (tox = tox_new(&tox_options, &tox_new_err)) == NULL)) { - log_printf(L_ERROR, "tox_new() failed - exiting\n"); - exit(1); + log_printf(L_DEBUG, "tox_new() failed (%u) - trying with Tor\n", tox_new_err); + if((tox_options.proxy_type = TOX_PROXY_TYPE_SOCKS5, tox_options.proxy_host="127.0.0.1", tox_options.proxy_port=9050, (tox = tox_new(&tox_options, &tox_new_err)) == NULL)) + { + log_printf(L_ERROR, "tox_new() failed (%u) - exiting\n", tox_new_err); + exit(1); + } } } } + if(save_size && save_data) + { + free(save_data); + } + set_tox_username(tox); + tox_callback_self_connection_status(tox, handle_connection_status_change, NULL); do_bootstrap(tox); if(client_mode) { - tox_get_address(tox, tox_id); + tox_self_get_address(tox, tox_id); id_to_string(tox_printable_id, tox_id); - tox_printable_id[TOX_FRIEND_ADDRESS_SIZE * 2] = '\0'; + tox_printable_id[TOX_ADDRESS_SIZE * 2] = '\0'; log_printf(L_DEBUG, "Generated Tox ID: %s\n", tox_printable_id); if(!remote_tox_id) @@ -1072,16 +1124,12 @@ int main(int argc, char *argv[]) } else { - if(!load_save(tox)) - { - /* Write generated ID if one is not already present */ - write_save(tox); - } + write_save(tox); - tox_get_address(tox, tox_id); + tox_self_get_address(tox, tox_id); memset(tox_printable_id, '\0', sizeof(tox_printable_id)); id_to_string(tox_printable_id, tox_id); - tox_printable_id[TOX_FRIEND_ADDRESS_SIZE * 2] = '\0'; + tox_printable_id[TOX_ADDRESS_SIZE * 2] = '\0'; log_printf(L_INFO, "Using Tox ID: %s\n", tox_printable_id); tox_callback_friend_request(tox, accept_friend_request, NULL); diff --git a/main.h b/main.h index 2300293..aad191a 100644 --- a/main.h +++ b/main.h @@ -74,6 +74,8 @@ extern Tox *tox; extern int client_mode; /* Just send a ping and exit */ extern int ping_mode; +/* TOX_CONNECTION global variable */ +extern TOX_CONNECTION connection_status; /* Open a local port and forward it */ extern int client_local_port_mode; /* Forward stdin/stdout to remote machine - SSH ProxyCommand mode */ @@ -88,7 +90,7 @@ extern int local_port; extern int select_nfds; extern tunnel *by_id; -int parse_lossless_packet(Tox *tox, int32_t friendnumber, const uint8_t *data, uint32_t len, void *sender_uc); +void parse_lossless_packet(Tox *tox, uint32_t friendnumber, const uint8_t *data, size_t len, void *tmp); tunnel *tunnel_create(int sockfd, int connid, uint32_t friendnumber); void tunnel_delete(tunnel *t); diff --git a/tox_bootstrap.h b/tox_bootstrap.h index 2511c52..0bae455 100644 --- a/tox_bootstrap.h +++ b/tox_bootstrap.h @@ -4,14 +4,13 @@ struct bootstrap_node { uint8_t key[32]; } bootstrap_nodes[] = { { - "37.187.46.132", + "192.254.75.102", 33445, { - 0x5E, 0xB6, 0x7C, 0x51, 0xD3, 0xFF, 0x5A, 0x9D, 0x52, 0x8D, 0x24, 0x2B, 0x66, 0x90, 0x36, 0xED, - 0x2A, 0x30, 0xF8, 0xA6, 0x0E, 0x67, 0x4C, 0x45, 0xE7, 0xD4, 0x30, 0x10, 0xCB, 0x2E, 0x13, 0x31 + 0x95, 0x1C, 0x88, 0xB7, 0xE7, 0x5C, 0x86, 0x74, 0x18, 0xAC, 0xDB, 0x5D, 0x27, 0x38, 0x21, 0x37, + 0x2B, 0xB5, 0xBD, 0x65, 0x27, 0x40, 0xBC, 0xDF, 0x62, 0x3A, 0x4F, 0xA2, 0x93, 0xE7, 0x5D, 0x2F } }, - { "144.76.60.215", 33445, @@ -20,7 +19,6 @@ struct bootstrap_node { 0x6A, 0xF8, 0xB9, 0x36, 0xF0, 0x35, 0x18, 0x5E, 0x2A, 0x8E, 0x9E, 0x0A, 0x67, 0xC8, 0x92, 0x4F } }, - { "23.226.230.47", 33445, @@ -29,16 +27,30 @@ struct bootstrap_node { 0x67, 0x96, 0x04, 0xB2, 0xD8, 0x0E, 0xA6, 0xE8, 0x4A, 0xD0, 0x99, 0x6A, 0x1A, 0xC8, 0xA0, 0x74 } }, - { - "54.199.139.199", + "178.62.125.224", 33445, { - 0x7F, 0x9C, 0x31, 0xFE, 0x85, 0x0E, 0x97, 0xCE, 0xFD, 0x4C, 0x45, 0x91, 0xDF, 0x93, 0xFC, 0x75, - 0x7C, 0x7C, 0x12, 0x54, 0x9D, 0xDD, 0x55, 0xF8, 0xEE, 0xAE, 0xCC, 0x34, 0xFE, 0x76, 0xC0, 0x29 + 0x10, 0xB2, 0x0C, 0x49, 0xAC, 0xBD, 0x96, 0x8D, 0x7C, 0x80, 0xF2, 0xE8, 0x43, 0x8F, 0x92, 0xEA, + 0x51, 0xF1, 0x89, 0xF4, 0xE7, 0x0C, 0xFB, 0xBB, 0x2C, 0x2C, 0x8C, 0x79, 0x9E, 0x97, 0xF0, 0x3E + } + }, + { + "178.21.112.187", + 33445, + { + 0x4B, 0x2C, 0x19, 0xE9, 0x24, 0x97, 0x2C, 0xB9, 0xB5, 0x77, 0x32, 0xFB, 0x17, 0x2F, 0x8A, 0x86, + 0x04, 0xDE, 0x13, 0xEE, 0xDA, 0x2A, 0x62, 0x34, 0xE3, 0x48, 0x98, 0x33, 0x44, 0xB2, 0x30, 0x57 + } + }, + { + "195.154.119.113", + 33445, + { + 0xE3, 0x98, 0xA6, 0x96, 0x46, 0xB8, 0xCE, 0xAC, 0xA9, 0xF0, 0xB8, 0x4F, 0x55, 0x37, 0x26, 0xC1, + 0xC4, 0x92, 0x70, 0x55, 0x8C, 0x57, 0xDF, 0x5F, 0x3C, 0x36, 0x8F, 0x05, 0xA7, 0xD7, 0x13, 0x54 } }, - { "192.210.149.121", 33445, @@ -47,73 +59,145 @@ struct bootstrap_node { 0x3E, 0x1D, 0xEF, 0x8B, 0xD4, 0x6B, 0x10, 0x38, 0xB9, 0xD8, 0x22, 0xE8, 0x46, 0x0F, 0xAB, 0x67 } }, - { - "192.254.75.98", + "104.219.184.206", + 443, + { + 0x8C, 0xD0, 0x87, 0xE3, 0x1C, 0x67, 0x56, 0x81, 0x03, 0xE8, 0xC2, 0xA2, 0x86, 0x53, 0x33, 0x7E, + 0x90, 0xE6, 0xB8, 0xED, 0xA0, 0xD7, 0x65, 0xD5, 0x7C, 0x6B, 0x51, 0x72, 0xB4, 0xF1, 0xF0, 0x4C + } + }, + { + "76.191.23.96", 33445, { - 0x95, 0x1C, 0x88, 0xB7, 0xE7, 0x5C, 0x86, 0x74, 0x18, 0xAC, 0xDB, 0x5D, 0x27, 0x38, 0x21, 0x37, - 0x2B, 0xB5, 0xBD, 0x65, 0x27, 0x40, 0xBC, 0xDF, 0x62, 0x3A, 0x4F, 0xA2, 0x93, 0xE7, 0x5D, 0x2F + 0x93, 0x57, 0x4A, 0x3F, 0xAB, 0x7D, 0x61, 0x2F, 0xEA, 0x29, 0xFD, 0x8D, 0x67, 0xD3, 0xDD, 0x10, + 0xDF, 0xD0, 0x7A, 0x07, 0x5A, 0x5D, 0x62, 0xE8, 0xAF, 0x3D, 0xD9, 0xF5, 0xD0, 0x93, 0x2E, 0x11 } }, - { - "31.7.57.236", - 443, + "46.38.239.179", + 33445, { - 0x2A, 0x4B, 0x50, 0xD1, 0xD5, 0x25, 0xDA, 0x2E, 0x66, 0x95, 0x92, 0xA2, 0x0C, 0x32, 0x7B, 0x5F, - 0xAD, 0x6C, 0x7E, 0x59, 0x62, 0xDC, 0x69, 0x29, 0x6F, 0x9F, 0xEC, 0x77, 0xC4, 0x43, 0x6E, 0x4E + 0xF5, 0xA1, 0xA3, 0x8E, 0xFB, 0x6B, 0xD3, 0xC2, 0xC8, 0xAF, 0x8B, 0x10, 0xD8, 0x5F, 0x0F, 0x89, + 0xE9, 0x31, 0x70, 0x4D, 0x34, 0x9F, 0x1D, 0x07, 0x20, 0xC3, 0xC4, 0x05, 0x9A, 0xF2, 0x44, 0x0A } }, - { - "107.161.17.51", + "178.62.250.138", 33445, { - 0x7B, 0xE3, 0x95, 0x1B, 0x97, 0xCA, 0x4B, 0x9E, 0xCD, 0xDA, 0x76, 0x8E, 0x8C, 0x52, 0xBA, 0x19, - 0xE9, 0xE2, 0x69, 0x0A, 0xB5, 0x84, 0x78, 0x7B, 0xF4, 0xC9, 0x0E, 0x04, 0xDB, 0xB7, 0x51, 0x11 + 0x78, 0x82, 0x36, 0xD3, 0x49, 0x78, 0xD1, 0xD5, 0xBD, 0x82, 0x2F, 0x0A, 0x5B, 0xEB, 0xD2, 0xC5, + 0x3C, 0x64, 0xCC, 0x31, 0xCD, 0x31, 0x49, 0x35, 0x0E, 0xE2, 0x7D, 0x4D, 0x9A, 0x2F, 0x9B, 0x6B } }, - { - "37.59.102.176", + "78.225.128.39", 33445, { - 0xB9, 0x8A, 0x2C, 0xEA, 0xA6, 0xC6, 0xA2, 0xFA, 0xDC, 0x2C, 0x36, 0x32, 0xD2, 0x84, 0x31, 0x8B, - 0x60, 0xFE, 0x53, 0x75, 0xCC, 0xB4, 0x1E, 0xFA, 0x08, 0x1A, 0xB6, 0x7F, 0x50, 0x0C, 0x1B, 0x0B + 0x7A, 0x23, 0x06, 0xBF, 0xBA, 0x66, 0x5E, 0x54, 0x80, 0xAE, 0x59, 0xB3, 0x1E, 0x11, 0x6B, 0xE9, + 0xC0, 0x4D, 0xCE, 0xFE, 0x04, 0xD9, 0xFE, 0x25, 0x08, 0x23, 0x16, 0xFA, 0x34, 0xB4, 0xDA, 0x0C } }, - { - "178.21.112.187", + "130.133.110.14", 33445, { - 0x4B, 0x2C, 0x19, 0xE9, 0x24, 0x97, 0x2C, 0xB9, 0xB5, 0x77, 0x32, 0xFB, 0x17, 0x2F, 0x8A, 0x86, - 0x04, 0xDE, 0x13, 0xEE, 0xDA, 0x2A, 0x62, 0x34, 0xE3, 0x48, 0x98, 0x33, 0x44, 0xB2, 0x30, 0x57 + 0x46, 0x1F, 0xA3, 0x77, 0x6E, 0xF0, 0xFA, 0x65, 0x5F, 0x1A, 0x05, 0x47, 0x7D, 0xF1, 0xB3, 0xB6, + 0x14, 0xF7, 0xD6, 0xB1, 0x24, 0xF7, 0xDB, 0x1D, 0xD4, 0xFE, 0x3C, 0x08, 0xB0, 0x3B, 0x64, 0x0F } }, - { - "63.165.243.15", - 443, + "104.167.101.29", + 33445, { - 0x8C, 0xD0, 0x87, 0xE3, 0x1C, 0x67, 0x56, 0x81, 0x03, 0xE8, 0xC2, 0xA2, 0x86, 0x53, 0x33, 0x7E, - 0x90, 0xE6, 0xB8, 0xED, 0xA0, 0xD7, 0x65, 0xD5, 0x7C, 0x6B, 0x51, 0x72, 0xB4, 0xF1, 0xF0, 0x4C + 0x59, 0x18, 0xAC, 0x3C, 0x06, 0x95, 0x59, 0x62, 0xA7, 0x5A, 0xD7, 0xDF, 0x4F, 0x80, 0xA5, 0xD7, + 0xC3, 0x4F, 0x7D, 0xB9, 0xE1, 0x49, 0x8D, 0x2E, 0x04, 0x95, 0xDE, 0x35, 0xB3, 0xFE, 0x8A, 0x57 } }, - { - "195.154.119.113", + "195.154.109.148", 33445, { - 0xE3, 0x98, 0xA6, 0x96, 0x46, 0xB8, 0xCE, 0xAC, 0xA9, 0xF0, 0xB8, 0x4F, 0x55, 0x37, 0x26, 0xC1, - 0xC4, 0x92, 0x70, 0x55, 0x8C, 0x57, 0xDF, 0x5F, 0x3C, 0x36, 0x8F, 0x05, 0xA7, 0xD7, 0x13, 0x54 + 0x39, 0x1C, 0x96, 0xCB, 0x67, 0xAE, 0x89, 0x3D, 0x47, 0x82, 0xB8, 0xE4, 0x49, 0x5E, 0xB9, 0xD8, + 0x9C, 0xF1, 0x03, 0x1F, 0x48, 0x46, 0x0C, 0x06, 0x07, 0x5A, 0xA8, 0xCE, 0x76, 0xD5, 0x0A, 0x21 } }, - { - "176.31.28.63", + "192.3.173.88", + 33445, + { + 0x3E, 0x1F, 0xFD, 0xEB, 0x66, 0x7B, 0xFF, 0x54, 0x9F, 0x61, 0x9E, 0xC6, 0x73, 0x78, 0x34, 0x76, + 0x21, 0x24, 0xF5, 0x0A, 0x89, 0xC8, 0xD0, 0xDB, 0xF1, 0xDD, 0xF6, 0x4A, 0x2D, 0xD6, 0xCD, 0x1B + } + }, + { + "205.185.116.116", + 33445, + { + 0xA1, 0x79, 0xB0, 0x97, 0x49, 0xAC, 0x82, 0x6F, 0xF0, 0x1F, 0x37, 0xA9, 0x61, 0x3F, 0x6B, 0x57, + 0x11, 0x8A, 0xE0, 0x14, 0xD4, 0x19, 0x6A, 0x0E, 0x11, 0x05, 0xA9, 0x8F, 0x93, 0xA5, 0x47, 0x02 + } + }, + { + "198.98.51.198", + 33445, + { + 0x1D, 0x5A, 0x5F, 0x2F, 0x5D, 0x62, 0x33, 0x05, 0x8B, 0xF0, 0x25, 0x9B, 0x09, 0x62, 0x2F, 0xB4, + 0x0B, 0x48, 0x2E, 0x4F, 0xA0, 0x93, 0x1E, 0xB8, 0xFD, 0x3A, 0xB8, 0xE7, 0xBF, 0x7D, 0xAF, 0x6F + } + }, + { + "80.232.246.79", + 33445, + { + 0x0B, 0x8D, 0xCE, 0xAA, 0x7B, 0xDD, 0xC4, 0x4B, 0xB1, 0x11, 0x73, 0xF9, 0x87, 0xCA, 0xE3, 0x56, + 0x6A, 0x2D, 0x70, 0x57, 0xD8, 0xDD, 0x3C, 0xC6, 0x42, 0xBD, 0x47, 0x2B, 0x93, 0x91, 0x00, 0x2A + } + }, + { + "108.61.165.198", + 33445, + { + 0x8E, 0x7D, 0x0B, 0x85, 0x99, 0x22, 0xEF, 0x56, 0x92, 0x98, 0xB4, 0xD2, 0x61, 0xA8, 0xCC, 0xB5, + 0xFE, 0xA1, 0x4F, 0xB9, 0x1E, 0xD4, 0x12, 0xA7, 0x60, 0x3A, 0x58, 0x5A, 0x25, 0x69, 0x88, 0x32 + } + }, + { + "212.71.252.109", 33445, + { + 0xC4, 0xCE, 0xB8, 0xC7, 0xAC, 0x60, 0x7C, 0x6B, 0x37, 0x4E, 0x2E, 0x78, 0x2B, 0x3C, 0x00, 0xEA, + 0x3A, 0x63, 0xB8, 0x0D, 0x49, 0x10, 0xB8, 0x64, 0x9C, 0xCA, 0xCD, 0xD1, 0x9F, 0x26, 0x08, 0x19 + } + }, + { + "194.249.212.109", + 33445, + { + 0x3C, 0xEE, 0x1F, 0x05, 0x40, 0x81, 0xE7, 0xA0, 0x11, 0x23, 0x48, 0x83, 0xBC, 0x4F, 0xC3, 0x9F, + 0x66, 0x1A, 0x55, 0xB7, 0x36, 0x37, 0xA5, 0xAC, 0x29, 0x3D, 0xDF, 0x12, 0x51, 0xD9, 0x43, 0x2B + } + }, + { + "194.249.212.109", + 443, + { + 0x3C, 0xEE, 0x1F, 0x05, 0x40, 0x81, 0xE7, 0xA0, 0x11, 0x23, 0x48, 0x83, 0xBC, 0x4F, 0xC3, 0x9F, + 0x66, 0x1A, 0x55, 0xB7, 0x36, 0x37, 0xA5, 0xAC, 0x29, 0x3D, 0xDF, 0x12, 0x51, 0xD9, 0x43, 0x2B + } + }, + { + "103.38.216.87", + 33445, + { + 0x60, 0x1A, 0xEE, 0x6F, 0xC8, 0xC1, 0x7E, 0x8C, 0xD8, 0xF8, 0xF1, 0xFF, 0xC4, 0xD4, 0xAD, 0x84, + 0xE5, 0x9A, 0x73, 0xBE, 0x45, 0x1F, 0x03, 0x71, 0x94, 0xE7, 0xA4, 0x04, 0xE3, 0x79, 0x53, 0x20 + } + }, + { + "176.31.28.63", + 465, { 0x0B, 0x6C, 0x7A, 0x93, 0xA6, 0xD8, 0xC0, 0xEB, 0x44, 0x96, 0x5C, 0x4A, 0x85, 0xCB, 0x88, 0xBA, 0x75, 0x71, 0x17, 0x0F, 0xE2, 0xDB, 0x3D, 0xEA, 0x10, 0x71, 0x3E, 0x48, 0x55, 0x9A, 0x55, 0x4D diff --git a/util.c b/util.c index 8cffe64..0d88f8d 100644 --- a/util.c +++ b/util.c @@ -44,13 +44,13 @@ void to_hex(char_t *a, const char_t *p, int size) /* From utox/util.c */ void id_to_string(char_t *dest, const char_t *src) { - to_hex(dest, src, TOX_FRIEND_ADDRESS_SIZE); + to_hex(dest, src, TOX_ADDRESS_SIZE); } /* From utox/util.c */ int string_to_id(char_t *w, char_t *a) { - char_t *end = w + TOX_FRIEND_ADDRESS_SIZE; + char_t *end = w + TOX_ADDRESS_SIZE; while(w != end) { char_t c, v; @@ -181,3 +181,18 @@ void* file_raw(char *path, uint32_t *size) } return data; } + +const char *readable_connection_status(TOX_CONNECTION status) +{ + switch(status) + { + case TOX_CONNECTION_NONE: + return "There is no connection"; + case TOX_CONNECTION_TCP: + return "A TCP connection has been established (via TCP relay)"; + case TOX_CONNECTION_UDP: + return "A UDP connection has been established with DHT nodes"; + default: + return "Unknown connection status"; + } +} diff --git a/util.h b/util.h index 30d24a5..1a210d5 100644 --- a/util.h +++ b/util.h @@ -3,6 +3,7 @@ #include #include +#include #define countof(x) (sizeof(x)/sizeof(*(x))) #define char_t unsigned char @@ -11,5 +12,6 @@ void to_hex(char_t *a, const char_t *p, int size); void id_to_string(char_t *dest, const char_t *src); int string_to_id(char_t *w, char_t *a); void* file_raw(char *path, uint32_t *size); +const char *readable_connection_status(TOX_CONNECTION status); #endif