| Class | Jabber::Bytestreams::SOCKS5BytestreamsTarget |
| In: |
lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb
|
| Parent: | SOCKS5Bytestreams |
SOCKS5 Bytestreams implementation of the target site
See SOCKS5Bytestreams#initialize
# File lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb, line 12
12: def initialize(stream, session_id, initiator_jid, target_jid)
13: @connect_timeout = 60
14: @accept_ready = Semaphore::new
15: super
16: end
Wait until the stream has been established
May raise various exceptions
# File lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb, line 26
26: def accept
27: error = nil
28: connect_sem = Semaphore.new
29:
30: @stream.add_iq_callback(200, self) { |iq|
31: if iq.type == :set and iq.from == @initiator_jid and iq.to == @target_jid and iq.query.kind_of?(IqQueryBytestreams)
32: begin
33: @stream.delete_iq_callback(self)
34:
35: iq.query.each_element('streamhost') { |streamhost|
36: if streamhost.host and streamhost.port and not @socks
37: begin
38: @socks = connect_socks(streamhost)
39: @streamhost_used = streamhost
40: rescue Exception => e
41: Jabber::debuglog("SOCKS5 Bytestreams: #{e.class}: #{e}\n#{e.backtrace.join("\n")}")
42: @streamhost_cbs.process(streamhost, :failure, e)
43: end
44: end
45: }
46:
47: reply = iq.answer(false)
48: if @streamhost_used
49: reply.type = :result
50: reply.add(IqQueryBytestreams.new)
51: reply.query.add(StreamHostUsed.new(@streamhost_used.jid))
52: else
53: reply.type = :error
54: reply.add(ErrorResponse.new('item-not-found'))
55: end
56: @stream.send(reply)
57: rescue Exception => e
58: error = e
59: end
60:
61: connect_sem.run
62: true
63: else
64: false
65: end
66: }
67: @accept_ready.run
68: begin
69: Timeout::timeout(@connect_timeout) { connect_sem.wait }
70: rescue Timeout::Error
71: @stream.delete_iq_callback(self)
72: end
73:
74: raise error if error
75: (@socks != nil)
76: end