Skip to content

Commit cde6e33

Browse files
author
patterniha
authored
Freedom: Add maxSplit fragment option; Add applyTo noises option (XTLS#4998)
1 parent 5dce7e4 commit cde6e33

File tree

4 files changed

+148
-71
lines changed

4 files changed

+148
-71
lines changed

infra/conf/freedom.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ type Fragment struct {
2727
Packets string `json:"packets"`
2828
Length *Int32Range `json:"length"`
2929
Interval *Int32Range `json:"interval"`
30+
MaxSplit *Int32Range `json:"maxSplit"`
3031
}
3132

3233
type Noise struct {
33-
Type string `json:"type"`
34-
Packet string `json:"packet"`
35-
Delay *Int32Range `json:"delay"`
34+
Type string `json:"type"`
35+
Packet string `json:"packet"`
36+
Delay *Int32Range `json:"delay"`
37+
ApplyTo string `json:"applyTo"`
3638
}
3739

3840
// Build implements Buildable
@@ -108,6 +110,13 @@ func (c *FreedomConfig) Build() (proto.Message, error) {
108110
config.Fragment.IntervalMin = uint64(c.Fragment.Interval.From)
109111
config.Fragment.IntervalMax = uint64(c.Fragment.Interval.To)
110112
}
113+
114+
{
115+
if c.Fragment.MaxSplit != nil {
116+
config.Fragment.MaxSplitMin = uint64(c.Fragment.MaxSplit.From)
117+
config.Fragment.MaxSplitMax = uint64(c.Fragment.MaxSplit.To)
118+
}
119+
}
111120
}
112121

113122
if c.Noise != nil {
@@ -193,5 +202,15 @@ func ParseNoise(noise *Noise) (*freedom.Noise, error) {
193202
NConfig.DelayMin = uint64(noise.Delay.From)
194203
NConfig.DelayMax = uint64(noise.Delay.To)
195204
}
205+
switch strings.ToLower(noise.ApplyTo) {
206+
case "", "ip", "all":
207+
NConfig.ApplyTo = "ip"
208+
case "ipv4":
209+
NConfig.ApplyTo = "ipv4"
210+
case "ipv6":
211+
NConfig.ApplyTo = "ipv6"
212+
default:
213+
return nil, errors.New("Invalid applyTo, only ip/ipv4/ipv6 are supported")
214+
}
196215
return NConfig, nil
197216
}

proxy/freedom/config.pb.go

Lines changed: 82 additions & 52 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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@ message Fragment {
1919
uint64 length_max = 4;
2020
uint64 interval_min = 5;
2121
uint64 interval_max = 6;
22+
uint64 max_split_min = 7;
23+
uint64 max_split_max = 8;
2224
}
2325
message Noise {
2426
uint64 length_min = 1;
2527
uint64 length_max = 2;
2628
uint64 delay_min = 3;
2729
uint64 delay_max = 4;
2830
bytes packet = 5;
31+
string apply_to = 6;
2932
}
3033

3134
message Config {

0 commit comments

Comments
 (0)