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();
59 this->
setLocalUri(FaceUri(sock.local_endpoint(),
"ws"));
60 this->
setRemoteUri(FaceUri(sock.remote_endpoint(),
"wsclient"));
62 if (
isLoopback(sock.local_endpoint().address()) &&
63 isLoopback(sock.remote_endpoint().address())) {
64 this->
setScope(ndn::nfd::FACE_SCOPE_LOCAL);
67 this->
setScope(ndn::nfd::FACE_SCOPE_NON_LOCAL);
71 this->
setLinkType(ndn::nfd::LINK_TYPE_POINT_TO_POINT);
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.c_str()), msg.size());
110 WebSocketTransport::schedulePing()
112 m_pingEventId =
scheduler::schedule(m_pingInterval, bind(&WebSocketTransport::sendPing,
this));
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 receiveMessage(const std::string &msg)
Translates a message into a Block and delivers it to the link service.
void setLocalUri(const FaceUri &uri)
#define NFD_LOG_FACE_TRACE(msg)
Log a message at TRACE level.
void setScope(ndn::nfd::FaceScope scope)
const ssize_t MTU_UNLIMITED
indicates the transport has no limit on payload size
websocketpp::server< websocketpp::config::asio > Server
void doClose() final
performs Transport specific operations to close the transport
WebSocketTransport(websocketpp::connection_hdl hdl, websocket::Server &server, time::milliseconds pingInterval)
void receive(Packet &&packet)
receive a link-layer packet
stores a packet along with the remote endpoint
the transport is being closed due to a failure
#define NFD_LOG_FACE_WARN(msg)
Log a message at WARN level.
static bool isLoopback(const boost::asio::ip::address &addr)
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
the transport is closed, and can be safely deallocated
#define NFD_LOG_FACE_INFO(msg)
Log a message at INFO level.
void setLinkType(ndn::nfd::LinkType linkType)
the transport is being closed gracefully, either by the peer or by a call to close() ...
void setPersistency(ndn::nfd::FacePersistency newPersistency)
changes face persistency setting
#define NFD_LOG_INIT(name)
EventId schedule(time::nanoseconds after, const EventCallback &event)
schedule an event
TransportState getState() const
void setState(TransportState newState)
set transport state
void setRemoteUri(const FaceUri &uri)
PacketCounter nOutPings
count of outgoing Pings
void cancel()
cancels the event manually
PacketCounter nInPongs
count of incoming Pongs
#define NFD_LOG_FACE_ERROR(msg)
Log a message at ERROR level.