Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Commit

Permalink
refactor for transport interface changes
Browse files Browse the repository at this point in the history
Also, refactor out reuseport logic into a separate package.
  • Loading branch information
Stebalien committed Mar 29, 2018
1 parent 578cd65 commit 07a94ce
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 368 deletions.
42 changes: 36 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
"gxDependencies": [
{
"author": "whyrusleeping",
"hash": "QmaBTcaZbAgei1Z2ksUipLJ2AeEZtqDnyGYAkL7NFJ8pg3",
"hash": "QmY8DANxsxSQVf9TidKjNDVnnkZcyMJhfjcCcvnJ2jGLzF",
"name": "go-reuseport",
"version": "0.1.10"
"version": "0.1.12"
},
{
"author": "whyrusleeping",
"hash": "QmRK2LxanhK2gZq6k6R7vk5ZoYZk8ULSSTB7FzDsMUX6CB",
"hash": "QmcGXGdw9BWDysPJQHxJinjGHha3eEg4vzFETre4woNwcX",
"name": "go-multiaddr-net",
"version": "1.5.7"
"version": "1.6.0"
},
{
"author": "whyrusleeping",
Expand All @@ -27,9 +27,9 @@
},
{
"author": "whyrusleeping",
"hash": "QmVxtCwKFMmwcjhQXsGj6m4JAW7nGb9hRoErH9jpgqcLxA",
"hash": "QmSEPMduJjt75DTfadn7D4jRAB91Y55kErcsYnbF6nc9rZ",
"name": "go-libp2p-transport",
"version": "2.2.13"
"version": "3.0.0"
},
{
"hash": "QmRb5jh8z2E8hMGN2tkvs1yHynUanqnZ3UeKwgN1i9P1F8",
Expand All @@ -41,6 +41,36 @@
"hash": "QmWWQ2Txc2c6tqjsBpzg5Ar652cHPGNsQQp2SejkNmkUMb",
"name": "go-multiaddr",
"version": "1.2.6"
},
{
"author": "whyrusleeping",
"hash": "Qmc14vuKyGqX27RvBhekYytxSFJpaEgQVuVJgKSm69MEix",
"name": "go-smux-multiplex",
"version": "3.0.5"
},
{
"author": "stebalien",
"hash": "QmW9X4sZ9svTsTHesgxGdS6soi5miSofH7PyH8AXF86ZAS",
"name": "go-reuseport-transport",
"version": "0.1.3"
},
{
"author": "steb",
"hash": "QmZPd1MNxvCgtHumkkuqkAPHaV6HEGuWwKKsAYLfDf4asZ",
"name": "go-libp2p-transport-upgrader",
"version": "0.1.1"
},
{
"author": "Stebalien",
"hash": "QmequdAMEeFJ5fBtfkwKChW8zt86wcmAu1JYfXN6wn9YGT",
"name": "go-conn-security",
"version": "0.1.0"
},
{
"author": "whyrusleeping",
"hash": "QmZoWKhxUmZ2seW4BzX6fJkNR8hh9PsGModr7q171yq2SS",
"name": "go-libp2p-peer",
"version": "2.2.3"
}
],
"gxVersion": "0.4.0",
Expand Down
30 changes: 0 additions & 30 deletions 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 reuseport_test.go

This file was deleted.

Loading

0 comments on commit 07a94ce

Please sign in to comment.