From 2c8db0879109dd90443d7b276e5ca2daf83920bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Thu, 20 Aug 2020 16:06:59 +0200 Subject: Rename the 3-arity gun_socks_up to gun_tunnel_up --- doc/src/manual/gun.asciidoc | 2 +- doc/src/manual/gun.await_up.asciidoc | 2 +- doc/src/manual/gun.open.asciidoc | 2 +- doc/src/manual/gun.open_unix.asciidoc | 2 +- doc/src/manual/gun_down.asciidoc | 2 +- doc/src/manual/gun_error.asciidoc | 2 +- doc/src/manual/gun_socks_up.asciidoc | 66 ---------------------------------- doc/src/manual/gun_tunnel_up.asciidoc | 68 +++++++++++++++++++++++++++++++++++ doc/src/manual/gun_up.asciidoc | 4 +-- src/gun.erl | 7 ++-- src/gun_http.erl | 2 ++ src/gun_http2.erl | 2 +- test/raw_SUITE.erl | 2 +- test/socks_SUITE.erl | 6 ++-- 14 files changed, 86 insertions(+), 83 deletions(-) delete mode 100644 doc/src/manual/gun_socks_up.asciidoc create mode 100644 doc/src/manual/gun_tunnel_up.asciidoc diff --git a/doc/src/manual/gun.asciidoc b/doc/src/manual/gun.asciidoc index 2067d96..a2d51f6 100644 --- a/doc/src/manual/gun.asciidoc +++ b/doc/src/manual/gun.asciidoc @@ -64,7 +64,7 @@ by sending any of the following messages: Connection: * link:man:gun_up(3)[gun_up(3)] - The connection is up -* link:man:gun_socks_up(3)[gun_socks_up(3)] - The Socks connection is up +* link:man:gun_tunnel_up(3)[gun_tunnel_up(3)] - The tunnel is up * link:man:gun_down(3)[gun_down(3)] - The connection is down * link:man:gun_upgrade(3)[gun_upgrade(3)] - Successful protocol upgrade * link:man:gun_error(3)[gun_error(3)] - Stream or connection-wide error diff --git a/doc/src/manual/gun.await_up.asciidoc b/doc/src/manual/gun.await_up.asciidoc index d9934b5..ffe39fd 100644 --- a/doc/src/manual/gun.await_up.asciidoc +++ b/doc/src/manual/gun.await_up.asciidoc @@ -71,5 +71,5 @@ may also be returned when a timeout or an error occur. link:man:gun(3)[gun(3)], link:man:gun:open(3)[gun:open(3)], link:man:gun:open_unix(3)[gun:open_unix(3)], -link:man:gun_socks_up(3)[gun_socks_up(3)], +link:man:gun_tunnel_up(3)[gun_tunnel_up(3)], link:man:gun_up(3)[gun_up(3)] diff --git a/doc/src/manual/gun.open.asciidoc b/doc/src/manual/gun.open.asciidoc index 63bb3f8..57d4490 100644 --- a/doc/src/manual/gun.open.asciidoc +++ b/doc/src/manual/gun.open.asciidoc @@ -73,5 +73,5 @@ message will be sent for that. link:man:gun(3)[gun(3)], link:man:gun:open_unix(3)[gun:open_unix(3)], link:man:gun:await_up(3)[gun:await_up(3)], -link:man:gun_socks_up(3)[gun_socks_up(3)], +link:man:gun_tunnel_up(3)[gun_tunnel_up(3)], link:man:gun_up(3)[gun_up(3)] diff --git a/doc/src/manual/gun.open_unix.asciidoc b/doc/src/manual/gun.open_unix.asciidoc index 441bfa8..0063728 100644 --- a/doc/src/manual/gun.open_unix.asciidoc +++ b/doc/src/manual/gun.open_unix.asciidoc @@ -61,5 +61,5 @@ message will be sent for that. link:man:gun(3)[gun(3)], link:man:gun:open(3)[gun:open(3)], link:man:gun:await_up(3)[gun:await_up(3)], -link:man:gun_socks_up(3)[gun_socks_up(3)], +link:man:gun_tunnel_up(3)[gun_tunnel_up(3)], link:man:gun_up(3)[gun_up(3)] diff --git a/doc/src/manual/gun_down.asciidoc b/doc/src/manual/gun_down.asciidoc index 6785cb5..a9fabde 100644 --- a/doc/src/manual/gun_down.asciidoc +++ b/doc/src/manual/gun_down.asciidoc @@ -75,5 +75,5 @@ link:man:gun(3)[gun(3)], link:man:gun:open(3)[gun:open(3)], link:man:gun:open_unix(3)[gun:open_unix(3)], link:man:gun_up(3)[gun_up(3)], -link:man:gun_socks_up(3)[gun_socks_up(3)], +link:man:gun_tunnel_up(3)[gun_tunnel_up(3)], link:man:gun_error(3)[gun_error(3)] diff --git a/doc/src/manual/gun_error.asciidoc b/doc/src/manual/gun_error.asciidoc index ac278fd..800b49c 100644 --- a/doc/src/manual/gun_error.asciidoc +++ b/doc/src/manual/gun_error.asciidoc @@ -64,5 +64,5 @@ handle_info({gun_error, ConnPid, _StreamRef, _Reason}, link:man:gun(3)[gun(3)], link:man:gun_up(3)[gun_up(3)], -link:man:gun_socks_up(3)[gun_socks_up(3)], +link:man:gun_tunnel_up(3)[gun_tunnel_up(3)], link:man:gun_down(3)[gun_down(3)] diff --git a/doc/src/manual/gun_socks_up.asciidoc b/doc/src/manual/gun_socks_up.asciidoc deleted file mode 100644 index e65cbff..0000000 --- a/doc/src/manual/gun_socks_up.asciidoc +++ /dev/null @@ -1,66 +0,0 @@ -= gun_socks_up(3) - -== Name - -gun_socks_up - The Socks connection is up - -== Description - -[source,erlang] ----- -{gun_socks_up, ConnPid, Protocol} - -ConnPid :: pid() -Protocol :: http | http2 | socks ----- - -The Socks connection is up. - -This message informs the owner/calling process that the connection -completed through the configured Socks proxy. - -If Gun is configured to connect to another Socks server, then the -connection is not usable yet. One or more -link:man:gun_socks_up(3)[gun_socks_up(3)] messages will follow. - -Otherwise, Gun will start processing the messages it received while -waiting for the connection to be up. If this is a reconnection, -then this may not be desirable for all requests. Those requests -should be cancelled when the connection goes down, and any -subsequent messages ignored. - -== Elements - -ConnPid:: - -The pid of the Gun connection process. - -Protocol:: - -The protocol selected for this connection. It can be used -to determine the capabilities of the server. - -== Changelog - -* *2.0*: Message introduced. - -== Examples - -.Receive a gun_socks_up message in a gen_server -[source,erlang] ----- -handle_info({gun_socks_up, ConnPid, _Protocol}, - State=#state{conn_pid=ConnPid}) -> - %% Do something. - {noreply, State}. ----- - -== See also - -link:man:gun(3)[gun(3)], -link:man:gun:open(3)[gun:open(3)], -link:man:gun:open_unix(3)[gun:open_unix(3)], -link:man:gun:await_up(3)[gun:await_up(3)], -link:man:gun_up(3)[gun_up(3)], -link:man:gun_down(3)[gun_down(3)], -link:man:gun_error(3)[gun_error(3)] diff --git a/doc/src/manual/gun_tunnel_up.asciidoc b/doc/src/manual/gun_tunnel_up.asciidoc new file mode 100644 index 0000000..5fc753e --- /dev/null +++ b/doc/src/manual/gun_tunnel_up.asciidoc @@ -0,0 +1,68 @@ += gun_tunnel_up(3) + +== Name + +gun_tunnel_up - The tunnel is up + +// @todo Update with StreamRef + +== Description + +[source,erlang] +---- +{gun_tunnel_up, ConnPid, Protocol} + +ConnPid :: pid() +Protocol :: http | http2 | socks +---- + +The Socks connection is up. + +This message informs the owner/calling process that the connection +completed through the configured Socks proxy. + +If Gun is configured to connect to another Socks server, then the +connection is not usable yet. One or more +link:man:gun_tunnel_up(3)[gun_tunnel_up(3)] messages will follow. + +Otherwise, Gun will start processing the messages it received while +waiting for the connection to be up. If this is a reconnection, +then this may not be desirable for all requests. Those requests +should be cancelled when the connection goes down, and any +subsequent messages ignored. + +== Elements + +ConnPid:: + +The pid of the Gun connection process. + +Protocol:: + +The protocol selected for this connection. It can be used +to determine the capabilities of the server. + +== Changelog + +* *2.0*: Message introduced. + +== Examples + +.Receive a gun_tunnel_up message in a gen_server +[source,erlang] +---- +handle_info({gun_tunnel_up, ConnPid, _Protocol}, + State=#state{conn_pid=ConnPid}) -> + %% Do something. + {noreply, State}. +---- + +== See also + +link:man:gun(3)[gun(3)], +link:man:gun:open(3)[gun:open(3)], +link:man:gun:open_unix(3)[gun:open_unix(3)], +link:man:gun:await_up(3)[gun:await_up(3)], +link:man:gun_up(3)[gun_up(3)], +link:man:gun_down(3)[gun_down(3)], +link:man:gun_error(3)[gun_error(3)] diff --git a/doc/src/manual/gun_up.asciidoc b/doc/src/manual/gun_up.asciidoc index db09fca..3853afd 100644 --- a/doc/src/manual/gun_up.asciidoc +++ b/doc/src/manual/gun_up.asciidoc @@ -21,7 +21,7 @@ reconnection completed. If Gun is configured to connect to a Socks server, then the connection is not usable yet. One or more -link:man:gun_socks_up(3)[gun_socks_up(3)] messages will follow. +link:man:gun_tunnel_up(3)[gun_tunnel_up(3)] messages will follow. Otherwise, Gun will start processing the messages it received while waiting for the connection to be up. If this is a reconnection, @@ -61,6 +61,6 @@ link:man:gun(3)[gun(3)], link:man:gun:open(3)[gun:open(3)], link:man:gun:open_unix(3)[gun:open_unix(3)], link:man:gun:await_up(3)[gun:await_up(3)], -link:man:gun_socks_up(3)[gun_socks_up(3)], +link:man:gun_tunnel_up(3)[gun_tunnel_up(3)], link:man:gun_down(3)[gun_down(3)], link:man:gun_error(3)[gun_error(3)] diff --git a/src/gun.erl b/src/gun.erl index e83c709..2f92b95 100644 --- a/src/gun.erl +++ b/src/gun.erl @@ -808,8 +808,7 @@ await_up(ServerPid, Timeout, MRef) -> receive {gun_up, ServerPid, Protocol} -> {ok, Protocol}; - %% @todo Maybe name it gun_tunnel_up. And send it for HTTP/1.1 CONNECT and HTTP/2 CONNECT and SOCKS. - {gun_socks_up, ServerPid, Protocol} -> + {gun_tunnel_up, ServerPid, Protocol} -> {ok, Protocol}; {'DOWN', MRef, process, ServerPid, Reason} -> {error, {down, Reason}} @@ -1587,9 +1586,9 @@ commands([{switch_protocol, Protocol0, ReplyTo}], State0=#state{ Protocol1 = protocol_handler(P), {Protocol1, maps:get(Protocol1:opts_name(), Opts, #{})} end, - %% When we switch_protocol from socks we must send a gun_socks_up message. + %% When we switch_protocol from socks we must send a gun_tunnel_up message. _ = case CurrentProtocol of - gun_socks -> ReplyTo ! {gun_socks_up, self(), Protocol:name()}; + gun_socks -> ReplyTo ! {gun_tunnel_up, self(), Protocol:name()}; _ -> ok end, {StateName, ProtoState} = Protocol:init(ReplyTo, Socket, Transport, ProtoOpts), diff --git a/src/gun_http.erl b/src/gun_http.erl index 6b511a3..bced64d 100644 --- a/src/gun_http.erl +++ b/src/gun_http.erl @@ -340,12 +340,14 @@ handle_connect(Rest, State=#http_state{ timeout => maps:get(tls_handshake_timeout, Destination, infinity) }, Protocols = maps:get(protocols, Destination, [http2, http]), +%% @todo gun_tunnel_up when the protocol switch is complete {handle_ret([ {origin, <<"https">>, NewHost, NewPort, connect}, {tls_handshake, HandshakeEvent, Protocols, ReplyTo} ], State), EvHandlerState1}; _ -> [Protocol] = maps:get(protocols, Destination, [http]), +%% @todo gun_tunnel_up {handle_ret([ {origin, <<"http">>, NewHost, NewPort, connect}, {switch_protocol, Protocol, ReplyTo} diff --git a/src/gun_http2.erl b/src/gun_http2.erl index da6747b..5b8d229 100644 --- a/src/gun_http2.erl +++ b/src/gun_http2.erl @@ -366,7 +366,7 @@ tunnel_commands([{switch_protocol, Protocol0, ReplyTo}|Tail], Stream=#stream{ref %% @todo We need to allow other protocol opts in http2_opts too. {Protocol1, maps:get(Protocol1:opts_name(), Opts, #{})} end, - %% When we switch_protocol from socks we must send a gun_socks_up message. + %% When we switch_protocol from socks we must send a gun_tunnel_up message. _ = case CurrentProtocol of gun_socks -> ReplyTo ! {gun_tunnel_up, self(), stream_ref(State, StreamRef), Protocol:name()}; _ -> ok diff --git a/test/raw_SUITE.erl b/test/raw_SUITE.erl index 9875467..bd34ebb 100644 --- a/test/raw_SUITE.erl +++ b/test/raw_SUITE.erl @@ -85,7 +85,7 @@ do_socks5_raw(OriginTransport, ProxyTransport) -> protocols => [raw] }}] }), - %% We receive a gun_up and a gun_socks_up. + %% We receive a gun_up and a gun_tunnel_up. {ok, socks} = gun:await_up(ConnPid), {ok, raw} = gun:await_up(ConnPid), %% The proxy received two packets. diff --git a/test/socks_SUITE.erl b/test/socks_SUITE.erl index 5e15eac..436ea3f 100644 --- a/test/socks_SUITE.erl +++ b/test/socks_SUITE.erl @@ -222,7 +222,7 @@ do_socks5(OriginScheme, OriginTransport, OriginProtocol, ProxyTransport, SocksAu protocols => [OriginProtocol] }}] }), - %% We receive a gun_up and a gun_socks_up. + %% We receive a gun_up and a gun_tunnel_up. {ok, socks} = gun:await_up(ConnPid), {ok, OriginProtocol} = gun:await_up(ConnPid), %% The proxy received two packets. @@ -300,7 +300,7 @@ do_socks5_through_multiple_proxies(OriginScheme, OriginTransport, ProxyTransport }}] }}] }), - %% We receive a gun_up and two gun_socks_up. + %% We receive a gun_up and two gun_tunnel_up. {ok, socks} = gun:await_up(ConnPid), {ok, socks} = gun:await_up(ConnPid), {ok, http} = gun:await_up(ConnPid), @@ -382,7 +382,7 @@ do_socks5_through_connect_proxy(OriginScheme, OriginTransport, ProxyTransport) - }), {request, <<"CONNECT">>, Authority1, 'HTTP/1.1', _} = receive_from(Proxy1Pid), {response, fin, 200, _} = gun:await(ConnPid, StreamRef), - %% We receive a gun_socks_up afterwards. This is the origin HTTP server. + %% We receive a gun_tunnel_up afterwards. This is the origin HTTP server. {ok, http} = gun:await_up(ConnPid), %% The second proxy receives a Socks5 auth/connect request. {auth_methods, 1, [none]} = receive_from(Proxy2Pid), -- cgit v1.2.3