mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 10:33:35 +00:00
Fresh dep ensure
This commit is contained in:
95
vendor/google.golang.org/grpc/resolver/dns/dns_resolver.go
generated
vendored
95
vendor/google.golang.org/grpc/resolver/dns/dns_resolver.go
generated
vendored
@ -1,6 +1,6 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2017 gRPC authors.
|
||||
* Copyright 2018 gRPC authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -33,6 +33,7 @@ import (
|
||||
|
||||
"golang.org/x/net/context"
|
||||
"google.golang.org/grpc/grpclog"
|
||||
"google.golang.org/grpc/internal/backoff"
|
||||
"google.golang.org/grpc/internal/grpcrand"
|
||||
"google.golang.org/grpc/resolver"
|
||||
)
|
||||
@ -51,25 +52,28 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
errMissingAddr = errors.New("missing address")
|
||||
errMissingAddr = errors.New("dns resolver: missing address")
|
||||
|
||||
// Addresses ending with a colon that is supposed to be the separator
|
||||
// between host and port is not allowed. E.g. "::" is a valid address as
|
||||
// it is an IPv6 address (host only) and "[::]:" is invalid as it ends with
|
||||
// a colon as the host and port separator
|
||||
errEndsWithColon = errors.New("dns resolver: missing port after port-separator colon")
|
||||
)
|
||||
|
||||
// NewBuilder creates a dnsBuilder which is used to factory DNS resolvers.
|
||||
func NewBuilder() resolver.Builder {
|
||||
return &dnsBuilder{freq: defaultFreq}
|
||||
return &dnsBuilder{minFreq: defaultFreq}
|
||||
}
|
||||
|
||||
type dnsBuilder struct {
|
||||
// frequency of polling the DNS server.
|
||||
freq time.Duration
|
||||
// minimum frequency of polling the DNS server.
|
||||
minFreq time.Duration
|
||||
}
|
||||
|
||||
// Build creates and starts a DNS resolver that watches the name resolution of the target.
|
||||
func (b *dnsBuilder) Build(target resolver.Target, cc resolver.ClientConn, opts resolver.BuildOption) (resolver.Resolver, error) {
|
||||
if target.Authority != "" {
|
||||
return nil, fmt.Errorf("Default DNS resolver does not support custom DNS server")
|
||||
}
|
||||
host, port, err := parseTarget(target.Endpoint)
|
||||
host, port, err := parseTarget(target.Endpoint, defaultPort)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -92,7 +96,8 @@ func (b *dnsBuilder) Build(target resolver.Target, cc resolver.ClientConn, opts
|
||||
// DNS address (non-IP).
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
d := &dnsResolver{
|
||||
freq: b.freq,
|
||||
freq: b.minFreq,
|
||||
backoff: backoff.Exponential{MaxDelay: b.minFreq},
|
||||
host: host,
|
||||
port: port,
|
||||
ctx: ctx,
|
||||
@ -103,6 +108,15 @@ func (b *dnsBuilder) Build(target resolver.Target, cc resolver.ClientConn, opts
|
||||
disableServiceConfig: opts.DisableServiceConfig,
|
||||
}
|
||||
|
||||
if target.Authority == "" {
|
||||
d.resolver = defaultResolver
|
||||
} else {
|
||||
d.resolver, err = customAuthorityResolver(target.Authority)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
d.wg.Add(1)
|
||||
go d.watcher()
|
||||
return d, nil
|
||||
@ -113,6 +127,12 @@ func (b *dnsBuilder) Scheme() string {
|
||||
return "dns"
|
||||
}
|
||||
|
||||
type netResolver interface {
|
||||
LookupHost(ctx context.Context, host string) (addrs []string, err error)
|
||||
LookupSRV(ctx context.Context, service, proto, name string) (cname string, addrs []*net.SRV, err error)
|
||||
LookupTXT(ctx context.Context, name string) (txts []string, err error)
|
||||
}
|
||||
|
||||
// ipResolver watches for the name resolution update for an IP address.
|
||||
type ipResolver struct {
|
||||
cc resolver.ClientConn
|
||||
@ -148,12 +168,15 @@ func (i *ipResolver) watcher() {
|
||||
|
||||
// dnsResolver watches for the name resolution update for a non-IP target.
|
||||
type dnsResolver struct {
|
||||
freq time.Duration
|
||||
host string
|
||||
port string
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
cc resolver.ClientConn
|
||||
freq time.Duration
|
||||
backoff backoff.Exponential
|
||||
retryCount int
|
||||
host string
|
||||
port string
|
||||
resolver netResolver
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
cc resolver.ClientConn
|
||||
// rn channel is used by ResolveNow() to force an immediate resolution of the target.
|
||||
rn chan struct{}
|
||||
t *time.Timer
|
||||
@ -192,8 +215,15 @@ func (d *dnsResolver) watcher() {
|
||||
case <-d.rn:
|
||||
}
|
||||
result, sc := d.lookup()
|
||||
// Next lookup should happen after an interval defined by d.freq.
|
||||
d.t.Reset(d.freq)
|
||||
// Next lookup should happen within an interval defined by d.freq. It may be
|
||||
// more often due to exponential retry on empty address list.
|
||||
if len(result) == 0 {
|
||||
d.retryCount++
|
||||
d.t.Reset(d.backoff.Backoff(d.retryCount))
|
||||
} else {
|
||||
d.retryCount = 0
|
||||
d.t.Reset(d.freq)
|
||||
}
|
||||
d.cc.NewServiceConfig(sc)
|
||||
d.cc.NewAddress(result)
|
||||
}
|
||||
@ -201,13 +231,13 @@ func (d *dnsResolver) watcher() {
|
||||
|
||||
func (d *dnsResolver) lookupSRV() []resolver.Address {
|
||||
var newAddrs []resolver.Address
|
||||
_, srvs, err := lookupSRV(d.ctx, "grpclb", "tcp", d.host)
|
||||
_, srvs, err := d.resolver.LookupSRV(d.ctx, "grpclb", "tcp", d.host)
|
||||
if err != nil {
|
||||
grpclog.Infof("grpc: failed dns SRV record lookup due to %v.\n", err)
|
||||
return nil
|
||||
}
|
||||
for _, s := range srvs {
|
||||
lbAddrs, err := lookupHost(d.ctx, s.Target)
|
||||
lbAddrs, err := d.resolver.LookupHost(d.ctx, s.Target)
|
||||
if err != nil {
|
||||
grpclog.Infof("grpc: failed load balancer address dns lookup due to %v.\n", err)
|
||||
continue
|
||||
@ -226,7 +256,7 @@ func (d *dnsResolver) lookupSRV() []resolver.Address {
|
||||
}
|
||||
|
||||
func (d *dnsResolver) lookupTXT() string {
|
||||
ss, err := lookupTXT(d.ctx, d.host)
|
||||
ss, err := d.resolver.LookupTXT(d.ctx, d.host)
|
||||
if err != nil {
|
||||
grpclog.Infof("grpc: failed dns TXT record lookup due to %v.\n", err)
|
||||
return ""
|
||||
@ -246,7 +276,7 @@ func (d *dnsResolver) lookupTXT() string {
|
||||
|
||||
func (d *dnsResolver) lookupHost() []resolver.Address {
|
||||
var newAddrs []resolver.Address
|
||||
addrs, err := lookupHost(d.ctx, d.host)
|
||||
addrs, err := d.resolver.LookupHost(d.ctx, d.host)
|
||||
if err != nil {
|
||||
grpclog.Warningf("grpc: failed dns A record lookup due to %v.\n", err)
|
||||
return nil
|
||||
@ -288,17 +318,16 @@ func formatIP(addr string) (addrIP string, ok bool) {
|
||||
return "[" + addr + "]", true
|
||||
}
|
||||
|
||||
// parseTarget takes the user input target string, returns formatted host and port info.
|
||||
// parseTarget takes the user input target string and default port, returns formatted host and port info.
|
||||
// If target doesn't specify a port, set the port to be the defaultPort.
|
||||
// If target is in IPv6 format and host-name is enclosed in sqarue brackets, brackets
|
||||
// are strippd when setting the host.
|
||||
// examples:
|
||||
// target: "www.google.com" returns host: "www.google.com", port: "443"
|
||||
// target: "ipv4-host:80" returns host: "ipv4-host", port: "80"
|
||||
// target: "[ipv6-host]" returns host: "ipv6-host", port: "443"
|
||||
// target: ":80" returns host: "localhost", port: "80"
|
||||
// target: ":" returns host: "localhost", port: "443"
|
||||
func parseTarget(target string) (host, port string, err error) {
|
||||
// target: "www.google.com" defaultPort: "443" returns host: "www.google.com", port: "443"
|
||||
// target: "ipv4-host:80" defaultPort: "443" returns host: "ipv4-host", port: "80"
|
||||
// target: "[ipv6-host]" defaultPort: "443" returns host: "ipv6-host", port: "443"
|
||||
// target: ":80" defaultPort: "443" returns host: "localhost", port: "80"
|
||||
func parseTarget(target, defaultPort string) (host, port string, err error) {
|
||||
if target == "" {
|
||||
return "", "", errMissingAddr
|
||||
}
|
||||
@ -307,15 +336,15 @@ func parseTarget(target string) (host, port string, err error) {
|
||||
return target, defaultPort, nil
|
||||
}
|
||||
if host, port, err = net.SplitHostPort(target); err == nil {
|
||||
if port == "" {
|
||||
// If the port field is empty (target ends with colon), e.g. "[::1]:", this is an error.
|
||||
return "", "", errEndsWithColon
|
||||
}
|
||||
// target has port, i.e ipv4-host:port, [ipv6-host]:port, host-name:port
|
||||
if host == "" {
|
||||
// Keep consistent with net.Dial(): If the host is empty, as in ":80", the local system is assumed.
|
||||
host = "localhost"
|
||||
}
|
||||
if port == "" {
|
||||
// If the port field is empty(target ends with colon), e.g. "[::1]:", defaultPort is used.
|
||||
port = defaultPort
|
||||
}
|
||||
return host, port, nil
|
||||
}
|
||||
if host, port, err = net.SplitHostPort(target + ":" + defaultPort); err == nil {
|
||||
|
135
vendor/google.golang.org/grpc/resolver/dns/dns_resolver_go19_test.go
generated
vendored
Normal file
135
vendor/google.golang.org/grpc/resolver/dns/dns_resolver_go19_test.go
generated
vendored
Normal file
@ -0,0 +1,135 @@
|
||||
// +build go1.9
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright 2018 gRPC authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package dns
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
"google.golang.org/grpc/internal/leakcheck"
|
||||
"google.golang.org/grpc/resolver"
|
||||
)
|
||||
|
||||
func TestCustomAuthority(t *testing.T) {
|
||||
defer leakcheck.Check(t)
|
||||
|
||||
tests := []struct {
|
||||
authority string
|
||||
authorityWant string
|
||||
expectError bool
|
||||
}{
|
||||
{
|
||||
"4.3.2.1:" + defaultDNSSvrPort,
|
||||
"4.3.2.1:" + defaultDNSSvrPort,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"4.3.2.1:123",
|
||||
"4.3.2.1:123",
|
||||
false,
|
||||
},
|
||||
{
|
||||
"4.3.2.1",
|
||||
"4.3.2.1:" + defaultDNSSvrPort,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"::1",
|
||||
"[::1]:" + defaultDNSSvrPort,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"[::1]",
|
||||
"[::1]:" + defaultDNSSvrPort,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"[::1]:123",
|
||||
"[::1]:123",
|
||||
false,
|
||||
},
|
||||
{
|
||||
"dnsserver.com",
|
||||
"dnsserver.com:" + defaultDNSSvrPort,
|
||||
false,
|
||||
},
|
||||
{
|
||||
":123",
|
||||
"localhost:123",
|
||||
false,
|
||||
},
|
||||
{
|
||||
":",
|
||||
"",
|
||||
true,
|
||||
},
|
||||
{
|
||||
"[::1]:",
|
||||
"",
|
||||
true,
|
||||
},
|
||||
{
|
||||
"dnsserver.com:",
|
||||
"",
|
||||
true,
|
||||
},
|
||||
}
|
||||
oldCustomAuthorityDialler := customAuthorityDialler
|
||||
defer func() {
|
||||
customAuthorityDialler = oldCustomAuthorityDialler
|
||||
}()
|
||||
|
||||
for _, a := range tests {
|
||||
errChan := make(chan error, 1)
|
||||
customAuthorityDialler = func(authority string) func(ctx context.Context, network, address string) (net.Conn, error) {
|
||||
if authority != a.authorityWant {
|
||||
errChan <- fmt.Errorf("wrong custom authority passed to resolver. input: %s expected: %s actual: %s", a.authority, a.authorityWant, authority)
|
||||
} else {
|
||||
errChan <- nil
|
||||
}
|
||||
return func(ctx context.Context, network, address string) (net.Conn, error) {
|
||||
return nil, errors.New("no need to dial")
|
||||
}
|
||||
}
|
||||
|
||||
b := NewBuilder()
|
||||
cc := &testClientConn{target: "foo.bar.com"}
|
||||
r, err := b.Build(resolver.Target{Endpoint: "foo.bar.com", Authority: a.authority}, cc, resolver.BuildOption{})
|
||||
|
||||
if err == nil {
|
||||
r.Close()
|
||||
|
||||
err = <-errChan
|
||||
if err != nil {
|
||||
t.Errorf(err.Error())
|
||||
}
|
||||
|
||||
if a.expectError {
|
||||
t.Errorf("custom authority should have caused an error: %s", a.authority)
|
||||
}
|
||||
} else if !a.expectError {
|
||||
t.Errorf("unexpected error using custom authority %s: %s", a.authority, err)
|
||||
}
|
||||
}
|
||||
}
|
92
vendor/google.golang.org/grpc/resolver/dns/dns_resolver_test.go
generated
vendored
92
vendor/google.golang.org/grpc/resolver/dns/dns_resolver_test.go
generated
vendored
@ -1,6 +1,6 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2017 gRPC authors.
|
||||
* Copyright 2018 gRPC authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -27,6 +27,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
"google.golang.org/grpc/internal/leakcheck"
|
||||
"google.golang.org/grpc/resolver"
|
||||
)
|
||||
@ -46,7 +47,7 @@ type testClientConn struct {
|
||||
target string
|
||||
m1 sync.Mutex
|
||||
addrs []resolver.Address
|
||||
a int
|
||||
a int // how many times NewAddress() has been called
|
||||
m2 sync.Mutex
|
||||
sc string
|
||||
s int
|
||||
@ -78,6 +79,30 @@ func (t *testClientConn) getSc() (string, int) {
|
||||
return t.sc, t.s
|
||||
}
|
||||
|
||||
type testResolver struct {
|
||||
}
|
||||
|
||||
func (*testResolver) LookupHost(ctx context.Context, host string) ([]string, error) {
|
||||
return hostLookup(host)
|
||||
}
|
||||
|
||||
func (*testResolver) LookupSRV(ctx context.Context, service, proto, name string) (string, []*net.SRV, error) {
|
||||
return srvLookup(service, proto, name)
|
||||
}
|
||||
|
||||
func (*testResolver) LookupTXT(ctx context.Context, host string) ([]string, error) {
|
||||
return txtLookup(host)
|
||||
}
|
||||
|
||||
func replaceNetFunc() func() {
|
||||
oldResolver := defaultResolver
|
||||
defaultResolver = &testResolver{}
|
||||
|
||||
return func() {
|
||||
defaultResolver = oldResolver
|
||||
}
|
||||
}
|
||||
|
||||
var hostLookupTbl = struct {
|
||||
sync.Mutex
|
||||
tbl map[string][]string
|
||||
@ -815,7 +840,7 @@ func testIPResolver(t *testing.T) {
|
||||
{"127.0.0.1:12345", []resolver.Address{{Addr: "127.0.0.1:12345"}}},
|
||||
{"::1", []resolver.Address{{Addr: "[::1]" + colonDefaultPort}}},
|
||||
{"[::1]:12345", []resolver.Address{{Addr: "[::1]:12345"}}},
|
||||
{"[::1]:", []resolver.Address{{Addr: "[::1]:443"}}},
|
||||
{"[::1]", []resolver.Address{{Addr: "[::1]:443"}}},
|
||||
{"2001:db8:85a3::8a2e:370:7334", []resolver.Address{{Addr: "[2001:db8:85a3::8a2e:370:7334]" + colonDefaultPort}}},
|
||||
{"[2001:db8:85a3::8a2e:370:7334]", []resolver.Address{{Addr: "[2001:db8:85a3::8a2e:370:7334]" + colonDefaultPort}}},
|
||||
{"[2001:db8:85a3::8a2e:370:7334]:12345", []resolver.Address{{Addr: "[2001:db8:85a3::8a2e:370:7334]:12345"}}},
|
||||
@ -867,6 +892,7 @@ func TestResolveFunc(t *testing.T) {
|
||||
{"www.google.com", nil},
|
||||
{"foo.bar:12345", nil},
|
||||
{"127.0.0.1", nil},
|
||||
{"::", nil},
|
||||
{"127.0.0.1:12345", nil},
|
||||
{"[::1]:80", nil},
|
||||
{"[2001:db8:a0b:12f0::1]:21", nil},
|
||||
@ -875,7 +901,8 @@ func TestResolveFunc(t *testing.T) {
|
||||
{"[fe80::1%lo0]:80", nil},
|
||||
{"golang.org:http", nil},
|
||||
{"[2001:db8::1]:http", nil},
|
||||
{":", nil},
|
||||
{"[2001:db8::1]:", errEndsWithColon},
|
||||
{":", errEndsWithColon},
|
||||
{"", errMissingAddr},
|
||||
{"[2001:db8:a0b:12f0::1", errForInvalidTarget},
|
||||
}
|
||||
@ -934,3 +961,60 @@ func TestDisableServiceConfig(t *testing.T) {
|
||||
r.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func TestDNSResolverRetry(t *testing.T) {
|
||||
b := NewBuilder()
|
||||
target := "ipv4.single.fake"
|
||||
cc := &testClientConn{target: target}
|
||||
r, err := b.Build(resolver.Target{Endpoint: target}, cc, resolver.BuildOption{})
|
||||
if err != nil {
|
||||
t.Fatalf("%v\n", err)
|
||||
}
|
||||
var addrs []resolver.Address
|
||||
for {
|
||||
addrs, _ = cc.getAddress()
|
||||
if len(addrs) == 1 {
|
||||
break
|
||||
}
|
||||
time.Sleep(time.Millisecond)
|
||||
}
|
||||
want := []resolver.Address{{Addr: "1.2.3.4" + colonDefaultPort}}
|
||||
if !reflect.DeepEqual(want, addrs) {
|
||||
t.Errorf("Resolved addresses of target: %q = %+v, want %+v\n", target, addrs, want)
|
||||
}
|
||||
// mutate the host lookup table so the target has 0 address returned.
|
||||
revertTbl := mutateTbl(target)
|
||||
// trigger a resolve that will get empty address list
|
||||
r.ResolveNow(resolver.ResolveNowOption{})
|
||||
for {
|
||||
addrs, _ = cc.getAddress()
|
||||
if len(addrs) == 0 {
|
||||
break
|
||||
}
|
||||
time.Sleep(time.Millisecond)
|
||||
}
|
||||
revertTbl()
|
||||
// wait for the retry to happen in two seconds.
|
||||
timer := time.NewTimer(2 * time.Second)
|
||||
for {
|
||||
b := false
|
||||
select {
|
||||
case <-timer.C:
|
||||
b = true
|
||||
default:
|
||||
addrs, _ = cc.getAddress()
|
||||
if len(addrs) == 1 {
|
||||
b = true
|
||||
break
|
||||
}
|
||||
time.Sleep(time.Millisecond)
|
||||
}
|
||||
if b {
|
||||
break
|
||||
}
|
||||
}
|
||||
if !reflect.DeepEqual(want, addrs) {
|
||||
t.Errorf("Resolved addresses of target: %q = %+v, want %+v\n", target, addrs, want)
|
||||
}
|
||||
r.Close()
|
||||
}
|
||||
|
35
vendor/google.golang.org/grpc/resolver/dns/go17.go
generated
vendored
35
vendor/google.golang.org/grpc/resolver/dns/go17.go
generated
vendored
@ -1,35 +0,0 @@
|
||||
// +build go1.6, !go1.8
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright 2017 gRPC authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package dns
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
var (
|
||||
lookupHost = func(ctx context.Context, host string) ([]string, error) { return net.LookupHost(host) }
|
||||
lookupSRV = func(ctx context.Context, service, proto, name string) (string, []*net.SRV, error) {
|
||||
return net.LookupSRV(service, proto, name)
|
||||
}
|
||||
lookupTXT = func(ctx context.Context, name string) ([]string, error) { return net.LookupTXT(name) }
|
||||
)
|
50
vendor/google.golang.org/grpc/resolver/dns/go17_test.go
generated
vendored
50
vendor/google.golang.org/grpc/resolver/dns/go17_test.go
generated
vendored
@ -1,50 +0,0 @@
|
||||
// +build go1.6, !go1.8
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright 2017 gRPC authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package dns
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
var errForInvalidTarget = fmt.Errorf("invalid target address [2001:db8:a0b:12f0::1, error info: missing ']' in address [2001:db8:a0b:12f0::1:443")
|
||||
|
||||
func replaceNetFunc() func() {
|
||||
oldLookupHost := lookupHost
|
||||
oldLookupSRV := lookupSRV
|
||||
oldLookupTXT := lookupTXT
|
||||
lookupHost = func(ctx context.Context, host string) ([]string, error) {
|
||||
return hostLookup(host)
|
||||
}
|
||||
lookupSRV = func(ctx context.Context, service, proto, name string) (string, []*net.SRV, error) {
|
||||
return srvLookup(service, proto, name)
|
||||
}
|
||||
lookupTXT = func(ctx context.Context, host string) ([]string, error) {
|
||||
return txtLookup(host)
|
||||
}
|
||||
return func() {
|
||||
lookupHost = oldLookupHost
|
||||
lookupSRV = oldLookupSRV
|
||||
lookupTXT = oldLookupTXT
|
||||
}
|
||||
}
|
24
vendor/google.golang.org/grpc/resolver/dns/go18_test.go
generated
vendored
24
vendor/google.golang.org/grpc/resolver/dns/go18_test.go
generated
vendored
@ -2,7 +2,7 @@
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright 2017 gRPC authors.
|
||||
* Copyright 2018 gRPC authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -21,29 +21,7 @@
|
||||
package dns
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
)
|
||||
|
||||
var errForInvalidTarget = fmt.Errorf("invalid target address [2001:db8:a0b:12f0::1, error info: address [2001:db8:a0b:12f0::1:443: missing ']' in address")
|
||||
|
||||
func replaceNetFunc() func() {
|
||||
oldLookupHost := lookupHost
|
||||
oldLookupSRV := lookupSRV
|
||||
oldLookupTXT := lookupTXT
|
||||
lookupHost = func(ctx context.Context, host string) ([]string, error) {
|
||||
return hostLookup(host)
|
||||
}
|
||||
lookupSRV = func(ctx context.Context, service, proto, name string) (string, []*net.SRV, error) {
|
||||
return srvLookup(service, proto, name)
|
||||
}
|
||||
lookupTXT = func(ctx context.Context, host string) ([]string, error) {
|
||||
return txtLookup(host)
|
||||
}
|
||||
return func() {
|
||||
lookupHost = oldLookupHost
|
||||
lookupSRV = oldLookupSRV
|
||||
lookupTXT = oldLookupTXT
|
||||
}
|
||||
}
|
||||
|
54
vendor/google.golang.org/grpc/resolver/dns/go19.go
generated
vendored
Normal file
54
vendor/google.golang.org/grpc/resolver/dns/go19.go
generated
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
// +build go1.9
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright 2018 gRPC authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package dns
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
var (
|
||||
defaultResolver netResolver = net.DefaultResolver
|
||||
)
|
||||
|
||||
const defaultDNSSvrPort = "53"
|
||||
|
||||
var customAuthorityDialler = func(authority string) func(ctx context.Context, network, address string) (net.Conn, error) {
|
||||
return func(ctx context.Context, network, address string) (net.Conn, error) {
|
||||
var dialer net.Dialer
|
||||
return dialer.DialContext(ctx, network, authority)
|
||||
}
|
||||
}
|
||||
|
||||
var customAuthorityResolver = func(authority string) (netResolver, error) {
|
||||
host, port, err := parseTarget(authority, defaultDNSSvrPort)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
authorityWithPort := net.JoinHostPort(host, port)
|
||||
|
||||
return &net.Resolver{
|
||||
PreferGo: true,
|
||||
Dial: customAuthorityDialler(authorityWithPort),
|
||||
}, nil
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
// +build go1.8
|
||||
// +build go1.6, !go1.8
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright 2017 gRPC authors.
|
||||
* Copyright 2018 gRPC authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -20,10 +20,8 @@
|
||||
|
||||
package dns
|
||||
|
||||
import "net"
|
||||
|
||||
var (
|
||||
lookupHost = net.DefaultResolver.LookupHost
|
||||
lookupSRV = net.DefaultResolver.LookupSRV
|
||||
lookupTXT = net.DefaultResolver.LookupTXT
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
var errForInvalidTarget = fmt.Errorf("invalid target address [2001:db8:a0b:12f0::1, error info: missing ']' in address [2001:db8:a0b:12f0::1:443")
|
51
vendor/google.golang.org/grpc/resolver/dns/pre_go19.go
generated
vendored
Normal file
51
vendor/google.golang.org/grpc/resolver/dns/pre_go19.go
generated
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
// +build go1.6, !go1.9
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright 2018 gRPC authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package dns
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
var (
|
||||
defaultResolver netResolver = &preGo19Resolver{}
|
||||
)
|
||||
|
||||
type preGo19Resolver struct {
|
||||
}
|
||||
|
||||
func (*preGo19Resolver) LookupHost(ctx context.Context, host string) ([]string, error) {
|
||||
return net.LookupHost(host)
|
||||
}
|
||||
|
||||
func (*preGo19Resolver) LookupSRV(ctx context.Context, service, proto, name string) (string, []*net.SRV, error) {
|
||||
return net.LookupSRV(service, proto, name)
|
||||
}
|
||||
|
||||
func (*preGo19Resolver) LookupTXT(ctx context.Context, name string) ([]string, error) {
|
||||
return net.LookupTXT(name)
|
||||
}
|
||||
|
||||
var customAuthorityResolver = func(authority string) (netResolver, error) {
|
||||
return nil, fmt.Errorf("Default DNS resolver does not support custom DNS server with go < 1.9")
|
||||
}
|
8
vendor/google.golang.org/grpc/resolver/resolver.go
generated
vendored
8
vendor/google.golang.org/grpc/resolver/resolver.go
generated
vendored
@ -49,8 +49,12 @@ func Get(scheme string) Builder {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetDefaultScheme sets the default scheme that will be used.
|
||||
// The default default scheme is "passthrough".
|
||||
// SetDefaultScheme sets the default scheme that will be used. The default
|
||||
// default scheme is "passthrough".
|
||||
//
|
||||
// NOTE: this function must only be called during initialization time (i.e. in
|
||||
// an init() function), and is not thread-safe. The scheme set last overrides
|
||||
// previously set values.
|
||||
func SetDefaultScheme(scheme string) {
|
||||
defaultScheme = scheme
|
||||
}
|
||||
|
Reference in New Issue
Block a user