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

Patch ReadDebugInfo issue in inproxy/portmapper dependency check

Rod Hynes 1 год назад
Родитель
Сommit
24d28f13be

+ 14 - 2
psiphon/common/inproxy/portmapper.go

@@ -147,12 +147,24 @@ func newPortMapper(
 var portmapperDependencyVersionCheck bool
 
 func init() {
+	expectedDependencyVersion := "v1.58.2"
+
+	// portmapper.Version is a temporary vendor patch, in the dependency, to
+	// accomodate GOPATH builds which cannot use debug.ReadBuildInfo, and go
+	// tests, before Go 1.24, which don't get dependency info in the returned
+	// BuildInfo.
+	//
+	// TODO: replace temporary patch with full fork of portmapper, and remove
+	// this temporary case, if not the entire dependency version check
+	// (see "TODO: fork" in cloneProbe).
+	portmapperDependencyVersionCheck = portmapper.Version == expectedDependencyVersion
+
 	buildInfo, ok := debug.ReadBuildInfo()
 	if !ok {
 		return
 	}
 	for _, dep := range buildInfo.Deps {
-		if dep.Path == "tailscale.com" && dep.Version == "v1.58.2" {
+		if dep.Path == "tailscale.com" && dep.Version == expectedDependencyVersion {
 			portmapperDependencyVersionCheck = true
 			return
 		}
@@ -166,7 +178,7 @@ func (p *portMapper) cloneProbe(probe *PortMappingProbe) error {
 	// The required portmapper.Client fields are not exported by
 	// tailscale/net/portmapper, so unsafe reflection is used to copy the
 	// values. A simple portmapper.Client struct copy can't be performed as
-	// the struct contain a sync.Mutex field.
+	// the struct contains a sync.Mutex field.
 	//
 	// The following is assumed, based on the pinned dependency version:
 	//

+ 8 - 0
vendor/tailscale.com/net/portmapper/portmapper.go

@@ -33,6 +33,14 @@ import (
 	"tailscale.com/util/clientmetric"
 )
 
+// [Psiphon]
+// Version is used to check this dependency version in GOPATH builds where
+// debug.ReadBuildInfo is not available, and go tests, before Go 1.24, which
+// don't get dependency info in the returned BuildInfo. This is currently a
+// temporary vendor patch which needs to be restored after any "go mod
+// vendor".
+const Version = "v1.58.2"
+
 // DebugKnobs contains debug configuration that can be provided when creating a
 // Client. The zero value is valid for use.
 type DebugKnobs struct {