2020-11-25 13:01:53 +02:00
|
|
|
package conf
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2021-12-15 02:28:47 +02:00
|
|
|
|
2020-12-04 03:36:16 +02:00
|
|
|
"github.com/xtls/xray-core/common/serial"
|
|
|
|
"github.com/xtls/xray-core/proxy/blackhole"
|
2023-08-10 07:43:34 +03:00
|
|
|
"google.golang.org/protobuf/proto"
|
2020-11-25 13:01:53 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2021-10-19 19:57:14 +03:00
|
|
|
var configLoader = NewJSONConfigLoader(
|
|
|
|
ConfigCreatorCache{
|
|
|
|
"none": func() interface{} { return new(NoneResponse) },
|
|
|
|
"http": func() interface{} { return new(HTTPResponse) },
|
|
|
|
},
|
|
|
|
"type",
|
|
|
|
"")
|