@ -18,8 +18,8 @@ import (
"golang.org/x/net/http2"
"golang.org/x/net/http2"
"tailscale.com/control/controlhttp"
"tailscale.com/control/controlhttp"
"tailscale.com/control/ts2021"
"tailscale.com/health"
"tailscale.com/health"
"tailscale.com/internal/noiseconn"
"tailscale.com/net/dnscache"
"tailscale.com/net/dnscache"
"tailscale.com/net/netmon"
"tailscale.com/net/netmon"
"tailscale.com/net/tsdial"
"tailscale.com/net/tsdial"
@ -50,7 +50,7 @@ type NoiseClient struct {
// sfDial ensures that two concurrent requests for a noise connection only
// sfDial ensures that two concurrent requests for a noise connection only
// produce one shared one between the two callers.
// produce one shared one between the two callers.
sfDial singleflight . Group [ struct { } , * noiseconn . Conn ]
sfDial singleflight . Group [ struct { } , * ts2021 . Conn ]
dialer * tsdial . Dialer
dialer * tsdial . Dialer
dnsCache * dnscache . Resolver
dnsCache * dnscache . Resolver
@ -72,9 +72,9 @@ type NoiseClient struct {
// mu only protects the following variables.
// mu only protects the following variables.
mu sync . Mutex
mu sync . Mutex
closed bool
closed bool
last * noiseconn . Conn // or nil
last * ts2021 . Conn // or nil
nextID int
nextID int
connPool map [ int ] * noiseconn. Conn // active connections not yet closed; see noiseconn .Conn.Close
connPool map [ int ] * ts2021. Conn // active connections not yet closed; see ts2021 .Conn.Close
}
}
// NoiseOpts contains options for the NewNoiseClient function. All fields are
// NoiseOpts contains options for the NewNoiseClient function. All fields are
@ -195,12 +195,12 @@ func (e contextErr) Unwrap() error {
return e . err
return e . err
}
}
// getConn returns a noiseconn .Conn that can be used to make requests to the
// getConn returns a ts2021 .Conn that can be used to make requests to the
// coordination server. It may return a cached connection or create a new one.
// coordination server. It may return a cached connection or create a new one.
// Dials are singleflighted, so concurrent calls to getConn may only dial once.
// Dials are singleflighted, so concurrent calls to getConn may only dial once.
// As such, context values may not be respected as there are no guarantees that
// As such, context values may not be respected as there are no guarantees that
// the context passed to getConn is the same as the context passed to dial.
// the context passed to getConn is the same as the context passed to dial.
func ( nc * NoiseClient ) getConn ( ctx context . Context ) ( * noiseconn . Conn , error ) {
func ( nc * NoiseClient ) getConn ( ctx context . Context ) ( * ts2021 . Conn , error ) {
nc . mu . Lock ( )
nc . mu . Lock ( )
if last := nc . last ; last != nil && last . CanTakeNewRequest ( ) {
if last := nc . last ; last != nil && last . CanTakeNewRequest ( ) {
nc . mu . Unlock ( )
nc . mu . Unlock ( )
@ -214,7 +214,7 @@ func (nc *NoiseClient) getConn(ctx context.Context) (*noiseconn.Conn, error) {
// canceled. Instead, we have to additionally check that the context
// canceled. Instead, we have to additionally check that the context
// which was canceled is our context and retry if our context is still
// which was canceled is our context and retry if our context is still
// valid.
// valid.
conn , err , _ := nc . sfDial . Do ( struct { } { } , func ( ) ( * noiseconn . Conn , error ) {
conn , err , _ := nc . sfDial . Do ( struct { } { } , func ( ) ( * ts2021 . Conn , error ) {
c , err := nc . dial ( ctx )
c , err := nc . dial ( ctx )
if err != nil {
if err != nil {
if ctx . Err ( ) != nil {
if ctx . Err ( ) != nil {
@ -282,7 +282,7 @@ func (nc *NoiseClient) Close() error {
// dial opens a new connection to tailcontrol, fetching the server noise key
// dial opens a new connection to tailcontrol, fetching the server noise key
// if not cached.
// if not cached.
func ( nc * NoiseClient ) dial ( ctx context . Context ) ( * noiseconn . Conn , error ) {
func ( nc * NoiseClient ) dial ( ctx context . Context ) ( * ts2021 . Conn , error ) {
nc . mu . Lock ( )
nc . mu . Lock ( )
connID := nc . nextID
connID := nc . nextID
nc . nextID ++
nc . nextID ++
@ -352,7 +352,7 @@ func (nc *NoiseClient) dial(ctx context.Context) (*noiseconn.Conn, error) {
return nil , err
return nil , err
}
}
ncc , err := noiseconn . New ( clientConn . Conn , nc . h2t , connID , nc . connClosed )
ncc , err := ts2021 . New ( clientConn . Conn , nc . h2t , connID , nc . connClosed )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}