Class: P2p2::P1

Inherits:
Object
  • Object
show all
Defined in:
lib/p2p2/p1.rb

Instance Method Summary collapse

Constructor Details

#initialize(config_path = nil) ⇒ P1

Returns a new instance of P1.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/p2p2/p1.rb', line 14

def initialize( config_path = nil )
  unless config_path then
    config_path = File.expand_path( '../p2p2.conf.json', __FILE__ )
  end

  raise "missing config file #{ config_path }" unless File.exist?( config_path )

  conf = JSON.parse( IO.binread( config_path ), symbolize_names: true )
  paird_host = conf[ :paird_host ]
  paird_port = conf[ :paird_port ]
  room = conf[ :room ]
  appd_host = conf[ :appd_host ]
  appd_port = conf[ :appd_port ]

  raise 'missing paird host' unless paird_host
  raise 'missing room' unless room

  unless paird_port then
    paird_port = 4040
  end

  unless appd_host then
    appd_host = '127.0.0.1'
  end

  unless appd_port then
    appd_port = 22
  end

  puts "p2p2 p1 #{ P2p2::VERSION }"
  puts "paird #{ paird_host } #{ paird_port } room #{ room } appd #{ appd_host } #{ appd_port }"

  worker = P2p2::P1Worker.new( paird_host, paird_port, room, appd_host, appd_port )

  Signal.trap( :TERM ) do
    puts 'exit'
    worker.quit!
  end

  worker.looping
end