mirror of
https://github.com/PeernetOfficial/core.git
synced 2026-07-21 04:17:50 +01:00
New function IsNetworkErrorFatal to invalidate connections on fatal network errors. Use connection.Expires field to trigger removal of inactive connections after a while.
This commit is contained in:
@@ -6,7 +6,10 @@ Author: Peter Kleissner
|
||||
|
||||
package core
|
||||
|
||||
import "net"
|
||||
import (
|
||||
"net"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// FindInterfaceByIP finds an interface based on the IP. The IP must be available at the interface.
|
||||
func FindInterfaceByIP(ip net.IP) (iface *net.Interface, ipnet *net.IPNet) {
|
||||
@@ -69,3 +72,18 @@ func IsIPv4(IP net.IP) bool {
|
||||
func IsIPv6(IP net.IP) bool {
|
||||
return IP.To4() == nil && IP.To16() != nil
|
||||
}
|
||||
|
||||
// IsNetworkErrorFatal checks if a network error indicates a broken connection.
|
||||
// Not every network error indicates a broken connection. This function prevents from over-dropping connections.
|
||||
func IsNetworkErrorFatal(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// Windows: A common error when the network adapter is disabled is "wsasendto: The requested address is not valid in its context".
|
||||
if strings.Contains(err.Error(), "requested address is not valid in its context") {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user