Skip to content

Commit 0353998

Browse files
authored
typo
1 parent 2acaebd commit 0353998

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

common/net/net.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package net // import "github.com/xtls/xray-core/common/net"
33

44
import (
55
"net"
6+
"sync"
67
"sync/atomic"
78
"time"
89

@@ -21,22 +22,23 @@ const ChromeH2KeepAlivePeriod = 45 * time.Second
2122

2223
var 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

3133
func 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
})

0 commit comments

Comments
 (0)