Setup the IPC PUB and SUB sockets for the proxy.
354098
def _setup_ipc(self):
        '''
        
        '''
        log.debug('Setting up the internal IPC proxy')
        self.ctx = zmq.Context()
        # Frontend
        self.sub = self.ctx.socket(zmq.SUB)
        self.sub.bind(PUB_PX_IPC_URL)
        self.sub.setsockopt(zmq.SUBSCRIBE, b'')
        log.debug('Setting HWM for the proxy frontend: %d', self.hwm)
        try:
            self.sub.setsockopt(zmq.HWM, self.hwm)
            # zmq 2
        except AttributeError:
            # zmq 3
            self.sub.setsockopt(zmq.SNDHWM, self.hwm)
        # Backend
        self.pub = self.ctx.socket(zmq.PUB)
        self.pub.bind(PUB_IPC_URL)
        log.debug('Setting HWM for the proxy backend: %d', self.hwm)
        try:
            self.pub.setsockopt(zmq.HWM, self.hwm)
            # zmq 2
        except AttributeError:
            # zmq 3
            self.pub.setsockopt(zmq.SNDHWM, self.hwm)
525435
def _setup_transport(self):
        """"""
        if hasattr(self, 'sslopts'):
            self.sock = ssl.wrap_socket(self.sock, **self.sslopts)
        else:
            self.sock = ssl.wrap_socket(self.sock)
        self.sock.do_handshake()
        self._quick_recv = self.sock.read
512094
public static void configureCustomProxyProperties(
      Map<SFSessionProperty, Object> connectionPropertiesMap)
  {
    if (connectionPropertiesMap.containsKey(SFSessionProperty.USE_PROXY))
    {
      useProxy = (boolean) connectionPropertiesMap.get(
          SFSessionProperty.USE_PROXY);
    }

    if (useProxy)
    {
      proxyHost =
          (String) connectionPropertiesMap.get(SFSessionProperty.PROXY_HOST);
      proxyPort =
          Integer.parseInt(
              connectionPropertiesMap.get(SFSessionProperty.PROXY_PORT).toString());
      proxyUser =
          (String) connectionPropertiesMap.get(SFSessionProperty.PROXY_USER);
      proxyPassword =
          (String) connectionPropertiesMap.get(SFSessionProperty.PROXY_PASSWORD);
      nonProxyHosts =
          (String) connectionPropertiesMap.get(SFSessionProperty.NON_PROXY_HOSTS);
    }
  }
1270780
def setup_rpc(self):
        """"""

        endpoints = RpcCallBacks(self._vdpm, self._iptd)
        self.server = rpc.DfaRpcServer(self._qn, self._my_host, self._url,
                                       endpoints,
                                       exchange=constants.DFA_EXCHANGE)
879451
public void setProxy(String proxyHost, int proxyPort) {
         this.proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort));
     }
157535
function Prox(settings) {

    var self = this;
    this.log = settings.log;

    this.devices = new DeviceManager(settings);
    this.server = new ServerConnection(settings);

    this.server.on('listening', function (localPort, localAddress, protocol) {
        self.log('Web-Remote-Control Proxy Server listening to "' + protocol + '" requests on ' + localAddress + ':' + localPort);
    });

    this.server.on('error', this.handleError.bind(this));

    this.server.on('socket-close', function (socketId) {
        self.devices.removeBySocketId(socketId);
    });

    this.server.on('register', this.registerDevice.bind(this));
    this.server.on('ping', this.respondToPing.bind(this));
    this.server.on('status', this.forwardStatus.bind(this));
    this.server.on('command', this.forwardCommand.bind(this));

    this.stickers = new StickyMessages();

    EventEmitter.call(this);

}
336414
function ProxySocket(proxy_port, proxy_addr, meta, proxy_opts) {
    stream.Duplex.call(this);

    this.connected_fn = null;
    this.proxy_addr   = proxy_addr;
    this.proxy_port   = proxy_port;
    this.proxy_opts   = proxy_opts || {};

    this.setMeta(meta || {});

    this.state = 'disconnected';
}
24245
def _setup_transport(self):
        
        if HAVE_PY26_SSL:
            if hasattr(self, 'sslopts'):
                self.sslobj = ssl.wrap_socket(self.sock, **self.sslopts)
            else:
                self.sslobj = ssl.wrap_socket(self.sock)
            self.sslobj.do_handshake()
        else:
            self.sslobj = socket.ssl(self.sock)
513530
def _setup_transport(self):
        
        self._write = self.sock.sendall
        self._read_buffer = bytes()
1318129
def _setup_transport(self):
        """"""
        if hasattr(self, 'sslopts'):
            self.sock = ssl.wrap_socket(self.sock, **self.sslopts)
        elif hasattr(self, 'sslctx'):
            self.sock = self.sslctx.wrap_socket(self.sock,
                                                server_hostname=self.hostname)
        else:
            self.sock = ssl.wrap_socket(self.sock)
        self.sock.do_handshake()
        self._quick_recv = self.sock.read
948011
def prepare_socket(bind_addr, family, type, proto, nodelay, ssl_adapter):
        """"""
        sock = socket.socket(family, type, proto)
        prevent_socket_inheritance(sock)

        host, port = bind_addr[:2]
        IS_EPHEMERAL_PORT = port == 0

        if not (IS_WINDOWS or IS_EPHEMERAL_PORT):
            """Enable SO_REUSEADDR for the current socket.

            Skip for Windows (has different semantics)
            or ephemeral ports (can steal ports from others).

            Refs:
            * https://msdn.microsoft.com/en-us/library/ms740621(v=vs.85).aspx
            * https://github.com/cherrypy/cheroot/issues/114
            * https://gavv.github.io/blog/ephemeral-port-reuse/
            """
            sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        if nodelay and not isinstance(bind_addr, str):
            sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)

        if ssl_adapter is not None:
            sock = ssl_adapter.bind(sock)

        # If listening on the IPV6 any address ('::' = IN6ADDR_ANY),
        # activate dual-stack. See
        # https://github.com/cherrypy/cherrypy/issues/871.
        listening_ipv6 = (
            hasattr(socket, 'AF_INET6')
            and family == socket.AF_INET6
            and host in ('::', '::0', '::0.0.0.0')
        )
        if listening_ipv6:
            try:
                sock.setsockopt(
                    socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0,
                )
            except (AttributeError, socket.error):
                # Apparently, the socket option is not available in
                # this machine's TCP stack
                pass

        return sock
708915
def start_proxy(self, port=None):
        

        self.runner.info_log("Starting proxy...")

        # Get a random port that is available
        if not port:
            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            sock.bind(('0.0.0.0', 0))
            sock.listen(5)
            self.proxy_port = sock.getsockname()[1]
            sock.close()

        network_data_path = os.path.join(
            self.runner.runner_dir,
            'network_capture'
        )
        create_dir_if_doesnt_exist(network_data_path)

        self.proxy_output_path = os.path.join(
            network_data_path,
            string_to_filename('%s.data' % self.test_name)
        )

        path_to_mitmproxy = BROME_CONFIG['mitmproxy']['path']

        if not path_to_mitmproxy:
            raise Exception("""
                You need to set the mitmproxy:path config to be able
                to the use the proxy with this browser
            """)

        filter_ = BROME_CONFIG['mitmproxy']['filter']
        command = [
            path_to_mitmproxy,
            "-p",
            "%s" % self.proxy_port,
            "-w",
            self.proxy_output_path
        ]

        if filter_:
            command.append(filter_)

        process = self.execute_command(command)

        self.proxy_pid = process.pid

        self.runner.info_log("Proxy pid: %s" % self.proxy_pid)
928342
def _setup_transport(self):
        '''
        
        '''
        if 'RAW' in self.error_whitelist:
            log.info('%s %d will publish partially parsed messages', self._transport_type, self.pub_id)
        if 'UNKNOWN' in self.error_whitelist:
            log.info('%s %d will publish unknown messages', self._transport_type, self.pub_id)
        transport_class = get_transport(self._transport_type)
        log.debug('Serializing the object for %s using %s',
                  self._transport_type,
                  self.serializer)
        self.serializer_fun = get_serializer(self.serializer)
        self.transport = transport_class(self.address,
                                         self.port,
                                         **self.publisher_opts)
        self.__transport_encrypt = True
        if hasattr(self.transport, 'NO_ENCRYPT') and\
           getattr(self.transport, 'NO_ENCRYPT') is True:
            self.__transport_encrypt = False
850821
def set_proxy(self, proxy_server, proxy_port, proxy_username,
                  proxy_password):
        
        if proxy_server and proxy_port:
            if proxy_username and proxy_password:
                self.proxy = {
                    "http": "http://{}:{}@{}:{}".format(proxy_username,
                                                        proxy_password,
                                                        proxy_server,
                                                        proxy_port),
                    "https": "https://{}:{}@{}:{}".format(proxy_username,
                                                          proxy_password,
                                                          proxy_server,
                                                          proxy_port),
                }
            else:
                self.proxy = {
                    "http": "http://{}:{}".format(proxy_server, proxy_port),
                    "https": "https://{}:{}".format(proxy_server, proxy_port),
                }
198488
def build_socket(self):
        
        try:
            self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            self.sock.settimeout(self.SOCKET_TIMEOUT)
            self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
            # Check if TLS
            if self.request_object.protocol == 'https':
                self.sock = ssl.wrap_socket(self.sock, ciphers=self.CIPHERS)
            self.sock.connect(
                (self.request_object.dest_addr, self.request_object.port))
        except socket.error as msg:
            raise errors.TestError(
                'Failed to connect to server',
                {
                    'host': self.request_object.dest_addr,
                    'port': self.request_object.port,
                    'proto': self.request_object.protocol,
                    'message': msg,
                    'function': 'http.HttpUA.build_socket'
                })
943673
public void setupPubsub() throws IOException {
    ExamplePubsubTopicAndSubscriptionOptions pubsubOptions =
        options.as(ExamplePubsubTopicAndSubscriptionOptions.class);
    if (!pubsubOptions.getPubsubTopic().isEmpty()) {
      pendingMessages.add("**********************Set Up Pubsub************************");
      setupPubsubTopic(pubsubOptions.getPubsubTopic());
      pendingMessages.add("The Pub/Sub topic has been set up for this example: "
          + pubsubOptions.getPubsubTopic());

      if (!pubsubOptions.getPubsubSubscription().isEmpty()) {
        setupPubsubSubscription(
            pubsubOptions.getPubsubTopic(), pubsubOptions.getPubsubSubscription());
        pendingMessages.add("The Pub/Sub subscription has been set up for this example: "
            + pubsubOptions.getPubsubSubscription());
      }
    }
  }
94080
def setup(self):
        ''''''
        log.debug( 'New request from address %s, port %d',  self.client_address )
        
        try:
            self.transport.load_server_moduli()
        except:
            log.exception( '(Failed to load moduli -- gex will be unsupported.)' )
            raise
        try:
            self.transport.add_server_key(self.host_key)
        except:
            if self.host_key is None:
                log.critical('Host key not set!  SSHHandler MUST define the host_key parameter.')
                raise NotImplementedError('Host key not set!  SSHHandler instance must define the host_key parameter.  Try host_key = paramiko_ssh.getRsaKeyFile("server_rsa.key").')
        
        try:
            # Tell transport to use this object as a server
            log.debug( 'Starting SSH server-side negotiation' )
            self.transport.start_server(server=self)
        except SSHException, e:
           log.warn('SSH negotiation failed. %s', e)
           raise
        
        # Accept any requested channels
        while True:
            channel = self.transport.accept(20)
            if channel is None:
                # check to see if any thread is running
                any_running = False
                for c, thread in self.channels.items():
                    if thread.is_alive():
                        any_running = True
                        break
                if not any_running:
                    break
            else:
                log.info( 'Accepted channel %s', channel )