30
30
/** The timeout after which a node is discarded completely. */
31
31
#define KILL_NODE_TIMEOUT (BAD_NODE_TIMEOUT + PING_INTERVAL)
32
32
33
- /** Ping interval in seconds for each random sending of a get nodes request. */
34
- #define GET_NODE_INTERVAL 20
33
+ /** Ping interval in seconds for each random sending of a nodes request. */
34
+ #define NODES_REQUEST_INTERVAL 20
35
35
36
36
#define MAX_PUNCHING_PORTS 48
37
37
46
46
#define NAT_PING_REQUEST 0
47
47
#define NAT_PING_RESPONSE 1
48
48
49
- /** Number of get node requests to send to quickly find close nodes. */
49
+ /** Number of node requests to send to quickly find close nodes. */
50
50
#define MAX_BOOTSTRAP_TIMES 5
51
51
52
52
// TODO(sudden6): find out why we need multiple callbacks and if we really need 32
@@ -66,9 +66,9 @@ struct DHT_Friend {
66
66
uint8_t public_key [CRYPTO_PUBLIC_KEY_SIZE ];
67
67
Client_data client_list [MAX_FRIEND_CLIENTS ];
68
68
69
- /* Time at which the last get_nodes request was sent. */
70
- uint64_t lastgetnode ;
71
- /* number of times get_node packets were sent. */
69
+ /* Time at which the last nodes request was sent. */
70
+ uint64_t last_nodes_request ;
71
+ /* number of times nodes request packets were sent. */
72
72
uint32_t bootstrap_times ;
73
73
74
74
/* Symmetric NAT hole punching stuff. */
@@ -104,7 +104,7 @@ struct DHT {
104
104
bool lan_discovery_enabled ;
105
105
106
106
Client_data close_clientlist [LCLIENT_LIST ];
107
- uint64_t close_lastgetnodes ;
107
+ uint64_t close_last_nodes_request ;
108
108
uint32_t close_bootstrap_times ;
109
109
110
110
/* DHT keypair */
@@ -130,7 +130,7 @@ struct DHT {
130
130
Node_format to_bootstrap [MAX_CLOSE_TO_BOOTSTRAP_NODES ];
131
131
unsigned int num_to_bootstrap ;
132
132
133
- dht_get_nodes_response_cb * get_nodes_response ;
133
+ dht_nodes_response_cb * nodes_response_callback ;
134
134
};
135
135
136
136
const uint8_t * dht_friend_public_key (const DHT_Friend * dht_friend )
@@ -712,7 +712,7 @@ static void get_close_nodes_inner(
712
712
}
713
713
714
714
/**
715
- * Find MAX_SENT_NODES nodes closest to the public_key for the send nodes request:
715
+ * Find MAX_SENT_NODES nodes closest to the public_key for the nodes request:
716
716
* put them in the nodes_list and return how many were found.
717
717
*
718
718
* want_announce: return only nodes which implement the dht announcements protocol.
@@ -1135,15 +1135,15 @@ static bool is_pk_in_close_list(const DHT *dht, const uint8_t *public_key, const
1135
1135
ip_port );
1136
1136
}
1137
1137
1138
- /** @brief Check if the node obtained with a get_nodes with public_key should be pinged.
1138
+ /** @brief Check if the node obtained from a nodes response with public_key should be pinged.
1139
1139
*
1140
1140
* NOTE: for best results call it after addto_lists.
1141
1141
*
1142
1142
* return false if the node should not be pinged.
1143
1143
* return true if it should.
1144
1144
*/
1145
1145
non_null ()
1146
- static bool ping_node_from_getnodes_ok (DHT * dht , const uint8_t * public_key , const IP_Port * ip_port )
1146
+ static bool ping_node_from_nodes_response_ok (DHT * dht , const uint8_t * public_key , const IP_Port * ip_port )
1147
1147
{
1148
1148
bool ret = false;
1149
1149
@@ -1314,7 +1314,7 @@ static void returnedip_ports(DHT *dht, const IP_Port *ip_port, const uint8_t *pu
1314
1314
}
1315
1315
}
1316
1316
1317
- bool dht_getnodes (DHT * dht , const IP_Port * ip_port , const uint8_t * public_key , const uint8_t * client_id )
1317
+ bool dht_send_nodes_request (DHT * dht , const IP_Port * ip_port , const uint8_t * public_key , const uint8_t * client_id )
1318
1318
{
1319
1319
/* Check if packet is going to be sent to ourself. */
1320
1320
if (pk_equal (public_key , dht -> self_public_key )) {
@@ -1349,21 +1349,21 @@ bool dht_getnodes(DHT *dht, const IP_Port *ip_port, const uint8_t *public_key, c
1349
1349
const uint8_t * shared_key = dht_get_shared_key_sent (dht , public_key );
1350
1350
1351
1351
const int len = dht_create_packet (dht -> mem , dht -> rng ,
1352
- dht -> self_public_key , shared_key , NET_PACKET_GET_NODES ,
1352
+ dht -> self_public_key , shared_key , NET_PACKET_NODES_REQUEST ,
1353
1353
plain , sizeof (plain ), data , sizeof (data ));
1354
1354
1355
1355
if (len != sizeof (data )) {
1356
- LOGGER_ERROR (dht -> log , "getnodes packet encryption failed" );
1356
+ LOGGER_ERROR (dht -> log , "nodes request packet encryption failed" );
1357
1357
return false;
1358
1358
}
1359
1359
1360
1360
return sendpacket (dht -> net , ip_port , data , len ) > 0 ;
1361
1361
}
1362
1362
1363
- /** Send a send nodes response: message for IPv6 nodes */
1363
+ /** Send a nodes response */
1364
1364
non_null ()
1365
- static int sendnodes_ipv6 (const DHT * dht , const IP_Port * ip_port , const uint8_t * public_key , const uint8_t * client_id ,
1366
- const uint8_t * sendback_data , uint16_t length , const uint8_t * shared_encryption_key )
1365
+ static int send_nodes_response (const DHT * dht , const IP_Port * ip_port , const uint8_t * public_key , const uint8_t * client_id ,
1366
+ const uint8_t * sendback_data , uint16_t length , const uint8_t * shared_encryption_key )
1367
1367
{
1368
1368
/* Check if packet is going to be sent to ourself. */
1369
1369
if (pk_equal (public_key , dht -> self_public_key )) {
@@ -1400,7 +1400,7 @@ static int sendnodes_ipv6(const DHT *dht, const IP_Port *ip_port, const uint8_t
1400
1400
VLA (uint8_t , data , data_size );
1401
1401
1402
1402
const int len = dht_create_packet (dht -> mem , dht -> rng ,
1403
- dht -> self_public_key , shared_encryption_key , NET_PACKET_SEND_NODES_IPV6 ,
1403
+ dht -> self_public_key , shared_encryption_key , NET_PACKET_NODES_RESPONSE ,
1404
1404
plain , 1 + nodes_length + length , data , data_size );
1405
1405
1406
1406
if (len < 0 || (uint32_t )len != data_size ) {
@@ -1413,7 +1413,7 @@ static int sendnodes_ipv6(const DHT *dht, const IP_Port *ip_port, const uint8_t
1413
1413
#define CRYPTO_NODE_SIZE (CRYPTO_PUBLIC_KEY_SIZE + sizeof(uint64_t))
1414
1414
1415
1415
non_null ()
1416
- static int handle_getnodes (void * object , const IP_Port * source , const uint8_t * packet , uint16_t length , void * userdata )
1416
+ static int handle_nodes_request (void * object , const IP_Port * source , const uint8_t * packet , uint16_t length , void * userdata )
1417
1417
{
1418
1418
DHT * const dht = (DHT * )object ;
1419
1419
@@ -1440,16 +1440,16 @@ static int handle_getnodes(void *object, const IP_Port *source, const uint8_t *p
1440
1440
return 1 ;
1441
1441
}
1442
1442
1443
- sendnodes_ipv6 (dht , source , packet + 1 , plain , plain + CRYPTO_PUBLIC_KEY_SIZE , sizeof (uint64_t ), shared_key );
1443
+ send_nodes_response (dht , source , packet + 1 , plain , plain + CRYPTO_PUBLIC_KEY_SIZE , sizeof (uint64_t ), shared_key );
1444
1444
1445
1445
ping_add (dht -> ping , packet + 1 , source );
1446
1446
1447
1447
return 0 ;
1448
1448
}
1449
1449
1450
- /** Return true if we sent a getnode packet to the peer associated with the supplied info. */
1450
+ /** Return true if we sent a nodes request packet to the peer associated with the supplied info. */
1451
1451
non_null ()
1452
- static bool sent_getnode_to_node (DHT * dht , const uint8_t * public_key , const IP_Port * node_ip_port , uint64_t ping_id )
1452
+ static bool sent_nodes_request_to_node (DHT * dht , const uint8_t * public_key , const IP_Port * node_ip_port , uint64_t ping_id )
1453
1453
{
1454
1454
uint8_t data [sizeof (Node_format ) * 2 ];
1455
1455
@@ -1467,8 +1467,8 @@ static bool sent_getnode_to_node(DHT *dht, const uint8_t *public_key, const IP_P
1467
1467
}
1468
1468
1469
1469
non_null ()
1470
- static bool handle_sendnodes_core (void * object , const IP_Port * source , const uint8_t * packet , uint16_t length ,
1471
- Node_format * plain_nodes , uint16_t size_plain_nodes , uint32_t * num_nodes_out )
1470
+ static bool handle_nodes_response_core (void * object , const IP_Port * source , const uint8_t * packet , uint16_t length ,
1471
+ Node_format * plain_nodes , uint16_t size_plain_nodes , uint32_t * num_nodes_out )
1472
1472
{
1473
1473
DHT * const dht = (DHT * )object ;
1474
1474
const uint32_t cid_size = 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + 1 + sizeof (uint64_t ) + CRYPTO_MAC_SIZE ;
@@ -1509,7 +1509,7 @@ static bool handle_sendnodes_core(void *object, const IP_Port *source, const uin
1509
1509
uint64_t ping_id ;
1510
1510
memcpy (& ping_id , plain + 1 + data_size , sizeof (ping_id ));
1511
1511
1512
- if (!sent_getnode_to_node (dht , packet + 1 , source , ping_id )) {
1512
+ if (!sent_nodes_request_to_node (dht , packet + 1 , source , ping_id )) {
1513
1513
return false;
1514
1514
}
1515
1515
@@ -1537,14 +1537,14 @@ static bool handle_sendnodes_core(void *object, const IP_Port *source, const uin
1537
1537
}
1538
1538
1539
1539
non_null ()
1540
- static int handle_sendnodes_ipv6 (void * object , const IP_Port * source , const uint8_t * packet , uint16_t length ,
1540
+ static int handle_nodes_response (void * object , const IP_Port * source , const uint8_t * packet , uint16_t length ,
1541
1541
void * userdata )
1542
1542
{
1543
1543
DHT * const dht = (DHT * )object ;
1544
1544
Node_format plain_nodes [MAX_SENT_NODES ];
1545
1545
uint32_t num_nodes ;
1546
1546
1547
- if (!handle_sendnodes_core (object , source , packet , length , plain_nodes , MAX_SENT_NODES , & num_nodes )) {
1547
+ if (!handle_nodes_response_core (object , source , packet , length , plain_nodes , MAX_SENT_NODES , & num_nodes )) {
1548
1548
return 1 ;
1549
1549
}
1550
1550
@@ -1554,11 +1554,11 @@ static int handle_sendnodes_ipv6(void *object, const IP_Port *source, const uint
1554
1554
1555
1555
for (uint32_t i = 0 ; i < num_nodes ; ++ i ) {
1556
1556
if (ipport_isset (& plain_nodes [i ].ip_port )) {
1557
- ping_node_from_getnodes_ok (dht , plain_nodes [i ].public_key , & plain_nodes [i ].ip_port );
1557
+ ping_node_from_nodes_response_ok (dht , plain_nodes [i ].public_key , & plain_nodes [i ].ip_port );
1558
1558
returnedip_ports (dht , & plain_nodes [i ].ip_port , plain_nodes [i ].public_key , packet + 1 );
1559
1559
1560
- if (dht -> get_nodes_response != nullptr ) {
1561
- dht -> get_nodes_response (dht , & plain_nodes [i ], userdata );
1560
+ if (dht -> nodes_response_callback != nullptr ) {
1561
+ dht -> nodes_response_callback (dht , & plain_nodes [i ], userdata );
1562
1562
}
1563
1563
}
1564
1564
}
@@ -1771,7 +1771,7 @@ static uint8_t do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, co
1771
1771
if (mono_time_is_timeout (dht -> mono_time , assoc -> last_pinged , PING_INTERVAL )) {
1772
1772
const IP_Port * target = & assoc -> ip_port ;
1773
1773
const uint8_t * target_key = client -> public_key ;
1774
- dht_getnodes (dht , target , target_key , public_key );
1774
+ dht_send_nodes_request (dht , target , target_key , public_key );
1775
1775
assoc -> last_pinged = temp_time ;
1776
1776
}
1777
1777
@@ -1796,7 +1796,7 @@ static uint8_t do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, co
1796
1796
sort_client_list (dht -> mem , list , dht -> cur_time , list_count , public_key );
1797
1797
}
1798
1798
1799
- if (num_nodes > 0 && (mono_time_is_timeout (dht -> mono_time , * lastgetnode , GET_NODE_INTERVAL )
1799
+ if (num_nodes > 0 && (mono_time_is_timeout (dht -> mono_time , * lastgetnode , NODES_REQUEST_INTERVAL )
1800
1800
|| * bootstrap_times < MAX_BOOTSTRAP_TIMES )) {
1801
1801
uint32_t rand_node = random_range_u32 (dht -> rng , num_nodes );
1802
1802
@@ -1806,7 +1806,7 @@ static uint8_t do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, co
1806
1806
1807
1807
const IP_Port * target = & assoc_list [rand_node ]-> ip_port ;
1808
1808
const uint8_t * target_key = client_list [rand_node ]-> public_key ;
1809
- dht_getnodes (dht , target , target_key , public_key );
1809
+ dht_send_nodes_request (dht , target , target_key , public_key );
1810
1810
1811
1811
* lastgetnode = temp_time ;
1812
1812
++ * bootstrap_times ;
@@ -1819,7 +1819,7 @@ static uint8_t do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, co
1819
1819
1820
1820
/** @brief Ping each client in the "friends" list every PING_INTERVAL seconds.
1821
1821
*
1822
- * Send a get nodes request every GET_NODE_INTERVAL seconds to a random good
1822
+ * Send a nodes request every NODES_REQUEST_INTERVAL seconds to a random good
1823
1823
* node for each "friend" in our "friends" list.
1824
1824
*/
1825
1825
non_null ()
@@ -1829,31 +1829,31 @@ static void do_dht_friends(DHT *dht)
1829
1829
DHT_Friend * const dht_friend = & dht -> friends_list [i ];
1830
1830
1831
1831
for (size_t j = 0 ; j < dht_friend -> num_to_bootstrap ; ++ j ) {
1832
- dht_getnodes (dht , & dht_friend -> to_bootstrap [j ].ip_port , dht_friend -> to_bootstrap [j ].public_key , dht_friend -> public_key );
1832
+ dht_send_nodes_request (dht , & dht_friend -> to_bootstrap [j ].ip_port , dht_friend -> to_bootstrap [j ].public_key , dht_friend -> public_key );
1833
1833
}
1834
1834
1835
1835
dht_friend -> num_to_bootstrap = 0 ;
1836
1836
1837
- do_ping_and_sendnode_requests (dht , & dht_friend -> lastgetnode , dht_friend -> public_key , dht_friend -> client_list ,
1837
+ do_ping_and_sendnode_requests (dht , & dht_friend -> last_nodes_request , dht_friend -> public_key , dht_friend -> client_list ,
1838
1838
MAX_FRIEND_CLIENTS , & dht_friend -> bootstrap_times , true);
1839
1839
}
1840
1840
}
1841
1841
1842
1842
/** @brief Ping each client in the close nodes list every PING_INTERVAL seconds.
1843
1843
*
1844
- * Send a get nodes request every GET_NODE_INTERVAL seconds to a random good node in the list.
1844
+ * Send a nodes request every NODES_REQUEST_INTERVAL seconds to a random good node in the list.
1845
1845
*/
1846
1846
non_null ()
1847
1847
static void do_close (DHT * dht )
1848
1848
{
1849
1849
for (size_t i = 0 ; i < dht -> num_to_bootstrap ; ++ i ) {
1850
- dht_getnodes (dht , & dht -> to_bootstrap [i ].ip_port , dht -> to_bootstrap [i ].public_key , dht -> self_public_key );
1850
+ dht_send_nodes_request (dht , & dht -> to_bootstrap [i ].ip_port , dht -> to_bootstrap [i ].public_key , dht -> self_public_key );
1851
1851
}
1852
1852
1853
1853
dht -> num_to_bootstrap = 0 ;
1854
1854
1855
1855
const uint8_t not_killed = do_ping_and_sendnode_requests (
1856
- dht , & dht -> close_lastgetnodes , dht -> self_public_key , dht -> close_clientlist , LCLIENT_LIST , & dht -> close_bootstrap_times ,
1856
+ dht , & dht -> close_last_nodes_request , dht -> self_public_key , dht -> close_clientlist , LCLIENT_LIST , & dht -> close_bootstrap_times ,
1857
1857
false);
1858
1858
1859
1859
if (not_killed != 0 ) {
@@ -1887,7 +1887,7 @@ bool dht_bootstrap(DHT *dht, const IP_Port *ip_port, const uint8_t *public_key)
1887
1887
return true;
1888
1888
}
1889
1889
1890
- return dht_getnodes (dht , ip_port , public_key , dht -> self_public_key );
1890
+ return dht_send_nodes_request (dht , ip_port , public_key , dht -> self_public_key );
1891
1891
}
1892
1892
1893
1893
bool dht_bootstrap_from_address (DHT * dht , const char * address , bool ipv6enabled , bool dns_enabled ,
@@ -2534,9 +2534,9 @@ static int cryptopacket_handle(void *object, const IP_Port *source, const uint8_
2534
2534
return 1 ;
2535
2535
}
2536
2536
2537
- void dht_callback_get_nodes_response (DHT * dht , dht_get_nodes_response_cb * function )
2537
+ void dht_callback_nodes_response (DHT * dht , dht_nodes_response_cb * function )
2538
2538
{
2539
- dht -> get_nodes_response = function ;
2539
+ dht -> nodes_response_callback = function ;
2540
2540
}
2541
2541
2542
2542
non_null (1 , 2 , 3 ) nullable (5 )
@@ -2597,8 +2597,8 @@ DHT *new_dht(const Logger *log, const Memory *mem, const Random *rng, const Netw
2597
2597
return nullptr ;
2598
2598
}
2599
2599
2600
- networking_registerhandler (dht -> net , NET_PACKET_GET_NODES , & handle_getnodes , dht );
2601
- networking_registerhandler (dht -> net , NET_PACKET_SEND_NODES_IPV6 , & handle_sendnodes_ipv6 , dht );
2600
+ networking_registerhandler (dht -> net , NET_PACKET_NODES_REQUEST , & handle_nodes_request , dht );
2601
+ networking_registerhandler (dht -> net , NET_PACKET_NODES_RESPONSE , & handle_nodes_response , dht );
2602
2602
networking_registerhandler (dht -> net , NET_PACKET_CRYPTO , & cryptopacket_handle , dht );
2603
2603
networking_registerhandler (dht -> net , NET_PACKET_LAN_DISCOVERY , & handle_lan_discovery , dht );
2604
2604
cryptopacket_registerhandler (dht , CRYPTO_PACKET_NAT_PING , & handle_nat_ping , dht );
@@ -2676,8 +2676,8 @@ void kill_dht(DHT *dht)
2676
2676
return ;
2677
2677
}
2678
2678
2679
- networking_registerhandler (dht -> net , NET_PACKET_GET_NODES , nullptr , nullptr );
2680
- networking_registerhandler (dht -> net , NET_PACKET_SEND_NODES_IPV6 , nullptr , nullptr );
2679
+ networking_registerhandler (dht -> net , NET_PACKET_NODES_REQUEST , nullptr , nullptr );
2680
+ networking_registerhandler (dht -> net , NET_PACKET_NODES_RESPONSE , nullptr , nullptr );
2681
2681
networking_registerhandler (dht -> net , NET_PACKET_CRYPTO , nullptr , nullptr );
2682
2682
networking_registerhandler (dht -> net , NET_PACKET_LAN_DISCOVERY , nullptr , nullptr );
2683
2683
cryptopacket_registerhandler (dht , CRYPTO_PACKET_NAT_PING , nullptr , nullptr );
0 commit comments