aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/handler/RemoteAddressHandler.java
diff options
context:
space:
mode:
authorcasswarry0 <casswarry0@gmail.com>2023-01-17 17:14:53 -0700
committercasswarry0 <casswarry0@gmail.com>2023-01-17 17:14:53 -0700
commit7338b8730949ed027b3f8b31d7dca20687ebbb8b (patch)
treec2d171e6121818ab511460a786f69aab97a2a628 /src/main/java/org/traccar/handler/RemoteAddressHandler.java
parentcdecd3fa4427a382c0b09f8ad9d69ec14388960a (diff)
parent85501f9cf4918d5eee345f83aed7a31eecb26b8d (diff)
downloadtrackermap-server-7338b8730949ed027b3f8b31d7dca20687ebbb8b.tar.gz
trackermap-server-7338b8730949ed027b3f8b31d7dca20687ebbb8b.tar.bz2
trackermap-server-7338b8730949ed027b3f8b31d7dca20687ebbb8b.zip
Merge branch 'master' into develop
Diffstat (limited to 'src/main/java/org/traccar/handler/RemoteAddressHandler.java')
-rw-r--r--src/main/java/org/traccar/handler/RemoteAddressHandler.java26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/main/java/org/traccar/handler/RemoteAddressHandler.java b/src/main/java/org/traccar/handler/RemoteAddressHandler.java
index c09b8c39a..e18d34ef2 100644
--- a/src/main/java/org/traccar/handler/RemoteAddressHandler.java
+++ b/src/main/java/org/traccar/handler/RemoteAddressHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2022 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,22 +18,36 @@ package org.traccar.handler;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
+import org.traccar.config.Config;
+import org.traccar.config.Keys;
import org.traccar.model.Position;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import java.net.InetSocketAddress;
+@Singleton
@ChannelHandler.Sharable
public class RemoteAddressHandler extends ChannelInboundHandlerAdapter {
+ private final boolean enabled;
+
+ @Inject
+ public RemoteAddressHandler(Config config) {
+ enabled = config.getBoolean(Keys.PROCESSING_REMOTE_ADDRESS_ENABLE);
+ }
+
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
- InetSocketAddress remoteAddress = (InetSocketAddress) ctx.channel().remoteAddress();
- String hostAddress = remoteAddress != null ? remoteAddress.getAddress().getHostAddress() : null;
+ if (enabled) {
+ InetSocketAddress remoteAddress = (InetSocketAddress) ctx.channel().remoteAddress();
+ String hostAddress = remoteAddress != null ? remoteAddress.getAddress().getHostAddress() : null;
- if (msg instanceof Position) {
- Position position = (Position) msg;
- position.set(Position.KEY_IP, hostAddress);
+ if (msg instanceof Position) {
+ Position position = (Position) msg;
+ position.set(Position.KEY_IP, hostAddress);
+ }
}
ctx.fireChannelRead(msg);