Is there any way to get the ip of the client?
Is there any way to get the ip of the client?
((InetSocketAddress)channel.remoteAddress()).getHostString()
((InetSocketAddress)channel.remoteAddress()).getHostString()
Thanks, but how do I get the connected channel
There are channels in MQTTConnection
NewNettyMQTTHandler uses ChannelHandlerContext to create an MQTTConnection
NewNettyMQTTHandler uses ChannelHandlerContext to create an MQTTConnection
Thank you. Is this part of the moquette source code? I want to get the ip in my moquette interceptor. The first time I use moquette, I don't know if it's the wrong way. The way you said to get the ip through the channel ((InetSocketAddress)channel.remoteAddress()).getHostString() should be fine, but this channel seems to be private and I can't call it @Override public void onConnect( InterceptConnectMessage msg) {
Connect connect = new Connect();
connect.setClient_id(msg.getClientID());
connect.setUsername(msg.getUsername() != null ? msg.getUsername() : "unset");
connect.setStatus(true);
connect.setKeeplive(msg.getKeepAlive());
connect.setCleansession(msg.isCleanSession());
connect.setDatetime(new Timestamp(System.currentTimeMillis()));
log.info("client connect:{}", connect);
connectService.handleClientConnection(connect);
}
@Agoni-sudo in the interceptor interface you can grab all the information present in InterceptConnectMessage, and actually it doesn't contains such information.
Please create an issue describing the desired behavior and label it with enhancement 🙏 and close this.
Use connection callbacks as an example,You can construct an ip property in an InterceptConnectMessage
@Override
public void notifyClientConnected(final MqttConnectMessage msg, String remoteAddress) {
for (final InterceptHandler handler : this.handlers.get(InterceptConnectMessage.class)) {
LOG.debug("Sending MQTT CONNECT message to interceptor. CId={}, interceptorId={}",
msg.payload().clientIdentifier(), handler.getID());
executor.execute(() -> handler.onConnect(new InterceptConnectMessage(msg, remoteAddress)));
}
}
Yep, @Yunustt if you or @Agoni-sudo desire to create a PR for this aspect I'll be happy to review :-)
My requirement is to determine the source of the client based on the IP address, so if I can get the IP address in IAuthenticator, it would be a perfect solution.
