28 #include <ndn-cxx/net/address-converter.hpp> 33 namespace ip = boost::asio::ip;
41 static std::string id(
"tcp");
63 if (!context.
isDryRun && !m_channels.empty()) {
64 NFD_LOG_WARN(
"Cannot disable tcp4 and tcp6 channels after initialization");
69 bool wantListen =
true;
74 for (
const auto& pair : *configSection) {
75 const std::string& key = pair.first;
77 if (key ==
"listen") {
80 else if (key ==
"port") {
81 port = ConfigFile::parseNumber<uint16_t>(pair,
"face_system.tcp");
83 else if (key ==
"enable_v4") {
86 else if (key ==
"enable_v6") {
90 BOOST_THROW_EXCEPTION(
ConfigFile::Error(
"Unrecognized option face_system.tcp." + key));
94 if (!enableV4 && !enableV6) {
96 "IPv4 and IPv6 TCP channels have been disabled. Remove face_system.tcp section to disable " 97 "TCP channels or enable at least one channel type."));
105 shared_ptr<TcpChannel> v4Channel = this->
createChannel(endpoint);
106 if (wantListen && !v4Channel->isListening()) {
107 v4Channel->listen(this->
addFace,
nullptr);
112 NFD_LOG_WARN(
"Cannot close tcp4 channel after its creation");
117 shared_ptr<TcpChannel> v6Channel = this->
createChannel(endpoint);
118 if (wantListen && !v6Channel->isListening()) {
119 v6Channel->listen(this->
addFace,
nullptr);
124 NFD_LOG_WARN(
"Cannot close tcp6 channel after its creation");
134 BOOST_ASSERT(params.
remoteUri.isCanonical());
137 NFD_LOG_TRACE(
"Cannot create unicast TCP face with LocalUri");
138 onFailure(406,
"Unicast TCP faces cannot be created with a LocalUri");
142 if (params.
persistency == ndn::nfd::FACE_PERSISTENCY_ON_DEMAND) {
143 NFD_LOG_TRACE(
"createFace does not support FACE_PERSISTENCY_ON_DEMAND");
144 onFailure(406,
"Outgoing TCP faces do not support on-demand persistency");
149 boost::lexical_cast<uint16_t>(params.
remoteUri.getPort()));
152 BOOST_ASSERT(!endpoint.address().is_multicast());
155 NFD_LOG_TRACE(
"createFace cannot create non-local face with local fields enabled");
156 onFailure(406,
"Local fields can only be enabled on faces with local scope");
161 for (
const auto& i : m_channels) {
162 if ((i.first.address().is_v4() && endpoint.address().is_v4()) ||
163 (i.first.address().is_v6() && endpoint.address().is_v6())) {
170 NFD_LOG_TRACE(
"No channels available to connect to " << endpoint);
171 onFailure(504,
"No channels available to connect");
174 shared_ptr<TcpChannel>
177 auto it = m_channels.find(endpoint);
178 if (it != m_channels.end())
181 auto channel = make_shared<TcpChannel>(endpoint);
182 m_channels[endpoint] = channel;
186 std::vector<shared_ptr<const Channel>>
FaceCreatedCallback addFace
callback when a new face is created
void createFace(const CreateFaceParams ¶ms, const FaceCreatedCallback &onCreated, const FaceCreationFailedCallback &onFailure) override
Try to create face using the supplied parameters.
shared_ptr< TcpChannel > createChannel(const tcp::Endpoint &localEndpoint)
Create TCP-based channel using tcp::Endpoint.
static const std::string & getId()
std::set< std::string > providedSchemes
FaceUri schemes provided by this ProtocolFactory.
static bool parseYesNo(const ConfigSection &node, const std::string &key, const std::string §ionName)
parse a config option that can be either "yes" or "no"
#define NFD_REGISTER_PROTOCOL_FACTORY(PF)
registers a protocol factory
TcpFactory(const CtorParams ¶ms)
#define NFD_LOG_WARN(expression)
ndn::nfd::FacePersistency persistency
ndn::optional< FaceUri > localUri
context for processing a config section in ProtocolFactory
static std::vector< shared_ptr< const Channel > > getChannelsFromMap(const ChannelMap &channelMap)
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
boost::asio::ip::tcp::endpoint Endpoint
void processConfig(OptionalConfigSection configSection, FaceSystem::ConfigContext &context) override
process face_system.tcp config section
boost::optional< const ConfigSection & > OptionalConfigSection
an optional config file section
function< void(uint32_t status, const std::string &reason)> FaceCreationFailedCallback
Prototype for the callback that is invoked when a face fails to be created.
std::vector< shared_ptr< const Channel > > getChannels() const override
Provides support for an underlying protocol.
Parameters to ProtocolFactory constructor.
#define NFD_LOG_INIT(name)
#define NFD_LOG_TRACE(expression)
Parameters to ProtocolFactory::createFace.
function< void(const shared_ptr< Face > &newFace)> FaceCreatedCallback
Prototype for the callback that is invoked when a face is created (in response to an incoming connect...