fix: proxy web device resources transparently
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user