-
Notifications
You must be signed in to change notification settings - Fork 82
/
vmess.go
95 lines (87 loc) · 2.29 KB
/
vmess.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package features
import (
"context"
"encoding/json"
"fmt"
"net"
vnet "github.com/xtls/xray-core/common/net"
vcore "github.com/xtls/xray-core/core"
)
type VmessOptions struct {
UseIPv6 bool `json:"useIPv6"`
Loglevel string `json:"logLevel"`
RouteMode int `json:"routeMode"` // for SSRRAY
DisableDNSCache bool `json:"disableDNSCache"` // for SSRRAY
EnableSniffing bool `json:"enableSniffing"`
DNS string `json:"dns"` // DNS Config
AllowInsecure bool `json:"allowInsecure"`
Mux int `json:"mux"`
LocalPort int `json:"localPort"`
ServerName string `json:"serverName"`
}
func NewVmessOptions(opt []byte) VmessOptions {
var options VmessOptions
err := json.Unmarshal(opt, &options)
if err != nil {
options = VmessOptions{
UseIPv6: false,
Loglevel: "error",
RouteMode: 0,
EnableSniffing: true,
DNS: "1.1.1.1:53,223.5.5.5:53",
AllowInsecure: true,
Mux: -1,
}
}
if options.Mux < 1 {
options.Mux = -1
}
return options
}
type Vmess struct {
Host string
Path string
TLS string
Add string
Port int
Aid int
Net string
ID string
Type string // headerType
Security string // vnext.Security
Encryption string // VlessUser.encryption
Flow string // VlessUser.flow
SNI string // tls sni
Protocol string
VmessOptions
Trojan *Trojan
Shadowsocks *Shadowsocks
}
func NewVmess(Host string, Path string, TLS string, Add string, Port int, Aid int, Net string, ID string, Type string, Security string, opt []byte) *Vmess {
var options VmessOptions = NewVmessOptions(opt)
return &Vmess{
Host: Host,
Path: Path,
TLS: TLS,
Add: Add,
Port: Port,
Aid: Aid,
Net: Net,
ID: ID,
Type: Type,
Security: Security,
Protocol: "vmess",
VmessOptions: options,
Trojan: nil,
}
}
type VmessDialer struct {
Instance *vcore.Instance
}
func (d *VmessDialer) DialContext(ctx context.Context, network string, addr string) (net.Conn, error) {
dest, err := vnet.ParseDestination(fmt.Sprintf("%s:%s", network, addr))
if err != nil {
return nil, err
}
return vcore.Dial(ctx, d.Instance, dest)
}