buschtelefon 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/README.md +1 -1
- data/bin/run +12 -6
- data/lib/buschtelefon/brain.rb +4 -2
- data/lib/buschtelefon/net_tattler.rb +43 -9
- data/lib/buschtelefon/remote_tattler.rb +14 -4
- data/lib/buschtelefon/tattler.rb +4 -0
- data/lib/buschtelefon/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 647eca794f57af404842ca0e5807e7c9ef57bcd8
|
4
|
+
data.tar.gz: 05b6225fbcb926ad2e286dbe0904ea6b322af450
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ff6c5e1dc9e2aa907f7ec47eef2b2246dbf1ced27ddd7050693527dbb4121d0966092cccebeb22410626ecb0f617198d31a0346b94a910dc61ceb5f48492e58
|
7
|
+
data.tar.gz: 571f2b5304c578859118b149c73ed3b72a8710ab212d5a5ca318d7823364a1d2827db4e7b680129c12c346de70f4f028b2c773871821f336cf9b593aeb69e2d6
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.4.0
|
4
|
+
|
5
|
+
* `NetTattler` now sends inquired payload back to requester
|
6
|
+
* `NetTattler` now attaches source information to gossip processor
|
7
|
+
* `NetTattler` now listens on a system chosen port per default
|
8
|
+
* `NetTattler` now connects to remotes via `connect_remote` and sends packets
|
9
|
+
to them via its outbound port (so it can receive responses)
|
10
|
+
* We work with IPs now instead of host names
|
11
|
+
* Default `Brain` capacity is now infinite
|
12
|
+
* `Tattler` now can load messages directly into its brain
|
13
|
+
|
3
14
|
## 0.3.0
|
4
15
|
|
5
16
|
* `NetTattler` now yields a `Gossip` instead of a raw message string.
|
data/README.md
CHANGED
@@ -40,7 +40,7 @@ include Buschtelefon
|
|
40
40
|
|
41
41
|
aunt_may = NetTattler.new
|
42
42
|
aunt_ruth = NetTattler.new
|
43
|
-
remote_aunt_ruth = RemoteTattler.new(host: '
|
43
|
+
remote_aunt_ruth = RemoteTattler.new(host: '127.0.0.1', port: aunt_ruth.port)
|
44
44
|
|
45
45
|
aunt_may.connect(remote_aunt_ruth)
|
46
46
|
|
data/bin/run
CHANGED
@@ -36,13 +36,19 @@ tattlers[:E].connect(tattlers[:D])
|
|
36
36
|
puts 'Feeding locals'
|
37
37
|
tattlers[:A].feed(Gossip.new('Tezos'))
|
38
38
|
|
39
|
-
josua = NetTattler.new
|
40
39
|
simon = NetTattler.new
|
41
|
-
|
42
|
-
|
43
|
-
josua.connect(remote_simon)
|
40
|
+
josua = NetTattler.new
|
41
|
+
remote_simon = josua.connect_remote(host: '127.0.0.1', port: simon.port)
|
44
42
|
|
45
|
-
|
46
|
-
Thread.new {
|
43
|
+
threads = [
|
44
|
+
Thread.new { josua.listen { |gossip, source| puts "I'm Josua, I got \"#{gossip.message}\" from #{source}" } },
|
45
|
+
Thread.new { simon.listen { |gossip, source| puts "I'm Simon, I got \"#{gossip.message}\" from #{source}" } }
|
46
|
+
]
|
47
47
|
|
48
|
+
sleep(0.1)
|
48
49
|
remote_simon.feed(Gossip.new('Antshare'))
|
50
|
+
sleep(0.1)
|
51
|
+
remote_simon.inquire
|
52
|
+
sleep(0.1)
|
53
|
+
|
54
|
+
threads.each(&:exit)
|
data/lib/buschtelefon/brain.rb
CHANGED
@@ -2,7 +2,7 @@ module Buschtelefon
|
|
2
2
|
class Brain
|
3
3
|
attr_reader :capacity
|
4
4
|
|
5
|
-
def initialize(capacity =
|
5
|
+
def initialize(capacity = nil)
|
6
6
|
@capacity = capacity
|
7
7
|
@gossip_sink = []
|
8
8
|
end
|
@@ -25,7 +25,9 @@ module Buschtelefon
|
|
25
25
|
def reorganize
|
26
26
|
@gossip_sink.sort! { |x, y| y.created_at <=> x.created_at }
|
27
27
|
@gossip_sink.uniq!(&:message)
|
28
|
-
@
|
28
|
+
if @capacity
|
29
|
+
@gossip_sink.slice!(capacity..-1) # only keep the newest
|
30
|
+
end
|
29
31
|
end
|
30
32
|
end
|
31
33
|
end
|
@@ -3,36 +3,70 @@ require_relative 'tattler'
|
|
3
3
|
|
4
4
|
module Buschtelefon
|
5
5
|
class NetTattler < Tattler
|
6
|
-
attr_accessor :port
|
6
|
+
attr_accessor :port, :socket
|
7
7
|
|
8
|
-
def initialize(port:
|
8
|
+
def initialize(port: 0)
|
9
9
|
super()
|
10
|
-
@
|
10
|
+
@socket = UDPSocket.new
|
11
|
+
@socket.bind('127.0.0.1', port)
|
12
|
+
@port = @socket.local_address.ip_port
|
11
13
|
end
|
12
14
|
|
13
15
|
def listen(&_callback)
|
14
16
|
puts "Started UDP server on #{@port}..."
|
15
17
|
|
16
|
-
Socket.
|
17
|
-
|
18
|
+
Socket.udp_server_loop_on([@socket]) do |message, message_source|
|
19
|
+
remote_tattler = find_or_build_remote_tattler(
|
20
|
+
host: message_source.remote_address.ip_address,
|
21
|
+
port: message_source.remote_address.ip_port
|
22
|
+
)
|
23
|
+
|
18
24
|
if message == "\x05"
|
19
|
-
|
25
|
+
#puts "#{@port} got inquiry from #{remote_tattler}. Is connected to #{@connections.inspect}"
|
26
|
+
handle_knowledge_inquiry(remote_tattler)
|
20
27
|
else
|
21
28
|
gossip = Gossip.new(message)
|
22
29
|
handle_incoming_gossip(gossip)
|
23
|
-
yield(gossip) if block_given?
|
30
|
+
yield(gossip, remote_tattler) if block_given?
|
24
31
|
end
|
25
32
|
end
|
26
33
|
end
|
27
34
|
|
35
|
+
def connect_remote(host:, port:)
|
36
|
+
find_or_build_remote_tattler(host: host, port: port).tap do |remote_tattler|
|
37
|
+
connect(remote_tattler)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def inquire_remote_neighbors
|
42
|
+
remote_connections.each { |remote_tattler| remote_tattler.inquire }
|
43
|
+
end
|
44
|
+
|
45
|
+
def remote_connections
|
46
|
+
@connections.select { |tattler| tattler.is_a?(RemoteTattler) }
|
47
|
+
end
|
48
|
+
|
49
|
+
def to_s
|
50
|
+
"127.0.0.1:#{@port}"
|
51
|
+
end
|
52
|
+
|
28
53
|
private
|
29
54
|
|
30
55
|
def handle_incoming_gossip(gossip)
|
31
56
|
feed(gossip)
|
32
57
|
end
|
33
58
|
|
34
|
-
|
35
|
-
|
59
|
+
# We just give out everything to the outbound port of the inquiry source
|
60
|
+
def handle_knowledge_inquiry(remote_tattler)
|
61
|
+
transfer_knowledge(remote_tattler)
|
62
|
+
end
|
63
|
+
|
64
|
+
def find_or_build_remote_tattler(host:, port:)
|
65
|
+
remote_connections.find { |t| t.host == host && t.port == port } || build_remote_tattler(host: host, port: port)
|
66
|
+
end
|
67
|
+
|
68
|
+
def build_remote_tattler(host:, port:)
|
69
|
+
RemoteTattler.new(host: host, port: port, outbound_socket: @socket)
|
36
70
|
end
|
37
71
|
end
|
38
72
|
end
|
@@ -1,17 +1,27 @@
|
|
1
1
|
require 'socket'
|
2
2
|
|
3
3
|
module Buschtelefon
|
4
|
-
# No need to
|
4
|
+
# No need to inheritance from Tattler because not all its features are available here (only #feed)
|
5
5
|
class RemoteTattler
|
6
|
-
|
6
|
+
attr_reader :host, :port
|
7
|
+
|
8
|
+
def initialize(host:, port:, outbound_socket: UDPSocket.new)
|
7
9
|
@host = host
|
8
10
|
@port = port
|
9
|
-
@outbound_socket =
|
11
|
+
@outbound_socket = outbound_socket
|
10
12
|
end
|
11
13
|
|
12
14
|
def feed(gossip)
|
15
|
+
#puts "#{@outbound_socket.local_address.ip_port} sending #{JSON.parse(gossip.message)['number']} to #{@port}"
|
13
16
|
@outbound_socket.send(gossip.message, 0, @host, @port)
|
14
|
-
|
17
|
+
end
|
18
|
+
|
19
|
+
def inquire
|
20
|
+
@outbound_socket.send("\x05", 0, @host, @port)
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_s
|
24
|
+
"#{@host}:#{@port}"
|
15
25
|
end
|
16
26
|
end
|
17
27
|
end
|
data/lib/buschtelefon/tattler.rb
CHANGED
data/lib/buschtelefon/version.rb
CHANGED
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.
|
4
|
+
version: 0.4.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: 2019-
|
11
|
+
date: 2019-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|