2021-06-19 08:45:43 -04:00
|
|
|
package v4
|
2019-02-10 13:04:11 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
|
|
|
|
"github.com/golang/protobuf/proto"
|
|
|
|
|
2022-01-02 10:16:23 -05:00
|
|
|
"github.com/v2fly/v2ray-core/v5/common/serial"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/infra/conf/cfgcommon"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/infra/conf/cfgcommon/loader"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/proxy/blackhole"
|
2019-02-10 13:04:11 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type NoneResponse struct{}
|
|
|
|
|
|
|
|
func (*NoneResponse) Build() (proto.Message, error) {
|
|
|
|
return new(blackhole.NoneResponse), nil
|
|
|
|
}
|
|
|
|
|
2020-10-11 07:22:46 -04:00
|
|
|
type HTTPResponse struct{}
|
2019-02-10 13:04:11 -05:00
|
|
|
|
2020-10-11 07:22:46 -04: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)
|
|
|
|
}
|
2021-06-19 08:04:50 -04:00
|
|
|
responseSettings, err := response.(cfgcommon.Buildable).Build()
|
2019-02-10 13:04:11 -05:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
config.Response = serial.ToTypedMessage(responseSettings)
|
|
|
|
}
|
|
|
|
|
|
|
|
return config, nil
|
|
|
|
}
|
|
|
|
|
2021-06-19 08:28:20 -04:00
|
|
|
var configLoader = loader.NewJSONConfigLoader(
|
|
|
|
loader.ConfigCreatorCache{
|
2021-05-19 17:28:52 -04:00
|
|
|
"none": func() interface{} { return new(NoneResponse) },
|
|
|
|
"http": func() interface{} { return new(HTTPResponse) },
|
|
|
|
},
|
|
|
|
"type",
|
|
|
|
"")
|