| 31 | import java.util.concurrent.TimeUnit; |
| 32 | |
| 33 | public abstract class TrackerClient implements TrackerConnector { |
| 34 | |
| 35 | private final boolean secure; |
| 36 | private final long interval; |
| 37 | |
| 38 | private final Bootstrap bootstrap; |
| 39 | |
| 40 | private final int port; |
| 41 | private final String address; |
| 42 | private final String[] devices; |
| 43 | |
| 44 | private final ChannelGroup channelGroup = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE); |
| 45 | |
| 46 | @Override |
| 47 | public boolean isDatagram() { |
| 48 | return false; |
| 49 | } |
| 50 | |
| 51 | @Override |
| 52 | public boolean isSecure() { |
| 53 | return secure; |
| 54 | } |
| 55 | |
| 56 | public TrackerClient(Config config, String protocol) { |
| 57 | secure = config.getBoolean(Keys.PROTOCOL_SSL.withPrefix(protocol)); |
| 58 | interval = config.getLong(Keys.PROTOCOL_INTERVAL.withPrefix(protocol)); |
| 59 | address = config.getString(Keys.PROTOCOL_ADDRESS.withPrefix(protocol)); |
| 60 | port = config.getInteger(Keys.PROTOCOL_PORT.withPrefix(protocol), secure ? 443 : 80); |
| 61 | devices = config.getString(Keys.PROTOCOL_DEVICES.withPrefix(protocol)).split("[, ]"); |
| 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 | engine.setUseClientMode(true); |
| 70 | pipeline.addLast(new SslHandler(engine)); |
| 71 | } |
| 72 | } catch (Exception e) { |
| 73 | throw new RuntimeException(e); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | @Override |
| 78 | protected void addProtocolHandlers(PipelineBuilder pipeline) { |
| 79 | try { |
| 80 | TrackerClient.this.addProtocolHandlers(pipeline, config); |
| 81 | } catch (Exception e) { |
| 82 | throw new RuntimeException(e); |
| 83 | } |
| 84 | } |
| 85 | }; |
| 86 | |
| 87 | var eventLoopGroupFactory = Main.getInjector().getInstance(EventLoopGroupFactory.class); |
| 88 | bootstrap = new Bootstrap() |
| 89 | .group(eventLoopGroupFactory.getWorkerGroup()) |
| 90 | .channel(NioSocketChannel.class) |
nothing calls this directly
no outgoing calls
no test coverage detected