Skip to content

Commit

Permalink
Expose more functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
myleshorton committed Nov 8, 2024
1 parent 71f39cc commit cb6bca4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
10 changes: 1 addition & 9 deletions proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func RegisterDialerType(scheme string, f func(*url.URL, Dialer) (Dialer, error))

// FromURL returns a Dialer given a URL specification and an underlying
// Dialer for it to make network requests.
func FromURL(u *url.URL, forward Dialer) (Dialer, error) {
func FromURL(u *url.URL, forward Dialer) (*SocksDialer, error) {
var auth *Auth
if u.User != nil {
auth = new(Auth)
Expand All @@ -98,14 +98,6 @@ func FromURL(u *url.URL, forward Dialer) (Dialer, error) {
return SOCKS5("tcp", net.JoinHostPort(addr, port), auth, forward)
}

// If the scheme doesn't match any of the built-in schemes, see if it
// was registered by another package.
if proxySchemes != nil {
if f, ok := proxySchemes[u.Scheme]; ok {
return f(u, forward)
}
}

return nil, errors.New("proxy: unknown scheme: " + u.Scheme)
}

Expand Down
16 changes: 8 additions & 8 deletions socks.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ func (c *Conn) BoundAddr() net.Addr {
// A SocksDialer holds SOCKS-specific options.
type SocksDialer struct {
cmd Command // either CmdConnect or cmdBind
proxyNetwork string // network between a proxy server and a client
proxyAddress string // proxy server address
ProxyNetwork string // network between a proxy server and a client
ProxyAddress string // proxy server address

// ProxyDial specifies the optional dial function for
// establishing the transport connection.
Expand Down Expand Up @@ -160,10 +160,10 @@ func (d *SocksDialer) DialContext(ctx context.Context, network, address string)
var err error
var c net.Conn
if d.ProxyDial != nil {
c, err = d.ProxyDial(ctx, d.proxyNetwork, d.proxyAddress)
c, err = d.ProxyDial(ctx, d.ProxyNetwork, d.ProxyAddress)
} else {
var dd net.Dialer
c, err = dd.DialContext(ctx, d.proxyNetwork, d.proxyAddress)
c, err = dd.DialContext(ctx, d.ProxyNetwork, d.ProxyAddress)
}
if err != nil {
proxy, dst, _ := d.pathAddrs(address)
Expand Down Expand Up @@ -215,9 +215,9 @@ func (d *SocksDialer) Dial(network, address string) (net.Conn, error) {
var err error
var c net.Conn
if d.ProxyDial != nil {
c, err = d.ProxyDial(context.Background(), d.proxyNetwork, d.proxyAddress)
c, err = d.ProxyDial(context.Background(), d.ProxyNetwork, d.ProxyAddress)
} else {
c, err = net.Dial(d.proxyNetwork, d.proxyAddress)
c, err = net.Dial(d.ProxyNetwork, d.ProxyAddress)
}
if err != nil {
proxy, dst, _ := d.pathAddrs(address)
Expand Down Expand Up @@ -245,7 +245,7 @@ func (d *SocksDialer) validateTarget(network string) error {
}

func (d *SocksDialer) pathAddrs(address string) (proxy, dst net.Addr, err error) {
for i, s := range []string{d.proxyAddress, address} {
for i, s := range []string{d.ProxyAddress, address} {
host, port, err := splitHostPort(s)
if err != nil {
return nil, nil, err
Expand All @@ -267,7 +267,7 @@ func (d *SocksDialer) pathAddrs(address string) (proxy, dst net.Addr, err error)
// NewSocksDialer returns a new Dialer that dials through the provided
// proxy server's network and address.
func NewSocksDialer(network, address string) *SocksDialer {
return &SocksDialer{proxyNetwork: network, proxyAddress: address, cmd: CmdConnect}
return &SocksDialer{ProxyNetwork: network, ProxyAddress: address, cmd: CmdConnect}
}

const (
Expand Down
2 changes: 1 addition & 1 deletion socks5.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
// SOCKS5 returns a Dialer that makes SOCKSv5 connections to the given
// address with an optional username and password.
// See RFC 1928 and RFC 1929.
func SOCKS5(network, address string, auth *Auth, forward Dialer) (Dialer, error) {
func SOCKS5(network, address string, auth *Auth, forward Dialer) (*SocksDialer, error) {
d := NewSocksDialer(network, address)
if forward != nil {
if f, ok := forward.(ContextDialer); ok {
Expand Down

0 comments on commit cb6bca4

Please sign in to comment.