feat: speed up first sysInfo call

This commit is contained in:
langhuihui
2024-12-17 16:05:36 +08:00
parent b3a3e37429
commit 0042568dff
17 changed files with 820 additions and 437 deletions

View File

@@ -36,7 +36,8 @@ type (
IdleTimeout time.Duration `desc:"空闲(无订阅)超时"` // 空闲(无订阅)超时
PauseTimeout time.Duration `default:"30s" desc:"暂停超时时间"` // 暂停超时
BufferTime time.Duration `desc:"缓冲时长0代表取最近关键帧"` // 缓冲长度(单位:秒)0代表取最近关键帧
Speed float64 `default:"0" desc:"倍速"` // 倍速0 为不限速
Speed float64 `default:"0" desc:"发送速率"` // 发送速率0 为不限速
Scale float64 `default:"1" desc:"缩放倍数"` // 缩放倍数
Key string `desc:"发布鉴权key"` // 发布鉴权key
RingSize util.Range[int] `default:"20-1024" desc:"RingSize范围"` // 缓冲区大小范围
RelayMode string `default:"remux" desc:"转发模式" enum:"remux:转格式,relay:纯转发,mix:混合转发"` // 转发模式

View File

@@ -11,6 +11,7 @@ import (
"regexp"
"strconv"
"strings"
"sync"
"time"
myip "github.com/husanpao/ip"
@@ -283,17 +284,26 @@ func IsPrivateIP(ip string) bool {
return privateIPReg.MatchString(ip)
}
// TODO: map race
func GetPublicIP(ip string) string {
if routes == nil {
routes = make(map[string]string)
for k, v := range myip.LocalAndInternalIPs() {
routes[k] = v
if lastdot := strings.LastIndex(k, "."); lastdot >= 0 {
routes[k[0:lastdot]] = k
}
func initRoutes() {
for k, v := range myip.LocalAndInternalIPs() {
routes[k] = v
if lastdot := strings.LastIndex(k, "."); lastdot >= 0 {
routes[k[0:lastdot]] = k
}
}
initRoutesWait.Done()
}
var initRoutesWait sync.WaitGroup
func init() {
routes = make(map[string]string)
initRoutesWait.Add(1)
go initRoutes()
}
func GetPublicIP(ip string) string {
initRoutesWait.Wait()
if publicIP, ok := routes[ip]; ok {
return publicIP
}