27 lines
646 B
Go
27 lines
646 B
Go
package pool
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net"
|
|
"net/netip"
|
|
"time"
|
|
)
|
|
|
|
// TCPProber reports a node as reachable when its management port accepts a
|
|
// TCP connection from the host side of the management bridge.
|
|
type TCPProber struct {
|
|
Timeout time.Duration
|
|
}
|
|
|
|
// Probe opens and closes one connection.
|
|
func (p TCPProber) Probe(ctx context.Context, address netip.AddrPort) error {
|
|
dialer := net.Dialer{Timeout: p.Timeout}
|
|
connection, err := dialer.DialContext(ctx, "tcp", address.String())
|
|
if err != nil {
|
|
return fmt.Errorf("TCPProber.Probe - dial: %w", err)
|
|
}
|
|
_ = connection.Close() // Only the accepted connection matters.
|
|
return nil
|
|
}
|