From c7318ccd4c003ed82b4a66cde138d8f73331dc53 Mon Sep 17 00:00:00 2001 From: nathan Date: Mon, 29 Jan 2018 00:50:25 +0100 Subject: [PATCH] Moved client handlers into their own package --- .../dns/DatagramDnsResponseDecoder.java | 55 ----------------- .../DatagramDnsQueryEncoder.java | 24 ++++---- .../DatagramDnsResponseDecoder.java | 60 +++++++++++++++++++ 3 files changed, 73 insertions(+), 66 deletions(-) delete mode 100644 src/dorkbox/network/dns/DatagramDnsResponseDecoder.java rename src/dorkbox/network/dns/{ => clientHandlers}/DatagramDnsQueryEncoder.java (71%) create mode 100644 src/dorkbox/network/dns/clientHandlers/DatagramDnsResponseDecoder.java diff --git a/src/dorkbox/network/dns/DatagramDnsResponseDecoder.java b/src/dorkbox/network/dns/DatagramDnsResponseDecoder.java deleted file mode 100644 index 1a55938a..00000000 --- a/src/dorkbox/network/dns/DatagramDnsResponseDecoder.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2015 The Netty Project - * - * The Netty Project 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 dorkbox.network.dns; - -import java.util.List; - -import dorkbox.network.dns.exceptions.WireParseException; -import dorkbox.network.dns.records.Header; -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandler; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.socket.DatagramPacket; -import io.netty.handler.codec.MessageToMessageDecoder; -import io.netty.util.internal.UnstableApi; - -/** - * Decodes a {@link DatagramPacket} into a {@link DnsResponse}. - */ -@UnstableApi -@ChannelHandler.Sharable -public class DatagramDnsResponseDecoder extends MessageToMessageDecoder { - - /** - * Creates a new DNS Response decoder - */ - public DatagramDnsResponseDecoder() { - } - - @Override - protected void decode(ChannelHandlerContext ctx, DatagramPacket packet, List out) throws Exception { - final ByteBuf buf = packet.content(); - - // Check that the response is long enough. - if (buf.readableBytes() < Header.LENGTH) { - throw new WireParseException("invalid DNS header - " + "too short"); - } - - DnsInput dnsInput = new DnsInput(buf); - DnsResponse dnsMessage = new DnsResponse(packet.sender(), packet.recipient(), dnsInput); - out.add(dnsMessage); - } -} diff --git a/src/dorkbox/network/dns/DatagramDnsQueryEncoder.java b/src/dorkbox/network/dns/clientHandlers/DatagramDnsQueryEncoder.java similarity index 71% rename from src/dorkbox/network/dns/DatagramDnsQueryEncoder.java rename to src/dorkbox/network/dns/clientHandlers/DatagramDnsQueryEncoder.java index f8b9b853..a6d5350e 100644 --- a/src/dorkbox/network/dns/DatagramDnsQueryEncoder.java +++ b/src/dorkbox/network/dns/clientHandlers/DatagramDnsQueryEncoder.java @@ -1,23 +1,25 @@ /* - * Copyright 2015 The Netty Project + * Copyright 2018 dorkbox, llc. * - * The Netty Project 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: + * Licensed 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 + * 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. + * 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 dorkbox.network.dns; +package dorkbox.network.dns.clientHandlers; import java.net.InetSocketAddress; import java.util.List; +import dorkbox.network.dns.DnsOutput; +import dorkbox.network.dns.DnsQuestion; import dorkbox.network.dns.records.DnsMessage; import io.netty.buffer.ByteBuf; import io.netty.channel.AddressedEnvelope; diff --git a/src/dorkbox/network/dns/clientHandlers/DatagramDnsResponseDecoder.java b/src/dorkbox/network/dns/clientHandlers/DatagramDnsResponseDecoder.java new file mode 100644 index 00000000..f9fd6ff7 --- /dev/null +++ b/src/dorkbox/network/dns/clientHandlers/DatagramDnsResponseDecoder.java @@ -0,0 +1,60 @@ +/* + * Copyright 2018 dorkbox, llc. + * + * Licensed 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 dorkbox.network.dns.clientHandlers; + +import java.util.List; + +import dorkbox.network.dns.DnsInput; +import dorkbox.network.dns.DnsResponse; +import dorkbox.network.dns.exceptions.WireParseException; +import dorkbox.network.dns.records.Header; +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandler; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.socket.DatagramPacket; +import io.netty.handler.codec.MessageToMessageDecoder; +import io.netty.util.internal.UnstableApi; + +/** + * Decodes a {@link DatagramPacket} into a {@link DnsResponse}. + */ +@UnstableApi +@ChannelHandler.Sharable +public +class DatagramDnsResponseDecoder extends MessageToMessageDecoder { + + /** + * Creates a new DNS Response decoder + */ + public + DatagramDnsResponseDecoder() { + } + + @Override + protected + void decode(ChannelHandlerContext ctx, DatagramPacket packet, List out) throws Exception { + final ByteBuf buf = packet.content(); + + // Check that the response is long enough. + if (buf.readableBytes() < Header.LENGTH) { + throw new WireParseException("invalid DNS header - " + "too short"); + } + + DnsInput dnsInput = new DnsInput(buf); + DnsResponse dnsMessage = new DnsResponse(dnsInput, packet.sender(), packet.recipient()); + out.add(dnsMessage); + } +}