directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erodrig...@apache.org
Subject svn commit: r548235 - in /directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns: Main.java protocol/DnsProtocolHandler.java protocol/DnsProtocolTcpCodecFactory.java protocol/DnsTcpDecoder.java protocol/DnsTcpEncoder.java
Date Mon, 18 Jun 2007 06:48:51 GMT
Author: erodriguez
Date: Sun Jun 17 23:48:50 2007
New Revision: 548235

URL: http://svn.apache.org/viewvc?view=rev&rev=548235
Log:
Added TCP support to DNS protocol.
o  Added TCP codecs
o  Enabled TCP vs. UDP in handler.
o  Enabled TCP in standalone Main class.

Added:
    directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsProtocolTcpCodecFactory.java
  (with props)
    directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsTcpDecoder.java
  (with props)
    directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsTcpEncoder.java
  (with props)
Modified:
    directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/Main.java
    directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsProtocolHandler.java

Modified: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/Main.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/Main.java?view=diff&rev=548235&r1=548234&r2=548235
==============================================================================
--- directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/Main.java
(original)
+++ directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/Main.java
Sun Jun 17 23:48:50 2007
@@ -26,6 +26,7 @@
 import org.apache.mina.common.IoAcceptor;
 import org.apache.mina.transport.socket.nio.DatagramAcceptor;
 import org.apache.mina.transport.socket.nio.DatagramAcceptorConfig;
+import org.apache.mina.transport.socket.nio.SocketAcceptor;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -46,10 +47,12 @@
     private static final int MAX_THREADS_DEFAULT = 4;
 
     protected static IoAcceptor udpAcceptor;
+    protected static IoAcceptor tcpAcceptor;
     protected static ThreadPoolExecutor threadPoolExecutor;
     protected static ExecutorThreadModel threadModel = ExecutorThreadModel.getInstance( "ApacheDS"
);
 
     private static DnsServer udpDnsServer;
+    private static DnsServer tcpDnsServer;
 
 
     /**
@@ -66,6 +69,7 @@
         threadModel.setExecutor( threadPoolExecutor );
 
         udpAcceptor = new DatagramAcceptor();
+        tcpAcceptor = new SocketAcceptor();
 
         new Main().go();
     }
@@ -96,10 +100,11 @@
 
         try
         {
-            DatagramAcceptorConfig udpConfig = new DatagramAcceptorConfig();
-            udpConfig.setThreadModel( threadModel );
+            DatagramAcceptorConfig serviceConfig = new DatagramAcceptorConfig();
+            serviceConfig.setThreadModel( threadModel );
 
-            udpDnsServer = new DnsServer( dnsConfig, udpAcceptor, udpConfig, store );
+            udpDnsServer = new DnsServer( dnsConfig, udpAcceptor, serviceConfig, store );
+            tcpDnsServer = new DnsServer( dnsConfig, tcpAcceptor, serviceConfig, store );
         }
         catch ( Throwable t )
         {
@@ -120,6 +125,18 @@
             }
 
             udpDnsServer = null;
+        }
+
+        if ( tcpDnsServer != null )
+        {
+            tcpDnsServer.destroy();
+
+            if ( log.isInfoEnabled() )
+            {
+                log.info( "Unbind of DNS Service complete: " + tcpDnsServer );
+            }
+
+            tcpDnsServer = null;
         }
     }
 }

Modified: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsProtocolHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsProtocolHandler.java?view=diff&rev=548235&r1=548234&r2=548235
==============================================================================
--- directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsProtocolHandler.java
(original)
+++ directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsProtocolHandler.java
Sun Jun 17 23:48:50 2007
@@ -37,6 +37,7 @@
 import org.apache.mina.common.IdleStatus;
 import org.apache.mina.common.IoHandler;
 import org.apache.mina.common.IoSession;
+import org.apache.mina.common.TransportType;
 import org.apache.mina.filter.codec.ProtocolCodecFilter;
 import org.apache.mina.handler.chain.IoHandlerCommand;
 import org.slf4j.Logger;
@@ -74,9 +75,21 @@
 
     public void sessionCreated( IoSession session ) throws Exception
     {
-        log.debug( "{} CREATED", session.getRemoteAddress() );
-
-        session.getFilterChain().addFirst( "codec", new ProtocolCodecFilter( DnsProtocolUdpCodecFactory.getInstance()
) );
+        if ( log.isDebugEnabled() )
+        {
+            log.debug( session.getRemoteAddress() + " CREATED : " + session.getTransportType()
);
+        }
+
+        if ( session.getTransportType() == TransportType.DATAGRAM )
+        {
+            session.getFilterChain().addFirst( "codec",
+                new ProtocolCodecFilter( DnsProtocolUdpCodecFactory.getInstance() ) );
+        }
+        else
+        {
+            session.getFilterChain().addFirst( "codec",
+                new ProtocolCodecFilter( DnsProtocolTcpCodecFactory.getInstance() ) );
+        }
     }
 
 

Added: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsProtocolTcpCodecFactory.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsProtocolTcpCodecFactory.java?view=auto&rev=548235
==============================================================================
--- directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsProtocolTcpCodecFactory.java
(added)
+++ directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsProtocolTcpCodecFactory.java
Sun Jun 17 23:48:50 2007
@@ -0,0 +1,67 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.server.dns.protocol;
+
+
+import org.apache.mina.filter.codec.ProtocolCodecFactory;
+import org.apache.mina.filter.codec.ProtocolDecoder;
+import org.apache.mina.filter.codec.ProtocolEncoder;
+
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 545041 $, $Date: 2007-06-06 20:31:34 -0700 (Wed, 06 Jun 2007) $
+ */
+public class DnsProtocolTcpCodecFactory implements ProtocolCodecFactory
+{
+    private static final DnsProtocolTcpCodecFactory INSTANCE = new DnsProtocolTcpCodecFactory();
+
+
+    /**
+     * Returns the singleton instance of {@link DnsProtocolTcpCodecFactory}.
+     *
+     * @return The singleton instance of {@link DnsProtocolTcpCodecFactory}.
+     */
+    public static DnsProtocolTcpCodecFactory getInstance()
+    {
+        return INSTANCE;
+    }
+
+
+    private DnsProtocolTcpCodecFactory()
+    {
+        // Private constructor prevents instantiation outside this class.
+    }
+
+
+    public ProtocolEncoder getEncoder()
+    {
+        // Create a new encoder.
+        return new DnsTcpEncoder();
+    }
+
+
+    public ProtocolDecoder getDecoder()
+    {
+        // Create a new decoder.
+        return new DnsTcpDecoder();
+    }
+}

Propchange: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsProtocolTcpCodecFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsTcpDecoder.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsTcpDecoder.java?view=auto&rev=548235
==============================================================================
--- directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsTcpDecoder.java
(added)
+++ directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsTcpDecoder.java
Sun Jun 17 23:48:50 2007
@@ -0,0 +1,93 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.server.dns.protocol;
+
+
+import org.apache.directory.server.dns.io.decoder.DnsMessageDecoder;
+import org.apache.mina.common.BufferDataException;
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.codec.CumulativeProtocolDecoder;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+
+
+/**
+ * A {@link CumulativeProtocolDecoder} which supports DNS operation over TCP,
+ * by reassembling split packets prior to decoding.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 545041 $, $Date: 2007-06-06 20:31:34 -0700 (Wed, 06 Jun 2007) $
+ */
+public class DnsTcpDecoder extends CumulativeProtocolDecoder
+{
+    private DnsMessageDecoder decoder = new DnsMessageDecoder();
+
+    private int maxObjectSize = 16384; // 16KB
+
+
+    /**
+     * Returns the allowed maximum size of the object to be decoded.
+     * If the size of the object to be decoded exceeds this value, this
+     * decoder will throw a {@link BufferDataException}.  The default
+     * value is <tt>16384</tt> (16KB).
+     * 
+     * @return The max object size.
+     */
+    public int getMaxObjectSize()
+    {
+        return maxObjectSize;
+    }
+
+
+    /**
+     * Sets the allowed maximum size of the object to be decoded.
+     * If the size of the object to be decoded exceeds this value, this
+     * decoder will throw a {@link BufferDataException}.  The default
+     * value is <tt>16384</tt> (16KB).
+     * 
+     * @param maxObjectSize 
+     */
+    public void setMaxObjectSize( int maxObjectSize )
+    {
+        if ( maxObjectSize <= 0 )
+        {
+            throw new IllegalArgumentException( "maxObjectSize: " + maxObjectSize );
+        }
+
+        this.maxObjectSize = maxObjectSize;
+    }
+
+
+    @Override
+    protected boolean doDecode( IoSession session, ByteBuffer in, ProtocolDecoderOutput out
) throws Exception
+    {
+        if ( !in.prefixedDataAvailable( 2, maxObjectSize ) )
+        {
+            return false;
+        }
+
+        in.getShort();
+
+        out.write( decoder.decode( in ) );
+
+        return true;
+    }
+}

Propchange: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsTcpDecoder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsTcpEncoder.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsTcpEncoder.java?view=auto&rev=548235
==============================================================================
--- directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsTcpEncoder.java
(added)
+++ directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsTcpEncoder.java
Sun Jun 17 23:48:50 2007
@@ -0,0 +1,69 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.server.dns.protocol;
+
+
+import org.apache.directory.server.dns.io.encoder.DnsMessageEncoder;
+import org.apache.directory.server.dns.messages.DnsMessage;
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.codec.ProtocolEncoderAdapter;
+import org.apache.mina.filter.codec.ProtocolEncoderOutput;
+
+
+/**
+ * A ProtocolEncoder for use in the MINA framework that uses the 
+ * DnsMessageEncoder to encode DnsMessages.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 545041 $, $Date: 2007-06-06 20:31:34 -0700 (Wed, 06 Jun 2007) $
+ */
+public class DnsTcpEncoder extends ProtocolEncoderAdapter
+{
+    private DnsMessageEncoder encoder = new DnsMessageEncoder();
+
+
+    public void encode( IoSession session, Object message, ProtocolEncoderOutput out )
+    {
+        ByteBuffer buf = ByteBuffer.allocate( 1024 );
+
+        // make space for short length
+        buf.putShort( ( short ) 0 );
+
+        encoder.encode( buf, ( DnsMessage ) message );
+
+        // mark position
+        int end = buf.position();
+
+        // length is the data minus 2 bytes for the pre-pended length
+        short recordLength = ( short ) ( end - 2 );
+
+        // write the length
+        buf.rewind();
+        buf.putShort( recordLength );
+
+        // set the position back before flipping the buffer
+        buf.position( end );
+        buf.flip();
+
+        out.write( buf );
+    }
+}

Propchange: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsTcpEncoder.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message