if (ch.remoteAddress() == null) { logger.debug("Drop connection - bad remote address, channel: {}", ch.toString()); return true; if (!ch.remoteAddress().getAddress().isLoopbackAddress() && !ch.remoteAddress().getAddress().isSiteLocalAddress() && channelManager.isAddressInQueue(ch.remoteAddress().getAddress())) { logger.debug("Drop connection - already processing connection from this host, channel: {}", ch.toString()); return true; if (channelManager.isRecentlyDisconnected(ch.remoteAddress().getAddress())) { logger.debug("Drop connection - the same IP was disconnected recently, channel: {}", ch.toString()); return true; if (nodeManager.isReputationPenalized(ch.remoteAddress())) { logger.debug("Drop connection - bad peer, channel: {}", ch.toString()); return true;
@Override public void initChannel(NioSocketChannel ch) throws Exception { try { if (!peerDiscoveryMode) { logger.debug("Open {} connection, channel: {}", isInbound() ? "inbound" : "outbound", ch.toString()); } if (notEligibleForIncomingConnection(ch)) { ch.disconnect(); return; } final Channel channel = ctx.getBean(Channel.class); channel.setInetSocketAddress(ch.remoteAddress()); channel.init(ch.pipeline(), remoteId, peerDiscoveryMode, channelManager); if(!peerDiscoveryMode) { channelManager.add(channel); } // limit the size of receiving buffer to 1024 ch.config().setRecvByteBufAllocator(new FixedRecvByteBufAllocator(256 * 1024)); ch.config().setOption(ChannelOption.SO_RCVBUF, 256 * 1024); ch.config().setOption(ChannelOption.SO_BACKLOG, 1024); // be aware of channel closing ch.closeFuture().addListener((ChannelFutureListener) future -> { if (!peerDiscoveryMode) { channelManager.notifyDisconnect(channel); } }); } catch (Exception e) { logger.error("Unexpected error: ", e); } }
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) { if (msg instanceof HttpRequest) { HttpRequest req = (HttpRequest) msg; clientIp = ((NioSocketChannel) ctx.channel()).remoteAddress().getAddress().toString().substring(1); requestTime = Instant.now(); reqLine = req.method().toString() + " " + req.getUri() + " " + req.getProtocolVersion().toString(); userAgentRef = headerValueOrDash("Referer", req) + " " + headerValueOrDash("User-Agent", req); lastChunk = false; } ctx.fireChannelRead(msg); }
@Override public void initChannel(final NioSocketChannel channel) throws Exception { if (secureService == null) { log.error("UscSecureService is not initialized!"); return; } log.debug("Received call home TCP connection"); ChannelPipeline p = channel.pipeline(); addCallHomeConnection(channel.remoteAddress(), channel); initAgentPipeline(p, secureService.getTcpServerHandler(channel)); } });
@Override public void initChannel(NioSocketChannel ch) throws Exception { try { InetSocketAddress address = isServerMode() ? ch.remoteAddress() : remoteNode.toAddress(); logger.debug("New {} channel: remoteAddress = {}:{}", isServerMode() ? "inbound" : "outbound", address.getAddress().getHostAddress(), address.getPort());