fix local

This commit is contained in:
Zack Scholl 2021-10-02 11:55:43 -07:00
parent 4ea66fbd18
commit 04662df347
2 changed files with 15 additions and 5 deletions

View File

@ -572,18 +572,21 @@ func (c *Client) Receive() (err error) {
continue
}
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 == "" {
portToUse = models.DEFAULT_PORT
}
address := net.JoinHostPort(discoveries[0].Address, portToUse)
if tcp.PingServer(address) == nil {
address := net.JoinHostPort(discoveries[i].Address, portToUse)
errPing := tcp.PingServer(address)
if errPing == nil {
log.Debugf("succesfully pinged '%s'", address)
c.Options.RelayAddress = address
c.ExternalIPConnected = c.Options.RelayAddress
c.Options.RelayAddress6 = ""
usingLocal = true
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)
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 {
log.Debug(errConn)
log.Debugf("could not connect to " + serverTry)
continue
}

View File

@ -186,7 +186,9 @@ func (s *server) clientCommunication(port string, c *comm.Comm) (room string, er
}
if bytes.Equal(Abytes, []byte("ping")) {
room = pingRoom
log.Debug("sending back pong")
c.Send([]byte("pong"))
time.Sleep(100 * time.Millisecond)
return
}
err = B.Update(Abytes)
@ -409,16 +411,20 @@ func pipe(conn1 net.Conn, conn2 net.Conn) {
}
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 {
log.Debug(err)
return
}
err = c.Send([]byte("ping"))
if err != nil {
log.Debug(err)
return
}
b, err := c.Receive()
if err != nil {
log.Debug(err)
return
}
if bytes.Equal(b, []byte("pong")) {