message: test: make sure non-IP peers get discouraged and disconnected
diff: @@ -214,12 +214,18 @@ BOOST_AUTO_TEST_CASE(peer_discouragement)
  auto peerLogic = PeerManager::make(chainparams, *connman, *m_node.addrman, banman.get(),
  *m_node.scheduler, *m_node.chainman, *m_node.mempool, false);
  - const std::array<CAddress, 2> addr{CAddress{ip(0xa0b0c001), NODE_NONE},
  - CAddress{ip(0xa0b0c002), NODE_NONE}};
  + CNetAddr tor_netaddr;
  + BOOST_REQUIRE(
  + tor_netaddr.SetSpecial("pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion"));
  + const CService tor_service{tor_netaddr, Params().GetDefaultPort()};
  +
  + const std::array<CAddress, 3> addr{CAddress{ip(0xa0b0c001), NODE_NONE},
  + CAddress{ip(0xa0b0c002), NODE_NONE},
  + CAddress{tor_service, NODE_NONE}};
  const CNetAddr other_addr{ip(0xa0b0ff01)}; // Not any of addr[].
  - std::array<CNode*, 2> nodes;
  + std::array<CNode*, 3> nodes;
  banman->ClearBanned();
  nodes[0] = new CNode{id++, NODE_NETWORK, INVALID_SOCKET, addr[0], /* nKeyedNetGroupIn */ 0,
  @@ -267,6 +273,27 @@ BOOST_AUTO_TEST_CASE(peer_discouragement)
  BOOST_CHECK(banman->IsDiscouraged(addr[1]));
  BOOST_CHECK(nodes[1]->fDisconnect);
  + // Make sure non-IP peers are discouraged and disconnected properly.
  +
  + nodes[2] = new CNode{id++, NODE_NETWORK, INVALID_SOCKET, addr[2], /* nKeyedNetGroupIn */ 1,
  + /* nLocalHostNonceIn */ 1, CAddress(), /* pszDest */ "",
  + ConnectionType::OUTBOUND_FULL_RELAY, /* inbound_onion */ false};
  + nodes[2]->SetCommonVersion(PROTOCOL_VERSION);
  + peerLogic->InitializeNode(nodes[2]);
  + nodes[2]->fSuccessfullyConnected = true;
  + connman->AddNode(*nodes[2]);
  + peerLogic->Misbehaving(nodes[2]->GetId(), DISCOURAGEMENT_THRESHOLD, /* message */ "");
  + {
  + LOCK(nodes[2]->cs_sendProcessing);
  + BOOST_CHECK(peerLogic->SendMessages(nodes[2]));
  + }
  + BOOST_CHECK(banman->IsDiscouraged(addr[0]));
  + BOOST_CHECK(banman->IsDiscouraged(addr[1]));
  + BOOST_CHECK(banman->IsDiscouraged(addr[2]));
  + BOOST_CHECK(nodes[0]->fDisconnect);
  + BOOST_CHECK(nodes[1]->fDisconnect);
  + BOOST_CHECK(nodes[2]->fDisconnect);
  +
  for (CNode* node : nodes) {
  peerLogic->FinalizeNode(*node);
  }
  