zashoku 1.6.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e0db9aff8e20d948bbfeedb2ee251d30d586b9d6
4
- data.tar.gz: d0af382c8c4f81b56d75ef9a91ac3c56abc797be
3
+ metadata.gz: 75e3775fdccdd11934891cf0ecb6dc26970861c2
4
+ data.tar.gz: 2bb3b8ec31b215d353b0fd89a22609a9eac5f952
5
5
  SHA512:
6
- metadata.gz: c6014610f36f4840174e2de7417a3020dd4905219fc0e6de60170227ac5fb1482115175a61db0a0c2523936aa091fd06a450c7f541abcd2487ff2a68c7c30c3a
7
- data.tar.gz: f6c68b7a354a964f85834e33a76c9ef8134c9f30aff28b0ad8c9d27e2752e3d5d757b540595e23748b8b3dc2b1a2798ddeacd4b8e680a0f1fa0b8ef66d415120
6
+ metadata.gz: 553deb8cd3b0b929aa9eb43f776150e8df4e8ac80f06b51d56ff17710e4b6845cf73f956c947a16485b44ab1da6cbbc7b261155a773b215b13d6e36963f3c588
7
+ data.tar.gz: 5995692a530495950f408e6b2aba395e3211b0c50c03a110209efce88e5fb568b2b20c416f14396fdbb7930b63fb143f385908a7e9b9200aa90eb01af769fc54
@@ -3,7 +3,7 @@
3
3
  require_relative 'core/util/util'
4
4
 
5
5
  module Zashoku
6
- Version = [1, 6, 0].freeze
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: {
@@ -11,7 +11,8 @@ module Zashoku
11
11
  next unless File.exist?(mod_path)
12
12
  begin
13
13
  require mod_path
14
- rescue LoadError
14
+ rescue LoadError => e
15
+ Zashoku.logger.error("error: #{e} while loading #{mod}")
15
16
  false
16
17
  end
17
18
  end.any?
@@ -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
- @semaphore = Mutex.new
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
- break if d.length < BSIZE
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
@@ -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
- client.puts(
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("client #{client.hash} disconnected")
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
- Zashoku.logger.info("got client (hash: #{client.hash})")
70
- @clients << client
71
- @client_queue[client] = Queue.new
72
- handle(client)
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
@@ -61,7 +61,7 @@ module Zashoku
61
61
  @x = string.length + prompt.length
62
62
  when 10, ?\n, ?\r
63
63
  break
64
- when 127 #backspace
64
+ when 127, 8, ?\b #backspace
65
65
  print "\e[#{y};#{x}H "
66
66
  @x -= 1
67
67
  break if @x < prompt.length
@@ -26,6 +26,8 @@ module Zashoku
26
26
  refresh
27
27
  end
28
28
 
29
+ def cleanup; end
30
+
29
31
  def dirty_all_lines
30
32
  @dirty_lines = 0.step(get_len).to_a
31
33
  end
@@ -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'
@@ -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('Type :quit<enter> to exit.') }
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
- #rescue StandardError => e
195
- # Zashoku.logger.error("#{cmd.split} raised an error '#{e}'")
196
- # Util.alert("Error: #{e}")
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.6.0
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-05 00:00:00.000000000 Z
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"