Просмотр исходного кода

Merge pull request #258 from rod-hynes/master

Change defaults for port forward traffic rules
Rod Hynes 9 лет назад
Родитель
Сommit
772b8833ae
2 измененных файлов с 33 добавлено и 12 удалено
  1. 4 4
      psiphon/server/config.go
  2. 29 8
      psiphon/server/trafficRules.go

+ 4 - 4
psiphon/server/config.go

@@ -534,10 +534,10 @@ func GenerateConfig(params *GenerateConfigParams) ([]byte, []byte, []byte, error
 				WriteUnthrottledBytes: new(int64),
 				WriteBytesPerSecond:   new(int64),
 			},
-			IdleTCPPortForwardTimeoutMilliseconds: intPtr(30000),
-			IdleUDPPortForwardTimeoutMilliseconds: intPtr(30000),
-			MaxTCPPortForwardCount:                intPtr(1024),
-			MaxUDPPortForwardCount:                intPtr(32),
+			IdleTCPPortForwardTimeoutMilliseconds: intPtr(DEFAULT_IDLE_TCP_PORT_FORWARD_TIMEOUT_MILLISECONDS),
+			IdleUDPPortForwardTimeoutMilliseconds: intPtr(DEFAULT_IDLE_UDP_PORT_FORWARD_TIMEOUT_MILLISECONDS),
+			MaxTCPPortForwardCount:                intPtr(DEFAULT_MAX_TCP_PORT_FORWARD_COUNT),
+			MaxUDPPortForwardCount:                intPtr(DEFAULT_MAX_UDP_PORT_FORWARD_COUNT),
 			AllowTCPPorts:                         nil,
 			AllowUDPPorts:                         nil,
 		},

+ 29 - 8
psiphon/server/trafficRules.go

@@ -28,6 +28,13 @@ import (
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common"
 )
 
+const (
+	DEFAULT_IDLE_TCP_PORT_FORWARD_TIMEOUT_MILLISECONDS = 30000
+	DEFAULT_IDLE_UDP_PORT_FORWARD_TIMEOUT_MILLISECONDS = 30000
+	DEFAULT_MAX_TCP_PORT_FORWARD_COUNT                 = 512
+	DEFAULT_MAX_UDP_PORT_FORWARD_COUNT                 = 32
+)
+
 // TrafficRulesSet represents the various traffic rules to
 // apply to Psiphon client tunnels. The Reload function supports
 // hot reloading of rules data while the server is running.
@@ -86,23 +93,29 @@ type TrafficRules struct {
 	// IdleTCPPortForwardTimeoutMilliseconds is the timeout period
 	// after which idle (no bytes flowing in either direction)
 	// client TCP port forwards are preemptively closed.
-	// The default, 0, is no idle timeout.
+	// A value of 0 specifies no idle timeout. When omitted in
+	// DefaultRules, DEFAULT_IDLE_TCP_PORT_FORWARD_TIMEOUT_MILLISECONDS
+	// is used.
 	IdleTCPPortForwardTimeoutMilliseconds *int
 
 	// IdleUDPPortForwardTimeoutMilliseconds is the timeout period
 	// after which idle (no bytes flowing in either direction)
 	// client UDP port forwards are preemptively closed.
-	// The default, 0, is no idle timeout.
+	// A value of 0 specifies no idle timeout. When omitted in
+	// DefaultRules, DEFAULT_IDLE_UDP_PORT_FORWARD_TIMEOUT_MILLISECONDS
+	// is used.
 	IdleUDPPortForwardTimeoutMilliseconds *int
 
 	// MaxTCPPortForwardCount is the maximum number of TCP port
 	// forwards each client may have open concurrently.
-	// The default, 0, is no maximum.
+	// A value of 0 specifies no maximum. When omitted in
+	// DefaultRules, DEFAULT_MAX_TCP_PORT_FORWARD_COUNT is used.
 	MaxTCPPortForwardCount *int
 
 	// MaxUDPPortForwardCount is the maximum number of UDP port
 	// forwards each client may have open concurrently.
-	// The default, 0, is no maximum.
+	// A value of 0 specifies no maximum. When omitted in
+	// DefaultRules, DEFAULT_MAX_UDP_PORT_FORWARD_COUNT is used.
 	MaxUDPPortForwardCount *int
 
 	// AllowTCPPorts specifies a whitelist of TCP ports that
@@ -277,20 +290,28 @@ func (set *TrafficRulesSet) GetTrafficRules(
 		trafficRules.RateLimits.CloseAfterExhausted = new(bool)
 	}
 
+	intPtr := func(i int) *int {
+		return &i
+	}
+
 	if trafficRules.IdleTCPPortForwardTimeoutMilliseconds == nil {
-		trafficRules.IdleTCPPortForwardTimeoutMilliseconds = new(int)
+		trafficRules.IdleTCPPortForwardTimeoutMilliseconds =
+			intPtr(DEFAULT_IDLE_TCP_PORT_FORWARD_TIMEOUT_MILLISECONDS)
 	}
 
 	if trafficRules.IdleUDPPortForwardTimeoutMilliseconds == nil {
-		trafficRules.IdleUDPPortForwardTimeoutMilliseconds = new(int)
+		trafficRules.IdleUDPPortForwardTimeoutMilliseconds =
+			intPtr(DEFAULT_IDLE_UDP_PORT_FORWARD_TIMEOUT_MILLISECONDS)
 	}
 
 	if trafficRules.MaxTCPPortForwardCount == nil {
-		trafficRules.MaxTCPPortForwardCount = new(int)
+		trafficRules.MaxTCPPortForwardCount =
+			intPtr(DEFAULT_MAX_TCP_PORT_FORWARD_COUNT)
 	}
 
 	if trafficRules.MaxUDPPortForwardCount == nil {
-		trafficRules.MaxUDPPortForwardCount = new(int)
+		trafficRules.MaxUDPPortForwardCount =
+			intPtr(DEFAULT_MAX_UDP_PORT_FORWARD_COUNT)
 	}
 
 	if trafficRules.AllowTCPPorts == nil {