diff options
-rw-r--r-- | docs/updates/DHT.md | 56 | ||||
-rw-r--r-- | toxav/msi.c | 20 | ||||
-rw-r--r-- | toxav/toxav.c | 2 | ||||
-rw-r--r-- | toxcore/Messenger.c | 5 | ||||
-rw-r--r-- | toxcore/group.c | 6 | ||||
-rw-r--r-- | toxcore/net_crypto.c | 10 | ||||
-rw-r--r-- | toxcore/onion_announce.c | 3 | ||||
-rw-r--r-- | toxcore/onion_client.c | 4 | ||||
-rw-r--r-- | toxcore/util.c | 37 | ||||
-rw-r--r-- | toxcore/util.h | 5 |
10 files changed, 96 insertions, 52 deletions
diff --git a/docs/updates/DHT.md b/docs/updates/DHT.md index 17db70ce..86fad3d1 100644 --- a/docs/updates/DHT.md +++ b/docs/updates/DHT.md | |||
@@ -36,39 +36,39 @@ Send a get nodes request every 20 seconds to a random good node in the client li | |||
36 | 36 | ||
37 | When a client receives any request from another | 37 | When a client receives any request from another |
38 | ----------------------------------------------- | 38 | ----------------------------------------------- |
39 | -Respond to the request | 39 | - Respond to the request |
40 | -Ping request is replied to with with a ping response containing the same encrypted data | 40 | - Ping request is replied to with with a ping response containing the same encrypted data |
41 | -Get nodes request is replied with a send nodes reply containing the same encrypted data and the good nodes from the client list and/or the "friends" list that are closest to the requested_node_id | 41 | - Get nodes request is replied with a send nodes reply containing the same encrypted data and the good nodes from the client list and/or the "friends" list that are closest to the requested_node_id |
42 | 42 | ||
43 | -If the requesting client is not in the client list: | 43 | - If the requesting client is not in the client list: |
44 | -If there are no bad clients in the list and the list is full: | 44 | - If there are no bad clients in the list and the list is full: |
45 | -If the id of the other client is closer (mathematically see bittorrent doc) than at least one of the clients in the list or our "friends" list: | 45 | - If the id of the other client is closer (mathematically see bittorrent doc) than at least one of the clients in the list or our "friends" list: |
46 | -Send a ping request to the client. | 46 | - Send a ping request to the client. |
47 | -if not forget about the client. | 47 | - if not forget about the client. |
48 | 48 | ||
49 | -If there are bad clients and/or the list isn't full: | 49 | - If there are bad clients and/or the list isn't full: |
50 | -Send a ping request to the client | 50 | - Send a ping request to the client |
51 | 51 | ||
52 | When a client receives a response | 52 | When a client receives a response |
53 | --------------------------------- | 53 | --------------------------------- |
54 | -Ping response | 54 | - Ping response |
55 | -If the node was previously pinged with a matching ping_id (check in the corresponding pinged list.) | 55 | - If the node was previously pinged with a matching ping_id (check in the corresponding pinged list.) |
56 | -If the node is in the client list the matching client's timestamp is set to current time. | 56 | - If the node is in the client list the matching client's timestamp is set to current time. |
57 | -If the node is in the "friends" list the matching client's timestamp is set to current time for every occurrence. | 57 | - If the node is in the "friends" list the matching client's timestamp is set to current time for every occurrence. |
58 | -If the node is not in the client list: | 58 | - If the node is not in the client list: |
59 | -If the list isn't full, add it to the list. | 59 | - If the list isn't full, add it to the list. |
60 | -If the list is full, the furthest away (mathematically see bittorrent doc) bad client is replaced by the new one. | 60 | - If the list is full, the furthest away (mathematically see bittorrent doc) bad client is replaced by the new one. |
61 | -If the list is filled with good nodes replace the furthest client with it only if it is closer than the replaced node. | 61 | - If the list is filled with good nodes replace the furthest client with it only if it is closer than the replaced node. |
62 | -for each friend in the "friends" list: | 62 | - for each friend in the "friends" list: |
63 | -If that friend's client list isn't full, add that client to it | 63 | - If that friend's client list isn't full, add that client to it |
64 | -If that friend's client list contains bad clients, replace the furthest one with that client. | 64 | - If that friend's client list contains bad clients, replace the furthest one with that client. |
65 | -If that friend's client list contains only good clients | 65 | - If that friend's client list contains only good clients |
66 | -If the client is closer to the friend than one of the other clients, it replaces the farthest one | 66 | - If the client is closer to the friend than one of the other clients, it replaces the farthest one |
67 | -If not, nothing happens. | 67 | - If not, nothing happens. |
68 | 68 | ||
69 | -Send nodes | 69 | - Send nodes |
70 | -If the ping_id matches what we sent previously (check in the corresponding pinged list.): | 70 | - If the ping_id matches what we sent previously (check in the corresponding pinged list.): |
71 | -Each node in the response is pinged. | 71 | - Each node in the response is pinged. |
72 | 72 | ||
73 | 73 | ||
74 | 74 | ||
diff --git a/toxav/msi.c b/toxav/msi.c index 138c8d3f..4445f567 100644 --- a/toxav/msi.c +++ b/toxav/msi.c | |||
@@ -486,7 +486,7 @@ struct timer_function_args { | |||
486 | * @param timeout Timeout in ms | 486 | * @param timeout Timeout in ms |
487 | * @return int | 487 | * @return int |
488 | */ | 488 | */ |
489 | static int timer_alloc ( TimerHandler *timers_container, void *(func)(void *), void *arg1, int arg2, uint32_t timeout) | 489 | static int timer_alloc ( TimerHandler *timers_container, void * (func)(void *), void *arg1, int arg2, uint32_t timeout) |
490 | { | 490 | { |
491 | static int timer_id; | 491 | static int timer_id; |
492 | pthread_mutex_lock(&timers_container->mutex); | 492 | pthread_mutex_lock(&timers_container->mutex); |
@@ -631,6 +631,15 @@ static void *timer_poll( void *arg ) | |||
631 | usleep(handler->resolution); | 631 | usleep(handler->resolution); |
632 | } | 632 | } |
633 | 633 | ||
634 | size_t i = 0; | ||
635 | |||
636 | for (; i < handler->max_capacity; i ++) | ||
637 | free(handler->timers[i]); | ||
638 | |||
639 | free(handler->timers); | ||
640 | |||
641 | pthread_mutex_destroy( &handler->mutex ); | ||
642 | |||
634 | free(handler); | 643 | free(handler); |
635 | pthread_exit(NULL); | 644 | pthread_exit(NULL); |
636 | } | 645 | } |
@@ -691,15 +700,6 @@ static void timer_terminate_session(TimerHandler *handler) | |||
691 | handler->running = 0; | 700 | handler->running = 0; |
692 | 701 | ||
693 | pthread_mutex_unlock(&handler->mutex); | 702 | pthread_mutex_unlock(&handler->mutex); |
694 | |||
695 | size_t i = 0; | ||
696 | |||
697 | for (; i < handler->max_capacity; i ++) | ||
698 | free(handler->timers[i]); | ||
699 | |||
700 | free(handler->timers); | ||
701 | |||
702 | pthread_mutex_destroy( &handler->mutex ); | ||
703 | } | 703 | } |
704 | 704 | ||
705 | /** | 705 | /** |
diff --git a/toxav/toxav.c b/toxav/toxav.c index 7cba031e..8549bc05 100644 --- a/toxav/toxav.c +++ b/toxav/toxav.c | |||
@@ -588,6 +588,8 @@ int toxav_kill_transmission ( ToxAv *av, int32_t call_index ) | |||
588 | codec_terminate_session(call->cs); | 588 | codec_terminate_session(call->cs); |
589 | call->cs = NULL; | 589 | call->cs = NULL; |
590 | 590 | ||
591 | free(call->frame_buf); | ||
592 | |||
591 | pthread_mutex_unlock(&call->mutex); | 593 | pthread_mutex_unlock(&call->mutex); |
592 | pthread_mutex_destroy(&call->mutex); | 594 | pthread_mutex_destroy(&call->mutex); |
593 | 595 | ||
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 4841cbd9..eaf87179 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -2648,10 +2648,9 @@ uint32_t messenger_size(const Messenger *m) | |||
2648 | 2648 | ||
2649 | static uint8_t *z_state_save_subheader(uint8_t *data, uint32_t len, uint16_t type) | 2649 | static uint8_t *z_state_save_subheader(uint8_t *data, uint32_t len, uint16_t type) |
2650 | { | 2650 | { |
2651 | memcpy(data, &len, sizeof(uint32_t)); | 2651 | host_to_lendian32(data, len); |
2652 | data += sizeof(uint32_t); | 2652 | data += sizeof(uint32_t); |
2653 | uint32_t temp = (MESSENGER_STATE_COOKIE_TYPE << 16) | type; | 2653 | host_to_lendian32(data, (host_tolendian16(MESSENGER_STATE_COOKIE_TYPE) << 16) | host_tolendian16(type)); |
2654 | memcpy(data, &temp, sizeof(uint32_t)); | ||
2655 | data += sizeof(uint32_t); | 2654 | data += sizeof(uint32_t); |
2656 | return data; | 2655 | return data; |
2657 | } | 2656 | } |
diff --git a/toxcore/group.c b/toxcore/group.c index 26df82bd..24f0b72e 100644 --- a/toxcore/group.c +++ b/toxcore/group.c | |||
@@ -190,7 +190,7 @@ static int get_peer_index(Group_c *g, uint16_t peer_number) | |||
190 | 190 | ||
191 | static uint16_t calculate_comp_value(const uint8_t *pk1, const uint8_t *pk2) | 191 | static uint16_t calculate_comp_value(const uint8_t *pk1, const uint8_t *pk2) |
192 | { | 192 | { |
193 | uint8_t cmp1, cmp2; | 193 | uint8_t cmp1, cmp2 = 0; |
194 | 194 | ||
195 | for (cmp1 = crypto_box_PUBLICKEYBYTES; cmp1 != 0; --cmp1) { | 195 | for (cmp1 = crypto_box_PUBLICKEYBYTES; cmp1 != 0; --cmp1) { |
196 | uint8_t index = crypto_box_PUBLICKEYBYTES - cmp1; | 196 | uint8_t index = crypto_box_PUBLICKEYBYTES - cmp1; |
@@ -1025,7 +1025,7 @@ static void handle_friend_invite_packet(Messenger *m, int32_t friendnumber, cons | |||
1025 | return; | 1025 | return; |
1026 | 1026 | ||
1027 | uint16_t peer_number = rand(); /* TODO: what if two people enter the group at the same time and | 1027 | uint16_t peer_number = rand(); /* TODO: what if two people enter the group at the same time and |
1028 | are given the same peer_number by different nodes? */ | 1028 | are given the same peer_number by different nodes? */ |
1029 | unsigned int tries = 0; | 1029 | unsigned int tries = 0; |
1030 | 1030 | ||
1031 | while (get_peer_index(g, peer_number) != -1) { | 1031 | while (get_peer_index(g, peer_number) != -1) { |
@@ -1282,6 +1282,8 @@ static void handle_direct_packet(Group_Chats *g_c, int groupnumber, const uint8_ | |||
1282 | } | 1282 | } |
1283 | } | 1283 | } |
1284 | 1284 | ||
1285 | break; | ||
1286 | |||
1285 | case PEER_QUERY_ID: { | 1287 | case PEER_QUERY_ID: { |
1286 | Group_c *g = get_group_c(g_c, groupnumber); | 1288 | Group_c *g = get_group_c(g_c, groupnumber); |
1287 | 1289 | ||
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index 63012ce6..c83c5d54 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c | |||
@@ -835,8 +835,9 @@ static int64_t send_lossless_packet(Net_Crypto *c, int crypt_connection_id, cons | |||
835 | 835 | ||
836 | if (send_data_packet_helper(c, crypt_connection_id, conn->recv_array.buffer_start, packet_num, data, length) == 0) { | 836 | if (send_data_packet_helper(c, crypt_connection_id, conn->recv_array.buffer_start, packet_num, data, length) == 0) { |
837 | Packet_Data *dt1 = NULL; | 837 | Packet_Data *dt1 = NULL; |
838 | get_data_pointer(&conn->send_array, &dt1, packet_num); | 838 | |
839 | dt1->time = temp_time; | 839 | if (get_data_pointer(&conn->send_array, &dt1, packet_num) == 1) |
840 | dt1->time = temp_time; | ||
840 | } else { | 841 | } else { |
841 | conn->maximum_speed_reached = 1; | 842 | conn->maximum_speed_reached = 1; |
842 | LOGGER_ERROR("send_data_packet failed\n"); | 843 | LOGGER_ERROR("send_data_packet failed\n"); |
@@ -1322,8 +1323,10 @@ static int create_crypto_connection(Net_Crypto *c) | |||
1322 | ++c->crypto_connections_length; | 1323 | ++c->crypto_connections_length; |
1323 | memset(&(c->crypto_connections[id]), 0, sizeof(Crypto_Connection)); | 1324 | memset(&(c->crypto_connections[id]), 0, sizeof(Crypto_Connection)); |
1324 | 1325 | ||
1325 | if (pthread_mutex_init(&c->crypto_connections[id].mutex, NULL) != 0) | 1326 | if (pthread_mutex_init(&c->crypto_connections[id].mutex, NULL) != 0) { |
1327 | pthread_mutex_unlock(&c->connections_mutex); | ||
1326 | return -1; | 1328 | return -1; |
1329 | } | ||
1327 | } | 1330 | } |
1328 | 1331 | ||
1329 | pthread_mutex_unlock(&c->connections_mutex); | 1332 | pthread_mutex_unlock(&c->connections_mutex); |
@@ -1817,6 +1820,7 @@ static int tcp_oob_callback(void *object, const uint8_t *public_key, const uint8 | |||
1817 | 1820 | ||
1818 | if (crypt_connection_id == -1) { | 1821 | if (crypt_connection_id == -1) { |
1819 | IP_Port source; | 1822 | IP_Port source; |
1823 | source.port = 0; | ||
1820 | source.ip.family = TCP_FAMILY; | 1824 | source.ip.family = TCP_FAMILY; |
1821 | source.ip.ip6.uint32[0] = location; | 1825 | source.ip.ip6.uint32[0] = location; |
1822 | 1826 | ||
diff --git a/toxcore/onion_announce.c b/toxcore/onion_announce.c index b25b6b11..2b0de595 100644 --- a/toxcore/onion_announce.c +++ b/toxcore/onion_announce.c | |||
@@ -178,6 +178,9 @@ int send_data_request(Networking_Core *net, const Onion_Path *path, IP_Port dest | |||
178 | uint8_t packet[ONION_MAX_PACKET_SIZE]; | 178 | uint8_t packet[ONION_MAX_PACKET_SIZE]; |
179 | len = create_onion_packet(packet, sizeof(packet), path, dest, request, len); | 179 | len = create_onion_packet(packet, sizeof(packet), path, dest, request, len); |
180 | 180 | ||
181 | if (len == -1) | ||
182 | return -1; | ||
183 | |||
181 | if (sendpacket(net, path->ip_port1, packet, len) != len) | 184 | if (sendpacket(net, path->ip_port1, packet, len) != len) |
182 | return -1; | 185 | return -1; |
183 | 186 | ||
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index 11858d4c..24949aff 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c | |||
@@ -1126,10 +1126,10 @@ static void populate_path_nodes(Onion_Client *onion_c) | |||
1126 | } | 1126 | } |
1127 | 1127 | ||
1128 | #define ANNOUNCE_FRIEND (ONION_NODE_PING_INTERVAL * 3) | 1128 | #define ANNOUNCE_FRIEND (ONION_NODE_PING_INTERVAL * 3) |
1129 | #define ANNOUNCE_FRIEND_BEGINNING 5 | 1129 | #define ANNOUNCE_FRIEND_BEGINNING 3 |
1130 | #define FRIEND_ONION_NODE_TIMEOUT (ONION_NODE_TIMEOUT * 3) | 1130 | #define FRIEND_ONION_NODE_TIMEOUT (ONION_NODE_TIMEOUT * 3) |
1131 | 1131 | ||
1132 | #define RUN_COUNT_FRIEND_ANNOUNCE_BEGINNING 15 | 1132 | #define RUN_COUNT_FRIEND_ANNOUNCE_BEGINNING 17 |
1133 | 1133 | ||
1134 | static void do_friend(Onion_Client *onion_c, uint16_t friendnum) | 1134 | static void do_friend(Onion_Client *onion_c, uint16_t friendnum) |
1135 | { | 1135 | { |
diff --git a/toxcore/util.c b/toxcore/util.c index ee4fa3b2..3d444b07 100644 --- a/toxcore/util.c +++ b/toxcore/util.c | |||
@@ -84,6 +84,35 @@ void host_to_net(uint8_t *num, uint16_t numbytes) | |||
84 | return; | 84 | return; |
85 | } | 85 | } |
86 | 86 | ||
87 | uint16_t lendian_to_host16(uint16_t lendian) | ||
88 | { | ||
89 | #ifdef WORDS_BIGENDIAN | ||
90 | return (lendian << 8) | (lendian >> 8 ); | ||
91 | #else | ||
92 | return lendian; | ||
93 | #endif | ||
94 | } | ||
95 | |||
96 | void host_to_lendian32(uint8_t *dest, uint32_t num) | ||
97 | { | ||
98 | #ifdef WORDS_BIGENDIAN | ||
99 | num = ((num << 8) & 0xFF00FF00 ) | ((num >> 8) & 0xFF00FF ); | ||
100 | num = (num << 16) | (num >> 16); | ||
101 | #endif | ||
102 | memcpy(dest, &num, sizeof(uint32_t)); | ||
103 | } | ||
104 | |||
105 | void lendian_to_host32(uint32_t *dest, const uint8_t *lendian) | ||
106 | { | ||
107 | uint32_t d; | ||
108 | memcpy(&d, lendian, sizeof(uint32_t)); | ||
109 | #ifdef WORDS_BIGENDIAN | ||
110 | d = ((d << 8) & 0xFF00FF00 ) | ((d >> 8) & 0xFF00FF ); | ||
111 | d = (d << 16) | (d >> 16); | ||
112 | #endif | ||
113 | *dest = d; | ||
114 | } | ||
115 | |||
87 | /* state load/save */ | 116 | /* state load/save */ |
88 | int load_state(load_state_callback_func load_state_callback, void *outer, | 117 | int load_state(load_state_callback_func load_state_callback, void *outer, |
89 | const uint8_t *data, uint32_t length, uint16_t cookie_inner) | 118 | const uint8_t *data, uint32_t length, uint16_t cookie_inner) |
@@ -101,8 +130,8 @@ int load_state(load_state_callback_func load_state_callback, void *outer, | |||
101 | uint32_t size_head = sizeof(uint32_t) * 2; | 130 | uint32_t size_head = sizeof(uint32_t) * 2; |
102 | 131 | ||
103 | while (length >= size_head) { | 132 | while (length >= size_head) { |
104 | memcpy(&length_sub, data, sizeof(length_sub)); | 133 | lendian_to_host32(&length_sub, data); |
105 | memcpy(&cookie_type, data + sizeof(length_sub), sizeof(cookie_type)); | 134 | lendian_to_host32(&cookie_type, data + sizeof(length_sub)); |
106 | data += size_head; | 135 | data += size_head; |
107 | length -= size_head; | 136 | length -= size_head; |
108 | 137 | ||
@@ -114,7 +143,7 @@ int load_state(load_state_callback_func load_state_callback, void *outer, | |||
114 | return -1; | 143 | return -1; |
115 | } | 144 | } |
116 | 145 | ||
117 | if ((cookie_type >> 16) != cookie_inner) { | 146 | if (lendian_to_host16((cookie_type >> 16)) != cookie_inner) { |
118 | /* something is not matching up in a bad way, give up */ | 147 | /* something is not matching up in a bad way, give up */ |
119 | #ifdef DEBUG | 148 | #ifdef DEBUG |
120 | fprintf(stderr, "state file garbeled: %04hx != %04hx\n", (cookie_type >> 16), cookie_inner); | 149 | fprintf(stderr, "state file garbeled: %04hx != %04hx\n", (cookie_type >> 16), cookie_inner); |
@@ -122,7 +151,7 @@ int load_state(load_state_callback_func load_state_callback, void *outer, | |||
122 | return -1; | 151 | return -1; |
123 | } | 152 | } |
124 | 153 | ||
125 | type = cookie_type & 0xFFFF; | 154 | type = lendian_to_host16(cookie_type & 0xFFFF); |
126 | 155 | ||
127 | if (-1 == load_state_callback(outer, data, length_sub, type)) | 156 | if (-1 == load_state_callback(outer, data, length_sub, type)) |
128 | return -1; | 157 | return -1; |
diff --git a/toxcore/util.h b/toxcore/util.h index 7992a985..e90eee0f 100644 --- a/toxcore/util.h +++ b/toxcore/util.h | |||
@@ -42,6 +42,11 @@ uint32_t id_copy(uint8_t *dest, const uint8_t *src); /* return value is CLIENT_I | |||
42 | void host_to_net(uint8_t *num, uint16_t numbytes); | 42 | void host_to_net(uint8_t *num, uint16_t numbytes); |
43 | #define net_to_host(x, y) host_to_net(x, y) | 43 | #define net_to_host(x, y) host_to_net(x, y) |
44 | 44 | ||
45 | uint16_t lendian_to_host16(uint16_t lendian); | ||
46 | #define host_tolendian16(x) lendian_to_host16(x) | ||
47 | |||
48 | void host_to_lendian32(uint8_t *dest, uint32_t num); | ||
49 | |||
45 | /* state load/save */ | 50 | /* state load/save */ |
46 | typedef int (*load_state_callback_func)(void *outer, const uint8_t *data, uint32_t len, uint16_t type); | 51 | typedef int (*load_state_callback_func)(void *outer, const uint8_t *data, uint32_t len, uint16_t type); |
47 | int load_state(load_state_callback_func load_state_callback, void *outer, | 52 | int load_state(load_state_callback_func load_state_callback, void *outer, |