Switch ALPN/NPN to advertise only h2
This commit is contained in:
@ -144,6 +144,7 @@ func Dial(target string, opts ...DialOption) (*ClientConn, error) {
|
||||
// Set the default codec.
|
||||
cc.dopts.codec = protoCodec{}
|
||||
}
|
||||
cc.stateCV = sync.NewCond(&cc.mu)
|
||||
if cc.dopts.block {
|
||||
if err := cc.resetTransport(false); err != nil {
|
||||
cc.Close()
|
||||
@ -190,6 +191,7 @@ type ClientConn struct {
|
||||
|
||||
mu sync.Mutex
|
||||
state ConnectivityState
|
||||
stateCV *sync.Cond
|
||||
// ready is closed and becomes nil when a new transport is up or failed
|
||||
// due to timeout.
|
||||
ready chan struct{}
|
||||
@ -200,6 +202,40 @@ type ClientConn struct {
|
||||
transport transport.ClientTransport
|
||||
}
|
||||
|
||||
// State returns the connectivity state of the ClientConn
|
||||
func (cc *ClientConn) State() ConnectivityState {
|
||||
cc.mu.Lock()
|
||||
defer cc.mu.Unlock()
|
||||
return cc.state
|
||||
}
|
||||
|
||||
// WaitForStateChange returns true when the state changes to something other than the
|
||||
// sourceState and false if timeout fires.
|
||||
func (cc *ClientConn) WaitForStateChange(timeout time.Duration, sourceState ConnectivityState) bool {
|
||||
cc.mu.Lock()
|
||||
defer cc.mu.Unlock()
|
||||
if sourceState != cc.state {
|
||||
return true
|
||||
}
|
||||
// Shutdown state is a sink -- once it is entered, no furhter state change could happen.
|
||||
if sourceState == Shutdown {
|
||||
return false
|
||||
}
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
select {
|
||||
case <-time.After(timeout):
|
||||
cc.stateCV.Broadcast()
|
||||
case <-done:
|
||||
}
|
||||
}()
|
||||
for sourceState == cc.state {
|
||||
cc.stateCV.Wait()
|
||||
}
|
||||
close(done)
|
||||
return true
|
||||
}
|
||||
|
||||
func (cc *ClientConn) resetTransport(closeTransport bool) error {
|
||||
var retries int
|
||||
start := time.Now()
|
||||
|
@ -51,7 +51,7 @@ import (
|
||||
|
||||
var (
|
||||
// alpnProtoStr are the specified application level protocols for gRPC.
|
||||
alpnProtoStr = []string{"h2", "h2-14", "h2-15", "h2-16"}
|
||||
alpnProtoStr = []string{"h2"}
|
||||
)
|
||||
|
||||
// Credentials defines the common interface all supported credentials must
|
||||
|
Reference in New Issue
Block a user