mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-13 06:07:34 +00:00
all: use syncs.AtomicValue
Signed-off-by: Maisem Ali <maisem@tailscale.com>
This commit is contained in:
@@ -341,8 +341,7 @@ func run(prog string, args ...string) error {
|
||||
}
|
||||
|
||||
func (t *Wrapper) destMAC() [6]byte {
|
||||
mac, _ := t.destMACAtomic.Load().([6]byte)
|
||||
return mac
|
||||
return t.destMACAtomic.Load()
|
||||
}
|
||||
|
||||
func (t *Wrapper) tapWrite(buf []byte, offset int) (int, error) {
|
||||
|
@@ -24,6 +24,7 @@ import (
|
||||
"tailscale.com/disco"
|
||||
"tailscale.com/net/packet"
|
||||
"tailscale.com/net/tsaddr"
|
||||
"tailscale.com/syncs"
|
||||
"tailscale.com/tstime/mono"
|
||||
"tailscale.com/types/ipproto"
|
||||
"tailscale.com/types/key"
|
||||
@@ -82,9 +83,9 @@ type Wrapper struct {
|
||||
// you might need to add a pad32.Four field here.
|
||||
lastActivityAtomic mono.Time // time of last send or receive
|
||||
|
||||
destIPActivity atomic.Value // of map[netip.Addr]func()
|
||||
destMACAtomic atomic.Value // of [6]byte
|
||||
discoKey atomic.Value // of key.DiscoPublic
|
||||
destIPActivity syncs.AtomicValue[map[netip.Addr]func()]
|
||||
destMACAtomic syncs.AtomicValue[[6]byte]
|
||||
discoKey syncs.AtomicValue[key.DiscoPublic]
|
||||
|
||||
// buffer stores the oldest unconsumed packet from tdev.
|
||||
// It is made a static buffer in order to avoid allocations.
|
||||
@@ -247,8 +248,8 @@ func (t *Wrapper) isSelfDisco(p *packet.Parsed) bool {
|
||||
return false
|
||||
}
|
||||
discoSrc := key.DiscoPublicFromRaw32(mem.B(discobs))
|
||||
selfDiscoPub, ok := t.discoKey.Load().(key.DiscoPublic)
|
||||
return ok && selfDiscoPub == discoSrc
|
||||
selfDiscoPub := t.discoKey.Load()
|
||||
return selfDiscoPub == discoSrc
|
||||
}
|
||||
|
||||
func (t *Wrapper) Close() error {
|
||||
@@ -543,7 +544,7 @@ func (t *Wrapper) Read(buf []byte, offset int) (int, error) {
|
||||
defer parsedPacketPool.Put(p)
|
||||
p.Decode(buf[offset : offset+n])
|
||||
|
||||
if m, ok := t.destIPActivity.Load().(map[netip.Addr]func()); ok {
|
||||
if m := t.destIPActivity.Load(); m != nil {
|
||||
if fn := m[p.Dst.Addr()]; fn != nil {
|
||||
fn()
|
||||
}
|
||||
|
Reference in New Issue
Block a user