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.
|
// Set the default codec.
|
||||||
cc.dopts.codec = protoCodec{}
|
cc.dopts.codec = protoCodec{}
|
||||||
}
|
}
|
||||||
|
cc.stateCV = sync.NewCond(&cc.mu)
|
||||||
if cc.dopts.block {
|
if cc.dopts.block {
|
||||||
if err := cc.resetTransport(false); err != nil {
|
if err := cc.resetTransport(false); err != nil {
|
||||||
cc.Close()
|
cc.Close()
|
||||||
@ -188,8 +189,9 @@ type ClientConn struct {
|
|||||||
dopts dialOptions
|
dopts dialOptions
|
||||||
shutdownChan chan struct{}
|
shutdownChan chan struct{}
|
||||||
|
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
state ConnectivityState
|
state ConnectivityState
|
||||||
|
stateCV *sync.Cond
|
||||||
// ready is closed and becomes nil when a new transport is up or failed
|
// ready is closed and becomes nil when a new transport is up or failed
|
||||||
// due to timeout.
|
// due to timeout.
|
||||||
ready chan struct{}
|
ready chan struct{}
|
||||||
@ -200,6 +202,40 @@ type ClientConn struct {
|
|||||||
transport transport.ClientTransport
|
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 {
|
func (cc *ClientConn) resetTransport(closeTransport bool) error {
|
||||||
var retries int
|
var retries int
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
@ -51,7 +51,7 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
// alpnProtoStr are the specified application level protocols for gRPC.
|
// 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
|
// Credentials defines the common interface all supported credentials must
|
||||||
|
Reference in New Issue
Block a user