Commit f4bb4313 authored by Steven Allen's avatar Steven Allen

feat(dial): implement the Timeout interface on dial errors

parent 5efa2fa2
...@@ -2,6 +2,7 @@ package swarm ...@@ -2,6 +2,7 @@ package swarm
import ( import (
"fmt" "fmt"
"os"
"strings" "strings"
"github.com/libp2p/go-libp2p-core/peer" "github.com/libp2p/go-libp2p-core/peer"
...@@ -20,6 +21,10 @@ type DialError struct { ...@@ -20,6 +21,10 @@ type DialError struct {
Skipped int Skipped int
} }
func (e *DialError) Timeout() bool {
return os.IsTimeout(e.Cause)
}
func (e *DialError) recordErr(addr ma.Multiaddr, err error) { func (e *DialError) recordErr(addr ma.Multiaddr, err error) {
if len(e.DialErrors) >= maxDialDialErrors { if len(e.DialErrors) >= maxDialDialErrors {
e.Skipped++ e.Skipped++
...@@ -48,11 +53,7 @@ func (e *DialError) Error() string { ...@@ -48,11 +53,7 @@ func (e *DialError) Error() string {
// Unwrap implements https://godoc.org/golang.org/x/xerrors#Wrapper. // Unwrap implements https://godoc.org/golang.org/x/xerrors#Wrapper.
func (e *DialError) Unwrap() error { func (e *DialError) Unwrap() error {
// If we have a context error, that's the "ultimate" error. return e.Cause
if e.Cause != nil {
return e.Cause
}
return nil
} }
var _ error = (*DialError)(nil) var _ error = (*DialError)(nil)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment