39 if (endpoint.address().is_v4() &&
40 endpoint.address() == ip::address_v4::any()) {
41 prohibitAllIpv4Endpoints(endpoint.port());
43 else if (endpoint.address().is_v6() &&
44 endpoint.address() == ip::address_v6::any()) {
45 prohibitAllIpv6Endpoints(endpoint.port());
49 m_prohibitedEndpoints.insert(endpoint);
53 TcpFactory::prohibitAllIpv4Endpoints(uint16_t port)
56 for (
const auto& addr : nic.ipv4Addresses) {
57 if (addr != ip::address_v4::any()) {
65 TcpFactory::prohibitAllIpv6Endpoints(uint16_t port)
68 for (
const auto& addr : nic.ipv6Addresses) {
69 if (addr != ip::address_v6::any()) {
76 shared_ptr<TcpChannel>
79 auto channel = findChannel(endpoint);
83 channel = make_shared<TcpChannel>(endpoint);
84 m_channels[endpoint] = channel;
85 prohibitEndpoint(endpoint);
91 shared_ptr<TcpChannel>
95 boost::lexical_cast<uint16_t>(localPort));
102 bool wantLocalFieldsEnabled,
109 NFD_LOG_TRACE(
"createFace only supports FACE_PERSISTENCY_PERSISTENT");
110 onFailure(406,
"Outgoing TCP faces only support persistent persistency");
115 boost::lexical_cast<uint16_t>(uri.
getPort()));
117 if (endpoint.address().is_multicast()) {
119 onFailure(406,
"Cannot create multicast TCP faces");
123 if (m_prohibitedEndpoints.find(endpoint) != m_prohibitedEndpoints.end()) {
125 "(reserved by NFD or disallowed by face management protocol)");
126 onFailure(406,
"Requested endpoint is prohibited");
130 if (wantLocalFieldsEnabled && !endpoint.address().is_loopback()) {
131 NFD_LOG_TRACE(
"createFace cannot create non-local face with local fields enabled");
132 onFailure(406,
"Local fields can only be enabled on faces with local scope");
137 for (
const auto& i : m_channels) {
138 if ((i.first.address().is_v4() && endpoint.address().is_v4()) ||
139 (i.first.address().is_v6() && endpoint.address().is_v6())) {
140 i.second->connect(endpoint, wantLocalFieldsEnabled, onCreated, onFailure);
145 NFD_LOG_TRACE(
"No channels available to connect to " + boost::lexical_cast<std::string>(endpoint));
146 onFailure(504,
"No channels available to connect");
149 std::vector<shared_ptr<const Channel>>
152 std::vector<shared_ptr<const Channel>> channels;
153 channels.reserve(m_channels.size());
155 for (
const auto& i : m_channels)
156 channels.push_back(i.second);
161 shared_ptr<TcpChannel>
162 TcpFactory::findChannel(
const tcp::Endpoint& localEndpoint)
const 164 auto i = m_channels.find(localEndpoint);
165 if (i != m_channels.end())
represents the underlying protocol and address used by a Face
bool isCanonical() const
determine whether this FaceUri is in canonical form
contains information about a network interface
#define NFD_LOG_DEBUG(expression)
std::vector< NetworkInterfaceInfo > listNetworkInterfaces()
List configured network interfaces on the system and their info.
#define NFD_LOG_TRACE(expression)
Copyright (c) 2011-2015 Regents of the University of California.
const std::string & getPort() const
get port
boost::asio::ip::tcp::endpoint Endpoint
virtual void createFace(const FaceUri &uri, ndn::nfd::FacePersistency persistency, bool wantLocalFieldsEnabled, const FaceCreatedCallback &onCreated, const FaceCreationFailedCallback &onFailure) override
Try to create Face using the supplied FaceUri.
function< void(uint32_t status, const std::string &reason)> FaceCreationFailedCallback
Prototype for the callback that is invoked when the face fails to be created.
function< void(const shared_ptr< Face > &newFace)> FaceCreatedCallback
Prototype for the callback that is invoked when the face is created (as a response to incoming connec...
shared_ptr< TcpChannel > createChannel(const tcp::Endpoint &localEndpoint)
Create TCP-based channel using tcp::Endpoint.
const std::string & getHost() const
get host (domain)
#define NFD_LOG_INIT(name)
virtual std::vector< shared_ptr< const Channel > > getChannels() const override