mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
fix local
This commit is contained in:
parent
4ea66fbd18
commit
04662df347
2 changed files with 15 additions and 5 deletions
|
@ -572,18 +572,21 @@ func (c *Client) Receive() (err error) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
log.Debug("switching to local")
|
log.Debug("switching to local")
|
||||||
portToUse := string(bytes.TrimPrefix(discoveries[0].Payload, []byte("croc")))
|
portToUse := string(bytes.TrimPrefix(discoveries[i].Payload, []byte("croc")))
|
||||||
if portToUse == "" {
|
if portToUse == "" {
|
||||||
portToUse = models.DEFAULT_PORT
|
portToUse = models.DEFAULT_PORT
|
||||||
}
|
}
|
||||||
address := net.JoinHostPort(discoveries[0].Address, portToUse)
|
address := net.JoinHostPort(discoveries[i].Address, portToUse)
|
||||||
if tcp.PingServer(address) == nil {
|
errPing := tcp.PingServer(address)
|
||||||
|
if errPing == nil {
|
||||||
log.Debugf("succesfully pinged '%s'", address)
|
log.Debugf("succesfully pinged '%s'", address)
|
||||||
c.Options.RelayAddress = address
|
c.Options.RelayAddress = address
|
||||||
c.ExternalIPConnected = c.Options.RelayAddress
|
c.ExternalIPConnected = c.Options.RelayAddress
|
||||||
c.Options.RelayAddress6 = ""
|
c.Options.RelayAddress6 = ""
|
||||||
usingLocal = true
|
usingLocal = true
|
||||||
break
|
break
|
||||||
|
} else {
|
||||||
|
log.Debugf("could not ping: %+v", errPing)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -660,8 +663,9 @@ func (c *Client) Receive() (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
serverTry := fmt.Sprintf("%s:%s", ip, port)
|
serverTry := fmt.Sprintf("%s:%s", ip, port)
|
||||||
conn, banner2, externalIP, errConn := tcp.ConnectToTCPServer(serverTry, c.Options.RelayPassword, c.Options.SharedSecret[:3], 250*time.Millisecond)
|
conn, banner2, externalIP, errConn := tcp.ConnectToTCPServer(serverTry, c.Options.RelayPassword, c.Options.SharedSecret[:3], 500*time.Millisecond)
|
||||||
if errConn != nil {
|
if errConn != nil {
|
||||||
|
log.Debug(errConn)
|
||||||
log.Debugf("could not connect to " + serverTry)
|
log.Debugf("could not connect to " + serverTry)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -186,7 +186,9 @@ func (s *server) clientCommunication(port string, c *comm.Comm) (room string, er
|
||||||
}
|
}
|
||||||
if bytes.Equal(Abytes, []byte("ping")) {
|
if bytes.Equal(Abytes, []byte("ping")) {
|
||||||
room = pingRoom
|
room = pingRoom
|
||||||
|
log.Debug("sending back pong")
|
||||||
c.Send([]byte("pong"))
|
c.Send([]byte("pong"))
|
||||||
|
time.Sleep(100 * time.Millisecond)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = B.Update(Abytes)
|
err = B.Update(Abytes)
|
||||||
|
@ -409,16 +411,20 @@ func pipe(conn1 net.Conn, conn2 net.Conn) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func PingServer(address string) (err error) {
|
func PingServer(address string) (err error) {
|
||||||
c, err := comm.NewConnection(address, 200*time.Millisecond)
|
log.Debugf("pinging %s", address)
|
||||||
|
c, err := comm.NewConnection(address, 300*time.Millisecond)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Debug(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = c.Send([]byte("ping"))
|
err = c.Send([]byte("ping"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Debug(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
b, err := c.Receive()
|
b, err := c.Receive()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Debug(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if bytes.Equal(b, []byte("pong")) {
|
if bytes.Equal(b, []byte("pong")) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue