OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <queue> | 5 #include <queue> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/macros.h" |
9 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
11 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
12 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
13 #include "base/thread_task_runner_handle.h" | 14 #include "base/thread_task_runner_handle.h" |
14 #include "base/time/clock.h" | 15 #include "base/time/clock.h" |
15 #include "base/time/default_clock.h" | 16 #include "base/time/default_clock.h" |
16 #include "base/timer/mock_timer.h" | 17 #include "base/timer/mock_timer.h" |
17 #include "net/base/rand_callback.h" | 18 #include "net/base/rand_callback.h" |
18 #include "net/base/test_completion_callback.h" | 19 #include "net/base/test_completion_callback.h" |
(...skipping 10 matching lines...) Expand all Loading... |
29 using ::testing::NiceMock; | 30 using ::testing::NiceMock; |
30 using ::testing::Exactly; | 31 using ::testing::Exactly; |
31 using ::testing::Return; | 32 using ::testing::Return; |
32 using ::testing::SaveArg; | 33 using ::testing::SaveArg; |
33 using ::testing::_; | 34 using ::testing::_; |
34 | 35 |
35 namespace net { | 36 namespace net { |
36 | 37 |
37 namespace { | 38 namespace { |
38 | 39 |
39 const uint8 kSamplePacket1[] = { | 40 const uint8_t kSamplePacket1[] = { |
40 // Header | |
41 0x00, 0x00, // ID is zeroed out | |
42 0x81, 0x80, // Standard query response, RA, no error | |
43 0x00, 0x00, // No questions (for simplicity) | |
44 0x00, 0x02, // 2 RRs (answers) | |
45 0x00, 0x00, // 0 authority RRs | |
46 0x00, 0x00, // 0 additional RRs | |
47 | |
48 // Answer 1 | |
49 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', | |
50 0x04, '_', 't', 'c', 'p', | |
51 0x05, 'l', 'o', 'c', 'a', 'l', | |
52 0x00, | |
53 0x00, 0x0c, // TYPE is PTR. | |
54 0x00, 0x01, // CLASS is IN. | |
55 0x00, 0x00, // TTL (4 bytes) is 1 second; | |
56 0x00, 0x01, | |
57 0x00, 0x08, // RDLENGTH is 8 bytes. | |
58 0x05, 'h', 'e', 'l', 'l', 'o', | |
59 0xc0, 0x0c, | |
60 | |
61 // Answer 2 | |
62 0x08, '_', 'p', 'r', 'i', 'n', 't', 'e', 'r', | |
63 0xc0, 0x14, // Pointer to "._tcp.local" | |
64 0x00, 0x0c, // TYPE is PTR. | |
65 0x00, 0x01, // CLASS is IN. | |
66 0x00, 0x01, // TTL (4 bytes) is 20 hours, 47 minutes, 49 seconds. | |
67 0x24, 0x75, | |
68 0x00, 0x08, // RDLENGTH is 8 bytes. | |
69 0x05, 'h', 'e', 'l', 'l', 'o', | |
70 0xc0, 0x32 | |
71 }; | |
72 | |
73 const uint8 kCorruptedPacketBadQuestion[] = { | |
74 // Header | |
75 0x00, 0x00, // ID is zeroed out | |
76 0x81, 0x80, // Standard query response, RA, no error | |
77 0x00, 0x01, // One question | |
78 0x00, 0x02, // 2 RRs (answers) | |
79 0x00, 0x00, // 0 authority RRs | |
80 0x00, 0x00, // 0 additional RRs | |
81 | |
82 // Question is corrupted and cannot be read. | |
83 0x99, 'h', 'e', 'l', 'l', 'o', | |
84 0x00, | |
85 0x00, 0x00, | |
86 0x00, 0x00, | |
87 | |
88 // Answer 1 | |
89 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', | |
90 0x04, '_', 't', 'c', 'p', | |
91 0x05, 'l', 'o', 'c', 'a', 'l', | |
92 0x00, | |
93 0x00, 0x0c, // TYPE is PTR. | |
94 0x00, 0x01, // CLASS is IN. | |
95 0x00, 0x01, // TTL (4 bytes) is 20 hours, 47 minutes, 48 seconds. | |
96 0x24, 0x74, | |
97 0x00, 0x99, // RDLENGTH is impossible | |
98 0x05, 'h', 'e', 'l', 'l', 'o', | |
99 0xc0, 0x0c, | |
100 | |
101 // Answer 2 | |
102 0x08, '_', 'p', 'r', // Useless trailing data. | |
103 }; | |
104 | |
105 const uint8 kCorruptedPacketUnsalvagable[] = { | |
106 // Header | |
107 0x00, 0x00, // ID is zeroed out | |
108 0x81, 0x80, // Standard query response, RA, no error | |
109 0x00, 0x00, // No questions (for simplicity) | |
110 0x00, 0x02, // 2 RRs (answers) | |
111 0x00, 0x00, // 0 authority RRs | |
112 0x00, 0x00, // 0 additional RRs | |
113 | |
114 // Answer 1 | |
115 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', | |
116 0x04, '_', 't', 'c', 'p', | |
117 0x05, 'l', 'o', 'c', 'a', 'l', | |
118 0x00, | |
119 0x00, 0x0c, // TYPE is PTR. | |
120 0x00, 0x01, // CLASS is IN. | |
121 0x00, 0x01, // TTL (4 bytes) is 20 hours, 47 minutes, 48 seconds. | |
122 0x24, 0x74, | |
123 0x00, 0x99, // RDLENGTH is impossible | |
124 0x05, 'h', 'e', 'l', 'l', 'o', | |
125 0xc0, 0x0c, | |
126 | |
127 // Answer 2 | |
128 0x08, '_', 'p', 'r', // Useless trailing data. | |
129 }; | |
130 | |
131 const uint8 kCorruptedPacketDoubleRecord[] = { | |
132 // Header | |
133 0x00, 0x00, // ID is zeroed out | |
134 0x81, 0x80, // Standard query response, RA, no error | |
135 0x00, 0x00, // No questions (for simplicity) | |
136 0x00, 0x02, // 2 RRs (answers) | |
137 0x00, 0x00, // 0 authority RRs | |
138 0x00, 0x00, // 0 additional RRs | |
139 | |
140 // Answer 1 | |
141 0x06, 'p', 'r', 'i', 'v', 'e', 't', | |
142 0x05, 'l', 'o', 'c', 'a', 'l', | |
143 0x00, | |
144 0x00, 0x01, // TYPE is A. | |
145 0x00, 0x01, // CLASS is IN. | |
146 0x00, 0x01, // TTL (4 bytes) is 20 hours, 47 minutes, 48 seconds. | |
147 0x24, 0x74, | |
148 0x00, 0x04, // RDLENGTH is 4 | |
149 0x05, 0x03, | |
150 0xc0, 0x0c, | |
151 | |
152 // Answer 2 -- Same key | |
153 0x06, 'p', 'r', 'i', 'v', 'e', 't', | |
154 0x05, 'l', 'o', 'c', 'a', 'l', | |
155 0x00, | |
156 0x00, 0x01, // TYPE is A. | |
157 0x00, 0x01, // CLASS is IN. | |
158 0x00, 0x01, // TTL (4 bytes) is 20 hours, 47 minutes, 48 seconds. | |
159 0x24, 0x74, | |
160 0x00, 0x04, // RDLENGTH is 4 | |
161 0x02, 0x03, | |
162 0x04, 0x05, | |
163 }; | |
164 | |
165 const uint8 kCorruptedPacketSalvagable[] = { | |
166 // Header | |
167 0x00, 0x00, // ID is zeroed out | |
168 0x81, 0x80, // Standard query response, RA, no error | |
169 0x00, 0x00, // No questions (for simplicity) | |
170 0x00, 0x02, // 2 RRs (answers) | |
171 0x00, 0x00, // 0 authority RRs | |
172 0x00, 0x00, // 0 additional RRs | |
173 | |
174 // Answer 1 | |
175 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', | |
176 0x04, '_', 't', 'c', 'p', | |
177 0x05, 'l', 'o', 'c', 'a', 'l', | |
178 0x00, | |
179 0x00, 0x0c, // TYPE is PTR. | |
180 0x00, 0x01, // CLASS is IN. | |
181 0x00, 0x01, // TTL (4 bytes) is 20 hours, 47 minutes, 48 seconds. | |
182 0x24, 0x74, | |
183 0x00, 0x08, // RDLENGTH is 8 bytes. | |
184 0x99, 'h', 'e', 'l', 'l', 'o', // Bad RDATA format. | |
185 0xc0, 0x0c, | |
186 | |
187 // Answer 2 | |
188 0x08, '_', 'p', 'r', 'i', 'n', 't', 'e', 'r', | |
189 0xc0, 0x14, // Pointer to "._tcp.local" | |
190 0x00, 0x0c, // TYPE is PTR. | |
191 0x00, 0x01, // CLASS is IN. | |
192 0x00, 0x01, // TTL (4 bytes) is 20 hours, 47 minutes, 49 seconds. | |
193 0x24, 0x75, | |
194 0x00, 0x08, // RDLENGTH is 8 bytes. | |
195 0x05, 'h', 'e', 'l', 'l', 'o', | |
196 0xc0, 0x32 | |
197 }; | |
198 | |
199 const uint8 kSamplePacket2[] = { | |
200 // Header | |
201 0x00, 0x00, // ID is zeroed out | |
202 0x81, 0x80, // Standard query response, RA, no error | |
203 0x00, 0x00, // No questions (for simplicity) | |
204 0x00, 0x02, // 2 RRs (answers) | |
205 0x00, 0x00, // 0 authority RRs | |
206 0x00, 0x00, // 0 additional RRs | |
207 | |
208 // Answer 1 | |
209 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', | |
210 0x04, '_', 't', 'c', 'p', | |
211 0x05, 'l', 'o', 'c', 'a', 'l', | |
212 0x00, | |
213 0x00, 0x0c, // TYPE is PTR. | |
214 0x00, 0x01, // CLASS is IN. | |
215 0x00, 0x01, // TTL (4 bytes) is 20 hours, 47 minutes, 48 seconds. | |
216 0x24, 0x74, | |
217 0x00, 0x08, // RDLENGTH is 8 bytes. | |
218 0x05, 'z', 'z', 'z', 'z', 'z', | |
219 0xc0, 0x0c, | |
220 | |
221 // Answer 2 | |
222 0x08, '_', 'p', 'r', 'i', 'n', 't', 'e', 'r', | |
223 0xc0, 0x14, // Pointer to "._tcp.local" | |
224 0x00, 0x0c, // TYPE is PTR. | |
225 0x00, 0x01, // CLASS is IN. | |
226 0x00, 0x01, // TTL (4 bytes) is 20 hours, 47 minutes, 48 seconds. | |
227 0x24, 0x74, | |
228 0x00, 0x08, // RDLENGTH is 8 bytes. | |
229 0x05, 'z', 'z', 'z', 'z', 'z', | |
230 0xc0, 0x32 | |
231 }; | |
232 | |
233 const uint8 kSamplePacket3[] = { | |
234 // Header | 41 // Header |
235 0x00, 0x00, // ID is zeroed out | 42 0x00, 0x00, // ID is zeroed out |
236 0x81, 0x80, // Standard query response, RA, no error | 43 0x81, 0x80, // Standard query response, RA, no error |
| 44 0x00, 0x00, // No questions (for simplicity) |
| 45 0x00, 0x02, // 2 RRs (answers) |
| 46 0x00, 0x00, // 0 authority RRs |
| 47 0x00, 0x00, // 0 additional RRs |
| 48 |
| 49 // Answer 1 |
| 50 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', 0x04, '_', 't', 'c', 'p', 0x05, |
| 51 'l', 'o', 'c', 'a', 'l', 0x00, 0x00, 0x0c, // TYPE is PTR. |
| 52 0x00, 0x01, // CLASS is IN. |
| 53 0x00, 0x00, // TTL (4 bytes) is 1 second; |
| 54 0x00, 0x01, 0x00, 0x08, // RDLENGTH is 8 bytes. |
| 55 0x05, 'h', 'e', 'l', 'l', 'o', 0xc0, 0x0c, |
| 56 |
| 57 // Answer 2 |
| 58 0x08, '_', 'p', 'r', 'i', 'n', 't', 'e', 'r', 0xc0, |
| 59 0x14, // Pointer to "._tcp.local" |
| 60 0x00, 0x0c, // TYPE is PTR. |
| 61 0x00, 0x01, // CLASS is IN. |
| 62 0x00, 0x01, // TTL (4 bytes) is 20 hours, 47 minutes, 49 seconds. |
| 63 0x24, 0x75, 0x00, 0x08, // RDLENGTH is 8 bytes. |
| 64 0x05, 'h', 'e', 'l', 'l', 'o', 0xc0, 0x32}; |
| 65 |
| 66 const uint8_t kCorruptedPacketBadQuestion[] = { |
| 67 // Header |
| 68 0x00, 0x00, // ID is zeroed out |
| 69 0x81, 0x80, // Standard query response, RA, no error |
| 70 0x00, 0x01, // One question |
| 71 0x00, 0x02, // 2 RRs (answers) |
| 72 0x00, 0x00, // 0 authority RRs |
| 73 0x00, 0x00, // 0 additional RRs |
| 74 |
| 75 // Question is corrupted and cannot be read. |
| 76 0x99, 'h', 'e', 'l', 'l', 'o', 0x00, 0x00, 0x00, 0x00, 0x00, |
| 77 |
| 78 // Answer 1 |
| 79 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', 0x04, '_', 't', 'c', 'p', 0x05, |
| 80 'l', 'o', 'c', 'a', 'l', 0x00, 0x00, 0x0c, // TYPE is PTR. |
| 81 0x00, 0x01, // CLASS is IN. |
| 82 0x00, 0x01, // TTL (4 bytes) is 20 hours, 47 minutes, 48 seconds. |
| 83 0x24, 0x74, 0x00, 0x99, // RDLENGTH is impossible |
| 84 0x05, 'h', 'e', 'l', 'l', 'o', 0xc0, 0x0c, |
| 85 |
| 86 // Answer 2 |
| 87 0x08, '_', 'p', 'r', // Useless trailing data. |
| 88 }; |
| 89 |
| 90 const uint8_t kCorruptedPacketUnsalvagable[] = { |
| 91 // Header |
| 92 0x00, 0x00, // ID is zeroed out |
| 93 0x81, 0x80, // Standard query response, RA, no error |
| 94 0x00, 0x00, // No questions (for simplicity) |
| 95 0x00, 0x02, // 2 RRs (answers) |
| 96 0x00, 0x00, // 0 authority RRs |
| 97 0x00, 0x00, // 0 additional RRs |
| 98 |
| 99 // Answer 1 |
| 100 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', 0x04, '_', 't', 'c', 'p', 0x05, |
| 101 'l', 'o', 'c', 'a', 'l', 0x00, 0x00, 0x0c, // TYPE is PTR. |
| 102 0x00, 0x01, // CLASS is IN. |
| 103 0x00, 0x01, // TTL (4 bytes) is 20 hours, 47 minutes, 48 seconds. |
| 104 0x24, 0x74, 0x00, 0x99, // RDLENGTH is impossible |
| 105 0x05, 'h', 'e', 'l', 'l', 'o', 0xc0, 0x0c, |
| 106 |
| 107 // Answer 2 |
| 108 0x08, '_', 'p', 'r', // Useless trailing data. |
| 109 }; |
| 110 |
| 111 const uint8_t kCorruptedPacketDoubleRecord[] = { |
| 112 // Header |
| 113 0x00, 0x00, // ID is zeroed out |
| 114 0x81, 0x80, // Standard query response, RA, no error |
| 115 0x00, 0x00, // No questions (for simplicity) |
| 116 0x00, 0x02, // 2 RRs (answers) |
| 117 0x00, 0x00, // 0 authority RRs |
| 118 0x00, 0x00, // 0 additional RRs |
| 119 |
| 120 // Answer 1 |
| 121 0x06, 'p', 'r', 'i', 'v', 'e', 't', 0x05, 'l', 'o', 'c', 'a', 'l', 0x00, |
| 122 0x00, 0x01, // TYPE is A. |
| 123 0x00, 0x01, // CLASS is IN. |
| 124 0x00, 0x01, // TTL (4 bytes) is 20 hours, 47 minutes, 48 seconds. |
| 125 0x24, 0x74, 0x00, 0x04, // RDLENGTH is 4 |
| 126 0x05, 0x03, 0xc0, 0x0c, |
| 127 |
| 128 // Answer 2 -- Same key |
| 129 0x06, 'p', 'r', 'i', 'v', 'e', 't', 0x05, 'l', 'o', 'c', 'a', 'l', 0x00, |
| 130 0x00, 0x01, // TYPE is A. |
| 131 0x00, 0x01, // CLASS is IN. |
| 132 0x00, 0x01, // TTL (4 bytes) is 20 hours, 47 minutes, 48 seconds. |
| 133 0x24, 0x74, 0x00, 0x04, // RDLENGTH is 4 |
| 134 0x02, 0x03, 0x04, 0x05, |
| 135 }; |
| 136 |
| 137 const uint8_t kCorruptedPacketSalvagable[] = { |
| 138 // Header |
| 139 0x00, 0x00, // ID is zeroed out |
| 140 0x81, 0x80, // Standard query response, RA, no error |
237 0x00, 0x00, // No questions (for simplicity) | 141 0x00, 0x00, // No questions (for simplicity) |
238 0x00, 0x02, // 2 RRs (answers) | 142 0x00, 0x02, // 2 RRs (answers) |
239 0x00, 0x00, // 0 authority RRs | 143 0x00, 0x00, // 0 authority RRs |
240 0x00, 0x00, // 0 additional RRs | 144 0x00, 0x00, // 0 additional RRs |
241 | 145 |
242 // Answer 1 | 146 // Answer 1 |
243 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', // | 147 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', 0x04, '_', 't', 'c', 'p', 0x05, |
244 0x04, '_', 't', 'c', 'p', // | 148 'l', 'o', 'c', 'a', 'l', 0x00, 0x00, 0x0c, // TYPE is PTR. |
245 0x05, 'l', 'o', 'c', 'a', 'l', // | |
246 0x00, 0x00, 0x0c, // TYPE is PTR. | |
247 0x00, 0x01, // CLASS is IN. | 149 0x00, 0x01, // CLASS is IN. |
248 0x00, 0x00, // TTL (4 bytes) is 1 second; | 150 0x00, 0x01, // TTL (4 bytes) is 20 hours, 47 minutes, 48 seconds. |
249 0x00, 0x01, // | 151 0x24, 0x74, 0x00, 0x08, // RDLENGTH is 8 bytes. |
250 0x00, 0x08, // RDLENGTH is 8 bytes. | 152 0x99, 'h', 'e', 'l', 'l', 'o', // Bad RDATA format. |
251 0x05, 'h', 'e', 'l', 'l', 'o', // | 153 0xc0, 0x0c, |
252 0xc0, 0x0c, // | |
253 | 154 |
254 // Answer 2 | 155 // Answer 2 |
255 0x08, '_', 'p', 'r', 'i', 'n', 't', 'e', 'r', // | 156 0x08, '_', 'p', 'r', 'i', 'n', 't', 'e', 'r', 0xc0, |
256 0xc0, 0x14, // Pointer to "._tcp.local" | 157 0x14, // Pointer to "._tcp.local" |
257 0x00, 0x0c, // TYPE is PTR. | 158 0x00, 0x0c, // TYPE is PTR. |
258 0x00, 0x01, // CLASS is IN. | 159 0x00, 0x01, // CLASS is IN. |
259 0x00, 0x00, // TTL (4 bytes) is 3 seconds. | 160 0x00, 0x01, // TTL (4 bytes) is 20 hours, 47 minutes, 49 seconds. |
260 0x00, 0x03, // | 161 0x24, 0x75, 0x00, 0x08, // RDLENGTH is 8 bytes. |
261 0x00, 0x08, // RDLENGTH is 8 bytes. | 162 0x05, 'h', 'e', 'l', 'l', 'o', 0xc0, 0x32}; |
262 0x05, 'h', 'e', 'l', 'l', 'o', // | 163 |
| 164 const uint8_t kSamplePacket2[] = { |
| 165 // Header |
| 166 0x00, 0x00, // ID is zeroed out |
| 167 0x81, 0x80, // Standard query response, RA, no error |
| 168 0x00, 0x00, // No questions (for simplicity) |
| 169 0x00, 0x02, // 2 RRs (answers) |
| 170 0x00, 0x00, // 0 authority RRs |
| 171 0x00, 0x00, // 0 additional RRs |
| 172 |
| 173 // Answer 1 |
| 174 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', 0x04, '_', 't', 'c', 'p', 0x05, |
| 175 'l', 'o', 'c', 'a', 'l', 0x00, 0x00, 0x0c, // TYPE is PTR. |
| 176 0x00, 0x01, // CLASS is IN. |
| 177 0x00, 0x01, // TTL (4 bytes) is 20 hours, 47 minutes, 48 seconds. |
| 178 0x24, 0x74, 0x00, 0x08, // RDLENGTH is 8 bytes. |
| 179 0x05, 'z', 'z', 'z', 'z', 'z', 0xc0, 0x0c, |
| 180 |
| 181 // Answer 2 |
| 182 0x08, '_', 'p', 'r', 'i', 'n', 't', 'e', 'r', 0xc0, |
| 183 0x14, // Pointer to "._tcp.local" |
| 184 0x00, 0x0c, // TYPE is PTR. |
| 185 0x00, 0x01, // CLASS is IN. |
| 186 0x00, 0x01, // TTL (4 bytes) is 20 hours, 47 minutes, 48 seconds. |
| 187 0x24, 0x74, 0x00, 0x08, // RDLENGTH is 8 bytes. |
| 188 0x05, 'z', 'z', 'z', 'z', 'z', 0xc0, 0x32}; |
| 189 |
| 190 const uint8_t kSamplePacket3[] = { |
| 191 // Header |
| 192 0x00, 0x00, // ID is zeroed out |
| 193 0x81, 0x80, // Standard query response, RA, no error |
| 194 0x00, 0x00, // No questions (for simplicity) |
| 195 0x00, 0x02, // 2 RRs (answers) |
| 196 0x00, 0x00, // 0 authority RRs |
| 197 0x00, 0x00, // 0 additional RRs |
| 198 |
| 199 // Answer 1 |
| 200 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', // |
| 201 0x04, '_', 't', 'c', 'p', // |
| 202 0x05, 'l', 'o', 'c', 'a', 'l', // |
| 203 0x00, 0x00, 0x0c, // TYPE is PTR. |
| 204 0x00, 0x01, // CLASS is IN. |
| 205 0x00, 0x00, // TTL (4 bytes) is 1 second; |
| 206 0x00, 0x01, // |
| 207 0x00, 0x08, // RDLENGTH is 8 bytes. |
| 208 0x05, 'h', 'e', 'l', 'l', 'o', // |
| 209 0xc0, 0x0c, // |
| 210 |
| 211 // Answer 2 |
| 212 0x08, '_', 'p', 'r', 'i', 'n', 't', 'e', 'r', // |
| 213 0xc0, 0x14, // Pointer to "._tcp.local" |
| 214 0x00, 0x0c, // TYPE is PTR. |
| 215 0x00, 0x01, // CLASS is IN. |
| 216 0x00, 0x00, // TTL (4 bytes) is 3 seconds. |
| 217 0x00, 0x03, // |
| 218 0x00, 0x08, // RDLENGTH is 8 bytes. |
| 219 0x05, 'h', 'e', 'l', 'l', 'o', // |
263 0xc0, 0x32}; | 220 0xc0, 0x32}; |
264 | 221 |
265 const uint8 kQueryPacketPrivet[] = { | 222 const uint8_t kQueryPacketPrivet[] = { |
266 // Header | 223 // Header |
267 0x00, 0x00, // ID is zeroed out | 224 0x00, 0x00, // ID is zeroed out |
268 0x00, 0x00, // No flags. | 225 0x00, 0x00, // No flags. |
269 0x00, 0x01, // One question. | 226 0x00, 0x01, // One question. |
270 0x00, 0x00, // 0 RRs (answers) | 227 0x00, 0x00, // 0 RRs (answers) |
271 0x00, 0x00, // 0 authority RRs | 228 0x00, 0x00, // 0 authority RRs |
272 0x00, 0x00, // 0 additional RRs | 229 0x00, 0x00, // 0 additional RRs |
273 | 230 |
274 // Question | 231 // Question |
275 // This part is echoed back from the respective query. | 232 // This part is echoed back from the respective query. |
276 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', | 233 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', 0x04, '_', 't', 'c', 'p', 0x05, |
277 0x04, '_', 't', 'c', 'p', | 234 'l', 'o', 'c', 'a', 'l', 0x00, 0x00, 0x0c, // TYPE is PTR. |
278 0x05, 'l', 'o', 'c', 'a', 'l', | 235 0x00, 0x01, // CLASS is IN. |
279 0x00, | |
280 0x00, 0x0c, // TYPE is PTR. | |
281 0x00, 0x01, // CLASS is IN. | |
282 }; | 236 }; |
283 | 237 |
284 const uint8 kQueryPacketPrivetA[] = { | 238 const uint8_t kQueryPacketPrivetA[] = { |
285 // Header | 239 // Header |
286 0x00, 0x00, // ID is zeroed out | 240 0x00, 0x00, // ID is zeroed out |
287 0x00, 0x00, // No flags. | 241 0x00, 0x00, // No flags. |
288 0x00, 0x01, // One question. | 242 0x00, 0x01, // One question. |
289 0x00, 0x00, // 0 RRs (answers) | 243 0x00, 0x00, // 0 RRs (answers) |
290 0x00, 0x00, // 0 authority RRs | 244 0x00, 0x00, // 0 authority RRs |
291 0x00, 0x00, // 0 additional RRs | 245 0x00, 0x00, // 0 additional RRs |
292 | 246 |
293 // Question | 247 // Question |
294 // This part is echoed back from the respective query. | 248 // This part is echoed back from the respective query. |
295 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', | 249 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', 0x04, '_', 't', 'c', 'p', 0x05, |
296 0x04, '_', 't', 'c', 'p', | 250 'l', 'o', 'c', 'a', 'l', 0x00, 0x00, 0x01, // TYPE is A. |
297 0x05, 'l', 'o', 'c', 'a', 'l', | 251 0x00, 0x01, // CLASS is IN. |
298 0x00, | |
299 0x00, 0x01, // TYPE is A. | |
300 0x00, 0x01, // CLASS is IN. | |
301 }; | 252 }; |
302 | 253 |
303 const uint8 kSamplePacketAdditionalOnly[] = { | 254 const uint8_t kSamplePacketAdditionalOnly[] = { |
304 // Header | 255 // Header |
305 0x00, 0x00, // ID is zeroed out | 256 0x00, 0x00, // ID is zeroed out |
306 0x81, 0x80, // Standard query response, RA, no error | 257 0x81, 0x80, // Standard query response, RA, no error |
307 0x00, 0x00, // No questions (for simplicity) | 258 0x00, 0x00, // No questions (for simplicity) |
308 0x00, 0x00, // 2 RRs (answers) | 259 0x00, 0x00, // 2 RRs (answers) |
309 0x00, 0x00, // 0 authority RRs | 260 0x00, 0x00, // 0 authority RRs |
310 0x00, 0x01, // 0 additional RRs | 261 0x00, 0x01, // 0 additional RRs |
311 | 262 |
312 // Answer 1 | 263 // Answer 1 |
313 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', | 264 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', 0x04, '_', 't', 'c', 'p', 0x05, |
314 0x04, '_', 't', 'c', 'p', | 265 'l', 'o', 'c', 'a', 'l', 0x00, 0x00, 0x0c, // TYPE is PTR. |
315 0x05, 'l', 'o', 'c', 'a', 'l', | 266 0x00, 0x01, // CLASS is IN. |
316 0x00, | 267 0x00, 0x01, // TTL (4 bytes) is 20 hours, 47 minutes, 48 seconds. |
317 0x00, 0x0c, // TYPE is PTR. | 268 0x24, 0x74, 0x00, 0x08, // RDLENGTH is 8 bytes. |
318 0x00, 0x01, // CLASS is IN. | 269 0x05, 'h', 'e', 'l', 'l', 'o', 0xc0, 0x0c, |
319 0x00, 0x01, // TTL (4 bytes) is 20 hours, 47 minutes, 48 seconds. | |
320 0x24, 0x74, | |
321 0x00, 0x08, // RDLENGTH is 8 bytes. | |
322 0x05, 'h', 'e', 'l', 'l', 'o', | |
323 0xc0, 0x0c, | |
324 }; | 270 }; |
325 | 271 |
326 const uint8 kSamplePacketNsec[] = { | 272 const uint8_t kSamplePacketNsec[] = { |
327 // Header | 273 // Header |
328 0x00, 0x00, // ID is zeroed out | 274 0x00, 0x00, // ID is zeroed out |
329 0x81, 0x80, // Standard query response, RA, no error | 275 0x81, 0x80, // Standard query response, RA, no error |
330 0x00, 0x00, // No questions (for simplicity) | 276 0x00, 0x00, // No questions (for simplicity) |
331 0x00, 0x01, // 1 RR (answers) | 277 0x00, 0x01, // 1 RR (answers) |
332 0x00, 0x00, // 0 authority RRs | 278 0x00, 0x00, // 0 authority RRs |
333 0x00, 0x00, // 0 additional RRs | 279 0x00, 0x00, // 0 additional RRs |
334 | 280 |
335 // Answer 1 | 281 // Answer 1 |
336 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', | 282 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', 0x04, '_', 't', 'c', 'p', 0x05, |
337 0x04, '_', 't', 'c', 'p', | 283 'l', 'o', 'c', 'a', 'l', 0x00, 0x00, 0x2f, // TYPE is NSEC. |
338 0x05, 'l', 'o', 'c', 'a', 'l', | 284 0x00, 0x01, // CLASS is IN. |
339 0x00, | 285 0x00, 0x01, // TTL (4 bytes) is 20 hours, 47 minutes, 48 seconds. |
340 0x00, 0x2f, // TYPE is NSEC. | 286 0x24, 0x74, 0x00, 0x06, // RDLENGTH is 6 bytes. |
341 0x00, 0x01, // CLASS is IN. | 287 0xc0, 0x0c, 0x00, 0x02, 0x00, 0x08 // Only A record present |
342 0x00, 0x01, // TTL (4 bytes) is 20 hours, 47 minutes, 48 seconds. | |
343 0x24, 0x74, | |
344 0x00, 0x06, // RDLENGTH is 6 bytes. | |
345 0xc0, 0x0c, | |
346 0x00, 0x02, 0x00, 0x08 // Only A record present | |
347 }; | 288 }; |
348 | 289 |
349 const uint8 kSamplePacketAPrivet[] = { | 290 const uint8_t kSamplePacketAPrivet[] = { |
350 // Header | 291 // Header |
351 0x00, 0x00, // ID is zeroed out | 292 0x00, 0x00, // ID is zeroed out |
352 0x81, 0x80, // Standard query response, RA, no error | 293 0x81, 0x80, // Standard query response, RA, no error |
353 0x00, 0x00, // No questions (for simplicity) | 294 0x00, 0x00, // No questions (for simplicity) |
354 0x00, 0x01, // 1 RR (answers) | 295 0x00, 0x01, // 1 RR (answers) |
355 0x00, 0x00, // 0 authority RRs | 296 0x00, 0x00, // 0 authority RRs |
356 0x00, 0x00, // 0 additional RRs | 297 0x00, 0x00, // 0 additional RRs |
357 | 298 |
358 // Answer 1 | 299 // Answer 1 |
359 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', | 300 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', 0x04, '_', 't', 'c', 'p', 0x05, |
360 0x04, '_', 't', 'c', 'p', | 301 'l', 'o', 'c', 'a', 'l', 0x00, 0x00, 0x01, // TYPE is A. |
361 0x05, 'l', 'o', 'c', 'a', 'l', | 302 0x00, 0x01, // CLASS is IN. |
362 0x00, | 303 0x00, 0x00, // TTL (4 bytes) is 5 seconds |
363 0x00, 0x01, // TYPE is A. | 304 0x00, 0x05, 0x00, 0x04, // RDLENGTH is 4 bytes. |
364 0x00, 0x01, // CLASS is IN. | 305 0xc0, 0x0c, 0x00, 0x02, |
365 0x00, 0x00, // TTL (4 bytes) is 5 seconds | |
366 0x00, 0x05, | |
367 0x00, 0x04, // RDLENGTH is 4 bytes. | |
368 0xc0, 0x0c, | |
369 0x00, 0x02, | |
370 }; | 306 }; |
371 | 307 |
372 const uint8 kSamplePacketGoodbye[] = { | 308 const uint8_t kSamplePacketGoodbye[] = { |
373 // Header | 309 // Header |
374 0x00, 0x00, // ID is zeroed out | 310 0x00, 0x00, // ID is zeroed out |
375 0x81, 0x80, // Standard query response, RA, no error | 311 0x81, 0x80, // Standard query response, RA, no error |
376 0x00, 0x00, // No questions (for simplicity) | 312 0x00, 0x00, // No questions (for simplicity) |
377 0x00, 0x01, // 2 RRs (answers) | 313 0x00, 0x01, // 2 RRs (answers) |
378 0x00, 0x00, // 0 authority RRs | 314 0x00, 0x00, // 0 authority RRs |
379 0x00, 0x00, // 0 additional RRs | 315 0x00, 0x00, // 0 additional RRs |
380 | 316 |
381 // Answer 1 | 317 // Answer 1 |
382 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', | 318 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', 0x04, '_', 't', 'c', 'p', 0x05, |
383 0x04, '_', 't', 'c', 'p', | 319 'l', 'o', 'c', 'a', 'l', 0x00, 0x00, 0x0c, // TYPE is PTR. |
384 0x05, 'l', 'o', 'c', 'a', 'l', | 320 0x00, 0x01, // CLASS is IN. |
385 0x00, | 321 0x00, 0x00, // TTL (4 bytes) is zero; |
386 0x00, 0x0c, // TYPE is PTR. | 322 0x00, 0x00, 0x00, 0x08, // RDLENGTH is 8 bytes. |
387 0x00, 0x01, // CLASS is IN. | 323 0x05, 'z', 'z', 'z', 'z', 'z', 0xc0, 0x0c, |
388 0x00, 0x00, // TTL (4 bytes) is zero; | |
389 0x00, 0x00, | |
390 0x00, 0x08, // RDLENGTH is 8 bytes. | |
391 0x05, 'z', 'z', 'z', 'z', 'z', | |
392 0xc0, 0x0c, | |
393 }; | 324 }; |
394 | 325 |
395 std::string MakeString(const uint8* data, unsigned size) { | 326 std::string MakeString(const uint8_t* data, unsigned size) { |
396 return std::string(reinterpret_cast<const char*>(data), size); | 327 return std::string(reinterpret_cast<const char*>(data), size); |
397 } | 328 } |
398 | 329 |
399 class PtrRecordCopyContainer { | 330 class PtrRecordCopyContainer { |
400 public: | 331 public: |
401 PtrRecordCopyContainer() {} | 332 PtrRecordCopyContainer() {} |
402 ~PtrRecordCopyContainer() {} | 333 ~PtrRecordCopyContainer() {} |
403 | 334 |
404 bool is_set() const { return set_; } | 335 bool is_set() const { return set_; } |
405 | 336 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 void RunFor(base::TimeDelta time_period); | 404 void RunFor(base::TimeDelta time_period); |
474 void Stop(); | 405 void Stop(); |
475 | 406 |
476 MOCK_METHOD2(MockableRecordCallback, void(MDnsTransaction::Result result, | 407 MOCK_METHOD2(MockableRecordCallback, void(MDnsTransaction::Result result, |
477 const RecordParsed* record)); | 408 const RecordParsed* record)); |
478 | 409 |
479 MOCK_METHOD2(MockableRecordCallback2, void(MDnsTransaction::Result result, | 410 MOCK_METHOD2(MockableRecordCallback2, void(MDnsTransaction::Result result, |
480 const RecordParsed* record)); | 411 const RecordParsed* record)); |
481 | 412 |
482 protected: | 413 protected: |
483 void ExpectPacket(const uint8* packet, unsigned size); | 414 void ExpectPacket(const uint8_t* packet, unsigned size); |
484 void SimulatePacketReceive(const uint8* packet, unsigned size); | 415 void SimulatePacketReceive(const uint8_t* packet, unsigned size); |
485 | 416 |
486 scoped_ptr<MDnsClientImpl> test_client_; | 417 scoped_ptr<MDnsClientImpl> test_client_; |
487 IPEndPoint mdns_ipv4_endpoint_; | 418 IPEndPoint mdns_ipv4_endpoint_; |
488 StrictMock<MockMDnsSocketFactory> socket_factory_; | 419 StrictMock<MockMDnsSocketFactory> socket_factory_; |
489 | 420 |
490 // Transactions and listeners that can be deleted by class methods for | 421 // Transactions and listeners that can be deleted by class methods for |
491 // reentrancy tests. | 422 // reentrancy tests. |
492 scoped_ptr<MDnsTransaction> transaction_; | 423 scoped_ptr<MDnsTransaction> transaction_; |
493 scoped_ptr<MDnsListener> listener1_; | 424 scoped_ptr<MDnsListener> listener1_; |
494 scoped_ptr<MDnsListener> listener2_; | 425 scoped_ptr<MDnsListener> listener2_; |
495 }; | 426 }; |
496 | 427 |
497 class MockListenerDelegate : public MDnsListener::Delegate { | 428 class MockListenerDelegate : public MDnsListener::Delegate { |
498 public: | 429 public: |
499 MOCK_METHOD2(OnRecordUpdate, | 430 MOCK_METHOD2(OnRecordUpdate, |
500 void(MDnsListener::UpdateType update, | 431 void(MDnsListener::UpdateType update, |
501 const RecordParsed* records)); | 432 const RecordParsed* records)); |
502 MOCK_METHOD2(OnNsecRecord, void(const std::string&, unsigned)); | 433 MOCK_METHOD2(OnNsecRecord, void(const std::string&, unsigned)); |
503 MOCK_METHOD0(OnCachePurged, void()); | 434 MOCK_METHOD0(OnCachePurged, void()); |
504 }; | 435 }; |
505 | 436 |
506 void MDnsTest::SetUp() { | 437 void MDnsTest::SetUp() { |
507 test_client_.reset(new MDnsClientImpl()); | 438 test_client_.reset(new MDnsClientImpl()); |
508 test_client_->StartListening(&socket_factory_); | 439 test_client_->StartListening(&socket_factory_); |
509 } | 440 } |
510 | 441 |
511 void MDnsTest::SimulatePacketReceive(const uint8* packet, unsigned size) { | 442 void MDnsTest::SimulatePacketReceive(const uint8_t* packet, unsigned size) { |
512 socket_factory_.SimulateReceive(packet, size); | 443 socket_factory_.SimulateReceive(packet, size); |
513 } | 444 } |
514 | 445 |
515 void MDnsTest::ExpectPacket(const uint8* packet, unsigned size) { | 446 void MDnsTest::ExpectPacket(const uint8_t* packet, unsigned size) { |
516 EXPECT_CALL(socket_factory_, OnSendTo(MakeString(packet, size))) | 447 EXPECT_CALL(socket_factory_, OnSendTo(MakeString(packet, size))) |
517 .Times(2); | 448 .Times(2); |
518 } | 449 } |
519 | 450 |
520 void MDnsTest::DeleteTransaction() { | 451 void MDnsTest::DeleteTransaction() { |
521 transaction_.reset(); | 452 transaction_.reset(); |
522 } | 453 } |
523 | 454 |
524 void MDnsTest::DeleteBothListeners() { | 455 void MDnsTest::DeleteBothListeners() { |
525 listener1_.reset(); | 456 listener1_.reset(); |
(...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1317 SendToInternal(sample_packet_, "224.0.0.251:5353", _)) | 1248 SendToInternal(sample_packet_, "224.0.0.251:5353", _)) |
1318 .Times(0); | 1249 .Times(0); |
1319 // Expect call for the second IPv6 packed. | 1250 // Expect call for the second IPv6 packed. |
1320 EXPECT_CALL(*socket_ipv6_, | 1251 EXPECT_CALL(*socket_ipv6_, |
1321 SendToInternal(sample_packet_, "[ff02::fb]:5353", _)) | 1252 SendToInternal(sample_packet_, "[ff02::fb]:5353", _)) |
1322 .WillOnce(Return(OK)); | 1253 .WillOnce(Return(OK)); |
1323 callback.Run(OK); | 1254 callback.Run(OK); |
1324 } | 1255 } |
1325 | 1256 |
1326 } // namespace net | 1257 } // namespace net |
OLD | NEW |