From 404aa6554da4bd5f760c8dbea8e0a416a018342c Mon Sep 17 00:00:00 2001 From: Vinicius Fortuna Date: Tue, 5 Nov 2024 19:34:19 -0500 Subject: [PATCH] Update config --- x/configurl/doc.go | 4 ++-- x/configurl/split.go | 33 ++++++++++++++++++++++++++++----- x/go.mod | 2 +- x/go.sum | 4 ++-- 4 files changed, 33 insertions(+), 10 deletions(-) diff --git a/x/configurl/doc.go b/x/configurl/doc.go index 056c7a23..9b2191d2 100644 --- a/x/configurl/doc.go +++ b/x/configurl/doc.go @@ -91,9 +91,9 @@ These strategies manipulate packets to bypass SNI-based blocking. Stream split transport (streams only, package [github.com/Jigsaw-Code/outline-sdk/transport/split]) -It takes the length of the prefix. The stream will be split when PREFIX_LENGTH bytes are first written. +It takes a list of count*length pairs meaning splitting the sequence in count segments of the given length. If you omit "[COUNT]*", it's assumed to be 1. - split:[PREFIX_LENGTH] + split:[COUNT1]*[LENGTH1],[COUNT2]*[LENGTH2],... TLS fragmentation (streams only, package [github.com/Jigsaw-Code/outline-sdk/transport/tlsfrag]). diff --git a/x/configurl/split.go b/x/configurl/split.go index 48242010..33737fbe 100644 --- a/x/configurl/split.go +++ b/x/configurl/split.go @@ -18,6 +18,7 @@ import ( "context" "fmt" "strconv" + "strings" "github.com/Jigsaw-Code/outline-sdk/transport" "github.com/Jigsaw-Code/outline-sdk/transport/split" @@ -29,11 +30,33 @@ func registerSplitStreamDialer(r TypeRegistry[transport.StreamDialer], typeID st if err != nil { return nil, err } - prefixBytesStr := config.URL.Opaque - prefixBytes, err := strconv.Atoi(prefixBytesStr) - if err != nil { - return nil, fmt.Errorf("prefixBytes is not a number: %v. Split config should be in split: format", prefixBytesStr) + configText := config.URL.Opaque + splits := make([]split.RepeatedSplit, 0) + for _, part := range strings.Split(configText, ",") { + var count int + var bytes int64 + subparts := strings.Split(strings.TrimSpace(part), "*") + switch len(subparts) { + case 1: + count = 1 + bytes, err = strconv.ParseInt(subparts[0], 10, 64) + if err != nil { + return nil, fmt.Errorf("bytes is not a number: %v", subparts[0]) + } + case 2: + count, err = strconv.Atoi(subparts[0]) + if err != nil { + return nil, fmt.Errorf("count is not a number: %v", subparts[0]) + } + bytes, err = strconv.ParseInt(subparts[1], 10, 64) + if err != nil { + return nil, fmt.Errorf("bytes is not a number: %v", subparts[0]) + } + default: + return nil, fmt.Errorf("split format must be a comma-separated list of '[$COUNT*]$BYTES' (e.g. '100,5*2'). Got %v", part) + } + splits = append(splits, split.RepeatedSplit{Count: count, Bytes: bytes}) } - return split.NewStreamDialer(sd, split.NewFixedSplitIterator(int64(prefixBytes))) + return split.NewStreamDialer(sd, split.NewRepeatedSplitIterator(splits...)) }) } diff --git a/x/go.mod b/x/go.mod index f5f452c5..ba02180e 100644 --- a/x/go.mod +++ b/x/go.mod @@ -3,7 +3,7 @@ module github.com/Jigsaw-Code/outline-sdk/x go 1.22 require ( - github.com/Jigsaw-Code/outline-sdk v0.0.18-0.20241105230628-4801a034fbaf + github.com/Jigsaw-Code/outline-sdk v0.0.18-0.20241106003301-3354513b85f8 // Use github.com/Psiphon-Labs/psiphon-tunnel-core@staging-client as per // https://github.com/Psiphon-Labs/psiphon-tunnel-core/?tab=readme-ov-file#using-psiphon-with-go-modules github.com/Psiphon-Labs/psiphon-tunnel-core v1.0.11-0.20240619172145-03cade11f647 diff --git a/x/go.sum b/x/go.sum index b8c6f4f3..46047f1c 100644 --- a/x/go.sum +++ b/x/go.sum @@ -6,8 +6,8 @@ github.com/AndreasBriese/bbloom v0.0.0-20170702084017-28f7e881ca57 h1:CVuXDbdzPW github.com/AndreasBriese/bbloom v0.0.0-20170702084017-28f7e881ca57/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8= github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8= github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= -github.com/Jigsaw-Code/outline-sdk v0.0.18-0.20241105230628-4801a034fbaf h1:nJFLb0ukT/K4zyQod4vXLqimWq9ekzgC7i5Q+J3x6Rg= -github.com/Jigsaw-Code/outline-sdk v0.0.18-0.20241105230628-4801a034fbaf/go.mod h1:CFDKyGZA4zatKE4vMLe8TyQpZCyINOeRFbMAmYHxodw= +github.com/Jigsaw-Code/outline-sdk v0.0.18-0.20241106003301-3354513b85f8 h1:3bdohee2xFJmsXYdAB/p1zZRdrKMQlp1kiyNJgCE1OY= +github.com/Jigsaw-Code/outline-sdk v0.0.18-0.20241106003301-3354513b85f8/go.mod h1:CFDKyGZA4zatKE4vMLe8TyQpZCyINOeRFbMAmYHxodw= github.com/Psiphon-Inc/rotate-safe-writer v0.0.0-20210303140923-464a7a37606e h1:NPfqIbzmijrl0VclX2t8eO5EPBhqe47LLGKpRrcVjXk= github.com/Psiphon-Inc/rotate-safe-writer v0.0.0-20210303140923-464a7a37606e/go.mod h1:ZdY5pBfat/WVzw3eXbIf7N1nZN0XD5H5+X8ZMDWbCs4= github.com/Psiphon-Labs/bolt v0.0.0-20200624191537-23cedaef7ad7 h1:Hx/NCZTnvoKZuIBwSmxE58KKoNLXIGG6hBJYN7pj9Ag=