Debian Codegraph @

infra/conf/http.go

raw symbols SCIP
1 package confscip-go gomod v2ray.com/core . `v2ray.com/core/infra/conf`/
2
3 import (
4 "encoding/jsonscip-go gomod github.com/golang/go/src go1.15 `encoding/json`/"
5
6 "github.com/golang/protobuf/protoscip-go gomod github.com/golang/protobuf v1.4.3 `github.com/golang/protobuf/proto`/"
7 "v2ray.com/core/common/protocolscip-go gomod v2ray.com/core . `v2ray.com/core/common/protocol`/"
8 "v2ray.com/core/common/serialscip-go gomod v2ray.com/core . `v2ray.com/core/common/serial`/"
9 "v2ray.com/core/proxy/httpscip-go gomod v2ray.com/core . `v2ray.com/core/proxy/http`/"
10 )
11
12 type HTTPAccountscip-go gomod v2ray.com/core . `v2ray.com/core/infra/conf`/HTTPAccount# struct {
13 Usernamescip-go gomod v2ray.com/core . `v2ray.com/core/infra/conf`/HTTPAccount#Username. string `json:"user"`
14 Passwordscip-go gomod v2ray.com/core . `v2ray.com/core/infra/conf`/HTTPAccount#Password. string `json:"pass"`
15 }
16
17 func (v *HTTPAccountscip-go gomod v2ray.com/core . `v2ray.com/core/infra/conf`/HTTPAccount#) Buildscip-go gomod v2ray.com/core . `v2ray.com/core/infra/conf`/HTTPAccount#Build().() *httpscip-go gomod v2ray.com/core . `v2ray.com/core/proxy/http`/.Accountscip-go gomod v2ray.com/core . `v2ray.com/core/proxy/http`/Account# {
18 return &httpscip-go gomod v2ray.com/core . `v2ray.com/core/proxy/http`/.Accountscip-go gomod v2ray.com/core . `v2ray.com/core/proxy/http`/Account#{
19 Usernamescip-go gomod v2ray.com/core . `v2ray.com/core/proxy/http`/Account#Username.: v.Usernamescip-go gomod v2ray.com/core . `v2ray.com/core/infra/conf`/HTTPAccount#Username.,
20 Passwordscip-go gomod v2ray.com/core . `v2ray.com/core/proxy/http`/Account#Password.: v.Passwordscip-go gomod v2ray.com/core . `v2ray.com/core/infra/conf`/HTTPAccount#Password.,
21 }
22 }
23
24 type HTTPServerConfigscip-go gomod v2ray.com/core . `v2ray.com/core/infra/conf`/HTTPServerConfig# struct {
25 Timeoutscip-go gomod v2ray.com/core . `v2ray.com/core/infra/conf`/HTTPServerConfig#Timeout. uint32 `json:"timeout"`
26 Accountsscip-go gomod v2ray.com/core . `v2ray.com/core/infra/conf`/HTTPServerConfig#Accounts. []*HTTPAccountscip-go gomod v2ray.com/core . `v2ray.com/core/infra/conf`/HTTPAccount# `json:"accounts"`
27 Transparentscip-go gomod v2ray.com/core . `v2ray.com/core/infra/conf`/HTTPServerConfig#Transparent. bool `json:"allowTransparent"`
28 UserLevelscip-go gomod v2ray.com/core . `v2ray.com/core/infra/conf`/HTTPServerConfig#UserLevel. uint32 `json:"userLevel"`
29 }
30
31 func (c *HTTPServerConfigscip-go gomod v2ray.com/core . `v2ray.com/core/infra/conf`/HTTPServerConfig#) Buildscip-go gomod v2ray.com/core . `v2ray.com/core/infra/conf`/HTTPServerConfig#Build().() (protoscip-go gomod github.com/golang/protobuf v1.4.3 `github.com/golang/protobuf/proto`/.Messagescip-go gomod github.com/golang/protobuf v1.4.3 `github.com/golang/protobuf/proto`/Message#, error) {
32 config := &httpscip-go gomod v2ray.com/core . `v2ray.com/core/proxy/http`/.ServerConfigscip-go gomod v2ray.com/core . `v2ray.com/core/proxy/http`/ServerConfig#{
33 Timeoutscip-go gomod v2ray.com/core . `v2ray.com/core/proxy/http`/ServerConfig#Timeout.: c.Timeoutscip-go gomod v2ray.com/core . `v2ray.com/core/infra/conf`/HTTPServerConfig#Timeout.,
34 AllowTransparentscip-go gomod v2ray.com/core . `v2ray.com/core/proxy/http`/ServerConfig#AllowTransparent.: c.Transparentscip-go gomod v2ray.com/core . `v2ray.com/core/infra/conf`/HTTPServerConfig#Transparent.,
35 UserLevelscip-go gomod v2ray.com/core . `v2ray.com/core/proxy/http`/ServerConfig#UserLevel.: c.UserLevelscip-go gomod v2ray.com/core . `v2ray.com/core/infra/conf`/HTTPServerConfig#UserLevel.,
36 }
37
38 if len(c.Accountsscip-go gomod v2ray.com/core . `v2ray.com/core/infra/conf`/HTTPServerConfig#Accounts.) > 0 {
39 config.Accountsscip-go gomod v2ray.com/core . `v2ray.com/core/proxy/http`/ServerConfig#Accounts. = make(map[string]string)
40 for _, account := range c.Accountsscip-go gomod v2ray.com/core . `v2ray.com/core/infra/conf`/HTTPServerConfig#Accounts. {
41 config.Accountsscip-go gomod v2ray.com/core . `v2ray.com/core/proxy/http`/ServerConfig#Accounts.[account.Usernamescip-go gomod v2ray.com/core . `v2ray.com/core/infra/conf`/HTTPAccount#Username.] = account.Passwordscip-go gomod v2ray.com/core . `v2ray.com/core/infra/conf`/HTTPAccount#Password.
42 }
43 }
44
45 return config, nil
46 }
47
48 type HTTPRemoteConfigscip-go gomod v2ray.com/core . `v2ray.com/core/infra/conf`/HTTPRemoteConfig# struct {
49 Addressscip-go gomod v2ray.com/core . `v2ray.com/core/infra/conf`/HTTPRemoteConfig#Address. *Addressscip-go gomod v2ray.com/core . `v2ray.com/core/infra/conf`/Address# `json:"address"`
50 Portscip-go gomod v2ray.com/core . `v2ray.com/core/infra/conf`/HTTPRemoteConfig#Port. uint16 `json:"port"`
51 Usersscip-go gomod v2ray.com/core . `v2ray.com/core/infra/conf`/HTTPRemoteConfig#Users. []jsonscip-go gomod github.com/golang/go/src go1.15 `encoding/json`/.RawMessagescip-go gomod github.com/golang/go/src go1.15 `encoding/json`/RawMessage# `json:"users"`
52 }
53 type HTTPClientConfigscip-go gomod v2ray.com/core . `v2ray.com/core/infra/conf`/HTTPClientConfig# struct {
54 Serversscip-go gomod v2ray.com/core . `v2ray.com/core/infra/conf`/HTTPClientConfig#Servers. []*HTTPRemoteConfigscip-go gomod v2ray.com/core . `v2ray.com/core/infra/conf`/HTTPRemoteConfig# `json:"servers"`
55 }
56
57 func (v *HTTPClientConfigscip-go gomod v2ray.com/core . `v2ray.com/core/infra/conf`/HTTPClientConfig#) Buildscip-go gomod v2ray.com/core . `v2ray.com/core/infra/conf`/HTTPClientConfig#Build().() (protoscip-go gomod github.com/golang/protobuf v1.4.3 `github.com/golang/protobuf/proto`/.Messagescip-go gomod github.com/golang/protobuf v1.4.3 `github.com/golang/protobuf/proto`/Message#, error) {
58 config := new(httpscip-go gomod v2ray.com/core . `v2ray.com/core/proxy/http`/.ClientConfigscip-go gomod v2ray.com/core . `v2ray.com/core/proxy/http`/ClientConfig#)
59 config.Serverscip-go gomod v2ray.com/core . `v2ray.com/core/proxy/http`/ClientConfig#Server. = make([]*protocolscip-go gomod v2ray.com/core . `v2ray.com/core/common/protocol`/.ServerEndpointscip-go gomod v2ray.com/core . `v2ray.com/core/common/protocol`/ServerEndpoint#, len(v.Serversscip-go gomod v2ray.com/core . `v2ray.com/core/infra/conf`/HTTPClientConfig#Servers.))
60 for idx, serverConfig := range v.Serversscip-go gomod v2ray.com/core . `v2ray.com/core/infra/conf`/HTTPClientConfig#Servers. {
61 server := &protocolscip-go gomod v2ray.com/core . `v2ray.com/core/common/protocol`/.ServerEndpointscip-go gomod v2ray.com/core . `v2ray.com/core/common/protocol`/ServerEndpoint#{
62 Addressscip-go gomod v2ray.com/core . `v2ray.com/core/common/protocol`/ServerEndpoint#Address.: serverConfig.Addressscip-go gomod v2ray.com/core . `v2ray.com/core/infra/conf`/HTTPRemoteConfig#Address..Buildscip-go gomod v2ray.com/core . `v2ray.com/core/infra/conf`/Address#Build().(),
63 Portscip-go gomod v2ray.com/core . `v2ray.com/core/common/protocol`/ServerEndpoint#Port.: uint32(serverConfig.Portscip-go gomod v2ray.com/core . `v2ray.com/core/infra/conf`/HTTPRemoteConfig#Port.),
64 }
65 for _, rawUser := range serverConfig.Usersscip-go gomod v2ray.com/core . `v2ray.com/core/infra/conf`/HTTPRemoteConfig#Users. {
66 user := new(protocolscip-go gomod v2ray.com/core . `v2ray.com/core/common/protocol`/.Userscip-go gomod v2ray.com/core . `v2ray.com/core/common/protocol`/User#)
67 if err := jsonscip-go gomod github.com/golang/go/src go1.15 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.15 `encoding/json`/Unmarshal().(rawUser, user); err != nil {
68 return nil, newErrorscip-go gomod v2ray.com/core . `v2ray.com/core/infra/conf`/newError().("failed to parse HTTP user").Basescip-go gomod v2ray.com/core . `v2ray.com/core/common/errors`/Error#Base().(err).AtErrorscip-go gomod v2ray.com/core . `v2ray.com/core/common/errors`/Error#AtError().()
69 }
70 account := new(HTTPAccountscip-go gomod v2ray.com/core . `v2ray.com/core/infra/conf`/HTTPAccount#)
71 if err := jsonscip-go gomod github.com/golang/go/src go1.15 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.15 `encoding/json`/Unmarshal().(rawUser, account); err != nil {
72 return nil, newErrorscip-go gomod v2ray.com/core . `v2ray.com/core/infra/conf`/newError().("failed to parse HTTP account").Basescip-go gomod v2ray.com/core . `v2ray.com/core/common/errors`/Error#Base().(err).AtErrorscip-go gomod v2ray.com/core . `v2ray.com/core/common/errors`/Error#AtError().()
73 }
74 user.Accountscip-go gomod v2ray.com/core . `v2ray.com/core/common/protocol`/User#Account. = serialscip-go gomod v2ray.com/core . `v2ray.com/core/common/serial`/.ToTypedMessagescip-go gomod v2ray.com/core . `v2ray.com/core/common/serial`/ToTypedMessage().(account.Buildscip-go gomod v2ray.com/core . `v2ray.com/core/infra/conf`/HTTPAccount#Build().())
75 server.Userscip-go gomod v2ray.com/core . `v2ray.com/core/common/protocol`/ServerEndpoint#User. = append(server.Userscip-go gomod v2ray.com/core . `v2ray.com/core/common/protocol`/ServerEndpoint#User., user)
76 }
77 config.Serverscip-go gomod v2ray.com/core . `v2ray.com/core/proxy/http`/ClientConfig#Server.[idx] = server
78 }
79 return config, nil
80 }