coap 0.0.16 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.travis.yml +13 -2
  4. data/Gemfile +0 -1
  5. data/LICENSE +2 -2
  6. data/README.md +37 -33
  7. data/Rakefile +12 -3
  8. data/bin/coap +111 -0
  9. data/coap.gemspec +34 -29
  10. data/lib/coap.rb +3 -34
  11. data/lib/core.rb +11 -0
  12. data/lib/core/coap.rb +42 -0
  13. data/lib/core/coap/block.rb +98 -0
  14. data/lib/core/coap/client.rb +314 -0
  15. data/lib/core/coap/coap.rb +26 -0
  16. data/lib/core/coap/coding.rb +146 -0
  17. data/lib/core/coap/fsm.rb +82 -0
  18. data/lib/core/coap/message.rb +203 -0
  19. data/lib/core/coap/observer.rb +40 -0
  20. data/lib/core/coap/options.rb +44 -0
  21. data/lib/core/coap/registry.rb +32 -0
  22. data/lib/core/coap/registry/content_formats.yml +7 -0
  23. data/lib/core/coap/resolver.rb +17 -0
  24. data/lib/core/coap/transmission.rb +165 -0
  25. data/lib/core/coap/types.rb +69 -0
  26. data/lib/core/coap/utility.rb +34 -0
  27. data/lib/core/coap/version.rb +5 -0
  28. data/lib/core/core_ext/socket.rb +19 -0
  29. data/lib/core/hexdump.rb +18 -0
  30. data/lib/core/link.rb +97 -0
  31. data/lib/core/os.rb +15 -0
  32. data/spec/block_spec.rb +160 -0
  33. data/spec/client_spec.rb +86 -0
  34. data/spec/fixtures/coap.me.link +1 -0
  35. data/spec/link_spec.rb +98 -0
  36. data/spec/registry_spec.rb +39 -0
  37. data/spec/resolver_spec.rb +19 -0
  38. data/spec/spec_helper.rb +17 -0
  39. data/spec/transmission_spec.rb +70 -0
  40. data/test/helper.rb +15 -0
  41. data/test/test_client.rb +99 -228
  42. data/test/test_message.rb +99 -71
  43. metadata +140 -37
  44. data/bin/client +0 -42
  45. data/lib/coap/block.rb +0 -45
  46. data/lib/coap/client.rb +0 -364
  47. data/lib/coap/coap.rb +0 -273
  48. data/lib/coap/message.rb +0 -187
  49. data/lib/coap/mysocket.rb +0 -81
  50. data/lib/coap/observer.rb +0 -41
  51. data/lib/coap/version.rb +0 -3
  52. data/lib/misc/hexdump.rb +0 -17
  53. data/test/coap_test_helper.rb +0 -2
  54. data/test/disabled_econotag_blck.rb +0 -33
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1ea95430043e3d9721078d8f6dd68118c3d6ad50
4
- data.tar.gz: 92df4bf71ded328e1377b93c9ca76662b739433f
3
+ metadata.gz: 56fd9991ac9ab886355fcce10739897c5ead898c
4
+ data.tar.gz: 53cf80a9babac55dd80aebe62741be8d13b3b1f4
5
5
  SHA512:
6
- metadata.gz: 28be7a9f4417b5be3e458cc422e8b618b019dfc5f5e827016d166dfdd95abf90ebc2d0dd5751dff0f5757a3b0a472cabc10d270e1b2309ad4974748e0533c92a
7
- data.tar.gz: a9032afb549e9f1632fdaafa2f4143834397da3dcc1b6ae4d1948e7c638984e06cd7908175ecd6e01fda606fddabd782a2db99824137b1cdc25b741732f408ac
6
+ metadata.gz: 01be6617acec7d215ddf15fdd34e443f6114f6677d5d2de3292298bd7e28c30c90f5a97f66f7aa3b08fd2d4853c3451f0159b41ef09ae1d675fcaa43727006ad
7
+ data.tar.gz: be1e122636bf35da1cd884cfaa663bd48539879b8607a96de3c53190045e10307193d84847048e981abe04f727cf621fb9041baa347d02856cbad004ece38ef0
data/.gitignore CHANGED
@@ -32,3 +32,5 @@ build/
32
32
 
33
33
  # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
34
  .rvmrc
35
+
36
+ /Gemfile.lock
data/.travis.yml CHANGED
@@ -1,5 +1,16 @@
1
1
  language: ruby
2
+
2
3
  rvm:
3
- - 2.1.0
4
+ - 2.2
5
+ - jruby
6
+
7
+ matrix:
8
+ allow_failures:
9
+ - rvm: jruby
10
+
11
+ notifications:
12
+ email: false
13
+
4
14
  script:
5
- - "bundle exec rake test"
15
+ - bundle exec rake build
16
+ - bundle exec rake coveralls
data/Gemfile CHANGED
@@ -1,4 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in coap.gemspec
4
3
  gemspec
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2014 Simon Frerichs, Carsten Bormann
3
+ Copyright (c) 2014 Carsten Bormann, Simon Frerichs, henning mueller
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
18
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,32 +1,31 @@
1
- [![Gem Version](https://badge.fury.io/rb/coap.png)](http://badge.fury.io/rb/coap)
2
- [![Dependency Status](https://gemnasium.com/SmallLars/coap.png)](https://gemnasium.com/SmallLars/coap)
3
- [![Build Status](https://travis-ci.org/SmallLars/coap.png?branch=master)](https://travis-ci.org/SmallLars/coap)
4
- [![Coverage Status](https://coveralls.io/repos/SmallLars/coap/badge.png?branch=master)](https://coveralls.io/r/SmallLars/coap)
5
- [![Code Climate](https://codeclimate.com/github/SmallLars/coap.png)](https://codeclimate.com/github/SmallLars/coap)
1
+ [![Gem Version](https://img.shields.io/gem/v/coap.svg)](http://badge.fury.io/rb/coap)
2
+ [![Dependency Status](https://img.shields.io/gemnasium/nning/coap.svg)](https://gemnasium.com/nning/coap)
3
+ [![Build Status](https://img.shields.io/travis/nning/coap.svg)](https://travis-ci.org/nning/coap)
4
+ [![Coverage Status](https://img.shields.io/coveralls/nning/coap.svg)](https://coveralls.io/r/nning/coap)
5
+ [![Code Climate](https://img.shields.io/codeclimate/github/nning/coap.svg)](https://codeclimate.com/github/nning/coap)
6
6
 
7
- # Gem CoAP
7
+ # CoAP
8
8
 
9
- Ruby Gem for RFC 7252 - Constrained Application Protocol (CoAP)<br>
10
- Based on code by Carsten Bormann<br>
9
+ This Ruby gem implements client functionality for [RFC
10
+ 7252](http://tools.ietf.org/html/rfc7252), the Constrained Application Protocol
11
+ (CoAP). The message parsing code included is written by Carsten Bormann, one of
12
+ the RFC authors.
11
13
 
12
- The Constrained Application Protocol (CoAP) is a specialized web
13
- transfer protocol for use with constrained nodes and constrained
14
- (e.g., low-power, lossy) networks. The nodes often have 8-bit
15
- microcontrollers with small amounts of ROM and RAM, while constrained
16
- networks such as 6LoWPAN often have high packet error rates and a
17
- typical throughput of 10s of kbit/s. The protocol is designed for
18
- machine-to-machine (M2M) applications such as smart energy and
19
- building automation.<br>
14
+ The Constrained Application Protocol (CoAP) is a specialized web transfer
15
+ protocol for use with constrained nodes and constrained (e.g., low-power,
16
+ lossy) networks. The nodes often have 8-bit microcontrollers with small
17
+ amounts of ROM and RAM, while constrained networks such as 6LoWPAN often have
18
+ high packet error rates and a typical throughput of 10s of kbit/s. The
19
+ protocol is designed for machine-to-machine (M2M) applications such as smart
20
+ energy and building automation.
20
21
 
22
+ Additionally supported extensions of the CoAP protocol:
21
23
 
22
- Implemented Version: RFC (http://tools.ietf.org/html/rfc7252)<br>
23
-
24
- Additionally implemented:
25
-
26
- - Blockwise Transfer http://tools.ietf.org/html/draft-ietf-core-block-14
27
- - Observe http://tools.ietf.org/html/draft-ietf-core-observe-13
24
+ * [Blockwise Transfer](http://tools.ietf.org/html/draft-ietf-core-block-14)
25
+ * [Observe](http://tools.ietf.org/html/draft-ietf-core-observe-13)
28
26
 
29
27
  ## Install
28
+
30
29
  Add this line to your application's Gemfile:
31
30
 
32
31
  gem 'coap'
@@ -41,24 +40,29 @@ Or install it yourself as:
41
40
 
42
41
  ## Usage
43
42
 
44
- ### In your ruby/rails application
43
+ ### In your Ruby (on Rails) application
45
44
 
45
+ require 'coap'
46
+ CoAP::Client.new.get_by_uri('coap://coap.me/hello').payload
46
47
 
47
- client = CoAP::Client.new
48
- answer = client.get('coap.me', 5683, '/hello')
49
- p answer.payload
48
+ See `test/test_client.rb` for more examples.
50
49
 
51
- Lot's of examples are stored in test/test_client.rb<br>
52
- Code is commented in rdoc format
50
+ ### Command Line Client
53
51
 
54
- ### Command Line Client (very limited)
52
+ The command line client supports the basic CoAP methods.
55
53
 
56
- ./client get coap://coap.me:5683/.well-known/core
54
+ coap get coap://coap.me/.well-known/core
57
55
 
58
56
  ## Testing
59
57
 
60
- rake test
58
+ rake
61
59
 
62
60
  ## Copyright
63
- Copyright (C) 2014 Simon Frerichs. See LICENSE.txt for further details.<br>
64
- Based on code by Carsten Bormann
61
+
62
+ The code is published under the MIT license (see the LICENSE file).
63
+
64
+ ### Authors
65
+
66
+ * Carsten Bormann
67
+ * Simon Frerichs
68
+ * [henning mueller](https://henning.orgizm.net)
data/Rakefile CHANGED
@@ -1,9 +1,18 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'coveralls/rake/task'
2
3
  require 'rake/testtask'
4
+ require 'rspec/core/rake_task'
5
+
6
+ Coveralls::RakeTask.new
3
7
 
4
8
  Rake::TestTask.new do |t|
5
9
  t.libs << 'test'
6
10
  end
7
11
 
8
- desc "Run tests"
9
- task :default => :test
12
+ RSpec::Core::RakeTask.new(:spec)
13
+
14
+ desc 'Run tests.'
15
+ task default: [:spec, :test]
16
+
17
+ desc 'Tun tests and push coverage to coveralls.'
18
+ task coveralls: [:default, 'coveralls:push']
data/bin/coap ADDED
@@ -0,0 +1,111 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'getoptlong'
4
+ require 'pp'
5
+ require 'uri'
6
+
7
+ $:.unshift File.expand_path('../lib', File.dirname(__FILE__))
8
+ require 'coap'
9
+
10
+ def usage
11
+ $stderr.puts <<EOF
12
+ Usage: #{File.basename($0)} [options] <method> <uri>
13
+
14
+ --debug, -d Extra debug output.
15
+ --output, -o <target> Redirect payload output. Target can be "-" for
16
+ STDOUT or a file path.
17
+ --payload, -p <string> Payload for POST and PUT as string.
18
+ --payload-file, -f <file> Read payload for POST and PUT from file.
19
+ --type, -t <type> Message type (con, non, ack, rst).
20
+ --help, -h This usage message.
21
+
22
+ EOF
23
+ exit 1
24
+ end
25
+
26
+ METHODS = CoAP::METHODS + [:observe]
27
+
28
+ opts = GetoptLong.new(
29
+ ['--debug', '-d', GetoptLong::NO_ARGUMENT],
30
+ ['--output', '-o', GetoptLong::REQUIRED_ARGUMENT],
31
+ ['--payload', '-p', GetoptLong::REQUIRED_ARGUMENT],
32
+ ['--payload-file', '-f', GetoptLong::REQUIRED_ARGUMENT],
33
+ ['--type', '-t', GetoptLong::REQUIRED_ARGUMENT],
34
+ ['--help', '-h', GetoptLong::NO_ARGUMENT]
35
+ )
36
+
37
+ $DEBUG = false
38
+ output = nil
39
+ payload = nil
40
+ options = {}
41
+
42
+ opts.each do |opt, arg|
43
+ case opt
44
+ when '--debug'
45
+ $DEBUG = true
46
+ when '--output'
47
+ if arg == '-'
48
+ output = $stdout
49
+ else
50
+ output = File.open(arg, 'w')
51
+ end
52
+ when '--payload'
53
+ payload = arg
54
+ when '--payload-file'
55
+ payload = File.read(arg)
56
+ when '--type'
57
+ options[:tt] = arg.to_sym
58
+ when '--help'
59
+ usage
60
+ end
61
+ end
62
+
63
+ usage if ARGV.size != 2
64
+
65
+ method = ARGV.shift
66
+ uri = ARGV.shift
67
+
68
+ method = method.to_sym
69
+ usage unless METHODS.include? method
70
+
71
+ uri = 'coap://' + uri unless uri[/^coap[s]?:\/\//]
72
+ uri = URI.parse(uri)
73
+
74
+ usage unless uri.scheme[/^coap/]
75
+
76
+ client = CoAP::Client.new
77
+
78
+ answer = case method
79
+ when :get
80
+ client.get_by_uri(uri, payload, options)
81
+
82
+ when :post
83
+ client.post_by_uri(uri, payload, options)
84
+
85
+ when :put
86
+ client.put_by_uri(uri, payload, options)
87
+
88
+ when :delete
89
+ client.delete_by_uri(uri, payload, options)
90
+
91
+ when :observe
92
+ callback = ->(socket, message) do
93
+ if output
94
+ output.puts message.payload
95
+ else
96
+ pp message
97
+ end
98
+ end
99
+
100
+ begin
101
+ client.observe_by_uri(uri, callback)
102
+ rescue Interrupt
103
+ exit
104
+ end
105
+ end
106
+
107
+ if output
108
+ output.puts answer.payload
109
+ else
110
+ pp answer
111
+ end
data/coap.gemspec CHANGED
@@ -1,33 +1,38 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'coap/version'
1
+ $:.unshift File.expand_path('lib', File.dirname(__FILE__))
2
+ require 'core/coap/version'
5
3
 
6
- Gem::Specification.new do |spec|
7
- spec.name = "coap"
8
- spec.version = Coap::VERSION
9
- spec.authors = ["Carsten Bormann","Simon Frerichs"]
10
- spec.email = ["morpheus@morphhome.net"]
11
- spec.summary = %q{Ruby Gem for RFC 7252 - Constrained Application Protocol (CoAP)}
12
- spec.description = %q{Ruby Gem for RFC 7252 - Constrained Application Protocol (CoAP)
13
- The Constrained Application Protocol (CoAP) is a specialized web
14
- transfer protocol for use with constrained nodes and constrained
15
- (e.g., low-power, lossy) networks. The nodes often have 8-bit
16
- microcontrollers with small amounts of ROM and RAM, while constrained
17
- networks such as 6LoWPAN often have high packet error rates and a
18
- typical throughput of 10s of kbit/s. The protocol is designed for
19
- machine-to-machine (M2M) applications such as smart energy and
20
- building automation}
21
- spec.homepage = "https://github.com/SmallLars/coap"
22
- spec.license = "MIT"
4
+ Gem::Specification.new do |s|
5
+ s.name = 'coap'
6
+ s.version = CoRE::CoAP::VERSION
23
7
 
24
- spec.files = `git ls-files`.split($/)
25
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
26
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
27
- spec.require_paths = ["lib"]
8
+ s.summary = 'Pure Ruby implementation of RFC 7252 (Constrained Application Protocol (CoAP))'
9
+ s.description = 'Pure Ruby implementation of RFC 7252 (Constrained Application
10
+ Protocol (CoAP)). The Constrained Application Protocol (CoAP) is a
11
+ specialized web transfer protocol for use with constrained nodes and
12
+ constrained (e.g., low-power, lossy) networks. The nodes often have 8-bit
13
+ microcontrollers with small amounts of ROM and RAM, while constrained
14
+ networks such as IPv6 over Low-Power Wireless Personal Area Networks
15
+ (6LoWPANs) often have high packet error rates and a typical throughput of
16
+ 10s of kbit/s. The protocol is designed for machine-to-machine (M2M)
17
+ applications such as smart energy and building automation.'
28
18
 
29
- spec.add_development_dependency "bundler", "~> 1.5"
30
- spec.add_development_dependency "rake"
31
- spec.add_dependency "resolv-ipv6favor"
32
- # spec.add_dependency "codtls"
19
+ s.homepage = 'https://github.com/nning/coap'
20
+ s.license = 'MIT'
21
+ s.authors = ['Carsten Bormann', 'Simon Frerichs', 'henning mueller']
22
+ s.email = 'henning@orgizm.net'
23
+
24
+ s.files = `git ls-files`.split($/)
25
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
26
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
27
+ s.require_paths = ['lib']
28
+
29
+ s.add_development_dependency 'bundler', '~> 1.6'
30
+ s.add_development_dependency 'coveralls', '~> 0.7'
31
+ s.add_development_dependency 'faker', '~> 1.4'
32
+ s.add_development_dependency 'minitest', '~> 5.4'
33
+ s.add_development_dependency 'rake', '~> 10.3'
34
+ s.add_development_dependency 'rspec', '~> 3.0'
35
+
36
+ s.add_dependency 'celluloid-io', '~> 0.16', '>= 0.16.1'
37
+ s.add_dependency 'resolv-ipv6favor', '~> 0'
33
38
  end
data/lib/coap.rb CHANGED
@@ -1,34 +1,3 @@
1
- # encoding: utf-8
2
- module CoAP
3
- module_function
4
-
5
- def logger
6
- if @logger.nil?
7
- @logger = Logger.new(STDOUT)
8
- @logger.level = Logger::WARN
9
- end
10
-
11
- @logger
12
- end
13
- def logger= logger
14
- @logger.close unless @logger.nil?
15
-
16
- @logger = logger
17
- end
18
- end
19
-
20
- require 'logger'
21
- require 'socket'
22
- require 'resolv-ipv6favor'
23
- require 'ipaddr'
24
- require 'timeout'
25
- #require 'CoDTLS'
26
-
27
- require 'coap/coap.rb'
28
- require 'coap/message.rb'
29
- require 'coap/block.rb'
30
- require 'coap/mysocket.rb'
31
- require 'coap/observer.rb'
32
- require 'coap/client.rb'
33
-
34
- require 'misc/hexdump.rb'
1
+ $:.unshift File.expand_path(File.dirname(__FILE__))
2
+ require 'core'
3
+ include CoRE
data/lib/core.rb ADDED
@@ -0,0 +1,11 @@
1
+ $:.unshift File.expand_path(File.dirname(__FILE__))
2
+
3
+ module CoRE
4
+ end
5
+
6
+ require 'core/link'
7
+ require 'core/coap'
8
+ require 'core/hexdump'
9
+ require 'core/os'
10
+
11
+ require 'core/core_ext/socket'
data/lib/core/coap.rb ADDED
@@ -0,0 +1,42 @@
1
+ module CoRE
2
+ module CoAP
3
+ module_function
4
+
5
+ def logger
6
+ if @logger.nil?
7
+ @logger = Logger.new(STDOUT)
8
+ @logger.level = Logger::WARN
9
+ end
10
+
11
+ @logger
12
+ end
13
+
14
+ def logger=(logger)
15
+ @logger.close unless @logger.nil?
16
+ @logger = logger
17
+ end
18
+ end
19
+ end
20
+
21
+ require 'celluloid/io'
22
+ require 'ipaddr'
23
+ require 'logger'
24
+ require 'resolv-ipv6favor'
25
+ require 'socket'
26
+ require 'timeout'
27
+ require 'yaml'
28
+
29
+ require 'core/coap/utility'
30
+ require 'core/coap/coding'
31
+ require 'core/coap/types'
32
+ require 'core/coap/options'
33
+ require 'core/coap/registry'
34
+
35
+ require 'core/coap/coap'
36
+ require 'core/coap/message'
37
+ require 'core/coap/version'
38
+ require 'core/coap/block'
39
+ require 'core/coap/resolver'
40
+ require 'core/coap/transmission'
41
+ require 'core/coap/observer'
42
+ require 'core/coap/client'