[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [pluggable-transports/snowflake] 03/04: Change how ephemeral-ports-range CLI flag is handled



This is an automated email from the git hooks/post-receive script.

meskio pushed a commit to branch main
in repository pluggable-transports/snowflake.

commit 068af0870370b5c1ae8690068088b2d8ed11bfa5
Author: KokaKiwi <kokakiwi+git@xxxxxxxxxxxx>
AuthorDate: Fri Sep 30 17:50:21 2022 +0200

    Change how ephemeral-ports-range CLI flag is handled
---
 proxy/main.go | 43 +++++++++++++++++++++++++------------------
 1 file changed, 25 insertions(+), 18 deletions(-)

diff --git a/proxy/main.go b/proxy/main.go
index e187559..a6e6a19 100644
--- a/proxy/main.go
+++ b/proxy/main.go
@@ -1,7 +1,9 @@
 package main
 
 import (
+	"errors"
 	"flag"
+	"fmt"
 	"io"
 	"io/ioutil"
 	"log"
@@ -30,7 +32,27 @@ func main() {
 	SummaryInterval := flag.Duration("summary-interval", time.Hour,
 		"the time interval to output summary, 0s disables summaries. Valid time units are \"s\", \"m\", \"h\". ")
 	verboseLogging := flag.Bool("verbose", false, "increase log verbosity")
-	ephemeralPortsRange := flag.String("ephemeral-ports-range", "", "UDP ephemeral ports range")
+	var ephemeralPortsRange []uint16 = []uint16{0, 0}
+	flag.Func("ephemeral-ports-range", "ICE UDP ephemeral ports range (format: \"[min]:[max]\")", func(s string) error {
+		ephemeralPortsRangeParts := strings.Split(s, ":")
+		if len(ephemeralPortsRangeParts) == 2 {
+			ephemeralMinPort, err := strconv.ParseUint(ephemeralPortsRangeParts[0], 10, 16)
+			if err != nil {
+				return err
+			}
+
+			ephemeralMaxPort, err := strconv.ParseUint(ephemeralPortsRangeParts[1], 10, 16)
+			if err != nil {
+				return err
+			}
+
+			ephemeralPortsRange = []uint16{uint16(ephemeralMinPort), uint16(ephemeralMaxPort)}
+
+			return nil
+		}
+
+		return errors.New(fmt.Sprintf("Bad range port format: %v", s))
+	})
 
 	flag.Parse()
 
@@ -42,6 +64,8 @@ func main() {
 		BrokerURL:          *rawBrokerURL,
 		KeepLocalAddresses: *keepLocalAddresses,
 		RelayURL:           *relayURL,
+		EphemeralMinPort:   ephemeralPortsRange[0],
+		EphemeralMaxPort:   ephemeralPortsRange[1],
 
 		NATTypeMeasurementInterval: *NATTypeMeasurementInterval,
 		EventDispatcher:            eventLogger,
@@ -50,23 +74,6 @@ func main() {
 		AllowNonTLSRelay:       *allowNonTLSRelay,
 	}
 
-	ephemeralPortsRangeParts := strings.Split(*ephemeralPortsRange, ":")
-	if len(ephemeralPortsRangeParts) == 2 {
-		ephemeralMinPort, err := strconv.ParseUint(ephemeralPortsRangeParts[0], 10, 16)
-		if err == nil {
-			proxy.EphemeralMinPort = uint16(ephemeralMinPort)
-		} else {
-			log.Printf("Invalid port (%v): %v", ephemeralPortsRangeParts[0], err)
-		}
-
-		ephemeralMaxPort, err := strconv.ParseUint(ephemeralPortsRangeParts[1], 10, 16)
-		if err == nil {
-			proxy.EphemeralMaxPort = uint16(ephemeralMaxPort)
-		} else {
-			log.Printf("Invalid port (%v): %v", ephemeralPortsRangeParts[1], err)
-		}
-	}
-
 	var logOutput io.Writer = os.Stderr
 	var eventlogOutput io.Writer = os.Stderr
 	log.SetFlags(log.LstdFlags | log.LUTC)

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits