@Override protected CC initRemoteConnection(SocketChannel channel){ local=channel.localAddress(); remote=channel.remoteAddress(); return null; }
@Override protected SC initRemoteConnection(SocketChannel channel) { local = channel.localAddress(); remote = channel.remoteAddress(); return null; }
@Override public SocketAddress getLocalSocketAddress() { return ch.localAddress(); }
@Override public boolean isBound() { return ch.localAddress() != null; }
@Override public int getLocalPort() { return ch.localAddress().getPort(); }
@Override public InetAddress getLocalAddress() { return ch.localAddress().getAddress(); }
public String getName() { if (name == null) { name = String.format("%s <--> %s (%s)", channel.localAddress(), channel.remoteAddress(), clientName); } return name; }
private int channel2Id(SocketChannel c) { return c.localAddress().getPort() + c.remoteAddress().getPort(); }
/** * Retrieve the connection information from the current connection directly * @param c the current channel * @return the connection information */ static ConnectionInfo newConnectionInfo(Channel c) { SocketChannel channel = (SocketChannel) c; InetSocketAddress hostAddress = channel.localAddress(); InetSocketAddress remoteAddress = channel.remoteAddress(); String scheme = channel.pipeline().get(SslHandler.class) != null ? "https" : "http"; return new ConnectionInfo(hostAddress, remoteAddress, scheme); }
/** * Retrieve the connection information from the current connection directly * @param c the current channel * @return the connection information */ static ConnectionInfo newConnectionInfo(Channel c) { SocketChannel channel = (SocketChannel) c; InetSocketAddress hostAddress = channel.localAddress(); InetSocketAddress remoteAddress = channel.remoteAddress(); String scheme = channel.pipeline().get(SslHandler.class) != null ? "https" : "http"; return new ConnectionInfo(hostAddress, remoteAddress, scheme); }
static ConnectionInfo parseForwardedInfo(HttpRequest request, SocketChannel channel) { InetSocketAddress hostAddress = channel.localAddress(); InetSocketAddress remoteAddress = channel.remoteAddress(); String scheme = channel.pipeline().get(SslHandler.class) != null ? "https" : "http"; String forwarded = request.headers().get(FORWARDED_HEADER).split(",")[0]; Matcher hostMatcher = FORWARDED_HOST_PATTERN.matcher(forwarded); if (hostMatcher.find()) { hostAddress = parseAddress(hostMatcher.group(1), hostAddress.getPort()); } Matcher protoMatcher = FORWARDED_PROTO_PATTERN.matcher(forwarded); if (protoMatcher.find()) { scheme = protoMatcher.group(1).trim(); } Matcher forMatcher = FORWARDED_FOR_PATTERN.matcher(forwarded); if(forMatcher.find()) { remoteAddress = parseAddress(forMatcher.group(1).trim(), remoteAddress.getPort()); } return new ConnectionInfo(hostAddress, remoteAddress, scheme); }
static ConnectionInfo parseXForwardedInfo(HttpRequest request, SocketChannel channel) { InetSocketAddress hostAddress = channel.localAddress(); InetSocketAddress remoteAddress = channel.remoteAddress(); String scheme = channel.pipeline().get(SslHandler.class) != null ? "https" : "http"; if (request.headers().contains(XFORWARDED_IP_HEADER)) { String remoteIpValue = request.headers().get(XFORWARDED_IP_HEADER).split(",")[0]; remoteAddress = parseAddress(remoteIpValue, remoteAddress.getPort()); } if(request.headers().contains(XFORWARDED_HOST_HEADER)) { if(request.headers().contains(XFORWARDED_PORT_HEADER)) { hostAddress = InetSocketAddressUtil.createUnresolved( request.headers().get(XFORWARDED_HOST_HEADER).split(",")[0].trim(), Integer.parseInt(request.headers().get(XFORWARDED_PORT_HEADER).split(",")[0].trim())); } else { hostAddress = InetSocketAddressUtil.createUnresolved( request.headers().get(XFORWARDED_HOST_HEADER).split(",")[0].trim(), channel.localAddress().getPort()); } } if (request.headers().contains(XFORWARDED_PROTO_HEADER)) { scheme = request.headers().get(XFORWARDED_PROTO_HEADER).trim(); } return new ConnectionInfo(hostAddress, remoteAddress, scheme); }
@Override protected void initChannel(final SocketChannel ch) { final Session session = new TcpSession(); ch.pipeline() .addLast(new TcpPacketDecoder(ch.remoteAddress(), ch.localAddress(), session)) .addLast(new PacketHandler(Protocol.IPFIX, TcpListener.this.dispatcher)) .addLast(new ChannelInboundHandlerAdapter() { @Override public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) throws Exception { cause.printStackTrace(); LOG.warn("Invalid packet: {}", cause.getMessage()); LOG.debug("", cause); ctx.close(); } }); } })
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof HttpRequest) { final HttpRequest request = (HttpRequest) msg; accessLog = new AccessLog() .address(((SocketChannel) ctx.channel()).remoteAddress().getHostString()) .port(((SocketChannel) ctx.channel()).localAddress().getPort()) .method(request.method().name()) .uri(request.uri()) .protocol(request.protocolVersion().text()); } super.channelRead(ctx, msg); }
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof Http2HeadersFrame){ final Http2HeadersFrame requestHeaders = (Http2HeadersFrame) msg; final SocketChannel channel = (SocketChannel) ctx.channel() .parent(); final Http2Headers headers = requestHeaders.headers(); accessLog = new AccessLog() .address(channel.remoteAddress().getHostString()) .port(channel.localAddress().getPort()) .method(headers.method()) .uri(headers.path()) .protocol(H2_PROTOCOL_NAME); } super.channelRead(ctx, msg); }
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof HttpRequest) { final HttpRequest request = (HttpRequest) msg; final SocketChannel channel = (SocketChannel) ctx.channel(); accessLog = new AccessLog() .address(channel.remoteAddress().getHostString()) .port(channel.localAddress().getPort()) .method(request.method().name()) .uri(request.uri()) .protocol(request.protocolVersion().text()); } super.channelRead(ctx, msg); }
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof HttpRequest) { final HttpRequest request = (HttpRequest) msg; final SocketChannel channel = (SocketChannel) ctx.channel(); accessLog = new AccessLog() .address(channel.remoteAddress().getHostString()) .port(channel.localAddress().getPort()) .method(request.method().name()) .uri(request.uri()) .protocol(request.protocolVersion().text()); } super.channelRead(ctx, msg); }
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof Http2HeadersFrame){ final Http2HeadersFrame requestHeaders = (Http2HeadersFrame) msg; final SocketChannel channel = (SocketChannel) ctx.channel() .parent(); final Http2Headers headers = requestHeaders.headers(); accessLog = new AccessLog() .address(channel.remoteAddress().getHostString()) .port(channel.localAddress().getPort()) .method(headers.method()) .uri(headers.path()) .protocol(H2_PROTOCOL_NAME); } super.channelRead(ctx, msg); }
@Override protected void initChannel( SocketChannel channel ) throws Exception { HandshakeClient handshakeClient = new HandshakeClient(); installHandlers( channel, handshakeClient ); log.info( "Scheduling handshake (and timeout) local %s remote %s", channel.localAddress(), channel.remoteAddress() ); scheduleHandshake( channel, handshakeClient, handshakeDelay.newTimeout() ); scheduleTimeout( channel, handshakeClient ); }
@Override public void initChannel( SocketChannel ch ) throws Exception { log.info( "Installing handshake server local %s remote %s", ch.localAddress(), ch.remoteAddress() ); pipelineBuilderFactory.server( ch, log ) .addFraming() .add( "handshake_server_encoder", new ServerMessageEncoder() ) .add( "handshake_server_decoder", new ServerMessageDecoder() ) .add( "handshake_server", createHandshakeServer( ch ) ) .install(); }