Skip to content

Commit

Permalink
Extract function to fetch remote from resolver.
Browse files Browse the repository at this point in the history
Signed-off-by: David Calavera <[email protected]>
  • Loading branch information
calavera committed Aug 22, 2020
1 parent c2ee499 commit 97ba9ff
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lib/netext/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,19 @@ func (d *Dialer) findRemote(addr string) (*lib.HostAddress, error) {
}

ip := net.ParseIP(host)
if ip != nil {
return lib.NewHostAddress(ip, port)
}

if ip == nil {
ip, err = d.Resolver.FetchOne(host)
if err != nil {
return nil, err
}
return d.fetchRemoteFromResover(host, port)
}

func (d *Dialer) fetchRemoteFromResover(host, port string) (*lib.HostAddress, error) {
ip, err := d.Resolver.FetchOne(host)
if err != nil {
return nil, err
}

if ip == nil {
return nil, errors.Errorf("lookup %s: no such host", host)
}
Expand Down

0 comments on commit 97ba9ff

Please sign in to comment.