rflow-components-irc 0.0.2 → 1.0.0a2
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 +7 -0
- data/.rspec +1 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/lib/rflow/components/irc/client.rb +23 -49
- data/lib/rflow/components/irc/extensions.rb +0 -6
- data/lib/rflow/components/irc/version.rb +1 -1
- data/lib/rflow/components/irc.rb +0 -3
- data/lib/rflow-components-irc.rb +0 -1
- data/rflow-components-irc.gemspec +4 -3
- data/spec/schema_spec.rb +10 -14
- metadata +40 -32
- data/spec/extensions_spec.rb +0 -47
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0268a88eef6110cffb56210467baef133fee9922
|
4
|
+
data.tar.gz: 26f578ac2b04c07abd6d196cc580e3c08b4391c7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 13e6df4df36df74e49c8155f0a5171cf6ea010a4d3754e76e090b67b0f4c81855a056c4f8630a41f57b7cf56e0651da73ef5ad6c6ff0c1510d009f8e177daf4e
|
7
|
+
data.tar.gz: 3ae240268dfe449de3758d2d0bf748e69caedc508e82b30b3871c1ca62e682c80d01a8ba8417d70a41487456a7563249333431fb8a1fc0c1749cf739b01ce3a4
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color -fd
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rflow-dev
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.1.1
|
@@ -1,11 +1,9 @@
|
|
1
1
|
require 'eventmachine'
|
2
|
-
|
3
2
|
require 'rflow'
|
4
3
|
|
5
4
|
class RFlow
|
6
5
|
module Components
|
7
6
|
module IRC
|
8
|
-
|
9
7
|
# Assumes a single connection, meaning that it can choose to be
|
10
8
|
# 'promiscuous' and not limit its sending to only those messages
|
11
9
|
# derived from one of its own
|
@@ -15,7 +13,6 @@ class RFlow
|
|
15
13
|
|
16
14
|
attr_accessor :config
|
17
15
|
attr_accessor :client_connection
|
18
|
-
|
19
16
|
attr_accessor :server, :port
|
20
17
|
|
21
18
|
DEFAULT_CONFIG = {
|
@@ -48,7 +45,6 @@ class RFlow
|
|
48
45
|
end
|
49
46
|
end
|
50
47
|
|
51
|
-
|
52
48
|
def process_message(input_port, input_port_key, connection, message)
|
53
49
|
RFlow.logger.debug "Received a message"
|
54
50
|
return unless message.data_type_name == 'RFlow::Message::Data::IRC::Message'
|
@@ -58,26 +54,20 @@ class RFlow
|
|
58
54
|
client_connection.send_irc_message message
|
59
55
|
else
|
60
56
|
RFlow.logger.debug "Received an IRC::Message message, determining if its mine"
|
61
|
-
my_events = message.provenance.find_all {|
|
57
|
+
my_events = message.provenance.find_all {|event| event.component_instance_uuid == instance_uuid}
|
62
58
|
RFlow.logger.debug "Found #{my_events.size} processing events from me"
|
63
|
-
# Attempt to send the data to each context match.
|
64
|
-
# check for correctness
|
65
|
-
my_events.each do |
|
66
|
-
RFlow.logger.debug "Inspecting context #{client_connection.signature.to_s} == #{
|
67
|
-
if client_connection.signature.to_s ==
|
68
|
-
RFlow.logger.debug "Found connection for #{
|
59
|
+
# Attempt to send the data to each context match.
|
60
|
+
# TODO: check for correctness
|
61
|
+
my_events.each do |event|
|
62
|
+
RFlow.logger.debug "Inspecting context #{client_connection.signature.to_s} == #{event.context.to_s}"
|
63
|
+
if client_connection.signature.to_s == event.context.to_s
|
64
|
+
RFlow.logger.debug "Found connection for #{event.context}, sending message to associated client connection"
|
69
65
|
client_connection.send_irc_message message
|
70
66
|
end
|
71
67
|
end
|
72
68
|
end
|
73
69
|
end
|
74
70
|
|
75
|
-
def shutdown!
|
76
|
-
end
|
77
|
-
|
78
|
-
def cleanup!
|
79
|
-
end
|
80
|
-
|
81
71
|
class Connection < EventMachine::Connection
|
82
72
|
include EventMachine::Protocols::LineText2
|
83
73
|
|
@@ -91,7 +81,6 @@ class RFlow
|
|
91
81
|
super
|
92
82
|
end
|
93
83
|
|
94
|
-
|
95
84
|
def connection_completed
|
96
85
|
@reconnecting = false
|
97
86
|
@connected = true
|
@@ -105,39 +94,32 @@ class RFlow
|
|
105
94
|
command "OPER", [client.config['oper_user'] || client.config['nickname'], client.config['oper_password']] unless client.config['oper_password'].nil?
|
106
95
|
end
|
107
96
|
|
108
|
-
|
109
97
|
def receive_line(line)
|
110
98
|
RFlow.logger.debug("IRCClient#receive_line: #{line}")
|
111
|
-
processing_event = RFlow::Message::ProcessingEvent.new(client.instance_uuid, Time.now.utc)
|
112
|
-
|
113
99
|
prefix, cmd, params = IRC.parse_irc_line(line)
|
114
100
|
|
115
|
-
# Now have an optional prefix, required cmd, and optional
|
116
|
-
# param array
|
117
|
-
|
101
|
+
# Now have an optional prefix, required cmd, and optional param array
|
118
102
|
case cmd
|
119
103
|
when /PING/
|
120
104
|
command('PONG', params)
|
121
105
|
else
|
122
106
|
# create an IRC message here and send it along
|
123
107
|
RFlow.logger.debug("Sending IRC message '#{line}', signature '#{signature.class}:#{signature}', '#{signature.to_s.class}:#{signature.to_s}'")
|
124
|
-
irc_message = RFlow::Message.new('RFlow::Message::Data::IRC::Message')
|
125
|
-
|
126
|
-
irc_message.data.prefix = prefix
|
127
|
-
irc_message.data.command = cmd
|
128
|
-
irc_message.data.parameters = params
|
129
108
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
109
|
+
client.from_server.send_message(RFlow::Message.new('RFlow::Message::Data::IRC::Message').tap do |m|
|
110
|
+
m.data.prefix = prefix
|
111
|
+
m.data.command = cmd
|
112
|
+
m.data.parameters = params
|
113
|
+
m.provenance << RFlow::Message::ProcessingEvent.new(client.instance_uuid, Time.now.utc).tap do |e|
|
114
|
+
e.context = signature.to_s
|
115
|
+
e.completed_at = Time.now.utc
|
116
|
+
end
|
117
|
+
end)
|
135
118
|
end
|
136
119
|
end
|
137
120
|
|
138
|
-
|
139
|
-
|
140
|
-
if @connected or @reconnecting
|
121
|
+
def unbind(reason = nil)
|
122
|
+
if @connected || @reconnecting
|
141
123
|
RFlow.logger.error("Disconnected from IRC server #{client.config['server']}:#{client.config['port']} due to '#{reason}', reconnecting ...")
|
142
124
|
EM.add_timer(client.config['reconnect_interval']) do
|
143
125
|
RFlow.logger.error "Attempting reconnect to IRC server #{client.config['server']}:#{client.config['port']}"
|
@@ -146,26 +128,21 @@ class RFlow
|
|
146
128
|
@connected = false
|
147
129
|
@reconnecting = true
|
148
130
|
else
|
149
|
-
|
150
|
-
RFlow.logger.error error_message
|
151
|
-
raise RuntimeError, error_message
|
131
|
+
raise RuntimeError, "Unable to connect to IRC server #{client.config['server']}:#{client.config['port']} due to '#{reason}'"
|
152
132
|
end
|
153
133
|
end
|
154
134
|
|
155
|
-
|
156
135
|
def send_irc_message(irc_message)
|
157
136
|
RFlow.logger.debug "Sending an IRC message to #{client_ip}:#{client_port}"
|
158
137
|
command irc_message.data.command, irc_message.data.parameters, irc_message.data.prefix
|
159
138
|
end
|
160
139
|
|
161
|
-
|
162
140
|
def send_irc_line(line)
|
163
141
|
RFlow.logger.debug "Sending line '#{line}'"
|
164
142
|
send_data "#{line}\r\n"
|
165
143
|
end
|
166
144
|
|
167
|
-
|
168
|
-
def command(cmd, args=[], prefix=nil)
|
145
|
+
def command(cmd, args = [], prefix = nil)
|
169
146
|
RFlow.logger.debug("command: '#{cmd}' with args ['#{args.join("', '")}'] and prefix '#{prefix}'")
|
170
147
|
line = ''
|
171
148
|
if prefix
|
@@ -175,11 +152,9 @@ class RFlow
|
|
175
152
|
line << cmd.upcase
|
176
153
|
|
177
154
|
last_arg = args.pop
|
178
|
-
unless args.empty?
|
179
|
-
line << " #{args.join ' '}"
|
180
|
-
end
|
155
|
+
line << " #{args.join ' '}" unless args.empty?
|
181
156
|
|
182
|
-
if last_arg =~ /\s
|
157
|
+
if last_arg =~ /\s/;
|
183
158
|
line << ' :' << last_arg
|
184
159
|
else
|
185
160
|
line << ' ' << last_arg
|
@@ -187,7 +162,6 @@ class RFlow
|
|
187
162
|
|
188
163
|
send_irc_line line
|
189
164
|
end
|
190
|
-
|
191
165
|
end
|
192
166
|
end
|
193
167
|
end
|
@@ -1,10 +1,7 @@
|
|
1
1
|
class RFlow
|
2
2
|
module Components
|
3
3
|
module IRC
|
4
|
-
|
5
|
-
# The set of extensions to add capability to IRC data types
|
6
4
|
module Extensions
|
7
|
-
|
8
5
|
module IRCMessageExtension
|
9
6
|
def self.extended(base_data)
|
10
7
|
base_data.data_object ||= {'timestamp' => Time.now.xmlschema, 'prefix' => nil, 'command' => 'PRIVMSG', 'parameters' => []}
|
@@ -38,10 +35,7 @@ class RFlow
|
|
38
35
|
end
|
39
36
|
end
|
40
37
|
end
|
41
|
-
|
42
|
-
|
43
38
|
end
|
44
|
-
|
45
39
|
end
|
46
40
|
end
|
47
41
|
end
|
data/lib/rflow/components/irc.rb
CHANGED
@@ -20,9 +20,7 @@ class RFlow
|
|
20
20
|
RFlow::Configuration.add_available_data_extension('RFlow::Message::Data::IRC::Message',
|
21
21
|
RFlow::Components::IRC::Extensions::IRCMessageExtension)
|
22
22
|
|
23
|
-
|
24
23
|
# Some useful IRC parsing methods
|
25
|
-
|
26
24
|
IRC_LINE_REGEX = /^(?::(\S+) )?(\S+)(?: (.+))?$/
|
27
25
|
IRC_PREFIX_REGEX = /^([^!]+)(?:!([^@]+))?(?:@(.*)+)?$/
|
28
26
|
|
@@ -52,7 +50,6 @@ class RFlow
|
|
52
50
|
# nick/server, user, host
|
53
51
|
match[1..3]
|
54
52
|
end
|
55
|
-
|
56
53
|
end
|
57
54
|
end
|
58
55
|
end
|
data/lib/rflow-components-irc.rb
CHANGED
@@ -21,8 +21,9 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
22
22
|
s.require_paths = ["lib"]
|
23
23
|
|
24
|
-
s.add_dependency 'rflow', '~>
|
24
|
+
s.add_dependency 'rflow', '~> 1.0.0a2'
|
25
25
|
|
26
|
-
s.add_development_dependency 'rspec', '~> 2.
|
27
|
-
s.add_development_dependency '
|
26
|
+
s.add_development_dependency 'rspec', '~> 2.99'
|
27
|
+
s.add_development_dependency 'rspec-collection_matchers', '~> 0.0.4'
|
28
|
+
s.add_development_dependency 'rake', '~> 0.8'
|
28
29
|
end
|
data/spec/schema_spec.rb
CHANGED
@@ -1,27 +1,23 @@
|
|
1
|
-
require 'spec_helper
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'RFlow::Message::Data::IRC::Message Avro Schema' do
|
4
|
-
|
5
|
-
@schema_string = RFlow::Configuration.available_data_types['RFlow::Message::Data::IRC::Message']['avro']
|
6
|
-
end
|
4
|
+
let(:schema) { RFlow::Configuration.available_data_types['RFlow::Message::Data::IRC::Message']['avro'] }
|
7
5
|
|
8
6
|
it "should encode and decode an object" do
|
9
|
-
|
7
|
+
message = {
|
10
8
|
'timestamp' => Time.now.xmlschema,
|
11
|
-
# 'prefix' => nil,
|
12
9
|
'command' => 'PRIVMSG',
|
13
10
|
'parameters' => ['yo yo yo'],
|
14
11
|
}
|
15
12
|
|
16
|
-
expect {encode_avro(
|
17
|
-
|
18
|
-
|
19
|
-
expect {decode_avro(@schema_string, avro_encoded_irc_message)}.to_not raise_error
|
20
|
-
decoded_irc_message = decode_avro(@schema_string, avro_encoded_irc_message)
|
13
|
+
expect { encode_avro(schema, message) }.to_not raise_error
|
14
|
+
encoded_message = encode_avro(schema, message)
|
21
15
|
|
22
|
-
|
23
|
-
|
24
|
-
decoded_irc_message['parameters'].should == irc_message['parameters']
|
16
|
+
expect { decode_avro(schema, encoded_message) }.to_not raise_error
|
17
|
+
decoded_message = decode_avro(schema, encoded_message)
|
25
18
|
|
19
|
+
decoded_message['prefix'].should == message['prefix']
|
20
|
+
decoded_message['command'].should == message['command']
|
21
|
+
decoded_message['parameters'].should == message['parameters']
|
26
22
|
end
|
27
23
|
end
|
metadata
CHANGED
@@ -1,64 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rflow-components-irc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.0a2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Michael L. Artz
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2014-
|
11
|
+
date: 2014-06-04 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rflow
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- - ~>
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
19
|
+
version: 1.0.0a2
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- - ~>
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
26
|
+
version: 1.0.0a2
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rspec
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- - ~>
|
31
|
+
- - "~>"
|
36
32
|
- !ruby/object:Gem::Version
|
37
|
-
version: 2.
|
33
|
+
version: '2.99'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- - ~>
|
38
|
+
- - "~>"
|
44
39
|
- !ruby/object:Gem::Version
|
45
|
-
version: 2.
|
40
|
+
version: '2.99'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec-collection_matchers
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.0.4
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.0.4
|
46
55
|
- !ruby/object:Gem::Dependency
|
47
56
|
name: rake
|
48
57
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
58
|
requirements:
|
51
|
-
- - ~>
|
59
|
+
- - "~>"
|
52
60
|
- !ruby/object:Gem::Version
|
53
|
-
version: 0.8
|
61
|
+
version: '0.8'
|
54
62
|
type: :development
|
55
63
|
prerelease: false
|
56
64
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
65
|
requirements:
|
59
|
-
- - ~>
|
66
|
+
- - "~>"
|
60
67
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.8
|
68
|
+
version: '0.8'
|
62
69
|
description: IRC client and server components for the RFlow FBP framework. Also includes
|
63
70
|
the necessary message types
|
64
71
|
email:
|
@@ -67,8 +74,11 @@ executables: []
|
|
67
74
|
extensions: []
|
68
75
|
extra_rdoc_files: []
|
69
76
|
files:
|
70
|
-
- .gitignore
|
71
|
-
- .
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rspec"
|
79
|
+
- ".ruby-gemset"
|
80
|
+
- ".ruby-version"
|
81
|
+
- ".travis.yml"
|
72
82
|
- Gemfile
|
73
83
|
- LICENSE
|
74
84
|
- README.md
|
@@ -80,35 +90,33 @@ files:
|
|
80
90
|
- lib/rflow/components/irc/version.rb
|
81
91
|
- rflow-components-irc.gemspec
|
82
92
|
- schema/irc_message.avsc
|
83
|
-
- spec/extensions_spec.rb
|
84
93
|
- spec/schema_spec.rb
|
85
94
|
- spec/spec_helper.rb
|
86
95
|
homepage: https://github.com/redjack/rflow-components-irc
|
87
96
|
licenses:
|
88
97
|
- Apache-2.0
|
98
|
+
metadata: {}
|
89
99
|
post_install_message:
|
90
100
|
rdoc_options: []
|
91
101
|
require_paths:
|
92
102
|
- lib
|
93
103
|
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
-
none: false
|
95
104
|
requirements:
|
96
|
-
- -
|
105
|
+
- - ">="
|
97
106
|
- !ruby/object:Gem::Version
|
98
107
|
version: '1.9'
|
99
108
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
-
none: false
|
101
109
|
requirements:
|
102
|
-
- -
|
110
|
+
- - ">"
|
103
111
|
- !ruby/object:Gem::Version
|
104
|
-
version:
|
112
|
+
version: 1.3.1
|
105
113
|
requirements: []
|
106
114
|
rubyforge_project: rflow-components-irc
|
107
|
-
rubygems_version:
|
115
|
+
rubygems_version: 2.2.2
|
108
116
|
signing_key:
|
109
|
-
specification_version:
|
117
|
+
specification_version: 4
|
110
118
|
summary: IRC client and server components for the RFlow FBP framework
|
111
119
|
test_files:
|
112
|
-
- spec/extensions_spec.rb
|
113
120
|
- spec/schema_spec.rb
|
114
121
|
- spec/spec_helper.rb
|
122
|
+
has_rdoc:
|
data/spec/extensions_spec.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'spec_helper.rb'
|
2
|
-
|
3
|
-
# describe RFlow::Components::File::Extensions::FileExtension do
|
4
|
-
# before(:each) do
|
5
|
-
# @schema_string = RFlow::Configuration.available_data_types['RFlow::Message::Data::File']['avro']
|
6
|
-
# end
|
7
|
-
#
|
8
|
-
# it "should add the extension to RFlow::Configuration" do
|
9
|
-
# RFlow::Configuration.available_data_extensions['RFlow::Message::Data::File'].should include(described_class)
|
10
|
-
# end
|
11
|
-
#
|
12
|
-
# it "should set the defaults" do
|
13
|
-
# file = RFlow::Message.new('RFlow::Message::Data::File')
|
14
|
-
#
|
15
|
-
# file.data.path.should == '/'
|
16
|
-
# file.data.size.should == 0
|
17
|
-
# file.data.content.should == ''
|
18
|
-
# file.data.creation_timestamp.should == nil
|
19
|
-
# file.data.modification_timestamp.should == nil
|
20
|
-
# file.data.accessed_timestamp.should == nil
|
21
|
-
# end
|
22
|
-
#
|
23
|
-
# it "should correctly use integers or strings for size field" do
|
24
|
-
# file = RFlow::Message.new('RFlow::Message::Data::File')
|
25
|
-
#
|
26
|
-
# file.data.size.should == 0
|
27
|
-
# file.data.size = 10
|
28
|
-
# file.data.size.should == 10
|
29
|
-
# file.data.size = '20'
|
30
|
-
# file.data.size == 20
|
31
|
-
# end
|
32
|
-
#
|
33
|
-
# it "should correctly use Time or xmlschema strings for timestamp fields" do
|
34
|
-
# file = RFlow::Message.new('RFlow::Message::Data::File')
|
35
|
-
#
|
36
|
-
# file.data.creation_timestamp.should == nil
|
37
|
-
# now = Time.now
|
38
|
-
#
|
39
|
-
# file.data.creation_timestamp = now
|
40
|
-
# file.data.creation_timestamp.should == Time.xmlschema(now.xmlschema(9))
|
41
|
-
#
|
42
|
-
# file.data.creation_timestamp = now.xmlschema
|
43
|
-
# file.data.creation_timestamp.should == Time.xmlschema(now.xmlschema)
|
44
|
-
# end
|
45
|
-
#
|
46
|
-
#
|
47
|
-
# end
|