### Home Classes Methods

### In Files

- lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb

### Parent

Object

### Methods

- ::new
- #add_address
- #each_streamhost
- #peer_sock

### Files

- CHANGELOG
- COPYING
- LICENSE
- README.rdoc
- README_ruby19.txt

### Class/Module Index

Quicksearch

- Jabber
- Jabber::ArgumentError
- Jabber::Bytestreams
- Jabber::Bytestreams::IBB
- Jabber::Bytestreams::IBBInitiator
- Jabber::Bytestreams::IBBQueueItem
- Jabber::Bytestreams::IBBTarget
- Jabber::Bytestreams::IqQueryBytestreams
- Jabber::Bytestreams::IqSi
- Jabber::Bytestreams::IqSiFile
- Jabber::Bytestreams::IqSiFileRange
- Jabber::Bytestreams::SOCKS5Bytestreams
- Jabber::Bytestreams::SOCKS5BytestreamsInitiator
- Jabber::Bytestreams::SOCKS5BytestreamsPeer
- Jabber::Bytestreams::SOCKS5BytestreamsServer
- Jabber::Bytestreams::SOCKS5BytestreamsServerStreamHost
- Jabber::Bytestreams::SOCKS5BytestreamsTarget
- Jabber::Bytestreams::SOCKS5Socket
- Jabber::Bytestreams::StreamHost
- Jabber::Bytestreams::StreamHostUsed
- Jabber::Callback
- Jabber::CallbackList
- Jabber::Caps
- Jabber::Caps::C
- Jabber::Caps::Helper
- Jabber::Client
- Jabber::ClientAuthenticationFailure
- Jabber::Command
- Jabber::Command::IqCommand
- Jabber::Command::Responder
- Jabber::Component
- Jabber::ComponentAuthenticationFailure
- Jabber::Connection
- Jabber::Connection::SSLSocketUTF8
- Jabber::Dataforms
- Jabber::Dataforms::XData
- Jabber::Dataforms::XDataField
- Jabber::Dataforms::XDataInstructions
- Jabber::Dataforms::XDataReported
- Jabber::Dataforms::XDataTitle
- Jabber::Delay
- Jabber::Delay::XDelay
- Jabber::Discovery
- Jabber::Discovery::Feature
- Jabber::Discovery::Helper
- Jabber::Discovery::Identity
- Jabber::Discovery::IqQueryDiscoInfo
- Jabber::Discovery::IqQueryDiscoItems
- Jabber::Discovery::Item
- Jabber::Discovery::Responder
- Jabber::EntityTime
- Jabber::EntityTime::IqTime
- Jabber::EntityTime::Responder
- Jabber::ErrorResponse
- Jabber::FeatureNegotiation
- Jabber::FeatureNegotiation::IqFeature
- Jabber::FileTransfer
- Jabber::FileTransfer::FileSource
- Jabber::FileTransfer::Helper
- Jabber::FileTransfer::TransferSource
- Jabber::Framework
- Jabber::Framework::Base
- Jabber::Framework::Bot
- Jabber::HTTPBinding
- Jabber::HTTPBinding::Client
- Jabber::IdGenerator
- Jabber::InvalidChatState
- Jabber::Iq
- Jabber::IqQuery
- Jabber::JID
- Jabber::JabberError
- Jabber::LastActivity
- Jabber::LastActivity::Helper
- Jabber::LastActivity::IqQueryLastActivity
- Jabber::MUC
- Jabber::MUC::IqQueryMUCAdmin
- Jabber::MUC::IqQueryMUCAdminItem
- Jabber::MUC::IqQueryMUCOwner
- Jabber::MUC::MUCBrowser
- Jabber::MUC::MUCClient
- Jabber::MUC::SimpleMUCClient
- Jabber::MUC::UserItem
- Jabber::MUC::XMUC
- Jabber::MUC::XMUCUser
- Jabber::MUC::XMUCUserInvite
- Jabber::MUC::XMUCUserItem
- Jabber::Message
- Jabber::NoNameXmlnsRegistered
- Jabber::NotConnected
- Jabber::Observable
- Jabber::Observable::Contact
- Jabber::Observable::PubSub
- Jabber::Observable::PubSub::AlreadySet
- Jabber::Observable::PubSub::NoService
- Jabber::Observable::Subscriptions
- Jabber::Presence
- Jabber::PubSub
- Jabber::PubSub::Configuration
- Jabber::PubSub::Event
- Jabber::PubSub::EventItem
- Jabber::PubSub::EventItems
- Jabber::PubSub::IqPubSub
- Jabber::PubSub::IqPubSubOwner
- Jabber::PubSub::Item
- Jabber::PubSub::Items
- Jabber::PubSub::NodeBrowser
- Jabber::PubSub::NodeConfig
- Jabber::PubSub::NodeHelper
- Jabber::PubSub::OAuthPubSubStreamHelper
- Jabber::PubSub::OAuthServiceHelper
- Jabber::PubSub::OwnerNodeConfig
- Jabber::PubSub::Publish
- Jabber::PubSub::Retract
- Jabber::PubSub::ServiceHelper
- Jabber::PubSub::Subscription
- Jabber::PubSub::SubscriptionConfig
- Jabber::PubSub::Unsubscribe
- Jabber::RPC
- Jabber::RPC::Client
- Jabber::RPC::IqQueryRPC
- Jabber::RPC::Server
- Jabber::Reliable
- Jabber::Reliable::Connection
- Jabber::Reliable::Listener
- Jabber::Roster
- Jabber::Roster::Helper
- Jabber::Roster::Helper::RosterItem
- Jabber::Roster::IqQueryRoster
- Jabber::Roster::RosterItem
- Jabber::Roster::RosterX
- Jabber::Roster::RosterXItem
- Jabber::Roster::XRoster
- Jabber::Roster::XRosterItem
- Jabber::SASL
- Jabber::SASL::Anonymous
- Jabber::SASL::Base
- Jabber::SASL::DigestMD5
- Jabber::SASL::Plain
- Jabber::SOCKS5Error
- Jabber::Semaphore
- Jabber::ServerDisconnected
- Jabber::Stream
- Jabber::Stream::ThreadBlock
- Jabber::StreamParser
- Jabber::Test
- Jabber::Test::ListenerMocker
- Jabber::UserLocation
- Jabber::UserLocation::Helper
- Jabber::UserLocation::Location
- Jabber::UserTune
- Jabber::UserTune::Helper
- Jabber::UserTune::Tune
- Jabber::Vcard
- Jabber::Vcard::Helper
- Jabber::Vcard::IqVcard
- Jabber::Version
- Jabber::Version::IqQueryVersion
- Jabber::Version::Responder
- Jabber::Version::SimpleResponder
- Jabber::X
- Jabber::XHTML
- Jabber::XHTML::Body
- Jabber::XHTML::HTML
- Jabber::XMPPElement
- Jabber::XMPPStanza
- Jabber::XParent
- REXML
- REXML::Element
- REXML::IOSource
- XMLRPC
- XMLRPC::Create
- Base64
- ObservableThing
- QObserver
- ThreadStore

No matching classes.

# Jabber::Bytestreams::SOCKS5BytestreamsServer

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:

- Instantiate with an unfirewalled port

- Add your external IP addresses with SOCKS5BytestreamsServer#add_address

- Once you've got an outgoing SOCKS5BytestreamsInitiator, do `SOCKS5BytestreamsInitiator#add_streamhost(my_socks5bytestreamsserver)` before you do `SOCKS5BytestreamsInitiator#open`

### Public Class Methods

new(port, listen_on=nil) click to toggle source

Start a local SOCKS5BytestreamsServer

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

port

Fixnum

  TCP port to listen on

listen_on

String

  Optional address for the server socket to listen on (i.e. '0.0.0.0' or '::')

    # File lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb, line 27
    def initialize(port, listen_on=nil)
      @port = port
      @addresses = []
      @peers = []
      @peers_lock = Mutex.new
      if listen_on
        socket = TCPServer.new(listen_on, port)
      else
        socket = TCPServer.new(port)
      end

      Thread.new do
        Thread.current.abort_on_exception = true
        loop do
          peer = SOCKS5BytestreamsPeer.new(socket.accept)
          Thread.new do
            Thread.current.abort_on_exception = true
            begin
              peer.start
            rescue
              Jabber::debuglog("SOCKS5 BytestreamsServer: Error accepting peer: #{$!}")
            end
          end
          @peers_lock.synchronize do
            @peers << peer
          end
        end
      end
    end

### Public Instance Methods

add_address(address) click to toggle source

Add an external IP address

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

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

each_streamhost(my_jid, &block) click to toggle source

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

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

peer_sock(addr) click to toggle source

Find the socket a peer is associated to

This method also performs some housekeeping, ie. removing peers with closed sockets.

addr

String

  Address like SOCKS5Bytestreams#stream_address

result

TCPSocker

  or [nil]

    # File lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb, line 64
    def peer_sock(addr)
      res = nil
      @peers_lock.synchronize {
        removes = []

        @peers.each { |peer|
          if peer.socket and peer.socket.closed?
            # Queue peers with closed socket for removal
            removes << peer
          elsif peer.address == addr and res.nil?
            res = peer.socket
          end

          # If we sent multiple addresses of our own, clients may
          # connect multiple times. DO NOT close any other connections
          # here. These may belong to other concurrent bytestreams,
          # believe that the peer will close any unneeded sockets
          # which will then be picked up by the next call to peer_sock.
        }

        # If we sent multiple addresses of our own, clients may
        # connect multiple times. Close these connections here.
        @peers.delete_if { |peer|
          if removes.include? peer
            peer.socket.close rescue IOError
            true
          else
            false
          end
        }
      }

      res
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.