lead_zeppelin 0.1.6 → 0.1.7
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.
- data/lead_zeppelin.gemspec +0 -1
- data/lib/lead_zeppelin/apns.rb +2 -1
- data/lib/lead_zeppelin/apns/application.rb +19 -20
- data/lib/lead_zeppelin/apns/client.rb +3 -1
- data/lib/lead_zeppelin/apns/gateway.rb +2 -3
- data/lib/lead_zeppelin/apns/gateway_pool.rb +12 -0
- data/lib/lead_zeppelin/version.rb +1 -1
- metadata +3 -18
data/lead_zeppelin.gemspec
CHANGED
data/lib/lead_zeppelin/apns.rb
CHANGED
@@ -7,10 +7,11 @@ require 'timeout'
|
|
7
7
|
require 'securerandom'
|
8
8
|
require_relative './apns/application'
|
9
9
|
require_relative './apns/client'
|
10
|
+
require_relative './apns/error_response'
|
10
11
|
require_relative './apns/gateway'
|
12
|
+
require_relative './apns/gateway_pool'
|
11
13
|
require_relative './apns/logger'
|
12
14
|
require_relative './apns/notification'
|
13
|
-
require_relative './apns/error_response'
|
14
15
|
|
15
16
|
module LeadZeppelin
|
16
17
|
module APNS
|
@@ -1,8 +1,7 @@
|
|
1
1
|
module LeadZeppelin
|
2
2
|
module APNS
|
3
3
|
class Application
|
4
|
-
|
5
|
-
CONNECTION_POOL_TIMEOUT = 5
|
4
|
+
GATEWAY_POOL_SIZE = 3
|
6
5
|
|
7
6
|
attr_reader :identifier
|
8
7
|
|
@@ -10,6 +9,8 @@ module LeadZeppelin
|
|
10
9
|
@identifier = identifier
|
11
10
|
@opts = opts
|
12
11
|
|
12
|
+
@gateway_pool = GatewayPool.new opts[:gateway_pool_size] || GATEWAY_POOL_SIZE
|
13
|
+
|
13
14
|
@ssl_context = OpenSSL::SSL::SSLContext.new
|
14
15
|
|
15
16
|
if opts[:p12]
|
@@ -24,22 +25,18 @@ module LeadZeppelin
|
|
24
25
|
end
|
25
26
|
end
|
26
27
|
|
27
|
-
def
|
28
|
-
cp_args = {size: (@opts[:connection_pool_size] || CONNECTION_POOL_SIZE),
|
29
|
-
timeout: (@opts[:connection_pool_timeout] || CONNECTION_POOL_TIMEOUT)}
|
30
|
-
|
28
|
+
def new_gateway
|
31
29
|
begin
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
30
|
+
gateway = Gateway.new @ssl_context,
|
31
|
+
(@opts[:gateway_opts] || {}).merge(notification_error_block: @opts[:notification_error_block],
|
32
|
+
certificate_error_block: @opts[:certificate_error_block],
|
33
|
+
application_identifier: @identifier)
|
37
34
|
|
38
35
|
rescue OpenSSL::SSL::SSLError => e
|
39
36
|
if e.message =~ /alert certificate unknown/
|
40
37
|
Logger.warn "bad certificate for #{@identifier}, failed to connect"
|
41
38
|
end
|
42
|
-
|
39
|
+
|
43
40
|
if e.message =~ /alert certificate expired/
|
44
41
|
Logger.warn "expired certificate for #{@identifier}, failed to connect"
|
45
42
|
end
|
@@ -50,20 +47,22 @@ module LeadZeppelin
|
|
50
47
|
else
|
51
48
|
@opts[:certificate_error_block].call @identifier
|
52
49
|
end
|
53
|
-
else
|
54
|
-
@gateway_connection_pool = gateway_connection_pool
|
55
50
|
end
|
51
|
+
|
52
|
+
gateway
|
56
53
|
end
|
57
54
|
|
58
55
|
def message(device_id, message, opts={})
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
56
|
+
if @gateway_pool.total < @gateway_pool.max
|
57
|
+
@gateway_pool.total += 1
|
58
|
+
Logger.info "adding new gateway connection for #{@identifier}"
|
59
|
+
gateway = new_gateway
|
60
|
+
else
|
61
|
+
gateway = @gateway_pool.pop
|
64
62
|
end
|
65
63
|
|
66
|
-
|
64
|
+
gateway.write Notification.new(device_id, message, opts)
|
65
|
+
@gateway_pool.push gateway
|
67
66
|
end
|
68
67
|
end
|
69
68
|
end
|
@@ -70,10 +70,12 @@ module LeadZeppelin
|
|
70
70
|
def remove_application(name)
|
71
71
|
Logger.info "removing application \"#{name}\""
|
72
72
|
Logger.thread 'r'
|
73
|
+
|
73
74
|
@semaphore.synchronize do
|
74
75
|
deleted = @applications.delete name
|
75
|
-
Logger.warn "removing application \"#{name}\" failed! Name may be invalid." if deleted.nil?
|
76
76
|
end
|
77
|
+
|
78
|
+
Logger.warn "removing application \"#{name}\" failed! Name may be invalid." if deleted.nil?
|
77
79
|
end
|
78
80
|
|
79
81
|
def message(app_name, device_id, message, opts={})
|
@@ -4,14 +4,13 @@ module LeadZeppelin
|
|
4
4
|
HOST = 'gateway.push.apple.com'
|
5
5
|
PORT = 2195
|
6
6
|
DEFAULT_TIMEOUT = 10
|
7
|
-
DEFAULT_SELECT_WAIT = 0.
|
7
|
+
DEFAULT_SELECT_WAIT = 0.3
|
8
8
|
|
9
9
|
def initialize(ssl_context, opts={})
|
10
10
|
Logger.thread 'g'
|
11
11
|
@semaphore = Mutex.new
|
12
12
|
@ssl_context = ssl_context
|
13
13
|
@opts = opts
|
14
|
-
|
15
14
|
connect
|
16
15
|
end
|
17
16
|
|
@@ -58,7 +57,7 @@ module LeadZeppelin
|
|
58
57
|
error_response = @ssl_socket.read_nonblock 6
|
59
58
|
error = ErrorResponse.new error_response, notification
|
60
59
|
|
61
|
-
Logger.warn "error: #{error.code}, #{error.identifier.
|
60
|
+
Logger.warn "error: #{error.code}, #{error.identifier.inspect}, #{error.message}"
|
62
61
|
Logger.thread 'e'
|
63
62
|
|
64
63
|
reconnect
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lead_zeppelin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: multi_json
|
@@ -43,22 +43,6 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
|
-
- !ruby/object:Gem::Dependency
|
47
|
-
name: connection_pool
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
|
-
requirements:
|
51
|
-
- - ! '>='
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '0'
|
54
|
-
type: :runtime
|
55
|
-
prerelease: false
|
56
|
-
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
|
-
requirements:
|
59
|
-
- - ! '>='
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
46
|
description: Thread-safe, multi-application APNS client
|
63
47
|
email:
|
64
48
|
- kyledrake@gmail.com
|
@@ -78,6 +62,7 @@ files:
|
|
78
62
|
- lib/lead_zeppelin/apns/client.rb
|
79
63
|
- lib/lead_zeppelin/apns/error_response.rb
|
80
64
|
- lib/lead_zeppelin/apns/gateway.rb
|
65
|
+
- lib/lead_zeppelin/apns/gateway_pool.rb
|
81
66
|
- lib/lead_zeppelin/apns/logger.rb
|
82
67
|
- lib/lead_zeppelin/apns/notification.rb
|
83
68
|
- lib/lead_zeppelin/version.rb
|