Skip to content

Commit

Permalink
update gosocks
Browse files Browse the repository at this point in the history
  • Loading branch information
firefart committed Mar 10, 2024
1 parent 0d246a4 commit d62ba01
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module github.com/firefart/stunner

go 1.21
go 1.22

require (
github.com/firefart/gosocks v0.4.1
github.com/firefart/gosocks v0.4.2
github.com/pion/dtls/v2 v2.2.10
github.com/sirupsen/logrus v1.9.3
github.com/urfave/cli/v2 v2.27.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/firefart/gosocks v0.4.1 h1:E5l/BrJE9yPNlOZ6WymBNeEFd5sP8QkM40QonpsfAJY=
github.com/firefart/gosocks v0.4.1/go.mod h1:zflfN1fX57OOzUz6nAZyem3xUf2aIGSFwWbcFrKtjto=
github.com/firefart/gosocks v0.4.2 h1:HduMZGxEVsBFEHa57rNwqg8S8M878Pe2Og1TfQKaIR8=
github.com/firefart/gosocks v0.4.2/go.mod h1:9k5AYic+qFxo1W9hxw3vFbRTBEVIT3nWepdFvqv0uc4=
github.com/pion/dtls/v2 v2.2.10 h1:u2Axk+FyIR1VFTPurktB+1zoEPGIW3bmyj3LEFrXjAA=
github.com/pion/dtls/v2 v2.2.10/go.mod h1:d9SYc9fch0CqK90mRk1dC7AkzzpwJj6u2GU3u+9pqFE=
github.com/pion/logging v0.2.2 h1:M9+AIj/+pxNsDfAT64+MAVgJO0rsyLnoJKCqf//DoeY=
Expand Down
16 changes: 8 additions & 8 deletions internal/socksimplementations/socksturntcphandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ type SocksTurnTCPHandler struct {
}

// PreHandler connects to the STUN server, sets the connection up and returns the data connections
func (s *SocksTurnTCPHandler) Init(ctx context.Context, request socks.Request) (io.ReadWriteCloser, *socks.Error) {
func (s *SocksTurnTCPHandler) Init(ctx context.Context, request socks.Request) (context.Context, io.ReadWriteCloser, *socks.Error) {
var target netip.Addr
var err error
switch request.AddressType {
case socks.RequestAddressTypeIPv4, socks.RequestAddressTypeIPv6:
tmp, ok := netip.AddrFromSlice(request.DestinationAddress)
if !ok {
return nil, socks.NewError(socks.RequestReplyAddressTypeNotSupported, fmt.Errorf("%02x is no ip address", request.DestinationAddress))
return ctx, nil, socks.NewError(socks.RequestReplyAddressTypeNotSupported, fmt.Errorf("%02x is no ip address", request.DestinationAddress))
}
target = tmp
case socks.RequestAddressTypeDomainname:
Expand All @@ -49,32 +49,32 @@ func (s *SocksTurnTCPHandler) Init(ctx context.Context, request socks.Request) (
// input is a hostname
names, err := helper.ResolveName(ctx, string(request.DestinationAddress))
if err != nil {
return nil, socks.NewError(socks.RequestReplyHostUnreachable, err)
return ctx, nil, socks.NewError(socks.RequestReplyHostUnreachable, err)
}
if len(names) == 0 {
return nil, socks.NewError(socks.RequestReplyHostUnreachable, fmt.Errorf("%s could not be resolved", string(request.DestinationAddress)))
return ctx, nil, socks.NewError(socks.RequestReplyHostUnreachable, fmt.Errorf("%s could not be resolved", string(request.DestinationAddress)))
}
target = names[0]
}
default:
return nil, socks.NewError(socks.RequestReplyAddressTypeNotSupported, fmt.Errorf("AddressType %#x not implemented", request.AddressType))
return ctx, nil, socks.NewError(socks.RequestReplyAddressTypeNotSupported, fmt.Errorf("AddressType %#x not implemented", request.AddressType))
}

if s.DropNonPrivateRequests && !helper.IsPrivateIP(target) {
s.Log.Debugf("dropping non private connection to %s:%d", target.String(), request.DestinationPort)
return nil, socks.NewError(socks.RequestReplyHostUnreachable, fmt.Errorf("dropping non private connection to %s:%d", target.String(), request.DestinationPort))
return ctx, nil, socks.NewError(socks.RequestReplyHostUnreachable, fmt.Errorf("dropping non private connection to %s:%d", target.String(), request.DestinationPort))
}

realm, nonce, controlConnection, dataConnection, err := internal.SetupTurnTCPConnection(ctx, s.Log, s.Server, s.UseTLS, s.Timeout, target, request.DestinationPort, s.TURNUsername, s.TURNPassword)
if err != nil {
return nil, socks.NewError(socks.RequestReplyHostUnreachable, err)
return ctx, nil, socks.NewError(socks.RequestReplyHostUnreachable, err)
}
s.realm = realm
s.nonce = nonce

// we need to keep this connection open
s.ControlConnection = controlConnection
return dataConnection, nil
return ctx, dataConnection, nil
}

// Refresh is used to refresh an active connection every 2 minutes
Expand Down

0 comments on commit d62ba01

Please sign in to comment.