mirror of https://github.com/schollz/croc.git
check discoveries for right prefix
This commit is contained in:
parent
aaeda77af4
commit
da626334e0
|
@ -258,7 +258,7 @@ func (c *Client) broadcastOnLocalNetwork() {
|
||||||
// look for peers first
|
// look for peers first
|
||||||
discoveries, err := peerdiscovery.Discover(peerdiscovery.Settings{
|
discoveries, err := peerdiscovery.Discover(peerdiscovery.Settings{
|
||||||
Limit: -1,
|
Limit: -1,
|
||||||
Payload: []byte(c.Options.RelayPorts[0]),
|
Payload: []byte("croc" + c.Options.RelayPorts[0]),
|
||||||
Delay: 10 * time.Millisecond,
|
Delay: 10 * time.Millisecond,
|
||||||
TimeLimit: 30 * time.Second,
|
TimeLimit: 30 * time.Second,
|
||||||
})
|
})
|
||||||
|
@ -394,10 +394,18 @@ func (c *Client) Receive() (err error) {
|
||||||
TimeLimit: 100 * time.Millisecond,
|
TimeLimit: 100 * time.Millisecond,
|
||||||
})
|
})
|
||||||
if err == nil && len(discoveries) > 0 {
|
if err == nil && len(discoveries) > 0 {
|
||||||
log.Debug("switching to local")
|
for i := 0; i < len(discoveries); i++ {
|
||||||
c.Options.RelayAddress = fmt.Sprintf("%s:%s", discoveries[0].Address, discoveries[0].Payload)
|
if !bytes.HasPrefix(discoveries[i].Payload, []byte("croc")) {
|
||||||
c.ExternalIPConnected = c.Options.RelayAddress
|
log.Debugf("discovery %d has wrong payload: %+v", i, discoveries[i])
|
||||||
usingLocal = true
|
}
|
||||||
|
log.Debug("switching to local")
|
||||||
|
c.Options.RelayAddress = fmt.Sprintf("%s:%s",
|
||||||
|
discoveries[0].Address,
|
||||||
|
bytes.TrimPrefix(discoveries[0].Payload, []byte("croc")),
|
||||||
|
)
|
||||||
|
c.ExternalIPConnected = c.Options.RelayAddress
|
||||||
|
usingLocal = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
log.Debugf("discoveries: %+v", discoveries)
|
log.Debugf("discoveries: %+v", discoveries)
|
||||||
log.Debug("establishing connection")
|
log.Debug("establishing connection")
|
||||||
|
|
Loading…
Reference in New Issue