face: Implementing Face::getUri() method
Change-Id: I9a9f774b95784e5b7ec75472f1cc6cf64c4e5d7b
Refs: #1319
diff --git a/daemon/core/face-uri.cpp b/daemon/core/face-uri.cpp
index 0a3f1d4..cc6c8c8 100644
--- a/daemon/core/face-uri.cpp
+++ b/daemon/core/face-uri.cpp
@@ -47,7 +47,7 @@
boost::regex v6Exp("^\\[(([a-fA-F0-9:]+))\\](:(\\d+))?$"); // [host]:port
boost::regex v4Exp("^((\\d+\\.){3}\\d+)(:(\\d+))?$");
- boost::regex hostExp("^(([^:]+))(:(\\d+))?$"); // host:port
+ boost::regex hostExp("^(([^:]*))(:(\\d+))?$"); // host:port
boost::smatch match;
m_isV6 = boost::regex_match(authority, match, v6Exp);
diff --git a/daemon/face/datagram-face.hpp b/daemon/face/datagram-face.hpp
index f4f9a18..78a4a12 100644
--- a/daemon/face/datagram-face.hpp
+++ b/daemon/face/datagram-face.hpp
@@ -18,7 +18,8 @@
typedef T protocol;
explicit
- DatagramFace(const shared_ptr<typename protocol::socket>& socket);
+ DatagramFace(const FaceUri& uri,
+ const shared_ptr<typename protocol::socket>& socket);
virtual
~DatagramFace();
@@ -64,8 +65,10 @@
template <class T>
inline
-DatagramFace<T>::DatagramFace(const shared_ptr<typename DatagramFace::protocol::socket>& socket)
- : m_socket(socket)
+DatagramFace<T>::DatagramFace(const FaceUri& uri,
+ const shared_ptr<typename DatagramFace::protocol::socket>& socket)
+ : Face(uri)
+ , m_socket(socket)
{
m_socket->async_receive(boost::asio::buffer(m_inputBuffer, MAX_NDN_PACKET_SIZE), 0,
bind(&DatagramFace<T>::handleReceive, this, _1, _2));
diff --git a/daemon/face/ethernet-face.cpp b/daemon/face/ethernet-face.cpp
index 2d3b8e3..f98a3da 100644
--- a/daemon/face/ethernet-face.cpp
+++ b/daemon/face/ethernet-face.cpp
@@ -34,7 +34,8 @@
EthernetFace::EthernetFace(const shared_ptr<boost::asio::posix::stream_descriptor>& socket,
const ethernet::Endpoint& interface,
const ethernet::Address& address)
- : m_socket(socket)
+ : Face(FaceUri("ether://" + interface + "/" + address.toString(':')))
+ , m_socket(socket)
, m_interface(interface)
, m_destAddress(address)
{
diff --git a/daemon/face/face.cpp b/daemon/face/face.cpp
index 8e81217..7268ee4 100644
--- a/daemon/face/face.cpp
+++ b/daemon/face/face.cpp
@@ -11,9 +11,10 @@
NFD_LOG_INIT("Face")
-Face::Face(bool isLocal)
+Face::Face(const FaceUri& uri, bool isLocal)
: m_id(INVALID_FACEID)
, m_isLocal(isLocal)
+ , m_uri(uri)
{
}
diff --git a/daemon/face/face.hpp b/daemon/face/face.hpp
index f20c37b..893a253 100644
--- a/daemon/face/face.hpp
+++ b/daemon/face/face.hpp
@@ -37,8 +37,7 @@
Error(const std::string& what) : std::runtime_error(what) {}
};
- explicit
- Face(bool isLocal = false);
+ Face(const FaceUri& uri, bool isLocal = false);
virtual
~Face();
@@ -104,6 +103,9 @@
const FaceCounters&
getCounters() const;
+ const FaceUri&
+ getUri() const;
+
protected:
// this is a non-virtual method
bool
@@ -121,6 +123,7 @@
std::string m_description;
bool m_isLocal; // for scoping purposes
FaceCounters m_counters;
+ FaceUri m_uri;
// allow setting FaceId
friend class FaceTable;
@@ -145,6 +148,12 @@
return m_counters;
}
+inline const FaceUri&
+Face::getUri() const
+{
+ return m_uri;
+}
+
} // namespace nfd
#endif // NFD_FACE_FACE_HPP
diff --git a/daemon/face/local-face.hpp b/daemon/face/local-face.hpp
index b7d973a..7023efb 100644
--- a/daemon/face/local-face.hpp
+++ b/daemon/face/local-face.hpp
@@ -31,7 +31,8 @@
class LocalFace : public Face
{
public:
- LocalFace();
+ explicit
+ LocalFace(const FaceUri& uri);
/** \brief get whether a LocalControlHeader feature is enabled
*
@@ -81,8 +82,8 @@
};
inline
-LocalFace::LocalFace()
- : Face(true)
+LocalFace::LocalFace(const FaceUri& uri)
+ : Face(uri, true)
, m_localControlHeaderFeatures(LOCAL_CONTROL_HEADER_FEATURE_MAX)
{
}
diff --git a/daemon/face/multicast-udp-face.cpp b/daemon/face/multicast-udp-face.cpp
index edd2ff4..e56c147 100644
--- a/daemon/face/multicast-udp-face.cpp
+++ b/daemon/face/multicast-udp-face.cpp
@@ -12,7 +12,7 @@
MulticastUdpFace::MulticastUdpFace(const shared_ptr<MulticastUdpFace::protocol::socket>& socket)
- : UdpFace(socket)
+ : DatagramFace<protocol>(FaceUri(socket->local_endpoint()), socket)
{
NFD_LOG_DEBUG("Face creation. Multicast group: "
<< m_socket->local_endpoint());
diff --git a/daemon/face/multicast-udp-face.hpp b/daemon/face/multicast-udp-face.hpp
index 46404da..2697a7f 100644
--- a/daemon/face/multicast-udp-face.hpp
+++ b/daemon/face/multicast-udp-face.hpp
@@ -7,7 +7,7 @@
#ifndef NFD_FACE_MULTICAST_UDP_FACE_HPP
#define NFD_FACE_MULTICAST_UDP_FACE_HPP
-#include "udp-face.hpp"
+#include "datagram-face.hpp"
namespace nfd
{
@@ -16,7 +16,7 @@
* \brief Implementation of Face abstraction that uses
* multicast UDP as underlying transport mechanism
*/
-class MulticastUdpFace : public UdpFace
+class MulticastUdpFace : public DatagramFace<boost::asio::ip::udp>
{
public:
typedef boost::asio::ip::udp protocol;
diff --git a/daemon/face/stream-face.hpp b/daemon/face/stream-face.hpp
index db37660..8a0f960 100644
--- a/daemon/face/stream-face.hpp
+++ b/daemon/face/stream-face.hpp
@@ -25,7 +25,8 @@
* \brief Create instance of StreamFace
*/
explicit
- StreamFace(const shared_ptr<typename protocol::socket>& socket);
+ StreamFace(const FaceUri& uri,
+ const shared_ptr<typename protocol::socket>& socket);
virtual
~StreamFace();
@@ -95,15 +96,17 @@
};
-template<class T, class U>
+template<class T, class FaceBase>
inline
-StreamFace<T, U>::StreamFace(const shared_ptr<typename StreamFace::protocol::socket>& socket)
- : m_socket(socket)
+StreamFace<T, FaceBase>::StreamFace(const FaceUri& uri,
+ const shared_ptr<typename StreamFace::protocol::socket>& socket)
+ : FaceBase(uri)
+ , m_socket(socket)
, m_inputBufferSize(0)
{
- StreamFaceValidator<T, U>::validateSocket(*socket);
+ StreamFaceValidator<T, FaceBase>::validateSocket(*socket);
m_socket->async_receive(boost::asio::buffer(m_inputBuffer, MAX_NDN_PACKET_SIZE), 0,
- bind(&StreamFace<T, U>::handleReceive, this, _1, _2));
+ bind(&StreamFace<T, FaceBase>::handleReceive, this, _1, _2));
}
template<class T, class U>
diff --git a/daemon/face/tcp-face.cpp b/daemon/face/tcp-face.cpp
index 4f8cbab..6f85a21 100644
--- a/daemon/face/tcp-face.cpp
+++ b/daemon/face/tcp-face.cpp
@@ -17,14 +17,14 @@
TcpLocalFace::protocol, LocalFace, "TcpLocalFace");
TcpFace::TcpFace(const shared_ptr<TcpFace::protocol::socket>& socket)
- : StreamFace<protocol>(socket)
+ : StreamFace<protocol>(FaceUri(socket->remote_endpoint()), socket)
{
}
//
TcpLocalFace::TcpLocalFace(const shared_ptr<TcpLocalFace::protocol::socket>& socket)
- : StreamFace<protocol, LocalFace>(socket)
+ : StreamFace<protocol, LocalFace>(FaceUri(socket->remote_endpoint()), socket)
{
}
diff --git a/daemon/face/udp-face.cpp b/daemon/face/udp-face.cpp
index 0ee40cc..dc516a7 100644
--- a/daemon/face/udp-face.cpp
+++ b/daemon/face/udp-face.cpp
@@ -11,7 +11,7 @@
NFD_LOG_INCLASS_TEMPLATE_SPECIALIZATION_DEFINE(DatagramFace, UdpFace::protocol, "UdpFace");
UdpFace::UdpFace(const shared_ptr<UdpFace::protocol::socket>& socket)
- : DatagramFace<protocol>(socket)
+ : DatagramFace<protocol>(FaceUri(socket->remote_endpoint()), socket)
{
}
diff --git a/daemon/face/unix-stream-face.cpp b/daemon/face/unix-stream-face.cpp
index 27ba693..43e2369 100644
--- a/daemon/face/unix-stream-face.cpp
+++ b/daemon/face/unix-stream-face.cpp
@@ -16,7 +16,7 @@
"UnixStreamFace");
UnixStreamFace::UnixStreamFace(const shared_ptr<UnixStreamFace::protocol::socket>& socket)
- : StreamFace<protocol, LocalFace>(socket)
+ : StreamFace<protocol, LocalFace>(FaceUri(socket->local_endpoint()), socket)
{
}
diff --git a/daemon/mgmt/internal-face.cpp b/daemon/mgmt/internal-face.cpp
index a6c116b..f7e5018 100644
--- a/daemon/mgmt/internal-face.cpp
+++ b/daemon/mgmt/internal-face.cpp
@@ -11,7 +11,7 @@
NFD_LOG_INIT("InternalFace");
InternalFace::InternalFace()
- : Face(true)
+ : Face(FaceUri("internal://"), true)
{
}