Skip to content

Commit

Permalink
When not being able to estabilish direct tls s2s connection, try next…
Browse files Browse the repository at this point in the history
… candidate
  • Loading branch information
prefiks committed Aug 23, 2024
1 parent 56c32a1 commit 8936f56
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/xmpp_socket.erl
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ starttls(#socket_state{sockmod = gen_tcp,
sockmod = fast_tls,
tls_certfile = proplists:get_value(certfile, TLSOpts, none)},
SocketData2 = reset_stream(SocketData1),
case fast_tls:recv_data(TLSSocket, <<>>) of
{ok, TLSData} ->
parse(SocketData2, TLSData);
case fast_tls:finish_handshake(TLSSocket, 10000) of
ok ->
parse(SocketData2, <<>>);
{error, _} = Err ->
Err
end;
Expand Down
24 changes: 13 additions & 11 deletions src/xmpp_stream_out.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1402,15 +1402,17 @@ h_addr_list_to_host_ports(AddrList) ->
{error, {tls, tls_error_reason()}}.
connect(AddrPorts, State) ->
case connect(AddrPorts, State, {error, nxdomain}) of
{ok, Socket, {Addr, Port, TLS = true}} ->
case starttls(Socket, State) of
{ok, TLSSocket} -> {ok, TLSSocket, {Addr, Port, TLS}};
{error, Why} -> {error, {tls, Why}}
end;
{ok, Socket, {Addr, Port, TLS = false}} ->
{ok, Socket, {Addr, Port, TLS}};
{error, Why} ->
{error, {socket, Why}}
{ok, Socket, {Addr, Port, TLS = true}, Rest} ->
case starttls(Socket, State) of
{ok, TLSSocket} ->
{ok, TLSSocket, {Addr, Port, TLS}};
{error, Why} ->
connect(Rest, State)
end;
{ok, Socket, {Addr, Port, TLS = false}, _Rest} ->
{ok, Socket, {Addr, Port, TLS}};
{error, Why} ->
{error, {socket, Why}}
end.

-ifndef(USE_GETHOSTBYNAME).
Expand All @@ -1428,7 +1430,7 @@ connect([{#{family := Type, addr := SockAddr}, TLS}|AddressInfos], State, _) ->
Timeout = get_connect_timeout(State),
try xmpp_socket:connect(SockAddr, Port, Opts1, Timeout) of
{ok, Socket} ->
{ok, Socket, {Addr, Port, TLS}};
{ok, Socket, {Addr, Port, TLS}, AddressInfos};
Err ->
connect(AddressInfos, State, Err)
catch _:badarg ->
Expand All @@ -1451,7 +1453,7 @@ connect([{Addr, Port, TLS}|AddrPorts], State, _) ->
Timeout = get_connect_timeout(State),
try xmpp_socket:connect(Addr, Port, Opts1, Timeout) of
{ok, Socket} ->
{ok, Socket, {Addr, Port, TLS}};
{ok, Socket, {Addr, Port, TLS}, AddrPorts};
Err ->
connect(AddrPorts, State, Err)
catch _:badarg ->
Expand Down

0 comments on commit 8936f56

Please sign in to comment.