Skip to content

Commit 958eb9e

Browse files
authored
Direct/Freedom outbound: Add blockDelay to finalRules (30~90s by default) (#6060)
Document: https://xtls.github.io/config/outbounds/freedom.html#finalruleobject #6058 (comment) #6058 (comment) #6060 (comment) #6060 (comment)
1 parent 8381a5a commit 958eb9e

5 files changed

Lines changed: 173 additions & 49 deletions

File tree

infra/conf/freedom.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ type Noise struct {
4444
}
4545

4646
type FreedomFinalRuleConfig struct {
47-
Action string `json:"action"`
48-
Network *NetworkList `json:"network"`
49-
Port *PortList `json:"port"`
50-
IP *StringList `json:"ip"`
47+
Action string `json:"action"`
48+
Network *NetworkList `json:"network"`
49+
Port *PortList `json:"port"`
50+
IP *StringList `json:"ip"`
51+
BlockDelay *Int32Range `json:"blockDelay"`
5152
}
5253

5354
// Build implements Buildable
@@ -276,5 +277,12 @@ func (c *FreedomFinalRuleConfig) Build() (*freedom.FinalRuleConfig, error) {
276277
rule.Ip = rules
277278
}
278279

280+
if c.BlockDelay != nil {
281+
rule.BlockDelay = &freedom.Range{
282+
Min: uint64(c.BlockDelay.From),
283+
Max: uint64(c.BlockDelay.To),
284+
}
285+
}
286+
279287
return rule, nil
280288
}

infra/conf/freedom_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ func TestFreedomConfig(t *testing.T) {
4545
"action": "block",
4646
"network": "tcp,udp",
4747
"port": "53,443",
48-
"ip": ["10.0.0.0/8", "2001:db8::/32"]
48+
"ip": ["10.0.0.0/8", "2001:db8::/32"],
49+
"blockDelay": "30-60"
4950
}, {
5051
"action": "allow",
5152
"network": ["udp"]
@@ -85,6 +86,10 @@ func TestFreedomConfig(t *testing.T) {
8586
},
8687
},
8788
},
89+
BlockDelay: &freedom.Range{
90+
Min: 30,
91+
Max: 60,
92+
},
8893
},
8994
{
9095
Action: freedom.RuleAction_Allow,

proxy/freedom/config.pb.go

Lines changed: 98 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proxy/freedom/config.proto

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ message Noise {
3636
string apply_to = 6;
3737
}
3838

39+
message Range {
40+
uint64 min = 1;
41+
uint64 max = 2;
42+
}
43+
3944
enum RuleAction {
4045
Allow = 0;
4146
Block = 1;
@@ -46,6 +51,7 @@ message FinalRuleConfig {
4651
repeated xray.common.net.Network networks = 2;
4752
xray.common.net.PortList port_list = 3;
4853
repeated xray.common.geodata.IPRule ip = 4;
54+
Range block_delay = 5;
4955
}
5056

5157
message Config {

0 commit comments

Comments
 (0)