-
Notifications
You must be signed in to change notification settings - Fork 18k
x/net/proxy: how to assert the underlying type from the returned value of Dialer.Dial #25104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
It is true that we changed the concrete type of the returned The type does include the underlying conn, // A Conn represents a forward proxy connection.
type Conn struct {
net.Conn
boundAddr net.Addr
} ... but the whole package is internal for now. /cc @mikioh |
There's no guarantee that the returned interface always contains a well-known concrete type, as the package description says that "for a variety of protocols." Otherwise, we cannot implement a bit complicated stuff like SOCKSv6 over TLS 1.3 in near future.
A simple way would be using the 4th parameter of the SOCKS5 function like the following:
PS: s/cast/type assertion/; the notation x.(T) is called a type assertion in the language specification. See https://golang.org/ref/spec#Type_assertions |
Also, it's fine to add both Close{Read,Write} methods to socks.Conn to allow to assert the behavior of close-read and -write, for example,
|
Change https://golang.org/cl/110135 mentions this issue: |
Change https://golang.org/cl/110136 mentions this issue: |
This change uses the DialWithConn method of socks.Dialer to ensure that the bundled SOCKS client implementation is agnostic to the behavior and capabilities of transport connections. Also updates the bundled golang.org/x/net/internal/socks at git rev 7594486. (golang.org/cl/110135) Updates #25104. Change-Id: I87c2e99eeb857f182ea5d8ef569181d4f45f2e5d Reviewed-on: https://go-review.googlesource.com/110136 Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Something recent (it appears to be this commit: golang/net@61147c4#diff-431387eb7262e1cfc79b125eb8a67c60) has broken the cast to *net.TCPConn. I don't know if this is intentional or not. If it is then I'd appreciate any advice on how to accomplish what I'm trying to do without the cast.
What version of Go are you using (
go version
)?go version go1.10.1 linux/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?GOARCH="amd64"
GOBIN=""
GOCACHE="/home/rhs/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/rhs/go"
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build051890453=/tmp/go-build -gno-record-gcc-switches"
What did you do?
This is slightly complicated to setup, so bear with me here. The reproducer program is available here: https://gist.github.com/rhs/7ed17d49dff7196c3539d2d1b01f6049
What did you expect to see?
Until recently this worked fine and connections were proxied:
What did you see instead?
Now the cast fails with a panic:
The text was updated successfully, but these errors were encountered: