Class: Phut::VhostDaemon

Inherits:
Object
  • Object
show all
Defined in:
lib/phut/vhost_daemon.rb

Overview

vhost daemon process rubocop:disable ClassLength

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ VhostDaemon

Returns a new instance of VhostDaemon.



18
19
20
21
22
# File 'lib/phut/vhost_daemon.rb', line 18

def initialize(options)
  @options = options
  @packets_sent = []
  @packets_received = []
end

Class Method Details

.process(name, socket_dir) ⇒ Object



14
15
16
# File 'lib/phut/vhost_daemon.rb', line 14

def self.process(name, socket_dir)
  DRbObject.new_with_uri(unix_domain_socket(name, socket_dir))
end

.unix_domain_socket(name, socket_dir) ⇒ Object



10
11
12
# File 'lib/phut/vhost_daemon.rb', line 10

def self.unix_domain_socket(name, socket_dir)
  "drbunix:#{socket_dir}/vhost.#{name}.ctl"
end

Instance Method Details

#runObject



24
25
26
27
28
29
30
# File 'lib/phut/vhost_daemon.rb', line 24

def run
  start_logging
  create_pid_file
  start_daemon
rescue
  shutdown
end

#send_packets(dest, npackets) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/phut/vhost_daemon.rb', line 36

def send_packets(dest, npackets)
  return unless lookup_arp_table(dest.ip_address)
  udp = create_udp_packet(dest)
  npackets.times do
    write_to_raw_socket udp
    @logger.info "Sent to #{dest.name}: #{udp}"
  end
end

#statsObject



45
46
47
# File 'lib/phut/vhost_daemon.rb', line 45

def stats
  { tx: @packets_sent, rx: @packets_received }
end

#stopObject



32
33
34
# File 'lib/phut/vhost_daemon.rb', line 32

def stop
  @stop = true
end