mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-02-03 22:18:39 +00:00
log ipv6 availability logic more debugging for ipv6 availability checks more debugging for ipv6 availability checks
52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
package ctrld
|
|
|
|
import (
|
|
"context"
|
|
"sync"
|
|
"sync/atomic"
|
|
"time"
|
|
|
|
ctrldnet "github.com/Control-D-Inc/ctrld/internal/net"
|
|
)
|
|
|
|
var (
|
|
hasIPv6Once sync.Once
|
|
ipv6Available atomic.Bool
|
|
)
|
|
|
|
const ipv6ProbingInterval = 10 * time.Second
|
|
|
|
func hasIPv6() bool {
|
|
hasIPv6Once.Do(func() {
|
|
Log(context.Background(), ProxyLogger.Load().Debug(), "checking for IPv6 availability once")
|
|
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
|
defer cancel()
|
|
val := ctrldnet.IPv6Available(ctx)
|
|
ipv6Available.Store(val)
|
|
go probingIPv6(context.TODO(), val)
|
|
})
|
|
return ipv6Available.Load()
|
|
}
|
|
|
|
// TODO(cuonglm): doing poll check natively for supported platforms.
|
|
func probingIPv6(ctx context.Context, old bool) {
|
|
ticker := time.NewTicker(ipv6ProbingInterval)
|
|
defer ticker.Stop()
|
|
for {
|
|
select {
|
|
case <-ctx.Done():
|
|
return
|
|
case <-ticker.C:
|
|
func() {
|
|
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
|
defer cancel()
|
|
cur := ctrldnet.IPv6Available(ctx)
|
|
if ipv6Available.CompareAndSwap(old, cur) {
|
|
old = cur
|
|
}
|
|
Log(ctx, ProxyLogger.Load().Debug(), "IPv6 availability: %v", cur)
|
|
}()
|
|
}
|
|
}
|
|
}
|