Class Jabber::Bytestreams::SOCKS5BytestreamsServer
In: lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb
Parent: Object
XMLStanza Message Presence Iq REXML::Element X IqQuery Error StreamHost IqSiFileRange IqSiFile StreamHostUsed IqSi XRosterItem RosterItem IqFeature XMUCUserItem XMUCUserInvite XDataField XDataReported XDataTitle XDataInstructions Feature Identity Item IqVcard Singleton IdGenerator Connection Client Component Comparable JID RuntimeError AuthenticationFailure ErrorException SOCKS5Error Stream SOCKS5Bytestreams SOCKS5BytestreamsTarget SOCKS5BytestreamsInitiator SOCKS5BytestreamsServerStreamHost TCPSocket SOCKS5Socket IBB IBBTarget IBBInitiator IqQuery IqQueryBytestreams IqQueryVersion IqQueryRoster IqQueryDiscoItems IqQueryDiscoInfo Responder SimpleResponder X XRoster XMUCUser XMUC XDelay XData MUCClient SimpleMUCClient Base DigestMD5 Plain FileSource StreamParser SOCKS5BytestreamsPeer SOCKS5BytestreamsServer IBBQueueItem Helper MUCBrowser Helper Helper lib/xmpp4r/authenticationfailure.rb lib/xmpp4r/idgenerator.rb lib/xmpp4r/connection.rb lib/xmpp4r/iq.rb lib/xmpp4r/jid.rb lib/xmpp4r/xmlstanza.rb lib/xmpp4r/errorexception.rb lib/xmpp4r/stream.rb lib/xmpp4r/client.rb lib/xmpp4r/x.rb lib/xmpp4r/streamparser.rb lib/xmpp4r/error.rb lib/xmpp4r/component.rb lib/xmpp4r/query.rb lib/xmpp4r/message.rb lib/xmpp4r/presence.rb lib/xmpp4r/bytestreams/helper/ibb/initiator.rb lib/xmpp4r/bytestreams/iq/si.rb lib/xmpp4r/bytestreams/iq/bytestreams.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/base.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/initiator.rb lib/xmpp4r/bytestreams/helper/ibb/base.rb lib/xmpp4r/bytestreams/helper/ibb/target.rb Bytestreams lib/xmpp4r/version/iq/version.rb lib/xmpp4r/version/helper/responder.rb lib/xmpp4r/version/helper/simpleresponder.rb Version lib/xmpp4r/roster/helper/roster.rb lib/xmpp4r/roster/iq/roster.rb lib/xmpp4r/roster/x/roster.rb Roster lib/xmpp4r/feature_negotiation/iq/feature.rb FeatureNegotiation lib/xmpp4r/muc/x/muc.rb lib/xmpp4r/muc/helper/mucclient.rb lib/xmpp4r/muc/x/mucuseritem.rb lib/xmpp4r/muc/helper/mucbrowser.rb lib/xmpp4r/muc/x/mucuserinvite.rb lib/xmpp4r/muc/helper/simplemucclient.rb MUC lib/xmpp4r/sasl.rb SASL lib/xmpp4r/bytestreams/helper/filetransfer.rb TransferSource FileTransfer lib/xmpp4r/delay/x/delay.rb Delay lib/xmpp4r/dataforms/x/data.rb Dataforms lib/xmpp4r/discovery/iq/discoinfo.rb lib/xmpp4r/discovery/iq/discoitems.rb Discovery lib/xmpp4r/vcard/helper/vcard.rb lib/xmpp4r/vcard/iq/vcard.rb Vcard Jabber dot/m_60_0.png

The SOCKS5BytestreamsServer is an implementation of a SOCKS5 server.

You can use it if you‘re reachable by your SOCKS5Bytestreams peers, thus avoiding use of an external proxy.

Usage:

Methods

Public Class methods

Start a local SOCKS5BytestreamsServer

Will start to listen on the given TCP port and accept new peers

port:[Fixnum] TCP port to listen on

[Source]

    # File lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb, line 22
22:       def initialize(port)
23:         @port = port
24:         @addresses = []
25:         @peers = []
26:         @peers_lock = Mutex.new
27:         socket = TCPServer.new(port)
28: 
29:         Thread.new {
30:           loop {
31:             peer = SOCKS5BytestreamsPeer.new(socket.accept)
32:             Thread.new {
33:               begin
34:                 peer.start
35:               rescue
36:                 Jabber::debuglog("SOCKS5 BytestreamsServer: Error accepting peer: #{$!}")
37:               end
38:             }
39:             @peers_lock.synchronize {
40:               @peers << peer
41:             }
42:           }
43:         }
44:       end

Public Instance methods

Add an external IP address

This is a must-have, as SOCKS5BytestreamsInitiator must inform the target where to connect

[Source]

    # File lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb, line 88
88:       def add_address(address)
89:         @addresses << address
90:       end

Iterate through all configured addresses, yielding SOCKS5BytestreamsServerStreamHost instances, which should be passed to SOCKS5BytestreamsInitiator#add_streamhost

This will be automatically invoked if you pass an instance of SOCKS5BytestreamsServer to SOCKS5BytestreamsInitiator#add_streamhost

my_jid:[JID] My Jabber-ID

[Source]

     # File lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb, line 102
102:       def each_streamhost(my_jid, &block)
103:         @addresses.each { |address|
104:           yield SOCKS5BytestreamsServerStreamHost.new(self, my_jid, address, @port)
105:         }
106:       end

Find the socket a peer is associated to

addr:[String] Address like SOCKS5Bytestreams#stream_address
result:[TCPSocker] or [nil]

[Source]

    # File lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb, line 50
50:       def peer_sock(addr)
51:         res = nil
52:         @peers_lock.synchronize {
53:           removes = []
54: 
55:           @peers.each { |peer|
56:             if peer.socket and peer.socket.closed?
57:               # Queue peers with closed socket for removal
58:               removes << peer
59:             elsif peer.address == addr and res.nil?
60:               res = peer.socket
61:             else
62:               # If we sent multiple addresses of our own, clients may
63:               # connect multiple times. Close these connections here.
64:               removes << peer
65:             end
66:           }
67: 
68:           # If we sent multiple addresses of our own, clients may
69:           # connect multiple times. Close these connections here.
70:           @peers.delete_if { |peer|
71:             if removes.include? peer
72:               peer.socket.close rescue IOError
73:               true
74:             else
75:               false
76:             end
77:           }
78:         }
79: 
80:         res
81:       end

[Validate]