mirror of https://github.com/schollz/croc.git
check if can connect first
This commit is contained in:
parent
42b9a00102
commit
181de46313
20
connect.go
20
connect.go
|
@ -22,7 +22,6 @@ import (
|
||||||
homedir "github.com/mitchellh/go-homedir"
|
homedir "github.com/mitchellh/go-homedir"
|
||||||
"github.com/schollz/croc/keypair"
|
"github.com/schollz/croc/keypair"
|
||||||
"github.com/schollz/croc/randomstring"
|
"github.com/schollz/croc/randomstring"
|
||||||
"github.com/schollz/ischrooted"
|
|
||||||
"github.com/schollz/peerdiscovery"
|
"github.com/schollz/peerdiscovery"
|
||||||
"github.com/schollz/progressbar"
|
"github.com/schollz/progressbar"
|
||||||
tarinator "github.com/schollz/tarinator-go"
|
tarinator "github.com/schollz/tarinator-go"
|
||||||
|
@ -247,7 +246,7 @@ func (c *Connection) Run() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.Server != "localhost" && !ischrooted.IsChrooted() {
|
if c.Server != "localhost" {
|
||||||
// broadcast local connection from sender
|
// broadcast local connection from sender
|
||||||
log.Debug("settings payload to ", c.Code)
|
log.Debug("settings payload to ", c.Code)
|
||||||
go func() {
|
go func() {
|
||||||
|
@ -277,11 +276,18 @@ func (c *Connection) Run() error {
|
||||||
log.Debug(errDiscover)
|
log.Debug(errDiscover)
|
||||||
}
|
}
|
||||||
if len(discovered) > 0 {
|
if len(discovered) > 0 {
|
||||||
c.Server = discovered[0].Address
|
log.Debugf("discovered %s on %s", discovered[0].Payload, discovered[0].Address)
|
||||||
log.Debug(discovered[0].Address)
|
_, connectTimeout := net.DialTimeout("tcp", discovered[0].Address+":27001", 1*time.Second)
|
||||||
c.Code = string(discovered[0].Payload)
|
if connectTimeout == nil {
|
||||||
log.Debugf("discovered code '%s'", c.Code)
|
log.Debug("connected")
|
||||||
time.Sleep(200 * time.Millisecond)
|
c.Server = discovered[0].Address
|
||||||
|
log.Debug(discovered[0].Address)
|
||||||
|
c.Code = string(discovered[0].Payload)
|
||||||
|
time.Sleep(200 * time.Millisecond)
|
||||||
|
} else {
|
||||||
|
log.Debug("could not connect")
|
||||||
|
c.Code = getInput("Enter receive code: ")
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
c.Code = getInput("Enter receive code: ")
|
c.Code = getInput("Enter receive code: ")
|
||||||
log.Debug("changed code to ", c.Code)
|
log.Debug("changed code to ", c.Code)
|
||||||
|
|
Loading…
Reference in New Issue