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

org.bdware.dogp.sample.DOGPDstNaiveFiller 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;

public class DOGPDstNaiveFiller implements DOGPRequestHandler {
    byte[] ipAndPort;
    RecvCounter counter;

    static Logger LOGGER = LogManager.getLogger(DOGPDstNaiveFiller.class);

    public DOGPDstNaiveFiller(String ip, int port) {
        ipAndPort = new byte[6];
        String[] splited = ip.split("\\.");
        assert splited.length == 4;
        for (int i = 0; i < splited.length; i++) {
            int val = Integer.valueOf(splited[i]);
            ipAndPort[i] = (byte) (val & 0xff);
        }
        ipAndPort[4] = (byte) ((port & 0xff00) >> 8);
        ipAndPort[5] = (byte) (port & 0xff);
        counter = new RecvCounter("DOGPDstNaiveFiller.class");
        counter.start();


    }

    @Override
    public DOGPMessage onRequest(ChannelHandlerContext ctx, DOGPMessage msg) {
        if (msg.opcode == 1)
            msg.opcode = 2;
        counter.inc();
        return msg.setDst(ipAndPort);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy