[netconnector] remove example

This CL removes the example app for netconnector. netconnector is
still used for p2p ledger sync, but is deprecated. The example was
growing stale.

TEST: no behavior change
Change-Id: Ib827b03271eb08da81aaa35ce4343c2473c42568
diff --git a/examples/netconnector/BUILD.gn b/examples/netconnector/BUILD.gn
deleted file mode 100644
index 0c15400..0000000
--- a/examples/netconnector/BUILD.gn
+++ /dev/null
@@ -1,21 +0,0 @@
-# Copyright 2016 The Fuchsia Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-import("//build/fidl/fidl.gni")
-import("//build/package.gni")
-
-package("netconnector") {
-  deprecated_system_image = true
-  package_name = "netconnector_examples"
-
-  deps = [
-    "netconnector_example",
-  ]
-
-  binaries = [
-    {
-      name = "netconnector_example"
-    },
-  ]
-}
diff --git a/examples/netconnector/MAINTAINERS b/examples/netconnector/MAINTAINERS
deleted file mode 100644
index d4b3d8e..0000000
--- a/examples/netconnector/MAINTAINERS
+++ /dev/null
@@ -1 +0,0 @@
-dalesat@google.com
diff --git a/examples/netconnector/netconnector_example/BUILD.gn b/examples/netconnector/netconnector_example/BUILD.gn
deleted file mode 100644
index c65efab..0000000
--- a/examples/netconnector/netconnector_example/BUILD.gn
+++ /dev/null
@@ -1,27 +0,0 @@
-# Copyright 2016 The Fuchsia Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-import("//build/package.gni")
-
-executable("netconnector_example") {
-  output_name = "netconnector_example"
-
-  sources = [
-    "main.cc",
-    "netconnector_example_impl.cc",
-    "netconnector_example_impl.h",
-    "netconnector_example_params.cc",
-    "netconnector_example_params.h",
-  ]
-
-  deps = [
-    "//garnet/public/lib/component/cpp",
-    "//garnet/public/lib/fsl",
-    "//garnet/public/lib/fxl",
-    "//garnet/public/lib/netconnector/cpp",
-    "//garnet/public/fidl/fuchsia.netconnector",
-    "//zircon/public/lib/async-loop-cpp",
-    "//zircon/public/lib/fit",
-  ]
-}
diff --git a/examples/netconnector/netconnector_example/README.md b/examples/netconnector/netconnector_example/README.md
deleted file mode 100644
index a6d057a..0000000
--- a/examples/netconnector/netconnector_example/README.md
+++ /dev/null
@@ -1,40 +0,0 @@
-# Application netconnector_example
-
-The application `netconnector_example` runs either as an example NetConnector
-requestor or as a responding service. As a responding service, it can either
-be registered in NetConnector's configuration, or it can register itself with
-NetConnector as a running service provider.
-
-With no arguments, `netconnector_example` runs as a responding service.
-It's invoked this way by `netconnector` by virtue of being registered as a
-service in `netconnector.config` (or on the `netconnector` command line).
-
-With the `--register-provider` option, `netconnector_example` also runs as a
-responding service, but it doesn't need to be registered as a service using
-the NetConnector config. Instead, the user invokes `netconnector_example` with
-`--register-provider`, and `netconnector_example` registers that running
-instance with NetConnector. This allows the user to decide what context the
-responding service should run in.
-
-With the `--request-device=<name>` option, `netconnector_example` runs as a
-requestor, requesting the example responding service on the specified device.
-The device name must be registered with the `netconnector` listener, and
-`netconnector_example` must be registered as a responding service with the
-running listener on the specified device.
-
-Here's an example of `netconnector_example` being registered in the
-`netconnector` config file:
-
-    {
-      "host": "my_acer",
-      "services": {
-        "netconnector.Example": "netconnector_example"
-      },
-      "devices": {
-        "acer": "192.168.4.118",
-        "nuc": "192.168.4.60"
-      }
-    }
-
-The `netconnector_example` requestor and responding service have a short
-conversation which appears as log messages.
diff --git a/examples/netconnector/netconnector_example/main.cc b/examples/netconnector/netconnector_example/main.cc
deleted file mode 100644
index e9a42dc..0000000
--- a/examples/netconnector/netconnector_example/main.cc
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright 2016 The Fuchsia Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include <fuchsia/netconnector/cpp/fidl.h>
-#include <lib/async-loop/cpp/loop.h>
-#include <lib/async/cpp/task.h>
-
-#include "garnet/examples/netconnector/netconnector_example/netconnector_example_impl.h"
-#include "garnet/examples/netconnector/netconnector_example/netconnector_example_params.h"
-#include "lib/fxl/command_line.h"
-
-int main(int argc, const char** argv) {
-  fxl::CommandLine command_line = fxl::CommandLineFromArgcArgv(argc, argv);
-  examples::NetConnectorExampleParams params(command_line);
-  if (!params.is_valid()) {
-    return 1;
-  }
-
-  async::Loop loop(&kAsyncLoopConfigAttachToThread);
-
-  examples::NetConnectorExampleImpl impl(&params, [&loop]() {
-    async::PostTask(loop.dispatcher(), [&loop]() { loop.Quit(); });
-  });
-
-  loop.Run();
-  return 0;
-}
diff --git a/examples/netconnector/netconnector_example/netconnector_example_impl.cc b/examples/netconnector/netconnector_example/netconnector_example_impl.cc
deleted file mode 100644
index 0506b4c..0000000
--- a/examples/netconnector/netconnector_example/netconnector_example_impl.cc
+++ /dev/null
@@ -1,150 +0,0 @@
-// Copyright 2016 The Fuchsia Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "garnet/examples/netconnector/netconnector_example/netconnector_example_impl.h"
-
-#include <fuchsia/netconnector/cpp/fidl.h>
-#include <lib/async/default.h>
-#include <lib/zx/channel.h>
-
-#include "garnet/examples/netconnector/netconnector_example/netconnector_example_params.h"
-#include "lib/fxl/logging.h"
-
-namespace examples {
-namespace {
-static constexpr char kRespondingServiceName[] = "netconnector::Example";
-
-static const std::vector<std::string> kConversation = {
-    "Hello!",    "Hello!",   "Do you like my hat?",
-    "I do not.", "Good-by!", "Good-by!"};
-}  // namespace
-
-NetConnectorExampleImpl::NetConnectorExampleImpl(
-    NetConnectorExampleParams* params, fit::closure quit_callback)
-    : quit_callback_(std::move(quit_callback)),
-      startup_context_(component::StartupContext::CreateFromStartupInfo()) {
-  // The MessageRelay makes using the channel easier. Hook up its callbacks.
-  message_relay_.SetMessageReceivedCallback(
-      [this](std::vector<uint8_t> message) { HandleReceivedMessage(message); });
-
-  // Quit when the local channel closes, unless we're registering our provider.
-  // In that case, we need to stay around to respond to future requests.
-  if (params->register_provider()) {
-    message_relay_.SetChannelClosedCallback([this]() {
-      if (conversation_iter_ == kConversation.end()) {
-        FXL_LOG(INFO) << "Channel closed, quitting";
-      } else {
-        FXL_LOG(ERROR) << "Channel closed unexpectedly, quitting";
-      }
-
-      quit_callback_();
-    });
-  }
-
-  // Start at the beginning of the conversation. The party that receives the
-  // last message in the conversation closes the channel.
-  conversation_iter_ = kConversation.begin();
-
-  if (params->request_device_name().empty()) {
-    // Params say we should be responding. Register the responding service.
-    FXL_LOG(INFO) << "Running as responder";
-    startup_context_->outgoing().deprecated_services()->AddServiceForName(
-        [this](zx::channel channel) {
-          message_relay_.SetChannel(std::move(channel));
-        },
-        kRespondingServiceName);
-
-    if (params->register_provider()) {
-      // Register our provider with netconnector.
-      FXL_LOG(INFO) << "Registering provider";
-      fuchsia::netconnector::NetConnectorPtr connector =
-          startup_context_->ConnectToEnvironmentService<
-              fuchsia::netconnector::NetConnector>();
-
-      fidl::InterfaceHandle<fuchsia::sys::ServiceProvider> handle;
-      startup_context_->outgoing().deprecated_services()->AddBinding(handle.NewRequest());
-
-      FXL_DCHECK(handle);
-
-      connector->RegisterServiceProvider(kRespondingServiceName,
-                                         std::move(handle));
-    }
-  } else {
-    // Params say we should be a requestor.
-    FXL_LOG(INFO) << "Running as requestor";
-    fuchsia::netconnector::NetConnectorPtr connector =
-        startup_context_->ConnectToEnvironmentService<
-            fuchsia::netconnector::NetConnector>();
-
-    // Create a pair of channels.
-    zx::channel local;
-    zx::channel remote;
-    zx_status_t status = zx::channel::create(0u, &local, &remote);
-
-    FXL_CHECK(status == ZX_OK)
-        << "zx::channel::create failed, status " << status;
-
-    // Give the local end of the channel to the relay.
-    message_relay_.SetChannel(std::move(local));
-
-    // Pass the remote end to NetConnector.
-    fuchsia::sys::ServiceProviderPtr device_service_provider;
-    connector->GetDeviceServiceProvider(params->request_device_name(),
-                                        device_service_provider.NewRequest());
-
-    device_service_provider->ConnectToService(kRespondingServiceName,
-                                              std::move(remote));
-
-    // Start the conversation.
-    SendMessage(*conversation_iter_);
-    ++conversation_iter_;
-    FXL_DCHECK(conversation_iter_ != kConversation.end());
-  }
-}
-
-NetConnectorExampleImpl::~NetConnectorExampleImpl() {}
-
-void NetConnectorExampleImpl::SendMessage(const std::string& message_string) {
-  FXL_LOG(INFO) << "Sending message: '" << message_string << "'";
-
-  std::vector<uint8_t> message(message_string.size());
-  std::memcpy(message.data(), message_string.data(), message.size());
-
-  message_relay_.SendMessage(std::move(message));
-}
-
-void NetConnectorExampleImpl::HandleReceivedMessage(
-    std::vector<uint8_t> message) {
-  std::string message_string(reinterpret_cast<char*>(message.data()), 0,
-                             message.size());
-
-  FXL_LOG(INFO) << "Message received: '" << message_string << "'";
-
-  if (conversation_iter_ == kConversation.end()) {
-    FXL_LOG(ERROR) << "Expected the channel to close, closing channel";
-    message_relay_.CloseChannel();
-    return;
-  }
-
-  if (message_string != *conversation_iter_) {
-    FXL_LOG(ERROR) << "Expected '" << *conversation_iter_
-                   << "', closing channel";
-    message_relay_.CloseChannel();
-    return;
-  }
-
-  ++conversation_iter_;
-  if (conversation_iter_ == kConversation.end()) {
-    FXL_LOG(INFO) << "Conversation complete, closing channel";
-    message_relay_.CloseChannel();
-    return;
-  }
-
-  SendMessage(*conversation_iter_);
-  ++conversation_iter_;
-  // We may have hit the end of the conversation here, but if so, the remote
-  // party is expected to close the channel.
-}
-
-}  // namespace examples
diff --git a/examples/netconnector/netconnector_example/netconnector_example_impl.h b/examples/netconnector/netconnector_example/netconnector_example_impl.h
deleted file mode 100644
index 39009a7..0000000
--- a/examples/netconnector/netconnector_example/netconnector_example_impl.h
+++ /dev/null
@@ -1,41 +0,0 @@
-// Copyright 2016 The Fuchsia Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef GARNET_EXAMPLES_NETCONNECTOR_NETCONNECTOR_EXAMPLE_NETCONNECTOR_EXAMPLE_IMPL_H_
-#define GARNET_EXAMPLES_NETCONNECTOR_NETCONNECTOR_EXAMPLE_NETCONNECTOR_EXAMPLE_IMPL_H_
-
-#include <lib/fit/function.h>
-#include <lib/zx/channel.h>
-
-#include "garnet/examples/netconnector/netconnector_example/netconnector_example_params.h"
-#include "lib/component/cpp/startup_context.h"
-#include "lib/fidl/cpp/binding_set.h"
-#include "lib/fxl/macros.h"
-#include "lib/netconnector/cpp/message_relay.h"
-
-namespace examples {
-
-class NetConnectorExampleImpl {
- public:
-  NetConnectorExampleImpl(NetConnectorExampleParams* params,
-                          fit::closure quit_callback);
-
-  ~NetConnectorExampleImpl();
-
- private:
-  void SendMessage(const std::string& message_string);
-
-  void HandleReceivedMessage(std::vector<uint8_t> message);
-
-  fit::closure quit_callback_;
-  std::unique_ptr<component::StartupContext> startup_context_;
-  netconnector::MessageRelay message_relay_;
-  std::vector<std::string>::const_iterator conversation_iter_;
-
-  FXL_DISALLOW_COPY_AND_ASSIGN(NetConnectorExampleImpl);
-};
-
-}  // namespace examples
-
-#endif  // GARNET_EXAMPLES_NETCONNECTOR_NETCONNECTOR_EXAMPLE_NETCONNECTOR_EXAMPLE_IMPL_H_
diff --git a/examples/netconnector/netconnector_example/netconnector_example_params.cc b/examples/netconnector/netconnector_example/netconnector_example_params.cc
deleted file mode 100644
index 744e755..0000000
--- a/examples/netconnector/netconnector_example/netconnector_example_params.cc
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright 2016 The Fuchsia Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "garnet/examples/netconnector/netconnector_example/netconnector_example_params.h"
-
-#include "lib/fxl/logging.h"
-
-namespace examples {
-
-NetConnectorExampleParams::NetConnectorExampleParams(
-    const fxl::CommandLine& command_line) {
-  is_valid_ = false;
-
-  register_provider_ = command_line.HasOption("register-provider");
-
-  if (!command_line.GetOptionValue("request-device", &request_device_name_)) {
-    request_device_name_.clear();
-  } else if (register_provider_) {
-    // Can't request-device if we register-provider.
-    Usage();
-    return;
-  }
-
-  is_valid_ = true;
-}
-
-void NetConnectorExampleParams::Usage() {
-  FXL_LOG(INFO) << "netconnector_example usage:";
-  FXL_LOG(INFO) << "    netconnector_example [ options ]";
-  FXL_LOG(INFO) << "options:";
-  FXL_LOG(INFO)
-      << "    --request-device=<name>   request example service from device";
-  FXL_LOG(INFO)
-      << "    --register-provider       register example service provider";
-  FXL_LOG(INFO) << "options are mutually exclusive";
-}
-
-}  // namespace examples
diff --git a/examples/netconnector/netconnector_example/netconnector_example_params.h b/examples/netconnector/netconnector_example/netconnector_example_params.h
deleted file mode 100644
index 7ffc8f5..0000000
--- a/examples/netconnector/netconnector_example/netconnector_example_params.h
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright 2016 The Fuchsia Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef GARNET_EXAMPLES_NETCONNECTOR_NETCONNECTOR_EXAMPLE_NETCONNECTOR_EXAMPLE_PARAMS_H_
-#define GARNET_EXAMPLES_NETCONNECTOR_NETCONNECTOR_EXAMPLE_NETCONNECTOR_EXAMPLE_PARAMS_H_
-
-#include <string>
-
-#include "lib/fxl/command_line.h"
-#include "lib/fxl/macros.h"
-
-namespace examples {
-
-class NetConnectorExampleParams {
- public:
-  NetConnectorExampleParams(const fxl::CommandLine& command_line);
-
-  bool is_valid() const { return is_valid_; }
-
-  bool register_provider() const { return register_provider_; }
-
-  const std::string& request_device_name() const {
-    return request_device_name_;
-  }
-
- private:
-  void Usage();
-
-  bool is_valid_;
-  bool register_provider_;
-  std::string request_device_name_;
-
-  FXL_DISALLOW_COPY_AND_ASSIGN(NetConnectorExampleParams);
-};
-
-}  // namespace examples
-
-#endif  // GARNET_EXAMPLES_NETCONNECTOR_NETCONNECTOR_EXAMPLE_NETCONNECTOR_EXAMPLE_PARAMS_H_
diff --git a/packages/examples/all b/packages/examples/all
index 80670f6..9139bf2 100644
--- a/packages/examples/all
+++ b/packages/examples/all
@@ -11,7 +11,6 @@
         "garnet/packages/examples/intl",
         "garnet/packages/examples/media",
         "garnet/packages/examples/mediaplayer",
-        "garnet/packages/examples/netconnector",
         "garnet/packages/examples/netstack",
         "garnet/packages/examples/overnet",
         "garnet/packages/examples/rust",
diff --git a/packages/examples/netconnector b/packages/examples/netconnector
deleted file mode 100644
index deff9a4..0000000
--- a/packages/examples/netconnector
+++ /dev/null
@@ -1,5 +0,0 @@
-{
-    "packages": [
-        "//garnet/examples/netconnector"
-    ]
-}