github.com/letsencrypt/boulder@v0.20251208.0/observer/probers/tcp/tcp.go (about)

     1  package tcp
     2  
     3  import (
     4  	"context"
     5  	"time"
     6  
     7  	"github.com/letsencrypt/boulder/observer/obsdialer"
     8  )
     9  
    10  type TCPProbe struct {
    11  	hostport string
    12  }
    13  
    14  // Name returns a string that uniquely identifies the monitor.
    15  
    16  func (p TCPProbe) Name() string {
    17  	return p.hostport
    18  }
    19  
    20  // Kind returns a name that uniquely identifies the `Kind` of `Prober`.
    21  func (p TCPProbe) Kind() string {
    22  	return "TCP"
    23  }
    24  
    25  // Probe performs the configured TCP dial.
    26  func (p TCPProbe) Probe(timeout time.Duration) (bool, time.Duration) {
    27  	ctx, cancel := context.WithTimeout(context.Background(), timeout)
    28  	defer cancel()
    29  	start := time.Now()
    30  	c, err := obsdialer.Dialer.DialContext(ctx, "tcp", p.hostport)
    31  	if err != nil {
    32  		return false, time.Since(start)
    33  	}
    34  	c.Close()
    35  	return true, time.Since(start)
    36  }