org.bdware.dogp.sample.DOGPGatewayNaiveFiller Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of doip-audit-tool Show documentation
Show all versions of doip-audit-tool Show documentation
doip audit tool developed by bdware
package org.bdware.dogp.sample;
import io.netty.channel.ChannelHandlerContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.bdware.dogp.DOGPRequestHandler;
import org.bdware.dogp.codec.DOGPMessage;
import org.bdware.dogp.codec.InetAddressUtil;
import java.net.InetSocketAddress;
import java.util.concurrent.atomic.AtomicInteger;
public class DOGPGatewayNaiveFiller implements DOGPRequestHandler {
private final InetSocketAddress dstAddress;
byte[] dstIPAndPort;
RecvCounter counter;
public DOGPGatewayNaiveFiller(String ip, int port) {
this.dstIPAndPort = InetAddressUtil.convertIpPortToBytes(ip, port);
this.dstAddress = InetAddressUtil.convertBytesToInetSocketAddress(dstIPAndPort);
counter = new RecvCounter("DOGPGatewayNaiveFiller.class");
counter.start();
}
AtomicInteger i;
static Logger LOGGER = LogManager.getLogger(DOGPGatewayNaiveFiller.class);
@Override
public DOGPMessage onRequest(ChannelHandlerContext ctx, DOGPMessage msg) {
if (msg.opcode == 1)
msg.opcode = 2;
InetSocketAddress sender = msg.getSender();
msg.setSrc(InetAddressUtil.convertInetSocketAddressToBytes(sender));
msg.setDst(this.dstIPAndPort);
msg.setSender(dstAddress);
counter.inc();
// LOGGER.info("rewrite dogp, src:" + ByteUtils.toHexString(msg.getSrc()) + " dst:" + ByteUtils.toHexString(msg.getDst()));
return msg;
}
}