-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdialer.go
26 lines (23 loc) · 816 Bytes
/
dialer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package main
import (
"fmt"
"net"
)
// Try to open a connection to the destination, and then immediately disconnect
// if succcessful. This ensures we have a network path to the destination, and
// validates each individual record in the DNS response.
func Dial(route *Route, dest *Destination, ip net.IP) bool {
metricTags := []string{fmt.Sprintf("dest_ip:%s", ip.String())}
hostPort := fmt.Sprintf("%s:%d", ip.String(), dest.Port)
// Test destination IP by dialing route
dest.Increment("connectivity.dial", metricTags)
conn, err := net.Dial(dest.Protocol, hostPort)
if err != nil {
dest.Increment("connectivity.dial.error", metricTags)
LogRouteDestinationError(route, dest, "Failed", err)
return false
}
defer conn.Close()
dest.Increment("connectivity.dial.success", metricTags)
return true
}