cuboid 0.2.2 → 0.2.3

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
  SHA256:
3
- metadata.gz: d6c97e639d098be63229081135c1932933631063155f23f675f3eb09c12ff321
4
- data.tar.gz: 11831be1794a18051dd5e3851615d8b5f1b65201265fd6d4d19366754940c87c
3
+ metadata.gz: ca74705ed31ac31d5e2dc69901fe2815df25e6fbcf30337d242ca2d1059624af
4
+ data.tar.gz: fc01ac528305655c7369cbe5af27fe5b2ffb8b03969c8f2b1d45df842d082c4d
5
5
  SHA512:
6
- metadata.gz: 4de63384fca1ec59a9e6a14ef7f8cacedc7bb3ea8674050fae925a6051ebf2c9e54888f015a9844c602cfaf043fe04d457ed8663e112477620cd625cf615ad29
7
- data.tar.gz: 3908975b45d9e601918fd9cd852c8cebcdf007c34a5a350d9ab709a86d0a41b8a544163a92b828c718bf4c01045e7ffdfd704eaaacc0ebda1d00ea7edd245632
6
+ metadata.gz: 618a9ac640b379063ea2710688c82345088043db0b0975467cd99ae363b3f376c08bb9d6116e0b77f2018510bda0a154e0ef53c1c2e795748cb692203da81d01
7
+ data.tar.gz: 92aab5e52a4477ceaf6ce48a4689bd86fa61f27a0c2a2243b0e4f6c1d812fb736bdeeb9d82cebf89ae058e92478301d2586f7a4ca355bf7f8268ebf8dc179110
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.2.3
2
+
3
+ * Simplified convergence of P2P mesh network.
4
+
1
5
  # 0.2.2
2
6
 
3
7
  * `Processes::Manager`
@@ -38,26 +38,24 @@ class Server::Agent::Node
38
38
 
39
39
  reroute_to_file( logfile ) if logfile
40
40
 
41
- print_status 'Initializing grid node...'
41
+ print_status 'Initializing node...'
42
42
 
43
43
  @dead_nodes = Set.new
44
- @peers = Set.new
44
+ @peers = Set.new
45
45
  @nodes_info_cache = []
46
46
 
47
47
  if (peer = @options.agent.peer)
48
48
  # Grab the peer's peers.
49
- connect_to_peer( peer ).peers do |urls|
50
- if urls.rpc_exception?
51
- add_dead_peer( peer )
52
- print_info "Neighbour seems dead: #{peer}"
49
+ connect_to_peer( peer ).peers do |peers|
50
+ if peers.rpc_exception?
51
+ print_info "Peer seems dead: #{peer}"
53
52
  add_dead_peer( peer )
54
53
  next
55
54
  end
56
55
 
57
- # Add peer and announce it to everyone.
58
- add_peer( peer, true )
59
-
60
- urls.each { |url| @peers << url if url != @url }
56
+ peers << peer
57
+ peers.each { |url| add_peer url }
58
+ announce @url
61
59
  end
62
60
  end
63
61
 
@@ -92,24 +90,11 @@ class Server::Agent::Node
92
90
  #
93
91
  # @param [String] node_url
94
92
  # URL of a peering node.
95
- # @param [Boolean] propagate
96
- # Whether or not to announce the new node to the peers.
97
- def add_peer( node_url, propagate = false )
98
- # we don't want ourselves in the Set
99
- return false if node_url == @url
100
- return false if @peers.include?( node_url )
101
-
93
+ def add_peer( node_url )
102
94
  print_status "Adding peer: #{node_url}"
103
95
 
104
96
  @peers << node_url
105
97
  log_updated_peers
106
- announce( node_url ) if propagate
107
-
108
- connect_to_peer( node_url ).add_peer( @url, propagate ) do |res|
109
- next if !res.rpc_exception?
110
- add_dead_peer( node_url )
111
- print_status "Neighbour seems dead: #{node_url}"
112
- end
113
98
  true
114
99
  end
115
100
 
@@ -120,7 +105,7 @@ class Server::Agent::Node
120
105
  end
121
106
 
122
107
  # @return [Array]
123
- # Neighbour/node/peer URLs.
108
+ # Peer/node/peer URLs.
124
109
  def peers
125
110
  @peers.to_a
126
111
  end
@@ -136,7 +121,7 @@ class Server::Agent::Node
136
121
  each = proc do |peer, iter|
137
122
  connect_to_peer( peer ).info do |info|
138
123
  if info.rpc_exception?
139
- print_info "Neighbour seems dead: #{peer}"
124
+ print_info "Peer seems dead: #{peer}"
140
125
  add_dead_peer( peer )
141
126
  log_updated_peers
142
127
 
@@ -165,8 +150,8 @@ class Server::Agent::Node
165
150
  # * `peers` -- Array of peers.
166
151
  def info
167
152
  {
168
- 'url' => @url,
169
- 'name' => @options.agent.name,
153
+ 'url' => @url,
154
+ 'name' => @options.agent.name,
170
155
  'peers' => @peers.to_a,
171
156
  'unreachable_peers' => @dead_nodes.to_a
172
157
  }
@@ -209,7 +194,7 @@ class Server::Agent::Node
209
194
  peer.alive? do |res|
210
195
  next if res.rpc_exception?
211
196
 
212
- print_status "Agent came back to life: #{url}"
197
+ print_status "Peer came back to life: #{url}"
213
198
  ([@url] | peers).each do |node|
214
199
  peer.add_peer( node ){}
215
200
  end
@@ -225,12 +210,10 @@ class Server::Agent::Node
225
210
  # @param [String] node
226
211
  # URL
227
212
  def announce( node )
228
- print_status "Advertising: #{node}"
213
+ print_status "Announcing: #{node}"
229
214
 
230
215
  peers.each do |peer|
231
- next if peer == node
232
-
233
- print_info '---- to: ' + peer
216
+ print_info "---- to: #{peer}"
234
217
  connect_to_peer( peer ).add_peer( node ) do |res|
235
218
  add_dead_peer( peer ) if res.rpc_exception?
236
219
  end
data/lib/version CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.2.3
@@ -24,7 +24,7 @@ describe Cuboid::RPC::Server::Agent::Node do
24
24
  end
25
25
 
26
26
  before( :each ) do
27
- options.paths.executables = "#{fixtures_path}executables/"
27
+ options.paths.executables = "#{fixtures_path}executables/"
28
28
  options.agent.ping_interval = 0.5
29
29
  end
30
30
  after( :each ) do
@@ -65,7 +65,6 @@ describe Cuboid::RPC::Server::Agent::Node do
65
65
 
66
66
  sleep 0.5
67
67
  expect(subject.peers).to eq([c.url])
68
- expect(c.peers).to eq([subject.url])
69
68
  end
70
69
  end
71
70
 
@@ -76,7 +75,6 @@ describe Cuboid::RPC::Server::Agent::Node do
76
75
  subject.add_peer( c.url )
77
76
  sleep 0.5
78
77
 
79
- expect(c.peers).to eq([subject.url])
80
78
  expect(subject.peers).to eq([c.url])
81
79
 
82
80
  subject.shutdown rescue break while sleep 0.1
@@ -117,7 +115,6 @@ describe Cuboid::RPC::Server::Agent::Node do
117
115
 
118
116
  subject.add_peer( c.url )
119
117
  sleep 0.5
120
- expect(c.peers).to eq([subject.url])
121
118
 
122
119
  c.unplug
123
120
 
@@ -136,35 +133,6 @@ describe Cuboid::RPC::Server::Agent::Node do
136
133
 
137
134
  it 'adds a peer' do
138
135
  expect(subject.peers).to eq([other.url])
139
- expect(other.peers).to eq([subject.url])
140
- end
141
-
142
- context 'when propagate is set to true' do
143
- it 'announces the new peer to the existing peers' do
144
- n = get_node
145
- subject.add_peer( n.url, true )
146
- sleep 0.5
147
-
148
- expect(subject.peers.sort).to eq([other.url, n.url].sort)
149
- expect(other.peers.sort).to eq([subject.url, n.url].sort)
150
-
151
- c = get_node
152
- n.add_peer( c.url, true )
153
- sleep 0.5
154
-
155
- expect(subject.peers.sort).to eq([other.url, n.url, c.url].sort)
156
- expect(other.peers.sort).to eq([subject.url, n.url, c.url].sort)
157
- expect(c.peers.sort).to eq([subject.url, n.url, other.url].sort)
158
-
159
- d = get_node
160
- d.add_peer( c.url, true )
161
- sleep 0.5
162
-
163
- expect(subject.peers.sort).to eq([d.url, other.url, n.url, c.url].sort)
164
- expect(other.peers.sort).to eq([d.url, subject.url, n.url, c.url].sort)
165
- expect(c.peers.sort).to eq([d.url, subject.url, n.url, other.url].sort)
166
- expect(d.peers.sort).to eq([c.url, subject.url, n.url, other.url].sort)
167
- end
168
136
  end
169
137
  end
170
138
 
@@ -226,13 +226,13 @@ describe Cuboid::RPC::Server::Agent do
226
226
  daemonize: true
227
227
  )
228
228
  d3.spawn( strategy: :direct )
229
- preferred = d3.url.split( ':' ).first
230
229
 
230
+ preferred = d3.url.split( ':' ).first
231
231
  expect(d3.spawn(strategy: :horizontal )['url'].split( ':' ).first).to eq(preferred)
232
232
  expect(%W{127.0.0.3 127.0.0.2}).to include d1.spawn['url'].split( ':' ).first
233
233
  expect(d2.spawn(strategy: :horizontal )['url'].split( ':' ).first).to eq(preferred)
234
+ expect(%W{127.0.0.1 127.0.0.2}).to include d3.spawn(strategy: :horizontal )['url'].split( ':' ).first
234
235
  expect(%W{127.0.0.1 127.0.0.3}).to include d3.spawn(strategy: :horizontal )['url'].split( ':' ).first
235
- expect(%W{127.0.0.2 127.0.0.3}).to include d3.spawn(strategy: :horizontal )['url'].split( ':' ).first
236
236
  expect(%W{127.0.0.2 127.0.0.3}).to include d1.spawn(strategy: :horizontal )['url'].split( ':' ).first
237
237
  end
238
238
  end
@@ -303,14 +303,14 @@ describe Cuboid::RPC::Server::Agent do
303
303
  daemonize: true
304
304
  )
305
305
  d3.spawn( strategy: :direct )
306
- preferred = d3.url.split( ':' ).first
307
306
 
308
- expect(d3.spawn['url'].split( ':' ).first).to eq(preferred)
307
+ preferred = d3.url.split( ':' ).first
308
+ expect(d3.spawn(strategy: :horizontal )['url'].split( ':' ).first).to eq(preferred)
309
309
  expect(%W{127.0.0.3 127.0.0.2}).to include d1.spawn['url'].split( ':' ).first
310
- expect(d2.spawn['url'].split( ':' ).first).to eq(preferred)
311
- expect(%W{127.0.0.1 127.0.0.3}).to include d3.spawn['url'].split( ':' ).first
312
- expect(%W{127.0.0.2 127.0.0.3}).to include d3.spawn['url'].split( ':' ).first
313
- expect(%W{127.0.0.2 127.0.0.3}).to include d1.spawn['url'].split( ':' ).first
310
+ expect(d2.spawn(strategy: :horizontal )['url'].split( ':' ).first).to eq(preferred)
311
+ expect(%W{127.0.0.1 127.0.0.2}).to include d3.spawn(strategy: :horizontal )['url'].split( ':' ).first
312
+ expect(%W{127.0.0.1 127.0.0.3}).to include d3.spawn(strategy: :horizontal )['url'].split( ':' ).first
313
+ expect(%W{127.0.0.2 127.0.0.3}).to include d1.spawn(strategy: :horizontal )['url'].split( ':' ).first
314
314
  end
315
315
  end
316
316
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cuboid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tasos Laskos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-19 00:00:00.000000000 Z
11
+ date: 2023-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print