blather 0.5.10 → 0.5.11
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +5 -0
- data/lib/blather/client/client.rb +7 -6
- data/lib/blather/stream.rb +16 -7
- data/lib/blather/version.rb +1 -1
- data/spec/blather/client/client_spec.rb +2 -2
- metadata +30 -30
data/CHANGELOG
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
v0.5.11
|
2
|
+
Feature(benlangfeld): Allow specifying a connection timeout
|
3
|
+
* Raise Blather::Stream::ConnectionTimeout if timeout is exceeded
|
4
|
+
* Default to 180 seconds
|
5
|
+
|
1
6
|
v0.5.10
|
2
7
|
Feature(juandebravo): Allow configuring the wire log level
|
3
8
|
Bugfix(benlangfeld): Checking connection status before the stream is established
|
@@ -45,8 +45,8 @@ module Blather
|
|
45
45
|
# @param [Fixnum, String] port the port to connect to.
|
46
46
|
#
|
47
47
|
# @return [Blather::Client]
|
48
|
-
def self.setup(jid, password, host = nil, port = nil, certs = nil)
|
49
|
-
self.new.setup(jid, password, host, port, certs)
|
48
|
+
def self.setup(jid, password, host = nil, port = nil, certs = nil, connect_timeout = nil)
|
49
|
+
self.new.setup(jid, password, host, port, certs, connect_timeout)
|
50
50
|
end
|
51
51
|
|
52
52
|
def initialize # @private
|
@@ -194,12 +194,13 @@ module Blather
|
|
194
194
|
end
|
195
195
|
|
196
196
|
# @private
|
197
|
-
def setup(jid, password, host = nil, port = nil, certs = nil)
|
197
|
+
def setup(jid, password, host = nil, port = nil, certs = nil, connect_timeout = nil)
|
198
198
|
@jid = JID.new(jid)
|
199
199
|
@setup = [@jid, password]
|
200
|
-
@setup << host
|
201
|
-
@setup << port
|
202
|
-
@setup << certs
|
200
|
+
@setup << host
|
201
|
+
@setup << port
|
202
|
+
@setup << certs
|
203
|
+
@setup << connect_timeout
|
203
204
|
self
|
204
205
|
end
|
205
206
|
|
data/lib/blather/stream.rb
CHANGED
@@ -51,6 +51,7 @@ module Blather
|
|
51
51
|
# Connection not found
|
52
52
|
class NoConnection < RuntimeError; end
|
53
53
|
class ConnectionFailed < RuntimeError; end
|
54
|
+
class ConnectionTimeout < RuntimeError; end
|
54
55
|
|
55
56
|
# @private
|
56
57
|
STREAM_NS = 'http://etherx.jabber.org/streams'
|
@@ -70,13 +71,15 @@ module Blather
|
|
70
71
|
# default of 5222
|
71
72
|
# @param [String, nil] certs the trusted cert store in pem format to verify
|
72
73
|
# communication with the server is trusted.
|
73
|
-
|
74
|
+
# @param [Fixnum, nil] connect_timeout the number of seconds for which to wait for a successful connection
|
75
|
+
def self.start(client, jid, pass, host = nil, port = nil, certs_directory = nil, connect_timeout = nil)
|
74
76
|
jid = JID.new jid
|
77
|
+
port ||= 5222
|
75
78
|
if certs_directory
|
76
79
|
@@store = CertStore.new(certs_directory)
|
77
80
|
end
|
78
81
|
if host
|
79
|
-
connect host, port, self, client, jid, pass
|
82
|
+
connect host, port, self, client, jid, pass, connect_timeout
|
80
83
|
else
|
81
84
|
require 'resolv'
|
82
85
|
srv = []
|
@@ -88,7 +91,7 @@ module Blather
|
|
88
91
|
end
|
89
92
|
|
90
93
|
if srv.empty?
|
91
|
-
connect jid.domain, port, self, client, jid, pass
|
94
|
+
connect jid.domain, port, self, client, jid, pass, connect_timeout
|
92
95
|
else
|
93
96
|
srv.sort! do |a,b|
|
94
97
|
(a.priority != b.priority) ? (a.priority <=> b.priority) :
|
@@ -96,7 +99,7 @@ module Blather
|
|
96
99
|
end
|
97
100
|
|
98
101
|
srv.detect do |r|
|
99
|
-
not connect(r.target.to_s, r.port, self, client, jid, pass) === false
|
102
|
+
not connect(r.target.to_s, r.port, self, client, jid, pass, connect_timeout) === false
|
100
103
|
end
|
101
104
|
end
|
102
105
|
end
|
@@ -106,8 +109,8 @@ module Blather
|
|
106
109
|
# Stream will raise +NoConnection+ if it receives #unbind before #post_init
|
107
110
|
# this catches that and returns false prompting for another attempt
|
108
111
|
# @private
|
109
|
-
def self.connect(host, port, conn, client, jid, pass)
|
110
|
-
EM.connect host, port, conn, client, jid, pass
|
112
|
+
def self.connect(host, port, conn, client, jid, pass, connect_timeout = nil)
|
113
|
+
EM.connect host, port, conn, client, jid, pass, connect_timeout
|
111
114
|
rescue NoConnection
|
112
115
|
false
|
113
116
|
end
|
@@ -129,7 +132,7 @@ module Blather
|
|
129
132
|
|
130
133
|
# Called by EM.connect to initialize stream variables
|
131
134
|
# @private
|
132
|
-
def initialize(client, jid, pass)
|
135
|
+
def initialize(client, jid, pass, connect_timeout = nil)
|
133
136
|
super()
|
134
137
|
|
135
138
|
@error = nil
|
@@ -138,12 +141,18 @@ module Blather
|
|
138
141
|
self.jid = jid
|
139
142
|
@to = self.jid.domain
|
140
143
|
@password = pass
|
144
|
+
@connect_timeout = connect_timeout || 180
|
141
145
|
end
|
142
146
|
|
143
147
|
# Called when EM completes the connection to the server
|
144
148
|
# this kicks off the starttls/authorize/bind process
|
145
149
|
# @private
|
146
150
|
def connection_completed
|
151
|
+
if @connect_timeout
|
152
|
+
EM::Timer.new @connect_timeout do
|
153
|
+
raise ConnectionTimeout, "Stream timed out after #{@connect_timeout} seconds." unless started?
|
154
|
+
end
|
155
|
+
end
|
147
156
|
@connected = true
|
148
157
|
# @keepalive = EM::PeriodicTimer.new(60) { send_data ' ' }
|
149
158
|
start
|
data/lib/blather/version.rb
CHANGED
@@ -51,14 +51,14 @@ describe Blather::Client do
|
|
51
51
|
it 'starts up a Component connection when setup without a node' do
|
52
52
|
setup = 'pubsub.jabber.local', 'secret'
|
53
53
|
@client.setup *setup
|
54
|
-
Blather::Stream::Component.expects(:start).with @client, *setup
|
54
|
+
Blather::Stream::Component.expects(:start).with @client, *setup + [nil, nil, nil, nil]
|
55
55
|
@client.run
|
56
56
|
end
|
57
57
|
|
58
58
|
it 'starts up a Client connection when setup with a node' do
|
59
59
|
setup = 'test@jabber.local', 'secret'
|
60
60
|
@client.setup *setup
|
61
|
-
Blather::Stream::Client.expects(:start).with @client, *setup
|
61
|
+
Blather::Stream::Client.expects(:start).with @client, *setup + [nil, nil, nil, nil]
|
62
62
|
@client.run
|
63
63
|
end
|
64
64
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blather
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.11
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-01-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: eventmachine
|
16
|
-
requirement: &
|
16
|
+
requirement: &2156508820 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.12.6
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2156508820
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: nokogiri
|
27
|
-
requirement: &
|
27
|
+
requirement: &2156506260 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.4.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2156506260
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: niceogiri
|
38
|
-
requirement: &
|
38
|
+
requirement: &2156518800 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 0.1.0
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2156518800
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: activesupport
|
49
|
-
requirement: &
|
49
|
+
requirement: &2156517580 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 3.0.7
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2156517580
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: minitest
|
60
|
-
requirement: &
|
60
|
+
requirement: &2156515520 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 1.7.1
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *2156515520
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: mocha
|
71
|
-
requirement: &
|
71
|
+
requirement: &2156514000 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: 0.9.12
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *2156514000
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: bundler
|
82
|
-
requirement: &
|
82
|
+
requirement: &2156526940 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ~>
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: 1.0.0
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *2156526940
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: rcov
|
93
|
-
requirement: &
|
93
|
+
requirement: &2156526080 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ~>
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: 0.9.9
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *2156526080
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: yard
|
104
|
-
requirement: &
|
104
|
+
requirement: &2156524880 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ~>
|
@@ -109,10 +109,10 @@ dependencies:
|
|
109
109
|
version: 0.6.1
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *2156524880
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: rake
|
115
|
-
requirement: &
|
115
|
+
requirement: &2156524380 !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|
118
118
|
- - ! '>='
|
@@ -120,10 +120,10 @@ dependencies:
|
|
120
120
|
version: '0'
|
121
121
|
type: :development
|
122
122
|
prerelease: false
|
123
|
-
version_requirements: *
|
123
|
+
version_requirements: *2156524380
|
124
124
|
- !ruby/object:Gem::Dependency
|
125
125
|
name: guard-minitest
|
126
|
-
requirement: &
|
126
|
+
requirement: &2156523580 !ruby/object:Gem::Requirement
|
127
127
|
none: false
|
128
128
|
requirements:
|
129
129
|
- - ! '>='
|
@@ -131,10 +131,10 @@ dependencies:
|
|
131
131
|
version: '0'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
|
-
version_requirements: *
|
134
|
+
version_requirements: *2156523580
|
135
135
|
- !ruby/object:Gem::Dependency
|
136
136
|
name: bluecloth
|
137
|
-
requirement: &
|
137
|
+
requirement: &2156519740 !ruby/object:Gem::Requirement
|
138
138
|
none: false
|
139
139
|
requirements:
|
140
140
|
- - ! '>='
|
@@ -142,10 +142,10 @@ dependencies:
|
|
142
142
|
version: '0'
|
143
143
|
type: :development
|
144
144
|
prerelease: false
|
145
|
-
version_requirements: *
|
145
|
+
version_requirements: *2156519740
|
146
146
|
- !ruby/object:Gem::Dependency
|
147
147
|
name: growl_notify
|
148
|
-
requirement: &
|
148
|
+
requirement: &2156535160 !ruby/object:Gem::Requirement
|
149
149
|
none: false
|
150
150
|
requirements:
|
151
151
|
- - ! '>='
|
@@ -153,10 +153,10 @@ dependencies:
|
|
153
153
|
version: '0'
|
154
154
|
type: :development
|
155
155
|
prerelease: false
|
156
|
-
version_requirements: *
|
156
|
+
version_requirements: *2156535160
|
157
157
|
- !ruby/object:Gem::Dependency
|
158
158
|
name: rb-fsevent
|
159
|
-
requirement: &
|
159
|
+
requirement: &2156531800 !ruby/object:Gem::Requirement
|
160
160
|
none: false
|
161
161
|
requirements:
|
162
162
|
- - ! '>='
|
@@ -164,7 +164,7 @@ dependencies:
|
|
164
164
|
version: '0'
|
165
165
|
type: :development
|
166
166
|
prerelease: false
|
167
|
-
version_requirements: *
|
167
|
+
version_requirements: *2156531800
|
168
168
|
description: An XMPP DSL for Ruby written on top of EventMachine and Nokogiri
|
169
169
|
email: sprsquish@gmail.com
|
170
170
|
executables: []
|