Class: Jabber::Bytestreams::SOCKS5BytestreamsTarget

Inherits:
SOCKS5Bytestreams show all
Defined in:
lib/gems/xmpp4r-0.4/lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb

Overview

SOCKS5 Bytestreams implementation of the target site

Instance Attribute Summary

Attributes inherited from SOCKS5Bytestreams

#connect_timeout, #streamhost_used

Instance Method Summary collapse

Methods inherited from SOCKS5Bytestreams

#add_streamhost_callback, #close, #flush, query_streamhost, #read, #write

Constructor Details

#initialize(stream, session_id, initiator_jid, target_jid) ⇒ SOCKS5BytestreamsTarget

See SOCKS5Bytestreams#initialize



12
13
14
15
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb', line 12

def initialize(stream, session_id, initiator_jid, target_jid)
  @connect_timeout = 60
  super
end

Instance Method Details

#acceptObject

Wait until the stream has been established

May raise various exceptions



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb', line 20

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
  }

  begin
    Timeout::timeout(@connect_timeout) { connect_sem.wait }
  rescue Timeout::Error
    @stream.delete_iq_callback(self)
  end

  raise error if error
  (@socks != nil)
end