forked from v2fly/v2ray-core
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
2,024 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package conf | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/golang/protobuf/proto" | ||
|
||
"v2ray.com/core/common/protocol" | ||
"v2ray.com/core/common/serial" | ||
"v2ray.com/core/proxy/vless" | ||
"v2ray.com/core/proxy/vless/inbound" | ||
"v2ray.com/core/proxy/vless/outbound" | ||
) | ||
|
||
type VLessInboundConfig struct { | ||
Users []json.RawMessage `json:"clients"` | ||
Decryption string `json:"decryption"` | ||
} | ||
|
||
// Build implements Buildable | ||
func (c *VLessInboundConfig) Build() (proto.Message, error) { | ||
|
||
if c.Decryption != "none" { | ||
return nil, newError(`please add/set "decryption":"none" directly to every VLess "settings"`) | ||
} | ||
config := &inbound.Config{ | ||
Decryption: c.Decryption, | ||
} | ||
|
||
config.User = make([]*protocol.User, len(c.Users)) | ||
for idx, rawData := range c.Users { | ||
user := new(protocol.User) | ||
if err := json.Unmarshal(rawData, user); err != nil { | ||
return nil, newError("invalid VLess user").Base(err) | ||
} | ||
account := new(vless.Account) | ||
if err := json.Unmarshal(rawData, account); err != nil { | ||
return nil, newError("invalid VLess user").Base(err) | ||
} | ||
|
||
if account.Mess != "" { | ||
return nil, newError(`VLess attr "mess" is not available in this version`) | ||
} | ||
if account.Encryption != "" { | ||
return nil, newError(`VLess attr "encryption" should not in inbound settings`) | ||
} | ||
|
||
user.Account = serial.ToTypedMessage(account) | ||
config.User[idx] = user | ||
} | ||
|
||
return config, nil | ||
} | ||
|
||
type VLessOutboundTarget struct { | ||
Address *Address `json:"address"` | ||
Port uint16 `json:"port"` | ||
Users []json.RawMessage `json:"users"` | ||
} | ||
|
||
type VLessOutboundConfig struct { | ||
Receivers []*VLessOutboundTarget `json:"vnext"` | ||
} | ||
|
||
// Build implements Buildable | ||
func (c *VLessOutboundConfig) Build() (proto.Message, error) { | ||
|
||
config := new(outbound.Config) | ||
|
||
if len(c.Receivers) == 0 { | ||
return nil, newError("0 VLess receiver configured") | ||
} | ||
serverSpecs := make([]*protocol.ServerEndpoint, len(c.Receivers)) | ||
for idx, rec := range c.Receivers { | ||
if len(rec.Users) == 0 { | ||
return nil, newError("0 user configured for VLess outbound") | ||
} | ||
if rec.Address == nil { | ||
return nil, newError("address is not set in VLess outbound config") | ||
} | ||
spec := &protocol.ServerEndpoint{ | ||
Address: rec.Address.Build(), | ||
Port: uint32(rec.Port), | ||
} | ||
for _, rawUser := range rec.Users { | ||
user := new(protocol.User) | ||
if err := json.Unmarshal(rawUser, user); err != nil { | ||
return nil, newError("invalid VLess user").Base(err) | ||
} | ||
account := new(vless.Account) | ||
if err := json.Unmarshal(rawUser, account); err != nil { | ||
return nil, newError("invalid VLess user").Base(err) | ||
} | ||
|
||
if account.Mess != "" { | ||
return nil, newError(`VLess attr "mess" is not available in this version`) | ||
} | ||
if account.Encryption != "none" { | ||
return nil, newError(`please add/set "encryption":"none" for every VLess user in "users"`) | ||
} | ||
|
||
user.Account = serial.ToTypedMessage(account) | ||
spec.User = append(spec.User, user) | ||
} | ||
serverSpecs[idx] = spec | ||
} | ||
config.Receiver = serverSpecs | ||
|
||
return config, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// +build !confonly | ||
|
||
package vless | ||
|
||
import ( | ||
"v2ray.com/core/common/protocol" | ||
"v2ray.com/core/common/uuid" | ||
) | ||
|
||
// AsAccount implements protocol.Account.AsAccount(). | ||
func (a *Account) AsAccount() (protocol.Account, error) { | ||
id, err := uuid.ParseString(a.Id) | ||
if err != nil { | ||
return nil, newError("failed to parse ID").Base(err).AtError() | ||
} | ||
return &MemoryAccount{ | ||
ID: protocol.NewID(id), | ||
Mess: a.Mess, // need parser? | ||
Encryption: a.Encryption, // need parser? | ||
}, nil | ||
} | ||
|
||
// MemoryAccount is an in-memory form of VLess account. | ||
type MemoryAccount struct { | ||
// ID of the account. | ||
ID *protocol.ID | ||
// Mess of the account. Used for client connections for now. | ||
Mess string | ||
// Encryption of the account. Used for client connections, and only accepts "none" for now. | ||
Encryption string | ||
} | ||
|
||
// Equals implements protocol.Account.Equals(). | ||
func (a *MemoryAccount) Equals(account protocol.Account) bool { | ||
vlessAccount, ok := account.(*MemoryAccount) | ||
if !ok { | ||
return false | ||
} | ||
return a.ID.Equals(vlessAccount.ID) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
syntax = "proto3"; | ||
|
||
package v2ray.core.proxy.vless; | ||
option csharp_namespace = "V2Ray.Core.Proxy.Vless"; | ||
option go_package = "vless"; | ||
option java_package = "com.v2ray.core.proxy.vless"; | ||
option java_multiple_files = true; | ||
|
||
message Account { | ||
// ID of the account, in the form of a UUID, e.g., "66ad4540-b58c-4ad2-9926-ea63445a9b57". | ||
string id = 1; | ||
// Mess settings. Only applies to client side for now. | ||
string mess = 2; | ||
// Encryption settings. Only applies to client side, and only accepts "none" for now. | ||
string encryption = 3; | ||
} |
Oops, something went wrong.