def relay_tests(self):
    self.log.info('Test address relay')
    self.log.info('Check that addr message content is relayed and added to addrman')
    addr_source = self.nodes[0].add_p2p_connection(P2PInterface())
    num_receivers = 7
    receivers = []
    for _ in range(num_receivers):
        receivers.append(self.nodes[0].add_p2p_connection(AddrReceiver()))
    num_ipv4_addrs = 10
    msg = self.setup_addr_msg(num_ipv4_addrs)
    with self.nodes[0].assert_debug_log(['Added {} addresses from 127.0.0.1: 0 tried'.format(num_ipv4_addrs), 'received: addr (301 bytes) peer=1']):
        self.send_addr_msg(addr_source, msg, receivers)
    total_ipv4_received = sum((r.num_ipv4_received for r in receivers))
    ipv4_branching_factor = 2
    assert_equal(total_ipv4_received, (num_ipv4_addrs * ipv4_branching_factor))
    self.nodes[0].disconnect_p2ps()
    self.log.info('Check relay of addresses received from outbound peers')
    inbound_peer = self.nodes[0].add_p2p_connection(AddrReceiver())
    full_outbound_peer = self.nodes[0].add_outbound_p2p_connection(GetAddrStore(), p2p_idx=0, connection_type='outbound-full-relay')
    msg = self.setup_addr_msg(2)
    self.send_addr_msg(full_outbound_peer, msg, [inbound_peer])
    self.log.info('Check that the first addr message received from an outbound peer is not relayed')
    assert_equal(inbound_peer.num_ipv4_received, 0)
    self.log.info('Check that subsequent addr messages sent from an outbound peer are relayed')
    msg2 = self.setup_addr_msg(2)
    self.send_addr_msg(full_outbound_peer, msg2, [inbound_peer])
    assert_equal(inbound_peer.num_ipv4_received, 2)
    self.log.info('Check address relay to outbound peers')
    block_relay_peer = self.nodes[0].add_outbound_p2p_connection(GetAddrStore(), p2p_idx=1, connection_type='block-relay-only')
    msg3 = self.setup_addr_msg(2)
    self.send_addr_msg(inbound_peer, msg3, [full_outbound_peer, block_relay_peer])
    self.log.info('Check that addresses are relayed to full outbound peers')
    assert_equal(full_outbound_peer.num_ipv4_received, 2)
    self.log.info('Check that addresses are not relayed to block-relay-only outbound peers')
    assert_equal(block_relay_peer.num_ipv4_received, 0)
    self.nodes[0].disconnect_p2ps()
def relay_tests(self):
    self.log.info('Test address relay')
    self.log.info('Check that addr message content is relayed and added to addrman')
    addr_source = self.nodes[0].add_p2p_connection(P2PInterface())
    num_receivers = 7
    receivers = []
    for _ in range(num_receivers):
        receivers.append(self.nodes[0].add_p2p_connection(AddrReceiver()))
    num_ipv4_addrs = 10
    msg = self.setup_addr_msg(num_ipv4_addrs)
    with self.nodes[0].assert_debug_log(['Added {} addresses from 127.0.0.1: 0 tried'.format(num_ipv4_addrs), 'received: addr (301 bytes) peer=1']):
        self.send_addr_msg(addr_source, msg, receivers)
    total_ipv4_received = sum((r.num_ipv4_received for r in receivers))
    ipv4_branching_factor = 2
    assert_equal(total_ipv4_received, (num_ipv4_addrs * ipv4_branching_factor))
    self.nodes[0].disconnect_p2ps()
    self.log.info('Check relay of addresses received from outbound peers')
    inbound_peer = self.nodes[0].add_p2p_connection(AddrReceiver())
    full_outbound_peer = self.nodes[0].add_outbound_p2p_connection(GetAddrStore(), p2p_idx=0, connection_type='outbound-full-relay')
    msg = self.setup_addr_msg(2)
    self.send_addr_msg(full_outbound_peer, msg, [inbound_peer])
    self.log.info('Check that the first addr message received from an outbound peer is not relayed')
    assert_equal(inbound_peer.num_ipv4_received, 0)
    self.log.info('Check that subsequent addr messages sent from an outbound peer are relayed')
    msg2 = self.setup_addr_msg(2)
    self.send_addr_msg(full_outbound_peer, msg2, [inbound_peer])
    assert_equal(inbound_peer.num_ipv4_received, 2)
    self.log.info('Check address relay to outbound peers')
    block_relay_peer = self.nodes[0].add_outbound_p2p_connection(GetAddrStore(), p2p_idx=1, connection_type='block-relay-only')
    msg3 = self.setup_addr_msg(2)
    self.send_addr_msg(inbound_peer, msg3, [full_outbound_peer, block_relay_peer])
    self.log.info('Check that addresses are relayed to full outbound peers')
    assert_equal(full_outbound_peer.num_ipv4_received, 2)
    self.log.info('Check that addresses are not relayed to block-relay-only outbound peers')
    assert_equal(block_relay_peer.num_ipv4_received, 0)
    self.nodes[0].disconnect_p2ps()