No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

37 líneas
949 B

  1. // Copyright 2011 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package proxy
  5. import (
  6. "context"
  7. "net"
  8. "golang.org/x/net/internal/socks"
  9. )
  10. // SOCKS5 returns a Dialer that makes SOCKSv5 connections to the given
  11. // address with an optional username and password.
  12. // See RFC 1928 and RFC 1929.
  13. func SOCKS5(network, address string, auth *Auth, forward Dialer) (Dialer, error) {
  14. d := socks.NewDialer(network, address)
  15. if forward != nil {
  16. d.ProxyDial = func(_ context.Context, network string, address string) (net.Conn, error) {
  17. return forward.Dial(network, address)
  18. }
  19. }
  20. if auth != nil {
  21. up := socks.UsernamePassword{
  22. Username: auth.User,
  23. Password: auth.Password,
  24. }
  25. d.AuthMethods = []socks.AuthMethod{
  26. socks.AuthMethodNotRequired,
  27. socks.AuthMethodUsernamePassword,
  28. }
  29. d.Authenticate = up.Authenticate
  30. }
  31. return d, nil
  32. }