|
|
@ -88,7 +88,6 @@ type Direct struct {
|
|
|
|
netinfo *tailcfg.NetInfo
|
|
|
|
netinfo *tailcfg.NetInfo
|
|
|
|
endpoints []tailcfg.Endpoint
|
|
|
|
endpoints []tailcfg.Endpoint
|
|
|
|
everEndpoints bool // whether we've ever had non-empty endpoints
|
|
|
|
everEndpoints bool // whether we've ever had non-empty endpoints
|
|
|
|
localPort uint16 // or zero to mean auto
|
|
|
|
|
|
|
|
lastPingURL string // last PingRequest.URL received, for dup suppression
|
|
|
|
lastPingURL string // last PingRequest.URL received, for dup suppression
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -586,20 +585,19 @@ func sameEndpoints(a, b []tailcfg.Endpoint) bool {
|
|
|
|
// whether they've changed.
|
|
|
|
// whether they've changed.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// It does not retain the provided slice.
|
|
|
|
// It does not retain the provided slice.
|
|
|
|
func (c *Direct) newEndpoints(localPort uint16, endpoints []tailcfg.Endpoint) (changed bool) {
|
|
|
|
func (c *Direct) newEndpoints(endpoints []tailcfg.Endpoint) (changed bool) {
|
|
|
|
c.mu.Lock()
|
|
|
|
c.mu.Lock()
|
|
|
|
defer c.mu.Unlock()
|
|
|
|
defer c.mu.Unlock()
|
|
|
|
|
|
|
|
|
|
|
|
// Nothing new?
|
|
|
|
// Nothing new?
|
|
|
|
if c.localPort == localPort && sameEndpoints(c.endpoints, endpoints) {
|
|
|
|
if sameEndpoints(c.endpoints, endpoints) {
|
|
|
|
return false // unchanged
|
|
|
|
return false // unchanged
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var epStrs []string
|
|
|
|
var epStrs []string
|
|
|
|
for _, ep := range endpoints {
|
|
|
|
for _, ep := range endpoints {
|
|
|
|
epStrs = append(epStrs, ep.Addr.String())
|
|
|
|
epStrs = append(epStrs, ep.Addr.String())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c.logf("[v2] client.newEndpoints(%v, %v)", localPort, epStrs)
|
|
|
|
c.logf("[v2] client.newEndpoints(%v)", epStrs)
|
|
|
|
c.localPort = localPort
|
|
|
|
|
|
|
|
c.endpoints = append(c.endpoints[:0], endpoints...)
|
|
|
|
c.endpoints = append(c.endpoints[:0], endpoints...)
|
|
|
|
if len(endpoints) > 0 {
|
|
|
|
if len(endpoints) > 0 {
|
|
|
|
c.everEndpoints = true
|
|
|
|
c.everEndpoints = true
|
|
|
@ -610,10 +608,10 @@ func (c *Direct) newEndpoints(localPort uint16, endpoints []tailcfg.Endpoint) (c
|
|
|
|
// SetEndpoints updates the list of locally advertised endpoints.
|
|
|
|
// SetEndpoints updates the list of locally advertised endpoints.
|
|
|
|
// It won't be replicated to the server until a *fresh* call to PollNetMap().
|
|
|
|
// It won't be replicated to the server until a *fresh* call to PollNetMap().
|
|
|
|
// You don't need to restart PollNetMap if we return changed==false.
|
|
|
|
// You don't need to restart PollNetMap if we return changed==false.
|
|
|
|
func (c *Direct) SetEndpoints(localPort uint16, endpoints []tailcfg.Endpoint) (changed bool) {
|
|
|
|
func (c *Direct) SetEndpoints(endpoints []tailcfg.Endpoint) (changed bool) {
|
|
|
|
// (no log message on function entry, because it clutters the logs
|
|
|
|
// (no log message on function entry, because it clutters the logs
|
|
|
|
// if endpoints haven't changed. newEndpoints() will log it.)
|
|
|
|
// if endpoints haven't changed. newEndpoints() will log it.)
|
|
|
|
return c.newEndpoints(localPort, endpoints)
|
|
|
|
return c.newEndpoints(endpoints)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func inTest() bool { return flag.Lookup("test.v") != nil }
|
|
|
|
func inTest() bool { return flag.Lookup("test.v") != nil }
|
|
|
@ -666,7 +664,6 @@ func (c *Direct) sendMapRequest(ctx context.Context, maxPolls int, readOnly bool
|
|
|
|
serverNoiseKey := c.serverNoiseKey
|
|
|
|
serverNoiseKey := c.serverNoiseKey
|
|
|
|
hi := c.hostInfoLocked()
|
|
|
|
hi := c.hostInfoLocked()
|
|
|
|
backendLogID := hi.BackendLogID
|
|
|
|
backendLogID := hi.BackendLogID
|
|
|
|
localPort := c.localPort
|
|
|
|
|
|
|
|
var epStrs []string
|
|
|
|
var epStrs []string
|
|
|
|
var epTypes []tailcfg.EndpointType
|
|
|
|
var epTypes []tailcfg.EndpointType
|
|
|
|
for _, ep := range c.endpoints {
|
|
|
|
for _, ep := range c.endpoints {
|
|
|
@ -692,7 +689,7 @@ func (c *Direct) sendMapRequest(ctx context.Context, maxPolls int, readOnly bool
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
allowStream := maxPolls != 1
|
|
|
|
allowStream := maxPolls != 1
|
|
|
|
c.logf("[v1] PollNetMap: stream=%v :%v ep=%v", allowStream, localPort, epStrs)
|
|
|
|
c.logf("[v1] PollNetMap: stream=%v ep=%v", allowStream, epStrs)
|
|
|
|
|
|
|
|
|
|
|
|
vlogf := logger.Discard
|
|
|
|
vlogf := logger.Discard
|
|
|
|
if Debug.NetMap {
|
|
|
|
if Debug.NetMap {
|
|
|
@ -948,14 +945,6 @@ func (c *Direct) sendMapRequest(ctx context.Context, maxPolls int, readOnly bool
|
|
|
|
nm.SelfNode.Capabilities = nil
|
|
|
|
nm.SelfNode.Capabilities = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Get latest localPort. This might've changed if
|
|
|
|
|
|
|
|
// a lite map update occurred meanwhile. This only affects
|
|
|
|
|
|
|
|
// the end-to-end test.
|
|
|
|
|
|
|
|
// TODO(bradfitz): remove the NetworkMap.LocalPort field entirely.
|
|
|
|
|
|
|
|
c.mu.Lock()
|
|
|
|
|
|
|
|
nm.LocalPort = c.localPort
|
|
|
|
|
|
|
|
c.mu.Unlock()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Occasionally print the netmap header.
|
|
|
|
// Occasionally print the netmap header.
|
|
|
|
// This is handy for debugging, and our logs processing
|
|
|
|
// This is handy for debugging, and our logs processing
|
|
|
|
// pipeline depends on it. (TODO: Remove this dependency.)
|
|
|
|
// pipeline depends on it. (TODO: Remove this dependency.)
|
|
|
|