david 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/benchmarks/rackup/Gemfile.lock +1 -1
- data/benchmarks/rackup/interop.ru +2 -2
- data/lib/david/observe.rb +7 -7
- data/lib/david/server.rb +3 -4
- data/lib/david/version.rb +1 -1
- data/lib/rack/handler/david.rb +1 -1
- data/lib/rack/hello_world.rb +1 -1
- data/spec/interop/mandatory_spec.rb +12 -11
- data/spec/interop/optional_spec.rb +8 -7
- data/spec/observe_spec.rb +33 -0
- data/spec/spec_helper.rb +13 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9290eb9d9985ad49903395efb724f8042e2942e3
|
4
|
+
data.tar.gz: 6dcfc403652e20f71ae2fd05983aab6101810e81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2de6801e0ae8e344dc88e4d64d5980c595738424314b739d49388163a77194f4bb56c15bc021fa17431ec489554a026b1fd8c791b42a91f451e05d3543ff1af2
|
7
|
+
data.tar.gz: 7cdb306f81d1baddafdaadf5a37435cc3ee393095762951a028a8b56ce42bd778857562cda44b2b3f4441b380ffe9448f453546cf4cbda3ad0d917c9b7a7102e
|
data/Gemfile.lock
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#\ -o ::1 -p 5683 -O
|
1
|
+
#\ -o ::1 -p 5683 -O Multicast=false -O Log=debug -E none
|
2
2
|
|
3
3
|
module David; module ETSI; end; end
|
4
4
|
|
@@ -10,8 +10,8 @@ require 'david/etsi/mandatory/rack'
|
|
10
10
|
require 'david/etsi/optional/rack'
|
11
11
|
|
12
12
|
apps = [
|
13
|
-
David::ETSI::Optional::Rack.new,
|
14
13
|
David::ETSI::Mandatory::Rack.new,
|
14
|
+
David::ETSI::Optional::Rack.new,
|
15
15
|
]
|
16
16
|
|
17
17
|
run Rack::Cascade.new(apps)
|
data/lib/david/observe.rb
CHANGED
@@ -9,12 +9,10 @@ module David
|
|
9
9
|
@tick_interval = tick_interval
|
10
10
|
async.run
|
11
11
|
|
12
|
-
log.debug
|
12
|
+
log.debug('Observe initialized')
|
13
13
|
end
|
14
14
|
|
15
15
|
def add(exchange, env, etag)
|
16
|
-
exchange.message.tt = :non
|
17
|
-
exchange.message.mid = nil
|
18
16
|
exchange.message.options.delete(:observe)
|
19
17
|
|
20
18
|
self[[exchange.host, exchange.token]] ||=
|
@@ -58,7 +56,10 @@ module David
|
|
58
56
|
end
|
59
57
|
|
60
58
|
if etag != response.options[:etag]
|
59
|
+
response.tt = :con
|
60
|
+
response.mid = SecureRandom.random_number(0xffff)
|
61
61
|
response.options[:observe] = n
|
62
|
+
|
62
63
|
transmit(exchange, response, options)
|
63
64
|
|
64
65
|
# TODO Implement removing of observe relationship on RST answer to
|
@@ -73,10 +74,9 @@ module David
|
|
73
74
|
end
|
74
75
|
|
75
76
|
def transmit(exchange, message, options)
|
76
|
-
log.debug(message.inspect)
|
77
|
-
|
78
77
|
begin
|
79
78
|
server.socket.send(message.to_wire, 0, exchange.host, exchange.port)
|
79
|
+
log.debug(message.inspect)
|
80
80
|
rescue Timeout::Error, RuntimeError, Errno::ENETUNREACH
|
81
81
|
end
|
82
82
|
end
|
@@ -87,8 +87,8 @@ module David
|
|
87
87
|
|
88
88
|
def tick(fiber = true)
|
89
89
|
unless self.empty?
|
90
|
-
log.debug
|
91
|
-
log.debug
|
90
|
+
log.debug('Observe tick')
|
91
|
+
log.debug(self)
|
92
92
|
end
|
93
93
|
|
94
94
|
self.each_key do |key|
|
data/lib/david/server.rb
CHANGED
@@ -52,8 +52,6 @@ module David
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
private
|
56
|
-
|
57
55
|
def answer(exchange, key = nil)
|
58
56
|
@socket.send(exchange.message.to_wire, 0, exchange.host, exchange.port)
|
59
57
|
|
@@ -62,10 +60,11 @@ module David
|
|
62
60
|
log.debug(exchange.message.inspect)
|
63
61
|
end
|
64
62
|
|
65
|
-
key
|
66
|
-
cache_add(key, exchange.message) if exchange.ack?
|
63
|
+
cache_add(exchange.key, exchange.message) if exchange.ack?
|
67
64
|
end
|
68
65
|
|
66
|
+
private
|
67
|
+
|
69
68
|
def dispatch(*args)
|
70
69
|
data, sender, _, anc = args
|
71
70
|
|
data/lib/david/version.rb
CHANGED
data/lib/rack/handler/david.rb
CHANGED
data/lib/rack/hello_world.rb
CHANGED
@@ -9,12 +9,13 @@ require 'spec_helper'
|
|
9
9
|
Rails.application
|
10
10
|
].each do |app|
|
11
11
|
describe "ETSI Plugstests, Mandatory, #{app.to_s.split('::').last}" do
|
12
|
-
let!(:
|
12
|
+
let!(:port) { random_port }
|
13
|
+
let!(:server) { supervised_server(:Port => port, :MinimalMapping => true, app: app) }
|
13
14
|
|
14
15
|
[:con, :non].each do |tt|
|
15
16
|
context tt do
|
16
17
|
it 'TD_COAP_CORE_0{1,5}' do
|
17
|
-
mid, response = req(:get, '/test', tt: tt)
|
18
|
+
mid, response = req(:get, '/test', port: port, tt: tt)
|
18
19
|
|
19
20
|
expect(response).to be_a(CoAP::Message)
|
20
21
|
expect(response.mcode).to eq([2, 5])
|
@@ -23,8 +24,8 @@ require 'spec_helper'
|
|
23
24
|
end
|
24
25
|
|
25
26
|
it 'TD_COAP_CORE_0{2,6}' do
|
26
|
-
mid, response = req(:post, '/test', tt: tt, payload:
|
27
|
-
content_format: 0)
|
27
|
+
mid, response = req(:post, '/test', port: port, tt: tt, payload:
|
28
|
+
'foo', content_format: 0)
|
28
29
|
|
29
30
|
expect(response).to be_a(CoAP::Message)
|
30
31
|
expect(response.mcode).to eq([2, 1])
|
@@ -32,8 +33,8 @@ require 'spec_helper'
|
|
32
33
|
end
|
33
34
|
|
34
35
|
it 'TD_COAP_CORE_0{3,7}' do
|
35
|
-
mid, response = req(:put, '/test', tt: tt, payload:
|
36
|
-
content_format: 0)
|
36
|
+
mid, response = req(:put, '/test', port: port, tt: tt, payload:
|
37
|
+
'foo', content_format: 0)
|
37
38
|
|
38
39
|
expect(response).to be_a(CoAP::Message)
|
39
40
|
expect(response.mcode).to eq([2, 4])
|
@@ -41,7 +42,7 @@ require 'spec_helper'
|
|
41
42
|
end
|
42
43
|
|
43
44
|
it 'TD_COAP_CORE_0{4,8}' do
|
44
|
-
mid, response = req(:delete, '/test', tt: tt)
|
45
|
+
mid, response = req(:delete, '/test', port: port, tt: tt)
|
45
46
|
|
46
47
|
expect(response).to be_a(CoAP::Message)
|
47
48
|
expect(response.mcode).to eq([2, 2])
|
@@ -52,7 +53,7 @@ require 'spec_helper'
|
|
52
53
|
|
53
54
|
it 'TD_COAP_CORE_10' do
|
54
55
|
token = rand(0xffffffff)
|
55
|
-
mid, response = req(:get, '/test', token: token)
|
56
|
+
mid, response = req(:get, '/test', port: port, token: token)
|
56
57
|
|
57
58
|
expect(response).to be_a(CoAP::Message)
|
58
59
|
expect(response.mcode).to eq([2, 5])
|
@@ -62,7 +63,7 @@ require 'spec_helper'
|
|
62
63
|
end
|
63
64
|
|
64
65
|
it 'TD_COAP_CORE_11' do
|
65
|
-
mid, response = req(:get, '/test')
|
66
|
+
mid, response = req(:get, '/test', port: port)
|
66
67
|
|
67
68
|
expect(response).to be_a(CoAP::Message)
|
68
69
|
expect(response.mcode).to eq([2, 5])
|
@@ -72,7 +73,7 @@ require 'spec_helper'
|
|
72
73
|
end
|
73
74
|
|
74
75
|
it 'TD_COAP_CORE_12' do
|
75
|
-
mid, response = req(:get, '/seg1/seg2/seg3')
|
76
|
+
mid, response = req(:get, '/seg1/seg2/seg3', port: port)
|
76
77
|
|
77
78
|
expect(response).to be_a(CoAP::Message)
|
78
79
|
expect(response.mcode).to eq([2, 5])
|
@@ -81,7 +82,7 @@ require 'spec_helper'
|
|
81
82
|
end
|
82
83
|
|
83
84
|
it 'TD_COAP_CORE_13' do
|
84
|
-
mid, response = req(:get, '/query', uri_query: ['foo=1', 'bar=2'])
|
85
|
+
mid, response = req(:get, '/query', port: port, uri_query: ['foo=1', 'bar=2'])
|
85
86
|
|
86
87
|
expect(response).to be_a(CoAP::Message)
|
87
88
|
expect(response.mcode).to eq([2, 5])
|
@@ -4,11 +4,12 @@ require 'spec_helper'
|
|
4
4
|
ETSI::Optional::Rack,
|
5
5
|
].each do |app|
|
6
6
|
describe "ETSI Plugstests, Optional, #{app.to_s.split('::').last}" do
|
7
|
-
let
|
7
|
+
let(:port) { random_port }
|
8
|
+
let!(:server) { supervised_server(:Port => port, :MinimalMapping => true, app: app) }
|
8
9
|
|
9
10
|
context 'TD_COAP_BLOCK_01' do
|
10
11
|
it 'block 0' do
|
11
|
-
mid, response = req(:get, '/large', block2: 0) # 0, false, 16
|
12
|
+
mid, response = req(:get, '/large', port: port, block2: 0) # 0, false, 16
|
12
13
|
block = CoAP::Block.new(response.options[:block2]).decode
|
13
14
|
|
14
15
|
expect(response).to be_a(CoAP::Message)
|
@@ -21,7 +22,7 @@ require 'spec_helper'
|
|
21
22
|
end
|
22
23
|
|
23
24
|
it 'block 1' do
|
24
|
-
mid, response = req(:get, '/large', block2: 16) # 1, false, 16
|
25
|
+
mid, response = req(:get, '/large', port: port, block2: 16) # 1, false, 16
|
25
26
|
block = CoAP::Block.new(response.options[:block2]).decode
|
26
27
|
|
27
28
|
expect(response).to be_a(CoAP::Message)
|
@@ -34,7 +35,7 @@ require 'spec_helper'
|
|
34
35
|
end
|
35
36
|
|
36
37
|
it 'block 64' do
|
37
|
-
mid, response = req(:get, '/large', block2: 1024) # 65, false, 16
|
38
|
+
mid, response = req(:get, '/large', port: port, block2: 1024) # 65, false, 16
|
38
39
|
block = CoAP::Block.new(response.options[:block2]).decode
|
39
40
|
|
40
41
|
expect(response).to be_a(CoAP::Message)
|
@@ -50,7 +51,7 @@ require 'spec_helper'
|
|
50
51
|
|
51
52
|
context 'TD_COAP_BLOCK_02' do
|
52
53
|
it 'block 0' do
|
53
|
-
mid, response = req(:get, '/large')
|
54
|
+
mid, response = req(:get, '/large', port: port)
|
54
55
|
block = CoAP::Block.new(response.options[:block2]).decode
|
55
56
|
|
56
57
|
expect(response).to be_a(CoAP::Message)
|
@@ -63,7 +64,7 @@ require 'spec_helper'
|
|
63
64
|
end
|
64
65
|
|
65
66
|
it 'block 1' do
|
66
|
-
mid, response = req(:get, '/large', block2: 22) # 1, false, 1024
|
67
|
+
mid, response = req(:get, '/large', port: port, block2: 22) # 1, false, 1024
|
67
68
|
block = CoAP::Block.new(response.options[:block2]).decode
|
68
69
|
|
69
70
|
expect(response).to be_a(CoAP::Message)
|
@@ -82,7 +83,7 @@ require 'spec_helper'
|
|
82
83
|
|
83
84
|
@t1 = Thread.start do
|
84
85
|
CoAP::Client.new.observe \
|
85
|
-
'/obs', '::1',
|
86
|
+
'/obs', '::1', port,
|
86
87
|
->(s, m) { @answers << m }
|
87
88
|
end
|
88
89
|
|
data/spec/observe_spec.rb
CHANGED
@@ -194,4 +194,37 @@ describe Observe do
|
|
194
194
|
end
|
195
195
|
end
|
196
196
|
end
|
197
|
+
|
198
|
+
describe 'integration' do
|
199
|
+
let(:port) { random_port }
|
200
|
+
|
201
|
+
let!(:server) { supervised_server(:Port => port) }
|
202
|
+
let!(:client) do
|
203
|
+
CoAP::Client.new(port: port, retransmit: false, recv_timeout: 0.1)
|
204
|
+
end
|
205
|
+
|
206
|
+
before do
|
207
|
+
@answers = []
|
208
|
+
|
209
|
+
@t1 = Thread.start do
|
210
|
+
client.observe \
|
211
|
+
'/value', '::1', nil,
|
212
|
+
->(s, m) { @answers << m }
|
213
|
+
end
|
214
|
+
|
215
|
+
Timeout.timeout(12) do
|
216
|
+
sleep 0.25 while !(@answers.size > 2)
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
it 'should receive updates' do
|
221
|
+
expect(@answers.size).to be > 2
|
222
|
+
expect(@answers.map(&:mid).uniq.size).to eq(3)
|
223
|
+
end
|
224
|
+
|
225
|
+
after do
|
226
|
+
@t1.kill
|
227
|
+
server.terminate
|
228
|
+
end
|
229
|
+
end
|
197
230
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -27,15 +27,16 @@ module David
|
|
27
27
|
|
28
28
|
def req(method, path, options = {})
|
29
29
|
mid = rand(0xffff) unless respond_to?(:mid)
|
30
|
-
port = random_port unless respond_to?(:port)
|
31
30
|
|
32
31
|
payload = options.delete(:payload)
|
32
|
+
port = options.delete(:port) || random_port
|
33
|
+
|
33
34
|
options.merge!(mid: mid)
|
34
35
|
|
35
36
|
client = CoAP::Client.new(retransmit: false, recv_timeout: 0.1,
|
36
37
|
token: false)
|
37
38
|
|
38
|
-
response = client.send(method, path, '::1',
|
39
|
+
response = client.send(method, path, '::1', port, payload, options)
|
39
40
|
|
40
41
|
[mid, response]
|
41
42
|
end
|
@@ -51,12 +52,18 @@ module David
|
|
51
52
|
|
52
53
|
app = options.delete(:app) || Rack::HelloWorld
|
53
54
|
|
54
|
-
|
55
|
+
g = Celluloid::SupervisionGroup.run!
|
56
|
+
|
57
|
+
g.supervise_as(:server, ::David::Server, app, defaults.merge(options))
|
58
|
+
g.supervise_as(:gc, ::David::GarbageCollector)
|
59
|
+
|
60
|
+
unless options[:Observe] == 'false'
|
61
|
+
g.supervise_as(:observe, ::David::Observe)
|
62
|
+
end
|
55
63
|
|
56
|
-
|
57
|
-
server.async.run
|
64
|
+
Celluloid::Actor[:server].async.run
|
58
65
|
|
59
|
-
|
66
|
+
g
|
60
67
|
end
|
61
68
|
end
|
62
69
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: david
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- henning mueller
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: celluloid-io
|