1
0
Fork 0

Merge pull request #14 from stbuehler/feature-without-resolve

support not resolving FQDN
logger
Armon Dadgar 2016-09-02 11:42:37 -07:00 committed by GitHub
commit e75332964e
1 changed files with 11 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import (
"fmt"
"io"
"net"
"strconv"
"strings"
"golang.org/x/net/context"
@ -54,6 +55,15 @@ func (a *AddrSpec) String() string {
return fmt.Sprintf("%s:%d", a.IP, a.Port)
}
// Address returns a string suitable to dial; prefer returning IP-based
// address, fallback to FQDN
func (a AddrSpec) Address() string {
if 0 != len(a.IP) {
return net.JoinHostPort(a.IP.String(), strconv.Itoa(a.Port))
}
return net.JoinHostPort(a.FQDN, strconv.Itoa(a.Port))
}
// A Request represents request received by a server
type Request struct {
// Protocol version
@ -158,14 +168,13 @@ func (s *Server) handleConnect(ctx context.Context, conn conn, req *Request) err
}
// Attempt to connect
addr := (&net.TCPAddr{IP: req.realDestAddr.IP, Port: req.realDestAddr.Port}).String()
dial := s.config.Dial
if dial == nil {
dial = func(ctx context.Context, net_, addr string) (net.Conn, error) {
return net.Dial(net_, addr)
}
}
target, err := dial(ctx, "tcp", addr)
target, err := dial(ctx, "tcp", req.realDestAddr.Address())
if err != nil {
msg := err.Error()
resp := hostUnreachable