cmd/quictpu/ping: add -count and -delay

This commit is contained in:
Leopold Schabel 2022-06-19 13:14:16 +02:00
parent 74ef2c4801
commit 6787f534c7
1 changed files with 24 additions and 12 deletions

View File

@ -22,6 +22,8 @@ import (
var (
flagDebug = flag.Bool("debug", false, "Enable debug logging")
flagCount = flag.Int("count", 1, "Number of pings to send, -1 for infinite")
flagDelay = flag.Duration("delay", 1*time.Second, "Delay between pings")
)
func init() {
@ -62,13 +64,18 @@ func main() {
KeyLogWriter: dbg,
}
c := 0
for c < *flagCount || *flagCount == -1 {
t := time.Now()
conn, err := quic.DialAddrContext(ctx, flag.Args()[0], tlsConf, &qconf)
if err != nil {
klog.Exitf("Failed to dial: %v", err)
}
klog.Infof("Connected to %s (%dms)", flag.Args()[0], time.Since(t).Milliseconds())
klog.Infof("Connected to %s (in %dms, %d/%d)",
flag.Args()[0], time.Since(t).Milliseconds(),
c+1, *flagCount)
for _, cert := range conn.ConnectionState().TLS.PeerCertificates {
klog.Infof("Certificate: %s", cert.Subject)
@ -78,4 +85,9 @@ func main() {
if err := conn.CloseWithError(0, ""); err != nil {
klog.Exitf("Failed to close: %v", err)
}
time.Sleep(*flagDelay)
c++
}
}