package swarm
import (
"fmt"
"os"
"strings"
"github.com/libp2p/go-libp2p/core/peer"
ma "github.com/multiformats/go-multiaddr"
)
const maxDialDialErrors = 16
type DialError struct {
Peer peer .ID
DialErrors []TransportError
Cause error
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 ++
return
}
e .DialErrors = append (e .DialErrors , TransportError {Address : addr , Cause : err })
}
func (e *DialError ) Error () string {
var builder strings .Builder
fmt .Fprintf (&builder , "failed to dial %s:" , e .Peer )
if e .Cause != nil {
fmt .Fprintf (&builder , " %s" , e .Cause )
}
for _ , te := range e .DialErrors {
fmt .Fprintf (&builder , "\n * [%s] %s" , te .Address , te .Cause )
}
if e .Skipped > 0 {
fmt .Fprintf (&builder , "\n ... skipping %d errors ..." , e .Skipped )
}
return builder .String ()
}
func (e *DialError ) Unwrap () []error {
if e == nil {
return nil
}
errs := make ([]error , 0 , len (e .DialErrors )+1 )
if e .Cause != nil {
errs = append (errs , e .Cause )
}
for i := 0 ; i < len (e .DialErrors ); i ++ {
errs = append (errs , &e .DialErrors [i ])
}
return errs
}
var _ error = (*DialError )(nil )
type TransportError struct {
Address ma .Multiaddr
Cause error
}
func (e *TransportError ) Error () string {
return fmt .Sprintf ("failed to dial %s: %s" , e .Address , e .Cause )
}
func (e *TransportError ) Unwrap () error {
return e .Cause
}
var _ error = (*TransportError )(nil )
The pages are generated with Golds v0.8.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .