mirror of https://github.com/schollz/croc.git
localhost -> 127.0.0.1 Fixes #513
This commit is contained in:
parent
e1b49e6d1c
commit
b3c0625659
|
@ -49,7 +49,7 @@ func TestComm(t *testing.T) {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
time.Sleep(300 * time.Millisecond)
|
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)
|
assert.Nil(t, err)
|
||||||
data, err := a.Receive()
|
data, err := a.Receive()
|
||||||
assert.Equal(t, []byte("hello, world"), data)
|
assert.Equal(t, []byte("hello, world"), data)
|
||||||
|
|
|
@ -428,7 +428,7 @@ func (c *Client) sendCollectFiles(filesInfo []FileInfo) (err error) {
|
||||||
func (c *Client) setupLocalRelay() {
|
func (c *Client) setupLocalRelay() {
|
||||||
// setup the relay locally
|
// setup the relay locally
|
||||||
firstPort, _ := strconv.Atoi(c.Options.RelayPorts[0])
|
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) {
|
if len(openPorts) < len(c.Options.RelayPorts) {
|
||||||
panic("not enough open ports to run local relay")
|
panic("not enough open ports to run local relay")
|
||||||
}
|
}
|
||||||
|
@ -441,7 +441,7 @@ func (c *Client) setupLocalRelay() {
|
||||||
if c.Options.Debug {
|
if c.Options.Debug {
|
||||||
debugString = "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 {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -480,10 +480,10 @@ func (c *Client) transferOverLocalRelay(errchan chan<- error) {
|
||||||
time.Sleep(500 * time.Millisecond)
|
time.Sleep(500 * time.Millisecond)
|
||||||
log.Debug("establishing connection")
|
log.Debug("establishing connection")
|
||||||
var banner string
|
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)
|
log.Debugf("banner: %s", banner)
|
||||||
if err != nil {
|
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)
|
log.Debug(err)
|
||||||
// not really an error because it will try to connect over the actual relay
|
// not really an error because it will try to connect over the actual relay
|
||||||
return
|
return
|
||||||
|
@ -501,7 +501,7 @@ func (c *Client) transferOverLocalRelay(errchan chan<- error) {
|
||||||
}
|
}
|
||||||
c.conn[0] = conn
|
c.conn[0] = conn
|
||||||
log.Debug("exchanged header message")
|
log.Debug("exchanged header message")
|
||||||
c.Options.RelayAddress = "localhost"
|
c.Options.RelayAddress = "127.0.0.1"
|
||||||
c.Options.RelayPorts = strings.Split(banner, ",")
|
c.Options.RelayPorts = strings.Split(banner, ",")
|
||||||
if c.Options.NoMultiplexing {
|
if c.Options.NoMultiplexing {
|
||||||
log.Debug("no multiplexing")
|
log.Debug("no multiplexing")
|
||||||
|
@ -1160,7 +1160,7 @@ func (c *Client) processMessagePake(m message.Message) (err error) {
|
||||||
go func(j int) {
|
go func(j int) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
var host string
|
var host string
|
||||||
if c.Options.RelayAddress == "localhost" {
|
if c.Options.RelayAddress == "127.0.0.1" {
|
||||||
host = c.Options.RelayAddress
|
host = c.Options.RelayAddress
|
||||||
} else {
|
} else {
|
||||||
host, _, err = net.SplitHostPort(c.Options.RelayAddress)
|
host, _, err = net.SplitHostPort(c.Options.RelayAddress)
|
||||||
|
|
|
@ -17,11 +17,11 @@ import (
|
||||||
func init() {
|
func init() {
|
||||||
log.SetLevel("trace")
|
log.SetLevel("trace")
|
||||||
|
|
||||||
go tcp.Run("debug", "localhost", "8281", "pass123", "8282,8283,8284,8285")
|
go tcp.Run("debug", "127.0.0.1", "8281", "pass123", "8282,8283,8284,8285")
|
||||||
go tcp.Run("debug", "localhost", "8282", "pass123")
|
go tcp.Run("debug", "127.0.0.1", "8282", "pass123")
|
||||||
go tcp.Run("debug", "localhost", "8283", "pass123")
|
go tcp.Run("debug", "127.0.0.1", "8283", "pass123")
|
||||||
go tcp.Run("debug", "localhost", "8284", "pass123")
|
go tcp.Run("debug", "127.0.0.1", "8284", "pass123")
|
||||||
go tcp.Run("debug", "localhost", "8285", "pass123")
|
go tcp.Run("debug", "127.0.0.1", "8285", "pass123")
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ func TestCrocReadme(t *testing.T) {
|
||||||
IsSender: true,
|
IsSender: true,
|
||||||
SharedSecret: "8123-testingthecroc",
|
SharedSecret: "8123-testingthecroc",
|
||||||
Debug: true,
|
Debug: true,
|
||||||
RelayAddress: "localhost:8281",
|
RelayAddress: "127.0.0.1:8281",
|
||||||
RelayPorts: []string{"8281"},
|
RelayPorts: []string{"8281"},
|
||||||
RelayPassword: "pass123",
|
RelayPassword: "pass123",
|
||||||
Stdout: false,
|
Stdout: false,
|
||||||
|
@ -51,7 +51,7 @@ func TestCrocReadme(t *testing.T) {
|
||||||
IsSender: false,
|
IsSender: false,
|
||||||
SharedSecret: "8123-testingthecroc",
|
SharedSecret: "8123-testingthecroc",
|
||||||
Debug: true,
|
Debug: true,
|
||||||
RelayAddress: "localhost:8281",
|
RelayAddress: "127.0.0.1:8281",
|
||||||
RelayPassword: "pass123",
|
RelayPassword: "pass123",
|
||||||
Stdout: false,
|
Stdout: false,
|
||||||
NoPrompt: true,
|
NoPrompt: true,
|
||||||
|
@ -99,7 +99,7 @@ func TestCrocEmptyFolder(t *testing.T) {
|
||||||
IsSender: true,
|
IsSender: true,
|
||||||
SharedSecret: "8123-testingthecroc",
|
SharedSecret: "8123-testingthecroc",
|
||||||
Debug: true,
|
Debug: true,
|
||||||
RelayAddress: "localhost:8281",
|
RelayAddress: "127.0.0.1:8281",
|
||||||
RelayPorts: []string{"8281"},
|
RelayPorts: []string{"8281"},
|
||||||
RelayPassword: "pass123",
|
RelayPassword: "pass123",
|
||||||
Stdout: false,
|
Stdout: false,
|
||||||
|
@ -117,7 +117,7 @@ func TestCrocEmptyFolder(t *testing.T) {
|
||||||
IsSender: false,
|
IsSender: false,
|
||||||
SharedSecret: "8123-testingthecroc",
|
SharedSecret: "8123-testingthecroc",
|
||||||
Debug: true,
|
Debug: true,
|
||||||
RelayAddress: "localhost:8281",
|
RelayAddress: "127.0.0.1:8281",
|
||||||
RelayPassword: "pass123",
|
RelayPassword: "pass123",
|
||||||
Stdout: false,
|
Stdout: false,
|
||||||
NoPrompt: true,
|
NoPrompt: true,
|
||||||
|
@ -166,7 +166,7 @@ func TestCrocSymlink(t *testing.T) {
|
||||||
IsSender: true,
|
IsSender: true,
|
||||||
SharedSecret: "8124-testingthecroc",
|
SharedSecret: "8124-testingthecroc",
|
||||||
Debug: true,
|
Debug: true,
|
||||||
RelayAddress: "localhost:8281",
|
RelayAddress: "127.0.0.1:8281",
|
||||||
RelayPorts: []string{"8281"},
|
RelayPorts: []string{"8281"},
|
||||||
RelayPassword: "pass123",
|
RelayPassword: "pass123",
|
||||||
Stdout: false,
|
Stdout: false,
|
||||||
|
@ -184,7 +184,7 @@ func TestCrocSymlink(t *testing.T) {
|
||||||
IsSender: false,
|
IsSender: false,
|
||||||
SharedSecret: "8124-testingthecroc",
|
SharedSecret: "8124-testingthecroc",
|
||||||
Debug: true,
|
Debug: true,
|
||||||
RelayAddress: "localhost:8281",
|
RelayAddress: "127.0.0.1:8281",
|
||||||
RelayPassword: "pass123",
|
RelayPassword: "pass123",
|
||||||
Stdout: false,
|
Stdout: false,
|
||||||
NoPrompt: true,
|
NoPrompt: true,
|
||||||
|
@ -241,7 +241,7 @@ func TestCrocLocal(t *testing.T) {
|
||||||
IsSender: true,
|
IsSender: true,
|
||||||
SharedSecret: "8123-testingthecroc",
|
SharedSecret: "8123-testingthecroc",
|
||||||
Debug: true,
|
Debug: true,
|
||||||
RelayAddress: "localhost:8181",
|
RelayAddress: "127.0.0.1:8181",
|
||||||
RelayPorts: []string{"8181", "8182"},
|
RelayPorts: []string{"8181", "8182"},
|
||||||
RelayPassword: "pass123",
|
RelayPassword: "pass123",
|
||||||
Stdout: true,
|
Stdout: true,
|
||||||
|
@ -260,7 +260,7 @@ func TestCrocLocal(t *testing.T) {
|
||||||
IsSender: false,
|
IsSender: false,
|
||||||
SharedSecret: "8123-testingthecroc",
|
SharedSecret: "8123-testingthecroc",
|
||||||
Debug: true,
|
Debug: true,
|
||||||
RelayAddress: "localhost:8181",
|
RelayAddress: "127.0.0.1:8181",
|
||||||
RelayPassword: "pass123",
|
RelayPassword: "pass123",
|
||||||
Stdout: true,
|
Stdout: true,
|
||||||
NoPrompt: true,
|
NoPrompt: true,
|
||||||
|
|
|
@ -85,7 +85,7 @@ func TestSend(t *testing.T) {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
time.Sleep(300 * time.Millisecond)
|
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)
|
assert.Nil(t, err)
|
||||||
m := Message{Type: TypeMessage, Message: "hello, world"}
|
m := Message{Type: TypeMessage, Message: "hello, world"}
|
||||||
e, salt, err := crypt.New([]byte("pass"), nil)
|
e, salt, err := crypt.New([]byte("pass"), nil)
|
||||||
|
|
|
@ -12,11 +12,11 @@ import (
|
||||||
|
|
||||||
func BenchmarkConnection(b *testing.B) {
|
func BenchmarkConnection(b *testing.B) {
|
||||||
log.SetLevel("trace")
|
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)
|
time.Sleep(100 * time.Millisecond)
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
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()
|
c.Close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,22 +24,22 @@ func BenchmarkConnection(b *testing.B) {
|
||||||
func TestTCP(t *testing.T) {
|
func TestTCP(t *testing.T) {
|
||||||
log.SetLevel("error")
|
log.SetLevel("error")
|
||||||
timeToRoomDeletion = 100 * time.Millisecond
|
timeToRoomDeletion = 100 * time.Millisecond
|
||||||
go Run("debug", "localhost", "8381", "pass123", "8382")
|
go Run("debug", "127.0.0.1", "8381", "pass123", "8382")
|
||||||
time.Sleep(timeToRoomDeletion)
|
time.Sleep(timeToRoomDeletion)
|
||||||
err := PingServer("localhost:8381")
|
err := PingServer("127.0.0.1:8381")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
err = PingServer("localhost:8333")
|
err = PingServer("127.0.0.1:8333")
|
||||||
assert.NotNil(t, err)
|
assert.NotNil(t, err)
|
||||||
|
|
||||||
time.Sleep(timeToRoomDeletion)
|
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.Equal(t, banner, "8382")
|
||||||
assert.Nil(t, err)
|
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)
|
assert.Nil(t, err)
|
||||||
_, _, _, err = ConnectToTCPServer("localhost:8381", "pass123", "testRoom")
|
_, _, _, err = ConnectToTCPServer("127.0.0.1:8381", "pass123", "testRoom")
|
||||||
assert.NotNil(t, err)
|
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)
|
assert.NotNil(t, err)
|
||||||
|
|
||||||
// try sending data
|
// try sending data
|
||||||
|
|
|
@ -359,7 +359,7 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsLocalIP(ipaddress string) bool {
|
func IsLocalIP(ipaddress string) bool {
|
||||||
if strings.Contains(ipaddress, "localhost") {
|
if strings.Contains(ipaddress, "127.0.0.1") {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
host, _, _ := net.SplitHostPort(ipaddress)
|
host, _, _ := net.SplitHostPort(ipaddress)
|
||||||
|
|
|
@ -209,7 +209,7 @@ func TestGetRandomName(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFindOpenPorts(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)
|
assert.Equal(t, []int{9009, 9010, 9011, 9012}, openPorts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue