simple_discovery 0.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 +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +35 -0
- data/Rakefile +1 -0
- data/bin/discovery_client +8 -0
- data/bin/discovery_server +12 -0
- data/lib/simple_discovery.rb +7 -0
- data/lib/simple_discovery/announcer.rb +53 -0
- data/lib/simple_discovery/browser.rb +47 -0
- data/lib/simple_discovery/version.rb +3 -0
- data/simple_discovery.gemspec +35 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 59658fd591b9cacd9df6a4a1ddb7ffacea61454d
|
4
|
+
data.tar.gz: e2d5cdee1333fc0aa96a47b468a1ca2d1f3c0eb6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 512892be50daf76d577d3d8557ad7d8a7c3fd673b58a4925bfce921fb185a5d076a67e32c6be08a4621a3b1551128c4067791f93b43b3d1bfa907cd28e495dcb
|
7
|
+
data.tar.gz: 6c3064b8db887b7ce6a17b7226edcfb4bbc23c1fc787fcaa08c926d9637d0c27179f34bfe8cbe7f7a03892494997be323c756c36686c1b22277a6e4d7879e4c4
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 fcarucci
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Discovery
|
2
|
+
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
Add this line to your application's Gemfile:
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
gem 'discovery'
|
10
|
+
```
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install discovery
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
TODO:
|
23
|
+
|
24
|
+
## Development
|
25
|
+
|
26
|
+
TODO:
|
27
|
+
|
28
|
+
## Contributing
|
29
|
+
|
30
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/fcarucci/discovery.
|
31
|
+
|
32
|
+
|
33
|
+
## License
|
34
|
+
|
35
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "simple_discovery"
|
5
|
+
|
6
|
+
announcer = Discovery::Announcer.new do |client, data|
|
7
|
+
puts "Serving #{client.inspect} #{data}"
|
8
|
+
end
|
9
|
+
|
10
|
+
puts "Announcer started..."
|
11
|
+
announcer.add_service(name: "test_server", description: "Test Server", address: "10.0.0.1", port: 2512)
|
12
|
+
announcer.join
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'simple_discovery'
|
2
|
+
|
3
|
+
require "socket"
|
4
|
+
require "timeout"
|
5
|
+
|
6
|
+
module Discovery
|
7
|
+
class Announcer
|
8
|
+
def add_service(name:, description: "", address:, port: )
|
9
|
+
@services[name] = { description: "", address: address, port: port}
|
10
|
+
end
|
11
|
+
|
12
|
+
def remove_service(name:)
|
13
|
+
@services.delete name
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
def reply(ip, port, response)
|
18
|
+
s = UDPSocket.new
|
19
|
+
s.send(Marshal.dump(response), 0, ip, port)
|
20
|
+
s.close
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize
|
24
|
+
@services = {}
|
25
|
+
@thread = Thread.fork do
|
26
|
+
begin
|
27
|
+
s = UDPSocket.new
|
28
|
+
s.bind('0.0.0.0', PORT)
|
29
|
+
|
30
|
+
loop do
|
31
|
+
body, sender = s.recvfrom(1024)
|
32
|
+
data = Marshal.load(body)
|
33
|
+
client_ip = sender[3]
|
34
|
+
|
35
|
+
services = @services.map { |name, service| service[:name] = name; service }
|
36
|
+
|
37
|
+
yield(client_ip, data)
|
38
|
+
|
39
|
+
response = { msg: "Discovery/Announcer", host: Socket.gethostname, services: services }
|
40
|
+
reply(client_ip, data[:port], response) unless data[:port].nil?
|
41
|
+
end
|
42
|
+
rescue Interrupt
|
43
|
+
ensure
|
44
|
+
s.close
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def join
|
50
|
+
@thread.join
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'simple_discovery'
|
2
|
+
|
3
|
+
require "socket"
|
4
|
+
require "timeout"
|
5
|
+
|
6
|
+
module Discovery
|
7
|
+
|
8
|
+
class Browser
|
9
|
+
attr_reader :services
|
10
|
+
attr_reader :response
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@services = []
|
14
|
+
listen
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def broadcast(target = '<broadcast>')
|
20
|
+
body = {:port => PORT + 1, :content => nil}
|
21
|
+
|
22
|
+
s = UDPSocket.new
|
23
|
+
s.setsockopt(Socket::SOL_SOCKET, Socket::SO_BROADCAST, true)
|
24
|
+
s.send(Marshal.dump(body), 0, target, PORT)
|
25
|
+
s.close
|
26
|
+
end
|
27
|
+
|
28
|
+
def listen(time_out = 3)
|
29
|
+
s = UDPSocket.new
|
30
|
+
s.bind('0.0.0.0', PORT + 1)
|
31
|
+
|
32
|
+
begin
|
33
|
+
broadcast
|
34
|
+
body, sender = timeout(time_out) { s.recvfrom(1024) }
|
35
|
+
server_ip = sender[3]
|
36
|
+
data = Marshal.load(body)
|
37
|
+
|
38
|
+
@response = data
|
39
|
+
@services = data[:services]
|
40
|
+
rescue Timeout::Error
|
41
|
+
retry
|
42
|
+
end
|
43
|
+
s.close
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'simple_discovery/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "simple_discovery"
|
8
|
+
spec.version = Discovery::VERSION
|
9
|
+
spec.authors = ["Francesco Carucci"]
|
10
|
+
spec.email = ["francesco@carucci.org"]
|
11
|
+
|
12
|
+
spec.summary = %q{Very simple network service discovery}
|
13
|
+
spec.description = %q{Very simple network service discovery. It doesn't require Bonjour or avahi. }
|
14
|
+
spec.homepage = "https://github.com/fcarucci/discovery-ruby"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
# if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
# else
|
22
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
# end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "bin"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
|
33
|
+
spec.add_runtime_dependency "eventmachine", "~> 1.0"
|
34
|
+
spec.add_runtime_dependency "awesome_print", "~> 1.6"
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple_discovery
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Francesco Carucci
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: eventmachine
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: awesome_print
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.6'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.6'
|
69
|
+
description: 'Very simple network service discovery. It doesn''t require Bonjour or
|
70
|
+
avahi. '
|
71
|
+
email:
|
72
|
+
- francesco@carucci.org
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/discovery_client
|
84
|
+
- bin/discovery_server
|
85
|
+
- lib/simple_discovery.rb
|
86
|
+
- lib/simple_discovery/announcer.rb
|
87
|
+
- lib/simple_discovery/browser.rb
|
88
|
+
- lib/simple_discovery/version.rb
|
89
|
+
- simple_discovery.gemspec
|
90
|
+
homepage: https://github.com/fcarucci/discovery-ruby
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.4.8
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: Very simple network service discovery
|
114
|
+
test_files: []
|