face: remove prohibited endpoint set

Prior to this commit, TcpFactory and UdpFactory each had a "prohibited
endpoint set" which prevents creating a face that connects to NFD
itself. This feature is no longer necessary after Nack-Duplicate has
been introduced, and is now removed.

refs #4189

Change-Id: I3b80ddc76ca1afb83b6f62061ccdbb69200e1841
diff --git a/daemon/face/tcp-factory.cpp b/daemon/face/tcp-factory.cpp
index 9833ee6..a53721c 100644
--- a/daemon/face/tcp-factory.cpp
+++ b/daemon/face/tcp-factory.cpp
@@ -149,13 +149,6 @@
   // a canonical tcp4/tcp6 FaceUri cannot have a multicast address
   BOOST_ASSERT(!endpoint.address().is_multicast());
 
-  if (m_prohibitedEndpoints.find(endpoint) != m_prohibitedEndpoints.end()) {
-    NFD_LOG_TRACE("Requested endpoint is prohibited "
-                  "(reserved by NFD or disallowed by face management protocol)");
-    onFailure(406, "Requested endpoint is prohibited");
-    return;
-  }
-
   if (params.wantLocalFieldsEnabled && !endpoint.address().is_loopback()) {
     NFD_LOG_TRACE("createFace cannot create non-local face with local fields enabled");
     onFailure(406, "Local fields can only be enabled on faces with local scope");
@@ -176,48 +169,6 @@
   onFailure(504, "No channels available to connect");
 }
 
-void
-TcpFactory::prohibitEndpoint(const tcp::Endpoint& endpoint)
-{
-  if (endpoint.address().is_v4() &&
-      endpoint.address() == ip::address_v4::any()) {
-    prohibitAllIpv4Endpoints(endpoint.port());
-  }
-  else if (endpoint.address().is_v6() &&
-           endpoint.address() == ip::address_v6::any()) {
-    prohibitAllIpv6Endpoints(endpoint.port());
-  }
-
-  NFD_LOG_TRACE("prohibiting TCP " << endpoint);
-  m_prohibitedEndpoints.insert(endpoint);
-}
-
-void
-TcpFactory::prohibitAllIpv4Endpoints(uint16_t port)
-{
-  ///\todo prohibited endpoints need to react to dynamic NIC changes
-  for (const NetworkInterfaceInfo& nic : listNetworkInterfaces()) {
-    for (const auto& addr : nic.ipv4Addresses) {
-      if (addr != ip::address_v4::any()) {
-        prohibitEndpoint(tcp::Endpoint(addr, port));
-      }
-    }
-  }
-}
-
-void
-TcpFactory::prohibitAllIpv6Endpoints(uint16_t port)
-{
-  ///\todo prohibited endpoints need to react to dynamic NIC changes
-  for (const NetworkInterfaceInfo& nic : listNetworkInterfaces()) {
-    for (const auto& addr : nic.ipv6Addresses) {
-      if (addr != ip::address_v6::any()) {
-        prohibitEndpoint(tcp::Endpoint(addr, port));
-      }
-    }
-  }
-}
-
 shared_ptr<TcpChannel>
 TcpFactory::createChannel(const tcp::Endpoint& endpoint)
 {
@@ -227,7 +178,6 @@
 
   channel = make_shared<TcpChannel>(endpoint);
   m_channels[endpoint] = channel;
-  prohibitEndpoint(endpoint);
   return channel;
 }
 
diff --git a/daemon/face/tcp-factory.hpp b/daemon/face/tcp-factory.hpp
index cbbbae6..fb4735d 100644
--- a/daemon/face/tcp-factory.hpp
+++ b/daemon/face/tcp-factory.hpp
@@ -83,16 +83,6 @@
   std::vector<shared_ptr<const Channel>>
   getChannels() const override;
 
-PUBLIC_WITH_TESTS_ELSE_PRIVATE:
-  void
-  prohibitEndpoint(const tcp::Endpoint& endpoint);
-
-  void
-  prohibitAllIpv4Endpoints(uint16_t port);
-
-  void
-  prohibitAllIpv6Endpoints(uint16_t port);
-
 private:
   /**
    * \brief Look up TcpChannel using specified local endpoint
@@ -105,9 +95,6 @@
 
 private:
   std::map<tcp::Endpoint, shared_ptr<TcpChannel>> m_channels;
-
-PUBLIC_WITH_TESTS_ELSE_PRIVATE:
-  std::set<tcp::Endpoint> m_prohibitedEndpoints;
 };
 
 } // namespace face
diff --git a/daemon/face/udp-factory.cpp b/daemon/face/udp-factory.cpp
index 702d02f..228af1c 100644
--- a/daemon/face/udp-factory.cpp
+++ b/daemon/face/udp-factory.cpp
@@ -233,13 +233,6 @@
     return;
   }
 
-  if (m_prohibitedEndpoints.find(endpoint) != m_prohibitedEndpoints.end()) {
-    NFD_LOG_TRACE("Requested endpoint is prohibited "
-                  "(reserved by this NFD or disallowed by face management protocol)");
-    onFailure(406, "Requested endpoint is prohibited");
-    return;
-  }
-
   if (params.wantLocalFieldsEnabled) {
     // UDP faces are never local
     NFD_LOG_TRACE("createFace cannot create non-local face with local fields enabled");
@@ -260,53 +253,6 @@
   onFailure(504, "No channels available to connect");
 }
 
-void
-UdpFactory::prohibitEndpoint(const udp::Endpoint& endpoint)
-{
-  if (endpoint.address().is_v4() &&
-      endpoint.address() == ip::address_v4::any()) {
-    prohibitAllIpv4Endpoints(endpoint.port());
-  }
-  else if (endpoint.address().is_v6() &&
-           endpoint.address() == ip::address_v6::any()) {
-    prohibitAllIpv6Endpoints(endpoint.port());
-  }
-
-  NFD_LOG_TRACE("prohibiting UDP " << endpoint);
-  m_prohibitedEndpoints.insert(endpoint);
-}
-
-void
-UdpFactory::prohibitAllIpv4Endpoints(uint16_t port)
-{
-  for (const NetworkInterfaceInfo& nic : listNetworkInterfaces()) {
-    for (const auto& addr : nic.ipv4Addresses) {
-      if (addr != ip::address_v4::any()) {
-        prohibitEndpoint(udp::Endpoint(addr, port));
-      }
-    }
-
-    if (nic.isBroadcastCapable() &&
-        nic.broadcastAddress != ip::address_v4::any()) {
-      prohibitEndpoint(udp::Endpoint(nic.broadcastAddress, port));
-    }
-  }
-
-  prohibitEndpoint(udp::Endpoint(ip::address_v4::broadcast(), port));
-}
-
-void
-UdpFactory::prohibitAllIpv6Endpoints(uint16_t port)
-{
-  for (const NetworkInterfaceInfo& nic : listNetworkInterfaces()) {
-    for (const auto& addr : nic.ipv6Addresses) {
-      if (addr != ip::address_v6::any()) {
-        prohibitEndpoint(udp::Endpoint(addr, port));
-      }
-    }
-  }
-}
-
 shared_ptr<UdpChannel>
 UdpFactory::createChannel(const udp::Endpoint& localEndpoint,
                           time::nanoseconds idleTimeout)
@@ -328,7 +274,6 @@
 
   auto channel = std::make_shared<UdpChannel>(localEndpoint, idleTimeout);
   m_channels[localEndpoint] = channel;
-  prohibitEndpoint(localEndpoint);
 
   return channel;
 }
@@ -370,11 +315,6 @@
                                 "endpoint is already allocated for a UDP unicast channel"));
   }
 
-  if (m_prohibitedEndpoints.find(multicastEndpoint) != m_prohibitedEndpoints.end()) {
-    BOOST_THROW_EXCEPTION(Error("Cannot create the requested UDP multicast face, "
-                                "remote endpoint is owned by this NFD instance"));
-  }
-
   if (localEndpoint.address().is_v6() || multicastEndpoint.address().is_v6()) {
     BOOST_THROW_EXCEPTION(Error("IPv6 multicast is not supported yet. Please provide an IPv4 "
                                 "address"));
diff --git a/daemon/face/udp-factory.hpp b/daemon/face/udp-factory.hpp
index 589817d..5ffa3b6 100644
--- a/daemon/face/udp-factory.hpp
+++ b/daemon/face/udp-factory.hpp
@@ -146,16 +146,6 @@
                       const std::string& multicastPort,
                       const std::string& networkInterfaceName = "");
 
-PUBLIC_WITH_TESTS_ELSE_PRIVATE:
-  void
-  prohibitEndpoint(const udp::Endpoint& endpoint);
-
-  void
-  prohibitAllIpv4Endpoints(uint16_t port);
-
-  void
-  prohibitAllIpv6Endpoints(uint16_t port);
-
 private:
   void
   applyMulticastConfig(const FaceSystem::ConfigContext& context);
@@ -173,9 +163,6 @@
 
   MulticastConfig m_mcastConfig;
   std::map<udp::Endpoint, shared_ptr<Face>> m_mcastFaces;
-
-PUBLIC_WITH_TESTS_ELSE_PRIVATE:
-  std::set<udp::Endpoint> m_prohibitedEndpoints;
 };
 
 } // namespace face
diff --git a/tests/daemon/face/tcp-factory.t.cpp b/tests/daemon/face/tcp-factory.t.cpp
index 8dd12ec..e00e984 100644
--- a/tests/daemon/face/tcp-factory.t.cpp
+++ b/tests/daemon/face/tcp-factory.t.cpp
@@ -215,14 +215,6 @@
               "Outgoing TCP faces do not support on-demand persistency"});
 
   createFace(factory,
-             FaceUri("tcp4://127.0.0.1:20071"),
-             {},
-             ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
-             false,
-             {CreateFaceExpectedResult::FAILURE, 406,
-              "Requested endpoint is prohibited"});
-
-  createFace(factory,
              FaceUri("tcp4://198.51.100.100:6363"),
              {},
              ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
@@ -269,87 +261,6 @@
   BOOST_CHECK(face == nullptr);
 }
 
-class FakeNetworkInterfaceFixture : public TcpFactoryFixture
-{
-public:
-  FakeNetworkInterfaceFixture()
-  {
-    using namespace boost::asio::ip;
-
-    auto fakeInterfaces = make_shared<std::vector<NetworkInterfaceInfo>>();
-
-    fakeInterfaces->push_back(
-      NetworkInterfaceInfo {0, "eth0",
-        ethernet::Address::fromString("3e:15:c2:8b:65:00"),
-        {address_v4::from_string("0.0.0.0")},
-        {address_v6::from_string("::")},
-        address_v4(),
-        IFF_UP});
-    fakeInterfaces->push_back(
-      NetworkInterfaceInfo {1, "eth0",
-        ethernet::Address::fromString("3e:15:c2:8b:65:00"),
-        {address_v4::from_string("192.168.2.1"), address_v4::from_string("192.168.2.2")},
-        {},
-        address_v4::from_string("192.168.2.255"),
-        0});
-    fakeInterfaces->push_back(
-      NetworkInterfaceInfo {2, "eth1",
-        ethernet::Address::fromString("3e:15:c2:8b:65:00"),
-        {address_v4::from_string("198.51.100.1")},
-        {address_v6::from_string("2001:db8::2"), address_v6::from_string("2001:db8::3")},
-        address_v4::from_string("198.51.100.255"),
-        IFF_MULTICAST | IFF_BROADCAST | IFF_UP});
-
-    setDebugNetworkInterfaces(fakeInterfaces);
-  }
-
-  ~FakeNetworkInterfaceFixture()
-  {
-    setDebugNetworkInterfaces(nullptr);
-  }
-};
-
-BOOST_FIXTURE_TEST_CASE(Bug2292, FakeNetworkInterfaceFixture)
-{
-  using namespace boost::asio::ip;
-
-  factory.prohibitEndpoint(tcp::Endpoint(address_v4::from_string("192.168.2.1"), 1024));
-  BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 1);
-  BOOST_CHECK((factory.m_prohibitedEndpoints ==
-               std::set<tcp::Endpoint> {
-                 tcp::Endpoint(address_v4::from_string("192.168.2.1"), 1024),
-               }));
-
-  factory.m_prohibitedEndpoints.clear();
-  factory.prohibitEndpoint(tcp::Endpoint(address_v6::from_string("2001:db8::1"), 2048));
-  BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 1);
-  BOOST_CHECK((factory.m_prohibitedEndpoints ==
-               std::set<tcp::Endpoint> {
-                 tcp::Endpoint(address_v6::from_string("2001:db8::1"), 2048)
-               }));
-
-  factory.m_prohibitedEndpoints.clear();
-  factory.prohibitEndpoint(tcp::Endpoint(address_v4(), 1024));
-  BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 4);
-  BOOST_CHECK((factory.m_prohibitedEndpoints ==
-               std::set<tcp::Endpoint> {
-                 tcp::Endpoint(address_v4::from_string("192.168.2.1"), 1024),
-                 tcp::Endpoint(address_v4::from_string("192.168.2.2"), 1024),
-                 tcp::Endpoint(address_v4::from_string("198.51.100.1"), 1024),
-                 tcp::Endpoint(address_v4::from_string("0.0.0.0"), 1024)
-               }));
-
-  factory.m_prohibitedEndpoints.clear();
-  factory.prohibitEndpoint(tcp::Endpoint(address_v6(), 2048));
-  BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 3);
-  BOOST_CHECK((factory.m_prohibitedEndpoints ==
-               std::set<tcp::Endpoint> {
-                 tcp::Endpoint(address_v6::from_string("2001:db8::2"), 2048),
-                 tcp::Endpoint(address_v6::from_string("2001:db8::3"), 2048),
-                 tcp::Endpoint(address_v6::from_string("::"), 2048)
-               }));
-}
-
 BOOST_AUTO_TEST_SUITE_END() // TestTcpFactory
 BOOST_AUTO_TEST_SUITE_END() // Face
 
diff --git a/tests/daemon/face/udp-factory.t.cpp b/tests/daemon/face/udp-factory.t.cpp
index 0ad5612..7f12af3 100644
--- a/tests/daemon/face/udp-factory.t.cpp
+++ b/tests/daemon/face/udp-factory.t.cpp
@@ -652,14 +652,6 @@
               "Cannot create multicast UDP faces"});
 
   createFace(factory,
-             FaceUri("udp4://127.0.0.1:20071"),
-             {},
-             ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
-             false,
-             {CreateFaceExpectedResult::FAILURE, 406,
-              "Requested endpoint is prohibited"});
-
-  createFace(factory,
              FaceUri("udp4://127.0.0.1:20072"),
              {},
              ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
@@ -668,89 +660,6 @@
               "Local fields can only be enabled on faces with local scope"});
 }
 
-class FakeNetworkInterfaceFixture : public UdpFactoryFixture
-{
-public:
-  FakeNetworkInterfaceFixture()
-  {
-    using namespace boost::asio::ip;
-
-    auto fakeInterfaces = make_shared<std::vector<NetworkInterfaceInfo>>();
-
-    fakeInterfaces->push_back(
-      NetworkInterfaceInfo {0, "eth0",
-        ethernet::Address::fromString("3e:15:c2:8b:65:00"),
-        {address_v4::from_string("0.0.0.0")},
-        {address_v6::from_string("::")},
-        address_v4(),
-        IFF_UP});
-    fakeInterfaces->push_back(
-      NetworkInterfaceInfo {1, "eth0",
-        ethernet::Address::fromString("3e:15:c2:8b:65:00"),
-        {address_v4::from_string("192.168.2.1"), address_v4::from_string("192.168.2.2")},
-        {},
-        address_v4::from_string("192.168.2.255"),
-        0});
-    fakeInterfaces->push_back(
-      NetworkInterfaceInfo {2, "eth1",
-        ethernet::Address::fromString("3e:15:c2:8b:65:00"),
-        {address_v4::from_string("198.51.100.1")},
-        {address_v6::from_string("2001:db8::2"), address_v6::from_string("2001:db8::3")},
-        address_v4::from_string("198.51.100.255"),
-        IFF_MULTICAST | IFF_BROADCAST | IFF_UP});
-
-    setDebugNetworkInterfaces(fakeInterfaces);
-  }
-
-  ~FakeNetworkInterfaceFixture()
-  {
-    setDebugNetworkInterfaces(nullptr);
-  }
-};
-
-BOOST_FIXTURE_TEST_CASE(Bug2292, FakeNetworkInterfaceFixture)
-{
-  using namespace boost::asio::ip;
-
-  factory.prohibitEndpoint(udp::Endpoint(address_v4::from_string("192.168.2.1"), 1024));
-  BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 1);
-  BOOST_CHECK((factory.m_prohibitedEndpoints ==
-               std::set<udp::Endpoint> {
-                 udp::Endpoint(address_v4::from_string("192.168.2.1"), 1024),
-               }));
-
-  factory.m_prohibitedEndpoints.clear();
-  factory.prohibitEndpoint(udp::Endpoint(address_v6::from_string("2001:db8::1"), 2048));
-  BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 1);
-  BOOST_CHECK((factory.m_prohibitedEndpoints ==
-               std::set<udp::Endpoint> {
-                 udp::Endpoint(address_v6::from_string("2001:db8::1"), 2048),
-               }));
-
-  factory.m_prohibitedEndpoints.clear();
-  factory.prohibitEndpoint(udp::Endpoint(address_v4(), 1024));
-  BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 6);
-  BOOST_CHECK((factory.m_prohibitedEndpoints ==
-               std::set<udp::Endpoint> {
-                 udp::Endpoint(address_v4::from_string("192.168.2.1"), 1024),
-                 udp::Endpoint(address_v4::from_string("192.168.2.2"), 1024),
-                 udp::Endpoint(address_v4::from_string("198.51.100.1"), 1024),
-                 udp::Endpoint(address_v4::from_string("198.51.100.255"), 1024),
-                 udp::Endpoint(address_v4::from_string("255.255.255.255"), 1024),
-                 udp::Endpoint(address_v4::from_string("0.0.0.0"), 1024)
-               }));
-
-  factory.m_prohibitedEndpoints.clear();
-  factory.prohibitEndpoint(udp::Endpoint(address_v6(), 2048));
-  BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 3);
-  BOOST_CHECK((factory.m_prohibitedEndpoints ==
-               std::set<udp::Endpoint> {
-                 udp::Endpoint(address_v6::from_string("2001:db8::2"), 2048),
-                 udp::Endpoint(address_v6::from_string("2001:db8::3"), 2048),
-                 udp::Endpoint(address_v6::from_string("::"), 2048),
-               }));
-}
-
 BOOST_AUTO_TEST_SUITE_END() // TestUdpFactory
 BOOST_AUTO_TEST_SUITE_END() // Face
 
diff --git a/tests/daemon/mgmt/face-manager-create-face.t.cpp b/tests/daemon/mgmt/face-manager-create-face.t.cpp
index ac50913..5a39ddb 100644
--- a/tests/daemon/mgmt/face-manager-create-face.t.cpp
+++ b/tests/daemon/mgmt/face-manager-create-face.t.cpp
@@ -1,5 +1,5 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
  * Copyright (c) 2014-2017,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
@@ -107,18 +107,6 @@
   }
 };
 
-class UdpFaceConnectToSelf // face that will cause afterCreateFaceFailure to be invoked
-                           // fails because remote endpoint is prohibited
-{
-public:
-  static ControlParameters
-  getParameters()
-  {
-    return ControlParameters()
-      .setUri("udp4://0.0.0.0:16363"); // cannot connect to self
-  }
-};
-
 class LocalTcpFaceLocalFieldsEnabled
 {
 public:
@@ -214,7 +202,6 @@
                     mpl::pair<UdpFaceOnDemand, CommandFailure<406>>,
                     mpl::pair<UdpFacePersistent, CommandSuccess>,
                     mpl::pair<UdpFacePermanent, CommandSuccess>,
-                    mpl::pair<UdpFaceConnectToSelf, CommandFailure<406>>,
                     mpl::pair<LocalTcpFaceLocalFieldsEnabled, CommandSuccess>,
                     mpl::pair<LocalTcpFaceLocalFieldsDisabled, CommandSuccess>,
                     mpl::pair<NonLocalUdpFaceLocalFieldsEnabled, CommandFailure<406>>,