All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bdware.dogp.sample.DOGPGatewayNaiveFiller Maven / Gradle / Ivy

There is a newer version: 1.5.4
Show newest version
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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy