-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwireguard_connection_manager.go
61 lines (45 loc) · 1.56 KB
/
wireguard_connection_manager.go
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
54
55
56
57
58
59
60
61
package main
import "sync"
type IWireguardConnectionManager interface {
// 初始化
Initial(configPath, templatePath, serviceDestPath, configDestPath, executionPath, localLibraryPath string)
// 加载数据
LoadData() (map[int]UDP2RawConnection, error)
// 打印列表
List()
// 保存数据
SaveConfig() error
// 添加链接
Add(item UDP2RawConnection) error
// 删除链接
Remove(key int) bool
// 是否存在
ContainsKey(key int) bool
// 获取
Get(key int) (*UDP2RawConnection, error)
// 同步物理文件
SyncPhysicalFiles(item UDP2RawConnection) (string, string)
// 切换状态
ToggleStatus(conn UDP2RawConnection) UDP2RawConnectionStatusType
}
type WireguardConnectionManager struct {
mu sync.Mutex
data map[string]*WireGuardInterfacePeer
ConfigPath, TemplatePath, ServiceDestPath, ConfigDestPath, ExecutionPath, LocalLibraryPath string
}
type WireGuardInterfacePeer struct {
PublicKey string `json:"publicKey"`
Endpoint string `json:"endpoint"`
AllowedIps string `json:"allowedIps"`
TransferIn string `json:"transferIn"`
TransferOut string `json:"transferOut"`
KeepAlive string `json:"keepAlive"`
LatestHandshake string `json:"latestHandshake"`
}
type WireguardInterface struct {
Address string `json:"address"`
PublicKey string `json:"publicKey"`
PrivateKey string `json:"privateKey"`
ListenPort string `json:"listenPort"`
Peers map[string]WireGuardInterfacePeer `json:"peers"`
}