Skip to content

Commit

Permalink
chainparams: added backup dns seed
Browse files Browse the repository at this point in the history
net: updated to query all seeds
tests: updated net test to query all seeds
  • Loading branch information
edtubbs committed Jan 16, 2025
1 parent 77cf47f commit 5aa6405
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/chainparams.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const dogecoin_chainparams dogecoin_chainparams_main = {
{0x91, 0x56, 0x35, 0x2c, 0x18, 0x18, 0xb3, 0x2e, 0x90, 0xc9, 0xe7, 0x92, 0xef, 0xd6, 0xa1, 0x1a, 0x82, 0xfe, 0x79, 0x56, 0xa6, 0x30, 0xf0, 0x3b, 0xbe, 0xe2, 0x36, 0xce, 0xda, 0xe3, 0x91, 0x1a},
{0x10, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
22556,
{{"seed.multidoge.org"}, {{1}}},
{{"seed.multidoge.org"}, {{"seed2.multidoge.org"}}},
true,
0x0062,
{0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, // pow limit
Expand Down
38 changes: 23 additions & 15 deletions src/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -833,21 +833,29 @@ dogecoin_bool dogecoin_node_group_add_peers_by_ip_or_seed(dogecoin_node_group *g
if (ips == NULL) {
/* === DNS QUERY === */
vector* ips_dns = vector_new(10, free);
const dogecoin_dns_seed seed = group->chainparams->dnsseeds[0];
if (strlen(seed.domain) == 0) {
return false;
}
/* todo: make sure we have enough peers, eventually */
dogecoin_get_peers_from_dns(seed.domain, ips_dns, group->chainparams->default_port, AF_INET);
unsigned int i;
for (i = 0; i < ips_dns->len; i++) {
char* ip = (char*)vector_idx(ips_dns, i);

/* create a node */
dogecoin_node* node = dogecoin_node_new();
if (dogecoin_node_set_ipport(node, ip) > 0) {
/* add the node to the group */
dogecoin_node_group_add_node(group, node);
unsigned int seed_index;
/* dogecoin_chainparams has up to 8 dns seeds */
for (seed_index = 0; seed_index < 8; seed_index++) {
const dogecoin_dns_seed seed = group->chainparams->dnsseeds[seed_index];
if (strlen(seed.domain) == 0) {
continue;
}
/* todo: make sure we have enough peers, eventually */
dogecoin_get_peers_from_dns(seed.domain, ips_dns, group->chainparams->default_port, AF_INET);
unsigned int i;
for (i = 0; i < ips_dns->len; i++) {
char* ip = (char*)vector_idx(ips_dns, i);

/* create a node */
dogecoin_node* node = dogecoin_node_new();
if (dogecoin_node_set_ipport(node, ip) > 0) {
/* add the node to the group */
dogecoin_node_group_add_node(group, node);
}
}
/* exit if we get peers from a seed */
if (ips_dns->len > 0) {
break;
}
}
vector_free(ips_dns, true);
Expand Down
23 changes: 16 additions & 7 deletions test/net_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,22 @@ void test_net_basics_plus_download_block()
{

vector *ips = vector_new(10, free);
const dogecoin_dns_seed seed = dogecoin_chainparams_test.dnsseeds[0];

dogecoin_get_peers_from_dns(seed.domain, ips, dogecoin_chainparams_test.default_port, AF_INET);
unsigned int i;
for (i = 0; i < ips->len; i++)
{
debug_print("dns seed ip %d: %s\n", i, (char *)vector_idx(ips, i));
unsigned int seed_index;
/* dogecoin_chainparams has up to 8 dns seeds */
for (seed_index = 0; seed_index < 8; seed_index++) {
const dogecoin_dns_seed seed = dogecoin_chainparams_test.dnsseeds[seed_index];
if (strlen(seed.domain) == 0) {
continue;
}
dogecoin_get_peers_from_dns(seed.domain, ips, dogecoin_chainparams_test.default_port, AF_INET);
unsigned int i;
for (i = 0; i < ips->len; i++) {
debug_print("dns seed ip %d: %s\n", i, (char *)vector_idx(ips, i));
}
/* exit if we get peers from a seed */
if (ips->len > 0) {
break;
}
}
vector_free(ips, true);

Expand Down

0 comments on commit 5aa6405

Please sign in to comment.