1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 10:08:15 -05:00
v2fly/infra/conf/blackhole.go

52 lines
1.1 KiB
Go
Raw Normal View History

2019-02-10 13:04:11 -05:00
package conf
import (
"encoding/json"
"github.com/golang/protobuf/proto"
2021-02-16 15:31:50 -05:00
"github.com/v2fly/v2ray-core/v4/common/serial"
"github.com/v2fly/v2ray-core/v4/proxy/blackhole"
2019-02-10 13:04:11 -05:00
)
type NoneResponse struct{}
func (*NoneResponse) Build() (proto.Message, error) {
return new(blackhole.NoneResponse), nil
}
type HTTPResponse struct{}
2019-02-10 13:04:11 -05:00
func (*HTTPResponse) Build() (proto.Message, error) {
2019-02-10 13:04:11 -05:00
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
}
2021-05-19 17:28:52 -04:00
var configLoader = NewJSONConfigLoader(
ConfigCreatorCache{
"none": func() interface{} { return new(NoneResponse) },
"http": func() interface{} { return new(HTTPResponse) },
},
"type",
"")