diff --git a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 index ff7d80ab..750f59c1 100644 --- a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 +++ b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 @@ -1 +1 @@ -8a21d15ab133d9cb6dea68a536ed1f3d9e7a5ae81c8ea55e315d3a111c857476 /usr/local/bin/tox-bootstrapd +ea227a21dcaed2f54d61bd9175c6deb02480ebd894ebd589061556a1708c0c9f /usr/local/bin/tox-bootstrapd diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 49582e9e..fd7ca57e 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c @@ -1035,7 +1035,7 @@ void set_announce_node(DHT *dht, const uint8_t *public_key) index = LCLIENT_LENGTH - 1; } - set_announce_node_in_list(dht->close_clientlist + index * LCLIENT_NODES, LCLIENT_LENGTH, public_key); + set_announce_node_in_list(dht->close_clientlist + index * LCLIENT_NODES, LCLIENT_NODES, public_key); for (int32_t i = 0; i < dht->num_friends; ++i) { set_announce_node_in_list(dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS, public_key); diff --git a/toxcore/DHT_test.cc b/toxcore/DHT_test.cc index 35efc652..3014c0b2 100644 --- a/toxcore/DHT_test.cc +++ b/toxcore/DHT_test.cc @@ -185,4 +185,47 @@ TEST(Request, CreateAndParse) } } +TEST(AnnounceNodes, SetAndTest) +{ + Logger *log = logger_new(); + Mono_Time *mono_time = mono_time_new(nullptr, nullptr); + const Random *rng = system_random(); + const Network *ns = system_network(); + Networking_Core *net = new_networking_no_udp(log, ns); + DHT *dht = new_dht(log, rng, ns, mono_time, net, true, true); + ASSERT_NE(dht, nullptr); + + uint8_t pk_data[CRYPTO_PUBLIC_KEY_SIZE]; + memcpy(pk_data, dht_get_self_public_key(dht), sizeof(pk_data)); + PublicKey self_pk = to_array(pk_data); + + PublicKey pk1 = random_pk(rng); + ASSERT_NE(pk1, self_pk); + + // Test with maximally close key to self + pk_data[CRYPTO_PUBLIC_KEY_SIZE - 1] = ~pk_data[CRYPTO_PUBLIC_KEY_SIZE - 1]; + PublicKey pk2 = to_array(pk_data); + ASSERT_NE(pk2, pk1); + + IP_Port ip_port = {0}; + ip_port.ip.family = net_family_ipv4(); + + set_announce_node(dht, pk1.data()); + set_announce_node(dht, pk2.data()); + + EXPECT_TRUE(addto_lists(dht, &ip_port, pk1.data())); + EXPECT_TRUE(addto_lists(dht, &ip_port, pk2.data())); + + Node_format nodes[MAX_SENT_NODES]; + EXPECT_EQ(0, get_close_nodes(dht, self_pk.data(), nodes, net_family_unspec(), true, true)); + set_announce_node(dht, pk1.data()); + set_announce_node(dht, pk2.data()); + EXPECT_EQ(2, get_close_nodes(dht, self_pk.data(), nodes, net_family_unspec(), true, true)); + + kill_dht(dht); + kill_networking(net); + mono_time_free(mono_time); + logger_kill(log); +} + } // namespace