2016-10-17 08:35:13 -04:00
|
|
|
package conf
|
|
|
|
|
|
|
|
import (
|
2016-11-04 05:49:18 -04:00
|
|
|
"errors"
|
2016-11-05 10:14:55 -04:00
|
|
|
|
2016-10-17 08:35:13 -04:00
|
|
|
"v2ray.com/core/common/loader"
|
2016-11-04 05:49:18 -04:00
|
|
|
"v2ray.com/core/transport/internet/authenticators/http"
|
2016-10-17 08:35:13 -04:00
|
|
|
"v2ray.com/core/transport/internet/authenticators/noop"
|
|
|
|
"v2ray.com/core/transport/internet/authenticators/srtp"
|
|
|
|
"v2ray.com/core/transport/internet/authenticators/utp"
|
|
|
|
)
|
|
|
|
|
|
|
|
type NoOpAuthenticator struct{}
|
|
|
|
|
|
|
|
func (NoOpAuthenticator) Build() (*loader.TypedSettings, error) {
|
|
|
|
return loader.NewTypedSettings(new(noop.Config)), nil
|
|
|
|
}
|
|
|
|
|
2016-11-04 20:15:32 -04:00
|
|
|
type NoOpConnectionAuthenticator struct{}
|
|
|
|
|
|
|
|
func (NoOpConnectionAuthenticator) Build() (*loader.TypedSettings, error) {
|
|
|
|
return loader.NewTypedSettings(new(noop.Config)), nil
|
|
|
|
}
|
|
|
|
|
2016-10-17 08:35:13 -04:00
|
|
|
type SRTPAuthenticator struct{}
|
|
|
|
|
|
|
|
func (SRTPAuthenticator) Build() (*loader.TypedSettings, error) {
|
|
|
|
return loader.NewTypedSettings(new(srtp.Config)), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type UTPAuthenticator struct{}
|
|
|
|
|
|
|
|
func (UTPAuthenticator) Build() (*loader.TypedSettings, error) {
|
|
|
|
return loader.NewTypedSettings(new(utp.Config)), nil
|
|
|
|
}
|
2016-11-04 05:49:18 -04:00
|
|
|
|
|
|
|
type HTTPAuthenticatorRequest struct {
|
2016-11-04 20:28:15 -04:00
|
|
|
Version *string `json:"version"`
|
|
|
|
Method *string `json:"method"`
|
|
|
|
Path *StringList `json:"path"`
|
|
|
|
Headers map[string]*StringList `json:"headers"`
|
2016-11-04 05:49:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (this *HTTPAuthenticatorRequest) Build() (*http.RequestConfig, error) {
|
|
|
|
config := &http.RequestConfig{
|
|
|
|
Uri: []string{"/"},
|
|
|
|
Header: []*http.Header{
|
|
|
|
{
|
|
|
|
Name: "Host",
|
|
|
|
Value: []string{"www.baidu.com", "www.bing.com"},
|
|
|
|
},
|
2016-11-05 19:42:54 -04:00
|
|
|
{
|
|
|
|
Name: "User-Agent",
|
|
|
|
Value: []string{
|
|
|
|
"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36",
|
|
|
|
"Mozilla/5.0 (iPhone; CPU iPhone OS 10_0_2 like Mac OS X) AppleWebKit/601.1 (KHTML, like Gecko) CriOS/53.0.2785.109 Mobile/14A456 Safari/601.1.46",
|
|
|
|
},
|
|
|
|
},
|
2016-11-06 07:38:32 -05:00
|
|
|
{
|
|
|
|
Name: "Accept-Encoding",
|
|
|
|
Value: []string{"gzip, deflate"},
|
|
|
|
},
|
2016-11-04 05:49:18 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
if this.Version != nil {
|
|
|
|
config.Version = &http.Version{Value: *this.Version}
|
|
|
|
}
|
|
|
|
|
|
|
|
if this.Method != nil {
|
|
|
|
config.Method = &http.Method{Value: *this.Method}
|
|
|
|
}
|
|
|
|
|
|
|
|
if this.Path != nil && this.Path.Len() > 0 {
|
|
|
|
config.Uri = append([]string(nil), (*this.Path)...)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(this.Headers) > 0 {
|
2016-11-04 20:28:15 -04:00
|
|
|
config.Header = make([]*http.Header, 0, len(this.Headers))
|
|
|
|
for key, value := range this.Headers {
|
|
|
|
config.Header = append(config.Header, &http.Header{
|
|
|
|
Name: key,
|
|
|
|
Value: append([]string(nil), (*value)...),
|
|
|
|
})
|
2016-11-04 05:49:18 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return config, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type HTTPAuthenticatorResponse struct {
|
2016-11-04 20:28:15 -04:00
|
|
|
Version *string `json:"version"`
|
|
|
|
Status *string `json:"status"`
|
|
|
|
Reason *string `json:"reason"`
|
|
|
|
Headers map[string]*StringList `json:"headers"`
|
2016-11-04 05:49:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (this *HTTPAuthenticatorResponse) Build() (*http.ResponseConfig, error) {
|
|
|
|
config := &http.ResponseConfig{
|
|
|
|
Header: []*http.Header{
|
|
|
|
{
|
|
|
|
Name: "Content-Type",
|
|
|
|
Value: []string{"application/octet-stream", "video/mpeg"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "Transfer-Encoding",
|
|
|
|
Value: []string{"chunked"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
if this.Version != nil {
|
|
|
|
config.Version = &http.Version{Value: *this.Version}
|
|
|
|
}
|
|
|
|
|
|
|
|
if this.Status != nil || this.Reason != nil {
|
2016-11-04 05:49:43 -04:00
|
|
|
config.Status = &http.Status{
|
2016-11-04 05:49:18 -04:00
|
|
|
Code: "200",
|
|
|
|
Reason: "OK",
|
|
|
|
}
|
|
|
|
if this.Status != nil {
|
|
|
|
config.Status.Code = *this.Status
|
|
|
|
}
|
|
|
|
if this.Reason != nil {
|
|
|
|
config.Status.Reason = *this.Reason
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(this.Headers) > 0 {
|
2016-11-04 20:28:15 -04:00
|
|
|
config.Header = make([]*http.Header, 0, len(this.Headers))
|
|
|
|
for key, value := range this.Headers {
|
|
|
|
config.Header = append(config.Header, &http.Header{
|
|
|
|
Name: key,
|
|
|
|
Value: append([]string(nil), (*value)...),
|
|
|
|
})
|
2016-11-04 05:49:18 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return config, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type HTTPAuthenticator struct {
|
2016-11-05 10:14:55 -04:00
|
|
|
Request *HTTPAuthenticatorRequest `json:"request"`
|
|
|
|
Response *HTTPAuthenticatorResponse `json:"response"`
|
2016-11-04 05:49:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (this *HTTPAuthenticator) Build() (*loader.TypedSettings, error) {
|
|
|
|
config := new(http.Config)
|
2016-11-05 10:14:55 -04:00
|
|
|
if this.Request == nil {
|
|
|
|
return nil, errors.New("HTTP request settings not set.")
|
2016-11-04 05:49:18 -04:00
|
|
|
}
|
2016-11-05 10:14:55 -04:00
|
|
|
requestConfig, err := this.Request.Build()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
config.Request = requestConfig
|
2016-11-04 05:49:18 -04:00
|
|
|
|
2016-11-05 10:14:55 -04:00
|
|
|
if this.Response != nil {
|
|
|
|
responseConfig, err := this.Response.Build()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2016-11-04 05:49:18 -04:00
|
|
|
}
|
2016-11-05 10:14:55 -04:00
|
|
|
config.Response = responseConfig
|
2016-11-04 05:49:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return loader.NewTypedSettings(config), nil
|
|
|
|
}
|