From 1040f75b4fcb9db89ad9c17120f11bab2c99085d Mon Sep 17 00:00:00 2001
From: cyberta <cyberta@riseup.net>
Date: Fri, 9 Dec 2022 17:38:05 +0100
Subject: [PATCH] update IPtProxy to 1.8.1, Snowflake 2.3.1

---
 IPtProxy       |   2 +-
 build_core.sh  |   2 +-
 iptproxy.patch | 148 +++++++++++++------------------------------------
 3 files changed, 40 insertions(+), 112 deletions(-)

diff --git a/IPtProxy b/IPtProxy
index c812426..0cd8663 160000
--- a/IPtProxy
+++ b/IPtProxy
@@ -1 +1 @@
-Subproject commit c812426041708a156be221b7edd3a88c723a14b9
+Subproject commit 0cd866334193d5e882bd537f18be89f831d7954c
diff --git a/build_core.sh b/build_core.sh
index 116f005..a38e86e 100755
--- a/build_core.sh
+++ b/build_core.sh
@@ -93,7 +93,7 @@ showtitle "initiating gomobile"
 # -------- prepare snowflake ---------------
 showtitle "Checking out snowflake repository"
 cd ./IPtProxy/snowflake
-git checkout --force --quiet c983c13a || quit "Failed to checkout snowflake at commit ead5a960"
+git checkout --force --quiet 36f03dfd4483922b3e7400dedc71df9cf2f30b6b || quit "Failed to checkout snowflake at commit 36f03dfd4483922b3e7400dedc71df9cf2f30b6b"
 git submodule update --init --recursive || quit "Failed to update snowflake submodules"
 cd ..
 
diff --git a/iptproxy.patch b/iptproxy.patch
index cc5a1ed..23837df 100644
--- a/iptproxy.patch
+++ b/iptproxy.patch
@@ -1,8 +1,8 @@
 diff --git a/IPtProxy.go/IPtProxy.go b/IPtProxy.go/IPtProxy.go
-index c2b9b2f..49ced93 100644
+index 9fea4f3..1dc3f2f 100644
 --- a/IPtProxy.go/IPtProxy.go
 +++ b/IPtProxy.go/IPtProxy.go
-@@ -1,69 +1,19 @@
+@@ -1,10 +1,6 @@
  package IPtProxy
  
  import (
@@ -13,12 +13,10 @@ index c2b9b2f..49ced93 100644
  	"io"
  	"log"
  	"net"
- 	"os"
- 	"runtime"
-+	"runtime/debug"
+@@ -14,57 +10,11 @@ import (
+ 	"runtime/debug"
  	"strconv"
  	"time"
--	"runtime/debug"
 -)
 -
 -var meekPort = 47000
@@ -50,7 +48,7 @@ index c2b9b2f..49ced93 100644
 -func Obfs3Port() int {
 -	return obfs3Port
 -}
- 
+-
 -var obfs4Port = 47300
 -
 -// Obfs4Port - Port where Obfs4proxy will provide its Obfs4 service.
@@ -62,7 +60,7 @@ index c2b9b2f..49ced93 100644
 -}
 -
 -var scramblesuitPort = 47400
--
+ 
 -// ScramblesuitPort - Port where Obfs4proxy will provide its Scramblesuit service.
 -// Only use this property after calling StartObfs4Proxy! It might have changed after that!
 -//
@@ -77,38 +75,39 @@ index c2b9b2f..49ced93 100644
  
  var snowflakePort = 52000
  
-@@ -92,120 +42,27 @@ func init() {
- 	StateLocation += "/pt_state"
+@@ -76,7 +26,6 @@ func SnowflakePort() int {
+ 	return snowflakePort
+ }
+ 
+-var obfs4ProxyRunning = false
+ var snowflakeRunning = false
+ var snowflakeProxy *sfp.SnowflakeProxy
+ 
+@@ -93,13 +42,6 @@ func init() {
+ 	StateLocation = filepath.Join(StateLocation, "pt_state")
  }
  
 -// Obfs4ProxyVersion - The version of Obfs4Proxy bundled with IPtProxy.
 -//
 -//goland:noinspection GoUnusedExportedFunction
 -func Obfs4ProxyVersion() string {
--    return obfs4proxy.Obfs4proxyVersion
+-	return obfs4proxy.Obfs4proxyVersion
 -}
 -
- // SnowflakeVersion  - The version of Snowflake bundled with IPtProxy.
+ // SnowflakeVersion - The version of Snowflake bundled with IPtProxy.
  //
  //goland:noinspection GoUnusedExportedFunction
- func SnowflakeVersion() string {
--    bi, ok := debug.ReadBuildInfo()
--    if !ok {
--        log.Printf("Failed to read build info")
--        return ""
--    }
--
--    for _, dep := range bi.Deps {
--    	if dep.Path == "git.torproject.org/pluggable-transports/snowflake.git/v2" {
--    	    if dep.Version[0:1] == "v" {
--        		return dep.Version[1:len(dep.Version)]
--    	    } else {
--    	        return dep.Version
--    	    }
--    	}
--    }
--
--    return ""
+@@ -123,102 +65,6 @@ func SnowflakeVersion() string {
+ 	return ""
+ }
+ 
+-// Obfs4proxyLogFile - The log file name used by Obfs4proxy.
+-//
+-// The Obfs4proxy log file can be found at `filepath.Join(StateLocation, Obfs4proxyLogFile())`.
+-//
+-//goland:noinspection GoUnusedExportedFunction
+-func Obfs4proxyLogFile() string {
+-	return obfs4proxy.Obfs4proxyLogFile
 -}
 -
 -// StartObfs4Proxy - Start the Obfs4Proxy.
@@ -125,18 +124,15 @@ index c2b9b2f..49ced93 100644
 -// @param proxy HTTP, SOCKS4 or SOCKS5 proxy to be used behind Obfs4proxy. E.g. "socks5://127.0.0.1:12345"
 -//
 -// @return Port number where Obfs4Proxy will listen on for Obfs4(!), if no error happens during start up.
+-//
 -//	If you need the other ports, check MeekPort, Obfs2Port, Obfs3Port and ScramblesuitPort properties!
 -//
 -//goland:noinspection GoUnusedExportedFunction
 -func StartObfs4Proxy(logLevel string, enableLogging, unsafeLogging bool, proxy string) int {
 -	if obfs4ProxyRunning {
 -		return obfs4Port
-+	bi, ok := debug.ReadBuildInfo()
-+	if !ok {
-+		log.Printf("Failed to read build info")
-+		return ""
- 	}
- 
+-	}
+-
 -	obfs4ProxyRunning = true
 -
 -	for !IsPortAvailable(meekPort) {
@@ -194,85 +190,17 @@ index c2b9b2f..49ced93 100644
 -func StopObfs4Proxy() {
 -	if !obfs4ProxyRunning {
 -		return
-+	for _, dep := range bi.Deps {
-+		if dep.Path == "git.torproject.org/pluggable-transports/snowflake.git/v2" {
-+			if dep.Version[0:1] == "v" {
-+				return dep.Version[1:len(dep.Version)]
-+			} else {
-+				return dep.Version
-+			}
-+		}
- 	}
- 
+-	}
+-
 -	go obfs4proxy.Stop()
 -
 -	obfs4ProxyRunning = false
-+	return ""
- }
- 
+-}
+-
  // StartSnowflake - Start the Snowflake client.
-@@ -302,16 +159,16 @@ func StartSnowflakeProxy(capacity int, broker, relay, stun, natProbe, logFile st
- 		capacity = 0
- 	}
- 
--	snowflakeProxy = &sfp.SnowflakeProxy {
--		Capacity:           uint(capacity),
--		STUNURL:            stun,
--		BrokerURL:          broker,
--		KeepLocalAddresses: keepLocalAddresses,
--		RelayURL:           relay,
--		NATProbeURL:        natProbe,
--		ProxyType:          "iptproxy",
-+	snowflakeProxy = &sfp.SnowflakeProxy{
-+		Capacity:               uint(capacity),
-+		STUNURL:                stun,
-+		BrokerURL:              broker,
-+		KeepLocalAddresses:     keepLocalAddresses,
-+		RelayURL:               relay,
-+		NATProbeURL:            natProbe,
-+		ProxyType:              "iptproxy",
- 		RelayDomainNamePattern: "snowflake.torproject.net$",
--		AllowNonTLSRelay: false,
-+		AllowNonTLSRelay:       false,
- 		ClientConnectedCallback: func() {
- 			if clientConnected != nil {
- 				clientConnected.Connected()
-@@ -326,7 +183,7 @@ func StartSnowflakeProxy(capacity int, broker, relay, stun, natProbe, logFile st
- 		log.SetFlags(log.LstdFlags | log.LUTC)
- 
- 		if logFile != "" {
--			f, err := os.OpenFile(logFile, os.O_CREATE | os.O_WRONLY | os.O_APPEND, 0600)
-+			f, err := os.OpenFile(logFile, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0600)
- 			if err != nil {
- 				log.Fatal(err)
- 			}
-@@ -352,6 +209,7 @@ func StartSnowflakeProxy(capacity int, broker, relay, stun, natProbe, logFile st
- func IsSnowflakeProxyRunning() bool {
- 	return snowflakeProxy != nil
- }
-+
- // StopSnowflakeProxy - Stop the Snowflake proxy.
  //
- //goland:noinspection GoUnusedExportedFunction
-@@ -364,7 +222,7 @@ func StopSnowflakeProxy() {
- 		snowflakeProxy.Stop()
- 	}(snowflakeProxy)
- 
--    snowflakeProxy = nil
-+	snowflakeProxy = nil
- }
- 
- // IsPortAvailable - Checks to see if a given port is not in use.
-@@ -373,7 +231,7 @@ func StopSnowflakeProxy() {
- func IsPortAvailable(port int) bool {
- 	address := net.JoinHostPort("127.0.0.1", strconv.Itoa(port))
- 
--	conn, err := net.DialTimeout("tcp", address, 500 * time.Millisecond)
-+	conn, err := net.DialTimeout("tcp", address, 500*time.Millisecond)
- 
- 	if err != nil {
- 		return true
-@@ -394,7 +252,7 @@ func IsPortAvailable(port int) bool {
+ // @param ice Comma-separated list of ICE servers.
+@@ -408,7 +254,7 @@ func IsPortAvailable(port int) bool {
  // time this is called. It's still the ENVIRONMENT, we're changing here, so there might
  // be race conditions.
  func fixEnv() {
-- 
GitLab