socket_duplex 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/socket_duplex.rb +27 -6
- data/socket_duplex.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec32418dd0c63c1b0c39c9be6b5197d236a5bd69
|
4
|
+
data.tar.gz: af7fd2a98b314685e8778a920144e1d036433f62
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 980e3b5ca6cc11c3e844fba8cfbe879be812da9ee1a3c61430ea9e721c361d5f05ea73a1f8b89f11183499217a195de81066221059868a560b7d9dfcb7745405
|
7
|
+
data.tar.gz: bd89f149880ee585a3e7c5255b53f3ad34c786d0e3b251e0a08e01b3e175e52e45910db241508296e298371840cbff2997285bb0c5ec824416883ed9d6418e33
|
data/lib/socket_duplex.rb
CHANGED
@@ -12,21 +12,32 @@ module Rack
|
|
12
12
|
def initialize(app, socket_path, secful_key, verify_mode=OpenSSL::SSL::VERIFY_PEER)
|
13
13
|
@app, @socket_path, @verify_mode = app, socket_path, verify_mode
|
14
14
|
begin
|
15
|
-
puts 'initialize'
|
15
|
+
puts 'secful: initialize'
|
16
16
|
@secful_key = secful_key
|
17
|
+
puts 'secful: secful_key'
|
17
18
|
@agent_identifier = SecureRandom.hex
|
19
|
+
puts 'secful: agent_identifier'
|
18
20
|
@machine_ip = Socket.ip_address_list.detect(&:ipv4_private?).try(:ip_address)
|
21
|
+
puts 'secful: machine_ip'
|
19
22
|
@queue = SizedQueue.new(MAX_QUEUE_SIZE)
|
23
|
+
puts 'secful: queue'
|
20
24
|
@threads_to_sockets = {}
|
25
|
+
puts 'secful: threads_to_sockets'
|
21
26
|
Thread.new { activate_workers() }
|
22
|
-
|
27
|
+
puts 'secful: activate_workers()'
|
28
|
+
rescue Exception => e
|
29
|
+
puts 'secful: init-exception: ' + e.message
|
30
|
+
puts 'secful: init-trace: ' + e.backtrace.inspect
|
23
31
|
end
|
24
32
|
end
|
25
33
|
|
26
34
|
def call(env)
|
27
35
|
begin
|
36
|
+
puts 'secful: call'
|
28
37
|
dup._call(env)
|
29
|
-
rescue Exception
|
38
|
+
rescue Exception => e
|
39
|
+
puts 'secful: call-exception: ' + e.message
|
40
|
+
puts 'secful: call-trace: ' + e.backtrace.inspect
|
30
41
|
@app.call(env)
|
31
42
|
end
|
32
43
|
end
|
@@ -34,23 +45,33 @@ module Rack
|
|
34
45
|
protected
|
35
46
|
|
36
47
|
def _call(env)
|
48
|
+
puts 'secful: _call'
|
37
49
|
status, headers, body = @app.call(env)
|
50
|
+
puts 'secful: app.call'
|
51
|
+
puts 'secful: queue.len = ' + @queue.length
|
38
52
|
if @queue.length < @queue.max
|
53
|
+
puts 'secful: put in queue'
|
39
54
|
@queue << env
|
40
55
|
end
|
41
56
|
return [status, headers, body]
|
42
57
|
end
|
43
58
|
|
44
59
|
def activate_workers
|
60
|
+
puts 'secful: activate_workers'
|
45
61
|
NUM_OF_THREADS.times do
|
62
|
+
puts 'secful: new thread'
|
46
63
|
Thread.new {worker()}
|
64
|
+
puts 'secful: thread started'
|
47
65
|
end
|
48
66
|
end
|
49
67
|
|
50
68
|
def worker
|
51
69
|
loop do
|
70
|
+
puts 'secful: worker start'
|
52
71
|
env = @queue.pop
|
72
|
+
puts 'secful: workers poped'
|
53
73
|
if env
|
74
|
+
puts 'secful: env'
|
54
75
|
connect_to_ws(Thread.current)
|
55
76
|
handle_request(env)
|
56
77
|
end rescue nil
|
@@ -59,17 +80,17 @@ module Rack
|
|
59
80
|
|
60
81
|
def connect_to_ws(thr)
|
61
82
|
begin
|
62
|
-
puts 'connect_to_ws'
|
83
|
+
puts 'secful: connect_to_ws'
|
63
84
|
ws = @threads_to_sockets[thr]
|
64
85
|
if !ws
|
65
|
-
puts 'creating ws'
|
86
|
+
puts 'secful: creating ws'
|
66
87
|
headers = { 'Agent-Type' => 'Ruby',
|
67
88
|
'Agent-Version' => '1.0',
|
68
89
|
'Agent-Identifier' => @agent_identifier,
|
69
90
|
'Authorization' => 'Bearer ' + @secful_key }
|
70
91
|
ws = WebSocket::Client::Simple.connect @socket_path, verify_mode: @verify_mode, headers: headers
|
71
92
|
sleep(3)
|
72
|
-
puts 'connected to ws'
|
93
|
+
puts 'secful: connected to ws'
|
73
94
|
end
|
74
95
|
if !ws.open?
|
75
96
|
sleep(60)
|
data/socket_duplex.gemspec
CHANGED
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |spec|
|
5
5
|
spec.name = "socket_duplex"
|
6
|
-
spec.version = '1.1.
|
6
|
+
spec.version = '1.1.2'
|
7
7
|
spec.authors = ["Secful"]
|
8
8
|
spec.description = %q{Rack middleware that duplexes HTTP traffic}
|
9
9
|
spec.summary = spec.description
|