pcp-client 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pcp/client.rb +26 -13
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4bbadd16844a443623b6d9d1389b580960b17592
|
4
|
+
data.tar.gz: cfe1c97388dbab0db4496b316f57961cc6e30d9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d006505e2bfdee5de658da1a1dff1215d3a483ce4e7326815f8229b39f9acf61597686ad7c4a83e1e0d46e712aa8420742387743792df3212ef760bbeb25947d
|
7
|
+
data.tar.gz: ef1ab13ddaeffda48954bc65c8d7b1d28c62037667dad6d40708eb79c37c69544767cd41198778cf690bd35b547d759665020897f82774aa7c85c31af5a30f04
|
data/lib/pcp/client.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'eventmachine
|
1
|
+
require 'eventmachine'
|
2
2
|
require 'faye/websocket'
|
3
3
|
require 'pcp/message'
|
4
4
|
require 'logger'
|
@@ -42,17 +42,6 @@ module PCP
|
|
42
42
|
# @param seconds [Numeric]
|
43
43
|
# @return [true,false,nil]
|
44
44
|
def connect(seconds = 0)
|
45
|
-
unless EM.reactor_running?
|
46
|
-
raise "An Eventmachine reactor needs to be running"
|
47
|
-
end
|
48
|
-
|
49
|
-
if EM.reactor_thread?
|
50
|
-
# Because we use a condition variable to signal this thread
|
51
|
-
# from the reactor thread to provide an imperative interface,
|
52
|
-
# they cannot be the same thread
|
53
|
-
raise "Cannot be run on the same thread as the reactor"
|
54
|
-
end
|
55
|
-
|
56
45
|
if @connection
|
57
46
|
# We close over so much, we really just need to say no for now
|
58
47
|
raise "Can only connect once per client"
|
@@ -64,7 +53,7 @@ module PCP
|
|
64
53
|
@logger.debug { [:connect, @server] }
|
65
54
|
@connection = Faye::WebSocket::Client.new(@server, nil, {:tls => {:private_key_file => @ssl_key,
|
66
55
|
:cert_chain_file => @ssl_cert,
|
67
|
-
:ssl_version =>
|
56
|
+
:ssl_version => ["TLSv1", "TLSv1_1", "TLSv1_2"]}})
|
68
57
|
|
69
58
|
@connection.on :open do |event|
|
70
59
|
begin
|
@@ -110,6 +99,22 @@ module PCP
|
|
110
99
|
@associated = false
|
111
100
|
end
|
112
101
|
|
102
|
+
if !EM.reactor_running?
|
103
|
+
@logger.debug { [:no_eventmachine_reactor,
|
104
|
+
"Eventmachine reactor is not running" ] }
|
105
|
+
return nil
|
106
|
+
end
|
107
|
+
|
108
|
+
if EM.reactor_thread?
|
109
|
+
# Because we use a condition variable to signal this thread
|
110
|
+
# from the reactor thread to provide an imperative interface,
|
111
|
+
# they cannot be the same thread. We might associate later,
|
112
|
+
# we just can't wait on ourselves from here.
|
113
|
+
@logger.debug { [:connection_cannot_wait,
|
114
|
+
"Cannot wait on a connection if we are in the same thread as the reactor" ] }
|
115
|
+
return nil
|
116
|
+
end
|
117
|
+
|
113
118
|
begin
|
114
119
|
Timeout::timeout(seconds) do
|
115
120
|
mutex.synchronize do
|
@@ -141,6 +146,14 @@ module PCP
|
|
141
146
|
@connection.send(message.encode)
|
142
147
|
end
|
143
148
|
|
149
|
+
# Disconnect the client
|
150
|
+
# @api public
|
151
|
+
# @return unused
|
152
|
+
def close
|
153
|
+
@logger.debug { [:close] }
|
154
|
+
@connection.close
|
155
|
+
end
|
156
|
+
|
144
157
|
private
|
145
158
|
|
146
159
|
# Get the common name from an X509 certficate in file
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pcp-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Puppet Labs
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name: eventmachine
|
14
|
+
name: eventmachine
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: faye-websocket
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|