logger.debug("Drop connection - bad remote address, channel: {}", ch.toString()); return true; logger.debug("Drop connection - many new peers are not processed, channel: {}", ch.toString()); return true; !ch.remoteAddress().getAddress().isSiteLocalAddress() && channelManager.isAddressInQueue(ch.remoteAddress().getAddress())) { logger.debug("Drop connection - already processing connection from this host, channel: {}", ch.toString()); return true; logger.debug("Drop connection - the same IP was disconnected recently, channel: {}", ch.toString()); return true; 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); } }