@Test public void socketToProto_ipv6() throws Exception { InetAddress address = InetAddress.getByName("2001:db8:0:0:0:0:2:1"); int port = 12345; InetSocketAddress socketAddress = new InetSocketAddress(address, port); assertEquals( Address .newBuilder() .setType(Type.TYPE_IPV6) .setAddress("2001:db8::2:1") .setIpPort(12345) .build(), BinlogHelper.socketToProto(socketAddress)); }
@VisibleForTesting static Address socketToProto(SocketAddress address) { checkNotNull(address, "address"); Address.Builder builder = Address.newBuilder(); if (address instanceof InetSocketAddress) { InetAddress inetAddress = ((InetSocketAddress) address).getAddress(); if (inetAddress instanceof Inet4Address) { builder.setType(Type.TYPE_IPV4) .setAddress(InetAddressUtil.toAddrString(inetAddress)); } else if (inetAddress instanceof Inet6Address) { builder.setType(Type.TYPE_IPV6) .setAddress(InetAddressUtil.toAddrString(inetAddress)); } else { logger.log(Level.SEVERE, "unknown type of InetSocketAddress: {}", address); builder.setAddress(address.toString()); } builder.setIpPort(((InetSocketAddress) address).getPort()); } else if (address.getClass().getName().equals("io.netty.channel.unix.DomainSocketAddress")) { builder.setType(Type.TYPE_UNIX) .setAddress(address.toString()); } else { builder.setType(Type.TYPE_UNKNOWN).setAddress(address.toString()); } return builder.build(); }
BinlogHelper { @VisibleForTesting static Address socketToProto(SocketAddress address) { checkNotNull(address, "address"); Address.Builder builder = Address.newBuilder(); if (address instanceof InetSocketAddress) { InetAddress inetAddress = ((InetSocketAddress) address).getAddress(); if (inetAddress instanceof Inet4Address) { builder.setType(Type.TYPE_IPV4) .setAddress(InetAddressUtil.toAddrString(inetAddress)); } else if (inetAddress instanceof Inet6Address) { builder.setType(Type.TYPE_IPV6) .setAddress(InetAddressUtil.toAddrString(inetAddress)); } else { logger.log(Level.SEVERE, "unknown type of InetSocketAddress: {}", address); builder.setAddress(address.toString()); } builder.setIpPort(((InetSocketAddress) address).getPort()); } else if (address.getClass().getName().equals("io.netty.channel.unix.DomainSocketAddress")) { builder.setType(Type.TYPE_UNIX) .setAddress(address.toString()); } else { builder.setType(Type.TYPE_UNKNOWN).setAddress(address.toString()); } return builder.build(); } }
BinlogHelper { @VisibleForTesting static Address socketToProto(SocketAddress address) { checkNotNull(address, "address"); Address.Builder builder = Address.newBuilder(); if (address instanceof InetSocketAddress) { InetAddress inetAddress = ((InetSocketAddress) address).getAddress(); if (inetAddress instanceof Inet4Address) { builder.setType(Type.TYPE_IPV4) .setAddress(InetAddressUtil.toAddrString(inetAddress)); } else if (inetAddress instanceof Inet6Address) { builder.setType(Type.TYPE_IPV6) .setAddress(InetAddressUtil.toAddrString(inetAddress)); } else { logger.log(Level.SEVERE, "unknown type of InetSocketAddress: {}", address); builder.setAddress(address.toString()); } builder.setIpPort(((InetSocketAddress) address).getPort()); } else if (address.getClass().getName().equals("io.netty.channel.unix.DomainSocketAddress")) { builder.setType(Type.TYPE_UNIX) .setAddress(address.toString()); } else { builder.setType(Type.TYPE_UNKNOWN).setAddress(address.toString()); } return builder.build(); } @VisibleForTesting  BinlogHelper(SinkWriter writer); }
BinlogHelper { @VisibleForTesting static Address socketToProto(SocketAddress address) { checkNotNull(address, "address"); Address.Builder builder = Address.newBuilder(); if (address instanceof InetSocketAddress) { InetAddress inetAddress = ((InetSocketAddress) address).getAddress(); if (inetAddress instanceof Inet4Address) { builder.setType(Type.TYPE_IPV4) .setAddress(InetAddressUtil.toAddrString(inetAddress)); } else if (inetAddress instanceof Inet6Address) { builder.setType(Type.TYPE_IPV6) .setAddress(InetAddressUtil.toAddrString(inetAddress)); } else { logger.log(Level.SEVERE, "unknown type of InetSocketAddress: {}", address); builder.setAddress(address.toString()); } builder.setIpPort(((InetSocketAddress) address).getPort()); } else if (address.getClass().getName().equals("io.netty.channel.unix.DomainSocketAddress")) { builder.setType(Type.TYPE_UNIX) .setAddress(address.toString()); } else { builder.setType(Type.TYPE_UNKNOWN).setAddress(address.toString()); } return builder.build(); } @VisibleForTesting  BinlogHelper(SinkWriter writer); ClientInterceptor getClientInterceptor(final long callId); ServerInterceptor getServerInterceptor(final long callId); }
BinlogHelper { @VisibleForTesting static Address socketToProto(SocketAddress address) { checkNotNull(address, "address"); Address.Builder builder = Address.newBuilder(); if (address instanceof InetSocketAddress) { InetAddress inetAddress = ((InetSocketAddress) address).getAddress(); if (inetAddress instanceof Inet4Address) { builder.setType(Type.TYPE_IPV4) .setAddress(InetAddressUtil.toAddrString(inetAddress)); } else if (inetAddress instanceof Inet6Address) { builder.setType(Type.TYPE_IPV6) .setAddress(InetAddressUtil.toAddrString(inetAddress)); } else { logger.log(Level.SEVERE, "unknown type of InetSocketAddress: {}", address); builder.setAddress(address.toString()); } builder.setIpPort(((InetSocketAddress) address).getPort()); } else if (address.getClass().getName().equals("io.netty.channel.unix.DomainSocketAddress")) { builder.setType(Type.TYPE_UNIX) .setAddress(address.toString()); } else { builder.setType(Type.TYPE_UNKNOWN).setAddress(address.toString()); } return builder.build(); } @VisibleForTesting  BinlogHelper(SinkWriter writer); ClientInterceptor getClientInterceptor(final long callId); ServerInterceptor getServerInterceptor(final long callId);  }