36 boost::asio::ip::address_v4::from_string(
"0.0.0.0"));
39 boost::asio::ip::address_v6::from_string(
"::"));
42 : m_defaultPort(defaultPort)
51 const address& address = endpoint.address();
55 prohibitAllIpv4Endpoints(endpoint.port());
59 prohibitAllIpv6Endpoints(endpoint.port());
64 m_prohibitedEndpoints.insert(endpoint);
68 TcpFactory::prohibitAllIpv4Endpoints(
const uint16_t port)
73 for (
const address_v4& addr : nic.ipv4Addresses) {
82 TcpFactory::prohibitAllIpv6Endpoints(
const uint16_t port)
87 for (
const address_v6& addr : nic.ipv6Addresses) {
95 shared_ptr<TcpChannel>
98 shared_ptr<TcpChannel> channel = findChannel(endpoint);
99 if (static_cast<bool>(channel))
102 channel = make_shared<TcpChannel>(endpoint);
103 m_channels[endpoint] = channel;
104 prohibitEndpoint(endpoint);
110 shared_ptr<TcpChannel>
114 tcp::Endpoint endpoint(address::from_string(localIp), boost::lexical_cast<uint16_t>(localPort));
118 shared_ptr<TcpChannel>
122 if (i != m_channels.end())
125 return shared_ptr<TcpChannel>();
135 BOOST_THROW_EXCEPTION(
Error(
"TcpFactory only supports persistent face"));
139 boost::asio::ip::address ipAddress = boost::asio::ip::address::from_string(uri.
getHost());
142 if (m_prohibitedEndpoints.find(endpoint) != m_prohibitedEndpoints.end())
144 onConnectFailed(
"Requested endpoint is prohibited " 145 "(reserved by this NFD or disallowed by face management protocol)");
151 channel != m_channels.end();
154 if ((channel->first.address().is_v4() && endpoint.address().is_v4()) ||
155 (channel->first.address().is_v6() && endpoint.address().is_v6()))
157 channel->second->connect(endpoint, onCreated, onConnectFailed);
161 onConnectFailed(
"No channels available to connect to " 162 + boost::lexical_cast<std::string>(endpoint));
165 std::list<shared_ptr<const Channel> >
168 std::list<shared_ptr<const Channel> > channels;
169 for (ChannelMap::const_iterator i = m_channels.begin(); i != m_channels.end(); ++i)
171 channels.push_back(i->second);
function< void(const std::string &reason)> FaceConnectFailedCallback
Prototype for the callback that is called when face is failed to get created.
#define NFD_LOG_DEBUG(expression)
represents the underlying protocol and address used by a Face
static const boost::asio::ip::address_v6 ALL_V6_ENDPOINT(boost::asio::ip::address_v6::from_string("::"))
contains information about a network interface
TcpFactory(const std::string &defaultPort="6363")
const std::string & getPort() const
get port
std::vector< NetworkInterfaceInfo > listNetworkInterfaces()
List configured network interfaces on the system and their info.
Table::const_iterator iterator
bool isCanonical() const
determine whether this FaceUri is in canonical form
Copyright (c) 2011-2015 Regents of the University of California.
boost::asio::ip::tcp::endpoint Endpoint
virtual std::list< shared_ptr< const Channel > > getChannels() const
#define NFD_LOG_INIT(name)
const std::string & getHost() const
get host (domain)
#define NFD_LOG_TRACE(expression)
function< void(const shared_ptr< Face > &newFace)> FaceCreatedCallback
Prototype for the callback called when face is created (as a response to incoming connection or after...
shared_ptr< TcpChannel > createChannel(const tcp::Endpoint &localEndpoint)
Create TCP-based channel using tcp::Endpoint.
static const boost::asio::ip::address_v4 ALL_V4_ENDPOINT(boost::asio::ip::address_v4::from_string("0.0.0.0"))
virtual void createFace(const FaceUri &uri, ndn::nfd::FacePersistency persistency, const FaceCreatedCallback &onCreated, const FaceConnectFailedCallback &onConnectFailed) 1
Try to create Face using the supplied FaceUri.