From c07cdeff926c2143517a89e32c928c4d723e391d Mon Sep 17 00:00:00 2001 From: Anton Tolchanov Date: Wed, 30 Nov 2022 07:21:28 +0000 Subject: [PATCH] Do not exit the server loop on obfs4 connection errors obfs4Listener.Accept() returns an error when obfs4 handshake fails, which in practice happens routinely when someone scans a machine that has an open listening port. Currently the accept loop in server.go exits on first such error, which makes further connections to the same port impossible. This change wraps obfs4 handshake errors into a custom error type that satisfies net.Error and presents itself as temporary, which will prevent such errors from aborting the server. --- obfs.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/obfs.go b/obfs.go index 33f97a6..47062f2 100644 --- a/obfs.go +++ b/obfs.go @@ -20,9 +20,9 @@ import ( "github.com/go-log/log" pt "git.torproject.org/pluggable-transports/goptlib.git" + dissector "github.com/go-gost/tls-dissector" "gitlab.com/yawning/obfs4.git/transports/base" "gitlab.com/yawning/obfs4.git/transports/obfs4" - dissector "github.com/go-gost/tls-dissector" ) const ( @@ -804,6 +804,16 @@ func Obfs4Listener(addr string) (Listener, error) { return l, nil } +// TempError satisfies the net.Error interface and presents itself +// as temporary to make sure that it gets retried by the Accept loop +// in server.go. +type TempError struct { + error +} + +func (e TempError) Timeout() bool { return false } +func (e TempError) Temporary() bool { return true } + func (l *obfs4Listener) Accept() (net.Conn, error) { conn, err := l.Listener.Accept() if err != nil { @@ -812,7 +822,7 @@ func (l *obfs4Listener) Accept() (net.Conn, error) { cc, err := obfs4ServerConn(l.addr, conn) if err != nil { conn.Close() - return nil, err + return nil, TempError{err} } return cc, nil }