core.hpp 11 KB

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