receiver.go 806 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package receiver
  2. import (
  3. "net"
  4. "time"
  5. v2net "v2ray.com/core/common/net"
  6. "v2ray.com/core/proxy"
  7. )
  8. type refresher struct {
  9. strategy *AllocationStrategy
  10. portsInUse []v2net.Port
  11. }
  12. func (r *refresher) Refresh(s *StreamReceiver) {
  13. }
  14. func (r *refresher) Interval() time.Duration {
  15. switch r.strategy.Type {
  16. case AllocationStrategy_Random:
  17. return time.Minute * time.Duration(r.strategy.GetRefreshValue())
  18. default:
  19. return 0
  20. }
  21. }
  22. type StreamReceiver struct {
  23. config *StreamReceiverConfig
  24. proxy *proxy.InboundHandler
  25. listeners []net.Listener
  26. refresher refresher
  27. }
  28. func (s *StreamReceiver) Start() {
  29. s.refresher.Refresh(s)
  30. interval := s.refresher.Interval()
  31. if interval == 0 {
  32. return
  33. }
  34. go func() {
  35. for {
  36. time.Sleep(s.refresher.Interval())
  37. s.refresher.Refresh(s)
  38. }
  39. }()
  40. }