class TellaPeer::Reply
Attributes
ip[W]
logger[W]
port[W]
Public Class Methods
logger()
click to toggle source
# File lib/tella_peer/reply.rb, line 4 def logger @logger ||= Logger.new('reply.log', File::WRONLY | File::APPEND) end
new(header = nil, body = '')
click to toggle source
Calls superclass method
TellaPeer::Message::new
# File lib/tella_peer/reply.rb, line 10 def initialize(header = nil, body = '') super(header, body) unless body.empty? content = body.unpack(payload_unpacker) self.port = content[0] self.ip = content[1..4].map(&:to_i) self.text = content[5..-1].map(&:chr).join end end
Public Instance Methods
connection_key()
click to toggle source
# File lib/tella_peer/reply.rb, line 60 def connection_key "#{pretty_ip}:#{port}" end
ip()
click to toggle source
# File lib/tella_peer/reply.rb, line 21 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/reply.rb, line 34 def key "#{pretty_ip}:#{port}" end
log()
click to toggle source
# File lib/tella_peer/reply.rb, line 38 def log self.class.logger.unknown "#{pretty_ip}:#{port} #{text}" end
payload()
click to toggle source
# File lib/tella_peer/reply.rb, line 42 def payload [port] + ip + text.chars.map(&:ord) end
payload_packer()
click to toggle source
# File lib/tella_peer/reply.rb, line 50 def payload_packer 'n' + 'CCCC' + text.gsub(/./, 'C') end
payload_unpacker()
click to toggle source
# File lib/tella_peer/reply.rb, line 46 def payload_unpacker 'n' + 'CCCC' + 'C' * (payload_length - 6) end
port()
click to toggle source
# File lib/tella_peer/reply.rb, line 30 def port @port ||= Message.port end
pretty_ip()
click to toggle source
# File lib/tella_peer/reply.rb, line 26 def pretty_ip ip.join('.') end
text()
click to toggle source
# File lib/tella_peer/reply.rb, line 64 def text @text ? @text : self.text = TellaPeer::Message.text end
text=(value)
click to toggle source
# File lib/tella_peer/reply.rb, line 54 def text=(value) @text = value @payload_length = 6 + value.length value end
type()
click to toggle source
# File lib/tella_peer/reply.rb, line 68 def type MessageTypes::REPLY end