mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 10:33:35 +00:00
34
vendor/google.golang.org/grpc/resolver/dns/dns_resolver.go
generated
vendored
34
vendor/google.golang.org/grpc/resolver/dns/dns_resolver.go
generated
vendored
@ -21,6 +21,7 @@
|
||||
package dns
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
@ -31,7 +32,6 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
"google.golang.org/grpc/grpclog"
|
||||
"google.golang.org/grpc/internal/backoff"
|
||||
"google.golang.org/grpc/internal/grpcrand"
|
||||
@ -43,9 +43,10 @@ func init() {
|
||||
}
|
||||
|
||||
const (
|
||||
defaultPort = "443"
|
||||
defaultFreq = time.Minute * 30
|
||||
golang = "GO"
|
||||
defaultPort = "443"
|
||||
defaultFreq = time.Minute * 30
|
||||
defaultDNSSvrPort = "53"
|
||||
golang = "GO"
|
||||
// In DNS, service config is encoded in a TXT record via the mechanism
|
||||
// described in RFC-1464 using the attribute name grpc_config.
|
||||
txtAttribute = "grpc_config="
|
||||
@ -61,6 +62,31 @@ var (
|
||||
errEndsWithColon = errors.New("dns resolver: missing port after port-separator colon")
|
||||
)
|
||||
|
||||
var (
|
||||
defaultResolver netResolver = net.DefaultResolver
|
||||
)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
// NewBuilder creates a dnsBuilder which is used to factory DNS resolvers.
|
||||
func NewBuilder() resolver.Builder {
|
||||
return &dnsBuilder{minFreq: defaultFreq}
|
||||
|
135
vendor/google.golang.org/grpc/resolver/dns/dns_resolver_go19_test.go
generated
vendored
135
vendor/google.golang.org/grpc/resolver/dns/dns_resolver_go19_test.go
generated
vendored
@ -1,135 +0,0 @@
|
||||
// +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)
|
||||
}
|
||||
}
|
||||
}
|
108
vendor/google.golang.org/grpc/resolver/dns/dns_resolver_test.go
generated
vendored
108
vendor/google.golang.org/grpc/resolver/dns/dns_resolver_test.go
generated
vendored
@ -19,6 +19,8 @@
|
||||
package dns
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
@ -27,7 +29,6 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
"google.golang.org/grpc/internal/leakcheck"
|
||||
"google.golang.org/grpc/resolver"
|
||||
)
|
||||
@ -904,7 +905,7 @@ func TestResolveFunc(t *testing.T) {
|
||||
{"[2001:db8::1]:", errEndsWithColon},
|
||||
{":", errEndsWithColon},
|
||||
{"", errMissingAddr},
|
||||
{"[2001:db8:a0b:12f0::1", errForInvalidTarget},
|
||||
{"[2001:db8:a0b:12f0::1", fmt.Errorf("invalid target address [2001:db8:a0b:12f0::1, error info: address [2001:db8:a0b:12f0::1:443: missing ']' in address")},
|
||||
}
|
||||
|
||||
b := NewBuilder()
|
||||
@ -1018,3 +1019,106 @@ func TestDNSResolverRetry(t *testing.T) {
|
||||
}
|
||||
r.Close()
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
27
vendor/google.golang.org/grpc/resolver/dns/go18_test.go
generated
vendored
27
vendor/google.golang.org/grpc/resolver/dns/go18_test.go
generated
vendored
@ -1,27 +0,0 @@
|
||||
// +build go1.8
|
||||
|
||||
/*
|
||||
*
|
||||
* 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"
|
||||
)
|
||||
|
||||
var errForInvalidTarget = fmt.Errorf("invalid target address [2001:db8:a0b:12f0::1, error info: address [2001:db8:a0b:12f0::1:443: missing ']' in address")
|
54
vendor/google.golang.org/grpc/resolver/dns/go19.go
generated
vendored
54
vendor/google.golang.org/grpc/resolver/dns/go19.go
generated
vendored
@ -1,54 +0,0 @@
|
||||
// +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
|
||||
}
|
27
vendor/google.golang.org/grpc/resolver/dns/pre_go18_test.go
generated
vendored
27
vendor/google.golang.org/grpc/resolver/dns/pre_go18_test.go
generated
vendored
@ -1,27 +0,0 @@
|
||||
// +build go1.6, !go1.8
|
||||
|
||||
/*
|
||||
*
|
||||
* 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"
|
||||
)
|
||||
|
||||
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
51
vendor/google.golang.org/grpc/resolver/dns/pre_go19.go
generated
vendored
@ -1,51 +0,0 @@
|
||||
// +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")
|
||||
}
|
Reference in New Issue
Block a user