bayserver-core 2.3.2 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/lib/baykit/bayserver/agent/accept_handler.rb +0 -26
  3. data/lib/baykit/bayserver/agent/channel_listener.rb +6 -6
  4. data/lib/baykit/bayserver/agent/command_receiver.rb +97 -38
  5. data/lib/baykit/bayserver/agent/grand_agent.rb +444 -134
  6. data/lib/baykit/bayserver/agent/letter.rb +30 -0
  7. data/lib/baykit/bayserver/agent/lifecycle_listener.rb +9 -7
  8. data/lib/baykit/bayserver/agent/monitor/grand_agent_monitor.rb +298 -0
  9. data/lib/baykit/bayserver/agent/multiplexer/job_multiplexer.rb +257 -0
  10. data/lib/baykit/bayserver/agent/multiplexer/job_multiplexer_base.rb +52 -0
  11. data/lib/baykit/bayserver/agent/multiplexer/multiplexer_base.rb +150 -0
  12. data/lib/baykit/bayserver/agent/multiplexer/plain_transporter.rb +129 -0
  13. data/lib/baykit/bayserver/agent/multiplexer/rudder_state.rb +81 -0
  14. data/lib/baykit/bayserver/agent/multiplexer/secure_transporter.rb +50 -0
  15. data/lib/baykit/bayserver/agent/multiplexer/spider_multiplexer.rb +561 -0
  16. data/lib/baykit/bayserver/agent/multiplexer/spin_multiplexer.rb +311 -0
  17. data/lib/baykit/bayserver/agent/multiplexer/taxi_multiplexer.rb +194 -0
  18. data/lib/baykit/bayserver/agent/multiplexer/transporter.rb +61 -0
  19. data/lib/baykit/bayserver/agent/multiplexer/write_unit.rb +30 -0
  20. data/lib/baykit/bayserver/agent/non_blocking_handler.rb +0 -319
  21. data/lib/baykit/bayserver/agent/signal/signal_agent.rb +2 -1
  22. data/lib/baykit/bayserver/agent/timer_handler.rb +1 -1
  23. data/lib/baykit/bayserver/agent/transporter/data_listener.rb +7 -7
  24. data/lib/baykit/bayserver/agent/transporter/package.rb +0 -3
  25. data/lib/baykit/bayserver/agent/transporter/transporter.rb +5 -139
  26. data/lib/baykit/bayserver/bay_log.rb +1 -0
  27. data/lib/baykit/bayserver/bayserver.rb +32 -28
  28. data/lib/baykit/bayserver/{util → common}/groups.rb +1 -1
  29. data/lib/baykit/bayserver/common/inbound_handler.rb +12 -0
  30. data/lib/baykit/bayserver/{docker/base → common}/inbound_ship.rb +94 -19
  31. data/lib/baykit/bayserver/{docker/base → common}/inbound_ship_store.rb +7 -9
  32. data/lib/baykit/bayserver/common/multiplexer.rb +98 -0
  33. data/lib/baykit/bayserver/common/postpone.rb +15 -0
  34. data/lib/baykit/bayserver/common/read_only_ship.rb +42 -0
  35. data/lib/baykit/bayserver/common/recipient.rb +24 -0
  36. data/lib/baykit/bayserver/common/vehicle.rb +24 -0
  37. data/lib/baykit/bayserver/common/vehicle_runner.rb +127 -0
  38. data/lib/baykit/bayserver/{docker/warp → common}/warp_data.rb +18 -10
  39. data/lib/baykit/bayserver/common/warp_handler.rb +27 -0
  40. data/lib/baykit/bayserver/{docker/warp → common}/warp_ship.rb +107 -27
  41. data/lib/baykit/bayserver/{docker/warp → common}/warp_ship_store.rb +3 -8
  42. data/lib/baykit/bayserver/docker/base/inbound_data_listener.rb +2 -2
  43. data/lib/baykit/bayserver/docker/base/port_base.rb +59 -27
  44. data/lib/baykit/bayserver/docker/{warp/warp_docker.rb → base/warp_base.rb} +43 -50
  45. data/lib/baykit/bayserver/docker/built_in/built_in_harbor_docker.rb +118 -31
  46. data/lib/baykit/bayserver/docker/built_in/built_in_log_docker.rb +60 -63
  47. data/lib/baykit/bayserver/docker/built_in/built_in_permission_docker.rb +11 -10
  48. data/lib/baykit/bayserver/docker/built_in/built_in_secure_docker.rb +13 -4
  49. data/lib/baykit/bayserver/docker/city.rb +27 -13
  50. data/lib/baykit/bayserver/docker/club.rb +8 -8
  51. data/lib/baykit/bayserver/docker/docker.rb +9 -1
  52. data/lib/baykit/bayserver/docker/harbor.rb +184 -22
  53. data/lib/baykit/bayserver/docker/permission.rb +7 -6
  54. data/lib/baykit/bayserver/docker/port.rb +39 -11
  55. data/lib/baykit/bayserver/docker/secure.rb +11 -9
  56. data/lib/baykit/bayserver/docker/send_file/file_content_handler.rb +99 -4
  57. data/lib/baykit/bayserver/docker/send_file/send_file_docker.rb +6 -2
  58. data/lib/baykit/bayserver/docker/send_file/send_file_ship.rb +92 -0
  59. data/lib/baykit/bayserver/docker/town.rb +31 -15
  60. data/lib/baykit/bayserver/docker/trouble.rb +17 -5
  61. data/lib/baykit/bayserver/docker/warp.rb +34 -0
  62. data/lib/baykit/bayserver/mem_usage.rb +9 -9
  63. data/lib/baykit/bayserver/protocol/command_packer.rb +1 -8
  64. data/lib/baykit/bayserver/protocol/packet_packer.rb +7 -11
  65. data/lib/baykit/bayserver/protocol/packet_store.rb +4 -4
  66. data/lib/baykit/bayserver/protocol/protocol_handler.rb +26 -8
  67. data/lib/baykit/bayserver/protocol/protocol_handler_store.rb +5 -5
  68. data/lib/baykit/bayserver/rudders/io_rudder.rb +62 -0
  69. data/lib/baykit/bayserver/rudders/rudder.rb +29 -0
  70. data/lib/baykit/bayserver/{watercraft → ships}/ship.rb +65 -41
  71. data/lib/baykit/bayserver/taxi/taxi.rb +15 -10
  72. data/lib/baykit/bayserver/taxi/taxi_runner.rb +9 -94
  73. data/lib/baykit/bayserver/tours/read_file_taxi.rb +2 -2
  74. data/lib/baykit/bayserver/tours/req_content_handler.rb +16 -13
  75. data/lib/baykit/bayserver/tours/tour.rb +2 -2
  76. data/lib/baykit/bayserver/tours/tour_handler.rb +36 -0
  77. data/lib/baykit/bayserver/tours/tour_req.rb +14 -24
  78. data/lib/baykit/bayserver/tours/tour_res.rb +5 -89
  79. data/lib/baykit/bayserver/tours/tour_store.rb +5 -5
  80. data/lib/baykit/bayserver/train/train_runner.rb +17 -13
  81. data/lib/baykit/bayserver/util/data_consume_listener.rb +1 -1
  82. data/lib/baykit/bayserver/util/executor_service.rb +11 -7
  83. data/lib/baykit/bayserver/util/ip_matcher.rb +9 -39
  84. data/lib/baykit/bayserver/util/locale.rb +1 -1
  85. data/lib/baykit/bayserver/util/selector.rb +24 -5
  86. data/lib/baykit/bayserver/util/sys_util.rb +6 -6
  87. data/lib/baykit/bayserver/version.rb +1 -1
  88. metadata +37 -18
  89. data/lib/baykit/bayserver/agent/grand_agent_monitor.rb +0 -231
  90. data/lib/baykit/bayserver/agent/transporter/plain_transporter.rb +0 -55
  91. data/lib/baykit/bayserver/agent/transporter/secure_transporter.rb +0 -81
  92. data/lib/baykit/bayserver/docker/base/inbound_handler.rb +0 -42
  93. data/lib/baykit/bayserver/docker/warp/package.rb +0 -4
  94. data/lib/baykit/bayserver/docker/warp/warp_data_listener.rb +0 -112
  95. data/lib/baykit/bayserver/docker/warp/warp_handler.rb +0 -38
  96. /data/lib/baykit/bayserver/{util → common}/cities.rb +0 -0
@@ -0,0 +1,150 @@
1
+ require 'baykit/bayserver/bay_log'
2
+ require 'baykit/bayserver/common/multiplexer'
3
+
4
+ module Baykit
5
+ module BayServer
6
+ module Agent
7
+ module Multiplexer
8
+ class MultiplexerBase
9
+ include Baykit::BayServer::Common::Multiplexer # implements
10
+ include Baykit::BayServer
11
+
12
+ attr :channel_count
13
+ attr :agent
14
+ attr :rudders
15
+ attr :rudders_lock
16
+ attr :lock
17
+
18
+ def initialize(agt)
19
+ @agent = agt
20
+ @channel_count = 0
21
+ @rudders = {}
22
+ @rudders_lock = Mutex::new
23
+ @lock = Mutex::new
24
+ end
25
+
26
+ #########################################
27
+ # Implements Multiplexer
28
+ #########################################
29
+
30
+ def add_rudder_state(rd, st)
31
+ st.multiplexer = self
32
+ @rudders_lock.synchronize do
33
+ @rudders[rd.key] = st
34
+ end
35
+ @channel_count += 1
36
+ st.access()
37
+ end
38
+
39
+ def get_rudder_state(rd)
40
+ return find_rudder_state_by_key(rd.key)
41
+ end
42
+
43
+ def get_transporter(rd)
44
+ return get_rudder_state(rd).transporter
45
+ end
46
+
47
+ def consume_oldest_unit(st)
48
+ u = nil
49
+ st.write_queue_lock.synchronize do
50
+ if st.write_queue.empty?
51
+ return false
52
+ end
53
+ u = st.write_queue.shift()
54
+ end
55
+ u.done()
56
+ return true
57
+ end
58
+
59
+ def close_rudder(st)
60
+ BayLog.debug("%s closeRd %s state=%s closed=%s", agent, st.rudder, st, st.closed)
61
+
62
+ @lock.synchronize do
63
+ if st.closed
64
+ return
65
+ end
66
+ st.closed = true
67
+ end
68
+
69
+ remove_rudder_state(st.rudder)
70
+
71
+ begin
72
+ st.rudder.close()
73
+ rescue IOError => e
74
+ Baylog.error_e(e)
75
+ end
76
+
77
+ while consume_oldest_unit(st) do
78
+
79
+ end
80
+
81
+ if st.transporter != nil
82
+ st.transporter.on_closed(st.rudder)
83
+ end
84
+ end
85
+
86
+ def is_busy()
87
+ return @channel_count >= @agent.max_inbound_ships
88
+ end
89
+
90
+
91
+ #########################################
92
+ # Custom methods
93
+ #########################################
94
+
95
+ def find_rudder_state_by_key(key)
96
+ @rudders_lock.synchronize do
97
+ return @rudders[key]
98
+ end
99
+ end
100
+
101
+ def remove_rudder_state(rd)
102
+ @rudders_lock.synchronize do
103
+ @rudders.delete(rd.key())
104
+ end
105
+ @channel_count -= 1
106
+ end
107
+
108
+ def close_timeout_sockets
109
+ if @rudders.empty?
110
+ return
111
+ end
112
+
113
+ close_list = []
114
+ copied = nil
115
+ @rudders_lock.synchronize do
116
+ copied = @rudders.values
117
+ end
118
+ now = Time.now.tv_sec
119
+
120
+ copied.each do |st|
121
+ if st.transporter != nil
122
+ duration = now - st.last_access_time
123
+ if st.transporter.check_timeout(st.rudder, duration)
124
+ BayLog.debug("%s timeout: ch=%s", @agent, st.rudder)
125
+ close_list << st
126
+ end
127
+ end
128
+ end
129
+
130
+ close_list.each do |st|
131
+ close_rudder(st)
132
+ end
133
+ end
134
+
135
+ def close_all()
136
+ copied = nil
137
+ @rudders_lock.synchronize do
138
+ copied = @rudders.values
139
+ end
140
+ copied.each do |st|
141
+ if st.rudder != @agent.command_receiver.rudder
142
+ close_rudder(st)
143
+ end
144
+ end
145
+ end
146
+ end
147
+ end
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,129 @@
1
+ require 'baykit/bayserver/agent/multiplexer/transporter'
2
+ require 'baykit/bayserver/protocol/protocol_exception'
3
+ require 'baykit/bayserver/agent/next_socket_action'
4
+
5
+ module Baykit
6
+ module BayServer
7
+ module Agent
8
+ module Multiplexer
9
+ class PlainTransporter
10
+ include Transporter # Implements
11
+ include Baykit::BayServer::Agent
12
+ include Baykit::BayServer::Protocol
13
+ include Baykit::BayServer::Util
14
+
15
+ attr :multiplexer
16
+ attr :server_mode
17
+ attr :trace_ssl
18
+ attr :read_buffer_size
19
+ attr :ship
20
+ attr :closed
21
+
22
+ def initialize(mpx, sip, server_mode, bufsiz, trace_ssl)
23
+ @multiplexer = mpx
24
+ @ship = sip
25
+ @server_mode = server_mode
26
+ @trace_ssl = trace_ssl
27
+ @read_buffer_size = bufsiz
28
+ @closed = false
29
+ end
30
+
31
+ def to_s
32
+ return "tp[#{@ship}]"
33
+ end
34
+
35
+ #########################################
36
+ # Implements Transporter
37
+ #########################################
38
+
39
+ def init
40
+
41
+ end
42
+
43
+ def on_connect(rd)
44
+ BayLog.trace("%s onConnect", self)
45
+
46
+ return @ship.notify_connect
47
+ ;
48
+ end
49
+
50
+ def on_read(rd, buf, adr)
51
+ BayLog.debug("%s onRead", self)
52
+
53
+ if buf.length == 0
54
+ return @ship.notify_eof
55
+ else
56
+ begin
57
+ return @ship.notify_read(buf)
58
+
59
+ rescue UpgradeException => e
60
+ BayLog.debug("%s Protocol upgrade", @ship)
61
+ return @ship.notify_read(buf)
62
+
63
+ rescue ProtocolException => e
64
+ close = @ship.notify_protocol_error(e)
65
+ if !close && @server_mode
66
+ return NextSocketAction::CONTINUE
67
+ else
68
+ return NextSocketAction::CLOSE
69
+ end
70
+
71
+ rescue IOError => e
72
+ # IOError which occur in notifyRead must be distinguished from
73
+ # IOError which occur in handshake or readNonBlock.
74
+ on_error(rd, e)
75
+ return NextSocketAction::CLOSE
76
+ end
77
+ end
78
+ end
79
+
80
+ def on_error(rd, e)
81
+ @ship.notify_error(e)
82
+ end
83
+
84
+ def on_closed(rd)
85
+ @ship.notify_close
86
+ end
87
+
88
+ def req_connect(rd, adr)
89
+ @multiplexer.req_connect(rd, adr)
90
+ end
91
+
92
+ def req_read(rd)
93
+ @multiplexer.req_read(rd)
94
+ end
95
+
96
+ def req_write(rd, buf, adr, tag, &lis)
97
+ @multiplexer.req_write(rd, buf, adr, tag, lis)
98
+ end
99
+
100
+ def req_close(rd)
101
+ @closed = true
102
+ @multiplexer.req_close(rd)
103
+ end
104
+
105
+ def check_timeout(rd, duration_sec)
106
+ return @ship.check_timeout(duration_sec)
107
+ end
108
+
109
+ def get_read_buffer_size
110
+ return @read_buffer_size
111
+ end
112
+
113
+ def print_usage(indent)
114
+ end
115
+
116
+
117
+ #########################################
118
+ # Custom methods
119
+ #########################################
120
+ def secure()
121
+ return false
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end
127
+ end
128
+
129
+
@@ -0,0 +1,81 @@
1
+
2
+ module Baykit
3
+ module BayServer
4
+ module Agent
5
+ module Multiplexer
6
+ class RudderState
7
+ attr :rudder
8
+ attr :transporter
9
+ attr_accessor :multiplexer
10
+
11
+ attr :last_access_time
12
+ attr_accessor :closing
13
+
14
+ attr :read_buf
15
+ attr :buf_size
16
+ attr :write_queue
17
+ attr_accessor :handshaking
18
+ attr_accessor :reading
19
+ attr_accessor :writing
20
+ attr_accessor :bytes_read
21
+ attr_accessor :bytes_wrote
22
+ attr :write_queue_lock
23
+ attr :reading_lock
24
+ attr :writing_lock
25
+ attr_accessor :closed
26
+ attr_accessor :finale
27
+
28
+ attr_accessor :accepting
29
+ attr_accessor :connecting
30
+
31
+
32
+ def initialize(rd, tp = nil, timeout_sec = 0)
33
+ @rudder = rd
34
+ @transporter = tp
35
+ @closed = false
36
+ @timeout_sec = timeout_sec
37
+
38
+ if tp != nil
39
+ @buf_size = tp.get_read_buffer_size
40
+ @handshaking = tp.secure() ? true : false
41
+ else
42
+ @buf_size = 8192
43
+ @handshaking = false
44
+ end
45
+ @read_buf = " ".b * @buf_size
46
+
47
+ @accepting = false
48
+ @connecting = false
49
+ @closing = false
50
+ @write_queue = []
51
+ @write_queue_lock = Mutex::new
52
+ @reading_lock = Mutex::new
53
+ @writing_lock = Mutex::new
54
+ @reading = false
55
+ @writing = false
56
+ @bytes_read = 0
57
+ @bytes_wrote = 0
58
+ end
59
+
60
+ def to_s
61
+ str = "st(rd=#{@rudder} mpx=#{@multiplexer} tp=#{@transporter})"
62
+ if @closing
63
+ str += " closing";
64
+ end
65
+ return str
66
+ end
67
+
68
+
69
+ def access
70
+ @last_access_time = Time.now.tv_sec
71
+ end
72
+
73
+ def end
74
+ @finale = true
75
+ end
76
+
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,50 @@
1
+ require 'openssl'
2
+
3
+ require 'baykit/bayserver/agent/multiplexer/plain_transporter'
4
+ require 'baykit/bayserver/agent/next_socket_action'
5
+
6
+ module Baykit
7
+ module BayServer
8
+ module Agent
9
+ module Multiplexer
10
+ class SecureTransporter < PlainTransporter
11
+ include OpenSSL
12
+ include Baykit::BayServer::Protocol
13
+
14
+ attr :sslctx
15
+
16
+ def initialize(mpx, sip, server_mode, bufsize, trace_ssl, sslctx)
17
+ super(mpx, sip, server_mode, bufsize, trace_ssl)
18
+ @sslctx = sslctx
19
+ end
20
+
21
+
22
+ def to_s()
23
+ "stp[#{@ship}]"
24
+ end
25
+
26
+ ######################################################
27
+ # Implements Transporter
28
+ ######################################################
29
+
30
+ def secure()
31
+ return true
32
+ end
33
+
34
+ def on_read(rd, buf, len)
35
+ super
36
+ end
37
+
38
+ ######################################################
39
+ # Custom methods
40
+ ######################################################
41
+
42
+ def new_ssl_socket(skt)
43
+ SSL::SSLSocket.new(skt, @sslctx)
44
+ end
45
+ end
46
+ end
47
+
48
+ end
49
+ end
50
+ end