falcon 0.14.1 → 0.14.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/falcon/hosts.rb +26 -9
- data/lib/falcon/version.rb +1 -1
- data/server.rb +51 -49
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f847d041f11cc2854a3e2fd3e7d7568c0113b6530df89460599df8fb204204cf
|
4
|
+
data.tar.gz: a348fd0255c62fe12df681649bb4b9055f23f705c068115af7a8039075f4fae7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 335772ebca6b5e93a7c9de54c614e9a61522547ac06fba52d3014457644b9d74f7bc2530da6414f4a15e39b3da48289e36109d9776ecee4ce2d1cdfc0df55677
|
7
|
+
data.tar.gz: 1b696f587b0f3e9ba85be31bc740e81f377968d7bf9b183347629402ba0742e5c81a39dd524d55dcd7e4024bc7e65393fdfbf634978adb2272a77ffbcfed8ec3
|
data/lib/falcon/hosts.rb
CHANGED
@@ -27,6 +27,8 @@ module Falcon
|
|
27
27
|
@endpoint = nil
|
28
28
|
@ssl_certificate = nil
|
29
29
|
@ssl_key = nil
|
30
|
+
|
31
|
+
@ssl_context = nil
|
30
32
|
end
|
31
33
|
|
32
34
|
attr_accessor :app
|
@@ -35,6 +37,15 @@ module Falcon
|
|
35
37
|
|
36
38
|
attr_accessor :ssl_certificate
|
37
39
|
attr_accessor :ssl_key
|
40
|
+
attr_accessor :ssl_context
|
41
|
+
|
42
|
+
def freeze
|
43
|
+
return if frozen?
|
44
|
+
|
45
|
+
ssl_context
|
46
|
+
|
47
|
+
super
|
48
|
+
end
|
38
49
|
|
39
50
|
def ssl_certificate_path= path
|
40
51
|
@ssl_certificate = OpenSSL::X509::Certificate.new(File.read(path))
|
@@ -45,13 +56,15 @@ module Falcon
|
|
45
56
|
end
|
46
57
|
|
47
58
|
def ssl_context
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
59
|
+
@ssl_context ||= OpenSSL::SSL::SSLContext.new(:TLSv1).tap do |context|
|
60
|
+
context.cert = @ssl_certificate
|
61
|
+
context.key = @ssl_key
|
62
|
+
|
63
|
+
context.session_id_context = "falcon"
|
64
|
+
|
65
|
+
context.set_params
|
66
|
+
|
67
|
+
context.freeze
|
55
68
|
end
|
56
69
|
end
|
57
70
|
|
@@ -81,21 +94,25 @@ module Falcon
|
|
81
94
|
|
82
95
|
def endpoint
|
83
96
|
@server_endpoint ||= Async::HTTP::URLEndpoint.parse(
|
84
|
-
'https://
|
97
|
+
'https://[::]',
|
85
98
|
ssl_context: self.ssl_context,
|
86
99
|
reuse_address: true
|
87
100
|
)
|
88
101
|
end
|
89
102
|
|
90
103
|
def ssl_context
|
91
|
-
@server_context ||= OpenSSL::SSL::SSLContext.new.tap do |context|
|
104
|
+
@server_context ||= OpenSSL::SSL::SSLContext.new(:TLSv1).tap do |context|
|
92
105
|
context.servername_cb = Proc.new do |socket, hostname|
|
93
106
|
self.host_context(socket, hostname)
|
94
107
|
end
|
95
108
|
|
109
|
+
context.session_id_context = "falcon"
|
110
|
+
|
96
111
|
context.alpn_protocols = DEFAULT_ALPN_PROTOCOLS
|
97
112
|
|
98
113
|
context.set_params
|
114
|
+
|
115
|
+
context.freeze
|
99
116
|
end
|
100
117
|
end
|
101
118
|
|
data/lib/falcon/version.rb
CHANGED
data/server.rb
CHANGED
@@ -8,23 +8,24 @@ require 'async/container/controller'
|
|
8
8
|
require 'async/container/forked'
|
9
9
|
|
10
10
|
require 'async/clock'
|
11
|
+
require 'ruby-prof'
|
11
12
|
|
12
13
|
Async.logger.level = Logger::INFO
|
13
14
|
|
14
15
|
hosts = Falcon::Hosts.new
|
15
16
|
|
16
|
-
hosts.add('
|
17
|
+
hosts.add('mc.oriontransfer.co.nz') do |host|
|
17
18
|
host.endpoint = Async::HTTP::URLEndpoint.parse('http://hana.local:8123')
|
18
19
|
|
19
|
-
|
20
|
-
|
20
|
+
host.ssl_certificate_path = '/etc/letsencrypt/live/mc.oriontransfer.co.nz/fullchain.pem'
|
21
|
+
host.ssl_key_path = '/etc/letsencrypt/live/mc.oriontransfer.co.nz/privkey.pem'
|
21
22
|
end
|
22
23
|
|
23
|
-
hosts.add('chick.
|
24
|
+
hosts.add('chick.nz') do |host|
|
24
25
|
host.endpoint = Async::HTTP::URLEndpoint.parse('http://hana.local:8765')
|
25
26
|
|
26
|
-
|
27
|
-
|
27
|
+
host.ssl_certificate_path = '/etc/letsencrypt/live/chick.nz/fullchain.pem'
|
28
|
+
host.ssl_key_path = '/etc/letsencrypt/live/chick.nz/privkey.pem'
|
28
29
|
end
|
29
30
|
|
30
31
|
controller = Async::Container::Controller.new
|
@@ -35,59 +36,60 @@ hosts.each do |name, host|
|
|
35
36
|
end
|
36
37
|
end
|
37
38
|
|
38
|
-
|
39
|
-
proxy = Falcon::Proxy.new(Falcon::BadRequest, hosts.client_endpoints)
|
40
|
-
#)
|
41
|
-
|
39
|
+
proxy = Falcon::Proxy.new(Falcon::BadRequest, hosts.client_endpoints)
|
42
40
|
debug_trap = Async::IO::Trap.new(:USR1)
|
43
41
|
|
44
|
-
|
42
|
+
profile = RubyProf::Profile.new(merge_fibers: true)
|
45
43
|
|
46
|
-
#controller << Async::Container::Forked.new do
|
44
|
+
#controller << Async::Container::Forked.new do |task|
|
47
45
|
Process.setproctitle("Falcon Proxy")
|
48
46
|
|
49
|
-
server = Falcon::Server.new(
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
47
|
+
server = Falcon::Server.new(
|
48
|
+
proxy,
|
49
|
+
Async::HTTP::URLEndpoint.parse(
|
50
|
+
'https://0.0.0.0',
|
51
|
+
reuse_address: true,
|
52
|
+
ssl_context: hosts.ssl_context
|
53
|
+
)
|
54
|
+
)
|
55
|
+
|
56
|
+
begin
|
57
|
+
#profile.start
|
56
58
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
task.async do
|
62
|
-
debug_trap.install!
|
63
|
-
$stderr.puts "Send `kill -USR1 #{Process.pid}` for detailed status :)"
|
64
|
-
|
65
|
-
debug_trap.trap do
|
66
|
-
task.reactor.print_hierarchy($stderr)
|
67
|
-
# Async.logger.level = Logger::DEBUG
|
68
|
-
end
|
69
|
-
end
|
59
|
+
Async::Reactor.run do |task|
|
60
|
+
task.async do
|
61
|
+
debug_trap.install!
|
62
|
+
$stderr.puts "Send `kill -USR1 #{Process.pid}` for detailed status :)"
|
70
63
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
while true
|
75
|
-
task.sleep(600)
|
76
|
-
duration = Async::Clock.now - start_time
|
77
|
-
puts "Handled #{proxy.count} requests; #{(proxy.count.to_f / duration.to_f).round(1)} requests per second."
|
78
|
-
end
|
64
|
+
debug_trap.trap do
|
65
|
+
task.reactor.print_hierarchy($stderr)
|
66
|
+
# Async.logger.level = Logger::DEBUG
|
79
67
|
end
|
68
|
+
end
|
69
|
+
|
70
|
+
task.async do |task|
|
71
|
+
start_time = Async::Clock.now
|
80
72
|
|
81
|
-
|
73
|
+
while true
|
74
|
+
task.sleep(600)
|
75
|
+
duration = Async::Clock.now - start_time
|
76
|
+
puts "Handled #{proxy.count} requests; #{(proxy.count.to_f / duration.to_f).round(1)} requests per second."
|
77
|
+
end
|
82
78
|
end
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
79
|
+
|
80
|
+
$stderr.puts "Starting server"
|
81
|
+
server.run
|
82
|
+
end
|
83
|
+
ensure
|
84
|
+
if profile.running?
|
85
|
+
profile.stop
|
86
|
+
|
87
|
+
# print a flat profile to text
|
88
|
+
printer = RubyProf::FlatPrinter.new(profile)
|
89
|
+
printer.print($stdout)
|
90
|
+
end
|
91
|
+
end
|
91
92
|
|
92
93
|
#Process.setproctitle("Falcon Controller")
|
93
94
|
#controller.wait
|
95
|
+
|