tkellem 0.8.11 → 0.9.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
data/tkellem.gemspec CHANGED
@@ -17,10 +17,12 @@ Gem::Specification.new do |s|
17
17
  s.default_executable = %q{tkellem}
18
18
  s.require_paths = ["lib"]
19
19
 
20
- s.add_dependency "eventmachine", "~> 0.12.10"
21
- s.add_dependency "activerecord", "~> 3.0.0"
22
- s.add_dependency "sqlite3", "~> 1.3.3"
20
+ s.add_dependency "celluloid", "~> 0.13.0"
21
+ s.add_dependency "celluloid-io", "~> 0.13.0"
22
+ s.add_dependency "activesupport", "3.2.10"
23
+ s.add_dependency "sequel", "3.42.0"
24
+ s.add_dependency "sqlite3", "1.3.6"
23
25
 
26
+ s.add_development_dependency "rake"
24
27
  s.add_development_dependency "rspec", "~> 2.5"
25
- s.add_development_dependency "rcov"
26
28
  end
metadata CHANGED
@@ -1,24 +1,24 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tkellem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.11
5
- prerelease:
4
+ version: 0.9.0.beta1
5
+ prerelease: 6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Brian Palmer
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-23 00:00:00.000000000 Z
12
+ date: 2013-01-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: eventmachine
15
+ name: celluloid
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 0.12.10
21
+ version: 0.13.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,15 +26,15 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 0.12.10
29
+ version: 0.13.0
30
30
  - !ruby/object:Gem::Dependency
31
- name: activerecord
31
+ name: celluloid-io
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
35
  - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: 3.0.0
37
+ version: 0.13.0
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,41 +42,57 @@ dependencies:
42
42
  requirements:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: 3.0.0
45
+ version: 0.13.0
46
46
  - !ruby/object:Gem::Dependency
47
- name: sqlite3
47
+ name: activesupport
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
51
- - - ~>
51
+ - - '='
52
52
  - !ruby/object:Gem::Version
53
- version: 1.3.3
53
+ version: 3.2.10
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  none: false
58
58
  requirements:
59
- - - ~>
59
+ - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: 1.3.3
61
+ version: 3.2.10
62
62
  - !ruby/object:Gem::Dependency
63
- name: rspec
63
+ name: sequel
64
64
  requirement: !ruby/object:Gem::Requirement
65
65
  none: false
66
66
  requirements:
67
- - - ~>
67
+ - - '='
68
68
  - !ruby/object:Gem::Version
69
- version: '2.5'
70
- type: :development
69
+ version: 3.42.0
70
+ type: :runtime
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
- - - ~>
75
+ - - '='
76
76
  - !ruby/object:Gem::Version
77
- version: '2.5'
77
+ version: 3.42.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: sqlite3
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - '='
84
+ - !ruby/object:Gem::Version
85
+ version: 1.3.6
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - '='
92
+ - !ruby/object:Gem::Version
93
+ version: 1.3.6
78
94
  - !ruby/object:Gem::Dependency
79
- name: rcov
95
+ name: rake
80
96
  requirement: !ruby/object:Gem::Requirement
81
97
  none: false
82
98
  requirements:
@@ -91,6 +107,22 @@ dependencies:
91
107
  - - ! '>='
92
108
  - !ruby/object:Gem::Version
93
109
  version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: rspec
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '2.5'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: '2.5'
94
126
  description:
95
127
  email:
96
128
  - brian@codekitchen.net
@@ -120,9 +152,9 @@ files:
120
152
  - lib/tkellem.rb
121
153
  - lib/tkellem/bouncer.rb
122
154
  - lib/tkellem/bouncer_connection.rb
155
+ - lib/tkellem/celluloid_tools.rb
123
156
  - lib/tkellem/daemon.rb
124
157
  - lib/tkellem/irc_message.rb
125
- - lib/tkellem/irc_server.rb
126
158
  - lib/tkellem/migrations/001_init_db.rb
127
159
  - lib/tkellem/migrations/002_at_connect_columns.rb
128
160
  - lib/tkellem/migrations/003_settings.rb
@@ -141,9 +173,7 @@ files:
141
173
  - lib/tkellem/version.rb
142
174
  - resources/bot_command_descriptions.yml
143
175
  - resources/setting_descriptions.yml
144
- - spec/bouncer_connection_spec.rb
145
176
  - spec/irc_message_spec.rb
146
- - spec/irc_server_spec.rb
147
177
  - spec/spec_helper.rb
148
178
  - tkellem.gemspec
149
179
  homepage: http://github.com/codekitchen/tkellem
@@ -161,9 +191,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
161
191
  required_rubygems_version: !ruby/object:Gem::Requirement
162
192
  none: false
163
193
  requirements:
164
- - - ! '>='
194
+ - - ! '>'
165
195
  - !ruby/object:Gem::Version
166
- version: '0'
196
+ version: 1.3.1
167
197
  requirements: []
168
198
  rubyforge_project:
169
199
  rubygems_version: 1.8.23
@@ -171,8 +201,6 @@ signing_key:
171
201
  specification_version: 3
172
202
  summary: IRC bouncer with multi-client support
173
203
  test_files:
174
- - spec/bouncer_connection_spec.rb
175
204
  - spec/irc_message_spec.rb
176
- - spec/irc_server_spec.rb
177
205
  - spec/spec_helper.rb
178
206
  has_rdoc:
@@ -1,124 +0,0 @@
1
- require 'eventmachine'
2
- require 'set'
3
- require 'socket'
4
-
5
- require 'tkellem/irc_message'
6
- require 'tkellem/bouncer_connection'
7
-
8
- module Tkellem
9
-
10
- module IrcServerConnection
11
- include EM::Protocols::LineText2
12
-
13
- def initialize(connection_state, bouncer, do_ssl)
14
- set_delimiter "\r\n"
15
- @bouncer = bouncer
16
- @ssl = do_ssl
17
- @connection_state = connection_state
18
- @connected = false
19
- end
20
-
21
- def connection_completed
22
- if @ssl
23
- @bouncer.failsafe(:connection_completed) do
24
- @bouncer.debug "starting TLS"
25
- # TODO: support strict cert checks
26
- start_tls :verify_peer => false
27
- end
28
- else
29
- ssl_handshake_completed
30
- end
31
- end
32
-
33
- def ssl_handshake_completed
34
- @bouncer.failsafe(:ssl_handshake_completed) do
35
- @connected = true
36
- @bouncer.connection_established(self)
37
- end
38
- end
39
-
40
- def receive_line(line)
41
- @bouncer.failsafe(:receive_line) do
42
- @bouncer.trace "from server: #{line}"
43
- return if line.blank?
44
- msg = IrcMessage.parse(line)
45
- @bouncer.server_msg(msg)
46
- end
47
- end
48
-
49
- def unbind
50
- @bouncer.failsafe(:unbind) do
51
- if @connected
52
- @bouncer.disconnected!
53
- else
54
- @bouncer.debug "Connection failed, trying next"
55
- @connection_state.connect!
56
- end
57
- end
58
- end
59
-
60
- class ConnectionState < Struct.new(:bouncer, :network, :attempted, :getting)
61
- def initialize(bouncer, network)
62
- super(bouncer, network, Set.new, false)
63
- reset
64
- end
65
-
66
- def connect!
67
- raise("already in the process of getting an address") if getting
68
- self.getting = true
69
- network.reload
70
- host_infos = network.hosts.map { |h| h.attributes }
71
- EM.defer(proc { find_address(host_infos) }, method(:got_address))
72
- end
73
-
74
- def reset
75
- self.attempted.clear
76
- end
77
-
78
- # runs in threadpool
79
- def find_address(hosts)
80
- candidates = Set.new
81
- hosts.each do |host|
82
- Socket.getaddrinfo(host['address'], host['port'], Socket::AF_INET, Socket::SOCK_STREAM, Socket::IPPROTO_TCP).each do |found|
83
- candidates << [found[3], host['port'], host['ssl']]
84
- end
85
- end
86
-
87
- to_try = candidates.to_a.sort_by { rand }.find { |c| !attempted.include?(c) }
88
- if to_try.nil?
89
- # we've tried all possible hosts, start over
90
- return nil
91
- end
92
-
93
- return to_try
94
- end
95
-
96
- # back on event thread
97
- def got_address(to_try)
98
- self.getting = false
99
-
100
- if !to_try
101
- # sleep for a bit and try again
102
- bouncer.debug "All available addresses failed, sleeping 5s and then trying over"
103
- reset
104
- EM.add_timer(5) { connect! }
105
- return
106
- end
107
-
108
- attempted << to_try
109
- address, port, ssl = to_try
110
-
111
- bouncer.debug "Connecting to: #{Host.address_string(address, port, ssl)}"
112
- bouncer.failsafe("connect: #{Host.address_string(address, port, ssl)}") do
113
- EM.connect(address, port, IrcServerConnection, self, bouncer, ssl)
114
- end
115
- end
116
- end
117
-
118
- def self.connector(bouncer, network)
119
- ConnectionState.new(bouncer, network)
120
- end
121
-
122
- end
123
-
124
- end
@@ -1,37 +0,0 @@
1
- require 'spec_helper'
2
- require 'tkellem/bouncer_connection'
3
-
4
- include Tkellem
5
-
6
- describe BouncerConnection, "connect" do
7
- before do
8
- @u = User.create(:username => 'speccer')
9
- @u.password = 'test123'
10
- @u.save
11
- @tk = mock(TkellemServer)
12
- @b = mock(Bouncer)
13
- @bc = em(BouncerConnection).new(@tk, false)
14
- end
15
-
16
- it "should ignore blank lines" do
17
- @bc.should_receive(:error!).never
18
- @bc.receive_line("")
19
- end
20
-
21
- it "should connect after receiving credentials" do
22
- @tk.should_receive(:find_bouncer).with(@u, 'testhost').and_return(@b)
23
- @bc.receive_line("NICK speccer")
24
- @bc.receive_line("PASS test123")
25
- @b.should_receive(:connect_client).with(@bc)
26
- @bc.receive_line("USER speccer@testhost")
27
- end
28
-
29
- it "should connect when receiving user before pass" do
30
- @tk.should_receive(:find_bouncer).with(@u, 'testhost').and_return(@b)
31
- @bc.receive_line("USER speccer@testhost")
32
- @bc.receive_line("PASS test123")
33
- @b.should_receive(:connect_client).with(@bc)
34
- @bc.receive_line("NICK speccer")
35
- end
36
- end
37
-
@@ -1,145 +0,0 @@
1
- require 'spec_helper'
2
- require 'tkellem/irc_server'
3
-
4
- include Tkellem
5
-
6
- describe Bouncer, "connection" do
7
- before do
8
- EM.stub!(:add_timer).and_return(nil)
9
- end
10
-
11
- def make_server
12
- network = Network.create!(:hosts => [Host.create!(:address => 'localhost', :port => 4321)], :name => 'test')
13
- b = Bouncer.new(NetworkUser.create!(:user => User.new(:username => 'speccer'), :network => network))
14
- b
15
- end
16
-
17
- def send_welcome(s, &just_before_last)
18
- s.should_receive(:send_msg).with("USER speccer somehost tkellem :speccer@tkellem")
19
- s.should_receive(:send_msg).with("NICK speccer")
20
- s.should_receive(:send_msg).with("AWAY :Away")
21
- s.connection_established(nil)
22
- s.server_msg(IrcMessage.parse("001 blah blah"))
23
- s.server_msg(IrcMessage.parse("002 more blah"))
24
- s.server_msg(IrcMessage.parse("003 even more blah"))
25
- just_before_last && just_before_last.call
26
- s.server_msg(IrcMessage.parse("376 :end of MOTD"))
27
- end
28
-
29
- def connected_server
30
- s = make_server
31
- send_welcome(s)
32
- s.connected?.should be_true
33
- s
34
- end
35
-
36
- it "should connect to the server on creation" do
37
- s = make_server
38
- s.connected?.should_not be_true
39
- s.should_receive(:send_msg).with("USER speccer somehost tkellem :speccer@tkellem")
40
- s.should_receive(:send_msg).with("NICK speccer")
41
- s.connection_established(nil)
42
- end
43
-
44
- it "should pong" do
45
- s = connected_server
46
- s.should_receive(:send_msg).with("PONG tkellem!tkellem :HAI")
47
- s.server_msg(IrcMessage.parse(":speccer!test@host ping :HAI"))
48
- end
49
-
50
- it "should ignore blank lines" do
51
- b = mock("bouncer", :trace => nil)
52
- b.should_receive(:failsafe).and_yield
53
- s = em(IrcServerConnection).new('connected', b, false)
54
- b.should_receive(:server_msg).never
55
- s.receive_line("")
56
- end
57
-
58
- def tk_server
59
- $tk_server ||= TkellemServer.new
60
- end
61
-
62
- after(:each) do
63
- $tk_server.stop if $tk_server
64
- $tk_server = nil
65
- end
66
-
67
- def network_user(opts = {})
68
- opts[:user] ||= @user ||= User.create!(:username => 'speccer', :password => 'test123')
69
- opts[:network] ||= @network ||= Network.create!(:name => 'localhost')
70
- @network_user ||= NetworkUser.create!(opts)
71
- end
72
-
73
- def bouncer(opts = {})
74
- tk_server
75
- network_user
76
- @bouncer = $tk_server.bouncers.values.last
77
- if opts[:connect]
78
- @server_conn = em(IrcServerConnection).new(nil, @bouncer, false)
79
- @server_conn.stub!(:send_data)
80
- @bouncer.connection_established(@server_conn)
81
- @bouncer.send :ready!
82
- end
83
- @bouncer
84
- end
85
-
86
- def client_connection(opts = {})
87
- @client ||= em(BouncerConnection).new(tk_server, false)
88
- if opts[:connect]
89
- end
90
- @client
91
- end
92
-
93
- it "should force the client nick on connect" do
94
- network_user(:nick => 'mynick')
95
- bouncer(:connect => true)
96
- @bouncer.server_msg(m ":mynick JOIN #t1")
97
- client_connection
98
- @client.should_receive(:send_msg).with(":some_other_nick NICK mynick")
99
- @client.should_receive(:send_msg).with(":mynick JOIN #t1")
100
- @client.receive_line("PASS test123")
101
- @client.receive_line("NICK some_other_nick")
102
- @client.receive_line("USER #{@user.username}@#{@network.name} a b :c")
103
- end
104
-
105
- it "should attempt another nick if the default is taken" do
106
- network_user(:nick => 'mynick')
107
- bouncer
108
- @server_conn = em(IrcServerConnection).new(nil, @bouncer, false)
109
- @server_conn.stub!(:send_data)
110
- @bouncer.connection_established(@server_conn)
111
- @server_conn.should_receive(:send_data).with("NICK mynick_\r\n")
112
- @bouncer.server_msg(m ":server 433 * mynick :Nickname already in use")
113
- @bouncer.nick.should == 'mynick_'
114
- @bouncer.send :ready!
115
- end
116
-
117
- it "should change nicks if a client sends nick after connecting" do
118
- network_user(:nick => 'mynick')
119
- bouncer(:connect => true)
120
- @bouncer.server_msg(m ":mynick JOIN #t1")
121
- client_connection
122
- @client.should_receive(:send_msg).with(":mynick JOIN #t1")
123
- @client.receive_line("PASS test123")
124
- @client.receive_line("NICK mynick")
125
- @client.receive_line("USER #{@user.username}@#{@network.name} a b :c")
126
- @bouncer.nick.should == 'mynick'
127
- @bouncer.client_msg(@client, m("NICK some_other"))
128
- @bouncer.nick.should == 'some_other'
129
- end
130
-
131
- it "should change nicks if a server forces nick change" do
132
- network_user(:nick => 'mynick')
133
- bouncer(:connect => true)
134
- @bouncer.server_msg(m ":mynick JOIN #t1")
135
- client_connection
136
- @client.should_receive(:send_msg).with(":mynick JOIN #t1")
137
- @client.receive_line("PASS test123")
138
- @client.receive_line("NICK mynick")
139
- @client.receive_line("USER #{@user.username}@#{@network.name} a b :c")
140
- @bouncer.nick.should == 'mynick'
141
- @client.should_receive(:send_msg).with(m ":mynick NICK some_other")
142
- @bouncer.server_msg(m ":mynick NICK some_other")
143
- @bouncer.nick.should == 'some_other'
144
- end
145
- end