summaryrefslogtreecommitdiff
path: root/toxcore/DHT.c
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2016-09-12 21:37:58 +0100
committeriphydf <iphydf@users.noreply.github.com>2016-09-13 01:07:02 +0100
commita8823830d39bdbde8d4f4f34bfcb26dc4bf79741 (patch)
tree086d51b0db42c8fdbef669d002739f607db52f01 /toxcore/DHT.c
parent0aa2840164fc782f150cd45f8668ca623e6002cf (diff)
Add some astyle options to make it do more.
It now enforces a bit more formatting. In particular, padding inside parentheses is removed. I would like it to remove padding after unary operators, but there seems to be no option for that.
Diffstat (limited to 'toxcore/DHT.c')
-rw-r--r--toxcore/DHT.c57
1 files changed, 30 insertions, 27 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c
index beff0499..7e2445b3 100644
--- a/toxcore/DHT.c
+++ b/toxcore/DHT.c
@@ -642,7 +642,7 @@ static void get_close_nodes_inner(const uint8_t *public_key, Node_format *nodes_
642 if (num_nodes < MAX_SENT_NODES) { 642 if (num_nodes < MAX_SENT_NODES) {
643 memcpy(nodes_list[num_nodes].public_key, 643 memcpy(nodes_list[num_nodes].public_key,
644 client->public_key, 644 client->public_key,
645 crypto_box_PUBLICKEYBYTES ); 645 crypto_box_PUBLICKEYBYTES);
646 646
647 nodes_list[num_nodes].ip_port = ipptp->ip_port; 647 nodes_list[num_nodes].ip_port = ipptp->ip_port;
648 num_nodes++; 648 num_nodes++;
@@ -827,11 +827,11 @@ static void sort_client_list(Client_data *list, unsigned int length, const uint8
827 * than public_key. 827 * than public_key.
828 * 828 *
829 * returns True(1) when the item was stored, False(0) otherwise */ 829 * returns True(1) when the item was stored, False(0) otherwise */
830static int replace_all( Client_data *list, 830static int replace_all(Client_data *list,
831 uint16_t length, 831 uint16_t length,
832 const uint8_t *public_key, 832 const uint8_t *public_key,
833 IP_Port ip_port, 833 IP_Port ip_port,
834 const uint8_t *comp_public_key ) 834 const uint8_t *comp_public_key)
835{ 835{
836 if ((ip_port.ip.family != AF_INET) && (ip_port.ip.family != AF_INET6)) { 836 if ((ip_port.ip.family != AF_INET) && (ip_port.ip.family != AF_INET6)) {
837 return 0; 837 return 0;
@@ -1197,11 +1197,11 @@ static int getnodes(DHT *dht, IP_Port ip_port, const uint8_t *public_key, const
1197 uint8_t nonce[crypto_box_NONCEBYTES]; 1197 uint8_t nonce[crypto_box_NONCEBYTES];
1198 new_nonce(nonce); 1198 new_nonce(nonce);
1199 1199
1200 int len = encrypt_data_symmetric( shared_key, 1200 int len = encrypt_data_symmetric(shared_key,
1201 nonce, 1201 nonce,
1202 plain, 1202 plain,
1203 sizeof(plain), 1203 sizeof(plain),
1204 encrypt ); 1204 encrypt);
1205 1205
1206 if (len != sizeof(encrypt)) { 1206 if (len != sizeof(encrypt)) {
1207 return -1; 1207 return -1;
@@ -1252,11 +1252,11 @@ static int sendnodes_ipv6(const DHT *dht, IP_Port ip_port, const uint8_t *public
1252 1252
1253 plain[0] = num_nodes; 1253 plain[0] = num_nodes;
1254 memcpy(plain + 1 + nodes_length, sendback_data, length); 1254 memcpy(plain + 1 + nodes_length, sendback_data, length);
1255 int len = encrypt_data_symmetric( shared_encryption_key, 1255 int len = encrypt_data_symmetric(shared_encryption_key,
1256 nonce, 1256 nonce,
1257 plain, 1257 plain,
1258 1 + nodes_length + length, 1258 1 + nodes_length + length,
1259 encrypt ); 1259 encrypt);
1260 1260
1261 if (len != 1 + nodes_length + length + crypto_box_MACBYTES) { 1261 if (len != 1 + nodes_length + length + crypto_box_MACBYTES) {
1262 return -1; 1262 return -1;
@@ -1288,11 +1288,11 @@ static int handle_getnodes(void *object, IP_Port source, const uint8_t *packet,
1288 uint8_t shared_key[crypto_box_BEFORENMBYTES]; 1288 uint8_t shared_key[crypto_box_BEFORENMBYTES];
1289 1289
1290 DHT_get_shared_key_recv(dht, shared_key, packet + 1); 1290 DHT_get_shared_key_recv(dht, shared_key, packet + 1);
1291 int len = decrypt_data_symmetric( shared_key, 1291 int len = decrypt_data_symmetric(shared_key,
1292 packet + 1 + crypto_box_PUBLICKEYBYTES, 1292 packet + 1 + crypto_box_PUBLICKEYBYTES,
1293 packet + 1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES, 1293 packet + 1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES,
1294 crypto_box_PUBLICKEYBYTES + sizeof(uint64_t) + crypto_box_MACBYTES, 1294 crypto_box_PUBLICKEYBYTES + sizeof(uint64_t) + crypto_box_MACBYTES,
1295 plain ); 1295 plain);
1296 1296
1297 if (len != crypto_box_PUBLICKEYBYTES + sizeof(uint64_t)) { 1297 if (len != crypto_box_PUBLICKEYBYTES + sizeof(uint64_t)) {
1298 return 1; 1298 return 1;
@@ -1515,9 +1515,9 @@ int DHT_delfriend(DHT *dht, const uint8_t *public_key, uint16_t lock_count)
1515 --dht->num_friends; 1515 --dht->num_friends;
1516 1516
1517 if (dht->num_friends != friend_num) { 1517 if (dht->num_friends != friend_num) {
1518 memcpy( &dht->friends_list[friend_num], 1518 memcpy(&dht->friends_list[friend_num],
1519 &dht->friends_list[dht->num_friends], 1519 &dht->friends_list[dht->num_friends],
1520 sizeof(DHT_Friend) ); 1520 sizeof(DHT_Friend));
1521 } 1521 }
1522 1522
1523 if (dht->num_friends == 0) { 1523 if (dht->num_friends == 0) {
@@ -1819,13 +1819,15 @@ static int friend_iplist(const DHT *dht, IP_Port *ip_portlist, uint16_t friend_n
1819#ifdef FRIEND_IPLIST_PAD 1819#ifdef FRIEND_IPLIST_PAD
1820 memcpy(ip_portlist, ipv6s, num_ipv6s * sizeof(IP_Port)); 1820 memcpy(ip_portlist, ipv6s, num_ipv6s * sizeof(IP_Port));
1821 1821
1822 if (num_ipv6s == MAX_FRIEND_CLIENTS) 1822 if (num_ipv6s == MAX_FRIEND_CLIENTS) {
1823 return MAX_FRIEND_CLIENTS; 1823 return MAX_FRIEND_CLIENTS;
1824 }
1824 1825
1825 int num_ipv4s_used = MAX_FRIEND_CLIENTS - num_ipv6s; 1826 int num_ipv4s_used = MAX_FRIEND_CLIENTS - num_ipv6s;
1826 1827
1827 if (num_ipv4s_used > num_ipv4s) 1828 if (num_ipv4s_used > num_ipv4s) {
1828 num_ipv4s_used = num_ipv4s; 1829 num_ipv4s_used = num_ipv4s;
1830 }
1829 1831
1830 memcpy(&ip_portlist[num_ipv6s], ipv4s, num_ipv4s_used * sizeof(IP_Port)); 1832 memcpy(&ip_portlist[num_ipv6s], ipv4s, num_ipv4s_used * sizeof(IP_Port));
1831 return num_ipv6s + num_ipv4s_used; 1833 return num_ipv6s + num_ipv4s_used;
@@ -2654,8 +2656,9 @@ void do_DHT(DHT *dht)
2654#endif 2656#endif
2655#ifdef ENABLE_ASSOC_DHT 2657#ifdef ENABLE_ASSOC_DHT
2656 2658
2657 if (dht->assoc) 2659 if (dht->assoc) {
2658 do_Assoc(dht->assoc, dht); 2660 do_Assoc(dht->assoc, dht);
2661 }
2659 2662
2660#endif 2663#endif
2661 dht->last_run = unix_time(); 2664 dht->last_run = unix_time();