feat(dial): implement the Timeout interface on dial errors
@@ -2,6 +2,7 @@ package swarm
import (
"fmt"
+ "os"
"strings"
"github.com/libp2p/go-libp2p-core/peer"
@@ -20,6 +21,10 @@ type DialError struct {
Skipped int
}
+func (e *DialError) Timeout() bool {
+ return os.IsTimeout(e.Cause)
+}
+
func (e *DialError) recordErr(addr ma.Multiaddr, err error) {
if len(e.DialErrors) >= maxDialDialErrors {
e.Skipped++
@@ -48,12 +53,8 @@ func (e *DialError) Error() string {
// Unwrap implements https://godoc.org/golang.org/x/xerrors#Wrapper.
func (e *DialError) Unwrap() error {
- // If we have a context error, that's the "ultimate" error.
- if e.Cause != nil {
return e.Cause
}
- return nil
-}
var _ error = (*DialError)(nil)
