Class: Mqlight::SecureEndPoint

Inherits:
UnsecureEndPoint show all
Includes:
Logging
Defined in:
lib/mqlight/connection.rb

Instance Method Summary collapse

Methods included from Logging

#logger, logger

Methods inherited from UnsecureEndPoint

#incoming_thread, #outgoing_thread, #retrying?, #start_connection_threads, #stopped?, #stopping?

Constructor Details

#initialize(args) ⇒ SecureEndPoint

Returns a new instance of SecureEndPoint.



510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
# File 'lib/mqlight/connection.rb', line 510

def initialize(args)
  logger.entry(@id) { self.class.to_s + '#' + __method__.to_s }
  parms = Hash[method(__method__).parameters.map do |parm|
    [parm[1], eval(parm[1].to_s)]
  end]
  logger.parms(@id, parms) { self.class.to_s + '#' + __method__.to_s }

  super(args)

  # SSL details
  ssl = SecureSocket.new(args[:options])
  context = ssl.context(@thread_vars.service.host)

  begin
    ssl_transport = OpenSSL::SSL::SSLSocket.new(@tcp_transport, context)
    ssl_transport.connect
    fail Mqlight::SecurityError, 'certificate verify failed' \
      if ssl.verify_server_host_name_failed?
    @proton.sockets_open = true
  rescue => e
    logger.throw(@id, e) { self.class.to_s + '#' + __method__.to_s }
    msg = e.to_s
    if msg.include? 'certificate verify failed'
      raise Mqlight::SecurityError, 'certificate verify failed'
    else
      raise Mqlight::NetworkError, msg
    end
  end
  @transport = ssl_transport
  logger.exit(@id) { self.class.to_s + '#' + __method__.to_s }
end

Instance Method Details

#read_socketObject



545
546
547
# File 'lib/mqlight/connection.rb', line 545

def read_socket
  @transport.sysread(1024)
end

#stop_threadsObject

Stop the IO threads



552
553
554
555
556
557
558
559
560
561
562
563
564
# File 'lib/mqlight/connection.rb', line 552

def stop_threads
  logger.entry(@id) { self.class.to_s + '#' + __method__.to_s }
  begin
    @tcp_transport.shutdown(:WR)
  rescue => e
    logger.data(@id, 'Ignored: shutdown error ' + e.to_s) do
      self.class.to_s + '#' + __method__.to_s
    end
  end
  @incoming.kill
  @outgoing.kill
  logger.exit(@id) { self.class.to_s + '#' + __method__.to_s }
end