Class: Jabber::Bytestreams::SOCKS5BytestreamsInitiator

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

new(stream, session_id, initiator_jid, target_jid)

[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_streamhost(streamhost)

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

open()

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.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:         }
    58:
    59:         @streamhost_used = nil
    60:         @streamhosts.each { |sh|
    61:           if peer_used.jid == sh.jid
    62:             @streamhost_used = sh
    63:             break
    64:           end
    65:         }
    66:         if @streamhost_used.jid == @initiator_jid
    67:           # This is our own JID, so the target chose SOCKS5BytestreamsServer
    68:           @socks = @streamhost_used.server.peer_sock(stream_address)
    69:           raise "Target didn't connect" unless @socks
    70:           @streamhost_cbs.process(@streamhost_used, :success, nil)
    71:         else
    72:           begin
    73:             @socks = connect_socks(@streamhost_used)
    74:           rescue Exception => e
    75:             Jabber::debuglog("SOCKS5 Bytestreams: #{e.class}: #{e}\n#{e.backtrace.join("\n")}")
    76:             @streamhost_cbs.process(@streamhost_used, :failure, e)
    77:             raise e
    78:           end
    79:           iq2 = Iq.new(:set, @streamhost_used.jid)
    80:           iq2.add(IqQueryBytestreams.new(@session_id)).activate = @target_jid.to_s
    81:           @stream.send_with_id(iq2)
    82:         end
    83:       end

[Validate]