Refactor code
This commit is contained in:
parent
a07ce6e410
commit
113b1ad2d6
|
@ -43,18 +43,21 @@ defmodule Chronoscope.Gemini.ConnectionClient do
|
|||
:ok = @ssl.send(socket, Request.create(url))
|
||||
{:ok, peercert} = @ssl.peercert(socket)
|
||||
|
||||
peercert
|
||||
|> await_response()
|
||||
|> tap(fn _ -> @ssl.close(socket) end)
|
||||
end
|
||||
|
||||
defp await_response(peercert) do
|
||||
receive do
|
||||
{:ssl, _socket, response} ->
|
||||
@ssl.close(socket)
|
||||
parse_response(response, peercert)
|
||||
|
||||
msg ->
|
||||
@ssl.close(socket)
|
||||
Logger.error("received unexpected message: #{inspect(msg)}")
|
||||
{:error, :no_response}
|
||||
after
|
||||
@timeout_in_milliseconds ->
|
||||
@ssl.close(socket)
|
||||
Logger.error("timed out waiting for response")
|
||||
{:error, :timeout}
|
||||
end
|
||||
|
|
|
@ -2,7 +2,6 @@ defmodule Chronoscope.NTS.Behaviour do
|
|||
@callback(key_establishment(host :: String.t(), port :: integer()) :: {:ok, Map.t()}, {:error, any()})
|
||||
end
|
||||
|
||||
# TODO - create macro
|
||||
defmodule Chronoscope.NTS do
|
||||
@behaviour Chronoscope.NTS.Behaviour
|
||||
|
||||
|
|
|
@ -36,19 +36,21 @@ defmodule Chronoscope.NTS.KeyEstablishmentClient do
|
|||
:ok = @ssl.send(socket, KeyEstablishmentRequest.create())
|
||||
{:ok, peercert} = @ssl.peercert(socket)
|
||||
|
||||
# TODO - refactor?
|
||||
peercert
|
||||
|> await_response()
|
||||
|> tap(fn _ -> @ssl.close(socket) end)
|
||||
end
|
||||
|
||||
defp await_response(peercert) do
|
||||
receive do
|
||||
{:ssl, _socket, response} ->
|
||||
@ssl.close(socket)
|
||||
parse_response(response, peercert)
|
||||
|
||||
msg ->
|
||||
@ssl.close(socket)
|
||||
Logger.error("received unexpected message: #{inspect(msg)}")
|
||||
{:error, :no_response}
|
||||
after
|
||||
@timeout_in_milliseconds ->
|
||||
@ssl.close(socket)
|
||||
Logger.error("timed out waiting for response")
|
||||
{:error, :timeout}
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue