Skip to content

Commit 19ef593

Browse files
committed
Bring back support for go version <1.13
- net.DNSError.IsNotFound required go1.13
1 parent 02a271e commit 19ef593

File tree

2 files changed

+28
-26
lines changed

2 files changed

+28
-26
lines changed

simulator/simulator.go

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,14 @@ func (TCPConnectSimulator) Simulate(ctx context.Context, bind net.IP, dst string
3939
}
4040

4141
conn, err := d.DialContext(ctx, "tcp", dst)
42-
if err != nil {
43-
if err, ok := err.(net.Error); ok {
44-
// TODO: find a better way of determining refused connection?
45-
if err.Timeout() || strings.HasSuffix(err.Error(), "connect: connection refused") {
46-
return nil
47-
}
48-
}
49-
return err
42+
if conn != nil {
43+
conn.Close()
5044
}
51-
conn.Close()
5245

53-
return nil
46+
if isSoftError(err, "connect: connection refused") {
47+
return nil
48+
}
49+
return err
5450
}
5551

5652
type DNSResolveSimulator struct {
@@ -72,11 +68,25 @@ func (DNSResolveSimulator) Simulate(ctx context.Context, bind net.IP, dst string
7268
}
7369
_, err := r.LookupHost(ctx, utils.FQDN(host))
7470

75-
if err, ok := err.(*net.DNSError); ok {
76-
if err.IsNotFound || err.IsTimeout {
77-
return nil
78-
}
71+
if isSoftError(err, "no such host") {
72+
return nil
7973
}
80-
8174
return err
8275
}
76+
77+
func isSoftError(err error, ss ...string) bool {
78+
netErr, ok := err.(net.Error)
79+
if !ok {
80+
return false
81+
}
82+
if netErr.Timeout() {
83+
return true
84+
}
85+
errStr := err.Error()
86+
for n := range ss {
87+
if strings.Contains(errStr, ss[n]) {
88+
return true
89+
}
90+
}
91+
return false
92+
}

simulator/tunnel.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,9 @@ func (*Tunnel) Simulate(ctx context.Context, extIP net.IP, host string) error {
4343
ctx, _ := context.WithTimeout(ctx, 200*time.Millisecond)
4444
_, err := r.LookupTXT(ctx, fmt.Sprintf("%s.%s", label, host))
4545

46-
if err != nil {
47-
// ignore timeouts and NotFound;
48-
// TODO: actually make sure we get a valid response
49-
switch e := err.(type) {
50-
case *net.DNSError:
51-
if !(e.IsNotFound || e.IsTimeout) {
52-
return err
53-
}
54-
default:
55-
return err
56-
}
46+
// ignore timeout and "no such host"
47+
if err != nil && !isSoftError(err, "no such host") {
48+
return err
5749
}
5850

5951
// wait until context expires so we don't flood

0 commit comments

Comments
 (0)