From 43d2ff0a091905559cecc26549ee2a6d318ef507 Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Mon, 21 Sep 2020 06:02:13 -0700 Subject: [PATCH] find open ports to open local relay --- src/croc/croc.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/croc/croc.go b/src/croc/croc.go index ff26161..fb08ff8 100644 --- a/src/croc/croc.go +++ b/src/croc/croc.go @@ -13,6 +13,7 @@ import ( "os" "path" "path/filepath" + "strconv" "strings" "sync" "time" @@ -264,6 +265,14 @@ func (c *Client) sendCollectFiles(options TransferOptions) (err error) { func (c *Client) setupLocalRelay() { // setup the relay locally + firstPort, _ := strconv.Atoi(c.Options.RelayPorts[0]) + openPorts := utils.FindOpenPorts("localhost", firstPort, len(c.Options.RelayPorts)) + if len(openPorts) < len(c.Options.RelayPorts) { + panic("not enough open ports to run local relay") + } + for i, port := range openPorts { + c.Options.RelayPorts[i] = fmt.Sprint(port) + } for _, port := range c.Options.RelayPorts { go func(portStr string) { debugString := "warn"