6
6
use React \Cache \CacheInterface ;
7
7
use React \Dns \Config \Config ;
8
8
use React \Dns \Config \HostsFile ;
9
+ use React \Dns \Config \Options ;
9
10
use React \Dns \Query \CachingExecutor ;
10
11
use React \Dns \Query \CoopExecutor ;
11
12
use React \Dns \Query \ExecutorInterface ;
@@ -125,54 +126,60 @@ private function createExecutor($nameserver, LoopInterface $loop)
125
126
126
127
if ($ tertiary !== false ) {
127
128
// 3 DNS servers given => nest first with fallback for second and third
128
- return new CoopExecutor (
129
- new RetryExecutor (
129
+ return $ this ->createTopLevelDecoratingExectors (
130
+ new FallbackExecutor (
131
+ $ this ->createSingleExecutor ($ primary , $ nameserver ->options , $ loop ),
130
132
new FallbackExecutor (
131
- $ this ->createSingleExecutor ($ primary , $ loop ),
132
- new FallbackExecutor (
133
- $ this ->createSingleExecutor ($ secondary , $ loop ),
134
- $ this ->createSingleExecutor ($ tertiary , $ loop )
135
- )
133
+ $ this ->createSingleExecutor ($ secondary , $ nameserver ->options , $ loop ),
134
+ $ this ->createSingleExecutor ($ tertiary , $ nameserver ->options , $ loop )
136
135
)
137
- )
136
+ ),
137
+ $ nameserver
138
138
);
139
139
} elseif ($ secondary !== false ) {
140
140
// 2 DNS servers given => fallback from first to second
141
- return new CoopExecutor (
142
- new RetryExecutor (
143
- new FallbackExecutor (
144
- $ this ->createSingleExecutor ($ primary , $ loop ),
145
- $ this ->createSingleExecutor ($ secondary , $ loop )
146
- )
147
- )
141
+ return $ this ->createTopLevelDecoratingExectors (
142
+ new FallbackExecutor (
143
+ $ this ->createSingleExecutor ($ primary , $ nameserver ->options , $ loop ),
144
+ $ this ->createSingleExecutor ($ secondary , $ nameserver ->options , $ loop )
145
+ ),
146
+ $ nameserver
148
147
);
149
148
} else {
150
149
// 1 DNS server given => use single executor
151
150
$ nameserver = $ primary ;
152
151
}
153
152
}
154
153
155
- return new CoopExecutor (new RetryExecutor ($ this ->createSingleExecutor ($ nameserver , $ loop )));
154
+ return $ this ->createTopLevelDecoratingExectors ($ this ->createSingleExecutor ($ nameserver , new Options (), $ loop ), $ nameserver );
155
+ }
156
+
157
+ private function createTopLevelDecoratingExectors (ExecutorInterface $ executor , $ nameserver )
158
+ {
159
+ $ executor = new RetryExecutor ($ executor , (is_string ($ nameserver ) ? new Options () : $ nameserver ->options )->attempts );
160
+
161
+ return new CoopExecutor ($ executor );
156
162
}
157
163
158
164
/**
159
165
* @param string $nameserver
166
+ * @param Options $options
160
167
* @param LoopInterface $loop
161
168
* @return ExecutorInterface
162
169
* @throws \InvalidArgumentException for invalid DNS server address
163
170
*/
164
- private function createSingleExecutor ($ nameserver , LoopInterface $ loop )
171
+ private function createSingleExecutor ($ nameserver , Options $ options , LoopInterface $ loop )
165
172
{
166
173
$ parts = \parse_url ($ nameserver );
167
174
168
175
if (isset ($ parts ['scheme ' ]) && $ parts ['scheme ' ] === 'tcp ' ) {
169
- $ executor = $ this ->createTcpExecutor ($ nameserver , $ loop );
176
+ $ executor = $ this ->createTcpExecutor ($ nameserver , $ options -> timeout , $ loop );
170
177
} elseif (isset ($ parts ['scheme ' ]) && $ parts ['scheme ' ] === 'udp ' ) {
171
- $ executor = $ this ->createUdpExecutor ($ nameserver , $ loop );
178
+ $ executor = $ this ->createUdpExecutor ($ nameserver , $ options -> timeout , $ loop );
172
179
} else {
173
180
$ executor = new SelectiveTransportExecutor (
174
- $ this ->createUdpExecutor ($ nameserver , $ loop ),
175
- $ this ->createTcpExecutor ($ nameserver , $ loop )
181
+ $ this ->createUdpExecutor ($ nameserver , $ options -> timeout , $ loop ),
182
+ $ this ->createTcpExecutor ($ nameserver , $ options -> timeout , $ loop )
176
183
);
177
184
}
178
185
@@ -181,33 +188,35 @@ private function createSingleExecutor($nameserver, LoopInterface $loop)
181
188
182
189
/**
183
190
* @param string $nameserver
191
+ * @param int $timeout
184
192
* @param LoopInterface $loop
185
193
* @return TimeoutExecutor
186
194
* @throws \InvalidArgumentException for invalid DNS server address
187
195
*/
188
- private function createTcpExecutor ($ nameserver , LoopInterface $ loop )
196
+ private function createTcpExecutor ($ nameserver , int $ timeout , LoopInterface $ loop )
189
197
{
190
198
return new TimeoutExecutor (
191
199
new TcpTransportExecutor ($ nameserver , $ loop ),
192
- 5.0 ,
200
+ $ timeout ,
193
201
$ loop
194
202
);
195
203
}
196
204
197
205
/**
198
206
* @param string $nameserver
207
+ * @param int $timeout
199
208
* @param LoopInterface $loop
200
209
* @return TimeoutExecutor
201
210
* @throws \InvalidArgumentException for invalid DNS server address
202
211
*/
203
- private function createUdpExecutor ($ nameserver , LoopInterface $ loop )
212
+ private function createUdpExecutor ($ nameserver , int $ timeout , LoopInterface $ loop )
204
213
{
205
214
return new TimeoutExecutor (
206
215
new UdpTransportExecutor (
207
216
$ nameserver ,
208
217
$ loop
209
218
),
210
- 5.0 ,
219
+ $ timeout ,
211
220
$ loop
212
221
);
213
222
}
0 commit comments