mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
wireaddr: correct the onion case in wireaddr_from_hostname
And, this time, add tests !
This commit is contained in:
@@ -40,6 +40,7 @@ int main(void)
|
|||||||
setup_locale();
|
setup_locale();
|
||||||
|
|
||||||
struct wireaddr addr;
|
struct wireaddr addr;
|
||||||
|
struct wireaddr *addresses = tal_arr(NULL, struct wireaddr, 0);
|
||||||
char *ip;
|
char *ip;
|
||||||
u16 port;
|
u16 port;
|
||||||
|
|
||||||
@@ -115,6 +116,11 @@ int main(void)
|
|||||||
|
|
||||||
assert(parse_wireaddr("odpzvneidqdf5hdq.onion", &addr, 1, false, NULL));
|
assert(parse_wireaddr("odpzvneidqdf5hdq.onion", &addr, 1, false, NULL));
|
||||||
assert(addr.port == 1);
|
assert(addr.port == 1);
|
||||||
|
|
||||||
|
assert(wireaddr_from_hostname(&addresses, "odpzvneidqdf5hdq.onion", 1, NULL, NULL, NULL));
|
||||||
|
assert(! wireaddr_from_hostname(&addresses, "aaa.onion", 1, NULL, NULL, NULL));
|
||||||
|
tal_free(addresses);
|
||||||
|
|
||||||
tal_free(tmpctx);
|
tal_free(tmpctx);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -308,19 +308,21 @@ bool wireaddr_from_hostname(struct wireaddr **addrs, const char *hostname,
|
|||||||
if (strends(hostname, ".onion")) {
|
if (strends(hostname, ".onion")) {
|
||||||
u8 *dec = b32_decode(tmpctx, hostname,
|
u8 *dec = b32_decode(tmpctx, hostname,
|
||||||
strlen(hostname) - strlen(".onion"));
|
strlen(hostname) - strlen(".onion"));
|
||||||
|
if (tal_count(*addrs) == 0)
|
||||||
|
tal_resize(addrs, 1);
|
||||||
if (tal_count(dec) == TOR_V2_ADDRLEN)
|
if (tal_count(dec) == TOR_V2_ADDRLEN)
|
||||||
addrs[0]->type = ADDR_TYPE_TOR_V2;
|
(*addrs)[0].type = ADDR_TYPE_TOR_V2;
|
||||||
else if (tal_count(dec) == TOR_V3_ADDRLEN)
|
else if (tal_count(dec) == TOR_V3_ADDRLEN)
|
||||||
addrs[0]->type = ADDR_TYPE_TOR_V3;
|
(*addrs)[0].type = ADDR_TYPE_TOR_V3;
|
||||||
else {
|
else {
|
||||||
if (err_msg)
|
if (err_msg)
|
||||||
*err_msg = "Invalid Tor address";
|
*err_msg = "Invalid Tor address";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
addrs[0]->addrlen = tal_count(dec);
|
(*addrs)[0].addrlen = tal_count(dec);
|
||||||
addrs[0]->port = port;
|
(*addrs)[0].port = port;
|
||||||
memcpy(&addrs[0]->addr, dec, tal_count(dec));
|
memcpy((*addrs)[0].addr, dec, tal_count(dec));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user