rgossip2 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -1,4 +1,4 @@
1
- = rgossip
1
+ = rgossip2
2
2
 
3
3
  == Description
4
4
 
@@ -1,4 +1,6 @@
1
1
  require 'socket'
2
+ require 'timeout'
3
+ require 'rping'
2
4
 
3
5
  module RGossip2
4
6
 
@@ -48,15 +50,21 @@ module RGossip2
48
50
  @node_list[@address] = @self_node
49
51
 
50
52
  # 初期ノードを追加
53
+ initial_nodes_threads = []
54
+
51
55
  initial_nodes.uniq.each do |i|
52
- addr = name2addr(i)
53
- # 自ノードはスキップ
54
- next if addr == @address
55
- # つながらない場合はスキップ
56
- next unless connectable?(addr, @context.port)
57
- @node_list[addr] = create(Node, @node_list, @dead_list, addr, nil, nil)
56
+ initial_nodes_threads << Thread.start(i) do |addr|
57
+ addr = name2addr(i)
58
+ # 自ノードはスキップ
59
+ next if addr == @address
60
+ # つながらない場合はスキップ
61
+ next unless connectable?(addr, @context.port)
62
+ @node_list[addr] = create(Node, @node_list, @dead_list, addr, nil, nil)
63
+ end
58
64
  end
59
65
 
66
+ initial_nodes_threads.each {|i| i.join }
67
+
60
68
  # Gossiper、Receiverを生成
61
69
  @gossiper = create(Gossiper, @self_node, @node_list)
62
70
  @receiver = create(Receiver, @self_node, @node_list, @dead_list)
@@ -204,12 +212,32 @@ module RGossip2
204
212
  end
205
213
 
206
214
  def connectable?(host, port)
215
+ # フラグが立っている場合はpingもチェック
216
+ if @context.ping_init_nodes
217
+ ping_results = RPing.ping(host,
218
+ :count => @context.ping_count, :interval => @context.ping_interval, :timeout => @context.ping_timeout)
219
+ raise 'ping failed' if ping_results.all? {|i| i.nil? }
220
+ end
221
+
207
222
  s = UDPSocket.new
208
223
  s.connect(host, port)
209
- s.close
224
+ s.send('', 0)
225
+
226
+ begin
227
+ timeout(@context.udp_timeout) do
228
+ s.recv(@context.buffer_size)
229
+ end
230
+ rescue Timeout::Error
231
+ ensure
232
+ s.close
233
+ end
234
+
235
+ debug("#{host}(#{port}) is connectable")
236
+
210
237
  return true
211
- rescue => e
212
- debug("#{host}:#{port}: #{e.message}")
238
+ rescue Exception => e
239
+ debug("#{host}(#{port}) is not connectable: #{e.message}")
240
+
213
241
  return false
214
242
  end
215
243
 
@@ -34,6 +34,15 @@ module RGossip2
34
34
  # 受信タイムアウト
35
35
  attr_accessor :receive_timeout
36
36
 
37
+ # 初期ノードのUDPスキャンのタイムアウト
38
+ attr_accessor :udp_timeout
39
+
40
+ # 初期ノードのpingチェックの有無
41
+ attr_accessor :ping_init_nodes
42
+ attr_accessor :ping_count
43
+ attr_accessor :ping_interval
44
+ attr_accessor :ping_timeout
45
+
37
46
  # ロガー
38
47
  attr_accessor :logger
39
48
 
@@ -59,6 +68,11 @@ module RGossip2
59
68
  :digest_algorithm => OpenSSL::Digest::SHA256,
60
69
  :digest_length => 32, # 256 / 8
61
70
  :logger => default_logger,
71
+ :udp_timeout => 0.3,
72
+ :ping_init_nodes => true,
73
+ :ping_count => 3,
74
+ :ping_interval => 0.1,
75
+ :ping_timeout => 0.1,
62
76
  :callback_handler => nil,
63
77
  }
64
78
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rgossip2
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 1
10
- version: 0.2.1
9
+ - 2
10
+ version: 0.2.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - winebarrel
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-01-19 00:00:00 +09:00
19
- default_executable:
18
+ date: 2012-01-22 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: msgpack
@@ -32,6 +31,22 @@ dependencies:
32
31
  version: "0"
33
32
  type: :runtime
34
33
  version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: rping
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 19
43
+ segments:
44
+ - 0
45
+ - 1
46
+ - 4
47
+ version: 0.1.4
48
+ type: :runtime
49
+ version_requirements: *id002
35
50
  description:
36
51
  email: sgwr_dts@yahoo.co.jp
37
52
  executables:
@@ -43,16 +58,15 @@ extra_rdoc_files: []
43
58
  files:
44
59
  - README
45
60
  - bin/gossip
61
+ - lib/rgossip2.rb
62
+ - lib/rgossip2/timer.rb
63
+ - lib/rgossip2/gossipper.rb
46
64
  - lib/rgossip2/client.rb
65
+ - lib/rgossip2/receiver.rb
47
66
  - lib/rgossip2/context.rb
48
- - lib/rgossip2/context_helper.rb
49
- - lib/rgossip2/gossipper.rb
50
67
  - lib/rgossip2/node.rb
68
+ - lib/rgossip2/context_helper.rb
51
69
  - lib/rgossip2/node_list.rb
52
- - lib/rgossip2/receiver.rb
53
- - lib/rgossip2/timer.rb
54
- - lib/rgossip2.rb
55
- has_rdoc: true
56
70
  homepage: https://bitbucket.org/winebarrel/rgossip2
57
71
  licenses: []
58
72
 
@@ -82,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
96
  requirements: []
83
97
 
84
98
  rubyforge_project:
85
- rubygems_version: 1.5.3
99
+ rubygems_version: 1.8.1
86
100
  signing_key:
87
101
  specification_version: 3
88
102
  summary: Basic implementation of a gossip protocol. This is a porting of Java implementation. see http://code.google.com/p/gossip-protocol-java/