Class: ProcessWanker::NetClient

Inherits:
NetConnection show all
Defined in:
lib/net/net_client.rb

Constant Summary

Constants included from Log

Log::DEBUG, Log::ERROR, Log::INFO, Log::WARN

Instance Attribute Summary

Attributes inherited from NetConnection

#ssl_connection, #user

Instance Method Summary collapse

Methods inherited from NetConnection

#close_rudely, #disconnect, #on_close, #read_connection, #read_proc, #send_msg

Methods included from Log

debug, error, info, log, set_level, warn

Constructor Details

#initialize(cfg_host) ⇒ NetClient

Returns a new instance of NetClient.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/net/net_client.rb', line 36

def initialize(cfg_host)
	
	@host=cfg_host
	@response=nil
	
	# find the real config...
#			auth=cfg_host.auth || cfg_host.parent.auth || cfg_host.parent.parent.auth
	auth=cfg_host.get_auth
	if(!auth)
		raise "could not find auth"
	end

	@ca_cert=auth.ca_cert
	@context=OpenSSL::SSL::SSLContext.new
	@context.cert=auth.my_cert
	@context.key=auth.my_key
	@context.verify_mode=OpenSSL::SSL::VERIFY_PEER
	@context.verify_callback=proc do |preverify_ok,ssl_context|
		verify_peer(preverify_ok,ssl_context)
	end
	
	@tcp_client=TCPSocket.new(cfg_host.hostname,cfg_host.port)
	ssl_connection=OpenSSL::SSL::SSLSocket.new(@tcp_client,@context)
	ssl_connection.connect
	super(ssl_connection)
end

Instance Method Details

#on_msg(msg) ⇒ Object



83
84
85
86
87
88
89
90
91
92
# File 'lib/net/net_client.rb', line 83

def on_msg(msg)
	super(msg)
	if(msg[:info])
		puts "==[#{@host.name}] #{msg[:info]}"
	end
	if(msg[:done])
		@response=msg
		disconnect()
	end
end

#verify_peer(preverify_ok, ssl_context) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/net/net_client.rb', line 69

def verify_peer(preverify_ok,ssl_context)
	if(!ssl_context.current_cert.verify(@ca_cert.public_key))
		info("server certificate rejected")
		return(false)
	end
	true
end

#waitObject



100
101
102
103
# File 'lib/net/net_client.rb', line 100

def wait
	super
	@response
end