Search in sources :

Example 1 with DnsProtocolHandler

use of org.apache.directory.server.dns.protocol.DnsProtocolHandler in project netty by netty.

the class TestDnsServer method start.

@Override
public void start() throws IOException {
    InetSocketAddress address = new InetSocketAddress(NetUtil.LOCALHOST4, 0);
    UdpTransport transport = new UdpTransport(address.getHostName(), address.getPort());
    setTransports(transport);
    DatagramAcceptor acceptor = transport.getAcceptor();
    acceptor.setHandler(new DnsProtocolHandler(this, store) {

        @Override
        public void sessionCreated(IoSession session) throws Exception {
            // USe our own codec to support AAAA testing
            session.getFilterChain().addFirst("codec", new ProtocolCodecFilter(new TestDnsProtocolUdpCodecFactory()));
        }
    });
    ((DatagramSessionConfig) acceptor.getSessionConfig()).setReuseAddress(true);
    // Start the listener
    acceptor.bind();
}
Also used : UdpTransport(org.apache.directory.server.protocol.shared.transport.UdpTransport) DatagramAcceptor(org.apache.mina.transport.socket.DatagramAcceptor) InetSocketAddress(java.net.InetSocketAddress) DatagramSessionConfig(org.apache.mina.transport.socket.DatagramSessionConfig) ProtocolCodecFilter(org.apache.mina.filter.codec.ProtocolCodecFilter) DnsProtocolHandler(org.apache.directory.server.dns.protocol.DnsProtocolHandler) DnsException(org.apache.directory.server.dns.DnsException) IOException(java.io.IOException) IoSession(org.apache.mina.core.session.IoSession)

Example 2 with DnsProtocolHandler

use of org.apache.directory.server.dns.protocol.DnsProtocolHandler in project vert.x by eclipse.

the class FakeDNSServer method start.

@Override
public void start() throws IOException {
    UdpTransport transport = new UdpTransport(ipAddress, port);
    setTransports(transport);
    acceptor = transport.getAcceptor();
    acceptor.setHandler(new DnsProtocolHandler(this, new RecordStore() {

        @Override
        public Set<ResourceRecord> getRecords(QuestionRecord question) throws DnsException {
            RecordStore actual = store;
            if (actual == null) {
                return Collections.emptySet();
            } else {
                return actual.getRecords(question);
            }
        }
    }) {

        @Override
        public void sessionCreated(IoSession session) throws Exception {
            // Use our own codec to support AAAA testing
            session.getFilterChain().addFirst("codec", new ProtocolCodecFilter(new TestDnsProtocolUdpCodecFactory()));
        }

        @Override
        public void messageReceived(IoSession session, Object message) {
            if (message instanceof DnsMessage) {
                synchronized (FakeDNSServer.this) {
                    currentMessage.add((DnsMessage) message);
                }
            }
            super.messageReceived(session, message);
        }
    });
    // Allow the port to be reused even if the socket is in TIME_WAIT state
    ((DatagramSessionConfig) acceptor.getSessionConfig()).setReuseAddress(true);
    // Start the listener
    acceptor.bind();
}
Also used : UdpTransport(org.apache.directory.server.protocol.shared.transport.UdpTransport) QuestionRecord(org.apache.directory.server.dns.messages.QuestionRecord) DatagramSessionConfig(org.apache.mina.transport.socket.DatagramSessionConfig) DnsMessage(org.apache.directory.server.dns.messages.DnsMessage) ProtocolCodecFilter(org.apache.mina.filter.codec.ProtocolCodecFilter) ResourceRecord(org.apache.directory.server.dns.messages.ResourceRecord) DnsProtocolHandler(org.apache.directory.server.dns.protocol.DnsProtocolHandler) DnsException(org.apache.directory.server.dns.DnsException) IOException(java.io.IOException) RecordStore(org.apache.directory.server.dns.store.RecordStore) IoSession(org.apache.mina.core.session.IoSession)

Example 3 with DnsProtocolHandler

use of org.apache.directory.server.dns.protocol.DnsProtocolHandler in project netty by netty.

the class TestDnsServer method start.

/**
 * Start the {@link TestDnsServer} but drop all {@code AAAA} queries and not send any response to these at all.
 */
public void start(final boolean dropAAAAQueries) throws IOException {
    InetSocketAddress address = new InetSocketAddress(NetUtil.LOCALHOST4, 0);
    UdpTransport transport = new UdpTransport(address.getHostName(), address.getPort());
    setTransports(transport);
    DatagramAcceptor acceptor = transport.getAcceptor();
    acceptor.setHandler(new DnsProtocolHandler(this, store) {

        @Override
        public void sessionCreated(IoSession session) {
            // USe our own codec to support AAAA testing
            session.getFilterChain().addFirst("codec", new ProtocolCodecFilter(new TestDnsProtocolUdpCodecFactory(dropAAAAQueries)));
        }
    });
    ((DatagramSessionConfig) acceptor.getSessionConfig()).setReuseAddress(true);
    // Start the listener
    acceptor.bind();
}
Also used : UdpTransport(org.apache.directory.server.protocol.shared.transport.UdpTransport) DatagramAcceptor(org.apache.mina.transport.socket.DatagramAcceptor) InetSocketAddress(java.net.InetSocketAddress) DatagramSessionConfig(org.apache.mina.transport.socket.DatagramSessionConfig) ProtocolCodecFilter(org.apache.mina.filter.codec.ProtocolCodecFilter) DnsProtocolHandler(org.apache.directory.server.dns.protocol.DnsProtocolHandler) IoSession(org.apache.mina.core.session.IoSession)

Aggregations

DnsProtocolHandler (org.apache.directory.server.dns.protocol.DnsProtocolHandler)3 UdpTransport (org.apache.directory.server.protocol.shared.transport.UdpTransport)3 IoSession (org.apache.mina.core.session.IoSession)3 ProtocolCodecFilter (org.apache.mina.filter.codec.ProtocolCodecFilter)3 DatagramSessionConfig (org.apache.mina.transport.socket.DatagramSessionConfig)3 IOException (java.io.IOException)2 InetSocketAddress (java.net.InetSocketAddress)2 DnsException (org.apache.directory.server.dns.DnsException)2 DatagramAcceptor (org.apache.mina.transport.socket.DatagramAcceptor)2 DnsMessage (org.apache.directory.server.dns.messages.DnsMessage)1 QuestionRecord (org.apache.directory.server.dns.messages.QuestionRecord)1 ResourceRecord (org.apache.directory.server.dns.messages.ResourceRecord)1 RecordStore (org.apache.directory.server.dns.store.RecordStore)1