Wladimir J. van der Laan
d9935222d5
Merge #19951: net, test: CNetAddr scoped ipv6 test coverage, rename scopeId to m_scope_id
f36887fa47b42af60f8a06a3995baca7c73ca310 net: rename CNetAddr scopeId to m_scope_id, improve code doc (Jon Atack)
5cb5fd3005435f3a7ca0c3401951d1db8db4fb88 test: add test coverage for CNetAddr ipv6 scoped addresses (Jon Atack)
Pull request description:
Add some test coverage for the IPv6 scoped address feature in `netaddress`/`netbase` per https://tools.ietf.org/html/rfc4007, update the member name `scopeId` to `m_scope_id` per `doc/developer-notes.md`, and improve the code doc.
----
Reviewers can manually verify the test with these steps:
- [pull down the changes locally and check out this branch](https://jonatack.github.io/articles/how-to-review-pull-requests-in-bitcoin-core#pull-down-the-code-locally)
- [build Bitcoin Core](https://jonatack.github.io/articles/how-to-compile-bitcoin-core-and-run-the-tests)
- run the test: `cd src ; test/test_bitcoin -t net_tests/cnetaddr_basic -l all`
<details><summary><em>you should see passing test output like this</em></summary><p>
```
Running 1 test case...
Entering test module "Bitcoin Core Test Suite"
test/net_tests.cpp(85): Entering test suite "net_tests"
test/net_tests.cpp(204): Entering test case "cnetaddr_basic"
test/net_tests.cpp(210): info: check LookupHost("0.0.0.0", addr, false) has passed
test/net_tests.cpp(211): info: check !addr.IsValid() has passed
test/net_tests.cpp(212): info: check addr.IsIPv4() has passed
test/net_tests.cpp(214): info: check addr.IsBindAny() has passed
test/net_tests.cpp(215): info: check addr.ToString() == "0.0.0.0" has passed
test/net_tests.cpp(218): info: check LookupHost("255.255.255.255", addr, false) has passed
test/net_tests.cpp(219): info: check !addr.IsValid() has passed
test/net_tests.cpp(220): info: check addr.IsIPv4() has passed
test/net_tests.cpp(222): info: check !addr.IsBindAny() has passed
test/net_tests.cpp(223): info: check addr.ToString() == "255.255.255.255" has passed
test/net_tests.cpp(226): info: check LookupHost("12.34.56.78", addr, false) has passed
test/net_tests.cpp(227): info: check addr.IsValid() has passed
test/net_tests.cpp(228): info: check addr.IsIPv4() has passed
test/net_tests.cpp(230): info: check !addr.IsBindAny() has passed
test/net_tests.cpp(231): info: check addr.ToString() == "12.34.56.78" has passed
test/net_tests.cpp(234): info: check LookupHost("::", addr, false) has passed
test/net_tests.cpp(235): info: check !addr.IsValid() has passed
test/net_tests.cpp(236): info: check addr.IsIPv6() has passed
test/net_tests.cpp(238): info: check addr.IsBindAny() has passed
test/net_tests.cpp(239): info: check addr.ToString() == "::" has passed
test/net_tests.cpp(242): info: check LookupHost(ipv6_addr, addr, false) has passed
test/net_tests.cpp(243): info: check addr.IsValid() has passed
test/net_tests.cpp(244): info: check addr.IsIPv6() has passed
test/net_tests.cpp(246): info: check !addr.IsBindAny() has passed
test/net_tests.cpp(247): info: check addr.ToString() == ipv6_addr has passed
test/net_tests.cpp(254): info: check LookupHost(scoped_addr, addr, false) has passed
test/net_tests.cpp(255): info: check addr.IsValid() has passed
test/net_tests.cpp(256): info: check addr.IsIPv6() has passed
test/net_tests.cpp(257): info: check !addr.IsBindAny() has passed
test/net_tests.cpp(258): info: check addr.ToString() == scoped_addr has passed
test/net_tests.cpp(254): info: check LookupHost(scoped_addr, addr, false) has passed
test/net_tests.cpp(255): info: check addr.IsValid() has passed
test/net_tests.cpp(256): info: check addr.IsIPv6() has passed
test/net_tests.cpp(257): info: check !addr.IsBindAny() has passed
test/net_tests.cpp(258): info: check addr.ToString() == scoped_addr has passed
test/net_tests.cpp(254): info: check LookupHost(scoped_addr, addr, false) has passed
test/net_tests.cpp(255): info: check addr.IsValid() has passed
test/net_tests.cpp(256): info: check addr.IsIPv6() has passed
test/net_tests.cpp(257): info: check !addr.IsBindAny() has passed
test/net_tests.cpp(258): info: check addr.ToString() == scoped_addr has passed
test/net_tests.cpp(254): info: check LookupHost(scoped_addr, addr, false) has passed
test/net_tests.cpp(255): info: check addr.IsValid() has passed
test/net_tests.cpp(256): info: check addr.IsIPv6() has passed
test/net_tests.cpp(257): info: check !addr.IsBindAny() has passed
test/net_tests.cpp(258): info: check addr.ToString() == scoped_addr has passed
test/net_tests.cpp(263): info: check !LookupHost(ipv6_addr + "%" + zone_id, addr, false) has passed
test/net_tests.cpp(263): info: check !LookupHost(ipv6_addr + "%" + zone_id, addr, false) has passed
test/net_tests.cpp(263): info: check !LookupHost(ipv6_addr + "%" + zone_id, addr, false) has passed
test/net_tests.cpp(266): info: check LookupHost(ipv6_addr + "%0", addr, false) has passed
test/net_tests.cpp(267): info: check addr.IsValid() has passed
test/net_tests.cpp(268): info: check addr.IsIPv6() has passed
test/net_tests.cpp(269): info: check !addr.IsBindAny() has passed
test/net_tests.cpp(270): info: check addr.ToString() == ipv6_addr has passed
test/net_tests.cpp(274): info: check addr.IsValid() has passed
test/net_tests.cpp(275): info: check addr.IsTor() has passed
test/net_tests.cpp(277): info: check !addr.IsBindAny() has passed
test/net_tests.cpp(278): info: check addr.ToString() == "6hzph5hv6337r6p2.onion" has passed
test/net_tests.cpp(282): info: check !addr.IsValid() has passed
test/net_tests.cpp(283): info: check addr.IsInternal() has passed
test/net_tests.cpp(285): info: check !addr.IsBindAny() has passed
test/net_tests.cpp(286): info: check addr.ToString() == "esffpvrt3wpeaygy.internal" has passed
test/net_tests.cpp(204): Leaving test case "cnetaddr_basic"; testing time: 30933us
test/net_tests.cpp(85): Leaving test suite "net_tests"; testing time: 30975us
Leaving test module "Bitcoin Core Test Suite"; testing time: 31169us
*** No errors detected
```
</p>/</details>
- change this line in the code to break the feature:
```diff
--- a/src/netaddress.cpp
+++ b/src/netaddress.cpp
@@ -716,7 +716,7 @@ bool CService::GetSockAddr(struct sockaddr* paddr, socklen_t *addrlen) const
memset(paddrin6, 0, *addrlen);
if (!GetIn6Addr(&paddrin6->sin6_addr))
return false;
- paddrin6->sin6_scope_id = m_scope_id;
+ // paddrin6->sin6_scope_id = m_scope_id;
```
- rebuild, e.g. `make`
- run the test: `test/test_bitcoin -t net_tests/cnetaddr_basic -l all`, verify that the added tests break
<details><summary><em>you should see test output with a few failed tests like this</em></summary><p>
```
Running 1 test case...
Entering test module "Bitcoin Core Test Suite"
test/net_tests.cpp(85): Entering test suite "net_tests"
test/net_tests.cpp(204): Entering test case "cnetaddr_basic"
test/net_tests.cpp(210): info: check LookupHost("0.0.0.0", addr, false) has passed
test/net_tests.cpp(211): info: check !addr.IsValid() has passed
test/net_tests.cpp(212): info: check addr.IsIPv4() has passed
test/net_tests.cpp(214): info: check addr.IsBindAny() has passed
test/net_tests.cpp(215): info: check addr.ToString() == "0.0.0.0" has passed
test/net_tests.cpp(218): info: check LookupHost("255.255.255.255", addr, false) has passed
test/net_tests.cpp(219): info: check !addr.IsValid() has passed
test/net_tests.cpp(220): info: check addr.IsIPv4() has passed
test/net_tests.cpp(222): info: check !addr.IsBindAny() has passed
test/net_tests.cpp(223): info: check addr.ToString() == "255.255.255.255" has passed
test/net_tests.cpp(226): info: check LookupHost("12.34.56.78", addr, false) has passed
test/net_tests.cpp(227): info: check addr.IsValid() has passed
test/net_tests.cpp(228): info: check addr.IsIPv4() has passed
test/net_tests.cpp(230): info: check !addr.IsBindAny() has passed
test/net_tests.cpp(231): info: check addr.ToString() == "12.34.56.78" has passed
test/net_tests.cpp(234): info: check LookupHost("::", addr, false) has passed
test/net_tests.cpp(235): info: check !addr.IsValid() has passed
test/net_tests.cpp(236): info: check addr.IsIPv6() has passed
test/net_tests.cpp(238): info: check addr.IsBindAny() has passed
test/net_tests.cpp(239): info: check addr.ToString() == "::" has passed
test/net_tests.cpp(242): info: check LookupHost(ipv6_addr, addr, false) has passed
test/net_tests.cpp(243): info: check addr.IsValid() has passed
test/net_tests.cpp(244): info: check addr.IsIPv6() has passed
test/net_tests.cpp(246): info: check !addr.IsBindAny() has passed
test/net_tests.cpp(247): info: check addr.ToString() == ipv6_addr has passed
test/net_tests.cpp(254): info: check LookupHost(scoped_addr, addr, false) has passed
test/net_tests.cpp(255): info: check addr.IsValid() has passed
test/net_tests.cpp(256): info: check addr.IsIPv6() has passed
test/net_tests.cpp(257): info: check !addr.IsBindAny() has passed
test/net_tests.cpp(258): error: in "net_tests/cnetaddr_basic": check addr.ToString() == scoped_addr has failed [1122:3344:5566:7788:9900:aabb:ccdd:eeff != 1122:3344:5566:7788:9900:aabb:ccdd:eeff%1]
test/net_tests.cpp(254): info: check LookupHost(scoped_addr, addr, false) has passed
test/net_tests.cpp(255): info: check addr.IsValid() has passed
test/net_tests.cpp(256): info: check addr.IsIPv6() has passed
test/net_tests.cpp(257): info: check !addr.IsBindAny() has passed
test/net_tests.cpp(258): error: in "net_tests/cnetaddr_basic": check addr.ToString() == scoped_addr has failed [1122:3344:5566:7788:9900:aabb:ccdd:eeff != 1122:3344:5566:7788:9900:aabb:ccdd:eeff%21]
test/net_tests.cpp(254): info: check LookupHost(scoped_addr, addr, false) has passed
test/net_tests.cpp(255): info: check addr.IsValid() has passed
test/net_tests.cpp(256): info: check addr.IsIPv6() has passed
test/net_tests.cpp(257): info: check !addr.IsBindAny() has passed
test/net_tests.cpp(258): error: in "net_tests/cnetaddr_basic": check addr.ToString() == scoped_addr has failed [1122:3344:5566:7788:9900:aabb:ccdd:eeff != 1122:3344:5566:7788:9900:aabb:ccdd:eeff%19]
test/net_tests.cpp(254): info: check LookupHost(scoped_addr, addr, false) has passed
test/net_tests.cpp(255): info: check addr.IsValid() has passed
test/net_tests.cpp(256): info: check addr.IsIPv6() has passed
test/net_tests.cpp(257): info: check !addr.IsBindAny() has passed
test/net_tests.cpp(258): error: in "net_tests/cnetaddr_basic": check addr.ToString() == scoped_addr has failed [1122:3344:5566:7788:9900:aabb:ccdd:eeff != 1122:3344:5566:7788:9900:aabb:ccdd:eeff%3]
test/net_tests.cpp(263): info: check !LookupHost(ipv6_addr + "%" + zone_id, addr, false) has passed
test/net_tests.cpp(263): info: check !LookupHost(ipv6_addr + "%" + zone_id, addr, false) has passed
test/net_tests.cpp(263): info: check !LookupHost(ipv6_addr + "%" + zone_id, addr, false) has passed
test/net_tests.cpp(266): info: check LookupHost(ipv6_addr + "%0", addr, false) has passed
test/net_tests.cpp(267): info: check addr.IsValid() has passed
test/net_tests.cpp(268): info: check addr.IsIPv6() has passed
test/net_tests.cpp(269): info: check !addr.IsBindAny() has passed
test/net_tests.cpp(270): info: check addr.ToString() == ipv6_addr has passed
test/net_tests.cpp(274): info: check addr.IsValid() has passed
test/net_tests.cpp(275): info: check addr.IsTor() has passed
test/net_tests.cpp(277): info: check !addr.IsBindAny() has passed
test/net_tests.cpp(278): info: check addr.ToString() == "6hzph5hv6337r6p2.onion" has passed
test/net_tests.cpp(282): info: check !addr.IsValid() has passed
test/net_tests.cpp(283): info: check addr.IsInternal() has passed
test/net_tests.cpp(285): info: check !addr.IsBindAny() has passed
test/net_tests.cpp(286): info: check addr.ToString() == "esffpvrt3wpeaygy.internal" has passed
test/net_tests.cpp(204): Leaving test case "cnetaddr_basic"; testing time: 32316us
test/net_tests.cpp(85): Leaving test suite "net_tests"; testing time: 32354us
Leaving test module "Bitcoin Core Test Suite"; testing time: 32522us
*** 4 failures are detected in the test module "Bitcoin Core Test Suite"
```
</p></details>
- leave your review here
ACKs for top commit:
laanwj:
ACK f36887fa47b42af60f8a06a3995baca7c73ca310
Tree-SHA512: 8e77e512db130642be7d3a910735ca803a2afdb5a704f713f163f8b5a80be3077a2be6f0a3ca43d299731dcd2545ac35571f8c74e5250a72a48233c26f9a3ab5
2020-10-02 17:06:59 +02:00
..
2020-09-29 10:20:05 +02:00
2020-05-20 08:27:07 -04:00
2020-09-10 10:47:40 +09:00
2020-01-28 17:00:01 +01:00
2020-09-28 12:27:08 -07:00
2020-08-21 12:48:46 +08:00
2020-09-26 17:57:26 -07:00
2020-01-28 16:59:07 +01:00
2020-04-30 18:02:04 +08:00
2020-09-16 06:30:57 +08:00
2020-09-14 16:23:23 +02:00
2020-09-17 22:17:17 +02:00
2020-10-01 22:24:08 +02:00
2020-09-30 09:01:23 +02:00
2020-09-30 14:21:42 +02:00
2020-09-11 12:44:08 -07:00
2020-08-20 17:55:06 +00:00
2020-10-02 16:40:15 +02:00
2020-02-09 07:44:29 -08:00
2020-09-28 12:27:08 -07:00
2020-09-30 09:28:33 +02:00
2020-10-01 00:33:38 +02:00
2020-07-06 03:52:37 +02:00
2020-06-22 12:12:22 +02:00
2020-07-03 20:43:55 -07:00
2020-08-12 09:22:07 +01:00
2020-08-12 09:22:07 +01:00
2019-12-30 10:42:20 +13:00
2019-12-30 10:42:20 +13:00
2020-07-08 21:44:45 +08:00
2020-07-03 20:43:55 -07:00
2020-08-28 16:50:57 +02:00
2020-08-28 16:50:57 +02:00
2020-10-01 17:33:56 +02:00
2020-09-22 22:32:25 +02:00
2020-09-22 22:32:25 +02:00
2020-09-22 22:32:25 +02:00
2020-05-28 09:55:39 +03:00
2020-05-28 09:55:39 +03:00
2020-07-30 13:57:54 -07:00
2020-05-26 17:27:15 -04:00
2020-06-21 06:41:55 -04:00
2020-05-20 07:30:29 -04:00
2019-12-30 10:42:20 +13:00
2020-08-27 20:07:27 -04:00
2020-10-01 11:25:42 +02:00
2020-09-29 10:20:05 +02:00
2020-09-29 09:59:51 +03:00
2020-09-29 09:59:52 +03:00
2020-04-03 16:29:26 +02:00
2020-04-16 13:33:09 -04:00
2020-05-04 19:53:58 +03:00
2020-07-01 14:44:28 -04:00
2020-07-01 14:44:28 -04:00
2020-08-20 17:55:06 +00:00
2019-12-30 10:42:20 +13:00
2020-04-16 13:33:09 -04:00
2019-12-30 10:42:20 +13:00
2020-05-22 01:40:31 +09:00
2020-09-04 10:25:44 +01:00
2020-04-08 14:45:27 +00:00
2019-12-30 10:42:20 +13:00
2020-07-08 14:26:14 +03:00
2020-09-01 09:26:28 +08:00
2020-05-20 07:30:29 -04:00
2020-06-16 15:15:46 -04:00
2019-12-30 10:42:20 +13:00
2020-08-06 16:28:26 -07:00
2020-08-06 16:28:26 -07:00
2020-05-21 06:53:39 -04:00
2020-05-13 16:20:13 -04:00
2020-06-27 11:49:28 -04:00
2020-04-16 13:33:09 -04:00
2020-04-16 13:33:09 -04:00
2020-10-02 13:37:23 +02:00
2020-08-27 14:33:00 -04:00
2019-12-30 10:42:20 +13:00
2020-08-18 18:03:57 +00:00
2019-12-30 10:42:20 +13:00
2020-06-07 17:03:49 +02:00
2020-05-28 09:54:24 +03:00
2020-09-21 22:33:00 +02:00
2020-09-14 16:35:09 +08:00
2020-01-28 17:01:48 +01:00
2020-05-12 18:03:39 +03:00
2020-10-01 22:24:08 +02:00
2020-09-14 16:35:09 +08:00
2020-09-14 16:35:09 +08:00
2020-04-05 01:01:13 +02:00
2020-04-05 10:46:24 +08:00
2020-09-21 22:33:00 +02:00
2020-04-16 13:33:09 -04:00
2020-07-30 13:57:54 -07:00
2020-03-30 16:09:51 -07:00
2020-06-15 08:08:19 -04:00
2020-09-04 09:46:44 -07:00
2020-07-30 14:38:50 +03:00
2020-07-30 14:38:50 +03:00
2020-10-02 16:42:38 +02:00
2020-09-30 15:53:25 +02:00
2020-10-02 13:37:23 +02:00
2020-10-02 13:37:23 +02:00
2020-10-02 16:42:02 +02:00
2020-10-02 16:42:02 +02:00
2020-08-24 21:50:59 +02:00
2020-01-08 12:35:59 +00:00
2020-05-11 00:20:57 +02:00
2020-06-27 11:49:28 -04:00
2020-05-05 04:45:59 +03:00
2019-12-30 10:42:20 +13:00
2020-07-01 18:03:12 -04:00
2020-07-01 18:02:38 -04:00
2020-04-30 18:02:03 +08:00
2020-09-22 22:05:18 -04:00
2020-09-22 22:05:18 -04:00
2020-06-24 16:32:19 -04:00
2020-06-24 16:32:19 -04:00
2020-08-18 18:03:56 +00:00
2020-07-30 13:57:54 -07:00
2020-08-10 21:30:42 +08:00
2020-04-30 09:19:14 -04:00
2020-04-16 13:33:09 -04:00
2020-09-22 17:08:08 +02:00
2020-06-21 06:02:59 -04:00
2020-06-21 06:02:59 -04:00
2020-06-22 12:12:22 +02:00
2020-09-22 22:31:31 +02:00
2020-09-22 22:31:31 +02:00
2020-07-30 13:57:09 -07:00
2020-07-26 22:46:28 +03:00
2020-08-29 20:46:47 +03:00
2020-09-19 18:02:42 +03:00
2019-12-30 10:42:20 +13:00
2020-08-18 10:46:53 +03:00
2020-06-27 11:49:28 -04:00
2020-10-01 19:00:07 +03:00
2020-10-01 19:00:07 +03:00
2020-07-29 07:53:19 +02:00
2020-07-01 14:44:24 -04:00
2020-09-22 11:34:30 -04:00
2020-09-22 11:34:30 -04:00
2020-09-28 12:14:19 +10:00
2020-09-28 12:14:19 +10:00
2020-04-16 13:33:09 -04:00
2020-09-29 20:41:11 +08:00
2020-09-23 20:35:54 +02:00
2020-09-22 11:34:30 -04:00
2020-09-22 11:34:30 -04:00
2020-09-17 22:17:17 +02:00
2019-12-30 10:42:20 +13:00
2019-12-30 10:42:20 +13:00
2019-12-30 10:42:20 +13:00
2020-07-29 16:36:44 +07:00
2020-06-10 15:01:20 +03:00
2020-06-10 15:01:20 +03:00