Skip to content

Commit a1e429f

Browse files
committed
control/controlclient, types/netmap: remove unused LocalPort field
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
1 parent 526b0b6 commit a1e429f

File tree

7 files changed

+19
-43
lines changed

7 files changed

+19
-43
lines changed

control/controlclient/auto.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -668,11 +668,8 @@ func (c *Auto) SetExpirySooner(ctx context.Context, expiry time.Time) error {
668668
// them to the control server if they've changed.
669669
//
670670
// It does not retain the provided slice.
671-
//
672-
// The localPort field is unused except for integration tests in
673-
// another repo.
674-
func (c *Auto) UpdateEndpoints(localPort uint16, endpoints []tailcfg.Endpoint) {
675-
changed := c.direct.SetEndpoints(localPort, endpoints)
671+
func (c *Auto) UpdateEndpoints(endpoints []tailcfg.Endpoint) {
672+
changed := c.direct.SetEndpoints(endpoints)
676673
if changed {
677674
c.sendNewMapRequest()
678675
}

control/controlclient/client.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,10 @@ type Client interface {
7575
SetNetInfo(*tailcfg.NetInfo)
7676
// UpdateEndpoints changes the Endpoint structure that will be sent
7777
// in subsequent node registration requests.
78-
// The localPort field is unused except for integration tests in another repo.
7978
// TODO: a server-side change would let us simply upload this
8079
// in a separate http request. It has nothing to do with the rest of
8180
// the state machine.
82-
UpdateEndpoints(localPort uint16, endpoints []tailcfg.Endpoint)
81+
UpdateEndpoints(endpoints []tailcfg.Endpoint)
8382
// SetDNS sends the SetDNSRequest request to the control plane server,
8483
// requesting a DNS record be created or updated.
8584
SetDNS(context.Context, *tailcfg.SetDNSRequest) error

control/controlclient/direct.go

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ type Direct struct {
8888
netinfo *tailcfg.NetInfo
8989
endpoints []tailcfg.Endpoint
9090
everEndpoints bool // whether we've ever had non-empty endpoints
91-
localPort uint16 // or zero to mean auto
9291
lastPingURL string // last PingRequest.URL received, for dup suppression
9392
}
9493

@@ -586,20 +585,19 @@ func sameEndpoints(a, b []tailcfg.Endpoint) bool {
586585
// whether they've changed.
587586
//
588587
// It does not retain the provided slice.
589-
func (c *Direct) newEndpoints(localPort uint16, endpoints []tailcfg.Endpoint) (changed bool) {
588+
func (c *Direct) newEndpoints(endpoints []tailcfg.Endpoint) (changed bool) {
590589
c.mu.Lock()
591590
defer c.mu.Unlock()
592591

593592
// Nothing new?
594-
if c.localPort == localPort && sameEndpoints(c.endpoints, endpoints) {
593+
if sameEndpoints(c.endpoints, endpoints) {
595594
return false // unchanged
596595
}
597596
var epStrs []string
598597
for _, ep := range endpoints {
599598
epStrs = append(epStrs, ep.Addr.String())
600599
}
601-
c.logf("[v2] client.newEndpoints(%v, %v)", localPort, epStrs)
602-
c.localPort = localPort
600+
c.logf("[v2] client.newEndpoints(%v)", epStrs)
603601
c.endpoints = append(c.endpoints[:0], endpoints...)
604602
if len(endpoints) > 0 {
605603
c.everEndpoints = true
@@ -610,10 +608,10 @@ func (c *Direct) newEndpoints(localPort uint16, endpoints []tailcfg.Endpoint) (c
610608
// SetEndpoints updates the list of locally advertised endpoints.
611609
// It won't be replicated to the server until a *fresh* call to PollNetMap().
612610
// You don't need to restart PollNetMap if we return changed==false.
613-
func (c *Direct) SetEndpoints(localPort uint16, endpoints []tailcfg.Endpoint) (changed bool) {
611+
func (c *Direct) SetEndpoints(endpoints []tailcfg.Endpoint) (changed bool) {
614612
// (no log message on function entry, because it clutters the logs
615613
// if endpoints haven't changed. newEndpoints() will log it.)
616-
return c.newEndpoints(localPort, endpoints)
614+
return c.newEndpoints(endpoints)
617615
}
618616

619617
func inTest() bool { return flag.Lookup("test.v") != nil }
@@ -666,7 +664,6 @@ func (c *Direct) sendMapRequest(ctx context.Context, maxPolls int, readOnly bool
666664
serverNoiseKey := c.serverNoiseKey
667665
hi := c.hostInfoLocked()
668666
backendLogID := hi.BackendLogID
669-
localPort := c.localPort
670667
var epStrs []string
671668
var epTypes []tailcfg.EndpointType
672669
for _, ep := range c.endpoints {
@@ -692,7 +689,7 @@ func (c *Direct) sendMapRequest(ctx context.Context, maxPolls int, readOnly bool
692689
}
693690

694691
allowStream := maxPolls != 1
695-
c.logf("[v1] PollNetMap: stream=%v :%v ep=%v", allowStream, localPort, epStrs)
692+
c.logf("[v1] PollNetMap: stream=%v ep=%v", allowStream, epStrs)
696693

697694
vlogf := logger.Discard
698695
if Debug.NetMap {
@@ -948,14 +945,6 @@ func (c *Direct) sendMapRequest(ctx context.Context, maxPolls int, readOnly bool
948945
nm.SelfNode.Capabilities = nil
949946
}
950947

951-
// Get latest localPort. This might've changed if
952-
// a lite map update occurred meanwhile. This only affects
953-
// the end-to-end test.
954-
// TODO(bradfitz): remove the NetworkMap.LocalPort field entirely.
955-
c.mu.Lock()
956-
nm.LocalPort = c.localPort
957-
c.mu.Unlock()
958-
959948
// Occasionally print the netmap header.
960949
// This is handy for debugging, and our logs processing
961950
// pipeline depends on it. (TODO: Remove this dependency.)

control/controlclient/direct_test.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,22 +68,18 @@ func TestNewDirect(t *testing.T) {
6868
}
6969

7070
endpoints := fakeEndpoints(1, 2, 3)
71-
changed = c.newEndpoints(12, endpoints)
71+
changed = c.newEndpoints(endpoints)
7272
if !changed {
73-
t.Errorf("c.newEndpoints(12) want true got %v", changed)
73+
t.Errorf("c.newEndpoints want true got %v", changed)
7474
}
75-
changed = c.newEndpoints(12, endpoints)
75+
changed = c.newEndpoints(endpoints)
7676
if changed {
77-
t.Errorf("c.newEndpoints(12) want false got %v", changed)
78-
}
79-
changed = c.newEndpoints(13, endpoints)
80-
if !changed {
81-
t.Errorf("c.newEndpoints(13) want true got %v", changed)
77+
t.Errorf("c.newEndpoints want false got %v", changed)
8278
}
8379
endpoints = fakeEndpoints(4, 5, 6)
84-
changed = c.newEndpoints(13, endpoints)
80+
changed = c.newEndpoints(endpoints)
8581
if !changed {
86-
t.Errorf("c.newEndpoints(13) want true got %v", changed)
82+
t.Errorf("c.newEndpoints want true got %v", changed)
8783
}
8884
}
8985

ipn/ipnlocal/local.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ func (b *LocalBackend) setWgengineStatus(s *wgengine.Status, err error) {
796796

797797
if cc != nil {
798798
if needUpdateEndpoints {
799-
cc.UpdateEndpoints(0, s.LocalAddrs)
799+
cc.UpdateEndpoints(s.LocalAddrs)
800800
}
801801
b.stateMachine()
802802
}
@@ -1070,7 +1070,7 @@ func (b *LocalBackend) Start(opts ipn.Options) error {
10701070
b.mu.Unlock()
10711071

10721072
if endpoints != nil {
1073-
cc.UpdateEndpoints(0, endpoints)
1073+
cc.UpdateEndpoints(endpoints)
10741074
}
10751075

10761076
cc.SetStatusFunc(b.setClientStatus)

ipn/ipnlocal/state_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,9 @@ func (cc *mockControl) SetNetInfo(ni *tailcfg.NetInfo) {
258258
cc.called("SetNetInfo")
259259
}
260260

261-
func (cc *mockControl) UpdateEndpoints(localPort uint16, endpoints []tailcfg.Endpoint) {
261+
func (cc *mockControl) UpdateEndpoints(endpoints []tailcfg.Endpoint) {
262262
// validate endpoint information here?
263-
cc.logf("UpdateEndpoints: lp=%v ep=%v", localPort, endpoints)
263+
cc.logf("UpdateEndpoints: ep=%v", endpoints)
264264
cc.called("UpdateEndpoints")
265265
}
266266

types/netmap/netmap.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ type NetworkMap struct {
3232
// Name is the DNS name assigned to this node.
3333
Name string
3434
Addresses []netaddr.IPPrefix // same as tailcfg.Node.Addresses (IP addresses of this Node directly)
35-
LocalPort uint16 // used for debugging
3635
MachineStatus tailcfg.MachineStatus
3736
MachineKey key.MachinePublic
3837
Peers []*tailcfg.Node // sorted by Node.ID
@@ -148,9 +147,6 @@ func (nm *NetworkMap) printConciseHeader(buf *strings.Builder) {
148147
}
149148
}
150149
fmt.Fprintf(buf, " u=%s", login)
151-
if nm.LocalPort != 0 {
152-
fmt.Fprintf(buf, " port=%v", nm.LocalPort)
153-
}
154150
if nm.Debug != nil {
155151
j, _ := json.Marshal(nm.Debug)
156152
fmt.Fprintf(buf, " debug=%s", j)
@@ -164,7 +160,6 @@ func (nm *NetworkMap) printConciseHeader(buf *strings.Builder) {
164160
func (a *NetworkMap) equalConciseHeader(b *NetworkMap) bool {
165161
if a.NodeKey != b.NodeKey ||
166162
a.MachineStatus != b.MachineStatus ||
167-
a.LocalPort != b.LocalPort ||
168163
a.User != b.User ||
169164
len(a.Addresses) != len(b.Addresses) {
170165
return false

0 commit comments

Comments
 (0)