Start connecting to the seed list.

        Args:
            seed_list: a list of host:port strings if not supplied use list from `protocol.xxx.json`
            skip_seeds: skip connecting to seed list
971857
def Start(self, seed_list: List[str] = None, skip_seeds: bool = False) -> None:
        
        if not seed_list:
            seed_list = settings.SEED_LIST

        logger.debug("Starting up nodeleader")
        if not skip_seeds:
            logger.debug("Attempting to connect to seed list...")
            for bootstrap in seed_list:
                if not is_ip_address(bootstrap):
                    host, port = bootstrap.split(':')
                    bootstrap = f"{hostname_to_ip(host)}:{port}"
                addr = Address(bootstrap)
                self.KNOWN_ADDRS.append(addr)
                self.SetupConnection(addr)

        logger.debug("Starting up nodeleader: starting peer, mempool, and blockheight check loops")
        # check in on peers every 10 seconds
        self.start_peer_check_loop()
        self.start_memcheck_loop()
        self.start_blockheight_loop()

        if settings.ACCEPT_INCOMING_PEERS and not self.incoming_server_running:
            class OneShotFactory(Factory):
                def __init__(self, leader):
                    self.leader = leader

                def buildProtocol(self, addr):
                    print(f"building new protocol for addr: {addr}")
                    self.leader.AddKnownAddress(Address(f"{addr.host}:{addr.port}"))
                    p = NeoNode(incoming_client=True)
                    p.factory = self
                    return p

            def listen_err(err):
                print(f"Failed start listening server for reason: {err.value}")

            def listen_ok(value):
                self.incoming_server_running = True

            logger.debug(f"Starting up nodeleader: setting up listen server on port: {settings.NODE_PORT}")
            server_endpoint = TCP4ServerEndpoint(self.reactor, settings.NODE_PORT)
            listenport_deferred = server_endpoint.listen(OneShotFactory(leader=self))
            listenport_deferred.addCallback(listen_ok)
            listenport_deferred.addErrback(listen_err)
542616
def connect(self):
        
        jobs = []
        self._socket.connect((self.host, self.port))
        try:
            jobs = [spawn(self._recv_loop), spawn(self._send_loop)]
            joinall(jobs)
        finally:
            killall(jobs)
1039221
def _append_seed(self, seed_type: str, data: Any) -> 'Seeding':
        
        self.append({
            SEED_METHOD: seed_type,
            SEED_DATA: data,
        })
        return self
718083
def connect(self, keyspace=None, wait_for_all_pools=False):
        
        with self._lock:
            if self.is_shutdown:
                raise DriverException("Cluster is already shut down")

            if not self._is_setup:
                log.debug("Connecting to cluster, contact points: %s; protocol version: %s",
                          self.contact_points, self.protocol_version)
                self.connection_class.initialize_reactor()
                _register_cluster_shutdown(self)
                for endpoint in self.endpoints_resolved:
                    host, new = self.add_host(endpoint, signal=False)
                    if new:
                        host.set_up()
                        for listener in self.listeners:
                            listener.on_add(host)

                self.profile_manager.populate(
                    weakref.proxy(self), self.metadata.all_hosts())
                self.load_balancing_policy.populate(
                    weakref.proxy(self), self.metadata.all_hosts()
                )

                try:
                    self.control_connection.connect()

                    # we set all contact points up for connecting, but we won't infer state after this
                    for endpoint in self.endpoints_resolved:
                        h = self.metadata.get_host(endpoint)
                        if h and self.profile_manager.distance(h) == HostDistance.IGNORED:
                            h.is_up = None

                    log.debug("Control connection created")
                except Exception:
                    log.exception("Control connection failed to connect, "
                                  "shutting down Cluster:")
                    self.shutdown()
                    raise

                self.profile_manager.check_supported()  # todo: rename this method

                if self.idle_heartbeat_interval:
                    self._idle_heartbeat = ConnectionHeartbeat(
                        self.idle_heartbeat_interval,
                        self.get_connection_holders,
                        timeout=self.idle_heartbeat_timeout
                    )
                self._is_setup = True

        session = self._new_session(keyspace)
        if wait_for_all_pools:
            wait_futures(session._initial_connect_futures)
        return session
823675
def _select_next_server(self):
        

        # Continue trying to connect until there is an available server
        # or bail in case there are no more available servers.
        while True:
            if len(self._server_pool) == 0:
                self._current_server = None
                raise ErrNoServers

            now = time.time()
            s = self._server_pool.pop(0)
            if self.options["max_reconnect_attempts"] > 0:
                if s.reconnects > self.options["max_reconnect_attempts"]:
                    # Discard server since already tried to reconnect too many times.
                    continue

            # Not yet exceeded max_reconnect_attempts so can still use
            # this server in the future.
            self._server_pool.append(s)
            if s.last_attempt is not None and now < s.last_attempt + self.options["reconnect_time_wait"]:
                # Backoff connecting to server if we attempted recently.
                yield tornado.gen.sleep(self.options["reconnect_time_wait"])

            try:
                yield self._server_connect(s)
                self._current_server = s
                break
            except Exception as e:
                s.last_attempt = time.time()
                s.reconnects += 1

                self._err = e
                if self._error_cb is not None:
                    self._error_cb(e)
                self._status = Client.RECONNECTING
                continue
502088
def connect_forwarder(forward_host=None,
                      forward_port=None,
                      max_retries=-1,
                      sleep_interval=1.0):
    

    forward_skt = None
    retry_count = 0
    if max_retries == -1:
        retry_count = -2

    if forward_host and forward_port:
        while not forward_skt and \
              retry_count < max_retries:
            try:
                forward_skt = socket.socket()
                log.info(("connecting to forward={}:{}")
                         .format(forward_host,
                                 forward_port))
                forward_skt.connect((forward_host,
                                     forward_port))
                log.debug(("connected to forward={}:{}")
                          .format(forward_host,
                                  forward_port))
            except Exception as s:
                forward_skt = None
                log.error(("Failed to connect forward address={}:{} "
                           "with ex={}")
                          .format(forward_host,
                                  forward_port,
                                  s))
                if max_retries == -1:
                    retry_count = -2
                else:
                    retry_count += 1
            # end of try/ex
            time.sleep(sleep_interval)
        # end of setting up forward
    # end forward_host and forward_port

    return forward_skt
28602
def _start_rpc_session(self, sock):
        
        session_name = RpcSession.NAME_FMT % str(sock.getpeername())
        self._stop_child_activities(session_name)

        rpc_session = RpcSession(sock, self)
        self._spawn_activity(rpc_session)
985224
def canonical_new_peer_list( self, peers_to_add ):
        
        new_peers = list(set(self.new_peers + peers_to_add))
        random.shuffle( new_peers )
        
        # canonicalize
        tmp = []
        for peer in new_peers:
            tmp.append( self.canonical_peer(peer) )

        new_peers = tmp

        # don't talk to myself
        if self.my_hostport in new_peers:
            new_peers.remove(self.my_hostport)

        return new_peers
1141542
def _connect_loop(self, client_factory):
        
        # If current configuration allow, enable active session establishment.
        if self._neigh_conf.enabled:
            self._connect_retry_event.set()

        while True:
            self._connect_retry_event.wait()

            # Reconnecting immediately after closing connection may be not very
            # well seen by some peers (ALU?)
            self.pause(1.0)
            if self.state.bgp_state in \
                    (const.BGP_FSM_IDLE, const.BGP_FSM_ACTIVE):

                # Check if we have to stop or retry
                self.state.bgp_state = const.BGP_FSM_CONNECT
                # If we have specific host interface to bind to, we will do so
                # else we will bind to system default.
                if self._neigh_conf.host_bind_ip and \
                        self._neigh_conf.host_bind_port:
                    bind_addr = (self._neigh_conf.host_bind_ip,
                                 self._neigh_conf.host_bind_port)
                else:
                    bind_addr = None
                peer_address = (self._neigh_conf.ip_address,
                                self._neigh_conf.port)

                if bind_addr:
                    LOG.debug('%s trying to connect from'
                              '%s to %s', self, bind_addr, peer_address)
                else:
                    LOG.debug('%s trying to connect to %s', self, peer_address)
                tcp_conn_timeout = self._common_conf.tcp_conn_timeout
                try:
                    password = self._neigh_conf.password
                    self._connect_tcp(peer_address,
                                      client_factory,
                                      time_out=tcp_conn_timeout,
                                      bind_address=bind_addr,
                                      password=password)
                except socket.error:
                    self.state.bgp_state = const.BGP_FSM_ACTIVE
                    if LOG.isEnabledFor(logging.DEBUG):
                        LOG.debug('Socket could not be created in time'
                                  ' (%s secs), reason %s', tcp_conn_timeout,
                                  traceback.format_exc())
                    LOG.info('Will try to reconnect to %s after %s secs: %s',
                             self._neigh_conf.ip_address,
                             self._common_conf.bgp_conn_retry_time,
                             self._connect_retry_event.is_set())

            self.pause(self._common_conf.bgp_conn_retry_time)
1163508
def postorder(self, skip_seed=False):
        
        for node in self._tree.postorder_node_iter():
            if skip_seed and node is self._tree.seed_node:
                continue
            yield node
984946
def start_tls(self, ssl_context: Union[bool, dict, ssl.SSLContext]=True) \
            -> 'SSLConnection':
        '''
        '''
        sock = self.writer.get_extra_info('socket')
        ssl_conn = SSLConnection(
            self._address,
            ssl_context=ssl_context,
            hostname=self._hostname, timeout=self._timeout,
            connect_timeout=self._connect_timeout, bind_host=self._bind_host,
            bandwidth_limiter=self._bandwidth_limiter, sock=sock
        )

        yield from ssl_conn.connect()

        return ssl_conn
16578
def _set_seed(self):
        
        if self.flags['SEED'] is not None:
            tf.set_random_seed(self.flags['SEED'])
            np.random.seed(self.flags['SEED'])
1231062
def plant(self, *seeds, **arguments):
        
        map(self._clean, seeds)
        self.network_kwargs.update(arguments)
171136
def start_client(host, port):
    '''  '''
    pydev_log.info("Connecting to %s:%s", host, port)

    s = socket(AF_INET, SOCK_STREAM)

    #  Set TCP keepalive on an open socket.
    #  It activates after 1 second (TCP_KEEPIDLE,) of idleness,
    #  then sends a keepalive ping once every 3 seconds (TCP_KEEPINTVL),
    #  and closes the connection after 5 failed ping (TCP_KEEPCNT), or 15 seconds
    try:
        from socket import IPPROTO_TCP, SO_KEEPALIVE, TCP_KEEPIDLE, TCP_KEEPINTVL, TCP_KEEPCNT
        s.setsockopt(SOL_SOCKET, SO_KEEPALIVE, 1)
        s.setsockopt(IPPROTO_TCP, TCP_KEEPIDLE, 1)
        s.setsockopt(IPPROTO_TCP, TCP_KEEPINTVL, 3)
        s.setsockopt(IPPROTO_TCP, TCP_KEEPCNT, 5)
    except ImportError:
        pass  # May not be available everywhere.

    try:
        # 10 seconds default timeout
        timeout = int(os.environ.get('PYDEVD_CONNECT_TIMEOUT', 10))
        s.settimeout(timeout)
        s.connect((host, port))
        s.settimeout(None)  # no timeout after connected
        pydev_log.info("Connected.")
        return s
    except:
        pydev_log.exception("Could not connect to %s: %s", host, port)
        raise
687100
def start_instances(self, instance_ids=None):
        
        params = {}
        if instance_ids:
            self.build_list_params(params, instance_ids, 'InstanceId')
        return self.get_list('StartInstances', params,
                             [('item', Instance)], verb='POST')
1238866
def _connect(self):
        

        self.first_data_sent_complete = False
        self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.socket.connect((self.host, self.port))

        msg = cr.Message()
        msg.type = cr.CONNECT
        msg.request_connect.auth_code = self.auth_code or 0
        msg.request_connect.send_playlist_songs = False
        msg.request_connect.downloader = False

        self.send_message(msg)
190868
def init_db_conn(connection_name, HOSTS=None):
    
    el = elasticsearch.Elasticsearch(hosts=HOSTS)
    el_pool.connections[connection_name] = ElasticSearchClient(el)