(self)
| 244 | self.nodes[0].disconnect_p2ps() |
| 245 | |
| 246 | def getaddr_tests(self): |
| 247 | # In the previous tests, the node answered GETADDR requests with an |
| 248 | # empty addrman. Due to GETADDR response caching (see |
| 249 | # CConnman::GetAddresses), the node would continue to provide 0 addrs |
| 250 | # in response until enough time has passed or the node is restarted. |
| 251 | self.restart_node(0) |
| 252 | |
| 253 | self.log.info('Test getaddr behavior') |
| 254 | self.log.info('Check that we send a getaddr message upon connecting to an outbound-full-relay peer') |
| 255 | full_outbound_peer = self.nodes[0].add_outbound_p2p_connection(AddrReceiver(), p2p_idx=0, connection_type="outbound-full-relay") |
| 256 | full_outbound_peer.sync_with_ping() |
| 257 | assert full_outbound_peer.getaddr_received() |
| 258 | |
| 259 | self.log.info('Check that we do not send a getaddr message upon connecting to a block-relay-only peer') |
| 260 | block_relay_peer = self.nodes[0].add_outbound_p2p_connection(AddrReceiver(), p2p_idx=1, connection_type="block-relay-only") |
| 261 | block_relay_peer.sync_with_ping() |
| 262 | assert_equal(block_relay_peer.getaddr_received(), False) |
| 263 | |
| 264 | self.log.info('Check that we answer getaddr messages only from inbound peers') |
| 265 | inbound_peer = self.nodes[0].add_p2p_connection(AddrReceiver(send_getaddr=False)) |
| 266 | inbound_peer.sync_with_ping() |
| 267 | |
| 268 | # Add some addresses to addrman |
| 269 | for i in range(1000): |
| 270 | first_octet = i >> 8 |
| 271 | second_octet = i % 256 |
| 272 | a = f"{first_octet}.{second_octet}.1.1" |
| 273 | self.nodes[0].addpeeraddress(a, 8333) |
| 274 | |
| 275 | full_outbound_peer.send_and_ping(msg_getaddr()) |
| 276 | block_relay_peer.send_and_ping(msg_getaddr()) |
| 277 | inbound_peer.send_and_ping(msg_getaddr()) |
| 278 | |
| 279 | # invoke m_next_addr_send timer, see under send_addr_msg() function for rationale |
| 280 | self.mocktime += 10 * 60 |
| 281 | self.nodes[0].setmocktime(self.mocktime) |
| 282 | inbound_peer.wait_until(lambda: inbound_peer.addr_received() is True) |
| 283 | |
| 284 | assert_equal(full_outbound_peer.num_ipv4_received, 0) |
| 285 | assert_equal(block_relay_peer.num_ipv4_received, 0) |
| 286 | assert inbound_peer.num_ipv4_received > 100 |
| 287 | |
| 288 | self.nodes[0].disconnect_p2ps() |
| 289 | |
| 290 | def blocksonly_mode_tests(self): |
| 291 | self.log.info('Test addr relay in -blocksonly mode') |
no test coverage detected