Class Jabber::Bytestreams::SOCKS5BytestreamsInitiator
In: lib/xmpp4r/bytestreams/helper/socks5bytestreams/initiator.rb
Parent: SOCKS5Bytestreams

SOCKS5Bytestreams implementation for the initiator side

Methods

add_streamhost   new   open  

Attributes

streamhosts  [R] 

Public Class methods

[Source]

    # File lib/xmpp4r/bytestreams/helper/socks5bytestreams/initiator.rb, line 12
12:       def initialize(stream, session_id, initiator_jid, target_jid)
13:         super
14:         @streamhosts = []
15:       end

Public Instance methods

Add a streamhost which will be offered to the target

streamhost:can be:
  • [StreamHost] if already got all information (host/port)
  • [SOCKS5BytestreamsServer] if this is the local streamhost
  • [String] or [JID] if information should be automatically resolved by SOCKS5Bytestreams::query_streamhost

[Source]

    # File lib/xmpp4r/bytestreams/helper/socks5bytestreams/initiator.rb, line 24
24:       def add_streamhost(streamhost)
25:         if streamhost.kind_of?(StreamHost)
26:           @streamhosts << streamhost
27:         elsif streamhost.kind_of?(SOCKS5BytestreamsServer)
28:           streamhost.each_streamhost(@initiator_jid) { |sh|
29:             @streamhosts << sh
30:           }
31:         elsif streamhost.kind_of?(String) or streamhost.kind_of?(JID)
32:           @streamhosts << SOCKS5Bytestreams::query_streamhost(@stream, streamhost, @initiator_jid)
33:         else
34:           raise "Unknwon streamhost type: #{streamhost.class}"
35:         end
36:       end

Send the configured streamhosts to the target, wait for an answer and connect to the host the target chose.

[Source]

    # File lib/xmpp4r/bytestreams/helper/socks5bytestreams/initiator.rb, line 42
42:       def open
43:         iq1 = Iq::new(:set, @target_jid)
44:         iq1.from = @initiator_jid
45:         bs = iq1.add IqQueryBytestreams.new(@session_id)
46:         @streamhosts.each { |se|
47:           bs.add(se)
48:         }
49: 
50:         peer_used = nil
51:         @stream.send_with_id(iq1) { |response|
52:           if response.type == :result and response.query.kind_of?(IqQueryBytestreams)
53:             peer_used = response.query.streamhost_used
54:             raise "No streamhost-used" unless peer_used
55:             raise "Invalid streamhost-used" unless peer_used.jid
56:           end
57:           true
58:         }
59: 
60:         @streamhost_used = nil
61:         @streamhosts.each { |sh|
62:           if peer_used.jid == sh.jid
63:             @streamhost_used = sh
64:             break
65:           end
66:         }
67:         if @streamhost_used.jid == @initiator_jid
68:           # This is our own JID, so the target chose SOCKS5BytestreamsServer
69:           @socks = @streamhost_used.server.peer_sock(stream_address)
70:           raise "Target didn't connect" unless @socks
71:           @streamhost_cbs.process(@streamhost_used, :success, nil)
72:         else
73:           begin
74:             @socks = connect_socks(@streamhost_used)
75:           rescue Exception => e
76:             Jabber::debuglog("SOCKS5 Bytestreams: #{e.class}: #{e}\n#{e.backtrace.join("\n")}")
77:             @streamhost_cbs.process(@streamhost_used, :failure, e)
78:             raise e
79:           end
80:           iq2 = Iq::new(:set, @streamhost_used.jid)
81:           iq2.add(IqQueryBytestreams.new(@session_id)).activate = @target_jid.to_s
82:           @stream.send_with_id(iq2) { |reply|
83:             reply.type == :result
84:           }
85:         end
86:       end

[Validate]