cuboid 0.2.2 → 0.2.4

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: 62a4b753db00386ea4858bd2ed61f9ccff0e89cd1aa7fb6c8d7e561e8cda87c3
4
+ data.tar.gz: 127005ff2cd7f621f80006f5b75d962ec6b32fb9cfa94f0e4ff86a63e63c7351
5
5
  SHA512:
6
- metadata.gz: 4de63384fca1ec59a9e6a14ef7f8cacedc7bb3ea8674050fae925a6051ebf2c9e54888f015a9844c602cfaf043fe04d457ed8663e112477620cd625cf615ad29
7
- data.tar.gz: 3908975b45d9e601918fd9cd852c8cebcdf007c34a5a350d9ab709a86d0a41b8a544163a92b828c718bf4c01045e7ffdfd704eaaacc0ebda1d00ea7edd245632
6
+ metadata.gz: 1e70d2d49b40ab668091b8d70edb50ccdce6b2ce2b19be8b85a38293e88bb3537355c89cd671e2c12ca5a8bce9b143557771c24e7e509dfc43e8319f51ea0ece
7
+ data.tar.gz: 72df9cb0de101c88229fc96f526fd50499b109611048c603bc1c61aaeadb5d6d60d601665749d9eb37ee91a83b3dd33acc15449c7c16e689a662de92a7eba99a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ # 0.2.4
2
+
3
+ * Made `Server::Instance` services accessible from `Application`.
4
+
5
+ # 0.2.3
6
+
7
+ * Simplified convergence of P2P mesh network.
8
+
1
9
  # 0.2.2
2
10
 
3
11
  * `Processes::Manager`
data/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # License
2
2
 
3
- Copyright (c) 2021 Tasos Laskos \<tasos.laskos@gmail.com\>.
3
+ Copyright (c) 2023 Ecsypno Single Member P.C. <http://ecsypno.com>.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -260,6 +260,10 @@ sleep 0.1 while sleepers.map(&:busy?).include?( true )
260
260
 
261
261
  _You can replace `host1` with `localhost` and run all examples on the same machine._
262
262
 
263
+ ## Users
264
+
265
+ * [QMap](https://github.com/qadron/qmap) -- A distributed network mapper/security scanner.
266
+
263
267
  ## License
264
268
 
265
269
  Please see the _LICENSE.md_ file.
@@ -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
@@ -332,7 +332,12 @@ class Instance
332
332
  server.add_handler( 'options', @active_options )
333
333
 
334
334
  Cuboid::Application.application.instance_services.each do |name, service|
335
- server.add_handler( name.to_s, service.new )
335
+ si = service.new
336
+
337
+ Cuboid::Application.application.send :attr_reader, name
338
+ @application.application.instance_variable_set( "@#{name}".to_sym, si )
339
+
340
+ server.add_handler( name.to_s, si )
336
341
  end
337
342
  end
338
343
 
data/lib/version CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.2.4
@@ -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.4
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-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print