File tree Expand file tree Collapse file tree 1 file changed +6
-4
lines changed
Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package net // import "github.com/xtls/xray-core/common/net"
33
44import (
55 "net"
6+ "sync"
67 "sync/atomic"
78 "time"
89
@@ -21,22 +22,23 @@ const ChromeH2KeepAlivePeriod = 45 * time.Second
2122
2223var ErrNotLocal = errors .New ("the source address is not from local machine." )
2324
24- type localIPCahceEntry struct {
25+ type localIPCacheEntry struct {
2526 addrs []net.Addr
2627 lastUpdate time.Time
28+ update sync.Once
2729}
2830
29- var localIPCahce = atomic.Pointer [localIPCahceEntry ]{}
31+ var localIPCache = atomic.Pointer [localIPCacheEntry ]{}
3032
3133func IsLocal (ip net.IP ) (bool , error ) {
3234 var addrs []net.Addr
33- if entry := localIPCahce .Load (); entry == nil || time .Since (entry .lastUpdate ) > time .Minute {
35+ if entry := localIPCache .Load (); entry == nil || time .Since (entry .lastUpdate ) > time .Minute {
3436 var err error
3537 addrs , err = net .InterfaceAddrs ()
3638 if err != nil {
3739 return false , err
3840 }
39- localIPCahce .Store (& localIPCahceEntry {
41+ localIPCache .Store (& localIPCacheEntry {
4042 addrs : addrs ,
4143 lastUpdate : time .Now (),
4244 })
You can’t perform that action at this time.
0 commit comments