|
36 | 36 | connection_info_all/0, connection_info_all/1, |
37 | 37 | emit_connection_info_all/4, emit_connection_info_local/3, |
38 | 38 | close_connection/2, force_connection_event_refresh/1, accept_ack/2, |
39 | | - tcp_host/1]). |
| 39 | + handshake/2, tcp_host/1]). |
40 | 40 |
|
41 | 41 | %% Used by TCP-based transports, e.g. STOMP adapter |
42 | 42 | -export([tcp_listener_addresses/1, tcp_listener_spec/9, |
@@ -122,7 +122,6 @@ boot() -> |
122 | 122 | %% Failures will throw exceptions |
123 | 123 | _ = boot_listeners(fun boot_tcp/1, application:get_env(rabbit, num_tcp_acceptors, 10), "TCP"), |
124 | 124 | _ = boot_listeners(fun boot_tls/1, application:get_env(rabbit, num_ssl_acceptors, 10), "TLS"), |
125 | | - _ = maybe_start_proxy_protocol(), |
126 | 125 | ok. |
127 | 126 |
|
128 | 127 | boot_listeners(Fun, NumAcceptors, Type) -> |
@@ -191,12 +190,6 @@ log_poodle_fail(Context) -> |
191 | 190 | "'rabbit' section of your configuration file.~n", |
192 | 191 | [rabbit_misc:otp_release(), Context]). |
193 | 192 |
|
194 | | -maybe_start_proxy_protocol() -> |
195 | | - case application:get_env(rabbit, proxy_protocol, false) of |
196 | | - false -> ok; |
197 | | - true -> application:start(ranch_proxy_protocol) |
198 | | - end. |
199 | | - |
200 | 193 | fix_ssl_options(Config) -> |
201 | 194 | rabbit_ssl_options:fix(Config). |
202 | 195 |
|
@@ -264,12 +257,9 @@ start_listener0(Address, NumAcceptors, Protocol, Label, Opts) -> |
264 | 257 | end. |
265 | 258 |
|
266 | 259 | transport(Protocol) -> |
267 | | - ProxyProtocol = application:get_env(rabbit, proxy_protocol, false), |
268 | | - case {Protocol, ProxyProtocol} of |
269 | | - {amqp, false} -> ranch_tcp; |
270 | | - {amqp, true} -> ranch_proxy; |
271 | | - {'amqp/ssl', false} -> ranch_ssl; |
272 | | - {'amqp/ssl', true} -> ranch_proxy_ssl |
| 260 | + case Protocol of |
| 261 | + amqp -> ranch_tcp; |
| 262 | + 'amqp/ssl' -> ranch_ssl |
273 | 263 | end. |
274 | 264 |
|
275 | 265 |
|
@@ -373,16 +363,31 @@ force_connection_event_refresh(Ref) -> |
373 | 363 | [rabbit_reader:force_event_refresh(C, Ref) || C <- connections()], |
374 | 364 | ok. |
375 | 365 |
|
| 366 | +handshake(Ref, ProxyProtocol) -> |
| 367 | + case ProxyProtocol of |
| 368 | + true -> |
| 369 | + {ok, ProxyInfo} = ranch:recv_proxy_header(Ref, 1000), |
| 370 | + {ok, Sock} = ranch:handshake(Ref), |
| 371 | + tune_buffer_size(Sock), |
| 372 | + ok = file_handle_cache:obtain(), |
| 373 | + {ok, {rabbit_proxy_socket, Sock, ProxyInfo}}; |
| 374 | + false -> |
| 375 | + ranch:handshake(Ref) |
| 376 | + end. |
| 377 | + |
376 | 378 | accept_ack(Ref, Sock) -> |
377 | 379 | ok = ranch:accept_ack(Ref), |
378 | | - case tune_buffer_size(Sock) of |
| 380 | + tune_buffer_size(Sock), |
| 381 | + ok = file_handle_cache:obtain(). |
| 382 | + |
| 383 | +tune_buffer_size(Sock) -> |
| 384 | + case tune_buffer_size1(Sock) of |
379 | 385 | ok -> ok; |
380 | 386 | {error, _} -> rabbit_net:fast_close(Sock), |
381 | 387 | exit(normal) |
382 | | - end, |
383 | | - ok = file_handle_cache:obtain(). |
| 388 | + end. |
384 | 389 |
|
385 | | -tune_buffer_size(Sock) -> |
| 390 | +tune_buffer_size1(Sock) -> |
386 | 391 | case rabbit_net:getopts(Sock, [sndbuf, recbuf, buffer]) of |
387 | 392 | {ok, BufSizes} -> BufSz = lists:max([Sz || {_Opt, Sz} <- BufSizes]), |
388 | 393 | rabbit_net:setopts(Sock, [{buffer, BufSz}]); |
|
0 commit comments