lib/riak/client/beefcake/socket.rb in riak-client-2.3.2 vs lib/riak/client/beefcake/socket.rb in riak-client-2.4.0.pre1

- old
+ new

@@ -1,5 +1,6 @@ +require 'socket' require 'openssl' require 'cert_validator' require 'riak/client/beefcake/messages' require 'riak/errors/connection_error' @@ -11,25 +12,26 @@ class BeefcakeSocket include Client::BeefcakeMessageCodes # Only create class methods, don't initialize class << self def new(host, port, options = {}) - return start_tcp_socket(host, port) if options[:authentication].blank? - return start_tls_socket(host, port, options[:authentication]) + return start_tcp_socket(host, port, options) if options[:authentication].blank? + return start_tls_socket(host, port, options) end private - def start_tcp_socket(host, port) - TCPSocket.new(host, port).tap do |sock| + def start_tcp_socket(host, port, options = {}) + Socket.tcp(host, port, connect_timeout: options[:connect_timeout]).tap do |sock| sock.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, true) end end - def start_tls_socket(host, port, authentication) + def start_tls_socket(host, port, options) + authentication = options[:authentication] raise Riak::UserConfigurationError.new if authentication[:username] - tcp = start_tcp_socket(host, port) + tcp = start_tcp_socket(host, port, options) TlsInitiator.new(tcp, host, authentication).tls_socket end # Wrap up the logic to turn a TCP socket into a TLS socket. # Depends on Beefcake, which should be relatively safe. @@ -176,16 +178,11 @@ validator = CertValidator.new riak_cert, ca_cert validator.crl = try_load @auth[:crl_file] if @auth[:crl_file] - if @auth[:crl] - raise TlsError::CertRevokedError.new unless validator.crl_valid? - end - - if @auth[:ocsp] - raise TlsError::CertRevokedError.new unless validator.ocsp_valid? - end + raise TlsError::CertRevokedError.new if @auth[:crl] and !validator.crl_valid? + raise TlsError::CertRevokedError.new if @auth[:ocsp] and !validator.ocsp_valid? end def validator_options o = { ocsp: !!@auth[:ocsp],