face: Implementation of encode/decode of LocalControlHeader
LocalControlHeader can only be used on faces that are derived from
LocalFace. UnixStreamFace is directly inherited from LocalFace,
TCP face has two specializations: generic TcpFace (strictly not local),
and LocalTcpFace.
refs #1213
Change-Id: I8a158c3bc4bb929eedd15757cfddecc0d1049f9f
diff --git a/daemon/face/tcp-face.hpp b/daemon/face/tcp-face.hpp
index c41f601..dfd6028 100644
--- a/daemon/face/tcp-face.hpp
+++ b/daemon/face/tcp-face.hpp
@@ -23,11 +23,45 @@
explicit
TcpFace(const shared_ptr<protocol::socket>& socket);
-
- virtual bool
- isLocal() const;
};
+//
+
+/** \brief Class validating use of TcpLocalFace
+ */
+template<>
+struct StreamFaceValidator<boost::asio::ip::tcp, LocalFace>
+{
+ /** Check that local endpoint is loopback
+ *
+ * @throws Face::Error if validation failed
+ */
+ static void
+ validateSocket(boost::asio::ip::tcp::socket& socket)
+ {
+ if (!socket.local_endpoint().address().is_loopback() ||
+ !socket.remote_endpoint().address().is_loopback())
+ {
+ throw Face::Error("TcpLocalFace can be created only on loopback interface");
+ }
+ }
+};
+
+/**
+ * \brief Implementation of Face abstraction that uses TCP
+ * as underlying transport mechanism and is used for
+ * local communication (can enable LocalControlHeader)
+ */
+class TcpLocalFace : public StreamFace<boost::asio::ip::tcp, LocalFace>
+{
+public:
+ typedef boost::asio::ip::tcp protocol;
+
+ explicit
+ TcpLocalFace(const shared_ptr<protocol::socket>& socket);
+};
+
+
} // namespace nfd
#endif // NFD_FACE_TCP_FACE_HPP