ruby_home 0.1.5 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +64 -5
  3. data/bin/rubyhome +4 -4
  4. data/lib/ruby_home/accessory_info.rb +45 -30
  5. data/lib/ruby_home/factories/characteristic_factory.rb +27 -19
  6. data/lib/ruby_home/factories/default_values/float_value.rb +1 -1
  7. data/lib/ruby_home/factories/service_factory.rb +89 -0
  8. data/lib/ruby_home/factories/templates/characteristic_template.rb +6 -2
  9. data/lib/ruby_home/hap/accessory.rb +24 -3
  10. data/lib/ruby_home/hap/accessory_collection.rb +38 -0
  11. data/lib/ruby_home/hap/characteristic.rb +25 -19
  12. data/lib/ruby_home/hap/crypto/session_key.rb +31 -0
  13. data/lib/ruby_home/hap/ev_response.rb +64 -0
  14. data/lib/ruby_home/{http → hap}/hap_request.rb +12 -5
  15. data/lib/ruby_home/{http → hap}/hap_response.rb +7 -4
  16. data/lib/ruby_home/hap/server.rb +81 -0
  17. data/lib/ruby_home/hap/service.rb +11 -15
  18. data/lib/ruby_home/http/application.rb +17 -22
  19. data/lib/ruby_home/http/controllers/application_controller.rb +8 -4
  20. data/lib/ruby_home/http/controllers/characteristics_controller.rb +19 -4
  21. data/lib/ruby_home/http/controllers/pair_verifies_controller.rb +3 -5
  22. data/lib/ruby_home/http/serializers/object_serializer.rb +1 -1
  23. data/lib/ruby_home/http/services/socket_notifier.rb +40 -0
  24. data/lib/ruby_home/http/services/start_srp_service.rb +36 -34
  25. data/lib/ruby_home/http/services/verify_srp_service.rb +55 -53
  26. data/lib/ruby_home/identifier_cache.rb +22 -49
  27. data/lib/ruby_home/persistable.rb +36 -0
  28. data/lib/ruby_home/version.rb +1 -1
  29. data/lib/ruby_home.rb +14 -5
  30. data/rubyhome.gemspec +3 -3
  31. metadata +35 -38
  32. data/lib/ruby_home/factories/accessory_factory.rb +0 -73
  33. data/lib/ruby_home/http/hap_server.rb +0 -60
  34. data/lib/ruby_home/rack/handler/hap_server.rb +0 -21
  35. data/lib/ruby_home/yaml_record.rb +0 -440
data/lib/ruby_home.rb CHANGED
@@ -1,14 +1,19 @@
1
+ require 'active_support'
2
+ require 'active_support/core_ext/hash'
1
3
  require 'bindata'
2
4
  require 'dnssd'
3
5
  require 'hkdf'
6
+ require 'nio'
4
7
  require 'oj'
5
8
  require 'rack'
6
9
  require 'rbnacl/libsodium'
7
- require 'request_store'
8
10
  require 'ruby_home-srp'
11
+ require 'securerandom'
9
12
  require 'sinatra/base'
13
+ require 'socket'
10
14
  require 'webrick'
11
15
  require 'wisper'
16
+ require 'yaml'
12
17
 
13
18
  module RubyHome
14
19
  Dir[File.dirname(__FILE__) + '/ruby_home/**/*.rb'].each { |file| require file }
@@ -24,7 +29,7 @@ module RubyHome
24
29
 
25
30
  def start
26
31
  threads << Thread.start { dns_service.register }
27
- threads << Thread.start { http_server.run }
32
+ threads << Thread.start { hap_server.run }
28
33
  threads.each(&:join)
29
34
  end
30
35
 
@@ -37,11 +42,15 @@ module RubyHome
37
42
  end
38
43
 
39
44
  def dns_service
40
- @@_dns_service ||= RubyHome::DNS::Service.new(http_server.port)
45
+ @@_dns_service ||= DNS::Service.new(hap_server.port)
41
46
  end
42
47
 
43
- def http_server
44
- @@_http_server ||= RubyHome::HTTP::Application.new
48
+ def hap_server
49
+ @@_hap_server ||= HAP::Server.new('0.0.0.0', 4567, socket_store)
50
+ end
51
+
52
+ def socket_store
53
+ @@_socket_store ||= {}
45
54
  end
46
55
 
47
56
  def greet
data/rubyhome.gemspec CHANGED
@@ -29,13 +29,13 @@ Gem::Specification.new do |spec|
29
29
  spec.add_dependency 'bindata', '~> 2.4', '>= 2.4.3'
30
30
  spec.add_dependency 'dnssd', '~> 3.0'
31
31
  spec.add_dependency 'hkdf', '~> 0.3.0'
32
+ spec.add_dependency 'nio4r', '~> 2.3', '>= 2.3.1'
32
33
  spec.add_dependency 'oj', '~> 3.4'
33
34
  spec.add_dependency 'rbnacl', '~> 5.0'
34
35
  spec.add_dependency 'rbnacl-libsodium', '~> 1.0', '>= 1.0.16'
35
- spec.add_dependency 'request_store', '~> 1.4', '>= 1.4.1'
36
36
  spec.add_dependency 'ruby_home-srp', '~> 1.2'
37
- spec.add_dependency 'sinatra', '2.0.3'
38
- spec.add_dependency 'wisper', '~> 1.6', '>= 1.6.1'
37
+ spec.add_dependency 'sinatra', '2.0.4'
38
+ spec.add_dependency 'wisper', '~> 2.0'
39
39
  spec.add_development_dependency 'bundler', '~> 1.16'
40
40
  spec.add_development_dependency 'byebug', '~> 10.0'
41
41
  spec.add_development_dependency 'plist', '~> 3.4'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_home
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karl Entwistle
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-09-09 00:00:00.000000000 Z
11
+ date: 2018-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -73,73 +73,73 @@ dependencies:
73
73
  - !ruby/object:Gem::Version
74
74
  version: 0.3.0
75
75
  - !ruby/object:Gem::Dependency
76
- name: oj
76
+ name: nio4r
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
79
  - - "~>"
80
80
  - !ruby/object:Gem::Version
81
- version: '3.4'
81
+ version: '2.3'
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 2.3.1
82
85
  type: :runtime
83
86
  prerelease: false
84
87
  version_requirements: !ruby/object:Gem::Requirement
85
88
  requirements:
86
89
  - - "~>"
87
90
  - !ruby/object:Gem::Version
88
- version: '3.4'
91
+ version: '2.3'
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: 2.3.1
89
95
  - !ruby/object:Gem::Dependency
90
- name: rbnacl
96
+ name: oj
91
97
  requirement: !ruby/object:Gem::Requirement
92
98
  requirements:
93
99
  - - "~>"
94
100
  - !ruby/object:Gem::Version
95
- version: '5.0'
101
+ version: '3.4'
96
102
  type: :runtime
97
103
  prerelease: false
98
104
  version_requirements: !ruby/object:Gem::Requirement
99
105
  requirements:
100
106
  - - "~>"
101
107
  - !ruby/object:Gem::Version
102
- version: '5.0'
108
+ version: '3.4'
103
109
  - !ruby/object:Gem::Dependency
104
- name: rbnacl-libsodium
110
+ name: rbnacl
105
111
  requirement: !ruby/object:Gem::Requirement
106
112
  requirements:
107
113
  - - "~>"
108
114
  - !ruby/object:Gem::Version
109
- version: '1.0'
110
- - - ">="
111
- - !ruby/object:Gem::Version
112
- version: 1.0.16
115
+ version: '5.0'
113
116
  type: :runtime
114
117
  prerelease: false
115
118
  version_requirements: !ruby/object:Gem::Requirement
116
119
  requirements:
117
120
  - - "~>"
118
121
  - !ruby/object:Gem::Version
119
- version: '1.0'
120
- - - ">="
121
- - !ruby/object:Gem::Version
122
- version: 1.0.16
122
+ version: '5.0'
123
123
  - !ruby/object:Gem::Dependency
124
- name: request_store
124
+ name: rbnacl-libsodium
125
125
  requirement: !ruby/object:Gem::Requirement
126
126
  requirements:
127
127
  - - "~>"
128
128
  - !ruby/object:Gem::Version
129
- version: '1.4'
129
+ version: '1.0'
130
130
  - - ">="
131
131
  - !ruby/object:Gem::Version
132
- version: 1.4.1
132
+ version: 1.0.16
133
133
  type: :runtime
134
134
  prerelease: false
135
135
  version_requirements: !ruby/object:Gem::Requirement
136
136
  requirements:
137
137
  - - "~>"
138
138
  - !ruby/object:Gem::Version
139
- version: '1.4'
139
+ version: '1.0'
140
140
  - - ">="
141
141
  - !ruby/object:Gem::Version
142
- version: 1.4.1
142
+ version: 1.0.16
143
143
  - !ruby/object:Gem::Dependency
144
144
  name: ruby_home-srp
145
145
  requirement: !ruby/object:Gem::Requirement
@@ -160,34 +160,28 @@ dependencies:
160
160
  requirements:
161
161
  - - '='
162
162
  - !ruby/object:Gem::Version
163
- version: 2.0.3
163
+ version: 2.0.4
164
164
  type: :runtime
165
165
  prerelease: false
166
166
  version_requirements: !ruby/object:Gem::Requirement
167
167
  requirements:
168
168
  - - '='
169
169
  - !ruby/object:Gem::Version
170
- version: 2.0.3
170
+ version: 2.0.4
171
171
  - !ruby/object:Gem::Dependency
172
172
  name: wisper
173
173
  requirement: !ruby/object:Gem::Requirement
174
174
  requirements:
175
175
  - - "~>"
176
176
  - !ruby/object:Gem::Version
177
- version: '1.6'
178
- - - ">="
179
- - !ruby/object:Gem::Version
180
- version: 1.6.1
177
+ version: '2.0'
181
178
  type: :runtime
182
179
  prerelease: false
183
180
  version_requirements: !ruby/object:Gem::Requirement
184
181
  requirements:
185
182
  - - "~>"
186
183
  - !ruby/object:Gem::Version
187
- version: '1.6'
188
- - - ">="
189
- - !ruby/object:Gem::Version
190
- version: 1.6.1
184
+ version: '2.0'
191
185
  - !ruby/object:Gem::Dependency
192
186
  name: bundler
193
187
  requirement: !ruby/object:Gem::Requirement
@@ -302,7 +296,6 @@ files:
302
296
  - lib/ruby_home/device_id.rb
303
297
  - lib/ruby_home/dns/service.rb
304
298
  - lib/ruby_home/dns/text_record.rb
305
- - lib/ruby_home/factories/accessory_factory.rb
306
299
  - lib/ruby_home/factories/characteristic_factory.rb
307
300
  - lib/ruby_home/factories/default_values/base_value.rb
308
301
  - lib/ruby_home/factories/default_values/bool_value.rb
@@ -312,15 +305,22 @@ files:
312
305
  - lib/ruby_home/factories/default_values/string_value.rb
313
306
  - lib/ruby_home/factories/default_values/uint32_value.rb
314
307
  - lib/ruby_home/factories/default_values/uint8_value.rb
308
+ - lib/ruby_home/factories/service_factory.rb
315
309
  - lib/ruby_home/factories/templates/characteristic_template.rb
316
310
  - lib/ruby_home/factories/templates/service_template.rb
317
311
  - lib/ruby_home/greeter.rb
318
312
  - lib/ruby_home/hap/accessory.rb
313
+ - lib/ruby_home/hap/accessory_collection.rb
319
314
  - lib/ruby_home/hap/characteristic.rb
320
315
  - lib/ruby_home/hap/crypto/chacha20poly1305.rb
321
316
  - lib/ruby_home/hap/crypto/hkdf.rb
317
+ - lib/ruby_home/hap/crypto/session_key.rb
318
+ - lib/ruby_home/hap/ev_response.rb
319
+ - lib/ruby_home/hap/hap_request.rb
320
+ - lib/ruby_home/hap/hap_response.rb
322
321
  - lib/ruby_home/hap/http_decryption.rb
323
322
  - lib/ruby_home/hap/http_encryption.rb
323
+ - lib/ruby_home/hap/server.rb
324
324
  - lib/ruby_home/hap/service.rb
325
325
  - lib/ruby_home/hap/tlv.rb
326
326
  - lib/ruby_home/hex_helper.rb
@@ -331,21 +331,18 @@ files:
331
331
  - lib/ruby_home/http/controllers/pair_setups_controller.rb
332
332
  - lib/ruby_home/http/controllers/pair_verifies_controller.rb
333
333
  - lib/ruby_home/http/controllers/pairings_controller.rb
334
- - lib/ruby_home/http/hap_request.rb
335
- - lib/ruby_home/http/hap_response.rb
336
- - lib/ruby_home/http/hap_server.rb
337
334
  - lib/ruby_home/http/serializers/accessory_serializer.rb
338
335
  - lib/ruby_home/http/serializers/characteristic_serializer.rb
339
336
  - lib/ruby_home/http/serializers/characteristic_value_serializer.rb
340
337
  - lib/ruby_home/http/serializers/object_serializer.rb
341
338
  - lib/ruby_home/http/serializers/service_serializer.rb
339
+ - lib/ruby_home/http/services/socket_notifier.rb
342
340
  - lib/ruby_home/http/services/start_srp_service.rb
343
341
  - lib/ruby_home/http/services/verify_srp_service.rb
344
342
  - lib/ruby_home/identifier_cache.rb
345
343
  - lib/ruby_home/password.rb
346
- - lib/ruby_home/rack/handler/hap_server.rb
344
+ - lib/ruby_home/persistable.rb
347
345
  - lib/ruby_home/version.rb
348
- - lib/ruby_home/yaml_record.rb
349
346
  - rubyhome.gemspec
350
347
  - sbin/characteristic_generator.rb
351
348
  - sbin/service_generator.rb
@@ -1,73 +0,0 @@
1
- module RubyHome
2
- class AccessoryFactory
3
- def self.create(service_name, characteristics: {}, **options)
4
- new(service_name, options, characteristics).create
5
- end
6
-
7
- def initialize(service_name, accessory_options, characteristic_options)
8
- @service_name = service_name
9
- @accessory_options = accessory_options
10
- @characteristic_options = characteristic_options
11
- end
12
-
13
- def create
14
- yield service if block_given?
15
-
16
- create_accessory_information
17
- service.save
18
- create_required_characteristics
19
- create_optional_characteristics
20
-
21
- service
22
- end
23
-
24
- private
25
-
26
- attr_reader :service_name, :accessory_options, :characteristic_options
27
-
28
- def template
29
- @template ||= ServiceTemplate.find_by(name: service_name.to_sym)
30
- end
31
-
32
- def create_accessory_information
33
- unless service_name == :accessory_information
34
- AccessoryFactory.create(:accessory_information, accessory_information_params)
35
- end
36
- end
37
-
38
- def accessory_information_params
39
- accessory_options.merge(accessory: service.accessory)
40
- end
41
-
42
- def create_required_characteristics
43
- template.required_characteristics.map do |characteristic_template|
44
- CharacteristicFactory.create(characteristic_template.name, service: service) do |characteristic|
45
- value = characteristic_options[characteristic.name]
46
- next unless value
47
-
48
- characteristic.value = value
49
- end
50
- end
51
- end
52
-
53
- def create_optional_characteristics
54
- template.optional_characteristics.map do |characteristic_template|
55
- value = characteristic_options[characteristic_template.name]
56
- next unless value
57
-
58
- CharacteristicFactory.create(characteristic_template.name, service: service) do |characteristic|
59
- characteristic.value = value
60
- end
61
- end
62
- end
63
-
64
- def service
65
- @service ||= Service.new(service_params)
66
- end
67
-
68
- def service_params
69
- accessory_options[:accessory] ||= Accessory.new
70
- accessory_options.merge(template.to_hash)
71
- end
72
- end
73
- end
@@ -1,60 +0,0 @@
1
- module RubyHome
2
- module HTTP
3
- class HAPServer < WEBrick::HTTPServer
4
- def run(socket)
5
- while true
6
- res = RubyHome::HTTP::HAPResponse.new(@config)
7
- req = RubyHome::HTTP::HAPRequest.new(@config)
8
- server = self
9
- begin
10
- timeout = @config[:RequestTimeout]
11
- while timeout > 0
12
- break if socket.to_io.wait_readable(0.5)
13
- break if @status != :Running
14
- timeout -= 0.5
15
- end
16
- raise WEBrick::HTTPStatus::EOFError if timeout <= 0 || @status != :Running
17
- raise WEBrick::HTTPStatus::EOFError if socket.eof?
18
- req.parse(socket)
19
- res.received_encrypted_request = req.received_encrypted_request?
20
- res.request_method = req.request_method
21
- res.request_uri = req.request_uri
22
- res.request_http_version = req.http_version
23
- res.keep_alive = req.keep_alive?
24
- server = lookup_server(req) || self
25
- if callback = server[:RequestCallback]
26
- callback.call(req, res)
27
- elsif callback = server[:RequestHandler]
28
- msg = ':RequestHandler is deprecated, please use :RequestCallback'
29
- @logger.warn(msg)
30
- callback.call(req, res)
31
- end
32
- server.service(req, res)
33
- rescue WEBrick::HTTPStatus::EOFError, WEBrick::HTTPStatus::RequestTimeout => ex
34
- res.set_error(ex)
35
- rescue WEBrick::HTTPStatus::Error => ex
36
- @logger.error(ex.message)
37
- res.set_error(ex)
38
- rescue WEBrick::HTTPStatus::Status => ex
39
- res.status = ex.code
40
- rescue StandardError => ex
41
- @logger.error(ex)
42
- res.set_error(ex, true)
43
- ensure
44
- if req.request_line
45
- if req.keep_alive? && res.keep_alive?
46
- req.fixup()
47
- end
48
- res.send_response(socket)
49
- server.access_log(@config, req, res)
50
- end
51
- end
52
-
53
- break if @http_version < '1.1'
54
- break unless req.keep_alive?
55
- break unless res.keep_alive?
56
- end
57
- end
58
- end
59
- end
60
- end
@@ -1,21 +0,0 @@
1
- module RubyHome
2
- module Rack
3
- module Handler
4
- class HAPServer < ::Rack::Handler::WEBrick
5
- def self.run(app, options={})
6
- environment = ENV['RACK_ENV'] || 'development'
7
- default_host = environment == 'development' ? 'localhost' : nil
8
-
9
- options[:BindAddress] = options.delete(:Host) || default_host
10
- options[:Port] ||= 8080
11
- options[:Logger] = WEBrick::Log.new("/dev/null")
12
- options[:AccessLog] = []
13
- @server = HTTP::HAPServer.new(options)
14
- @server.mount '/', Handler::HAPServer, app
15
- yield @server if block_given?
16
- @server.start
17
- end
18
- end
19
- end
20
- end
21
- end