-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauto.go
More file actions
53 lines (41 loc) · 908 Bytes
/
auto.go
File metadata and controls
53 lines (41 loc) · 908 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"sync"
"github.com/easymesh/autoproxy-windows/engin"
)
type LocalAccessInfo struct {
Hostname string
Access bool
}
type AutoCtrl struct {
sync.RWMutex
cache map[string]LocalAccessInfo
}
var autoCtrl AutoCtrl
func init() {
autoCtrl.cache = make(map[string]LocalAccessInfo, 100)
}
func AutoCheck(address string) bool {
autoCtrl.RLock()
result, ok := autoCtrl.cache[address]
autoCtrl.RUnlock()
if ok {
return result.Access
}
result.Hostname = address
result.Access = engin.IsConnect(address, 3)
autoCtrl.Lock()
autoCtrl.cache[address] = result
autoCtrl.Unlock()
return result.Access
}
func AutoCheckUpdate(address string, access bool) {
autoCtrl.RLock()
result, ok := autoCtrl.cache[address]
autoCtrl.RUnlock()
if !ok || result.Access != access {
autoCtrl.Lock()
autoCtrl.cache[address] = LocalAccessInfo{address, access}
autoCtrl.Unlock()
}
}