class TellaPeer::Pong

Attributes

ip[W]
port[W]

Public Class Methods

new(header = nil, body = '') click to toggle source
Calls superclass method TellaPeer::Message::new
# File lib/tella_peer/pong.rb, line 5
def initialize(header = nil, body = '')
  super(header, body)

  unless body.empty?
    content   = body.unpack(payload_packer)
    self.port = content.first
    self.ip   = content[1..-1].map(&:to_i)
  end
  self.payload_length = 6
end

Public Instance Methods

ip() click to toggle source
# File lib/tella_peer/pong.rb, line 16
def ip
  @ip = @ip.map(&:to_i) if @ip && @ip.first.kind_of?(String)
  @ip ||= Message.ip.map(&:to_i)
end
key() click to toggle source
# File lib/tella_peer/pong.rb, line 25
def key
  "#{pretty_ip}:#{port}"
end
payload() click to toggle source
# File lib/tella_peer/pong.rb, line 33
def payload
  [port] + ip
end
payload_packer() click to toggle source
# File lib/tella_peer/pong.rb, line 37
def payload_packer
  'nCCCC'
end
port() click to toggle source
# File lib/tella_peer/pong.rb, line 29
def port
  @port ||= Message.port
end
pretty_ip() click to toggle source
# File lib/tella_peer/pong.rb, line 21
def pretty_ip
  ip.map(&:to_s).join('.')
end
type() click to toggle source
# File lib/tella_peer/pong.rb, line 41
def type
  MessageTypes::PONG
end