NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
websocket-factory.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #include "websocket-factory.hpp"
27 
28 namespace nfd {
29 
30 namespace ip = boost::asio::ip;
31 
32 shared_ptr<WebSocketChannel>
34 {
35  auto channel = findChannel(endpoint);
36  if (channel)
37  return channel;
38 
39  channel = make_shared<WebSocketChannel>(endpoint);
40  m_channels[endpoint] = channel;
41 
42  return channel;
43 }
44 
45 shared_ptr<WebSocketChannel>
46 WebSocketFactory::createChannel(const std::string& localIp, const std::string& localPort)
47 {
48  websocket::Endpoint endpoint(ip::address::from_string(localIp),
49  boost::lexical_cast<uint16_t>(localPort));
50  return createChannel(endpoint);
51 }
52 
53 void
55  ndn::nfd::FacePersistency persistency,
56  bool wantLocalFieldsEnabled,
57  const FaceCreatedCallback& onCreated,
58  const FaceCreationFailedCallback& onFailure)
59 {
60  onFailure(406, "Unsupported protocol");
61 }
62 
63 std::vector<shared_ptr<const Channel>>
65 {
66  std::vector<shared_ptr<const Channel>> channels;
67  channels.reserve(m_channels.size());
68 
69  for (const auto& i : m_channels)
70  channels.push_back(i.second);
71 
72  return channels;
73 }
74 
75 shared_ptr<WebSocketChannel>
76 WebSocketFactory::findChannel(const websocket::Endpoint& endpoint) const
77 {
78  auto i = m_channels.find(endpoint);
79  if (i != m_channels.end())
80  return i->second;
81  else
82  return nullptr;
83 }
84 
85 } // namespace nfd
virtual std::vector< shared_ptr< const Channel > > getChannels() const override
represents the underlying protocol and address used by a Face
Definition: face-uri.hpp:44
shared_ptr< WebSocketChannel > createChannel(const websocket::Endpoint &localEndpoint)
Create WebSocket-based channel using websocket::Endpoint.
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
function< void(uint32_t status, const std::string &reason)> FaceCreationFailedCallback
Prototype for the callback that is invoked when the face fails to be created.
Definition: channel.hpp:44
virtual void createFace(const FaceUri &uri, ndn::nfd::FacePersistency persistency, bool wantLocalFieldsEnabled, const FaceCreatedCallback &onCreated, const FaceCreationFailedCallback &onFailure) override
Try to create Face using the supplied FaceUri.
function< void(const shared_ptr< Face > &newFace)> FaceCreatedCallback
Prototype for the callback that is invoked when the face is created (as a response to incoming connec...
Definition: channel.hpp:38
boost::asio::ip::tcp::endpoint Endpoint