buschtelefon 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.ruby-version +1 -0
- data/.travis.yml +9 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +64 -0
- data/Rakefile +8 -0
- data/bin/check +3 -0
- data/bin/console +14 -0
- data/bin/run +49 -0
- data/bin/setup +8 -0
- data/buschtelefon.gemspec +31 -0
- data/lib/buschtelefon/brain.rb +31 -0
- data/lib/buschtelefon/gossip.rb +20 -0
- data/lib/buschtelefon/net_tattler.rb +28 -0
- data/lib/buschtelefon/remote_tattler.rb +17 -0
- data/lib/buschtelefon/tattler.rb +23 -0
- data/lib/buschtelefon/version.rb +3 -0
- data/lib/buschtelefon.rb +9 -0
- metadata +149 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 58f0e2bba934f20c2e27a56e2d5109ea3c924834
|
4
|
+
data.tar.gz: f7608312630b99fe86315b002a556fae92f48d3a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c2347c888c76585598c99413da4e0ceb583cc0d7271c82a7e27a373d5172cc7de1f6b7673f9589389cb888997f25e8d377a046b9a880edecba782a092c024d08
|
7
|
+
data.tar.gz: 8770936ae6a8454e69f6fb5d8a5d908ca1ba6fd8e4ff994034afebc4775ebdfdfc2de4a4faa176233287a606702c13da532b97cdb8899cca48e8cdbbefb27ed6
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.8
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Josua Schmid
|
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,64 @@
|
|
1
|
+
# Buschtelefon
|
2
|
+
|
3
|
+
With *buschtelefon* you can setup a gossiping meshnet.
|
4
|
+
All of it should behave just like human beings tattling at a
|
5
|
+
coffee party.
|
6
|
+
|
7
|
+
There basically are two features:
|
8
|
+
* Nodes make coffee klatsch available between each other automatically.
|
9
|
+
* Nodes can be asked about stale information to fight FOMO.
|
10
|
+
|
11
|
+
Communication happens via UDP. Autodiscovery of nodes is not
|
12
|
+
implemented (yet).
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
Add this line to your application's Gemfile:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
gem 'buschtelefon'
|
20
|
+
```
|
21
|
+
|
22
|
+
And then execute:
|
23
|
+
|
24
|
+
$ bundle
|
25
|
+
|
26
|
+
Or install it yourself as:
|
27
|
+
|
28
|
+
$ gem install buschtelefon
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
You can setup your tattling meshnet the following way:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
include Buschtelefon
|
36
|
+
|
37
|
+
aunt_may = NetTattler.new(port: 1337)
|
38
|
+
aunt_ruth = RemoteTattler.new(host: 'example.com', port: 1337)
|
39
|
+
aunt_may.connect(aunt_ruth)
|
40
|
+
|
41
|
+
aunt_may.feed(Gossip.new('Renuo can do blockchain consulting!'))
|
42
|
+
```
|
43
|
+
|
44
|
+
## Development
|
45
|
+
|
46
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
47
|
+
Then, run `bin/check` to run the tests. You can also run `bin/console`
|
48
|
+
for an interactive prompt that will allow you to experiment.
|
49
|
+
|
50
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
51
|
+
To release a new version, update the version number in `version.rb`,
|
52
|
+
and then run `bundle exec rake release`, which will create a git tag
|
53
|
+
for the version, push git commits and tags, and push the `.gem` file
|
54
|
+
to [rubygems.org](https://rubygems.org).
|
55
|
+
|
56
|
+
## Contributing
|
57
|
+
|
58
|
+
Bug reports and pull requests are welcome on GitHub at
|
59
|
+
<https://github.com/renuo/buschtelefon>.
|
60
|
+
|
61
|
+
## License
|
62
|
+
|
63
|
+
The gem is available as open source under the terms of
|
64
|
+
the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/check
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'buschtelefon'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require 'pry'
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start(__FILE__)
|
data/bin/run
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
Thread.abort_on_exception = true
|
3
|
+
|
4
|
+
require_relative '../lib/buschtelefon'
|
5
|
+
|
6
|
+
include Buschtelefon
|
7
|
+
|
8
|
+
# A
|
9
|
+
# ↕
|
10
|
+
# B ↔ D ↔ E
|
11
|
+
# ↓ ↑
|
12
|
+
# C → F
|
13
|
+
|
14
|
+
tattlers = {
|
15
|
+
A: Tattler.new,
|
16
|
+
B: Tattler.new,
|
17
|
+
C: Tattler.new,
|
18
|
+
D: Tattler.new,
|
19
|
+
E: Tattler.new,
|
20
|
+
F: Tattler.new
|
21
|
+
}
|
22
|
+
|
23
|
+
tattlers[:A].connect(tattlers[:B])
|
24
|
+
tattlers[:B].connect(tattlers[:A])
|
25
|
+
|
26
|
+
tattlers[:B].connect(tattlers[:C])
|
27
|
+
tattlers[:C].connect(tattlers[:F])
|
28
|
+
tattlers[:F].connect(tattlers[:D])
|
29
|
+
|
30
|
+
tattlers[:B].connect(tattlers[:D])
|
31
|
+
tattlers[:D].connect(tattlers[:B])
|
32
|
+
|
33
|
+
tattlers[:D].connect(tattlers[:E])
|
34
|
+
tattlers[:E].connect(tattlers[:D])
|
35
|
+
|
36
|
+
puts 'Feeding locals'
|
37
|
+
tattlers[:A].feed(Gossip.new('Tezos'))
|
38
|
+
|
39
|
+
josua = NetTattler.new(port: 9999)
|
40
|
+
simon = NetTattler.new(port: 9998)
|
41
|
+
remote_simon = RemoteTattler.new(host: 'localhost', port: 9998)
|
42
|
+
|
43
|
+
josua.connect(remote_simon)
|
44
|
+
|
45
|
+
Thread.new { josua.listen }
|
46
|
+
Thread.new { simon.listen }
|
47
|
+
|
48
|
+
remote_simon.feed(Gossip.new('Antshare'))
|
49
|
+
puts 'gach'
|
data/bin/setup
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'buschtelefon/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'buschtelefon'
|
7
|
+
spec.version = Buschtelefon::VERSION
|
8
|
+
spec.authors = ['Josua Schmid']
|
9
|
+
spec.email = ['josua.schmid@renuo.ch']
|
10
|
+
|
11
|
+
spec.summary = %q{Library for meshnet gossip}
|
12
|
+
spec.description = %q{Buschtelefon can be used to share information in a between Ruby clients over a network}
|
13
|
+
spec.homepage = 'https://github.com/schmijos/buschtelefon'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = 'exe'
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ['lib']
|
22
|
+
|
23
|
+
spec.required_ruby_version = '>= 2.1.0'
|
24
|
+
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
26
|
+
spec.add_development_dependency 'cucumber', '~> 3.0'
|
27
|
+
spec.add_development_dependency 'factory_bot', '~> 4.0'
|
28
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
29
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
30
|
+
spec.add_development_dependency 'simplecov', '~> 0.16'
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Buschtelefon
|
2
|
+
class Brain
|
3
|
+
attr_reader :capacity
|
4
|
+
|
5
|
+
def initialize(capacity = 100)
|
6
|
+
@capacity = capacity
|
7
|
+
@gossip_sink = []
|
8
|
+
end
|
9
|
+
|
10
|
+
def <<(gossip)
|
11
|
+
@gossip_sink << gossip
|
12
|
+
reorganize
|
13
|
+
end
|
14
|
+
|
15
|
+
def contains?(gossip)
|
16
|
+
@gossip_sink.include?(gossip)
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_a
|
20
|
+
@gossip_sink
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def reorganize
|
26
|
+
@gossip_sink.sort! { |x, y| y.created_at <=> x.created_at }
|
27
|
+
@gossip_sink.uniq!(&:message)
|
28
|
+
@gossip_sink.slice!(capacity..-1) # only keep the newest
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Buschtelefon
|
2
|
+
class Gossip
|
3
|
+
attr_reader :created_at, :message
|
4
|
+
|
5
|
+
def initialize(message)
|
6
|
+
@created_at = unix_timestamp_ms
|
7
|
+
@message = message
|
8
|
+
end
|
9
|
+
|
10
|
+
def ==(other)
|
11
|
+
@message == other.message
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def unix_timestamp_ms
|
17
|
+
(Time.now.to_f * 1000).to_i
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'socket'
|
2
|
+
require_relative 'tattler'
|
3
|
+
|
4
|
+
module Buschtelefon
|
5
|
+
class NetTattler < Tattler
|
6
|
+
def initialize(port: 9999, &interceptor)
|
7
|
+
super()
|
8
|
+
@port = port
|
9
|
+
end
|
10
|
+
|
11
|
+
def listen(&_block)
|
12
|
+
puts "Started UDP server on #{@port}..."
|
13
|
+
|
14
|
+
Socket.udp_server_loop(@port) do |message, message_source|
|
15
|
+
yield(message)
|
16
|
+
handle_incoming_message(message)
|
17
|
+
puts "Got \"#{message}\" from #{message_source}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def handle_incoming_message(message)
|
24
|
+
feed(Gossip.new(message))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'socket'
|
2
|
+
|
3
|
+
module Buschtelefon
|
4
|
+
# No need to inherit from Tattler in Ruby
|
5
|
+
class RemoteTattler
|
6
|
+
def initialize(host:, port:)
|
7
|
+
@host = host
|
8
|
+
@port = port
|
9
|
+
@outbound_socket = UDPSocket.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def feed(gossip)
|
13
|
+
@outbound_socket.send(gossip.message, 0, @host, @port)
|
14
|
+
puts "Sent \"#{gossip.message}\" to #{@host}:#{@port}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Buschtelefon
|
2
|
+
class Tattler
|
3
|
+
attr_reader :connections
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@connections = []
|
7
|
+
@brain = Brain.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def connect(tattler)
|
11
|
+
@connections << tattler
|
12
|
+
@connections.uniq!
|
13
|
+
end
|
14
|
+
|
15
|
+
def feed(gossip)
|
16
|
+
old_gossip = @brain.contains?(gossip)
|
17
|
+
@brain << gossip # refresh memory
|
18
|
+
return if old_gossip
|
19
|
+
|
20
|
+
@connections.each { |tattler| tattler.feed(gossip) }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/buschtelefon.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
require_relative 'buschtelefon/version'
|
2
|
+
require_relative 'buschtelefon/brain'
|
3
|
+
require_relative 'buschtelefon/gossip'
|
4
|
+
require_relative 'buschtelefon/net_tattler'
|
5
|
+
require_relative 'buschtelefon/remote_tattler'
|
6
|
+
require_relative 'buschtelefon/tattler'
|
7
|
+
|
8
|
+
module Buschtelefon
|
9
|
+
end
|
metadata
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: buschtelefon
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Josua Schmid
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-12-09 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.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: cucumber
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: factory_bot
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '4.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.16'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.16'
|
97
|
+
description: Buschtelefon can be used to share information in a between Ruby clients
|
98
|
+
over a network
|
99
|
+
email:
|
100
|
+
- josua.schmid@renuo.ch
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- ".ruby-version"
|
108
|
+
- ".travis.yml"
|
109
|
+
- Gemfile
|
110
|
+
- LICENSE.txt
|
111
|
+
- README.md
|
112
|
+
- Rakefile
|
113
|
+
- bin/check
|
114
|
+
- bin/console
|
115
|
+
- bin/run
|
116
|
+
- bin/setup
|
117
|
+
- buschtelefon.gemspec
|
118
|
+
- lib/buschtelefon.rb
|
119
|
+
- lib/buschtelefon/brain.rb
|
120
|
+
- lib/buschtelefon/gossip.rb
|
121
|
+
- lib/buschtelefon/net_tattler.rb
|
122
|
+
- lib/buschtelefon/remote_tattler.rb
|
123
|
+
- lib/buschtelefon/tattler.rb
|
124
|
+
- lib/buschtelefon/version.rb
|
125
|
+
homepage: https://github.com/schmijos/buschtelefon
|
126
|
+
licenses:
|
127
|
+
- MIT
|
128
|
+
metadata: {}
|
129
|
+
post_install_message:
|
130
|
+
rdoc_options: []
|
131
|
+
require_paths:
|
132
|
+
- lib
|
133
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: 2.1.0
|
138
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
requirements: []
|
144
|
+
rubyforge_project:
|
145
|
+
rubygems_version: 2.2.5
|
146
|
+
signing_key:
|
147
|
+
specification_version: 4
|
148
|
+
summary: Library for meshnet gossip
|
149
|
+
test_files: []
|