This is an automated email from the git hooks/post-receive script.
shelikhoo pushed a commit to branch main in repository pluggable-transports/snowflake.
commit 33248f3dec5594c985cfd11e6c6143ddaa5613c0 Author: Shelikhoo xiaokangwang@outlook.com AuthorDate: Tue Nov 8 14:58:23 2022 +0000
Add Version Output Support to Snowflake
From now on, there will be a file at common/version/version.go that includes current version number. --- client/snowflake.go | 8 ++++++++ common/utls/client_hello_id.go | 8 ++++++++ common/utls/client_hello_id_version.go | 24 ++++++++++++++++++++++++ common/version/combined.go | 5 +++++ common/version/detail.go | 13 +++++++++++++ common/version/version.go | 7 +++++++ proxy/main.go | 8 ++++++++ server/server.go | 8 ++++++++ 8 files changed, 81 insertions(+)
diff --git a/client/snowflake.go b/client/snowflake.go index 2cb6549..e4344e4 100644 --- a/client/snowflake.go +++ b/client/snowflake.go @@ -3,6 +3,7 @@ package main
import ( "flag" + "fmt" "io" "io/ioutil" "log" @@ -19,6 +20,7 @@ import ( sf "git.torproject.org/pluggable-transports/snowflake.git/v2/client/lib" "git.torproject.org/pluggable-transports/snowflake.git/v2/common/event" "git.torproject.org/pluggable-transports/snowflake.git/v2/common/safelog" + "git.torproject.org/pluggable-transports/snowflake.git/v2/common/version" )
const ( @@ -157,6 +159,7 @@ func main() { unsafeLogging := flag.Bool("unsafe-logging", false, "prevent logs from being scrubbed") max := flag.Int("max", DefaultSnowflakeCapacity, "capacity for number of multiplexed WebRTC peers") + versionFlag := flag.Bool("version", false, "display version info to stderr and quit")
// Deprecated oldLogToStateDir := flag.Bool("logToStateDir", false, "use -log-to-state-dir instead") @@ -164,6 +167,11 @@ func main() {
flag.Parse()
+ if *versionFlag { + fmt.Fprintf(os.Stderr, "snowflake-client %s", version.ConstructResult()) + os.Exit(0) + } + log.SetFlags(log.LstdFlags | log.LUTC)
// Don't write to stderr; versions of tor earlier than about 0.3.5.6 do diff --git a/common/utls/client_hello_id.go b/common/utls/client_hello_id.go index 8a13280..c134ecf 100644 --- a/common/utls/client_hello_id.go +++ b/common/utls/client_hello_id.go @@ -36,3 +36,11 @@ func NameToUTLSID(name string) (utls.ClientHelloID, error) { } return utls.ClientHelloID{}, errNameNotFound } + +func ListAllNames() []string { + var names []string + for k, _ := range clientHelloIDMap { + names = append(names, k) + } + return names +} diff --git a/common/utls/client_hello_id_version.go b/common/utls/client_hello_id_version.go new file mode 100644 index 0000000..7228694 --- /dev/null +++ b/common/utls/client_hello_id_version.go @@ -0,0 +1,24 @@ +package utls + +import ( + "git.torproject.org/pluggable-transports/snowflake.git/v2/common/version" + "strings" +) + +func generateVersionOutput() string { + var versionOutputBuilder strings.Builder + + versionOutputBuilder.WriteString(`Known utls-imitate values: +(empty) +`) + + for _, name := range ListAllNames() { + versionOutputBuilder.WriteString(name) + versionOutputBuilder.WriteRune('\n') + } + return versionOutputBuilder.String() +} + +func init() { + version.AddVersionDetail(generateVersionOutput()) +} diff --git a/common/version/combined.go b/common/version/combined.go new file mode 100644 index 0000000..9de74db --- /dev/null +++ b/common/version/combined.go @@ -0,0 +1,5 @@ +package version + +func ConstructResult() string { + return GetVersion() + "\n" + GetVersionDetail() +} diff --git a/common/version/detail.go b/common/version/detail.go new file mode 100644 index 0000000..6965630 --- /dev/null +++ b/common/version/detail.go @@ -0,0 +1,13 @@ +package version + +import "strings" + +var detailBuilder strings.Builder + +func AddVersionDetail(detail string) { + detailBuilder.WriteString(detail) +} + +func GetVersionDetail() string { + return detailBuilder.String() +} diff --git a/common/version/version.go b/common/version/version.go new file mode 100644 index 0000000..4936905 --- /dev/null +++ b/common/version/version.go @@ -0,0 +1,7 @@ +package version + +func GetVersion() string { + return version +} + +var version = "2.3.1" diff --git a/proxy/main.go b/proxy/main.go index 3dad5a9..2218609 100644 --- a/proxy/main.go +++ b/proxy/main.go @@ -2,6 +2,7 @@ package main
import ( "flag" + "fmt" "io" "io/ioutil" "log" @@ -12,6 +13,7 @@ import (
"git.torproject.org/pluggable-transports/snowflake.git/v2/common/event" "git.torproject.org/pluggable-transports/snowflake.git/v2/common/safelog" + "git.torproject.org/pluggable-transports/snowflake.git/v2/common/version" sf "git.torproject.org/pluggable-transports/snowflake.git/v2/proxy/lib" )
@@ -31,11 +33,17 @@ func main() { "the time interval to output summary, 0s disables summaries. Valid time units are "s", "m", "h". ") verboseLogging := flag.Bool("verbose", false, "increase log verbosity") ephemeralPortsRangeFlag := flag.String("ephemeral-ports-range", "", "ICE UDP ephemeral ports range (format:"<min>:<max>")") + versionFlag := flag.Bool("version", false, "display version info to stderr and quit")
var ephemeralPortsRange []uint16 = []uint16{0, 0}
flag.Parse()
+ if *versionFlag { + fmt.Fprintf(os.Stderr, "snowflake-proxy %s", version.ConstructResult()) + os.Exit(0) + } + eventLogger := event.NewSnowflakeEventDispatcher()
if *ephemeralPortsRangeFlag != "" { diff --git a/server/server.go b/server/server.go index 6eb5cf7..8b6c7a5 100644 --- a/server/server.go +++ b/server/server.go @@ -19,6 +19,7 @@ import ( "syscall"
"git.torproject.org/pluggable-transports/snowflake.git/v2/common/safelog" + "git.torproject.org/pluggable-transports/snowflake.git/v2/common/version" "golang.org/x/crypto/acme/autocert"
pt "git.torproject.org/pluggable-transports/goptlib.git" @@ -130,6 +131,7 @@ func main() { var disableTLS bool var logFilename string var unsafeLogging bool + var versionFlag bool
flag.Usage = usage flag.StringVar(&acmeEmail, "acme-email", "", "optional contact email for Let's Encrypt notifications") @@ -137,8 +139,14 @@ func main() { flag.BoolVar(&disableTLS, "disable-tls", false, "don't use HTTPS") flag.StringVar(&logFilename, "log", "", "log file to write to") flag.BoolVar(&unsafeLogging, "unsafe-logging", false, "prevent logs from being scrubbed") + flag.BoolVar(&versionFlag, "unsafe-logging", false, "display version info to stderr and quit") flag.Parse()
+ if versionFlag { + fmt.Fprintf(os.Stderr, "snowflake-server %s", version.ConstructResult()) + os.Exit(0) + } + log.SetFlags(log.LstdFlags | log.LUTC)
var logOutput io.Writer = os.Stderr