1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.handler.codec.dns;
17
18 import io.netty.channel.AddressedEnvelope;
19
20 import java.net.InetSocketAddress;
21 import java.net.SocketAddress;
22
23
24
25
26 public class DatagramDnsResponse extends DefaultDnsResponse
27 implements AddressedEnvelope<DatagramDnsResponse, InetSocketAddress> {
28
29 private final InetSocketAddress sender;
30 private final InetSocketAddress recipient;
31
32
33
34
35
36
37
38
39
40 public DatagramDnsResponse(InetSocketAddress sender, InetSocketAddress recipient, int id) {
41 this(sender, recipient, id, DnsOpCode.QUERY, DnsResponseCode.NOERROR);
42 }
43
44
45
46
47
48
49
50
51
52 public DatagramDnsResponse(InetSocketAddress sender, InetSocketAddress recipient, int id, DnsOpCode opCode) {
53 this(sender, recipient, id, opCode, DnsResponseCode.NOERROR);
54 }
55
56
57
58
59
60
61
62
63
64
65 public DatagramDnsResponse(
66 InetSocketAddress sender, InetSocketAddress recipient,
67 int id, DnsOpCode opCode, DnsResponseCode responseCode) {
68 super(id, opCode, responseCode);
69
70 if (recipient == null && sender == null) {
71 throw new NullPointerException("recipient and sender");
72 }
73
74 this.sender = sender;
75 this.recipient = recipient;
76 }
77
78 @Override
79 public DatagramDnsResponse content() {
80 return this;
81 }
82
83 @Override
84 public InetSocketAddress sender() {
85 return sender;
86 }
87
88 @Override
89 public InetSocketAddress recipient() {
90 return recipient;
91 }
92
93 @Override
94 public DatagramDnsResponse setAuthoritativeAnswer(boolean authoritativeAnswer) {
95 return (DatagramDnsResponse) super.setAuthoritativeAnswer(authoritativeAnswer);
96 }
97
98 @Override
99 public DatagramDnsResponse setTruncated(boolean truncated) {
100 return (DatagramDnsResponse) super.setTruncated(truncated);
101 }
102
103 @Override
104 public DatagramDnsResponse setRecursionAvailable(boolean recursionAvailable) {
105 return (DatagramDnsResponse) super.setRecursionAvailable(recursionAvailable);
106 }
107
108 @Override
109 public DatagramDnsResponse setCode(DnsResponseCode code) {
110 return (DatagramDnsResponse) super.setCode(code);
111 }
112
113 @Override
114 public DatagramDnsResponse setId(int id) {
115 return (DatagramDnsResponse) super.setId(id);
116 }
117
118 @Override
119 public DatagramDnsResponse setOpCode(DnsOpCode opCode) {
120 return (DatagramDnsResponse) super.setOpCode(opCode);
121 }
122
123 @Override
124 public DatagramDnsResponse setRecursionDesired(boolean recursionDesired) {
125 return (DatagramDnsResponse) super.setRecursionDesired(recursionDesired);
126 }
127
128 @Override
129 public DatagramDnsResponse setZ(int z) {
130 return (DatagramDnsResponse) super.setZ(z);
131 }
132
133 @Override
134 public DatagramDnsResponse setRecord(DnsSection section, DnsRecord record) {
135 return (DatagramDnsResponse) super.setRecord(section, record);
136 }
137
138 @Override
139 public DatagramDnsResponse addRecord(DnsSection section, DnsRecord record) {
140 return (DatagramDnsResponse) super.addRecord(section, record);
141 }
142
143 @Override
144 public DatagramDnsResponse addRecord(DnsSection section, int index, DnsRecord record) {
145 return (DatagramDnsResponse) super.addRecord(section, index, record);
146 }
147
148 @Override
149 public DatagramDnsResponse clear(DnsSection section) {
150 return (DatagramDnsResponse) super.clear(section);
151 }
152
153 @Override
154 public DatagramDnsResponse clear() {
155 return (DatagramDnsResponse) super.clear();
156 }
157
158 @Override
159 public DatagramDnsResponse touch() {
160 return (DatagramDnsResponse) super.touch();
161 }
162
163 @Override
164 public DatagramDnsResponse touch(Object hint) {
165 return (DatagramDnsResponse) super.touch(hint);
166 }
167
168 @Override
169 public DatagramDnsResponse retain() {
170 return (DatagramDnsResponse) super.retain();
171 }
172
173 @Override
174 public DatagramDnsResponse retain(int increment) {
175 return (DatagramDnsResponse) super.retain(increment);
176 }
177
178 @Override
179 public boolean equals(Object obj) {
180 if (this == obj) {
181 return true;
182 }
183
184 if (!super.equals(obj)) {
185 return false;
186 }
187
188 if (!(obj instanceof AddressedEnvelope)) {
189 return false;
190 }
191
192 @SuppressWarnings("unchecked")
193 final AddressedEnvelope<?, SocketAddress> that = (AddressedEnvelope<?, SocketAddress>) obj;
194 if (sender() == null) {
195 if (that.sender() != null) {
196 return false;
197 }
198 } else if (!sender().equals(that.sender())) {
199 return false;
200 }
201
202 if (recipient() == null) {
203 return that.recipient() == null;
204 } else {
205 return recipient().equals(that.recipient());
206 }
207 }
208
209 @Override
210 public int hashCode() {
211 int hashCode = super.hashCode();
212 if (sender() != null) {
213 hashCode = hashCode * 31 + sender().hashCode();
214 }
215 if (recipient() != null) {
216 hashCode = hashCode * 31 + recipient().hashCode();
217 }
218 return hashCode;
219 }
220 }