Class: Jabber::Bytestreams::SOCKS5Bytestreams
- Inherits:
-
Object
- Object
- Jabber::Bytestreams::SOCKS5Bytestreams
- Defined in:
- lib/xmpp4r/bytestreams/helper/socks5bytestreams/base.rb
Overview
SOCKS5 Bytestreams (JEP-0065) implementation
Don’t use directly, use SOCKS5BytestreamsInitiator and SOCKS5BytestreamsTarget
Direct Known Subclasses
Instance Attribute Summary collapse
-
#connect_timeout ⇒ Object
SOCKS connection timeout (for trying multiple streamhosts).
-
#streamhost_used ⇒ Object
readonly
- StreamHost
-
the SOCKS connection is using.
Class Method Summary collapse
-
.query_streamhost(stream, streamhost, my_jid = nil) ⇒ Object
Query a JID for its stream-host information.
Instance Method Summary collapse
-
#add_streamhost_callback(priority = 0, ref = nil, &block) ⇒ Object
Add a callback that will be called when there is action regarding SOCKS stream-hosts.
-
#close ⇒ Object
Close the stream-host connection.
-
#flush ⇒ Object
Flush the SOCKS5 socket.
-
#initialize(stream, session_id, initiator_jid, target_jid) ⇒ SOCKS5Bytestreams
constructor
A new instance of SOCKS5Bytestreams.
-
#read(length = nil) ⇒ Object
- Receive from the stream-host length
- Fixnum
- Amount of bytes (Will be passed to TCPSocket#read for the underlying SOCKS5 connection) result
- String
-
(or [nil] if finished).
-
#write(buf) ⇒ Object
- Send to the stream-host buf
- String
- Data result
- Fixnum
-
Amount of bytes sent.
Constructor Details
#initialize(stream, session_id, initiator_jid, target_jid) ⇒ SOCKS5Bytestreams
Returns a new instance of SOCKS5Bytestreams.
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/xmpp4r/bytestreams/helper/socks5bytestreams/base.rb', line 31 def initialize(stream, session_id, initiator_jid, target_jid) @stream = stream @session_id = session_id @initiator_jid = (initiator_jid.kind_of?(String) ? JID.new(initiator_jid) : initiator_jid) @target_jid = (target_jid.kind_of?(String) ? JID.new(target_jid) : target_jid) @socks = nil @connect_timeout = nil @streamhost_used = nil @streamhost_cbs = CallbackList.new end |
Instance Attribute Details
#connect_timeout ⇒ Object
SOCKS connection timeout (for trying multiple streamhosts)
default: nil, use the OS’ default timeout
29 30 31 |
# File 'lib/xmpp4r/bytestreams/helper/socks5bytestreams/base.rb', line 29 def connect_timeout @connect_timeout end |
#streamhost_used ⇒ Object (readonly)
- StreamHost
-
the SOCKS connection is using
23 24 25 |
# File 'lib/xmpp4r/bytestreams/helper/socks5bytestreams/base.rb', line 23 def streamhost_used @streamhost_used end |
Class Method Details
.query_streamhost(stream, streamhost, my_jid = nil) ⇒ Object
Query a JID for its stream-host information
SOCKS5BytestreamsInitiator#add_streamhost can do this for you. Use this method if you plan to do multiple transfers, so you can cache the result.
- stream
- Stream
-
to operate on
- streamhost
- JID
-
of the proxy
- my_jid
- JID
-
Optional sender JID for Component operation
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/xmpp4r/bytestreams/helper/socks5bytestreams/base.rb', line 96 def self.query_streamhost(stream, streamhost, my_jid=nil) res = nil iq = Iq.new(:get, streamhost) iq.from = my_jid iq.add(IqQueryBytestreams.new) stream.send_with_id(iq) { |reply| reply.query.each_element { |e| if e.kind_of?(StreamHost) e.jid = reply.from # Help misconfigured proxys res = e end } } if res and res.jid and res.host and res.port res else nil end end |
Instance Method Details
#add_streamhost_callback(priority = 0, ref = nil, &block) ⇒ Object
Add a callback that will be called when there is action regarding SOCKS stream-hosts
Usage of this callback is optional and serves informational purposes only.
block takes three arguments:
-
The StreamHost instance that is currently being tried
-
State information (is either :connecting, :authenticating, :success or :failure)
-
The exception value for the state :failure, else nil
52 53 54 |
# File 'lib/xmpp4r/bytestreams/helper/socks5bytestreams/base.rb', line 52 def add_streamhost_callback(priority = 0, ref = nil, &block) @streamhost_cbs.add(priority, ref, block) end |
#close ⇒ Object
Close the stream-host connection
83 84 85 |
# File 'lib/xmpp4r/bytestreams/helper/socks5bytestreams/base.rb', line 83 def close @socks.close end |
#flush ⇒ Object
Flush the SOCKS5 socket
66 67 68 |
# File 'lib/xmpp4r/bytestreams/helper/socks5bytestreams/base.rb', line 66 def flush @socks.flush end |
#read(length = nil) ⇒ Object
Receive from the stream-host
- length
- Fixnum
-
Amount of bytes (Will be passed to TCPSocket#read for the underlying SOCKS5 connection)
- result
- String
-
(or [nil] if finished)
60 61 62 |
# File 'lib/xmpp4r/bytestreams/helper/socks5bytestreams/base.rb', line 60 def read(length=nil) @socks.read(length) end |
#write(buf) ⇒ Object
Send to the stream-host
- buf
- String
-
Data
- result
- Fixnum
-
Amount of bytes sent
74 75 76 77 78 79 |
# File 'lib/xmpp4r/bytestreams/helper/socks5bytestreams/base.rb', line 74 def write(buf) @socks.write(buf) # FIXME: On FreeBSD this throws Errno::EPERM after it has already written a few # kilobytes, and when there are multiple sockets. ktrace told, that this originates # from the syscall, not ruby. end |