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

Don't import packetman and its dependencies client-side

Rod Hynes 5 лет назад
Родитель
Сommit
bd457ffbd5
2 измененных файлов с 34 добавлено и 7 удалено
  1. 27 6
      psiphon/common/parameters/packetman.go
  2. 7 1
      psiphon/server/packetman.go

+ 27 - 6
psiphon/common/parameters/packetman.go

@@ -21,12 +21,25 @@ package parameters
 
 import (
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/errors"
-	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/packetman"
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/protocol"
 )
 
+// PacketManipulationSpec is a work-around to avoid the client-side code size
+// impact of importing the packetman package and its dependencies.
+//
+// TODO: Given that packetman and its parameters are server-side only,
+// rearrange tactics/parameters to reference packetman.Spec directly, but only
+// in server code. This should allow reinstating the spec.Validate below.
+
+// PacketManipulationSpec is type-compatible with
+// psiphon/common.packetman.Spec.
+type PacketManipulationSpec struct {
+	Name        string
+	PacketSpecs [][]string
+}
+
 // PacketManipulationSpecs is a list of packet manipulation specs.
-type PacketManipulationSpecs []*packetman.Spec
+type PacketManipulationSpecs []*PacketManipulationSpec
 
 // Validate checks that each spec name is unique and that each spec compiles.
 func (specs PacketManipulationSpecs) Validate() error {
@@ -39,10 +52,18 @@ func (specs PacketManipulationSpecs) Validate() error {
 			return errors.TraceNew("duplicate spec name")
 		}
 		specNames[spec.Name] = true
-		err := spec.Validate()
-		if err != nil {
-			return errors.Trace(err)
-		}
+
+		// See PacketManipulationSpec comment above.
+		//
+		// Note that, even with spec.Validate disabled, spec validation will still
+		// be performed, by packetman.Manipulator, on startup and after tactics hot
+		// reload, with equivilent outcomes for invalid specs; however, the tactics
+		// load itself will not fail in this case.
+
+		// err := spec.Validate()
+		// if err != nil {
+		// 	return errors.Trace(err)
+		// }
 	}
 	return nil
 }

+ 7 - 1
psiphon/server/packetman.go

@@ -98,7 +98,13 @@ func getPacketManipulationSpecs(support *SupportServices) ([]*packetman.Spec, er
 	}
 	p := clientParameters.Get()
 
-	specs := p.PacketManipulationSpecs(parameters.ServerPacketManipulationSpecs)
+	paramSpecs := p.PacketManipulationSpecs(parameters.ServerPacketManipulationSpecs)
+
+	specs := make([]*packetman.Spec, len(paramSpecs))
+	for i, spec := range paramSpecs {
+		packetmanSpec := packetman.Spec(*spec)
+		specs[i] = &packetmanSpec
+	}
 
 	return specs, nil
 }