rbkb 0.7.2 → 0.7.3

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.
Files changed (69) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -0
  3. data/Gemfile.lock +21 -13
  4. data/bin/b64 +2 -2
  5. data/bin/bgrep +2 -2
  6. data/bin/blit +2 -2
  7. data/bin/c +2 -2
  8. data/bin/crc32 +2 -2
  9. data/bin/d64 +2 -2
  10. data/bin/dedump +2 -2
  11. data/bin/feed +2 -2
  12. data/bin/hexify +2 -2
  13. data/bin/len +2 -2
  14. data/bin/plugsrv +66 -76
  15. data/bin/rex +1 -2
  16. data/bin/rstrings +2 -2
  17. data/bin/slice +2 -2
  18. data/bin/telson +2 -2
  19. data/bin/unhexify +2 -2
  20. data/bin/urldec +2 -2
  21. data/bin/urlenc +2 -2
  22. data/bin/xor +2 -2
  23. data/lib/rbkb/cli/b64.rb +6 -7
  24. data/lib/rbkb/cli/bgrep.rb +16 -17
  25. data/lib/rbkb/cli/blit.rb +29 -31
  26. data/lib/rbkb/cli/chars.rb +1 -2
  27. data/lib/rbkb/cli/crc32.rb +8 -10
  28. data/lib/rbkb/cli/d64.rb +3 -4
  29. data/lib/rbkb/cli/dedump.rb +15 -18
  30. data/lib/rbkb/cli/feed.rb +58 -64
  31. data/lib/rbkb/cli/hexify.rb +15 -16
  32. data/lib/rbkb/cli/len.rb +19 -27
  33. data/lib/rbkb/cli/rstrings.rb +41 -44
  34. data/lib/rbkb/cli/slice.rb +8 -15
  35. data/lib/rbkb/cli/telson.rb +33 -37
  36. data/lib/rbkb/cli/unhexify.rb +10 -11
  37. data/lib/rbkb/cli/urldec.rb +8 -9
  38. data/lib/rbkb/cli/urlenc.rb +8 -8
  39. data/lib/rbkb/cli/xor.rb +13 -14
  40. data/lib/rbkb/cli.rb +52 -65
  41. data/lib/rbkb/extends/array.rb +7 -8
  42. data/lib/rbkb/extends/common.rb +3 -5
  43. data/lib/rbkb/extends/enumerable.rb +9 -9
  44. data/lib/rbkb/extends/float.rb +1 -2
  45. data/lib/rbkb/extends/numeric.rb +29 -30
  46. data/lib/rbkb/extends/object.rb +1 -2
  47. data/lib/rbkb/extends/string.rb +172 -189
  48. data/lib/rbkb/extends/symbol.rb +2 -4
  49. data/lib/rbkb/extends.rb +0 -1
  50. data/lib/rbkb/plug/blit.rb +66 -69
  51. data/lib/rbkb/plug/cli.rb +22 -25
  52. data/lib/rbkb/plug/feed_import.rb +17 -21
  53. data/lib/rbkb/plug/peer.rb +11 -13
  54. data/lib/rbkb/plug/plug.rb +83 -91
  55. data/lib/rbkb/plug/proxy.rb +4 -8
  56. data/lib/rbkb/plug/unix_domain.rb +12 -14
  57. data/lib/rbkb/plug.rb +5 -6
  58. data/lib/rbkb/version.rb +1 -1
  59. data/lib/rbkb.rb +2 -3
  60. data/rbkb.gemspec +3 -3
  61. data/test/disabled_test_cli_blit.rb +1 -2
  62. data/test/disabled_test_cli_feed.rb +1 -2
  63. data/test/disabled_test_cli_telson.rb +1 -2
  64. data/test/test_cli_crc32.rb +1 -1
  65. data/test/test_cli_dedump.rb +83 -79
  66. data/test/test_cli_len.rb +25 -24
  67. data/test/test_cli_slice.rb +22 -22
  68. data/test/test_cli_xor.rb +4 -4
  69. metadata +18 -23
data/lib/rbkb/cli/blit.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'rbkb/cli'
2
2
  require 'rbkb/plug'
3
3
 
4
- # Copyright 2009 emonti at matasano.com
4
+ # Copyright 2009 emonti at matasano.com
5
5
  # See README.rdoc for license information
6
6
  #
7
7
  # blit is for use with any of the "plug" tools such as telson, feed, blitplug.
@@ -12,64 +12,63 @@ class Rbkb::Cli::Blit < Rbkb::Cli::Executable
12
12
  def initialize(*args)
13
13
  super(*args)
14
14
  {
15
- :b_addr => Plug::Blit::DEFAULT_IPADDR,
16
- :b_port => Plug::Blit::DEFAULT_PORT,
17
- :bp_proto => :TCP,
18
- :b_peeridx => 0,
19
- }.each {|k, v| @opts[k] ||= v}
15
+ b_addr: Plug::Blit::DEFAULT_IPADDR,
16
+ b_port: Plug::Blit::DEFAULT_PORT,
17
+ bp_proto: :TCP,
18
+ b_peeridx: 0
19
+ }.each { |k, v| @opts[k] ||= v }
20
20
  end
21
21
 
22
- def make_parser()
22
+ def make_parser
23
23
  super()
24
24
  add_std_file_opt(:indat)
25
25
  arg = @oparse
26
26
 
27
- arg.banner += " <data | blank for stdin>"
27
+ arg.banner += ' <data | blank for stdin>'
28
28
 
29
- arg.on("-t", "--trans-protocol=PROTO",
30
- "Blit transport protocol TCP/UDP") do |t|
29
+ arg.on('-t', '--trans-protocol=PROTO',
30
+ 'Blit transport protocol TCP/UDP') do |t|
31
31
  @opts[:b_proto] = t.upcase.to_sym
32
32
  end
33
33
 
34
- arg.on("-S", "--starttls", "Start TLS handshake for the peer index (-i)") do |s|
34
+ arg.on('-S', '--starttls', 'Start TLS handshake for the peer index (-i)') do |_s|
35
35
  @blit_msg = Plug::Blit.make_starttls(@opts[:b_peeridx])
36
36
  end
37
37
 
38
- arg.on("-b", "--blitsrv=ADDR:PORT",
39
- "Where to send blit messages") do |b|
40
-
41
- unless(m=/^(?:([\w\.]+):)?(\d+)$/.match(b))
42
- bail "invalid blit address/port"
38
+ arg.on('-b', '--blitsrv=ADDR:PORT',
39
+ 'Where to send blit messages') do |b|
40
+ unless (m = /^(?:([\w.]+):)?(\d+)$/.match(b))
41
+ bail 'invalid blit address/port'
43
42
  end
44
43
  @opts[:b_port] = m[2].to_i
45
44
  @opts[:b_port] = m[1] if m[1]
46
45
  end
47
46
 
48
- arg.on("-i", "--peer-index=IDX", Numeric,
49
- "Index for remote peer to receive") do |i|
47
+ arg.on('-i', '--peer-index=IDX', Numeric,
48
+ 'Index for remote peer to receive') do |i|
50
49
  @opts[:b_peeridx] = i
51
50
  end
52
51
 
53
- arg.on("-l", "--list-peers", "Lists the peer array for the target") do
52
+ arg.on('-l', '--list-peers', 'Lists the peer array for the target') do
54
53
  @blit_msg = Plug::Blit.make_list_peers
55
54
  end
56
55
 
57
- arg.on("-k", "--kill", "Stops the remote event loop.") do
56
+ arg.on('-k', '--kill', 'Stops the remote event loop.') do
58
57
  @blit_msg = Plug::Blit.make_kill
59
58
  end
60
59
 
61
- return arg
60
+ arg
62
61
  end
63
62
 
64
63
  def parse(*args)
65
64
  super(*args)
66
65
 
67
- unless @blit_msg
68
- if @opts[:indat].nil?
69
- @opts[:indat] = (@argv.length > 0)? @argv.join(" ") : @stdin.read()
70
- end
71
- @blit_msg = Plug::Blit.make_sendmsg(@opts[:b_peeridx], @opts[:indat])
66
+ return if @blit_msg
67
+
68
+ if @opts[:indat].nil?
69
+ @opts[:indat] = @argv.length > 0 ? @argv.join(' ') : @stdin.read
72
70
  end
71
+ @blit_msg = Plug::Blit.make_sendmsg(@opts[:b_peeridx], @opts[:indat])
73
72
  end
74
73
 
75
74
  def go(*args)
@@ -77,17 +76,16 @@ class Rbkb::Cli::Blit < Rbkb::Cli::Executable
77
76
 
78
77
  begin
79
78
  Plug::Blit.blit_init(
80
- :addr => @opts[:b_addr],
81
- :port => @opts[:b_port],
82
- :protocol => @opts[:b_proto]
79
+ addr: @opts[:b_addr],
80
+ port: @opts[:b_port],
81
+ protocol: @opts[:b_proto]
83
82
  )
84
83
 
85
84
  Plug::Blit.blit_raw(@blit_msg)
86
- rescue
85
+ rescue StandardError
87
86
  bail($!)
88
87
  end
89
88
 
90
89
  self.exit(0)
91
90
  end
92
-
93
91
  end
@@ -1,6 +1,6 @@
1
1
  require 'rbkb/cli'
2
2
 
3
- # Copyright 2009 emonti at matasano.com
3
+ # Copyright 2009 emonti at matasano.com
4
4
  # See README.rdoc for license information
5
5
  #
6
6
  # Repeats an argument N times
@@ -21,4 +21,3 @@ class Rbkb::Cli::Chars < Rbkb::Cli::Executable
21
21
  self.exit(0)
22
22
  end
23
23
  end
24
-
@@ -1,6 +1,6 @@
1
1
  require 'rbkb/cli'
2
2
 
3
- # Copyright 2009 emonti at matasano.com
3
+ # Copyright 2009 emonti at matasano.com
4
4
  # See README.rdoc for license information
5
5
  #
6
6
  # crc32 returns a crc32 checksum in hex from stdin or a file
@@ -11,9 +11,9 @@ class Rbkb::Cli::Crc32 < Rbkb::Cli::Executable
11
11
  @opts[:last] ||= -1
12
12
  end
13
13
 
14
- def make_parser()
14
+ def make_parser
15
15
  arg = super()
16
- arg.banner += " [filename]"
16
+ arg.banner += ' [filename]'
17
17
  add_std_file_opt(:indat)
18
18
  add_range_opts(:first, :last)
19
19
  end
@@ -21,18 +21,16 @@ class Rbkb::Cli::Crc32 < Rbkb::Cli::Executable
21
21
  def parse(*args)
22
22
  super(*args)
23
23
  parse_file_argument(:indat)
24
- parse_catchall()
24
+ parse_catchall
25
25
  end
26
26
 
27
27
  def go(*args)
28
28
  super(*args)
29
- @opts[:indat] ||= @stdin.read()
29
+ @opts[:indat] ||= @stdin.read
30
30
  dat = opts[:indat].force_to_binary
31
- dat = dat[ @opts[:first] .. @opts[:last] ]
32
- dat ||= ""
33
- @stdout.puts( "%0.8x" % dat.force_to_binary.crc32 )
31
+ dat = dat[@opts[:first]..@opts[:last]]
32
+ dat ||= ''
33
+ @stdout.puts('%0.8x' % dat.force_to_binary.crc32)
34
34
  self.exit(0)
35
35
  end
36
36
  end
37
-
38
-
data/lib/rbkb/cli/d64.rb CHANGED
@@ -1,13 +1,13 @@
1
1
  require 'rbkb/cli'
2
2
 
3
- # Copyright 2009 emonti at matasano.com
3
+ # Copyright 2009 emonti at matasano.com
4
4
  # See README.rdoc for license information
5
5
  #
6
6
  # d64 converts a base-64 encoded string back to its orginal form.
7
7
  class Rbkb::Cli::D64 < Rbkb::Cli::Executable
8
8
  def make_parser
9
9
  super()
10
- @oparse.banner += " <data | blank for stdin>"
10
+ @oparse.banner += ' <data | blank for stdin>'
11
11
  add_std_file_opt(:indat)
12
12
  end
13
13
 
@@ -15,7 +15,7 @@ class Rbkb::Cli::D64 < Rbkb::Cli::Executable
15
15
  super(*args)
16
16
  parse_string_argument(:indat)
17
17
  parse_file_argument(:indat)
18
- parse_catchall()
18
+ parse_catchall
19
19
  @opts[:indat] ||= @stdin.read
20
20
  end
21
21
 
@@ -25,4 +25,3 @@ class Rbkb::Cli::D64 < Rbkb::Cli::Executable
25
25
  self.exit(0)
26
26
  end
27
27
  end
28
-
@@ -1,53 +1,50 @@
1
1
  require 'rbkb/cli'
2
2
  require 'rbkb/extends'
3
3
 
4
- # Copyright 2009 emonti at matasano.com
4
+ # Copyright 2009 emonti at matasano.com
5
5
  # See README.rdoc for license information
6
6
  #
7
- # Reverses a hexdump back to raw data. Designed to work with hexdumps created
7
+ # Reverses a hexdump back to raw data. Designed to work with hexdumps created
8
8
  # by Unix utilities like 'xxd' as well as 'hexdump -C'.
9
9
  class Rbkb::Cli::Dedump < Rbkb::Cli::Executable
10
10
  def initialize(*args)
11
- super(*args) {|this|
11
+ super(*args) do |this|
12
12
  this.opts[:len] ||= 16
13
13
  yield this if block_given?
14
- }
14
+ end
15
15
  end
16
16
 
17
- def make_parser()
17
+ def make_parser
18
18
  arg = super()
19
- arg.banner += " <input-file | blank for stdin>"
19
+ arg.banner += ' <input-file | blank for stdin>'
20
20
 
21
- arg.on("-l", "--length LEN", Numeric,
22
- "Bytes per line in hexdump (Default: #{@opts[:len]})") do |l|
23
- bail("Length must be greater than zero") unless (@opts[:len] = l) > 0
21
+ arg.on('-l', '--length LEN', Numeric,
22
+ "Bytes per line in hexdump (Default: #{@opts[:len]})") do |l|
23
+ bail('Length must be greater than zero') unless (@opts[:len] = l) > 0
24
24
  end
25
- return arg
25
+ arg
26
26
  end
27
27
 
28
28
  def parse(*args)
29
29
  super(*args)
30
30
  parse_file_argument(:indat)
31
- parse_catchall()
31
+ parse_catchall
32
32
  end
33
33
 
34
34
  def go(*args)
35
35
  super(*args)
36
36
 
37
37
  # Default to standard input
38
- @opts[:indat] ||= @stdin.read()
38
+ @opts[:indat] ||= @stdin.read
39
39
 
40
- self.exit(1) unless((@opts[:len] ||= @opts[:indat].length) > 0)
40
+ self.exit(1) unless (@opts[:len] ||= @opts[:indat].length) > 0
41
41
 
42
42
  begin
43
- @opts[:indat].dehexdump( :len => @opts[:len], :out => @stdout)
44
- rescue
43
+ @opts[:indat].dehexdump(len: @opts[:len], out: @stdout)
44
+ rescue StandardError
45
45
  bail "Error: #{$!}"
46
46
  end
47
47
 
48
48
  self.exit(0)
49
49
  end
50
50
  end
51
-
52
-
53
-
data/lib/rbkb/cli/feed.rb CHANGED
@@ -7,10 +7,10 @@ require 'eventmachine'
7
7
  # See README.rdoc for license information
8
8
  #
9
9
  # This is a plug-board message feeder from static data sources.
10
- # The "feed" handles messages opaquely and just plays them in the given
10
+ # The "feed" handles messages opaquely and just plays them in the given
11
11
  # sequence.
12
12
  #
13
- # Feed can do the following things with minimum fuss:
13
+ # Feed can do the following things with minimum fuss:
14
14
  # - Import messages from files, yaml, or pcap
15
15
  # - Inject custom/modified messages with "blit"
16
16
  # - Run as a server or client using UDP or TCP
@@ -29,7 +29,7 @@ require 'eventmachine'
29
29
 
30
30
  class Rbkb::Cli::Feed < Rbkb::Cli::Executable
31
31
  def initialize(*args)
32
- @local_addr = "0.0.0.0"
32
+ @local_addr = '0.0.0.0'
33
33
  @local_port = nil
34
34
  @listen = false
35
35
  @persist = false
@@ -39,108 +39,106 @@ class Rbkb::Cli::Feed < Rbkb::Cli::Executable
39
39
  @blit_addr = Plug::Blit::DEFAULT_IPADDR
40
40
  @blit_port = Plug::Blit::DEFAULT_PORT
41
41
 
42
-
43
42
  ## Default options sent to the Feed handler
44
- @feed_opts = {
45
- :close_at_end => false,
46
- :step => false,
47
- :go_first => false
43
+ @feed_opts = {
44
+ close_at_end: false,
45
+ step: false,
46
+ go_first: false
48
47
  }
49
48
 
50
49
  super(*args)
51
50
 
52
- # TODO Plug::UI obviously need fixing.
51
+ # TODO: Plug::UI obviously need fixing.
53
52
  # TODO It shouldn't be driven by constants for configuration
54
53
  Plug::UI::LOGCFG[:verbose] = true
55
54
  Plug::UI::LOGCFG[:dump] = :hex
56
55
  Plug::UI::LOGCFG[:out] = @stderr
57
56
  end
58
57
 
59
- def make_parser()
58
+ def make_parser
60
59
  arg = super()
61
- arg.banner += " host:port"
60
+ arg.banner += ' host:port'
62
61
 
63
- arg.on("-o", "--output=FILE", "Output to file") do |o|
64
- Plug::UI::LOGCFG[:out] = File.open(o, "w")
62
+ arg.on('-o', '--output=FILE', 'Output to file') do |o|
63
+ Plug::UI::LOGCFG[:out] = File.open(o, 'w')
65
64
  end
66
65
 
67
- arg.on("-l", "--listen=(ADDR:?)PORT", "Server - on port (and addr?)") do |p|
68
- if m=/^(?:([\w\._-]+):)?(\d+)$/.match(p)
69
- @local_addr = $1 if $1
70
- @local_port = $2.to_i
71
- @listen = true
72
- else
73
- raise "Invalid listen argument: #{p.inspect}"
74
- end
66
+ arg.on('-l', '--listen=(ADDR:?)PORT', 'Server - on port (and addr?)') do |p|
67
+ raise "Invalid listen argument: #{p.inspect}" unless /^(?:([\w._-]+):)?(\d+)$/.match(p)
68
+
69
+ @local_addr = ::Regexp.last_match(1) if ::Regexp.last_match(1)
70
+ @local_port = ::Regexp.last_match(2).to_i
71
+ @listen = true
75
72
  end
76
73
 
77
- arg.on("-s", "--source=(ADDR:?)PORT", "Bind client on port and addr") do |p|
78
- if m=/^(?:([\w\.]+):)?(\d+)$/.match(p)
79
- @local_addr = $1 if $1
80
- @local_port = $2.to_i
74
+ arg.on('-s', '--source=(ADDR:?)PORT', 'Bind client on port and addr') do |p|
75
+ if /^(?:([\w.]+):)?(\d+)$/.match(p)
76
+ @local_addr = ::Regexp.last_match(1) if ::Regexp.last_match(1)
77
+ @local_port = ::Regexp.last_match(2).to_i
81
78
  else
82
79
  bail("Invalid source argument: #{p.inspect}")
83
80
  end
84
81
  end
85
82
 
86
- arg.on("-b", "--blit=(ADDR:)?PORT", "Where to listen for blit") do |b|
83
+ arg.on('-b', '--blit=(ADDR:)?PORT', 'Where to listen for blit') do |b|
87
84
  puts b
88
- unless(m=/^(?:([\w\._-]+):)?(\d+)$/.match(b))
85
+ unless (m = /^(?:([\w._-]+):)?(\d+)$/.match(b))
89
86
  raise "Invalid blit argument: #{b.inspect}"
90
87
  end
88
+
91
89
  @blit_port = m[2].to_i
92
90
  @blit_addr = m[1] if m[1]
93
91
  end
94
92
 
95
- arg.on("-i", "--[no-]initiate", "Send the first message on connect") do |i|
93
+ arg.on('-i', '--[no-]initiate', 'Send the first message on connect') do |i|
96
94
  @feed_opts[:go_first] = i
97
95
  end
98
96
 
99
- arg.on("-e", "--[no-]end", "End connection when feed is exhausted") do |c|
97
+ arg.on('-e', '--[no-]end', 'End connection when feed is exhausted') do |c|
100
98
  @feed_opts[:close_at_end] = c
101
99
  end
102
-
103
- arg.on("--[no-]step", "'Continue' prompt between messages") do |s|
100
+
101
+ arg.on('--[no-]step', "'Continue' prompt between messages") do |s|
104
102
  @feed_opts[:step] = s
105
103
  end
106
104
 
107
- arg.on("-u", "--udp", "Use UDP instead of TCP" ) do
105
+ arg.on('-u', '--udp', 'Use UDP instead of TCP') do
108
106
  @transport = :UDP
109
107
  end
110
108
 
111
- arg.on("-r", "--reconnect", "Attempt to reconnect endlessly.") do
112
- @persist=true
109
+ arg.on('-r', '--reconnect', 'Attempt to reconnect endlessly.') do
110
+ @persist = true
113
111
  end
114
112
 
115
- arg.on("-q", "--quiet", "Suppress verbose messages/dumps") do
113
+ arg.on('-q', '--quiet', 'Suppress verbose messages/dumps') do
116
114
  Plug::UI::LOGCFG[:verbose] = false
117
115
  end
118
116
 
119
- arg.on("-Q", "--squelch-exhausted", "Squelch 'FEED EXHAUSTED' messages") do |s|
117
+ arg.on('-Q', '--squelch-exhausted', "Squelch 'FEED EXHAUSTED' messages") do |_s|
120
118
  @feed_opts[:squelch_exhausted] = true
121
119
  end
122
120
 
123
- arg.separator " Sources: (can be combined)"
121
+ arg.separator ' Sources: (can be combined)'
124
122
 
125
- arg.on("-f", "--from-files=GLOB", "Import messages from raw files") do |f|
123
+ arg.on('-f', '--from-files=GLOB', 'Import messages from raw files') do |f|
126
124
  @feed_opts[:feed] ||= []
127
125
  @feed_opts[:feed] += FeedImport.import_rawfiles(f)
128
126
  end
129
127
 
130
- arg.on("-x", "--from-hex=FILE", "Import messages from hexdumps") do |x|
128
+ arg.on('-x', '--from-hex=FILE', 'Import messages from hexdumps') do |x|
131
129
  @feed_opts[:feed] ||= []
132
130
  @feed_opts[:feed] += FeedImport.import_dump(x)
133
131
  end
134
132
 
135
- arg.on("-y", "--from-yaml=FILE", "Import messages from yaml") do |y|
133
+ arg.on('-y', '--from-yaml=FILE', 'Import messages from yaml') do |y|
136
134
  @feed_opts[:feed] ||= []
137
135
  @feed_opts[:feed] += FeedImport.import_yaml(y)
138
136
  end
139
137
 
140
- arg.on("-p", "--from-pcap=FILE[:FILTER]", "Import messages from pcap") do |p|
138
+ arg.on('-p', '--from-pcap=FILE[:FILTER]', 'Import messages from pcap') do |p|
141
139
  if /^([^:]+):(.+)$/.match(p)
142
- file = $1
143
- filter = $2
140
+ file = ::Regexp.last_match(1)
141
+ filter = ::Regexp.last_match(2)
144
142
  else
145
143
  file = p
146
144
  filter = nil
@@ -154,9 +152,7 @@ class Rbkb::Cli::Feed < Rbkb::Cli::Executable
154
152
  def parse(*args)
155
153
  super(*args)
156
154
 
157
- if @transport == :UDP
158
- @svr_method = @cli_method = :open_datagram_socket
159
- end
155
+ @svr_method = @cli_method = :open_datagram_socket if @transport == :UDP
160
156
 
161
157
  @local_port ||= 0
162
158
  # Prepare EventMachine arguments based on whether we are a client or server
@@ -168,18 +164,18 @@ class Rbkb::Cli::Feed < Rbkb::Cli::Executable
168
164
  else # client
169
165
 
170
166
  ## Get target/listen argument for client mode
171
- unless (m = /^([\w\.]+):(\d+)$/.match(tgt=@argv.shift))
167
+ unless (m = /^([\w.]+):(\d+)$/.match(tgt = @argv.shift))
172
168
  bail_args tgt
173
169
  end
174
170
 
175
171
  @target_addr = m[1]
176
172
  @target_port = m[2].to_i
177
173
 
178
- if @transport == :UDP
179
- addr_args = [@local_addr, @local_port]
180
- else
181
- addr_args = [@local_addr, @local_port, @target_addr, @target_port]
182
- end
174
+ addr_args = if @transport == :UDP
175
+ [@local_addr, @local_port]
176
+ else
177
+ [@local_addr, @local_port, @target_addr, @target_port]
178
+ end
183
179
 
184
180
  @meth = @cli_method
185
181
  @feed_opts[:kind] = :client
@@ -187,18 +183,17 @@ class Rbkb::Cli::Feed < Rbkb::Cli::Executable
187
183
 
188
184
  @feed_opts[:feed] ||= []
189
185
 
190
- @em_args=[
191
- @meth,
186
+ @em_args = [
187
+ @meth,
192
188
  addr_args,
193
- Plug::ArrayFeeder,
194
- @transport,
189
+ Plug::ArrayFeeder,
190
+ @transport,
195
191
  @feed_opts
196
192
  ].flatten
197
193
 
198
- parse_catchall()
194
+ parse_catchall
199
195
  end
200
196
 
201
-
202
197
  def go(*args)
203
198
  super(*args)
204
199
 
@@ -206,13 +201,13 @@ class Rbkb::Cli::Feed < Rbkb::Cli::Executable
206
201
 
207
202
  ## Start the eventmachine
208
203
  loop do
209
- EventMachine::run do
204
+ EventMachine.run do
210
205
  EventMachine.send(*@em_args) do |c|
211
206
  EventMachine.start_server(@blit_addr, @blit_port, Plug::Blit, :TCP, c)
212
- Plug::UI::verbose("** BLITSRV-#{@blit_addr}:#{@blit_port}(TCP) Started")
207
+ Plug::UI.verbose("** BLITSRV-#{@blit_addr}:#{@blit_port}(TCP) Started")
213
208
 
214
209
  # if this is a UDP client, we will always send the first message
215
- if [:UDP, :client] == [@transport, c.kind]
210
+ if %i[UDP client] == [@transport, c.kind]
216
211
  peer = c.peers.add_peer_manually(@target_addr, @target_port)
217
212
  c.feed_data(peer)
218
213
  c.go_first = false
@@ -221,9 +216,8 @@ class Rbkb::Cli::Feed < Rbkb::Cli::Executable
221
216
  end
222
217
 
223
218
  break unless @persist
224
- Plug::UI::verbose("** RECONNECTING")
225
- end
226
219
 
220
+ Plug::UI.verbose('** RECONNECTING')
221
+ end
227
222
  end
228
223
  end
229
-
@@ -1,9 +1,9 @@
1
1
  require 'rbkb/cli'
2
2
 
3
- # Copyright 2009 emonti at matasano.com
3
+ # Copyright 2009 emonti at matasano.com
4
4
  # See README.rdoc for license information
5
5
  #
6
- # The hexify command converts a string or raw data to hex characters.
6
+ # The hexify command converts a string or raw data to hex characters.
7
7
  # Input can be supplied via stdin, a string argument, or a file (with -f).
8
8
  class Rbkb::Cli::Hexify < Rbkb::Cli::Executable
9
9
  def make_parser
@@ -12,21 +12,21 @@ class Rbkb::Cli::Hexify < Rbkb::Cli::Executable
12
12
  arg = @oparse
13
13
 
14
14
  # Add local options
15
- arg.banner += " <data | blank for stdin>"
15
+ arg.banner += ' <data | blank for stdin>'
16
16
 
17
- arg.on("-l", "--length LEN", Numeric, "Output lines of LEN bytes") do |l|
17
+ arg.on('-l', '--length LEN', Numeric, 'Output lines of LEN bytes') do |l|
18
18
  @opts[:len] = l
19
19
  end
20
20
 
21
- arg.on("-d", "--delim=DELIMITER", "DELIMITER between each byte") do |d|
21
+ arg.on('-d', '--delim=DELIMITER', 'DELIMITER between each byte') do |d|
22
22
  @opts[:delim] = d
23
23
  end
24
24
 
25
- arg.on("-p", "--prefix=PREFIX", "PREFIX before each byte") do |p|
25
+ arg.on('-p', '--prefix=PREFIX', 'PREFIX before each byte') do |p|
26
26
  @opts[:prefix] = p
27
27
  end
28
28
 
29
- arg.on("-s", "--suffix=SUFFIX", "SUFFIX after each byte") do |s|
29
+ arg.on('-s', '--suffix=SUFFIX', 'SUFFIX after each byte') do |s|
30
30
  @opts[:suffix] = s
31
31
  end
32
32
  end
@@ -35,31 +35,30 @@ class Rbkb::Cli::Hexify < Rbkb::Cli::Executable
35
35
  super(*args)
36
36
 
37
37
  # blackbag-style space delimiter compatability
38
- if @argv[0] == "+" and @opts[:delim].nil?
39
- @opts[:delim]=" "
38
+ if @argv[0] == '+' and @opts[:delim].nil?
39
+ @opts[:delim] = ' '
40
40
  @argv.shift
41
41
  end
42
42
 
43
43
  parse_string_argument(:indat)
44
- parse_catchall()
44
+ parse_catchall
45
45
  end
46
46
 
47
47
  def go(*args)
48
48
  super(*args)
49
49
 
50
50
  # Default to standard input
51
- @opts[:indat] ||= @stdin.read()
51
+ @opts[:indat] ||= @stdin.read
52
52
 
53
53
  indat = @opts.delete(:indat)
54
- len = (@opts.delete(:len) || indat.length)
54
+ len = @opts.delete(:len) || indat.length
55
55
 
56
- bail("Length must be greater than zero") unless(len > 0)
56
+ bail('Length must be greater than zero') unless len > 0
57
57
 
58
- until (m = indat.slice!(0..len-1)).empty?
58
+ until (m = indat.slice!(0..len - 1)).empty?
59
59
  @stdout << m.hexify(@opts)
60
- @stdout.puts((opts[:delim] and ! indat.empty?)? opts[:delim] : "\n")
60
+ @stdout.puts((opts[:delim] and !indat.empty?) ? opts[:delim] : "\n")
61
61
  end
62
62
  self.exit(0)
63
63
  end
64
64
  end
65
-