fix: proxy web device resources transparently

This commit is contained in:
Yoilun
2026-05-15 11:12:27 +08:00
parent bd49486304
commit 7498960ba3
4 changed files with 146 additions and 15 deletions

View File

@@ -61,6 +61,7 @@ type Service struct {
mu sync.RWMutex
allowed map[string]time.Time
forwarders map[string]*webDeviceForwarder
proxyLimiters map[string]chan struct{}
interfaceGetter InterfaceGetter
hostLANGetter InterfaceGetter
tcpScanner TCPScanner
@@ -73,6 +74,7 @@ func NewService() *Service {
return &Service{
allowed: make(map[string]time.Time),
forwarders: make(map[string]*webDeviceForwarder),
proxyLimiters: make(map[string]chan struct{}),
interfaceGetter: defaultInterfaceGetter,
hostLANGetter: defaultHostLANInterfaceGetter,
tcpScanner: scanTCP,
@@ -256,6 +258,20 @@ func (s *Service) ProxyTargetURL(ip string) string {
return s.proxyTarget(ip)
}
func (s *Service) proxyLimiter(ip string) chan struct{} {
s.mu.Lock()
defer s.mu.Unlock()
if s.proxyLimiters == nil {
s.proxyLimiters = make(map[string]chan struct{})
}
limiter := s.proxyLimiters[ip]
if limiter == nil {
limiter = make(chan struct{}, webDeviceProxyConcurrency)
s.proxyLimiters[ip] = limiter
}
return limiter
}
func IsPrivateIPv4Literal(value string) bool {
ip := net.ParseIP(value)
if ip == nil {