Skip to content

Commit

Permalink
Merge pull request #23 from libp2p/feat/refactor
Browse files Browse the repository at this point in the history
refactor for transport interface changes
  • Loading branch information
Stebalien authored Jun 6, 2018
2 parents 1d47d21 + 4784a35 commit df410f8
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 362 deletions.
30 changes: 0 additions & 30 deletions p2p/transport/tcp/reuseport.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package tcp

import (
"net"
"os"
"strings"
"syscall"

reuseport "github.com/libp2p/go-reuseport"
)
Expand Down Expand Up @@ -35,31 +33,3 @@ func init() {
func ReuseportIsAvailable() bool {
return envReuseportVal && reuseport.Available()
}

// ReuseErrShouldRetry diagnoses whether to retry after a reuse error.
// if we failed to bind, we should retry. if bind worked and this is a
// real dial error (remote end didnt answer) then we should not retry.
func ReuseErrShouldRetry(err error) bool {
if err == nil {
return false // hey, it worked! no need to retry.
}

// if it's a network timeout error, it's a legitimate failure.
if nerr, ok := err.(net.Error); ok && nerr.Timeout() {
return false
}

errno, ok := err.(syscall.Errno)
if !ok { // not an errno? who knows what this is. retry.
return true
}

switch errno {
case syscall.EADDRINUSE, syscall.EADDRNOTAVAIL:
return true // failure to bind. retry.
case syscall.ECONNREFUSED:
return false // real dial error
default:
return true // optimistically default to retry.
}
}
48 changes: 0 additions & 48 deletions p2p/transport/tcp/reuseport_test.go

This file was deleted.

Loading

0 comments on commit df410f8

Please sign in to comment.