@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; }
private ChannelHandler createSslHandler(SocketChannel channel, SslContext sslContext, boolean needsClientAuth) { SSLEngine sslEngine = sslContext.newEngine( channel.alloc(), channel.remoteAddress().getHostString(), channel.remoteAddress().getPort()); sslEngine.setUseClientMode(false); if (needsClientAuth) { sslEngine.setNeedClientAuth(true); } return new SslHandler(sslEngine); } }
@Override public void initChannel(SocketChannel ch) throws Exception { if (logger.fineEnabled()) logger.fine("GeodeRedisServer-Connection established with " + ch.remoteAddress()); ChannelPipeline p = ch.pipeline(); p.addLast(ByteToCommandDecoder.class.getSimpleName(), new ByteToCommandDecoder()); p.addLast(ExecutionHandlerContext.class.getSimpleName(), new ExecutionHandlerContext(ch, cache, regionCache, GeodeRedisServer.this, pwdB)); } }).option(ChannelOption.SO_REUSEADDR, true).option(ChannelOption.SO_RCVBUF, getBufferSize())
@Override protected void initChannel(SocketChannel ch) throws Exception { final ChannelPipeline p = ch.pipeline(); final UUID uuid = UUID.randomUUID(); LOG.debug("KaaTcpServerInitializer Initializing Channel {} connection from {}:{}", uuid, ch.remoteAddress().getAddress().toString(), ch.remoteAddress().getPort()); Attribute<UUID> uuidAttr = ch.attr(AbstractNettyServer.UUID_KEY); uuidAttr.set(uuid); p.addLast("binaryDecoder", new ByteArrayDecoder()); p.addLast("kaaTcpDecoder", getDecoder()); p.addLast("binaryEncoder", new ByteArrayEncoder()); p.addLast("kaaTcpEncoder", new KaaTcpEncoder()); p.addLast("mainHandler", getMainHandler(uuid)); p.addLast("kaaTcpExceptionHandler", new KaaTcpExceptionHandler()); }
@Override protected void initChannel(SocketChannel ch) throws Exception { final ChannelPipeline p = ch.pipeline(); final UUID uuid = UUID.randomUUID(); LOG.info("DefaultServerInitializer Initializing Channel {} connection from {}:{}", uuid, ch.remoteAddress().getAddress().toString(), ch.remoteAddress().getPort()); Attribute<UUID> uuidAttr = ch.attr(AbstractNettyServer.UUID_KEY); uuidAttr.set(uuid); p.addLast("httpDecoder", new HttpRequestDecoder()); p.addLast("httpAggregator", new HttpObjectAggregator(getClientMaxBodySize())); p.addLast("httpDecoderAux", getRequestDecoder()); p.addLast("httpEncoder", new HttpResponseEncoder()); p.addLast("httpEncoderAux", new ResponseEncoder()); p.addLast("handler", getMainHandler(uuid)); p.addLast("httpExceptionHandler", new DefaultExceptionHandler()); }
@Override protected void channelRead0(ChannelHandlerContext ctx, HttpMessage msg) throws Exception { // If this handler is hit then no upgrade has been attempted and the client is just talking HTTP. if (LOGGER.isWarnEnabled()) { LOGGER.warn("Directly talking: {} (no upgrade was attempted) from {}", msg.protocolVersion(), NetUtil.toSocketAddressString(ch.remoteAddress())); } ChannelPipeline pipeline = ctx.pipeline(); ChannelHandlerContext thisCtx = pipeline.context(this); // 不需要了 pipeline.addAfter(bizGroup, thisCtx.name(), "Http1ChannelHandler", new Http1ServerChannelHandler(serverHandler)); pipeline.replace(this, "HttpObjectAggregator", new HttpObjectAggregator(maxHttpContentLength)); // HttpServerUpgradeHandler -> HttpServerCodec -> HttpObjectAggregator -> Http1ChannelHandler, ctx.fireChannelRead(ReferenceCountUtil.retain(msg)); } });
@Override protected void channelRead0(ChannelHandlerContext ctx, HttpMessage msg) throws Exception { // If this handler is hit then no upgrade has been attempted and the client is just talking HTTP. if (LOGGER.isWarnEnabled()) { LOGGER.warn("Directly talking: {} (no upgrade was attempted) from {}", msg.protocolVersion(), NetUtil.toSocketAddressString(ch.remoteAddress())); } ChannelPipeline pipeline = ctx.pipeline(); ChannelHandlerContext thisCtx = pipeline.context(this); // 不需要了 pipeline.addAfter(bizGroup, thisCtx.name(), "Http1ChannelHandler", new Http1ServerChannelHandler(serverHandler)); pipeline.replace(this, "HttpObjectAggregator", new HttpObjectAggregator(maxHttpContentLength)); // HttpServerUpgradeHandler -> HttpServerCodec -> HttpObjectAggregator -> Http1ChannelHandler, ctx.fireChannelRead(ReferenceCountUtil.retain(msg)); } });
@Override public int compare(SocketChannel t0, SocketChannel t1) { // Should not be null as these are filtered previously in matchingChannels. assert t0 != null && t0.remoteAddress() != null; assert t1 != null && t1.remoteAddress() != null; return t0.remoteAddress().toString().compareTo(t1.remoteAddress().toString()); } };
@Override public boolean apply(SocketChannel input) { return input.isOpen() && input.remoteAddress() != null && addresses.contains(input.remoteAddress()); } }));
@Override protected void initChannel(SocketChannel ch) throws Exception { InetSocketAddress addr = ch.remoteAddress(); SslHandler sslHandler; // for some hosts the hostname and port required, jdk ssl throws handshake_failure if (addr != null) { sslHandler = sslCtx.newHandler(ch.alloc(), addr.getHostName(), addr.getPort()); } else { sslHandler = sslCtx.newHandler(ch.alloc()); } ch.pipeline().addLast(sslHandler) .addLast(new HttpClientCodec()) .addLast(new HttpContentDecompressor()) .addLast(new HttpObjectAggregator(10048576)) .addLast(new ProxyChannelInboundHandler()); } });
public NettyChannel(String name, io.netty.channel.Channel socket, ExecutorService callbackexecutor) { this.name = name; this.socket = socket; this.callbackexecutor = callbackexecutor; if (socket instanceof SocketChannel) { this.remoteAddress = ((SocketChannel) socket).remoteAddress() + ""; } else { this.remoteAddress = "jvm-local"; } }
public UserClientConnectionImpl(SocketChannel channel) { super(channel, "user client", false); uuid = UUID.randomUUID(); remote = channel.remoteAddress(); }
public String getName() { if (name == null) { name = String.format("%s <--> %s (%s)", channel.localAddress(), channel.remoteAddress(), clientName); } return name; }
/** * 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); }
@Override public int compare(SocketChannel t0, SocketChannel t1) { // Should not be null as these are filtered previously in matchingChannels. assert t0 != null && t0.remoteAddress() != null; assert t1 != null && t1.remoteAddress() != null; return t0.remoteAddress().toString().compareTo(t1.remoteAddress().toString()); } };
@Override public void initChannel(SocketChannel ch) throws Exception { if (logger.fineEnabled()) logger.fine("GemFireRedisServer-Connection established with " + ch.remoteAddress()); ChannelPipeline p = ch.pipeline(); p.addLast(ByteToCommandDecoder.class.getSimpleName(), new ByteToCommandDecoder()); p.addLast(ExecutionHandlerContext.class.getSimpleName(), new ExecutionHandlerContext(ch, cache, regionCache, GemFireRedisServer.this, pwdB)); } })
@Override public boolean apply(SocketChannel input) { return input.isOpen() && input.remoteAddress() != null && addresses.contains(input.remoteAddress()); } }));
@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(); }