Class: P2p2::P2
- Inherits:
-
Object
- Object
- P2p2::P2
- Defined in:
- lib/p2p2/p2.rb
Instance Method Summary collapse
-
#initialize(config_path = nil) ⇒ P2
constructor
A new instance of P2.
Constructor Details
#initialize(config_path = nil) ⇒ P2
Returns a new instance of P2.
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/p2.rb', line 14 def initialize( config_path = nil ) unless config_path then config_path = File.( '../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 ] shadow_host = conf[ :shadow_host ] shadow_port = conf[ :shadow_port ] raise 'missing paird host' unless paird_host raise 'missing room' unless room unless paird_port then paird_port = 4040 end unless shadow_host then shadow_host = '0.0.0.0' end unless shadow_port then shadow_port = 4444 end puts "p2p2 p2 #{ P2p2::VERSION }" puts "paird #{ paird_host } #{ paird_port } room #{ room } shadow #{ shadow_host } #{ shadow_port }" worker = P2p2::P2Worker.new( paird_host, paird_port, room, shadow_host, shadow_port ) Signal.trap( :TERM ) do puts 'exit' worker.quit! end worker.looping end |