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())) {
84 websocketpp::lib::error_code error;
85 m_server.send(m_handle, packet.packet.wire(), packet.packet.size(),
86 websocketpp::frame::opcode::binary, error);
88 return processErrorCode(error);
100 std::tie(isOk, element) =
Block::fromBuffer(reinterpret_cast<const uint8_t*>(msg.data()), msg.size());
110 WebSocketTransport::schedulePing()
116 WebSocketTransport::sendPing()
120 websocketpp::lib::error_code error;
121 m_server.ping(m_handle,
"NFD-WebSocket", error);
123 return processErrorCode(error);
127 this->schedulePing();
147 WebSocketTransport::processErrorCode(
const websocketpp::lib::error_code& error)
170 websocketpp::lib::error_code error;
171 m_server.close(m_handle, websocketpp::close::status::normal,
"closed by NFD", error);
void setPersistency(ndn::nfd::FacePersistency newPersistency)
changes face persistency setting
static std::tuple< bool, Block > fromBuffer(ConstBufferPtr buffer, size_t offset)
Try to parse Block from a wire buffer.
#define NFD_LOG_FACE_TRACE(msg)
Log a message at TRACE level.
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
#define NFD_LOG_FACE_ERROR(msg)
Log a message at ERROR level.
stores a packet along with the remote endpoint
Represents a TLV element of NDN 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)
#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 cancel()
Cancel the operation.
void setLocalUri(const FaceUri &uri)
PacketCounter nOutPings
count of outgoing Pings
PacketCounter nInPongs
count of incoming Pongs
the transport is being closed gracefully, either by the peer or by a call to close()
represents the underlying protocol and address used by a Face
EventId schedule(time::nanoseconds after, const EventCallback &event)
Schedule an event.
A Transport that communicates on a WebSocket connection.
void setState(TransportState newState)
set transport state
void receive(Packet &&packet)
receive a link-layer packet
#define NFD_LOG_INIT(name)
void doClose() final
performs Transport specific operations to close the transport
#define NFD_LOG_FACE_WARN(msg)
Log a message at WARN level.