/** * Obtain a "host" from an {@link InetSocketAddress}. This returns a string containing either an * actual host name or a numeric IP address. */ // Visible for testing static String getHostString(InetSocketAddress socketAddress) { InetAddress address = socketAddress.getAddress(); if (address == null) { // The InetSocketAddress was specified with a string (either a numeric IP or a host name). If // it is a name, all IPs for that name should be tried. If it is an IP address, only that IP // address should be tried. return socketAddress.getHostName(); } // The InetSocketAddress has a specific address: we should only try that address. Therefore we // return the address and ignore any host name that may be available. return address.getHostAddress(); }
@Override public Object getParameter(String name) { if (name.equals(ConnRouteParams.DEFAULT_PROXY)) { Proxy proxy = client.proxy(); if (proxy == null) { return null; } InetSocketAddress address = (InetSocketAddress) proxy.address(); return new HttpHost(address.getHostName(), address.getPort()); } throw new IllegalArgumentException(name); }
public static boolean compare(InetSocketAddress entryAddr, URI addr) { if (((entryAddr.getHostName() != null && entryAddr.getHostName().equals(trimIpv6Brackets(addr.getHost()))) || entryAddr.getAddress().getHostAddress().equals(trimIpv6Brackets(addr.getHost()))) && entryAddr.getPort() == addr.getPort()) { return true; } return false; }
@Override public void serialize(InetSocketAddress value, JsonGenerator jgen, SerializerProvider provider) throws IOException { InetAddress addr = value.getAddress(); String str = addr == null ? value.getHostName() : addr.toString().trim(); int ix = str.indexOf('/'); if (ix >= 0) { if (ix == 0) { // missing host name; use address str = addr instanceof Inet6Address ? "[" + str.substring(1) + "]" // bracket IPv6 addresses with : str.substring(1); } else { // otherwise use name str = str.substring(0, ix); } } jgen.writeString(str + ":" + value.getPort()); }
if (address != null) { if ((resolveType == ResolveType.FORWARD || resolveType == ResolveType.FORWARD_AND_REVERSE) && address.isUnresolved()) { try { if (System.getSecurityManager() == null) { final InetSocketAddress resolvedAddress = new InetSocketAddress(InetAddress.getByName(address.getHostName()), address.getPort()); exchange.setSourceAddress(resolvedAddress); } else { address.getHostName(); } else { AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Map<String, Object> getHost(HttpServerExchange exchange) { Map<String, Object> hostMap = new LinkedHashMap<>(); String ip = "unknown"; String hostname = "unknown"; InetAddress inetAddress = Util.getInetAddress(); ip = inetAddress.getHostAddress(); hostname = inetAddress.getHostName(); hostMap.put("ip", ip); hostMap.put("hostname", hostname); hostMap.put("dns", exchange.getSourceAddress().getHostName()); return hostMap; }
private static String getHostNameNoResolve(InetSocketAddress socketAddress) { if (Xnio.NIO2) { return socketAddress.getHostString(); } else { String hostName; if (socketAddress.isUnresolved()) { hostName = socketAddress.getHostName(); } else { final InetAddress address = socketAddress.getAddress(); final String string = address.toString(); final int slash = string.indexOf('/'); if (slash == -1 || slash == 0) { // unresolved both ways hostName = string.substring(slash + 1); } else { // has a cached host name hostName = string.substring(0, slash); } } return hostName; } } }
public static String getAmHostNameFromAddress(InetSocketAddress address, Configuration conf) { if (!HiveConf.getBoolVar(conf, HiveConf.ConfVars.LLAP_DAEMON_AM_USE_FQDN)) { return address.getHostName(); } InetAddress ia = address.getAddress(); // getCanonicalHostName would either return FQDN, or an IP. return (ia == null) ? address.getHostName() : ia.getCanonicalHostName(); }
BlockingRpcConnection(BlockingRpcClient rpcClient, ConnectionId remoteId) throws IOException { super(rpcClient.conf, AbstractRpcClient.WHEEL_TIMER, remoteId, rpcClient.clusterId, rpcClient.userProvider.isHBaseSecurityEnabled(), rpcClient.codec, rpcClient.compressor); this.rpcClient = rpcClient; if (remoteId.getAddress().isUnresolved()) { throw new UnknownHostException("unknown host: " + remoteId.getAddress().getHostName()); } this.connectionHeaderPreamble = getConnectionHeaderPreamble(); ConnectionHeader header = getConnectionHeader(); ByteArrayOutputStream baos = new ByteArrayOutputStream(4 + header.getSerializedSize()); DataOutputStream dos = new DataOutputStream(baos); dos.writeInt(header.getSerializedSize()); header.writeTo(dos); assert baos.size() == 4 + header.getSerializedSize(); this.connectionHeaderWithLength = baos.getBuffer(); UserGroupInformation ticket = remoteId.ticket.getUGI(); this.threadName = "IPC Client (" + this.rpcClient.socketFactory.hashCode() + ") connection to " + remoteId.getAddress().toString() + ((ticket == null) ? " from an unknown user" : (" from " + ticket.getUserName())); if (this.rpcClient.conf.getBoolean(BlockingRpcClient.SPECIFIC_WRITE_THREAD, false)) { callSender = new CallSender(threadName, this.rpcClient.conf); callSender.start(); } else { callSender = null; } }
public static boolean compare(InetSocketAddress entryAddr, URI addr) { if (((entryAddr.getHostName() != null && entryAddr.getHostName().equals(trimIpv6Brackets(addr.getHost()))) || entryAddr.getAddress().getHostAddress().equals(trimIpv6Brackets(addr.getHost()))) && entryAddr.getPort() == addr.getPort()) { return true; } return false; }
/** * get remote host. * * @return remote host */ public String getRemoteHost() { return remoteAddress == null ? null : remoteAddress.getAddress() == null ? remoteAddress.getHostName() : NetUtils.filterLocalHost(remoteAddress.getAddress().getHostAddress()); }
@Override public void serialize(InetSocketAddress value, JsonGenerator jgen, SerializerProvider provider) throws IOException { InetAddress addr = value.getAddress(); String str = addr == null ? value.getHostName() : addr.toString().trim(); int ix = str.indexOf('/'); if (ix >= 0) { if (ix == 0) { // missing host name; use address str = addr instanceof Inet6Address ? "[" + str.substring(1) + "]" // bracket IPv6 addresses with : str.substring(1); } else { // otherwise use name str = str.substring(0, ix); } } jgen.writeString(str + ":" + value.getPort()); }
private void send(final String name, final String value) { try { String formatted = String.format("%s:%s|g", name, value); byte[] data = formatted.getBytes(StandardCharsets.UTF_8); socket.send(new DatagramPacket(data, data.length, this.address)); } catch (IOException e) { LOG.error("unable to send packet to statsd at '{}:{}'", address.getHostName(), address.getPort()); } }
if (address != null) { if ((resolveType == ResolveType.FORWARD || resolveType == ResolveType.FORWARD_AND_REVERSE) && address.isUnresolved()) { try { if (System.getSecurityManager() == null) { final InetSocketAddress resolvedAddress = new InetSocketAddress(InetAddress.getByName(address.getHostName()), address.getPort()); exchange.setDestinationAddress(resolvedAddress); } else { address.getHostName(); } else { AccessController.doPrivileged(new PrivilegedAction<Object>() {
protected RpcConnection(Configuration conf, HashedWheelTimer timeoutTimer, ConnectionId remoteId, String clusterId, boolean isSecurityEnabled, Codec codec, CompressionCodec compressor) throws IOException { if (remoteId.getAddress().isUnresolved()) { throw new UnknownHostException("unknown host: " + remoteId.getAddress().getHostName()); remoteId.address.getAddress().getCanonicalHostName().toLowerCase()); if (LOG.isDebugEnabled()) { LOG.debug("RPC Server Kerberos principal name for service=" + remoteId.getServiceName()
BlockingRpcConnection(BlockingRpcClient rpcClient, ConnectionId remoteId) throws IOException { super(rpcClient.conf, AbstractRpcClient.WHEEL_TIMER, remoteId, rpcClient.clusterId, rpcClient.userProvider.isHBaseSecurityEnabled(), rpcClient.codec, rpcClient.compressor); this.rpcClient = rpcClient; if (remoteId.getAddress().isUnresolved()) { throw new UnknownHostException("unknown host: " + remoteId.getAddress().getHostName()); } this.connectionHeaderPreamble = getConnectionHeaderPreamble(); ConnectionHeader header = getConnectionHeader(); ByteArrayOutputStream baos = new ByteArrayOutputStream(4 + header.getSerializedSize()); DataOutputStream dos = new DataOutputStream(baos); dos.writeInt(header.getSerializedSize()); header.writeTo(dos); assert baos.size() == 4 + header.getSerializedSize(); this.connectionHeaderWithLength = baos.getBuffer(); UserGroupInformation ticket = remoteId.ticket.getUGI(); this.threadName = "IPC Client (" + this.rpcClient.socketFactory.hashCode() + ") connection to " + remoteId.getAddress().toString() + ((ticket == null) ? " from an unknown user" : (" from " + ticket.getUserName())); if (this.rpcClient.conf.getBoolean(BlockingRpcClient.SPECIFIC_WRITE_THREAD, false)) { callSender = new CallSender(threadName, this.rpcClient.conf); callSender.start(); } else { callSender = null; } }
@Override public Channel getChannel(InetSocketAddress remoteAddress) { String host = remoteAddress.getAddress() != null ? remoteAddress.getAddress().getHostAddress() : remoteAddress.getHostName(); int port = remoteAddress.getPort(); Channel channel = super.getChannel(remoteAddress); if (channel == null) { for (Map.Entry<URL, Client> entry : clients.entrySet()) { URL url = entry.getKey(); if (url.getIp().equals(host) && url.getPort() == port) { return entry.getValue(); } } } return channel; }
/** * get remote host. * * @return remote host */ public String getRemoteHost() { return remoteAddress == null ? null : remoteAddress.getAddress() == null ? remoteAddress.getHostName() : NetUtils.filterLocalHost(remoteAddress.getAddress().getHostAddress()); }
@Override public void writeObject(ObjectOutput output, InetSocketAddress socketAddress) throws IOException { InetAddress address = socketAddress.getAddress(); DefaultExternalizer.INET_ADDRESS.writeObject(output, address); IndexSerializer.UNSIGNED_SHORT.writeInt(output, socketAddress.getPort()); if (address == null) { output.writeUTF(socketAddress.getHostName()); } }
/** * Returns the "hostname:port" that the RPC is connected to */ public String getRemoteAddress() { InetSocketAddress remoteAddress = ((InetSocketAddress) this.channel.remoteAddress()); return remoteAddress.getHostName() + ":" + remoteAddress.getPort(); }