36 if (addr.is_loopback()) {
41 else if (addr.is_v6()) {
42 auto addr6 = addr.to_v6();
43 if (addr6.is_v4_mapped()) {
44 return addr6.to_v4().is_loopback();
53 time::milliseconds pingInterval)
56 , m_pingInterval(pingInterval)
58 const auto& sock = m_server.get_con_from_hdl(hdl)->get_socket();
62 if (
isLoopback(sock.local_endpoint().address()) &&
63 isLoopback(sock.remote_endpoint().address())) {
83 BOOST_THROW_EXCEPTION(
84 std::invalid_argument(
"WebSocketTransport supports only FACE_PERSISTENCY_ON_DEMAND"));
93 websocketpp::lib::error_code error;
94 m_server.send(m_handle, packet.packet.wire(), packet.packet.size(),
95 websocketpp::frame::opcode::binary, error);
97 return processErrorCode(error);
109 std::tie(isOk, element) =
Block::fromBuffer(reinterpret_cast<const uint8_t*>(msg.c_str()), msg.size());
119 WebSocketTransport::schedulePing()
121 m_pingEventId =
scheduler::schedule(m_pingInterval, bind(&WebSocketTransport::sendPing,
this));
125 WebSocketTransport::sendPing()
131 websocketpp::lib::error_code error;
132 m_server.ping(m_handle,
"NFD-WebSocket", error);
134 return processErrorCode(error);
136 this->schedulePing();
156 WebSocketTransport::processErrorCode(
const websocketpp::lib::error_code& error)
180 websocketpp::lib::error_code error;
181 m_server.close(m_handle, websocketpp::close::status::normal,
"closed by NFD", error);
void cancel()
cancels the event manually
static std::tuple< bool, Block > fromBuffer(ConstBufferPtr buffer, size_t offset)
Try to construct block from Buffer.
#define NFD_LOG_FACE_TRACE(msg)
Log a message at TRACE level.
void setPersistency(ndn::nfd::FacePersistency persistency)
changes face persistency setting
const ssize_t MTU_UNLIMITED
indicates the transport has no limit on payload size
void setRemoteUri(const FaceUri &uri)
websocketpp::server< websocketpp::config::asio > Server
represents the underlying protocol and address used by a Face
stores a packet along with the remote endpoint
Class representing a wire element of NDN-TLV packet format.
WebSocketTransport(websocketpp::connection_hdl hdl, websocket::Server &server, time::milliseconds pingInterval)
void setLinkType(ndn::nfd::LinkType linkType)
void receiveMessage(const std::string &msg)
Translates a message into a Block and delivers it to the link service.
the transport is being closed due to a failure
void setScope(ndn::nfd::FaceScope scope)
static bool isLoopback(const boost::asio::ip::address &addr)
virtual void beforeChangePersistency(ndn::nfd::FacePersistency newPersistency) final
invoked before persistency is changed
#define NFD_LOG_FACE_INFO(msg)
Log a message at INFO level.
TransportState getState() const
Copyright (c) 2011-2015 Regents of the University of California.
the transport is closed, and can be safely deallocated
void setLocalUri(const FaceUri &uri)
PacketCounter nOutPings
count of outgoing Pings
PacketCounter nInPongs
count of incoming Pongs
the transport is requested to be closed
EventId schedule(const time::nanoseconds &after, const Scheduler::Event &event)
schedule an event
void setState(TransportState newState)
set transport state
void receive(Packet &&packet)
receive a link-layer packet
#define NFD_LOG_INIT(name)
virtual void doClose() final
performs Transport specific operations to close the transport
#define NFD_LOG_FACE_WARN(msg)
Log a message at WARN level.