wgengine/magicsock: unexport AddrSet.

Signed-off-by: David Anderson <danderson@tailscale.com>
This commit is contained in:
David Anderson 2020-12-18 00:22:12 -08:00 committed by Dave Anderson
parent c9b9afd761
commit 65ae66260f
3 changed files with 39 additions and 39 deletions

View File

@ -41,7 +41,7 @@ func shouldSprayPacket(b []byte) bool {
// be fake addrs representing DERP servers.
//
// It also returns as's current roamAddr, if any.
func (as *AddrSet) appendDests(dsts []netaddr.IPPort, b []byte) (_ []netaddr.IPPort, roamAddr netaddr.IPPort) {
func (as *addrSet) appendDests(dsts []netaddr.IPPort, b []byte) (_ []netaddr.IPPort, roamAddr netaddr.IPPort) {
spray := shouldSprayPacket(b) // true for handshakes
now := as.timeNow()
@ -127,11 +127,11 @@ func (as *AddrSet) appendDests(dsts []netaddr.IPPort, b []byte) (_ []netaddr.IPP
return dsts, roamAddr
}
// AddrSet is a set of UDP addresses that implements wireguard/conn.Endpoint.
// addrSet is a set of UDP addresses that implements wireguard/conn.Endpoint.
//
// This is the legacy endpoint for peers that don't support discovery;
// it predates discoEndpoint.
type AddrSet struct {
type addrSet struct {
publicKey key.Public // peer public key used for DERP communication
// addrs is an ordered priority list provided by wgengine,
@ -180,8 +180,8 @@ type AddrSet struct {
loggedLogPriMask uint32
}
// derpID returns this AddrSet's home DERP node, or 0 if none is found.
func (as *AddrSet) derpID() int {
// derpID returns this addrSet's home DERP node, or 0 if none is found.
func (as *addrSet) derpID() int {
for _, ua := range as.addrs {
if ua.IP.Equal(derpMagicIP) {
return ua.Port
@ -190,7 +190,7 @@ func (as *AddrSet) derpID() int {
return 0
}
func (as *AddrSet) timeNow() time.Time {
func (as *addrSet) timeNow() time.Time {
if as.clock != nil {
return as.clock()
}
@ -199,7 +199,7 @@ func (as *AddrSet) timeNow() time.Time {
var noAddr, _ = netaddr.FromStdAddr(net.ParseIP("127.127.127.127"), 127, "")
func (a *AddrSet) dst() netaddr.IPPort {
func (a *addrSet) dst() netaddr.IPPort {
a.mu.Lock()
defer a.mu.Unlock()
@ -229,21 +229,21 @@ func packUDPAddr(ua *net.UDPAddr) []byte {
return b
}
func (a *AddrSet) DstToBytes() []byte {
func (a *addrSet) DstToBytes() []byte {
return packIPPort(a.dst())
}
func (a *AddrSet) DstToString() string {
func (a *addrSet) DstToString() string {
dst := a.dst()
return dst.String()
}
func (a *AddrSet) DstIP() net.IP {
func (a *addrSet) DstIP() net.IP {
return a.dst().IP.IPAddr().IP // TODO: add netaddr accessor to cut an alloc here?
}
func (a *AddrSet) SrcIP() net.IP { return nil }
func (a *AddrSet) SrcToString() string { return "" }
func (a *AddrSet) ClearSrc() {}
func (a *addrSet) SrcIP() net.IP { return nil }
func (a *addrSet) SrcToString() string { return "" }
func (a *addrSet) ClearSrc() {}
func (a *AddrSet) UpdateDst(new *net.UDPAddr) error {
func (a *addrSet) UpdateDst(new *net.UDPAddr) error {
if new.IP.Equal(derpMagicIP) {
// Never consider DERP addresses as a viable candidate for
// either curAddr or roamAddr. It's only ever a last resort
@ -327,7 +327,7 @@ func equalUDPAddr(x, y *net.UDPAddr) bool {
return x.Port == y.Port && x.IP.Equal(y.IP)
}
func (a *AddrSet) String() string {
func (a *addrSet) String() string {
a.mu.Lock()
defer a.mu.Unlock()
@ -351,7 +351,7 @@ func (a *AddrSet) String() string {
return buf.String()
}
func (as *AddrSet) populatePeerStatus(ps *ipnstate.PeerStatus) {
func (as *addrSet) populatePeerStatus(ps *ipnstate.PeerStatus) {
as.mu.Lock()
defer as.mu.Unlock()
@ -371,7 +371,7 @@ func (as *AddrSet) populatePeerStatus(ps *ipnstate.PeerStatus) {
}
}
func (a *AddrSet) Addrs() []wgcfg.Endpoint {
func (a *addrSet) Addrs() []wgcfg.Endpoint {
var eps []wgcfg.Endpoint
for _, addr := range a.addrs {
eps = append(eps, wgcfg.Endpoint{

View File

@ -222,13 +222,13 @@ type Conn struct {
//
// Used only to communicate with legacy, pre-active-discovery
// clients.
addrsByUDP map[netaddr.IPPort]*AddrSet
addrsByUDP map[netaddr.IPPort]*addrSet
// addrsByKey maps from public keys (as seen by incoming DERP
// packets) to its AddrSet (the same values as in addrsByUDP).
// packets) to its addrSet (the same values as in addrsByUDP).
//
// Used only to communicate with legacy, pre-active-discovery
// clients.
addrsByKey map[key.Public]*AddrSet
addrsByKey map[key.Public]*addrSet
// netInfoFunc is a callback that provides a tailcfg.NetInfo when
// discovered network conditions change.
@ -411,8 +411,8 @@ func (o *Options) derpActiveFunc() func() {
func newConn() *Conn {
c := &Conn{
sendLogLimit: rate.NewLimiter(rate.Every(1*time.Minute), 1),
addrsByUDP: make(map[netaddr.IPPort]*AddrSet),
addrsByKey: make(map[key.Public]*AddrSet),
addrsByUDP: make(map[netaddr.IPPort]*addrSet),
addrsByKey: make(map[key.Public]*addrSet),
derpRecvCh: make(chan derpReadResult),
udpRecvCh: make(chan udpReadResult),
derpStarted: make(chan struct{}),
@ -973,7 +973,7 @@ func (c *Conn) Send(b []byte, ep conn.Endpoint) error {
return errNetworkDown
}
var as *AddrSet
var as *addrSet
switch v := ep.(type) {
default:
panic(fmt.Sprintf("[unexpected] Endpoint type %T", v))
@ -987,7 +987,7 @@ func (c *Conn) Send(b []byte, ep conn.Endpoint) error {
}
_, err := c.sendUDPStd(addr, b)
return err
case *AddrSet:
case *addrSet:
as = v
}
@ -1430,7 +1430,7 @@ func (c *Conn) findEndpoint(ipp netaddr.IPPort, addr *net.UDPAddr) conn.Endpoint
}
}
// Pre-disco: look up their AddrSet.
// Pre-disco: look up their addrSet.
if as, ok := c.addrsByUDP[ipp]; ok {
return as
}
@ -1533,7 +1533,7 @@ func (c *Conn) ReceiveIPv4(b []byte) (n int, ep conn.Endpoint, addr *net.UDPAddr
// to udpRecvCh. The code below must not access b until it's
// completed a successful receive on udpRecvCh.
var addrSet *AddrSet
var addrSet *addrSet
var discoEp *discoEndpoint
var ipp netaddr.IPPort
var didNoteRecvActivity bool
@ -2588,7 +2588,7 @@ func (c *Conn) CreateEndpoint(pubKey [32]byte, addrs string) (conn.Endpoint, err
return de, nil
}
a := &AddrSet{
a := &addrSet{
Logf: c.logf,
publicKey: pk,
curAddr: -1,

View File

@ -442,8 +442,8 @@ func TestPickDERPFallback(t *testing.T) {
// But move if peers are elsewhere.
const otherNode = 789
c.addrsByKey = map[key.Public]*AddrSet{
key.Public{1}: &AddrSet{addrs: []net.UDPAddr{{IP: derpMagicIP, Port: otherNode}}},
c.addrsByKey = map[key.Public]*addrSet{
key.Public{1}: &addrSet{addrs: []net.UDPAddr{{IP: derpMagicIP, Port: otherNode}}},
}
if got := c.pickDERPFallback(); got != otherNode {
t.Errorf("didn't join peers: got %v; want %v", got, someNode)
@ -1075,7 +1075,7 @@ func testTwoDevicePing(t *testing.T, d *devices) {
})
}
// TestAddrSet tests AddrSet appendDests and UpdateDst.
// TestAddrSet tests addrSet appendDests and UpdateDst.
func TestAddrSet(t *testing.T) {
tstest.PanicOnLog()
rc := tstest.NewResourceCheck()
@ -1134,13 +1134,13 @@ type step struct {
}
tests := []struct {
name string
as *AddrSet
as *addrSet
steps []step
logCheck func(t *testing.T, logged []byte)
}{
{
name: "reg_packet_no_curaddr",
as: &AddrSet{
as: &addrSet{
addrs: udpAddrs("127.3.3.40:1", "123.45.67.89:123", "10.0.0.1:123"),
curAddr: -1, // unknown
roamAddr: nil,
@ -1151,7 +1151,7 @@ type step struct {
},
{
name: "reg_packet_have_curaddr",
as: &AddrSet{
as: &addrSet{
addrs: udpAddrs("127.3.3.40:1", "123.45.67.89:123", "10.0.0.1:123"),
curAddr: 1, // global IP
roamAddr: nil,
@ -1162,7 +1162,7 @@ type step struct {
},
{
name: "reg_packet_have_roamaddr",
as: &AddrSet{
as: &addrSet{
addrs: udpAddrs("127.3.3.40:1", "123.45.67.89:123", "10.0.0.1:123"),
curAddr: 2, // should be ignored
roamAddr: mustIPPortPtr("5.6.7.8:123"),
@ -1175,7 +1175,7 @@ type step struct {
},
{
name: "start_roaming",
as: &AddrSet{
as: &addrSet{
addrs: udpAddrs("127.3.3.40:1", "123.45.67.89:123", "10.0.0.1:123"),
curAddr: 2,
},
@ -1191,7 +1191,7 @@ type step struct {
},
{
name: "spray_packet",
as: &AddrSet{
as: &addrSet{
addrs: udpAddrs("127.3.3.40:1", "123.45.67.89:123", "10.0.0.1:123"),
curAddr: 2, // should be ignored
roamAddr: mustIPPortPtr("5.6.7.8:123"),
@ -1207,7 +1207,7 @@ type step struct {
},
{
name: "low_pri",
as: &AddrSet{
as: &addrSet{
addrs: udpAddrs("127.3.3.40:1", "123.45.67.89:123", "10.0.0.1:123"),
curAddr: 2,
},
@ -1254,9 +1254,9 @@ type step struct {
}
}
// initAddrSet initializes fields in the provided incomplete AddrSet
// initAddrSet initializes fields in the provided incomplete addrSet
// to satisfying invariants within magicsock.
func initAddrSet(as *AddrSet) {
func initAddrSet(as *addrSet) {
if as.roamAddr != nil && as.roamAddrStd == nil {
as.roamAddrStd = as.roamAddr.UDPAddr()
}