Build implements Buildable
()
| 39 | |
| 40 | // Build implements Buildable |
| 41 | func (c *VLessInboundConfig) Build() (proto.Message, error) { |
| 42 | config := new(inbound.Config) |
| 43 | config.Clients = make([]*protocol.User, len(c.Clients)) |
| 44 | switch c.Flow { |
| 45 | case vless.XRV, "": |
| 46 | default: |
| 47 | return nil, errors.New(`VLESS "settings.flow" doesn't support "` + c.Flow + `" in this version`) |
| 48 | } |
| 49 | for idx, rawUser := range c.Clients { |
| 50 | user := new(protocol.User) |
| 51 | if err := json.Unmarshal(rawUser, user); err != nil { |
| 52 | return nil, errors.New(`VLESS clients: invalid user`).Base(err) |
| 53 | } |
| 54 | account := new(vless.Account) |
| 55 | if err := json.Unmarshal(rawUser, account); err != nil { |
| 56 | return nil, errors.New(`VLESS clients: invalid user`).Base(err) |
| 57 | } |
| 58 | |
| 59 | u, err := uuid.ParseString(account.Id) |
| 60 | if err != nil { |
| 61 | return nil, err |
| 62 | } |
| 63 | account.Id = u.String() |
| 64 | |
| 65 | switch account.Flow { |
| 66 | case "": |
| 67 | account.Flow = c.Flow |
| 68 | case vless.XRV: |
| 69 | default: |
| 70 | return nil, errors.New(`VLESS clients: "flow" doesn't support "` + account.Flow + `" in this version`) |
| 71 | } |
| 72 | |
| 73 | if len(account.Testseed) < 4 { |
| 74 | account.Testseed = c.Testseed |
| 75 | } |
| 76 | |
| 77 | if account.Encryption != "" { |
| 78 | return nil, errors.New(`VLESS clients: "encryption" should not be in inbound settings`) |
| 79 | } |
| 80 | |
| 81 | if account.Reverse != nil { |
| 82 | if account.Reverse.Tag == "" { |
| 83 | return nil, errors.New(`VLESS clients: "tag" can't be empty for "reverse"`) |
| 84 | } |
| 85 | if account.Reverse.Sniffing != nil { // may not be reached: error json unmarshal |
| 86 | return nil, errors.New(`VLESS clients: inbound's "reverse" can't have "sniffing"`) |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | user.Account = serial.ToTypedMessage(account) |
| 91 | config.Clients[idx] = user |
| 92 | } |
| 93 | |
| 94 | config.Decryption = c.Decryption |
| 95 | if !func() bool { |
| 96 | s := strings.Split(config.Decryption, ".") |
| 97 | if len(s) < 4 || s[0] != "mlkem768x25519plus" { |
| 98 | return false |
nothing calls this directly
no test coverage detected