core+daemon: declare all equality operators as hidden friends

Change-Id: Id832ee1fb16fb6742879c8b87f56002f94745103
diff --git a/daemon/rib/fib-update.cpp b/daemon/rib/fib-update.cpp
index ca53565..7f48e69 100644
--- a/daemon/rib/fib-update.cpp
+++ b/daemon/rib/fib-update.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2022,  Regents of the University of California,
+ * Copyright (c) 2014-2023,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -28,28 +28,41 @@
 namespace nfd::rib {
 
 FibUpdate
-FibUpdate::createAddUpdate(const Name& name, const uint64_t faceId, const uint64_t cost)
+FibUpdate::createAddUpdate(const Name& name, uint64_t faceId, uint64_t cost)
 {
   FibUpdate update;
-
   update.name = name;
   update.faceId = faceId;
   update.cost = cost;
   update.action = ADD_NEXTHOP;
-
   return update;
 }
 
 FibUpdate
-FibUpdate::createRemoveUpdate(const Name& name, const uint64_t faceId)
+FibUpdate::createRemoveUpdate(const Name& name, uint64_t faceId)
 {
   FibUpdate update;
-
   update.name = name;
   update.faceId = faceId;
   update.action = REMOVE_NEXTHOP;
-
   return update;
 }
 
+std::ostream&
+operator<<(std::ostream& os, const FibUpdate& update)
+{
+  os << "FibUpdate(" << update.name << ", "
+     << "faceid: " << update.faceId << ", ";
+
+  if (update.action == FibUpdate::ADD_NEXTHOP) {
+    os << "cost: " << update.cost << ", "
+       << "action: ADD_NEXTHOP";
+  }
+  else {
+    os << "action: REMOVE_NEXTHOP";
+  }
+
+  return os << ")";
+}
+
 } // namespace nfd::rib
diff --git a/daemon/rib/fib-update.hpp b/daemon/rib/fib-update.hpp
index 6eead74..fd80b89 100644
--- a/daemon/rib/fib-update.hpp
+++ b/daemon/rib/fib-update.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2022,  Regents of the University of California,
+ * Copyright (c) 2014-2023,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -30,64 +30,48 @@
 
 namespace nfd::rib {
 
-/** \class FibUpdate
- *  \brief represents a FIB update
+/**
+ * \brief Represents a FIB update.
  */
 class FibUpdate
 {
 public:
-  FibUpdate()
-    : faceId(0)
-    , cost(0)
-  {
-  }
-
-  bool
-  operator==(const FibUpdate& other) const
-  {
-    return (this->name == other.name &&
-            this->faceId == other.faceId &&
-            this->cost == other.cost &&
-            this->action == other.action);
-  }
-
-  static FibUpdate
-  createAddUpdate(const Name& name, const uint64_t faceId, const uint64_t cost);
-
-  static FibUpdate
-  createRemoveUpdate(const Name& name, const uint64_t faceId);
-
   enum Action {
     ADD_NEXTHOP    = 0,
-    REMOVE_NEXTHOP = 1
+    REMOVE_NEXTHOP = 1,
   };
 
+  static FibUpdate
+  createAddUpdate(const Name& name, uint64_t faceId, uint64_t cost);
+
+  static FibUpdate
+  createRemoveUpdate(const Name& name, uint64_t faceId);
+
+public: // non-member operators (hidden friends)
+  friend bool
+  operator==(const FibUpdate& lhs, const FibUpdate& rhs) noexcept
+  {
+    return lhs.name == rhs.name &&
+           lhs.faceId == rhs.faceId &&
+           lhs.cost == rhs.cost &&
+           lhs.action == rhs.action;
+  }
+
+  friend bool
+  operator!=(const FibUpdate& lhs, const FibUpdate& rhs) noexcept
+  {
+    return !(lhs == rhs);
+  }
+
 public:
   Name name;
-  uint64_t faceId;
-  uint64_t cost;
+  uint64_t faceId = 0;
+  uint64_t cost = 0;
   Action action;
 };
 
-inline std::ostream&
-operator<<(std::ostream& os, const FibUpdate& update)
-{
-  os << "FibUpdate("
-     << " Name: " << update.name << ", "
-     << "faceId: " << update.faceId << ", ";
-
-  if (update.action == FibUpdate::ADD_NEXTHOP) {
-    os << "cost: " << update.cost << ", "
-       << "action: ADD_NEXTHOP";
-  }
-  else {
-    os << "action: REMOVE_NEXTHOP";
-  }
-
-  os << ")";
-
-  return os;
-}
+std::ostream&
+operator<<(std::ostream& os, const FibUpdate& update);
 
 } // namespace nfd::rib
 
diff --git a/daemon/rib/fib-updater.cpp b/daemon/rib/fib-updater.cpp
index 3a7caff..75ffa4c 100644
--- a/daemon/rib/fib-updater.cpp
+++ b/daemon/rib/fib-updater.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2022,  Regents of the University of California,
+ * Copyright (c) 2014-2023,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -186,11 +186,10 @@
                         const FibUpdateSuccessCallback& onSuccess,
                         const FibUpdateFailureCallback& onFailure)
 {
-  std::string updateString = (updates.size() == 1) ? " update" : " updates";
-  NFD_LOG_DEBUG("Applying " << updates.size() << updateString << " to FIB");
+  NFD_LOG_DEBUG("Applying " << updates.size() << " FIB update(s)");
 
   for (const FibUpdate& update : updates) {
-    NFD_LOG_DEBUG("Sending FIB update: " << update);
+    NFD_LOG_DEBUG("Sending " << update);
 
     if (update.action == FibUpdate::ADD_NEXTHOP) {
       sendAddNextHopUpdate(update, onSuccess, onFailure);
@@ -283,7 +282,7 @@
 {
   uint32_t code = response.getCode();
   NFD_LOG_DEBUG("Failed to apply " << update <<
-                " (code: " << code << ", error: " << response.getText() << ")");
+                " [code: " << code << ", error: " << response.getText() << "]");
 
   if (code == ndn::nfd::Controller::ERROR_TIMEOUT && nTimeouts < MAX_NUM_TIMEOUTS) {
     sendAddNextHopUpdate(update, onSuccess, onFailure, ++nTimeouts);
diff --git a/daemon/rib/rib-update.cpp b/daemon/rib/rib-update.cpp
index 343d39e..935ccce 100644
--- a/daemon/rib/rib-update.cpp
+++ b/daemon/rib/rib-update.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2022,  Regents of the University of California,
+ * Copyright (c) 2014-2023,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -32,14 +32,11 @@
 {
   switch (action) {
   case RibUpdate::REGISTER:
-    os << "REGISTER";
-    break;
+    return os << "REGISTER";
   case RibUpdate::UNREGISTER:
-    os << "UNREGISTER";
-    break;
+    return os << "UNREGISTER";
   case RibUpdate::REMOVE_FACE:
-    os << "REMOVE_FACE";
-    break;
+    return os << "REMOVE_FACE";
   }
   return os;
 }
diff --git a/daemon/rib/route.cpp b/daemon/rib/route.cpp
index 43227f1..e7c825f 100644
--- a/daemon/rib/route.cpp
+++ b/daemon/rib/route.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2022,  Regents of the University of California,
+ * Copyright (c) 2014-2023,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -31,6 +31,8 @@
 
 constexpr uint64_t PA_ROUTE_COST = 2048; // cost of route created by prefix announcement
 
+Route::Route() = default;
+
 static time::steady_clock::time_point
 computeExpiration(const ndn::PrefixAnnouncement& ann)
 {
@@ -59,17 +61,6 @@
 {
 }
 
-bool
-operator==(const Route& lhs, const Route& rhs)
-{
-  return lhs.faceId == rhs.faceId &&
-         lhs.origin == rhs.origin &&
-         lhs.flags == rhs.flags &&
-         lhs.cost == rhs.cost &&
-         lhs.expires == rhs.expires &&
-         lhs.announcement == rhs.announcement;
-}
-
 std::ostream&
 operator<<(std::ostream& os, const Route& route)
 {
@@ -78,18 +69,19 @@
      << ", origin: " << route.origin
      << ", cost: " << route.cost
      << ", flags: " << ndn::AsHex{route.flags};
+
   if (route.expires) {
     os << ", expires in: " << time::duration_cast<time::milliseconds>(*route.expires - time::steady_clock::now());
   }
   else {
     os << ", never expires";
   }
+
   if (route.announcement) {
     os << ", announcement: (" << *route.announcement << ')';
   }
-  os << ')';
 
-  return os;
+  return os << ')';
 }
 
 } // namespace nfd::rib
diff --git a/daemon/rib/route.hpp b/daemon/rib/route.hpp
index 471bdb6..5179dbf 100644
--- a/daemon/rib/route.hpp
+++ b/daemon/rib/route.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2022,  Regents of the University of California,
+ * Copyright (c) 2014-2023,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -37,14 +37,15 @@
 
 namespace nfd::rib {
 
-/** \brief Represents a route for a name prefix.
+/**
+ * \brief Represents a route for a name prefix.
  */
 class Route : public ndn::nfd::RouteFlagsTraits<Route>
 {
 public:
   /** \brief Default constructor.
    */
-  Route() = default;
+  Route();
 
   /** \brief Construct from a prefix announcement.
    *  \param ann a prefix announcement that has passed verification
@@ -76,6 +77,24 @@
     return flags;
   }
 
+public: // non-member operators (hidden friends)
+  friend bool
+  operator==(const Route& lhs, const Route& rhs)
+  {
+    return lhs.faceId == rhs.faceId &&
+           lhs.origin == rhs.origin &&
+           lhs.cost == rhs.cost &&
+           lhs.flags == rhs.flags &&
+           lhs.expires == rhs.expires &&
+           lhs.announcement == rhs.announcement;
+  }
+
+  friend bool
+  operator!=(const Route& lhs, const Route& rhs)
+  {
+    return !(lhs == rhs);
+  }
+
 public:
   uint64_t faceId = 0;
   ndn::nfd::RouteOrigin origin = ndn::nfd::ROUTE_ORIGIN_APP;
@@ -103,15 +122,6 @@
   scheduler::EventId m_expirationEvent;
 };
 
-bool
-operator==(const Route& lhs, const Route& rhs);
-
-inline bool
-operator!=(const Route& lhs, const Route& rhs)
-{
-  return !(lhs == rhs);
-}
-
 std::ostream&
 operator<<(std::ostream& os, const Route& route);