poke: use unsetInterestFilter on Face instead of shutdown

refs #4642

Change-Id: I7b73c7bcde0763226a15d465046db2f4b7bb9b05
diff --git a/tests/peek/ndnpoke.t.cpp b/tests/peek/ndnpoke.t.cpp
index d6252f9..d8bbb69 100644
--- a/tests/peek/ndnpoke.t.cpp
+++ b/tests/peek/ndnpoke.t.cpp
@@ -80,6 +80,10 @@
 
   this->advanceClocks(io, 1_ms, 10);
 
+  // Check for prefix registration
+  BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
+  BOOST_CHECK_EQUAL(face.sentInterests.front().getName().getPrefix(4), "/localhost/nfd/rib/register");
+
   Interest interest("/poke/test");
   face.receive(interest);
   this->advanceClocks(io, 1_ms, 10);
@@ -91,6 +95,10 @@
   BOOST_CHECK(!face.sentData.back().getFinalBlock());
   BOOST_CHECK_EQUAL(face.sentData.back().getFreshnessPeriod(), 0_ms);
   BOOST_CHECK_EQUAL(face.sentData.back().getSignature().getType(), tlv::SignatureSha256WithEcdsa);
+
+  // Check for prefix unregistration
+  BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 2); // One for registration, one for unregistration
+  BOOST_CHECK_EQUAL(face.sentInterests.back().getName().getPrefix(4), "/localhost/nfd/rib/unregister");
 }
 
 BOOST_AUTO_TEST_CASE(FinalBlockId)
diff --git a/tools/peek/ndnpoke/main.cpp b/tools/peek/ndnpoke/main.cpp
index 5cb0dda..976fcd7 100644
--- a/tools/peek/ndnpoke/main.cpp
+++ b/tools/peek/ndnpoke/main.cpp
@@ -165,9 +165,6 @@
   scheduler::Scheduler scheduler(io);
   NdnPoke program(face, keyChain, std::cin, options);
   try {
-    program.afterFinish.connect([&scheduler, &face] {
-        scheduler.scheduleEvent(2_s, [&face] { face.shutdown(); });
-      });
     program.start();
     face.processEvents(timeout);
   }
diff --git a/tools/peek/ndnpoke/ndnpoke.cpp b/tools/peek/ndnpoke/ndnpoke.cpp
index 512d75b..1bda0de 100644
--- a/tools/peek/ndnpoke/ndnpoke.cpp
+++ b/tools/peek/ndnpoke/ndnpoke.cpp
@@ -52,10 +52,10 @@
     m_wasDataSent = true;
   }
   else {
-    m_face.setInterestFilter(m_options.prefixName,
-                             bind(&NdnPoke::onInterest, this, _1, _2, dataPacket),
-                             nullptr,
-                             bind(&NdnPoke::onRegisterFailed, this, _1, _2));
+    m_registeredPrefix = m_face.setInterestFilter(m_options.prefixName,
+                                                  bind(&NdnPoke::onInterest, this, _1, _2, dataPacket),
+                                                  nullptr,
+                                                  bind(&NdnPoke::onRegisterFailed, this, _1, _2));
   }
 }
 
@@ -92,7 +92,8 @@
   catch (const Face::OversizedPacketError& e) {
     std::cerr << "Data exceeded maximum packet size" << std::endl;
   }
-  afterFinish();
+
+  m_face.unsetInterestFilter(m_registeredPrefix);
 }
 
 void
diff --git a/tools/peek/ndnpoke/ndnpoke.hpp b/tools/peek/ndnpoke/ndnpoke.hpp
index 8aa8740..f297f9d 100644
--- a/tools/peek/ndnpoke/ndnpoke.hpp
+++ b/tools/peek/ndnpoke/ndnpoke.hpp
@@ -59,9 +59,6 @@
     return m_wasDataSent;
   }
 
-public:
-  signal::Signal<NdnPoke> afterFinish;
-
 private:
   shared_ptr<Data>
   createDataPacket();
@@ -78,6 +75,7 @@
   std::istream& m_inStream;
   const PokeOptions& m_options;
 
+  const RegisteredPrefixId* m_registeredPrefix;
   bool m_wasDataSent;
 };