zashoku 1.6.0 → 1.7.0
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/constants.rb +4 -1
- data/lib/core/module.rb +2 -1
- data/lib/core/net/client.rb +19 -2
- data/lib/core/net/client_san.rb +35 -0
- data/lib/core/net/server.rb +20 -10
- data/lib/core/util/readline.rb +1 -1
- data/lib/core/view.rb +2 -0
- data/lib/daemon.rb +8 -0
- data/lib/viewer.rb +8 -4
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75e3775fdccdd11934891cf0ecb6dc26970861c2
|
4
|
+
data.tar.gz: 2bb3b8ec31b215d353b0fd89a22609a9eac5f952
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 553deb8cd3b0b929aa9eb43f776150e8df4e8ac80f06b51d56ff17710e4b6845cf73f956c947a16485b44ab1da6cbbc7b261155a773b215b13d6e36963f3c588
|
7
|
+
data.tar.gz: 5995692a530495950f408e6b2aba395e3211b0c50c03a110209efce88e5fb568b2b20c416f14396fdbb7930b63fb143f385908a7e9b9200aa90eb01af769fc54
|
data/lib/constants.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
require_relative 'core/util/util'
|
4
4
|
|
5
5
|
module Zashoku
|
6
|
-
Version = [1,
|
6
|
+
Version = [1, 7, 0].freeze
|
7
7
|
|
8
8
|
Root = File.expand_path('../', __dir__)
|
9
9
|
|
@@ -26,6 +26,9 @@ module Zashoku
|
|
26
26
|
net: {
|
27
27
|
host: 'localhost',
|
28
28
|
port: 26_119
|
29
|
+
},
|
30
|
+
msg: {
|
31
|
+
quit: 'Type :quit<enter> to quit'
|
29
32
|
}
|
30
33
|
},
|
31
34
|
core: {
|
data/lib/core/module.rb
CHANGED
data/lib/core/net/client.rb
CHANGED
@@ -25,9 +25,18 @@ module Zashoku
|
|
25
25
|
@result_queue = Queue.new
|
26
26
|
@event_queue = Queue.new
|
27
27
|
|
28
|
+
@semaphore = Mutex.new
|
29
|
+
|
28
30
|
start_threads
|
31
|
+
say_helo
|
32
|
+
end
|
29
33
|
|
30
|
-
|
34
|
+
def say_helo
|
35
|
+
r = command(
|
36
|
+
'helo',
|
37
|
+
{zv: Zashoku::Version, app: Zashoku::CConf[:app][:name]}
|
38
|
+
)
|
39
|
+
Zashoku.logger.warn('Everything is not okay') unless r['response'] == 'ok'
|
31
40
|
end
|
32
41
|
|
33
42
|
def start_threads
|
@@ -123,14 +132,22 @@ module Zashoku
|
|
123
132
|
payload = { 'msg' => msg, 'raw' => true }.merge(args)
|
124
133
|
@socket.puts(JSON.generate(payload))
|
125
134
|
f = File.open(file, 'w')
|
135
|
+
Zashoku::Util.alert("opened file #{file}")
|
126
136
|
f.sync = true
|
137
|
+
Zashoku::Util.alert('waiting for server...')
|
138
|
+
l = @socket.gets(Zashoku::EOF).split(Zashoku::EOF).first.to_i
|
139
|
+
Zashoku::Util.alert("got length #{l}")
|
140
|
+
r = 0
|
127
141
|
loop do
|
128
142
|
d = @socket.gets(Zashoku::EOF, BSIZE)
|
143
|
+
dl = d.length
|
129
144
|
f.print(d)
|
130
|
-
|
145
|
+
Zashoku::Util.alert( "file #{((r += dl) / Float(l) * 100).round}% buffered" )
|
146
|
+
break if dl < BSIZE
|
131
147
|
end
|
132
148
|
f.close
|
133
149
|
}
|
150
|
+
Zashoku::Util.alert('file buffered')
|
134
151
|
Zashoku.logger.info('re-starting client threads from command_to_file')
|
135
152
|
start_threads
|
136
153
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'client_san'
|
4
|
+
|
5
|
+
module Zashoku
|
6
|
+
module Net
|
7
|
+
class ClientSan
|
8
|
+
KANA=[ 'a', 'i', 'u', 'e', 'o', 'ka', 'ki', 'ku', 'ke', 'ko', 'sa',
|
9
|
+
'shi', 'su', 'se', 'so', 'ta', 'chi', 'tsu', 'te', 'to', 'na',
|
10
|
+
'ni', 'nu', 'ne', 'no', 'ha', 'hi', 'fu', 'he', 'ho', 'ma', 'mi',
|
11
|
+
'mu', 'me', 'mo', 'ya', 'yu','yo', 'ra', 'ri', 'ru', 're', 'ro',
|
12
|
+
'wa', 'n' ]
|
13
|
+
|
14
|
+
attr_reader :c
|
15
|
+
|
16
|
+
def initialize(client)
|
17
|
+
@c = client
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_s
|
21
|
+
"#{@name || @name = generate_name(@c.hash)}@#{@c.addr[2]}:#{@c.addr[1]}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def generate_name(hash)
|
25
|
+
coll = ''
|
26
|
+
hash.abs.to_s[0..5].chars.map do |c|
|
27
|
+
coll += c
|
28
|
+
if coll.to_i >= KANA.length
|
29
|
+
KANA[coll.to_i % KANA.length]
|
30
|
+
end
|
31
|
+
end.compact.join + '-san'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/core/net/server.rb
CHANGED
@@ -4,6 +4,8 @@ require 'socket'
|
|
4
4
|
require 'json'
|
5
5
|
require 'thread'
|
6
6
|
|
7
|
+
require_relative 'client_san'
|
8
|
+
|
7
9
|
module Zashoku
|
8
10
|
module Net
|
9
11
|
class Server
|
@@ -21,6 +23,7 @@ module Zashoku
|
|
21
23
|
raise "error, port #{port} is busy"
|
22
24
|
end
|
23
25
|
@server_thread = Thread.new { serve_clients! }
|
26
|
+
Zashoku.logger.info("serving customers on localhost:#{port}")
|
24
27
|
end
|
25
28
|
|
26
29
|
def exit
|
@@ -29,23 +32,29 @@ module Zashoku
|
|
29
32
|
|
30
33
|
def event(e)
|
31
34
|
clients.each do |client|
|
32
|
-
client.puts JSON.generate(e)
|
35
|
+
client.c.puts JSON.generate(e)
|
33
36
|
end
|
34
37
|
end
|
35
38
|
|
36
39
|
def handle(client)
|
40
|
+
expecting_helo = true
|
37
41
|
loop do
|
38
42
|
message =
|
39
43
|
begin
|
40
|
-
JSON.parse(client.readline.chomp)
|
44
|
+
JSON.parse(client.c.readline.chomp)
|
41
45
|
rescue EOFError
|
42
46
|
{ 'msg' => 'disconnect' }
|
43
47
|
end
|
48
|
+
if expecting_helo and message['msg'] != 'helo'
|
49
|
+
Zashoku.logger.warn("#{client} did not say helo, rude!")
|
50
|
+
end
|
51
|
+
expecting_helo = false
|
44
52
|
begin
|
45
53
|
response = @handler.call(message)
|
46
|
-
|
54
|
+
Zashoku.logger.debug("sending message to #{client}")
|
55
|
+
client.c.puts(
|
47
56
|
if message['raw']
|
48
|
-
response + Zashoku::EOF
|
57
|
+
response.length.to_s + Zashoku::EOF + response + Zashoku::EOF
|
49
58
|
else
|
50
59
|
JSON.generate(response: response)
|
51
60
|
end
|
@@ -56,20 +65,21 @@ module Zashoku
|
|
56
65
|
break unless response
|
57
66
|
end
|
58
67
|
end
|
59
|
-
Zashoku.logger.info("
|
68
|
+
Zashoku.logger.info("bye bye #{client}")
|
60
69
|
@clients.delete(client)
|
61
70
|
@client_queue.delete(client)
|
62
|
-
client.close
|
71
|
+
client.c.close
|
63
72
|
end
|
64
73
|
|
65
74
|
def serve_clients!
|
66
75
|
Thread.abort_on_exception = true
|
67
76
|
loop do
|
68
77
|
Thread.start(@server.accept) do |client|
|
69
|
-
|
70
|
-
|
71
|
-
@
|
72
|
-
|
78
|
+
csan = ClientSan.new(client)
|
79
|
+
Zashoku.logger.info("#{csan} connected")
|
80
|
+
@clients << csan
|
81
|
+
@client_queue[csan] = Queue.new
|
82
|
+
handle(csan)
|
73
83
|
end
|
74
84
|
end
|
75
85
|
end
|
data/lib/core/util/readline.rb
CHANGED
data/lib/core/view.rb
CHANGED
data/lib/daemon.rb
CHANGED
@@ -43,6 +43,7 @@ module Zashoku
|
|
43
43
|
|
44
44
|
Zashoku.logger = Logger.new(STDOUT)
|
45
45
|
Zashoku.logger.level = Zashoku::CConf[:app][:log_level][:daemon]
|
46
|
+
Zashoku.logger.info("server using zashoku v#{Version.join('.')}")
|
46
47
|
# Load conf
|
47
48
|
Zashoku.conf = DaemonConfig.new
|
48
49
|
# Load modules
|
@@ -78,6 +79,13 @@ module Zashoku
|
|
78
79
|
Zashoku.command(mod: message[:mod], meth: :items)
|
79
80
|
when 'fwd'
|
80
81
|
Zashoku.command(message)
|
82
|
+
when 'helo'
|
83
|
+
Zashoku.logger.info("Client saying helo #{message}")
|
84
|
+
if message['zv'] == Zashoku::Version && message['app'] == Zashoku::CConf[:app][:name]
|
85
|
+
'ok'
|
86
|
+
else
|
87
|
+
'rejected'
|
88
|
+
end
|
81
89
|
when 'disconnect'
|
82
90
|
nil
|
83
91
|
when 'stop'
|
data/lib/viewer.rb
CHANGED
@@ -143,13 +143,17 @@ module Zashoku
|
|
143
143
|
end
|
144
144
|
Signal.trap('INT') do
|
145
145
|
Thread.new do
|
146
|
-
@semaphore.synchronize { Util.alert(
|
146
|
+
@semaphore.synchronize { Util.alert(Zashoku::CConf[:app][:msg][:quit]) }
|
147
147
|
end
|
148
148
|
end
|
149
149
|
end
|
150
150
|
|
151
151
|
def cleanup
|
152
152
|
Zashoku.client.disconnect
|
153
|
+
@views.each do |m, v|
|
154
|
+
Zashoku.logger.debug("sending cleanup to #{m} #{v}")
|
155
|
+
v&.send(:cleanup)
|
156
|
+
end
|
153
157
|
@key_thread&.exit
|
154
158
|
Curses.close_screen
|
155
159
|
|
@@ -191,9 +195,9 @@ module Zashoku
|
|
191
195
|
return builtin_command(*cmd.split) if COMMANDS.key?(cmd.split.first)
|
192
196
|
raise "no such command" if cmd.split.length == 1
|
193
197
|
command(*cmd.split) unless cmd.empty?
|
194
|
-
|
195
|
-
|
196
|
-
|
198
|
+
rescue StandardError => e
|
199
|
+
Zashoku.logger.error("#{cmd.split} raised an error '#{e}'")
|
200
|
+
Util.alert("Error: #{e}")
|
197
201
|
end
|
198
202
|
|
199
203
|
def search(*)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zashoku
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- annacrombie
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-12-
|
11
|
+
date: 2017-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: curses
|
@@ -122,6 +122,7 @@ files:
|
|
122
122
|
- "./lib/core/modules/conf/lib/conf.rb"
|
123
123
|
- "./lib/core/modules/conf/lib/conf/config_view.rb"
|
124
124
|
- "./lib/core/net/client.rb"
|
125
|
+
- "./lib/core/net/client_san.rb"
|
125
126
|
- "./lib/core/net/server.rb"
|
126
127
|
- "./lib/core/options.rb"
|
127
128
|
- "./lib/core/statusline/statusline.rb"
|