You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

293 lines
11 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright (c) 2014, Peter Thorson. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. * * Redistributions of source code must retain the above copyright
  7. * notice, this list of conditions and the following disclaimer.
  8. * * Redistributions in binary form must reproduce the above copyright
  9. * notice, this list of conditions and the following disclaimer in the
  10. * documentation and/or other materials provided with the distribution.
  11. * * Neither the name of the WebSocket++ Project nor the
  12. * names of its contributors may be used to endorse or promote products
  13. * derived from this software without specific prior written permission.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18. * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
  19. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  20. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  21. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  22. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. *
  26. */
  27. #ifndef WEBSOCKETPP_CONFIG_CORE_HPP
  28. #define WEBSOCKETPP_CONFIG_CORE_HPP
  29. // Non-Policy common stuff
  30. #include <websocketpp/common/cpp11.hpp>
  31. #include <websocketpp/common/platforms.hpp>
  32. #include <websocketpp/common/stdint.hpp>
  33. // Concurrency
  34. #include <websocketpp/concurrency/basic.hpp>
  35. // Transport
  36. #include <websocketpp/transport/iostream/endpoint.hpp>
  37. // HTTP
  38. #include <websocketpp/http/request.hpp>
  39. #include <websocketpp/http/response.hpp>
  40. // Messages
  41. #include <websocketpp/message_buffer/alloc.hpp>
  42. #include <websocketpp/message_buffer/message.hpp>
  43. // Loggers
  44. #include <websocketpp/logger/basic.hpp>
  45. #include <websocketpp/logger/levels.hpp>
  46. // RNG
  47. #include <websocketpp/random/none.hpp>
  48. // User stub base classes
  49. #include <websocketpp/connection_base.hpp>
  50. #include <websocketpp/endpoint_base.hpp>
  51. // Extensions
  52. #include <websocketpp/extensions/permessage_deflate/disabled.hpp>
  53. namespace websocketpp
  54. {
  55. namespace config
  56. {
  57. /// Server config with iostream transport
  58. struct core
  59. {
  60. typedef core type;
  61. // Concurrency policy
  62. typedef websocketpp::concurrency::basic concurrency_type;
  63. // HTTP Parser Policies
  64. typedef http::parser::request request_type;
  65. typedef http::parser::response response_type;
  66. // Message Policies
  67. typedef message_buffer::message<message_buffer::alloc::con_msg_manager> message_type;
  68. typedef message_buffer::alloc::con_msg_manager<message_type> con_msg_manager_type;
  69. typedef message_buffer::alloc::endpoint_msg_manager<con_msg_manager_type> endpoint_msg_manager_type;
  70. /// Logging policies
  71. typedef websocketpp::log::basic<concurrency_type, websocketpp::log::elevel> elog_type;
  72. typedef websocketpp::log::basic<concurrency_type, websocketpp::log::alevel> alog_type;
  73. /// RNG policies
  74. typedef websocketpp::random::none::int_generator<uint32_t> rng_type;
  75. /// Controls compile time enabling/disabling of thread syncronization
  76. /// code Disabling can provide a minor performance improvement to single
  77. /// threaded applications
  78. static const bool enable_multithreading = true;
  79. struct transport_config
  80. {
  81. typedef type::concurrency_type concurrency_type;
  82. typedef type::elog_type elog_type;
  83. typedef type::alog_type alog_type;
  84. typedef type::request_type request_type;
  85. typedef type::response_type response_type;
  86. /// Controls compile time enabling/disabling of thread syncronization
  87. /// code Disabling can provide a minor performance improvement to single
  88. /// threaded applications
  89. static const bool enable_multithreading = true;
  90. /// Default timer values (in ms)
  91. /// Length of time to wait for socket pre-initialization
  92. /**
  93. * Exactly what this includes depends on the socket policy in use
  94. */
  95. static const long timeout_socket_pre_init = 5000;
  96. /// Length of time to wait before a proxy handshake is aborted
  97. static const long timeout_proxy = 5000;
  98. /// Length of time to wait for socket post-initialization
  99. /**
  100. * Exactly what this includes depends on the socket policy in use.
  101. * Often this means the TLS handshake
  102. */
  103. static const long timeout_socket_post_init = 5000;
  104. /// Length of time to wait for dns resolution
  105. static const long timeout_dns_resolve = 5000;
  106. /// Length of time to wait for TCP connect
  107. static const long timeout_connect = 5000;
  108. /// Length of time to wait for socket shutdown
  109. static const long timeout_socket_shutdown = 5000;
  110. };
  111. /// Transport Endpoint Component
  112. typedef websocketpp::transport::iostream::endpoint<transport_config> transport_type;
  113. /// User overridable Endpoint base class
  114. typedef websocketpp::endpoint_base endpoint_base;
  115. /// User overridable Connection base class
  116. typedef websocketpp::connection_base connection_base;
  117. /// Default timer values (in ms)
  118. /// Length of time before an opening handshake is aborted
  119. static const long timeout_open_handshake = 5000;
  120. /// Length of time before a closing handshake is aborted
  121. static const long timeout_close_handshake = 5000;
  122. /// Length of time to wait for a pong after a ping
  123. static const long timeout_pong = 5000;
  124. /// WebSocket Protocol version to use as a client
  125. /**
  126. * What version of the WebSocket Protocol to use for outgoing client
  127. * connections. Setting this to a value other than 13 (RFC6455) is not
  128. * recommended.
  129. */
  130. static const int client_version = 13; // RFC6455
  131. /// Default static error logging channels
  132. /**
  133. * Which error logging channels to enable at compile time. Channels not
  134. * enabled here will be unable to be selected by programs using the library.
  135. * This option gives an optimizing compiler the ability to remove entirely
  136. * code to test whether or not to print out log messages on a certain
  137. * channel
  138. *
  139. * Default is all except for development/debug level errors
  140. */
  141. static const websocketpp::log::level elog_level = websocketpp::log::elevel::all ^ websocketpp::log::elevel::devel;
  142. /// Default static access logging channels
  143. /**
  144. * Which access logging channels to enable at compile time. Channels not
  145. * enabled here will be unable to be selected by programs using the library.
  146. * This option gives an optimizing compiler the ability to remove entirely
  147. * code to test whether or not to print out log messages on a certain
  148. * channel
  149. *
  150. * Default is all except for development/debug level access messages
  151. */
  152. static const websocketpp::log::level alog_level = websocketpp::log::alevel::all ^ websocketpp::log::alevel::devel;
  153. /// Size of the per-connection read buffer
  154. /**
  155. * Each connection has an internal buffer of this size. A larger value will
  156. * result in fewer trips through the library and less CPU overhead at the
  157. * expense of increased memory usage per connection.
  158. *
  159. * If your application primarily deals in very large messages you may want
  160. * to try setting this value higher.
  161. *
  162. * If your application has a lot of connections or primarily deals in small
  163. * messages you may want to try setting this smaller.
  164. */
  165. static const size_t connection_read_buffer_size = 16384;
  166. /// Drop connections immediately on protocol error.
  167. /**
  168. * Drop connections on protocol error rather than sending a close frame.
  169. * Off by default. This may result in legit messages near the error being
  170. * dropped as well. It may free up resources otherwise spent dealing with
  171. * misbehaving clients.
  172. */
  173. static const bool drop_on_protocol_error = false;
  174. /// Suppresses the return of detailed connection close information
  175. /**
  176. * Silence close suppresses the return of detailed connection close
  177. * information during the closing handshake. This information is useful
  178. * for debugging and presenting useful errors to end users but may be
  179. * undesirable for security reasons in some production environments.
  180. * Close reasons could be used by an attacker to confirm that the endpoint
  181. * is out of resources or be used to identify the WebSocket implementation
  182. * in use.
  183. *
  184. * Note: this will suppress *all* close codes, including those explicitly
  185. * sent by local applications.
  186. */
  187. static const bool silent_close = false;
  188. /// Default maximum message size
  189. /**
  190. * Default value for the processor's maximum message size. Maximum message size
  191. * determines the point at which the library will fail a connection with the
  192. * message_too_big protocol error.
  193. *
  194. * The default is 32MB
  195. *
  196. * @since 0.3.0
  197. */
  198. static const size_t max_message_size = 32000000;
  199. /// Default maximum http body size
  200. /**
  201. * Default value for the http parser's maximum body size. Maximum body size
  202. * determines the point at which the library will abort reading an HTTP
  203. * connection with the 413/request entity too large error.
  204. *
  205. * The default is 32MB
  206. *
  207. * @since 0.5.0
  208. */
  209. static const size_t max_http_body_size = 32000000;
  210. /// Global flag for enabling/disabling extensions
  211. static const bool enable_extensions = true;
  212. /// Extension specific settings:
  213. /// permessage_compress extension
  214. struct permessage_deflate_config
  215. {
  216. typedef core::request_type request_type;
  217. /// If the remote endpoint requests that we reset the compression
  218. /// context after each message should we honor the request?
  219. static const bool allow_disabling_context_takeover = true;
  220. /// If the remote endpoint requests that we reduce the size of the
  221. /// LZ77 sliding window size this is the lowest value that will be
  222. /// allowed. Values range from 8 to 15. A value of 8 means we will
  223. /// allow any possible window size. A value of 15 means do not allow
  224. /// negotiation of the window size (ie require the default).
  225. static const uint8_t minimum_outgoing_window_bits = 8;
  226. };
  227. typedef websocketpp::extensions::permessage_deflate::disabled<permessage_deflate_config> permessage_deflate_type;
  228. /// Autonegotiate permessage-deflate
  229. /**
  230. * Automatically enables the permessage-deflate extension.
  231. *
  232. * For clients this results in a permessage-deflate extension request being
  233. * sent with every request rather than requiring it to be requested manually
  234. *
  235. * For servers this results in accepting the first set of extension settings
  236. * requested by the client that we understand being used. The alternative is
  237. * requiring the extension to be manually negotiated in `validate`. With
  238. * auto-negotiate on, you may still override the auto-negotiate manually if
  239. * needed.
  240. */
  241. // static const bool autonegotiate_compression = false;
  242. };
  243. } // namespace config
  244. } // namespace websocketpp
  245. #endif // WEBSOCKETPP_CONFIG_CORE_HPP