aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/TrackerServer.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2022-01-15 23:19:23 -0800
committerAnton Tananaev <anton.tananaev@gmail.com>2022-01-15 23:19:23 -0800
commit0ce163ba62cc991fee56d9c05fca41c9f7a28143 (patch)
treeecdad61979167b4fc605ba2ec4420709b5c1b0fd /src/main/java/org/traccar/TrackerServer.java
parent93745ce5de3f5004cb98d951794c692db284a2e2 (diff)
downloadtrackermap-server-0ce163ba62cc991fee56d9c05fca41c9f7a28143.tar.gz
trackermap-server-0ce163ba62cc991fee56d9c05fca41c9f7a28143.tar.bz2
trackermap-server-0ce163ba62cc991fee56d9c05fca41c9f7a28143.zip
Finish initial implementation
Diffstat (limited to 'src/main/java/org/traccar/TrackerServer.java')
-rw-r--r--src/main/java/org/traccar/TrackerServer.java24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/main/java/org/traccar/TrackerServer.java b/src/main/java/org/traccar/TrackerServer.java
index caae6c585..8e2fce616 100644
--- a/src/main/java/org/traccar/TrackerServer.java
+++ b/src/main/java/org/traccar/TrackerServer.java
@@ -23,14 +23,18 @@ import io.netty.channel.group.ChannelGroup;
import io.netty.channel.group.DefaultChannelGroup;
import io.netty.channel.socket.nio.NioDatagramChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
+import io.netty.handler.ssl.SslHandler;
import io.netty.util.concurrent.GlobalEventExecutor;
import org.traccar.config.Keys;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLEngine;
import java.net.InetSocketAddress;
public abstract class TrackerServer implements TrackerConnector {
private final boolean datagram;
+ private final boolean secure;
@SuppressWarnings("rawtypes")
private final AbstractBootstrap bootstrap;
@@ -45,14 +49,32 @@ public abstract class TrackerServer implements TrackerConnector {
return datagram;
}
+ @Override
+ public boolean isSecure() {
+ return secure;
+ }
+
public TrackerServer(boolean datagram, String protocol) {
this.datagram = datagram;
+ secure = Context.getConfig().getBoolean(Keys.PROTOCOL_SSL.withPrefix(protocol));
address = Context.getConfig().getString(Keys.PROTOCOL_ADDRESS.withPrefix(protocol));
port = Context.getConfig().getInteger(Keys.PROTOCOL_PORT.withPrefix(protocol));
BasePipelineFactory pipelineFactory = new BasePipelineFactory(this, protocol) {
@Override
+ protected void addTransportHandlers(PipelineBuilder pipeline) {
+ try {
+ if (isSecure()) {
+ SSLEngine engine = SSLContext.getDefault().createSSLEngine();
+ pipeline.addLast(new SslHandler(engine));
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
protected void addProtocolHandlers(PipelineBuilder pipeline) {
TrackerServer.this.addProtocolHandlers(pipeline);
}
@@ -99,7 +121,7 @@ public abstract class TrackerServer implements TrackerConnector {
endpoint = new InetSocketAddress(address, port);
}
- Channel channel = bootstrap.bind(endpoint).sync().channel();
+ Channel channel = bootstrap.bind(endpoint).syncUninterruptibly().channel();
if (channel != null) {
getChannelGroup().add(channel);
}