class Jabber::Bytestreams::SOCKS5BytestreamsTarget

SOCKS5 Bytestreams implementation of the target site

Public Class Methods

new(stream, session_id, initiator_jid, target_jid) click to toggle source

See SOCKS5Bytestreams#initialize

# File lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb, line 12
def initialize(stream, session_id, initiator_jid, target_jid)
  @connect_timeout = 60
  @accept_ready = Semaphore::new
  super
end

Public Instance Methods

accept() click to toggle source

Wait until the stream has been established

May raise various exceptions

# File lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb, line 26
def accept
  error = nil
  connect_sem = Semaphore.new

  @stream.add_iq_callback(200, self) { |iq|
    if iq.type == :set and iq.from == @initiator_jid and iq.to == @target_jid and iq.query.kind_of?(IqQueryBytestreams)
      begin
        @stream.delete_iq_callback(self)

        iq.query.each_element('streamhost') { |streamhost|
          if streamhost.host and streamhost.port and not @socks
            begin
              @socks = connect_socks(streamhost)
              @streamhost_used = streamhost
            rescue Exception => e
              Jabber::debuglog("SOCKS5 Bytestreams: #{e.class}: #{e}\n#{e.backtrace.join("\n")}")
              @streamhost_cbs.process(streamhost, :failure, e)
            end
          end
        }

        reply = iq.answer(false)
        if @streamhost_used
          reply.type = :result
          reply.add(IqQueryBytestreams.new)
          reply.query.add(StreamHostUsed.new(@streamhost_used.jid))
        else
          reply.type = :error
          reply.add(ErrorResponse.new('item-not-found'))
        end
        @stream.send(reply)
      rescue Exception => e
        error = e
      end

      connect_sem.run
      true
    else
      false
    end
  }
  @accept_ready.run
  begin
    Timeout::timeout(@connect_timeout) { connect_sem.wait }
  rescue Timeout::Error
    @stream.delete_iq_callback(self)
  end

  raise error if error
  (@socks != nil)
end
accept_wait() click to toggle source
# File lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb, line 18
def accept_wait
  @accept_ready.wait
end