31 namespace ip = boost::asio::ip;
39 static std::string id(
"tcp");
58 if (!context.
isDryRun && !m_channels.empty()) {
59 NFD_LOG_WARN(
"Cannot disable TCP channels after initialization");
64 bool wantListen =
true;
69 bool isLocalConfigured =
false;
71 for (
const auto& pair : *configSection) {
72 const std::string& key = pair.first;
74 if (key ==
"listen") {
77 else if (key ==
"port") {
78 port = ConfigFile::parseNumber<uint16_t>(pair,
"face_system.tcp");
80 else if (key ==
"enable_v4") {
83 else if (key ==
"enable_v6") {
86 else if (key ==
"local") {
87 isLocalConfigured =
true;
88 for (
const auto& localPair : pair.second) {
89 const std::string& localKey = localPair.first;
90 if (localKey ==
"whitelist") {
93 else if (localKey ==
"blacklist") {
105 if (!isLocalConfigured) {
106 local.
assign({{
"subnet",
"127.0.0.0/8"}, {
"subnet",
"::1/128"}}, {});
109 if (!enableV4 && !enableV6) {
111 "IPv4 and IPv6 TCP channels have been disabled. Remove face_system.tcp section to disable " 112 "TCP channels or enable at least one channel type."));
124 if (wantListen && !v4Channel->isListening()) {
125 v4Channel->listen(this->
addFace,
nullptr);
130 NFD_LOG_WARN(
"Cannot close tcp4 channel after its creation");
136 if (wantListen && !v6Channel->isListening()) {
137 v6Channel->listen(this->
addFace,
nullptr);
142 NFD_LOG_WARN(
"Cannot close tcp6 channel after its creation");
154 NFD_LOG_TRACE(
"Cannot create unicast TCP face with LocalUri");
155 onFailure(406,
"Unicast TCP faces cannot be created with a LocalUri");
160 NFD_LOG_TRACE(
"createFace does not support FACE_PERSISTENCY_ON_DEMAND");
161 onFailure(406,
"Outgoing TCP faces do not support on-demand persistency");
169 BOOST_ASSERT(!endpoint.address().is_multicast());
172 NFD_LOG_TRACE(
"createFace cannot create non-local face with local fields enabled");
173 onFailure(406,
"Local fields can only be enabled on faces with local scope");
178 NFD_LOG_TRACE(
"createFace cannot create a TCP face with an overridden MTU");
179 onFailure(406,
"TCP faces do not support MTU overrides");
184 for (
const auto& i : m_channels) {
185 if ((i.first.address().is_v4() && endpoint.address().is_v4()) ||
186 (i.first.address().is_v6() && endpoint.address().is_v6())) {
187 i.second->connect(endpoint, req.
params, onCreated, onFailure);
192 NFD_LOG_TRACE(
"No channels available to connect to " << endpoint);
193 onFailure(504,
"No channels available to connect");
196 shared_ptr<TcpChannel>
199 auto it = m_channels.find(endpoint);
200 if (it != m_channels.end())
203 auto channel = make_shared<TcpChannel>(endpoint, m_wantCongestionMarking, [
this] (
auto&&... args) {
204 return determineFaceScopeFromAddresses(std::forward<decltype(args)>(args)...);
206 m_channels[endpoint] = channel;
210 std::vector<shared_ptr<const Channel>>
211 TcpFactory::doGetChannels()
const 217 TcpFactory::determineFaceScopeFromAddresses(
const boost::asio::ip::address& localAddress,
218 const boost::asio::ip::address& remoteAddress)
const 220 if (m_local(localAddress) && m_local(remoteAddress)) {
std::set< std::string > providedSchemes
FaceUri schemes provided by this protocol factory.
bool wantCongestionMarking
const std::string & getHost() const
get host (domain)
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_LOG_INIT(name)
GeneralConfig generalConfig
ndn::nfd::FacePersistency persistency
const std::string & getPort() const
get port
NFD_REGISTER_PROTOCOL_FACTORY(EthernetFactory)
std::function< void(uint32_t status, const std::string &reason)> FaceCreationFailedCallback
Prototype for the callback that is invoked when a face fails to be created.
boost::optional< const ConfigSection & > OptionalConfigSection
an optional config file section
FaceCreatedCallback addFace
callback when a new face is created
Protocol factory for TCP over IPv4 and IPv6.
Copyright (c) 2011-2015 Regents of the University of California.
boost::asio::ip::tcp::endpoint Endpoint
void assign(std::initializer_list< std::pair< std::string, std::string >> whitelist, std::initializer_list< std::pair< std::string, std::string >> blacklist)
void parseBlacklist(const boost::property_tree::ptree &list)
context for processing a config section in ProtocolFactory
Represents a predicate to accept or reject an IP address.
void parseWhitelist(const boost::property_tree::ptree &list)
Encapsulates a face creation request and all its parameters.
optional< FaceUri > localUri
std::function< void(const shared_ptr< Face > &)> FaceCreatedCallback
Prototype for the callback that is invoked when a face is created (in response to an incoming connect...
static std::vector< shared_ptr< const Channel > > getChannelsFromMap(const ChannelMap &channelMap)
shared_ptr< TcpChannel > createChannel(const tcp::Endpoint &localEndpoint)
Create TCP-based channel using tcp::Endpoint.
static const std::string & getId() noexcept