Skip to content

Commit 861b651

Browse files
committed
Populate Seed (more TBD) and checks
1 parent 86acbcc commit 861b651

8 files changed

Lines changed: 139 additions & 58 deletions

File tree

proxy/vless/account.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ func (a *Account) AsAccount() (protocol.Account, error) {
1515
ID: protocol.NewID(id),
1616
Flow: a.Flow, // needs parser here?
1717
Encryption: a.Encryption, // needs parser here?
18+
Seed: a.Seed,
1819
}, nil
1920
}
2021

@@ -26,6 +27,8 @@ type MemoryAccount struct {
2627
Flow string
2728
// Encryption of the account. Used for client connections, and only accepts "none" for now.
2829
Encryption string
30+
// Seed. Details TBD
31+
Seed string
2932
}
3033

3134
// Equals implements protocol.Account.Equals().

proxy/vless/account.pb.go

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

proxy/vless/account.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ message Account {
1313
string flow = 2;
1414
// Encryption settings. Only applies to client side, and only accepts "none" for now.
1515
string encryption = 3;
16+
// Seed settings. Details TBD
17+
string seed = 4;
1618
}

proxy/vless/encoding/addons.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package encoding
22

33
import (
4+
"bytes"
45
"context"
56
"io"
67

@@ -177,3 +178,64 @@ func (r *LengthPacketReader) ReadMultiBuffer() (buf.MultiBuffer, error) {
177178
}
178179
return mb, nil
179180
}
181+
182+
func PopulateSeed(seed string, addons *Addons) {
183+
if len(seed) > 0 {
184+
addons.Seed = []byte {1} // only turn on, more TBD
185+
addons.Mode = SeedMode_PaddingPlusDelay
186+
addons.Duration = "0-8"
187+
addons.Padding = &PaddingConfig{
188+
RegularMin: 0,
189+
RegularMax: 256,
190+
LongMin: 900,
191+
LongMax: 1400,
192+
}
193+
addons.Delay = &DelayConfig{
194+
IsRandom: true,
195+
MinMillis: 100,
196+
MaxMillis: 500,
197+
}
198+
addons.Scheduler = &SchedulerConfig{
199+
TimeoutMillis: 600,
200+
}
201+
}
202+
}
203+
204+
func CheckSeed(requestAddons *Addons, responseAddons *Addons) error {
205+
if !bytes.Equal(requestAddons.Seed, responseAddons.Seed) {
206+
return newError("Seed bytes not match", requestAddons.Seed, responseAddons.Seed)
207+
}
208+
if requestAddons.Mode != responseAddons.Mode {
209+
return newError("Mode not match", requestAddons.Mode, responseAddons.Mode)
210+
}
211+
if requestAddons.Duration != responseAddons.Duration {
212+
return newError("Duration not match", requestAddons.Duration, responseAddons.Duration)
213+
}
214+
if requestAddons.Padding != nil && responseAddons.Padding != nil {
215+
if requestAddons.Padding.RegularMin != responseAddons.Padding.RegularMin ||
216+
requestAddons.Padding.RegularMax != responseAddons.Padding.RegularMax ||
217+
requestAddons.Padding.LongMin != responseAddons.Padding.LongMin ||
218+
requestAddons.Padding.LongMax != responseAddons.Padding.LongMax {
219+
return newError("Padding not match")
220+
}
221+
} else if requestAddons.Padding != nil || responseAddons.Padding != nil {
222+
return newError("Padding of one is nil but the other is not nil")
223+
}
224+
if requestAddons.Delay != nil && responseAddons.Delay != nil {
225+
if requestAddons.Delay.IsRandom != responseAddons.Delay.IsRandom ||
226+
requestAddons.Delay.MinMillis != responseAddons.Delay.MinMillis ||
227+
requestAddons.Delay.MaxMillis != responseAddons.Delay.MaxMillis {
228+
return newError("Delay not match")
229+
}
230+
} else if requestAddons.Delay != nil || responseAddons.Delay != nil {
231+
return newError("Delay of one is nil but the other is not nil")
232+
}
233+
if requestAddons.Scheduler != nil && responseAddons.Scheduler != nil {
234+
if requestAddons.Scheduler.TimeoutMillis != responseAddons.Scheduler.TimeoutMillis {
235+
return newError("Scheduler not match")
236+
}
237+
} else if requestAddons.Scheduler != nil || responseAddons.Scheduler != nil {
238+
return newError("Scheduler of one is nil but the other is not nil")
239+
}
240+
return nil
241+
}

proxy/vless/encoding/addons.pb.go

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

proxy/vless/encoding/addons.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ message Addons {
1313
string Duration = 4; // "0-8" means apply to number of packets, "1kb-" means start applying once both side exchange 1kb data, counting two-ways
1414
PaddingConfig Padding = 5;
1515
DelayConfig Delay = 6;
16-
SchedulerConfig SchedulerConfig = 7;
16+
SchedulerConfig Scheduler = 7;
1717
}
1818

1919
enum SeedMode {

proxy/vless/inbound/inbound.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,10 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection s
443443
responseAddons := &encoding.Addons{
444444
// Flow: requestAddons.Flow,
445445
}
446+
encoding.PopulateSeed(account.Seed, responseAddons)
447+
if check := encoding.CheckSeed(requestAddons, responseAddons); check != nil {
448+
return newError("Seed configuration mis-match").Base(check).AtWarning()
449+
}
446450

447451
var input *bytes.Reader
448452
var rawInput *bytes.Buffer

proxy/vless/outbound/outbound.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
120120
requestAddons := &encoding.Addons{
121121
Flow: account.Flow,
122122
}
123+
encoding.PopulateSeed(account.Seed, requestAddons)
123124

124125
var input *bytes.Reader
125126
var rawInput *bytes.Buffer

0 commit comments

Comments
 (0)