Files
ginuerzh 1d42c2ec66 feat(tun): add device write-side self-probe
A running tun entrypoint cannot tell a dead device fd from an idle link: both look like frozen stats. The probe writes a self-addressed IPv4/UDP packet (spokeIP->spokeIP, magic+seq) into the device every 30s and reads it back on its own bound socket; sent/acked deltas go to the caller through the metadata probeReport callback. Enabled by metadata probe (default off, gost path unchanged); new probeSent/probeAcked counters (101/102) in x stats.
2026-10-07 05:07:13 +00:00

44 lines
1020 B
Go

package tun
import (
"math"
"time"
mdata "github.com/go-gost/core/metadata"
mdutil "github.com/go-gost/x/metadata/util"
)
const (
defaultKeepAlivePeriod = 10 * time.Second
MaxMessageSize = math.MaxUint16
)
type metadata struct {
keepAlivePeriod time.Duration
passphrase string
p2p bool
probe bool
probeReport func(sentDelta, ackedDelta uint64)
}
func (h *tunHandler) parseMetadata(md mdata.Metadata) (err error) {
if mdutil.GetBool(md, "tun.keepalive", "keepalive") {
h.md.keepAlivePeriod = mdutil.GetDuration(md, "tun.ttl", "ttl")
if h.md.keepAlivePeriod <= 0 {
h.md.keepAlivePeriod = defaultKeepAlivePeriod
}
}
h.md.passphrase = mdutil.GetString(md, "tun.token", "token", "passphrase")
h.md.p2p = mdutil.GetBool(md, "tun.p2p", "p2p")
h.md.probe = mdutil.GetBool(md, "tun.probe", "probe")
v := md.Get("tun.probeReport")
if v == nil {
v = md.Get("probeReport")
}
if fn, ok := v.(func(uint64, uint64)); ok {
h.md.probeReport = fn
}
return
}