mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-11-20 16:49:12 +00:00
https://github.com/XTLS/Xray-core/pull/7238#issuecomment-6467092152 https://github.com/XTLS/Xray-core/pull/7281#issuecomment-6484050347 https://github.com/XTLS/Xray-core/pull/7281#issuecomment-6484439860 https://github.com/XTLS/Xray-core/pull/7281#issuecomment-6621021705 https://github.com/XTLS/Xray-core/pull/7329#issuecomment-6623818990 https://github.com/XTLS/Xray-core/pull/7329#issuecomment-6624149740 https://github.com/XTLS/Xray-core/pull/7329#issuecomment-6625219097 https://github.com/XTLS/Xray-core/pull/7281#issuecomment-6627156942 https://github.com/XTLS/Xray-core/pull/7281#issuecomment-6850640864 https://github.com/XTLS/Xray-core/pull/7281#issuecomment-6973501579 --------- Co-authored-by: Codex <codex@openai.com>
49 lines
1.4 KiB
Go
49 lines
1.4 KiB
Go
package conf
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"strings"
|
|
|
|
"github.com/xtls/xray-core/common/errors"
|
|
"github.com/xtls/xray-core/common/log"
|
|
"github.com/xtls/xray-core/proxy/freedom"
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
type ResponseConfig struct {
|
|
Type string `json:"type"`
|
|
CustomResponseData string `json:"customResponseData"`
|
|
}
|
|
|
|
type BlackholeConfig struct {
|
|
Response *ResponseConfig `json:"response"`
|
|
}
|
|
|
|
func (v *BlackholeConfig) Build() (proto.Message, error) {
|
|
errors.PrintDeprecatedFeatureWarning(`"blackhole" outbound`, `"freedom" outbound with a blocking "firewall" rule`)
|
|
rule := &freedom.FirewallConfig{
|
|
Action: freedom.RuleAction_Block,
|
|
Delay: &freedom.Range{},
|
|
LogLevel: log.Severity_Unknown.Enum(),
|
|
}
|
|
if v.Response != nil {
|
|
responseName := strings.ToLower(v.Response.Type)
|
|
switch responseName {
|
|
case "none", "":
|
|
rule.Reply = &freedom.Reply{Type: "none"}
|
|
case "http":
|
|
rule.Reply = &freedom.Reply{Type: "http"}
|
|
case "custom":
|
|
data, err := base64.StdEncoding.DecodeString(v.Response.CustomResponseData)
|
|
if err != nil {
|
|
return nil, errors.New("failed to decode custom response data: " + err.Error())
|
|
}
|
|
rule.Reply = &freedom.Reply{Type: "custom", CustomResponseData: data}
|
|
default:
|
|
return nil, errors.New("unknown blackhole response: " + responseName)
|
|
}
|
|
}
|
|
|
|
return &freedom.Config{Firewall: []*freedom.FirewallConfig{rule}}, nil
|
|
}
|