ffi-rzmq 2.0.0 → 2.0.1
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 +4 -4
- data/History.txt +5 -0
- data/examples/repreq_over_curve.rb +60 -0
- data/lib/ffi-rzmq/exceptions.rb +3 -0
- data/lib/ffi-rzmq/socket.rb +3 -4
- data/lib/ffi-rzmq/util.rb +17 -0
- data/lib/ffi-rzmq/version.rb +1 -1
- data/spec/util_spec.rb +28 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d4e271f6dc0fcbad07111b4b23c969f192eb6d57
|
4
|
+
data.tar.gz: d5a508626d471997f3568646cd05a95a70ad19f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72b0886538590486c2e8c64e4e03eeab7259c39a9720b0ae763f7c4d0e149cda5926ddbc1710b39ecbf4cfeee0f348d1c85e1816c437764ac99becb7be784286
|
7
|
+
data.tar.gz: 0ca81c180fb1a7a8c7dd7767f7200589ec91fb42553c49eac03a2b91c5e51a95f002c64503e2d79fe77cee74adb0331a9adda1107ffd498effaa10ce2b471f01
|
data/History.txt
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
== 2.0.1 / 20140122
|
2
|
+
* Fix setsockopt with string parameters for options that have very strict
|
3
|
+
requirements (like CURVE_SECRETKEY) (37aed3c)
|
4
|
+
|
5
|
+
* Provide a wrapper for zmq_curve_keypair for ZeroMQ4
|
1
6
|
|
2
7
|
== 2.0.0 / 20140108
|
3
8
|
* Split out all of the FFI code to its own gem so other projects can use
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'ffi-rzmq')
|
2
|
+
|
3
|
+
# This example shows the basics of a CURVE-secured REP/REQ setup between
|
4
|
+
# a Server and Client. This is the minimal required setup for authenticating
|
5
|
+
# a connection between a Client and a Server. For validating the Client's authentication
|
6
|
+
# once the initial connection has succeeded, you'll need a ZAP handler on the Server.
|
7
|
+
|
8
|
+
# Build the Server's keys
|
9
|
+
server_public_key, server_private_key = ZMQ::Util.curve_keypair
|
10
|
+
|
11
|
+
# Build the Client's keys
|
12
|
+
client_public_key, client_private_key = ZMQ::Util.curve_keypair
|
13
|
+
|
14
|
+
context = ZMQ::Context.new
|
15
|
+
bind_point = "tcp://127.0.0.1:4455"
|
16
|
+
|
17
|
+
##
|
18
|
+
# Configure the Server
|
19
|
+
##
|
20
|
+
server = context.socket ZMQ::REP
|
21
|
+
|
22
|
+
server.setsockopt(ZMQ::CURVE_SERVER, 1)
|
23
|
+
server.setsockopt(ZMQ::CURVE_SECRETKEY, server_private_key)
|
24
|
+
|
25
|
+
server.bind(bind_point)
|
26
|
+
|
27
|
+
##
|
28
|
+
# Configure the Client to talk to the Server
|
29
|
+
##
|
30
|
+
client = context.socket ZMQ::REQ
|
31
|
+
|
32
|
+
client.setsockopt(ZMQ::CURVE_SERVERKEY, server_public_key)
|
33
|
+
client.setsockopt(ZMQ::CURVE_PUBLICKEY, client_public_key)
|
34
|
+
client.setsockopt(ZMQ::CURVE_SECRETKEY, client_private_key)
|
35
|
+
|
36
|
+
client.connect(bind_point)
|
37
|
+
|
38
|
+
##
|
39
|
+
# Show that communication still works
|
40
|
+
##
|
41
|
+
|
42
|
+
client_message = "Hello Server!"
|
43
|
+
server_response = "Hello Client!"
|
44
|
+
|
45
|
+
puts "Client sending: #{client_message}"
|
46
|
+
client.send_string client_message
|
47
|
+
|
48
|
+
server.recv_string(server_message = '')
|
49
|
+
puts "Server received: #{server_message}, replying with #{server_response}"
|
50
|
+
|
51
|
+
server.send_string(server_response)
|
52
|
+
|
53
|
+
client.recv_string(response = '')
|
54
|
+
puts "Client has received: #{response}"
|
55
|
+
|
56
|
+
puts "Finished"
|
57
|
+
|
58
|
+
client.close
|
59
|
+
server.close
|
60
|
+
context.terminate
|
data/lib/ffi-rzmq/exceptions.rb
CHANGED
data/lib/ffi-rzmq/socket.rb
CHANGED
@@ -135,15 +135,14 @@ module ZMQ
|
|
135
135
|
pointer.write_int value
|
136
136
|
|
137
137
|
elsif 2 == @option_lookup[name]
|
138
|
+
# Strings are treated as pointers by FFI so we'll just pass it through
|
138
139
|
length ||= value.size
|
140
|
+
pointer = value
|
139
141
|
|
140
|
-
# note: not checking errno for failed memory allocations :(
|
141
|
-
pointer = LibC.malloc length
|
142
|
-
pointer.write_string value
|
143
142
|
end
|
144
143
|
|
145
144
|
rc = LibZMQ.zmq_setsockopt @socket, name, pointer, length
|
146
|
-
LibC.free(pointer) unless pointer.nil? || pointer.null?
|
145
|
+
LibC.free(pointer) unless pointer.is_a?(String) || pointer.nil? || pointer.null?
|
147
146
|
rc
|
148
147
|
end
|
149
148
|
|
data/lib/ffi-rzmq/util.rb
CHANGED
@@ -5,6 +5,23 @@ module ZMQ
|
|
5
5
|
#
|
6
6
|
class Util
|
7
7
|
|
8
|
+
# Generate and return a CURVE public/private keypair
|
9
|
+
#
|
10
|
+
# Raises an error if ZeroMQ is not configured for CURVE connections.
|
11
|
+
# Install libsodium if this is the case.
|
12
|
+
def self.curve_keypair
|
13
|
+
public_key = FFI::MemoryPointer.from_string(' ' * 41)
|
14
|
+
private_key = FFI::MemoryPointer.from_string(' ' * 41)
|
15
|
+
rc = LibZMQ.zmq_curve_keypair public_key, private_key
|
16
|
+
|
17
|
+
if rc < 0
|
18
|
+
raise NotSupportedError.new "zmq_curve_keypair" , rc, ZMQ::Util.errno,
|
19
|
+
"Rebuild zeromq with libsodium to enable CURVE security options."
|
20
|
+
end
|
21
|
+
|
22
|
+
[public_key.read_string, private_key.read_string]
|
23
|
+
end
|
24
|
+
|
8
25
|
# Returns true when +rc+ is greater than or equal to 0, false otherwise.
|
9
26
|
#
|
10
27
|
# We use the >= test because zmq_poll() returns the number of sockets
|
data/lib/ffi-rzmq/version.rb
CHANGED
data/spec/util_spec.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), %w[spec_helper])
|
2
|
+
|
3
|
+
module ZMQ
|
4
|
+
describe Util do
|
5
|
+
|
6
|
+
if LibZMQ.version4?
|
7
|
+
describe "curve_keypair" do
|
8
|
+
|
9
|
+
it "returns a set of public and private keys" do
|
10
|
+
public_key, private_key = ZMQ::Util.curve_keypair
|
11
|
+
|
12
|
+
public_key.should_not == private_key
|
13
|
+
public_key.should_not be_nil
|
14
|
+
private_key.should_not be_nil
|
15
|
+
end
|
16
|
+
|
17
|
+
it "raises if zmq does not support CURVE (libsodium not linked)" do
|
18
|
+
lambda {
|
19
|
+
LibZMQ.should_receive(:zmq_curve_keypair).and_return(-1)
|
20
|
+
ZMQ::Util.curve_keypair
|
21
|
+
}.should raise_exception(ZMQ::NotSupportedError)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ffi-rzmq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chuck Remes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi-rzmq-core
|
@@ -79,6 +79,7 @@ files:
|
|
79
79
|
- examples/publish_subscribe.rb
|
80
80
|
- examples/remote_lat.rb
|
81
81
|
- examples/remote_throughput.rb
|
82
|
+
- examples/repreq_over_curve.rb
|
82
83
|
- examples/reqrep_poll.rb
|
83
84
|
- examples/request_response.rb
|
84
85
|
- examples/sub.rb
|
@@ -110,6 +111,7 @@ files:
|
|
110
111
|
- spec/spec_helper.rb
|
111
112
|
- spec/support/test.crt
|
112
113
|
- spec/support/test.key
|
114
|
+
- spec/util_spec.rb
|
113
115
|
homepage: http://github.com/chuckremes/ffi-rzmq
|
114
116
|
licenses:
|
115
117
|
- MIT
|
@@ -130,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
130
132
|
version: '0'
|
131
133
|
requirements: []
|
132
134
|
rubyforge_project: ffi-rzmq
|
133
|
-
rubygems_version: 2.0.
|
135
|
+
rubygems_version: 2.0.14
|
134
136
|
signing_key:
|
135
137
|
specification_version: 4
|
136
138
|
summary: This gem wraps the ZeroMQ (0mq) networking library using Ruby FFI (foreign
|
@@ -148,3 +150,4 @@ test_files:
|
|
148
150
|
- spec/spec_helper.rb
|
149
151
|
- spec/support/test.crt
|
150
152
|
- spec/support/test.key
|
153
|
+
- spec/util_spec.rb
|