Serge Bazanski | cc25bdf | 2018-10-25 14:02:58 +0200 | [diff] [blame^] | 1 | // +build go1.9 |
| 2 | |
| 3 | /* |
| 4 | * |
| 5 | * Copyright 2018 gRPC authors. |
| 6 | * |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | * you may not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 13 | * Unless required by applicable law or agreed to in writing, software |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | * See the License for the specific language governing permissions and |
| 17 | * limitations under the License. |
| 18 | * |
| 19 | */ |
| 20 | |
| 21 | package dns |
| 22 | |
| 23 | import ( |
| 24 | "net" |
| 25 | |
| 26 | "golang.org/x/net/context" |
| 27 | ) |
| 28 | |
| 29 | var ( |
| 30 | defaultResolver netResolver = net.DefaultResolver |
| 31 | ) |
| 32 | |
| 33 | const defaultDNSSvrPort = "53" |
| 34 | |
| 35 | var customAuthorityDialler = func(authority string) func(ctx context.Context, network, address string) (net.Conn, error) { |
| 36 | return func(ctx context.Context, network, address string) (net.Conn, error) { |
| 37 | var dialer net.Dialer |
| 38 | return dialer.DialContext(ctx, network, authority) |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | var customAuthorityResolver = func(authority string) (netResolver, error) { |
| 43 | host, port, err := parseTarget(authority, defaultDNSSvrPort) |
| 44 | if err != nil { |
| 45 | return nil, err |
| 46 | } |
| 47 | |
| 48 | authorityWithPort := net.JoinHostPort(host, port) |
| 49 | |
| 50 | return &net.Resolver{ |
| 51 | PreferGo: true, |
| 52 | Dial: customAuthorityDialler(authorityWithPort), |
| 53 | }, nil |
| 54 | } |