1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-10-03 17:23:43 -04:00
v2fly/net/vmess/config.go

60 lines
1.3 KiB
Go
Raw Normal View History

2015-09-12 05:51:42 -04:00
package vmess
import (
"encoding/json"
"github.com/v2ray/v2ray-core"
2015-09-12 14:36:21 -04:00
"github.com/v2ray/v2ray-core/log"
2015-09-12 05:51:42 -04:00
v2net "github.com/v2ray/v2ray-core/net"
)
2015-09-12 14:36:21 -04:00
type VMessUser struct {
Id string `json:"id"`
Email string `json:"email"`
}
func (u *VMessUser) ToVUser() (core.VUser, error) {
id, err := core.UUIDToVID(u.Id)
return core.VUser{id}, err
}
2015-09-12 05:51:42 -04:00
type VMessInboundConfig struct {
2015-09-12 14:36:21 -04:00
AllowedClients []VMessUser `json:"clients"`
2015-09-12 05:51:42 -04:00
}
func loadInboundConfig(rawConfig []byte) (VMessInboundConfig, error) {
config := VMessInboundConfig{}
err := json.Unmarshal(rawConfig, &config)
return config, err
}
type VNextConfig struct {
2015-09-12 14:36:21 -04:00
Address string `json:"address"`
Port uint16 `json:"port"`
Users []VMessUser `json:"users"`
2015-09-12 05:51:42 -04:00
}
func (config VNextConfig) ToVNextServer() VNextServer {
2015-09-12 14:36:21 -04:00
users := make([]core.VUser, 0, len(config.Users))
for _, user := range config.Users {
vuser, err := user.ToVUser()
if err != nil {
panic(log.Error("Failed to convert %v to VUser.", user))
}
users = append(users, vuser)
}
2015-09-12 05:51:42 -04:00
return VNextServer{
v2net.DomainAddress(config.Address, config.Port),
2015-09-12 14:36:21 -04:00
users}
2015-09-12 05:51:42 -04:00
}
type VMessOutboundConfig struct {
2015-09-12 14:36:21 -04:00
VNextList []VNextConfig `json:"vnext"`
2015-09-12 05:51:42 -04:00
}
func loadOutboundConfig(rawConfig []byte) (VMessOutboundConfig, error) {
config := VMessOutboundConfig{}
err := json.Unmarshal(rawConfig, &config)
return config, err
}