mirror of
				https://github.com/v2fly/v2ray-core.git
				synced 2025-11-04 11:49:16 +00:00 
			
		
		
		
	refresher prototype
This commit is contained in:
		
							parent
							
								
									0e940fb1fa
								
							
						
					
					
						commit
						2eb313d0c2
					
				
							
								
								
									
										15
									
								
								app/receiver/config.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								app/receiver/config.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,15 @@
 | 
			
		||||
package receiver
 | 
			
		||||
 | 
			
		||||
func (v *AllocationStrategy) GetConcurrencyValue() uint32 {
 | 
			
		||||
	if v == nil || v.Concurrency == nil {
 | 
			
		||||
		return 3
 | 
			
		||||
	}
 | 
			
		||||
	return v.Concurrency.Value
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (v *AllocationStrategy) GetRefreshValue() uint32 {
 | 
			
		||||
	if v == nil || v.Refresh == nil {
 | 
			
		||||
		return 5
 | 
			
		||||
	}
 | 
			
		||||
	return v.Refresh.Value
 | 
			
		||||
}
 | 
			
		||||
@ -3,10 +3,27 @@ package receiver
 | 
			
		||||
import (
 | 
			
		||||
	"net"
 | 
			
		||||
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	v2net "v2ray.com/core/common/net"
 | 
			
		||||
	"v2ray.com/core/proxy"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type refresher struct {
 | 
			
		||||
	strategy   *AllocationStrategy
 | 
			
		||||
	portsInUse []v2net.Port
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (r *refresher) Refresh(s *StreamReceiver) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (r *refresher) Interval() time.Duration {
 | 
			
		||||
	switch r.strategy.Type {
 | 
			
		||||
	case AllocationStrategy_Random:
 | 
			
		||||
		return time.Minute * time.Duration(r.strategy.GetRefreshValue())
 | 
			
		||||
	default:
 | 
			
		||||
		return 0
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type StreamReceiver struct {
 | 
			
		||||
@ -14,8 +31,20 @@ type StreamReceiver struct {
 | 
			
		||||
	proxy  *proxy.InboundHandler
 | 
			
		||||
 | 
			
		||||
	listeners []net.Listener
 | 
			
		||||
	refresher refresher
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (r *StreamReceiver) Start() {
 | 
			
		||||
func (s *StreamReceiver) Start() {
 | 
			
		||||
	s.refresher.Refresh(s)
 | 
			
		||||
	interval := s.refresher.Interval()
 | 
			
		||||
	if interval == 0 {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	go func() {
 | 
			
		||||
		for {
 | 
			
		||||
			time.Sleep(s.refresher.Interval())
 | 
			
		||||
			s.refresher.Refresh(s)
 | 
			
		||||
		}
 | 
			
		||||
	}()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user