socket_duplex 1.1.1 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d5f3a6a99568a1bc408e5ca9756c4f5a0193e1cd
4
- data.tar.gz: 33014f7ffe2d49cadb35f39ab1b4d38667c7a0b8
3
+ metadata.gz: ec32418dd0c63c1b0c39c9be6b5197d236a5bd69
4
+ data.tar.gz: af7fd2a98b314685e8778a920144e1d036433f62
5
5
  SHA512:
6
- metadata.gz: d6c5276bbfaab46d51af00f5aa1aa8f243f282a2d5384efebe47d53dbef749c06ac34b2866cbf01b86e67954eef690460a878a4b00045d0b6e2033c91b28014c
7
- data.tar.gz: a64e598c9a666c9ea5b1313163df02cd6f96353ea813d8012a590f94e9fb33e7e9524a8c92405e16be5ed3b3b0f8f4c778f870881e45a6bda777027c3194e92b
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
- rescue Exception
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)
@@ -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.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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: socket_duplex
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Secful