localhost -> 127.0.0.1 Fixes #513

This commit is contained in:
Zack Scholl 2023-03-20 09:16:07 -07:00
parent e1b49e6d1c
commit b3c0625659
7 changed files with 32 additions and 32 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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,

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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)
}