// Ping a node and return whether or not we think it is online. We do this by trying to
// open a TCP connection to the "discard" service (port 9); if the node is offline, the
// attempt will either time out with no response, or else return "no route to host" (and
// we will return false). If the node is online then we presumably will get a "connection
// refused" error; but the code below assumes that anything other than timeout or "no
// route" indicates that the node is online.
Ping a node and return whether or not we think it is online. We do this by trying to
open a TCP connection to the "discard" service (port 9); if the node is offline, the
attempt will either time out with no response, or else return "no route to host" (and
we will return false). If the node is online then we presumably will get a "connection
refused" error; but the code below assumes that anything other than timeout or "no
route" indicates that the node is online.
// Ping a node and return whether or not we think it is online . We do this by trying to // open a TCP connection to the " discard " service ( port 9 ) ; if the node is offline the // attempt will either time out with no response or else return " no route to host " ( and // we will return false ) . If the node is online then we presumably will get a " connection // refused " error ; but the code below assumes that anything other than timeout or " no // route " indicates that the node is online .
func (eit *EgressIPTracker) Ping(ip string, timeout time.Duration) bool {
	ip = eit.lookupNodeIP(ip)
	conn, err := net.DialTimeout("tcp", ip+":9", timeout)
	if conn != nil {
		conn.Close()
	}
	if opErr, ok := err.(*net.OpError); ok {
		if opErr.Timeout() {
			return false
		}
		if sysErr, ok := opErr.Err.(*os.SyscallError); ok && sysErr.Err == syscall.EHOSTUNREACH {
			return false
		}
	}
	return true
}
func ( eit * EgressIPTracker ) Ping ( ip string , timeout time . Duration ) bool { ip = eit . lookupNodeIP ( ip ) conn , err := net . DialTimeout ( " " , ip + " " , timeout ) if conn != nil { conn . Close ( ) } if opErr , ok := err . ( * net . OpError ) ; ok { if opErr . Timeout ( ) { return false } if sysErr , ok := opErr . Err . ( * os . SyscallError ) ; ok && sysErr . Err == syscall . EHOSTUNREACH { return false } } return true }
Ping a node and return whether or not we think it is online.
Ping a node and return whether or not we think it is online .
// If the caller used a public node IP, replace it with the SDN IP