Class: DHT::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/dht/node.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Node

Returns a new instance of Node.



11
12
13
14
15
16
17
18
19
# File 'lib/dht/node.rb', line 11

def initialize(options = {})
  options = default_options.merge(options)

  @host = options.delete(:host)
  @port = options.delete(:port)
  @name = options.delete(:name)
  @node = options.delete(:node)
  @explorer = options.delete(:explorer)
end

Instance Method Details

#configurationObject



26
27
28
29
30
31
# File 'lib/dht/node.rb', line 26

def configuration
  configuration = {:id => @name, :addr => "tcp://#{@host}:#{@port}"}
  configuration.merge!(:directory => @node) if @node

  configuration
end

#keyObject



33
34
35
# File 'lib/dht/node.rb', line 33

def key
  @key ||= Key.for_content("#{@name}:#{@host}:#{@port}")
end

#startObject



21
22
23
24
# File 'lib/dht/node.rb', line 21

def start
  DCell.start(configuration)
  DHT::Service.new(:key => key, :explorer => @explorer).run
end