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.

297 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/platforms.hpp>
  31. #include <websocketpp/common/cpp11.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/message.hpp>
  42. #include <websocketpp/message_buffer/alloc.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/endpoint_base.hpp>
  50. #include <websocketpp/connection_base.hpp>
  51. // Extensions
  52. #include <websocketpp/extensions/permessage_deflate/disabled.hpp>
  53. namespace websocketpp {
  54. namespace config {
  55. /// Server config with iostream transport
  56. struct core {
  57. typedef core type;
  58. // Concurrency policy
  59. typedef websocketpp::concurrency::basic concurrency_type;
  60. // HTTP Parser Policies
  61. typedef http::parser::request request_type;
  62. typedef http::parser::response response_type;
  63. // Message Policies
  64. typedef message_buffer::message<message_buffer::alloc::con_msg_manager>
  65. message_type;
  66. typedef message_buffer::alloc::con_msg_manager<message_type>
  67. con_msg_manager_type;
  68. typedef message_buffer::alloc::endpoint_msg_manager<con_msg_manager_type>
  69. endpoint_msg_manager_type;
  70. /// Logging policies
  71. typedef websocketpp::log::basic<concurrency_type,
  72. websocketpp::log::elevel> elog_type;
  73. typedef websocketpp::log::basic<concurrency_type,
  74. websocketpp::log::alevel> alog_type;
  75. /// RNG policies
  76. typedef websocketpp::random::none::int_generator<uint32_t> rng_type;
  77. /// Controls compile time enabling/disabling of thread syncronization
  78. /// code Disabling can provide a minor performance improvement to single
  79. /// threaded applications
  80. static bool const enable_multithreading = true;
  81. struct transport_config {
  82. typedef type::concurrency_type concurrency_type;
  83. typedef type::elog_type elog_type;
  84. typedef type::alog_type alog_type;
  85. typedef type::request_type request_type;
  86. typedef type::response_type response_type;
  87. /// Controls compile time enabling/disabling of thread syncronization
  88. /// code Disabling can provide a minor performance improvement to single
  89. /// threaded applications
  90. static bool const enable_multithreading = true;
  91. /// Default timer values (in ms)
  92. /// Length of time to wait for socket pre-initialization
  93. /**
  94. * Exactly what this includes depends on the socket policy in use
  95. */
  96. static const long timeout_socket_pre_init = 5000;
  97. /// Length of time to wait before a proxy handshake is aborted
  98. static const long timeout_proxy = 5000;
  99. /// Length of time to wait for socket post-initialization
  100. /**
  101. * Exactly what this includes depends on the socket policy in use.
  102. * Often this means the TLS handshake
  103. */
  104. static const long timeout_socket_post_init = 5000;
  105. /// Length of time to wait for dns resolution
  106. static const long timeout_dns_resolve = 5000;
  107. /// Length of time to wait for TCP connect
  108. static const long timeout_connect = 5000;
  109. /// Length of time to wait for socket shutdown
  110. static const long timeout_socket_shutdown = 5000;
  111. };
  112. /// Transport Endpoint Component
  113. typedef websocketpp::transport::iostream::endpoint<transport_config>
  114. transport_type;
  115. /// User overridable Endpoint base class
  116. typedef websocketpp::endpoint_base endpoint_base;
  117. /// User overridable Connection base class
  118. typedef websocketpp::connection_base connection_base;
  119. /// Default timer values (in ms)
  120. /// Length of time before an opening handshake is aborted
  121. static const long timeout_open_handshake = 5000;
  122. /// Length of time before a closing handshake is aborted
  123. static const long timeout_close_handshake = 5000;
  124. /// Length of time to wait for a pong after a ping
  125. static const long timeout_pong = 5000;
  126. /// WebSocket Protocol version to use as a client
  127. /**
  128. * What version of the WebSocket Protocol to use for outgoing client
  129. * connections. Setting this to a value other than 13 (RFC6455) is not
  130. * recommended.
  131. */
  132. static const int client_version = 13; // RFC6455
  133. /// Default static error logging channels
  134. /**
  135. * Which error logging channels to enable at compile time. Channels not
  136. * enabled here will be unable to be selected by programs using the library.
  137. * This option gives an optimizing compiler the ability to remove entirely
  138. * code to test whether or not to print out log messages on a certain
  139. * channel
  140. *
  141. * Default is all except for development/debug level errors
  142. */
  143. static const websocketpp::log::level elog_level =
  144. websocketpp::log::elevel::all ^ websocketpp::log::elevel::devel;
  145. /// Default static access logging channels
  146. /**
  147. * Which access logging channels to enable at compile time. Channels not
  148. * enabled here will be unable to be selected by programs using the library.
  149. * This option gives an optimizing compiler the ability to remove entirely
  150. * code to test whether or not to print out log messages on a certain
  151. * channel
  152. *
  153. * Default is all except for development/debug level access messages
  154. */
  155. static const websocketpp::log::level alog_level =
  156. websocketpp::log::alevel::all ^ websocketpp::log::alevel::devel;
  157. /// Size of the per-connection read buffer
  158. /**
  159. * Each connection has an internal buffer of this size. A larger value will
  160. * result in fewer trips through the library and less CPU overhead at the
  161. * expense of increased memory usage per connection.
  162. *
  163. * If your application primarily deals in very large messages you may want
  164. * to try setting this value higher.
  165. *
  166. * If your application has a lot of connections or primarily deals in small
  167. * messages you may want to try setting this smaller.
  168. */
  169. static const size_t connection_read_buffer_size = 16384;
  170. /// Drop connections immediately on protocol error.
  171. /**
  172. * Drop connections on protocol error rather than sending a close frame.
  173. * Off by default. This may result in legit messages near the error being
  174. * dropped as well. It may free up resources otherwise spent dealing with
  175. * misbehaving clients.
  176. */
  177. static const bool drop_on_protocol_error = false;
  178. /// Suppresses the return of detailed connection close information
  179. /**
  180. * Silence close suppresses the return of detailed connection close
  181. * information during the closing handshake. This information is useful
  182. * for debugging and presenting useful errors to end users but may be
  183. * undesirable for security reasons in some production environments.
  184. * Close reasons could be used by an attacker to confirm that the endpoint
  185. * is out of resources or be used to identify the WebSocket implementation
  186. * in use.
  187. *
  188. * Note: this will suppress *all* close codes, including those explicitly
  189. * sent by local applications.
  190. */
  191. static const bool silent_close = false;
  192. /// Default maximum message size
  193. /**
  194. * Default value for the processor's maximum message size. Maximum message size
  195. * determines the point at which the library will fail a connection with the
  196. * message_too_big protocol error.
  197. *
  198. * The default is 32MB
  199. *
  200. * @since 0.3.0
  201. */
  202. static const size_t max_message_size = 32000000;
  203. /// Default maximum http body size
  204. /**
  205. * Default value for the http parser's maximum body size. Maximum body size
  206. * determines the point at which the library will abort reading an HTTP
  207. * connection with the 413/request entity too large error.
  208. *
  209. * The default is 32MB
  210. *
  211. * @since 0.5.0
  212. */
  213. static const size_t max_http_body_size = 32000000;
  214. /// Global flag for enabling/disabling extensions
  215. static const bool enable_extensions = true;
  216. /// Extension specific settings:
  217. /// permessage_compress extension
  218. struct permessage_deflate_config {
  219. typedef core::request_type request_type;
  220. /// If the remote endpoint requests that we reset the compression
  221. /// context after each message should we honor the request?
  222. static const bool allow_disabling_context_takeover = true;
  223. /// If the remote endpoint requests that we reduce the size of the
  224. /// LZ77 sliding window size this is the lowest value that will be
  225. /// allowed. Values range from 8 to 15. A value of 8 means we will
  226. /// allow any possible window size. A value of 15 means do not allow
  227. /// negotiation of the window size (ie require the default).
  228. static const uint8_t minimum_outgoing_window_bits = 8;
  229. };
  230. typedef websocketpp::extensions::permessage_deflate::disabled
  231. <permessage_deflate_config> permessage_deflate_type;
  232. /// Autonegotiate permessage-deflate
  233. /**
  234. * Automatically enables the permessage-deflate extension.
  235. *
  236. * For clients this results in a permessage-deflate extension request being
  237. * sent with every request rather than requiring it to be requested manually
  238. *
  239. * For servers this results in accepting the first set of extension settings
  240. * requested by the client that we understand being used. The alternative is
  241. * requiring the extension to be manually negotiated in `validate`. With
  242. * auto-negotiate on, you may still override the auto-negotiate manually if
  243. * needed.
  244. */
  245. //static const bool autonegotiate_compression = false;
  246. };
  247. } // namespace config
  248. } // namespace websocketpp
  249. #endif // WEBSOCKETPP_CONFIG_CORE_HPP