| 33 | import java.net.InetSocketAddress; |
| 34 | |
| 35 | public abstract class TrackerServer implements TrackerConnector { |
| 36 | |
| 37 | private final boolean datagram; |
| 38 | private final boolean secure; |
| 39 | |
| 40 | @SuppressWarnings("rawtypes") |
| 41 | private final AbstractBootstrap bootstrap; |
| 42 | |
| 43 | private final int port; |
| 44 | private final String address; |
| 45 | |
| 46 | private final ChannelGroup channelGroup = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE); |
| 47 | |
| 48 | @Override |
| 49 | public boolean isDatagram() { |
| 50 | return datagram; |
| 51 | } |
| 52 | |
| 53 | @Override |
| 54 | public boolean isSecure() { |
| 55 | return secure; |
| 56 | } |
| 57 | |
| 58 | public TrackerServer(Config config, String protocol, boolean datagram) { |
| 59 | secure = config.getBoolean(Keys.PROTOCOL_SSL.withPrefix(protocol)); |
| 60 | address = config.getString(Keys.PROTOCOL_ADDRESS.withPrefix(protocol)); |
| 61 | port = config.getInteger(Keys.PROTOCOL_PORT.withPrefix(protocol)); |
| 62 | |
| 63 | BasePipelineFactory pipelineFactory = new BasePipelineFactory(this, config, protocol) { |
| 64 | @Override |
| 65 | protected void addTransportHandlers(PipelineBuilder pipeline) { |
| 66 | try { |
| 67 | if (isSecure()) { |
| 68 | SSLEngine engine = SSLContext.getDefault().createSSLEngine(); |
| 69 | pipeline.addLast(new SslHandler(engine)); |
| 70 | } |
| 71 | } catch (Exception e) { |
| 72 | throw new RuntimeException(e); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | protected void addProtocolHandlers(PipelineBuilder pipeline) { |
| 78 | TrackerServer.this.addProtocolHandlers(pipeline, config); |
| 79 | } |
| 80 | }; |
| 81 | |
| 82 | this.datagram = datagram; |
| 83 | var eventLoopGroupFactory = Main.getInjector().getInstance(EventLoopGroupFactory.class); |
| 84 | if (datagram) { |
| 85 | bootstrap = new Bootstrap() |
| 86 | .group(eventLoopGroupFactory.getWorkerGroup()) |
| 87 | .channel(NioDatagramChannel.class) |
| 88 | .handler(pipelineFactory); |
| 89 | } else { |
| 90 | bootstrap = new ServerBootstrap() |
| 91 | .group(eventLoopGroupFactory.getBossGroup(), eventLoopGroupFactory.getWorkerGroup()) |
| 92 | .channel(NioServerSocketChannel.class) |
nothing calls this directly
no outgoing calls
no test coverage detected