-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathcore.go
More file actions
59 lines (47 loc) · 1.06 KB
/
core.go
File metadata and controls
59 lines (47 loc) · 1.06 KB
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
package libcore
import (
"os"
"github.com/sagernet/libping"
"github.com/v2fly/v2ray-core/v5/common/net"
"libcore/stun"
)
//go:generate go run ./errorgen
func Setenv(key, value string) error {
return os.Setenv(key, value)
}
func Unsetenv(key string) error {
return os.Unsetenv(key)
}
func IcmpPing(address string, timeout int32) (int32, error) {
return libping.IcmpPing(address, timeout)
}
const (
StunNoResult int32 = iota
StunEndpointIndependentNoNAT
StunEndpointIndependent
StunAddressDependent
StunAddressAndPortDependent
)
type StunResult struct {
NatMapping int32
NatFiltering int32
}
func StunTest(serverAddress string, socksPort int32) (*StunResult, error) {
natMapping, natFiltering, err := stun.Test(serverAddress, int(socksPort))
if err != nil {
return nil, err
}
return &StunResult{
NatMapping: int32(natMapping),
NatFiltering: int32(natFiltering),
}, nil
}
func EnableConnectionPool() {
net.EnableConnectionPool()
}
func DisableConnectionPool() {
net.DisableConnectionPool()
}
func ResetConnections() {
net.ResetConnections()
}