Class: Fenris::Connection
- Inherits:
-
EventMachine::Connection
- Object
- EventMachine::Connection
- Fenris::Connection
show all
- Defined in:
- lib/fenris/connection.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(client = nil, options = {}) ⇒ Connection
Returns a new instance of Connection.
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/fenris/connection.rb', line 17
def initialize(client = nil, options = {})
@client = client
@binding = options[:binding]
@peer_to_be = options[:peer]
@peer_name = options[:peer_name]
@peer_binding = options[:peer_binding]
@peer = []
end
|
Class Method Details
.mkbinding(action, binding) ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/fenris/connection.rb', line 5
def self.mkbinding(action, binding)
if binding =~ /^:?(\d+)$/
[ action, "0.0.0.0", $1.to_i ]
elsif binding =~ /^(.+):(\d+)/
[ action, $1, $2.to_i ]
elsif binding == "--"
[ :attach, $stdin ]
else
[ action, binding ]
end
end
|
Instance Method Details
#log(msg) ⇒ Object
28
29
30
|
# File 'lib/fenris/connection.rb', line 28
def log msg
@client.log msg if @client
end
|
#proxy(peer, leader = true) ⇒ Object
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/fenris/connection.rb', line 54
def proxy(peer, leader = true)
peer.close if @unbound
@peer.each { |d| peer.push d}
@peer = peer
@peer_to_be = nil
if leader
@peer.proxy(self, false)
EventMachine::enable_proxy(self, @peer)
end
end
|
#proxy_target_unbound ⇒ Object
65
66
67
|
# File 'lib/fenris/connection.rb', line 65
def proxy_target_unbound
unbind
end
|
#push(data) ⇒ Object
32
33
34
35
|
# File 'lib/fenris/connection.rb', line 32
def push(data)
send_data data
end
|
#receive_data(data) ⇒ Object
69
70
71
|
# File 'lib/fenris/connection.rb', line 69
def receive_data data
@peer.push data
end
|
#ssl_handshake_completed ⇒ Object
50
51
52
|
# File 'lib/fenris/connection.rb', line 50
def ssl_handshake_completed
@post_ssl.call
end
|
#ssl_verify_peer(pem) ⇒ Object
37
38
39
|
# File 'lib/fenris/connection.rb', line 37
def ssl_verify_peer(pem)
@verify ||= @client.validate_peer pem, @peer_to_be, @peer_name
end
|
#unbind ⇒ Object
41
42
43
44
45
46
47
48
|
# File 'lib/fenris/connection.rb', line 41
def unbind
log "Connection closed"
@unbound = true
(@peer_to_be || @peer).close_connection_after_writing rescue nil
close_connection
EventMachine::stop if @binding[0] == :attach
end
|