From c04b5b8cda745fef76530705509c8eb0cd1d2bd4 Mon Sep 17 00:00:00 2001 From: SokoloffA Date: Fri, 22 Oct 2021 17:38:14 +0300 Subject: [PATCH] Add fallback protocol support --- cmd/protoplex/protoplex.go | 4 ++++ protoplex/protocols/fallback.go | 10 ++++++++++ 2 files changed, 14 insertions(+) create mode 100644 protoplex/protocols/fallback.go diff --git a/cmd/protoplex/protoplex.go b/cmd/protoplex/protoplex.go index 93b2c3a..cf55e5e 100644 --- a/cmd/protoplex/protoplex.go +++ b/cmd/protoplex/protoplex.go @@ -39,6 +39,7 @@ func main() { socks5 := app.Flag("socks5", "The SOCKS5 server address").String() socks4 := app.Flag("socks4", "The SOCKS4 server address").String() // stRelay := flag.String("strelay", "", "The Syncthing Relay server address") + fallback := app.Flag("fallback", "The fallback address. If no protocol match, this address will be used.").String() _, _ = app.Parse(os.Args[1:]) @@ -83,6 +84,9 @@ func main() { if *http != "" { p = append(p, protocols.NewHTTPProtocol(*http)) } + if *fallback != "" { + p = append(p, protocols.FallbackProtocol(*fallback)) + } protoplex.RunServer(*bind, p, logger) } diff --git a/protoplex/protocols/fallback.go b/protoplex/protocols/fallback.go new file mode 100644 index 0000000..3e78ee9 --- /dev/null +++ b/protoplex/protocols/fallback.go @@ -0,0 +1,10 @@ +package protocols + +// FallbackProtocol initializes a Protocol with a SOCKS4 signature. +func FallbackProtocol(targetAddress string) *Protocol { + return &Protocol{ + Name: "Fallback", + Target: targetAddress, + MatchBytes: [][]byte{{}}, + } +}