rbkb 0.7.1 → 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 -13
- 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 +21 -3
- 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 -22
data/lib/rbkb/extends/symbol.rb
CHANGED
data/lib/rbkb/extends.rb
CHANGED
data/lib/rbkb/plug/blit.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
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
|
module Plug
|
5
5
|
module Blit
|
6
6
|
include Base
|
7
7
|
|
8
|
-
DEFAULT_IPADDR =
|
9
|
-
DEFAULT_PORT =
|
8
|
+
DEFAULT_IPADDR = '127.0.0.1'
|
9
|
+
DEFAULT_PORT = 25_195
|
10
10
|
DEFAULT_PROTOCOL = :TCP
|
11
11
|
|
12
12
|
OPCODES = {
|
@@ -18,7 +18,7 @@ module Plug
|
|
18
18
|
7 => :starttls,
|
19
19
|
|
20
20
|
0xfe => :clear,
|
21
|
-
0xff => :kill
|
21
|
+
0xff => :kill
|
22
22
|
}
|
23
23
|
|
24
24
|
attr_accessor :kind
|
@@ -40,94 +40,91 @@ module Plug
|
|
40
40
|
# override so we don't get unneccessary "closed" message from Base
|
41
41
|
end
|
42
42
|
|
43
|
-
|
44
43
|
### Blit protocol stuff
|
45
|
-
SIG =
|
44
|
+
SIG = 'BLT'
|
46
45
|
|
47
46
|
# (re)initializes the blit buffer
|
48
47
|
def initbuf
|
49
48
|
@buf = StringIO.new
|
50
49
|
end
|
51
|
-
|
52
|
-
def receive_data
|
50
|
+
|
51
|
+
def receive_data(dat)
|
53
52
|
return unless (@buf.write(dat) > SIG.size) or (@buf.pos > (SIG.size + 1))
|
54
53
|
|
55
54
|
@buf.rewind
|
56
55
|
|
57
56
|
return unless @buf.read(SIG.size) == SIG and
|
58
|
-
op = OPCODES[
|
57
|
+
op = OPCODES[@buf.read(1)[0]]
|
59
58
|
|
60
|
-
initbuf if
|
59
|
+
initbuf if send(op)
|
61
60
|
end
|
62
|
-
|
63
61
|
|
64
62
|
def self.blit_header(op)
|
65
63
|
return nil unless opno = OPCODES.invert[op]
|
64
|
+
|
66
65
|
SIG + opno.chr
|
67
66
|
end
|
68
67
|
|
69
68
|
def starttls
|
70
|
-
unless
|
71
|
-
|
69
|
+
unless peerno = @buf.read(2) and peerno.size == 2 and
|
70
|
+
peer = @peers[peerno.dat_to_num(:big)]
|
72
71
|
|
73
|
-
UI.log
|
72
|
+
UI.log '** BLIT-ERROR(Malformed or missing peer for starttls)'
|
74
73
|
return true
|
75
74
|
end
|
76
75
|
|
77
76
|
peer.start_tls(self)
|
78
77
|
end
|
79
|
-
|
78
|
+
|
80
79
|
def self.make_starttls(peerno)
|
81
|
-
|
80
|
+
blit_header(:starttls) + peerno.to_bytes(:big, 2)
|
82
81
|
end
|
83
82
|
|
84
83
|
def mute
|
85
|
-
unless
|
86
|
-
|
84
|
+
unless peerno = @buf.read(2) and peerno.size == 2 and
|
85
|
+
@peers[peerno.dat_to_num(:big)]
|
87
86
|
|
88
|
-
UI.log
|
89
|
-
|
87
|
+
UI.log '** BLIT-ERROR(Malformed or missing peer for mute)'
|
88
|
+
true
|
90
89
|
end
|
91
90
|
end
|
92
91
|
|
93
92
|
def self.make_mute(peerno)
|
94
|
-
|
93
|
+
blit_header(:squelch) +
|
95
94
|
peerno.to_bytes(:big, 2)
|
96
95
|
end
|
97
96
|
|
98
97
|
def unmute
|
99
|
-
unless
|
100
|
-
|
101
|
-
UI.log
|
102
|
-
|
98
|
+
unless peerno = @buf.read(2) and peerno.size == 2 and
|
99
|
+
@peers[peerno.dat_to_num(:big)]
|
100
|
+
UI.log '** BLIT-ERROR(Malformed or missing peer for unmute)'
|
101
|
+
true
|
103
102
|
end
|
104
103
|
end
|
105
104
|
|
106
105
|
def self.make_squelch(peerno)
|
107
|
-
|
106
|
+
blit_header(:squelch) +
|
108
107
|
peerno.to_bytes(:big, 2)
|
109
108
|
end
|
110
109
|
|
111
110
|
def sendmsg
|
112
|
-
unless peerno
|
113
|
-
bufsiz
|
114
|
-
UI.log
|
111
|
+
unless peerno = @buf.read(2) and peerno.size == 2 and
|
112
|
+
bufsiz = @buf.read(4) and bufsiz.size == 4
|
113
|
+
UI.log '** BLIT-ERROR(Malformed sendmsg)'
|
115
114
|
return true
|
116
115
|
end
|
117
116
|
|
118
117
|
peerno = peerno.dat_to_num(:big)
|
119
118
|
bufsiz = bufsiz.dat_to_num(:big)
|
120
119
|
|
121
|
-
if (rdat
|
122
|
-
if peer
|
120
|
+
if (rdat = @buf.read(bufsiz)).size == bufsiz
|
121
|
+
if peer = @peers[peerno]
|
123
122
|
peer.say(rdat, self)
|
124
|
-
|
123
|
+
true
|
125
124
|
else
|
126
125
|
UI.log "** BLIT-ERROR(Invalid peer index #{peerno})"
|
127
|
-
|
126
|
+
true
|
128
127
|
end
|
129
|
-
else
|
130
|
-
return nil
|
131
128
|
end
|
132
129
|
end
|
133
130
|
|
@@ -138,19 +135,19 @@ module Plug
|
|
138
135
|
# uint32le size = length of data
|
139
136
|
# str data
|
140
137
|
def self.make_sendmsg(idx, dat)
|
141
|
-
|
142
|
-
idx.to_bytes(:big, 2) +
|
143
|
-
dat.size.to_bytes(:big, 4) +
|
138
|
+
blit_header(:sendmsg) +
|
139
|
+
idx.to_bytes(:big, 2) +
|
140
|
+
dat.size.to_bytes(:big, 4) +
|
144
141
|
dat
|
145
142
|
end
|
146
143
|
|
147
144
|
def kill
|
148
|
-
UI.log(
|
145
|
+
UI.log('** BLIT-KILL - Received shutdown command')
|
149
146
|
EM.stop
|
150
147
|
end
|
151
148
|
|
152
|
-
def self.make_kill(
|
153
|
-
|
149
|
+
def self.make_kill(_idx = nil)
|
150
|
+
blit_header(:kill)
|
154
151
|
end
|
155
152
|
|
156
153
|
def clear
|
@@ -159,27 +156,27 @@ module Plug
|
|
159
156
|
end
|
160
157
|
|
161
158
|
def self.make_clear
|
162
|
-
|
159
|
+
blit_header(:clear)
|
163
160
|
end
|
164
161
|
|
165
162
|
def delete(peerno)
|
166
163
|
@peers.delete(peerno)
|
167
164
|
end
|
168
165
|
|
169
|
-
def self.make_delete(idx=0)
|
170
|
-
|
166
|
+
def self.make_delete(idx = 0)
|
167
|
+
blit_header(:delete) +
|
171
168
|
idx.to_bytes(:big, 2)
|
172
169
|
end
|
173
170
|
|
174
171
|
def list_peers
|
175
|
-
UI.log(
|
172
|
+
UI.log('** BLIT-LISTPEERS - Received list peers command')
|
176
173
|
|
177
|
-
@peers.each_index {|i| UI.log "** #{i} - #{@peers[i].name}"}
|
178
|
-
UI.log(
|
174
|
+
@peers.each_index { |i| UI.log "** #{i} - #{@peers[i].name}" }
|
175
|
+
UI.log('** BLIT-LISTPEERS-END - End of peer list')
|
179
176
|
end
|
180
177
|
|
181
178
|
def self.make_list_peers
|
182
|
-
|
179
|
+
blit_header(:list_peers)
|
183
180
|
end
|
184
181
|
|
185
182
|
#----------------------------------------------------------------------
|
@@ -187,33 +184,33 @@ module Plug
|
|
187
184
|
#----------------------------------------------------------------------
|
188
185
|
|
189
186
|
BLIT_HANDLERS = {
|
190
|
-
:
|
191
|
-
s=TCPSocket.new(@blit_addr, @blit_port)
|
192
|
-
wl=s.write(msg)
|
187
|
+
TCP: lambda { |msg|
|
188
|
+
s = TCPSocket.new(@blit_addr, @blit_port)
|
189
|
+
wl = s.write(msg)
|
193
190
|
s.close
|
194
|
-
|
191
|
+
wl
|
195
192
|
},
|
196
|
-
:
|
197
|
-
s=UDPSocket.new
|
198
|
-
wl=s.send(
|
193
|
+
UDP: lambda { |msg|
|
194
|
+
s = UDPSocket.new
|
195
|
+
wl = s.send(msg, 0, @blit_addr, @blit_port)
|
199
196
|
s.close
|
200
|
-
|
197
|
+
wl
|
201
198
|
}
|
202
199
|
}
|
203
200
|
|
204
|
-
def self.blit_init(opts={})
|
205
|
-
@blit_addr =
|
206
|
-
@blit_port =
|
207
|
-
proto =
|
208
|
-
@blit_handler = BLIT_HANDLERS[
|
209
|
-
raise
|
201
|
+
def self.blit_init(opts = {})
|
202
|
+
@blit_addr = opts[:addr] || DEFAULT_IPADDR
|
203
|
+
@blit_port = opts[:port] || DEFAULT_PORT
|
204
|
+
proto = opts[:protocol] || DEFAULT_PROTOCOL
|
205
|
+
@blit_handler = BLIT_HANDLERS[proto]
|
206
|
+
raise 'invalid blit transport protocol' unless @blit_handler
|
210
207
|
end
|
211
208
|
|
212
209
|
def self.initialized?
|
213
210
|
@blit_addr and @blit_port and @blit_handler
|
214
211
|
end
|
215
212
|
|
216
|
-
def self.blit_send(data, idx=0)
|
213
|
+
def self.blit_send(data, idx = 0)
|
217
214
|
msg = make_sendmsg(idx, data)
|
218
215
|
blit_raw(msg)
|
219
216
|
end
|
@@ -224,19 +221,19 @@ module Plug
|
|
224
221
|
end
|
225
222
|
|
226
223
|
def self.blit_raw(buf)
|
227
|
-
raise
|
224
|
+
raise 'use blit_init first!' unless initialized?
|
225
|
+
|
228
226
|
@blit_handler.call buf
|
229
227
|
end
|
230
|
-
|
231
|
-
end # of module Blit
|
232
|
-
|
228
|
+
end # of module Blit
|
233
229
|
end # of module Plug
|
234
230
|
|
235
231
|
class String
|
236
232
|
#----------------------------------------------------------------------
|
237
233
|
# A Blit sender convenience method for strings
|
238
|
-
def blit(idx=0)
|
239
|
-
raise
|
234
|
+
def blit(idx = 0)
|
235
|
+
raise 'blit must be initialized with blit_init' unless Plug::Blit.initialized?
|
236
|
+
|
240
237
|
Plug::Blit.blit_send(self, idx)
|
241
238
|
end
|
242
239
|
end
|
data/lib/rbkb/plug/cli.rb
CHANGED
@@ -2,19 +2,17 @@ require 'rbkb/cli'
|
|
2
2
|
require 'rbkb/plug'
|
3
3
|
require 'eventmachine'
|
4
4
|
|
5
|
-
|
6
|
-
# Copyright 2009 emonti at matasano.com
|
5
|
+
# Copyright 2009 emonti at matasano.com
|
7
6
|
# See README.rdoc for license information
|
8
7
|
#
|
9
8
|
module Rbkb::Cli
|
10
|
-
|
11
9
|
# Rbkb::Cli::Executable is an abstract class for creating command line
|
12
10
|
# executables using the Ruby Black Bag framework.
|
13
11
|
class PlugCli < Executable
|
14
|
-
RX_HOST_AND_PORT = /^([\w
|
15
|
-
RX_PORT_OPT_ADDR = /^(?:([\w
|
12
|
+
RX_HOST_AND_PORT = /^([\w._-]+):(\d+)$/
|
13
|
+
RX_PORT_OPT_ADDR = /^(?:([\w._-]+):)?(\d+)$/
|
16
14
|
|
17
|
-
attr_accessor :blit_addr, :blit_port, :blit_proto,
|
15
|
+
attr_accessor :blit_addr, :blit_port, :blit_proto,
|
18
16
|
:local_addr, :local_port, :transport,
|
19
17
|
:target_addr, :target_port, :plug_opts
|
20
18
|
|
@@ -27,57 +25,56 @@ module Rbkb::Cli
|
|
27
25
|
yield this if block_given?
|
28
26
|
end
|
29
27
|
|
30
|
-
# TODO Plug::UI obviously need fixing.
|
28
|
+
# TODO: Plug::UI obviously need fixing.
|
31
29
|
# TODO It shouldn't be driven by constants for configuration
|
32
30
|
Plug::UI::LOGCFG[:verbose] = true
|
33
31
|
Plug::UI::LOGCFG[:dump] = :hex
|
34
32
|
Plug::UI::LOGCFG[:out] = @stderr
|
35
33
|
end
|
36
34
|
|
37
|
-
def make_parser
|
35
|
+
def make_parser
|
38
36
|
arg = super()
|
39
|
-
arg.banner <<
|
37
|
+
arg.banner << ' host:port'
|
40
38
|
|
41
|
-
arg.on(
|
42
|
-
Plug::UI::LOGCFG[:out] = File.open(o,
|
39
|
+
arg.on('-o', '--output=FILE', 'Output to file') do |o|
|
40
|
+
Plug::UI::LOGCFG[:out] = File.open(o, 'w') # XXX
|
43
41
|
end
|
44
42
|
|
45
|
-
arg.on(
|
43
|
+
arg.on('-q', '--quiet', 'Turn off verbose logging') do
|
46
44
|
Plug::UI::LOGCFG[:verbose] = false # XXX
|
47
45
|
end
|
48
46
|
|
49
|
-
arg.on(
|
50
|
-
|
51
|
-
if m
|
47
|
+
arg.on('-d', '--dump-format=hex/raw',
|
48
|
+
'Output conversations in hexdump or raw') do |d|
|
49
|
+
if m = /^(hex|raw)$/i.match(d)
|
52
50
|
Plug::UI::LOGCFG[:dump] = m[1].downcase.to_sym # XXX
|
53
51
|
else
|
54
52
|
bail "Invalid dump format: #{d.inspect}"
|
55
53
|
end
|
56
54
|
end
|
57
55
|
|
58
|
-
arg.on(
|
59
|
-
unless m=RX_PORT_OPT_ADDR.match(b)
|
60
|
-
bail(
|
56
|
+
arg.on('-b', '--blit=ADDR:PORT', 'Where to listen for blit') do |b|
|
57
|
+
unless m = RX_PORT_OPT_ADDR.match(b)
|
58
|
+
bail('Invalid blit address/port')
|
61
59
|
end
|
62
60
|
@blit_port = m[2].to_i
|
63
61
|
@blit_addr = m[1] if m[1]
|
64
62
|
end
|
65
63
|
|
66
|
-
arg.on(
|
64
|
+
arg.on('-u', '--udp', 'UDP mode') { @transport = :UDP }
|
67
65
|
|
68
|
-
arg.on(
|
66
|
+
arg.on('-S', '--start-tls', 'Initiate TLS') { |_s| @plug_opts[:tls] = true }
|
69
67
|
|
70
|
-
|
68
|
+
arg
|
71
69
|
end
|
72
70
|
|
73
|
-
def parse_target_argument
|
74
|
-
unless (m = RX_HOST_AND_PORT.match(tgt
|
71
|
+
def parse_target_argument
|
72
|
+
unless (m = RX_HOST_AND_PORT.match(tgt = @argv.shift))
|
75
73
|
bail "Invalid target: #{tgt}\n Hint: use -h"
|
76
74
|
end
|
77
75
|
@target_addr = m[1]
|
78
76
|
@target_port = m[2].to_i
|
79
|
-
|
77
|
+
m
|
80
78
|
end
|
81
79
|
end
|
82
80
|
end
|
83
|
-
|
@@ -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
|
|
@@ -6,60 +6,57 @@ require 'yaml'
|
|
6
6
|
require 'rbkb'
|
7
7
|
|
8
8
|
module FeedImport
|
9
|
-
|
10
9
|
## TODO switch to pcaprub or some other up to date pcap lib. make it a dep.
|
11
10
|
begin
|
12
11
|
## This requires the 'ruby-pcap' library from:
|
13
12
|
## http://raa.ruby-lang.org/project/pcap/
|
14
13
|
## ... which is old and krufty...
|
15
|
-
$VERBOSE=nil
|
14
|
+
$VERBOSE = nil
|
16
15
|
require 'pcaplet'
|
17
|
-
$VERBOSE=false
|
16
|
+
$VERBOSE = false
|
18
17
|
|
19
18
|
# Imports an array from pcap
|
20
|
-
def import_pcap(file, filter=nil)
|
21
|
-
ret =
|
19
|
+
def import_pcap(file, filter = nil)
|
20
|
+
ret = []
|
22
21
|
pcap = Pcap::Capture.open_offline(file)
|
23
22
|
pcap.setfilter filter if filter
|
24
23
|
pcap.each_packet do |pkt|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
24
|
+
next unless (pkt.udp? and dat = pkt.udp_data) or
|
25
|
+
(pkt.tcp? and dat = pkt.tcp_data and !dat.empty?)
|
26
|
+
|
27
|
+
ret << dat
|
30
28
|
end
|
31
|
-
|
29
|
+
ret
|
32
30
|
end
|
33
31
|
rescue LoadError
|
34
|
-
def import_pcap(*
|
35
|
-
raise
|
32
|
+
def import_pcap(*_args)
|
33
|
+
raise 'you must install ruby-pcap to use this feature'
|
36
34
|
end
|
37
35
|
end
|
38
36
|
|
39
37
|
module_function :import_pcap
|
40
38
|
|
41
|
-
|
42
39
|
# Imports an array from yaml
|
43
40
|
def import_yaml(file)
|
44
|
-
unless (
|
41
|
+
unless (ret = YAML.load_file(file)).is_a? Array
|
45
42
|
raise "#{file.inspect} did not provide an array"
|
46
43
|
end
|
47
|
-
|
44
|
+
|
45
|
+
ret
|
48
46
|
end
|
49
47
|
module_function :import_yaml
|
50
48
|
|
51
|
-
|
52
49
|
# Imports from hexdumps separated by "%" and merged by ','
|
53
50
|
def import_dump(file)
|
54
51
|
ret = []
|
55
52
|
dat = File.read(file)
|
56
53
|
dat.strip.split(/^%$/).each do |msg|
|
57
|
-
ret <<
|
54
|
+
ret << ''
|
58
55
|
msg.strip.split(/^,$/).each do |chunk|
|
59
56
|
ret[-1] << chunk.strip.dehexdump
|
60
57
|
end
|
61
58
|
end
|
62
|
-
|
59
|
+
ret
|
63
60
|
end
|
64
61
|
module_function :import_dump
|
65
62
|
|
@@ -71,4 +68,3 @@ module FeedImport
|
|
71
68
|
end
|
72
69
|
module_function :import_rawfiles
|
73
70
|
end
|
74
|
-
|
data/lib/rbkb/plug/peer.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
5
|
require 'socket'
|
6
6
|
|
7
7
|
module Plug
|
8
|
-
|
9
8
|
class Peer
|
10
9
|
attr_reader :addr, :transport, :name, :owner, :host, :port
|
11
10
|
attr_accessor :mute
|
@@ -20,7 +19,7 @@ module Plug
|
|
20
19
|
end
|
21
20
|
|
22
21
|
def say(dat, sender)
|
23
|
-
UI.dump(sender.name,
|
22
|
+
UI.dump(sender.name, name, dat)
|
24
23
|
|
25
24
|
if @transport == :UDP
|
26
25
|
@owner.send_datagram(dat, @host, @port)
|
@@ -30,7 +29,7 @@ module Plug
|
|
30
29
|
end
|
31
30
|
|
32
31
|
def start_tls(sender)
|
33
|
-
UI.logmsg(
|
32
|
+
UI.logmsg(name, "#{sender.name} initiated TLS")
|
34
33
|
@owner.start_tls
|
35
34
|
end
|
36
35
|
|
@@ -39,34 +38,33 @@ module Plug
|
|
39
38
|
end
|
40
39
|
end
|
41
40
|
|
42
|
-
|
43
41
|
class PeerList < Array
|
44
42
|
def initialize(owner, *args)
|
45
43
|
@owner = owner
|
46
44
|
@transport = @owner.transport
|
47
|
-
|
45
|
+
|
48
46
|
super(*args)
|
49
47
|
end
|
50
48
|
|
51
49
|
def find_peer(addr)
|
52
|
-
|
50
|
+
find { |p| p.addr == addr }
|
53
51
|
end
|
54
52
|
|
55
53
|
def add_peer(addr)
|
56
54
|
self << Peer.new(addr, @owner)
|
57
|
-
|
55
|
+
last
|
58
56
|
end
|
59
57
|
|
60
58
|
def add_peer_manually(host, port)
|
61
59
|
addr = Socket.pack_sockaddr_in(port, host)
|
62
|
-
|
60
|
+
find_peer(addr) || add_peer(addr)
|
63
61
|
end
|
64
62
|
|
65
63
|
def delete(addr)
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
64
|
+
return unless p = find_peer(addr)
|
65
|
+
|
66
|
+
p.close
|
67
|
+
super(p)
|
70
68
|
end
|
71
69
|
end
|
72
70
|
end
|