NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
main.cpp
Go to the documentation of this file.
1 //#ifndef _WEBSOCKETPP_CPP11_STL_
2 // #define _WEBSOCKETPP_CPP11_STL_
3 //#endif
4 
5 #include <random>
6 #include <boost/timer/timer.hpp>
7 
9 
10 //#include <websocketpp/security/none.hpp>
11 
12 //#include <websocketpp/concurrency/none.hpp>
13 //#include <websocketpp/concurrency/stl.hpp>
14 
15 //#include <websocketpp/transport/iostream.hpp>
16 #include <websocketpp/server.hpp>
17 
18 #include <iostream>
19 #include <sstream>
20 
21 //typedef websocketpp::concurrency::stl concurrency;
22 //typedef websocketpp::transport::iostream<concurrency> transport;
23 //typedef websocketpp::server<concurrency,transport> server;
25 
26 /*class handler : public server::handler {
27  bool validate(connection_ptr con) {
28  std::cout << "handler validate" << std::endl;
29  if (con->get_origin() != "http://www.example.com") {
30  con->set_status(websocketpp::http::status_code::FORBIDDEN);
31  return false;
32  }
33  return true;
34  }
35 
36  void http(connection_ptr con) {
37  std::cout << "handler http" << std::endl;
38  }
39 
40  void on_load(connection_ptr con, ptr old_handler) {
41  std::cout << "handler on_load" << std::endl;
42  }
43  void on_unload(connection_ptr con, ptr new_handler) {
44  std::cout << "handler on_unload" << std::endl;
45  }
46 
47  void on_open(connection_ptr con) {
48  std::cout << "handler on_open" << std::endl;
49  }
50  void on_fail(connection_ptr con) {
51  std::cout << "handler on_fail" << std::endl;
52  }
53 
54  void on_message(connection_ptr con, message_ptr msg) {
55  std::cout << "handler on_message" << std::endl;
56 
57 
58  }
59 
60  void on_close(connection_ptr con) {
61  std::cout << "handler on_close" << std::endl;
62  }
63 };*/
64 
65 int main() {
67  message_type;
69  con_msg_man_type;
70 
71  con_msg_man_type::ptr manager = websocketpp::lib::make_shared<con_msg_man_type>();
72 
73  size_t foo = 1024;
74 
75  message_type::ptr input = manager->get_message(websocketpp::frame::opcode::TEXT,foo);
76  message_type::ptr output = manager->get_message(websocketpp::frame::opcode::TEXT,foo);
78 
79  std::random_device dev;
80 
81 
82 
83  key.i = 0x12345678;
84 
85  double m = 18094238402394.0824923;
86 
87  /*std::cout << "Some Math" << std::endl;
88  {
89  boost::timer::auto_cpu_timer t;
90 
91  for (int i = 0; i < foo; i++) {
92  m /= 1.001;
93  }
94 
95  }*/
96 
97  std::cout << m << std::endl;
98 
99  std::cout << "Random Gen" << std::endl;
100  {
101  boost::timer::auto_cpu_timer t;
102 
103  input->get_raw_payload().replace(0,foo,foo,'\0');
104  output->get_raw_payload().replace(0,foo,foo,'\0');
105  }
106 
107  std::cout << "Out of place accelerated" << std::endl;
108  {
109  boost::timer::auto_cpu_timer t;
110 
111  websocketpp::frame::word_mask_exact(reinterpret_cast<uint8_t*>(const_cast<char*>(input->get_raw_payload().data())), reinterpret_cast<uint8_t*>(const_cast<char*>(output->get_raw_payload().data())), foo, key);
112  }
113 
114  std::cout << websocketpp::utility::to_hex(input->get_payload().c_str(),20) << std::endl;
115  std::cout << websocketpp::utility::to_hex(output->get_payload().c_str(),20) << std::endl;
116 
117  input->get_raw_payload().replace(0,foo,foo,'\0');
118  output->get_raw_payload().replace(0,foo,foo,'\0');
119 
120  std::cout << "In place accelerated" << std::endl;
121  {
122  boost::timer::auto_cpu_timer t;
123 
124  websocketpp::frame::word_mask_exact(reinterpret_cast<uint8_t*>(const_cast<char*>(input->get_raw_payload().data())), reinterpret_cast<uint8_t*>(const_cast<char*>(input->get_raw_payload().data())), foo, key);
125  }
126 
127  std::cout << websocketpp::utility::to_hex(input->get_payload().c_str(),20) << std::endl;
128  std::cout << websocketpp::utility::to_hex(output->get_payload().c_str(),20) << std::endl;
129 
130  input->get_raw_payload().replace(0,foo,foo,'\0');
131  output->get_raw_payload().replace(0,foo,foo,'\0');
132  std::cout << "Out of place byte by byte" << std::endl;
133  {
134  boost::timer::auto_cpu_timer t;
135 
136  websocketpp::frame::byte_mask(input->get_raw_payload().begin(), input->get_raw_payload().end(), output->get_raw_payload().begin(), key);
137  }
138 
139  std::cout << websocketpp::utility::to_hex(input->get_payload().c_str(),20) << std::endl;
140  std::cout << websocketpp::utility::to_hex(output->get_payload().c_str(),20) << std::endl;
141 
142  input->get_raw_payload().replace(0,foo,foo,'\0');
143  output->get_raw_payload().replace(0,foo,foo,'\0');
144  std::cout << "In place byte by byte" << std::endl;
145  {
146  boost::timer::auto_cpu_timer t;
147 
148  websocketpp::frame::byte_mask(input->get_raw_payload().begin(), input->get_raw_payload().end(), input->get_raw_payload().begin(), key);
149  }
150 
151  std::cout << websocketpp::utility::to_hex(input->get_payload().c_str(),20) << std::endl;
152  std::cout << websocketpp::utility::to_hex(output->get_payload().c_str(),20) << std::endl;
153 
154  input->get_raw_payload().replace(0,foo,foo,'a');
155  output->get_raw_payload().replace(0,foo,foo,'b');
156  std::cout << "Copy" << std::endl;
157  {
158  boost::timer::auto_cpu_timer t;
159 
160  std::copy(input->get_raw_payload().begin(), input->get_raw_payload().end(), output->get_raw_payload().begin());
161  }
162 
163  std::cout << websocketpp::utility::to_hex(input->get_payload().c_str(),20) << std::endl;
164  std::cout << websocketpp::utility::to_hex(output->get_payload().c_str(),20) << std::endl;
165 
166  /*server::handler::ptr h(new handler());
167 
168  server test_server(h);
169  server::connection_ptr con;
170 
171  std::stringstream output;
172 
173  test_server.register_ostream(&output);
174 
175  con = test_server.get_connection();
176 
177  con->start();
178 
179  //foo.handle_accept(con,true);
180 
181  std::stringstream input;
182  input << "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: Upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\nOrigin: http://www.example.com\r\n\r\n";
183  //input << "GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n";
184  input >> *con;
185 
186  std::stringstream input2;
187  input2 << "messageabc2";
188  input2 >> *con;
189 
190  std::stringstream input3;
191  input3 << "messageabc3";
192  input3 >> *con;
193 
194  std::stringstream input4;
195  input4 << "close";
196  input4 >> *con;
197 
198  std::cout << "connection output:" << std::endl;
199  std::cout << output.str() << std::endl;*/
200 }
websocketpp::server< websocketpp::config::core > server
Definition: main.cpp:24
int main(int argc, char **argv)
Definition: main.cpp:248
std::string to_hex(std::string const &input)
Convert std::string to ascii printed string of hex digits.
Four byte conversion union.
Definition: frame.hpp:61
void byte_mask(input_iter b, input_iter e, output_iter o, masking_key_type const &key, size_t key_offset=0)
Byte by byte mask/unmask.
Definition: frame.hpp:645
message_ptr get_message()
Get an empty message buffer.
Definition: alloc.hpp:55
void word_mask_exact(uint8_t *input, uint8_t *output, size_t length, masking_key_type const &key)
Exact word aligned mask/unmask.
Definition: frame.hpp:702
Server endpoint role based on the given config.
Represents a buffer for a single WebSocket message.
Definition: message.hpp:84
A connection message manager that allocates a new message for each request.
Definition: alloc.hpp:41