Skip to content
This repository has been archived by the owner on Nov 29, 2022. It is now read-only.

Adds TLS support to the elixir client and server #26

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

cwertyar
Copy link

@cwertyar cwertyar commented Oct 18, 2018

  • Added a transport parameter to the client which can hold :gen_tcp or :ssl modules and is added to the client state
  • Renamed tcp_opts to transport_opts to fit with the transport
  • Replaced calls to :gen_tcp with calls to the transport
  • Changed calls to make_active_once and update_socket_opts to either call into :inet or :ssl based on the transport

Fixes #25

send_buffer_size = opts[:sndbuf]
recieve_buffer_size = opts[:recbuf]
buffer_size = max(send_buffer_size, recieve_buffer_size)
:inet.setopts(socket, [sndbuf: send_buffer_size,
transport.setopts(socket, [sndbuf: send_buffer_size,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be done a little more cleanly with my suggestion below.

with :ok <- :gen_tcp.send(sock, upgrade_request(state)),
{:ok, data} <- :gen_tcp.recv(sock, 0, recv_timeout),
defp make_active_once(%State{sock: sock, transport: transport}=state) do
:ok = transport.setopts(sock, [active: :once])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alternate take here:

defp setopts(:ssl, socket, opts) do 
  :ssl.setopts(socket, opts)
end
defp setopts(:gen_tcp, socket, opts) do 
  :inet.setopts(socket, opts)
end

then you can just call setopts(transport, socket, opts) everywhere.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made the changes. Also did the same for getopts.

@scohen scohen requested a review from jhgg October 19, 2018 16:18
@scohen
Copy link
Contributor

scohen commented Oct 19, 2018

This looks good to me; I'm going to have @jhgg take a look too.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants