/
convert.go
71 lines (67 loc) · 2.22 KB
/
convert.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
package utils
import (
"github.com/coolray-dev/rayagent/models"
"v2ray.com/core"
"v2ray.com/core/app/proxyman"
"v2ray.com/core/common/net"
"v2ray.com/core/common/protocol"
"v2ray.com/core/common/serial"
"v2ray.com/core/proxy/vmess"
vmessInbound "v2ray.com/core/proxy/vmess/inbound"
"v2ray.com/core/transport/internet"
"v2ray.com/core/transport/internet/websocket"
)
func ConvertVmessInbound(s *models.Service) *core.InboundHandlerConfig {
port, _ := net.PortFromInt(uint32(s.Port))
return &core.InboundHandlerConfig{
Tag: string(s.ID),
ReceiverSettings: serial.ToTypedMessage(
&proxyman.ReceiverConfig{
PortRange: net.SinglePortRange(port),
Listen: net.NewIPOrDomain(net.ParseAddress("0.0.0.0")),
AllocationStrategy: &proxyman.AllocationStrategy{
Type: proxyman.AllocationStrategy_Always,
},
StreamSettings: &internet.StreamConfig{
Protocol: internet.TransportProtocol(internet.TransportProtocol_value[s.VmessSetting.StreamSettings.TransportProtocol]),
ProtocolName: s.VmessSetting.StreamSettings.TransportProtocol,
TransportSettings: []*internet.TransportConfig{&internet.TransportConfig{
Protocol: internet.TransportProtocol(internet.TransportProtocol_value[s.VmessSetting.StreamSettings.TransportProtocol]),
ProtocolName: s.VmessSetting.StreamSettings.TransportProtocol,
Settings: // need a func to handler different transport settings
serial.ToTypedMessage(&websocket.Config{
Path: "", // leave for future
}),
}},
},
ReceiveOriginalDestination: true,
SniffingSettings: &proxyman.SniffingConfig{
Enabled: true,
DestinationOverride: []string{"http", "tls"},
},
},
),
ProxySettings: serial.ToTypedMessage(
&vmessInbound.Config{
User: []*protocol.User{ConvertService(s)},
Default: &vmessInbound.DefaultConfig{
AlterId: 64, // hard coded
},
Detour: &vmessInbound.DetourConfig{
To: "", // No detour, not support yet
},
SecureEncryptionOnly: true,
},
),
}
}
func ConvertService(s *models.Service) *protocol.User {
return &protocol.User{
Level: 0,
Email: s.Email,
Account: serial.ToTypedMessage(&vmess.Account{
Id: s.UUID,
AlterId: 64, // hard coded
}),
}
}