buschtelefon 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 58f0e2bba934f20c2e27a56e2d5109ea3c924834
4
- data.tar.gz: f7608312630b99fe86315b002a556fae92f48d3a
3
+ metadata.gz: 324cfeafd9c295fdd335f6b60da096845eddb1fd
4
+ data.tar.gz: 234ef8b0e84fd3d39880f4d63141887c69445a9f
5
5
  SHA512:
6
- metadata.gz: c2347c888c76585598c99413da4e0ceb583cc0d7271c82a7e27a373d5172cc7de1f6b7673f9589389cb888997f25e8d377a046b9a880edecba782a092c024d08
7
- data.tar.gz: 8770936ae6a8454e69f6fb5d8a5d908ca1ba6fd8e4ff994034afebc4775ebdfdfc2de4a4faa176233287a606702c13da532b97cdb8899cca48e8cdbbefb27ed6
6
+ metadata.gz: dd93c3f0f4805b0b849fbdab2f9527d086380694d05eb8e953bbdef4a0b817414c5782cc5e35a51f6fb0519c0b83973e6a49129af0b31f299479c8e5f79afe1a
7
+ data.tar.gz: 990c757b4760830488ad70a8cef7eccc9c85375e708989b4d7ac7e6752073d8bda066e43d28b4d9e5aac14cc275a31cacd01176cd7edaa410b25e953f3a309b6
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.1.8
1
+ 2.1.10
data/.travis.yml CHANGED
@@ -1,9 +1,11 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.1.0
5
- - 2.2.0
6
- - 2.3.0
7
- - 2.4.0
8
- - 2.5.0
9
- before_install: gem install bundler -v 1.16.1
4
+ - 2.1
5
+ - 2.2
6
+ - 2.3
7
+ - 2.4
8
+ - 2.5
9
+ - 2.6
10
+ cache: bundler
11
+ script: bin/check
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Buschtelefon
2
2
 
3
+ [![Travis Build Status](https://travis-ci.org/renuo/buschtelefon.svg?branch=master)](https://travis-ci.org/renuo/buschtelefon)
4
+
3
5
  With *buschtelefon* you can setup a gossiping meshnet.
4
6
  All of it should behave just like human beings tattling at a
5
7
  coffee party.
@@ -13,7 +15,8 @@ implemented (yet).
13
15
 
14
16
  ## Installation
15
17
 
16
- Add this line to your application's Gemfile:
18
+ You can use this gem with Ruby versions starting from 2.1.
19
+ Add the following line to your application's Gemfile:
17
20
 
18
21
  ```ruby
19
22
  gem 'buschtelefon'
@@ -29,16 +32,21 @@ Or install it yourself as:
29
32
 
30
33
  ## Usage
31
34
 
32
- You can setup your tattling meshnet the following way:
35
+ You can setup your local tattling meshnet the following way:
33
36
 
34
37
  ```ruby
35
38
  include Buschtelefon
36
39
 
37
- aunt_may = NetTattler.new(port: 1337)
38
- aunt_ruth = RemoteTattler.new(host: 'example.com', port: 1337)
39
- aunt_may.connect(aunt_ruth)
40
+ aunt_may = NetTattler.new
41
+ aunt_ruth = NetTattler.new
42
+ remote_aunt_ruth = RemoteTattler.new(host: 'localhost', port: aunt_ruth.port)
43
+
44
+ aunt_may.connect(remote_aunt_ruth)
45
+
46
+ Thread.new { aunt_may.listen }
47
+ Thread.new { aunt_ruth.listen }
40
48
 
41
- aunt_may.feed(Gossip.new('Renuo can do blockchain consulting!'))
49
+ aunt_may.feed(Gossip.new('Did you hear about the cool company "Renuo"?'))
42
50
  ```
43
51
 
44
52
  ## Development
data/bin/check CHANGED
@@ -1,3 +1,7 @@
1
1
  #!/bin/sh
2
2
 
3
- bundle exec rake
3
+ set -e
4
+
5
+ bundle exec rspec
6
+ bundle exec cucumber
7
+
data/bin/run CHANGED
@@ -36,9 +36,9 @@ tattlers[:E].connect(tattlers[:D])
36
36
  puts 'Feeding locals'
37
37
  tattlers[:A].feed(Gossip.new('Tezos'))
38
38
 
39
- josua = NetTattler.new(port: 9999)
40
- simon = NetTattler.new(port: 9998)
41
- remote_simon = RemoteTattler.new(host: 'localhost', port: 9998)
39
+ josua = NetTattler.new
40
+ simon = NetTattler.new
41
+ remote_simon = RemoteTattler.new(host: 'localhost', port: simon.port)
42
42
 
43
43
  josua.connect(remote_simon)
44
44
 
@@ -46,4 +46,3 @@ Thread.new { josua.listen }
46
46
  Thread.new { simon.listen }
47
47
 
48
48
  remote_simon.feed(Gossip.new('Antshare'))
49
- puts 'gach'
data/buschtelefon.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.email = ['josua.schmid@renuo.ch']
10
10
 
11
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}
12
+ spec.description = %q{Buschtelefon can be used to share information between Ruby clients over a network}
13
13
  spec.homepage = 'https://github.com/schmijos/buschtelefon'
14
14
  spec.license = 'MIT'
15
15
 
@@ -3,18 +3,24 @@ require_relative 'tattler'
3
3
 
4
4
  module Buschtelefon
5
5
  class NetTattler < Tattler
6
- def initialize(port: 9999, &interceptor)
6
+ attr_accessor :port
7
+
8
+ def initialize(port: nil)
7
9
  super()
8
- @port = port
10
+ @port = port || rand(1025..65365) # TODO: use port 0
9
11
  end
10
12
 
11
- def listen(&_block)
13
+ def listen(&_callback)
12
14
  puts "Started UDP server on #{@port}..."
13
15
 
14
16
  Socket.udp_server_loop(@port) do |message, message_source|
15
- yield(message)
16
- handle_incoming_message(message)
17
17
  puts "Got \"#{message}\" from #{message_source}"
18
+ if message == "\x05"
19
+ handle_knowledge_inquiry(message_source)
20
+ else
21
+ handle_incoming_message(message)
22
+ yield(message) if block_given?
23
+ end
18
24
  end
19
25
  end
20
26
 
@@ -23,6 +29,10 @@ module Buschtelefon
23
29
  def handle_incoming_message(message)
24
30
  feed(Gossip.new(message))
25
31
  end
32
+
33
+ def handle_knowledge_inquiry(message_source)
34
+ transfer_knowledge(RemoteTattler.new(message_source.local_address))
35
+ end
26
36
  end
27
37
  end
28
38
 
@@ -7,9 +7,12 @@ module Buschtelefon
7
7
  @brain = Brain.new
8
8
  end
9
9
 
10
+ def knowledge
11
+ @brain.to_a
12
+ end
13
+
10
14
  def connect(tattler)
11
- @connections << tattler
12
- @connections.uniq!
15
+ @connections << tattler unless @connections.include?(tattler)
13
16
  end
14
17
 
15
18
  def feed(gossip)
@@ -19,5 +22,10 @@ module Buschtelefon
19
22
 
20
23
  @connections.each { |tattler| tattler.feed(gossip) }
21
24
  end
25
+
26
+ def transfer_knowledge(tattler)
27
+ connect(tattler)
28
+ knowledge.each { |gossip| tattler.feed(gossip) }
29
+ end
22
30
  end
23
31
  end
@@ -1,3 +1,3 @@
1
1
  module Buschtelefon
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: buschtelefon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josua Schmid
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-12-09 00:00:00.000000000 Z
11
+ date: 2019-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,8 +94,8 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0.16'
97
- description: Buschtelefon can be used to share information in a between Ruby clients
98
- over a network
97
+ description: Buschtelefon can be used to share information between Ruby clients over
98
+ a network
99
99
  email:
100
100
  - josua.schmid@renuo.ch
101
101
  executables: []