mirror of
https://github.com/tailscale/tailscale.git
synced 2025-10-09 08:01:31 +00:00
control/controlclient, wgengine/magicsock: misc cleanups
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:

committed by
Brad Fitzpatrick

parent
58ce50389e
commit
587c3fcac4
@@ -2,7 +2,8 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Package controlclient implements the client for the IPN control plane.
|
||||
// Package controlclient implements the client for the Tailscale
|
||||
// control plane.
|
||||
//
|
||||
// It handles authentication, port picking, and collects the local
|
||||
// network configuration.
|
||||
@@ -565,10 +566,8 @@ func (c *Client) Logout() {
|
||||
}
|
||||
|
||||
func (c *Client) UpdateEndpoints(localPort uint16, endpoints []string) {
|
||||
changed, err := c.direct.SetEndpoints(localPort, endpoints)
|
||||
if err != nil {
|
||||
c.sendStatus("updateEndpoints", err, "", nil)
|
||||
} else if changed {
|
||||
changed := c.direct.SetEndpoints(localPort, endpoints)
|
||||
if changed {
|
||||
c.cancelMapSafely()
|
||||
}
|
||||
}
|
||||
|
@@ -71,7 +71,7 @@ type Direct struct {
|
||||
expiry *time.Time
|
||||
hostinfo tailcfg.Hostinfo
|
||||
endpoints []string
|
||||
localPort uint16
|
||||
localPort uint16 // or zero to mean auto
|
||||
}
|
||||
|
||||
type Options struct {
|
||||
@@ -363,7 +363,11 @@ func sameStrings(a, b []string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (c *Direct) newEndpoints(localPort uint16, endpoints []string) bool {
|
||||
// newEndpoints acquires c.mu and sets the local port and endpoints and reports
|
||||
// whether they've changed.
|
||||
//
|
||||
// It does not retain the provided slice.
|
||||
func (c *Direct) newEndpoints(localPort uint16, endpoints []string) (changed bool) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
|
||||
@@ -372,23 +376,18 @@ func (c *Direct) newEndpoints(localPort uint16, endpoints []string) bool {
|
||||
return false // unchanged
|
||||
}
|
||||
c.logf("client.newEndpoints(%v, %v)\n", localPort, endpoints)
|
||||
if len(c.endpoints) > 0 {
|
||||
// empty the old list without deallocating it
|
||||
c.endpoints = c.endpoints[:0]
|
||||
}
|
||||
c.localPort = localPort
|
||||
c.endpoints = append(c.endpoints, endpoints...)
|
||||
c.endpoints = append(c.endpoints[:0], endpoints...)
|
||||
return true // changed
|
||||
}
|
||||
|
||||
// SetEndpoints updates the list of locally advertised endpoints.
|
||||
// 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.
|
||||
func (c *Direct) SetEndpoints(localPort uint16, endpoints []string) (changed bool, err error) {
|
||||
func (c *Direct) SetEndpoints(localPort uint16, endpoints []string) (changed bool) {
|
||||
// (no log message on function entry, because it clutters the logs
|
||||
// if endpoints haven't changed. newEndpoints() will log it.)
|
||||
changed = c.newEndpoints(localPort, endpoints)
|
||||
return changed, nil
|
||||
return c.newEndpoints(localPort, endpoints)
|
||||
}
|
||||
|
||||
func (c *Direct) PollNetMap(ctx context.Context, maxPolls int, cb func(*NetworkMap)) error {
|
||||
|
Reference in New Issue
Block a user