Files
Wormhole/internal/bridge/keepalive.go
T
rose_cat707 612d68f56f feat: Wormhole 内网穿透与反向代理网关
Go + Vue 管理台,SQLite 持久化;支持隧道/域名穿透、域名转发插件链、访客认证、
IP 规则、API Key、Docker 单镜像部署;配置通过 Web 系统设置管理,无需 YAML 文件。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-23 12:15:02 +08:00

47 lines
1022 B
Go

package bridge
import (
"crypto/tls"
"net"
"time"
"github.com/xtaci/smux"
)
const (
// HeartbeatInterval is the application-level ping interval (agent and server probe).
HeartbeatInterval = 30 * time.Second
// HeartbeatTimeout evicts a session when no ping/pong for this duration.
HeartbeatTimeout = 90 * time.Second
// WatchdogInterval is how often the server checks agent heartbeats.
WatchdogInterval = 15 * time.Second
// ServerProbeAfter triggers a server-initiated ping when agent has been silent.
ServerProbeAfter = 45 * time.Second
)
func SmuxConfig() *smux.Config {
return smuxConfig()
}
func smuxConfig() *smux.Config {
cfg := smux.DefaultConfig()
cfg.KeepAliveInterval = 10 * time.Second
cfg.KeepAliveTimeout = 30 * time.Second
return cfg
}
func SetTCPKeepAlive(conn net.Conn) {
for {
switch c := conn.(type) {
case *net.TCPConn:
_ = c.SetKeepAlive(true)
_ = c.SetKeepAlivePeriod(30 * time.Second)
return
case *tls.Conn:
conn = c.NetConn()
default:
return
}
}
}