Migrate the AmneziaWG graft from the old sagernet base (506b763) onto v0.0.3, the base sing-box 1.14 uses. Strategy: start from v0.0.3, copy the net-new obfuscation files verbatim from the proven graft (27290b6), take the 6 modified device/ files wholesale from the graft, keep all tun/* and conn/* from v0.0.3. Net-new (copied from27290b6): device/magic-header.go + device/obf*.go (9). Modified (from27290b6): device/{send,receive,uapi,device,noise-protocol,cookie}.go. - receive.go: reverted two Go-1.22 'range int' loops to the v0.0.3 form (go 1.20). - cookie.go: keeps the 4-arg CreateReply(msgType) the grafted send.go calls. - noise-protocol.go: MessageEncapsulatingTransportSize=0 (AWG composes without the sagernet Bind.Send headroom prepend). §010 android UDP_GRO guard (fb8d8d8) intentionally DROPPED: v0.0.3 fixes the receive split-brain at source — bind_std.go now gates all 5 RX/offload paths on linux||android, and gso_linux.go splits coalesced packets on android. Re-inserting the guard would disable a now-working android RX-offload path. Requires on-device re-verification before release. go.mod: go 1.20, golang.org/x/sys v0.21.0 (v0.0.3 baseline). No amnezia-vpn import paths remain. Builds clean for linux/android/windows/darwin (library packages).
38 lines
623 B
Go
38 lines
623 B
Go
package device
|
|
|
|
import "strconv"
|
|
|
|
func newDataSizeObf(val string) (obf, error) {
|
|
length, err := strconv.Atoi(val)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &dataSizeObf{
|
|
length: length,
|
|
}, nil
|
|
}
|
|
|
|
type dataSizeObf struct {
|
|
length int
|
|
}
|
|
|
|
func (o *dataSizeObf) Obfuscate(dst, src []byte) {
|
|
srcLen := len(src)
|
|
for i := o.length - 1; i >= 0; i-- {
|
|
dst[i] = byte(srcLen & 0xFF)
|
|
srcLen >>= 8
|
|
}
|
|
}
|
|
|
|
func (o *dataSizeObf) Deobfuscate(dst, src []byte) bool {
|
|
return true
|
|
}
|
|
|
|
func (o *dataSizeObf) ObfuscatedLen(srcLen int) int {
|
|
return o.length
|
|
}
|
|
|
|
func (o *dataSizeObf) DeobfuscatedLen(srcLen int) int {
|
|
return 0
|
|
}
|