It's overkill and suffers from annoying false positives that
prevent us from applying the "protected non-virtual destructor"
idiom in several perfectly valid cases. See for instance the
GCC bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102168
The -Wdelete-non-virtual-dtor warning (included in -Wall) is
the preferred alternative and is enough to catch the unsafe
cases without false positives.
Partially reverts 847de408cb
Change-Id: I46ee1f01e7d4e2b125c2c534c6550824ba1de4c0
133 lines
3.7 KiB
C++
133 lines
3.7 KiB
C++
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
|
/*
|
|
* Copyright (c) 2014-2023, Regents of the University of California,
|
|
* Arizona Board of Regents,
|
|
* Colorado State University,
|
|
* University Pierre & Marie Curie, Sorbonne University,
|
|
* Washington University in St. Louis,
|
|
* Beijing Institute of Technology,
|
|
* The University of Memphis.
|
|
*
|
|
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
|
* See AUTHORS.md for complete list of NFD authors and contributors.
|
|
*
|
|
* NFD is free software: you can redistribute it and/or modify it under the terms
|
|
* of the GNU General Public License as published by the Free Software Foundation,
|
|
* either version 3 of the License, or (at your option) any later version.
|
|
*
|
|
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along with
|
|
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef NFD_DAEMON_FACE_INTERNAL_TRANSPORT_HPP
|
|
#define NFD_DAEMON_FACE_INTERNAL_TRANSPORT_HPP
|
|
|
|
#include "transport.hpp"
|
|
|
|
#include <ndn-cxx/transport/transport.hpp>
|
|
|
|
namespace nfd::face {
|
|
|
|
/**
|
|
* \brief Abstracts a transport that can be paired with another.
|
|
*/
|
|
class InternalTransportBase
|
|
{
|
|
public:
|
|
virtual void
|
|
receivePacket(const Block& packet) = 0;
|
|
|
|
protected:
|
|
~InternalTransportBase() = default;
|
|
};
|
|
|
|
/**
|
|
* \brief Implements a forwarder-side transport that can be paired with another transport.
|
|
*/
|
|
class InternalForwarderTransport final : public Transport, public InternalTransportBase
|
|
{
|
|
public:
|
|
explicit
|
|
InternalForwarderTransport(const FaceUri& localUri = FaceUri("internal://"),
|
|
const FaceUri& remoteUri = FaceUri("internal://"),
|
|
ndn::nfd::FaceScope scope = ndn::nfd::FACE_SCOPE_LOCAL,
|
|
ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_POINT_TO_POINT);
|
|
|
|
void
|
|
setPeer(InternalTransportBase* peer) noexcept
|
|
{
|
|
m_peer = peer;
|
|
}
|
|
|
|
void
|
|
receivePacket(const Block& packet) final;
|
|
|
|
protected:
|
|
void
|
|
doClose() final;
|
|
|
|
private:
|
|
void
|
|
doSend(const Block& packet) final;
|
|
|
|
private:
|
|
NFD_LOG_MEMBER_DECL();
|
|
|
|
InternalTransportBase* m_peer = nullptr;
|
|
};
|
|
|
|
/**
|
|
* \brief Implements a client-side transport that can be paired with an InternalForwarderTransport.
|
|
*/
|
|
class InternalClientTransport final : public ndn::Transport, public InternalTransportBase
|
|
{
|
|
public:
|
|
~InternalClientTransport() final;
|
|
|
|
/** \brief Connect to a forwarder-side transport.
|
|
* \param forwarder the forwarder-side transport to connect to; may be nullptr
|
|
*
|
|
* The connected forwarder-side transport will be disconnected automatically if this method
|
|
* is called again, or if that transport is closed.
|
|
* It's safe to use InternalClientTransport without a connected forwarder-side transport:
|
|
* all sent packets would be lost, and nothing would be received.
|
|
*/
|
|
void
|
|
connectToForwarder(InternalForwarderTransport* forwarder);
|
|
|
|
void
|
|
receivePacket(const Block& packet) final;
|
|
|
|
void
|
|
send(const Block& block) final;
|
|
|
|
void
|
|
close() final
|
|
{
|
|
}
|
|
|
|
void
|
|
pause() final
|
|
{
|
|
}
|
|
|
|
void
|
|
resume() final
|
|
{
|
|
}
|
|
|
|
private:
|
|
NFD_LOG_MEMBER_DECL();
|
|
|
|
InternalForwarderTransport* m_forwarder = nullptr;
|
|
signal::ScopedConnection m_fwTransportStateConn;
|
|
};
|
|
|
|
} // namespace nfd::face
|
|
|
|
#endif // NFD_DAEMON_FACE_INTERNAL_TRANSPORT_HPP
|