RPC addpeeraddress sets the source address equal to the destination address. If an address with the same /16 as an existing new entry is passed, it will be placed in the same new bucket and have a 1/64 chance of the bucket positions colliding (depending on the value of nKey i
(self)
| 236 | assert_raises_rpc_error(-8, "Network not recognized: Foo", self.nodes[0].getnodeaddresses, 1, "Foo") |
| 237 | |
| 238 | def test_addpeeraddress(self): |
| 239 | """RPC addpeeraddress sets the source address equal to the destination address. |
| 240 | If an address with the same /16 as an existing new entry is passed, it will be |
| 241 | placed in the same new bucket and have a 1/64 chance of the bucket positions |
| 242 | colliding (depending on the value of nKey in the addrman), in which case the |
| 243 | new address won't be added. The probability of collision can be reduced to |
| 244 | 1/2^16 = 1/65536 by using an address from a different /16. We avoid this here |
| 245 | by first testing adding a tried table entry before testing adding a new table one. |
| 246 | """ |
| 247 | self.log.info("Test addpeeraddress") |
| 248 | self.restart_node(1, ["-checkaddrman=1"]) |
| 249 | node = self.nodes[1] |
| 250 | |
| 251 | self.log.debug("Test that addpeerinfo is a hidden RPC") |
| 252 | # It is hidden from general help, but its detailed help may be called directly. |
| 253 | assert "addpeerinfo" not in node.help() |
| 254 | assert "addpeerinfo" in node.help("addpeerinfo") |
| 255 | |
| 256 | self.log.debug("Test that adding an empty address fails") |
| 257 | assert_equal(node.addpeeraddress(address="", port=8333), {"success": False}) |
| 258 | assert_equal(node.getnodeaddresses(count=0), []) |
| 259 | |
| 260 | self.log.debug("Test that adding a valid address to the tried table succeeds") |
| 261 | assert_equal(node.addpeeraddress(address="1.2.3.4", tried=True, port=8333), {"success": True}) |
| 262 | with node.assert_debug_log(expected_msgs=["CheckAddrman: new 0, tried 1, total 1 started"]): |
| 263 | addrs = node.getnodeaddresses(count=0) # getnodeaddresses re-runs the addrman checks |
| 264 | assert_equal(len(addrs), 1) |
| 265 | assert_equal(addrs[0]["address"], "1.2.3.4") |
| 266 | assert_equal(addrs[0]["port"], 8333) |
| 267 | |
| 268 | self.log.debug("Test that adding an already-present tried address to the new and tried tables fails") |
| 269 | for value in [True, False]: |
| 270 | assert_equal(node.addpeeraddress(address="1.2.3.4", tried=value, port=8333), {"success": False}) |
| 271 | assert_equal(len(node.getnodeaddresses(count=0)), 1) |
| 272 | |
| 273 | self.log.debug("Test that adding a second address, this time to the new table, succeeds") |
| 274 | assert_equal(node.addpeeraddress(address="2.0.0.0", port=8333), {"success": True}) |
| 275 | with node.assert_debug_log(expected_msgs=["CheckAddrman: new 1, tried 1, total 2 started"]): |
| 276 | addrs = node.getnodeaddresses(count=0) # getnodeaddresses re-runs the addrman checks |
| 277 | assert_equal(len(addrs), 2) |
| 278 | |
| 279 | |
| 280 | if __name__ == '__main__': |
no test coverage detected