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.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/Gemfile.lock +21 -13
- data/bin/b64 +2 -2
- data/bin/bgrep +2 -2
- data/bin/blit +2 -2
- data/bin/c +2 -2
- data/bin/crc32 +2 -2
- data/bin/d64 +2 -2
- data/bin/dedump +2 -2
- data/bin/feed +2 -2
- data/bin/hexify +2 -2
- data/bin/len +2 -2
- data/bin/plugsrv +66 -76
- data/bin/rex +1 -2
- data/bin/rstrings +2 -2
- data/bin/slice +2 -2
- data/bin/telson +2 -2
- data/bin/unhexify +2 -2
- data/bin/urldec +2 -2
- data/bin/urlenc +2 -2
- data/bin/xor +2 -2
- data/lib/rbkb/cli/b64.rb +6 -7
- data/lib/rbkb/cli/bgrep.rb +16 -17
- data/lib/rbkb/cli/blit.rb +29 -31
- data/lib/rbkb/cli/chars.rb +1 -2
- data/lib/rbkb/cli/crc32.rb +8 -10
- data/lib/rbkb/cli/d64.rb +3 -4
- data/lib/rbkb/cli/dedump.rb +15 -18
- data/lib/rbkb/cli/feed.rb +58 -64
- data/lib/rbkb/cli/hexify.rb +15 -16
- data/lib/rbkb/cli/len.rb +19 -27
- data/lib/rbkb/cli/rstrings.rb +41 -44
- data/lib/rbkb/cli/slice.rb +8 -15
- data/lib/rbkb/cli/telson.rb +33 -37
- data/lib/rbkb/cli/unhexify.rb +10 -11
- data/lib/rbkb/cli/urldec.rb +8 -9
- data/lib/rbkb/cli/urlenc.rb +8 -8
- data/lib/rbkb/cli/xor.rb +13 -14
- data/lib/rbkb/cli.rb +52 -65
- data/lib/rbkb/extends/array.rb +7 -8
- data/lib/rbkb/extends/common.rb +3 -5
- data/lib/rbkb/extends/enumerable.rb +9 -9
- data/lib/rbkb/extends/float.rb +1 -2
- data/lib/rbkb/extends/numeric.rb +29 -30
- data/lib/rbkb/extends/object.rb +1 -2
- data/lib/rbkb/extends/string.rb +172 -189
- data/lib/rbkb/extends/symbol.rb +2 -4
- data/lib/rbkb/extends.rb +0 -1
- data/lib/rbkb/plug/blit.rb +66 -69
- data/lib/rbkb/plug/cli.rb +22 -25
- data/lib/rbkb/plug/feed_import.rb +17 -21
- data/lib/rbkb/plug/peer.rb +11 -13
- data/lib/rbkb/plug/plug.rb +83 -91
- data/lib/rbkb/plug/proxy.rb +4 -8
- data/lib/rbkb/plug/unix_domain.rb +12 -14
- data/lib/rbkb/plug.rb +5 -6
- data/lib/rbkb/version.rb +1 -1
- data/lib/rbkb.rb +2 -3
- data/rbkb.gemspec +3 -3
- data/test/disabled_test_cli_blit.rb +1 -2
- data/test/disabled_test_cli_feed.rb +1 -2
- data/test/disabled_test_cli_telson.rb +1 -2
- data/test/test_cli_crc32.rb +1 -1
- data/test/test_cli_dedump.rb +83 -79
- data/test/test_cli_len.rb +25 -24
- data/test/test_cli_slice.rb +22 -22
- data/test/test_cli_xor.rb +4 -4
- metadata +18 -23
data/lib/rbkb/plug/plug.rb
CHANGED
@@ -1,219 +1,211 @@
|
|
1
|
-
# Copyright 2009 emonti at matasano.com
|
1
|
+
# Copyright 2009 emonti at matasano.com
|
2
2
|
# See README.rdoc for license information
|
3
3
|
#
|
4
4
|
|
5
|
-
require
|
5
|
+
require 'rbkb/plug/peer'
|
6
6
|
require 'stringio'
|
7
7
|
require 'socket'
|
8
8
|
|
9
|
-
|
10
9
|
module Plug
|
11
10
|
module UI
|
12
|
-
LOGCFG = {:
|
11
|
+
LOGCFG = { out: STDERR, dump: :hex }
|
13
12
|
|
14
|
-
def self.prompt(*msg)
|
13
|
+
def self.prompt(*msg)
|
14
|
+
warn msg
|
15
|
+
STDIN.gets
|
16
|
+
end
|
15
17
|
|
16
|
-
def self.log(*msg)
|
18
|
+
def self.log(*msg)
|
19
|
+
LOGCFG[:out].puts msg
|
20
|
+
end
|
17
21
|
|
18
|
-
def self.verbose(*msg)
|
22
|
+
def self.verbose(*msg)
|
23
|
+
LOGCFG[:out].puts msg if LOGCFG[:verbose]
|
24
|
+
end
|
19
25
|
|
20
|
-
def self.debug(*msg)
|
26
|
+
def self.debug(*msg)
|
27
|
+
LOGCFG[:out].puts msg if LOGCFG[:debug]
|
28
|
+
end
|
21
29
|
|
22
30
|
def self.logmsg(name, msg)
|
23
31
|
log "%% #{name} - #{msg}"
|
24
32
|
end
|
25
33
|
|
26
34
|
def self.dump(from, to, dat)
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
log "%%" if LOGCFG[:verbose]
|
35
|
+
return unless dump = LOGCFG[:dump]
|
36
|
+
|
37
|
+
log "%% #{from} SAYS TO #{to} LEN=#{dat.size}" if LOGCFG[:verbose]
|
38
|
+
case dump
|
39
|
+
when :hex
|
40
|
+
dat.hexdump(out: LOGCFG[:out])
|
41
|
+
when :raw
|
42
|
+
LOGCFG[:out].puts dat
|
43
|
+
else
|
44
|
+
LOGCFG[:out].puts dat
|
38
45
|
end
|
46
|
+
log '%%' if LOGCFG[:verbose]
|
39
47
|
end
|
40
48
|
end
|
41
49
|
|
42
|
-
|
43
50
|
module Base
|
44
51
|
attr_accessor :peers, :transport, :kind, :tls, :tls_opts, :no_stop_on_unbind
|
45
52
|
|
46
|
-
def initialize(transport, opts={})
|
47
|
-
# raise "Invalid transport #{transport.inspect}" unless (:UDP, :TCP).include?(transport)
|
53
|
+
def initialize(transport, opts = {})
|
54
|
+
# raise "Invalid transport #{transport.inspect}" unless (:UDP, :TCP).include?(transport)
|
48
55
|
@transport = transport
|
49
56
|
@peers = PeerList.new(self)
|
50
57
|
|
51
|
-
opts.each_pair do |k,v|
|
52
|
-
accessor = k.to_s +
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
raise "Bad attribute: #{k}"
|
57
|
-
end
|
58
|
+
opts.each_pair do |k, v|
|
59
|
+
accessor = k.to_s + '='
|
60
|
+
raise "Bad attribute: #{k}" unless respond_to?(accessor)
|
61
|
+
|
62
|
+
send(accessor, v)
|
58
63
|
end
|
59
64
|
end
|
60
65
|
|
61
66
|
def name
|
62
67
|
sn = get_sockname
|
63
|
-
addr = sn ? Socket.unpack_sockaddr_in(sn).reverse.join(
|
68
|
+
addr = sn ? Socket.unpack_sockaddr_in(sn).reverse.join(':') : 'PENDING'
|
64
69
|
"#{kind.to_s.upcase}-#{addr}(#{@transport})"
|
65
70
|
end
|
66
71
|
|
67
|
-
|
68
|
-
# plug_peer creates a peering association for a given peer based on
|
72
|
+
# plug_peer creates a peering association for a given peer based on
|
69
73
|
# get_peername. The existing or newly created peer object is returned.
|
70
74
|
def plug_peer
|
71
75
|
paddr = get_peername
|
72
|
-
|
76
|
+
@peers.find_peer(paddr) || @peers.add_peer(paddr)
|
73
77
|
end
|
74
78
|
|
75
|
-
|
76
|
-
#
|
77
|
-
# The "peer" is added if it is not already present. This instance
|
79
|
+
# plug_receive is used by receive_data to divert incoming messages.
|
80
|
+
# The "peer" is added if it is not already present. This instance
|
78
81
|
# will check whether # a peer is "muted" and will return the peer if not.
|
79
82
|
# This method can be overriden by child classes to implement additional
|
80
83
|
# checks. It receives "dat" so that such checks can optionally make
|
81
84
|
# forwarding decisions based on message data contents as well.
|
82
85
|
#
|
83
|
-
# Returns:
|
86
|
+
# Returns:
|
84
87
|
# - nil : indicates that the message should be stifled
|
85
|
-
# - A peer object : indicates that the message should be processed
|
88
|
+
# - A peer object : indicates that the message should be processed
|
86
89
|
# further
|
87
|
-
def plug_receive(
|
90
|
+
def plug_receive(_dat)
|
88
91
|
peer = plug_peer
|
89
|
-
|
92
|
+
peer unless peer.mute
|
90
93
|
end
|
91
|
-
|
92
|
-
# This instance of the say method is an abstract stub and just
|
93
|
-
# "dumps" the message. It should be overridden and optionally called
|
94
|
-
# with super() if you actually want to do anything useful when
|
94
|
+
|
95
|
+
# This instance of the say method is an abstract stub and just
|
96
|
+
# "dumps" the message. It should be overridden and optionally called
|
97
|
+
# with super() if you actually want to do anything useful when
|
95
98
|
# incoming messages are received.
|
96
99
|
def say(dat, sender)
|
97
|
-
UI.dump(sender.name,
|
100
|
+
UI.dump(sender.name, name, dat)
|
98
101
|
end
|
99
102
|
|
100
103
|
def post_init
|
101
104
|
UI.verbose "** #{name} Started"
|
102
|
-
if @kind
|
105
|
+
if @kind == :server and peer = plug_peer
|
103
106
|
UI.log "** #{name} CONNECTED TO #{peer.name}"
|
104
|
-
if tls
|
105
|
-
start_tls(tls_opts || {})
|
106
|
-
end
|
107
|
+
start_tls(tls_opts || {}) if tls
|
107
108
|
end
|
108
109
|
end
|
109
110
|
|
110
111
|
def receive_data(dat)
|
111
|
-
if peer=plug_receive(dat)
|
112
|
-
say(dat, peer)
|
112
|
+
if peer = plug_receive(dat)
|
113
|
+
say(dat, peer)
|
113
114
|
end
|
114
|
-
|
115
|
+
peer
|
115
116
|
end
|
116
117
|
|
117
118
|
def connection_completed
|
118
119
|
peer = plug_peer
|
119
120
|
UI.log "** #{name} CONNECTED TO #{peer.name}"
|
120
|
-
if tls
|
121
|
-
|
122
|
-
end
|
123
|
-
return peer
|
121
|
+
start_tls(tls_opts || {}) if tls
|
122
|
+
peer
|
124
123
|
end
|
125
124
|
|
126
125
|
def unbind
|
127
|
-
UI.log
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
126
|
+
UI.log '** Connection ' + (@peers.empty? ? 'refused.' : 'closed.')
|
127
|
+
return if @no_stop_on_unbind
|
128
|
+
|
129
|
+
UI.log 'STOPPING!!'
|
130
|
+
EM.stop
|
132
131
|
end
|
133
132
|
end
|
134
133
|
|
135
|
-
|
136
134
|
# An abstract module to implement custom servers for any protocol
|
137
135
|
# incoming messages are diverted to 'process(dat, sender)' which takes
|
138
136
|
# a block, the yields to which are messages to respond with
|
139
|
-
module UdpServer
|
137
|
+
module UdpServer
|
140
138
|
include Base
|
141
139
|
|
142
|
-
def kind
|
140
|
+
def kind
|
141
|
+
:server
|
142
|
+
end
|
143
143
|
|
144
144
|
def say(dat, sender)
|
145
145
|
super(dat, sender)
|
146
146
|
|
147
|
-
if
|
148
|
-
self.send(:process, dat, sender) { |rply| sender.say(rply, self) }
|
149
|
-
end
|
147
|
+
send(:process, dat, sender) { |rply| sender.say(rply, self) } if respond_to? :process
|
150
148
|
end
|
151
149
|
end
|
152
150
|
|
153
|
-
|
154
|
-
|
155
151
|
# Telson is just a receiver for blit
|
156
152
|
module Telson
|
157
153
|
include Base
|
158
|
-
def kind
|
154
|
+
def kind
|
155
|
+
:telson
|
156
|
+
end
|
159
157
|
end
|
160
158
|
|
161
|
-
|
162
159
|
# Uses an array of static messages as a datasource for opaque protocol
|
163
160
|
# messages. Useful as a generic blit-able loop
|
164
161
|
module ArrayFeeder
|
165
162
|
include Base
|
166
|
-
attr_accessor :pos, :feed, :step, :close_at_end, :go_first,
|
163
|
+
attr_accessor :pos, :feed, :step, :close_at_end, :go_first,
|
167
164
|
:squelch_exhausted
|
168
|
-
|
165
|
+
|
169
166
|
def initialize(*args)
|
170
167
|
super(*args)
|
171
168
|
|
172
169
|
@pos ||= 0
|
173
170
|
@feed ||= []
|
174
171
|
|
175
|
-
raise
|
172
|
+
raise 'feed must be enumerable' unless @feed.is_a?(Enumerable)
|
176
173
|
end
|
177
|
-
|
174
|
+
|
178
175
|
def go
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
176
|
+
return unless @go_first
|
177
|
+
|
178
|
+
feed_data
|
179
|
+
@go_first = false
|
183
180
|
end
|
184
181
|
|
185
182
|
def connection_completed
|
186
|
-
peer=super()
|
183
|
+
peer = super()
|
187
184
|
go if @go_first
|
188
|
-
|
185
|
+
peer
|
189
186
|
end
|
190
187
|
|
191
|
-
|
192
188
|
def say(dat, sender)
|
193
189
|
super(dat, sender)
|
194
190
|
if @step
|
195
191
|
EventMachine.defer(
|
196
192
|
proc { UI.prompt ">> Hit [enter] to continue at #{@pos}:" },
|
197
|
-
proc {|
|
193
|
+
proc { |_x| feed_data }
|
198
194
|
)
|
199
195
|
else
|
200
196
|
feed_data
|
201
197
|
end
|
202
198
|
end
|
203
199
|
|
204
|
-
def feed_data(dst=plug_peer)
|
205
|
-
unless dat
|
206
|
-
UI.log
|
200
|
+
def feed_data(dst = plug_peer)
|
201
|
+
unless dat = @feed[@pos]
|
202
|
+
UI.log '** FEED EXHAUSTED' unless @squelch_exhausted
|
207
203
|
return nil
|
208
204
|
end
|
209
205
|
|
210
206
|
dst.say dat.to_s, self
|
211
207
|
|
212
|
-
if (@pos += 1) >= @feed.size and @close_at_end
|
213
|
-
close_connection_after_writing
|
214
|
-
end
|
208
|
+
close_connection_after_writing if (@pos += 1) >= @feed.size and @close_at_end
|
215
209
|
end
|
216
|
-
|
217
210
|
end # ArrayFeeder
|
218
211
|
end # Plug
|
219
|
-
|
data/lib/rbkb/plug/proxy.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright 2009 emonti at matasano.com
|
1
|
+
# Copyright 2009 emonti at matasano.com
|
2
2
|
# See README.rdoc for license information
|
3
3
|
#
|
4
4
|
|
@@ -7,20 +7,16 @@ module Plug
|
|
7
7
|
include Base
|
8
8
|
attr_accessor :target
|
9
9
|
|
10
|
-
def initialize(transport,
|
10
|
+
def initialize(transport, _target)
|
11
11
|
@transport = transport
|
12
12
|
@peers = ProxyPeerList.new(self)
|
13
13
|
@kind = :proxy
|
14
14
|
end
|
15
|
-
|
16
15
|
end
|
17
16
|
|
18
17
|
class ProxyPeerList < PeerList
|
18
|
+
def add_peer(addr); end
|
19
19
|
|
20
|
-
def
|
21
|
-
end
|
22
|
-
|
23
|
-
def add_peer_manually(*args)
|
24
|
-
end
|
20
|
+
def add_peer_manually(*args); end
|
25
21
|
end
|
26
22
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright 2009 emonti at matasano.com
|
1
|
+
# Copyright 2009 emonti at matasano.com
|
2
2
|
# See README.rdoc for license information
|
3
3
|
#
|
4
4
|
|
@@ -16,11 +16,11 @@ module Plug
|
|
16
16
|
@owner = owner
|
17
17
|
end
|
18
18
|
|
19
|
-
def [](
|
19
|
+
def [](_junk)
|
20
20
|
@owner
|
21
21
|
end
|
22
22
|
|
23
|
-
def []=(
|
23
|
+
def []=(_junk)
|
24
24
|
[@owner]
|
25
25
|
end
|
26
26
|
|
@@ -37,39 +37,37 @@ module Plug
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def name
|
40
|
-
|
40
|
+
'a domain socket'
|
41
41
|
end
|
42
42
|
|
43
43
|
def receive_data(dat)
|
44
|
-
puts
|
44
|
+
puts 'Got:', dat.hexdump
|
45
45
|
end
|
46
46
|
|
47
47
|
def say(dat, sender)
|
48
|
-
UI.dump(sender.name,
|
48
|
+
UI.dump(sender.name, name, dat)
|
49
49
|
send_data(dat)
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
|
55
54
|
if $0 == __FILE__
|
56
55
|
Plug::UI::LOGCFG[:verbose] = true
|
57
56
|
|
58
57
|
b_addr = Plug::Blit::DEFAULT_IPADDR
|
59
58
|
b_port = Plug::Blit::DEFAULT_PORT
|
60
|
-
unless
|
61
|
-
|
59
|
+
unless sock = ARGV.shift and ARGV.shift.nil?
|
60
|
+
warn "usage: #{File.basename $0} unix_socket"
|
62
61
|
exit 1
|
63
62
|
end
|
64
63
|
|
65
|
-
|
66
|
-
EventMachine.run {
|
64
|
+
EventMachine.run do
|
67
65
|
s = EventMachine.connect_unix_domain(sock, Plug::UnixDomain)
|
68
|
-
Plug::UI
|
66
|
+
Plug::UI.verbose("** UNIX-DOMAIN-#{sock.inspect} Started")
|
69
67
|
|
70
68
|
# connect a blit channel:
|
71
69
|
EventMachine.start_server(b_addr, b_port, Plug::Blit, :TCP, s)
|
72
|
-
Plug::UI
|
73
|
-
|
70
|
+
Plug::UI.verbose("** BLITSRV-#{b_addr}:#{b_port}(TCP) Started")
|
71
|
+
end
|
74
72
|
|
75
73
|
end
|
data/lib/rbkb/plug.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
|
-
# Copyright 2009 emonti at matasano.com
|
1
|
+
# Copyright 2009 emonti at matasano.com
|
2
2
|
# See README.rdoc for license information
|
3
3
|
#
|
4
4
|
|
5
|
-
require
|
5
|
+
require 'rbkb'
|
6
6
|
|
7
|
-
begin require 'rubygems'
|
7
|
+
begin require 'rubygems'; rescue LoadError; end
|
8
8
|
require 'eventmachine'
|
9
|
-
require
|
10
|
-
require
|
11
|
-
|
9
|
+
require 'rbkb/plug/plug'
|
10
|
+
require 'rbkb/plug/blit'
|
data/lib/rbkb/version.rb
CHANGED
data/lib/rbkb.rb
CHANGED
data/rbkb.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_development_dependency "bundler"
|
22
|
-
spec.add_development_dependency "rake", "~>
|
23
|
-
spec.add_development_dependency "rspec"
|
21
|
+
spec.add_development_dependency "bundler"
|
22
|
+
spec.add_development_dependency "rake", "~> 13"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
24
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__),
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_cli_helper.rb')
|
2
2
|
|
3
3
|
class TestCliBlit < Test::Unit::TestCase
|
4
4
|
include CliTest
|
@@ -7,5 +7,4 @@ class TestCliBlit < Test::Unit::TestCase
|
|
7
7
|
@cli_class = Rbkb::Cli::Blit
|
8
8
|
super()
|
9
9
|
end
|
10
|
-
|
11
10
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__),
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_cli_helper.rb')
|
2
2
|
|
3
3
|
class TestCliFeed < Test::Unit::TestCase
|
4
4
|
include CliTest
|
@@ -7,5 +7,4 @@ class TestCliFeed < Test::Unit::TestCase
|
|
7
7
|
@cli_class = Rbkb::Cli::Feed
|
8
8
|
super()
|
9
9
|
end
|
10
|
-
|
11
10
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__),
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_cli_helper.rb')
|
2
2
|
|
3
3
|
class TestCliTelson < Test::Unit::TestCase
|
4
4
|
include CliTest
|
@@ -7,5 +7,4 @@ class TestCliTelson < Test::Unit::TestCase
|
|
7
7
|
@cli_class = Rbkb::Cli::Telson
|
8
8
|
super()
|
9
9
|
end
|
10
|
-
|
11
10
|
end
|
data/test/test_cli_crc32.rb
CHANGED
@@ -81,7 +81,7 @@ class TestCliCrc32 < Test::Unit::TestCase
|
|
81
81
|
assert_match(/invalid range/, @stderr_io.string)
|
82
82
|
end
|
83
83
|
|
84
|
-
def
|
84
|
+
def test_range_last_ten_hex_invalid
|
85
85
|
assert_equal 1, go_with_args(%w(-x 26:z30))
|
86
86
|
assert_match(/invalid range/, @stderr_io.string)
|
87
87
|
end
|