Get b58 string from multiaddr or peerinfo

@param {Multiaddr|PeerInfo} peer
@return {*}
777389
function getB58String (peer) {
    let b58Id = null
    if (multiaddr.isMultiaddr(peer)) {
      const relayMa = multiaddr(peer)
      b58Id = relayMa.getPeerId()
    } else if (PeerInfo.isPeerInfo(peer)) {
      b58Id = peer.id.toB58String()
    }

    return b58Id
  }
1324477
def show_bgp_peer(self, peer_id, **_params):
        """"""
        return self.get(self.bgp_peer_path % peer_id,
                        params=_params)
64949
public String getPeerInternalHostName (String nodeName)
    {
        if (Objects.equal(_nodeName, nodeName)) {
            return _self.hostName;
        }
        PeerNode peer = _peers.get(nodeName);
        return (peer == null) ? null : peer.getInternalHostName();
    }
1310798
def get_peer_ips(self):
        '''
        
        '''
        presponse = [ord(i) for i in self.tracker_response['peers']]
        while presponse:
            peer_ip = (('.'.join(str(x) for x in presponse[0:4]),
                       256 * presponse[4] + presponse[5]))
            if peer_ip not in self.peer_ips:
                self.peer_ips.append(peer_ip)
            presponse = presponse[6:]
1191088
function getPeerInfo (peer, peerBook) {
  let peerInfo

  // Already a PeerInfo instance,
  // add to the peer book and return the latest value
  if (PeerInfo.isPeerInfo(peer)) {
    return peerBook.put(peer)
  }

  // Attempt to convert from Multiaddr instance (not string)
  if (multiaddr.isMultiaddr(peer)) {
    const peerIdB58Str = peer.getPeerId()
    try {
      peerInfo = peerBook.get(peerIdB58Str)
    } catch (err) {
      peerInfo = new PeerInfo(PeerId.createFromB58String(peerIdB58Str))
    }
    peerInfo.multiaddrs.add(peer)
    return peerInfo
  }

  // Attempt to convert from PeerId
  if (PeerId.isPeerId(peer)) {
    const peerIdB58Str = peer.toB58String()
    try {
      return peerBook.get(peerIdB58Str)
    } catch (err) {
      throw new Error(`Couldnt get PeerInfo for ${peerIdB58Str}`)
    }
  }

  throw new Error('peer type not recognized')
}
1272271
public int getPeerPort (String nodeName)
    {
        if (Objects.equal(_nodeName, nodeName)) {
            return _self.port;
        }
        PeerNode peer = _peers.get(nodeName);
        return (peer == null) ? -1 : peer.getPort();
    }
378979
function readSharedAddressPeerAddresses(shared_address, handlePeerAddresses){
	readSharedAddressPeers(shared_address, function(assocNamesByAddress){
		handlePeerAddresses(Object.keys(assocNamesByAddress));
	});
}
465176
function getByAddr(addr) {
  var i;
  for(i = 0;i < this._conn.length;i++) {
    if(this._conn[i].client.addr === addr) {
      return this._conn[i];
    }
  }
  return null;
}
499202
@Override
	public final String getRemotePeerID()
	{
		SocketAddress peerAddress = getRemotePeer();
		return peerAddress != null ? peerAddress.toString() : "not connected";
	}
735776
public static HostAndPort parseString(String from){
    // NOTE: redis answers with
    // '99aa9999aa9a99aa099aaa990aa99a09aa9a9999 9a09:9a9:a090:9a::99a slave 8c88888888cc08088cc8c8c888c88c8888c88cc8 0 1468251272993 37 connected'
    // for CLUSTER NODES, ASK and MOVED scenarios. That's why there is no possibility to parse address in 'correct' way.
    // Redis should switch to 'bracketized' (RFC 3986) IPv6 address.
    try {
      String[] parts = extractParts(from);
      String host = parts[0];
      int port = Integer.parseInt(parts[1]);
      return new HostAndPort(convertHost(host), port);
    } catch (NumberFormatException ex) {
      throw new IllegalArgumentException(ex);
    }
  }
216481
def get(self, hostport):
        
        assert hostport, "hostport is required"
        assert isinstance(hostport, basestring), "hostport must be a string"

        if hostport not in self._peers:
            self._add(hostport)

        return self._peers[hostport]
164151
def parse229(resp) # :nodoc:
      if resp[0, 3] != "229"
        raise FTPReplyError, resp
      end
      if m = /\((?<d>[!-~])\k<d>\k<d>(?<port>\d+)\k<d>\)/.match(resp)
        return @sock.peeraddr[3], m["port"].to_i
      else
        raise FTPProtoError, resp
      end
    end
314411
function parseSubaddress(user) {
	var parsed = {
		username: user
	};
	if (user.indexOf('+')) {
		parsed.username = user.split('+')[0];
		parsed.subaddress = user.split('+')[1];
	}
	return parsed;
}
216906
def get_bgp_neighbors_detail(self, neighbor_address=''):
        """"""
        def _parse_per_peer_bgp_detail(peer_output):
            """This function parses the raw data per peer and returns a
            json structure per peer.
            """

            int_fields = ['local_as', 'remote_as',
                          'local_port', 'remote_port', 'local_port',
                          'input_messages', 'output_messages', 'input_updates',
                          'output_updates', 'messages_queued_out', 'holdtime',
                          'configured_holdtime', 'keepalive',
                          'configured_keepalive', 'advertised_prefix_count',
                          'received_prefix_count']

            peer_details = []

            # Using preset template to extract peer info
            peer_info = (
                napalm_base.helpers.textfsm_extractor(
                    self, 'bgp_detail', peer_output))

            for item in peer_info:

                # Determining a few other fields in the final peer_info
                item['up'] = (
                    True if item['up'] == "up" else False)
                item['local_address_configured'] = (
                    True if item['local_address'] else False)
                item['multihop'] = (
                    False if item['multihop'] == 0 or
                    item['multihop'] == '' else True)

                # TODO: The below fields need to be retrieved
                # Currently defaulting their values to False or 0
                item['multipath'] = False
                item['remove_private_as'] = False
                item['suppress_4byte_as'] = False
                item['local_as_prepend'] = False
                item['flap_count'] = 0
                item['active_prefix_count'] = 0
                item['suppressed_prefix_count'] = 0

                # Converting certain fields into int
                for key in int_fields:
                    item[key] = napalm_base.helpers.convert(int, item[key], 0)

                # Conforming with the datatypes defined by the base class
                item['export_policy'] = (
                    napalm_base.helpers.convert(
                        py23_compat.text_type, item['export_policy']))
                item['last_event'] = (
                    napalm_base.helpers.convert(
                        py23_compat.text_type, item['last_event']))
                item['remote_address'] = napalm_base.helpers.ip(item['remote_address'])
                item['previous_connection_state'] = (
                    napalm_base.helpers.convert(
                        py23_compat.text_type, item['previous_connection_state']))
                item['import_policy'] = (
                    napalm_base.helpers.convert(
                        py23_compat.text_type, item['import_policy']))
                item['connection_state'] = (
                    napalm_base.helpers.convert(
                        py23_compat.text_type, item['connection_state']))
                item['routing_table'] = (
                    napalm_base.helpers.convert(
                        py23_compat.text_type, item['routing_table']))
                item['router_id'] = napalm_base.helpers.ip(item['router_id'])
                item['local_address'] = napalm_base.helpers.convert(
                    napalm_base.helpers.ip, item['local_address'])

                peer_details.append(item)

            return peer_details

        def _append(bgp_dict, peer_info):

            remote_as = peer_info['remote_as']
            vrf_name = peer_info['routing_table']

            if vrf_name not in bgp_dict.keys():
                bgp_dict[vrf_name] = {}
            if remote_as not in bgp_dict[vrf_name].keys():
                bgp_dict[vrf_name][remote_as] = []

            bgp_dict[vrf_name][remote_as].append(peer_info)

        commands = []
        summary_commands = []
        if not neighbor_address:
            commands.append('show ip bgp neighbors vrf all')
            commands.append('show ipv6 bgp neighbors vrf all')
            summary_commands.append('show ip bgp summary vrf all')
            summary_commands.append('show ipv6 bgp summary vrf all')
        else:
            try:
                peer_ver = IPAddress(neighbor_address).version
            except Exception as e:
                raise e

            if peer_ver == 4:
                commands.append('show ip bgp neighbors %s vrf all' %
                                neighbor_address)
                summary_commands.append('show ip bgp summary vrf all')
            elif peer_ver == 6:
                commands.append('show ipv6 bgp neighbors %s vrf all' %
                                neighbor_address)
                summary_commands.append('show ipv6 bgp summary vrf all')

        raw_output = (
            self.device.run_commands(commands, encoding='text'))
        bgp_summary = (
            self.device.run_commands(summary_commands, encoding='json'))

        bgp_detail_info = {}

        v4_peer_info = []
        v6_peer_info = []

        if neighbor_address:
            peer_info = _parse_per_peer_bgp_detail(raw_output[0]['output'])

            if peer_ver == 4:
                v4_peer_info.append(peer_info[0])
            else:
                v6_peer_info.append(peer_info[0])

        else:
            # Using preset template to extract peer info
            v4_peer_info = _parse_per_peer_bgp_detail(raw_output[0]['output'])
            v6_peer_info = _parse_per_peer_bgp_detail(raw_output[1]['output'])

        for peer_info in v4_peer_info:

            vrf_name = peer_info['routing_table']
            peer_remote_addr = peer_info['remote_address']
            peer_info['accepted_prefix_count'] = (
                bgp_summary[0]['vrfs'][vrf_name]['peers'][peer_remote_addr]['prefixAccepted']
                if peer_remote_addr in bgp_summary[0]['vrfs'][vrf_name]['peers'].keys()
                else 0
            )

            _append(bgp_detail_info, peer_info)

        for peer_info in v6_peer_info:

            vrf_name = peer_info['routing_table']
            peer_remote_addr = peer_info['remote_address']
            peer_info['accepted_prefix_count'] = (
                bgp_summary[1]['vrfs'][vrf_name]['peers'][peer_remote_addr]['prefixAccepted']
                if peer_remote_addr in bgp_summary[1]['vrfs'][vrf_name]['peers'].keys()
                else 0
            )

            _append(bgp_detail_info, peer_info)

        return bgp_detail_info
517403
function getPort(req) {
		if (req.connection && req.connection.localPort) {
			return req.connection.localPort.toString();
		}
		const host = req.headers && req.headers.host;
		let protocolSrc = 80;
		if (host && ((host.match(/:/g) || []).length) === 1) {
			const possiblePort = host.split(':')[1];
			protocolSrc = isNaN(possiblePort) ? protocolSrc : possiblePort;
		}
		return protocolSrc;
	}
887421
function getOrCreatePeer(id)
    {
        if(scope.peers[id])
        {
            return scope.peers[id];
        }
        return createPeerInstance(id);
    }
1107979
def peer_header_value(self, peer, name):
        
        return return_fresh_string(lib.zyre_peer_header_value(self._as_parameter_, peer, name))