class I2PLookuper::SAMLookuper
Attributes
status[R]
version[R]
Public Class Methods
new(host = "127.0.0.1", port = 7656, samhelper = SAMHelper)
click to toggle source
# File lib/i2plookuper.rb, line 100 def initialize host = "127.0.0.1", port = 7656, samhelper = SAMHelper @samhelper = SAMHelper @sock = TCPSocket.new host, port @status = :connected @sock.puts @samhelper.samcmd "HELLO", "VERSION", { "MIN" => "1.0" } res = @samhelper.parsesamcmd @sock.gets.chomp @status = "connectedand#{res[2]["RESULT"].downcase}".to_sym @version = res[2]["VERSION"] at_exit { self.close } end
Public Instance Methods
close()
click to toggle source
# File lib/i2plookuper.rb, line 115 def close if @status != :disconnected @sock.puts @samhelper.samcmd "QUIT" @sock.close @status = :disconnected end end
lookup(name)
click to toggle source
# File lib/i2plookuper.rb, line 123 def lookup name oldstatus = @status @status = :lookup @sock.puts @samhelper.samcmd "NAMING", "LOOKUP", { "NAME" => name } res = @samhelper.parsesamcmd @sock.gets @status = oldstatus return res[2]["RESULT"].downcase.to_sym, res[2].has_key?("VALUE") ? res[2]["VALUE"] : res[2]["RESULT"].tr("_", " ") end