Class: BetterCap::Proxy::UDP::Server

Inherits:
EM::Connection
  • Object
show all
Defined in:
lib/bettercap/proxy/udp/pool.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(address, relay_ip, relay_port) ⇒ Server

Returns a new instance of Server.



42
43
44
45
# File 'lib/bettercap/proxy/udp/pool.rb', line 42

def initialize(address, relay_ip, relay_port)
  @relay_ip, @relay_port = relay_ip, relay_port
  @pool = Pool.new(self, address)
end

Instance Attribute Details

#relay_ipObject

Returns the value of attribute relay_ip.



40
41
42
# File 'lib/bettercap/proxy/udp/pool.rb', line 40

def relay_ip
  @relay_ip
end

#relay_portObject

Returns the value of attribute relay_port.



40
41
42
# File 'lib/bettercap/proxy/udp/pool.rb', line 40

def relay_port
  @relay_port
end

Instance Method Details

#receive_data(data) ⇒ Object

ip -> upstream



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/bettercap/proxy/udp/pool.rb', line 48

def receive_data(data)
  port, ip = Socket.unpack_sockaddr_in(get_peername)
  client = @pool.client(ip, port)
  event = Event.new( ip, port, data )

  Logger.info "[#{'UDP PROXY'.green}] #{ip} #{'->'.green} #{'upstream'.yellow}:#{@relay_port} ( #{event.data.bytesize} bytes )"

  Module.dispatch( 'on_data', event )

  client.send_datagram( event.data, @relay_ip, @relay_port )
end