Skip to content

Commit

Permalink
Merge branch 'use-ranch-1.6.0' into master-rmq
Browse files Browse the repository at this point in the history
  • Loading branch information
dumbbell committed Sep 11, 2018
2 parents 0f6235c + 1c1b127 commit d4f3f0b
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 10 deletions.
16 changes: 15 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
# vim:sw=2:et:

language: erlang
otp_release:
- 19.3
- 20.3
- 21.0
script: "rebar3 ct"
env:
global:
- PATH=~/.cache/rebar3/bin:$PATH
install:
- rebar3 local upgrade
# We apparently need to run it once before Travis picks it up, even if
# it's in the $PATH.
- PATH=~/.cache/rebar3/bin:$PATH rebar3 -v
- rebar3 report
script:
- rebar3 eunit -v
- rebar3 ct
sudo: false

2 changes: 1 addition & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

{deps,
[
{ranch, "1.5.0"}]}.
{ranch, "1.6.1"}]}.

{profiles, [
{test, [{deps,
Expand Down
4 changes: 2 additions & 2 deletions rebar.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{"1.1.0",
[{<<"ranch">>,{pkg,<<"ranch">>,<<"1.5.0">>},0}]}.
[{<<"ranch">>,{pkg,<<"ranch">>,<<"1.6.1">>},0}]}.
[
{pkg_hash,[
{<<"ranch">>, <<"F04166F456790FEE2AC1AA05A02745CC75783C2BFB26D39FAF6AEFC9A3D3A58A">>}]}
{<<"ranch">>, <<"2609724C9A7E163CA716A46C9087E037DB4262935F5D866122BA158ED917C233">>}]}
].
10 changes: 9 additions & 1 deletion src/ranch_proxy.erl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
listen/1,
accept/2,
accept_ack/2,
handshake/3,
connect/3,
connect/4,
recv/3,
Expand Down Expand Up @@ -63,7 +64,14 @@ accept(ProxySocket, Timeout) ->

-spec accept_ack(proxy_socket(), timeout()) -> ok.
accept_ack(ProxySocket, Timeout) ->
ranch_proxy_protocol:accept_ack(?TRANSPORT, ProxySocket, Timeout).
{ok, _} = handshake(ProxySocket, [], Timeout),
ok.

-spec handshake(proxy_socket(), list(), timeout())
-> {ok, proxy_socket()} | {error, any()}.
handshake(ProxySocket, _Opts, Timeout) ->
ranch_proxy_protocol:accept_ack(?TRANSPORT, ProxySocket, Timeout),
{ok, ProxySocket}.

-spec connect(inet:ip_address() | inet:hostname(),
inet:port_number(), any())
Expand Down
22 changes: 17 additions & 5 deletions src/ranch_proxy_ssl.erl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
listen/1,
accept/2,
accept_ack/2,
handshake/3,
connect/3,
connect/4,
recv/3,
Expand Down Expand Up @@ -87,7 +88,11 @@ accept(#ssl_socket{proxy_socket = ProxySocket,
{ok, ProxySocket1} ->
CSocket = ranch_proxy_protocol:get_csocket(ProxySocket1),
SSLOpts = application:get_env(ranch_proxy_protocol, ssl_accept_opts, []),
case ssl:handshake(CSocket, SSLOpts++Opts, Timeout) of
Fun = case erlang:function_exported(ssl, handshake, 3) of
true -> handshake;
false -> ssl_accept
end,
case ssl:Fun(CSocket, SSLOpts++Opts, Timeout) of
{ok, SslSocket} ->
ProxySocket2 = ranch_proxy_protocol:set_csocket(ProxySocket1,
SslSocket),
Expand All @@ -103,12 +108,19 @@ accept(#ssl_socket{proxy_socket = ProxySocket,
end.

-spec accept_ack(ssl_socket(), timeout()) -> ok.
accept_ack(#ssl_socket{proxy_socket = ProxySocket,
upgraded = false}, Timeout) ->
ranch_proxy_protocol:accept_ack(?TRANSPORT, ProxySocket, Timeout);
accept_ack(_, _) ->
accept_ack(CSocket, Timeout) ->
{ok, _} = handshake(CSocket, [], Timeout),
ok.

-spec handshake(ssl_socket(), list(), timeout())
-> {ok, ssl_socket()} | {error, any()}.
handshake(#ssl_socket{proxy_socket = ProxySocket,
upgraded = false} = CSocket, _Opts, Timeout) ->
ranch_proxy_protocol:accept_ack(?TRANSPORT, ProxySocket, Timeout),
{ok, CSocket};
handshake(CSocket, _Opts, _Timeout) ->
{ok, CSocket}.

-spec connect(inet:ip_address() | inet:hostname(),
inet:port_number(), any())
-> {ok, ssl_socket()} | {error, atom()}.
Expand Down

0 comments on commit d4f3f0b

Please sign in to comment.