summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--toxcore/list.c10
-rw-r--r--toxcore/list.h8
-rw-r--r--toxcore/net_crypto.c12
3 files changed, 15 insertions, 15 deletions
diff --git a/toxcore/list.c b/toxcore/list.c
index 301e56f8..8bb71306 100644
--- a/toxcore/list.c
+++ b/toxcore/list.c
@@ -45,7 +45,7 @@
45 * < 0 : no match, returns index (return value is INDEX(index)) where 45 * < 0 : no match, returns index (return value is INDEX(index)) where
46 * the data should be inserted 46 * the data should be inserted
47 */ 47 */
48static int find(const BS_LIST *list, const void *data) 48static int find(const BS_LIST *list, const uint8_t *data)
49{ 49{
50 //should work well, but could be improved 50 //should work well, but could be improved
51 if (list->n == 0) { 51 if (list->n == 0) {
@@ -113,7 +113,7 @@ static int find(const BS_LIST *list, const void *data)
113 */ 113 */
114static int resize(BS_LIST *list, uint32_t new_size) 114static int resize(BS_LIST *list, uint32_t new_size)
115{ 115{
116 void *p; 116 uint8_t *p;
117 117
118 p = realloc(list->data, list->element_size * new_size); 118 p = realloc(list->data, list->element_size * new_size);
119 119
@@ -162,7 +162,7 @@ void bs_list_free(BS_LIST *list)
162 free(list->ids); 162 free(list->ids);
163} 163}
164 164
165int bs_list_find(const BS_LIST *list, const void *data) 165int bs_list_find(const BS_LIST *list, const uint8_t *data)
166{ 166{
167 int r = find(list, data); 167 int r = find(list, data);
168 168
@@ -174,7 +174,7 @@ int bs_list_find(const BS_LIST *list, const void *data)
174 return list->ids[r]; 174 return list->ids[r];
175} 175}
176 176
177int bs_list_add(BS_LIST *list, const void *data, int id) 177int bs_list_add(BS_LIST *list, const uint8_t *data, int id)
178{ 178{
179 //find where the new element should be inserted 179 //find where the new element should be inserted
180 //see: return value of find() 180 //see: return value of find()
@@ -214,7 +214,7 @@ int bs_list_add(BS_LIST *list, const void *data, int id)
214 return 1; 214 return 1;
215} 215}
216 216
217int bs_list_remove(BS_LIST *list, const void *data, int id) 217int bs_list_remove(BS_LIST *list, const uint8_t *data, int id)
218{ 218{
219 int i = find(list, data); 219 int i = find(list, data);
220 220
diff --git a/toxcore/list.h b/toxcore/list.h
index 03ac04dd..b04177e1 100644
--- a/toxcore/list.h
+++ b/toxcore/list.h
@@ -34,7 +34,7 @@ typedef struct {
34 uint32_t n; //number of elements 34 uint32_t n; //number of elements
35 uint32_t capacity; //number of elements memory is allocated for 35 uint32_t capacity; //number of elements memory is allocated for
36 uint32_t element_size; //size of the elements 36 uint32_t element_size; //size of the elements
37 void *data; //array of elements 37 uint8_t *data; //array of elements
38 int *ids; //array of element ids 38 int *ids; //array of element ids
39} BS_LIST; 39} BS_LIST;
40 40
@@ -56,7 +56,7 @@ void bs_list_free(BS_LIST *list);
56 * >= 0 : id associated with data 56 * >= 0 : id associated with data
57 * -1 : failure 57 * -1 : failure
58 */ 58 */
59int bs_list_find(const BS_LIST *list, const void *data); 59int bs_list_find(const BS_LIST *list, const uint8_t *data);
60 60
61/* Add an element with associated id to the list 61/* Add an element with associated id to the list
62 * 62 *
@@ -64,7 +64,7 @@ int bs_list_find(const BS_LIST *list, const void *data);
64 * 1 : success 64 * 1 : success
65 * 0 : failure (data already in list) 65 * 0 : failure (data already in list)
66 */ 66 */
67int bs_list_add(BS_LIST *list, const void *data, int id); 67int bs_list_add(BS_LIST *list, const uint8_t *data, int id);
68 68
69/* Remove element from the list 69/* Remove element from the list
70 * 70 *
@@ -72,7 +72,7 @@ int bs_list_add(BS_LIST *list, const void *data, int id);
72 * 1 : success 72 * 1 : success
73 * 0 : failure (element not found or id does not match) 73 * 0 : failure (element not found or id does not match)
74 */ 74 */
75int bs_list_remove(BS_LIST *list, const void *data, int id); 75int bs_list_remove(BS_LIST *list, const uint8_t *data, int id);
76 76
77/* Removes the memory overhead 77/* Removes the memory overhead
78 * 78 *
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c
index b7c634de..d74f0bf5 100644
--- a/toxcore/net_crypto.c
+++ b/toxcore/net_crypto.c
@@ -1439,10 +1439,10 @@ static int crypto_connection_add_source(Net_Crypto *c, int crypt_connection_id,
1439 1439
1440 if (source.ip.family == AF_INET || source.ip.family == AF_INET6) { 1440 if (source.ip.family == AF_INET || source.ip.family == AF_INET6) {
1441 if (!ipport_equal(&source, &conn->ip_port)) { 1441 if (!ipport_equal(&source, &conn->ip_port)) {
1442 if (!bs_list_add(&c->ip_port_list, &source, crypt_connection_id)) 1442 if (!bs_list_add(&c->ip_port_list, (uint8_t *)&source, crypt_connection_id))
1443 return -1; 1443 return -1;
1444 1444
1445 bs_list_remove(&c->ip_port_list, &conn->ip_port, crypt_connection_id); 1445 bs_list_remove(&c->ip_port_list, (uint8_t *)&conn->ip_port, crypt_connection_id);
1446 conn->ip_port = source; 1446 conn->ip_port = source;
1447 } 1447 }
1448 1448
@@ -1658,8 +1658,8 @@ int set_direct_ip_port(Net_Crypto *c, int crypt_connection_id, IP_Port ip_port)
1658 return -1; 1658 return -1;
1659 } 1659 }
1660 1660
1661 if (bs_list_add(&c->ip_port_list, &ip_port, crypt_connection_id)) { 1661 if (bs_list_add(&c->ip_port_list, (uint8_t *)&ip_port, crypt_connection_id)) {
1662 bs_list_remove(&c->ip_port_list, &conn->ip_port, crypt_connection_id); 1662 bs_list_remove(&c->ip_port_list, (uint8_t *)&conn->ip_port, crypt_connection_id);
1663 conn->ip_port = ip_port; 1663 conn->ip_port = ip_port;
1664 conn->direct_lastrecv_time = 0; 1664 conn->direct_lastrecv_time = 0;
1665 return 0; 1665 return 0;
@@ -1933,7 +1933,7 @@ int nc_dht_pk_callback(Net_Crypto *c, int crypt_connection_id, void (*function)(
1933 */ 1933 */
1934static int crypto_id_ip_port(const Net_Crypto *c, IP_Port ip_port) 1934static int crypto_id_ip_port(const Net_Crypto *c, IP_Port ip_port)
1935{ 1935{
1936 return bs_list_find(&c->ip_port_list, &ip_port); 1936 return bs_list_find(&c->ip_port_list, (uint8_t *)&ip_port);
1937} 1937}
1938 1938
1939#define CRYPTO_MIN_PACKET_SIZE (1 + sizeof(uint16_t) + crypto_box_MACBYTES) 1939#define CRYPTO_MIN_PACKET_SIZE (1 + sizeof(uint16_t) + crypto_box_MACBYTES)
@@ -2282,7 +2282,7 @@ int crypto_kill(Net_Crypto *c, int crypt_connection_id)
2282 kill_tcp_connection_to(c->tcp_c, conn->connection_number_tcp); 2282 kill_tcp_connection_to(c->tcp_c, conn->connection_number_tcp);
2283 pthread_mutex_unlock(&c->tcp_mutex); 2283 pthread_mutex_unlock(&c->tcp_mutex);
2284 2284
2285 bs_list_remove(&c->ip_port_list, &conn->ip_port, crypt_connection_id); 2285 bs_list_remove(&c->ip_port_list, (uint8_t *)&conn->ip_port, crypt_connection_id);
2286 clear_temp_packet(c, crypt_connection_id); 2286 clear_temp_packet(c, crypt_connection_id);
2287 clear_buffer(&conn->send_array); 2287 clear_buffer(&conn->send_array);
2288 clear_buffer(&conn->recv_array); 2288 clear_buffer(&conn->recv_array);