(self)
| 132 | self.nodes[0].disconnect_p2ps() |
| 133 | |
| 134 | def relay_tests(self): |
| 135 | self.log.info('Test address relay') |
| 136 | self.log.info('Check that addr message content is relayed and added to addrman') |
| 137 | addr_source = self.nodes[0].add_p2p_connection(P2PInterface()) |
| 138 | num_receivers = 7 |
| 139 | receivers = [] |
| 140 | for _ in range(num_receivers): |
| 141 | receivers.append(self.nodes[0].add_p2p_connection(AddrReceiver(test_addr_contents=True))) |
| 142 | |
| 143 | # Keep this with length <= 10. Addresses from larger messages are not |
| 144 | # relayed. |
| 145 | num_ipv4_addrs = 10 |
| 146 | msg = self.setup_addr_msg(num_ipv4_addrs) |
| 147 | with self.nodes[0].assert_debug_log( |
| 148 | [ |
| 149 | 'received: addr (301 bytes) peer=1', |
| 150 | ] |
| 151 | ): |
| 152 | self.send_addr_msg(addr_source, msg, receivers) |
| 153 | |
| 154 | total_ipv4_received = sum(r.num_ipv4_received for r in receivers) |
| 155 | |
| 156 | # Every IPv4 address must be relayed to two peers, other than the |
| 157 | # originating node (addr_source). |
| 158 | ipv4_branching_factor = 2 |
| 159 | assert_equal(total_ipv4_received, num_ipv4_addrs * ipv4_branching_factor) |
| 160 | |
| 161 | self.nodes[0].disconnect_p2ps() |
| 162 | |
| 163 | self.log.info('Check relay of addresses received from outbound peers') |
| 164 | inbound_peer = self.nodes[0].add_p2p_connection(AddrReceiver(test_addr_contents=True, send_getaddr=False)) |
| 165 | full_outbound_peer = self.nodes[0].add_outbound_p2p_connection(AddrReceiver(), p2p_idx=0, connection_type="outbound-full-relay") |
| 166 | msg = self.setup_addr_msg(2) |
| 167 | self.send_addr_msg(full_outbound_peer, msg, [inbound_peer]) |
| 168 | self.log.info('Check that the first addr message received from an outbound peer is not relayed') |
| 169 | # Currently, there is a flag that prevents the first addr message received |
| 170 | # from a new outbound peer to be relayed to others. Originally meant to prevent |
| 171 | # large GETADDR responses from being relayed, it now typically affects the self-announcement |
| 172 | # of the outbound peer which is often sent before the GETADDR response. |
| 173 | assert_equal(inbound_peer.num_ipv4_received, 0) |
| 174 | |
| 175 | # Send an empty ADDR message to initialize address relay on this connection. |
| 176 | inbound_peer.send_and_ping(msg_addr()) |
| 177 | |
| 178 | self.log.info('Check that subsequent addr messages sent from an outbound peer are relayed') |
| 179 | msg2 = self.setup_addr_msg(2) |
| 180 | self.send_addr_msg(full_outbound_peer, msg2, [inbound_peer]) |
| 181 | assert_equal(inbound_peer.num_ipv4_received, 2) |
| 182 | |
| 183 | self.log.info('Check address relay to outbound peers') |
| 184 | block_relay_peer = self.nodes[0].add_outbound_p2p_connection(AddrReceiver(), p2p_idx=1, connection_type="block-relay-only") |
| 185 | msg3 = self.setup_addr_msg(2) |
| 186 | self.send_addr_msg(inbound_peer, msg3, [full_outbound_peer, block_relay_peer]) |
| 187 | |
| 188 | self.log.info('Check that addresses are relayed to full outbound peers') |
| 189 | assert_equal(full_outbound_peer.num_ipv4_received, 2) |
| 190 | self.log.info('Check that addresses are not relayed to block-relay-only outbound peers') |
| 191 | assert_equal(block_relay_peer.num_ipv4_received, 0) |
no test coverage detected