查看本类的 API文档回源码主页即时通讯网 - 即时通讯开发者社区!
1   /*
2    * Copyright 2018 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   https://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  package io.netty.resolver.dns;
17  
18  import java.net.UnknownHostException;
19  import java.util.List;
20  
21  import io.netty.channel.Channel;
22  import io.netty.channel.EventLoop;
23  import io.netty.handler.codec.dns.DnsQuestion;
24  import io.netty.handler.codec.dns.DnsRecord;
25  import io.netty.handler.codec.dns.DnsRecordType;
26  import io.netty.util.ReferenceCountUtil;
27  import io.netty.util.concurrent.Future;
28  import io.netty.util.concurrent.Promise;
29  
30  final class DnsRecordResolveContext extends DnsResolveContext<DnsRecord> {
31  
32      DnsRecordResolveContext(DnsNameResolver parent, Channel channel, Future<? extends Channel> channelReadyFuture,
33                              Promise<?> originalPromise, DnsQuestion question, DnsRecord[] additionals,
34                              DnsServerAddressStream nameServerAddrs, int allowedQueries) {
35          this(parent, channel, channelReadyFuture, originalPromise, question.name(), question.dnsClass(),
36               new DnsRecordType[] { question.type() },
37               additionals, nameServerAddrs, allowedQueries);
38      }
39  
40      private DnsRecordResolveContext(DnsNameResolver parent, Channel channel,
41                                      Future<? extends Channel> channelReadyFuture, Promise<?> originalPromise,
42                                      String hostname, int dnsClass, DnsRecordType[] expectedTypes,
43                                      DnsRecord[] additionals,
44                                      DnsServerAddressStream nameServerAddrs,
45                                      int allowedQueries) {
46          super(parent, channel, channelReadyFuture, originalPromise, hostname, dnsClass, expectedTypes,
47                  additionals, nameServerAddrs, allowedQueries);
48      }
49  
50      @Override
51      DnsResolveContext<DnsRecord> newResolverContext(DnsNameResolver parent, Channel channel,
52                                                      Future<? extends Channel> channelReadyFuture,
53                                                      Promise<?> originalPromise,
54                                                      String hostname,
55                                                      int dnsClass, DnsRecordType[] expectedTypes,
56                                                      DnsRecord[] additionals,
57                                                      DnsServerAddressStream nameServerAddrs,
58                                                      int allowedQueries) {
59          return new DnsRecordResolveContext(parent, channel, channelReadyFuture, originalPromise, hostname, dnsClass,
60                                             expectedTypes, additionals, nameServerAddrs, allowedQueries);
61      }
62  
63      @Override
64      DnsRecord convertRecord(DnsRecord record, String hostname, DnsRecord[] additionals, EventLoop eventLoop) {
65          return ReferenceCountUtil.retain(record);
66      }
67  
68      @Override
69      List<DnsRecord> filterResults(List<DnsRecord> unfiltered) {
70          return unfiltered;
71      }
72  
73      @Override
74      boolean isCompleteEarly(DnsRecord resolved) {
75          return false;
76      }
77  
78      @Override
79      boolean isDuplicateAllowed() {
80          return true;
81      }
82  
83      @Override
84      void cache(String hostname, DnsRecord[] additionals, DnsRecord result, DnsRecord convertedResult) {
85          // Do not cache.
86          // XXX: When we implement cache, we would need to retain the reference count of the result record.
87      }
88  
89      @Override
90      void cache(String hostname, DnsRecord[] additionals, UnknownHostException cause) {
91          // Do not cache.
92          // XXX: When we implement cache, we would need to retain the reference count of the result record.
93      }
94  
95      @Override
96      DnsCnameCache cnameCache() {
97          // We don't use a cache here at all as we also don't cache if we end up using the DnsRecordResolverContext.
98          return NoopDnsCnameCache.INSTANCE;
99      }
100 }