From b3c0625659804fe7fd562d74afd9365c919190f1 Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Mon, 20 Mar 2023 09:16:07 -0700 Subject: [PATCH] localhost -> 127.0.0.1 Fixes #513 --- src/comm/comm_test.go | 2 +- src/croc/croc.go | 12 ++++++------ src/croc/croc_test.go | 26 +++++++++++++------------- src/message/message_test.go | 2 +- src/tcp/tcp_test.go | 18 +++++++++--------- src/utils/utils.go | 2 +- src/utils/utils_test.go | 2 +- 7 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/comm/comm_test.go b/src/comm/comm_test.go index f2e0ad8..afba91f 100644 --- a/src/comm/comm_test.go +++ b/src/comm/comm_test.go @@ -49,7 +49,7 @@ func TestComm(t *testing.T) { }() time.Sleep(300 * time.Millisecond) - a, err := NewConnection("localhost:"+port, 10*time.Minute) + a, err := NewConnection("127.0.0.1:"+port, 10*time.Minute) assert.Nil(t, err) data, err := a.Receive() assert.Equal(t, []byte("hello, world"), data) diff --git a/src/croc/croc.go b/src/croc/croc.go index 1823527..9892f4c 100644 --- a/src/croc/croc.go +++ b/src/croc/croc.go @@ -428,7 +428,7 @@ func (c *Client) sendCollectFiles(filesInfo []FileInfo) (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)) + openPorts := utils.FindOpenPorts("127.0.0.1", firstPort, len(c.Options.RelayPorts)) if len(openPorts) < len(c.Options.RelayPorts) { panic("not enough open ports to run local relay") } @@ -441,7 +441,7 @@ func (c *Client) setupLocalRelay() { if c.Options.Debug { debugString = "debug" } - err := tcp.Run(debugString, "localhost", portStr, c.Options.RelayPassword, strings.Join(c.Options.RelayPorts[1:], ",")) + err := tcp.Run(debugString, "127.0.0.1", portStr, c.Options.RelayPassword, strings.Join(c.Options.RelayPorts[1:], ",")) if err != nil { panic(err) } @@ -480,10 +480,10 @@ func (c *Client) transferOverLocalRelay(errchan chan<- error) { time.Sleep(500 * time.Millisecond) log.Debug("establishing connection") var banner string - conn, banner, ipaddr, err := tcp.ConnectToTCPServer("localhost:"+c.Options.RelayPorts[0], c.Options.RelayPassword, c.Options.SharedSecret[:3]) + conn, banner, ipaddr, err := tcp.ConnectToTCPServer("127.0.0.1:"+c.Options.RelayPorts[0], c.Options.RelayPassword, c.Options.SharedSecret[:3]) log.Debugf("banner: %s", banner) if err != nil { - err = fmt.Errorf("could not connect to localhost:%s: %w", c.Options.RelayPorts[0], err) + err = fmt.Errorf("could not connect to 127.0.0.1:%s: %w", c.Options.RelayPorts[0], err) log.Debug(err) // not really an error because it will try to connect over the actual relay return @@ -501,7 +501,7 @@ func (c *Client) transferOverLocalRelay(errchan chan<- error) { } c.conn[0] = conn log.Debug("exchanged header message") - c.Options.RelayAddress = "localhost" + c.Options.RelayAddress = "127.0.0.1" c.Options.RelayPorts = strings.Split(banner, ",") if c.Options.NoMultiplexing { log.Debug("no multiplexing") @@ -1160,7 +1160,7 @@ func (c *Client) processMessagePake(m message.Message) (err error) { go func(j int) { defer wg.Done() var host string - if c.Options.RelayAddress == "localhost" { + if c.Options.RelayAddress == "127.0.0.1" { host = c.Options.RelayAddress } else { host, _, err = net.SplitHostPort(c.Options.RelayAddress) diff --git a/src/croc/croc_test.go b/src/croc/croc_test.go index 2248827..dec48ab 100644 --- a/src/croc/croc_test.go +++ b/src/croc/croc_test.go @@ -17,11 +17,11 @@ import ( func init() { log.SetLevel("trace") - go tcp.Run("debug", "localhost", "8281", "pass123", "8282,8283,8284,8285") - go tcp.Run("debug", "localhost", "8282", "pass123") - go tcp.Run("debug", "localhost", "8283", "pass123") - go tcp.Run("debug", "localhost", "8284", "pass123") - go tcp.Run("debug", "localhost", "8285", "pass123") + go tcp.Run("debug", "127.0.0.1", "8281", "pass123", "8282,8283,8284,8285") + go tcp.Run("debug", "127.0.0.1", "8282", "pass123") + go tcp.Run("debug", "127.0.0.1", "8283", "pass123") + go tcp.Run("debug", "127.0.0.1", "8284", "pass123") + go tcp.Run("debug", "127.0.0.1", "8285", "pass123") time.Sleep(1 * time.Second) } @@ -33,7 +33,7 @@ func TestCrocReadme(t *testing.T) { IsSender: true, SharedSecret: "8123-testingthecroc", Debug: true, - RelayAddress: "localhost:8281", + RelayAddress: "127.0.0.1:8281", RelayPorts: []string{"8281"}, RelayPassword: "pass123", Stdout: false, @@ -51,7 +51,7 @@ func TestCrocReadme(t *testing.T) { IsSender: false, SharedSecret: "8123-testingthecroc", Debug: true, - RelayAddress: "localhost:8281", + RelayAddress: "127.0.0.1:8281", RelayPassword: "pass123", Stdout: false, NoPrompt: true, @@ -99,7 +99,7 @@ func TestCrocEmptyFolder(t *testing.T) { IsSender: true, SharedSecret: "8123-testingthecroc", Debug: true, - RelayAddress: "localhost:8281", + RelayAddress: "127.0.0.1:8281", RelayPorts: []string{"8281"}, RelayPassword: "pass123", Stdout: false, @@ -117,7 +117,7 @@ func TestCrocEmptyFolder(t *testing.T) { IsSender: false, SharedSecret: "8123-testingthecroc", Debug: true, - RelayAddress: "localhost:8281", + RelayAddress: "127.0.0.1:8281", RelayPassword: "pass123", Stdout: false, NoPrompt: true, @@ -166,7 +166,7 @@ func TestCrocSymlink(t *testing.T) { IsSender: true, SharedSecret: "8124-testingthecroc", Debug: true, - RelayAddress: "localhost:8281", + RelayAddress: "127.0.0.1:8281", RelayPorts: []string{"8281"}, RelayPassword: "pass123", Stdout: false, @@ -184,7 +184,7 @@ func TestCrocSymlink(t *testing.T) { IsSender: false, SharedSecret: "8124-testingthecroc", Debug: true, - RelayAddress: "localhost:8281", + RelayAddress: "127.0.0.1:8281", RelayPassword: "pass123", Stdout: false, NoPrompt: true, @@ -241,7 +241,7 @@ func TestCrocLocal(t *testing.T) { IsSender: true, SharedSecret: "8123-testingthecroc", Debug: true, - RelayAddress: "localhost:8181", + RelayAddress: "127.0.0.1:8181", RelayPorts: []string{"8181", "8182"}, RelayPassword: "pass123", Stdout: true, @@ -260,7 +260,7 @@ func TestCrocLocal(t *testing.T) { IsSender: false, SharedSecret: "8123-testingthecroc", Debug: true, - RelayAddress: "localhost:8181", + RelayAddress: "127.0.0.1:8181", RelayPassword: "pass123", Stdout: true, NoPrompt: true, diff --git a/src/message/message_test.go b/src/message/message_test.go index 8c05bd7..eae58f5 100644 --- a/src/message/message_test.go +++ b/src/message/message_test.go @@ -85,7 +85,7 @@ func TestSend(t *testing.T) { }() time.Sleep(300 * time.Millisecond) - a, err := comm.NewConnection("localhost:"+port, 10*time.Minute) + a, err := comm.NewConnection("127.0.0.1:"+port, 10*time.Minute) assert.Nil(t, err) m := Message{Type: TypeMessage, Message: "hello, world"} e, salt, err := crypt.New([]byte("pass"), nil) diff --git a/src/tcp/tcp_test.go b/src/tcp/tcp_test.go index 21740eb..769d999 100644 --- a/src/tcp/tcp_test.go +++ b/src/tcp/tcp_test.go @@ -12,11 +12,11 @@ import ( func BenchmarkConnection(b *testing.B) { log.SetLevel("trace") - go Run("debug", "localhost", "8283", "pass123", "8284") + go Run("debug", "127.0.0.1", "8283", "pass123", "8284") time.Sleep(100 * time.Millisecond) b.ResetTimer() for i := 0; i < b.N; i++ { - c, _, _, _ := ConnectToTCPServer("localhost:8283", "pass123", fmt.Sprintf("testroom%d", i), 1*time.Minute) + c, _, _, _ := ConnectToTCPServer("127.0.0.1:8283", "pass123", fmt.Sprintf("testroom%d", i), 1*time.Minute) c.Close() } } @@ -24,22 +24,22 @@ func BenchmarkConnection(b *testing.B) { func TestTCP(t *testing.T) { log.SetLevel("error") timeToRoomDeletion = 100 * time.Millisecond - go Run("debug", "localhost", "8381", "pass123", "8382") + go Run("debug", "127.0.0.1", "8381", "pass123", "8382") time.Sleep(timeToRoomDeletion) - err := PingServer("localhost:8381") + err := PingServer("127.0.0.1:8381") assert.Nil(t, err) - err = PingServer("localhost:8333") + err = PingServer("127.0.0.1:8333") assert.NotNil(t, err) time.Sleep(timeToRoomDeletion) - c1, banner, _, err := ConnectToTCPServer("localhost:8381", "pass123", "testRoom", 1*time.Minute) + c1, banner, _, err := ConnectToTCPServer("127.0.0.1:8381", "pass123", "testRoom", 1*time.Minute) assert.Equal(t, banner, "8382") assert.Nil(t, err) - c2, _, _, err := ConnectToTCPServer("localhost:8381", "pass123", "testRoom") + c2, _, _, err := ConnectToTCPServer("127.0.0.1:8381", "pass123", "testRoom") assert.Nil(t, err) - _, _, _, err = ConnectToTCPServer("localhost:8381", "pass123", "testRoom") + _, _, _, err = ConnectToTCPServer("127.0.0.1:8381", "pass123", "testRoom") assert.NotNil(t, err) - _, _, _, err = ConnectToTCPServer("localhost:8381", "pass123", "testRoom", 1*time.Nanosecond) + _, _, _, err = ConnectToTCPServer("127.0.0.1:8381", "pass123", "testRoom", 1*time.Nanosecond) assert.NotNil(t, err) // try sending data diff --git a/src/utils/utils.go b/src/utils/utils.go index dabbe3f..f85ddcb 100644 --- a/src/utils/utils.go +++ b/src/utils/utils.go @@ -359,7 +359,7 @@ func init() { } func IsLocalIP(ipaddress string) bool { - if strings.Contains(ipaddress, "localhost") { + if strings.Contains(ipaddress, "127.0.0.1") { return true } host, _, _ := net.SplitHostPort(ipaddress) diff --git a/src/utils/utils_test.go b/src/utils/utils_test.go index 134d2bf..ad28f16 100644 --- a/src/utils/utils_test.go +++ b/src/utils/utils_test.go @@ -209,7 +209,7 @@ func TestGetRandomName(t *testing.T) { } func TestFindOpenPorts(t *testing.T) { - openPorts := FindOpenPorts("localhost", 9009, 4) + openPorts := FindOpenPorts("127.0.0.1", 9009, 4) assert.Equal(t, []int{9009, 9010, 9011, 9012}, openPorts) }