mirror of https://github.com/v2ray/v2ray-core
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.1 KiB
54 lines
1.1 KiB
6 years ago
|
package conf
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
|
||
|
"github.com/golang/protobuf/proto"
|
||
|
|
||
|
"v2ray.com/core/common/serial"
|
||
|
"v2ray.com/core/proxy/blackhole"
|
||
|
)
|
||
|
|
||
|
type NoneResponse struct{}
|
||
|
|
||
|
func (*NoneResponse) Build() (proto.Message, error) {
|
||
|
return new(blackhole.NoneResponse), nil
|
||
|
}
|
||
|
|
||
|
type HttpResponse struct{}
|
||
|
|
||
|
func (*HttpResponse) Build() (proto.Message, error) {
|
||
|
return new(blackhole.HTTPResponse), nil
|
||
|
}
|
||
|
|
||
|
type BlackholeConfig struct {
|
||
|
Response json.RawMessage `json:"response"`
|
||
|
}
|
||
|
|
||
|
func (v *BlackholeConfig) Build() (proto.Message, error) {
|
||
|
config := new(blackhole.Config)
|
||
|
if v.Response != nil {
|
||
|
response, _, err := configLoader.Load(v.Response)
|
||
|
if err != nil {
|
||
|
return nil, newError("Config: Failed to parse Blackhole response config.").Base(err)
|
||
|
}
|
||
|
responseSettings, err := response.(Buildable).Build()
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
config.Response = serial.ToTypedMessage(responseSettings)
|
||
|
}
|
||
|
|
||
|
return config, nil
|
||
|
}
|
||
|
|
||
|
var (
|
||
|
configLoader = NewJSONConfigLoader(
|
||
|
ConfigCreatorCache{
|
||
|
"none": func() interface{} { return new(NoneResponse) },
|
||
|
"http": func() interface{} { return new(HttpResponse) },
|
||
|
},
|
||
|
"type",
|
||
|
"")
|
||
|
)
|