Class: RGossip2::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/rgossip2/context.rb

Overview

class Context ゴシッププロトコルのための各種変数格納クラス ほとんどのクラスから参照される

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Context

Returns a new instance of Context.



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/rgossip2/context.rb', line 56

def initialize(options = {})
  unless @auth_key = options[:auth_key]
    raise ':auth_key is required'
  end

  default_logger = Logger.new($stderr)
  default_logger.level = Logger::INFO

  defaults = {
    :port             => 10870,
    :buffer_size      => 512,
    :allowance        => 3,
    :node_lifetime    => 10,
    :gossip_interval  => 0.1,
    :receive_timeout  => 3,
    :digest_algorithm => OpenSSL::Digest::SHA256,
    :digest_length    => 32, # 256 / 8
    :logger           => default_logger,
    :udp_timeout      => 0.3,
    :ping_init_nodes  => false,
    :ping_count       => 3,
    :ping_interval    => 0.1,
    :ping_timeout     => 0.1,
    :callback_handler => nil,
  }

  defaults[:error_handler] = lambda do |e|
    message = (["#{e.class}: #{e.message}"] + (e.backtrace || [])).join("\n\tfrom ")

    if self.logger
      self.logger.error(message)
    else
      $stderr.puts(message)
    end
  end

  defaults.each do |k, v|
    self.instance_variable_set("@#{k}", options.fetch(k, v))
  end
end

Instance Attribute Details

#allowanceObject

Returns the value of attribute allowance.



22
23
24
# File 'lib/rgossip2/context.rb', line 22

def allowance
  @allowance
end

#auth_keyObject

HMACの秘密鍵



29
30
31
# File 'lib/rgossip2/context.rb', line 29

def auth_key
  @auth_key
end

#buffer_sizeObject

バッファサイズと遊び 「buffer_size * allowance + digest_length」が 65515bytes 以下になるようにする



21
22
23
# File 'lib/rgossip2/context.rb', line 21

def buffer_size
  @buffer_size
end

#callback_handlerObject

各種ハンドラ



53
54
55
# File 'lib/rgossip2/context.rb', line 53

def callback_handler
  @callback_handler
end

#digest_algorithmObject

ハッシュ関数のアルゴリズムと長さ



25
26
27
# File 'lib/rgossip2/context.rb', line 25

def digest_algorithm
  @digest_algorithm
end

#digest_lengthObject

Returns the value of attribute digest_length.



26
27
28
# File 'lib/rgossip2/context.rb', line 26

def digest_length
  @digest_length
end

#error_handlerObject

Returns the value of attribute error_handler.



54
55
56
# File 'lib/rgossip2/context.rb', line 54

def error_handler
  @error_handler
end

#gossip_intervalObject

送信インターバル



35
36
37
# File 'lib/rgossip2/context.rb', line 35

def gossip_interval
  @gossip_interval
end

#loggerObject

ロガー



50
51
52
# File 'lib/rgossip2/context.rb', line 50

def logger
  @logger
end

#node_lifetimeObject

Nodeの寿命



32
33
34
# File 'lib/rgossip2/context.rb', line 32

def node_lifetime
  @node_lifetime
end

#ping_countObject

Returns the value of attribute ping_count.



45
46
47
# File 'lib/rgossip2/context.rb', line 45

def ping_count
  @ping_count
end

#ping_init_nodesObject

初期ノードのpingチェックの有無



44
45
46
# File 'lib/rgossip2/context.rb', line 44

def ping_init_nodes
  @ping_init_nodes
end

#ping_intervalObject

Returns the value of attribute ping_interval.



46
47
48
# File 'lib/rgossip2/context.rb', line 46

def ping_interval
  @ping_interval
end

#ping_timeoutObject

Returns the value of attribute ping_timeout.



47
48
49
# File 'lib/rgossip2/context.rb', line 47

def ping_timeout
  @ping_timeout
end

#portObject

ポート番号



17
18
19
# File 'lib/rgossip2/context.rb', line 17

def port
  @port
end

#receive_timeoutObject

受信タイムアウト



38
39
40
# File 'lib/rgossip2/context.rb', line 38

def receive_timeout
  @receive_timeout
end

#udp_timeoutObject

初期ノードのUDPスキャンのタイムアウト



41
42
43
# File 'lib/rgossip2/context.rb', line 41

def udp_timeout
  @udp_timeout
end